18 #include <vtkCellData.h>
19 #include <vtkDoubleArray.h>
20 #include <vtkInformation.h>
21 #include <vtkInformationVector.h>
22 #include <vtkObjectFactory.h>
23 #include <vtkPointData.h>
24 #include <vtkSmartPointer.h>
25 #include <vtkStreamingDemandDrivenPipeline.h>
26 #include <vtkUnstructuredGrid.h>
38 this->Superclass::PrintSelf(os, indent);
39 os << indent <<
"== VtkAppendArrayFilter ==" << endl;
43 vtkInformationVector** inputVector,
44 vtkInformationVector* outputVector)
48 ERR(
"VtkAppendArrayFilter::RequestData(): Selection array is empty.");
51 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
52 vtkUnstructuredGrid* input = vtkUnstructuredGrid::SafeDownCast(
53 inInfo->Get(vtkDataObject::DATA_OBJECT()));
55 vtkSmartPointer<vtkDoubleArray> colors =
56 vtkSmartPointer<vtkDoubleArray>::New();
57 colors->SetNumberOfComponents(1);
58 std::size_t arrayLength = this->
_array.size();
59 colors->SetNumberOfValues(arrayLength);
60 colors->SetName(
"Selection");
62 std::size_t nCells = input->GetNumberOfCells();
63 if (nCells > arrayLength)
65 "VtkAppendArrayFilter::RequestData(): Number of cells exceeds "
66 "selection array length. Surplus cells won't be examined.");
68 for (std::size_t i = 0; i < arrayLength; i++)
70 colors->SetValue(i,
_array[i]);
73 vtkInformation* outInfo = outputVector->GetInformationObject(0);
74 vtkUnstructuredGrid* output = vtkUnstructuredGrid::SafeDownCast(
75 outInfo->Get(vtkDataObject::DATA_OBJECT()));
76 output->CopyStructure(input);
77 output->GetPointData()->PassData(input->GetPointData());
78 output->GetCellData()->PassData(input->GetCellData());
79 output->GetCellData()->AddArray(colors);
80 output->GetCellData()->SetActiveScalars(
_array_name.c_str());
86 const std::vector<double>& new_array)
void ERR(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... args)
vtkStandardNewMacro(VtkAppendArrayFilter)
Definition of the VtkAppendArrayFilter class.
std::vector< double > _array
void SetArray(const std::string &array_name, const std::vector< double > &new_array)
~VtkAppendArrayFilter() override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
The filter logic.
void PrintSelf(ostream &os, vtkIndent indent) override
Prints the mesh data to an output stream.