Commit 560ddef6 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] added extended fiber-attribution. You can define an arbitrary amount of...

[ADD] added extended fiber-attribution. You can define an arbitrary amount of per-vertex and per-fiber attributes now.
parent 7959ea0a
......@@ -96,7 +96,7 @@ WDataSetFibers::WDataSetFibers( WDataSetFibers::VertexArray vertices,
m_lineLengths( lineLengths ),
m_verticesReverse( verticesReverse ),
m_bb( boundingBox ),
m_vertexParameters( vertexParameters )
m_vertexParameters( 1, vertexParameters )
{
WAssert( m_vertices->size() % 3 == 0, "Invalid vertex array." );
init();
......@@ -112,7 +112,7 @@ WDataSetFibers::WDataSetFibers( WDataSetFibers::VertexArray vertices,
m_lineStartIndexes( lineStartIndexes ),
m_lineLengths( lineLengths ),
m_verticesReverse( verticesReverse ),
m_vertexParameters( vertexParameters )
m_vertexParameters( 1, vertexParameters )
{
WAssert( m_vertices->size() % 3 == 0, "Invalid vertex array." );
// determine bounding box
......@@ -326,9 +326,24 @@ const WPropSelection WDataSetFibers::getColorSchemeProperty() const
return m_colorProp;
}
WDataSetFibers::VertexParemeterArray WDataSetFibers::getVertexParameters() const
WDataSetFibers::VertexParemeterArray WDataSetFibers::getVertexParameters( size_t parameterIndex ) const
{
return m_vertexParameters;
return m_vertexParameters[ parameterIndex ];
}
void WDataSetFibers::setVertexParameters( std::vector< WDataSetFibers::VertexParemeterArray > parameters )
{
m_vertexParameters = parameters;
}
WDataSetFibers::LineParemeterArray WDataSetFibers::getLineParameters( size_t parameterIndex ) const
{
return m_lineParameters[ parameterIndex ];
}
void WDataSetFibers::setLineParameters( std::vector< WDataSetFibers::LineParemeterArray > parameters )
{
m_lineParameters = parameters;
}
WPosition WDataSetFibers::getPosition( size_t fiber, size_t vertex ) const
......@@ -733,12 +748,12 @@ WFiberPointsIterator::operator bool() const
return m_fibers != NULL && m_fiberIndex < m_fibers->size() && m_index < m_fibers->getLengthOfLine( m_fiberIndex );
}
double WFiberPointsIterator::getParameter( double def ) const
double WFiberPointsIterator::getParameter( double def, size_t parameterIndex ) const
{
// TODO(reichenbach): change this to avoid the copy of a shared_ptr
if( m_fibers->getVertexParameters() )
if( m_fibers->getVertexParameters( parameterIndex ) )
{
return m_fibers->getVertexParameters()->operator[]( getBaseIndex() );
return m_fibers->getVertexParameters( parameterIndex )->operator[]( getBaseIndex() );
}
return def;
}
......
......@@ -98,6 +98,11 @@ public:
*/
typedef boost::shared_ptr< std::vector< double > > VertexParemeterArray;
/**
* Parameter storage for each line.
*/
typedef boost::shared_ptr< std::vector< double > > LineParemeterArray;
/**
* Iterator to go through the fibers.
*/
......@@ -321,8 +326,33 @@ public:
* Get the parameter values for each vertex. Same indexing as vertices. Used to store additional scalar values for each vertex.
*
* \return the array. Can be NULL.
*
* \param parameterIndex there can be multiple parameters. The index defines the index of the parameter array to get. Default is 0.
*/
VertexParemeterArray getVertexParameters() const;
VertexParemeterArray getVertexParameters( size_t parameterIndex = 0 ) const;
/**
* Set the given array of parameters to be the vertex parameters of this fiber dataset.
*
* \param parameters the list of parameters. Can be an empty vector to remove parameters.
*/
void setVertexParameters( std::vector< VertexParemeterArray > parameters );
/**
* Get the parameter values for each line. Same indexing as lines. Used to store additional scalar values for each line.
*
* \return the array. Can be NULL.
*
* \param parameterIndex there can be multiple parameters. The index defines the index of the parameter array to get. Default is 0.
*/
LineParemeterArray getLineParameters( size_t parameterIndex = 0 ) const;
/**
* Set an array to be the list of line parameters.
*
* \param parameters the list of parameters. Can be an empty vector to remove parameters.
*/
void setLineParameters( std::vector< LineParemeterArray > parameters );
/**
* This method adds a new color scheme to the list of available colors. The color scheme needs to have a name and description to allow the
......@@ -519,9 +549,14 @@ private:
WBoundingBox m_bb;
/**
* Parameter array. Used to store additional scalar values for each vertex.
* Parameter array. Used to store additional scalar values for each vertex. Multiple parameter arrays allowed.
*/
std::vector< VertexParemeterArray > m_vertexParameters;
/**
* Parameter array. Used to store additional scalar values for each line. Multiple parameter arrays allowed.
*/
VertexParemeterArray m_vertexParameters;
std::vector< LineParemeterArray > m_lineParameters;
};
/**
......@@ -989,10 +1024,11 @@ public:
* returned.
*
* \param def the default value which will be returned if no vertex parameter array was defined.
* \param parameterIndex the parameter to get.
*
* \return the value or the specified default
*/
double getParameter( double def = 0.0 ) const;
double getParameter( double def = 0.0, size_t parameterIndex = 0 ) const;
/**
* The tangent of the point.
......
......@@ -25,6 +25,10 @@
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/foreach.hpp>
#include "core/kernel/WKernel.h"
#include "core/kernel/WDataModuleInputFile.h"
......@@ -176,6 +180,8 @@ void WMReadSimpleTextLineData::load()
std::vector< WVector3f > loadedVertices;
typedef std::vector< size_t > LineStrip;
std::vector< LineStrip > loadedLineStrips;
std::map< size_t, std::vector< double > > loadedPointAttribs;
std::map< size_t, std::vector< double > > loadedLineAttribs;
while( !ifs.eof() )
{
......@@ -205,6 +211,7 @@ void WMReadSimpleTextLineData::load()
loadedVertices.push_back( coord );
}
// It is a line.
if( string_utils::toLower( tokens[0] ) == "l" )
{
LineStrip ls;
......@@ -219,6 +226,20 @@ void WMReadSimpleTextLineData::load()
// NOTE: a lot of copying, but when considering overall bad performance of hard disk IO vs RAM ...
loadedLineStrips.push_back( ls );
}
// It is a point attribute.
if( string_utils::toLower( tokens[0] ) == "pa" )
{
size_t attrIdx = string_utils::fromString< size_t >( tokens[1] );
loadedPointAttribs[ attrIdx ].push_back( string_utils::fromString< float >( tokens[2] ) );
}
// It is a line attribute.
if( string_utils::toLower( tokens[0] ) == "la" )
{
size_t attrIdx = string_utils::fromString< size_t >( tokens[1] );
loadedLineAttribs[ attrIdx ].push_back( string_utils::fromString< float >( tokens[2] ) );
}
}
// As the DataSetFibers uses run-length encoded linestrips, we need to transform the stuff now.
......@@ -228,8 +249,43 @@ void WMReadSimpleTextLineData::load()
WDataSetFibers::LengthArray lengths( new WDataSetFibers::LengthArray::element_type() );
WDataSetFibers::IndexArray lineStartIndices( new WDataSetFibers::IndexArray::element_type() );
WDataSetFibers::IndexArray verticesReverse( new WDataSetFibers::IndexArray::element_type() );
// WDataSetFibers::VertexParemeterArray attribs( new WDataSetFibers::VertexParemeterArray::element_type() );
std::vector< WDataSetFibers::VertexParemeterArray > pAttribs;
std::vector< WDataSetFibers::LineParemeterArray > lAttribs;
for( std::map< size_t, std::vector< double > >::const_iterator i = loadedLineAttribs.begin(); i != loadedLineAttribs.end(); ++i )
{
size_t desiredSize = loadedLineStrips.size();
size_t realSize = ( *i ).second.size();
if( desiredSize != realSize )
{
warnLog() << "Ignoring line attribute " << ( *i ).first << " as there are too few/too much items.";
}
// Create and copy
boost::shared_ptr< WDataSetFibers::LineParemeterArray::element_type > vec(
new WDataSetFibers::LineParemeterArray::element_type( realSize ) );
std::copy( ( *i ).second.begin(), ( *i ).second.end(), vec->begin() );
lAttribs.push_back( vec );
}
for( std::map< size_t, std::vector< double > >::const_iterator i = loadedPointAttribs.begin(); i != loadedPointAttribs.end(); ++i )
{
size_t desiredSize = loadedVertices.size();
size_t realSize = ( *i ).second.size();
if( desiredSize != realSize )
{
warnLog() << "Ignoring point attribute " << ( *i ).first << " as there are too few/too much items.";
}
// Create and copy
boost::shared_ptr< WDataSetFibers::VertexParemeterArray::element_type > vec(
new WDataSetFibers::VertexParemeterArray::element_type( realSize ) );
std::copy( ( *i ).second.begin(), ( *i ).second.end(), vec->begin() );
pAttribs.push_back( vec );
}
size_t currentStartIndex = 0;
// For each lineStrip, we need to add vertices and fill the run-lenght info in lengths and lineStartIndices.
......@@ -260,12 +316,17 @@ void WMReadSimpleTextLineData::load()
currentStartIndex += ls.size();
}
m_output->updateData( WDataSetFibers::SPtr( new WDataSetFibers( vertices, lineStartIndices, lengths, verticesReverse, bb ) ) );
WDataSetFibers::SPtr ds( new WDataSetFibers( vertices, lineStartIndices, lengths, verticesReverse, bb ) );
ds->setVertexParameters( pAttribs );
ds->setLineParameters( lAttribs );
m_output->updateData( ds );
// done. close file and report finish
progress1->finish();
ifs.close();
infoLog() << "Loaded " << loadedLineStrips.size() << " line strips from file. Done.";
infoLog() << "Loaded " << loadedLineStrips.size() << " line strips from file, having " << pAttribs.size() << " point attributes and "
<< lAttribs.size() << " line attributes. Done.";
}
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