TTK
Loading...
Searching...
No Matches
ttkCinemaImagingEmbree.cpp
Go to the documentation of this file.
2
3#include <ttkCinemaImaging.h>
4#include <ttkUtils.h>
5
6#include <vtkCellArray.h>
7#include <vtkCellData.h>
8#include <vtkImageData.h>
9#include <vtkMultiBlockDataSet.h>
10#include <vtkPointData.h>
11#include <vtkPointSet.h>
12
13#include <vtkFloatArray.h>
14#include <vtkUnsignedIntArray.h>
15
20
22 vtkMultiBlockDataSet *outputImages,
23
24 vtkPointSet *inputObject,
25 vtkPointSet *inputGrid) const {
26 int status = 0;
27
28#ifdef TTK_ENABLE_EMBREE
29
30 auto inputObjectCells = ttkCinemaImaging::GetCells(inputObject);
31
32 RTCDevice device;
33 status = this->initializeDevice(device);
34 if(!status)
35 return 0;
36
37 auto inputObjectConnectivityList = static_cast<vtkIdType *>(
38 ttkUtils::GetVoidPointer(inputObjectCells->GetConnectivityArray()));
39
40 RTCScene scene;
41 status = this->initializeScene<vtkIdType>(
42 scene,
43
44 device, inputObject->GetNumberOfPoints(),
45 static_cast<float *>(ttkUtils::GetVoidPointer(inputObject->GetPoints())),
46 inputObjectCells->GetNumberOfCells(), inputObjectConnectivityList);
47 if(!status)
48 return 0;
49
50 // ---------------------------------------------------------------------------
51 // Prepare Field Data for Depth Values
52 // ---------------------------------------------------------------------------
53
54 // iterate over sampling locations
56 float *samplingPositions
57 = static_cast<float *>(ttkUtils::GetVoidPointer(inputGrid->GetPoints()));
58 int const nSamplingPositions = inputGrid->GetNumberOfPoints();
59 auto camParameters = inputGrid->GetPointData();
60 auto camUp = static_cast<double *>(
61 ttkUtils::GetVoidPointer(camParameters->GetArray("CamUp")));
62 auto camDir = static_cast<double *>(
63 ttkUtils::GetVoidPointer(camParameters->GetArray("CamDirection")));
64 auto camHeight = static_cast<double *>(
65 ttkUtils::GetVoidPointer(camParameters->GetArray("CamHeight")));
66 auto camNearFar = static_cast<double *>(
67 ttkUtils::GetVoidPointer(camParameters->GetArray("CamNearFar")));
68 auto camAngle = static_cast<double *>(
69 ttkUtils::GetVoidPointer(camParameters->GetArray("CamAngle")));
70 auto resolution = static_cast<double *>(
71 ttkUtils::GetVoidPointer(camParameters->GetArray("Resolution")));
72 auto projectionMode = static_cast<double *>(
73 ttkUtils::GetVoidPointer(camParameters->GetArray("ProjectionMode")));
74
75 for(int i = 0; i < nSamplingPositions; i++) {
76
77 double camPos[3]{samplingPositions[i * 3], samplingPositions[i * 3 + 1],
78 samplingPositions[i * 3 + 2]};
79
80 // Initialize Output
81 auto outputImage = vtkSmartPointer<vtkImageData>::New();
82 outputImage->SetDimensions(resolution[0], resolution[1], 1);
83 outputImage->SetSpacing(1, 1, 1);
84 outputImage->SetOrigin(0, 0, 0);
85 outputImage->AllocateScalars(VTK_FLOAT, 1);
86
87 size_t const nPixels = resolution[i * 2] * resolution[i * 2 + 1];
88 auto outputImagePD = outputImage->GetPointData();
89
90 auto depthBuffer = outputImagePD->GetArray(0);
91 depthBuffer->SetName("Depth");
92
93 auto primitiveIdArray = vtkSmartPointer<vtkUnsignedIntArray>::New();
94 primitiveIdArray->SetName("PrimitiveId");
95 primitiveIdArray->SetNumberOfComponents(1);
96 primitiveIdArray->SetNumberOfTuples(nPixels);
97 auto primitiveIdArrayData
98 = static_cast<unsigned int *>(ttkUtils::GetVoidPointer(primitiveIdArray));
99 outputImagePD->AddArray(primitiveIdArray);
100
101 auto barycentricCoordinates = vtkSmartPointer<vtkFloatArray>::New();
102 barycentricCoordinates->SetName("BarycentricCoordinates");
103 barycentricCoordinates->SetNumberOfComponents(2);
104 barycentricCoordinates->SetNumberOfTuples(nPixels);
105 auto barycentricCoordinatesData
106 = static_cast<float *>(ttkUtils::GetVoidPointer(barycentricCoordinates));
107 outputImagePD->AddArray(barycentricCoordinates);
108
109 // Render Object
110 status = this->renderImage(
111 static_cast<float *>(ttkUtils::GetVoidPointer(depthBuffer)),
112 primitiveIdArrayData, barycentricCoordinatesData,
113
114 scene, &resolution[i * 2], camPos, &camDir[i * 3], &camUp[i * 3],
115 projectionMode[i] == 0 ? camHeight[i] : camAngle[i],
116 projectionMode[i] == 0);
117 if(!status)
118 return 0;
119
120 ttkCinemaImaging::Normalize(depthBuffer, &camNearFar[i * 2]);
121
123 outputImage,
124
125 inputObject, this, primitiveIdArrayData, barycentricCoordinatesData,
126 inputObjectConnectivityList);
127 if(!status)
128 return 0;
129
130 ttkCinemaImaging::AddAllFieldDataArrays(inputGrid, outputImage, i);
131
132 outputImages->SetBlock(i, outputImage);
133 }
135
136 this->deallocateScene(device, scene);
137
138#else
139 TTK_FORCE_USE(outputImages);
140 TTK_FORCE_USE(inputObject);
141 TTK_FORCE_USE(inputGrid);
142
143 this->printErr("TTK was build without EMBREE backend.");
144#endif // TTK_ENABLE_EMBREE
145
146 return status;
147};
#define TTK_FORCE_USE(x)
Force the compiler to use the function/method parameter.
Definition BaseClass.h:57
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
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
int RenderVTKObject(vtkMultiBlockDataSet *outputImages, vtkPointSet *inputObject, vtkPointSet *inputGrid) const
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)