def __init__(self,data_reader,main_renderer,main_interactor,chart,pts):

        self.widget=vtk.vtkLineWidget()
        self.widget.SetCurrentRenderer(main_renderer)
        #interactor = vtk.vtkRenderWindowInteractor()
        self.widget.SetInteractor(vtk.vtkRenderWindowInteractor())
        self.widget.SetInput(data_reader.get_data_set())
        self.widget.ClampToBoundsOff()
        self.widget.SetResolution(1000)
        self.widget.SetAlignToNone()
        
        self.point1=[pts[0],pts[1],pts[2]]
        self.point2=[pts[3],pts[4],pts[5]]
        self.widget.SetPoint1(self.point1)
        self.widget.SetPoint2(self.point2)

        self.widget.PlaceWidget()

        self.widget.AddObserver("InteractionEvent",self.PrepareProfile(chart))
        self.widget.On()
Exemplo n.º 2
0
    def __init__(self, data_reader, main_renderer, main_interactor, chart,
                 pts):

        self.widget = vtk.vtkLineWidget()
        self.widget.SetCurrentRenderer(main_renderer)
        #interactor = vtk.vtkRenderWindowInteractor()
        self.widget.SetInteractor(vtk.vtkRenderWindowInteractor())
        self.widget.SetInput(data_reader.get_data_set())
        self.widget.ClampToBoundsOff()
        self.widget.SetResolution(1000)
        self.widget.SetAlignToNone()

        self.point1 = [pts[0], pts[1], pts[2]]
        self.point2 = [pts[3], pts[4], pts[5]]
        self.widget.SetPoint1(self.point1)
        self.widget.SetPoint2(self.point2)

        self.widget.PlaceWidget()

        self.widget.AddObserver("InteractionEvent", self.PrepareProfile(chart))
        self.widget.On()
Exemplo n.º 3
0
import vtk
from vtk.util.misc import vtkGetDataRoot

VTK_DATA_ROOT = vtkGetDataRoot()

# Start by loading some data.
pl3d = vtk.vtkMultiBlockPLOT3DReader()
pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin")
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin")
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()
pl3d_output = pl3d.GetOutput().GetBlock(0)

# The line widget is used seed the streamlines.
lineWidget = vtk.vtkLineWidget()
seeds = vtk.vtkPolyData()
lineWidget.SetInputData(pl3d_output)
lineWidget.SetAlignToYAxis()
lineWidget.PlaceWidget()
lineWidget.GetPolyData(seeds)
lineWidget.ClampToBoundsOn()

rk4 = vtk.vtkRungeKutta4()
streamer = vtk.vtkStreamTracer()
streamer.SetInputData(pl3d_output)
streamer.SetSourceData(seeds)
streamer.SetMaximumPropagation(100)
streamer.SetInitialIntegrationStep(.2)
streamer.SetIntegrationDirectionToForward()
streamer.SetComputeVorticity(1)
Exemplo n.º 4
0
    def add_line_widget(self,
                        callback,
                        bounds=None,
                        factor=1.25,
                        resolution=100,
                        color=None,
                        use_vertices=False,
                        pass_widget=False):
        """Add a line widget to the scene.

        This is useless without a callback function. You can pass a callable
        function that takes a single argument, the PolyData line output from this
        widget, and performs a task with that line.

        Parameters
        ----------
        callback : callable
            The method called every time the line is updated. This has two
            options: Take a single argument, the ``PolyData`` line (default) or
            if ``use_vertices=True``, then it can take two arguments of the
            coordinates of the line's end points.

        bounds : tuple(float)
            Length 6 tuple of the bounding box where the widget is placed.

        factor : float, optional
            An inflation factor to expand on the bounds when placing

        resolution : int
            The number of points in the line created

        color : string or 3 item list, optional, defaults to white
            Either a string, rgb list, or hex color string.

        use_vertices : bool, optional
            Changess the arguments of the callback method to take the end
            points of the line instead of a PolyData object.

        pass_widget : bool
            If true, the widget will be passed as the last argument of the
            callback

        """
        if hasattr(self, 'notebook') and self.notebook:
            raise AssertionError(
                'Line widget not available in notebook plotting')
        if not hasattr(self, 'iren'):
            raise AttributeError(
                'Widgets must be used with an intereactive renderer. No off screen plotting.'
            )
        if not hasattr(self, "line_widgets"):
            self.line_widgets = []

        if bounds is None:
            bounds = self.bounds

        if color is None:
            color = rcParams['font']['color']

        def _the_callback(widget, event_id):
            pointa = widget.GetPoint1()
            pointb = widget.GetPoint2()
            if hasattr(callback, '__call__'):
                if use_vertices:
                    args = [pointa, pointb]
                else:
                    the_line = pyvista.Line(pointa,
                                            pointb,
                                            resolution=resolution)
                    args = [the_line]
                if pass_widget:
                    args.append(widget)
                try_callback(callback, *args)
            return

        line_widget = vtk.vtkLineWidget()
        line_widget.GetLineProperty().SetColor(parse_color(color))
        line_widget.SetInteractor(self.iren)
        line_widget.SetCurrentRenderer(self.renderer)
        line_widget.SetPlaceFactor(factor)
        line_widget.PlaceWidget(bounds)
        line_widget.SetResolution(resolution)
        line_widget.Modified()
        line_widget.On()
        line_widget.AddObserver(vtk.vtkCommand.EndInteractionEvent,
                                _the_callback)
        _the_callback(line_widget, None)

        self.line_widgets.append(line_widget)
        return line_widget
Exemplo n.º 5
0
try:
  import vtk

except:
  print "Cannot import vtk"
  sys.exit(1)
try:
  print dir(vtk)
except:
  print "Cannot print dir(vtk)"
  sys.exit(1)

try:
  try:
    try:
      o = vtk.vtkLineWidget()
      print "Using Hybrid"
    except:
      o = vtk.vtkActor()
      print "Using Rendering"
  except:
    o = vtk.vtkObject()
    print "Using Common"
except:
  print "Cannot create vtkObject"
  sys.exit(1)

try:
  print o
  print "Reference count: %d" % o.GetReferenceCount()
  print "Class name: %s" % o.GetClassName()
Exemplo n.º 6
0
import vtk
from vtk.util.misc import vtkGetDataRoot

VTK_DATA_ROOT = vtkGetDataRoot()

# Start by loading some data.
pl3d = vtk.vtkMultiBlockPLOT3DReader()
pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin")
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin")
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()
pl3d_output = pl3d.GetOutput().GetBlock(0)

# The line widget is used seed the streamlines.
lineWidget = vtk.vtkLineWidget()
seeds = vtk.vtkPolyData()
lineWidget.SetInputData(pl3d_output)
lineWidget.SetAlignToYAxis()
lineWidget.PlaceWidget()
lineWidget.GetPolyData(seeds)
lineWidget.ClampToBoundsOn()

rk4 = vtk.vtkRungeKutta4()
streamer = vtk.vtkStreamLine()
streamer.SetInputData(pl3d_output)
streamer.SetSourceData(seeds)
streamer.SetMaximumPropagationTime(100)
streamer.SetIntegrationStepLength(0.2)
streamer.SetStepLength(0.001)
streamer.SetNumberOfThreads(1)
Exemplo n.º 7
0
try:
    import vtk

except:
    print "Cannot import vtk"
    qt.QApplication.exit(1)
try:
    print dir(vtk)
except:
    print "Cannot print dir(vtk)"
    qt.QApplication.exit(1)

try:
    try:
        try:
            o = vtk.vtkLineWidget()
            print "Using Hybrid"
        except:
            o = vtk.vtkActor()
            print "Using Rendering"
    except:
        o = vtk.vtkObject()
        print "Using Common"
except:
    print "Cannot create vtkObject"
    qt.QApplication.exit(1)

try:
    print o
    print "Reference count: %d" % o.GetReferenceCount()
    print "Class name: %s" % o.GetClassName()
Exemplo n.º 8
0
    def plot(self, struct):

        # creates self. data1, legend, filename, fieldname, dim, has_field, tracker, revision
        if not self.call_config(struct):
            return

        # creates self.src
        if not self.call_src():
            return

# linha start
# => src_update1
        self.range_in = self.src.GetOutput().GetScalarRange()
        b = self.range_bo = self.src.GetOutput().GetBounds()
        print 'reader scalars', self.range_in
        print 'reader bounds', self.range_bo

        # Create three the line source to use for the probe lines.
        #        p1 = ((b[0]+b[1])/2.0, b[2], (b[4]+b[5])/2.0)
        #        p2 = ((b[0]+b[1])/2.0, b[3], (b[4]+b[5])/2.0)
        p1 = (b[0], b[2], b[4])
        p2 = (b[1], b[3], b[5])
        self.line = vtk.vtkLineSource()
        self.line.SetResolution(100)
        #self.line.SetPoint1(p1)
        #self.line.SetPoint2(p2)
        self.line.SetPoint1((0, 0, 0))
        self.line.SetPoint2((1, 1, 1))

        self.probe = probe = vtk.vtkProbeFilter()
        probe.SetInputConnection(self.line.GetOutputPort())

        # si es cell data, lo transforma a point data, porque vtkProbeFilter parece ser que no soporta cell data.
        if self.data1.get('fielddomain') == 'cell':
            self.cdtpd = vtk.vtkCellDataToPointData()
            self.cdtpd.SetInputConnection(self.src.GetOutputPort())
            if vtk.vtkVersion.GetVTKMajorVersion() < 6:
                probe.SetSource(self.cdtpd.GetOutput())
            else:
                probe.SetSourceConnection(self.cdtpd.GetOutputPort())
        else:
            if vtk.vtkVersion.GetVTKMajorVersion() < 6:
                probe.SetSource(self.src.GetOutput())
            else:
                probe.SetSourceConnection(self.src.GetOutputPort())

#        lineMapper = vtk.vtkPolyDataMapper()
#        lineMapper.SetInputConnection(probe.GetOutputPort())
#        lineMapper.ScalarVisibilityOff()
#        self.lineActor = vtk.vtkActor()
#        self.lineActor.SetMapper(lineMapper)
#        self.lineActor.GetProperty().SetColor(Plot.probe_line_color)
# linha end

        self.wireM = vtk.vtkDataSetMapper()
        self.wireM.SetInputConnection(self.src.GetOutputPort())

        # reverse rainbow [red->blue] -> [blue->red]
        self.look = look = self.wireM.GetLookupTable()

        self.scalarrange.local_set(self.src.GetOutput().GetScalarRange())

        self.add_scalarbar_2(look)

        self.add_outline_2(self.src)

        self.wireA = vtk.vtkActor()
        self.wireA.SetMapper(self.wireM)
        self.wireA.GetProperty().SetRepresentationToSurface()
        self.wireA.GetProperty().SetColor(Plot.edges_color)
        self.wireA.GetProperty().SetEdgeColor(Plot.edges_color)

        self.add_swe_2(self.wireA)  # wireframe/surface/surface+edges
        self.add_opacity_2([self.wireA])  # Opacity: 100%/75%/50%/25%/0%
        # test mover liña interactivamente 2 INICIO
        self.lineI = vtk.vtkLineWidget()
        self.lineI.GetLineProperty().SetColor(Plot.probe_line_color)
        seeds = vtk.vtkPolyData()
        if vtk.vtkVersion.GetVTKMajorVersion() < 6:
            self.lineI.SetInput(self.src.GetOutput())
        else:
            self.lineI.SetInputConnection(self.src.GetOutputPort())
        self.lineI.PlaceWidget()
        self.lineI.GetPolyData(seeds)

        iren = self.widget.GetRenderWindow().GetInteractor()
        self.lineI.SetInteractor(iren)
        self.lineI.On()

        self.lineI.AddObserver("StartInteractionEvent", self.event_start)
        #        self.lineI.AddObserver("InteractionEvent", self.event)
        self.lineI.AddObserver("EndInteractionEvent", self.event_end)

        # test mover liña interactivamente 2 FIN
        p1 = self.lineI.GetPoint1()
        p2 = self.lineI.GetPoint2()
        self.line.SetPoint1(p1)
        self.line.SetPoint2(p2)

        self.rens[0].AddActor(self.wireA)
        #        self.rens[0].AddActor(self.lineActor)
        #self.rens[0].SetViewport(0, 0, 0.5, 1)

        # end

        # xy start

        # The x-values we are plotting are the underlying point data values.
        self.xyplot3 = xyplot3 = vtk.vtkXYPlotActor()
        if vtk.vtkVersion.GetVTKMajorVersion() < 6:
            xyplot3.AddInput(probe.GetOutput())
        else:
            xyplot3.AddDataSetInputConnection(probe.GetOutputPort())
        xyplot3.GetPositionCoordinate().SetValue(0.0, 0.0, 0)
        xyplot3.GetPosition2Coordinate().SetValue(1.0, 0.95,
                                                  0)  #relative to Position
        #        xyplot3.SetXValuesToIndex()
        #        SetXValuesToNormalizedArcLength()
        xyplot3.SetXValuesToArcLength()
        #        xyplot3.SetXValuesToValue()
        xyplot3.SetPointComponent(0, 1)
        xyplot3.SetNumberOfXLabels(6)
        xyplot3.SetTitle(" ")
        xyplot3.SetXTitle(" ")
        xyplot3.SetYTitle(" ")
        xyplot3.PlotPointsOn()
        xyplot3.GetProperty().SetColor(1, 1, 1)
        xyplot3.GetProperty().SetPointSize(3)
        # Set text prop color (same color for backward compat with test)
        # Assign same object to all text props
        tprop = xyplot3.GetTitleTextProperty()
        tprop.SetColor(xyplot3.GetProperty().GetColor())
        xyplot3.SetAxisTitleTextProperty(tprop)
        xyplot3.SetAxisLabelTextProperty(tprop)

        #        self.ren2 = self.add_ren()
        ren = vtk.vtkRenderer()
        self.widget2.GetRenderWindow().AddRenderer(ren)
        #ren.SetViewport(0.5, 0, 1, 1)
        ren.AddActor(xyplot3)

        # xy end

        # se é esta en branco o leaf float, encheo de valores extremos
        if self.is_empty(struct):
            self.fill(struct, p1, p2)

        # le os datos do leaf float
        self.copy_params(struct)

        self.done = True
Exemplo n.º 9
0
def main():
    colors = vtk.vtkNamedColors()

    fileName1, fileName2, numOfStreamLines, illustration = get_program_parameters(
    )
    if illustration:
        numOfStreamLines = 25

    # Start by loading some data.
    pl3d = vtk.vtkMultiBlockPLOT3DReader()
    pl3d.SetXYZFileName(fileName1)
    pl3d.SetQFileName(fileName2)
    pl3d.SetScalarFunctionNumber(100)  # Density
    pl3d.SetVectorFunctionNumber(202)  # Momentum
    pl3d.Update()

    pl3d_output = pl3d.GetOutput().GetBlock(0)

    # Create the Renderer, RenderWindow and RenderWindowInteractor.
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Needed by: vtkStreamTracer and vtkLineWidget.
    seeds = vtk.vtkPolyData()
    streamline = vtk.vtkActor()
    seeds2 = vtk.vtkPolyData()
    streamline2 = vtk.vtkActor()

    # The line widget is used seed the streamlines.
    lineWidget = vtk.vtkLineWidget()
    lineWidget.SetResolution(numOfStreamLines)
    lineWidget.SetInputData(pl3d_output)
    lineWidget.GetPolyData(seeds)
    if illustration:
        lineWidget.SetAlignToNone()
        lineWidget.SetPoint1(0.974678, 5.073630, 31.217961)
        lineWidget.SetPoint2(0.457544, -4.995921, 31.080175)
    else:
        lineWidget.SetAlignToYAxis()
    lineWidget.ClampToBoundsOn()
    lineWidget.PlaceWidget()
    # Associate the line widget with the interactor and setup callbacks.
    lineWidget.SetInteractor(iren)
    lineWidget.AddObserver("StartInteractionEvent",
                           EnableActorCallback(streamline))
    lineWidget.AddObserver("InteractionEvent",
                           GenerateStreamlinesCallback(seeds, renWin))

    # The second line widget is used seed more streamlines.
    lineWidget2 = vtk.vtkLineWidget()
    lineWidget2.SetResolution(numOfStreamLines)
    lineWidget2.SetInputData(pl3d_output)
    lineWidget2.GetPolyData(seeds2)
    lineWidget2.SetKeyPressActivationValue('L')
    lineWidget2.SetAlignToZAxis()
    lineWidget.ClampToBoundsOn()
    lineWidget2.PlaceWidget()
    # Associate the line widget with the interactor and setup callbacks.
    lineWidget2.SetInteractor(iren)
    lineWidget2.AddObserver("StartInteractionEvent",
                            EnableActorCallback(streamline2))
    lineWidget2.AddObserver("InteractionEvent",
                            GenerateStreamlinesCallback(seeds2, renWin))

    # Here we set up two streamlines.
    rk4 = vtk.vtkRungeKutta4()
    streamer = vtk.vtkStreamTracer()
    streamer.SetInputData(pl3d_output)
    streamer.SetSourceData(seeds)
    streamer.SetMaximumPropagation(100)
    streamer.SetInitialIntegrationStep(0.2)
    streamer.SetIntegrationDirectionToForward()
    streamer.SetComputeVorticity(1)
    streamer.SetIntegrator(rk4)
    rf = vtk.vtkRibbonFilter()
    rf.SetInputConnection(streamer.GetOutputPort())
    rf.SetWidth(0.1)
    rf.SetWidthFactor(5)
    streamMapper = vtk.vtkPolyDataMapper()
    streamMapper.SetInputConnection(rf.GetOutputPort())
    streamMapper.SetScalarRange(pl3d_output.GetScalarRange())
    streamline.SetMapper(streamMapper)
    streamline.VisibilityOff()

    streamer2 = vtk.vtkStreamTracer()
    streamer2.SetInputData(pl3d_output)
    streamer2.SetSourceData(seeds2)
    streamer2.SetMaximumPropagation(100)
    streamer2.SetInitialIntegrationStep(0.2)
    streamer2.SetIntegrationDirectionToForward()
    streamer2.SetComputeVorticity(1)
    streamer2.SetIntegrator(rk4)
    rf2 = vtk.vtkRibbonFilter()
    rf2.SetInputConnection(streamer2.GetOutputPort())
    rf2.SetWidth(0.1)
    rf2.SetWidthFactor(5)
    streamMapper2 = vtk.vtkPolyDataMapper()
    streamMapper2.SetInputConnection(rf2.GetOutputPort())
    streamMapper2.SetScalarRange(pl3d_output.GetScalarRange())
    streamline2.SetMapper(streamMapper2)
    streamline2.VisibilityOff()

    # Get an outline of the data set for context.
    outline = vtk.vtkStructuredGridOutlineFilter()
    outline.SetInputData(pl3d_output)
    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())
    outlineActor = vtk.vtkActor()
    outlineActor.GetProperty().SetColor(colors.GetColor3d("Black"))
    outlineActor.SetMapper(outlineMapper)

    # Add the actors to the renderer, set the background and size.
    ren.AddActor(outlineActor)
    ren.AddActor(streamline)
    ren.AddActor(streamline2)
    renWin.SetSize(512, 512)
    cam = ren.GetActiveCamera()
    if illustration:
        # We need to directly display the streamlines in this case.
        lineWidget.EnabledOn()
        streamline.VisibilityOn()
        lineWidget.GetPolyData(seeds)
        renWin.Render()

        cam.SetClippingRange(14.216207, 68.382915)
        cam.SetFocalPoint(9.718210, 0.458166, 29.399900)
        cam.SetPosition(-15.827551, -16.997463, 54.003120)
        cam.SetViewUp(0.616076, 0.179428, 0.766979)
        ren.SetBackground(colors.GetColor3d("Silver"))
    else:
        cam.SetClippingRange(3.95297, 50)
        cam.SetFocalPoint(9.71821, 0.458166, 29.3999)
        cam.SetPosition(2.7439, -37.3196, 38.7167)
        cam.SetViewUp(-0.16123, 0.264271, 0.950876)
        ren.SetBackground(colors.GetColor3d("Silver"))

    iren.Initialize()
    renWin.Render()
    iren.Start()