mesh_filter_base.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2013, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 /* Author: Suat Gedikli */
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 //forward declarations
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     // inner types and typedefs
00066   public:
00067     typedef boost::function<bool (MeshHandle, Eigen::Affine3d&)> TransformCallback;
00068   // \todo @suat: to avoid a few comparisons, it would be much nicer if background = 14 and shadow = 15 (near/far clip can be anything below that)
00069   // this would allow me to do a single comparison instead of 3, in the code i write
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 } // namespace mesh_filter
00285 
00286 #endif    /* __MESH_FILTER_MESH_FILTER_BASE_H__ */


perception
Author(s): Ioan Sucan , Jon Binney , Suat Gedikli
autogenerated on Wed Aug 26 2015 12:43:21