Commit 99740a229dc281db7964a7a07c08a759590c45a6

Authored by Paulo Henrique Junqueira Amorim
1 parent cc41da0f

ADD: Clipping plane

Showing 1 changed file with 73 additions and 6 deletions   Show diff stats
invesalius/data/volume.py
@@ -253,10 +253,64 @@ class Volume(): @@ -253,10 +253,64 @@ class Volume():
253 volume_mapper.SetGradientEstimator(gradientEstimator) 253 volume_mapper.SetGradientEstimator(gradientEstimator)
254 volume_mapper.IntermixIntersectingGeometryOn() 254 volume_mapper.IntermixIntersectingGeometryOn()
255 255
256 - #clip = vtk.vtkPlane()  
257 -  
258 - #volume_mapper.AddClippingPlane(clip) 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 +
259 307
  308 +
  309 +
  310 +
  311 + #===============================================================================
  312 +
  313 +
260 self.color_transfer = color_transfer 314 self.color_transfer = color_transfer
261 315
262 volume_properties = vtk.vtkVolumeProperty() 316 volume_properties = vtk.vtkVolumeProperty()
@@ -298,6 +352,19 @@ class Volume(): @@ -298,6 +352,19 @@ class Volume():
298 return value - scale[0] 352 return value - scale[0]
299 353
300 354
301 -  
302 -  
303 - 355 + def MovePlane(self):
  356 + pass
  357 +
  358 + def UpdatePlane(self, a, b):
  359 + 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())
  364 + self.plane_actor.VisibilityOn()
  365 +
  366 + self.plane.SetNormal(plane_source.GetNormal())
  367 + self.plane.SetOrigin(plane_source.GetOrigin())
  368 +
  369 + ps.Publisher().sendMessage('Render volume viewer', None)
  370 +