mesh_types.h
Go to the documentation of this file.
00001 
00063 #ifndef COB_MESH_TYPES_H
00064 #define COB_MESH_TYPES_H
00065 
00066 #include "cob_3d_meshing/slots.hpp"
00067 #include "cob_3d_meshing/mesh_property_types.h"
00068 
00069 namespace cob_3d_meshing
00070 {
00071   /*** policy classes to access plugin functionalities ***
00072    *
00073    * "inline static void T::runPlugin(const PluginT&, ...)
00074    * is called by slots.run<T>() for all defined plugins.
00075    * it should just redirect to the desired function within the plugin.
00076    *
00077    */
00078   template<typename MeshTraits = DefaultMeshTraits>
00079   class SetVertex
00080   {
00081   public:
00082     typedef typename MeshTraits::VertexHandle VertexHandle;
00083 
00084     struct PluginArgs { VertexHandle vh; int idx; };
00085 
00086     template<typename PluginT>
00087     inline static void runPlugin(PluginT& plugin, const PluginArgs& args)
00088     {
00089       plugin.setVertex(args.vh, args.idx);
00090     }
00091   };
00092 
00093   template<typename MeshTraits = DefaultMeshTraits>
00094   class Init
00095   {
00096   public:
00097     typedef typename MeshTraits::MeshT MeshT;
00098 
00099     template<typename PluginT>
00100     inline static void runPlugin(PluginT& plugin, MeshT* mesh)
00101     {
00102       plugin.init(mesh);
00103     }
00104   };
00105 
00106 
00107   template<typename PT1 = NullT,
00108            typename PT2 = NullT,
00109            typename PT3 = NullT,
00110            typename PT4 = NullT,
00111            typename PT5 = NullT,
00112            typename MeshTraits = DefaultMeshTraits >
00113   class Mesh
00114   {
00115   public:
00116     typedef typename MeshTraits::MeshT MeshT;
00117     typedef typename MeshTraits::VertexHandle VertexHandle;
00118     typedef typename MeshTraits::FaceHandle FaceHandle;
00119 
00120     // tie all properties together in one handler:
00121     typedef Slots<PT1,PT2,PT3,PT4,PT5> Properties;
00122 
00123     template<typename U> friend class MeshDecimation;
00124 
00125     Mesh(const PT1& prop1 = PT1(),
00126          const PT2& prop2 = PT2(),
00127          const PT3& prop3 = PT3(),
00128          const PT4& prop4 = PT4(),
00129          const PT5& prop5 = PT5())
00130       : mesh_()
00131       , prop_(prop1,prop2,prop3,prop4,prop5)
00132     {
00133       // init all properites
00134       runPolicy<Init<MeshTraits> >(prop_, &mesh_);
00135     }
00136 
00137     template<typename PointT>
00138     VertexHandle addVertex(int idx, const PointT& p)
00139     {
00140       typename SetVertex<MeshTraits>::PluginArgs args;
00141       args.vh = mesh_.add_vertex(typename MeshT::Point(p.x,p.y,p.z));
00142       args.idx = idx;
00143       runPolicy<SetVertex<MeshTraits> >(prop_,args);
00144       return args.vh;
00145     }
00146 
00147     FaceHandle addFace(const VertexHandle& v1,
00148                        const VertexHandle& v2,
00149                        const VertexHandle& v3)
00150     {
00151       return mesh_.add_face(v1,v2,v3);
00152     }
00153 
00154     bool savePLY(const std::string& file)
00155     {
00156       return OpenMesh::IO::write_mesh(mesh_, file);
00157     }
00158 
00159   private:
00160     MeshT mesh_;
00161     Properties prop_;
00162 
00163   };
00164 
00165 }
00166 
00167 #endif


cob_3d_meshing
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:04:03