Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HoleInfoT.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: 11127 $ *
45 * $LastChangedBy: moebius $ *
46 * $Date: 2011-03-15 16:18:28 +0100 (Di, 15 Mär 2011) $ *
47 * *
48 \*===========================================================================*/
49 
50 #define HOLEINFO_C
51 
52 #include "HoleInfoT.hh"
53 
55 
57 template< class MeshT >
59  : mesh_(_mesh), filler_(0)
60 {
61 }
62 
64 template< class MeshT >
66 {
67  if (filler_ != 0)
68  delete filler_;
69 }
70 
72 template< class MeshT >
74 {
75 
76  // Property for the active mesh to mark already visited edges
77  OpenMesh::EPropHandleT< bool > boundary_search;
78 
79  // Add a property to the mesh to store original vertex positions
80  mesh_->add_property( boundary_search, "Boundary search" );
81 
82  // Initialize Property
83  typename MeshT::EdgeIter e_it, e_end=mesh_->edges_end();
84  for (e_it=mesh_->edges_begin(); e_it!=e_end; ++e_it) {
85  mesh_->property( boundary_search , *e_it ) = false;
86  }
87 
88  holes_.clear();
89 
90  for (e_it=mesh_->edges_begin(); e_it!=e_end; ++e_it) {
91 
92  // Skip already visited edges
93  if ( mesh_->property( boundary_search , *e_it ) )
94  continue;
95 
96  // Check only boundary edges
97  if ( !mesh_->is_boundary(*e_it))
98  continue;
99 
100  // Get boundary halfedge
101  typename MeshT::HalfedgeHandle hh = mesh_->halfedge_handle( *e_it, 0 );
102  if ( ! mesh_->is_boundary( hh ) )
103  hh = mesh_->opposite_halfedge_handle( hh );
104 
105 
106  typename MeshT::Point center(0,0,0);
107 
108  Hole currentHole;
109 
110  // Collect boundary edges
111  typename MeshT::HalfedgeHandle ch = hh;
112  do {
113  currentHole.push_back( mesh_->edge_handle(ch) );
114 
115  center += mesh_->point( mesh_->from_vertex_handle(ch) );
116 
117  mesh_->property( boundary_search , mesh_->edge_handle(ch) ) = true;
118 
119  //check number of outgoing boundary HEH's at Vertex
120  int c = 0;
121  typename MeshT::VertexHandle vh = mesh_->to_vertex_handle(ch);
122 
123  for ( typename MeshT::VertexOHalfedgeIter voh_it(*mesh_,vh); voh_it.is_valid(); ++voh_it)
124  if ( mesh_->is_boundary( *voh_it ) )
125  c++;
126 
127  if ( c >= 2){
128  typename MeshT::HalfedgeHandle op = mesh_->opposite_halfedge_handle( ch );
129  typename MeshT::VertexOHalfedgeIter voh_it(*mesh_,op);
130 
131  ch = *(++voh_it);
132 
133  }else
134  ch = mesh_->next_halfedge_handle( ch );
135 
136  } while ( ch != hh );
137 
138 
139  center /= currentHole.size();
140 
141  bool isHole = true;
142 
143  int err = 0;
144 
145  for (unsigned int i=0; i < currentHole.size(); i++){
146  typename MeshT::HalfedgeHandle hh = mesh_->halfedge_handle( currentHole[i], 0 );
147 
148  if ( ! mesh_->is_boundary( hh ) )
149  hh = mesh_->opposite_halfedge_handle( hh );
150 
151  typename MeshT::VertexHandle vh = mesh_->from_vertex_handle(hh);
152 
153  typename MeshT::Normal n = mesh_->normal( vh );
154 
155  typename MeshT::Point p = mesh_->point( vh );
156 
157  if ( (p - center).norm() < (p + n - center).norm() ){
158 // isHole = false;
159 // break;
160  err++;
161  }
162  }
163 
164 // std::cerr << "Errors " << err << " Size " << hole.count << std::endl;
165  if (isHole)
166  holes_.push_back(currentHole);
167  }
168 
169  mesh_->remove_property( boundary_search);
170 
171 }
172 
174 template< class MeshT >
175 void HoleInfo< MeshT >::fillHole(int _index, int _stages)
176 {
177 
178  if ( (uint) _index > holes_.size()){
179  std::cerr << "Cannot fill hole. Index invalid." << std::endl;
180  return;
181  }
182 
183  if (filler_ == 0)
184  filler_ = new HoleFiller< MeshT >(*mesh_);
185 
186  filler_->fill_hole( holes_[_index][0], _stages );
187 
188  mesh_->garbage_collection();
189 
190  MeshSelection::clearEdgeSelection(mesh_);
191 
192  mesh_->update_normals();
193 }
194 
196 template< class MeshT >
197 void HoleInfo< MeshT >::fillHole(typename MeshT::EdgeHandle _eh, int _stages)
198 {
199  if (filler_ == 0)
200  filler_ = new HoleFiller< MeshT >(*mesh_);
201 
202  filler_->fill_hole( _eh, _stages );
203 
204  mesh_->garbage_collection();
205 
206  MeshSelection::clearEdgeSelection(mesh_);
207 
208  mesh_->update_normals();
209 }
210 
212 template< class MeshT >
214 {
215 
216  if (filler_ == 0)
217  filler_ = new HoleFiller< MeshT >(*mesh_);
218 
219  filler_->fill_all_holes( _stages );
220 
221 }
222 
224 template< class MeshT >
226 {
227 
228  if ( (uint) _index > holes_.size()){
229  std::cerr << "Cannot select hole. Index invalid." << std::endl;
230  return;
231  }
232 
233  for ( uint i = 0 ; i < (holes_[_index]).size() ; ++i ) {
234  mesh_->status( (holes_[_index])[i] ).set_selected(true);
235  }
236 
237 }
238 
240 template< class MeshT >
241 std::vector< std::vector< typename MeshT::EdgeHandle > >* HoleInfo< MeshT >::holes()
242 {
243  return &holes_;
244 }
245 
246 
void selectHole(int _index)
select a hole with given index
Definition: HoleInfoT.cc:225
~HoleInfo()
Destructor.
Definition: HoleInfoT.cc:65
HoleInfo(MeshT *_mesh)
Constructor.
Definition: HoleInfoT.cc:58
std::vector< std::vector< typename MeshT::EdgeHandle > > * holes()
get the holes vector
Definition: HoleInfoT.cc:241
void fillAllHoles(int _stages=3)
fill all holes of the mesh
Definition: HoleInfoT.cc:213
void getHoles()
get all holes and store them internally
Definition: HoleInfoT.cc:73
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
Functions for selection on a mesh.
void fillHole(int _index, int _stages=3)
fill hole with given index
Definition: HoleInfoT.cc:175