Example #1
0
 def _load_species(self, itr, species, arrays, piece, npieces, ugrid):
     nparticles = self._get_num_particles(itr, species)
     nlocalparticles = nparticles // npieces
     start = nlocalparticles * piece
     end = start + nlocalparticles - 1
     if piece == npieces - 1:
         end = nparticles - 1
     pts = self._load_particles(itr, species, start, end)
     npts = pts.shape[0]
     ugrid.Points = pts
     for array in arrays:
         if array[1] == 'position' or array[1] == 'positionOffset':
             continue
         ugrid.PointData.append(
             self._load_particle_array(itr, array[0], array[1], start, end),
             array[1])
     from vtkmodules.vtkCommonDataModel import vtkCellArray
     ca = vtkCellArray()
     if npts < np.iinfo(np.int32).max:
         dtype = np.int32
     else:
         dtype = np.int64
     offsets = np.linspace(0, npts, npts + 1, dtype=dtype)
     cells = np.linspace(0, npts - 1, npts, dtype=dtype)
     from vtkmodules.numpy_interface import dataset_adapter
     offsets = dataset_adapter.numpyTovtkDataArray(offsets)
     offsets2 = offsets.NewInstance()
     offsets2.DeepCopy(offsets)
     cells = dataset_adapter.numpyTovtkDataArray(cells)
     cells2 = cells.NewInstance()
     cells2.DeepCopy(cells)
     ca.SetData(offsets2, cells2)
     from vtkmodules.util import vtkConstants
     ugrid.VTKObject.SetCells(vtkConstants.VTK_VERTEX, ca)
Example #2
0
 def t_coords(self, t_coords: np.ndarray):
     """Set the active texture coordinates using an np.ndarray."""
     if not isinstance(t_coords, np.ndarray):
         raise TypeError('Texture coordinates must be a numpy array')
     if t_coords.ndim != 2:
         raise ValueError('Texture coordinates must be a 2-dimensional array')
     valid_length = self.valid_array_len
     if t_coords.shape[0] != valid_length:
         raise ValueError(f'Number of texture coordinates ({t_coords.shape[0]}) must match number of points ({valid_length})')
     if t_coords.shape[1] != 2:
         raise ValueError('Texture coordinates must only have 2 components,'
                          f' not ({t_coords.shape[1]})')
     vtkarr = numpyTovtkDataArray(t_coords, name='Texture Coordinates')
     self.SetTCoords(vtkarr)
     self.Modified()