38 #include <osg/Geometry>
40 #include "WMButterfly.h"
41 #include "WMButterfly.xpm"
42 #include "core/dataHandler/WDataSetScalar.h"
43 #include "core/graphicsEngine/WGEGeodeUtils.h"
44 #include "core/graphicsEngine/WGEManagedGroupNode.h"
45 #include "core/graphicsEngine/callbacks/WGELinearTranslationCallback.h"
46 #include "core/graphicsEngine/shaders/WGEPropertyUniform.h"
47 #include "core/graphicsEngine/shaders/WGEShader.h"
48 #include "core/kernel/WKernel.h"
49 #include "core/kernel/WModuleInputData.h"
50 #include "structure/WVertexFactory.h"
60 m_butterfly->assignProgressCombiner( m_progress );
74 return WMButterfly_xpm;
79 return "Butterfly subdivision";
84 return "Subdivides triangles in a mesh using the improved butterfly scheme (Zorin et al., 1996).";
92 "input mesh",
"The mesh to display" );
93 m_output = std::shared_ptr<WModuleOutputData<WTriangleMesh> >(
96 "The loaded mesh." ) );
107 "It's the general Butterfly Subdivision setting w that affects "
108 "the subdivision. It's usually chosen substantially small. "
109 "The original authors used 0.0.",
115 "Iteration count that is attempted regarding the maximal triangle count.",
121 "Maximal triangle count as result, scaled by 10^n. "
122 "The Subdivision stops when the triangle count is above it.",
128 "Maximal triangle count as result. "
129 "The Subdivision stops when the triangle count is above it.",
133 "Number of CPU cores/threads to use. 1,4x with 2, "
134 "1,7x with 4 threads and 2,2x speed with 8 threads "
135 "(total cycle performance).",
141 "There are no subdivision in lines where the angle transformation "
142 "at the stencil center point would not exceed this value.",
148 "There are no subdivision in lines where the angle transformation "
149 "at the stencil center point would exceed this value.",
155 "Minimal allowed quotient of the new lines that lie between "
156 "the stencil center points and the new point.",
162 "Line length divided by that value must be at least as big "
163 "as the longest line in the stencil in order to subdivide.",
169 "Line length divided by that value must be at least as big "
170 "as the average line in the stencil in order to subdivide.",
176 "Lines below that length are not subdivided.",
182 "Amount which multiplies the value above after each iteration. "
183 "As consequence subdivision is don by the order of connection "
190 "Connections that have angles in shared triangles below that "
191 "angle are interpolated by the mixture of linearly and proposed "
192 "subdivision, weighted by the comparison between the smallest "
193 "angle and this limit.",
199 "A subdivision is marked as invalid if the angle between any "
200 "neighbor triangle line is above that angle.",
206 "If the line length is smaller than the subdividable line "
207 "by this ratio, then it won't be marked as invalid.",
213 "Examining all triangles. If any line is smaller than the "
214 "longest multiplied by this value so the points of the small "
215 "line will be joined.",
221 "If any triangle that connects two vertices has two angles at "
222 "these points that both are below this degree value so the "
223 "triangle orientation is rotated in this square constellation",
284 m_output->updateData( interpolatedMesh );
302 std::shared_ptr< WTriangleMesh > meshData =
m_input->getData();
315 float maxLineLength = 0.0f;
316 for (
size_t triID = 0; triID < inputMesh->triangleSize(); triID++ )
318 size_t id0 = inputMesh->getTriVertId0( triID );
319 size_t id1 = inputMesh->getTriVertId1( triID );
320 size_t id2 = inputMesh->getTriVertId2( triID );
321 osg::Vec3 point0 = inputMesh->getVertex( id0 );
322 osg::Vec3 point1 = inputMesh->getVertex( id1 );
323 osg::Vec3 point2 = inputMesh->getVertex( id2 );
324 float length0 = WVertexFactory::getDistance( point0, point1 );
325 float length1 = WVertexFactory::getDistance( point0, point2 );
326 float length2 = WVertexFactory::getDistance( point2, point1 );
327 if ( length0 > maxLineLength )
328 maxLineLength = length0;
330 if ( length1 > maxLineLength )
331 maxLineLength = length1;
333 if ( length2 > maxLineLength )
334 maxLineLength = length2;
336 return maxLineLength>0.0f ?maxLineLength :1.0f;
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
This class adds some convenience methods to WGEGroupNode.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
OpenWalnut module that subdivides a triangle mesh in more points resulting a smoother surface.
WPropDouble m_maxNeighbourTriangleAngleTriangleFlip
The Minimal allowed angle which fits in both vertices at a subdividable line end.
WPropDouble m_minTransformationAngle
Angle setting which both angles at the subdivided line ends should be at least as big as this value.
WPropDouble m_minAmountOfMax
Factor for multiplying the maximal distance to a neighbour within the Butterfly stencil.
WPropDouble m_minSubdividedLineLengthMultiplierPerIteration
The factor where the minimal subdivided line length is multiplied by in each Subdivision iteration st...
virtual void properties()
Initialize the properties for this module.
virtual ~WMButterfly()
Destroys this module.
WPropInt m_cpuThreads
CPU thread count setting for multithreading support.
WPropDouble m_maxNeighbourTriangleAngle
A subdivision is marked as invalid if the angle between any neighbor triangle line is above that angl...
std::shared_ptr< WModuleInputData< WTriangleMesh > > m_input
Input connector for scalar data.
WPropDouble m_maxNeighbourTriangleAngleLengthRatio
This settings extends If the line length is smaller than the subdividable line by this ratio,...
WPropDouble m_maxAmountOfMaxForVertexJoin
The Factor for comparison to the maximal length of a triangle.
std::shared_ptr< WCondition > m_propCondition
Needed for recreating the geometry, incase when resolution changes.
WPropInt m_maxTriangles
Maximal allowed triangle count after Butterfly subdivision.
WPropDouble m_minAmountOfAverage
Factor for multiplying the average distance to a neighbour within the Butterfly stencil.
std::shared_ptr< WTriangleMesh > m_mesh
Triangle mesh which will be assigned to the Butterfly subdivision instance.
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.
WPropInt m_iterations
The iteration count of the Butterfly subdivision to attempt.
WPropDouble m_minQuotient
Maximum factor which the following lines should differ to show a valid subdivision.
virtual void requirements()
Initialize requirements for this module.
std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_output
Output connector provided by this module.
osg::ref_ptr< WGEManagedGroupNode > m_rootNode
The OSG root node for this module.
virtual const std::string getDescription() const
Gives back a description of this module.
virtual const std::string getName() const
Gives back the name of this module.
virtual void moduleMain()
Entry point after loading the module.
WMButterfly()
Creates the module for subdividing a triangle mesh using Butterfly subdivision.
WPropDouble m_minSubdividedLineLength
The minimal subdividable line length.
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.
WPropDouble m_maxTriangles10n
Maximal allowed triangle count after Butterfly subdivision.
WPropDouble m_butterflySettingW
The general Butterfly Subdivision setting w that affects the subdivision.
WPropDouble m_maxTransformationAngle
Angle setting which both angles at the subdivided line ends should be not bigger than this value.
virtual void connectors()
Initialize the connectors this module is using.
butterfly::WButterflyFactory * m_butterfly
Butterfly subdivision instance.
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...
WPropDouble m_minNeighbourTriangleAngle
The Minimal allowed angle between two Subdivided line ends.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
WPropBool m_active
True whenever the module should be active.
virtual void connectors()
Initialize connectors in this function.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Class that depicts the whole Butterfly subdivision algorithm but nothing more as such.
WSubdivisionValidator * getValidator()
Returns the Butterfly subdivision validator.
void setCpuThreadCount(size_t cpuThreadCount)
Sets the count of CPU threads to use.
std::shared_ptr< WTriangleMesh > getSubdividedMesh(std::shared_ptr< WTriangleMesh > edgedMmesh)
Launch the Butterfly subdivision.
void setButterflySettingW(float butterflySettingW)
Set the general Butterfly Subdivision setting w that affects the subdivision.
void setIterationsSettings(float m_iterations, float m_maxTriangles10n)
Assign main butterfly subdivision iterations settings.
Class that validates the Butterfly subdivision.
void setMinMeighbourTriangleAngle(float minNeighbourTriangleAngle)
Sets the Minimal allowed angle between two Subdivided line ends.
void setMinSubdividedLineLength(float minSubdividedLineLength)
Sets the minimal subdividable line length.
void setMinTransformationAngle(float minTransformationAngle)
Sets up the angle setting which both angles at the subdivided line ends should be at least as big as ...
void setMinAmountOfMax(float minAmountOfMax)
Sets the factor for multiplying the maximal distance to a neighbour within the Butterfly stencil.
void setMinAmountOfAverage(float minAmountOfAverage)
Sets the factor for multiplying the average distance to a neighbour within the Butterfly stencil.
void setMaxNeighbourTriangleAngle(float maxNeighbourTriangleAngle, float maxNeighbourTriangleAngleLengthRatio)
Sets settings of the further feature: A subdivision is marked as invalid if the angle between any nei...
void setMinLenghtsQuotient(float minLenghtsQuotient)
Sets the maximum factor which the following lines should differ to show a valid subdivision.
void setMinSubdividedLineLengthMultiplierPerIteration(float minSubdividedLineLengthMultiplierPerIteration)
Sets the factor where the minimal subdivided line length is multiplied by in each Subdivision iterati...
void setMaxNeighbourTriangleAngleTriangleFlip(float maxNeighbourTriangleAngleTriangleFlip)
Sets the Minimal allowed angle which fits in both vertices at a subdividable line end.
void setMaxTransformationAngle(float maxTransformationAngle)
Sets up the angle setting which both angles at the subdivided line ends should be not bigger than thi...
void setMaxAmountOfMaxForVertexJoin(float maxAmountOfMaxForVertexJoin)
Sets the Factor for comparison to the maximal length of a triangle.