Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef MOVEIT_MESH_FILTER_MESH_FILTER_BASE_
00038 #define MOVEIT_MESH_FILTER_MESH_FILTER_BASE_
00039
00040 #include <map>
00041 #include <moveit/mesh_filter/gl_renderer.h>
00042 #include <moveit/mesh_filter/sensor_model.h>
00043 #include <boost/function.hpp>
00044 #include <boost/thread/mutex.hpp>
00045 #include <Eigen/Eigen>
00046 #include <queue>
00047
00048
00049 namespace shapes
00050 {
00051 class Mesh;
00052 }
00053
00054 namespace mesh_filter
00055 {
00056
00057 class Job;
00058 class GLMesh;
00059
00060 typedef unsigned int MeshHandle;
00061 typedef uint32_t LabelType;
00062
00063 class MeshFilterBase
00064 {
00065
00066 public:
00067 typedef boost::function<bool (MeshHandle, Eigen::Affine3d&)> TransformCallback;
00068
00069
00070 enum {Background = 0, Shadow = 1, NearClip = 2, FarClip = 3, FirstLabel = 16};
00071 public:
00078 MeshFilterBase (const TransformCallback& transform_callback,
00079 const SensorModel::Parameters& sensor_parameters,
00080 const std::string& render_vertex_shader = "", const std::string& render_fragment_shader = "",
00081 const std::string& filter_vertex_shader = "", const std::string& filter_fragment_shader = "");
00082
00084 ~MeshFilterBase ();
00085
00092 MeshHandle addMesh (const shapes::Mesh& mesh);
00093
00099 void removeMesh (MeshHandle mesh_handle);
00100
00107 void filter (const void* sensor_data, GLushort type, bool wait = false) const;
00108
00116 void getFilteredLabels (LabelType* labels) const;
00117
00123 void getFilteredDepth (float* depth) const;
00124
00133 void getModelLabels (LabelType* labels) const;
00134
00140 void getModelDepth (float* depth) const;
00141
00149 void setShadowThreshold (float threshold);
00150
00156 void setTransformCallback (const TransformCallback& transform_callback);
00157
00162 void setPaddingScale (float scale);
00163
00168 void setPaddingOffset (float offset);
00169
00170 protected:
00171
00175 void initialize (const std::string& render_vertex_shader, const std::string& render_fragment_shader,
00176 const std::string& filter_vertex_shader, const std::string& filter_fragment_shader);
00177
00181 void deInitialize ();
00182
00186 void run (const std::string& render_vertex_shader, const std::string& render_fragment_shader,
00187 const std::string& filter_vertex_shader, const std::string& filter_fragment_shader);
00188
00194 void doFilter (const void* sensor_data, const int encoding) const;
00195
00201 void addMeshHelper (MeshHandle handle, const shapes::Mesh *cmesh);
00202
00207 bool removeMeshHelper (MeshHandle handle);
00208
00213 void addJob (const boost::shared_ptr<Job> &job) const;
00214
00221 void setSize (unsigned int width, unsigned int height);
00222
00224 std::map<MeshHandle, boost::shared_ptr<GLMesh> > meshes_;
00225
00227 boost::shared_ptr<SensorModel::Parameters> sensor_parameters_;
00228
00230 MeshHandle next_handle_;
00231
00233 MeshHandle min_handle_;
00234
00236 boost::thread filter_thread_;
00237
00239 mutable boost::condition_variable jobs_condition_;
00240
00242 mutable boost::mutex jobs_mutex_;
00243
00245 mutable std::queue<boost::shared_ptr<Job> > jobs_queue_;
00246
00248 mutable boost::mutex meshes_mutex_;
00249
00251 mutable boost::mutex transform_callback_mutex_;
00252
00254 bool stop_;
00255
00257 boost::shared_ptr<GLRenderer> mesh_renderer_;
00258
00260 boost::shared_ptr<GLRenderer> depth_filter_;
00261
00263 GLuint canvas_;
00264
00266 GLuint sensor_depth_texture_;
00267
00269 GLuint shadow_threshold_location_;
00270
00272 TransformCallback transform_callback_;
00273
00275 float padding_scale_;
00276
00278 float padding_offset_;
00279
00281 float shadow_threshold_;
00282
00283 };
00284 }
00285
00286 #endif