7#include <vtkCellData.h>
9#include <vtkIdTypeArray.h>
10#include <vtkInformation.h>
11#include <vtkIntArray.h>
12#include <vtkPointData.h>
21 SetNumberOfInputPorts(1);
22 SetNumberOfOutputPorts(1);
26 vtkInformation *info) {
28 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
36 vtkInformation *info) {
45template <
typename VTK_TT>
49 auto greater_cmp = [=](
int a,
int b) {
return arr[a] > arr[b]; };
50 auto lower_cmp = [=](
int a,
int b) {
return arr[a] < arr[b]; };
53 std::sort(inputIds.begin(), inputIds.end(), lower_cmp);
55 std::sort(inputIds.begin(), inputIds.end(), greater_cmp);
62 vtkInformationVector **inputVector,
63 vtkInformationVector *outputVector) {
64 vtkDataSet *input = vtkDataSet::GetData(inputVector[0]);
65 vtkDataSet *output = vtkDataSet::GetData(outputVector);
67 inputScalars_ = this->GetInputArrayToProcess(0, inputVector);
71 int inputArrayAssociation = this->GetInputArrayAssociation(0, inputVector);
73 if(inputArrayAssociation > 1 || inputArrayAssociation < 0) {
74 printErr(
"input array has to be cell data or point data.");
82 const SimplexId numberOfValues = inputArrayAssociation == 0
83 ? input->GetNumberOfPoints()
84 : input->GetNumberOfCells();
86 vector<SimplexId> inputIds(numberOfValues);
87 std::iota(inputIds.begin(), inputIds.end(), 0);
88 switch(inputScalars_->GetDataType()) {
89 vtkTemplateMacro(dispatch<VTK_TT>(inputIds));
96 ids->SetNumberOfComponents(1);
97 ids->SetNumberOfTuples(numberOfValues);
98 ids->SetName(inputArrayAssociation == 0 ?
"PointScalarFieldName"
99 :
"CellScalarFieldName");
104 for(
int i = 0; i < numberOfValues; ++i)
105 outputIds[inputIds[i]] = i;
107 for(
int i = 0; i < numberOfValues; ++i)
111 output->ShallowCopy(input);
113 if(inputArrayAssociation == 0) {
114 output->GetPointData()->AddArray(ids);
116 output->GetCellData()->AddArray(ids);
#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()
TTK VTK-filter that computes a new scalar array based on a sorting of the input array.
int dispatch(std::vector< ttk::SimplexId > &inputIds)
ttkIdentifyByScalarField()
int FillInputPortInformation(int port, vtkInformation *info) override
int FillOutputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
void setDebugMsgPrefix(const std::string &prefix)
int printMsg(const std::string &msg, const debug::Priority &priority=debug::Priority::INFO, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cout) const
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
int SimplexId
Identifier type for simplices of any dimension.
vtkStandardNewMacro(ttkIdentifyByScalarField)