TTK
Loading...
Searching...
No Matches
CinemaImagingEmbree.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <CinemaImaging.h>
13
14#ifdef TTK_ENABLE_EMBREE
15#include <embree3/rtcore.h>
16#include <limits>
17#include <string>
18#endif // TTK_ENABLE_EMBREE
19
20namespace ttk {
21
23 public:
26
27#ifdef TTK_ENABLE_EMBREE
28
29 int initializeDevice(RTCDevice &device) const;
30
31 template <typename IT>
32 int initializeScene(RTCScene &scene,
33
34 const RTCDevice &device,
35 const size_t &nVertices,
36 const float *vertexCoords,
37 const size_t &nTriangles,
38 const IT *connectivityList) const;
39
40 int renderImage(float *depthBuffer,
41 unsigned int *primitiveIds,
42 float *barycentricCoordinates,
43
44 const RTCScene &scene,
45 const double resolution[2],
46 const double camCenter[3],
47 const double camDir[3],
48 const double camUp[3],
49 const double &camFactor, // either height or angle
50 const bool &orthographicProjection = true) const;
51
52 int deallocateScene(RTCDevice &device, RTCScene &scene) const;
53
54#endif // TTK_ENABLE_EMBREE
55 };
56} // namespace ttk
57
58#ifdef TTK_ENABLE_EMBREE
59
60template <typename IT>
61int ttk::CinemaImagingEmbree::initializeScene(
62 RTCScene &scene,
63
64 const RTCDevice &device,
65 const size_t &nVertices,
66 const float *vertexCoords,
67 const size_t &nTriangles,
68 const IT *connectivityList) const {
69 ttk::Timer timer;
70 this->printMsg("Initializing Scene (#v:" + std::to_string(nVertices)
71 + "|#t:" + std::to_string(nTriangles) + ")",
73
74 scene = rtcNewScene(device);
75
76 RTCGeometry mesh = rtcNewGeometry(device, RTC_GEOMETRY_TYPE_TRIANGLE);
77
78 // vertices
79 {
80 rtcSetSharedGeometryBuffer(mesh, RTC_BUFFER_TYPE_VERTEX, 0,
81 RTC_FORMAT_FLOAT3, (const void *)vertexCoords, 0,
82 3 * sizeof(float), nVertices);
83 }
84
85 // triangles
86 {
87 // unfortunately embree does not support signed integer based indexing
88 // rtcSetSharedGeometryBuffer(
89 // mesh,
90 // RTC_BUFFER_TYPE_INDEX,
91 // 0,
92 // RTC_FORMAT_LLONG3,
93 // static_cast<const void*>(connectivityList),
94 // 0,
95 // 3*sizeof(long long),
96 // nTriangles
97 // );
98
99 unsigned int *indices = (unsigned int *)rtcSetNewGeometryBuffer(
100 mesh, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3,
101 3 * sizeof(unsigned int), nTriangles);
102
103 for(size_t t = 0, tn = nTriangles * 3; t < tn; t++)
104 indices[t] = (unsigned int)connectivityList[t];
105
106 rtcCommitGeometry(mesh);
107 rtcAttachGeometry(scene, mesh);
108 rtcReleaseGeometry(mesh);
109 }
110
111 rtcCommitScene(scene);
112
113 this->printMsg("Initializing Scene (#v:" + std::to_string(nVertices)
114 + "|#t:" + std::to_string(nTriangles) + ")",
115 1, timer.getElapsedTime());
116 return 1;
117};
118
119#endif // TTK_ENABLE_EMBREE
TTK CinemaImagingEmbree processing package.
~CinemaImagingEmbree() override
TTK modules that generates images of a dataset.
double getElapsedTime()
Definition Timer.h:15
The Topology ToolKit.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)