Beispiel #1
6
    def __init__(self, module_manager):
        # initialise our base class
        ModuleBase.__init__(self, module_manager)
        # initialise any mixins we might have
        NoConfigModuleMixin.__init__(self)


        # we'll be playing around with some vtk objects, this could
        # be anything
        self._thresh = vtk.vtkThresholdPoints()
        # this is wacked syntax!
        self._thresh.ThresholdByUpper(1)
        self._reconstructionFilter = vtk.vtkSurfaceReconstructionFilter()
        self._reconstructionFilter.SetInput(self._thresh.GetOutput())
        self._mc = vtk.vtkMarchingCubes()
        self._mc.SetInput(self._reconstructionFilter.GetOutput())
        self._mc.SetValue(0, 0.0)

        module_utils.setup_vtk_object_progress(self, self._thresh,
                                           'Extracting points...')
        module_utils.setup_vtk_object_progress(self, self._reconstructionFilter,
                                           'Reconstructing...')
        module_utils.setup_vtk_object_progress(self, self._mc,
                                           'Extracting surface...')

        self._iObj = self._thresh
        self._oObj = self._mc
        
        self._viewFrame = self._createViewFrame({'threshold' :
                                                 self._thresh,
                                                 'reconstructionFilter' :
                                                 self._reconstructionFilter,
                                                 'marchingCubes' :
                                                 self._mc})
Beispiel #2
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkThresholdPoints(), 'Processing.',
         ('vtkDataSet',), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkThresholdPoints(),
                                       'Processing.', ('vtkDataSet', ),
                                       ('vtkPolyData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Beispiel #4
0
def select(connected):
    selector = vtk.vtkThresholdPoints()
    selector.SetInput(connected.GetOutput())
    print n_regions
    for i in range(10,11):#change to n_regions
        selector.ThresholdBetween(48,48)
        selector.SetInputArrayToProcess(1, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS, "RegionId" )
        selector.Update()
        triangles = vtk.vtkTriangleFilter()
        triangles.SetInputConnection(selector.GetOutputPort())
        [V, A] = getMassProperties(triangles)
        print ("The volume is: " + str(V) + "\n")
    return selector
Beispiel #5
0
def select(connected):
    selector = vtk.vtkThresholdPoints()
    selector.SetInput(connected.GetOutput())
    print n_regions
    for i in range(10, 11):  #change to n_regions
        selector.ThresholdBetween(48, 48)
        selector.SetInputArrayToProcess(
            1, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS, "RegionId")
        selector.Update()
        triangles = vtk.vtkTriangleFilter()
        triangles.SetInputConnection(selector.GetOutputPort())
        [V, A] = getMassProperties(triangles)
        print("The volume is: " + str(V) + "\n")
    return selector
Beispiel #6
0
TubeMapper = vtk.vtkPolyDataMapper()
TubeMapper.SetInputConnection(Tubes.GetOutputPort())
TubeMapper.ScalarVisibilityOff()
CubeEdges = vtk.vtkActor()
CubeEdges.SetMapper(TubeMapper)
CubeEdges.GetProperty().SetDiffuseColor(GetRGBColor('khaki'))
CubeEdges.GetProperty().SetSpecular(.4)
CubeEdges.GetProperty().SetSpecularPower(10)

# build the vertices of the cube
#
Sphere = vtk.vtkSphereSource()
Sphere.SetRadius(0.04)
Sphere.SetPhiResolution(20)
Sphere.SetThetaResolution(20)
ThresholdIn = vtk.vtkThresholdPoints()
ThresholdIn.SetInputData(grid)
ThresholdIn.ThresholdByUpper(.5)
Vertices = vtk.vtkGlyph3D()
Vertices.SetInputConnection(ThresholdIn.GetOutputPort())
Vertices.SetSourceConnection(Sphere.GetOutputPort())
SphereMapper = vtk.vtkPolyDataMapper()
SphereMapper.SetInputConnection(Vertices.GetOutputPort())
SphereMapper.ScalarVisibilityOff()
CubeVertices = vtk.vtkActor()
CubeVertices.SetMapper(SphereMapper)
CubeVertices.GetProperty().SetDiffuseColor(GetRGBColor('tomato'))

# define the text for the labels
caseLabel = vtk.vtkVectorText()
caseLabel.SetText("Case 1")
Beispiel #7
0
def main():
    fileName = r"carotid.vtk"

    colors = vtk.vtkNamedColors()

    ren1 = vtk.vtkRenderer()

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Create the pipeline.
    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(fileName)

    threshold = vtk.vtkThresholdPoints()
    threshold.SetInputConnection(reader.GetOutputPort())
    threshold.ThresholdByUpper(200)

    mask = vtk.vtkMaskPoints()
    mask.SetInputConnection(threshold.GetOutputPort())
    mask.SetOnRatio(5)

    cone = vtk.vtkConeSource()
    cone.SetResolution(11)
    cone.SetHeight(1)
    cone.SetRadius(0.25)

    cones = vtk.vtkGlyph3D()
    cones.SetInputConnection(mask.GetOutputPort())
    cones.SetSourceConnection(cone.GetOutputPort())
    cones.SetScaleFactor(0.4)
    cones.SetScaleModeToScaleByVector()

    lut = vtk.vtkLookupTable()
    lut.SetHueRange(.667, 0.0)
    lut.Build()

    scalarRange = [0] * 2
    cones.Update()
    scalarRange[0] = cones.GetOutput().GetPointData().GetScalars().GetRange(
    )[0]
    scalarRange[1] = cones.GetOutput().GetPointData().GetScalars().GetRange(
    )[1]

    vectorMapper = vtk.vtkPolyDataMapper()
    vectorMapper.SetInputConnection(cones.GetOutputPort())
    vectorMapper.SetScalarRange(scalarRange[0], scalarRange[1])
    vectorMapper.SetLookupTable(lut)

    vectorActor = vtk.vtkActor()
    vectorActor.SetMapper(vectorMapper)

    # Speed contours.
    iso = vtk.vtkContourFilter()
    iso.SetInputConnection(reader.GetOutputPort())
    iso.SetValue(0, 175)

    isoMapper = vtk.vtkPolyDataMapper()
    isoMapper.SetInputConnection(iso.GetOutputPort())
    isoMapper.ScalarVisibilityOff()

    isoActor = vtk.vtkActor()
    isoActor.SetMapper(isoMapper)
    isoActor.GetProperty().SetRepresentationToWireframe()
    isoActor.GetProperty().SetOpacity(0.25)

    # Outline
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(reader.GetOutputPort())

    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(0., 0., 0.)

    # Add the actors to the renderer, set the background and size.
    ren1.AddActor(outlineActor)
    ren1.AddActor(vectorActor)
    ren1.AddActor(isoActor)
    ren1.SetBackground(1., 1., 1.)
    renWin.SetSize(640, 480)

    ren1.ResetCamera()
    ren1.ResetCameraClippingRange()

    # Render the image.
    renWin.Render()
    iren.Start()
renderer.SetBackground(0.2, 0.2, 0.2)
interactor.Initialize()

# Draw Outline
outline = vtk.vtkStructuredGridOutlineFilter()
outline.SetInputData(b0)
outline_mapper = vtk.vtkPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())
outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)
outline_actor.GetProperty().SetColor(1, 1, 1)
renderer.AddActor(outline_actor)
renderer.ResetCamera()

# Threshold points
threshold = vtk.vtkThresholdPoints()
threshold.SetInputData(b0)
threshold.ThresholdByUpper(0.5)

# Draw arrows
arrow = vtk.vtkArrowSource()
glyphs = vtk.vtkGlyph3D()
glyphs.SetInputData(b0)
glyphs.SetSourceConnection(arrow.GetOutputPort())
glyphs.SetInputConnection(threshold.GetOutputPort())

glyphs.SetVectorModeToUseVector()
glyphs.SetScaleModeToScaleByVector()
glyphs.SetScaleFactor(0.005)
glyphs.SetColorModeToColorByVector()
    def __init__(self, parent, data_dir):
        super(QGlyphViewer,self).__init__(parent)

        # Make tha actual QtWidget a child so that it can be re parented
        interactor = QVTKRenderWindowInteractor(self)
        self.layout = QtGui.QHBoxLayout()
        self.layout.addWidget(interactor)
        self.layout.setContentsMargins(0,0,0,0)
        self.setLayout(self.layout)

        # Read the data
        xyx_file = os.path.join(data_dir, "combxyz.bin")
        q_file = os.path.join(data_dir, "combq.bin")
        pl3d = vtk.vtkMultiBlockPLOT3DReader()
        pl3d.SetXYZFileName(xyx_file)
        pl3d.SetQFileName(q_file)
        pl3d.SetScalarFunctionNumber(100)
        pl3d.SetVectorFunctionNumber(202)
        pl3d.Update()

        blocks = pl3d.GetOutput()
        b0 = blocks.GetBlock(0)

        # Setup VTK environment
        renderer = vtk.vtkRenderer()
        render_window = interactor.GetRenderWindow()
        render_window.AddRenderer(renderer)

        interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
        render_window.SetInteractor(interactor)
        renderer.SetBackground(0.2,0.2,0.2)

        # Draw Outline
        outline = vtk.vtkStructuredGridOutlineFilter()
        outline.SetInputData(b0)
        outline_mapper = vtk.vtkPolyDataMapper()
        outline_mapper.SetInputConnection(outline.GetOutputPort())
        outline_actor = vtk.vtkActor()
        outline_actor.SetMapper(outline_mapper)
        outline_actor.GetProperty().SetColor(1,1,1)
        renderer.AddActor(outline_actor)
        renderer.ResetCamera()

        # Draw Outline
        outline = vtk.vtkStructuredGridOutlineFilter()
        outline.SetInputData(b0)
        outline_mapper = vtk.vtkPolyDataMapper()
        outline_mapper.SetInputConnection(outline.GetOutputPort())
        outline_actor = vtk.vtkActor()
        outline_actor.SetMapper(outline_mapper)
        outline_actor.GetProperty().SetColor(1,1,1)
        renderer.AddActor(outline_actor)
        renderer.ResetCamera()

        # Threshold points
        threshold = vtk.vtkThresholdPoints()
        threshold.SetInputData(b0)
        threshold.ThresholdByUpper(0.5)

        # Draw arrows
        arrow = vtk.vtkArrowSource()
        glyphs = vtk.vtkGlyph3D()
        glyphs.SetInputData(b0)
        glyphs.SetSourceConnection(arrow.GetOutputPort())
        glyphs.SetInputConnection(threshold.GetOutputPort())

        glyphs.SetVectorModeToUseVector()
        glyphs.SetScaleModeToScaleByVector()
        glyphs.SetScaleFactor(0.005)
        glyphs.SetColorModeToColorByVector()

        # Mapper
        glyph_mapper =  vtk.vtkPolyDataMapper()
        glyph_mapper.SetInputConnection(glyphs.GetOutputPort())
        glyph_actor = vtk.vtkActor()
        glyph_actor.SetMapper(glyph_mapper)

        glyph_mapper.UseLookupTableScalarRangeOn()
        renderer.AddActor(glyph_actor)

        # Set color lookuptable
        glyphs.Update()
        s0,sf = glyphs.GetOutput().GetScalarRange()
        lut = vtk.vtkColorTransferFunction()
        lut.AddRGBPoint(s0, 1,0,0)
        lut.AddRGBPoint(sf, 0,1,0)
        glyph_mapper.SetLookupTable(lut)

        self.b0 = b0
        self.renderer = renderer
        self.interactor = interactor
        self.threshold = threshold
Beispiel #10
0
    def __init__(self, data_dir):
        # Read the data
        xyx_file = os.path.join(data_dir, "combxyz.bin")
        q_file = os.path.join(data_dir, "combq.bin")
        pl3d = vtk.vtkMultiBlockPLOT3DReader()
        pl3d.SetXYZFileName(xyx_file)
        pl3d.SetQFileName(q_file)
        pl3d.SetScalarFunctionNumber(100)
        pl3d.SetVectorFunctionNumber(202)
        pl3d.Update()

        blocks = pl3d.GetOutput()
        b0 = blocks.GetBlock(0)

        # Setup VTK environment
        renderer = vtk.vtkRenderer()
        render_window = vtk.vtkRenderWindow()
        render_window.AddRenderer(renderer)
        interactor = vtk.vtkRenderWindowInteractor()
        interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
        render_window.SetInteractor(interactor)
        renderer.SetBackground(0.2, 0.2, 0.2)
        interactor.Initialize()

        # Draw Outline
        outline = vtk.vtkStructuredGridOutlineFilter()
        outline.SetInputData(b0)
        outline_mapper = vtk.vtkPolyDataMapper()
        outline_mapper.SetInputConnection(outline.GetOutputPort())
        outline_actor = vtk.vtkActor()
        outline_actor.SetMapper(outline_mapper)
        outline_actor.GetProperty().SetColor(1, 1, 1)
        renderer.AddActor(outline_actor)
        renderer.ResetCamera()

        # Draw Outline
        outline = vtk.vtkStructuredGridOutlineFilter()
        outline.SetInputData(b0)
        outline_mapper = vtk.vtkPolyDataMapper()
        outline_mapper.SetInputConnection(outline.GetOutputPort())
        outline_actor = vtk.vtkActor()
        outline_actor.SetMapper(outline_mapper)
        outline_actor.GetProperty().SetColor(1, 1, 1)
        renderer.AddActor(outline_actor)
        renderer.ResetCamera()

        # Threshold points
        threshold = vtk.vtkThresholdPoints()
        threshold.SetInputData(b0)
        threshold.ThresholdByUpper(0.5)

        # Draw arrows
        arrow = vtk.vtkArrowSource()
        glyphs = vtk.vtkGlyph3D()
        glyphs.SetInputData(b0)
        glyphs.SetSourceConnection(arrow.GetOutputPort())
        glyphs.SetInputConnection(threshold.GetOutputPort())

        glyphs.SetVectorModeToUseVector()
        glyphs.SetScaleModeToScaleByVector()
        glyphs.SetScaleFactor(0.005)
        glyphs.SetColorModeToColorByVector()

        # Mapper
        glyph_mapper = vtk.vtkPolyDataMapper()
        glyph_mapper.SetInputConnection(glyphs.GetOutputPort())
        glyph_actor = vtk.vtkActor()
        glyph_actor.SetMapper(glyph_mapper)

        glyph_mapper.UseLookupTableScalarRangeOn()
        renderer.AddActor(glyph_actor)

        # Set color lookuptable
        glyphs.Update()
        s0, sf = glyphs.GetOutput().GetScalarRange()
        lut = vtk.vtkColorTransferFunction()
        lut.AddRGBPoint(s0, 1, 0, 0)
        lut.AddRGBPoint(sf, 0, 1, 0)
        glyph_mapper.SetLookupTable(lut)

        self.b0 = b0
        self.renderer = renderer
        self.interactor = interactor
        self.threshold = threshold
interactor.Initialize()

# Draw Outline
outline = vtk.vtkStructuredGridOutlineFilter()
outline.SetInputData(b0)
outline_mapper = vtk.vtkPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())
outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)
outline_actor.GetProperty().SetColor(1,1,1)
renderer.AddActor(outline_actor)
renderer.ResetCamera()


# Threshold points
threshold = vtk.vtkThresholdPoints()
threshold.SetInputData(b0)
threshold.ThresholdByUpper(0.5)

# Draw arrows
arrow = vtk.vtkArrowSource()
glyphs = vtk.vtkGlyph3D()
glyphs.SetInputData(b0)
glyphs.SetSourceConnection(arrow.GetOutputPort())
glyphs.SetInputConnection(threshold.GetOutputPort())

glyphs.SetVectorModeToUseVector()
glyphs.SetScaleModeToScaleByVector()
glyphs.SetScaleFactor(0.005)
glyphs.SetColorModeToColorByVector()
points, strength, time_, = ReadPointsCSV.readPoints("events3.csv")
min_strength, max_strength = strength.GetRange()
min_time, max_time = time_.GetRange()  # in seconds

# Assign unique names to the scalar arrays
strength.SetName("strength")
time_.SetName("time")

# Create a vtkPolyData object from the earthquake data and specify
# that "strength" should be the active scalar array
points_polydata = vtk.vtkPolyData()
points_polydata.SetPoints(points)
points_polydata.GetPointData().AddArray(strength)
points_polydata.GetPointData().AddArray(time_)
points_polydata.GetPointData().SetActiveScalars("strength")

# Threshold the earthquake points to extract all points within a
# specified time interval.
#
# If you do not specify which input array to process, i.e., if you
# comment out the SetInputArrayToProcess() call, the thresholding will
# be performed on the active scalar array ("strength", in this case).
threshold_filter = vtk.vtkThresholdPoints()
threshold_filter.SetInput(points_polydata)
threshold_filter.ThresholdBetween(min_time, max_time)
threshold_filter.SetInputArrayToProcess(0, 0, 0, 0, "time")
threshold_filter.Update()

# Connect the output of the threshold filter to a vtkGlyph3D filter
# and proceed with the visualization!
Beispiel #13
0
def marching_cubes(mcCases):
    color = vtk.vtkNamedColors()

    renWin = vtk.vtkRenderWindow()
    renWin.SetSize(640, 480)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    renderers = list()
    gridSize = ((len(mcCases) + 3) // 4) * 4
    if len(mcCases) < 4:
        gridSize = len(mcCases)
    print("gridSize:", gridSize)
    for i in range(0, gridSize):
        # Create the Renderer
        renderer = vtk.vtkRenderer()
        renderers.append(renderer)
        renWin.AddRenderer(renderer)

    for i in range(0, len(mcCases)):
        # Define a Single Cube
        Scalars = vtk.vtkFloatArray()
        Scalars.InsertNextValue(1.0)
        Scalars.InsertNextValue(0.0)
        Scalars.InsertNextValue(0.0)
        Scalars.InsertNextValue(1.0)
        Scalars.InsertNextValue(0.0)
        Scalars.InsertNextValue(0.0)
        Scalars.InsertNextValue(0.0)
        Scalars.InsertNextValue(0.0)

        Points = vtk.vtkPoints()
        Points.InsertNextPoint(0, 0, 0)
        Points.InsertNextPoint(1, 0, 0)
        Points.InsertNextPoint(1, 1, 0)
        Points.InsertNextPoint(0, 1, 0)
        Points.InsertNextPoint(0, 0, 1)
        Points.InsertNextPoint(1, 0, 1)
        Points.InsertNextPoint(1, 1, 1)
        Points.InsertNextPoint(0, 1, 1)

        Ids = vtk.vtkIdList()
        Ids.InsertNextId(0)
        Ids.InsertNextId(1)
        Ids.InsertNextId(2)
        Ids.InsertNextId(3)
        Ids.InsertNextId(4)
        Ids.InsertNextId(5)
        Ids.InsertNextId(6)
        Ids.InsertNextId(7)

        Grid = vtk.vtkUnstructuredGrid()
        Grid.Allocate(10, 10)
        Grid.InsertNextCell(12, Ids)
        Grid.SetPoints(Points)
        Grid.GetPointData().SetScalars(Scalars)

        # Find the triangles that lie along the 0.5 contour in this cube.
        Marching = vtk.vtkContourFilter()
        Marching.SetInputData(Grid)
        Marching.SetValue(0, 0.5)
        Marching.Update()

        # Extract the edges of the triangles just found.
        triangleEdges = vtk.vtkExtractEdges()
        triangleEdges.SetInputConnection(Marching.GetOutputPort())

        # Draw the edges as tubes instead of lines.  Also create the associated
        # mapper and actor to display the tubes.
        triangleEdgeTubes = vtk.vtkTubeFilter()
        triangleEdgeTubes.SetInputConnection(triangleEdges.GetOutputPort())
        triangleEdgeTubes.SetRadius(.005)
        triangleEdgeTubes.SetNumberOfSides(6)
        triangleEdgeTubes.UseDefaultNormalOn()
        triangleEdgeTubes.SetDefaultNormal(.577, .577, .577)

        triangleEdgeMapper = vtk.vtkPolyDataMapper()
        triangleEdgeMapper.SetInputConnection(
            triangleEdgeTubes.GetOutputPort())
        triangleEdgeMapper.ScalarVisibilityOff()

        triangleEdgeActor = vtk.vtkActor()
        triangleEdgeActor.SetMapper(triangleEdgeMapper)
        triangleEdgeActor.GetProperty().SetDiffuseColor(
            color.GetColor3d("lamp_black"))
        triangleEdgeActor.GetProperty().SetSpecular(.4)
        triangleEdgeActor.GetProperty().SetSpecularPower(10)

        # Shrink the triangles we found earlier.  Create the associated mapper
        # and actor.  Set the opacity of the shrunken triangles.
        aShrinker = vtk.vtkShrinkPolyData()
        aShrinker.SetShrinkFactor(1)
        aShrinker.SetInputConnection(Marching.GetOutputPort())

        aMapper = vtk.vtkPolyDataMapper()
        aMapper.ScalarVisibilityOff()
        aMapper.SetInputConnection(aShrinker.GetOutputPort())

        Triangles = vtk.vtkActor()
        Triangles.SetMapper(aMapper)
        Triangles.GetProperty().SetDiffuseColor(color.GetColor3d("banana"))
        Triangles.GetProperty().SetOpacity(.6)

        # Draw a cube the same size and at the same position as the one
        # created previously.  Extract the edges because we only want to see
        # the outline of the cube.  Pass the edges through a vtkTubeFilter so
        # they are displayed as tubes rather than lines.
        CubeModel = vtk.vtkCubeSource()
        CubeModel.SetCenter(.5, .5, .5)

        Edges = vtk.vtkExtractEdges()
        Edges.SetInputConnection(CubeModel.GetOutputPort())

        Tubes = vtk.vtkTubeFilter()
        Tubes.SetInputConnection(Edges.GetOutputPort())
        Tubes.SetRadius(.01)
        Tubes.SetNumberOfSides(6)
        Tubes.UseDefaultNormalOn()
        Tubes.SetDefaultNormal(.577, .577, .577)
        # Create the mapper and actor to display the cube edges.
        TubeMapper = vtk.vtkPolyDataMapper()
        TubeMapper.SetInputConnection(Tubes.GetOutputPort())
        CubeEdges = vtk.vtkActor()
        CubeEdges.SetMapper(TubeMapper)
        CubeEdges.GetProperty().SetDiffuseColor(color.GetColor3d("khaki"))
        CubeEdges.GetProperty().SetSpecular(.4)
        CubeEdges.GetProperty().SetSpecularPower(10)

        # Create a sphere to use as a glyph source for vtkGlyph3D.
        Sphere = vtk.vtkSphereSource()
        Sphere.SetRadius(0.04)
        Sphere.SetPhiResolution(20)
        Sphere.SetThetaResolution(20)
        # Remove the part of the cube with data values below 0.5.
        ThresholdIn = vtk.vtkThresholdPoints()
        ThresholdIn.SetInputData(Grid)
        ThresholdIn.ThresholdByUpper(.5)
        # Display spheres at the vertices remaining in the cube data set after
        # it was passed through vtkThresholdPoints.
        Vertices = vtk.vtkGlyph3D()
        Vertices.SetInputConnection(ThresholdIn.GetOutputPort())
        Vertices.SetSourceConnection(Sphere.GetOutputPort())
        # Create a mapper and actor to display the glyphs.
        SphereMapper = vtk.vtkPolyDataMapper()
        SphereMapper.SetInputConnection(Vertices.GetOutputPort())
        SphereMapper.ScalarVisibilityOff()

        CubeVertices = vtk.vtkActor()
        CubeVertices.SetMapper(SphereMapper)
        CubeVertices.GetProperty().SetDiffuseColor(color.GetColor3d("tomato"))

        # Define the text for the label
        caseLabel = vtk.vtkVectorText()
        caseLabel.SetText("Case 1")

        # Set up a transform to move the label to a new position.
        aLabelTransform = vtk.vtkTransform()
        aLabelTransform.Identity()
        aLabelTransform.Translate(-0.2, 0, 1.25)
        aLabelTransform.Scale(.05, .05, .05)

        # Move the label to a new position.
        labelTransform = vtk.vtkTransformPolyDataFilter()
        labelTransform.SetTransform(aLabelTransform)
        labelTransform.SetInputConnection(caseLabel.GetOutputPort())

        # Create a mapper and actor to display the text.
        labelMapper = vtk.vtkPolyDataMapper()
        labelMapper.SetInputConnection(labelTransform.GetOutputPort())

        labelActor = vtk.vtkActor()
        labelActor.SetMapper(labelMapper)

        # Define the base that the cube sits on.  Create its associated mapper
        # and actor.  Set the position of the actor.
        baseModel = vtk.vtkCubeSource()
        baseModel.SetXLength(1.5)
        baseModel.SetYLength(.01)
        baseModel.SetZLength(1.5)

        baseMapper = vtk.vtkPolyDataMapper()
        baseMapper.SetInputConnection(baseModel.GetOutputPort())

        base = vtk.vtkActor()
        base.SetMapper(baseMapper)
        base.SetPosition(.5, -0.09, .5)

        # Set the scalar values for this case of marching cubes.
        # A negative case number will generate a complementary case
        mcCase = mcCases[i]
        if mcCase < 0:
            cases[-mcCase](Scalars, caseLabel, 0, 1)
        else:
            cases[mcCase](Scalars, caseLabel, 1, 0)
        # Force the grid to update.
        Grid.Modified()

        # Add the actors to the renderer
        renderers[i].AddActor(triangleEdgeActor)
        renderers[i].AddActor(base)
        renderers[i].AddActor(labelActor)
        renderers[i].AddActor(CubeEdges)
        renderers[i].AddActor(CubeVertices)
        renderers[i].AddActor(Triangles)
        # Set the background color.
        renderers[i].SetBackground(color.GetColor3d("slate_grey"))

        # Position the camera.
        renderers[i].GetActiveCamera().Dolly(1.2)
        renderers[i].GetActiveCamera().Azimuth(30)
        renderers[i].GetActiveCamera().Elevation(20)
        renderers[i].ResetCamera()
        renderers[i].ResetCameraClippingRange()
        if i > 0:
            renderers[i].SetActiveCamera(renderers[0].GetActiveCamera())

    # Setup viewports for the renderers
    rendererSize = 300
    xGridDimensions = 4
    if len(mcCases) < 4:
        xGridDimensions = len(mcCases)
    yGridDimensions = (len(mcCases) - 1) // 4 + 1
    print("x, y:", xGridDimensions, ",", yGridDimensions)
    renWin.SetSize(rendererSize * xGridDimensions,
                   rendererSize * yGridDimensions)
    for row in range(0, yGridDimensions):
        for col in range(0, xGridDimensions):
            index = row * xGridDimensions + col

            # (xmin, ymin, xmax, ymax)
            viewport = [
                float(col) / xGridDimensions,
                float(yGridDimensions - (row + 1)) / yGridDimensions,
                float(col + 1) / xGridDimensions,
                float(yGridDimensions - row) / yGridDimensions
            ]

            renderers[index].SetViewport(viewport)

    iren.Initialize()
    renWin.Render()
    iren.Start()
Beispiel #14
0
def main():
    fileName = r"carotid.vtk"

    colors = vtk.vtkNamedColors()

    ren1 = vtk.vtkRenderer()

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Create the pipeline.
    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(fileName)

    psource = vtk.vtkPointSource()
    psource.SetNumberOfPoints(25)
    psource.SetCenter(133.1, 116.3, 5.0)
    psource.SetRadius(2.0)

    threshold = vtk.vtkThresholdPoints()
    threshold.SetInputConnection(reader.GetOutputPort())
    threshold.ThresholdByUpper(275)

    streamers = vtk.vtkStreamTracer()
    streamers.SetInputConnection(reader.GetOutputPort())
    streamers.SetSourceConnection(psource.GetOutputPort())
    streamers.SetMaximumPropagation(100.0)
    streamers.SetInitialIntegrationStep(0.2)
    streamers.SetTerminalSpeed(.01)
    streamers.Update()
    scalarRange = [0] * 2
    scalarRange[0] = streamers.GetOutput().GetPointData().GetScalars(
    ).GetRange()[0]
    scalarRange[1] = streamers.GetOutput().GetPointData().GetScalars(
    ).GetRange()[1]

    tubes = vtk.vtkTubeFilter()
    tubes.SetInputConnection(streamers.GetOutputPort())
    tubes.SetRadius(0.3)
    tubes.SetNumberOfSides(6)
    tubes.SetVaryRadius(0)

    lut = vtk.vtkLookupTable()
    lut.SetHueRange(.667, 0.0)
    lut.Build()

    streamerMapper = vtk.vtkPolyDataMapper()
    streamerMapper.SetInputConnection(tubes.GetOutputPort())
    streamerMapper.SetScalarRange(scalarRange[0], scalarRange[1])
    streamerMapper.SetLookupTable(lut)

    streamerActor = vtk.vtkActor()
    streamerActor.SetMapper(streamerMapper)

    # Speed contours.
    iso = vtk.vtkContourFilter()
    iso.SetInputConnection(reader.GetOutputPort())
    iso.SetValue(0, 175)

    isoMapper = vtk.vtkPolyDataMapper()
    isoMapper.SetInputConnection(iso.GetOutputPort())
    isoMapper.ScalarVisibilityOff()

    isoActor = vtk.vtkActor()
    isoActor.SetMapper(isoMapper)
    isoActor.GetProperty().SetRepresentationToWireframe()
    isoActor.GetProperty().SetOpacity(0.25)

    # Outline
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(reader.GetOutputPort())

    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(0., 0., 0.)

    # Add the actors to the renderer, set the background and size.
    ren1.AddActor(outlineActor)
    ren1.AddActor(streamerActor)
    ren1.AddActor(isoActor)
    ren1.SetBackground(1., 1., 1.)
    renWin.SetSize(640, 480)

    ren1.ResetCamera()
    ren1.ResetCameraClippingRange()

    # Render the image.
    renWin.Render()
    iren.Start()
def main():
    fileName = get_program_parameters()

    colors = vtk.vtkNamedColors()

    ren1 = vtk.vtkRenderer()

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Create the pipeline.
    #
    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(fileName)

    threshold = vtk.vtkThresholdPoints()
    threshold.SetInputConnection(reader.GetOutputPort())
    threshold.ThresholdByUpper(200)

    mask = vtk.vtkMaskPoints()
    mask.SetInputConnection(threshold.GetOutputPort())
    mask.SetOnRatio(5)

    cone = vtk.vtkConeSource()
    cone.SetResolution(11)
    cone.SetHeight(1)
    cone.SetRadius(0.25)

    cones = vtk.vtkGlyph3D()
    cones.SetInputConnection(mask.GetOutputPort())
    cones.SetSourceConnection(cone.GetOutputPort())
    cones.SetScaleFactor(0.4)
    cones.SetScaleModeToScaleByVector()

    lut = vtk.vtkLookupTable()
    lut.SetHueRange(.667, 0.0)
    lut.Build()

    scalarRange = [0] * 2
    cones.Update()
    scalarRange[0] = cones.GetOutput().GetPointData().GetScalars().GetRange(
    )[0]
    scalarRange[1] = cones.GetOutput().GetPointData().GetScalars().GetRange(
    )[1]
    print("range: ", scalarRange[0], ", ", scalarRange[1])

    vectorMapper = vtk.vtkPolyDataMapper()
    vectorMapper.SetInputConnection(cones.GetOutputPort())
    vectorMapper.SetScalarRange(scalarRange[0], scalarRange[1])
    vectorMapper.SetLookupTable(lut)

    vectorActor = vtk.vtkActor()
    vectorActor.SetMapper(vectorMapper)

    # Speed contours.
    iso = vtk.vtkContourFilter()
    iso.SetInputConnection(reader.GetOutputPort())
    iso.SetValue(0, 175)

    isoMapper = vtk.vtkPolyDataMapper()
    isoMapper.SetInputConnection(iso.GetOutputPort())
    isoMapper.ScalarVisibilityOff()

    isoActor = vtk.vtkActor()
    isoActor.SetMapper(isoMapper)
    isoActor.GetProperty().SetRepresentationToWireframe()
    isoActor.GetProperty().SetOpacity(0.25)

    # Outline
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(reader.GetOutputPort())

    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(colors.GetColor3d("Black"))

    # Add the actors to the renderer, set the background and size.
    #
    ren1.AddActor(outlineActor)
    ren1.AddActor(vectorActor)
    ren1.AddActor(isoActor)
    ren1.SetBackground(colors.GetColor3d("Wheat"))
    renWin.SetSize(640, 480)
    renWin.SetWindowName('CarotidFlowGlyphs')

    cam1 = vtk.vtkCamera()
    cam1.SetClippingRange(17.4043, 870.216)
    cam1.SetFocalPoint(136.71, 104.025, 23)
    cam1.SetPosition(204.747, 258.939, 63.7925)
    cam1.SetViewUp(-0.102647, -0.210897, 0.972104)
    cam1.Zoom(1.2)
    ren1.SetActiveCamera(cam1)

    # Render the image.
    #
    renWin.Render()
    iren.Start()
Beispiel #16
0
def main():
    fileName = get_program_parameters()

    colors = vtk.vtkNamedColors()

    ren1 = vtk.vtkRenderer()

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Create the pipeline.
    #
    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(fileName)

    psource = vtk.vtkPointSource()
    psource.SetNumberOfPoints(25)
    psource.SetCenter(133.1, 116.3, 5.0)
    psource.SetRadius(2.0)

    threshold = vtk.vtkThresholdPoints()
    threshold.SetInputConnection(reader.GetOutputPort())
    threshold.ThresholdByUpper(275)

    streamers = vtk.vtkStreamTracer()
    streamers.SetInputConnection(reader.GetOutputPort())
    streamers.SetSourceConnection(psource.GetOutputPort())
    # streamers.SetMaximumPropagationUnitToTimeUnit()
    streamers.SetMaximumPropagation(100.0)
    # streamers.SetInitialIntegrationStepUnitToCellLengthUnit()
    streamers.SetInitialIntegrationStep(0.2)
    streamers.SetTerminalSpeed(.01)
    streamers.Update()
    scalarRange = [0] * 2
    scalarRange[0] = streamers.GetOutput().GetPointData().GetScalars(
    ).GetRange()[0]
    scalarRange[1] = streamers.GetOutput().GetPointData().GetScalars(
    ).GetRange()[1]
    print("range: ", scalarRange[0], ", ", scalarRange[1])

    tubes = vtk.vtkTubeFilter()
    tubes.SetInputConnection(streamers.GetOutputPort())
    tubes.SetRadius(0.3)
    tubes.SetNumberOfSides(6)
    tubes.SetVaryRadius(0)

    lut = vtk.vtkLookupTable()
    lut.SetHueRange(.667, 0.0)
    lut.Build()

    streamerMapper = vtk.vtkPolyDataMapper()
    streamerMapper.SetInputConnection(tubes.GetOutputPort())
    streamerMapper.SetScalarRange(scalarRange[0], scalarRange[1])
    streamerMapper.SetLookupTable(lut)

    streamerActor = vtk.vtkActor()
    streamerActor.SetMapper(streamerMapper)

    # Speed contours.
    iso = vtk.vtkContourFilter()
    iso.SetInputConnection(reader.GetOutputPort())
    iso.SetValue(0, 175)

    isoMapper = vtk.vtkPolyDataMapper()
    isoMapper.SetInputConnection(iso.GetOutputPort())
    isoMapper.ScalarVisibilityOff()

    isoActor = vtk.vtkActor()
    isoActor.SetMapper(isoMapper)
    isoActor.GetProperty().SetRepresentationToWireframe()
    isoActor.GetProperty().SetOpacity(0.25)

    # Outline
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(reader.GetOutputPort())

    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(colors.GetColor3d("Black"))

    # Add the actors to the renderer, set the background and size.
    #
    ren1.AddActor(outlineActor)
    ren1.AddActor(streamerActor)
    ren1.AddActor(isoActor)
    ren1.SetBackground(colors.GetColor3d("Wheat"))
    renWin.SetSize(640, 480)

    cam1 = vtk.vtkCamera()
    cam1.SetClippingRange(17.4043, 870.216)
    cam1.SetFocalPoint(136.71, 104.025, 23)
    cam1.SetPosition(204.747, 258.939, 63.7925)
    cam1.SetViewUp(-0.102647, -0.210897, 0.972104)
    cam1.Zoom(1.6)
    ren1.SetActiveCamera(cam1)

    # Render the image.
    #
    renWin.Render()
    iren.Start()
Beispiel #17
0
def opyfFindBlobs3D(scalars,
                    th1,
                    th2=None,
                    R=1.,
                    minArea=None,
                    CenterType='barycenter'):
    if th2 is None:
        th2 = np.max(scalars)

    [h, w, p] = scalars.shape
    scalars = scalars.T.copy()
    scalars = scalars.ravel()
    #    (scalars>=th1)*(scalars<=th2)
    #    indth=np.where((scalars>=th1)*(scalars<=th2))
    # Points XYZ
    x, y, z = np.mgrid[0:h, 0:w, 0:p]
    pts = np.empty(z.shape + (3, ), dtype=float)
    pts[..., 0] = x
    pts[..., 1] = y
    pts[..., 2] = z
    pts = pts.transpose(2, 1, 0, 3).copy()
    pts.shape = pts.size / 3, 3

    # VTK
    points = vtk.vtkPoints()
    points.SetDataTypeToDouble()

    for [x, y, z] in pts:
        points.InsertNextPoint(x, y, z)

    Scalarsvtk = vtk.vtkFloatArray()

    for s in scalars:
        Scalarsvtk.InsertNextValue(s)
    Ids = vtk.vtkIdList()

    polydata = vtk.vtkPolyData()
    #    polydata=vtk.vtkUnstructuredGrid()
    polydata.SetPoints(points)
    polydata.GetPointData().SetScalars(Scalarsvtk)

    ThresholdIn = vtk.vtkThresholdPoints()
    ThresholdIn.SetInputData(polydata)
    # ThresholdIn.ThresholdByLower(230.)
    ThresholdIn.ThresholdBetween(th1, th2)

    ThresholdIn.Update()

    PointsThresh = ThresholdIn.GetOutput().GetPoints()

    staticLocator = vtk.vtkStaticPointLocator()
    staticLocator.SetDataSet(ThresholdIn.GetOutput())
    staticLocator.SetNumberOfPointsPerBucket(5)
    staticLocator.AutomaticOn()

    staticLocator.BuildLocator()

    S = ThresholdIn.GetOutput().GetPointData().GetArray(0)
    nppointsArr = vtk_to_numpy(S)

    idspointsThresh = np.arange(0, PointsThresh.GetNumberOfPoints())
    entitiy = 0
    i = idspointsThresh[0]
    idsStored = np.array([])
    ids1 = [0]

    C = 1
    blob3D = []
    indstore = 0

    while len(idspointsThresh) > 0:
        C = 1
        while C == 1:
            ids2 = []
            l = len(idsStored)
            for i in ids1:
                PointswhithinRadius = vtk.vtkIdList()
                staticLocator.FindPointsWithinRadius(R,
                                                     PointsThresh.GetPoint(i),
                                                     PointswhithinRadius)

                for j in range(PointswhithinRadius.GetNumberOfIds()):
                    tempid = PointswhithinRadius.GetId(j)
                    if len(np.where(idsStored == tempid)[0]) == 0:
                        idsStored = np.append(idsStored, np.int(tempid))
                        ids2.append(tempid)
                        indDel = np.where(idspointsThresh == tempid)
                        idspointsThresh = np.delete(idspointsThresh, indDel, 0)

            if len(idsStored) == l:
                C = 0
                blob3D.append(idsStored[indstore:].astype(int))
                indstore = len(idsStored)
                entitiy += 1
                if len(idspointsThresh) > 0:
                    ids1 = [idspointsThresh[0]]
            else:
                ids1 = ids2

    C = np.zeros((len(blob3D), 3))

    AreaBlob = []
    X = vtk_to_numpy(PointsThresh.GetData())
    blob3Dout = []
    for i in range(len(blob3D)):
        ind = blob3D[i]

        Xblob = X[ind]
        blob3Dout.append(Xblob)
        pxInts = nppointsArr[ind]
        if CenterType == 'barycenter':
            C[i, :] = np.sum(Xblob * np.array([pxInts, pxInts, pxInts]).T,
                             axis=0) / (np.sum(pxInts))
        elif CenterType == 'geometric':
            C[i, :] = np.sum(Xblob, axis=0) / (np.float(len(pxInts)))
        AreaBlob.append(len(Xblob))
    AreaBlob = np.array(AreaBlob)
    blob3Dout = np.array(blob3Dout)
    if minArea is not None:
        C = C[np.where(AreaBlob > minArea)]
        blob3Dout = blob3Dout[np.where(AreaBlob > minArea)]
        AreaBlob = AreaBlob[np.where(AreaBlob > minArea)]

    return blob3Dout, C, AreaBlob
Beispiel #18
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

# wireframe

# test proba
#self.ref0 = vtk.vtkThreshold() # necesario en selrF_
#self.ref0.SetInputConnection(self.src.GetOutputPort())
#self.ref0.ThresholdByLower(0.999) # valor inclusive

        self.wireM = vtk.vtkDataSetMapper()
        # test proba
        #self.wireM.SetInputConnection(self.ref0.GetOutputPort())
        self.wireM.SetInputConnection(self.src.GetOutputPort())
        self.wireM.ScalarVisibilityOff()

        self.wireA = vtk.vtkActor()
        self.wireA.SetMapper(self.wireM)
        self.wireA.GetProperty().SetRepresentationToWireframe()
        self.wireA.GetProperty().SetColor(Plot.mesh3_color)
        self.wireA.SetVisibility(0)

        self.add_outline_2(self.src)

        if self.has_field:

            # reference labels
            if self.data1.get('fielddomain') == 'point':
                self.refsT = vtk.vtkThresholdPoints()
                self.refsT.SetInputConnection(self.src.GetOutputPort())
                self.refsT.ThresholdByUpper(1.0 - epsilon)
            else:
                self.refsT = vtk.vtkThreshold()  # necesario en selrF_
                self.refsT.SetInputConnection(self.src.GetOutputPort())
                self.refsT.ThresholdByUpper(1.0 - epsilon)
#            self.refsT.SetInputArrayToProcess(1, 0, 0, 0, self.fieldname)
#            self.refsT.SetAttributeModeToUseCellData()

            if self.data1.get('fielddomain') == 'point':
                label_con = self.refsT.GetOutputPort()
            else:
                self.ccrF = vtk.vtkCellCenters()
                self.ccrF.SetInputConnection(self.refsT.GetOutputPort())
                label_con = self.ccrF.GetOutputPort()

            self.lrM = vtk.vtkLabeledDataMapper()
            self.lrM.SetInputConnection(label_con)
            self.lrM.SetLabelModeToLabelScalars()
            self.lrM.GetLabelTextProperty().SetColor(Plot.label_color)

            self.lrA = vtk.vtkActor2D()
            self.lrA.SetMapper(self.lrM)
            self.lrA.SetVisibility(0)

            # CELL  POINT  FIELD  VERTEX  EDGE
            if self.data1.get('fielddomain') == 'point':
                ftype = 1  # vtkSelection::POINT
            else:
                ftype = 0  # vtkSelection::CELL

# selected edges
            self.selr = vtk.vtkSelectionSource()
            self.selr.SetContentType(7)  # vtkSelection::THRESHOLDS
            self.selr.SetFieldType(ftype)
            if self.data1.get(
                    'fielddomain'
            ) == 'point':  # necesario para los puntos, sino colapsa
                self.selr.SetContainingCells(0)

# unselected edges
            self.selr_ = vtk.vtkSelectionSource()
            self.selr_.SetContentType(7)  # vtkSelection::THRESHOLDS
            self.selr_.SetFieldType(ftype)
            if self.data1.get(
                    'fielddomain'
            ) == 'point':  # necesario para los puntos, sino colapsa
                self.selr_.SetContainingCells(0)
            self.selr_.SetInverse(1)

            self.selrF = vtk.vtkExtractSelectedThresholds()
            #self.selrF.SetInputConnection(self.src.GetOutputPort()) # por que era asi? # x1sbc
            self.selrF.SetInputConnection(self.refsT.GetOutputPort())
            self.selrF.SetSelectionConnection(self.selr.GetOutputPort())

            self.selrF_ = vtk.vtkExtractSelectedThresholds()
            self.selrF_.SetInputConnection(self.refsT.GetOutputPort())  #
            self.selrF_.SetSelectionConnection(self.selr_.GetOutputPort())

            self.selrM = vtk.vtkDataSetMapper()
            self.selrM.SetInputConnection(self.selrF.GetOutputPort())
            if not several_colors:
                self.selrM.ScalarVisibilityOff()

            self.selrM_ = vtk.vtkDataSetMapper()
            self.selrM_.SetInputConnection(self.selrF_.GetOutputPort())
            self.selrM_.ScalarVisibilityOff()

            self.selrM.SetScalarRange(self.change_range(self.src))

            self.selrA = vtk.vtkActor()
            self.selrA.SetMapper(self.selrM)
            if not several_colors:
                self.selrA.GetProperty().SetColor(Plot.mesh2_color)
            if self.data1.get('fielddomain') == 'point':
                self.selrA.GetProperty().SetRepresentationToPoints()
            else:
                self.selrA.GetProperty().SetRepresentationToSurface()

            self.selrA_ = vtk.vtkActor()
            self.selrA_.SetMapper(self.selrM_)
            if several_colors:
                self.selrA_.GetProperty().SetColor(Plot.unselected_color)
            else:
                self.selrA_.GetProperty().SetColor(Plot.mesh_color)
            if self.data1.get('fielddomain') == 'point':
                self.selrA_.GetProperty().SetRepresentationToPoints()
            else:
                self.selrA_.GetProperty().SetRepresentationToWireframe()

            if self.data1.get('fielddomain') == 'point':
                self.selrA.GetProperty().SetPointSize(3.0)
                self.selrA_.GetProperty().SetPointSize(2.0)

            # lóxica dudosa: depende do nome do campo
            if self.data1.get('fieldname') == 'edge_ref':
                self.selrA.GetProperty().SetLineWidth(5.0)
                self.selrA_.GetProperty().SetLineWidth(5.0)

            self.update_thresholds(struct, True)

            # Add the actors to the render
            self.rens[0].AddActor(self.selrA_)  # unselected
            self.rens[0].AddActor(self.selrA)  # selected
            self.rens[0].AddActor(self.lrA)  # labels

        self.rens[0].AddActor(self.wireA)  # mesh

        self.set_iren()
        self.iren.AddObserver("LeftButtonPressEvent", self.ButtonEvent)

        if self.data1.get('fielddomain') == 'cell':
            self.picker = vtk.vtkCellPicker()
        else:
            self.picker = vtk.vtkPointPicker()
        self.picker.AddObserver("EndPickEvent", self.EndPick)
        self.iren.SetPicker(self.picker)

        self.done = True
def main():
    fileNames = [''] * 2
    fileNames[0], fileNames[1] = get_program_parameters()

    # Generate the other vecAnim file names. There are 8 of them.
    tmpFn = fileNames[1][:-5]
    for i in range(2, 9):
        fileNames.append(tmpFn + str(i) + '.vtk')

    colors = vtk.vtkNamedColors()

    # Setup the render window, renderer, and interactor.
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    # Read the data.
    #
    # Create the pipeline.
    #
    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(fileNames[0])

    threshold = vtk.vtkThresholdPoints()
    threshold.SetInputConnection(reader.GetOutputPort())
    threshold.ThresholdByUpper(200)

    line = vtk.vtkLineSource()
    line.SetResolution(1)

    lines = vtk.vtkGlyph3D()
    lines.SetInputConnection(threshold.GetOutputPort())
    lines.SetSourceConnection(line.GetOutputPort())
    lines.SetScaleFactor(0.005)
    lines.SetScaleModeToScaleByScalar()
    lines.Update()

    vectorMapper = vtk.vtkPolyDataMapper()
    vectorMapper.SetInputConnection(lines.GetOutputPort())
    vectorMapper.SetScalarRange(lines.GetOutput().GetScalarRange())

    vectorActor = vtk.vtkActor()
    vectorActor.SetMapper(vectorMapper)
    vectorActor.GetProperty().SetOpacity(0.99)
    vectorActor.GetProperty().SetLineWidth(1.5)

    # Outline
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(reader.GetOutputPort())

    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(colors.GetColor3d('Black'))

    #  Texture maps.
    textureMaps = list()
    for i in range(2, len(fileNames)):
        tmap = vtk.vtkStructuredPointsReader()
        tmap.SetFileName(fileNames[i])

        texture = vtk.vtkTexture()
        texture.SetInputConnection(tmap.GetOutputPort())
        texture.InterpolateOff()
        texture.RepeatOff()
        textureMaps.append(texture)

    vectorActor.SetTexture(textureMaps[0])

    # Add the actors to the renderer, set the background and size.
    #
    renderer.AddActor(vectorActor)
    renderer.AddActor(outlineActor)

    cam1 = vtk.vtkCamera()
    cam1.SetClippingRange(17.4043, 870.216)
    cam1.SetFocalPoint(136.71, 104.025, 23)
    cam1.SetPosition(204.747, 258.939, 63.7925)
    cam1.SetViewUp(-0.102647, -0.210897, 0.972104)
    cam1.Zoom(1.2)
    renderer.SetActiveCamera(cam1)

    renderer.SetBackground(colors.GetColor3d('Wheat'))
    renderWindow.SetSize(640, 480)
    renderWindow.SetWindowName('AnimateVectors')

    # Go into a loop.
    for j in range(0, 100):
        for i in range(0, len(textureMaps)):
            vectorActor.SetTexture(textureMaps[i])
            renderWindow.Render()
    interactor.Start()
    def __init__(self, parent, data_dir):
        super(QGlyphViewer, self).__init__(parent)

        # Make tha actual QtWidget a child so that it can be re parented
        interactor = QVTKRenderWindowInteractor(self)
        self.layout = QtWidgets.QHBoxLayout()
        self.layout.addWidget(interactor)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.layout)

        # Read the data
        xyx_file = os.path.join(data_dir, "combxyz.bin")
        q_file = os.path.join(data_dir, "combq.bin")
        pl3d = vtk.vtkMultiBlockPLOT3DReader()
        pl3d.SetXYZFileName(xyx_file)
        pl3d.SetQFileName(q_file)
        pl3d.SetScalarFunctionNumber(100)
        pl3d.SetVectorFunctionNumber(202)
        pl3d.Update()

        blocks = pl3d.GetOutput()
        b0 = blocks.GetBlock(0)

        # Setup VTK environment
        renderer = vtk.vtkRenderer()
        render_window = interactor.GetRenderWindow()
        render_window.AddRenderer(renderer)

        interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
        render_window.SetInteractor(interactor)
        renderer.SetBackground(0.2, 0.2, 0.2)

        # Draw Outline
        outline = vtk.vtkStructuredGridOutlineFilter()
        outline.SetInputData(b0)
        outline_mapper = vtk.vtkPolyDataMapper()
        outline_mapper.SetInputConnection(outline.GetOutputPort())
        outline_actor = vtk.vtkActor()
        outline_actor.SetMapper(outline_mapper)
        outline_actor.GetProperty().SetColor(1, 1, 1)
        renderer.AddActor(outline_actor)
        renderer.ResetCamera()

        # Draw Outline
        outline = vtk.vtkStructuredGridOutlineFilter()
        outline.SetInputData(b0)
        outline_mapper = vtk.vtkPolyDataMapper()
        outline_mapper.SetInputConnection(outline.GetOutputPort())
        outline_actor = vtk.vtkActor()
        outline_actor.SetMapper(outline_mapper)
        outline_actor.GetProperty().SetColor(1, 1, 1)
        renderer.AddActor(outline_actor)
        renderer.ResetCamera()

        # Threshold points
        threshold = vtk.vtkThresholdPoints()
        threshold.SetInputData(b0)
        threshold.ThresholdByUpper(0.5)

        # Draw arrows
        arrow = vtk.vtkArrowSource()
        glyphs = vtk.vtkGlyph3D()
        glyphs.SetInputData(b0)
        glyphs.SetSourceConnection(arrow.GetOutputPort())
        glyphs.SetInputConnection(threshold.GetOutputPort())

        glyphs.SetVectorModeToUseVector()
        glyphs.SetScaleModeToScaleByVector()
        glyphs.SetScaleFactor(0.005)
        glyphs.SetColorModeToColorByVector()

        # Mapper
        glyph_mapper = vtk.vtkPolyDataMapper()
        glyph_mapper.SetInputConnection(glyphs.GetOutputPort())
        glyph_actor = vtk.vtkActor()
        glyph_actor.SetMapper(glyph_mapper)

        glyph_mapper.UseLookupTableScalarRangeOn()
        renderer.AddActor(glyph_actor)

        # Set color lookuptable
        glyphs.Update()
        s0, sf = glyphs.GetOutput().GetScalarRange()
        lut = vtk.vtkColorTransferFunction()
        lut.AddRGBPoint(s0, 1, 0, 0)
        lut.AddRGBPoint(sf, 0, 1, 0)
        glyph_mapper.SetLookupTable(lut)

        # Register pick listener

        self.b0 = b0
        self.renderer = renderer
        self.interactor = interactor
        self.threshold = threshold
        self.render_window = render_window
        self.picker = vtk.vtkCellPicker()
        self.picker.AddObserver("EndPickEvent", self.process_pick)
        self.interactor.SetPicker(self.picker)
        self.glyphs = glyphs
Beispiel #21
0
Tubes.UseDefaultNormalOn()
Tubes.SetDefaultNormal(.577, .577, .577)
TubeMapper = vtk.vtkPolyDataMapper()
TubeMapper.SetInputConnection(Tubes.GetOutputPort())
CubeEdges = vtk.vtkActor()
CubeEdges.SetMapper(TubeMapper)
CubeEdges.GetProperty().SetDiffuseColor(khaki)
CubeEdges.GetProperty().SetSpecular(.4)
CubeEdges.GetProperty().SetSpecularPower(10)
# build the vertices of the cube
#
Sphere = vtk.vtkSphereSource()
Sphere.SetRadius(0.04)
Sphere.SetPhiResolution(20)
Sphere.SetThetaResolution(20)
ThresholdIn = vtk.vtkThresholdPoints()
ThresholdIn.SetInputData(Grid)
ThresholdIn.ThresholdByUpper(.5)
Vertices = vtk.vtkGlyph3D()
Vertices.SetInputConnection(ThresholdIn.GetOutputPort())
Vertices.SetSourceConnection(Sphere.GetOutputPort())
SphereMapper = vtk.vtkPolyDataMapper()
SphereMapper.SetInputConnection(Vertices.GetOutputPort())
SphereMapper.ScalarVisibilityOff()
CubeVertices = vtk.vtkActor()
CubeVertices.SetMapper(SphereMapper)
CubeVertices.GetProperty().SetDiffuseColor(tomato)
CubeVertices.GetProperty().SetDiffuseColor(tomato)
#define the text for the labels
caseLabel = vtk.vtkVectorText()
caseLabel.SetText("Case 2")
Beispiel #22
0
def normalizeVessels2(case_dir,
                      dist_from_bif_inlet=35,
                      dist_from_bif_outlet=35):
    # phases = ["baseline","baseline-post","12months","followup"]
    phases = ["baseline"]

    centerlines = {}
    surfaces = {}

    for phase in phases:
        if not os.path.exists(os.path.join(case_dir, phase, "centerline.vtp")):
            continue
        # load the centerline file
        reader = vtk.vtkXMLPolyDataReader()
        reader.SetFileName(os.path.join(case_dir, phase, "centerline.vtp"))
        reader.Update()
        centerline = reader.GetOutput()
        centerlines.update({phase: centerline})

        # load surface files
        if not os.path.exists(os.path.join(case_dir, phase, "surface.stl")):
            continue
        # reader = vtk.vtkGenericDataObjectReader()
        reader = vtk.vtkSTLReader()
        reader.SetFileName(os.path.join(case_dir, phase, "surface.stl"))
        reader.Update()
        surface = reader.GetOutput()
        surfaces.update({phase: surface})

    # get the bifurcation point from baseline data
    # split the polydata by centerline id
    splitter = vtk.vtkThreshold()
    splitter.SetInputData(centerlines["baseline"])
    splitter.ThresholdBetween(0, 0)
    splitter.SetInputArrayToProcess(0, 0, 0,
                                    vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS,
                                    "GroupIds")
    splitter.Update()
    mainBranch = splitter.GetOutput()

    maxAbsc = 0
    maxAbscId = 0

    for i in range(mainBranch.GetNumberOfPoints()):
        absc = mainBranch.GetPointData().GetArray("Abscissas").GetComponent(
            i, 0)
        if absc > maxAbsc:
            maxAbsc = absc
            maxAbscId = i

    bifPoint = mainBranch.GetPoint(maxAbscId)

    thresholdFilter = vtk.vtkThresholdPoints()
    thresholdFilter.SetInputData(centerlines["baseline"])
    thresholdFilter.ThresholdBetween(4.4156, 74.4156)
    thresholdFilter.SetInputArrayToProcess(
        0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, "Abscissas")
    thresholdFilter.Update()

    vtpWriter = vtk.vtkXMLPolyDataWriter()
    vtpWriter.SetFileName(
        os.path.join(case_dir, phase, "centerline_clipped.vtp"))
    vtpWriter.SetInputData(thresholdFilter.GetOutput())
    vtpWriter.Update()