def initUI(self): self.planes = vtk.vtkPlanes() self.ren = vtk.vtkRenderer() self.vtkWidget.GetRenderWindow().AddRenderer(self.ren) self.vtkWidget.GetRenderWindow().GetInteractor().SetInteractorStyle( MainInteractorStyle()) self.iren = self.vtkWidget.GetRenderWindow().GetInteractor() self.drawPoint = [[0, 0, 0], [360, 0, 0]] self.loadFile(self._filePath) #================Draw CoordLine================ self.lineSource = vtk.vtkLineSource() self.targetPoint = vtk.vtkSphereSource() self.incidencePoint = vtk.vtkSphereSource() self.drawCoordLine() self.drawCoordPoint() self.initCutPlane() self.initCutSlider() self.initText() # self.initBoxWidget() pass
def AutoClip(self): # Check to see if ClipsIn is provided if self.ClipsIn == None: self.PrintError('Error: no AutoClip without ClipsIn') # Init AutoClipper/Function AutoClipper = vtk.vtkClipPolyData() AutoClipFunction = vtk.vtkPlanes() AutoClipper.SetInputData(self.Surface) AutoClipper.GenerateClippedOutputOn() AutoClipper.SetInsideOut(self.InsideOut) AutoClipper.SetClipFunction(AutoClipFunction) # Perform ClipFunction while ClipsIn is not empty while not self.ClipsIn.GetNumberOfBlocks() == 0: Bounds = self.NextBlockBounds() self.PrintLog('Bounds for AutoClip are: ' + str(Bounds)) AutoClipFunction.SetBounds(Bounds) AutoClipper.Update() self.Surface.DeepCopy(AutoClipper.GetOutput()) import pdb; pdb.set_trace() self.CleanAutoClip() self.PrintLog('AutoClip complete.')
def cut_with_planes(obj): #This function take a obj (vtk source) and cuts it with a plane defined by normal and point. num_cuts = 40 rad_tol = 0.5 point_min = obj.GetRadius() - rad_tol points = vtkPoints() normals = vtkDoubleArray() normals.SetNumberOfComponents(3) for i in range(num_cuts): normal = make_rand_vector() point = (point_min + np.random.rand(3) * rad_tol/2) * np.sign(normal) normals.InsertNextTuple(normal) points.InsertNextPoint(*point) #Create vtkPlanes object: planes = vtkPlanes() planes.SetPoints(points) planes.SetNormals(normals) #Create clipper object: clipper = vtkClipPolyData() clipper.SetInputConnection(obj.GetOutputPort()) clipper.SetClipFunction(planes) #Cut in the positive side of the plane: # clipper.SetValue(0) clipper.InsideOutOn() clipper.Update() #Returned as cut vtkPolyData: return clipper.GetOutput()
def __init__(self,viewer, selection_color): self.viewer = viewer self.selection_color = selection_color outline = vtk.vtkOutlineFilter() if vtk.vtkVersion.GetVTKMajorVersion()<6: outline.SetInput(self.viewer._polydata) else: outline.SetInputData(self.viewer._polydata) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) self.box=vtk.vtkActor() self.box.SetMapper( outlineMapper ) self.box.GetProperty().SetColor(1,1,1) self.box.PickableOff() self.SetProp3D(self.box) self.planes=vtk.vtkPlanes() self.SetInteractor(viewer.iren) if vtk.vtkVersion.GetVTKMajorVersion()<6: self.SetInput(self.viewer._polydata) else: self.SetInputData(self.viewer._polydata) self.SetPlaceFactor(1) self.PlaceWidget() self.InsideOutOn() self.SetRotationEnabled(0) self.GetPlanes(self.planes) self.AddObserver("EndInteractionEvent",self.on_select_atoms)
def voiWidgetInteractionCallback(self, o, e): planes = vtk.vtkPlanes() o.GetPlanes(planes) bounds = planes.GetPoints().GetBounds() # first set bounds self.controlFrame.voiBoundsText.SetValue( "(%.2f %.2f %.2f %.2f %.2f %.2f) mm" % bounds) input_data = self.getPrimaryInput() if input_data: ispacing = input_data.GetSpacing() iorigin = input_data.GetOrigin() # calculate discrete coords bounds = planes.GetPoints().GetBounds() voi = 6 * [0] # excuse the for loop :) for i in range(6): voi[i] = int( round((bounds[i] - iorigin[i / 2]) / ispacing[i / 2])) # store the VOI (this is a shallow copy) self._currentVOI = voi # display the discrete extent self.controlFrame.voiExtentText.SetValue("(%d %d %d %d %d %d)" % tuple(voi))
def voiWidgetInteractionCallback(self, o, e): planes = vtk.vtkPlanes() o.GetPlanes(planes) bounds = planes.GetPoints().GetBounds() # first set bounds self.controlFrame.voiBoundsText.SetValue( "(%.2f %.2f %.2f %.2f %.2f %.2f) mm" % bounds) input_data = self.getPrimaryInput() if input_data: ispacing = input_data.GetSpacing() iorigin = input_data.GetOrigin() # calculate discrete coords bounds = planes.GetPoints().GetBounds() voi = 6 * [0] # excuse the for loop :) for i in range(6): voi[i] = int(round((bounds[i] - iorigin[i / 2]) / ispacing[i / 2])) # store the VOI (this is a shallow copy) self._currentVOI = voi # display the discrete extent self.controlFrame.voiExtentText.SetValue( "(%d %d %d %d %d %d)" % tuple(voi))
def box_select_points(self, start_pos, end_pos): aspect = self.model_viewer.viewer.renderer.GetAspect() frustum_planes = np.zeros(24) self.model_viewer.viewer.renderer.GetActiveCamera().GetFrustumPlanes(aspect[0] / aspect[1], frustum_planes) min_pos = np.fmin(start_pos, end_pos) max_pos = np.fmax(start_pos, end_pos) + 1 # Shift frustum planes inwards to match the box selection y_world_size = 2.0 * self.model_viewer.viewer.renderer.GetActiveCamera().GetParallelScale() window_size = self.model_viewer.viewer.renderer.GetSize() pixel_to_world_scale = y_world_size / window_size[1] frustum_planes[3] -= pixel_to_world_scale * min_pos[0] frustum_planes[7] -= pixel_to_world_scale * (window_size[0] - max_pos[0]) frustum_planes[11] -= pixel_to_world_scale * min_pos[1] frustum_planes[15] -= pixel_to_world_scale * (window_size[1] - max_pos[1]) # For visualization, it's better to set near and far planes from depth of filtered data planes = vtk.vtkPlanes() planes.SetFrustumPlanes(frustum_planes) self.model_viewer.point_cloud_troupe.set_filtering_frustum(planes) filtered_ids = self.model_viewer.point_cloud_troupe.get_filtered_ids() if len(filtered_ids) > 0: dists = self.model_viewer.cached_points[filtered_ids, :].dot(frustum_planes[16:19]) min_dist = np.min(dists) max_dist = np.max(dists) range = max_dist - min_dist range = max(range, 0.01) frustum_planes[19] = -min_dist + 0.1 * range frustum_planes[23] = max_dist + 0.1 * range self.set_roibox(frustum_planes) else: self.reset_roibox() # Potential workaround for http://www.vtk.org/Bug/view.php?id=7823 # self.model_viewer.viewer.renderer.ResetCamera() self.model_viewer.change_mode(ViewModes.EDIT_BONES)
def main(): colors = vtk.vtkNamedColors() camera = vtk.vtkCamera() camera.SetClippingRange(0.1, 0.4) planesArray = [0] * 24 camera.GetFrustumPlanes(1.0, planesArray) planes = vtk.vtkPlanes() planes.SetFrustumPlanes(planesArray) frustumSource = vtk.vtkFrustumSource() frustumSource.ShowLinesOff() frustumSource.SetPlanes(planes) shrink = vtk.vtkShrinkPolyData() shrink.SetInputConnection(frustumSource.GetOutputPort()) shrink.SetShrinkFactor(.9) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(shrink.GetOutputPort()) back = vtk.vtkProperty() back.SetColor(colors.GetColor3d("Tomato")) actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().EdgeVisibilityOn() actor.GetProperty().SetColor(colors.GetColor3d("Banana")) actor.SetBackfaceProperty(back) # a renderer and render window renderer = vtk.vtkRenderer() renderWindow = vtk.vtkRenderWindow() renderWindow.SetWindowName("Frustum") renderWindow.AddRenderer(renderer) # an interactor renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # add the actors to the scene renderer.AddActor(actor) renderer.SetBackground(colors.GetColor3d("Silver")) # Position the camera so that we can see the frustum renderer.GetActiveCamera().SetPosition(1, 0, 0) renderer.GetActiveCamera().SetFocalPoint(0, 0, 0) renderer.GetActiveCamera().SetViewUp(0, 1, 0) renderer.GetActiveCamera().Azimuth(30) renderer.GetActiveCamera().Elevation(30) renderer.ResetCamera() # render an image (lights and cameras are created automatically) renderWindow.Render() # begin mouse interaction renderWindowInteractor.Start()
def Execute(self): if self.Surface == None: self.PrintError('Error: no Surface.') if self.WidgetType == "box": self.ClipFunction = vtk.vtkPlanes() elif self.WidgetType == "sphere": self.ClipFunction = vtk.vtkSphere() self.Clipper = vtk.vtkClipPolyData() self.Clipper.SetInput(self.Surface) self.Clipper.SetClipFunction(self.ClipFunction) self.Clipper.GenerateClippedOutputOn() self.Clipper.InsideOutOn() if not self.vmtkRenderer: self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 mapper = vtk.vtkPolyDataMapper() mapper.SetInput(self.Surface) mapper.ScalarVisibilityOff() self.Actor = vtk.vtkActor() self.Actor.SetMapper(mapper) self.vmtkRenderer.Renderer.AddActor(self.Actor) if self.WidgetType == "box": self.ClipWidget = vtk.vtkBoxWidget() self.ClipWidget.GetFaceProperty().SetColor(0.6,0.6,0.2) self.ClipWidget.GetFaceProperty().SetOpacity(0.25) elif self.WidgetType == "sphere": self.ClipWidget = vtk.vtkSphereWidget() self.ClipWidget.GetSphereProperty().SetColor(0.6,0.6,0.2) self.ClipWidget.GetSphereProperty().SetOpacity(0.25) self.ClipWidget.GetSelectedSphereProperty().SetColor(0.6,0.0,0.0) self.ClipWidget.GetSelectedSphereProperty().SetOpacity(0.75) self.ClipWidget.SetRepresentationToSurface() self.ClipWidget.SetPhiResolution(20) self.ClipWidget.SetThetaResolution(20) self.ClipWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor) self.Display() self.Transform = vtk.vtkTransform() self.ClipWidget.GetTransform(self.Transform) if self.OwnRenderer: self.vmtkRenderer.Deallocate() if self.CleanOutput == 1: cleaner = vtk.vtkCleanPolyData() cleaner.SetInput(self.Surface) cleaner.Update() self.Surface = cleaner.GetOutput() if self.Surface.GetSource(): self.Surface.GetSource().UnRegisterAllOutputs()
def SelectPolygons(self, widget, event_string): # As can be seen the callback takes two arguments. The first being the object that generates the event # and the second argument the event name (which is a string). self.planes = vtk.vtkPlanes() self.boxWidget.GetPlanes(self.planes) self.boundsPlane_presel = self.planes.GetPoints().GetBounds() return
def Execute(Surface, cl): if Surface == None: print 'Error: no Surface.' sys.exit(0) # Initialize Clipper = vtk.vtkClipPolyData() Clipper.SetInput(Surface) Clipper.GenerateClippedOutputOn() Clipper.SetInsideOut(0) ClipFunction = vtk.vtkPlanes() Clipper.SetClipFunction(ClipFunction) Cutter = vtk.vtkCutter() Cutter.SetInput(Surface) Cutter.SetCutFunction(ClipFunction) ClippedSurface = vtk.vtkPolyData() CutLines = vtk.vtkPolyData() ClipWidget = vtk.vtkBoxWidget() ClipWidget.GetFaceProperty().SetColor(0.6,0.6,0.2) ClipWidget.GetFaceProperty().SetOpacity(0.25) Transform = vtk.vtkTransform() ClipWidget.GetTransform(Transform) for i in range(cl.GetNumberOfLines()): # TODO: Implement thing here. # Clean surface cleaner = vtk.vtkCleanPolyData() cleaner.SetInput(Surface) cleaner.Update() Surface = cleaner.GetOutput() cleaner = vtk.vtkCleanPolyData() cleaner.SetInput(ClippedSurface) cleaner.Update() ClippedSurface = cleaner.GetOutput() cleaner = vtk.vtkCleanPolyData() cleaner.SetInput(CutLines) cleaner.Update() stripper = vtk.vtkStripper() stripper.SetInput(cleaner.GetOutput()) stripper.Update() CutLines = stripper.GetOutput() if Surface.GetSource(): Surface.GetSource().UnRegisterAllOutputs() if __name__=='__main__': surface = read_command_line() Execute()
def executeClip( self, caller=None, event=None ): planes = vtk.vtkPlanes(); np = 6 self.clipper.GetPlanes(planes) if not self.cropRegion: self.cropRegion = [0.0]*np for ip in range( np ): plane = planes.GetPlane( ip ) o = plane.GetOrigin() self.cropRegion[ip] = o[ ip/2 ] self.cropVolume()
def Execute(self): if (self.Surface == None): self.PrintError('Error: no Surface.') if self.WidgetType == "box": self.ClipFunction = vtk.vtkPlanes() elif self.WidgetType == "sphere": self.ClipFunction = vtk.vtkSphere() self.Clipper = vtk.vtkClipPolyData() self.Clipper.SetInput(self.Surface) self.Clipper.SetClipFunction(self.ClipFunction) self.Clipper.GenerateClippedOutputOn() self.Clipper.InsideOutOn() if not self.vmtkRenderer: self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 mapper = vtk.vtkPolyDataMapper() mapper.SetInput(self.Surface) mapper.ScalarVisibilityOff() self.Actor = vtk.vtkActor() self.Actor.SetMapper(mapper) self.vmtkRenderer.Renderer.AddActor(self.Actor) if self.WidgetType == "box": self.ClipWidget = vtk.vtkBoxWidget() self.ClipWidget.GetFaceProperty().SetColor(0.6, 0.6, 0.2) self.ClipWidget.GetFaceProperty().SetOpacity(0.25) elif self.WidgetType == "sphere": self.ClipWidget = vtk.vtkSphereWidget() self.ClipWidget.GetSphereProperty().SetColor(0.6, 0.6, 0.2) self.ClipWidget.GetSphereProperty().SetOpacity(0.25) self.ClipWidget.GetSelectedSphereProperty().SetColor(0.6, 0.0, 0.0) self.ClipWidget.GetSelectedSphereProperty().SetOpacity(0.75) self.ClipWidget.SetRepresentationToSurface() self.ClipWidget.SetPhiResolution(20) self.ClipWidget.SetThetaResolution(20) self.ClipWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor) self.Display() if self.OwnRenderer: self.vmtkRenderer.Deallocate() if self.CleanOutput == 1: cleaner = vtk.vtkCleanPolyData() cleaner.SetInput(self.Surface) cleaner.Update() self.Surface = cleaner.GetOutput() if self.Surface.GetSource(): self.Surface.GetSource().UnRegisterAllOutputs()
def createContent( self ): input = self.module.inputModule.getOutput() self.boxWidget = vtk.vtkBoxWidget() self.boxWidget.SetRotationEnabled(0) self.boxWidget.SetPlaceFactor(1.0) self.boxWidget.SetInput( input ) self.planes = vtk.vtkPlanes() self.boxWidget.AddObserver("StartInteractionEvent", self.startConfiguration ) self.boxWidget.AddObserver("InteractionEvent", self.updateConfiguration ) self.boxWidget.AddObserver("EndInteractionEvent", self.endConfiguration )
def __init__( self, parent, imode_callback, rmode_callback, ppos_callback, ao, **kwargs ): # initialize Panel if 'id' not in kwargs: kwargs['id'] = wx.ID_ANY wx.Panel.__init__( self, parent, **kwargs ) self.setInteractionMode = imode_callback self.setInteractionMode(True) self.recordingMode = False self.setRecordingMode = rmode_callback self.setRecordingMode(False) self.setPickerPos = ppos_callback self.ao = ao self.aa = False self.firstRender = True self.vtkWidget = wxVTKRenderWindowInteractor(self, wx.ID_ANY) self.iren = self.vtkWidget._Iren self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera()) self.renderer = vtk.vtkRenderer() self.renderer.SetBackground(0,0,0) self.imageLayer = {} self.CISID = -1 # Current Image Set ID self.imageLayer[self.CISID] = IBCRenderer(self.renderer, self.iren.Render) self.bacteriaLayer = BacteriaLayer(self.renderer, self.iren.Render) self.viewCamActive = True # for interactive clipping self.planes = vtk.vtkPlanes() self.ellipsoid = None self.ellipsoidTextActor = None # The SetInteractor method is how 3D widgets are associated with the # render window interactor. Internally, SetInteractor sets up a bunch # of callbacks using the Command/Observer mechanism (AddObserver()). self.boxWidget = vtk.vtkBoxWidget() self.boxWidget.SetInteractor(self.iren) self.boxWidget.SetPlaceFactor(1.0) # init vtk window self.vtkWidget.Enable(1) self.vtkWidget.AddObserver("ExitEvent", lambda o,e,f=parent: f.Close()) self.vtkWidget.GetRenderWindow().AddRenderer(self.renderer) # Bind VTK events self.iren.AddObserver("KeyPressEvent", self.OnKeyDown) self.Sizer = wx.BoxSizer() self.Sizer.Add(self.vtkWidget, 1, wx.EXPAND)
def _the_callback(box_widget, event_id): the_box = pyvista.PolyData() box_widget.GetPolyData(the_box) planes = vtk.vtkPlanes() box_widget.GetPlanes(planes) if hasattr(callback, '__call__'): if use_planes: try_callback(callback, planes) else: try_callback(callback, the_box) return
def set_region_of_interest(self, planes_vector): if planes_vector is None: self.planes_troupe.set_visible(False) if self.point_cloud_troupe is not None: self.point_cloud_troupe.set_filtering_frustum(None) else: planes = vtk.vtkPlanes() planes.SetFrustumPlanes(planes_vector) if self.point_cloud_troupe is not None: self.point_cloud_troupe.set_filtering_frustum(planes) self.planes_troupe.set_planes(planes) self.planes_troupe.set_visible(True)
def generate_actors(data, gradient_magnitude, iso_values, cmap, clip): # contour iso = vtk.vtkContourFilter() iso.SetInputConnection(data.GetOutputPort()) if (iso_values): [ iso.SetValue(index, value) for (index, value) in enumerate(iso_values) ] else: iso.SetValue(0, max / 4) #probe probe = vtk.vtkProbeFilter() probe.SetInputConnection(iso.GetOutputPort()) probe.SetSourceConnection(gradient_magnitude.GetOutputPort()) # generate vtkPlanes stuff. origins = generate_plane_origins(clip) normals = generate_plane_normals() # the list of planes planes = vtk.vtkPlanes() planes.SetPoints(origins) planes.SetNormals(normals) planes.GetPlane(0, xplane) planes.GetPlane(1, yplane) planes.GetPlane(2, zplane) xclipper = vtk.vtkClipPolyData() xclipper.SetInputConnection(probe.GetOutputPort()) xclipper.SetClipFunction(xplane) yclipper = vtk.vtkClipPolyData() yclipper.SetInputConnection(xclipper.GetOutputPort()) yclipper.SetClipFunction(yplane) zclipper = vtk.vtkClipPolyData() zclipper.SetInputConnection(yclipper.GetOutputPort()) zclipper.SetClipFunction(zplane) ctf = generate_ctf(cmap) clipMapper = vtk.vtkDataSetMapper() clipMapper.SetLookupTable(ctf) clipMapper.SetInputConnection(zclipper.GetOutputPort()) clipMapper.SetScalarRange(0, 255) # Generate iso surface actor from iso surface mapper. isoActor = vtk.vtkActor() isoActor.SetMapper(clipMapper) return [isoActor]
def resetClippingBox(self): """ Resets position and shape of the clipping box. """ # Reset the planes by setting identity transform transform = vtkTransform() self.clippingBox.SetTransform(transform) # Make sure the mapper is informed of the changes planes = vtkPlanes() self.clippingBox.GetPlanes(planes) self._updateMapperWithClippingPlanes(planes)
def __init__(self, data_dir, reader): tfun = vtk.vtkPiecewiseFunction() tfun.AddPoint(2440.0, 0.0) tfun.AddPoint(2800.0, 0.85) ctfun = vtk.vtkColorTransferFunction() ctfun.AddRGBPoint(0.0, 0.5, 0.0, 0.0) ctfun.AddRGBPoint(600.0, 1.0, 0.5, 0.5) ctfun.AddRGBPoint(1280.0, 0.9, 0.2, 0.3) ctfun.AddRGBPoint(1960.0, 0.81, 0.27, 0.1) ctfun.AddRGBPoint(4095.0, 0.5, 0.5, 0.5) volumeMapper = vtk.vtkGPUVolumeRayCastMapper() volumeMapper.SetInputConnection(reader.GetOutputPort()) volumeMapper.SetBlendModeToComposite() volumeProperty = vtk.vtkVolumeProperty() #volumeProperty.SetColor(ctfun) volumeProperty.SetScalarOpacity(tfun) volumeProperty.SetInterpolationTypeToLinear() #volumeProperty.ShadeOn() newvol = vtk.vtkVolume() newvol.SetMapper(volumeMapper) newvol.SetProperty(volumeProperty) # The SetInteractor method is how 3D widgets are associated with the # render window interactor. Internally, SetInteractor sets up a bunch # of callbacks using the Command/Observer mechanism (AddObserver()). boxWidget = vtk.vtkBoxWidget() #boxWidget.SetInteractor(iren) boxWidget.SetPlaceFactor(1.0) # The implicit function vtkPlanes is used in conjunction with the # volume ray cast mapper to limit which portion of the volume is # volume rendered. planes = vtk.vtkPlanes() self.planes = planes def ClipVolumeRender(obj, event): #global self.planes, volumeMapper obj.GetPlanes(self.planes) volumeMapper.SetClippingPlanes(self.planes) # Place the interactor initially. The output of the reader is used to # place the box widget. boxWidget.SetInputConnection(reader.GetOutputPort()) boxWidget.PlaceWidget() boxWidget.InsideOutOn() boxWidget.AddObserver("InteractionEvent", ClipVolumeRender) self.boxWidget = boxWidget
def clipVTKDataWithBox(vtkData, bounds): planes = vtk.vtkPlanes() planes.SetBounds(bounds) clipper = vtk.vtkClipPolyData() if vtk.VTK_MAJOR_VERSION <= 5: clipper.SetInput(vtkData) else: clipper.SetInputData(vtkData) clipper.SetClipFunction(planes) clipper.SetValue(0.0) clipper.InsideOutOn() clipper.Update() vtkDataClipped = clipper.GetOutput() return vtkDataClipped
def __init__(self, actorlist, volumelist): self.render = vtk.vtkRenderer() self.renWindow = vtk.vtkRenderWindow() self.renWindow.AddRenderer(self.render) self.interactor = vtk.vtkRenderWindowInteractor() self.interactor.SetRenderWindow(self.renWindow) self.actorstoadd = actorlist self.volumestoadd = volumelist self.t = vtk.vtkTransform() self.box = vtk.vtkBoxWidget() self.planes = vtk.vtkPlanes() self.clipper = vtk.vtkClipPolyData() self.selectMapper = vtk.vtkPolyDataMapper() self.selectActor = vtk.vtkLODActor()
def _the_callback(box_widget, event_id): the_box = pyvista.PolyData() box_widget.GetPolyData(the_box) planes = vtk.vtkPlanes() box_widget.GetPlanes(planes) if hasattr(callback, '__call__'): if use_planes: args = [planes] else: args = [the_box] if pass_widget: args.append(box_widget) try_callback(callback, *args) return
def clipVolumeRender(self, obj, evt, *args): """ clip the module based on the given clipping planes """ modules = self.getModulesToClip() planes = vtk.vtkPlanes() obj.GetPlanes(planes) for mapper in self.clippedMappers: mapper.RemoveAllClippingPlanes() self.clippedMappers = [] for module in modules: if hasattr(module, "mapper") and hasattr(module.mapper, "SetClippingPlanes"): module.mapper.SetClippingPlanes(planes) self.clippedMappers.append(module.mapper)
def generate_actors(data, val, clip): # contour global iso iso.SetInputConnection(data.GetOutputPort()) if (val): iso.SetValue(0, val) else: iso.SetValue(0, max / 4) ctf = vtk.vtkColorTransferFunction() ctf.AddRGBPoint(min, 31 / 255, 162 / 255, 255 / 255) ctf.AddRGBPoint(max, 255 / 255, 251 / 255, 19 / 255) # generate vtkPlanes stuff. origins = generate_plane_origins(clip) normals = generate_plane_normals() # the list of planes planes = vtk.vtkPlanes() planes.SetPoints(origins) planes.SetNormals(normals) planes.GetPlane(0, xplane) planes.GetPlane(1, yplane) planes.GetPlane(2, zplane) xclipper = vtk.vtkClipPolyData() xclipper.SetInputConnection(iso.GetOutputPort()) xclipper.SetClipFunction(xplane) yclipper = vtk.vtkClipPolyData() yclipper.SetInputConnection(xclipper.GetOutputPort()) yclipper.SetClipFunction(yplane) zclipper = vtk.vtkClipPolyData() zclipper.SetInputConnection(yclipper.GetOutputPort()) zclipper.SetClipFunction(zplane) clipMapper = vtk.vtkDataSetMapper() clipMapper.SetLookupTable(ctf) clipMapper.SetInputConnection(zclipper.GetOutputPort()) clipMapper.SetScalarRange(0, 255) # Generate iso surface actor from iso surface mapper. isoActor = vtk.vtkActor() isoActor.SetMapper(clipMapper) return [isoActor]
def picker_callback(self,obj,event): extract = vtk.vtkExtractSelectedFrustum() fPlanes=obj.GetFrustum() #collection of planes based on unscaled display #scale frustum to account for the zaspect scaledPlanes=vtk.vtkPlanes() scaledNormals=vtk.vtkDoubleArray() scaledNormals.SetNumberOfComponents(3) scaledNormals.SetNumberOfTuples(6) scaledOrigins=vtk.vtkPoints() for j in range(6): i=fPlanes.GetPlane(j) k=i.GetOrigin() q=i.GetNormal() scaledOrigins.InsertNextPoint(k[0],k[1],k[2]/float(self.Zaspect)) scaledNormals.SetTuple(j,(q[0],q[1],q[2]*float(self.Zaspect))) scaledPlanes.SetNormals(scaledNormals) scaledPlanes.SetPoints(scaledOrigins) extract.SetFrustum(scaledPlanes) extract.SetInputData(self.vtkPntsPolyData) extract.Update() extracted = extract.GetOutput() ids = vtk.vtkIdTypeArray() ids = extracted.GetPointData().GetArray("vtkOriginalPointIds") if ids: #store them in an array for an undo operation self.lastSelectedIds=ids for i in range(ids.GetNumberOfTuples()): #turn them red self.colors.SetTuple(ids.GetValue(i),(255,0,0)) self.bool_pnt[ids.GetValue(i)]=False self.vtkPntsPolyData.GetPointData().SetScalars(self.colors) self.vtkPntsPolyData.Modified() self.ui.vtkWidget.update() #set flag on ui to show that data has been modified self.unsaved_changes=True
def __init__(self): VTKPythonAlgorithmBase.__init__(self, nInputPorts=1, inputType='vtkUnstructuredGrid', nOutputPorts=1, outputType='vtkUnstructuredGrid') self.append_filter = vtk.vtkAppendFilter() self.append_filter.ReleaseDataFlagOn() self.triangle_filter = vtk.vtkTriangleFilter() self.planes = vtk.vtkPlanes() self.ex = vtk.vtkExtractSelectedFrustum() self.ex.ReleaseDataFlagOn() self.poly_pick_data = None self.renderer = None
def __init__(self, renwin, volume): self.renwin = renwin self.iren = renwin.GetInteractor() self.mapper = volume.GetMapper() self.volume = volume self.SetProp3D(volume) self.GetOutlineProperty().SetColor(0, 0, 0) self.planes = vtk.vtkPlanes() self.SetInteractor(self.iren) self.SetPlaceFactor(1) self.PlaceWidget() self.InsideOutOn() self.SetRotationEnabled(0) self.GetPlanes(self.planes) self.AddObserver("EndInteractionEvent", self.SelectPolygons) self.inorout = 1 self.show() self.SelectPolygons()
def Execute(self): if (self.Mesh == None): self.PrintError('Error: no Mesh.') self.Planes = vtk.vtkPlanes() self.Clipper = vtk.vtkClipDataSet() self.Clipper.SetInput(self.Mesh) self.Clipper.SetClipFunction(self.Planes) self.Clipper.GenerateClippedOutputOn() self.Clipper.InsideOutOn() if not self.vmtkRenderer: self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 self.vmtkRenderer.RegisterScript(self) mapper = vtk.vtkDataSetMapper() mapper.SetInput(self.Mesh) mapper.ScalarVisibilityOff() self.Actor = vtk.vtkActor() self.Actor.SetMapper(mapper) self.vmtkRenderer.Renderer.AddActor(self.Actor) self.BoxWidget = vtk.vtkBoxWidget() self.BoxWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor) self.BoxWidget.GetFaceProperty().SetColor(0.6, 0.6, 0.2) self.BoxWidget.GetFaceProperty().SetOpacity(0.25) self.vmtkRenderer.AddKeyBinding('i', 'Interact.', self.InteractCallback) self.vmtkRenderer.AddKeyBinding('space', 'Clip.', self.ClipCallback) self.Display() if self.OwnRenderer: self.vmtkRenderer.Deallocate() if self.Mesh.GetSource(): self.Mesh.GetSource().UnRegisterAllOutputs()
def Execute(self): if (self.Mesh == None): self.PrintError('Error: no Mesh.') self.Planes = vtk.vtkPlanes() self.Clipper = vtk.vtkClipDataSet() self.Clipper.SetInput(self.Mesh) self.Clipper.SetClipFunction(self.Planes) self.Clipper.GenerateClippedOutputOn() self.Clipper.InsideOutOn() if not self.vmtkRenderer: self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 self.vmtkRenderer.RegisterScript(self) mapper = vtk.vtkDataSetMapper() mapper.SetInput(self.Mesh) mapper.ScalarVisibilityOff() self.Actor = vtk.vtkActor() self.Actor.SetMapper(mapper) self.vmtkRenderer.Renderer.AddActor(self.Actor) self.BoxWidget = vtk.vtkBoxWidget() self.BoxWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor) self.BoxWidget.GetFaceProperty().SetColor(0.6,0.6,0.2) self.BoxWidget.GetFaceProperty().SetOpacity(0.25) self.vmtkRenderer.AddKeyBinding('i','Interact.', self.InteractCallback) self.vmtkRenderer.AddKeyBinding('space','Clip.', self.ClipCallback) self.Display() if self.OwnRenderer: self.vmtkRenderer.Deallocate() if self.Mesh.GetSource(): self.Mesh.GetSource().UnRegisterAllOutputs()
def __init__(self,gfx,iso,cropentry,entryval): self.gfx = gfx self.entry = cropentry self.entryval = entryval self.crpfn=None self.SetProp3D(gfx.map[0].box) self.planes=vtk.vtkPlanes() self.SetInteractor(gfx.iren) self.SetInput(gfx.map[0].iso.GetOutput()) self.SetPlaceFactor(1) self.PlaceWidget() self.InsideOutOn() self.SetRotationEnabled(0) self.GetPlanes(self.planes) self.AddObserver("EndInteractionEvent",self.SelectPolygons) self.AddObserver("InteractionEvent",self.Update_crop_bounds) self.inorout=1 self.init_entrys() (xmin,xmax,ymin,ymax,zmin,zmax)=self.gfx.map[0].box.GetBounds() spcing=self.gfx.map[0].reader.GetOutput().GetSpacing() self.old=(nint(xmin/spcing[0]),nint(xmax/spcing[0]),nint(ymin/spcing[1]),nint(ymax/spcing[1]),nint(zmin/spcing[2]),nint(zmax/spcing[2]))
def OnBox(self, event): boxWidget = vtk.vtkBoxWidget() # change handle properties boxWidget.SetHandleSize(0.005) # default is 0.01 boxWidget.SetInteractor(self.widget) boxWidget.SetPlaceFactor(1.25) boxWidget.SetInput(self.normals.GetOutput()) boxWidget.PlaceWidget() boxCallback = self.BoxSelectPolygons() boxWidget.AddObserver("EndInteractionEvent", boxCallback) boxWidget.KeyPressActivationOff() plane = vtk.vtkPlanes() self.boxes.append(boxWidget) self.planes[boxWidget.GetAddressAsString('')] = plane self.region.AddFunction(plane) newId = self.GateMenu.AppendCheckItem(-1, "Box #" + str(self.boxCount)) self.boxCount = self.boxCount + 1 self.boxIds[newId.GetId()] = boxWidget.GetAddressAsString('') newId.Check(True) self.Bind(wx.EVT_MENU, self.OnBoxSelect, newId) boxWidget.On()
def box_select_points(self, start_pos, end_pos): aspect = self.model_viewer.viewer.renderer.GetAspect() frustum_planes = np.zeros(24) self.model_viewer.viewer.renderer.GetActiveCamera().GetFrustumPlanes( aspect[0] / aspect[1], frustum_planes) min_pos = np.fmin(start_pos, end_pos) max_pos = np.fmax(start_pos, end_pos) + 1 # Shift frustum planes inwards to match the box selection y_world_size = 2.0 * self.model_viewer.viewer.renderer.GetActiveCamera( ).GetParallelScale() window_size = self.model_viewer.viewer.renderer.GetSize() pixel_to_world_scale = y_world_size / window_size[1] frustum_planes[3] -= pixel_to_world_scale * min_pos[0] frustum_planes[7] -= pixel_to_world_scale * (window_size[0] - max_pos[0]) frustum_planes[11] -= pixel_to_world_scale * min_pos[1] frustum_planes[15] -= pixel_to_world_scale * (window_size[1] - max_pos[1]) # For visualization, it's better to set near and far planes from depth of filtered data planes = vtk.vtkPlanes() planes.SetFrustumPlanes(frustum_planes) self.model_viewer.point_cloud_troupe.set_filtering_frustum(planes) filtered_ids = self.model_viewer.point_cloud_troupe.get_filtered_ids() if len(filtered_ids) > 0: dists = self.model_viewer.cached_points[filtered_ids, :].dot( frustum_planes[16:19]) min_dist = np.min(dists) max_dist = np.max(dists) range = max_dist - min_dist range = max(range, 0.01) frustum_planes[19] = -min_dist + 0.1 * range frustum_planes[23] = max_dist + 0.1 * range self.set_roibox(frustum_planes) else: self.reset_roibox() # Potential workaround for http://www.vtk.org/Bug/view.php?id=7823 # self.model_viewer.viewer.renderer.ResetCamera() self.model_viewer.change_mode(ViewModes.EDIT_BONES)
def _addVolumeCutterTool(vol): vp = settings.plotter_instance if not vp.renderer: save_int = vp.interactive vp.show(interactive=0) vp.interactive = save_int boxWidget = vtk.vtkBoxWidget() boxWidget.SetInteractor(vp.interactor) boxWidget.SetPlaceFactor(1.0) vp.cutterWidget = boxWidget planes = vtk.vtkPlanes() def ClipVolumeRender(obj, event): obj.GetPlanes(planes) vol.mapper.SetClippingPlanes(planes) boxWidget.SetInputData(vol.image) boxWidget.OutlineCursorWiresOn() boxWidget.GetSelectedOutlineProperty().SetColor(1, 0, 1) boxWidget.GetOutlineProperty().SetColor(0.1, 0.1, 0.1) boxWidget.GetOutlineProperty().SetOpacity(0.7) boxWidget.SetPlaceFactor(1.05) boxWidget.PlaceWidget() boxWidget.InsideOutOn() boxWidget.AddObserver("InteractionEvent", ClipVolumeRender) colors.printc("Mesh Cutter Tool:", c="m", invert=1) colors.printc(" Move gray handles to cut away parts of the mesh", c="m") colors.printc(" Press X to save file to: clipped.vtk", c="m") vp.renderer.ResetCamera() boxWidget.On() vp.interactor.Start() boxWidget.Off() vp.widgets.append(boxWidget)
def runGeoJSONCropExample(input_filename, bbox_filename): inputDataset = loadGeoJSONData(input_filename) bboxDataset = loadGeoJSONData(bbox_filename) # Use the bounds from the bounding box to create an implicit function queryBounds = list(bboxDataset.GetBounds()) bbox = vtk.vtkPlanes() bbox.SetBounds(queryBounds) # This filter uses the implicit function to extract the data bboxFilter = vtk.vtkExtractPolyDataGeometry() bboxFilter.SetInputData(inputDataset) bboxFilter.SetImplicitFunction(bbox) # Exclude (set to 0) or include (set to 1) districts on the boundary bboxFilter.SetExtractBoundaryCells(0) # Get the cropped region and write it to disk bboxFilter.Update() croppedDataset = bboxFilter.GetOutput() outputWriter = vtk.vtkGeoJSONWriter() outputWriter.SetFileName('cropped_output.geojson') outputWriter.SetInputData(croppedDataset) outputWriter.Write() renderer = init() inputActor = renderPolyData(renderer, inputDataset) bboxActor = renderPolyData(renderer, bboxDataset) cropActor = renderPolyData(renderer, croppedDataset) # Set rendering type and color on the actors inputActor.GetProperty().SetRepresentationToWireframe() inputActor.GetProperty().SetColor(0.0, 1.0, 0.0) bboxActor.GetProperty().SetRepresentationToWireframe() bboxActor.GetProperty().SetColor(1.0, 0.0, 0.0) cropActor.GetProperty().SetRepresentationToWireframe() cropActor.GetProperty().SetColor(1.0, 0.0, 1.0) run()
def create_frustum(aspect_ratio, fovy, scale, R, t): camera = vtk.vtkCamera() camera.SetViewAngle(fovy) print(t.item(0), t.item(1), t.item(2)) camera.SetPosition(t.item(0), t.item(1), t.item(2)) camera.SetViewUp(R[0][0], R[1][0], R[2][0]) camera.SetFocalPoint(0.0, 0.0, 1.0) camera.SetClippingRange(1e-9, scale) planes_array = [0] * 24 camera.GetFrustumPlanes(aspect_ratio, planes_array) planes = vtk.vtkPlanes() planes.SetFrustumPlanes(planes_array) frustumSource = vtk.vtkFrustumSource() frustumSource.SetPlanes(planes) extract_edges = vtk.vtkExtractEdges() extract_edges.SetInputConnection(frustumSource.GetOutputPort()) extract_edges.Update() return extract_edges.GetOutput()
def __init__(self, gfx, iso, cropentry, entryval): self.gfx = gfx self.entry = cropentry self.entryval = entryval self.crpfn = None self.SetProp3D(gfx.map[0].box) self.planes = vtk.vtkPlanes() self.SetInteractor(gfx.iren) self.SetInput(gfx.map[0].iso.GetOutput()) self.SetPlaceFactor(1) self.PlaceWidget() self.InsideOutOn() self.SetRotationEnabled(0) self.GetPlanes(self.planes) self.AddObserver("EndInteractionEvent", self.SelectPolygons) self.AddObserver("InteractionEvent", self.Update_crop_bounds) self.inorout = 1 self.init_entrys() (xmin, xmax, ymin, ymax, zmin, zmax) = self.gfx.map[0].box.GetBounds() spcing = self.gfx.map[0].reader.GetOutput().GetSpacing() self.old = (nint(xmin / spcing[0]), nint(xmax / spcing[0]), nint(ymin / spcing[1]), nint(ymax / spcing[1]), nint(zmin / spcing[2]), nint(zmax / spcing[2]))
def clip(self, plane): """Clip the surface against the supplied plane, using a vtkClipPolyData filter.""" if self.Clipper is None: self.Clipper = vtk.vtkClipPolyData() self.Clipper.SetInput(self.Clipped) pass # Get the axis-aligned cuboid bounding the surface bounds = self.Surface.GetBounds() # (xmin,xmax, ymin,ymax, zmin,zmax) planes = vtk.vtkPlanes() planes.SetBounds(*bounds) # Iterate over BB, find plane with closest normal, replace # with our plane. maxDot = -1 maxI = -1 for i in range(planes.GetNumberOfPlanes()): bound = planes.GetPlane(i) dot = normalDot(plane, bound) if dot > maxDot: maxDot = dot maxI = i pass continue planes.GetNormals().SetTuple3(maxI, *plane.GetNormal()) planes.GetPoints().SetPoint(maxI, *plane.GetOrigin()) self.Clipper.SetClipFunction(planes) self.Clipper.GenerateClippedOutputOn() self.Clipper.InsideOutOn() self.Clipper.Update() self.Clipped.DeepCopy(self.Clipper.GetClippedOutput()) self.Clipped.Update() return
def __init__(self, parent = None): super(VTKFrame, self).__init__(parent) self.vtkWidget = QVTKRenderWindowInteractor(self) vl = QtGui.QVBoxLayout(self) vl.addWidget(self.vtkWidget) vl.setContentsMargins(0, 0, 0, 0) self.ren = vtk.vtkRenderer() self.ren.SetBackground(0.1, 0.2, 0.4) self.vtkWidget.GetRenderWindow().AddRenderer(self.ren) self.iren = self.vtkWidget.GetRenderWindow().GetInteractor() # Create source camera = vtk.vtkCamera() planesArray = [0]*24 camera.GetFrustumPlanes(2, planesArray) planes = vtk.vtkPlanes() planes.SetFrustumPlanes(planesArray) frustumSource = vtk.vtkFrustumSource() frustumSource.SetPlanes(planes) frustumSource.Update() frustum = frustumSource.GetOutput() mapper = vtk.vtkPolyDataMapper() mapper.SetInput(frustum) actor = vtk.vtkActor() actor.SetMapper(mapper) self.ren.AddActor(actor) self.ren.ResetCamera() self._initialized = False
def clip(self, plane): """Clip the surface against the supplied plane, using a vtkClipPolyData filter.""" if self.Clipper is None: self.Clipper = vtk.vtkClipPolyData() self.Clipper.SetInput(self.Clipped) pass # Get the axis-aligned cuboid bounding the surface bounds = self.Surface.GetBounds() # (xmin,xmax, ymin,ymax, zmin,zmax) planes = vtk.vtkPlanes() planes.SetBounds(*bounds) # Iterate over BB, find plane with closest normal, replace # with our plane. maxDot = -1; maxI = -1 for i in range(planes.GetNumberOfPlanes()): bound = planes.GetPlane(i) dot = normalDot(plane, bound) if dot> maxDot: maxDot = dot maxI = i pass continue planes.GetNormals().SetTuple3(maxI, *plane.GetNormal()) planes.GetPoints().SetPoint(maxI, *plane.GetOrigin()) self.Clipper.SetClipFunction(planes) self.Clipper.GenerateClippedOutputOn() self.Clipper.InsideOutOn() self.Clipper.Update() self.Clipped.DeepCopy(self.Clipper.GetClippedOutput()) self.Clipped.Update() return
def buildPipeline(self): """ execute() -> None Dispatch the vtkRenderer to the actual rendering widget """ texture_ispec = self.getInputSpec( 1 ) xMin, xMax, yMin, yMax, zMin, zMax = self.input().GetWholeExtent() self.sliceCenter = [ (xMax-xMin)/2, (yMax-yMin)/2, (zMax-zMin)/2 ] spacing = self.input().GetSpacing() sx, sy, sz = spacing # self.input().SetSpacing( sx, sy, 5*sz ) origin = self.input().GetOrigin() ox, oy, oz = origin dataType = self.input().GetScalarTypeAsString() self.setMaxScalarValue( self.input().GetScalarType() ) self.colorByMappedScalars = False rangeBounds = self.getRangeBounds() dr = rangeBounds[1] - rangeBounds[0] range_offset = .2*dr self.range = [ rangeBounds[0] + range_offset, rangeBounds[1] - range_offset ] print "Data Type = %s, range = (%f,%f), range bounds = (%f,%f), max_scalar = %s" % ( dataType, self.range[0], self.range[1], rangeBounds[0], rangeBounds[1], self._max_scalar_value ) self.probeFilter = None textureRange = self.range if texture_ispec and texture_ispec.input(): self.probeFilter = vtk.vtkProbeFilter() textureRange = texture_ispec.input().GetScalarRange() self.probeFilter.SetSource( texture_ispec.input() ) self.generateTexture = True if (self.surfacePicker == None): self.surfacePicker = vtk.vtkPointPicker() self.levelSetFilter = vtk.vtkContourFilter() self.inputModule().inputToAlgorithm( self.levelSetFilter ) self.clipPlanes = vtk.vtkPlanes() self.polyClipper = vtk.vtkClipPolyData() self.polyClipper.SetInputConnection( self.levelSetFilter.GetOutputPort() ) self.polyClipper.SetClipFunction( self.clipPlanes ) self.polyClipper.InsideOutOn() self.levelSetMapper = vtk.vtkPolyDataMapper() self.levelSetMapper.SetColorModeToMapScalars() if ( self.probeFilter == None ): imageRange = self.getImageValues( self.range ) self.levelSetMapper.SetInputConnection( self.polyClipper.GetOutputPort() ) self.levelSetMapper.SetScalarRange( imageRange[0], imageRange[1] ) else: self.probeFilter.SetInputConnection( self.polyClipper.GetOutputPort() ) self.levelSetMapper.SetInputConnection( self.probeFilter.GetOutputPort() ) self.levelSetMapper.SetScalarRange( textureRange ) colormapManager = self.getColormapManager( index=1 ) if texture_ispec and texture_ispec.input() else self.getColormapManager() colormapManager.setAlphaRange ( self.opacityRange ) self.levelSetMapper.SetLookupTable( colormapManager.lut ) self.levelSetMapper.UseLookupTableScalarRangeOn() self.updateLevels() # levelSetMapper.SetColorModeToMapScalars() # levelSetActor = vtk.vtkLODActor() self.levelSetActor = vtk.vtkLODActor() # levelSetMapper.ScalarVisibilityOff() # levelSetActor.SetProperty( self.levelSetProperty ) self.levelSetActor.SetMapper( self.levelSetMapper ) self.cursorActor = vtk.vtkActor() self.cursorProperty = None self.cursor = vtk.vtkSphereSource() self.cursor.SetRadius(2.0) self.cursor.SetThetaResolution(8) self.cursor.SetPhiResolution(8) self.clipper = vtk.vtkBoxWidget() self.clipper.RotationEnabledOff() self.clipper.SetPlaceFactor( 1.0 ) self.clipper.AddObserver( 'StartInteractionEvent', self.startClip ) self.clipper.AddObserver( 'EndInteractionEvent', self.executeClip ) mapper = vtk.vtkPolyDataMapper() mapper.SetInput(self.cursor.GetOutput()) self.cursorActor.SetMapper(mapper) self.createDefaultProperties() # pointData = self.levelSetFilter.GetOutput().GetPointData() # pointData.SetScalars( colorLevelData ) # if pd <> None: # na = pd.GetNumberOfArrays() # print " ** Dataset has %d arrays. ** " % ( pd.GetNumberOfArrays() ) # for i in range( na ): print " --- Array %d: %s " % ( i, str( pd.GetArrayName(i) ) ) # else: print " ** No point data. " self.renderer.AddActor( self.levelSetActor ) self.surfacePicker.AddPickList( self.levelSetActor ) self.surfacePicker.PickFromListOn() self.renderer.AddViewProp(self.cursorActor) self.cursorActor.SetProperty(self.cursorProperty) self.renderer.SetBackground( VTK_BACKGROUND_COLOR[0], VTK_BACKGROUND_COLOR[1], VTK_BACKGROUND_COLOR[2] ) self.set3DOutput()
def Execute(self): if self.Mesh == None: self.PrintError("Error: no Mesh.") self.Clipper = vtk.vtkClipDataSet() self.Clipper.SetInput(self.Mesh) self.Clipper.GenerateClippedOutputOn() self.Clipper.SetInsideOut(self.InsideOut) if self.Interactive: self.Planes = vtk.vtkPlanes() self.Clipper.SetClipFunction(self.Planes) self.Cutter = vtk.vtkCutter() self.Cutter.SetInput(self.Mesh) self.Cutter.SetCutFunction(self.Planes) self.ClippedMesh = vtk.vtkUnstructuredGrid() self.Surface = vtk.vtkPolyData() if not self.vmtkRenderer: self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 self.vmtkRenderer.RegisterScript(self) mapper = vtk.vtkDataSetMapper() mapper.SetInput(self.Mesh) mapper.ScalarVisibilityOff() self.Actor = vtk.vtkActor() self.Actor.SetMapper(mapper) self.vmtkRenderer.Renderer.AddActor(self.Actor) self.BoxWidget = vtk.vtkBoxWidget() self.BoxWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor) self.BoxWidget.GetFaceProperty().SetColor(0.6, 0.6, 0.2) self.BoxWidget.GetFaceProperty().SetOpacity(0.25) self.vmtkRenderer.AddKeyBinding("i", "Interact.", self.InteractCallback) self.vmtkRenderer.AddKeyBinding("space", "Clip.", self.ClipCallback) self.Display() if self.OwnRenderer: self.vmtkRenderer.Deallocate() else: self.Mesh.GetPointData().SetActiveScalars(self.ClipArrayName) self.Clipper.GenerateClipScalarsOff() self.Clipper.SetValue(self.ClipValue) self.Clipper.Update() self.Cutter = vtk.vtkContourFilter() self.Cutter.SetInput(self.Mesh) self.Cutter.SetValue(0, self.ClipValue) self.Cutter.Update() self.Mesh = self.Clipper.GetOutput() self.Surface = self.Cutter.GetOutput() self.ClippedMesh = self.Clipper.GetClippedOutput() if self.Mesh.GetSource(): self.Mesh.GetSource().UnRegisterAllOutputs()
def transformCallback(self, arg1, arg2): planes = vtkPlanes() arg1.GetPlanes(planes) self._updateMapperWithClippingPlanes(planes)
color as doubles. ''' rgb = [0.0, 0.0, 0.0] # black vtk.vtkNamedColors().GetColorRGB(colorName, rgb) return rgb # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # create cutting planes planes = vtk.vtkPlanes() points = vtk.vtkPoints() norms = vtk.vtkFloatArray() norms.SetNumberOfComponents(3) points.InsertPoint(0, 0.0, 0.0, 0.0) norms.InsertTuple3(0, 0.0, 0.0, 1.0) points.InsertPoint(1, 0.0, 0.0, 0.0) norms.InsertTuple3(1, -1.0, 0.0, 0.0) planes.SetPoints(points) planes.SetNormals(norms) # texture texReader = vtk.vtkStructuredPointsReader() texReader.SetFileName(VTK_DATA_ROOT + "/Data/texThres2.vtk") texture = vtk.vtkTexture()
def _updateImagePlanePlacement(self): if not self._clippingPlanesState: return # First get the planes of the clipping box planes = vtkPlanes() self.clippingBox.GetPlanes(planes) # Also get the polydata of the box polyData = vtkPolyData() self.clippingBox.GetPolyData(polyData) # Append a 4th element to the polydata points p = [] for i in range(8): p.append(list(polyData.GetPoint(i)) + [1.0]) # Transform all the polydata points inv = self.transform.GetInverse() for i in range(len(p)): inv.MultiplyPoint(p[i], p[i]) p[i] = p[i][0:3] # Calculate the center of the planes # so that it is possible to figure out where # to place the image planes center = [0, 0, 0] for point in p: center[0] += point[0] center[1] += point[1] center[2] += point[2] center[0] /= len(p) center[1] /= len(p) center[2] /= len(p) # Place the image plane just outside the clipping box for i in range(len(p)): point = p[i] for j in range(3): dist = point[j] - center[j] p[i][j] += (dist / 30.0) # Update the position of all the planes self.planes[0].SetOrigin(p[0]) self.planes[0].SetPoint1(p[4]) self.planes[0].SetPoint2(p[3]) self.planes[1].SetOrigin(p[3]) self.planes[1].SetPoint1(p[7]) self.planes[1].SetPoint2(p[2]) self.planes[2].SetOrigin(p[2]) self.planes[2].SetPoint1(p[6]) self.planes[2].SetPoint2(p[1]) self.planes[3].SetOrigin(p[1]) self.planes[3].SetPoint1(p[5]) self.planes[3].SetPoint2(p[0]) self.planes[4].SetOrigin(p[0]) self.planes[4].SetPoint2(p[3]) self.planes[4].SetPoint1(p[1]) self.planes[5].SetOrigin(p[4]) self.planes[5].SetPoint1(p[7]) self.planes[5].SetPoint2(p[5]) for plane in self.planes: plane.UpdatePlacement()
def __init__(self, parent, data_set): wxVTKRenderWindowInteractor.__init__(self, parent, -1, size=parent.GetSize()) ren = vtk.vtkRenderer() self.GetRenderWindow().AddRenderer(ren) # prob should allow a string as data_set also, but for now assume it's a python or numpy array #img = self.LoadVolumeData(data_set) # load from filename img = vtkImageImportFromArray() img.SetArray(data_set) pix_diag = 5.0 # volMapper = vtk.vtkVolumeTextureMapper3D() volMapper = vtk.vtkVolumeRayCastMapper() compositeFunction = vtk.vtkVolumeRayCastCompositeFunction() compositeFunction.SetCompositeMethodToInterpolateFirst() volMapper.SetVolumeRayCastFunction(compositeFunction) volMapper.SetSampleDistance(pix_diag / 5.0) volMapper.SetInputConnection(img.GetOutputPort()) # Transfer Functions self.opacity_tf = vtk.vtkPiecewiseFunction() self.color_tf = vtk.vtkColorTransferFunction() # The property describes how the data will look self.volProperty = volProperty = vtk.vtkVolumeProperty() volProperty.SetColor(self.color_tf) volProperty.SetScalarOpacity(self.opacity_tf) volProperty.ShadeOn() volProperty.SetInterpolationTypeToLinear() volProperty.SetScalarOpacityUnitDistance(pix_diag) vol = vtk.vtkVolume() vol.SetMapper(volMapper) vol.SetProperty(volProperty) ren.AddVolume(vol) boxWidget = vtk.vtkBoxWidget() boxWidget.SetInteractor(self) boxWidget.SetPlaceFactor(1.0) # The implicit function vtkPlanes is used in conjunction with the # volume ray cast mapper to limit which portion of the volume is # volume rendered. planes = vtk.vtkPlanes() def ClipVolumeRender(obj, event): obj.GetPlanes(planes) volMapper.SetClippingPlanes(planes) # Place the interactor initially. The output of the reader is used to # place the box widget. boxWidget.SetInput(img.GetOutput()) boxWidget.PlaceWidget() boxWidget.InsideOutOn() boxWidget.AddObserver("InteractionEvent", ClipVolumeRender) outline = vtk.vtkOutlineFilter() outline.SetInputConnection(img.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineProperty = boxWidget.GetOutlineProperty() outlineProperty.SetRepresentationToWireframe() outlineProperty.SetAmbient(1.0) outlineProperty.SetAmbientColor(1, 1, 1) outlineProperty.SetLineWidth(3) selectedOutlineProperty = boxWidget.GetSelectedOutlineProperty() selectedOutlineProperty.SetRepresentationToWireframe() selectedOutlineProperty.SetAmbient(1.0) selectedOutlineProperty.SetAmbientColor(1, 0, 0) selectedOutlineProperty.SetLineWidth(3) ren.AddActor(outlineActor) style = vtk.vtkInteractorStyleTrackballCamera() self.SetInteractorStyle(style) self.t_graph = TransferGraph(self) self.SetFocus() # So we know when new values are added / changed on the tgraph self.t_graph.Connect(-1, -1, wx.wxEVT_COMMAND_SLIDER_UPDATED, self.OnTGraphUpdate) self.OnTGraphUpdate(None) self.lighting = True # This is the transfer graph self.t_graph.Show()
def Execute(self): if self.Surface == None: self.PrintError('Error: no Surface.') self.Clipper = vtk.vtkClipPolyData() self.Clipper.SetInput(self.Surface) self.Clipper.GenerateClippedOutputOn() self.Clipper.SetInsideOut(self.InsideOut) if self.Interactive: if self.WidgetType == "box": self.ClipFunction = vtk.vtkPlanes() elif self.WidgetType == "sphere": self.ClipFunction = vtk.vtkSphere() self.Clipper.SetClipFunction(self.ClipFunction) self.Cutter = vtk.vtkCutter() self.Cutter.SetInput(self.Surface) self.Cutter.SetCutFunction(self.ClipFunction) self.ClippedSurface = vtk.vtkPolyData() self.CutLines = vtk.vtkPolyData() if not self.vmtkRenderer: self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 self.vmtkRenderer.RegisterScript(self) mapper = vtk.vtkPolyDataMapper() mapper.SetInput(self.Surface) mapper.ScalarVisibilityOff() self.Actor = vtk.vtkActor() self.Actor.SetMapper(mapper) self.vmtkRenderer.Renderer.AddActor(self.Actor) if self.WidgetType == "box": self.ClipWidget = vtk.vtkBoxWidget() self.ClipWidget.GetFaceProperty().SetColor(0.6,0.6,0.2) self.ClipWidget.GetFaceProperty().SetOpacity(0.25) elif self.WidgetType == "sphere": self.ClipWidget = vtk.vtkSphereWidget() self.ClipWidget.GetSphereProperty().SetColor(0.6,0.6,0.2) self.ClipWidget.GetSphereProperty().SetOpacity(0.25) self.ClipWidget.GetSelectedSphereProperty().SetColor(0.6,0.0,0.0) self.ClipWidget.GetSelectedSphereProperty().SetOpacity(0.75) self.ClipWidget.SetRepresentationToSurface() self.ClipWidget.SetPhiResolution(20) self.ClipWidget.SetThetaResolution(20) self.ClipWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor) self.vmtkRenderer.AddKeyBinding('space','Clip.',self.ClipCallback) self.vmtkRenderer.AddKeyBinding('i','Interact.',self.InteractCallback) self.Display() self.Transform = vtk.vtkTransform() self.ClipWidget.GetTransform(self.Transform) if self.OwnRenderer: self.vmtkRenderer.Deallocate() else: self.Surface.GetPointData().SetActiveScalars(self.ClipArrayName) self.Clipper.GenerateClipScalarsOff() self.Clipper.SetValue(self.ClipValue) self.Clipper.Update() self.Cutter = vtk.vtkContourFilter() self.Cutter.SetInput(self.Surface) self.Cutter.SetValue(0,self.ClipValue) self.Cutter.Update() self.Surface = self.Clipper.GetOutput() self.ClippedSurface = self.Clipper.GetClippedOutput() self.CutLines = self.Cutter.GetOutput() if self.CleanOutput == 1: cleaner = vtk.vtkCleanPolyData() cleaner.SetInput(self.Surface) cleaner.Update() self.Surface = cleaner.GetOutput() cleaner = vtk.vtkCleanPolyData() cleaner.SetInput(self.ClippedSurface) cleaner.Update() self.ClippedSurface = cleaner.GetOutput() cleaner = vtk.vtkCleanPolyData() cleaner.SetInput(self.CutLines) cleaner.Update() stripper = vtk.vtkStripper() stripper.SetInput(cleaner.GetOutput()) stripper.Update() self.CutLines = stripper.GetOutput() if self.Surface.GetSource(): self.Surface.GetSource().UnRegisterAllOutputs()
def testInteractorEventRecorder(self): # Demonstrate how to use the vtkInteractorEventRecorder to play back some # events. # Create a mace out of filters. # sphere = vtk.vtkSphereSource() cone = vtk.vtkConeSource() glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(sphere.GetOutputPort()) glyph.SetSourceConnection(cone.GetOutputPort()) glyph.SetVectorModeToUseNormal() glyph.SetScaleModeToScaleByVector() glyph.SetScaleFactor(0.25) # The sphere and spikes are appended into a single polydata. This just makes things # simpler to manage. apd = vtk.vtkAppendPolyData() apd.AddInputConnection(glyph.GetOutputPort()) apd.AddInputConnection(sphere.GetOutputPort()) maceMapper = vtk.vtkPolyDataMapper() maceMapper.SetInputConnection(apd.GetOutputPort()) maceActor = vtk.vtkLODActor() maceActor.SetMapper(maceMapper) maceActor.VisibilityOn() # This portion of the code clips the mace with the vtkPlanes implicit function. # The clipped region is colored green. planes = vtk.vtkPlanes() clipper = vtk.vtkClipPolyData() clipper.SetInputConnection(apd.GetOutputPort()) clipper.SetClipFunction(planes) clipper.InsideOutOn() selectMapper = vtk.vtkPolyDataMapper() selectMapper.SetInputConnection(clipper.GetOutputPort()) selectActor = vtk.vtkLODActor() selectActor.SetMapper(selectMapper) selectActor.GetProperty().SetColor(0, 1, 0) selectActor.VisibilityOff() selectActor.SetScale(1.01, 1.01, 1.01) # Create the RenderWindow, Renderer and both Actors # ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin); #iren = vtk.vtkRenderWindowInteractor() #iren.SetRenderWindow(renWin) iRen.AddObserver("ExitEvent", sys.exit) # The SetInteractor method is how 3D widgets are associated with the render # window interactor. Internally, SetInteractor sets up a bunch of callbacks # using the Command/Observer mechanism (AddObserver()). ren.AddActor(maceActor) ren.AddActor(selectActor) # Add the actors to the renderer, set the background and size # ren.SetBackground(0.1, 0.2, 0.4) renWin.SetSize(300, 300) # This does the actual work: updates the vtkPlanes implicit function. # This in turn causes the pipeline to update. def SelectPolygons(widget, event_string): ''' The callback takes two parameters. Parameters: widget - the object that generates the event. event_string - the event name (which is a string). ''' boxRep.GetPlanes(planes) selectActor.VisibilityOn() # Place the interactor initially. The input to a 3D widget is used to # initially position and scale the widget. The EndInteractionEvent is # observed which invokes the SelectPolygons callback. boxRep = vtk.vtkBoxRepresentation() boxRep.SetPlaceFactor(0.75) boxRep.PlaceWidget(glyph.GetOutput().GetBounds()) boxWidget = vtk.vtkBoxWidget2() boxWidget.SetInteractor(iRen) boxWidget.SetRepresentation(boxRep) boxWidget.AddObserver("EndInteractionEvent", SelectPolygons) boxWidget.SetPriority(1) # record events recorder = vtk.vtkInteractorEventRecorder() recorder.SetInteractor(iRen) recorder.SetFileName(VTK_DATA_ROOT + "/Data/EventRecording.log") # render the image iRen.Initialize() renWin.Render() #recorder.Record() recorder.Play() recorder.Off() # render and interact with data renWin.Render() img_file = "TestInteractorEventRecorder.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def addVol(self, data, header=None): pix_diag = 5.0/10.0 img = vtkImageImportFromArray() img.SetArray(data) img.ConvertIntToUnsignedShortOn() ''' Origin and Data spacing setting are essential for a normalized volume rendering of the DWI image volumes ------- dawdling for a long time for addressing the problem that the volume is too thin and even resorted to pre-resampling of the DWI volumes ''' #img.GetImport().SetDataSpacing(0.9375, 0.9375, 4.5200) img.GetImport().SetDataSpacing(header['pixdim'][1:4]) #img.GetImport().SetDataOrigin(128.0, 128.0, 68.50) img.GetImport().SetDataOrigin( header['dim'][0]*header['pixdim'][0], header['dim'][1]*header['pixdim'][1], header['dim'][2]*header['pixdim'][2]) print img.GetDataExtent() volMapper = vtk.vtkGPUVolumeRayCastMapper() compositeFunction = vtk.vtkVolumeRayCastCompositeFunction() compositeFunction.SetCompositeMethodToInterpolateFirst() #compositeFunction.SetCompositeMethodToClassifyFirst() #volMapper.SetVolumeRayCastFunction(compositeFunction) #volMapper.SetSampleDistance(pix_diag / 5.0) volMapper.SetImageSampleDistance( .5 ) volMapper.SetSampleDistance(1.0) volMapper.SetInputConnection( img.GetOutputPort() ) volMapper.SetBlendModeToComposite() # The property describes how the data will look self.volProperty = volProperty = vtk.vtkVolumeProperty() volProperty.SetColor(self.color_tf) volProperty.SetScalarOpacity(self.opacity_tf) volProperty.SetGradientOpacity(self.opacity_tf) if self.parent.lighting: volProperty.ShadeOn() #volProperty.SetInterpolationTypeToLinear() volProperty.SetInterpolationTypeToNearest() volProperty.SetScalarOpacityUnitDistance(pix_diag/5.0) vol = vtk.vtkVolume() vol.SetMapper(volMapper) vol.SetProperty(volProperty) self.ren.AddVolume(vol) boxWidget = vtk.vtkBoxWidget() boxWidget.SetInteractor(self.parent.m_ui.renderView) boxWidget.SetPlaceFactor(1.0) planes = vtk.vtkPlanes() def ClipVolumeRender(obj, event): obj.GetPlanes(planes) volMapper.SetClippingPlanes(planes) boxWidget.SetInput(img.GetOutput()) boxWidget.PlaceWidget(img.GetOutput().GetBounds()) boxWidget.InsideOutOn() boxWidget.AddObserver("InteractionEvent", ClipVolumeRender) outlineProperty = boxWidget.GetOutlineProperty() outlineProperty.SetRepresentationToWireframe() outlineProperty.SetAmbient(1.0) outlineProperty.SetAmbientColor(1, 1, 1) outlineProperty.SetLineWidth(3) selectedOutlineProperty = boxWidget.GetSelectedOutlineProperty() selectedOutlineProperty.SetRepresentationToWireframe() selectedOutlineProperty.SetAmbient(1.0) selectedOutlineProperty.SetAmbientColor(1, 0, 0) selectedOutlineProperty.SetLineWidth(1) outline = vtk.vtkOutlineFilter() outline.SetInputConnection(img.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) self.ren.AddActor(outlineActor) self.volnum += 1
def testBoxWidget(self): # Demonstrate how to use the vtkBoxWidget. # This script uses a 3D box widget to define a "clipping box" to clip some # simple geometry (a mace). Make sure that you hit the "W" key to activate the widget. # create a sphere source # sphere = vtk.vtkSphereSource() cone = vtk.vtkConeSource() glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(sphere.GetOutputPort()) glyph.SetSourceConnection(cone.GetOutputPort()) glyph.SetVectorModeToUseNormal() glyph.SetScaleModeToScaleByVector() glyph.SetScaleFactor(0.25) apd = vtk.vtkAppendPolyData() apd.AddInputConnection(glyph.GetOutputPort()) apd.AddInputConnection(sphere.GetOutputPort()) maceMapper = vtk.vtkPolyDataMapper() maceMapper.SetInputConnection(apd.GetOutputPort()) maceActor = vtk.vtkLODActor() maceActor.SetMapper(maceMapper) maceActor.VisibilityOn() planes = vtk.vtkPlanes() clipper = vtk.vtkClipPolyData() clipper.SetInputConnection(apd.GetOutputPort()) clipper.SetClipFunction(planes) clipper.InsideOutOn() selectMapper = vtk.vtkPolyDataMapper() selectMapper.SetInputConnection(clipper.GetOutputPort()) selectActor = vtk.vtkLODActor() selectActor.SetMapper(selectMapper) selectActor.GetProperty().SetColor(0, 1, 0) selectActor.VisibilityOff() selectActor.SetScale(1.01, 1.01, 1.01) # Create the RenderWindow, Renderer and both Actors # ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin); boxWidget = vtk.vtkBoxWidget() boxWidget.SetInteractor(iRen) ren.AddActor(maceActor) ren.AddActor(selectActor) # Add the actors to the renderer, set the background and size # ren.SetBackground(0.1, 0.2, 0.4) renWin.SetSize(300, 300) def SelectPolygons(widget, event_string): ''' The callback takes two parameters. Parameters: widget - the object that generates the event. event_string - the event name (which is a string). ''' boxWidget, selectActor boxWidget.GetPlanes(planes) selectActor.VisibilityOn() # place the interactor initially boxWidget.SetInputConnection(glyph.GetOutputPort()) boxWidget.PlaceWidget() boxWidget.AddObserver("EndInteractionEvent", SelectPolygons) # render and interact with data renWin.Render() img_file = "TestBoxWidget.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def __init__(self, file_list,spacing_list,feature_type,irad = 1.2, h_th=-200, glyph_type='sphere', glyph_scale_factor=1,use_field_data=True, opacity_list=[], color_list=[], lung=[]): assert feature_type == "ridge_line" or feature_type == "valley_line" \ or feature_type == "ridge_surface" or feature_type == "valley_surface" \ or feature_type == "vessel" or feature_type == "airway" \ or feature_type == "fissure", "Invalid feature type" if feature_type == "airway": feature_type = "valley_line" elif feature_type == "vessel": feature_type = "ridge_line" elif feature_type == "fissure": feature_type = "ridge_surface" self.mapper_list = list() self.actor_list = list() self.glyph_list = list() self.glyph_type = glyph_type self.file_list = file_list self.spacing_list = spacing_list self.opacity_list = opacity_list self.irad = irad self.h_th = h_th self.color_list = color_list self.lung = lung self.use_field_data = use_field_data self.feature_type = feature_type self.normal_map=dict() self.normal_map['ridge_line'] = "hevec0" self.normal_map['valley_line'] = "hevec2" self.normal_map['ridge_surface'] = "hevec2" self.normal_map['valley_surface'] = "hevec0" self.strength_map=dict() self.strength_map['ridge_line'] = "h1" self.strength_map['valley_line'] = "h1" self.strength_map['ridge_surface'] = "h2" self.strength_map['valley_surface'] = "h0" if feature_type == 'ridge_line' or feature_type == 'valley_line': self.height = irad self.radius = 0.5 elif feature_type == 'ridge_surface' or feature_type == 'valley_surface': self.height = 0.5 self.radius = irad self.min_rad = 0.5 self.max_rad = 6 self.glyph_scale_factor = glyph_scale_factor self.capture_prefix = "" self.capture_count = 1 self.image_count = 1 # VTK Objects self.ren = vtk.vtkOpenGLRenderer() self.renWin = vtk.vtkRenderWindow() self.iren = vtk.vtkRenderWindowInteractor() # Volume rendering objects self.volumeActor = vtk.vtkVolume() self.volumeMapper = vtk.vtkVolumeRayCastMapper() #self.volumeMapper = vtk.vtkGPUVolumeRayCastMapper() # Variables for the interaction self.volume_loaded = False self.volume_added_to_renderer = False self.volume_size = [0,0,0] self.particles_loaded = False self.particles_added_to_renderer = False self.planeWidgetX = vtk.vtkImagePlaneWidget() self.planeWidgetY = vtk.vtkImagePlaneWidget() self.planeWidgetZ = vtk.vtkImagePlaneWidget() self.lastPlaneWidget = self.planeWidgetX self.lastPlaneWidgetIndex = 0 self.planeWidgetLayer = [0,0,0] self.boxWidgetVolume = vtk.vtkBoxWidget() self.boxWidgetParticles = vtk.vtkBoxWidget() self.planesParticles = vtk.vtkPlanes() self.planesParticles.SetBounds(-10000,10000,-10000,10000,-10000,10000); # For some reason planes needs initializaiton self.planesVolume = vtk.vtkPlanes() self.planesVolume.SetBounds(-10000,10000,-10000,10000,-10000,10000); # For some reason planes needs initializaiton