OGS
VtkAppendArrayFilter.cpp
Go to the documentation of this file.
1
15// ** VTK INCLUDES **
17
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>
27
28#include "BaseLib/Logging.h"
29
31
33
35
36void VtkAppendArrayFilter::PrintSelf(ostream& os, vtkIndent indent)
37{
38 this->Superclass::PrintSelf(os, indent);
39 os << indent << "== VtkAppendArrayFilter ==" << endl;
40}
41
42int VtkAppendArrayFilter::RequestData(vtkInformation* /*request*/,
43 vtkInformationVector** inputVector,
44 vtkInformationVector* outputVector)
45{
46 if (this->_array.empty())
47 {
48 ERR("VtkAppendArrayFilter::RequestData(): Selection array is empty.");
49 return 0;
50 }
51 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
52 vtkUnstructuredGrid* input = vtkUnstructuredGrid::SafeDownCast(
53 inInfo->Get(vtkDataObject::DATA_OBJECT()));
54
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");
61
62 std::size_t nCells = input->GetNumberOfCells();
63 if (nCells > arrayLength)
64 WARN(
65 "VtkAppendArrayFilter::RequestData(): Number of cells exceeds "
66 "selection array length. Surplus cells won't be examined.");
67
68 for (std::size_t i = 0; i < arrayLength; i++)
69 {
70 colors->SetValue(i, _array[i]);
71 }
72
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());
81
82 return 1;
83}
84
85void VtkAppendArrayFilter::SetArray(const std::string& array_name,
86 const std::vector<double>& new_array)
87{
88 this->_array_name = array_name;
89 this->_array = new_array;
90}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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.