Commit 2a5582a674ac1da54fe6fe133b1d5bcf34b8ce5f

Authored by Paulo Henrique Junqueira Amorim
1 parent 14dec315

ENH: Creted Class manipulate Cut Plane

invesalius/data/viewer_volume.py
... ... @@ -64,9 +64,9 @@ class Viewer(wx.Panel):
64 64 ps.Publisher().subscribe(self.ChangeBackgroundColour,
65 65 'Change volume viewer background colour')
66 66 ps.Publisher().subscribe(self.LoadVolume, 'Load volume into viewer')
  67 + ps.Publisher().subscribe(self.AppendActor,'AppendActor')
  68 + ps.Publisher().subscribe(self.SetWidgetInteractor, 'Set Widget Interactor')
67 69  
68   - ps.Publisher().subscribe(self.GetInteractorVolume, 'Get Interactor Volume')
69   - ps.Publisher().subscribe(self.ADDActor, 'ADD Actor')
70 70  
71 71 def LoadVolume(self, pubsub_evt):
72 72 volume, colour = pubsub_evt.data
... ... @@ -130,8 +130,8 @@ class Viewer(wx.Panel):
130 130 sagital_plane.Show()
131 131 sagital_plane.Update()
132 132  
133   - def GetInteractorVolume(self, evt_pubsub=None):
  133 + def SetWidgetInteractor(self, evt_pubsub=None):
134 134 evt_pubsub.data.SetInteractor(self.iren._Iren)
135   -
136   - def ADDActor(self, evt_pubsub=None):
  135 +
  136 + def AppendActor(self, evt_pubsub=None):
137 137 self.ren.AddActor(evt_pubsub.data)
138 138 \ No newline at end of file
... ...
invesalius/data/volume.py
... ... @@ -252,64 +252,9 @@ class Volume():
252 252 volume_mapper.SetVolumeRayCastFunction(composite_function)
253 253 volume_mapper.SetGradientEstimator(gradientEstimator)
254 254 volume_mapper.IntermixIntersectingGeometryOn()
255   -
256   - #============================ TESTE =============================================
257   -
258   - self.plane_widget = plane_widget = vtk.vtkImagePlaneWidget()
259   - plane_widget.SetInput(image2.GetOutput())
260   - plane_widget.SetPlaneOrientationToXAxes()
261   - plane_widget.SetResliceInterpolateToLinear()
262   - plane_widget.TextureVisibilityOff()
263   -
264   - #Set left mouse button to move and rotate plane
265   - plane_widget.SetLeftButtonAction(1)
266   -
267   - #SetColor margin to green
268   - margin_property = plane_widget.GetMarginProperty()
269   - margin_property.SetColor(0,0.8,0)
270   -
271   - #Disable cross
272   - cursor_property = plane_widget.GetCursorProperty()
273   - cursor_property.SetOpacity(0)
274   -
275   -
276   - self.plane_source = vtk.vtkPlaneSource()
277   - self.plane_source.SetOrigin(plane_widget.GetOrigin())
278   - self.plane_source.SetPoint1(plane_widget.GetPoint1())
279   - self.plane_source.SetPoint2(plane_widget.GetPoint2())
280   - self.plane_source.SetNormal(plane_widget.GetNormal())
281   -
282   - plane_mapper = vtk.vtkPolyDataMapper()
283   - plane_mapper.SetInput(self.plane_source.GetOutput())
284   -
285   - self.plane_actor = vtk.vtkActor()
286   - self.plane_actor.SetMapper(plane_mapper)
287   - self.plane_actor.GetProperty().BackfaceCullingOn()
288   - self.plane_actor.GetProperty().SetOpacity(0)
289   -
290   - self.plane_actor.SetVisibility(1)
291   -
292   - self.plane_widget.AddObserver("InteractionEvent", self.UpdatePlane)
293   -
294   - ps.Publisher().sendMessage('ADD Actor', self.plane_actor)
295   - ps.Publisher().sendMessage('Get Interactor Volume', self.plane_widget)
296   -
297   - self.plane_actor.SetVisibility(1)
298   - self.plane_widget.On()
299   -
300   -
301   - self.plane = plane = vtk.vtkPlane()
302   - plane.SetNormal(self.plane_source.GetNormal())
303   - plane.SetOrigin(self.plane_source.GetOrigin())
304   -
305   - volume_mapper.AddClippingPlane(plane)
306   -
307   -
308   -
309   -
310   -
311   - #===============================================================================
312 255  
  256 + #Cut Plane
  257 + CutPlane(image2.GetOutput(), volume_mapper)
313 258  
314 259 self.color_transfer = color_transfer
315 260  
... ... @@ -347,24 +292,96 @@ class Volume():
347 292 #if value < 0:
348 293 # valor = 2**16 - abs(value)
349 294 #else:
350   - # valor = value
351   -
  295 + # valor = value
352 296 return value - scale[0]
353   -
354   -
355   - def MovePlane(self):
356   - pass
  297 +
  298 +
  299 +class CutPlane:
  300 + def __init__(self, img, volume_mapper):
  301 + self.img = img
  302 + self.volume_mapper = volume_mapper
  303 + self.CreatePlane()
  304 + self.__bind_events()
357 305  
  306 + def __bind_events(self):
  307 + ps.Publisher().subscribe(self.ResetPlane,
  308 + 'Reset Cut Plane')
  309 + ps.Publisher().subscribe(self.EnablePlane,
  310 + 'Enable Cut Plane')
  311 + ps.Publisher().subscribe(self.DisablePlane,
  312 + 'Disable Cut Plane')
  313 +
  314 + def CreatePlane(self):
  315 + self.plane_widget = plane_widget = vtk.vtkImagePlaneWidget()
  316 + plane_widget.SetInput(self.img)
  317 + plane_widget.SetPlaneOrientationToXAxes()
  318 + #plane_widget.SetResliceInterpolateToLinear()
  319 + plane_widget.TextureVisibilityOff()
  320 + #Set left mouse button to move and rotate plane
  321 + plane_widget.SetLeftButtonAction(1)
  322 + #SetColor margin to green
  323 + margin_property = plane_widget.GetMarginProperty()
  324 + margin_property.SetColor(0,0.8,0)
  325 + #Disable cross
  326 + cursor_property = plane_widget.GetCursorProperty()
  327 + cursor_property.SetOpacity(0)
  328 + self.plane_source = plane_source = vtk.vtkPlaneSource()
  329 + plane_source.SetOrigin(plane_widget.GetOrigin())
  330 + plane_source.SetPoint1(plane_widget.GetPoint1())
  331 + plane_source.SetPoint2(plane_widget.GetPoint2())
  332 + plane_source.SetNormal(plane_widget.GetNormal())
  333 + plane_mapper = vtk.vtkPolyDataMapper()
  334 + plane_mapper.SetInput(plane_source.GetOutput())
  335 + self.plane_actor = plane_actor = vtk.vtkActor()
  336 + plane_actor.SetMapper(plane_mapper)
  337 + plane_actor.GetProperty().BackfaceCullingOn()
  338 + plane_actor.GetProperty().SetOpacity(0)
  339 + plane_widget.AddObserver("InteractionEvent", self.UpdatePlane)
  340 + ps.Publisher().sendMessage('AppendActor', self.plane_actor)
  341 + ps.Publisher().sendMessage('Set Widget Interactor', self.plane_widget)
  342 + plane_actor.SetVisibility(1)
  343 + plane_widget.On()
  344 + self.plane = plane = vtk.vtkPlane()
  345 + plane.SetNormal(self.plane_source.GetNormal())
  346 + plane.SetOrigin(self.plane_source.GetOrigin())
  347 + self.volume_mapper.AddClippingPlane(plane)
  348 + #Storage First Position
  349 + self.origin = plane_widget.GetOrigin()
  350 + self.p1 = plane_widget.GetPoint1()
  351 + self.p2 = plane_widget.GetPoint2()
  352 + self.normal = plane_widget.GetNormal()
  353 +
358 354 def UpdatePlane(self, a, b):
359 355 plane_source = self.plane_source
360   - plane_source.SetOrigin(self.plane_widget.GetOrigin())
361   - plane_source.SetPoint1(self.plane_widget.GetPoint1())
362   - plane_source.SetPoint2(self.plane_widget.GetPoint2())
363   - plane_source.SetNormal(self.plane_widget.GetNormal())
  356 + plane_widget = self.plane_widget
  357 + plane_source.SetOrigin(plane_widget.GetOrigin())
  358 + plane_source.SetPoint1(plane_widget.GetPoint1())
  359 + plane_source.SetPoint2(plane_widget.GetPoint2())
  360 + plane_source.SetNormal(plane_widget.GetNormal())
364 361 self.plane_actor.VisibilityOn()
365   -
366 362 self.plane.SetNormal(plane_source.GetNormal())
367 363 self.plane.SetOrigin(plane_source.GetOrigin())
  364 + ps.Publisher().sendMessage('Render volume viewer', None)
  365 +
  366 + def EnablePlane(self, evt_pubsub=None):
  367 + self.plane_actor.SetVisibility(1)
  368 + ps.Publisher().sendMessage('Render volume viewer', None)
368 369  
  370 + def DisablePlane(self,evt_pubsub=None):
  371 + self.plane_actor.SetVisibility(0)
369 372 ps.Publisher().sendMessage('Render volume viewer', None)
370 373  
  374 + def ResetPlane(self, evt_pubsub=None):
  375 + plane_source = self.plane_source
  376 + plane_widget = self.plane_widget
  377 + plane_source.SetOrigin(self.origin)
  378 + plane_source.SetPoint1(self.p1)
  379 + plane_source.SetPoint2(self.p2)
  380 + plane_source.SetNormal(self.normal)
  381 + self.plane_actor.VisibilityOn()
  382 + self.plane.SetNormal(self.normal)
  383 + self.plane.SetOrigin(self.origin)
  384 + ps.Publisher().sendMessage('Render volume viewer', None)
  385 +
  386 +
  387 +
371 388 \ No newline at end of file
... ...