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});
161 {{
"#Objects", std::to_string(nInputObjects)},
162 {
"Backend", this->Backend == 0 ? std::string(
"VTK_OPENGL")
163 : this->Backend == 1 ? std::string(
"EMBREE")
164 : std::string(
"NATIVE")},
165 {
"Resolution", std::to_string(this->Resolution[0]) +
" x "
166 + std::to_string(this->Resolution[1])},
167 {
"Projection", this->ProjectionMode ?
"Perspective" :
"Orthographic"},
168 {
"CamNearFar", std::to_string(defaultNearFar[0]) +
" / "
169 + std::to_string(defaultNearFar[1])},
170 {
"CamFocalPoint", gridHasDirection || gridHasFocalPoint
172 :
"(" + std::to_string(defaultFocalPoint[0]) +
", "
173 + std::to_string(defaultFocalPoint[1]) +
", "
174 + std::to_string(defaultFocalPoint[2]) +
")"},
175 {std::string(this->ProjectionMode == 0 ?
"CamHeight" :
"CamAngle"),
176 std::to_string(this->ProjectionMode == 0 ? defaultHeight
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));
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()));