35 info->Remove(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
37 vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkMultiBlockDataSet");
39 vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkUnstructuredGrid");
40 info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkPolyData");
42 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkPointSet");
58 vtkInformationVector **inputVector,
59 vtkInformationVector *outputVector) {
61 auto inputObject = vtkDataObject::GetData(inputVector[0]);
62 auto inputGrid = vtkPointSet::GetData(inputVector[1]);
63 auto outputCollection = vtkMultiBlockDataSet::GetData(outputVector);
64 if(!inputObject || !inputGrid) {
65 this->
printErr(
"Unsupported input object types.");
70 if(inputObject->IsA(
"vtkMultiBlockDataSet"))
71 inputObjectAsMB->ShallowCopy(inputObject);
73 inputObjectAsMB->SetBlock(0, inputObject);
74 const size_t nInputObjects = inputObjectAsMB->GetNumberOfBlocks();
77 std::vector<double> defaultFocalPoint{
78 this->FocalPoint[0], this->FocalPoint[1], this->FocalPoint[2]};
79 std::vector<double> defaultNearFar{this->NearFar[0], this->NearFar[1]};
80 double defaultHeight = this->Height;
81 double const defaultAngle = this->Angle;
83 if(this->AutoFocalPoint || this->AutoNearFar || this->AutoHeight) {
85 double objectBounds[6];
86 inputObjectAsMB->GetBounds(objectBounds);
88 auto norm = [](
const double v[3]) {
89 return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
92 const double d[3]{objectBounds[1] - objectBounds[0],
93 objectBounds[3] - objectBounds[2],
94 objectBounds[5] - objectBounds[4]};
95 const double objectDiameter = norm(d);
97 const double c[3]{objectBounds[0] + 0.5 * d[0],
98 objectBounds[2] + 0.5 * d[1],
99 objectBounds[4] + 0.5 * d[2]};
101 if(this->AutoFocalPoint) {
102 defaultFocalPoint[0] = c[0];
103 defaultFocalPoint[1] = c[1];
104 defaultFocalPoint[2] = c[2];
107 if(this->AutoNearFar) {
108 double gridBounds[6];
109 inputGrid->GetBounds(gridBounds);
112 gridBounds[0] - c[0],
113 gridBounds[2] - c[1],
114 gridBounds[4] - c[2],
116 const double ld = norm(l);
118 defaultNearFar[0] = std::max(0.01, ld - objectDiameter * 0.5);
119 defaultNearFar[1] = ld + objectDiameter * 0.5;
122 if(this->AutoHeight) {
123 defaultHeight = objectDiameter;
130 aInputGrid->ShallowCopy(inputGrid);
131 int const n = aInputGrid->GetNumberOfPoints();
132 auto aInputGridPD = aInputGrid->GetPointData();
135 aInputGridPD,
"Resolution", n,
136 {(double)this->Resolution[0], (
double)this->Resolution[1]});
138 aInputGridPD,
"ProjectionMode", n, {(double)this->ProjectionMode});
141 aInputGridPD,
"CamNearFar", n, defaultNearFar);
143 aInputGridPD,
"CamHeight", n, {defaultHeight});
147 const bool gridHasDirection = aInputGridPD->HasArray(
"CamDirection");
148 const bool gridHasFocalPoint = aInputGridPD->HasArray(
"CamFocalPoint");
149 if(gridHasFocalPoint || !gridHasDirection) {
151 aInputGridPD,
"CamFocalPoint", n, defaultFocalPoint);
155 aInputGridPD,
"CamDirection", n, {0, 0, -1});
162 {
"Backend", this->Backend == 0 ? std::string(
"VTK_OPENGL")
163 : this->Backend == 1 ? std::string(
"EMBREE")
164 : std::string(
"NATIVE")},
167 {
"Projection", this->ProjectionMode ?
"Perspective" :
"Orthographic"},
170 {
"CamFocalPoint", gridHasDirection || gridHasFocalPoint
175 {std::string(this->ProjectionMode == 0 ?
"CamHeight" :
"CamAngle"),
182 for(
size_t b = 0; b < nInputObjects; b++) {
185 = vtkPointSet::SafeDownCast(inputObjectAsMB->GetBlock(b));
186 if(!inputPointSet->IsA(
"vtkUnstructuredGrid")
187 && !inputPointSet->IsA(
"vtkPolyData")) {
188 this->
printErr(
"Unsupported input object type.");
193 inputPointSet, aInputGrid, defaultFocalPoint,
194 defaultNearFar, defaultHeight, defaultAngle);
195 outputAsMB->SetBlock(b, outputImages);
198 if(inputObject->IsA(
"vtkMultiBlockDataSet"))
199 outputCollection->ShallowCopy(outputAsMB);
201 outputCollection->ShallowCopy(outputAsMB->GetBlock(0));
207 vtkMultiBlockDataSet *outputImages,
209 vtkPointSet *inputObject,
210 vtkPointSet *inputGrid,
211 const std::vector<double> &
ttkNotUsed(defaultFocalPoint),
212 const std::vector<double> &
ttkNotUsed(defaultNearFar),
221 size_t const nTriangles = cells->GetNumberOfCells();
224 auto offsets =
static_cast<vtkIdType *
>(
227 for(
size_t i = 0; i < nTriangles; i++, j += 3) {
228 if(j != offsets[i]) {
229 this->
printErr(
"Connectivity list has to contain only triangles.");
236 if(this->Backend == 0) {
240 status = renderer.
RenderVTKObject(outputImages, inputObject, inputGrid);
241 }
else if(this->Backend == 1) {
245 status = renderer.
RenderVTKObject(outputImages, inputObject, inputGrid);
250 status = renderer.
RenderVTKObject(outputImages, inputObject, inputGrid);
272 const std::string &name) {
276 size_t const nComponents = array->GetNumberOfComponents();
279 newArray->SetName(name.empty() ? array->GetName() : name.data());
280 newArray->SetNumberOfComponents(nComponents);
281 newArray->SetNumberOfTuples(1);
283 if(newArray->GetDataType() == array->GetDataType()) {
284 newArray->SetTuple(0, tupleIdx, array);
286 for(
size_t i = 0; i < nComponents; i++)
288 i, array->GetVariantValue(tupleIdx * nComponents + i).ToDouble());
291 fd->AddArray(newArray);
337 const std::string &name,
339 const std::vector<double> &defaultValues) {
340 auto array = vtkDoubleArray::SafeDownCast(fd->GetArray(name.data()));
343 int const nComponents = defaultValues.size();
346 newArray->SetName(name.data());
347 newArray->SetNumberOfComponents(nComponents);
348 newArray->SetNumberOfTuples(nTuples);
351 for(
int i = 0, q = 0; i < nTuples; i++)
352 for(
int j = 0; j < nComponents; j++)
353 data[q++] = defaultValues[j];
355 fd->AddArray(newArray);
393 vtkImageData *outputImage,
395 vtkPointSet *inputObject,
397 const unsigned int *primitiveIdArray,
398 const float *barycentricCoordinates,
399 const vtkIdType *inputObjectConnectivityList) {
401 auto inputObjectPD = inputObject->GetPointData();
402 auto inputObjectCD = inputObject->GetCellData();
403 auto outputImagePD = outputImage->GetPointData();
405 outputImage->GetDimensions(dim);
406 size_t const nPixels = dim[0] * dim[1];
408 const size_t nInputObjectPDArrays = inputObjectPD->GetNumberOfArrays();
409 const size_t nInputObjectCDArrays = inputObjectCD->GetNumberOfArrays();
414 for(
size_t j = 0; j < nInputObjectPDArrays; j++) {
415 auto inputArray = inputObjectPD->GetArray(j);
418 outputArray->SetName(inputArray->GetName());
419 outputArray->SetNumberOfComponents(inputArray->GetNumberOfComponents());
420 outputArray->SetNumberOfTuples(nPixels);
422 outputImagePD->AddArray(outputArray);
424 switch(outputArray->GetDataType()) {
428 primitiveIdArray, barycentricCoordinates,
429 inputObjectConnectivityList,
432 nPixels, inputArray->GetNumberOfComponents()));
440 for(
size_t j = 0; j < nInputObjectCDArrays; j++) {
441 auto inputArray = inputObjectCD->GetArray(j);
444 outputArray->SetName(inputArray->GetName());
445 outputArray->SetNumberOfComponents(inputArray->GetNumberOfComponents());
446 outputArray->SetNumberOfTuples(nPixels);
448 outputImagePD->AddArray(outputArray);
450 switch(outputArray->GetDataType()) {
456 nPixels, inputArray->GetNumberOfComponents()));
int interpolateArray(DT *outputArray, const unsigned int *primitiveIds, const float *barycentricCoordinates, const IT *connectivityList, const DT *inputArray, const size_t &nTuples, const size_t &nComponents=1, const DT &missingValue=std::numeric_limits< DT >::has_quiet_NaN ? std::numeric_limits< DT >::quiet_NaN() :std::numeric_limits< DT >::max()) const