Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef CLOUD_H
00017 #define CLOUD_H
00018
00019 #include <string>
00020 #include <vector>
00021 #include <iostream>
00022 #include <fstream>
00023
00024 #include "observation.h"
00025 #include "options.h"
00026 #include "math_types.h"
00027 #include "calibration.h"
00028 #include "project2d.h"
00029 #include "opencv_helper.h"
00030 #include "knn_cloud.h"
00031
00040 template <class observation_type>
00041 class cloud : public observation<observation_type>
00042 {
00043 public:
00063 cloud (const options &opts, const calibration &_calib)
00064 : frame (opts.data_start_idx ()),
00065 scale (opts.data_scaling ()),
00066 calib (_calib)
00067 {
00068 try
00069 {
00070 depth_threshold = opts.depth_threshold ();
00071 use_depth_threshold = true;
00072 }
00073 catch (missing_option)
00074 {
00075 use_depth_threshold = false;
00076 }
00077 };
00078
00079 ~cloud () {};
00080
00095 virtual bool refresh (bool goto_next = true) = 0;
00096
00101 virtual size_t size () const = 0;
00102
00107 virtual void show () const = 0;
00108
00109 protected:
00110 int frame;
00111 const double scale;
00112 bool use_depth_threshold;
00113 double depth_threshold;
00114 const calibration &calib;
00115 };
00116
00121 typedef std::vector<vector3> point_vector;
00122
00127 class cloud3 : public cloud<point_vector>
00128 {
00129 public:
00135 cloud3 (const options &opts, const calibration &_calib)
00136 : cloud<point_vector> (opts, _calib),
00137 downsample (opts.measure_downsampling ()),
00138 first_frame (frame)
00139 {
00140 background = cvCreateImage (cvSize (PROJ2D_SCALE * 1024.0, PROJ2D_SCALE * 768.0), IPL_DEPTH_8U, 1);
00141 try
00142 {
00143 depth_background = opts.depth_background ();
00144 use_background_subtraction = true;
00145 }
00146 catch (missing_option)
00147 {
00148 use_background_subtraction = false;
00149 }
00150 }
00151
00156 void init ()
00157 {
00158 if (use_background_subtraction)
00159 use_background_subtraction = read_background (depth_background);
00160 }
00161
00169 virtual bool read_background (const std::string &depth_background)
00170 {
00171 std::cerr << "warning: 'read:background' not implemented in 'cloud3'" << std::endl;
00172 return false;
00173 }
00174
00190 void render_background_image (IplImage *retval, double scale = 1.0) const
00191 {
00192 cvZero (retval);
00193 const size_t num_points = points.size ();
00194 for (size_t k = 0; k < num_points; k++)
00195 {
00196 const CvPoint pixel = calib.world_to_pixel (points [k], scale);
00197 GRAY (retval, pixel.x, pixel.y) = 255;
00198 }
00199 cvMorphologyEx (retval, retval, NULL, NULL, CV_MOP_CLOSE);
00200 }
00201
00205 void show () const
00206 {
00207 glPointSize (4.5f);
00208
00209
00210 glDisable (GL_LIGHTING);
00211 glBegin (GL_POINTS);
00212 for (size_t k = 0; k < points.size (); k++)
00213 {
00214 const vector3 rgb = colours [k];
00215 const vector3 p = points [k];
00216 glColor3f (rgb (0), rgb (1), rgb (2));
00217 glVertex3f (p [0], p [1], p [2]);
00218 }
00219 glEnd ();
00220 glEnable (GL_LIGHTING);
00221 }
00222
00237 vector3 operator[] (const size_t i) const
00238 {
00239 return points [i];
00240 };
00241
00246 size_t size () const
00247 {
00248 return points.size ();
00249 }
00250
00260 const project2d& get_project2d () const
00261 {
00262 return proj2d;
00263 }
00264
00271 const knn_cloud& get_knn_cloud () const
00272 {
00273 return nearest_cloud;
00274 }
00275
00282 const knn_cloud& get_knn_bg_cloud () const
00283 {
00284 return bg_nearest_cloud;
00285 }
00286
00287 protected:
00288 point_vector points, colours;
00289 const int downsample;
00290 const int first_frame;
00291 bool use_background_subtraction;
00292 std::string depth_background;
00293 project2d proj2d;
00294 knn_cloud nearest_cloud, bg_nearest_cloud;
00295 IplImage *background;
00296 };
00297 #endif // CLOUD_H