Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CompositeLoopT.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 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
53 //=============================================================================
54 //
55 // CLASS LoopT
56 //
57 //=============================================================================
58 
59 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITELOOPT_HH
60 #define OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITELOOPT_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 #include "Composite/CompositeT.hh"
66 #include "Composite/CompositeTraits.hh"
67 
68 
69 //== NAMESPACE ================================================================
70 
71 namespace OpenMesh { // BEGIN_NS_OPENMESH
72 namespace Subdivider { // BEGIN_NS_DECIMATER
73 namespace Uniform { // BEGIN_NS_DECIMATER
74 
75 
76 //== CLASS DEFINITION =========================================================
77 
80 template <class MeshType, class RealType=float>
81 class CompositeLoopT : public CompositeT<MeshType, RealType>
82 {
83 public:
84 
86 
87 public:
88 
89  CompositeLoopT() : Inherited() {};
90  CompositeLoopT(MeshType& _mesh) : Inherited(_mesh) {};
91  ~CompositeLoopT() {}
92 
93 public:
94 
95  const char *name() const { return "Uniform Composite Loop"; }
96 
97 protected: // inherited interface
98 
99  void apply_rules(void)
100  {
101  Inherited::Tvv4();
102  Inherited::VdE();
103  Inherited::EVc(coeffs_);
104  Inherited::VdE();
105  Inherited::EVc(coeffs_);
106  }
107 
108 protected:
109 
110  typedef typename Inherited::Coeff Coeff;
111 
112 
116  struct EVCoeff : public Coeff
117  {
118  EVCoeff() : Coeff() { init(50); }
119 
120  void init(size_t _max_valence)
121  {
122  weights_.resize(_max_valence);
123  std::generate(weights_.begin(),
124  weights_.end(), compute_weight() );
125  }
126 
127  double operator()(size_t _valence) { return weights_[_valence]; }
128 
131  {
132  compute_weight() : val_(0) { }
133 
134  double operator()(void) // Loop weights for non-boundary vertices
135  {
136  // 1 3 2 * pi
137  // - * ( --- + cos ( ------- ) )� - 1.0
138  // 2 2 valence
139  double f1 = 1.5 + cos(2.0*M_PI/val_++);
140  return 0.5 * f1 * f1 - 1.0;
141  }
142  size_t val_;
143 
144  };
145 
146  std::vector<double> weights_;
147  } coeffs_;
148 
149 };
150 
151 //=============================================================================
152 } // END_NS_UNIFORM
153 } // END_NS_SUBDIVIDER
154 } // END_NS_OPENMESH
155 //=============================================================================
156 #endif // OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITELOOPT_HH defined
157 //=============================================================================
const char * name() const
Return name of subdivision algorithm.