Esempio n. 1
0
    def __init__(
        self,
        inputobj=None,
        c=('r', 'y', 'lg', 'lb', 'b'),  #('b','lb','lg','y','r')
        alpha=(0.5, 1),
        alphaUnit=1,
        mapper='tetra',
    ):

        BaseGrid.__init__(self)

        self.useArray = 0

        inputtype = str(type(inputobj))
        #printc('TetMesh inputtype', inputtype)

        ###################
        if inputobj is None:
            self._data = vtk.vtkUnstructuredGrid()

        elif isinstance(inputobj, vtk.vtkUnstructuredGrid):
            self._data = inputobj

        elif isinstance(inputobj, vtk.vtkRectilinearGrid):
            r2t = vtk.vtkRectilinearGridToTetrahedra()
            r2t.SetInputData(inputobj)
            r2t.RememberVoxelIdOn()
            r2t.SetTetraPerCellTo6()
            r2t.Update()
            self._data = r2t.GetOutput()

        elif isinstance(inputobj, vtk.vtkDataSet):
            r2t = vtk.vtkDataSetTriangleFilter()
            r2t.SetInputData(inputobj)
            #r2t.TetrahedraOnlyOn()
            r2t.Update()
            self._data = r2t.GetOutput()

        elif isinstance(inputobj, str):
            from vedo.io import download, loadUnStructuredGrid
            if "https://" in inputobj:
                inputobj = download(inputobj, verbose=False)
            ug = loadUnStructuredGrid(inputobj)
            tt = vtk.vtkDataSetTriangleFilter()
            tt.SetInputData(ug)
            tt.SetTetrahedraOnly(True)
            tt.Update()
            self._data = tt.GetOutput()

        elif utils.isSequence(inputobj):
            # if "ndarray" not in inputtype:
            #     inputobj = np.array(inputobj)
            self._data = self._buildtetugrid(inputobj[0], inputobj[1])

        ###################
        if 'tetra' in mapper:
            self._mapper = vtk.vtkProjectedTetrahedraMapper()
        elif 'ray' in mapper:
            self._mapper = vtk.vtkUnstructuredGridVolumeRayCastMapper()
        elif 'zs' in mapper:
            self._mapper = vtk.vtkUnstructuredGridVolumeZSweepMapper()
        elif isinstance(mapper, vtk.vtkMapper):
            self._mapper = mapper
        else:
            printc('Unknown mapper type', [mapper], c='r')
            raise RuntimeError()

        self._mapper.SetInputData(self._data)
        self.SetMapper(self._mapper)
        self.color(c).alpha(alpha)
        if alphaUnit:
            self.GetProperty().SetScalarOpacityUnitDistance(alphaUnit)

        # remember stuff:
        self._color = c
        self._alpha = alpha
        self._alphaUnit = alphaUnit
Esempio n. 2
0
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(0,1.0,0.0,1.0)
colorTransferFunction.AddRGBPoint(2,0.0,0.0,1.0)
colorTransferFunction.AddRGBPoint(4,0.0,1.0,1.0)
colorTransferFunction.AddRGBPoint(6,0.0,1.0,0.0)
colorTransferFunction.AddRGBPoint(8,1.0,1.0,0.0)
colorTransferFunction.AddRGBPoint(10,1.0,0.0,0.0)
# The property describes how the data will look
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.ShadeOff()
volumeProperty.SetInterpolationTypeToLinear()
volumeProperty.SetScalarOpacityUnitDistance(0.75)
# The mapper / ray cast function / ray integrator know how to render the data
volumeMapper = vtk.vtkUnstructuredGridVolumeZSweepMapper()
volumeMapper.SetInputConnection(trifilter.GetOutputPort())
#vtkUnstructuredGridLinearRayIntegrator rayIntegrator
#    volumeMapper SetRayIntegrator rayIntegrator
rayIntegrator = vtk.vtkUnstructuredGridPreIntegration()
volumeMapper.SetRayIntegrator(rayIntegrator)
# The volume holds the mapper and the property and
# can be used to position/orient the volume
volume = vtk.vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)
ren1.AddVolume(volume)
renWin.SetSize(300,300)
ren1.ResetCamera()
ren1.GetActiveCamera().Azimuth(20.0)
ren1.GetActiveCamera().Elevation(15.0)
Esempio n. 3
0
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(0, 1.0, 0.0, 1.0)
colorTransferFunction.AddRGBPoint(2, 0.0, 0.0, 1.0)
colorTransferFunction.AddRGBPoint(4, 0.0, 1.0, 1.0)
colorTransferFunction.AddRGBPoint(6, 0.0, 1.0, 0.0)
colorTransferFunction.AddRGBPoint(8, 1.0, 1.0, 0.0)
colorTransferFunction.AddRGBPoint(10, 1.0, 0.0, 0.0)
# The property describes how the data will look
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.ShadeOff()
volumeProperty.SetInterpolationTypeToLinear()
volumeProperty.SetScalarOpacityUnitDistance(0.75)
# The mapper / ray cast function / ray integrator know how to render the data
volumeMapper = vtk.vtkUnstructuredGridVolumeZSweepMapper()
volumeMapper.SetInputConnection(trifilter.GetOutputPort())
#vtkUnstructuredGridLinearRayIntegrator rayIntegrator
#    volumeMapper SetRayIntegrator rayIntegrator
rayIntegrator = vtk.vtkUnstructuredGridPreIntegration()
volumeMapper.SetRayIntegrator(rayIntegrator)
# The volume holds the mapper and the property and
# can be used to position/orient the volume
volume = vtk.vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)
ren1.AddVolume(volume)
renWin.SetSize(300, 300)
ren1.ResetCamera()
ren1.GetActiveCamera().Azimuth(20.0)
ren1.GetActiveCamera().Elevation(15.0)
Esempio n. 4
0
    def __init__(
        self,
        inputobj=None,
        c=('r', 'y', 'lg', 'lb', 'b'),  #('b','lb','lg','y','r')
        alpha=(0.5, 1),
        alphaUnit=1,
        mapper='tetra',
    ):

        vtk.vtkVolume.__init__(self)
        ActorBase.__init__(self)

        self._ugrid = None

        self.useCells = True
        self.useArray = 0

        inputtype = str(type(inputobj))
        #printc('TetMesh inputtype', inputtype)

        ###################
        if inputobj is None:
            self._ugrid = vtk.vtkUnstructuredGrid()
        elif isinstance(inputobj, vtk.vtkUnstructuredGrid):
            self._ugrid = inputobj
        elif isinstance(inputobj, vtk.vtkRectilinearGrid):
            r2t = vtk.vtkRectilinearGridToTetrahedra()
            r2t.SetInputData(inputobj)
            r2t.RememberVoxelIdOn()
            r2t.SetTetraPerCellTo6()
            r2t.Update()
            self._ugrid = r2t.GetOutput()
        elif isinstance(inputobj, vtk.vtkDataSet):
            r2t = vtk.vtkDataSetTriangleFilter()
            r2t.SetInputData(inputobj)
            #r2t.TetrahedraOnlyOn()
            r2t.Update()
            self._ugrid = r2t.GetOutput()
        elif isinstance(inputobj, str):
            from vtkplotter.vtkio import loadUnStructuredGrid
            self._ugrid = loadUnStructuredGrid(inputobj)
        elif utils.isSequence(inputobj):
            if "ndarray" not in inputtype:
                inputobj = np.array(inputobj)
            self._ugrid = self._buildugrid(inputobj[0], inputobj[1])

        ###################
        if 'tetra' in mapper:
            self._mapper = vtk.vtkProjectedTetrahedraMapper()
        elif 'ray' in mapper:
            self._mapper = vtk.vtkUnstructuredGridVolumeRayCastMapper()
        elif 'zs' in mapper:
            self._mapper = vtk.vtkUnstructuredGridVolumeZSweepMapper()
        elif isinstance(mapper, vtk.vtkMapper):
            self._mapper = mapper
        else:
            printc('Unknown mapper type', [mapper], c=1)
            return

        self._mapper.SetInputData(self._ugrid)
        self.SetMapper(self._mapper)
        self.color(c).alpha(alpha)
        if alphaUnit:
            self.GetProperty().SetScalarOpacityUnitDistance(alphaUnit)

        # remember stuff:
        self._color = c
        self._alpha = alpha
        self._alphaUnit = alphaUnit