4#include <vtkFloatArray.h>
5#include <vtkInformation.h>
7#include <vtkPointData.h>
8#include <vtkUnstructuredGrid.h>
15 this->SetNumberOfInputPorts(1);
16 this->SetNumberOfOutputPorts(1);
22 vtkInformation *info) {
24 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkPointSet");
31 vtkInformation *info) {
40 vtkUnstructuredGrid *
const inputDiagram,
41 vtkUnstructuredGrid *
const outputDiagram) {
43 auto pointData = inputDiagram->GetPointData();
46 const auto critCoordinates = vtkFloatArray::SafeDownCast(
48 bool embed = critCoordinates ==
nullptr;
54 if(critCoordinates ==
nullptr) {
55 this->
printErr(
"Missing `Coordinates' vtkPointData array");
58 if(critCoordinates->GetNumberOfComponents() != 3) {
59 this->
printErr(
"`Coordinates' array should have 3 components");
65 return ret == 0 ? 1 : 0;
69 vtkInformationVector **inputVector,
70 vtkInformationVector *outputVector) {
74 vtkPointSet *input = vtkPointSet::GetData(inputVector[0]);
75 vtkPointSet *output = vtkPointSet::GetData(outputVector, 0);
77 if(this->ProjectPersistenceDiagram) {
78 auto inputGrid = vtkUnstructuredGrid::SafeDownCast(input);
79 auto outputGrid = vtkUnstructuredGrid::SafeDownCast(output);
80 if(inputGrid !=
nullptr && outputGrid !=
nullptr) {
83 this->
printErr(
"Input should be a vtkUnstructuredGrid");
87 output->ShallowCopy(input);
89 vtkNew<vtkPoints> pointSet{};
90 pointSet->SetNumberOfPoints(input->GetNumberOfPoints());
92 if(UseTextureCoordinates) {
94 const auto textureCoordinates = input->GetPointData()->GetTCoords();
95 if(textureCoordinates ==
nullptr) {
98 printMsg(
"Starting computation with texture coordinates...");
100#ifdef TTK_ENABLE_OPENMP
101#pragma omp parallel for num_threads(threadNumber_)
103 for(
int i = 0; i < input->GetNumberOfPoints(); i++) {
104 std::array<double, 3> pt{};
105 textureCoordinates->GetTuple(i, pt.data());
106 pointSet->SetPoint(i, pt[0], pt[1], pt[2]);
109 }
else if(this->Use3DCoordinatesArray) {
111 const auto inputCoordsArray = this->GetInputArrayToProcess(2, inputVector);
112 if(inputCoordsArray ==
nullptr) {
115 printMsg(
"Starting computation...");
116 printMsg(std::vector<std::vector<std::string>>{
117 {
" Coordinates Array", inputCoordsArray->GetName()}});
119#ifdef TTK_ENABLE_OPENMP
120#pragma omp parallel for num_threads(threadNumber_)
122 for(
int i = 0; i < input->GetNumberOfPoints(); i++) {
123 std::array<double, 3> pt{};
124 inputCoordsArray->GetTuple(i, pt.data());
125 pointSet->SetPoint(i, pt[0], pt[1], pt[2]);
130 const auto inputScalarFieldU = this->GetInputArrayToProcess(0, inputVector);
131 const auto inputScalarFieldV = this->GetInputArrayToProcess(1, inputVector);
133 if(inputScalarFieldU ==
nullptr || inputScalarFieldV ==
nullptr) {
137 printMsg(
"Starting computation...");
138 printMsg({{
" U-component", inputScalarFieldU->GetName()},
139 {
" V-component", inputScalarFieldV->GetName()}});
141#ifdef TTK_ENABLE_OPENMP
142#pragma omp parallel for num_threads(threadNumber_)
144 for(
int i = 0; i < input->GetNumberOfPoints(); i++) {
145 pointSet->SetPoint(i, inputScalarFieldU->GetComponent(i, 0),
146 inputScalarFieldV->GetComponent(i, 0), 0);
150 output->SetPoints(pointSet);
152 printMsg(std::to_string(input->GetNumberOfPoints()) +
" points projected", 1,
#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 which projects a data-set to 2D given two point-data scalar fields to be used as 2D co...
int projectPersistenceDiagram(vtkUnstructuredGrid *const inputDiagram, vtkUnstructuredGrid *const outputDiagram)
Switch a given Persistence Diagram representation.
int FillOutputPortInformation(int port, vtkInformation *info) override
int FillInputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
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
const char PersistenceCoordinatesName[]
int ProjectDiagramInsideDomain(vtkUnstructuredGrid *const inputDiagram, vtkUnstructuredGrid *const outputDiagram, const ttk::Debug &dbg)
Generate the spatial embedding of a given Persistence Diagram.
int ProjectDiagramIn2D(vtkUnstructuredGrid *const inputDiagram, vtkUnstructuredGrid *const outputDiagram, const ttk::Debug &dbg)
Generate the 2D embedding of a given Persistence Diagram.
vtkStandardNewMacro(ttkProjectionFromField)