Commit 4b8f481e authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD #157] checked that the fiber clustering really works and now it displays...

[ADD #157] checked that the fiber clustering really works and now it displays also some fibers... this is just a proof of concept hack ATM! So do not relay on that
parent 316a7059
......@@ -62,9 +62,9 @@ public:
void merge( WFiberCluster &other ); // NOLINT
/**
* Returns a copy of all indices inside this cluster
* Returns a const reference of all indices inside this cluster
*/
const std::list< size_t > getIndices() const;
const std::list< size_t >& getIndices() const;
/**
* Find the minimal distance for any pair of fibers where one fiber is
......@@ -181,7 +181,7 @@ inline bool WFiberCluster::operator!=( const WFiberCluster& other ) const
return m_memberIndices != other.m_memberIndices;
}
inline const std::list< size_t > WFiberCluster::getIndices() const
inline const std::list< size_t >& WFiberCluster::getIndices() const
{
return m_memberIndices;
}
......
......@@ -25,6 +25,7 @@
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <string>
#include <vector>
......@@ -37,6 +38,7 @@
#include "../../common/WColor.h"
#include "../../common/WLogger.h"
#include "../../common/WStatusReport.h"
#include "../../common/WStringUtils.hpp"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WDataSetFibers.h"
......@@ -122,6 +124,11 @@ void WMFiberClustering::cluster()
{
m_dLtTable.reset( new WDXtLookUpTable( numFibers ) );
}
m_proximity_t = 1.0;
std::cout << "Proximity threshold: " << m_proximity_t << std::endl;
m_maxDistance_t = 6.5;
std::cout << "Maximum inter cluster distance threshold: " << m_maxDistance_t << std::endl;
WStatusReport st( numFibers );
WDLTMetric dLt( m_proximity_t * m_proximity_t ); // metric instance for computation of the dLt measure
for( size_t i = 0; i < numFibers; ++i ) // loop over all "symmetric" fibers pairs
......@@ -159,7 +166,10 @@ void WMFiberClustering::cluster()
}
}
}
std::cout << "\r" << std::fixed << std::setprecision( 2 );
std::cout << ( ++st ).progress() << " " << st.stringBar() << std::flush;
}
std::cout << std::endl;
m_dLtTableExists = true;
// remove empty clusters
......@@ -187,6 +197,49 @@ void WMFiberClustering::cluster()
m_lastFibsSize = m_fibs->size();
}
osg::ref_ptr< osg::Geode > WMFiberClustering::genFiberGeode( const WFiberCluster &cluster, const WColor color ) const
{
using osg::ref_ptr;
ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >( new osg::Geometry );
std::list< size_t >::const_iterator cit = cluster.getIndices().begin();
for( ; cit != cluster.getIndices().end(); ++cit )
{
const wmath::WFiber &fib = (*m_fibs)[ *cit ];
for( size_t i = 0; i < fib.size(); ++i )
{
vertices->push_back( osg::Vec3( fib[i][0], fib[i][1], fib[i][2] ) );
}
geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, vertices->size() - fib.size(), fib.size() ) );
}
geometry->setVertexArray( vertices );
ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
colors->push_back( color.getOSGColor() );
geometry->setColorArray( colors );
geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >( new osg::Geode );
geode->addDrawable( geometry.get() );
return geode;
}
void WMFiberClustering::paint()
{
double hue = 0.0;
double hue_increment = 1.0 / m_clusters.size();
WColor color;
std::cout << "cluster: " << m_clusters.size() << std::endl;
osg::ref_ptr< osg::Group > group = osg::ref_ptr< osg::Group >( new osg::Group );
for( size_t i = 0; i < m_clusters.size(); ++i, hue += hue_increment )
{
color.setHSV( hue, 1.0, 0.75 );
group->addChild( genFiberGeode( m_clusters[i], color ).get() );
}
group->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( group.get() );
}
......@@ -87,6 +87,8 @@ private:
*/
void cluster();
osg::ref_ptr< osg::Geode > genFiberGeode( const WFiberCluster &cluster, const WColor color ) const;
/**
* Choose colors and build and commit new FgePrimitve
*/
......@@ -149,7 +151,7 @@ private:
inline const std::string WMFiberClustering::getName() const
{
return std::string( "FiberClustering" );
return std::string( "Fiber Clustering Module" );
}
inline const std::string WMFiberClustering::getDescription() const
......
......@@ -109,7 +109,10 @@ void WMFiberCulling::cullOutFibers( boost::shared_ptr< WDataSetFibers > fibers )
fibers->sortDescLength(); // sort the fiber on their length (biggest first)
std::cout << "Sorted fibers done." << std::endl;
m_proximity_t = 1.0;
std::cout << "Proximity threshold: " << m_proximity_t << std::endl;
m_dSt_culling_t = 6.5;
std::cout << "Culling threshold: " << m_dSt_culling_t << std::endl;
std::vector< bool > unusedFibers( numFibers, false );
WDSTMetric dSt( m_proximity_t * m_proximity_t );
WStatusReport st( numFibers );
......
......@@ -104,7 +104,7 @@ private:
inline const std::string WMFiberCulling::getName() const
{
return std::string( "FiberCulling" );
return std::string( "Fiber Culling Module" );
}
inline const std::string WMFiberCulling::getDescription() const
......
......@@ -96,26 +96,55 @@ osg::ref_ptr< osg::Geode > WMFiberDisplay::genFiberGeode(
void WMFiberDisplay::moduleMain()
{
ready();
while( !m_FinishRequested )
// ready();
// while( !m_FinishRequested )
// {
// if( m_fiberInput->getData() != boost::shared_ptr< const WDataSetFibers >() )
// {
// boost::shared_ptr< const WDataSetFibers > fiberDS = m_fiberInput->getData();
//
// osg::ref_ptr< osg::Group > group = osg::ref_ptr< osg::Group >( new osg::Group );
// group->addChild( genFiberGeode( fiberDS, false ).get() );
// group->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
//
// WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( group.get() );
// }
// // TODO(math): implement some redraw if data has changed
// // - replacing the OSG group node?
// // - using notifyDataChange() method
// while( !m_FinishRequested )
// {
// sleep( 1 );
// }
// }
boost::shared_ptr< WDataHandler > dataHandler;
// TODO(math): fix this hack when possible by using an input connector.
while( !WKernel::getRunningKernel() )
{
if( m_fiberInput->getData() != boost::shared_ptr< const WDataSetFibers >() )
{
boost::shared_ptr< const WDataSetFibers > fiberDS = m_fiberInput->getData();
sleep( 1 );
}
while( !( dataHandler = WKernel::getRunningKernel()->getDataHandler() ) )
{
sleep( 1 );
}
while( !dataHandler->getNumberOfSubjects() )
{
sleep( 1 );
}
osg::ref_ptr< osg::Group > group = osg::ref_ptr< osg::Group >( new osg::Group );
group->addChild( genFiberGeode( fiberDS, false ).get() );
group->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
boost::shared_ptr< const WDataSetFibers > fiberDS;
assert( fiberDS = boost::shared_dynamic_cast< const WDataSetFibers >( dataHandler->getSubject( 0 )->getDataSet( 0 ) ) );
osg::ref_ptr< osg::Group > group = osg::ref_ptr< osg::Group >( new osg::Group );
group->addChild( genFiberGeode( fiberDS, false ).get() );
group->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( group.get() );
}
// TODO(math): implement some redraw if data has changed
// - replacing the OSG group node?
// - using notifyDataChange() method
while( !m_FinishRequested )
{
sleep( 1 );
}
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( group.get() );
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
{
// do fancy stuff
sleep( 1 );
}
}
......
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