5#include <vtkCellData.h>
6#include <vtkInformation.h>
7#include <vtkPointData.h>
8#include <vtkUnstructuredGrid.h>
13 SetNumberOfInputPorts(1);
14 SetNumberOfOutputPorts(1);
18 vtkInformation *info) {
20 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
27 vtkInformation *info) {
29 info->Set(vtkDataObject::DATA_TYPE_NAME(),
"vtkUnstructuredGrid");
36 vtkDataArray *
const inputScalarField,
int ntuples)
const {
41 switch(inputScalarField->GetDataType()) {
48 res = inputScalarField->NewInstance();
51 this->
printErr(
"Unsupported data array type");
54 res->SetNumberOfComponents(1);
55 res->SetNumberOfTuples(ntuples);
56 res->SetName(inputScalarField->GetName());
61 vtkDataSet *
const input,
62 vtkUnstructuredGrid *
const output,
65 const size_t npointdata = input->GetPointData()->GetNumberOfArrays();
66 const size_t ncelldata = input->GetCellData()->GetNumberOfArrays();
70 for(
size_t i = 0; i < npointdata; ++i) {
71 auto inputScalarField = input->GetPointData()->GetArray(i);
72 if(inputScalarField ==
nullptr) {
76#define DISPATCH_INTERPOLATE_DIS(CASE, TYPE) \
78 this->interpolateDiscreteScalarField<TYPE>( \
79 static_cast<TYPE *>(ttkUtils::GetVoidPointer(inputScalarField)), \
80 static_cast<TYPE *>(ttkUtils::GetVoidPointer(outputScalarField))); \
82#define DISPATCH_INTERPOLATE_CONT(CASE, TYPE) \
84 switch(inputTriangulation.getType()) { \
85 BARYSUBD_TRIANGL_CALLS( \
86 TYPE, ttk::Triangulation::Type::EXPLICIT, ttk::ExplicitTriangulation) \
87 BARYSUBD_TRIANGL_CALLS(TYPE, ttk::Triangulation::Type::IMPLICIT, \
88 ttk::ImplicitNoPreconditions) \
89 BARYSUBD_TRIANGL_CALLS(TYPE, ttk::Triangulation::Type::HYBRID_IMPLICIT, \
90 ttk::ImplicitWithPreconditions) \
91 BARYSUBD_TRIANGL_CALLS( \
92 TYPE, ttk::Triangulation::Type::COMPACT, ttk::CompactTriangulation) \
93 BARYSUBD_TRIANGL_CALLS(TYPE, ttk::Triangulation::Type::PERIODIC, \
94 ttk::PeriodicNoPreconditions) \
95 BARYSUBD_TRIANGL_CALLS(TYPE, ttk::Triangulation::Type::HYBRID_PERIODIC, \
96 ttk::PeriodicWithPreconditions) \
99#define BARYSUBD_TRIANGL_CALLS(DATATYPE, TRIANGL_CASE, TRIANGL_TYPE) \
100 case TRIANGL_CASE: { \
102 = static_cast<TRIANGL_TYPE *>(inputTriangulation.getData()); \
103 if(inpTri != nullptr) { \
104 this->interpolateContinuousScalarField<DATATYPE, TRIANGL_TYPE>( \
105 static_cast<DATATYPE *>(ttkUtils::GetVoidPointer(inputScalarField)), \
106 static_cast<DATATYPE *>(ttkUtils::GetVoidPointer(outputScalarField)), \
112 auto outputScalarField
114 if(outputScalarField ==
nullptr) {
119 switch(inputScalarField->GetDataType()) {
127 output->GetPointData()->AddArray(outputScalarField);
132 for(
size_t i = 0; i < ncelldata; ++i) {
133 auto inputScalarField = input->GetCellData()->GetArray(i);
134 if(inputScalarField ==
nullptr) {
138 auto outputScalarField
140 if(outputScalarField ==
nullptr) {
145 switch(inputScalarField->GetDataType()) {
146 vtkTemplateMacro(this->interpolateCellDataField<VTK_TT>(
150 output->GetCellData()->AddArray(outputScalarField);
157 vtkInformationVector **inputVector,
158 vtkInformationVector *outputVector) {
162 auto input = vtkDataSet::GetData(inputVector[0]);
163 auto output = vtkUnstructuredGrid::GetData(outputVector);
168 if(triangulation ==
nullptr) {
169 printMsg(
"Error, internal triangulation is empty.");
174 if(SubdivisionLevel == 0) {
175 output->ShallowCopy(input);
182 int ret = this->
execute(*triangulation, triangulationSubdivision);
184 this->
printErr(
"Could not subdivide input mesh");
191 this->
printErr(
"Error interpolating input data array(s)");
195 for(
unsigned int i = 1; i < SubdivisionLevel; ++i) {
207 decltype(triangulationSubdivision) tmpTr{};
208 std::swap(triangulationSubdivision, tmpTr);
210#ifdef TTK_CELL_ARRAY_NEW
212 tmpCellsOff.size() - 1, tmpCellsCo.data(), tmpCellsOff.data());
216 tmpTr.setInputCells(tmpCellsCo.size() - 1, tmpCells);
218 tmpTr.setInputPoints(tmpPoints.size() / 3, tmpPoints.data());
222 this->
execute(*triangulation, triangulationSubdivision);
230 for(
size_t i = 0; i <
points_.size() / 3; i++) {
231 points->InsertNextPoint(&
points_[3 * i]);
233 output->SetPoints(points);
240 output->SetCells(VTK_TRIANGLE, cells);
244 cellId->SetName(
"CellId");
246 output->GetPointData()->AddArray(cellId);
250 cellDim->SetName(
"CellDimension");
252 output->GetPointData()->AddArray(cellDim);
255 output->GetFieldData()->ShallowCopy(input->GetFieldData());
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
ttk::Triangulation * GetTriangulation(vtkDataSet *dataSet)
TTK VTK-filter that wraps the ttk::BarycentricSubdivision processing package.
vtkSmartPointer< vtkDataArray > AllocateScalarField(vtkDataArray *const inputScalarField, int ntuples) const
Allocate an output array of same type that input array.
int FillInputPortInformation(int port, vtkInformation *info) override
int FillOutputPortInformation(int port, vtkInformation *info) override
ttkBarycentricSubdivision()
int InterpolateScalarFields(vtkDataSet *const input, vtkUnstructuredGrid *const output, ttk::Triangulation &inputTriangulation) const
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
static void SetVoidArray(vtkDataArray *array, void *data, vtkIdType size, int save)
SimplexId getNumberOfVertices() const
Return the number of vertices in the output triangulation.
std::vector< float > points_
std::vector< LongSimplexId > cells_connectivity_
void preconditionTriangulation(AbstractTriangulation *const triangulation)
int execute(const triangulationType &inputTriangl, ExplicitTriangulation &outputTriangl)
std::vector< SimplexId > pointId_
SimplexId getNumberOfTriangles() const
Return the number of triangles in the output triangulation.
std::vector< LongSimplexId > cells_offsets_
std::vector< SimplexId > pointDim_
static void TranslateToFlatLayout(std::vector< LongSimplexId > &connectivity, std::vector< LongSimplexId > &offset, LongSimplexId *&singleArray)
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
ExplicitTriangulation is a class that provides time efficient traversal methods on triangulations of ...
Triangulation is a class that provides time and memory efficient traversal methods on triangulations ...
long long int LongSimplexId
Identifier type for simplices of any dimension.
#define DISPATCH_INTERPOLATE_DIS(CASE, TYPE)
vtkStandardNewMacro(ttkBarycentricSubdivision)
#define DISPATCH_INTERPOLATE_CONT(CASE, TYPE)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)