Esempio n. 1
2
	def __init__(self, parent, visualizer, **kws):
		"""
		Initialization
		"""		
		self.x, self.y, self.z = -1, -1, -1
		VisualizationModule.__init__(self, parent, visualizer, **kws)	

		self.on = 0
		self.renew = 1
	
		self.distanceWidget = vtk.vtkDistanceWidget()
		self.obsTag = self.distanceWidget.AddObserver("EndInteractionEvent", self.onPlacePoint)
		self.representation = vtkbxd.vtkDistanceRepresentationScaled2D()
		self.representation.SetScaleX(1.0)
		self.representation.SetScaleZ(1.0)
		self.distanceWidget.SetRepresentation(self.representation)
		self.renderer = self.parent.getRenderer()
		iactor = self.wxrenwin.GetRenderWindow().GetInteractor()
		self.distanceWidget.SetInteractor(iactor)
		self.picker = vtk.vtkCellPicker()
		self.currentPlane = None

		#self.picker.SetTolerance(0.05)
		#self.updateRendering()
		self.filterDesc = "Measure distance in 3D view"
Esempio n. 2
0
 def __init__(self, scene=None):
     logging.debug("In Ruler::__init__()")
     self._scene = scene
     self._distanceWidget = vtk.vtkDistanceWidget()
     self._handle = vtk.vtkPointHandleRepresentation3D()
     self._representation = vtk.vtkDistanceRepresentation2D()
     self._representation.SetHandleRepresentation(self._handle)
     self._distanceWidget.SetRepresentation(self._representation)
     self._distanceWidget.CreateDefaultRepresentation()
     self._distanceWidget.parent = self
     self._started = False
     self._lineColor = [0, 1, 0]
     self._fontColor = [0, 1, 0]
     self._handle.GetProperty().SetOpacity(0.01)
     self._distanceWidget.AddObserver("PlacePointEvent", self.startEvent)
Esempio n. 3
0
    def __init__(self, parent=None):
        QtWidgets.QMainWindow.__init__(self, parent)

        self.frame = QtWidgets.QFrame()

        self.vl = QtWidgets.QVBoxLayout()
        self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
        self.vl.addWidget(self.vtkWidget)

        self.ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        self.widget = vtk.vtkDistanceWidget()
        self.widget.SetInteractor(self.iren)
        self.handle = vtk.vtkPointHandleRepresentation3D()
        self.representation = vtk.vtkDistanceRepresentation2D()
        self.representation.SetHandleRepresentation(self.handle)
        self.widget.SetRepresentation(self.representation)
        self.widget.CreateDefaultRepresentation()
        self.widget.On()

        # Create source
        source = vtk.vtkSphereSource()
        source.SetCenter(0, 0, 0)
        source.SetRadius(5.0)

        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())

        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        self.ren.AddActor(actor)

        self.ren.ResetCamera()

        self.frame.setLayout(self.vl)
        self.setCentralWidget(self.frame)

        self.show()
        self.iren.Initialize()
        self.iren.Start()
Esempio n. 4
0
    def _handler_new_measurement_button(self, event):

        widget_type = 0

        if widget_type == 0:

            # instantiate widget with correct init vars
            name = self._view_frame._measurement_panel.name_cb.GetValue()
            if not name or name in self._widgets:
                # FIXME: add error message here
                pass
            else:

                w = vtktudoss.vtkEllipseWidget()
                w.SetInteractor(self._view_frame._rwi)
                w.SetEnabled(1)

                widget = M2DWidget(w, name, 'ellipse')
                # add it to the internal list
                self._widgets.add(widget)

                def observer_interaction(o, e):
                    r = o.GetRepresentation()
                    s = r.GetLabelText()
                    widget.measurement_string = s
                    # c, axis_lengths, radius_vectors
                    mi = widget.measurement_info
                    mi.c = [0.0, 0.0, 0.0]
                    r.GetCenterWorldPosition(mi.c)
                    mi.c[2] = 0.0
                    mi.axis_lengths = (r.GetSemiMajorAxisLength() * 2.0,
                                       r.GetSemiMinorAxisLength() * 2.0, 0.0)
                    mi.radius_vectors = ([0.0, 0.0,
                                          0.0], [0.0, 0.0,
                                                 0.0], [0.0, 0.0, 0.0])

                    # these vectors describe the principal HALF-axes
                    # of the ellipse, starting out from the centre
                    # (mi.c)
                    r.GetSemiMajorAxisVector(mi.radius_vectors[0])
                    r.GetSemiMinorAxisVector(mi.radius_vectors[1])

                    self._sync_measurement_grid()

                # make sure state is initialised  (if one just places
                # the widget without interacting, the observer won't
                # be invoked and measurement_info won't have the
                # necessary attributes; if the network then executes,
                # there will be errors)
                widget.measurement_string = ''
                mi = widget.measurement_info
                mi.c = [0.0, 0.0, 0.0]
                mi.axis_lengths = (0.0, 0.0, 0.0)
                mi.radius_vectors = ([0.0, 0.0, 0.0], [0.0, 0.0,
                                                       0.0], [0.0, 0.0, 0.0])

                w.AddObserver('EndInteractionEvent', observer_interaction)

                # and then make the display thing sync up
                self._sync_measurement_grid()

        else:
            handle = vtk.vtkPointHandleRepresentation2D()
            handle.GetProperty().SetColor(1, 0, 0)

            rep = vtk.vtkDistanceRepresentation2D()
            rep.SetHandleRepresentation(handle)
            rep.GetAxis().SetNumberOfMinorTicks(4)
            rep.GetAxis().SetTickLength(9)
            rep.GetAxis().SetTitlePosition(0.2)

            w = vtk.vtkDistanceWidget()
            w.SetInteractor(self._view_frame._rwi)
            #w.CreateDefaultRepresentation()
            w.SetRepresentation(rep)

            w.SetEnabled(1)

            # instantiate widget with correct init vars
            widget = M2DWidget(w, 'name', 'ellipse')
            # add it to the internal list
            self._widgets.add(w)

        self.render()
Esempio n. 5
0
    def _handler_new_measurement_button(self, event):
        
        widget_type = 0


        if widget_type == 0:

            # instantiate widget with correct init vars
            name = self._view_frame._measurement_panel.name_cb.GetValue()
            if not name or name in self._widgets:
                # FIXME: add error message here
                pass
            else:

                w = vtktudoss.vtkEllipseWidget()
                w.SetInteractor(self._view_frame._rwi)
                w.SetEnabled(1)
                

                widget = M2DWidget(w, name, 'ellipse')
                # add it to the internal list
                self._widgets.add(widget)

                def observer_interaction(o, e):
                    r = o.GetRepresentation()
                    s = r.GetLabelText()
                    widget.measurement_string = s 
                    # c, axis_lengths, radius_vectors
                    mi = widget.measurement_info
                    mi.c = [0.0,0.0,0.0]
                    r.GetCenterWorldPosition(mi.c)
                    mi.c[2] = 0.0
                    mi.axis_lengths = (
                        r.GetSemiMajorAxisLength() * 2.0,
                        r.GetSemiMinorAxisLength() * 2.0,
                        0.0)
                    mi.radius_vectors = (
                            [0.0,0.0,0.0],
                            [0.0,0.0,0.0],
                            [0.0,0.0,0.0])

                    # these vectors describe the principal HALF-axes
                    # of the ellipse, starting out from the centre
                    # (mi.c)
                    r.GetSemiMajorAxisVector(mi.radius_vectors[0])
                    r.GetSemiMinorAxisVector(mi.radius_vectors[1])

                    self._sync_measurement_grid()

                # make sure state is initialised  (if one just places
                # the widget without interacting, the observer won't
                # be invoked and measurement_info won't have the
                # necessary attributes; if the network then executes,
                # there will be errors)
                widget.measurement_string = ''
                mi = widget.measurement_info
                mi.c = [0.0,0.0,0.0]
                mi.axis_lengths = (0.0, 0.0, 0.0)
                mi.radius_vectors = (
                        [0.0,0.0,0.0],
                        [0.0,0.0,0.0],
                        [0.0,0.0,0.0])

                w.AddObserver('EndInteractionEvent',
                              observer_interaction)

                # and then make the display thing sync up
                self._sync_measurement_grid()
        
        else:
            handle = vtk.vtkPointHandleRepresentation2D()
            handle.GetProperty().SetColor(1,0,0)

            rep = vtk.vtkDistanceRepresentation2D()
            rep.SetHandleRepresentation(handle)
            rep.GetAxis().SetNumberOfMinorTicks(4)
            rep.GetAxis().SetTickLength(9)
            rep.GetAxis().SetTitlePosition(0.2)
        
            w = vtk.vtkDistanceWidget()
            w.SetInteractor(self._view_frame._rwi)        
            #w.CreateDefaultRepresentation()
            w.SetRepresentation(rep)
        
            w.SetEnabled(1)

            # instantiate widget with correct init vars
            widget = M2DWidget(w, 'name', 'ellipse')
            # add it to the internal list
            self._widgets.add(w)

        self.render()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(ss.GetOutput())
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Create the widget and its representation
handle = vtk.vtkPointHandleRepresentation2D()
handle.GetProperty().SetColor(1,0,0)
rep = vtk.vtkDistanceRepresentation2D()
rep.SetHandleRepresentation(handle)

rep.GetAxis().SetNumberOfMinorTicks(4)
rep.GetAxis().SetTickLength(9)
rep.GetAxis().SetTitlePosition(0.2)

widget = vtk.vtkDistanceWidget()
widget.SetInteractor(iren)
widget.CreateDefaultRepresentation()
widget.SetRepresentation(rep)

widget.AddObserver("InteractionEvent", vtkDistanceCallback)
widget.AddObserver("EndInteractionEvent", vtkDistanceCallback)
widget.AddObserver("PlacePointEvent", vtkDistanceCallback)
widget.AddObserver("StartInteractionEvent", vtkDistanceCallback)

# Add the actor to the renderer, set the background and size
ren1.AddActor(actor)
ren1.SetBackground(0.1, 0.2, 0.4)
renWin.SetSize(300, 300)

# record events