Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MeshInfoT.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
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 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50
51
52
53 //=============================================================================
54 //
55 // IMPLEMENTATION
56 //
57 //=============================================================================
58
59 #define MESHINFOT_C
60
61 //== INCLUDES =================================================================
62
63 #include "MeshInfoT.hh"
64
65 #include <iostream>
66 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
67 #include <OpenMesh/Core/Geometry/MathDefs.hh>
68
69
70 //== NAMESPACES ===============================================================
71
72 namespace MeshInfo {
73
74 //== IMPLEMENTATION ===========================================================
75
76 template < typename MeshT >
77 inline
78 int boundaryCount(MeshT* _mesh ) {
79
80 int numOfBounds = 0;
81
82 OpenMesh::HPropHandleT< bool > visited;
83 _mesh->add_property(visited);
84
85 typename MeshT::VertexHandle last;
86 const typename MeshT::VertexHandle begin;
87
88 //Iteration �ber Halfedges
89 for (typename MeshT::HalfedgeIter he_it=_mesh->halfedges_begin(); he_it!=_mesh->halfedges_end() ; ++he_it )
90 _mesh->property(visited,*he_it) = false;
91
92 for (typename MeshT::HalfedgeIter he_it=_mesh->halfedges_begin(); he_it!=_mesh->halfedges_end() ; ++he_it ) {
93 if ( _mesh->property(visited,*he_it) )
94 continue;
95
96 if( !_mesh->is_boundary(*he_it ) )
97 continue;
98
99 _mesh->property(visited,*he_it) = true;
100 typename MeshT::HalfedgeHandle he = _mesh->next_halfedge_handle(*he_it);
101
102 while( _mesh->is_boundary(*he_it) && ! _mesh->property(visited,he) ) {
103 _mesh->property(visited,he) = true;
104 he = _mesh->next_halfedge_handle(he);
105 }
106
107 ++numOfBounds;
108
109 }
110
111 _mesh->remove_property(visited);
112
113 return numOfBounds;
114 }
115
116 //=============================================================================
117
118 template < typename MeshT >
119 inline
120 int componentCount(MeshT* _mesh ) {
121
122 int numOfComps = 0;
123
124 OpenMesh::VPropHandleT< bool > visited;
125 _mesh->add_property(visited);
126
127 typename MeshT::VertexIter v_it;
128 typename MeshT::VertexIter v_end = _mesh->vertices_end();
129
130 //iterate over all vertices
131 for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it)
132 _mesh->property(visited, *v_it) = false;
133
134 typename MeshT::VertexHandle vh;
135 typename MeshT::VertexIter current_pos = _mesh->vertices_begin();
136
137 while( true ){
138 //find an unvisited vertex
139 bool found = false;
140 for (v_it = current_pos ; v_it != v_end; ++v_it)
141 if ( !_mesh->property(visited, *v_it) ){
142 found = true;
143 vh = *v_it;
144 _mesh->property(visited, *v_it) = true;
145 current_pos = v_it;
146 break;
147 }
148
149 //if none was found -> finished
150 if (!found) break;
151
152 numOfComps++;
153
154 std::vector< typename MeshT::VertexHandle > handles;
155 handles.push_back( vh );
156
157 //grow from found vertex
158 while( ! handles.empty() ){
159 typename MeshT::VertexHandle current = handles.back();
160 handles.pop_back();
161
162 typename MeshT::VertexVertexIter vv_it;
163
164 for (vv_it=_mesh->vv_iter( current ); vv_it.is_valid(); ++vv_it)
165 if ( !_mesh->property(visited, *vv_it) ){
166 _mesh->property(visited, *vv_it) = true;
167 handles.push_back( *vv_it );
168 }
169 }
170 }
171
172 _mesh->remove_property(visited);
173
174 return numOfComps;
175 }
176
177 //=============================================================================
178
179 template < typename MeshT >
180 inline
181 void getBoundingBox( MeshT* _mesh,
182 typename MeshT::Point& _min ,
183 typename MeshT::Point& _max) {
184 if ( _mesh->n_vertices() == 0 ) {
185 std::cerr << "Unable to compute Bounding Box: No points in Mesh!" << std::endl;
186 }
187 // Use any point as initial value
188 _min = _mesh->point(_mesh->vertex_handle(0));
189 _max = _mesh->point(_mesh->vertex_handle(0));
190
191 for (typename MeshT::VertexIter v_it = _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it ) {
192 _min.minimize( _mesh->point(*v_it) );
193 _max.maximize( _mesh->point(*v_it) );
194 }
195
196 }
197
198 //=============================================================================
199
200 template < typename MeshT >
201 inline
202 typename MeshT::Point
203 cog ( const MeshT* _mesh ) {
204 typename MeshT::ConstVertexIter v_it, v_end=_mesh->vertices_end();
205 typename MeshT::Point cog(0.0,0.0,0.0);
206
207 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
208 cog += _mesh->point(*v_it);
209 cog = 1.0 / (typename MeshT::Scalar)_mesh->n_vertices() * cog;
210
211 return cog;
212 }
213
214 //=============================================================================
215 } // MeshInfo Namespace
216 //=============================================================================
OpenMesh::HPropHandleT
Definition: Property.hh:501
MeshInfo
Definition: MeshInfoT.cc:72
OpenMesh::VPropHandleT< bool >