warp4b.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Same as warp4b.py but using the applications.MorphPlotter class
  2. from vedo import Mesh, settings, dataurl
  3. from vedo.applications import MorphPlotter
  4. ####################################################################################
  5. # THIS IS IMPLEMENTED IN vedo.applications.MorphPlotter, shown here for reference
  6. ####################################################################################
  7. # from vedo import Plotter, Points, Text2D, Axes
  8. # class MorphPlotter(Plotter):
  9. #
  10. # def __init__(self, source, target, **kwargs):
  11. # kwargs.update(dict(N=3, sharecam=0))
  12. # super().__init__(**kwargs)
  13. #
  14. # self.source = source.pickable(True)
  15. # self.target = target.pickable(False)
  16. # self.clicked = []
  17. # self.sources = []
  18. # self.targets = []
  19. # self.msg0 = Text2D("Pick a point on the surface",
  20. # pos="bottom-center", c='white', bg="blue4", alpha=1)
  21. # self.msg1 = Text2D(pos="bottom-center", c='white', bg="blue4", alpha=1)
  22. # instructions = (
  23. # "Morphological alignment of 3D surfaces.\n"
  24. # "Pick a point on the source surface, then\n"
  25. # "pick the corresponding point on the target surface\n"
  26. # "Pick at least 4 point pairs. Press:\n"
  27. # "- c to clear the selection.\n"
  28. # "- d to delete the last selection.\n"
  29. # "- q to quit."
  30. # )
  31. # self.instructions = Text2D(instructions, s=0.7, bg="blue4", alpha=0.1)
  32. # self.at(0).add(source, self.msg0, self.instructions).reset_camera()
  33. # self.at(1).add(f"Reference {target.filename}", self.msg1, target)
  34. # cam1 = self.camera # save camera at 1
  35. # self.at(2).add("Morphing Output", target).background("k9")
  36. # self.camera = cam1 # use the same camera of renderer1
  37. #
  38. # self.callid1 = self.add_callback("on key press", self.on_keypress)
  39. # self.callid2 = self.add_callback("on click", self.on_click)
  40. # self._interactive = True
  41. #
  42. # def update(self):
  43. # source_pts = Points(self.sources).color("purple5").ps(12)
  44. # target_pts = Points(self.targets).color("purple5").ps(12)
  45. # source_pts.name = "source_pts"
  46. # target_pts.name = "target_pts"
  47. # slabels = self.source_pts.labels2d("id", c="purple3")
  48. # tlabels = self.target_pts.labels2d("id", c="purple3")
  49. # slabels.name = "source_pts"
  50. # tlabels.name = "target_pts"
  51. # self.at(0).remove("source_pts").add(source_pts, slabels)
  52. # self.at(1).remove("target_pts").add(target_pts, tlabels)
  53. # self.render()
  54. #
  55. # if len(self.sources) == len(self.targets) and len(self.sources) > 3:
  56. # warped = self.source.clone().warp(self.sources, self.targets)
  57. # warped.name = "warped"
  58. # self.at(2).remove("warped").add(warped)
  59. # self.render()
  60. #
  61. # def on_click(self, evt):
  62. # if evt.object == source:
  63. # self.sources.append(evt.picked3d)
  64. # self.source.pickable(False)
  65. # self.target.pickable(True)
  66. # self.msg0.text("--->")
  67. # self.msg1.text("now pick a target point")
  68. # elif evt.object == self.target:
  69. # self.targets.append(evt.picked3d)
  70. # self.source.pickable(True)
  71. # self.target.pickable(False)
  72. # self.msg0.text("now pick a source point")
  73. # self.msg1.text("<---")
  74. # self.update()
  75. #
  76. # def on_keypress(self, evt):
  77. # if evt.keypress == "c":
  78. # self.sources.clear()
  79. # self.targets.clear()
  80. # self.at(0).remove("source_pts")
  81. # self.at(1).remove("target_pts")
  82. # self.at(2).remove("warped")
  83. # self.msg0.text("CLEARED! Pick a point here")
  84. # self.msg1.text("")
  85. # self.source.pickable(True)
  86. # self.target.pickable(False)
  87. # self.update()
  88. # elif evt.keypress == "d":
  89. # n = min(len(self.sources), len(self.targets))
  90. # self.sources = self.sources[:n-1]
  91. # self.targets = self.targets[:n-1]
  92. # self.msg0.text("Last point deleted! Pick a point here")
  93. # self.msg1.text("")
  94. # self.source.pickable(True)
  95. # self.target.pickable(False)
  96. # self.update()
  97. ################################################################################
  98. settings.default_font = "Calco"
  99. source = Mesh(dataurl+"limb_surface.vtk").color("k5")
  100. source.rotate_y(90).rotate_z(-60).rotate_x(40)
  101. target = Mesh(dataurl+"290.vtk").color("yellow5")
  102. target.rotate_y(-40)
  103. plt = MorphPlotter(source, target, size=(2400, 850), axes=14)
  104. plt.cmap_name = "RdYlBu_r"
  105. plt.show()
  106. plt.close()