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
lvr2::CLRaycaster::m_queue
cl::CommandQueue m_queue
Definition: CLRaycaster.hpp:207
lvr2::CLRaycaster::m_resultBuffer
cl::Buffer m_resultBuffer
Definition: CLRaycaster.hpp:224
lvr2::CLRaycaster::m_mps
cl_uint m_mps
Definition: CLRaycaster.hpp:196
lvr2::CLRaycaster::m_platform
cl::Platform m_platform
Definition: CLRaycaster.hpp:203
lvr2::CLRaycaster::initOpenCL
void initOpenCL()
Initializes OpenCL related stuff.
lvr2::CLRaycaster::createKernel
void createKernel()
TODO.
lvr2::CLRaycaster::ClTriangleIntersectionResult::hit
cl_uchar hit
Definition: CLRaycaster.hpp:127
lvr2::CLRaycaster::m_program
cl::Program m_program
Definition: CLRaycaster.hpp:206
lvr2::CLRaycaster::castRay
bool castRay(const Vector3f &origin, const Vector3f &direction, IntT &intersection)
Overload functions ///.
lvr2::CLRaycaster::ClTriangleIntersectionResult::pBestTriId
cl_uint pBestTriId
Definition: CLRaycaster.hpp:128
lvr2::CLRaycaster::m_device
cl::Device m_device
Definition: CLRaycaster.hpp:204
lvr2::CLRaycaster::CLRaycaster
CLRaycaster(const MeshBufferPtr mesh, unsigned int stack_size=32)
Constructor: Generate BVH tree on mesh, loads CL kernels.
BVHRaycaster.hpp
lvr2::Vector3f
Eigen::Vector3f Vector3f
Eigen 3D vector, single precision.
Definition: MatrixTypes.hpp:118
lvr2::CLRaycaster::m_rayBuffer
cl::Buffer m_rayBuffer
Definition: CLRaycaster.hpp:220
lvr2::CLRaycaster
CLRaycaster: GPU OpenCL version of BVH Raycasting.
Definition: CLRaycaster.hpp:70
MatrixTypes.hpp
Intersection.hpp
lvr2::CLRaycaster::m_bvhLimitsnBuffer
cl::Buffer m_bvhLimitsnBuffer
Definition: CLRaycaster.hpp:215
lvr2::CLRaycaster::m_kernel_one_multi
cl::Kernel m_kernel_one_multi
Definition: CLRaycaster.hpp:209
lvr2::CLRaycaster::initOpenCLBuffer
void initOpenCLBuffer(size_t num_origins, size_t num_dirs)
TODO.
lvr2::CLRaycaster::castRays
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.
MeshBuffer.hpp
lvr2::CLRaycaster::m_max_work_group_size
size_t m_max_work_group_size
Definition: CLRaycaster.hpp:198
lvr2::CLRaycaster::m_bvhIndicesOrTriListsBuffer
cl::Buffer m_bvhIndicesOrTriListsBuffer
BUFFER ///.
Definition: CLRaycaster.hpp:214
lvr2::CLRaycaster::copyBVHToGPU
void copyBVHToGPU()
TODO.
lvr2::CLRaycaster::m_kernel_multi_multi
cl::Kernel m_kernel_multi_multi
Definition: CLRaycaster.hpp:210
lvr2::CLRaycaster::ClTriangleIntersectionResult::hitDist
cl_float hitDist
Definition: CLRaycaster.hpp:130
lvr2::CLRaycaster::m_bvhTriangleIntersectionDataBuffer
cl::Buffer m_bvhTriangleIntersectionDataBuffer
Definition: CLRaycaster.hpp:216
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::CLRaycaster::m_kernel_one_one
cl::Kernel m_kernel_one_one
Definition: CLRaycaster.hpp:208
lvr2::MeshBufferPtr
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
lvr2::CLRaycaster::ClTriangleIntersectionResult
Definition: CLRaycaster.hpp:126
lvr2::CLRaycaster::m_device_global_memory
cl_ulong m_device_global_memory
Definition: CLRaycaster.hpp:200
lvr2::CLRaycaster::m_warp_size
size_t m_warp_size
Definition: CLRaycaster.hpp:199
lvr2::CLRaycaster::ClTriangleIntersectionResult::pointHit
cl_float3 pointHit
Definition: CLRaycaster.hpp:129
lvr2::BVHRaycaster
BVHRaycaster: CPU version of BVH Raycasting: WIP.
Definition: BVHRaycaster.hpp:56
CLUtil.hpp
lvr2::CLRaycaster::initOpenCLTreeBuffer
void initOpenCLTreeBuffer()
TODO docu.
lvr2::CLRaycaster::m_context
cl::Context m_context
Definition: CLRaycaster.hpp:205
mesh
HalfEdgeMesh< Vec > mesh
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:26
lvr2::CLRaycaster::m_bvhTriIdxListBuffer
cl::Buffer m_bvhTriIdxListBuffer
Definition: CLRaycaster.hpp:217
lvr2::CLRaycaster::getDeviceInformation
void getDeviceInformation()
TODO.
lvr2::CLRaycaster::m_rayOriginBuffer
cl::Buffer m_rayOriginBuffer
Definition: CLRaycaster.hpp:221
lvr2::CLRaycaster::m_threads_per_block
cl_uint m_threads_per_block
Definition: CLRaycaster.hpp:197


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 Wed Mar 2 2022 00:37:23