TTK
Loading...
Searching...
No Matches
ttkCinemaImagingNative.cpp
Go to the documentation of this file.
2
3#include <vtkImageData.h>
4#include <vtkMultiBlockDataSet.h>
5#include <vtkPointSet.h>
6
7#include <vtkCellArray.h>
8#include <vtkCellData.h>
9#include <vtkFloatArray.h>
10#include <vtkPointData.h>
11#include <vtkUnsignedIntArray.h>
12
13#include <ttkCinemaImaging.h>
14#include <ttkUtils.h>
15
17
21
23
25 vtkMultiBlockDataSet *outputImages,
26
27 vtkPointSet *inputObject,
28 vtkPointSet *inputGrid) const {
29 int status = 0;
30
31 auto inputObjectCells = ttkCinemaImaging::GetCells(inputObject);
32
33 // ---------------------------------------------------------------------------
34 // Prepare Field Data for Depth Values
35 // ---------------------------------------------------------------------------
36
37 // iterate over sampling locations
39 float *samplingPositions
40 = static_cast<float *>(ttkUtils::GetVoidPointer(inputGrid->GetPoints()));
41 int const nSamplingPositions = inputGrid->GetNumberOfPoints();
42 auto camParameters = inputGrid->GetPointData();
43 auto camUp = static_cast<double *>(
44 ttkUtils::GetVoidPointer(camParameters->GetArray("CamUp")));
45 auto camNearFar = static_cast<double *>(
46 ttkUtils::GetVoidPointer(camParameters->GetArray("CamNearFar")));
47 auto camDir = static_cast<double *>(
48 ttkUtils::GetVoidPointer(camParameters->GetArray("CamDirection")));
49 auto camHeight = static_cast<double *>(
50 ttkUtils::GetVoidPointer(camParameters->GetArray("CamHeight")));
51 auto camAngle = static_cast<double *>(
52 ttkUtils::GetVoidPointer(camParameters->GetArray("CamAngle")));
53 auto resolution = static_cast<double *>(
54 ttkUtils::GetVoidPointer(camParameters->GetArray("Resolution")));
55 auto projectionMode = static_cast<double *>(
56 ttkUtils::GetVoidPointer(camParameters->GetArray("ProjectionMode")));
57
58 auto inputObjectConnectivityList = static_cast<vtkIdType *>(
59 ttkUtils::GetVoidPointer(inputObjectCells->GetConnectivityArray()));
60
61 ttk::Timer test;
63 static_cast<float *>(ttkUtils::GetVoidPointer(inputObject->GetPoints())),
64 inputObjectConnectivityList, inputObjectCells->GetNumberOfCells());
65
66 this->printMsg("BVH", 1, test.getElapsedTime(), 1);
67
68 for(int i = 0; i < nSamplingPositions; i++) {
69
70 double camPos[3]{samplingPositions[i * 3], samplingPositions[i * 3 + 1],
71 samplingPositions[i * 3 + 2]};
72
73 // Initialize Output
74 auto outputImage = vtkSmartPointer<vtkImageData>::New();
75 outputImage->SetDimensions(resolution[0], resolution[1], 1);
76 outputImage->SetSpacing(1, 1, 1);
77 outputImage->SetOrigin(0, 0, 0);
78 outputImage->AllocateScalars(VTK_FLOAT, 1);
79
80 size_t const nPixels = resolution[i * 2] * resolution[i * 2 + 1];
81 auto outputImagePD = outputImage->GetPointData();
82
83 auto depthBuffer = outputImagePD->GetArray(0);
84 depthBuffer->SetName("Depth");
85
86 auto primitiveIdArray = vtkSmartPointer<vtkUnsignedIntArray>::New();
87 primitiveIdArray->SetName("PrimitiveId");
88 primitiveIdArray->SetNumberOfComponents(1);
89 primitiveIdArray->SetNumberOfTuples(nPixels);
90 auto primitiveIdArrayData
91 = static_cast<unsigned int *>(ttkUtils::GetVoidPointer(primitiveIdArray));
92 outputImagePD->AddArray(primitiveIdArray);
93
94 auto barycentricCoordinates = vtkSmartPointer<vtkFloatArray>::New();
95 barycentricCoordinates->SetName("BarycentricCoordinates");
96 barycentricCoordinates->SetNumberOfComponents(2);
97 barycentricCoordinates->SetNumberOfTuples(nPixels);
98 auto barycentricCoordinatesData
99 = static_cast<float *>(ttkUtils::GetVoidPointer(barycentricCoordinates));
100 outputImagePD->AddArray(barycentricCoordinates);
101
102 // Render Object
103 status = this->renderImage(
104 static_cast<float *>(ttkUtils::GetVoidPointer(depthBuffer)),
105 static_cast<unsigned int *>(ttkUtils::GetVoidPointer(primitiveIdArray)),
106 static_cast<float *>(ttkUtils::GetVoidPointer(barycentricCoordinates)),
107 inputObject->GetNumberOfPoints(),
108 static_cast<float *>(ttkUtils::GetVoidPointer(inputObject->GetPoints())),
109 inputObjectCells->GetNumberOfCells(), inputObjectConnectivityList, bvh,
110 &resolution[i * 2], camPos, &camDir[i * 3], &camUp[i * 3], camHeight[i],
111 projectionMode[i] == 0, camAngle[i]);
112 if(!status)
113 return 0;
114
115 ttkCinemaImaging::Normalize(depthBuffer, &camNearFar[i * 2]);
116
118 outputImage,
119
120 inputObject, this, primitiveIdArrayData, barycentricCoordinatesData,
121 inputObjectConnectivityList);
122 if(!status)
123 return 0;
124
125 ttkCinemaImaging::AddAllFieldDataArrays(inputGrid, outputImage, i);
126
127 outputImages->SetBlock(i, outputImage);
128 }
130
131 return status;
132};
static int AddAllFieldDataArrays(vtkPointSet *inputGrid, vtkImageData *image, int tupleIdx)
static int MapPointAndCellData(vtkImageData *outputImage, vtkPointSet *inputObject, const ttk::CinemaImaging *renderer, const unsigned int *primitiveIdArray, const float *barycentricCoordinates, const vtkIdType *inputObjectConnectivityList)
static vtkCellArray * GetCells(vtkPointSet *pointSet)
static int Normalize(vtkDataArray *depthArray, const double nearFar[2])
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
Definition ttkUtils.cpp:226
Acceleration structure for native ray tracer. Based on implementation described in Physically Based R...
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
double getElapsedTime()
Definition Timer.h:15
int RenderVTKObject(vtkMultiBlockDataSet *outputImages, vtkPointSet *inputObject, vtkPointSet *inputGrid) const
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)