OpenWalnut  1.5.0dev
WButterflyFactory.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 #ifndef WBUTTERFLYFACTORY_H_
26 #define WBUTTERFLYFACTORY_H_
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include "WButterflyCalculator.h"
33 #include "WSubdivisionValidator.h"
34 #include "core/kernel/WModule.h"
35 #include "structure/WVertexFactory.h"
36 
37 
38 using osg::Vec3;
39 
40 namespace butterfly
41 {
42  /**
43  * Class that depicts the whole Butterfly subdivision algorithm but nothing more as such.
44  */
46  {
47  public:
48  /**
49  * Butterfly subdivision tool object creating instance.
50  */
52 
53  /**
54  * Destroys the Butterfly instance object and its substructures.
55  */
56  virtual ~WButterflyFactory();
57 
58  /**
59  * Set the general Butterfly Subdivision setting w that affects the subdivision. See the algorithm
60  * documentation for the exact meaning. It's usually chosen substantially small. The original
61  * authors used 0.0f.
62  * \author schwarzkopf
63  * \param butterflySettingW The general butterfly subdivision parameter w.
64  */
65  void setButterflySettingW( float butterflySettingW );
66 
67  /**
68  * Assign main butterfly subdivision iterations settings.
69  * \author schwarzkopf
70  * \param m_iterations Count how many times the butterfly subdivision should be iteratedly
71  * applied.
72  * \param m_maxTriangles10n Maximal triangle count. If there are more triangles then the
73  * subdivision will be stop.
74  */
75  void setIterationsSettings( float m_iterations, float m_maxTriangles10n );
76 
77  /**
78  * Sets the count of CPU threads to use.
79  * \author schwarzkopf
80  * \param cpuThreadCount CPU thread count to use.
81  */
82  void setCpuThreadCount( size_t cpuThreadCount );
83 
84  /**
85  * Assigns a ProbressCombiner to the Butterfly factory. After that the algorithm will be
86  * able to actualize the progress within the module overview.
87  * \author schwarzkopf
88  * \param associatedProgressCombiner Progress combiner to be associated.
89  */
90  void assignProgressCombiner( std::shared_ptr< WProgressCombiner > associatedProgressCombiner );
91 
92  /**
93  * Sets progress which iteration step and kind of cumputing step is currently done.
94  * The scale of the computing step is also set.
95  * \author schwarzkopf
96  * \param iteration Butterfly iteration step.
97  * \param steps Scale of the progress bar.
98  */
99  void setProgressSettings( size_t iteration, size_t steps );
100 
101  /**
102  * Returns the Butterfly subdivision validator. Therefore settings can be changed externally.
103  * \author schwarzkopf
104  * \return Subdivision validator pointer.
105  */
107 
108  /**
109  * Launch the Butterfly subdivision. Afterwards the interpolated Triangle mesh is returned.
110  * \param edgedMmesh Triangle mesh to be interpolated.
111  * \return Interpolated triangle mesh.
112  */
113  std::shared_ptr< WTriangleMesh > getSubdividedMesh( std::shared_ptr< WTriangleMesh > edgedMmesh );
114 
115 
116  private:
117  /**
118  * Examines Butterfly stencils of all vertices and stores data
119  * \author schwarzkopf
120  */
121  void examineStencilAll();
122 
123  /**
124  * Attachs new vertices that are used for the subdivision. The data sets are only assigned.
125  * The calculation itself will be applied afterwards.
126  * \author schwarzkopf
127  */
129 
130  /**
131  * Applies triangle mesh preprocessing if vertex flip or triangle flip setting is not
132  * default.
133  * \author schwarzkopf
134  * \param iteration Preprocessing is applied only before the first iteration
135  */
136  void applyMeshPreprocessing( size_t iteration );
137 
138  /**
139  * Examine The triangle mesh before Butterfly subdivision. Following steps are included:
140  * - Register all triangles to corresponding vertices
141  * - Optionally preprocess Triangle mesh.
142  * - Examine Butterfly stencils (Vertex neighbours only) and valence of all vertices
143  * - Collect statistical information required for validation of subdividable new vertices.
144  * Currently it includes maximal and averate neighbour distance from each vertex.
145  * \author schwarzkopf
146  * \param iteration Consecutive Iteration step of the Butterfly subdivision.
147  */
148  void examineVertexNeighborhood( size_t iteration );
149 
150  /**
151  * Calculates coordinates of the new vertices. It uses multithreading.
152  * \author schwarzkopf
153  */
154  void interpolateNewVertices();
155 
156  /**
157  * Calculates coordinates of the new vertices. The parameters are to select the vertices
158  * to calculated. It's useful for multithreading.
159  * \author schwarzkopf
160  * \param fromVertex First data set holding vertex property.
161  * \param toVertex Last data set holding vertex property.
162  */
163  void interpolateNewVerticesRange( size_t fromVertex, size_t toVertex );
164 
165  /**
166  * Adds interpolated vertices and triangles to the output triangle mesh.
167  * \author schwarzkopf
168  */
169  void addInterpolatedContent();
170 
171 
172  /**
173  * Iteration steps to apply iteratedly.
174  */
175  size_t m_iterations;
176 
177  /**
178  * Maximal allowed triangle count applyable for subdivision.
179  */
181 
182  /**
183  * Base triangle mesh used for calculations.
184  */
185  std::shared_ptr< WTriangleMesh > m_inputMesh;
186 
187  /**
188  * Triangle mesh that is set up by interpolation.
189  */
190  std::shared_ptr< WTriangleMesh > m_outputMesh;
191 
192  /**
193  * Data set used for analyzation of the triangle mesh.
194  */
196 
197  /**
198  * Triangle mesh validation instance.
199  */
201 
202  /**
203  * Total triangle count.
204  */
205  size_t m_triCount; //TODO(schwarzkopf): Consider removing this variable
206 
207  /**
208  * Current count of currently added vertices during interpolation.
209  */
210  size_t m_vertCount;
211 
212  /**
213  * Progress combiner for changing the plugin status in the modules overview.
214  */
215  std::shared_ptr< WProgressCombiner > m_associatedProgressCombiner;
216 
217  /**
218  * Current progress status.
219  */
220  std::shared_ptr< WProgress > m_progressStatus;
221 
222  /**
223  * CPU threads count for multithreading support.
224  */
226 
227  /**
228  * CPU threads object for multithreading support.
229  */
230  vector<boost::thread*> m_cpuThreads;
231 
232  /**
233  * Instance for interpolating new vertices.
234  */
236  };
237 } /* namespace butterfly */
238 #endif // WBUTTERFLYFACTORY_H
Class that depicts the whole Butterfly subdivision algorithm but nothing more as such.
Class that depicts the whole Butterfly subdivision algorithm but nothing more as such.
virtual ~WButterflyFactory()
Destroys the Butterfly instance object and its substructures.
WSubdivisionValidator * getValidator()
Returns the Butterfly subdivision validator.
size_t m_cpuThreadCount
CPU threads count for multithreading support.
void addInterpolatedContent()
Adds interpolated vertices and triangles to the output triangle mesh.
std::shared_ptr< WProgressCombiner > m_associatedProgressCombiner
Progress combiner for changing the plugin status in the modules overview.
void setCpuThreadCount(size_t cpuThreadCount)
Sets the count of CPU threads to use.
void setProgressSettings(size_t iteration, size_t steps)
Sets progress which iteration step and kind of cumputing step is currently done.
vector< boost::thread * > m_cpuThreads
CPU threads object for multithreading support.
size_t m_iterations
Iteration steps to apply iteratedly.
WSubdivisionValidator * m_validator
Triangle mesh validation instance.
WVertexFactory * m_verts
Data set used for analyzation of the triangle mesh.
std::shared_ptr< WTriangleMesh > getSubdividedMesh(std::shared_ptr< WTriangleMesh > edgedMmesh)
Launch the Butterfly subdivision.
size_t m_maxTriangles
Maximal allowed triangle count applyable for subdivision.
void examineStencilAll()
Examines Butterfly stencils of all vertices and stores data.
std::shared_ptr< WTriangleMesh > m_inputMesh
Base triangle mesh used for calculations.
void attachUncalculatedNewVertices()
Attachs new vertices that are used for the subdivision.
size_t m_triCount
Total triangle count.
void applyMeshPreprocessing(size_t iteration)
Applies triangle mesh preprocessing if vertex flip or triangle flip setting is not default.
WButterflyCalculator * m_butterflyCalculator
Instance for interpolating new vertices.
std::shared_ptr< WProgress > m_progressStatus
Current progress status.
size_t m_vertCount
Current count of currently added vertices during interpolation.
void setButterflySettingW(float butterflySettingW)
Set the general Butterfly Subdivision setting w that affects the subdivision.
void assignProgressCombiner(std::shared_ptr< WProgressCombiner > associatedProgressCombiner)
Assigns a ProbressCombiner to the Butterfly factory.
std::shared_ptr< WTriangleMesh > m_outputMesh
Triangle mesh that is set up by interpolation.
WButterflyFactory()
Butterfly subdivision tool object creating instance.
void interpolateNewVerticesRange(size_t fromVertex, size_t toVertex)
Calculates coordinates of the new vertices.
void setIterationsSettings(float m_iterations, float m_maxTriangles10n)
Assign main butterfly subdivision iterations settings.
void interpolateNewVertices()
Calculates coordinates of the new vertices.
void examineVertexNeighborhood(size_t iteration)
Examine The triangle mesh before Butterfly subdivision.
Class that validates the Butterfly subdivision.
Class that manages all vertex properties.