5#include <vtkCellData.h>
6#include <vtkImageData.h>
7#include <vtkMultiBlockDataSet.h>
8#include <vtkPointData.h>
9#include <vtkSmartPointer.h>
10#include <vtkUnstructuredGrid.h>
12#include <vtkCellArray.h>
13#include <vtkDoubleArray.h>
15#include <vtkInformation.h>
22 this->SetNumberOfInputPorts(1);
23 this->SetNumberOfOutputPorts(1);
30 int port, vtkInformation *info) {
32 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkMultiBlockDataSet");
39 int port, vtkInformation *info) {
49 vtkInformationVector **inputVector,
50 vtkInformationVector *outputVector) {
54 auto inputMBD = vtkMultiBlockDataSet::GetData(inputVector[0]);
55 auto outputMBD = vtkMultiBlockDataSet::GetData(outputVector);
58 size_t nBlocks = inputMBD->GetNumberOfBlocks();
59 for(
size_t i = 0; i < nBlocks; i++) {
61 auto inputImage = vtkImageData::SafeDownCast(inputMBD->GetBlock(i));
63 if(inputImage ==
nullptr) {
68 auto depthArray = this->GetInputArrayToProcess(0, inputImage);
71 auto inputFD = inputImage->GetFieldData();
74 = vtkDoubleArray::SafeDownCast(inputFD->GetAbstractArray(
"CamHeight"));
76 = vtkDoubleArray::SafeDownCast(inputFD->GetAbstractArray(
"CamPosition"));
78 = vtkDoubleArray::SafeDownCast(inputFD->GetAbstractArray(
"CamDirection"));
80 = vtkDoubleArray::SafeDownCast(inputFD->GetAbstractArray(
"CamUp"));
82 = vtkDoubleArray::SafeDownCast(inputFD->GetAbstractArray(
"CamNearFar"));
84 = vtkDoubleArray::SafeDownCast(inputFD->GetAbstractArray(
"Resolution"));
87 if(depthArray ==
nullptr || camHeight ==
nullptr || camPosition ==
nullptr
88 || camDirection ==
nullptr || camUp ==
nullptr || camNearFar ==
nullptr
89 || resolution ==
nullptr) {
90 this->
printErr(
"Input depth image does not have all of the required "
91 "field data arrays (see Cinema Spec D - Data Product "
96 const size_t resX = resolution->GetValue(0);
97 const size_t resY = resolution->GetValue(1);
102 points->SetNumberOfPoints(resX * resY);
107 const size_t nTriangles = 2 * (resX - 1) * (resY - 1);
110 triangleDistortions->SetName(
"TriangleDistortion");
111 triangleDistortions->SetNumberOfComponents(1);
112 triangleDistortions->SetNumberOfTuples(nTriangles);
115 connectivityArray->SetNumberOfTuples(3 * nTriangles);
118 offsetArray->SetNumberOfTuples(nTriangles + 1);
122 switch(depthArray->GetDataType()) {
124 (status = this->execute<VTK_TT, int>(
147 cellArray->SetData(offsetArray, connectivityArray);
149 mesh->SetPoints(points);
150 mesh->SetCells(VTK_TRIANGLE, cellArray);
151 mesh->GetCellData()->AddArray(triangleDistortions);
156 auto meshPD = mesh->GetPointData();
157 auto inputPD = inputImage->GetPointData();
158 for(
int p = 0; p < inputPD->GetNumberOfArrays(); p++)
159 meshPD->AddArray(inputPD->GetAbstractArray(p));
161 outputMBD->SetBlock(i, mesh);
167 this->
printMsg(
"Complete (#images: " + std::to_string(nBlocks) +
")", 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 that approximates the geometry that is depicted by a set of depth images.
ttkDepthImageBasedGeometryApproximation()
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillInputPortInformation(int port, vtkInformation *info) override
int FillOutputPortInformation(int port, vtkInformation *info) override
~ttkDepthImageBasedGeometryApproximation() override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
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
vtkStandardNewMacro(ttkDepthImageBasedGeometryApproximation)