Python vtk.vtkDoubleArray() Examples

The following are 19 code examples of vtk.vtkDoubleArray(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module vtk , or try the search function .
Example #1
Source File: pointobject.py    From Det3D with Apache License 2.0 6 votes vote down vote up
def AddPoses(self, matrix_list):
        """"Add poses (4x4 NumPy arrays) to the object 
        """
        R_list = [p[:3, :3] for p in matrix_list]  # translation data
        t_list = [p[:3, 3] for p in matrix_list]  # rotation data

        self.points = vtk.vtkPoints()  # where t goes
        self.tensors = vtk.vtkDoubleArray()  # where R goes, column major
        self.tensors.SetNumberOfComponents(9)
        for i, R, t in zip(count(), R_list, t_list):
            self.points.InsertNextPoint(*tuple(t))
            self.tensors.InsertNextTypedTuple(tuple(R.ravel(order="F")))

        self.pose_pd = vtk.vtkPolyData()
        self.pose_pd.SetPoints(self.points)
        self.pose_pd.GetPointData().SetTensors(self.tensors) 
Example #2
Source File: voxelize.py    From PVGeo with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def add_field_data(self, grid):
        """An internal helper to add the recovered information as field data
        """
        # Add angle
        a = vtk.vtkDoubleArray()
        a.SetName('Recovered Angle (Deg.)')
        a.SetNumberOfValues(1)
        a.SetValue(0, np.rad2deg(self.__angle))
        grid.GetFieldData().AddArray(a)
        # Add cell sizes
        s = vtk.vtkDoubleArray()
        s.SetName('Recovered Cell Sizes')
        s.SetNumberOfComponents(3)
        s.InsertNextTuple3(self.__dx, self.__dy, self.__dz)
        grid.GetFieldData().AddArray(s)
        return grid 
Example #3
Source File: filters.py    From pyvista with MIT License 5 votes vote down vote up
def clip_surface(dataset, surface, invert=True, value=0.0,
                     compute_distance=False):
        """Clip any mesh type using a :class:`pyvista.PolyData` surface mesh.

        This will return a :class:`pyvista.UnstructuredGrid` of the clipped
        mesh. Geometry of the input dataset will be preserved where possible -
        geometries near the clip intersection will be triangulated/tessellated.

        Parameters
        ----------
        surface : pyvista.PolyData
            The PolyData surface mesh to use as a clipping function. If this
            mesh is not PolyData, the external surface will be extracted.

        invert : bool
            Flag on whether to flip/invert the clip

        value : float:
            Set the clipping value of the implicit function (if clipping with
            implicit function) or scalar value (if clipping with scalars).
            The default value is 0.0.

        compute_distance : bool, optional
            Compute the implicit distance from the mesh onto the input dataset.
            A new array called ``'implicit_distance'`` will be added to the
            output clipped mesh.

        """
        if not isinstance(surface, vtk.vtkPolyData):
            surface = DataSetFilters.extract_geometry(surface)
        function = vtk.vtkImplicitPolyDataDistance()
        function.SetInput(surface)
        if compute_distance:
            points = pyvista.convert_array(dataset.points)
            dists = vtk.vtkDoubleArray()
            function.FunctionValue(points, dists)
            dataset['implicit_distance'] = pyvista.convert_array(dists)
        # run the clip
        result = DataSetFilters._clip_with_function(dataset, function,
                                                    invert=invert, value=value)
        return result 
Example #4
Source File: show_lidar_vtk.py    From Det3D with Apache License 2.0 5 votes vote down vote up
def draw_grid():
    xArray = vtk.vtkDoubleArray()
    yArray = vtk.vtkDoubleArray()
    zArray = vtk.vtkDoubleArray()

    for x in range(-60, 61):
        xArray.InsertNextValue(x)
    # for y in range(-10, 10):
    #     yArray.InsertNextValue(y)
    for y in range(0, 1):
        yArray.InsertNextValue(y)
    for z in range(-80, 80):
        zArray.InsertNextValue(z)

    grid = vtk.vtkRectilinearGrid()
    grid.SetDimensions(121, 1, 161)
    grid.SetXCoordinates(xArray)
    grid.SetYCoordinates(yArray)
    grid.SetZCoordinates(zArray)

    # print(grid.GetPoint(0))

    gridMapper = vtk.vtkDataSetMapper()
    gridMapper.SetInputData(grid)

    gridActor = vtk.vtkActor()
    gridActor.SetMapper(gridMapper)
    gridActor.GetProperty().SetColor(0.75, 0.75, 0)
    gridActor.GetProperty().SetOpacity(0.1)
    # import pdb; pdb.set_trace()
    return gridActor 
Example #5
Source File: kinect3Dcould.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def clearPoints(self):
        self.vtkPoints = vtk.vtkPoints()
        self.vtkCells = vtk.vtkCellArray()
        self.vtkDepth = vtk.vtkDoubleArray()
        self.vtkDepth.SetName('DepthArray')
        self.vtkPolyData.SetPoints(self.vtkPoints)
        self.vtkPolyData.SetVerts(self.vtkCells)
        self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth)
        self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray')

        self.Colors = vtk.vtkUnsignedCharArray()
        self.Colors.SetNumberOfComponents(3) 
        self.Colors.SetName("Colors") 
Example #6
Source File: viz.py    From deep_gcns with MIT License 5 votes vote down vote up
def clear_points(self):
        self.vtkPoints = vtk.vtkPoints()
        self.vtkCells = vtk.vtkCellArray()
        self.vtkDepth = vtk.vtkDoubleArray()
        self.vtkDepth.SetName('DepthArray')
        self.vtkPolyData.SetPoints(self.vtkPoints)
        self.vtkPolyData.SetVerts(self.vtkCells)
        self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth)
        self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray') 
Example #7
Source File: pc_viz.py    From deep_gcns_torch with MIT License 5 votes vote down vote up
def clear_points(self):
        self.vtkPoints = vtk.vtkPoints()
        self.vtkCells = vtk.vtkCellArray()
        self.vtkDepth = vtk.vtkDoubleArray()
        self.vtkDepth.SetName('DepthArray')
        self.vtkPolyData.SetPoints(self.vtkPoints)
        self.vtkPolyData.SetVerts(self.vtkCells)
        self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth)
        self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray') 
Example #8
Source File: vtkpointcloud.py    From semi-auto-anno with GNU General Public License v3.0 5 votes vote down vote up
def clearPoints(self):
        """
        Clear all points from the point cloud
        :return: None
        """
        self.vtkPoints = vtk.vtkPoints()
        self.vtkCells = vtk.vtkCellArray()
        self.vtkDepth = vtk.vtkDoubleArray()
        self.vtkDepth.SetName('DepthArray')
        self.vtkPolyData.SetPoints(self.vtkPoints)
        self.vtkPolyData.SetVerts(self.vtkCells)
        self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth)
        self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray') 
Example #9
Source File: general.py    From PVGeo with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def RequestData(self, request, inInfo, outInfo):
        """Used by pipeline to get data for current timestep and populate the
        output data object.
        """
        # Set points using parent
        DelimitedPointsReaderBase.RequestData(self, request, inInfo, outInfo)
        # Add field data to ouptput
        output = self.GetOutputData(outInfo, 0)

        # Add inducing magnetic field
        x, y, z = self.convert_vector(self.__incl, self.__decl, mag=self.__geomag)
        ind = vtk.vtkDoubleArray()
        ind.SetName('Inducing Magnetic Field')
        ind.SetNumberOfComponents(3)
        ind.InsertNextTuple3(x, y, z)
        output.GetFieldData().AddArray(ind)

        # Add Inclination and declination of the anomaly projection
        x, y, z = self.convert_vector(self.__ainc, self.__adec)
        anom = vtk.vtkDoubleArray()
        anom.SetName('Anomaly Projection')
        anom.SetNumberOfComponents(3)
        anom.InsertNextTuple3(x, y, z)
        output.GetFieldData().AddArray(anom)

        return 1



############################################################################### 
Example #10
Source File: viz.py    From 3d-semantic-segmentation with MIT License 5 votes vote down vote up
def clear_points(self):
        self.vtkPoints = vtk.vtkPoints()
        self.vtkCells = vtk.vtkCellArray()
        self.vtkDepth = vtk.vtkDoubleArray()
        self.vtkDepth.SetName('DepthArray')
        self.vtkPolyData.SetPoints(self.vtkPoints)
        self.vtkPolyData.SetVerts(self.vtkCells)
        self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth)
        self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray') 
Example #11
Source File: viz.py    From vkitti3D-dataset with MIT License 5 votes vote down vote up
def clear_points(self):
        self.vtkPoints = vtk.vtkPoints()
        self.vtkCells = vtk.vtkCellArray()
        self.vtkDepth = vtk.vtkDoubleArray()
        self.vtkDepth.SetName('DepthArray')
        self.vtkPolyData.SetPoints(self.vtkPoints)
        self.vtkPolyData.SetVerts(self.vtkCells)
        self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth)
        self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray') 
Example #12
Source File: filters.py    From pyvista with MIT License 5 votes vote down vote up
def compute_implicit_distance(dataset, surface, inplace=False):
        """Compute the implicit distance from the points to a surface.

        This filter will comput the implicit distance from all of the nodes of
        this mesh to a given surface. This distance will be added as a point
        array called ``'implicit_distance'``.

        Parameters
        ----------
        surface : pyvista.Common
            The surface used to compute the distance

        inplace : bool
            If True, a new scalar array will be added to the ``point_arrays``
            of this mesh. Otherwise a copy of this mesh is returned with that
            scalar field.
        """
        function = vtk.vtkImplicitPolyDataDistance()
        function.SetInput(surface)
        points = pyvista.convert_array(dataset.points)
        dists = vtk.vtkDoubleArray()
        function.FunctionValue(points, dists)
        if inplace:
            dataset.point_arrays['implicit_distance'] = pyvista.convert_array(dists)
            return
        result = dataset.copy()
        result.point_arrays['implicit_distance'] = pyvista.convert_array(dists)
        return result 
Example #13
Source File: vtkpointcloud.py    From deep-prior-pp with GNU General Public License v3.0 5 votes vote down vote up
def clearPoints(self):
        """
        Clear all points from the point cloud
        :return: None
        """
        self.vtkPoints = vtk.vtkPoints()
        self.vtkCells = vtk.vtkCellArray()
        self.vtkDepth = vtk.vtkDoubleArray()
        self.vtkDepth.SetName('DepthArray')
        self.vtkPolyData.SetPoints(self.vtkPoints)
        self.vtkPolyData.SetVerts(self.vtkCells)
        self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth)
        self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray') 
Example #14
Source File: vts_converter.py    From handyscripts with MIT License 5 votes vote down vote up
def get_array_values(dims, arr, component):
    data = vtk.vtkDoubleArray()
    arr.GetData(0,arr.GetNumberOfTuples()-1,component,component,data)
    values = np.empty(dims)
    data.ExportToVoidPointer(values)
    return values.ravel() 
Example #15
Source File: vtk_file_converter.py    From handyscripts with MIT License 5 votes vote down vote up
def get_array_values(dims, arr, component):
    data = vtk.vtkDoubleArray()
    arr.GetData(0,arr.GetNumberOfTuples()-1,component,component,data)
    values = np.empty(dims)
    data.ExportToVoidPointer(values)
    return values.ravel() 
Example #16
Source File: vtkpointcloud.py    From deep-prior with GNU General Public License v3.0 5 votes vote down vote up
def clearPoints(self):
        """
        Clear all points from the point cloud
        :return: None
        """
        self.vtkPoints = vtk.vtkPoints()
        self.vtkCells = vtk.vtkCellArray()
        self.vtkDepth = vtk.vtkDoubleArray()
        self.vtkDepth.SetName('DepthArray')
        self.vtkPolyData.SetPoints(self.vtkPoints)
        self.vtkPolyData.SetVerts(self.vtkCells)
        self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth)
        self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray') 
Example #17
Source File: vti_converter.py    From handyscripts with MIT License 4 votes vote down vote up
def create_dataset(filename):
    reader = vtk.vtkXMLImageDataReader()
    reader.SetFileName(filename)
    reader.Update()
    output = reader.GetOutput()
    
    dims = output.GetDimensions()
    fd = output.GetFieldData()
    cd = output.GetCellData()
    pd = output.GetPointData()
    
    var_names = ['x', 'y', 'z']
    for i in range(pd.GetNumberOfArrays()):
        arr = pd.GetArray(i)
        var_names.append(arr.GetName())

    tp.new_layout()
    ds = tp.active_frame().create_dataset(filename)
    # Add the XYZ variables - a dataset needs one variable before you can add a zone
    ds.add_variable(var_names[0], dtypes = [FieldDataType.Float])
    ds.add_variable(var_names[1], dtypes = [FieldDataType.Float])
    ds.add_variable(var_names[2], dtypes = [FieldDataType.Float])
    solution_time = float(filename.split('_')[-1].split('.')[0])
    strand = 1
    zone = ds.add_ordered_zone(filename, dims)
    zone.solution_time = solution_time
    zone.strand = strand

    # Write XYZ values
    spacing = output.GetSpacing()
    origin = output.GetOrigin()
    xvals = np.linspace(origin[0] - spacing[0]*dims[0]/2, origin[0] + spacing[0]*dims[0]/2, dims[0])
    yvals = np.linspace(origin[1] - spacing[1]*dims[1]/2, origin[1] + spacing[1]*dims[1]/2, dims[1])
    zvals = np.linspace(origin[2] - spacing[2]*dims[2]/2, origin[2] + spacing[2]*dims[2]/2, dims[2])
    xx,yy,zz = np.meshgrid(xvals,yvals,zvals,indexing='ij')
    zone.values(0)[:] = xx.ravel()
    zone.values(1)[:] = yy.ravel()
    zone.values(2)[:] = zz.ravel()
    
    # Write the Point Data
    var_num = 3
    for i in range(pd.GetNumberOfArrays()):
        arr = pd.GetArray(i)
        type = arr.GetDataType()
        print("Writing: ", arr.GetName())
        data = vtk.vtkDoubleArray()
        arr.GetData(0,arr.GetNumberOfTuples()-1,0,0,data)
        values = np.zeros(dims)
        data.ExportToVoidPointer(values)
        # VTI point data is not in the same IJK order as Tecplot, so we must
        # "roll" the values to reorder them.
        values = np.rollaxis(np.rollaxis(values,1), -1).ravel()
        fd_type = field_data_type(type)
        ds.add_variable(var_names[var_num], dtypes = [fd_type])
        if fd_type == FieldDataType.Float or fd_type == FieldDataType.Double:
            zone.values(var_num)[:] = values
        elif fd_type == FieldDataType.Byte or fd_type == FieldDataType.Int16:
            zone.values(var_num)[:] = values.astype(int)
        var_num += 1
    return ds 
Example #18
Source File: vti_converter_tecio.py    From handyscripts with MIT License 4 votes vote down vote up
def convert_vti_file(src,dst):
    reader = vtk.vtkXMLImageDataReader()
    reader.SetFileName(src)
    reader.Update()
    output = reader.GetOutput()
    
    dims = output.GetDimensions()
    fd = output.GetFieldData()
    cd = output.GetCellData()
    pd = output.GetPointData()
    
    var_names = ['x', 'y', 'z']
    for i in range(pd.GetNumberOfArrays()):
        arr = pd.GetArray(i)
        var_names.append(arr.GetName())

    use_double = False
    tecio.open_file(dst, src, var_names, use_double)
    solution_time = 0
    strand = 0
    tecio.create_ordered_zone(src, dims, solution_time, strand)

    # Write XYZ values
    spacing = output.GetSpacing()
    origin = output.GetOrigin()
    xvals = np.linspace(origin[0] - spacing[0]*dims[0]/2, origin[0] + spacing[0]*dims[0]/2, dims[0])
    yvals = np.linspace(origin[1] - spacing[1]*dims[1]/2, origin[1] + spacing[1]*dims[1]/2, dims[1])
    zvals = np.linspace(origin[2] - spacing[2]*dims[2]/2, origin[2] + spacing[2]*dims[2]/2, dims[2])
    xx,yy,zz = np.meshgrid(xvals,yvals,zvals,indexing='ij')
    tecio.zone_write_values(xx.ravel())
    tecio.zone_write_values(yy.ravel())
    tecio.zone_write_values(zz.ravel())
    
    # Write the Point Data
    for i in range(pd.GetNumberOfArrays()):
        arr = pd.GetArray(i)
        print("Writing: ", arr.GetName())

        # Get the data values from the array
        data = vtk.vtkDoubleArray()
        arr.GetData(0,arr.GetNumberOfTuples()-1,0,0,data)
        values = np.zeros(dims)
        data.ExportToVoidPointer(values)
        # VTI point data is not in the same IJK order as Tecplot, so we must
        # "roll" the values to reorder them.
        values = np.rollaxis(np.rollaxis(values,1), -1).ravel()
        tecio.zone_write_values(values)
    tecio.close_file() 
Example #19
Source File: vtk_file_converter.py    From handyscripts with MIT License 4 votes vote down vote up
def add_image_data(vtk_dataset, tecplot_dataset):
    assert(vtk_dataset.GetDataObjectType() == vtk.VTK_IMAGE_DATA)

    dims = vtk_dataset.GetDimensions()
    pd = vtk_dataset.GetPointData()
    
    var_names = ['x', 'y', 'z']
    for i in range(pd.GetNumberOfArrays()):
        arr = pd.GetArray(i)
        var_names.append(arr.GetName())

    zone_name = "NO ZONE NAME"
    # Add the XYZ variables - a dataset needs one variable before you can add a zone
    tecplot_dataset.add_variable(var_names[0], dtypes = [FieldDataType.Float])
    tecplot_dataset.add_variable(var_names[1], dtypes = [FieldDataType.Float])
    tecplot_dataset.add_variable(var_names[2], dtypes = [FieldDataType.Float])
    zone = tecplot_dataset.add_ordered_zone(zone_name, dims)
    
    # Write XYZ values
    spacing = vtk_dataset.GetSpacing()
    origin = vtk_dataset.GetOrigin()
    xvals = np.linspace(origin[0] - spacing[0]*dims[0]/2, origin[0] + spacing[0]*dims[0]/2, dims[0])
    yvals = np.linspace(origin[1] - spacing[1]*dims[1]/2, origin[1] + spacing[1]*dims[1]/2, dims[1])
    zvals = np.linspace(origin[2] - spacing[2]*dims[2]/2, origin[2] + spacing[2]*dims[2]/2, dims[2])
    xx,yy,zz = np.meshgrid(xvals,yvals,zvals,indexing='ij')
    zone.values(0)[:] = xx.ravel()
    zone.values(1)[:] = yy.ravel()
    zone.values(2)[:] = zz.ravel()
    
    # Write the Point Data
    var_num = 3
    for i in range(pd.GetNumberOfArrays()):
        arr = pd.GetArray(i)
        type = arr.GetDataType()
        data = vtk.vtkDoubleArray()
        arr.GetData(0,arr.GetNumberOfTuples()-1,0,0,data)
        values = np.zeros(dims)
        data.ExportToVoidPointer(values)
        # VTI point data is not in the same IJK order as Tecplot, so we must
        # "roll" the values to reorder them.
        values = np.rollaxis(np.rollaxis(values,1), -1).ravel()
        fd_type = field_data_type(type)
        tecplot_dataset.add_variable(var_names[var_num], dtypes = [fd_type])
        if fd_type == FieldDataType.Float or fd_type == FieldDataType.Double:
            zone.values(var_num)[:] = values
        elif fd_type == FieldDataType.Byte or fd_type == FieldDataType.Int16:
            zone.values(var_num)[:] = values.astype(int)
        var_num += 1
    
    return zone