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/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 // forward declarations
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   // 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
00069   // can be anything below that)
00070   // this would allow me to do a single comparison instead of 3, in the code i write
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 }  // namespace mesh_filter
00297 
00298 #endif /* __MESH_FILTER_MESH_FILTER_BASE_H__ */


perception
Author(s): Ioan Sucan , Jon Binney , Suat Gedikli
autogenerated on Tue Dec 26 2017 03:33:51