Beispiel #1
0
    def legosurface(self, vmin=None, vmax=None, invert=False, cmap='afmhot_r'):
        """
        Represent a ``Volume`` as lego blocks (voxels).
        By default colors correspond to the volume's scalar.
        Returns an ``Mesh``.

        :param float vmin: the lower threshold, voxels below this value are not shown.
        :param float vmax: the upper threshold, voxels above this value are not shown.
        :param str cmap: color mapping of the scalar associated to the voxels.

        |legosurface| |legosurface.py|_
        """
        dataset = vtk.vtkImplicitDataSet()
        dataset.SetDataSet(self._imagedata)
        window = vtk.vtkImplicitWindowFunction()
        window.SetImplicitFunction(dataset)

        srng = list(self._imagedata.GetScalarRange())
        if vmin is not None:
            srng[0] = vmin
        if vmax is not None:
            srng[1] = vmax
        tol = 0.00001*(srng[1]-srng[0])
        srng[0] -= tol
        srng[1] += tol
        window.SetWindowRange(srng)

        extract = vtk.vtkExtractGeometry()
        extract.SetInputData(self._imagedata)
        extract.SetImplicitFunction(window)
        extract.SetExtractInside(invert)
        extract.ExtractBoundaryCellsOff()
        extract.Update()

        gf = vtk.vtkGeometryFilter()
        gf.SetInputData(extract.GetOutput())
        gf.Update()

        a = Mesh(gf.GetOutput()).lw(0.1).flat()
        scalars = a.getPointArray()
        if scalars is None:
            print("Error in legosurface(): no scalars found!")
            return a
        a.pointColors(scalars, vmin=srng[0], vmax=srng[1], cmap=cmap)
        a.mapPointsToCells()
        return a
Beispiel #2
0
# Example demonstrates how to generate a 3D tetrahedra mesh from a
# volume. This example differs from the previous clipVolume.tcl examples
# in that it uses the slower ordered triangulator and generates clip scalars.
# Quadric definition
quadric = vtk.vtkQuadric()
quadric.SetCoefficients([.5,1,.2,0,.1,0,0,.2,0,0])
sample = vtk.vtkSampleFunction()
sample.SetSampleDimensions(20,20,20)
sample.SetImplicitFunction(quadric)
sample.ComputeNormalsOff()
sample.Update()
# Program a bandpass filter to clip a range of data. What we do is transform the
# scalars so that values laying betweeen (minRange,maxRange) are >= 0.0; all
# others are < 0.0,
dataset = vtk.vtkImplicitDataSet()
dataset.SetDataSet(sample.GetOutput())
window = vtk.vtkImplicitWindowFunction()
window.SetImplicitFunction(dataset)
window.SetWindowRange(0.5,1.0)
# Generate tetrahedral mesh
clip = vtk.vtkClipVolume()
clip.SetInputConnection(sample.GetOutputPort())
clip.SetClipFunction(window)
clip.SetValue(0.0)
clip.GenerateClippedOutputOff()
clip.Mixed3DCellGenerationOff()
gf = vtk.vtkGeometryFilter()
#  gf SetInput [clip GetClippedOutput]
gf.SetInputConnection(clip.GetOutputPort())
clipMapper = vtk.vtkPolyDataMapper()
Beispiel #3
0
VTK_DATA_ROOT = vtkGetDataRoot()

# Example demonstrates how to generate a 3D tetrahedra mesh from a volume. This example
# differs from clipVolume.tcl in that the mesh is generated within a range of contour values.
#
# Quadric definition
quadric = vtk.vtkQuadric()
quadric.SetCoefficients([.5,1,.2,0,.1,0,0,.2,0,0])
sample = vtk.vtkSampleFunction()
sample.SetSampleDimensions(20,20,20)
sample.SetImplicitFunction(quadric)
sample.ComputeNormalsOff()
# Program a bandpass filter to clip a range of data. What we do is transform the
# scalars so that values laying betweeen (minRange,maxRange) are >= 0.0; all
# others are < 0.0,
dataset = vtk.vtkImplicitDataSet()
dataset.SetDataSet(sample.GetOutput())
window = vtk.vtkImplicitWindowFunction()
window.SetImplicitFunction(dataset)
window.SetWindowRange(0.5,1.0)
# Generate tetrahedral mesh
clip = vtk.vtkClipVolume()
clip.SetInputConnection(sample.GetOutputPort())
clip.SetClipFunction(window)
clip.SetValue(0.0)
clip.GenerateClippedOutputOff()
clipMapper = vtk.vtkDataSetMapper()
clipMapper.SetInputConnection(clip.GetOutputPort())
clipMapper.ScalarVisibilityOff()
clipActor = vtk.vtkActor()
clipActor.SetMapper(clipMapper)
    def __init__(self, parent = None):
        super(VTKFrame, self).__init__(parent)

        self.vtkWidget = QVTKRenderWindowInteractor(self)
        vl = QtGui.QVBoxLayout(self)
        vl.addWidget(self.vtkWidget)
        vl.setContentsMargins(0, 0, 0, 0)
 
        self.ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
         
        sphere = vtk.vtkSphereSource()
        sphere.SetCenter(1, 1, 1)
        sphere.SetRadius(1)
        sphere.SetThetaResolution(100)
        sphere.SetPhiResolution(100)
        sphere.Update()
         
        cube = vtk.vtkCubeSource()
        cube.SetBounds(-1,1,-1,1,-1,1)
        cube.Update()
         
        # Create 3D cells so vtkImplicitDataSet evaluates inside vs outside correctly
        tri = vtk.vtkDelaunay3D()
        tri.SetInput(cube.GetOutput())
        tri.BoundingTriangulationOff()
         
        # vtkImplicitDataSet needs some scalars to interpolate to find inside/outside
        elev = vtk.vtkElevationFilter()
        elev.SetInputConnection(tri.GetOutputPort())
         
        implicit = vtk.vtkImplicitDataSet()
        implicit.SetDataSet(elev.GetOutput())
         
        clipper = vtk.vtkClipPolyData()
        clipper.SetClipFunction(implicit)
        clipper.SetInputConnection(sphere.GetOutputPort())
        clipper.InsideOutOn()
        clipper.Update()
         
        # Vis for clipped sphere
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(clipper.GetOutputPort())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetRepresentationToWireframe()
         
        # Vis for cube so can see it in relation to clipped sphere
        mapper2 = vtk.vtkDataSetMapper()
        mapper2.SetInputConnection(elev.GetOutputPort())
        actor2 = vtk.vtkActor()
        actor2.SetMapper(mapper2)
        #actor2.GetProperty().SetRepresentationToWireframe()
         
        #create renderers and add actors of plane and cube
        self.ren.AddActor(actor)
        self.ren.AddActor(actor2)
        self.ren.SetBackground(0.1, 0.2, 0.4)

        self.ren.ResetCamera()
        self._initialized = False
Beispiel #5
0
sphere.Update()

cube = vtk.vtkCubeSource()
cube.SetBounds(-1, 1, -1, 1, -1, 1)
cube.Update()

# Create 3D cells so vtkImplicitDataSet evaluates inside vs outside correctly
tri = vtk.vtkDelaunay3D()
tri.SetInputConnection(cube.GetOutputPort())
tri.BoundingTriangulationOff()

# vtkImplicitDataSet needs some scalars to interpolate to find inside/outside
elev = vtk.vtkElevationFilter()
elev.SetInputConnection(tri.GetOutputPort())

implicit = vtk.vtkImplicitDataSet()
implicit.SetDataSet(elev.GetOutput())

clipper = vtk.vtkClipPolyData()
clipper.SetClipFunction(implicit)
clipper.SetInputConnection(sphere.GetOutputPort())
clipper.InsideOutOn()
clipper.Update()

# Vis for clipped sphere
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(clipper.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Vis for cube so can see it in relation to clipped sphere
sphere.Update()

cube = vtk.vtkCubeSource()
cube.SetBounds(-1,1,-1,1,-1,1)
cube.Update()

# Create 3D cells so vtkImplicitDataSet evaluates inside vs outside correctly
tri = vtk.vtkDelaunay3D()
tri.SetInput(cube.GetOutput())
tri.BoundingTriangulationOff()

# vtkImplicitDataSet needs some scalars to interpolate to find inside/outside
elev = vtk.vtkElevationFilter()
elev.SetInputConnection(tri.GetOutputPort())

implicit = vtk.vtkImplicitDataSet()
implicit.SetDataSet(elev.GetOutput())

clipper = vtk.vtkClipPolyData()
clipper.SetClipFunction(implicit)
clipper.SetInputConnection(sphere.GetOutputPort())
clipper.InsideOutOn()
clipper.Update()

# Vis for clipped sphere
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(clipper.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Vis for cube so can see it in relation to clipped sphere