Exemple #1
0
def _extractRectGridByBounds(vtrObj,boundObj):
    '''
    Function that extracts cell from a rectilinear grid (vtr) using bounds.

    Should be signifacantly faster the extractBounds method.

    '''
    import numpy as np, SimPEG as simpeg, vtk
    import vtk.util.numpy_support as npsup

    bO = boundObj.GetBounds()
    xC = npsup.vtk_to_numpy(vtrObj.GetXCoordinates())
    yC = npsup.vtk_to_numpy(vtrObj.GetYCoordinates())
    zC = npsup.vtk_to_numpy(vtrObj.GetZCoordinates())
    iLT = np.where(xC <= bO[0])[0]
    iL = 0 if iLT.shape[0] == 0 else iLT[-1]
    iUT = np.where(xC >= bO[1])[0]
    iU = len(xC) if iUT.shape[0] == 0 else iUT[0]
    jLT = np.where(yC <= bO[2])[0]
    jL = 0 if jLT.shape[0] == 0 else jLT[-1]
    jUT = np.where(yC >= bO[3])[0]
    jU = len(yC) if jUT.shape[0] == 0 else jUT[0]
    kLT = np.where(zC <= bO[4])[0]
    kL = 0 if kLT.shape[0] == 0 else kLT[-1]
    kUT = np.where(zC >= bO[5])[0]
    kU = len(zC) if kUT.shape[0] == 0 else kUT[0]
    extRect = vtk.vtkExtractRectilinearGrid()
    extRect.SetInputData(vtrObj)
    extRect.SetVOI((iL,iU,jL,jU,kL,kU))
    extRect.Update()
    return extRect
Exemple #2
0
def _extractRectGridByBounds(vtrObj,boundObj):
    '''
    Function that extracts cell from a rectilinear grid (vtr) using bounds.

    Should be signifacantly faster the extractBounds method.

    '''

    bO = boundObj.GetBounds()
    xC = npsup.vtk_to_numpy(vtrObj.GetXCoordinates())
    yC = npsup.vtk_to_numpy(vtrObj.GetYCoordinates())
    zC = npsup.vtk_to_numpy(vtrObj.GetZCoordinates())
    iLT = np.where(xC <= bO[0])[0]
    iL = 0 if iLT.shape[0] == 0 else iLT[-1]
    iUT = np.where(xC >= bO[1])[0]
    iU = len(xC) if iUT.shape[0] == 0 else iUT[0]
    jLT = np.where(yC <= bO[2])[0]
    jL = 0 if jLT.shape[0] == 0 else jLT[-1]
    jUT = np.where(yC >= bO[3])[0]
    jU = len(yC) if jUT.shape[0] == 0 else jUT[0]
    kLT = np.where(zC <= bO[4])[0]
    kL = 0 if kLT.shape[0] == 0 else kLT[-1]
    kUT = np.where(zC >= bO[5])[0]
    kU = len(zC) if kUT.shape[0] == 0 else kUT[0]
    extRect = vtk.vtkExtractRectilinearGrid()
    extRect.SetInputData(vtrObj)
    extRect.SetVOI((iL,iU,jL,jU,kL,kU))
    extRect.Update()
    return extRect
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkExtractRectilinearGrid(), 'Processing.',
         ('vtkRectilinearGrid',), ('vtkRectilinearGrid',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkExtractRectilinearGrid(),
                                       'Processing.',
                                       ('vtkRectilinearGrid', ),
                                       ('vtkRectilinearGrid', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Exemple #5
0
	def makeRectiVTKVOIThres(vtkObj,VOI,limits):
		"""Make volume of interest and threshold for rectilinear grid."""
		# Check for the input
		cellCore = vtk.vtkExtractRectilinearGrid()
		cellCore.SetVOI(VOI)
		cellCore.SetInput(vtkObj)

		cellThres = vtk.vtkThreshold()
		cellThres.AllScalarsOn()
		cellThres.SetInputConnection(cellCore.GetOutputPort())
		cellThres.ThresholdBetween(limits[0],limits[1])
		cellThres.Update()
		return cellThres.GetOutput(), cellCore.GetOutput()
Exemple #6
0
 def _set_input (self):        
     """ This function tries its best to use an appropriate filter
     for the given input data."""        
     debug ("In ExtractGrid::_set_input ()")
     out = self.prev_fil.GetOutput ()
     dim = out.GetDimensions ()
     self.dim = [dim[0] -1, dim[1] -1, dim[2] -1]
     if out.IsA ('vtkStructuredGrid'):
         f = vtk.vtkExtractGrid()
     elif out.IsA ('vtkRectilinearGrid'):
         f = vtk.vtkExtractRectilinearGrid()
     elif out.IsA ('vtkStructuredPoints') or out.IsA('vtkImageData'):
         f = vtk.vtkExtractVOI()
     else:
         msg = "This module does not support the given "\
               "output - %s "%(out.GetClassName ())
         raise Base.Objects.ModuleException, msg
     if f.GetClassName() != self.fil.GetClassName():
         self.fil = f
     self.fil.SetInput (out)
from vtk.util.misc import vtkGetDataRoot

VTK_DATA_ROOT = vtkGetDataRoot()

# create pipeline - rectilinear grid
#
rgridReader = vtk.vtkRectilinearGridReader()
rgridReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/RectGrid2.vtk")
outline = vtk.vtkOutlineFilter()
outline.SetInputConnection(rgridReader.GetOutputPort())
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(outline.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
rgridReader.Update()
extract1 = vtk.vtkExtractRectilinearGrid()
extract1.SetInputConnection(rgridReader.GetOutputPort())
# extract1 SetVOI 0 46 0 32 0 10
extract1.SetVOI(23, 40, 16, 30, 9, 9)
extract1.SetSampleRate(2, 2, 1)
extract1.IncludeBoundaryOn()
extract1.Update()
surf1 = vtk.vtkDataSetSurfaceFilter()
surf1.SetInputConnection(extract1.GetOutputPort())
tris = vtk.vtkTriangleFilter()
tris.SetInputConnection(surf1.GetOutputPort())
mapper1 = vtk.vtkPolyDataMapper()
mapper1.SetInputConnection(tris.GetOutputPort())
mapper1.SetScalarRange(extract1.GetOutput().GetScalarRange())
actor1 = vtk.vtkActor()
actor1.SetMapper(mapper1)
from vtk.util.misc import vtkGetTempDir

VTK_DATA_ROOT = vtkGetDataRoot()

VTK_TEMP_DIR = vtkGetTempDir()
file0 = VTK_TEMP_DIR + '/rgFile0.vtr'
file1 = VTK_TEMP_DIR + '/rgFile1.vtr'
file2 = VTK_TEMP_DIR + '/rgFile2.vtr'

# read in some grid data
gridReader = vtk.vtkRectilinearGridReader()
gridReader.SetFileName(VTK_DATA_ROOT + "/Data/RectGrid2.vtk")
gridReader.Update()

# extract to reduce extents of grid
extract = vtk.vtkExtractRectilinearGrid()
extract.SetInputConnection(gridReader.GetOutputPort())
extract.SetVOI(0, 23, 0, 32, 0, 10)
extract.Update()

# write just a piece (extracted piece) as well as the whole thing
rgWriter = vtk.vtkXMLRectilinearGridWriter()
rgWriter.SetFileName(file0)
rgWriter.SetInputConnection(extract.GetOutputPort())
rgWriter.SetDataModeToAscii()
rgWriter.Write()

rgWriter.SetFileName(file1)
rgWriter.SetInputConnection(gridReader.GetOutputPort())
rgWriter.SetDataModeToAppended()
rgWriter.SetNumberOfPieces(2)