Developer Documentation
CompositeSqrt3T.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 
48 //=============================================================================
49 //
50 // CLASS SQRT3T
51 //
52 //=============================================================================
53 
54 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITESQRT3T_HH
55 #define OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITESQRT3T_HH
56 
57 
58 //== INCLUDES =================================================================
59 
60 #include "Composite/CompositeT.hh"
61 #include "Composite/CompositeTraits.hh"
62 
63 
64 //== NAMESPACE ================================================================
65 
66 namespace OpenMesh { // BEGIN_NS_OPENMESH
67 namespace Subdivider { // BEGIN_NS_DECIMATER
68 namespace Uniform { // BEGIN_NS_UNIFORM
69 
70 
71 //== CLASS DEFINITION =========================================================
72 
75 template <typename MeshType, typename RealType = double>
76 class CompositeSqrt3T : public CompositeT<MeshType, RealType>
77 {
78 public:
79 
81 
82 public:
83 
84  CompositeSqrt3T() : Inherited() {};
85  explicit CompositeSqrt3T(MeshType& _mesh) : Inherited(_mesh) {};
86  ~CompositeSqrt3T() {}
87 
88 public:
89 
90  const char *name() const override { return "Uniform Composite Sqrt3"; }
91 
92 protected: // inherited interface
93 
94  void apply_rules(void) override
95  {
96  Inherited::Tvv3();
97  Inherited::VF();
98  Inherited::FF();
99  Inherited::FVc(coeffs_);
100  }
101 
102 protected:
103 
104  typedef typename Inherited::Coeff Coeff;
105 
109  struct FVCoeff : public Coeff
110  {
111  FVCoeff() : Coeff() { init(50); }
112 
113  void init(size_t _max_valence)
114  {
115  weights_.resize(_max_valence);
116  std::generate(weights_.begin(),
117  weights_.end(), compute_weight() );
118  }
119 
120  double operator()(size_t _valence) override { return weights_[_valence]; }
121 
125  {
126  compute_weight() : val_(0) { }
127 
128  double operator()(void) // sqrt(3) weights for non-boundary vertices
129  {
130  return 2.0/3.0 * (cos(2.0*M_PI/val_++)+1.0);
131  }
132  size_t val_;
133  };
134 
135  std::vector<double> weights_;
136 
137  } coeffs_;
138 
139 };
140 
141 
142 //=============================================================================
143 } // END_NS_UNIFORM
144 } // END_NS_SUBDIVIDER
145 } // END_NS_OPENMESH
146 //=============================================================================
147 #endif // OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITESQRT3T_HH defined
148 //=============================================================================
Abstract base class for coefficient functions.
Definition: CompositeT.hh:157
const char * name() const override
Return name of subdivision algorithm.