当前位置: 首页>>代码示例>>Python>>正文


Python numpy_support.vtk_to_numpy方法代码示例

本文整理汇总了Python中vtk.util.numpy_support.vtk_to_numpy方法的典型用法代码示例。如果您正苦于以下问题:Python numpy_support.vtk_to_numpy方法的具体用法?Python numpy_support.vtk_to_numpy怎么用?Python numpy_support.vtk_to_numpy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vtk.util.numpy_support的用法示例。


在下文中一共展示了numpy_support.vtk_to_numpy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_shallow_copy_back_propagation

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def test_shallow_copy_back_propagation():
    """Test that the original data object's points get modified after a
    shallow copy.

    Reference: https://github.com/pyvista/pyvista/issues/375#issuecomment-531691483
    """
    # Case 1
    points = vtk.vtkPoints()
    points.InsertNextPoint(0.0, 0.0, 0.0)
    points.InsertNextPoint(1.0, 0.0, 0.0)
    points.InsertNextPoint(2.0, 0.0, 0.0)
    original = vtk.vtkPolyData()
    original.SetPoints(points)
    wrapped = pyvista.PolyData(original, deep=False)
    wrapped.points[:] = 2.8
    orig_points = vtk_to_numpy(original.GetPoints().GetData())
    assert np.allclose(orig_points, wrapped.points)
    # Case 2
    original = vtk.vtkPolyData()
    wrapped = pyvista.PolyData(original, deep=False)
    wrapped.points = np.random.rand(5, 3)
    orig_points = vtk_to_numpy(original.GetPoints().GetData())
    assert np.allclose(orig_points, wrapped.points) 
开发者ID:pyvista,项目名称:pyvista,代码行数:25,代码来源:test_common.py

示例2: test_VTK_object_conversion

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def test_VTK_object_conversion(self):
            mesh = self.mesh
            vec = np.arange(mesh.nC)
            models = {'arange': vec}

            vtkObj = mesh.to_vtk(models)

            self.assertEqual(mesh.nC, vtkObj.GetNumberOfCells())
            self.assertEqual(mesh.nN, vtkObj.GetNumberOfPoints())
            self.assertEqual(len(models.keys()), vtkObj.GetCellData().GetNumberOfArrays())
            bnds = vtkObj.GetBounds()
            self.assertEqual(mesh.x0[0], bnds[0])
            self.assertEqual(mesh.x0[1], bnds[2])
            self.assertEqual(mesh.x0[2], bnds[4])

            for i in range(vtkObj.GetCellData().GetNumberOfArrays()):
                name = list(models.keys())[i]
                self.assertEqual(name, vtkObj.GetCellData().GetArrayName(i))
                arr = nps.vtk_to_numpy(vtkObj.GetCellData().GetArray(i))
                arr = arr.flatten(order='F')
                self.assertTrue(np.allclose(models[name], arr)) 
开发者ID:simpeg,项目名称:discretize,代码行数:23,代码来源:test_tensor_vtk.py

示例3: test_VTK_object_conversion

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def test_VTK_object_conversion(self):
            mesh = self.mesh
            vec = np.arange(mesh.nC)
            models = {'arange': vec}

            vtkObj = mesh.to_vtk(models)

            self.assertEqual(mesh.nC, vtkObj.GetNumberOfCells())
            self.assertEqual(mesh.nN, vtkObj.GetNumberOfPoints())
            self.assertEqual(len(models.keys()), vtkObj.GetCellData().GetNumberOfArrays())
            bnds = vtkObj.GetBounds()
            self.assertEqual(mesh.x0[0], bnds[0])
            self.assertEqual(mesh.x0[1], bnds[2])
            self.assertEqual(mesh.x0[2], bnds[4])

            names = list(models.keys())
            for i in range(vtkObj.GetCellData().GetNumberOfArrays()):
                name = names[i]
                self.assertEqual(name, vtkObj.GetCellData().GetArrayName(i))
                arr = nps.vtk_to_numpy(vtkObj.GetCellData().GetArray(i))
                arr = arr.flatten(order='F')
                self.assertTrue(np.allclose(models[name], arr)) 
开发者ID:simpeg,项目名称:discretize,代码行数:24,代码来源:test_curvilinear_vtk.py

示例4: test_VTK_object_conversion

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def test_VTK_object_conversion(self):
            mesh = self.mesh
            vec = np.arange(mesh.nC)
            models = {'arange': vec}

            vtkObj = mesh.to_vtk(models)

            self.assertEqual(mesh.nC, vtkObj.GetNumberOfCells())
            # TODO: this is actually different?: self.assertEqual(mesh.nN, vtkObj.GetNumberOfPoints())
            # Remember that the tree vtk conversion adds two arrays
            self.assertEqual(len(models.keys())+2, vtkObj.GetCellData().GetNumberOfArrays())
            bnds = vtkObj.GetBounds()
            self.assertEqual(mesh.x0[0], bnds[0])
            self.assertEqual(mesh.x0[1], bnds[2])
            self.assertEqual(mesh.x0[2], bnds[4])

            names = list(models.keys())
            for name in names:
                arr = nps.vtk_to_numpy(vtkObj.GetCellData().GetArray(name))
                arr = arr.flatten(order='F')
                self.assertTrue(np.allclose(models[name], arr)) 
开发者ID:simpeg,项目名称:discretize,代码行数:23,代码来源:test_tree_vtk.py

示例5: _get_volume_data

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def _get_volume_data(self):
        if self.object is None:
            return None
        elif isinstance(self.object, np.ndarray):
            return self._volume_from_array(self._subsample_array(self.object))
        else:
            available_serializer = [v for k, v in VTKVolume._serializers.items() if isinstance(self.object, k)]
            if not available_serializer:
                import vtk
                from vtk.util import numpy_support

                def volume_serializer(inst):
                    imageData = inst.object
                    array = numpy_support.vtk_to_numpy(imageData.GetPointData().GetScalars())
                    dims = imageData.GetDimensions()[::-1]
                    inst.spacing = imageData.GetSpacing()[::-1]
                    inst.origin = imageData.GetOrigin()
                    return inst._volume_from_array(inst._subsample_array(array.reshape(dims, order='C')))

                VTKVolume.register_serializer(vtk.vtkImageData, volume_serializer)
                serializer = volume_serializer
            else:
                serializer = available_serializer[0]
            return serializer(self) 
开发者ID:holoviz,项目名称:panel,代码行数:26,代码来源:vtk.py

示例6: _read_stl

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def _read_stl(file_name):
    '''Internal function to read stl mesh files
    '''

    reader = vtk.vtkSTLReader()
    reader.SetFileName(file_name)
    reader.Update()

    mesh_data = PanelMesh(file_name)
    mesh_data.orig_type = 'Stereolithography (.stl)'
    mesh_data.num_faces = int(reader.GetOutput().GetNumberOfCells())
    mesh_data.num_points = mesh_data.num_faces * 3
    for i in range(mesh_data.num_faces):
        n = i*3
        mesh_data.faces.append(np.array([n,n+1,n+2,n+2]))
        mesh_data.points.append(np.array(vtk_to_numpy(reader.GetOutput().GetCell(i).GetPoints().GetData())))
    mesh_data.points = np.array(mesh_data.points).reshape([mesh_data.num_faces*3,3])

    return mesh_data 
开发者ID:NREL,项目名称:OpenWARP,代码行数:21,代码来源:mesh.py

示例7: readData

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def readData(filename, x = all, y = all, z = all):
    """Read data from raw/mhd image
    
    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
    
    Returns:
        array: image data
    """   
    
    imr = vtk.vtkMetaImageReader()
    imr.SetFileName(filename);
    imr.Update()
    
    im = imr.GetOutput()
    dims = im.GetDimensions()
    
    print dims    
    
    sc = im.GetPointData().GetScalars()
    img = vtk_to_numpy(sc)
    #print img.shape
    
    dims = list(dims);
    dims[0:3] = [dims[2], dims[1], dims[0]];
    
    imgs = list(img.shape);
    if len(imgs) > 1:
        imgs.pop(0);
        dims = dims + imgs;
    
    img = img.reshape(dims)
    #img = img.transpose([1,2,0]);
    tp = [2,1,0];
    tp = tp + [i for i in range(3, len(dims))];
    img = img.transpose(tp);
    
    return io.dataToRange(img, x = x, y = y, z = z); 
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:41,代码来源:RAW.py

示例8: test_numpy_to_idarr_bool

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def test_numpy_to_idarr_bool():
    mask = np.ones(10, np.bool_)
    idarr = pyvista.utilities.cells.numpy_to_idarr(mask)
    assert np.allclose(mask.nonzero()[0], vtk_to_numpy(idarr)) 
开发者ID:pyvista,项目名称:pyvista,代码行数:6,代码来源:test_cells.py

示例9: cells

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def cells(self):
        """Return a numpy array of the cells."""
        return vtk_to_numpy(self.GetData()).ravel() 
开发者ID:pyvista,项目名称:pyvista,代码行数:5,代码来源:cells.py

示例10: y

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def y(self):
        """Get the coordinates along the Y-direction."""
        return vtk_to_numpy(self.GetYCoordinates()) 
开发者ID:pyvista,项目名称:pyvista,代码行数:5,代码来源:grid.py

示例11: z

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def z(self):
        """Get the coordinates along the Z-direction."""
        return vtk_to_numpy(self.GetZCoordinates()) 
开发者ID:pyvista,项目名称:pyvista,代码行数:5,代码来源:grid.py

示例12: vtkPolyData_to_tracts

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def vtkPolyData_to_tracts(polydata):

	result = {}
	result['lines'] = ns.vtk_to_numpy(polydata.GetLines().GetData())
	result['points'] = ns.vtk_to_numpy(polydata.GetPoints().GetData())
	result['numberOfLines'] = polydata.GetNumberOfLines()

	data = {}
	if polydata.GetPointData().GetScalars():
		data['ActiveScalars'] = polydata.GetPointData().GetScalars().GetName()
		result['Scalars'] = polydata.GetPointData().GetScalars()
	if polydata.GetPointData().GetVectors():
		data['ActiveVectors'] = polydata.GetPointData().GetVectors().GetName()
	if polydata.GetPointData().GetTensors():
		data['ActiveTensors'] = polydata.GetPointData().GetTensors().GetName()

	for i in xrange(polydata.GetPointData().GetNumberOfArrays()):
		array = polydata.GetPointData().GetArray(i)
		np_array = ns.vtk_to_numpy(array)
		if np_array.ndim == 1:
			np_array = np_array.reshape(len(np_array), 1)
		data[polydata.GetPointData().GetArrayName(i)] = np_array

	result['pointData'] = data

	tracts, data = vtkPolyData_dictionary_to_tracts_and_data(result)
	return tracts, data 
开发者ID:jeanfeydy,项目名称:geomloss,代码行数:29,代码来源:tract_io.py

示例13: vtk_to_tensor_mesh

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def vtk_to_tensor_mesh(TensorMesh, vtrGrid):
        """Converts a ``vtkRectilinearGrid`` or :class:`pyvista.RectilinearGrid`
        to a :class:`discretize.TensorMesh` object.

        """
        # Sort information
        hx = np.abs(np.diff(_nps.vtk_to_numpy(vtrGrid.GetXCoordinates())))
        xR = _nps.vtk_to_numpy(vtrGrid.GetXCoordinates())[0]
        hy = np.abs(np.diff(_nps.vtk_to_numpy(vtrGrid.GetYCoordinates())))
        yR = _nps.vtk_to_numpy(vtrGrid.GetYCoordinates())[0]
        zD = np.diff(_nps.vtk_to_numpy(vtrGrid.GetZCoordinates()))
        # Check the direction of hz
        if np.all(zD < 0):
            hz = np.abs(zD[::-1])
            zR = _nps.vtk_to_numpy(vtrGrid.GetZCoordinates())[-1]
        else:
            hz = np.abs(zD)
            zR = _nps.vtk_to_numpy(vtrGrid.GetZCoordinates())[0]
        x0 = np.array([xR, yR, zR])

        # Make the object
        tensMsh = TensorMesh([hx, hy, hz], x0=x0)

        # Grap the models
        models = {}
        for i in np.arange(vtrGrid.GetCellData().GetNumberOfArrays()):
            modelName = vtrGrid.GetCellData().GetArrayName(i)
            if np.all(zD < 0):
                modFlip = _nps.vtk_to_numpy(vtrGrid.GetCellData().GetArray(i))
                tM = tensMsh.r(modFlip, 'CC', 'CC', 'M')
                modArr = tensMsh.r(tM[:, :, ::-1], 'CC', 'CC', 'V')
            else:
                modArr = _nps.vtk_to_numpy(vtrGrid.GetCellData().GetArray(i))
            models[modelName] = modArr

        # Return the data
        return tensMsh, models 
开发者ID:simpeg,项目名称:discretize,代码行数:39,代码来源:vtkModule.py

示例14: place_model_on_octree_mesh

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def place_model_on_octree_mesh(mesh, model, data_name='Data'):
        """Places model data onto a mesh. This is for the UBC Grid data reaers
        to associate model data with the mesh grid.

        Args:
            mesh (vtkUnstructuredGrid): The ``vtkUnstructuredGrid`` that is the
                mesh to place the model data upon. Needs to have been read in by ubcOcTree
            model (np.ndarray): A NumPy float array that holds all of the data
                to place inside of the mesh's cells.
            data_name (str): The name of the model data array once placed on the
                ``vtkUnstructuredGrid``.

        Return:
            vtkUnstructuredGrid:
                The input ``vtkUnstructuredGrid`` with model data appended.
        """
        if isinstance(model, dict):
            for key in model.keys():
                mesh = OcTreeReader.place_model_on_octree_mesh(mesh, model[key], data_name=key)
            return mesh
        # Make sure this model file fits the dimensions of the mesh
        numCells = mesh.GetNumberOfCells()
        if (numCells < len(model)):
            raise _helpers.PVGeoError('This model file has more data than the given mesh has cells to hold.')
        elif (numCells > len(model)):
            raise _helpers.PVGeoError('This model file does not have enough data to fill the given mesh\'s cells.')

        # This is absolutely crucial!
        # Do not play with unless you know what you are doing!
        # Also note that this assumes ``discretize`` handles addin this array
        ind_reorder = nps.vtk_to_numpy(
            mesh.GetCellData().GetArray('index_cell_corner'))

        model = model[ind_reorder]

        # Convert data to VTK data structure and append to output
        c = interface.convert_array(model, name=data_name, deep=True)
        # THIS IS CELL DATA! Add the model data to CELL data:
        mesh.GetCellData().AddArray(c)
        return mesh 
开发者ID:OpenGeoVis,项目名称:PVGeo,代码行数:42,代码来源:octree.py

示例15: test_data_fidelity

# 需要导入模块: from vtk.util import numpy_support [as 别名]
# 或者: from vtk.util.numpy_support import vtk_to_numpy [as 别名]
def test_data_fidelity(self):
        """`GSLibReader`: data fidelity"""
        for i, title in enumerate(self.titles):
            arr = nps.vtk_to_numpy(self.TABLE.GetColumn(i))
            self.assertTrue(np.allclose(self.data[:,i], arr, rtol=RTOL))
        return 
开发者ID:OpenGeoVis,项目名称:PVGeo,代码行数:8,代码来源:gslib_test.py


注:本文中的vtk.util.numpy_support.vtk_to_numpy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。