def RequestData(self, request, inInfo, outInfo): from vtkmodules.vtkCommonDataModel import vtkPolyData self._realAlgorithm.Update() output = vtkPolyData.GetData(outInfo, 0) output.ShallowCopy(self._realAlgorithm.GetOutput()) output.Update() return 1
def RequestData(self, request, inInfoVec, outInfoVec): from vtkmodules.vtkCommonDataModel import vtkTable, vtkDataSet, vtkPolyData input0 = vtkDataSet.GetData(inInfoVec[0], 0) input1 = vtkDataSet.GetData(inInfoVec[1], 0) output = vtkPolyData.GetData(outInfoVec, 0) # do work print("Pretend work done!") return 1
def RequestData(self, request, inInfo, outInfo): logger.debug("Requesting data...") input = self.GetInputDataObject(0, 0) trajectory_data = dsa.WrapDataObject(input) output = dsa.WrapDataObject(vtkPolyData.GetData(outInfo)) # Retrieve current time time = timesteps_util.get_timestep(self, logger=logger) # Retrieve trajectory data trajectory_times = trajectory_data.PointData["Time"] trajectory_points = trajectory_data.Points # Interpolate along the trajectory to find current position current_position = [ np.interp(time, trajectory_times, trajectory_points[:, i]) for i in range(3) ] # Expose to VTK points_vtk = vtk.vtkPoints() verts_vtk = vtk.vtkCellArray() verts_vtk.InsertNextCell(1) points_vtk.InsertPoint(0, *current_position) verts_vtk.InsertCellPoint(0) output.SetPoints(points_vtk) output.SetVerts(verts_vtk) # Interpolate remaining point data along the trajectory for dataset in trajectory_data.PointData.keys(): if dataset == "Time": continue point_data = trajectory_data.PointData[dataset] data_at_position = np.zeros(point_data.shape[1:]) if len(data_at_position.shape) > 0: for i in itertools.product( *map(range, data_at_position.shape)): point_data_i = point_data[(slice(None), ) + i] if len(trajectory_times) == len(point_data_i): data_at_position[i] = np.interp( time, trajectory_times, point_data_i) else: logger.warning( "Unable to interpolate trajectory dataset" f" {dataset}[{i}]: Length of dataset" f" ({len(point_data_i)}) does not match length of" f" trajectory times ({len(trajectory_times)}).") else: data_at_position = np.interp(time, trajectory_times, point_data) data_vtk = vtknp.numpy_to_vtk(np.array([data_at_position])) data_vtk.SetName(dataset) output.GetPointData().AddArray(data_vtk) return 1
def RequestData(self, request, inInfo, outInfo): logger.debug("Requesting data...") input = self.GetInputDataObject(0, 0) trajectory_data = dsa.WrapDataObject(input) output = dsa.WrapDataObject(vtkPolyData.GetData(outInfo)) # Shallow-copy input trajectory data to output output.ShallowCopy(input) # Retrieve current time time = timesteps_util.get_timestep(self, logger=logger) # Add age data to the points age = time - trajectory_data.PointData["Time"] age_vtk = vtknp.numpy_to_vtk(age, deep=True) age_vtk.SetName("Age") output.GetPointData().AddArray(age_vtk) return 1
def RequestData(self, request, inInfo, outInfo): logger.debug("Requesting data...") output = dsa.WrapDataObject(vtkPolyData.GetData(outInfo)) with h5py.File(self._filename, "r") as trajectory_file: subfile = trajectory_file[self._subfile] coords = np.array(subfile[self._coords_dataset]) coords[:, 1:] *= self._radial_scale logger.debug(f"Loaded coordinates with shape {coords.shape}.") # Construct a line of points points_vtk = vtk.vtkPoints() # Each ID is composed of (1) the order of the point in the line and (2) # the index in the `vtkPoints` constructed above line_vtk = vtk.vtkPolyLine() point_ids = line_vtk.GetPointIds() point_ids.SetNumberOfIds(len(coords)) for i, point in enumerate(coords): points_vtk.InsertPoint(i, *point[1:]) point_ids.SetId(i, i) output.SetPoints(points_vtk) # Set the line ordering as "cell data" output.Allocate(1, 1) output.InsertNextCell(line_vtk.GetCellType(), line_vtk.GetPointIds()) # Add time data to the points time = vtknp.numpy_to_vtk(coords[:, 0]) time.SetName("Time") output.GetPointData().AddArray(time) # Add remaining datasets from file to trajectory points with h5py.File(self._filename, "r") as trajectory_file: subfile = trajectory_file[self._subfile] for dataset in subfile: if dataset == self._coords_dataset: continue dataset_vtk = vtknp.numpy_to_vtk(subfile[dataset][:, 1:]) dataset_vtk.SetName(dataset.replace(".dat", "")) output.GetPointData().AddArray(dataset_vtk) return 1
def RequestData(self, request: str, inInfo: vtkInformation, outInfo: vtkInformation) -> int: input_src = vtkPolyData.GetData(inInfo[0]) output = vtkImageData.GetData(outInfo) output.ShallowCopy(self.slicer.slice_object(input_src)) return 1
def RequestInformation(self, request: str, inInfo: vtkInformation, outInfo: vtkInformation) -> int: input_src = vtkPolyData.GetData(inInfo[0]) info = outInfo.GetInformationObject(0) self.slicer.update_info(input_src, info) return 1