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
00038
00039
00040
00041 #include <iostream>
00042
00043 #include <pcl/geometry/polygon_mesh.h>
00044
00046
00047
00048
00049
00050
00051
00052 class MyVertexData
00053 {
00054 public:
00055
00056 MyVertexData (const int id = -1) : id_ (id) {}
00057
00058 int id () const {return (id_);}
00059 int& id () {return (id_);}
00060
00061 private:
00062
00063 int id_;
00064 };
00065
00066 std::ostream&
00067 operator << (std::ostream& os, const MyVertexData& vd)
00068 {
00069 return (os << vd.id ());
00070 }
00071
00073
00074
00075 typedef pcl::geometry::PolygonMesh <pcl::geometry::DefaultMeshTraits <MyVertexData> > Mesh;
00076
00077 typedef Mesh::VertexIndex VertexIndex;
00078 typedef Mesh::HalfEdgeIndex HalfEdgeIndex;
00079 typedef Mesh::FaceIndex FaceIndex;
00080
00081 typedef Mesh::VertexIndices VertexIndices;
00082 typedef Mesh::HalfEdgeIndices HalfEdgeIndices;
00083 typedef Mesh::FaceIndices FaceIndices;
00084
00085 typedef Mesh::VertexAroundVertexCirculator VAVC;
00086 typedef Mesh::OutgoingHalfEdgeAroundVertexCirculator OHEAVC;
00087 typedef Mesh::IncomingHalfEdgeAroundVertexCirculator IHEAVC;
00088 typedef Mesh::FaceAroundVertexCirculator FAVC;
00089 typedef Mesh::VertexAroundFaceCirculator VAFC;
00090 typedef Mesh::InnerHalfEdgeAroundFaceCirculator IHEAFC;
00091 typedef Mesh::OuterHalfEdgeAroundFaceCirculator OHEAFC;
00092
00094
00095
00096 void
00097 printVertices (const Mesh& mesh)
00098 {
00099 std::cout << "Vertices:\n ";
00100 for (unsigned int i=0; i<mesh.sizeVertices (); ++i)
00101 {
00102 std::cout << mesh.getVertexDataCloud () [i] << " ";
00103 }
00104 std::cout << std::endl;
00105 }
00106
00107 void
00108 printEdge (const Mesh& mesh, const HalfEdgeIndex& idx_he)
00109 {
00110 std::cout << " "
00111 << mesh.getVertexDataCloud () [mesh.getOriginatingVertexIndex (idx_he).get ()]
00112 << " "
00113 << mesh.getVertexDataCloud () [mesh.getTerminatingVertexIndex (idx_he).get ()]
00114 << std::endl;
00115 }
00116
00117 void
00118 printFace (const Mesh& mesh, const FaceIndex& idx_face)
00119 {
00120
00121 VAFC circ = mesh.getVertexAroundFaceCirculator (idx_face);
00122 const VAFC circ_end = circ;
00123 std::cout << " ";
00124 do
00125 {
00126 std::cout << mesh.getVertexDataCloud () [circ.getTargetIndex ().get ()] << " ";
00127 } while (++circ != circ_end);
00128 std::cout << std::endl;
00129 }
00130
00131 void
00132 printFaces (const Mesh& mesh)
00133 {
00134 std::cout << "Faces:\n";
00135 for (unsigned int i=0; i<mesh.sizeFaces (); ++i)
00136 {
00137 printFace (mesh, FaceIndex (i));
00138 }
00139 }
00140
00142
00143 int main ()
00144 {
00145 Mesh mesh;
00146 VertexIndices vi;
00147
00148
00149
00150
00151
00152
00153
00154 for (unsigned int i=0; i<8; ++i)
00155 {
00156 vi.push_back (mesh.addVertex (MyVertexData (i)));
00157 }
00158
00159
00160 VertexIndices tmp;
00161 tmp.push_back (vi [0]);
00162 tmp.push_back (vi [1]);
00163 tmp.push_back (vi [2]);
00164 mesh.addFace (tmp);
00165 tmp.clear ();
00166
00167
00168 mesh.addFace (vi [0], vi [2], vi [3]);
00169 mesh.addFace (vi [0], vi [3], vi [4]);
00170 mesh.addFace (vi [0], vi [4], vi [5]);
00171
00172
00173 mesh.addFace (vi [0], vi [5], vi [6], vi [1]);
00174
00175 printVertices (mesh);
00176 printFaces (mesh);
00177
00179
00180 std::cout << "Outgoing half-edges of vertex 0:" << std::endl;
00181 OHEAVC circ_oheav = mesh.getOutgoingHalfEdgeAroundVertexCirculator (vi[0]);
00182 const OHEAVC circ_oheav_end = circ_oheav;
00183 do
00184 {
00185 printEdge (mesh,circ_oheav.getTargetIndex ());
00186 } while (++circ_oheav != circ_oheav_end);
00187
00189
00190 std::cout << "Circulate around the boundary half-edges:" << std::endl;
00191 const HalfEdgeIndex& idx_he_boundary = mesh.getOutgoingHalfEdgeIndex (vi [6]);
00192 IHEAFC circ_iheaf = mesh.getInnerHalfEdgeAroundFaceCirculator (idx_he_boundary);
00193 const IHEAFC circ_iheaf_end = circ_iheaf;
00194 do
00195 {
00196 printEdge (mesh, circ_iheaf.getTargetIndex ());
00197 } while (++circ_iheaf != circ_iheaf_end);
00198
00200
00201 std::cout << std::endl << "Deleting face 1 (0 2 3) and 3 (0 4 5) ...\n";
00202 std::cout << "(If the mesh is set to manifold further faces are removed automatically)\n\n";
00203 mesh.deleteFace (FaceIndex (1));
00204 mesh.deleteFace (FaceIndex (3));
00205
00206 mesh.cleanUp ();
00207 vi.clear ();
00208
00209 printVertices (mesh);
00210 printFaces (mesh);
00211
00213
00214 std::cout << "Circulate around all faces of vertex 0:\n";
00215
00216 FAVC circ_fav = mesh.getFaceAroundVertexCirculator (vi [0]);
00217 const FAVC circ_fav_end = circ_fav;
00218 do
00219 {
00220
00221
00222 if (!mesh.isBoundary (circ_fav.getCurrentHalfEdgeIndex ()))
00223 {
00224 printFace (mesh, circ_fav.getTargetIndex ());
00225 }
00226 else
00227 {
00228 std::cout << " invalid face -> boundary half-edge\n";
00229 }
00230 } while (++circ_fav!=circ_fav_end);
00231
00232 return (0);
00233 }