38 #include "WButterflyCalculator.h"
39 #include "WSubdivisionValidator.h"
40 #include "core/kernel/WKernel.h"
47 {{0.75f, 5.0f / 12.0f, -1.0f / 12.0f, -1.0f / 12.0f, 0.0f, 0.0f, 0.0f},
48 {0.875f, 3.0f / 8.0f, -1.0f / 8.0f, 0.0f, -1.0f / 8.0f, 0.0f, 0.0f},
49 {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
50 {0.5f - m_w, 0.0f, 0.0625f + m_w, -0.0625f - m_w, m_w, -0.0625f - m_w, 0.0625f + m_w}};
67 this->
m_verts = vertexProperties;
71 m_w = butterflySettingW;
87 valence1 += valence1 - 2;
89 valence2 += valence2 - 2;
90 Vec3
final = Vec3( 0.0f, 0.0f, 0.0f );
91 if ( bound1 < 2 && bound2 < 2 && bound1 >= 0 && bound2 >= 0 )
93 if( bound1 != 1 || bound2 != 1 )
95 if ( valence1 == 6 && valence2 == 6 )
97 final =
m_verts->
add( Vec3( 0.0f, 0.0f, 0.0f ),
102 else if( valence1 != 6 || valence2 != 6 )
104 final =
m_verts->
add( Vec3( 0.0f, 0.0f, 0.0f ),
123 final =
calcMean( vertID1, vertID2 );
131 float coordX = ( vert1.x() + vert2.x() ) / 2.0f,
132 coordY = ( vert1.y() + vert2.y() ) / 2.0f,
133 coordZ = ( vert1.z() + vert2.z() ) / 2.0f;
134 return osg::Vec3( coordX , coordY, coordZ );
137 size_t directedNeighbourVertID,
bool isIrregular )
141 float valence =
property->getValence();
142 int bounds =
property->getBoundClass();
144 valence += valence - 2;
146 int weightRow =
static_cast<int>( valence + 0.3f ) - 3;
147 bool hasCustomWeight = ( valence == 3 || valence == 4 || ( valence == 6 && !isIrregular ) );
151 for (
int index = 0; index < valence; index++ )
153 float neighbour = index - start;
154 if ( neighbour < 0.0f )
155 neighbour = valence + neighbour;
157 bool isBehindBound = ( bounds == 1 && index > valence / 2 );
158 int i_mirrored = isBehindBound ?index-valence/2 :index,
159 weightCol = 1 +
static_cast<int>( neighbour + 0.3f );
160 int neighbourID =
property->getStencilNeighbourID( i_mirrored );
161 float weight = hasCustomWeight ?
m_weights[weightRow][weightCol]
162 :( 0.25f + cos( 2.0f * M_PI * neighbour / valence )
163 + 0.5f * cos( 4.0f * M_PI * neighbour / valence ) ) / valence;
164 Vec3 value =
m_inputMesh->getVertex( neighbourID );
Object that contains all necessary properties of a vertex necessary for a sufficient analysis.
int getStencilNeighbourIndex(size_t neighbourID)
Returns the Stencil neighbor index of a particular vertex ID.
size_t getStencilNeighbourID(size_t index)
Returns a neighbor ID within the stencil by the index.
size_t getValence()
Returns the Neighbor vertex count of the current vertex.
int getBoundClass()
Returns the bound count class of the stencil's center point.
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.
WVertexProperty * getProperty(size_t vertexID)
Get properties of a vertex.
static osg::Vec3 add(osg::Vec3 base, osg::Vec3 sum, float factor)
Adding a sum multiplied by a factor to the base number.