コード例 #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
コード例 #2
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

### SetUp the pipeline
FormMesh = vtk.vtkRectilinearGridToTetrahedra()
FormMesh.SetInput(4,2,2,1,1,1,0.001)
FormMesh.RememberVoxelIdOn()
TetraEdges = vtk.vtkExtractEdges()
TetraEdges.SetInputConnection(FormMesh.GetOutputPort())
tubes = vtk.vtkTubeFilter()
tubes.SetInputConnection(TetraEdges.GetOutputPort())
tubes.SetRadius(0.05)
tubes.SetNumberOfSides(6)
### Run the pipeline 3 times, with different conversions to TetMesh
Tubes1 = vtk.vtkPolyData()
FormMesh.SetTetraPerCellTo5()
tubes.Update()
Tubes1.DeepCopy(tubes.GetOutput())
Tubes2 = vtk.vtkPolyData()
FormMesh.SetTetraPerCellTo6()
tubes.Update()
Tubes2.DeepCopy(tubes.GetOutput())
Tubes3 = vtk.vtkPolyData()
FormMesh.SetTetraPerCellTo12()
tubes.Update()
Tubes3.DeepCopy(tubes.GetOutput())
### Run the pipeline once more, this time converting some cells to
### 5 and some data to 12 TetMesh
コード例 #3
0
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()


def GetRGBColor(colorName):
    '''
        Return the red, green and blue components for a
        color as doubles.
    '''
    rgb = [0.0, 0.0, 0.0]  # black
    vtk.vtkNamedColors().GetColorRGB(colorName, rgb)
    return rgb


# SetUp the pipeline
FormMesh = vtk.vtkRectilinearGridToTetrahedra()
FormMesh.SetInput(4, 2, 2, 1, 1, 1, 0.001)
FormMesh.RememberVoxelIdOn()

TetraEdges = vtk.vtkExtractEdges()
TetraEdges.SetInputConnection(FormMesh.GetOutputPort())

tubes = vtk.vtkTubeFilter()
tubes.SetInputConnection(TetraEdges.GetOutputPort())
tubes.SetRadius(0.05)
tubes.SetNumberOfSides(6)

# Run the pipeline 3 times, with different conversions to TetMesh
FormMesh.SetTetraPerCellTo5()

tubes.Update()
コード例 #4
0
ファイル: Sample.py プロジェクト: TACC/ParaviewCustomModules
o = igrid.GetOrigin()
s = igrid.GetSpacing()
n = igrid.GetDimensions()

x = dsa.numpy_support.numpy_to_vtk(np.array([o[0] - e[0]*s[0] + i*s[0] for i in range(e[1]+1)]).astype('f8'))
y = dsa.numpy_support.numpy_to_vtk(np.array([o[1] - e[2]*s[1] + i*s[1] for i in range(e[3]+1)]).astype('f8'))
z = dsa.numpy_support.numpy_to_vtk(np.array([o[2] - e[4]*s[2] + i*s[2] for i in range(e[5]+1)]).astype('f8'))

rgrid = vtk.vtkRectilinearGrid()
rgrid.SetDimensions(n)
rgrid.SetXCoordinates(x)
rgrid.SetYCoordinates(y)
rgrid.SetZCoordinates(z)
rgrid.GetPointData().ShallowCopy(igrid.GetPointData())

to_tets = vtk.vtkRectilinearGridToTetrahedra()
to_tets.SetInputData(rgrid)
to_tets.Update()

tets = to_tets.GetOutput()
tets.GetPointData().ShallowCopy(rgrid.GetPointData())

w = dsa.WrapDataObject(tets)

p_to_c = vtk.vtkPointDataToCellData()
p_to_c.SetInputConnection(to_tets.GetOutputPort())
p_to_c.Update()
ctets = p_to_c.GetOutput()

vtu = dsa.WrapDataObject(p_to_c.GetOutput())
コード例 #5
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