CLRaycaster.hpp
Go to the documentation of this file.
1 
28 /*
29  * CLRaycaster.hpp
30  *
31  * @date 25.01.2020
32  * @author Johan M. von Behren <johan@vonbehren.eu>
33  * @author Alexander Mock <amock@uos.de>
34  */
35 
36 #ifndef LVR2_ALGORITHM_RAYCASTING_CLRAYCASTER
37 #define LVR2_ALGORITHM_RAYCASTING_CLRAYCASTER
38 
39 #include <chrono>
40 #include "lvr2/io/MeshBuffer.hpp"
43 
44 #define CL_HPP_ENABLE_EXCEPTIONS
45 #define CL_HPP_MINIMUM_OPENCL_VERSION 120 // Need to set to 120 on CUDA 8
46 #define CL_HPP_TARGET_OPENCL_VERSION 120 // Need to set to 120 on CUDA 8
47 
48 // hard cl2 depencency
49 #include <CL/cl2.hpp>
50 
51 // if your code can handle cl.hpp and cl2.hpp use:
52 // #if defined LVR2_USE_OPENCL_NEW_API
53 // #include <CL/cl2.hpp>
54 // #else
55 // #include <CL/cl.hpp>
56 // #endif
57 
58 #include "lvr2/util/CLUtil.hpp"
59 #include "Intersection.hpp"
60 
61 
62 
63 namespace lvr2
64 {
65 
69 template<typename IntT>
70 class CLRaycaster : public BVHRaycaster<IntT> {
71 public:
72 
77  unsigned int stack_size = 32);
78 
80 
89  bool castRay(
90  const Vector3f& origin,
91  const Vector3f& direction,
92  IntT& intersection);
93 
95 
105  void castRays(
106  const Vector3f& origin,
107  const std::vector<Vector3f>& directions,
108  std::vector<IntT>& intersections,
109  std::vector<uint8_t>& hits) override;
110 
120  void castRays(
121  const std::vector<Vector3f>& origins,
122  const std::vector<Vector3f>& directions,
123  std::vector<IntT>& intersections,
124  std::vector<uint8_t>& hits) override;
125 
127  cl_uchar hit = 0;
128  cl_uint pBestTriId;
129  cl_float3 pointHit;
130  cl_float hitDist;
131  };
132 
133 protected:
138 
139 private:
143  void initOpenCL();
144 
148  void getDeviceInformation();
149 
153  void initOpenCLTreeBuffer();
154 
158  // void initOpenCLRayBuffer(
159  // int num_origins,
160  // int num_rays);
161 
162  void initOpenCLBuffer(
163  size_t num_origins,
164  size_t num_dirs
165  );
166 
170  void copyBVHToGPU();
171 
175  void createKernel();
176 
177  // /**
178  // * @brief TODO
179  // */
180  // void copyRayDataToGPU(
181  // const vector<float>& origins,
182  // const vector<float>& rays
183  // );
184 
185  // /**
186  // * @brief TODO
187  // */
188  // void copyRayDataToGPU(
189  // const float* origin_buffer, size_t origin_buffer_size,
190  // const float* ray_buffer, size_t ray_buffer_size
191  // );
192 
193  // Member vars
194 
195  // OpenCL Device information
196  cl_uint m_mps;
199  size_t m_warp_size;
201 
202  // OpenCL variables
203  cl::Platform m_platform;
204  cl::Device m_device;
205  cl::Context m_context;
206  cl::Program m_program;
207  cl::CommandQueue m_queue;
208  cl::Kernel m_kernel_one_one;
209  cl::Kernel m_kernel_one_multi;
211 
213  // buffer bvh tree
215  cl::Buffer m_bvhLimitsnBuffer;
218 
219  // buffer rays
220  cl::Buffer m_rayBuffer;
221  cl::Buffer m_rayOriginBuffer;
222 
223  // buffer results
224  cl::Buffer m_resultBuffer;
225  // cl::Buffer m_resultHitsBuffer;
226 
227 };
228 
229 } // namespace lvr2
230 
231 #include "CLRaycaster.tcc"
232 
233 #endif // LVR2_ALGORITHM_RAYCASTING_CLRAYCASTER
CLRaycaster(const MeshBufferPtr mesh, unsigned int stack_size=32)
Constructor: Generate BVH tree on mesh, loads CL kernels.
HalfEdgeMesh< Vec > mesh
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
cl::Program m_program
cl::CommandQueue m_queue
bool castRay(const Vector3f &origin, const Vector3f &direction, IntT &intersection)
Overload functions ///.
cl_ulong m_device_global_memory
void initOpenCLBuffer(size_t num_origins, size_t num_dirs)
TODO.
void copyBVHToGPU()
TODO.
cl::Buffer m_bvhTriIdxListBuffer
cl::Kernel m_kernel_multi_multi
BVHRaycaster: CPU version of BVH Raycasting: WIP.
cl::Kernel m_kernel_one_one
void castRays(const Vector3f &origin, const std::vector< Vector3f > &directions, std::vector< IntT > &intersections, std::vector< uint8_t > &hits) override
Cast a ray from single origin with multiple directions onto the mesh.
Eigen::Vector3f Vector3f
Eigen 3D vector, single precision.
cl::Buffer m_rayOriginBuffer
void initOpenCLTreeBuffer()
TODO docu.
cl::Context m_context
cl::Buffer m_resultBuffer
cl_uint m_mps
TODO.
CLRaycaster: GPU OpenCL version of BVH Raycasting.
Definition: CLRaycaster.hpp:70
size_t m_max_work_group_size
void createKernel()
TODO.
void initOpenCL()
Initializes OpenCL related stuff.
cl::Device m_device
cl_uint m_threads_per_block
cl::Buffer m_bvhTriangleIntersectionDataBuffer
cl::Platform m_platform
cl::Buffer m_rayBuffer
void getDeviceInformation()
TODO.
cl::Kernel m_kernel_one_multi
cl::Buffer m_bvhLimitsnBuffer
cl::Buffer m_bvhIndicesOrTriListsBuffer
BUFFER ///.


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06