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/macros/class_forward.h>
00042 #include <moveit/mesh_filter/gl_renderer.h>
00043 #include <moveit/mesh_filter/sensor_model.h>
00044 #include <boost/function.hpp>
00045 #include <boost/thread/mutex.hpp>
00046 #include <Eigen/Eigen>
00047 #include <queue>
00048
00049
00050 namespace shapes
00051 {
00052 class Mesh;
00053 }
00054
00055 namespace mesh_filter
00056 {
00057 MOVEIT_CLASS_FORWARD(Job);
00058 MOVEIT_CLASS_FORWARD(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
00071 enum
00072 {
00073 Background = 0,
00074 Shadow = 1,
00075 NearClip = 2,
00076 FarClip = 3,
00077 FirstLabel = 16
00078 };
00079
00080 public:
00088 MeshFilterBase(const TransformCallback& transform_callback, const SensorModel::Parameters& sensor_parameters,
00089 const std::string& render_vertex_shader = "", const std::string& render_fragment_shader = "",
00090 const std::string& filter_vertex_shader = "", const std::string& filter_fragment_shader = "");
00091
00093 ~MeshFilterBase();
00094
00102 MeshHandle addMesh(const shapes::Mesh& mesh);
00103
00109 void removeMesh(MeshHandle mesh_handle);
00110
00117 void filter(const void* sensor_data, GLushort type, bool wait = false) const;
00118
00127 void getFilteredLabels(LabelType* labels) const;
00128
00134 void getFilteredDepth(float* depth) const;
00135
00145 void getModelLabels(LabelType* labels) const;
00146
00152 void getModelDepth(float* depth) const;
00153
00161 void setShadowThreshold(float threshold);
00162
00168 void setTransformCallback(const TransformCallback& transform_callback);
00169
00175 void setPaddingScale(float scale);
00176
00181 void setPaddingOffset(float offset);
00182
00183 protected:
00187 void initialize(const std::string& render_vertex_shader, const std::string& render_fragment_shader,
00188 const std::string& filter_vertex_shader, const std::string& filter_fragment_shader);
00189
00193 void deInitialize();
00194
00198 void run(const std::string& render_vertex_shader, const std::string& render_fragment_shader,
00199 const std::string& filter_vertex_shader, const std::string& filter_fragment_shader);
00200
00206 void doFilter(const void* sensor_data, const int encoding) const;
00207
00213 void addMeshHelper(MeshHandle handle, const shapes::Mesh* cmesh);
00214
00219 bool removeMeshHelper(MeshHandle handle);
00220
00225 void addJob(const JobPtr& job) const;
00226
00233 void setSize(unsigned int width, unsigned int height);
00234
00236 std::map<MeshHandle, GLMeshPtr> meshes_;
00237
00239 SensorModel::ParametersPtr sensor_parameters_;
00240
00242 MeshHandle next_handle_;
00243
00246 MeshHandle min_handle_;
00247
00249 boost::thread filter_thread_;
00250
00252 mutable boost::condition_variable jobs_condition_;
00253
00255 mutable boost::mutex jobs_mutex_;
00256
00258 mutable std::queue<JobPtr> jobs_queue_;
00259
00261 mutable boost::mutex meshes_mutex_;
00262
00264 mutable boost::mutex transform_callback_mutex_;
00265
00267 bool stop_;
00268
00270 GLRendererPtr mesh_renderer_;
00271
00273 GLRendererPtr depth_filter_;
00274
00276 GLuint canvas_;
00277
00279 GLuint sensor_depth_texture_;
00280
00282 GLuint shadow_threshold_location_;
00283
00285 TransformCallback transform_callback_;
00286
00288 float padding_scale_;
00289
00291 float padding_offset_;
00292
00294 float shadow_threshold_;
00295 };
00296 }
00297
00298 #endif