Commit 3afc6ef7 authored by Andreas Schwarzkopf's avatar Andreas Schwarzkopf
Browse files

[FIX #294] fixed problem producing spikes

parent cfea9cbf
......@@ -36,7 +36,7 @@ namespace butterfly
{
float ButterflyFactory::w = 0.0f,
ButterflyFactory::factor[4][7] = {{0.75f, 5.0f/12.0f, -1.0f/12.0f, -1.0f/12.0f, 0.0f, 0.0f, 0.0f}, //NOLINT
{0.75f, 3.0f/8.0f, -1.0f/8.0f, 0.0f, -1.0f/8.0f, 0.0f, 0.0f},//NOLINT
{0.875f, 3.0f/8.0f, -1.0f/8.0f, 0.0f, -1.0f/8.0f, 0.0f, 0.0f},//NOLINT
{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},//NOLINT
{0.5f-w, 0.0f, 0.125f+2*w, -0.0625f-w, w, -0.0625f-w, 0.125f+2*w}},//NOLINT
ButterflyFactory::s1 = 9.0f / 16.0f,
......@@ -155,19 +155,8 @@ namespace butterfly
final = add( Vec3( 0.0f, 0.0f, 0.0f ), getKNeighbourValueBoundary( vertID1, vertID2, false, false ), 1.0f );
final = add( final, getKNeighbourValueBoundary( vertID2, vertID1, true, false ), 1.0f );
}
else if( false/*(k1==6) != (k2==6)*/ )
{ //Case 2: one vertex of valence=6 and onother has valence!=6
if( k1 != 6 )
{
final = getKNeighbourValueBoundary( vertID1, vertID2, false, false );
}
else
{
final = getKNeighbourValueBoundary( vertID2, vertID1, false, false );
}
}
else if( k1 != 6 || k2 != 6 )
{ //Case 3: two vertices of valence!=6
{ //Case 2/3: at least one vertex of valence!=6
final = add( Vec3( 0.0f, 0.0f, 0.0f ), getKNeighbourValueBoundary( vertID1, vertID2, false, true ), 0.5f );
final = add( final, getKNeighbourValueBoundary( vertID2, vertID1, false, true ), 0.5f );
}
......@@ -213,9 +202,10 @@ namespace butterfly
if( bounds == 1 )
k += k - 2;
int k_row = static_cast<int>( k + 0.3f ) - 3;
bool isDefaultButterfly = ( k == 3 || k == 4 || ( k == 6 && !treatK6AsKn ) );
bool hasCustomWeight = ( k == 3 || k == 4 || ( k == 6 && !treatK6AsKn ) );
Vec3 final = add( Vec3( 0.0f, 0.0f, 0.0f ), mesh->getVertex( stencilCenterVertID ),
isDefaultButterfly ? factor[k_row][0] : factor[0][0] );
hasCustomWeight ? factor[k_row][0] : factor[0][0] );
for( int i = 0; i < k; i++)
{
float j = i - start;
......@@ -225,7 +215,7 @@ namespace butterfly
int i_mirrored = isBehindBound ?i-k/2 :i,
k_col = 1 + static_cast<int>( j + 0.3f );
int neighbourID = verts->getVertexProperty( stencilCenterVertID )->getNeighbourVertices()[i_mirrored];
float s_j = isDefaultButterfly ?factor[k_row][k_col]
float s_j = hasCustomWeight ?factor[k_row][k_col]
:( 0.25f + cos( 2.0f * M_PI * j / k ) + 0.5f * cos( 4.0f * M_PI * j / k ) ) / k;
Vec3 value = mesh->getVertex( neighbourID );
if( isBehindBound )
......@@ -233,7 +223,7 @@ namespace butterfly
value = add( mesh->getVertex( stencilCenterVertID ), value, -1.0f );
value = add( mesh->getVertex( stencilCenterVertID ), value, 1.0f );
}
if( !isSecondK6 || ( j != 1 && j != 5 ) )
if( !isSecondK6 || treatK6AsKn || ( j != 1 && j != 5 ) )
final = add( final, value, s_j );
}
return final;
......
......@@ -45,14 +45,6 @@ const double M_PI = 3.14159265358979323846;
// This line is needed by the module loader to actually find your module.
W_LOADABLE_MODULE( WMButterfly )
float WMButterfly::w = 0.0f,
WMButterfly::factor[4][7] = {{0.75f, 5.0f/12.0f, -1.0f/12.0f, -1.0f/12.0f, 0.0f, 0.0f, 0.0f}, //NOLINT
{0.75f, 3.0f/8.0f, -1.0f/8.0f, 0.0f, -1.0f/8.0f, 0.0f, 0.0f},//NOLINT
{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},//NOLINT
{0.5f-w, 0.0f, 0.125f+2*w, -0.0625f-w, w, -0.0625f-w, 0.125f+2*w}},//NOLINT
WMButterfly::s1 = 9.0f / 16.0f,
WMButterfly::s2 = -1.0f / 16.0f;
WMButterfly::WMButterfly() :
WModule(), m_propCondition( new WCondition() )
{
......@@ -76,7 +68,7 @@ const char** WMButterfly::getXPMIcon() const
const std::string WMButterfly::getName() const
{
return "[Proj.] Butterfly";
return "Butterfly subdivision";
}
const std::string WMButterfly::getDescription() const
......@@ -172,5 +164,31 @@ void WMButterfly::moduleMain()
// ---> Insert code doing the real stuff here
}
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
}
boost::shared_ptr< WTriangleMesh > WMButterfly::popUnusedVertices( boost::shared_ptr< WTriangleMesh > inputMesh )
{
boost::shared_ptr<WTriangleMesh> outputMesh( new WTriangleMesh( 0, 0 ) );
size_t triCount = 0;
boost::shared_ptr<WTriangleMesh> tmpMesh( new WTriangleMesh( 0, 0 ) );
try
{
while (true)
{
Vec3 point0 = inputMesh->getVertex( mesh->getTriVertId0( triCount ) );
Vec3 point1 = inputMesh->getVertex( mesh->getTriVertId1( triCount ) );
Vec3 point2 = inputMesh->getVertex( mesh->getTriVertId2( triCount ) );
outputMesh->addTriangle( point0, point1, point2 );
triCount++;
}
} catch( ... )
{
}
return inputMesh;
}
......@@ -69,6 +69,8 @@ protected:
/**Entry point after loading the module. Runs in separate thread.*/
virtual void moduleMain();
virtual boost::shared_ptr< WTriangleMesh > popUnusedVertices( boost::shared_ptr< WTriangleMesh > inputMesh );
/**Initialize the connectors this module is using.*/
virtual void connectors();
......@@ -96,8 +98,6 @@ private:
boost::shared_ptr< WTriangleMesh > mesh;
butterfly::VertexFactory* verts;
static float w, factor[4][7], s1, s2;
butterfly::ButterflyFactory* butterfly;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment