Commit eba0f635 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD #156] Now global coloring is the default

parent c9d29bf8
......@@ -52,26 +52,46 @@ boost::shared_ptr< WModule > WMFiberDisplay::factory() const
return boost::shared_ptr< WModule >( new WMFiberDisplay() );
}
osg::ref_ptr< osg::Geode > WMFiberDisplay::genFiberGeode( const wmath::WFiber &fib ) const
osg::ref_ptr< osg::Geode > WMFiberDisplay::genFiberGeode( const wmath::WFiber &fib, bool globalColoring ) const
{
using osg::ref_ptr;
ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
vertices->push_back( osg::Vec3( fib[0][0], fib[0][1], fib[0][2] ) );
for( size_t i = 1; i < fib.size(); ++i )
if( !globalColoring )
{
vertices->push_back( osg::Vec3( fib[i][0], fib[i][1], fib[i][2] ) );
WColor c = color_utils::getRGBAColorFromDirection( wmath::WPosition( fib[i][0], fib[i][1], fib[i][2] ),
wmath::WPosition( fib[i-1][0], fib[i-1][1], fib[i-1][2] ) );
for( size_t i = 1; i < fib.size(); ++i )
{
vertices->push_back( osg::Vec3( fib[i][0], fib[i][1], fib[i][2] ) );
WColor c = color_utils::getRGBAColorFromDirection( fib[i], fib[i-1] );
colors->push_back( c.getOSGColor() );
}
colors->push_back( colors->back() );
}
else
{
for( size_t i = 1; i < fib.size(); ++i )
{
vertices->push_back( osg::Vec3( fib[i][0], fib[i][1], fib[i][2] ) );
}
WColor c = color_utils::getRGBAColorFromDirection( fib[0], fib[ fib.size() -1 ] );
colors->push_back( c.getOSGColor() );
}
colors->push_back( colors->back() );
ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >( new osg::Geometry );
geometry->setVertexArray( vertices );
geometry->setColorArray( colors );
geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
if( !globalColoring )
{
geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
}
else
{
geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
}
geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, fib.size() ) );
osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >( new osg::Geode );
geode->addDrawable( geometry.get() );
......
......@@ -81,7 +81,7 @@ protected:
* \param fib reference to a WFiber instance
* \return OSG geometry representing the fiber.
*/
osg::ref_ptr< osg::Geode > genFiberGeode( const wmath::WFiber &fib ) const;
osg::ref_ptr< osg::Geode > genFiberGeode( const wmath::WFiber &fib, bool globalColoring = true ) const;
private:
};
......
......@@ -44,9 +44,9 @@ class WMFiberDisplayTest : public CxxTest::TestSuite
public:
/**
* The OSG geometry of a WFiber instance should have either arrays for
* colors and vertices of the same size.
* colors and vertices of the same size if localColoring is selected.
*/
void testGeometryOfFiber( void )
void testGeometryOfFiberOnLocalColoring( void )
{
using wmath::WPosition;
std::vector< WPosition > fibData;
......@@ -57,11 +57,31 @@ public:
using wmath::WFiber;
WFiber fib( fibData );
WMFiberDisplay mod;
osg::ref_ptr< osg::Geode > result = mod.genFiberGeode( fib );
osg::ref_ptr< osg::Geode > result = mod.genFiberGeode( fib, false );
osg::Geometry *geo = result->getDrawable( 0 )->asGeometry();
TS_ASSERT_EQUALS( geo->getVertexArray()->getNumElements(), 4 );
TS_ASSERT_EQUALS( geo->getVertexArray()->getNumElements(), geo->getColorArray()->getNumElements() );
}
/**
* When global coloring is used, only one color should be there.
*/
void testGeometryOfFiberOnGlobalColoring( void )
{
using wmath::WPosition;
std::vector< WPosition > fibData;
fibData.push_back( WPosition( 0., 0., 0. ) );
fibData.push_back( WPosition( 1., 0., 0. ) );
fibData.push_back( WPosition( 1., 1., 0. ) );
fibData.push_back( WPosition( 1., 1., 1. ) );
using wmath::WFiber;
WFiber fib( fibData );
WMFiberDisplay mod;
osg::ref_ptr< osg::Geode > result = mod.genFiberGeode( fib );
osg::Geometry *geo = result->getDrawable( 0 )->asGeometry();
TS_ASSERT_EQUALS( geo->getVertexArray()->getNumElements(), 4 );
TS_ASSERT_EQUALS( 1, geo->getColorArray()->getNumElements() );
}
};
#endif // WMFIBERDISPLAY_TEST_H
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