OpenWalnut  1.5.0dev
WMButterfly.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 // The class WButterflyCalculator partially relies on the Butterfly Subdivision
27 // algorithm.that dates from Denis Zorin, Peter Schroeder, Wim Sweldens, Nira
28 // Dyn, David 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 WMBUTTERFLY_H
35 #define WMBUTTERFLY_H
36 
37 #include <memory>
38 #include <string>
39 
40 #include "WButterflyFactory.h"
41 #include "core/kernel/WModule.h"
42 #include "structure/WVertexFactory.h"
43 
44 
45 using osg::Vec3;
46 // forward declarations to reduce compile dependencies
47 template< class T > class WModuleInputData;
48 class WDataSetScalar;
50 
51 /**
52  * OpenWalnut module that subdivides a triangle mesh in more points resulting a smoother surface.
53  * Plugin Version: 0.9.0, Release Candidate 1
54  * Date: 2013/08/23 23:32
55  * \ingroup modules
56  */
57 class WMButterfly: public WModule
58 {
59 public:
60  /**
61  * Creates the module for subdividing a triangle mesh using Butterfly subdivision.
62  */
63 WMButterfly();
64 
65  /**
66  * Destroys this module.
67  */
68  virtual ~WMButterfly();
69 
70  /**
71  * Gives back the name of this module.
72  * \return the module's name.
73  */
74  virtual const std::string getName() const;
75 
76  /**
77  * Gives back a description of this module.
78  * \return description to module.
79  */
80  virtual const std::string getDescription() const;
81 
82  /**
83  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
84  * should never be initialized or modified in some other way. A simple new instance is required.
85  * \return the prototype used to create every module in OpenWalnut.
86  */
87  virtual std::shared_ptr< WModule > factory() const;
88 
89  /**
90  * Get the icon for this module in XPM format.
91  * \return The icon.
92  */
93  virtual const char** getXPMIcon() const;
94 
95 protected:
96  /**
97  * Entry point after loading the module. Runs in separate thread.
98  */
99  virtual void moduleMain();
100 
101  /**
102  * Initialize the connectors this module is using.
103  */
104  virtual void connectors();
105 
106  /**
107  * Initialize the properties for this module.
108  */
109  virtual void properties();
110 
111  /**
112  * Initialize requirements for this module.
113  */
114  virtual void requirements();
115 
116 private:
117  /**
118  * Returns the biggest length of a neighbour relationship.
119  * \param inputMesh Triangle mesh to analyze.
120  * \return The biggest distance of all vertex neighbour relationships.
121  */
122  float getMaxLineLength( std::shared_ptr< WTriangleMesh > inputMesh );
123 
124  /**
125  * Input connector for scalar data.
126  */
127  std::shared_ptr< WModuleInputData< WTriangleMesh > > m_input;
128  std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_output; //!< Output connector provided by this module.
129 
130  /**
131  * Holder for the current triangle mesh that grants that there's always a valid data output at
132  * the end. The old data is deleted after the new one is applied. Deleting a triangle mesh that
133  * is attached at the output connector makes some plugins crash.
134  */
135  std::shared_ptr< WTriangleMesh > m_oldInterpolatedMesh;
136 
137  /**
138  * The OSG root node for this module. All other geodes or OSG nodes will be attached on this single node.
139  */
140  osg::ref_ptr< WGEManagedGroupNode > m_rootNode;
141 
142  /**
143  * Needed for recreating the geometry, incase when resolution changes.
144  */
145  std::shared_ptr< WCondition > m_propCondition;
146 
147  /**
148  * The general Butterfly Subdivision setting w that affects the subdivision. See the algorithm
149  * documentation for the exact meaning. It's usually chosen substantially small. The original
150  * authors used 0.0.
151  */
152  WPropDouble m_butterflySettingW;
153 
154  /**
155  * The iteration count of the Butterfly subdivision to attempt.
156  */
157  WPropInt m_iterations;
158 
159  /**
160  * Maximal allowed triangle count after Butterfly subdivision. Subdivision stops at last subdivision
161  * step exceeding that triangle count. Due to usability the scale is exponential by 10^n.
162  */
163  WPropDouble m_maxTriangles10n;
164 
165  /**
166  * Maximal allowed triangle count after Butterfly subdivision. Subdivision stops at last subdivision
167  * step exceeding that triangle count.
168  */
169  WPropInt m_maxTriangles;
170 
171  /**
172  * CPU thread count setting for multithreading support.
173  */
174  WPropInt m_cpuThreads;
175 
176  /**
177  * Angle setting which both angles at the subdivided line ends should be at
178  * least as big as this value. The regarded triangle consists of the two subdivided
179  * line end points and the new vertex.
180  */
182 
183  /**
184  * Angle setting which both angles at the subdivided line ends should be not
185  * bigger than this value. The regarded triangle consists of the two subdivided
186  * line end points and the new vertex.
187  */
189 
190  /**
191  * Maximum factor which the following lines should differ to show a valid
192  * subdivision. Both lines are measured from the new subdivided point and end at the
193  * ends of the subdivided line end.
194  */
195  WPropDouble m_minQuotient;
196 
197  /**
198  * Factor for multiplying the maximal distance to a neighbour within the Butterfly
199  * stencil. Lines are not subdivided being smaller than this distance multiplied by it.
200  */
201  WPropDouble m_minAmountOfMax;
202 
203  /**
204  * Factor for multiplying the average distance to a neighbour within the Butterfly
205  * stencil. Lines are not subdivided being smaller than the average distance multiplied by it.
206  */
207  WPropDouble m_minAmountOfAverage;
208 
209  /**
210  * The minimal subdividable line length. Lines of smaller distance than this are not
211  * subdivided.
212  */
214 
215  /**
216  * The factor where the minimal subdivided line length is multiplied by in each
217  * Subdivision iteration step.
218  */
220 
221  /**
222  * The Minimal allowed angle between two Subdivided line ends. If the two points have
223  * a triangle where the angle is at least in one triangle cutting that vertices amaller than
224  * this so the coordinates will be interpolated between the mean of the two neighbors and
225  * its Butterfly subdivision used one, weighted using the minimal transformation angle.
226  */
228 
229  /**
230  * A subdivision is marked as invalid if the angle between any neighbor triangle line
231  * is above that angle.
232  */
234 
235  /**
236  * This settings extends
237  * If the line length is smaller than the subdividable line by this ratio, then it won't
238  * be marked as invalid.
239  */
241 
242  /**
243  * The Factor for comparison to the maximal length of a triangle. Lines smaller than this
244  * force a joint of the corresponding two vertices. The triangle falls finally away.
245  */
247 
248  /**
249  * The Minimal allowed angle which fits in both vertices at a subdividable line end.
250  * An existing triangle where both angles fit in forces it to rotate it with the other triangle
251  * connected with that vertices araund the four vertices of that two triangles. There is no
252  * application if the final state would be also invalid.
253  */
255 
256  /**
257  * Triangle mesh which will be assigned to the Butterfly subdivision instance.
258  */
259  std::shared_ptr< WTriangleMesh > m_mesh;
260 
261  /**
262  * Butterfly subdivision instance.
263  */
265 };
266 
267 #endif // WMBUTTERFLY_H
This data set type contains scalars as values.
This class adds some convenience methods to WGEGroupNode.
OpenWalnut module that subdivides a triangle mesh in more points resulting a smoother surface.
Definition: WMButterfly.h:58
WPropDouble m_maxNeighbourTriangleAngleTriangleFlip
The Minimal allowed angle which fits in both vertices at a subdividable line end.
Definition: WMButterfly.h:254
WPropDouble m_minTransformationAngle
Angle setting which both angles at the subdivided line ends should be at least as big as this value.
Definition: WMButterfly.h:181
WPropDouble m_minAmountOfMax
Factor for multiplying the maximal distance to a neighbour within the Butterfly stencil.
Definition: WMButterfly.h:201
WPropDouble m_minSubdividedLineLengthMultiplierPerIteration
The factor where the minimal subdivided line length is multiplied by in each Subdivision iteration st...
Definition: WMButterfly.h:219
virtual void properties()
Initialize the properties for this module.
virtual ~WMButterfly()
Destroys this module.
Definition: WMButterfly.cpp:63
WPropInt m_cpuThreads
CPU thread count setting for multithreading support.
Definition: WMButterfly.h:174
WPropDouble m_maxNeighbourTriangleAngle
A subdivision is marked as invalid if the angle between any neighbor triangle line is above that angl...
Definition: WMButterfly.h:233
std::shared_ptr< WModuleInputData< WTriangleMesh > > m_input
Input connector for scalar data.
Definition: WMButterfly.h:127
WPropDouble m_maxNeighbourTriangleAngleLengthRatio
This settings extends If the line length is smaller than the subdividable line by this ratio,...
Definition: WMButterfly.h:240
WPropDouble m_maxAmountOfMaxForVertexJoin
The Factor for comparison to the maximal length of a triangle.
Definition: WMButterfly.h:246
std::shared_ptr< WCondition > m_propCondition
Needed for recreating the geometry, incase when resolution changes.
Definition: WMButterfly.h:145
WPropInt m_maxTriangles
Maximal allowed triangle count after Butterfly subdivision.
Definition: WMButterfly.h:169
WPropDouble m_minAmountOfAverage
Factor for multiplying the average distance to a neighbour within the Butterfly stencil.
Definition: WMButterfly.h:207
std::shared_ptr< WTriangleMesh > m_mesh
Triangle mesh which will be assigned to the Butterfly subdivision instance.
Definition: WMButterfly.h:259
std::shared_ptr< WTriangleMesh > m_oldInterpolatedMesh
Holder for the current triangle mesh that grants that there's always a valid data output at the end.
Definition: WMButterfly.h:135
WPropInt m_iterations
The iteration count of the Butterfly subdivision to attempt.
Definition: WMButterfly.h:157
WPropDouble m_minQuotient
Maximum factor which the following lines should differ to show a valid subdivision.
Definition: WMButterfly.h:195
virtual void requirements()
Initialize requirements for this module.
std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_output
Output connector provided by this module.
Definition: WMButterfly.h:128
osg::ref_ptr< WGEManagedGroupNode > m_rootNode
The OSG root node for this module.
Definition: WMButterfly.h:140
virtual const std::string getDescription() const
Gives back a description of this module.
Definition: WMButterfly.cpp:82
virtual const std::string getName() const
Gives back the name of this module.
Definition: WMButterfly.cpp:77
virtual void moduleMain()
Entry point after loading the module.
WMButterfly()
Creates the module for subdividing a triangle mesh using Butterfly subdivision.
Definition: WMButterfly.cpp:56
WPropDouble m_minSubdividedLineLength
The minimal subdividable line length.
Definition: WMButterfly.h:213
float getMaxLineLength(std::shared_ptr< WTriangleMesh > inputMesh)
Returns the biggest length of a neighbour relationship.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
Definition: WMButterfly.cpp:72
WPropDouble m_maxTriangles10n
Maximal allowed triangle count after Butterfly subdivision.
Definition: WMButterfly.h:163
WPropDouble m_butterflySettingW
The general Butterfly Subdivision setting w that affects the subdivision.
Definition: WMButterfly.h:152
WPropDouble m_maxTransformationAngle
Angle setting which both angles at the subdivided line ends should be not bigger than this value.
Definition: WMButterfly.h:188
virtual void connectors()
Initialize the connectors this module is using.
Definition: WMButterfly.cpp:89
butterfly::WButterflyFactory * m_butterfly
Butterfly subdivision instance.
Definition: WMButterfly.h:264
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
Definition: WMButterfly.cpp:67
WPropDouble m_minNeighbourTriangleAngle
The Minimal allowed angle between two Subdivided line ends.
Definition: WMButterfly.h:227
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
Class that depicts the whole Butterfly subdivision algorithm but nothing more as such.