Developer Documentation
Sqrt3InterpolatingSubdividerLabsikGreinerT.hh
Go to the documentation of this file.
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.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
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 
51 //=============================================================================
52 //
53 // CLASS InterpolatingSqrt3LGT
54 //
55 //=============================================================================
56 
57 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_INTERP_SQRT3T_LABSIK_GREINER_HH
58 #define OPENMESH_SUBDIVIDER_UNIFORM_INTERP_SQRT3T_LABSIK_GREINER_HH
59 
60 
61 //== INCLUDES =================================================================
62 
63 #include <OpenMesh/Core/Mesh/Handles.hh>
64 #include <OpenMesh/Core/System/config.hh>
66 
67 #if defined(_DEBUG) || defined(DEBUG)
68 // Makes life lot easier, when playing/messing around with low-level topology
69 // changing methods of OpenMesh
70 # include <OpenMesh/Tools/Utils/MeshCheckerT.hh>
71 # define ASSERT_CONSISTENCY( T, m ) \
72  assert(OpenMesh::Utils::MeshCheckerT<T>(m).check())
73 #else
74 # define ASSERT_CONSISTENCY( T, m )
75 #endif
76 // -------------------- STL
77 #include <vector>
78 #if defined(OM_CC_MIPS)
79 # include <math.h>
80 #else
81 # include <cmath>
82 #endif
83 
84 //#define MIRROR_TRIANGLES
85 //#define MIN_NORM
86 
87 //== NAMESPACE ================================================================
88 
89 namespace OpenMesh { // BEGIN_NS_OPENMESH
90 namespace Subdivider { // BEGIN_NS_DECIMATER
91 namespace Uniform { // BEGIN_NS_UNIFORM
92 
93 
94 //== CLASS DEFINITION =========================================================
95 
96 
105 template <typename MeshType, typename RealType = double>
106 class InterpolatingSqrt3LGT : public SubdividerT< MeshType, RealType >
107 {
108 public:
109 
110  typedef RealType real_t;
111  typedef MeshType mesh_t;
113 
114  typedef std::vector< std::vector<real_t> > weights_t;
115 
116 public:
117 
118 
119  InterpolatingSqrt3LGT(void) : parent_t()
120  { init_weights(); }
121 
122  explicit InterpolatingSqrt3LGT(MeshType &_m) : parent_t(_m)
123  { init_weights(); }
124 
125  virtual ~InterpolatingSqrt3LGT() {}
126 
127 
128 public:
129 
130 
131  const char *name() const override { return "Uniform Interpolating Sqrt3"; }
132 
134  void init_weights(size_t _max_valence=50)
135  {
136  weights_.resize(_max_valence);
137 
138  weights_[3].resize(4);
139  weights_[3][0] = real_t(+4.0/27);
140  weights_[3][1] = real_t(-5.0/27);
141  weights_[3][2] = real_t(+4.0/27);
142  weights_[3][3] = real_t(+8.0/9);
143 
144  weights_[4].resize(5);
145  weights_[4][0] = real_t(+2.0/9);
146  weights_[4][1] = real_t(-1.0/9);
147  weights_[4][2] = real_t(-1.0/9);
148  weights_[4][3] = real_t(+2.0/9);
149  weights_[4][4] = real_t(+7.0/9);
150 
151  for(unsigned int K=5; K<_max_valence; ++K)
152  {
153  weights_[K].resize(K+1);
154  double aH = 2.0*cos(M_PI/static_cast<double>(K))/3.0;
155  weights_[K][K] = static_cast<real_t>(1.0 - aH*aH);
156  for(unsigned int i=0; i<K; ++i)
157  {
158 
159  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)) +
160  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));
161  }
162  }
163 
164  //just to be sure:
165  weights_[6].resize(0);
166 
167  }
168 
169 
170 protected:
171 
172 
173  bool prepare( MeshType& _m ) override
174  {
175  _m.request_edge_status();
176  _m.add_property( fp_pos_ );
177  _m.add_property( ep_nv_ );
178  _m.add_property( mp_gen_ );
179  _m.property( mp_gen_ ) = 0;
180 
181  return _m.has_edge_status()
182  && ep_nv_.is_valid() && mp_gen_.is_valid();
183  }
184 
185 
186  bool cleanup( MeshType& _m ) override
187  {
188  _m.release_edge_status();
189  _m.remove_property( fp_pos_ );
190  _m.remove_property( ep_nv_ );
191  _m.remove_property( mp_gen_ );
192  return true;
193  }
194 
195 
196  bool subdivide( MeshType& _m, size_t _n , const bool _update_points = true) override
197  {
198 
200 
201  typename MeshType::VertexIter vit;
202  typename MeshType::VertexVertexIter vvit;
203  typename MeshType::EdgeIter eit;
204  typename MeshType::FaceIter fit;
205  typename MeshType::FaceVertexIter fvit;
206  typename MeshType::FaceHalfedgeIter fheit;
207  typename MeshType::VertexHandle vh;
208  typename MeshType::HalfedgeHandle heh;
209  typename MeshType::Point pos(0,0,0), zero(0,0,0);
210  size_t &gen = _m.property( mp_gen_ );
211 
212  for (size_t l=0; l<_n; ++l)
213  {
214  // tag existing edges
215  for (eit=_m.edges_begin(); eit != _m.edges_end();++eit)
216  {
217  _m.status( *eit ).set_tagged( true );
218  if ( (gen%2) && _m.is_boundary(*eit) )
219  compute_new_boundary_points( _m, *eit ); // *) creates new vertices
220  }
221 
222  // insert new vertices, and store pos in vp_pos_
223  typename MeshType::FaceIter fend = _m.faces_end();
224  for (fit = _m.faces_begin();fit != fend; ++fit)
225  {
226  if (_m.is_boundary(*fit))
227  {
228  if(gen%2)
229  _m.property(fp_pos_, *fit).invalidate();
230  else
231  {
232  //find the interior boundary halfedge
233  for( heh = _m.halfedge_handle(*fit); !_m.is_boundary( _m.opposite_halfedge_handle(heh) ); heh = _m.next_halfedge_handle(heh) )
234  ;
235  assert(_m.is_boundary( _m.opposite_halfedge_handle(heh) ));
236  pos = zero;
237  //check for two boundaries case:
238  if( _m.is_boundary(_m.next_halfedge_handle(heh)) || _m.is_boundary(_m.prev_halfedge_handle(heh)) )
239  {
240  if(_m.is_boundary(_m.prev_halfedge_handle(heh)))
241  heh = _m.prev_halfedge_handle(heh); //ensure that the boundary halfedges are heh and heh->next
242  //check for three boundaries case:
243  if(_m.is_boundary(_m.next_halfedge_handle(_m.next_halfedge_handle(heh))))
244  {
245  //three boundaries, use COG of triangle
246  pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(heh));
247  pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
248  pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(_m.prev_halfedge_handle(heh)));
249  }
250  else
251  {
252 #ifdef MIRROR_TRIANGLES
253  //two boundaries, mirror two triangles
254  pos += real_t(2.0/9) * _m.point(_m.to_vertex_handle(heh));
255  pos += real_t(4.0/9) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
256  pos += real_t(4.0/9) * _m.point(_m.to_vertex_handle(_m.prev_halfedge_handle(heh)));
257  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)))));
258 #else
259  pos += real_t(7.0/24) * _m.point(_m.to_vertex_handle(heh));
260  pos += real_t(3.0/8) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
261  pos += real_t(3.0/8) * _m.point(_m.to_vertex_handle(_m.prev_halfedge_handle(heh)));
262  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)))));
263 #endif
264  }
265  }
266  else
267  {
268  vh = _m.to_vertex_handle(_m.next_halfedge_handle(heh));
269  //check last vertex regularity
270  if((_m.valence(vh) == 6) || _m.is_boundary(vh))
271  {
272 #ifdef MIRROR_TRIANGLES
273  //use regular rule and mirror one triangle
274  pos += real_t(5.0/9) * _m.point(vh);
275  pos += real_t(3.0/9) * _m.point(_m.to_vertex_handle(heh));
276  pos += real_t(3.0/9) * _m.point(_m.to_vertex_handle(_m.opposite_halfedge_handle(heh)));
277  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)))));
278  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)))));
279 #else
280 #ifdef MIN_NORM
281  pos += real_t(1.0/9) * _m.point(vh);
282  pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(heh));
283  pos += real_t(1.0/3) * _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)))));
286 #else
287  pos += real_t(1.0/2) * _m.point(vh);
288  pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(heh));
289  pos += real_t(1.0/3) * _m.point(_m.to_vertex_handle(_m.opposite_halfedge_handle(heh)));
290  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)))));
291  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)))));
292 #endif
293 #endif
294  }
295  else
296  {
297  //irregular setting, use usual irregular rule
298  unsigned int K = _m.valence(vh);
299  pos += weights_[K][K]*_m.point(vh);
300  heh = _m.opposite_halfedge_handle( _m.next_halfedge_handle(heh) );
301  for(unsigned int i = 0; i<K; ++i, heh = _m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh)) )
302  {
303  pos += weights_[K][i]*_m.point(_m.to_vertex_handle(heh));
304  }
305  }
306  }
307  vh = _m.add_vertex( pos );
308  _m.property(fp_pos_, *fit) = vh;
309  }
310  }
311  else
312  {
313  pos = zero;
314  int nOrdinary = 0;
315 
316  //check number of extraordinary vertices
317  for(fvit = _m.fv_iter( *fit ); fvit.is_valid(); ++fvit)
318  if( (_m.valence(*fvit)) == 6 || _m.is_boundary(*fvit) )
319  ++nOrdinary;
320 
321  if(nOrdinary==3)
322  {
323  for(fheit = _m.fh_iter( *fit ); fheit.is_valid(); ++fheit)
324  {
325  //one ring vertex has weight 32/81
326  heh = *fheit;
327  assert(_m.to_vertex_handle(heh).is_valid());
328  pos += real_t(32.0/81) * _m.point(_m.to_vertex_handle(heh));
329  //tip vertex has weight -1/81
330  heh = _m.opposite_halfedge_handle(heh);
331  assert(heh.is_valid());
332  assert(_m.next_halfedge_handle(heh).is_valid());
333  assert(_m.to_vertex_handle(_m.next_halfedge_handle(heh)).is_valid());
334  pos -= real_t(1.0/81) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
335  //outer vertices have weight -2/81
336  heh = _m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh));
337  assert(heh.is_valid());
338  assert(_m.next_halfedge_handle(heh).is_valid());
339  assert(_m.to_vertex_handle(_m.next_halfedge_handle(heh)).is_valid());
340  pos -= real_t(2.0/81) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
341  heh = _m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh));
342  assert(heh.is_valid());
343  assert(_m.next_halfedge_handle(heh).is_valid());
344  assert(_m.to_vertex_handle(_m.next_halfedge_handle(heh)).is_valid());
345  pos -= real_t(2.0/81) * _m.point(_m.to_vertex_handle(_m.next_halfedge_handle(heh)));
346  }
347  }
348  else
349  {
350  //only use irregular vertices:
351  for(fheit = _m.fh_iter( *fit ); fheit.is_valid(); ++fheit)
352  {
353  vh = _m.to_vertex_handle(*fheit);
354  if( (_m.valence(vh) != 6) && (!_m.is_boundary(vh)) )
355  {
356  unsigned int K = _m.valence(vh);
357  pos += weights_[K][K]*_m.point(vh);
358  heh = _m.opposite_halfedge_handle( *fheit );
359  for(unsigned int i = 0; i<K; ++i, heh = _m.opposite_halfedge_handle(_m.prev_halfedge_handle(heh)) )
360  {
361  pos += weights_[K][i]*_m.point(_m.to_vertex_handle(heh));
362  }
363  }
364  }
365  pos *= real_t(1.0/(3-nOrdinary));
366  }
367 
368  vh = _m.add_vertex( pos );
369  _m.property(fp_pos_, *fit) = vh;
370  }
371  }
372 
373  //split faces
374  for (fit = _m.faces_begin();fit != fend; ++fit)
375  {
376  if ( _m.is_boundary(*fit) && (gen%2))
377  {
378  boundary_split( _m, *fit );
379  }
380  else
381  {
382  assert(_m.property(fp_pos_, *fit).is_valid());
383  _m.split( *fit, _m.property(fp_pos_, *fit) );
384  }
385  }
386 
387  // flip old edges
388  for (eit=_m.edges_begin(); eit != _m.edges_end(); ++eit)
389  if ( _m.status( *eit ).tagged() && !_m.is_boundary( *eit ) )
390  _m.flip(*eit);
391 
392  // Now we have an consistent mesh!
393  ASSERT_CONSISTENCY( MeshType, _m );
394 
395  // increase generation by one
396  ++gen;
397  }
398  return true;
399  }
400 
401 private:
402 
403  // Pre-compute location of new boundary points for odd generations
404  // and store them in the edge property ep_nv_;
405  void compute_new_boundary_points( MeshType& _m,
406  const typename MeshType::EdgeHandle& _eh)
407  {
408  assert( _m.is_boundary(_eh) );
409 
410  typename MeshType::HalfedgeHandle heh;
411  typename MeshType::VertexHandle vh1, vh2, vh3, vh4, vhl, vhr;
412  typename MeshType::Point P1, P2, P3, P4;
413 
414  /*
415  // *---------*---------*
416  // / \ / \ / \
417  // / \ / \ / \
418  // / \ / \ / \
419  // / \ / \ / \
420  // *---------*--#---#--*---------*
421  //
422  // ^ ^ ^ ^ ^ ^
423  // P1 P2 pl pr P3 P4
424  */
425  // get halfedge pointing from P3 to P2 (outer boundary halfedge)
426 
427  heh = _m.halfedge_handle(_eh,
428  _m.is_boundary(_m.halfedge_handle(_eh,1)));
429 
430  assert( _m.is_boundary( _m.next_halfedge_handle( heh ) ) );
431  assert( _m.is_boundary( _m.prev_halfedge_handle( heh ) ) );
432 
433  vh1 = _m.to_vertex_handle( _m.next_halfedge_handle( heh ) );
434  vh2 = _m.to_vertex_handle( heh );
435  vh3 = _m.from_vertex_handle( heh );
436  vh4 = _m.from_vertex_handle( _m.prev_halfedge_handle( heh ));
437 
438  P1 = _m.point(vh1);
439  P2 = _m.point(vh2);
440  P3 = _m.point(vh3);
441  P4 = _m.point(vh4);
442 
443  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);
444  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);
445 
446  _m.property(ep_nv_, _eh).first = vhl;
447  _m.property(ep_nv_, _eh).second = vhr;
448  }
449 
450 
451  void boundary_split( MeshType& _m, const typename MeshType::FaceHandle& _fh )
452  {
453  assert( _m.is_boundary(_fh) );
454 
455  typename MeshType::VertexHandle vhl, vhr;
456  typename MeshType::FaceEdgeIter fe_it;
457  typename MeshType::HalfedgeHandle heh;
458 
459  // find boundary edge
460  for( fe_it=_m.fe_iter( _fh ); fe_it.is_valid() && !_m.is_boundary( *fe_it ); ++fe_it ) {};
461 
462  // use precomputed, already inserted but not linked vertices
463  vhl = _m.property(ep_nv_, *fe_it).first;
464  vhr = _m.property(ep_nv_, *fe_it).second;
465 
466  /*
467  // *---------*---------*
468  // / \ / \ / \
469  // / \ / \ / \
470  // / \ / \ / \
471  // / \ / \ / \
472  // *---------*--#---#--*---------*
473  //
474  // ^ ^ ^ ^ ^ ^
475  // P1 P2 pl pr P3 P4
476  */
477  // get halfedge pointing from P2 to P3 (inner boundary halfedge)
478 
479  heh = _m.halfedge_handle(*fe_it, _m.is_boundary(_m.halfedge_handle(*fe_it,0)));
480 
481  typename MeshType::HalfedgeHandle pl_P3;
482 
483  // split P2->P3 (heh) in P2->pl (heh) and pl->P3
484  boundary_split( _m, heh, vhl ); // split edge
485  pl_P3 = _m.next_halfedge_handle( heh ); // store next halfedge handle
486  boundary_split( _m, heh ); // split face
487 
488  // split pl->P3 in pl->pr and pr->P3
489  boundary_split( _m, pl_P3, vhr );
490  boundary_split( _m, pl_P3 );
491 
492  assert( _m.is_boundary( vhl ) && _m.halfedge_handle(vhl).is_valid() );
493  assert( _m.is_boundary( vhr ) && _m.halfedge_handle(vhr).is_valid() );
494  }
495 
496  void boundary_split(MeshType& _m,
497  const typename MeshType::HalfedgeHandle& _heh,
498  const typename MeshType::VertexHandle& _vh)
499  {
500  assert( _m.is_boundary( _m.edge_handle(_heh) ) );
501 
502  typename MeshType::HalfedgeHandle
503  heh(_heh),
504  opp_heh( _m.opposite_halfedge_handle(_heh) ),
505  new_heh, opp_new_heh;
506  typename MeshType::VertexHandle to_vh(_m.to_vertex_handle(heh));
507  typename MeshType::HalfedgeHandle t_heh;
508 
509  /*
510  * P5
511  * *
512  * /|\
513  * / \
514  * / \
515  * / \
516  * / \
517  * /_ heh new \
518  * *-----\*-----\*\-----*
519  * ^ ^ t_heh
520  * _vh to_vh
521  *
522  * P1 P2 P3 P4
523  */
524  // Re-Setting Handles
525 
526  // find halfedge point from P4 to P3
527  for(t_heh = heh;
528  _m.next_halfedge_handle(t_heh) != opp_heh;
529  t_heh = _m.opposite_halfedge_handle(_m.next_halfedge_handle(t_heh)))
530  {}
531 
532  assert( _m.is_boundary( t_heh ) );
533 
534  new_heh = _m.new_edge( _vh, to_vh );
535  opp_new_heh = _m.opposite_halfedge_handle(new_heh);
536 
537  // update halfedge connectivity
538  _m.set_next_halfedge_handle(t_heh, opp_new_heh); // P4-P3 -> P3-P2
539  _m.set_next_halfedge_handle(new_heh, _m.next_halfedge_handle(heh)); // P2-P3 -> P3-P5
540  _m.set_next_halfedge_handle(heh, new_heh); // P1-P2 -> P2-P3
541  _m.set_next_halfedge_handle(opp_new_heh, opp_heh); // P3-P2 -> P2-P1
542 
543  // both opposite halfedges point to same face
544  _m.set_face_handle(opp_new_heh, _m.face_handle(opp_heh));
545 
546  // let heh finally point to new inserted vertex
547  _m.set_vertex_handle(heh, _vh);
548 
549  // let heh and new_heh point to same face
550  _m.set_face_handle(new_heh, _m.face_handle(heh));
551 
552  // let opp_new_heh be the new outgoing halfedge for to_vh
553  // (replaces for opp_heh)
554  _m.set_halfedge_handle( to_vh, opp_new_heh );
555 
556  // let opp_heh be the outgoing halfedge for _vh
557  _m.set_halfedge_handle( _vh, opp_heh );
558  }
559 
560  void boundary_split( MeshType& _m,
561  const typename MeshType::HalfedgeHandle& _heh)
562  {
563  assert( _m.is_boundary( _m.opposite_halfedge_handle( _heh ) ) );
564 
565  typename MeshType::HalfedgeHandle
566  heh(_heh),
567  n_heh(_m.next_halfedge_handle(heh));
568 
569  typename MeshType::VertexHandle
570  to_vh(_m.to_vertex_handle(heh));
571 
572  typename MeshType::HalfedgeHandle
573  heh2(_m.new_edge(to_vh,
574  _m.to_vertex_handle(_m.next_halfedge_handle(n_heh)))),
575  heh3(_m.opposite_halfedge_handle(heh2));
576 
577  typename MeshType::FaceHandle
578  new_fh(_m.new_face()),
579  fh(_m.face_handle(heh));
580 
581  // Relink (half)edges
582  _m.set_face_handle(heh, new_fh);
583  _m.set_face_handle(heh2, new_fh);
584  _m.set_next_halfedge_handle(heh2, _m.next_halfedge_handle(_m.next_halfedge_handle(n_heh)));
585  _m.set_next_halfedge_handle(heh, heh2);
586  _m.set_face_handle( _m.next_halfedge_handle(heh2), new_fh);
587 
588  _m.set_next_halfedge_handle(heh3, n_heh);
589  _m.set_next_halfedge_handle(_m.next_halfedge_handle(n_heh), heh3);
590  _m.set_face_handle(heh3, fh);
591 
592  _m.set_halfedge_handle( fh, n_heh);
593  _m.set_halfedge_handle(new_fh, heh);
594 
595 
596  }
597 
598 private:
599 
600  weights_t weights_;
602  OpenMesh::EPropHandleT< std::pair< typename MeshType::VertexHandle,
603  typename MeshType::VertexHandle> > ep_nv_;
605 };
606 
607 
608 //=============================================================================
609 } // END_NS_UNIFORM
610 } // END_NS_SUBDIVIDER
611 } // END_NS_OPENMESH
612 //=============================================================================
613 #endif // OPENMESH_SUBDIVIDER_UNIFORM_SQRT3T_HH
614 //=============================================================================
bool prepare(MeshType &_m) override
Prepare mesh, e.g. add properties.
bool cleanup(MeshType &_m) override
Cleanup mesh after usage, e.g. remove added properties.
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72
bool subdivide(MeshType &_m, size_t _n, const bool _update_points=true) override
Subdivide mesh _m _n times.
const char * name() const override
Return name of subdivision algorithm.