64 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_INTERP_SQRT3T_LABSIK_GREINER_HH 65 #define OPENMESH_SUBDIVIDER_UNIFORM_INTERP_SQRT3T_LABSIK_GREINER_HH 70 #include <OpenMesh/Core/Mesh/Handles.hh> 71 #include <OpenMesh/Core/System/config.hh> 74 #if defined(_DEBUG) || defined(DEBUG) 77 # include <OpenMesh/Tools/Utils/MeshCheckerT.hh> 78 # define ASSERT_CONSISTENCY( T, m ) \ 79 assert(OpenMesh::Utils::MeshCheckerT<T>(m).check()) 81 # define ASSERT_CONSISTENCY( T, m ) 85 #if defined(OM_CC_MIPS) 97 namespace Subdivider {
112 template <
typename MeshType,
typename RealType =
double>
117 typedef RealType real_t;
118 typedef MeshType mesh_t;
121 typedef std::vector< std::vector<real_t> > weights_t;
138 const char *
name()
const {
return "Uniform Interpolating Sqrt3"; }
143 weights_.resize(_max_valence);
145 weights_[3].resize(4);
146 weights_[3][0] = real_t(+4.0/27);
147 weights_[3][1] = real_t(-5.0/27);
148 weights_[3][2] = real_t(+4.0/27);
149 weights_[3][3] = real_t(+8.0/9);
151 weights_[4].resize(5);
152 weights_[4][0] = real_t(+2.0/9);
153 weights_[4][1] = real_t(-1.0/9);
154 weights_[4][2] = real_t(-1.0/9);
155 weights_[4][3] = real_t(+2.0/9);
156 weights_[4][4] = real_t(+7.0/9);
158 for(
unsigned int K=5; K<_max_valence; ++K)
160 weights_[K].resize(K+1);
161 double aH = 2.0*cos(M_PI/static_cast<double>(K))/3.0;
162 weights_[K][K] =
static_cast<real_t
>(1.0 - aH*aH);
163 for(
unsigned int i=0; i<K; ++i)
166 weights_[K][i] =
static_cast<real_t
>((aH*aH + 2.0*aH*cos(2.0*static_cast<double>(i)*M_PI/static_cast<double>(K) + M_PI/static_cast<double>(K)) +
167 2.0*aH*aH*cos(4.0*static_cast<double>(i)*M_PI/static_cast<double>(K) + 2.0*M_PI/static_cast<double>(K)))/static_cast<double>(K));
172 weights_[6].resize(0);
182 _m.request_edge_status();
183 _m.add_property( fp_pos_ );
184 _m.add_property( ep_nv_ );
185 _m.add_property( mp_gen_ );
186 _m.property( mp_gen_ ) = 0;
188 return _m.has_edge_status()
195 _m.release_edge_status();
196 _m.remove_property( fp_pos_ );
197 _m.remove_property( ep_nv_ );
198 _m.remove_property( mp_gen_ );
203 bool subdivide( MeshType& _m,
size_t _n ,
const bool _update_points =
true)
208 typename MeshType::VertexIter vit;
209 typename MeshType::VertexVertexIter vvit;
210 typename MeshType::EdgeIter eit;
211 typename MeshType::FaceIter fit;
212 typename MeshType::FaceVertexIter fvit;
213 typename MeshType::FaceHalfedgeIter fheit;
214 typename MeshType::VertexHandle vh;
215 typename MeshType::HalfedgeHandle heh;
216 typename MeshType::Point pos(0,0,0), zero(0,0,0);
217 size_t &gen = _m.property( mp_gen_ );
219 for (
size_t l=0; l<_n; ++l)
222 for (eit=_m.edges_begin(); eit != _m.edges_end();++eit)
224 _m.status( *eit ).set_tagged(
true );
225 if ( (gen%2) && _m.is_boundary(*eit) )
226 compute_new_boundary_points( _m, *eit );
230 typename MeshType::FaceIter fend = _m.faces_end();
231 for (fit = _m.faces_begin();fit != fend; ++fit)
233 if (_m.is_boundary(*fit))
236 _m.property(fp_pos_, *fit).invalidate();
240 for( heh = _m.halfedge_handle(*fit); !_m.is_boundary( _m.opposite_halfedge_handle(heh) ); heh = _m.next_halfedge_handle(heh) )
242 assert(_m.is_boundary( _m.opposite_halfedge_handle(heh) ));
245 if( _m.is_boundary(_m.next_halfedge_handle(heh)) || _m.is_boundary(_m.prev_halfedge_handle(heh)) )
247 if(_m.is_boundary(_m.prev_halfedge_handle(heh)))
248 heh = _m.prev_halfedge_handle(heh);
250 if(_m.is_boundary(_m.next_halfedge_handle(_m.next_halfedge_handle(heh))))
253 pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(heh));
254 pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
255 pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(_m.prev_halfedge_handle(heh)));
259 #ifdef MIRROR_TRIANGLES 261 pos += real_t(2.0/9) * _m.point(_m.to_vertex_handle(heh));
262 pos += real_t(4.0/9) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
263 pos += real_t(4.0/9) * _m.point(_m.to_vertex_handle(_m.prev_halfedge_handle(heh)));
264 pos += real_t(-1.0/9) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(_m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh)))));
266 pos += real_t(7.0/24) * _m.point(_m.to_vertex_handle(heh));
267 pos += real_t(3.0/8) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
268 pos += real_t(3.0/8) * _m.point(_m.to_vertex_handle(_m.prev_halfedge_handle(heh)));
269 pos += real_t(-1.0/24) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(_m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh)))));
275 vh = _m.to_vertex_handle(_m.next_halfedge_handle(heh));
277 if((_m.valence(vh) == 6) || _m.is_boundary(vh))
279 #ifdef MIRROR_TRIANGLES 281 pos += real_t(5.0/9) * _m.point(vh);
282 pos += real_t(3.0/9) * _m.point(_m.to_vertex_handle(heh));
283 pos += real_t(3.0/9) * _m.point(_m.to_vertex_handle(_m.opposite_halfedge_handle(heh)));
284 pos += real_t(-1.0/9) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(_m.opposite_halfedge_handle(_m.next_halfedge_handle(heh)))));
285 pos += real_t(-1.0/9) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(_m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh)))));
288 pos += real_t(1.0/9) * _m.point(vh);
289 pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(heh));
290 pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(_m.opposite_halfedge_handle(heh)));
291 pos += real_t(1.0/9) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(_m.opposite_halfedge_handle(_m.next_halfedge_handle(heh)))));
292 pos += real_t(1.0/9) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(_m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh)))));
294 pos += real_t(1.0/2) * _m.point(vh);
295 pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(heh));
296 pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(_m.opposite_halfedge_handle(heh)));
297 pos += real_t(-1.0/12) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(_m.opposite_halfedge_handle(_m.next_halfedge_handle(heh)))));
298 pos += real_t(-1.0/12) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(_m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh)))));
305 unsigned int K = _m.valence(vh);
306 pos += weights_[K][K]*_m.point(vh);
307 heh = _m.opposite_halfedge_handle( _m.next_halfedge_handle(heh) );
308 for(
unsigned int i = 0; i<K; ++i, heh = _m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh)) )
310 pos += weights_[K][i]*_m.point(_m.to_vertex_handle(heh));
314 vh = _m.add_vertex( pos );
315 _m.property(fp_pos_, *fit) = vh;
324 for(fvit = _m.fv_iter( *fit ); fvit.is_valid(); ++fvit)
325 if( (_m.valence(*fvit)) == 6 || _m.is_boundary(*fvit) )
330 for(fheit = _m.fh_iter( *fit ); fheit.is_valid(); ++fheit)
334 assert(_m.to_vertex_handle(heh).is_valid());
335 pos += real_t(32.0/81) * _m.point(_m.to_vertex_handle(heh));
337 heh = _m.opposite_halfedge_handle(heh);
338 assert(heh.is_valid());
339 assert(_m.next_halfedge_handle(heh).is_valid());
340 assert(_m.to_vertex_handle(_m.next_halfedge_handle(heh)).is_valid());
341 pos -= real_t(1.0/81) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
343 heh = _m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh));
344 assert(heh.is_valid());
345 assert(_m.next_halfedge_handle(heh).is_valid());
346 assert(_m.to_vertex_handle(_m.next_halfedge_handle(heh)).is_valid());
347 pos -= real_t(2.0/81) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
348 heh = _m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh));
349 assert(heh.is_valid());
350 assert(_m.next_halfedge_handle(heh).is_valid());
351 assert(_m.to_vertex_handle(_m.next_halfedge_handle(heh)).is_valid());
352 pos -= real_t(2.0/81) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
358 for(fheit = _m.fh_iter( *fit ); fheit.is_valid(); ++fheit)
360 vh = _m.to_vertex_handle(*fheit);
361 if( (_m.valence(vh) != 6) && (!_m.is_boundary(vh)) )
363 unsigned int K = _m.valence(vh);
364 pos += weights_[K][K]*_m.point(vh);
365 heh = _m.opposite_halfedge_handle( *fheit );
366 for(
unsigned int i = 0; i<K; ++i, heh = _m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh)) )
368 pos += weights_[K][i]*_m.point(_m.to_vertex_handle(heh));
372 pos *= real_t(1.0/(3-nOrdinary));
375 vh = _m.add_vertex( pos );
376 _m.property(fp_pos_, *fit) = vh;
381 for (fit = _m.faces_begin();fit != fend; ++fit)
383 if ( _m.is_boundary(*fit) && (gen%2))
385 boundary_split( _m, *fit );
389 assert(_m.property(fp_pos_, *fit).is_valid());
390 _m.split( *fit, _m.property(fp_pos_, *fit) );
395 for (eit=_m.edges_begin(); eit != _m.edges_end(); ++eit)
396 if ( _m.status( *eit ).tagged() && !_m.is_boundary( *eit ) )
400 ASSERT_CONSISTENCY( MeshType, _m );
412 void compute_new_boundary_points( MeshType& _m,
413 const typename MeshType::EdgeHandle& _eh)
415 assert( _m.is_boundary(_eh) );
417 typename MeshType::HalfedgeHandle heh;
418 typename MeshType::VertexHandle vh1, vh2, vh3, vh4, vhl, vhr;
419 typename MeshType::Point zero(0,0,0), P1, P2, P3, P4;
434 heh = _m.halfedge_handle(_eh,
435 _m.is_boundary(_m.halfedge_handle(_eh,1)));
437 assert( _m.is_boundary( _m.next_halfedge_handle( heh ) ) );
438 assert( _m.is_boundary( _m.prev_halfedge_handle( heh ) ) );
440 vh1 = _m.to_vertex_handle( _m.next_halfedge_handle( heh ) );
441 vh2 = _m.to_vertex_handle( heh );
442 vh3 = _m.from_vertex_handle( heh );
443 vh4 = _m.from_vertex_handle( _m.prev_halfedge_handle( heh ));
450 vhl = _m.add_vertex(real_t(-5.0/81)*P1 + real_t(20.0/27)*P2 + real_t(10.0/27)*P3 + real_t(-4.0/81)*P4);
451 vhr = _m.add_vertex(real_t(-5.0/81)*P4 + real_t(20.0/27)*P3 + real_t(10.0/27)*P2 + real_t(-4.0/81)*P1);
453 _m.property(ep_nv_, _eh).first = vhl;
454 _m.property(ep_nv_, _eh).second = vhr;
458 void boundary_split( MeshType& _m,
const typename MeshType::FaceHandle& _fh )
460 assert( _m.is_boundary(_fh) );
462 typename MeshType::VertexHandle vhl, vhr;
463 typename MeshType::FaceEdgeIter fe_it;
464 typename MeshType::HalfedgeHandle heh;
467 for( fe_it=_m.fe_iter( _fh ); fe_it.is_valid() && !_m.is_boundary( *fe_it ); ++fe_it ) {};
470 vhl = _m.property(ep_nv_, *fe_it).first;
471 vhr = _m.property(ep_nv_, *fe_it).second;
486 heh = _m.halfedge_handle(*fe_it, _m.is_boundary(_m.halfedge_handle(*fe_it,0)));
488 typename MeshType::HalfedgeHandle pl_P3;
491 boundary_split( _m, heh, vhl );
492 pl_P3 = _m.next_halfedge_handle( heh );
493 boundary_split( _m, heh );
496 boundary_split( _m, pl_P3, vhr );
497 boundary_split( _m, pl_P3 );
499 assert( _m.is_boundary( vhl ) && _m.halfedge_handle(vhl).is_valid() );
500 assert( _m.is_boundary( vhr ) && _m.halfedge_handle(vhr).is_valid() );
503 void boundary_split(MeshType& _m,
504 const typename MeshType::HalfedgeHandle& _heh,
505 const typename MeshType::VertexHandle& _vh)
507 assert( _m.is_boundary( _m.edge_handle(_heh) ) );
509 typename MeshType::HalfedgeHandle
511 opp_heh( _m.opposite_halfedge_handle(_heh) ),
512 new_heh, opp_new_heh;
513 typename MeshType::VertexHandle to_vh(_m.to_vertex_handle(heh));
514 typename MeshType::HalfedgeHandle t_heh;
535 _m.next_halfedge_handle(t_heh) != opp_heh;
536 t_heh = _m.opposite_halfedge_handle(_m.next_halfedge_handle(t_heh)))
539 assert( _m.is_boundary( t_heh ) );
541 new_heh = _m.new_edge( _vh, to_vh );
542 opp_new_heh = _m.opposite_halfedge_handle(new_heh);
545 _m.set_next_halfedge_handle(t_heh, opp_new_heh);
546 _m.set_next_halfedge_handle(new_heh, _m.next_halfedge_handle(heh));
547 _m.set_next_halfedge_handle(heh, new_heh);
548 _m.set_next_halfedge_handle(opp_new_heh, opp_heh);
551 _m.set_face_handle(opp_new_heh, _m.face_handle(opp_heh));
554 _m.set_vertex_handle(heh, _vh);
557 _m.set_face_handle(new_heh, _m.face_handle(heh));
561 _m.set_halfedge_handle( to_vh, opp_new_heh );
564 _m.set_halfedge_handle( _vh, opp_heh );
567 void boundary_split( MeshType& _m,
568 const typename MeshType::HalfedgeHandle& _heh)
570 assert( _m.is_boundary( _m.opposite_halfedge_handle( _heh ) ) );
572 typename MeshType::HalfedgeHandle
574 n_heh(_m.next_halfedge_handle(heh));
576 typename MeshType::VertexHandle
577 to_vh(_m.to_vertex_handle(heh));
579 typename MeshType::HalfedgeHandle
580 heh2(_m.new_edge(to_vh,
581 _m.to_vertex_handle(_m.next_halfedge_handle(n_heh)))),
582 heh3(_m.opposite_halfedge_handle(heh2));
584 typename MeshType::FaceHandle
585 new_fh(_m.new_face()),
586 fh(_m.face_handle(heh));
589 _m.set_face_handle(heh, new_fh);
590 _m.set_face_handle(heh2, new_fh);
591 _m.set_next_halfedge_handle(heh2, _m.next_halfedge_handle(_m.next_halfedge_handle(n_heh)));
592 _m.set_next_halfedge_handle(heh, heh2);
593 _m.set_face_handle( _m.next_halfedge_handle(heh2), new_fh);
595 _m.set_next_halfedge_handle(heh3, n_heh);
596 _m.set_next_halfedge_handle(_m.next_halfedge_handle(n_heh), heh3);
597 _m.set_face_handle(heh3, fh);
599 _m.set_halfedge_handle( fh, n_heh);
600 _m.set_halfedge_handle(new_fh, heh);
610 typename MeshType::VertexHandle> > ep_nv_;
620 #endif // OPENMESH_SUBDIVIDER_UNIFORM_SQRT3T_HH bool subdivide(MeshType &_m, size_t _n, const bool _update_points=true)
Subdivide mesh _m _n times.
Definition: Sqrt3InterpolatingSubdividerLabsikGreinerT.hh:203
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
bool cleanup(MeshType &_m)
Cleanup mesh after usage, e.g. remove added properties.
Definition: Sqrt3InterpolatingSubdividerLabsikGreinerT.hh:193
const char * name() const
Return name of subdivision algorithm.
Definition: Sqrt3InterpolatingSubdividerLabsikGreinerT.hh:138
Abstract base class for uniform subdivision algorithms.
Definition: SubdividerT.hh:93
Uniform Interpolating Sqrt3 subdivision algorithm
Definition: Sqrt3InterpolatingSubdividerLabsikGreinerT.hh:113
Handle representing an edge property.
Definition: Property.hh:515
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:77
bool prepare(MeshType &_m)
Prepare mesh, e.g. add properties.
Definition: Sqrt3InterpolatingSubdividerLabsikGreinerT.hh:180
void init_weights(size_t _max_valence=50)
Pre-compute weights.
Definition: Sqrt3InterpolatingSubdividerLabsikGreinerT.hh:141