1#include <vtkDataArray.h>
3#include <vtkFloatArray.h>
4#include <vtkInformation.h>
5#include <vtkObjectFactory.h>
6#include <vtkPointData.h>
16 this->SetNumberOfInputPorts(1);
17 this->SetNumberOfOutputPorts(1);
21 vtkInformation *info) {
23 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
29 vtkInformation *info) {
38 vtkInformationVector **inputVector,
39 vtkInformationVector *outputVector) {
41 const auto input = vtkDataSet::GetData(inputVector[0]);
42 auto output = vtkDataSet::GetData(outputVector);
46 output->ShallowCopy(input);
48 const auto inputScalarFieldU = this->GetInputArrayToProcess(0, input);
49 const auto inputScalarFieldV = this->GetInputArrayToProcess(1, input);
51 if(inputScalarFieldU ==
nullptr || inputScalarFieldV ==
nullptr) {
55 vtkNew<vtkFloatArray> textureCoordinates{};
56 textureCoordinates->SetNumberOfComponents(2);
57 textureCoordinates->SetName(
"UV coordinates from field");
59 if(textureCoordinates->GetNumberOfTuples() != output->GetNumberOfPoints()) {
60 textureCoordinates->SetNumberOfTuples(output->GetNumberOfPoints());
63 double uRange[2], vRange[2];
64 inputScalarFieldU->GetRange(uRange);
65 inputScalarFieldV->GetRange(vRange);
67 std::vector<std::array<double, 2>> coordinates(
threadNumber_);
69#ifdef TTK_ENABLE_OPENMP
70#pragma omp parallel for num_threads(threadNumber_)
72 for(
int i = 0; i < output->GetNumberOfPoints(); i++) {
76#ifdef TTK_ENABLE_OPENMP
77 threadId = omp_get_thread_num();
80 coordinates[threadId][0] = coordinates[threadId][1] = 0;
83 inputScalarFieldU->GetTuple(i, &(coordinates[threadId][0]));
85 coordinates[threadId][0]
86 = (coordinates[threadId][0] - uRange[0]) / (uRange[1] - uRange[0]);
91 inputScalarFieldV->GetTuple(i, &(coordinates[threadId][1]));
93 coordinates[threadId][1]
94 = (coordinates[threadId][1] - vRange[0]) / (vRange[1] - vRange[0]);
98 textureCoordinates->SetTuple(i, coordinates[threadId].data());
101 output->GetPointData()->SetTCoords(textureCoordinates);
104 "Computed texture map", 1.0, t.
getElapsedTime(), this->threadNumber_);
#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 generates a texture map from one or two point data scalar fields.
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillOutputPortInformation(int port, vtkInformation *info) override
int FillInputPortInformation(int port, vtkInformation *info) 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 ThreadId
Identifier type for threads (i.e. with OpenMP).
vtkStandardNewMacro(ttkTextureMapFromField)