Commit 7443b377 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[FIX #287] added boundixbox for fibers. It is computed while loading but

does not seem to slow it down too much.
parent 1fee9273
......@@ -24,6 +24,7 @@
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <iostream>
#include <boost/filesystem/fstream.hpp>
......@@ -48,13 +49,16 @@ WDataSetFibers::WDataSetFibers()
WDataSetFibers::WDataSetFibers( boost::shared_ptr< std::vector< float > >vertices,
boost::shared_ptr< std::vector< size_t > > lineStartIndexes,
boost::shared_ptr< std::vector< size_t > > lineLengths,
boost::shared_ptr< std::vector< size_t > > verticesReverse )
boost::shared_ptr< std::vector< size_t > > verticesReverse,
std::pair< wmath::WPosition, wmath::WPosition > boundingBox )
: WDataSet(),
m_vertices( vertices ),
m_localColors( boost::shared_ptr< std::vector< float > >() ),
m_lineStartIndexes( lineStartIndexes ),
m_lineLengths( lineLengths ),
m_verticesReverse( verticesReverse )
m_verticesReverse( verticesReverse ),
m_bbMin( boundingBox.first ),
m_bbMax( boundingBox.second )
{
m_tangents = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
......@@ -293,3 +297,8 @@ void WDataSetFibers::saveSelected( std::string filename, boost::shared_ptr< std:
ofs << vBuffer[i];
}
}
std::pair< wmath::WPosition, wmath::WPosition > WDataSetFibers::getBoundingBox() const
{
return std::make_pair( m_bbMin, m_bbMax );
}
......@@ -26,6 +26,7 @@
#define WDATASETFIBERS_H
#include <string>
#include <utility>
#include <vector>
#include <boost/shared_ptr.hpp>
......@@ -65,11 +66,13 @@ public:
* \param lineStartIndexes the index in which the fiber start (index of the 3D-vertex, not the index of the float in the vertices vector)
* \param lineLengths how many vertices belong to a fiber
* \param verticesReverse stores for each vertex the index of the corresponding fiber
* \param boundingBox The bounding box of the fibers (first minimum, secon maximum). If not given both are (0,0,0).
*/
WDataSetFibers( boost::shared_ptr< std::vector< float > >vertices,
boost::shared_ptr< std::vector< size_t > > lineStartIndexes,
boost::shared_ptr< std::vector< size_t > > lineLengths,
boost::shared_ptr< std::vector< size_t > > verticesReverse );
boost::shared_ptr< std::vector< size_t > > verticesReverse,
std::pair< wmath::WPosition, wmath::WPosition > boundingBox = std::make_pair( wmath::WPosition(), wmath::WPosition() ) );
/**
* Constructs a new set of WFibers. The constructed instance is not usable.
......@@ -171,6 +174,12 @@ public:
* \param active bitfield of the fiber selection
*/
void saveSelected( std::string filename, boost::shared_ptr< std::vector< bool > > active ) const;
/**
* Get the bounding box as pair of WPositions.
*/
std::pair< wmath::WPosition, wmath::WPosition > getBoundingBox() const;
protected:
/**
......@@ -216,6 +225,9 @@ private:
* Reverse lookup table for which point belongs to which fiber
*/
boost::shared_ptr< std::vector< size_t > > m_verticesReverse;
wmath::WPosition m_bbMin; //!< Minimum position of bounding box of all fibers.
wmath::WPosition m_bbMax; //!< Maximum position of bounding box of all fibers.
};
#endif // WDATASETFIBERS_H
......@@ -30,6 +30,7 @@
#include <boost/shared_ptr.hpp>
#include "../../common/WIOTools.h"
#include "../../common/WLimits.h"
#include "../../common/WAssert.h"
#include "../../common/WLogger.h"
#include "../../common/WStringUtils.h"
......@@ -40,7 +41,9 @@
#include "WReaderFiberVTK.h"
WReaderFiberVTK::WReaderFiberVTK( std::string fname )
: WReader( fname )
: WReader( fname ),
m_bbMin( wmath::WPosition( wlimits::MAX_DOUBLE, wlimits::MAX_DOUBLE, wlimits::MAX_DOUBLE ) ),
m_bbMax( wmath::WPosition( -wlimits::MAX_DOUBLE, -wlimits::MAX_DOUBLE, -wlimits::MAX_DOUBLE ) )
{
}
......@@ -70,7 +73,8 @@ boost::shared_ptr< WDataSetFibers > WReaderFiberVTK::read()
boost::shared_ptr< WDataSetFibers > fibers = boost::shared_ptr< WDataSetFibers >( new WDataSetFibers( m_points,
m_fiberStartIndices,
m_fiberLengths,
m_pointFiberMapping ) );
m_pointFiberMapping,
std::make_pair( m_bbMin, m_bbMax ) ) );
fibers->setFileName( m_fname );
m_ifs->close();
......@@ -129,6 +133,16 @@ void WReaderFiberVTK::readPoints()
m_points = boost::shared_ptr< std::vector< float > >( new std::vector< float >( pointData, pointData + 3 * numPoints ) );
WAssert( m_points->size() % 3 == 0, "Number of floats for coordinates not dividable by three." );
for( size_t i = 0; i < m_points->size()/3; ++i )
{
m_bbMin[0] = m_bbMin[0] < ( *m_points )[i*3+0] ? m_bbMin[0] : ( *m_points )[i*3+0];
m_bbMin[1] = m_bbMin[1] < ( *m_points )[i*3+1] ? m_bbMin[1] : ( *m_points )[i*3+1];
m_bbMin[2] = m_bbMin[2] < ( *m_points )[i*3+2] ? m_bbMin[2] : ( *m_points )[i*3+2];
m_bbMax[0] = m_bbMax[0] > ( *m_points )[i*3+0] ? m_bbMax[0] : ( *m_points )[i*3+0];
m_bbMax[1] = m_bbMax[1] > ( *m_points )[i*3+1] ? m_bbMax[1] : ( *m_points )[i*3+1];
m_bbMax[2] = m_bbMax[2] > ( *m_points )[i*3+2] ? m_bbMax[2] : ( *m_points )[i*3+2];
}
delete[] pointData;
// since we know here the size of the vector we may allocate it right here
......
......@@ -122,6 +122,9 @@ private:
*/
std::string getLine( const std::string& desc );
wmath::WPosition m_bbMin; //!< Minimum position of bounding box of all fibers.
wmath::WPosition m_bbMax; //!< Maximum position of bounding box of all fibers.
/**
* Try to cast from the given string to the template value T. If the cast fails a
* WDHParseError is thrown.
......
......@@ -187,6 +187,12 @@ void WMFiberDisplay::create()
osg::ref_ptr< osg::Group > osgNodeNew = osg::ref_ptr< osg::Group >( new osg::Group );
m_tubeDrawable = osg::ref_ptr< WTubeDrawable >( new WTubeDrawable );
m_tubeDrawable->setBoundingBox( osg::BoundingBox( m_dataset->getBoundingBox().first[0],
m_dataset->getBoundingBox().first[1],
m_dataset->getBoundingBox().first[2],
m_dataset->getBoundingBox().second[0],
m_dataset->getBoundingBox().second[1],
m_dataset->getBoundingBox().second[2] ) );
m_tubeDrawable->setDataset( m_dataset );
m_tubeDrawable->setUseDisplayList( false );
m_tubeDrawable->setDataVariance( osg::Object::DYNAMIC );
......
......@@ -108,6 +108,11 @@ void WTubeDrawable::setCustomColoring( bool custom )
m_customColoring = custom;
}
void WTubeDrawable::setBoundingBox( const osg::BoundingBox & bb )
{
setBound( bb );
}
void WTubeDrawable::drawFibers( osg::RenderInfo& renderInfo ) const //NOLINT
{
boost::shared_ptr< std::vector< size_t > > startIndexes = m_dataset->getLineStartIndexes();
......
......@@ -125,6 +125,12 @@ public:
*/
bool getColoringMode() const;
/**
* Set the bounding box of all fibers.
* \param bb The new bounding box.
*/
void setBoundingBox( const osg::BoundingBox & bb );
protected:
private:
/**
......
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