예제 #1
0
파일: handle.py 프로젝트: UNESCO-IHE/uvcdat
    def __init__(self,
                 interactor,
                 point,
                 width=10,
                 height=10,
                 opacity=1,
                 color=(0, 0, 0),
                 clicked=None,
                 dragged=None,
                 released=None,
                 normalize=False):

        self.x, self.y = point
        self.color = color
        self.clicked = clicked
        self.dragged = dragged
        self.released = released
        self.normalize = normalize
        widget = vtkHandleWidget()

        widget.AllowHandleResizeOff()

        widget.SetRepresentation(vtkPointHandleRepresentation2D())

        super(Handle, self).__init__(interactor, widget)

        self.repr.SetCursorShape(quad_poly_data(width, height))

        properties = self.repr.GetProperty()
        properties.SetColor(*color)
        properties.SetOpacity(opacity)

        self.repr.SetHandleSize(10)

        properties = self.repr.GetSelectedProperty()
        properties.SetColor(*color)
        properties.SetOpacity(.5 * opacity)

        self.widget.SetRepresentation(self.repr)
        self.place()

        self.subscribe("StartInteractionEvent", self.click)
        self.subscribe("EndInteractionEvent", self.release)
        self.subscribe("InteractionEvent", self.drag)

        self.clicking = False
        """
예제 #2
0
파일: handle.py 프로젝트: NESII/uvcdat
    def __init__(self, interactor, point, width=10, height=10, opacity=1, color=(
            0, 0, 0), clicked=None, dragged=None, released=None, normalize=False):

        self.x, self.y = point
        self.color = color
        self.clicked = clicked
        self.dragged = dragged
        self.released = released
        self.normalize = normalize
        widget = vtkHandleWidget()

        widget.AllowHandleResizeOff()

        widget.SetRepresentation(vtkPointHandleRepresentation2D())

        super(Handle, self).__init__(interactor, widget)

        self.repr.SetCursorShape(quad_poly_data(width, height))

        properties = self.repr.GetProperty()
        properties.SetColor(*color)
        properties.SetOpacity(opacity)

        self.repr.SetHandleSize(10)

        properties = self.repr.GetSelectedProperty()
        properties.SetColor(*color)
        properties.SetOpacity(.5 * opacity)

        self.widget.SetRepresentation(self.repr)
        self.place()

        self.subscribe("StartInteractionEvent", self.click)
        self.subscribe("EndInteractionEvent", self.release)
        self.subscribe("InteractionEvent", self.drag)

        self.clicking = False
        """
예제 #3
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()
예제 #4
0
Created on Tue Jan 26 17:42:59 2016

@author: qinshuo
"""

import vtk

render = vtk.vtkRenderer()

win = vtk.vtkRenderWindow()
win.AddRenderer(render)

interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(win)

# create a representation
handleRep = vtk.vtkPointHandleRepresentation2D()
handleRep.GetProperty().SetColor(1, 1, 0)

widgetRep = vtk.vtkSeedRepresentation()
widgetRep.SetHandleRepresentation(handleRep)

# create a seedwidget here
seedWidget = vtk.vtkSeedWidget()

seedWidget.SetInteractor(interactor)
seedWidget.SetRepresentation(widgetRep)

seedWidget.On()
interactor.Start()