examples/raycasting/Main.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
3 #include <tuple>
4 #include <stdlib.h>
5 
6 #include <boost/optional.hpp>
7 #include <chrono>
8 
9 // lvr2 includes
10 #include "lvr2/util/Synthetic.hpp"
11 #include "lvr2/io/MeshBuffer.hpp"
12 #include "lvr2/io/ModelFactory.hpp"
14 
17 
18 // LVR2 internal raycaster that is always available
20 #if defined LVR2_USE_OPENCL
22 #endif
23 #if defined LVR2_USE_EMBREE
25 #endif
26 
27 using std::unique_ptr;
28 using std::make_unique;
29 
30 using namespace lvr2;
31 
32 void singleRay()
33 {
34  // contruct a sphere mesh
36 
37  // construct a single ray
38  Vector3f ray_origin = {0.0,0.0,0.0};
39  Vector3f ray_dir = {1.0,0.0,0.0};
40 
41  // Choose intersection elements and combine them
42  // by Intersection Container
43  // predefined types are also available: PointInt, FaceInt, AllInt
44  using MyIntType = Intersection<
48  >;
49 
50  // construct raycaster
52  rc.reset(new BVHRaycaster<MyIntType>(mesh));
53 
54 
55  MyIntType intersection;
56  // use the raycaster
57  if(rc->castRay(ray_origin, ray_dir, intersection))
58  {
59  std::cout << "Hit the mesh!" << std::endl;
60  std::cout << intersection << std::endl;
61  }
62 }
63 
64 void multiRay1()
65 {
66  // contruct a sphere mesh
68 
69  size_t num_rays = 100000;
70 
71  // construct a rays single origin multiple directions
72  Vector3f ray_origin = {0.0,0.0,0.0};
73  std::vector<Vector3f> ray_dirs(num_rays, {1.0,0.0,0.0});
74 
75  // Choose intersection elements and combine them
76  // by Intersection Container
77  // predefined types are also available: PointInt, FaceInt, AllInt
78  using MyIntType = Intersection<
81  >;
82 
83  // construct raycaster
85  rc.reset(new BVHRaycaster<MyIntType>(mesh));
86 
87 
88  std::vector<MyIntType> intersections;
89  std::vector<uint8_t> hits;
90 
91  // use the raycaster
92  rc->castRays(ray_origin, ray_dirs, intersections, hits);
93 
94  if(hits.back())
95  {
96  std::cout << "Hit the mesh!" << std::endl;
97  std::cout << intersections.back() << std::endl;
98  }
99 }
100 
101 void multiRay2()
102 {
103  // contruct a sphere mesh
105 
106  size_t num_rays = 100000;
107 
108  // construct a rays single origin multiple directions
109  std::vector<Vector3f> ray_origins(num_rays, {0.0,0.0,0.0});
110  std::vector<Vector3f> ray_dirs(num_rays, {1.0,0.0,0.0});
111 
112  // Choose intersection elements and combine them
113  // by Intersection Container
114  // predefined types are also available: PointInt, FaceInt, AllInt
115  // using MyIntType = Intersection<
116  // intelem::Point,
117  // intelem::Distance,
118  // intelem::Face
119  // >;
120 
121  // construct raycaster
123  rc.reset(new BVHRaycaster<AllInt>(mesh));
124 
125 
126  std::vector<AllInt> intersections;
127  std::vector<uint8_t> hits;
128 
129  // use the raycaster
130  rc->castRays(ray_origins, ray_dirs, intersections, hits);
131 
132  if(hits.back())
133  {
134  std::cout << "Hit the mesh!" << std::endl;
135  std::cout << intersections.back() << std::endl;
136  }
137 }
138 
139 int main(int argc, char** argv)
140 {
141  std::cout << "1. Shoot a single ray onto a mesh" << std::endl;
142  singleRay();
143  std::cout << "2. Shoot rays contraining same origin" << std::endl;
144  multiRay1();
145  std::cout << "3. Shoot multi rays" << std::endl;
146  multiRay2();
147  return 0;
148 }
lvr2::intelem::Face
Intersection face as uint id.
Definition: Intersection.hpp:47
BaseVector.hpp
multiRay2
void multiRay2()
Definition: examples/raycasting/Main.cpp:101
EmbreeRaycaster.hpp
lvr2::RaycasterBasePtr
std::shared_ptr< RaycasterBase< IntT > > RaycasterBasePtr
Definition: RaycasterBase.hpp:147
Synthetic.hpp
lvr2::Intersection
CRTP Container for User defined intersection elements.
Definition: Intersection.hpp:103
multiRay1
void multiRay1()
Definition: examples/raycasting/Main.cpp:64
CLRaycaster.hpp
lvr2::intelem::Distance
Intersection distance(float)
Definition: Intersection.hpp:30
BVHRaycaster.hpp
lvr2::Vector3f
Eigen::Vector3f Vector3f
Eigen 3D vector, single precision.
Definition: MatrixTypes.hpp:118
Intersection.hpp
kfusion::device::Point
float4 Point
Definition: internal.hpp:14
singleRay
void singleRay()
Definition: examples/raycasting/Main.cpp:32
lvr2::synthetic::genSphere
MeshBufferPtr genSphere(int num_long=50, int num_lat=50)
Definition: Synthetic.hpp:12
MeshBuffer.hpp
argc
int argc
Definition: tests_high_five_parallel.cpp:27
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::MeshBufferPtr
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
ModelFactory.hpp
lvr2::BVHRaycaster
BVHRaycaster: CPU version of BVH Raycasting: WIP.
Definition: BVHRaycaster.hpp:56
lvr2::intelem::Normal
Raycaster should compute the normal of the intersected face flipped towards the ray.
Definition: Intersection.hpp:39
main
int main(int argc, char **argv)
Definition: examples/raycasting/Main.cpp:139
mesh
HalfEdgeMesh< Vec > mesh
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:26
argv
char ** argv
Definition: tests_high_five_parallel.cpp:28
RaycasterBase.hpp


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:24