示例#1
0
    def __init__(self):
        # 1 mm is probably about right.
        # TODO: force this to be recalculated when the StlReader updates
        self.WidgetSize = 1

        self.SurfaceMapper = vtkPolyDataMapper()
        self.SurfaceActor = vtkActor()
        self.SurfaceActor.SetMapper(self.SurfaceMapper)
        # self.seeder = SeedPlacer(self, self.stlActor)
        self.Locator = vtkModifiedBSPTree()

        self.SurfacePlacer = vtkPolygonalSurfacePointPlacer()
        self.SurfacePlacer.AddProp(self.SurfaceActor)

        self.Renderer = vtkRenderer()
        self.Renderer.AddActor(self.SurfaceActor)

        self.CreateMarker()

        self.PlacedSeed = PlacedSeed(self)
        self.PlacedSeed.AddObserver('Enabled',
                                    self.HandlePlacedItemEnabledChange)
        self.AddObserver('WidgetSize', self.PlacedSeed.HandleWidgetSizeChange)

        self.PlacedIolets = PlacedIoletList()
        self.PlacedIolets.SetItemEnabledChangeHandler(
            self.HandlePlacedItemEnabledChange)

        return
示例#2
0
    def __init__(self):
        # 1 mm is probably about right.
        # TODO: force this to be recalculated when the StlReader updates
        self.WidgetSize = 1
        
        self.SurfaceMapper = vtkPolyDataMapper()
        self.SurfaceActor = vtkActor()
        self.SurfaceActor.SetMapper(self.SurfaceMapper)
        # self.seeder = SeedPlacer(self, self.stlActor)
        self.Locator = vtkModifiedBSPTree()
        
        self.SurfacePlacer = vtkPolygonalSurfacePointPlacer()
        self.SurfacePlacer.AddProp(self.SurfaceActor)

        self.Renderer = vtkRenderer()
        self.Renderer.AddActor(self.SurfaceActor)
        
        self.CreateMarker()

        self.PlacedSeed = PlacedSeed(self)
        self.PlacedSeed.AddObserver('Enabled', self.HandlePlacedItemEnabledChange)
        
        self.PlacedIolets = PlacedIoletList()
        self.PlacedIolets.SetItemEnabledChangeHandler(self.HandlePlacedItemEnabledChange)
        
        return
示例#3
0
    def Execute(self):

        if self.Surface == None:
            self.PrintError('Error: no Surface.')

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self) 

        triangleFilter = vtk.vtkTriangleFilter()
        triangleFilter.SetInputData(self.Surface)
        triangleFilter.Update()

        self.Surface = triangleFilter.GetOutput()

        contourScalars = vtk.vtkDoubleArray()
        contourScalars.SetNumberOfComponents(1)
        contourScalars.SetNumberOfTuples(self.Surface.GetNumberOfPoints())
        contourScalars.SetName(self.ContourScalarsArrayName)
        contourScalars.FillComponent(0,self.OutsideValue)

        self.Surface.GetPointData().AddArray(contourScalars)
        self.Surface.GetPointData().SetActiveScalars(self.ContourScalarsArrayName)

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputData(self.Surface)
        mapper.ScalarVisibilityOn()
        self.Actor = vtk.vtkActor()
        self.Actor.SetMapper(mapper)
        self.Actor.GetMapper().SetScalarRange(-1.0,0.0)
        self.vmtkRenderer.Renderer.AddActor(self.Actor)

        self.ContourWidget = vtk.vtkContourWidget()
        self.ContourWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor)

        rep = vtk.vtkOrientedGlyphContourRepresentation.SafeDownCast(self.ContourWidget.GetRepresentation())
        rep.GetLinesProperty().SetColor(1, 0.2, 0)
        rep.GetLinesProperty().SetLineWidth(3.0)

        pointPlacer = vtk.vtkPolygonalSurfacePointPlacer()
        pointPlacer.AddProp(self.Actor)
        pointPlacer.GetPolys().AddItem(self.Surface)
        rep.SetPointPlacer(pointPlacer)

        self.Interpolator = vtk.vtkPolygonalSurfaceContourLineInterpolator()
        self.Interpolator.GetPolys().AddItem(self.Surface)
        rep.SetLineInterpolator(self.Interpolator)

        self.vmtkRenderer.AddKeyBinding('space','Generate scalars',self.ScalarsCallback)
        self.vmtkRenderer.AddKeyBinding('d','Delete contour',self.DeleteContourCallback)
        self.vmtkRenderer.AddKeyBinding('i','Start interaction',self.InteractCallback)
        self.Display()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
    def Execute(self):

        if self.Surface == None:
            self.PrintError('Error: no Surface.')

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self)

        triangleFilter = vtk.vtkTriangleFilter()
        triangleFilter.SetInputData(self.Surface)
        triangleFilter.Update()

        self.Surface = triangleFilter.GetOutput()

        contourScalars = vtk.vtkDoubleArray()
        contourScalars.SetNumberOfComponents(1)
        contourScalars.SetNumberOfTuples(self.Surface.GetNumberOfPoints())
        contourScalars.SetName(self.ContourScalarsArrayName)
        contourScalars.FillComponent(0,self.OutsideValue)

        self.Surface.GetPointData().AddArray(contourScalars)
        self.Surface.GetPointData().SetActiveScalars(self.ContourScalarsArrayName)

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputData(self.Surface)
        mapper.ScalarVisibilityOn()
        self.Actor = vtk.vtkActor()
        self.Actor.SetMapper(mapper)
        self.Actor.GetMapper().SetScalarRange(-1.0,0.0)
        self.vmtkRenderer.Renderer.AddActor(self.Actor)

        self.ContourWidget = vtk.vtkContourWidget()
        self.ContourWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor)

        rep = vtk.vtkOrientedGlyphContourRepresentation.SafeDownCast(self.ContourWidget.GetRepresentation())
        rep.GetLinesProperty().SetColor(1, 0.2, 0)
        rep.GetLinesProperty().SetLineWidth(3.0)

        pointPlacer = vtk.vtkPolygonalSurfacePointPlacer()
        pointPlacer.AddProp(self.Actor)
        pointPlacer.GetPolys().AddItem(self.Surface)
        rep.SetPointPlacer(pointPlacer)

        self.Interpolator = vtk.vtkPolygonalSurfaceContourLineInterpolator()
        self.Interpolator.GetPolys().AddItem(self.Surface)
        rep.SetLineInterpolator(self.Interpolator)

        self.vmtkRenderer.AddKeyBinding('space','Generate scalars',self.ScalarsCallback)
        self.vmtkRenderer.AddKeyBinding('d','Delete contour',self.DeleteContourCallback)
        self.vmtkRenderer.AddKeyBinding('i','Start interaction',self.InteractCallback)
        self.Display()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Surface == None:
            self.PrintError('Error: no Surface.')

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self)

        triangleFilter = vtk.vtkTriangleFilter()
        triangleFilter.SetInputData(self.Surface)
        triangleFilter.Update()

        self.Surface = triangleFilter.GetOutput()

        self.tagviewer = vmtkscripts.vmtkSurfaceViewer()
        self.tagviewer.Surface = self.Surface
        self.tagviewer.vmtkRenderer = self.vmtkRenderer
        self.tagviewer.Representation = 'edges'
        self.tagviewer.Opacity = self.Opacity
        self.tagviewer.Execute()

        self.ContourWidget = vtk.vtkContourWidget()
        self.ContourWidget.SetInteractor(
            self.vmtkRenderer.RenderWindowInteractor)

        rep = vtk.vtkOrientedGlyphContourRepresentation.SafeDownCast(
            self.ContourWidget.GetRepresentation())
        rep.GetLinesProperty().SetColor(1, 0, 0)
        rep.GetLinesProperty().SetLineWidth(4.0)

        pointPlacer = vtk.vtkPolygonalSurfacePointPlacer()
        pointPlacer.AddProp(self.tagviewer.Actor)
        pointPlacer.GetPolys().AddItem(self.Surface)
        rep.SetPointPlacer(pointPlacer)

        self.Interpolator = vtk.vtkPolygonalSurfaceContourLineInterpolator()
        self.Interpolator.GetPolys().AddItem(self.Surface)
        rep.SetLineInterpolator(self.Interpolator)

        self.InputInfo("Building loop ...\n")

        self.vmtkRenderer.AddKeyBinding('space', 'Generate loop',
                                        self.LoopCallback)
        self.vmtkRenderer.AddKeyBinding('d', 'Delete contour',
                                        self.DeleteContourCallback)
        self.vmtkRenderer.AddKeyBinding('i', 'Start/stop contour drawing',
                                        self.InteractCallback)

        self.Display()

        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
示例#6
0
    def Execute(self):
        from vmtk import vmtkscripts
        if self.Surface == None:
            self.PrintError('Error: no Surface.')

        if not self.vmtkRenderer:
            self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
            self.vmtkRenderer.Initialize()
            self.OwnRenderer = 1

        self.vmtkRenderer.RegisterScript(self) 

        triangleFilter = vtk.vtkTriangleFilter()
        triangleFilter.SetInputData(self.Surface)
        triangleFilter.Update()

        self.Surface = triangleFilter.GetOutput()

        self.tagviewer = vmtkscripts.vmtkSurfaceViewer()
        self.tagviewer.Surface = self.Surface
        self.tagviewer.vmtkRenderer = self.vmtkRenderer
        self.tagviewer.Representation = 'edges'
        self.tagviewer.Opacity = self.Opacity
        self.tagviewer.Execute()

        self.ContourWidget = vtk.vtkContourWidget()
        self.ContourWidget.SetInteractor(self.vmtkRenderer.RenderWindowInteractor)

        rep = vtk.vtkOrientedGlyphContourRepresentation.SafeDownCast(self.ContourWidget.GetRepresentation())
        rep.GetLinesProperty().SetColor(1, 0, 0)
        rep.GetLinesProperty().SetLineWidth(4.0)

        pointPlacer = vtk.vtkPolygonalSurfacePointPlacer()
        pointPlacer.AddProp(self.tagviewer.Actor)
        pointPlacer.GetPolys().AddItem(self.Surface)
        rep.SetPointPlacer(pointPlacer)

        self.Interpolator = vtk.vtkPolygonalSurfaceContourLineInterpolator()
        self.Interpolator.GetPolys().AddItem(self.Surface)
        rep.SetLineInterpolator(self.Interpolator)

        self.InputInfo("Building loop ...\n")

        self.vmtkRenderer.AddKeyBinding('space','Generate loop',self.LoopCallback)
        self.vmtkRenderer.AddKeyBinding('d','Delete contour',self.DeleteContourCallback)
        self.vmtkRenderer.AddKeyBinding('i','Start/stop contour drawing',self.InteractCallback)


        self.Display()


        if self.OwnRenderer:
            self.vmtkRenderer.Deallocate()
示例#7
0
    def _InitializeWidget(self):
        contourWidget = vtk.vtkContourWidget()
        contourWidget.SetInteractor(self.RenderWindowInteractor)
        contourWidget.FollowCursorOn()

        eventTranslator = contourWidget.GetEventTranslator()
        # Right Button Press controls both camera dolly and contour loop closing,
        # which can lead to premature interaction end
        eventTranslator.RemoveTranslation(vtk.vtkCommand.RightButtonPressEvent)
        set_event_translator_key_press_event(eventTranslator,
                                             vtk.vtkWidgetEvent.AddFinalPoint,
                                             'c')
        set_event_translator_key_press_event(eventTranslator,
                                             vtk.vtkWidgetEvent.Delete, 'd')
        set_event_translator_key_press_event(eventTranslator,
                                             vtk.vtkWidgetEvent.Reset, 'r')

        rep = contourWidget.GetRepresentation()
        repProperty = rep.GetLinesProperty()
        repProperty.SetColor(1, 0, 0)
        repProperty.SetLineWidth(4.0)

        pointPlacer = vtk.vtkPolygonalSurfacePointPlacer()
        pointPlacer.AddProp(self.Actor)
        pointPlacer.GetPolys().AddItem(self.InputData)

        interpolator = vtk.vtkPolygonalSurfaceContourLineInterpolator()
        interpolator.GetPolys().AddItem(self.InputData)

        rep.SetPointPlacer(pointPlacer)
        rep.SetLineInterpolator(interpolator)

        self.ContourWidget = contourWidget
        self.PointPlacer = pointPlacer
        self.Interpolator = interpolator
        self.ContourRepresentation = rep
# Here comes the surface constrained handle widget stuff....

widget = vtk.vtkHandleWidget()
widget.SetInteractor(iren)
rep = vtk.vtkPolygonalHandleRepresentation3D()
widget.SetRepresentation(rep)

sphere = vtk.vtkSphereSource()
sphere.SetThetaResolution(10)
sphere.SetPhiResolution(10)
sphere.SetRadius(300.0)
sphere.Update()
rep.SetHandle(sphere.GetOutput())

pointPlacer = vtk.vtkPolygonalSurfacePointPlacer()
pointPlacer.AddProp(demActor)
pointPlacer.GetPolys().AddItem(pd)
rep.SetPointPlacer(pointPlacer)

# Let the surface constrained point-placer be the sole constraint dictating 
# the placement of handles. Lets not over-constrain it allowing axis
# constrained interactions.
widget.EnableAxisConstraintOff()

# Set some defaults on the handle widget
d = [562532, 5.11396e+06, 2618.62]
rep.SetWorldPosition(d)
rep.GetProperty().SetColor(1.0, 0.0, 0.0)
rep.GetProperty().SetLineWidth(1.0)
rep.GetSelectedProperty().SetColor(0.2, 0.0, 1.0)
示例#9
0
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(0.5)

contourRep = vtk.vtkOrientedGlyphContourRepresentation()
contourRep.GetLinesProperty().SetColor(0, 0, 1)
contourRep.GetLinesProperty().SetLineWidth(5)
contourRep.GetProperty().SetPointSize(5)

contourWidget = vtk.vtkContourWidget()
contourWidget.SetInteractor(iren)
contourWidget.SetRepresentation(contourRep)
contourWidget.On()
contourWidget.Initialize(TemplateF, 1)
contourWidget.CloseLoop()

pointPlacer = vtk.vtkPolygonalSurfacePointPlacer()
pointPlacer.AddProp(actor)
pointPlacer.GetPolys().AddItem(r.GetOutput())
pointPlacer.SnapToClosestPointOn()
contourRep.SetPointPlacer(pointPlacer)

ren.AddActor(actor)
ren.ResetCamera()
renWin.Render()

iren.Initialize()
iren.Start()

pro_model = load(path)

line_point = contourWidget.GetRepresentation().GetContourRepresentationAsPolyData()