Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MeshFixingT.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
49 
50 #ifndef OPENMESH_MESHFIXING_HH
51 #define OPENMESH_MESHFIXING_HH
52 
53 //=============================================================================
54 //
55 // CLASS MeshFixing
56 //
57 //=============================================================================
58 
59 //== INCLUDES =================================================================
60 
61 //== NAMESPACE ================================================================
62 
63 //== CLASS DEFINITION =========================================================
64 
71 {
72 public:
73 
75  CompareVectors(double _eps = FLT_MIN);
76 
78  bool operator()( const ACG::Vec3d& _v0, const ACG::Vec3d& _v1 ) const;
79 
80 private:
81  const double epsilon_;
82 };
83 
84 
88 template<class MeshT>
89 class MeshFixing {
90 
91 public:
92 
93  MeshFixing(MeshT& _mesh, double _epsilon );
94 
95  bool fix();
96 
97 
98 private:
99 
100  TriMesh& mesh_;
101 
102 
111  void add_face(const ACG::Vec3d& _p0, const ACG::Vec3d& _p1, const ACG::Vec3d& _p2);
112 
113  void fix_topology();
114  void fix_orientation();
115 
116  int neighbor(unsigned int _f, unsigned int _v0, unsigned int _v1);
117 
118 
119 
121  struct Vertex
122  {
123  Vertex(const ACG::Vec3d& _p) : p(_p) { };
124  ACG::Vec3d p;
125 
127  std::vector<unsigned int> faces;
128  };
129 
131  struct Face
132  {
133  Face(int _i0, int _i1, int _i2) :
134  component(-1)
135  {
136  v[0] = _i0;
137  v[1] = _i1;
138  v[2] = _i2;
139 
140  }
141 
142  unsigned int v[3];
143  int component;
144  };
145 
146 
147  typedef std::map<ACG::Vec3d, int, CompareVectors> VertexMap;
148 
149  typedef VertexMap::iterator MapIter;
150 
151  std::vector<Vertex> vertices_;
152  std::vector<Face> faces_;
153 
154 
160  int add_vertex(const ACG::Vec3d& _p);
161 
162  VertexMap vmap_;
163 
164 };
165 
166 #if defined(INCLUDE_TEMPLATES) && !defined(OPENMESH_MESHFIXING_CC)
167 #define OPENMESH_MESHFIXING_TEMPLATES
168 #include "MeshFixingT.cc"
169 #endif
170 
171 #endif
172 
Fix a mesh.
Definition: MeshFixingT.hh:89
Compare two vectors.
Definition: MeshFixingT.hh:70
std::vector< unsigned int > faces
This vector will contain a list of all faces incident to the current vertex.
Definition: MeshFixingT.hh:127
void fix_topology()
Fix the mesh topology.
Definition: MeshFixingT.cc:142
int add_vertex(const ACG::Vec3d &_p)
Definition: MeshFixingT.cc:93
void add_face(const ACG::Vec3d &_p0, const ACG::Vec3d &_p1, const ACG::Vec3d &_p2)
Add a face to the fixing data.
Definition: MeshFixingT.cc:99
bool operator()(const ACG::Vec3d &_v0, const ACG::Vec3d &_v1) const
comparison operator
Definition: MeshFixingT.cc:76
Internal vertex type.
Definition: MeshFixingT.hh:121
void fix_orientation()
Definition: MeshFixingT.cc:308
int neighbor(unsigned int _f, unsigned int _v0, unsigned int _v1)
Definition: MeshFixingT.cc:271
Internal face type.
Definition: MeshFixingT.hh:131
CompareVectors(double _eps=FLT_MIN)
Constructor.
Definition: MeshFixingT.cc:71