OpenWalnut  1.5.0dev
WButterflyCalculator.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 // Additional copyright information:
26 // This class partially relies on the Butterfly Subdivision algorithm.
27 // that dates from Denis Zorin, Peter Schroeder, Wim Sweldens, Nira Dyn, David
28 // Levin and John A. Gregory. The original algorithm is depicted in:
29 // http://wwwmath.tau.ac.il/~niradyn/papers/butterfly.pdf
30 // http://mrl.nyu.edu/~dzorin/papers/zorin1996ism.pdf
31 // This work was required especially in the methods calcNewVertex and
32 // getInterpolatedValue.
33 
34 #ifndef WBUTTERFLYCALCULATOR_H_
35 #define WBUTTERFLYCALCULATOR_H_
36 
37 #include <memory>
38 #include <string>
39 #include <vector>
40 
41 #include "WSubdivisionValidator.h"
42 #include "core/kernel/WModule.h"
43 #include "structure/WVertexFactory.h"
44 
45 
46 using osg::Vec3;
47 
48 namespace butterfly
49 {
50  /**
51  * Class that depicts the whole Butterfly subdivision algorithm but nothing more as such.
52  */
54  {
55  public:
56  /**
57  * Butterfly subdivision tool object creating instance.
58  */
60 
61  /**
62  * Destroys the Butterfly instance object and its substructures.
63  */
64  virtual ~WButterflyCalculator();
65 
66  /**
67  * Assigns the input mesh andd its analyzed data that are required for the butterfly subdivision.
68  * \author schwarzkopf
69  * \param inputMesh Triangle mesh that should be subdivided
70  * \param vertexProperties The analyzed data of the input triangle mesh
71  */
72  void assignInputMesh( std::shared_ptr< WTriangleMesh > inputMesh,
73  WVertexFactory* vertexProperties );
74 
75  /**
76  * Set the general Butterfly Subdivision setting w that affects the subdivision. See the algorithm
77  * documentation for the exact meaning. It's usually chosen substantially small. The original
78  * authors used 0.0f.
79  * \author schwarzkopf
80  * \param butterflySettingW The general butterfly subdivision parameter w.
81  */
82  void setButterflySettingW( float butterflySettingW );
83 
84  /**
85  * Calculate the subdivided new vertex between two vertices using the Butterfly Subdivision.
86  * algorithm.
87  * \author schwarzkopf
88  * \param vertID1 First vertex to subdivide between.
89  * \param vertID2 Second vertex ID to subdivide between
90  * \return Calculated coordinates.
91  */
92  osg::Vec3 calcNewVertex( size_t vertID1, size_t vertID2 );
93 
94 
95  private:
96  /**
97  * The general Butterfly Subdivision setting w that affects the subdivision. See the algorithm
98  * documentation for the exact meaning. It's usually chosen substantially small. The original
99  * authors used 0.0f.
100  */
101  static float m_w;
102 
103  /**
104  * Butterfly subdivision Weights for each neighbor which always are applied for valences 3 and 4.
105  * Valence 6 is applied for Butterfly stencils where both valences are 6.
106  * The first row starts with valence 6. The first column starts with the center vertex weight.
107  * Then comes the Neighbor vertex connected to the other stencil center vertex.
108  */
109  static float m_weights[4][7];
110 
111  /**
112  * Weight where both stencil centers lie on a border. This weight is for a stencil center.
113  */
115 
116  /**
117  * Weight where both stencil centers lie on a border. This weight is beside the stencil
118  * centers.
119  */
120  static float m_weightRimAtBorder;
121 
122  /**
123  * Calculate a subdivided mit point between two vertices using the mean calculation.
124  * \author schwarzkopf
125  * \param vertID1 First vertex to subdivide between.
126  * \param vertID2 Second vertex ID to subdivide between.
127  * \return Mean between the two vertices.
128  */
129  osg::Vec3 calcMean( size_t vertID1, size_t vertID2 );
130 
131  /**
132  * Calculate the coordinates of a stencil half using the Butterfly subdivision algorithm.
133  * \param stencilCenterVertID Vertex ID of the stencil center. Coordinates are calculated
134  * for that value.
135  * \param directedNeighbourVertID Vertex ID of the other half of the whole butterfly stencil.
136  * \param isIrregular Calculate stencil half as an irregular. False is set calculating a
137  * Stencil where both valences are 6.
138  * \return Interpolated coordinates.
139  */
140  Vec3 getInterpolatedValue( size_t stencilCenterVertID, size_t directedNeighbourVertID, bool isIrregular );
141 
142  /**
143  * Associated data set used for analyzation of the triangle mesh.
144  */
146 
147  /**
148  * Base triangle mesh used for calculations.
149  */
150  std::shared_ptr< WTriangleMesh > m_inputMesh;
151  };
152 } /* namespace butterfly */
153 #endif // WBUTTERFLYCALCULATOR_H
Class that depicts the whole Butterfly subdivision algorithm but nothing more as such.
osg::Vec3 calcMean(size_t vertID1, size_t vertID2)
Calculate a subdivided mit point between two vertices using the mean calculation.
void assignInputMesh(std::shared_ptr< WTriangleMesh > inputMesh, WVertexFactory *vertexProperties)
Assigns the input mesh andd its analyzed data that are required for the butterfly subdivision.
Vec3 getInterpolatedValue(size_t stencilCenterVertID, size_t directedNeighbourVertID, bool isIrregular)
Calculate the coordinates of a stencil half using the Butterfly subdivision algorithm.
WVertexFactory * m_verts
Associated data set used for analyzation of the triangle mesh.
static float m_weightCenterAtBorder
Weight where both stencil centers lie on a border.
std::shared_ptr< WTriangleMesh > m_inputMesh
Base triangle mesh used for calculations.
static float m_weightRimAtBorder
Weight where both stencil centers lie on a border.
void setButterflySettingW(float butterflySettingW)
Set the general Butterfly Subdivision setting w that affects the subdivision.
osg::Vec3 calcNewVertex(size_t vertID1, size_t vertID2)
Calculate the subdivided new vertex between two vertices using the Butterfly Subdivision.
WButterflyCalculator()
Butterfly subdivision tool object creating instance.
virtual ~WButterflyCalculator()
Destroys the Butterfly instance object and its substructures.
static float m_weights[4][7]
Butterfly subdivision Weights for each neighbor which always are applied for valences 3 and 4.
static float m_w
The general Butterfly Subdivision setting w that affects the subdivision.
Class that manages all vertex properties.