Developer Documentation
CompositeT.cc
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 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
53 //=============================================================================
54 //
55 // CLASS CompositeT - IMPLEMENTATION
56 //
57 //=============================================================================
58 
59 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITE_CC
60 #define OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITE_CC
61 
62 
63 //== INCLUDES =================================================================
64 
65 
66 #include <vector>
68 
69 
70 //== NAMESPACE ================================================================
71 
72 namespace OpenMesh { // BEGIN_NS_OPENMESH
73 namespace Subdivider { // BEGIN_NS_DECIMATER
74 namespace Uniform { // BEGIN_NS_UNIFORM
75 
76 
77 //== IMPLEMENTATION ==========================================================
78 
79 
80 template <typename MeshType, typename RealType>
82 {
83  // store mesh for later usage in subdivide(), cleanup() and all rules.
84  p_mesh_ = &_m;
85 
86  typename MeshType::VertexIter v_it(_m.vertices_begin());
87 
88  for (; v_it != _m.vertices_end(); ++v_it)
89  _m.data(*v_it).set_position(_m.point(*v_it));
90 
91  return true;
92 }
93 
94 
95 
96 template<typename MeshType, typename RealType>
98 {
99  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
100 
101  typename MeshType::VertexHandle vh;
102  typename MeshType::FaceIter f_it;
103  typename MeshType::EdgeIter e_it;
104  typename MeshType::VertexIter v_it;
105  typename MeshType::Point zero_point(0.0, 0.0, 0.0);
106  size_t n_edges, n_faces, n_vertices, j;
107 
108  // Store number of original edges
109  n_faces = mesh_.n_faces();
110  n_edges = mesh_.n_edges();
111  n_vertices = mesh_.n_vertices();
112 
113  // reserve enough memory for iterator
114  mesh_.reserve(n_vertices + n_faces, n_edges + 3 * n_faces, 3 * n_faces);
115 
116  // set new positions for vertices
117  v_it = mesh_.vertices_begin();
118  for (j = 0; j < n_vertices; ++j) {
119  mesh_.data(*v_it).set_position(mesh_.data(*v_it).position() * 3.0);
120  ++v_it;
121  }
122 
123  // Split each face
124  f_it = mesh_.faces_begin();
125  for (j = 0; j < n_faces; ++j) {
126 
127  vh = mesh_.add_vertex(zero_point);
128 
129  mesh_.data(vh).set_position(zero_point);
130 
131  mesh_.split(*f_it, vh);
132 
133  ++f_it;
134  }
135 
136  // Flip each old edge
137  std::vector<typename MeshType::EdgeHandle> edge_vector;
138  edge_vector.clear();
139 
140  e_it = mesh_.edges_begin();
141  for (j = 0; j < n_edges; ++j) {
142  if (mesh_.is_flip_ok(*e_it)) {
143  mesh_.flip(*e_it);
144  } else {
145  edge_vector.push_back(*e_it);
146  }
147  ++e_it;
148  }
149 
150  // split all boundary edges
151  while (!edge_vector.empty()) {
152  vh = mesh_.add_vertex(zero_point);
153  mesh_.data(vh).set_position(zero_point);
154  mesh_.split(edge_vector.back(), vh);
155  edge_vector.pop_back();
156  }
157 }
158 
159 
160 template<typename MeshType, typename RealType>
162 {
163  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
164 
165  typename MeshType::VertexHandle vh;
166  typename MeshType::FaceIter f_it;
167  typename MeshType::EdgeIter e_it;
168  typename MeshType::VertexIter v_it;
169  typename MeshType::Point zero_point(0.0, 0.0, 0.0);
170  size_t n_edges, n_faces, n_vertices, j;
171 
172  // Store number of original edges
173  n_faces = mesh_.n_faces();
174  n_edges = mesh_.n_edges();
175  n_vertices = mesh_.n_vertices();
176 
177  // reserve memory ahead for the succeeding operations
178  mesh_.reserve(n_vertices + n_edges, 2 * n_edges + 3 * n_faces, 4 * n_faces);
179 
180  // set new positions for vertices
181  v_it = mesh_.vertices_begin();
182  for (j = 0; j < n_vertices; ++j) {
183  mesh_.data(*v_it).set_position(mesh_.data(*v_it).position() * 4.0);
184  ++v_it;
185  }
186 
187  // Split each edge
188  e_it = mesh_.edges_begin();
189  for (j = 0; j < n_edges; ++j) {
190 
191  vh = split_edge(mesh_.halfedge_handle(*e_it, 0));
192  mesh_.data(vh).set_position(zero_point);
193 
194  ++e_it;
195  }
196 
197  // Corner Cutting of Each Face
198  f_it = mesh_.faces_begin();
199  for (j = 0; j < n_faces; ++j) {
200  typename MeshType::HalfedgeHandle heh1(mesh_.halfedge_handle(*f_it));
201  typename MeshType::HalfedgeHandle heh2(mesh_.next_halfedge_handle(mesh_.next_halfedge_handle(heh1)));
202  typename MeshType::HalfedgeHandle heh3(mesh_.next_halfedge_handle(mesh_.next_halfedge_handle(heh2)));
203 
204  // Cutting off every corner of the 6_gon
205 
206  corner_cutting(heh1);
207  corner_cutting(heh2);
208  corner_cutting(heh3);
209 
210  ++f_it;
211  }
212 }
213 
214 
215 template<typename MeshType, typename RealType>
217 {
218  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
219 
220  typename MeshType::VertexHandle vh;
221  typename MeshType::FaceIter f_it;
222  typename MeshType::EdgeIter e_it;
223  typename MeshType::VertexIter v_it;
224  typename MeshType::VertexFaceIter vf_it;
225  typename MeshType::FaceFaceIter ff_it;
226  typename MeshType::Point cog;
227  const typename MeshType::Point zero_point(0.0, 0.0, 0.0);
228  size_t n_edges, n_faces, n_vertices, j, valence;
229 
230  // Store number of original edges
231  n_faces = mesh_.n_faces();
232  n_edges = mesh_.n_edges();
233  n_vertices = mesh_.n_vertices();
234 
235  // reserve enough space for iterator
236  mesh_.reserve(n_vertices + n_faces, n_edges + 3 * n_faces, 3 * n_faces);
237 
238  // set new positions for vertices
239  v_it = mesh_.vertices_begin();
240  for (j = 0; j < n_vertices; ++j) {
241  valence = 0;
242  cog = zero_point;
243  for (vf_it = mesh_.vf_iter(*v_it); vf_it; ++vf_it) {
244  ++valence;
245  cog += vf_it->position();
246  }
247  cog /= valence;
248 
249  v_it->set_position(cog);
250  ++v_it;
251  }
252 
253  // Split each face, insert new vertex and calculate position
254  f_it = mesh_.faces_begin();
255  for (j = 0; j < n_faces; ++j) {
256 
257  vh = mesh_.add_vertex();
258 
259  valence = 0;
260  cog = zero_point;
261  for (ff_it = mesh_.ff_iter(*f_it); ff_it; ++ff_it) {
262  ++valence;
263  cog += ff_it->position();
264  }
265  cog /= valence;
266 
267  mesh_.split(*f_it, vh);
268 
269  for (vf_it = mesh_.vf_iter(vh); vf_it; ++vf_it) {
270  vf_it->set_position(f_it->position());
271  }
272 
273  mesh_.deref(vh).set_position(cog);
274 
275  mesh_.set_point(vh, cog);
276 
277  ++f_it;
278  }
279 
280  // Flip each old edge
281  e_it = mesh_.edges_begin();
282  for (j = 0; j < n_edges; ++j) {
283  if (mesh_.is_flip_ok(*e_it))
284  mesh_.flip(*e_it);
285  ++e_it;
286  }
287 }
288 
289 
290 
291 template<typename MeshType, typename RealType>
293 {
294  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
295 
296  typename MeshType::Point cog,zero_point(0.0, 0.0, 0.0);
297  typename MeshType::FaceVertexIter fv_it;
298  typename MeshType::FaceIter f_it;
299 
300  for (f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it) {
301 
302  unsigned int valence = 0;
303  cog = zero_point;
304 
305  for (fv_it = mesh_.fv_iter(*f_it); fv_it.is_valid(); ++fv_it) {
306  cog += mesh_.data(*fv_it).position();
307  ++valence;
308  }
309  cog /= valence;
310  mesh_.data(*f_it).set_position(cog);
311  }
312 }
313 
314 
315 template<typename MeshType, typename RealType>
317 {
318  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
319 
320  unsigned int valence[3], i;
321  typename MeshType::Point cog,zero_point(0.0, 0.0, 0.0);
322  typename MeshType::Scalar alpha;
323  typename MeshType::FaceIter f_it;
324  typename MeshType::HalfedgeHandle heh;
325  typename MeshType::VertexHandle vh[3];
326  typename MeshType::VertexOHalfedgeIter voh_it;
327  typename MeshType::FaceVertexIter fv_it;
328 
329  for (f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it) {
330 
331  heh = mesh_.halfedge_handle(*f_it);
332  for (i = 0; i <= 2; ++i) {
333 
334  valence[i] = 0;
335  vh[i] = mesh_.to_vertex_handle(heh);
336 
337  for (voh_it = mesh_.voh_iter(vh[i]); voh_it; ++voh_it) {
338  ++valence[i];
339  }
340 
341  heh = mesh_.next_halfedge_handle(heh);
342  }
343 
344  if (valence[0] <= valence[1])
345  if (valence[0] <= valence[2])
346  i = 0;
347  else
348  i = 2;
349  else
350  if (valence[1] <= valence[2])
351  i = 1;
352  else
353  i = 2;
354 
355  alpha = _coeff(valence[i]);
356 
357  cog = zero_point;
358 
359  for (fv_it = mesh_.fv_iter(*f_it); fv_it.is_valid(); ++fv_it) {
360  if (*fv_it == vh[i]) {
361  cog += fv_it->position() * alpha;
362  } else {
363  cog += fv_it->position() * (1.0 - alpha) / 2.0;
364  }
365  }
366 
367  f_it->set_position(cog);
368  }
369 }
370 
371 
372 template<typename MeshType, typename RealType>
374 {
375  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
376 
377  unsigned int valence[3], i;
378  typename MeshType::Point cog,
379  zero_point(0.0, 0.0, 0.0);
380  typename MeshType::FaceIter f_it;
381  typename MeshType::HalfedgeHandle heh;
382  typename MeshType::VertexHandle vh[3];
383  typename MeshType::VertexOHalfedgeIter voh_it;
384  typename MeshType::FaceVertexIter fv_it;
385 
386  for (f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it) {
387 
388  heh = mesh_.halfedge_handle(*f_it);
389  for (i = 0; i <= 2; ++i) {
390 
391  valence[i] = 0;
392  vh[i] = mesh_.to_vertex_handle(heh);
393 
394  for (voh_it = mesh_.voh_iter(vh[i]); voh_it; ++voh_it) {
395  ++valence[i];
396  }
397 
398  heh = mesh_.next_halfedge_handle(heh);
399  }
400 
401  if (valence[0] <= valence[1])
402  if (valence[0] <= valence[2])
403  i = 0;
404  else
405  i = 2;
406  else
407  if (valence[1] <= valence[2])
408  i = 1;
409  else
410  i = 2;
411 
412  cog = zero_point;
413 
414  for (fv_it = mesh_.fv_iter(*f_it); fv_it.is_valid(); ++fv_it) {
415  if (*fv_it == vh[i]) {
416  cog += fv_it->position() * _alpha;
417  } else {
418  cog += fv_it->position() * (1.0 - _alpha) / 2.0;
419  }
420  }
421 
422  f_it->set_position(cog);
423  }
424 }
425 
426 
427 template<typename MeshType, typename RealType>
429 {
430  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
431 
432  typename MeshType::Point cog,
433  zero_point(0.0, 0.0, 0.0);
434  typename MeshType::FaceFaceIter ff_it;
435  typename MeshType::FaceIter f_it;
436  std::vector<typename MeshType::Point> point_vector;
437 
438  point_vector.clear();
439 
440  for (f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it)
441  {
442  unsigned int valence = 0;
443  cog = zero_point;
444 
445  for (ff_it = mesh_.ff_iter(*f_it); ff_it.is_valid(); ++ff_it)
446  {
447  cog += mesh_.data(*ff_it).position();
448  ++valence;
449  }
450  cog /= valence;
451  point_vector.push_back(cog);
452  }
453 
454  for (f_it = mesh_.faces_end(); f_it != mesh_.faces_begin(); )
455  {
456  --f_it;
457  mesh_.data(*f_it).set_position(point_vector.back());
458  point_vector.pop_back();
459  }
460 }
461 
462 
463 template<typename MeshType, typename RealType>
465 {
466  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
467 
468  typename MeshType::Point cog,
469  zero_point(0.0, 0.0, 0.0);
470  typename MeshType::FaceFaceIter ff_it;
471  typename MeshType::FaceIter f_it;
472  typename MeshType::Scalar c;
473  std::vector<typename MeshType::Point> point_vector;
474 
475  for (f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it) {
476 
477  unsigned int valence = 0;
478  cog = zero_point;
479 
480  for (ff_it = mesh_.ff_iter(*f_it); ff_it; ++ff_it) {
481  cog += ff_it->position();
482  ++valence;
483  }
484  cog /= valence;
485 
486  c = _coeff(valence);
487 
488  cog = cog * (1.0 - c) + f_it->position() * c;
489 
490  point_vector.push_back(cog);
491 
492  }
493  for (f_it = mesh_.faces_end(); f_it != mesh_.faces_begin(); ) {
494 
495  --f_it;
496  f_it->set_position(point_vector.back());
497  point_vector.pop_back();
498 
499  }
500 }
501 
502 
503 template<typename MeshType, typename RealType>
505 {
506  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
507 
508  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
509  typename MeshType::FaceFaceIter ff_it;
510  typename MeshType::FaceIter f_it;
511  std::vector<typename MeshType::Point> point_vector;
512 
513  for (f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it) {
514 
515  unsigned int valence = 0;
516  cog = zero_point;
517 
518  for (ff_it = mesh_.ff_iter(*f_it); ff_it; ++ff_it) {
519  cog += ff_it->position();
520  ++valence;
521  }
522  cog /= valence;
523 
524  cog = cog * (1.0 - _c) + f_it->position() * _c;
525 
526  point_vector.push_back(cog);
527 
528  }
529  for (f_it = mesh_.faces_end(); f_it != mesh_.faces_begin(); ) {
530 
531  --f_it;
532  f_it->set_position(point_vector.back());
533  point_vector.pop_back();
534  }
535 }
536 
537 
538 template<typename MeshType, typename RealType>
540 {
541  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
542 
543  typename MeshType::Point cog,
544  zero_point(0.0, 0.0, 0.0);
545  typename MeshType::VertexFaceIter vf_it;
546  typename MeshType::VertexIter v_it;
547 
548  for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
549 
550  unsigned int valence = 0;
551  cog = zero_point;
552 
553  for (vf_it = mesh_.vf_iter(*v_it); vf_it; ++vf_it) {
554  cog += vf_it->position();
555  ++valence;
556  }
557  cog /= valence;
558  v_it->set_position(cog);
559  }
560 }
561 
562 
563 template<typename MeshType, typename RealType>
565 {
566  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
567 
568 
569  typename MeshType::Point cog,
570  zero_point(0.0, 0.0, 0.0);
571  scalar_t c;
572  typename MeshType::VertexOHalfedgeIter voh_it;
573  typename MeshType::VertexIter v_it;
574 
575  for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
576 
577  unsigned int valence = 0;
578  cog = zero_point;
579 
580  for (voh_it = mesh_.voh_iter(*v_it); voh_it.is_valid(); ++voh_it) {
581  ++valence;
582  }
583 
584  c = _coeff(valence);
585 
586  for (voh_it = mesh_.voh_iter(*v_it); voh_it.is_valid(); ++voh_it) {
587 
588  if (mesh_.face_handle(*voh_it).is_valid()) {
589 
590  if (mesh_.face_handle(mesh_.opposite_halfedge_handle(mesh_.next_halfedge_handle(*voh_it))).is_valid()) {
591  cog += mesh_.data(mesh_.face_handle(*voh_it)).position() * c;
592  cog += mesh_.data(mesh_.face_handle(mesh_.opposite_halfedge_handle(mesh_.next_halfedge_handle(*voh_it)))).position() * (1.0 - c);
593  } else {
594  cog += mesh_.data(mesh_.face_handle(*voh_it)).position();
595  }
596  } else {
597  --valence;
598  }
599  }
600 
601  if (valence > 0)
602  cog /= valence;
603 
604  mesh_.data(*v_it).set_position(cog);
605  }
606 }
607 
608 
609 template<typename MeshType, typename RealType>
611 {
612  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
613 
614  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
615  typename MeshType::VertexOHalfedgeIter voh_it;
616  typename MeshType::VertexIter v_it;
617 
618  for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
619 
620  unsigned int valence = 0;
621  cog = zero_point;
622 
623  for (voh_it = mesh_.voh_iter(*v_it); voh_it; ++voh_it) {
624  ++valence;
625  }
626 
627  for (voh_it = mesh_.voh_iter(*v_it); voh_it; ++voh_it) {
628 
629  if (mesh_.face_handle(*voh_it).is_valid()) {
630 
631  if (mesh_.face_handle(mesh_.opposite_halfedge_handle(mesh_.next_halfedge_handle(*voh_it))).is_valid()) {
632  cog += mesh_.deref(mesh_.face_handle(*voh_it)).position() * _c;
633  cog += mesh_.deref(mesh_.face_handle(mesh_.opposite_halfedge_handle(mesh_.next_halfedge_handle(*voh_it)))).position() * (1.0 - _c);
634  } else {
635  cog += mesh_.deref(mesh_.face_handle(*voh_it)).position();
636  }
637  } else {
638  --valence;
639  }
640  }
641 
642  if (valence > 0)
643  cog /= valence;
644 
645  v_it->set_position(cog);
646  }
647 }
648 
649 
650 template<typename MeshType, typename RealType>
652 {
653  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
654 
655  typename MeshType::EdgeIter e_it;
656  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
657  typename MeshType::HalfedgeHandle heh1, heh2;
658 
659  for (e_it = mesh_.edges_begin(); e_it != mesh_.edges_end(); ++e_it) {
660 
661  cog = zero_point;
662  unsigned int valence = 2;
663 
664  heh1 = mesh_.halfedge_handle(*e_it, 0);
665  heh2 = mesh_.opposite_halfedge_handle(heh1);
666  cog += mesh_.data(mesh_.to_vertex_handle(heh1)).position();
667  cog += mesh_.data(mesh_.to_vertex_handle(heh2)).position();
668 
669  if (!mesh_.is_boundary(heh1)) {
670  cog += mesh_.data(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(heh1))).position();
671  ++valence;
672  }
673 
674  if (!mesh_.is_boundary(heh2)) {
675  cog += mesh_.data(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(heh2))).position();
676  ++valence;
677  }
678 
679  cog /= valence;
680 
681  mesh_.data(*e_it).set_position(cog);
682  }
683 }
684 
685 
686 template<typename MeshType, typename RealType>
688 {
689  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
690 
691  typename MeshType::EdgeIter e_it;
692  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
693  typename MeshType::HalfedgeHandle heh;
694 
695  for (e_it = mesh_.edges_begin(); e_it != mesh_.edges_end(); ++e_it) {
696 
697  cog = zero_point;
698 
699  for (int i = 0; i <= 1; ++i) {
700 
701  heh = mesh_.halfedge_handle(*e_it, i);
702  if (!mesh_.is_boundary(heh))
703  {
704  cog += mesh_.point(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(heh))) * (0.5 - _c);
705  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position() * _c;
706  }
707  else
708  {
709  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position();
710  }
711  }
712 
713  mesh_.data(*e_it).set_position(cog);
714  }
715 }
716 
717 
718 template<typename MeshType, typename RealType>
720 {
721  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
722 
723  typename MeshType::EdgeIter e_it;
724  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
725  typename MeshType::HalfedgeHandle heh;
726  typename MeshType::VertexOHalfedgeIter voh_it;
727  unsigned int valence[2], i;
728 
729  for (e_it = mesh_.edges_begin(); e_it != mesh_.edges_end(); ++e_it) {
730 
731  cog = zero_point;
732 
733  for (i = 0; i <= 1; ++i)
734  {
735  heh = mesh_.halfedge_handle(*e_it, i);
736  valence[i] = 0;
737 
738  // look for lowest valence vertex
739  for (voh_it = mesh_.voh_iter(mesh_.to_vertex_handle(heh)); voh_it; ++voh_it)
740  {
741  ++valence[i];
742  }
743  }
744 
745  if (valence[0] < valence[1])
746  i = 0;
747  else
748  i = 1;
749 
750  heh = mesh_.halfedge_handle(*e_it, i);
751 
752  if (!mesh_.is_boundary(heh)) {
753  cog += mesh_.point(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(heh))) * (_gamma);
754  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position() * (1.0 - 3.0 * _gamma);
755  } else {
756  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position() * (1.0 - 2.0 * _gamma);
757  }
758 
759 
760  heh = mesh_.halfedge_handle(*e_it, 1-i);
761 
762  if (!mesh_.is_boundary(heh))
763  {
764  cog += mesh_.point(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(heh))) * (_gamma);
765  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position() * _gamma;
766  }
767  else
768  {
769  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position() * 2.0 * _gamma;
770  }
771 
772  mesh_.data(*e_it).set_position(cog);
773  }
774 }
775 
776 
777 template<typename MeshType, typename RealType>
779 {
780  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
781 
782  typename MeshType::EdgeIter e_it;
783  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
784  typename MeshType::HalfedgeHandle heh;
785  typename MeshType::VertexOHalfedgeIter voh_it;
786  unsigned int valence[2], i;
787  scalar_t gamma;
788 
789  for (e_it = mesh_.edges_begin(); e_it != mesh_.edges_end(); ++e_it) {
790 
791  cog = zero_point;
792 
793  for (i = 0; i <= 1; ++i) {
794 
795  heh = mesh_.halfedge_handle(*e_it, i);
796  valence[i] = 0;
797 
798  // look for lowest valence vertex
799  for (voh_it = mesh_.voh_iter(mesh_.to_vertex_handle(heh)); voh_it; ++voh_it)
800  {
801  ++valence[i];
802  }
803  }
804 
805  if (valence[0] < valence[1])
806  i = 0;
807  else
808  i = 1;
809 
810  gamma = _coeff(valence[i]);
811 
812  heh = mesh_.halfedge_handle(*e_it, i);
813 
814  if (!mesh_.is_boundary(heh))
815  {
816  cog += mesh_.point(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(heh))) * (gamma);
817  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position() * (1.0 - 3.0 * gamma);
818  }
819  else
820  {
821  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position() * (1.0 - 2.0 * gamma);
822  }
823 
824 
825  heh = mesh_.halfedge_handle(*e_it, 1-i);
826 
827  if (!mesh_.is_boundary(heh)) {
828  cog += mesh_.point(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(heh))) * (gamma);
829  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position() * gamma;
830  } else {
831  cog += mesh_.data(mesh_.to_vertex_handle(heh)).position() * 2.0 * gamma;
832  }
833 
834  mesh_.data(*e_it).set_position(cog);
835  }
836 }
837 
838 
839 template<typename MeshType, typename RealType>
841 {
842  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
843 
844  typename MeshType::VertexIter v_it;
845  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
846  typename MeshType::VertexEdgeIter ve_it;
847 
848  for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it)
849  {
850  unsigned int valence = 0;
851  cog = zero_point;
852 
853  for (ve_it = mesh_.ve_iter(*v_it); ve_it; ++ve_it) {
854  cog += mesh_.data(ve_it).position();
855  ++valence;
856  }
857 
858  cog /= valence;
859 
860  mesh_.data(*v_it).set_position(cog);
861  }
862 }
863 
864 
865 template<typename MeshType, typename RealType>
867 {
868  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
869 
870  typename MeshType::VertexIter v_it;
871  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
872  typename MeshType::VertexOHalfedgeIter voh_it;
873  scalar_t c;
874 
875  for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it)
876  {
877  unsigned int valence = 0;
878  cog = zero_point;
879 
880  for (voh_it = mesh_.voh_iter(*v_it); voh_it.is_valid(); ++voh_it)
881  {
882  ++valence;
883  }
884 
885  c = _coeff(valence);
886 
887  for (voh_it = mesh_.voh_iter(*v_it); voh_it.is_valid(); ++voh_it) {
888  cog += mesh_.data(mesh_.edge_handle(*voh_it)).position() * c;
889  cog += mesh_.data(mesh_.edge_handle(mesh_.next_halfedge_handle(*voh_it))).position() * (1.0 - c);
890  }
891 
892  cog /= valence;
893 
894  mesh_.data(*v_it).set_position(cog);
895  }
896 }
897 
898 
899 template<typename MeshType, typename RealType>
901 {
902  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
903  typename MeshType::VertexIter v_it;
904  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
905  typename MeshType::VertexOHalfedgeIter voh_it;
906 
907  for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
908  unsigned int valence = 0;
909  cog = zero_point;
910 
911  for (voh_it = mesh_.voh_iter(*v_it); voh_it; ++voh_it) {
912  ++valence;
913  }
914 
915  for (voh_it = mesh_.voh_iter(*v_it); voh_it; ++voh_it) {
916  cog += mesh_.data(mesh_.edge_handle(*voh_it)).position() * _c;
917  cog += mesh_.data(mesh_.edge_handle(mesh_.next_halfedge_handle(*voh_it))).position() * (1.0 - _c);
918  }
919 
920  cog /= valence;
921 
922  mesh_.data(*v_it).set_position(cog);
923  }
924 }
925 
926 
927 template<typename MeshType, typename RealType>
929 {
930  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
931 
932  typename MeshType::FaceIter f_it;
933  typename MeshType::FaceEdgeIter fe_it;
934  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
935 
936  for (f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it) {
937  unsigned int valence = 0;
938  cog = zero_point;
939 
940  for (fe_it = mesh_.fe_iter(*f_it); fe_it; ++fe_it) {
941  ++valence;
942  cog += mesh_.data(fe_it).position();
943  }
944 
945  cog /= valence;
946  mesh_.data(*f_it).set_position(cog);
947  }
948 }
949 
950 
951 template<typename MeshType, typename RealType>
953 {
954  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
955 
956  typename MeshType::EdgeIter e_it;
957  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
958 
959  for (e_it = mesh_.edges_begin(); e_it != mesh_.edges_end(); ++e_it) {
960  unsigned int valence = 0;
961  cog = zero_point;
962 
963  if (mesh_.face_handle(mesh_.halfedge_handle(*e_it, 0)).is_valid()) {
964  cog += mesh_.data(mesh_.face_handle(mesh_.halfedge_handle(*e_it, 0))).position();
965  ++valence;
966  }
967 
968  if (mesh_.face_handle(mesh_.halfedge_handle(*e_it, 1)).is_valid()) {
969  cog += mesh_.data(mesh_.face_handle(mesh_.halfedge_handle(*e_it, 1))).position();
970  ++valence;
971  }
972 
973  cog /= valence;
974  mesh_.data(*e_it).set_position(cog);
975  }
976 }
977 
978 
979 template<typename MeshType, typename RealType>
981 {
982  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
983 
984  typename MeshType::EdgeIter e_it;
985  typename MeshType::Point cog;
986 
987  for (e_it = mesh_.edges_begin(); e_it != mesh_.edges_end(); ++e_it)
988  {
989  cog = mesh_.data(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0))).position();
990  cog += mesh_.data(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1))).position();
991  cog /= 2.0;
992  mesh_.data(*e_it).set_position(cog);
993  }
994 }
995 
996 
997 template<typename MeshType, typename RealType>
999 {
1000  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
1001 
1002  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
1003  typename MeshType::VertexVertexIter vv_it;
1004  typename MeshType::VertexIter v_it;
1005  std::vector<typename MeshType::Point> point_vector;
1006 
1007  point_vector.clear();
1008 
1009  for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
1010 
1011  unsigned int valence = 0;
1012  cog = zero_point;
1013 
1014  for (vv_it = mesh_.vv_iter(*v_it); vv_it; ++vv_it) {
1015  cog += vv_it->position();
1016  ++valence;
1017  }
1018  cog /= valence;
1019  point_vector.push_back(cog);
1020  }
1021 
1022  for (v_it = mesh_.vertices_end(); v_it != mesh_.vertices_begin(); )
1023  {
1024  --v_it;
1025  mesh_.data(*v_it).set_position(point_vector.back());
1026  point_vector.pop_back();
1027  }
1028 }
1029 
1030 
1031 template<typename MeshType, typename RealType>
1033 {
1034  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
1035 
1036  typename MeshType::Point cog,
1037  zero_point(0.0, 0.0, 0.0);
1038  typename MeshType::VertexVertexIter vv_it;
1039  typename MeshType::VertexIter v_it;
1040  scalar_t c;
1041  std::vector<typename MeshType::Point> point_vector;
1042 
1043  for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it)
1044  {
1045  unsigned int valence = 0;
1046  cog = zero_point;
1047 
1048  for (vv_it = mesh_.vv_iter(*v_it); vv_it; ++vv_it)
1049  {
1050  cog += vv_it->position();
1051  ++valence;
1052  }
1053  cog /= valence;
1054  c = _coeff(valence);
1055  cog = cog * (1 - c) + mesh_.data(*v_it).position() * c;
1056  point_vector.push_back(cog);
1057  }
1058  for (v_it = mesh_.vertices_end(); v_it != mesh_.vertices_begin(); )
1059  {
1060  --v_it;
1061  mesh_.data(*v_it).set_position(point_vector.back());
1062  point_vector.pop_back();
1063  }
1064 }
1065 
1066 
1067 template<typename MeshType, typename RealType>
1069 {
1070  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
1071 
1072  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
1073  typename MeshType::VertexVertexIter vv_it;
1074  typename MeshType::VertexIter v_it;
1075  std::vector<typename MeshType::Point> point_vector;
1076 
1077  for (v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
1078 
1079  unsigned int valence = 0;
1080  cog = zero_point;
1081 
1082  for (vv_it = mesh_.vv_iter(*v_it); vv_it; ++vv_it) {
1083  cog += mesh_.data(vv_it).position();
1084  ++valence;
1085  }
1086  cog /= valence;
1087 
1088  cog = cog * (1.0 - _c) + v_it->position() * _c;
1089 
1090  point_vector.push_back(cog);
1091 
1092  }
1093  for (v_it = mesh_.vertices_end(); v_it != mesh_.vertices_begin(); ) {
1094 
1095  --v_it;
1096  mesh_.data(*v_it).set_position(point_vector.back());
1097  point_vector.pop_back();
1098 
1099  }
1100 }
1101 
1102 
1103 template<typename MeshType, typename RealType>
1105 {
1106  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
1107 
1108  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
1109  typename MeshType::EdgeIter e_it;
1110  typename MeshType::HalfedgeHandle heh;
1111  std::vector<typename MeshType::Point> point_vector;
1112 
1113  point_vector.clear();
1114 
1115  for (e_it = mesh_.edges_begin(); e_it != mesh_.edges_end(); ++e_it) {
1116 
1117  unsigned int valence = 0;
1118  cog = zero_point;
1119 
1120  for (int i = 0; i <= 1; ++i) {
1121  heh = mesh_.halfedge_handle(*e_it, i);
1122  if (mesh_.face_handle(heh).is_valid())
1123  {
1124  cog += mesh_.data(mesh_.edge_handle(mesh_.next_halfedge_handle(heh))).position();
1125  cog += mesh_.data(mesh_.edge_handle(mesh_.next_halfedge_handle(mesh_.next_halfedge_handle(heh)))).position();
1126  ++valence;
1127  ++valence;
1128  }
1129  }
1130 
1131  cog /= valence;
1132  point_vector.push_back(cog);
1133  }
1134 
1135  for (e_it = mesh_.edges_end(); e_it != mesh_.edges_begin(); )
1136  {
1137  --e_it;
1138  mesh_.data(*e_it).set_position(point_vector.back());
1139  point_vector.pop_back();
1140  }
1141 }
1142 
1143 
1144 template<typename MeshType, typename RealType>
1146 {
1147  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
1148 
1149  typename MeshType::Point cog, zero_point(0.0, 0.0, 0.0);
1150  typename MeshType::EdgeIter e_it;
1151  typename MeshType::HalfedgeHandle heh;
1152  std::vector<typename MeshType::Point> point_vector;
1153 
1154  point_vector.clear();
1155 
1156  for (e_it = mesh_.edges_begin(); e_it != mesh_.edges_end(); ++e_it)
1157  {
1158  unsigned int valence = 0;
1159  cog = zero_point;
1160 
1161  for (int i = 0; i <= 1; ++i) {
1162  heh = mesh_.halfedge_handle(*e_it, i);
1163  if (mesh_.face_handle(heh).is_valid())
1164  {
1165  cog += mesh_.data(mesh_.edge_handle(mesh_.next_halfedge_handle(heh))).position() * (1.0 - _c);
1166  cog += mesh_.data(mesh_.edge_handle(mesh_.next_halfedge_handle(mesh_.next_halfedge_handle(heh)))).position() * (1.0 - _c);
1167  ++valence;
1168  ++valence;
1169  }
1170  }
1171 
1172  cog /= valence;
1173  cog += mesh_.data(e_it).position() * _c;
1174  point_vector.push_back(cog);
1175  }
1176 
1177  for (e_it = mesh_.edges_end(); e_it != mesh_.edges_begin(); ) {
1178 
1179  --e_it;
1180  mesh_.data(*e_it).set_position(point_vector.back());
1181  point_vector.pop_back();
1182  }
1183 }
1184 
1185 
1187 template<typename MeshType, typename RealType>
1189 {
1190  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
1191 
1192  // Define Halfedge Handles
1193  typename MeshType::HalfedgeHandle heh5(_heh);
1194  typename MeshType::HalfedgeHandle heh6(mesh_.next_halfedge_handle(_heh));
1195 
1196  // Cycle around the polygon to find correct Halfedge
1197  for (; mesh_.next_halfedge_handle(mesh_.next_halfedge_handle(heh5)) != _heh;
1198  heh5 = mesh_.next_halfedge_handle(heh5)) {};
1199 
1200  typename MeshType::HalfedgeHandle heh2(mesh_.next_halfedge_handle(heh5));
1201  typename MeshType::HalfedgeHandle
1202  heh3(mesh_.new_edge(mesh_.to_vertex_handle(_heh),
1203  mesh_.to_vertex_handle(heh5)));
1204  typename MeshType::HalfedgeHandle heh4(mesh_.opposite_halfedge_handle(heh3));
1205 
1206  // Old and new Face
1207  typename MeshType::FaceHandle fh_old(mesh_.face_handle(heh6));
1208  typename MeshType::FaceHandle fh_new(mesh_.new_face());
1209 
1210  // Init new face
1211  mesh_.data(fh_new).set_position(mesh_.data(fh_old).position());
1212 
1213  // Re-Set Handles around old Face
1214  mesh_.set_next_halfedge_handle(heh4, heh6);
1215  mesh_.set_next_halfedge_handle(heh5, heh4);
1216 
1217  mesh_.set_face_handle(heh4, fh_old);
1218  mesh_.set_face_handle(heh5, fh_old);
1219  mesh_.set_face_handle(heh6, fh_old);
1220  mesh_.set_halfedge_handle(fh_old, heh4);
1221 
1222  // Re-Set Handles around new Face
1223  mesh_.set_next_halfedge_handle(_heh, heh3);
1224  mesh_.set_next_halfedge_handle(heh3, heh2);
1225 
1226  mesh_.set_face_handle(_heh, fh_new);
1227  mesh_.set_face_handle(heh2, fh_new);
1228  mesh_.set_face_handle(heh3, fh_new);
1229 
1230  mesh_.set_halfedge_handle(fh_new, _heh);
1231 }
1232 
1233 
1235 template<typename MeshType, typename RealType>
1236 typename MeshType::VertexHandle
1238 {
1239  assert(p_mesh_); MeshType& mesh_ = *p_mesh_;
1240 
1241  HalfedgeHandle heh1;
1242  HalfedgeHandle heh2;
1243  HalfedgeHandle heh3;
1244  HalfedgeHandle temp_heh;
1245 
1246  VertexHandle
1247  vh,
1248  vh1(mesh_.to_vertex_handle(_heh)),
1249  vh2(mesh_.from_vertex_handle(_heh));
1250 
1251  // Calculate and Insert Midpoint of Edge
1252  vh = mesh_.add_vertex((mesh_.point(vh2) + mesh_.point(vh1)) / 2.0);
1253  // Re-Set Handles
1254  heh2 = mesh_.opposite_halfedge_handle(_heh);
1255 
1256  if (!mesh_.is_boundary(mesh_.edge_handle(_heh))) {
1257 
1258  for (temp_heh = mesh_.next_halfedge_handle(heh2);
1259  mesh_.next_halfedge_handle(temp_heh) != heh2;
1260  temp_heh = mesh_.next_halfedge_handle(temp_heh) ) {}
1261  } else {
1262  for (temp_heh = _heh;
1263  mesh_.next_halfedge_handle(temp_heh) != heh2;
1264  temp_heh = mesh_.opposite_halfedge_handle(mesh_.next_halfedge_handle(temp_heh))) {}
1265  }
1266 
1267  heh1 = mesh_.new_edge(vh, vh1);
1268  heh3 = mesh_.opposite_halfedge_handle(heh1);
1269  mesh_.set_vertex_handle(_heh, vh);
1270  mesh_.set_next_halfedge_handle(temp_heh, heh3);
1271  mesh_.set_next_halfedge_handle(heh1, mesh_.next_halfedge_handle(_heh));
1272  mesh_.set_next_halfedge_handle(_heh, heh1);
1273  mesh_.set_next_halfedge_handle(heh3, heh2);
1274  if (mesh_.face_handle(heh2).is_valid()) {
1275  mesh_.set_face_handle(heh3, mesh_.face_handle(heh2));
1276  mesh_.set_halfedge_handle(mesh_.face_handle(heh3), heh3);
1277  }
1278  mesh_.set_face_handle(heh1, mesh_.face_handle(_heh));
1279  mesh_.set_halfedge_handle(vh, heh1);
1280  mesh_.set_halfedge_handle(mesh_.face_handle(_heh), _heh);
1281  mesh_.set_halfedge_handle(vh1, heh3);
1282 
1283  return vh;
1284 }
1285 
1286 
1287 //=============================================================================
1288 } // END_NS_UNIFORM
1289 } // END_NS_SUBDIVIDER
1290 } // END_NS_OPENMESH
1291 //=============================================================================
1292 #endif // OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITE_CC defined
1293 //=============================================================================
1294 
void VFa(Coeff &_coeff)
Vertex to Face Averaging, weighted.
Definition: CompositeT.cc:316
void Tvv3()
Split Face, using Vertex information (1-3 split)
Definition: CompositeT.cc:97
void EVc(Coeff &_coeff)
Weighted edge to vertex averaging.
Definition: CompositeT.cc:866
void EF()
Edge to face averaging.
Definition: CompositeT.cc:928
void VdE()
Vertex to edge averaging, using diamond of edges.
Definition: CompositeT.cc:651
void FE()
Face to edge averaging.
Definition: CompositeT.cc:952
void VE()
VE Step (Vertex to Edge Averaging)
Definition: CompositeT.cc:980
void VdEc(scalar_t _c)
Weighted vertex to edge averaging, using diamond of edges.
Definition: CompositeT.cc:687
VertexHandle split_edge(HalfedgeHandle _heh)
Split Edge.
Definition: CompositeT.cc:1237
bool prepare(MeshType &_m)
Prepare mesh, e.g. add properties.
Definition: CompositeT.cc:81
void Tvv4()
Split Face, using Vertex information (1-4 split)
Definition: CompositeT.cc:161
void VVc(Coeff &_coeff)
Vertex to vertex averaging, weighted.
Definition: CompositeT.cc:1032
void EdE()
Edge to edge averaging w/ flap rule.
Definition: CompositeT.cc:1104
void VF()
Vertex to Face Averaging.
Definition: CompositeT.cc:292
Abstract base class for coefficient functions.
Definition: CompositeT.hh:162
void FF()
Face to face averaging.
Definition: CompositeT.cc:428
void FVc(Coeff &_coeff)
Weighted face to vertex Averaging with flaps.
Definition: CompositeT.cc:564
void FFc(Coeff &_coeff)
Weighted face to face averaging.
Definition: CompositeT.cc:464
void corner_cutting(HalfedgeHandle _heh)
Corner Cutting.
Definition: CompositeT.cc:1188
void Tfv()
Split Face, using Face Information.
Definition: CompositeT.cc:216
void EV()
Edge to vertex averaging.
Definition: CompositeT.cc:840
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
void EdEc(scalar_t _c)
Weighted edge to edge averaging w/ flap rule.
Definition: CompositeT.cc:1145
void FV()
Face to vertex averaging.
Definition: CompositeT.cc:539
void VV()
Vertex to vertex averaging.
Definition: CompositeT.cc:998