def __init__(self, pos, cell): """Construct basic VTK-representation of a set of atomic positions. pos: NumPy array of dtype float and shape ``(n,3)`` Cartesian positions of the atoms. cell: Instance of vtkUnitCellModule of subclass thereof Holds information equivalent to that of atoms.get_cell(). """ # Make sure position argument is a valid array if not isinstance(pos, np.ndarray): pos = np.array(pos) assert pos.dtype == float and pos.shape[1:] == (3, ) vtkBaseGrid.__init__(self, len(pos), cell) # Convert positions to VTK array npy2da = vtkDoubleArrayFromNumPyArray(pos) vtk_pda = npy2da.get_output() del npy2da # Transfer atomic positions to VTK points self.vtk_pts = vtkPoints() self.vtk_pts.SetData(vtk_pda) # Create a VTK unstructured grid of these points self.vtk_ugd = vtkUnstructuredGrid() self.vtk_ugd.SetWholeBoundingBox(self.cell.get_bounding_box()) self.vtk_ugd.SetPoints(self.vtk_pts) # Extract the VTK point data set self.set_point_data(self.vtk_ugd.GetPointData())
def __init__(self, pos, cell): """Construct basic VTK-representation of a set of atomic positions. pos: NumPy array of dtype float and shape ``(n,3)`` Cartesian positions of the atoms. cell: Instance of vtkUnitCellModule of subclass thereof Holds information equivalent to that of atoms.get_cell(). """ # Make sure position argument is a valid array if not isinstance(pos, np.ndarray): pos = np.array(pos) assert pos.dtype == float and pos.shape[1:] == (3,) vtkBaseGrid.__init__(self, len(pos), cell) # Convert positions to VTK array npy2da = vtkDoubleArrayFromNumPyArray(pos) vtk_pda = npy2da.get_output() del npy2da # Transfer atomic positions to VTK points self.vtk_pts = vtkPoints() self.vtk_pts.SetData(vtk_pda) # Create a VTK unstructured grid of these points self.vtk_ugd = vtkUnstructuredGrid() self.vtk_ugd.SetWholeBoundingBox(self.cell.get_bounding_box()) self.vtk_ugd.SetPoints(self.vtk_pts) # Extract the VTK point data set self.set_point_data(self.vtk_ugd.GetPointData())
def add_scalar_property(self, data, name=None, active=True): """Add VTK-representation of scalar data at the atomic positions. data: NumPy array of dtype float and shape ``(n,)`` Scalar values corresponding to the atomic positions. name=None: str Unique identifier for the scalar data. active=True: bool Flag indicating whether to use as active scalar data. """ # Make sure data argument is a valid array if not isinstance(data, np.ndarray): data = np.array(data) assert data.dtype == float and data.shape == (self.npoints, ) # Convert scalar properties to VTK array npa2da = vtkDoubleArrayFromNumPyArray(data) return vtkBaseGrid.add_scalar_data_array(self, npa2da, name, active)
def add_vector_property(self, data, name=None, active=True): """Add VTK-representation of vector data at the atomic positions. data: NumPy array of dtype float and shape ``(n,3)`` Vector components corresponding to the atomic positions. name=None: str Unique identifier for the vector data. active=True: bool Flag indicating whether to use as active vector data. """ # Make sure data argument is a valid array if not isinstance(data, np.ndarray): data = np.array(data) assert data.dtype == float and data.shape == (self.npoints,3,) # Convert vector properties to VTK array npa2da = vtkDoubleArrayFromNumPyArray(data) return vtkBaseGrid.add_vector_data_array(self, npa2da, name, active)