1#include <vtkDataArray.h>
3#include <vtkInformation.h>
4#include <vtkIntArray.h>
6#include <vtkObjectFactory.h>
7#include <vtkPointData.h>
8#include <vtkSmartPointer.h>
18 this->SetNumberOfInputPorts(1);
19 this->SetNumberOfOutputPorts(1);
23 vtkInformation *info) {
25 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
32 vtkInformation *info) {
41 int nbScalars = input->GetPointData()->GetNumberOfArrays();
42 AvailableFields.clear();
43 AvailableFields.resize(nbScalars);
44 for(
int i = 0; i < nbScalars; ++i) {
45 AvailableFields[i] = input->GetPointData()->GetArrayName(i);
50 vtkInformation *request,
51 vtkInformationVector **inputVector,
52 vtkInformationVector *outputVector) {
54 vtkDataSet *input = vtkDataSet::GetData(inputVector[0]);
60 vtkInformationVector **inputVector,
61 vtkInformationVector *outputVector) {
63 vtkDataSet *input = vtkDataSet::GetData(inputVector[0]);
64 vtkDataSet *output = vtkDataSet::GetData(outputVector);
66 output->ShallowCopy(input);
68 vtkPointData *inputPointData = input->GetPointData();
69 vtkNew<vtkPointData> outputPointData{};
71#ifndef TTK_ENABLE_KAMIKAZE
73 this->
printErr(
"Input has no point data.");
77 if(!outputPointData) {
78 this->
printErr(
"vtkPointData memory allocation problem.");
83 if(AvailableFields.empty()) {
89 for(
auto &scalar : SelectedFields) {
96 = std::find(AvailableFields.begin(), AvailableFields.end(), scalar)
97 - AvailableFields.begin();
98 if(pos < RangeId[0] || pos > RangeId[1]) {
102 if(!std::regex_match(scalar, std::regex(RegexpString))) {
106 vtkDataArray *arr = inputPointData->GetArray(scalar.c_str());
110 if(SelectedFields.size() != 1 && RangeId[1] - RangeId[0] != 0) {
111 this->
printErr(
"Can't rename more than one field.");
117 localFieldCopy->DeepCopy(arr);
118 localFieldCopy->SetName(SelectedFieldName.data());
119 arr = localFieldCopy;
123 outputPointData->AddArray(arr);
126 }
catch(std::regex_error &) {
130 output->GetPointData()->ShallowCopy(outputPointData);
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
static vtkInformationIntegerKey * SAME_DATA_TYPE_AS_INPUT_PORT()
virtual int RequestInformation(vtkInformation *ttkNotUsed(request), vtkInformationVector **ttkNotUsed(inputVectors), vtkInformationVector *ttkNotUsed(outputVector))
TTK VTK-filter that selects scalar fields on input with shallow copy.
int FillOutputPortInformation(int port, vtkInformation *info) override
int FillInputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
void FillAvailableFields(vtkDataSet *input)
int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
void setDebugMsgPrefix(const std::string &prefix)
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
vtkStandardNewMacro(ttkPointDataSelector)