Commit eda49bf2 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD #305] added getter for the other fiber parameters like color, tangent to the point iterator

parent 37243fb2
......@@ -494,6 +494,16 @@ WFiberPointsIterator WFiberIterator::rend()
return WFiberPointsIterator( m_fibers, m_index, numPoints(), true );
}
std::size_t WFiberIterator::getLineStartIndex() const
{
return m_fibers->getLineStartIndexes()->operator[]( getIndex() );
}
std::size_t WFiberIterator::getIndex() const
{
return m_index;
}
WFiberPointsIterator::WFiberPointsIterator()
: m_fibers( NULL ),
m_fiberIndex( 0 ),
......@@ -563,7 +573,7 @@ WFiberPointsIterator WFiberPointsIterator::operator--( int )
return t;
}
osg::Vec3 WFiberPointsIterator::operator*()
std::size_t WFiberPointsIterator::getBaseIndex() const
{
WAssert( m_fibers, "" );
WAssert( m_fiberIndex < m_fibers->getLineLengths()->size(), "" );
......@@ -574,8 +584,13 @@ osg::Vec3 WFiberPointsIterator::operator*()
{
i = m_fibers->getLineLengths()->operator[] ( m_fiberIndex ) - i - 1;
}
std::size_t v = m_fibers->getLineStartIndexes()->operator[] ( m_fiberIndex ) + i;
return osg::Vec3( m_fibers->getVertices()->operator[]( 3 * v + 0 ),
return m_fibers->getLineStartIndexes()->operator[] ( m_fiberIndex ) + i;
}
WPosition WFiberPointsIterator::operator*()
{
std::size_t v = getBaseIndex();
return WPosition( m_fibers->getVertices()->operator[]( 3 * v + 0 ),
m_fibers->getVertices()->operator[]( 3 * v + 1 ),
m_fibers->getVertices()->operator[]( 3 * v + 2 ) );
}
......@@ -595,3 +610,72 @@ bool WFiberPointsIterator::operator!=( WFiberPointsIterator const& rhs ) const
return !( this->operator==( rhs ) );
}
double WFiberPointsIterator::getParameter( double def ) const
{
if( m_fibers->getVertexParameters() )
{
return m_fibers->getVertexParameters()->operator[]( getBaseIndex() );
}
return def;
}
WPosition WFiberPointsIterator::getTangent() const
{
std::size_t v = getBaseIndex();
return WPosition( m_fibers->getTangents()->operator[]( 3 * v + 0 ),
m_fibers->getTangents()->operator[]( 3 * v + 1 ),
m_fibers->getTangents()->operator[]( 3 * v + 2 ) );
}
WColor WFiberPointsIterator::getColor( const boost::shared_ptr< WDataSetFibers::ColorScheme > scheme ) const
{
std::size_t v = getBaseIndex();
WColor ret;
switch( scheme->getMode() )
{
case WDataSetFibers::ColorScheme::GRAY:
{
double r = scheme->getColor()->operator[]( 1 * v + 0 );
ret.set( r, r, r, 1.0 );
}
break;
case WDataSetFibers::ColorScheme::RGB:
{
double r = scheme->getColor()->operator[]( 3 * v + 0 );
double g = scheme->getColor()->operator[]( 3 * v + 1 );
double b = scheme->getColor()->operator[]( 3 * v + 2 );
ret.set( r, g, b, 1.0 );
}
break;
case WDataSetFibers::ColorScheme::RGBA:
{
double r = scheme->getColor()->operator[]( 4 * v + 0 );
double g = scheme->getColor()->operator[]( 4 * v + 1 );
double b = scheme->getColor()->operator[]( 4 * v + 2 );
double a = scheme->getColor()->operator[]( 4 * v + 3 );
ret.set( r, g, b, a );
}
break;
default:
ret.set( 1.0, 1.0, 1.0, 1.0 );
break;
}
return ret;
}
WColor WFiberPointsIterator::getColor() const
{
return getColor( m_fibers->getColorScheme() );
}
WColor WFiberPointsIterator::getColor( std::size_t idx ) const
{
return getColor( m_fibers->getColorScheme( idx ) );
}
WColor WFiberPointsIterator::getColor( std::string name ) const
{
return getColor( m_fibers->getColorScheme( name ) );
}
......@@ -601,6 +601,27 @@ public:
*/
std::size_t numPoints() const;
/**
* Get the index in the point array where the points data starts for this line. You can use \ref numPoints to know how much data to read
* from the vertex array.
*
* \note You should avoid using these indices as can use the iterators to query the data. But it might get handy in some situations,
* where raw data processing is needed.
*
* \return the start index.
*/
std::size_t getLineStartIndex() const;
/**
* Get the index of the line.
*
* \note You should avoid using these indices as can use the iterators to query the data. But it might get handy in some situations,
* where raw data processing is needed.
*
* \return the index.
*/
std::size_t getIndex() const;
private:
//! The pointer to the fibers.
WDataSetFibers const* m_fibers;
......@@ -664,7 +685,7 @@ public:
/**
* Decrement operator. Makes the iterator point to the previous point.
*
*3
* \return The incremented iterator.
*/
WFiberPointsIterator& operator-- ();
......@@ -706,7 +727,75 @@ public:
*
* \return The current coordinates.
*/
osg::Vec3 operator* ();
WPosition operator* ();
/**
* Returns the parameter specified in the vertex parameter array of the dataset. If no such array was set, the specified default will be
* returned.
*
* \param def the default value which will be returned if no vertex parameter array was defined.
*
* \return the value or the specified default
*/
double getParameter( double def = 0.0 ) const;
/**
* The tangent of the point.
*
* \return the tangent
*/
WPosition getTangent() const;
/**
* Return the color of the point.
*
* \return the color.
*/
WColor getColor() const;
/**
* Return the color of the point.
*
* \param idx the index of the colorscheme to use.
*
* \throw WDHNoSuchDataSet if the colorscheme does not exist.
*
* \return the color.
*/
WColor getColor( std::size_t idx ) const;
/**
* Return the color of the point.
*
* \param name the name of the colorscheme to use.
*
* \throw WDHNoSuchDataSet if the colorscheme does not exist.
*
* \return the color.
*/
WColor getColor( std::string name ) const;
/**
* Return the color of the point.
*
* \param scheme the colorscheme to use.
*
* \throw WDHNoSuchDataSet if the colorscheme does not exist.
*
* \return the color.
*/
WColor getColor( const boost::shared_ptr< WDataSetFibers::ColorScheme > scheme ) const;
protected:
/**
* Calculates the index of this point in the dataset arrays. But be aware that this index works vertex-wise. This mens, getting the y
* coordinate of the vertex in the dataset vertex array, use 3 * getBaseIndex() + 1. This depends on the type of array you like to query.
*
* \note this function properly handles the case when walking in reverse direction.
*
* \return the base index, vertex-wise.
*/
std::size_t getBaseIndex() const;
private:
//! The pointer to the fibers.
......
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