OCLSLAM  0.1.0
 Hosted by GitHub
ocl_processing.hpp
Go to the documentation of this file.
1 
29 #ifndef OCL_PROCESSING_HPP
30 #define OCL_PROCESSING_HPP
31 
32 #include <functional>
33 #include <mutex>
34 #include <GL/glew.h> // Add before CLUtils.hpp
35 #include <CLUtils.hpp>
36 #include <GuidedFilter/algorithms.hpp>
37 #include <ICP/algorithms.hpp>
38 #include <eigen3/Eigen/Dense>
39 #include <freenect_rgbd.hpp>
40 #include <octomap/octomap.h>
41 #include <octomap/OcTree.h>
42 // #include <octomap/ColorOcTree.h>
43 #include <oclslam/pointcloud.hpp>
44 #include <oclslam/algorithms.hpp>
45 
46 using namespace cl_algo;
47 
48 
50 class CLEnvGL : public clutils::CLEnv
51 {
52 public:
54  CLEnvGL (int width, int height, int numPC);
55 
56 private:
58  void initGLMemObjects ();
59 
60  int width, height, numPC;
61 
62 };
63 
64 
75 template <ICP::ICPStepConfigT CR, ICP::ICPStepConfigW CW>
76 class OCLSLAM
77 {
78 public:
80  OCLSLAM (Kinect *kinect, octomap::OcTree &map);
82  ~OCLSLAM ();
84  void init ();
86  void registerPointCloud ();
88  void write (std::string filename = std::string ("map.ot"));
90  void writeBinary (std::string filename = std::string ("map.bt"));
93  void display ();
95  bool getSLAMStatus () { return slamStatus; }
97  void setSLAMStatus (bool flag);
99  void toggleSLAMStatus ();
101  bool getGFRGBStatus () { return gfRGBStatus; }
103  void setGFRGBStatus (bool flag) { gfRGBStatus = flag; }
105  void toggleGFRGBStatus () { gfRGBStatus = !gfRGBStatus; }
107  bool getGFDStatus () { return gfDRadius; }
109  void setGFDStatus (bool flag) { gfDStatus = flag; }
111  void toggleGFDStatus () { gfDStatus = !gfDStatus; }
113  int getRGBNormalization () { return rgbNorm; }
115  void setRGBNormalization (int flag) { rgbNorm = flag; to8D.setRGBNorm (rgbNorm); }
117  void toggleRGBNormalization () { rgbNorm = !rgbNorm; to8D.setRGBNorm (rgbNorm); }
119  int getGFRGBRadius () { return gfRGB.getRadius (); }
121  void setGFRGBRadius (int radius) { gfRGBRadius = radius; gfRGB.setRadius (radius); }
123  float getGFRGBEps () { return gfRGB.getEps (); }
125  void setGFRGBEps (float eps) { gfRGBEps = eps; gfRGB.setEps (eps); }
127  int getGFDRadius () { return gfD.getRadius (); }
129  void setGFDRadius (int radius) { gfDRadius = radius; gfD.setRadius (radius); }
131  float getGFDEps () { return gfD.getEps (); }
133  void setGFDEps (float eps) { gfDEps = eps; gfD.setEps (eps); }
135  float getGFDScaling () { return gfD.getDScaling (); }
137  void setGFDScaling (float scaling) { gfDScaling = scaling; gfD.setDScaling (scaling); }
139  float getSensorFocalLength () { return to8D.getFocalLength (); }
141  void setSensorFocalLength (float f) { focalLength = f; to8D.setFocalLength (f); }
143  float getRBCAlpha () { return icp.getAlpha (); }
145  void setRBCAlpha (float _a) { a = _a; icp.setAlpha (_a); }
148  float getICPSScaling () { return icp.getScaling (); }
151  void setICPSScaling (float _c) { c = _c; icp.setScaling (_c); }
153  unsigned int getICPMaxIterations () { return icp.getMaxIterations (); }
155  void setICPMaxIterations (unsigned int maxIter) { max_iterations = maxIter; icp.setMaxIterations (maxIter); }
157  double getICPAngleThreshold () { return icp.getAngleThreshold (); }
159  void setICPAngleThreshold (double at) { angle_threshold = at; icp.setAngleThreshold (at); }
161  double getICPTranslationThreshold () { return icp.getTranslationThreshold (); }
163  void setICPTranslationThreshold (double tt) { translation_threshold = tt; icp.setTranslationThreshold (tt); }
164 
169  std::function<void ()> slam;
170 
171  volatile int timeStep;
173  // Global localization parameters
174  Eigen::Matrix3f R_g;
176  Eigen::Quaternionf q_g;
179  Eigen::Vector3f t_g;
181  cl_float s_g;
185 private:
186  void _mapping ();
187 
188  // Internal parameters
189  int gfRGBRadius;
190  float gfRGBEps;
191  int gfDRadius;
192  float gfDEps;
193  float gfDScaling;
194  float focalLength;
195  float a;
196  float c;
197  unsigned int max_iterations;
198  double angle_threshold;
199  double translation_threshold;
200 
201  // External parameters
202  volatile bool slamStatus;
203  volatile bool gfRGBStatus;
204  volatile bool gfDStatus;
205  volatile int rgbNorm;
206 
207  size_t slamFuncHashCode;
208  int maxPCGL; // Limits in the number of point clouds held in memory for visualization
209  unsigned int width, height;
210  unsigned int n; // Number of points in a point cloud
211  unsigned int m; // Number of landmarks
212  unsigned int r; // Number of representatives
213 
214  CLEnvGL env;
215  clutils::CLEnvInfo<2> infoGF;
216  clutils::CLEnvInfo<1> infoRBC, infoICP, infoSLAM;
217  cl::Context &context;
218  cl::CommandQueue &queue0, &queue1;
219 
220  Kinect *kinect;
221 
222  cl_float *hPtrTg;
223  cl::Buffer hBufferTg;
224  cl::Buffer hBufferRGB, hBufferD;
225  cl::Buffer dBufferRGB, dBufferD;
226  std::vector<cl::BufferGL> dBufferGL;
227 
228  GF::Kinect::GuidedFilterRGB<GF::Kinect::GuidedFilterRGBConfig::SEPARATED> gfRGB;
229  GF::Kinect::GuidedFilterDepth gfD;
230  GF::SeparateRGB<GF::SeparateRGBConfig::UCHAR_FLOAT> sepRGB;
231  GF::Depth<GF::DepthConfig::USHORT_FLOAT> convD;
232  GF::RGBDTo8D to8D;
233  ICP::ICPLMs lm;
234  ICP::ICP<CR, CW> icp;
235  ICP::ICPTransform<ICP::ICPTransformConfig::QUATERNION> transform;
236  GF::SplitPC8D sp8D;
237  oclslam::SplitPC8D sp8DMap;
238 
239  cl::Event eventGL;
240  std::vector<cl::Event> waitListGL;
241  clutils::CPUTimer<double, std::milli> timer;
242  clutils::CPUTimer<double, std::milli> timerICP;
243  volatile double lICP;
244 
245  // Map parameters
246  octomap::point3d global_pos; // Global position in meters
247  oclslam::PointCloud pc;
248  // std::vector<octomap::ColorOcTreeNode::Color> cc;
249  octomap::OcTree &map;
250  // octomap::ColorOcTree &map;
251 };
252 
253 #endif // OCL_PROCESSING_HPP
float getGFRGBEps()
Gets the variability threshold for the guided filter performed on the RGB frame. ...
Definition: ocl_processing.hpp:123
float getGFDEps()
Gets the variability threshold for the guided filter performed on the Depth frame.
Definition: ocl_processing.hpp:131
void setRGBNormalization(int flag)
Sets the status of the RGB normalization.
Definition: ocl_processing.hpp:115
void setGFDEps(float eps)
Sets the variability threshold for the guided filter performed on the Depth frame.
Definition: ocl_processing.hpp:133
Eigen::Vector3f t_g
Definition: ocl_processing.hpp:179
void setICPSScaling(float _c)
Sets the scaling applying to the deviations when computing matrix S in the ICP algorithm, for managing floating point arithmetic issues.
Definition: ocl_processing.hpp:151
const int width
Definition: glut_viewer.cpp:53
bool getSLAMStatus()
Gets the status of the automated SLAM process.
Definition: ocl_processing.hpp:95
void setGFDStatus(bool flag)
Sets the status of the Depth Guided Filter.
Definition: ocl_processing.hpp:109
int getRGBNormalization()
Gets the status of the RGB normalization.
Definition: ocl_processing.hpp:113
void setICPTranslationThreshold(double tt)
Sets the translation threshold (in mm) for the convergence check of the ICP.
Definition: ocl_processing.hpp:163
Declares classes that enhance the default octomap::Pointcloud.
void setICPAngleThreshold(double at)
Sets the angle threshold (in degrees) for the convergence check of the ICP.
Definition: ocl_processing.hpp:159
Declares classes that organize the execution of OpenCL kernels.
float getGFDScaling()
Gets the scaling applied to the depth frame for processing with the guided filter.
Definition: ocl_processing.hpp:135
void setGFRGBEps(float eps)
Sets the variability threshold for the guided filter performed on the RGB frame. ...
Definition: ocl_processing.hpp:125
void setSensorFocalLength(float f)
Sets the sensor's focal length.
Definition: ocl_processing.hpp:141
Offers classes which set up kernel execution parameters and provide interfaces for the handling of me...
Definition: algorithms.hpp:45
unsigned int getICPMaxIterations()
Gets the maximum number of iterations considered for an ICP registration.
Definition: ocl_processing.hpp:153
void setGFDScaling(float scaling)
Sets the scaling applied to the depth frame for processing with the guided filter.
Definition: ocl_processing.hpp:137
int getGFDRadius()
Gets the window radius for the guided filter performed on the Depth frame.
Definition: ocl_processing.hpp:127
int getGFRGBRadius()
Gets the window radius for the guided filter performed on the RGB frame.
Definition: ocl_processing.hpp:119
void toggleGFDStatus()
Toggles the status of the Depth Guided Filter.
Definition: ocl_processing.hpp:111
double getICPAngleThreshold()
Gets the angle threshold (in degrees) for the convergence check of the ICP.
Definition: ocl_processing.hpp:157
void setGFRGBStatus(bool flag)
Sets the status of the RGB Guided Filter.
Definition: ocl_processing.hpp:103
void setRBCAlpha(float _a)
Sets the parameter used in the distance function for the RBC data structure.
Definition: ocl_processing.hpp:145
volatile int timeStep
Definition: ocl_processing.hpp:171
float getICPSScaling()
Gets the scaling applying to the deviations when computing matrix S in the ICP algorithm, for managing floating point arithmetic issues.
Definition: ocl_processing.hpp:148
const int height
Definition: glut_viewer.cpp:54
Eigen::Matrix3f R_g
Definition: ocl_processing.hpp:174
Eigen::Quaternionf q_g
Definition: ocl_processing.hpp:176
void toggleRGBNormalization()
Toggles the status of the RGB normalization.
Definition: ocl_processing.hpp:117
A class that extends Freenect::FreenectDevice by defining the VideoCallback and DepthCallback functio...
Definition: freenect_rgbd.hpp:46
Creates an OpenCL environment with CL-GL interoperability.
Definition: ocl_processing.hpp:50
float getRBCAlpha()
Gets the parameter used in the distance function for the RBC data structure.
Definition: ocl_processing.hpp:143
Interface class for the SLAM pipeline.
Definition: ocl_processing.hpp:76
void setGFDRadius(int radius)
Sets the window radius for the guided filter performed on the Depth frame.
Definition: ocl_processing.hpp:129
octomap::OcTree map(res)
Kinect * kinect
Definition: slam.cpp:46
float getSensorFocalLength()
Gets the sensor's focal length.
Definition: ocl_processing.hpp:139
Declares classes necessary for setting up the freenect library.
std::function< void()> slam
Performs the SLAM process.
Definition: ocl_processing.hpp:169
void toggleGFRGBStatus()
Toggles the status of the RGB Guided Filter.
Definition: ocl_processing.hpp:105
void setICPMaxIterations(unsigned int maxIter)
Sets the maximum number of iterations considered for an ICP registration.
Definition: ocl_processing.hpp:155
bool getGFDStatus()
Gets the status of the Depth Guided Filter.
Definition: ocl_processing.hpp:107
void setGFRGBRadius(int radius)
Sets the window radius for the guided filter performed on the RGB frame.
Definition: ocl_processing.hpp:121
double getICPTranslationThreshold()
Gets the translation threshold (in mm) for the convergence check of the ICP.
Definition: ocl_processing.hpp:161
bool getGFRGBStatus()
Gets the status of the RGB Guided Filter.
Definition: ocl_processing.hpp:101
cl_float s_g
Definition: ocl_processing.hpp:181