29 #include <boost/shared_ptr.hpp>
31 #include "../../common/math/WMath.h"
32 #include "../../common/math/WPlane.h"
33 #include "../../common/WLimits.h"
34 #include "../../common/WTransferable.h"
35 #include "../WDataSetFiberVector.h"
36 #include "WFiberCluster.h"
43 m_centerLineCreationLock( new boost::shared_mutex() ),
44 m_longestLineCreationLock( new boost::shared_mutex() )
50 m_centerLineCreationLock( new boost::shared_mutex() ),
51 m_longestLineCreationLock( new boost::shared_mutex() )
58 m_memberIndices( indices ),
60 m_centerLineCreationLock( new boost::shared_mutex() ),
61 m_longestLineCreationLock( new boost::shared_mutex() )
70 m_centerLineCreationLock( new boost::shared_mutex() ),
71 m_longestLineCreationLock( new boost::shared_mutex() )
79 m_memberIndices( other.m_memberIndices ),
80 m_fibs( other.m_fibs ),
81 m_color( other.m_color ),
82 m_centerLineCreationLock( new boost::shared_mutex() ),
84 m_longestLineCreationLock( new boost::shared_mutex() ),
107 WFiberCluster::IndexList::const_iterator cit = other.
m_memberIndices.begin();
127 void WFiberCluster::setDataSetReference( boost::shared_ptr< const WDataSetFiberVector > fibs )
132 boost::shared_ptr< const WDataSetFiberVector > WFiberCluster::getDataSetReference()
const
154 boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( *m_centerLineCreationLock );
164 size_t avgFiberSize = 0;
167 fibs->push_back(
m_fibs->at( *cit ) );
168 avgFiberSize += fibs->back().size();
170 avgFiberSize /= fibs->size();
176 cit->resampleByNumberOfPoints( avgFiberSize );
181 for(
size_t i = 0; i < avgFiberSize; ++i )
186 avgPosition += cit->at( i );
188 avgPosition /=
static_cast< double >( fibs->size() );
199 boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( *m_longestLineCreationLock );
216 size_t longestID = 0;
217 for(
size_t cit = 0; cit <
m_fibs->size(); ++cit )
219 if(
m_fibs->at( cit ).size() > longest )
221 longest =
m_fibs->at( cit ).size();
239 WPlane p( cL[0] - cL[1], cL[0] + ( cL[0] - cL[1] ) );
240 boost::shared_ptr< WPosition > cutPoint(
new WPosition( 0, 0, 0 ) );
241 bool intersectionFound =
true;
247 fibs->push_back(
m_fibs->at( *cit ) );
250 while( intersectionFound )
252 intersectionFound =
false;
253 size_t intersectingFibers = 0;
257 if( intersectPlaneLineNearCP( p, *cit, cutPoint ) )
262 intersectingFibers++;
263 intersectionFound =
true;
268 cit = fibs->erase( cit );
273 cit = fibs->erase( cit );
276 if( intersectingFibers > 10 )
278 cL.insert( cL.begin(), cL[0] + ( cL[0] - cL[1] ) );
296 fobs->push_back(
m_fibs->at( *cit ) );
301 WPlane q( cL.back() - cL[ cL.size() - 2 ], cL.back() + ( cL.back() - cL[ cL.size() - 2 ] ) );
302 intersectionFound =
true;
303 while( intersectionFound )
305 intersectionFound =
false;
306 size_t intersectingFibers = 0;
310 if( intersectPlaneLineNearCP( q, *cit, cutPoint ) )
315 intersectingFibers++;
316 intersectionFound =
true;
321 cit = fobs->erase( cit );
326 cit = fobs->erase( cit );
329 if( intersectingFibers > 10 )
331 cL.push_back( cL.back() + ( cL.back() - cL[ cL.size() - 2 ] ) );
332 q.
resetPosition( cL.back() + ( cL.back() - cL[ cL.size() - 2 ] ) );
350 if( fibs->size() < 2 )
355 assert( !( fibs->at( 0 ).empty() ) &&
"WFiberCluster.unifyDirection: Empty fiber processed.. aborting" );
366 const WFiber& other = *cit;
367 double distance = length2( start - other.
front() ) +
368 length2( m1 - other.
at( other.
size() * 1.0 / 3.0 ) ) +
369 length2( m2 - other.
at( other.
size() * 2.0 / 3.0 ) ) +
370 length2( end - other.
back() );
371 double inverseDistance = length2( start - other.
back() ) +
372 length2( m1 - other.
at( other.
size() * 2.0 / 3.0 ) ) +
373 length2( m2 - other.
at( other.
size() * 1.0 / 3.0 ) ) +
374 length2( end - other.
front() );
376 inverseDistance /= 4.0;
377 if( inverseDistance < distance )
virtual ~WFiberCluster()
Destructs.
Represents a neural pathway.
vector_type::const_iterator const_iterator
Compares to std::vector type.
boost::shared_ptr< WFiber > m_centerLine
Average fiber for this cluster representing the main direction and curvature of this cluster...
const_reference at(size_type index) const
Wrapper around std::vector member function.
void elongateCenterLine() const
The centerline may be shortened due to the averaging of outliers.
void expandBy(const WBoundingBoxImpl< VT > &bb)
Expands this bounding box to include the given bounding box.
Represents a cluster of indices of a WDataSetFiberVector.
boost::shared_ptr< WFiber > getCenterLine() const
Returns the center line of this cluster.
std::list< size_t > IndexList
This is the list of indices of fibers.
boost::shared_mutex * m_centerLineCreationLock
Lock the modification in the m_centerLine mutable.
vector_type::iterator iterator
Compares to std::vector type.
This only is a 3d double vector.
Represents a simple set of WFibers.
WBoundingBox getBoundingBox() const
Recomputes on every call the axis aligned bounding box incorporating all tracts in this cluster...
Represents a plane with a normal vector and a position in space.
const WPosition & getPosition() const
Returns a point in that plane.
void resetPosition(WPosition newPos)
Reset the position of the plane, normal remains the same.
void merge(WFiberCluster &other)
Merge the fibers of the other cluster with the fibers of this cluster.
Class building the interface for classes that might be transferred using WModuleConnector.
IndexList m_memberIndices
All indices in this set are members of this cluster.
void unifyDirection(boost::shared_ptr< WDataSetFiberVector > fibs) const
Alings all fibers within the given dataset to be in one main direction.
const_reference front() const
Wrapper around std::vector member function.
void clear()
Make this cluster empty.
void generateCenterLine() const
Makes the hard work to compute the center line.
boost::shared_ptr< WFiber > m_longestLine
The longest fiber in the dataset.
static boost::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
boost::shared_mutex * m_longestLineCreationLock
Lock the modification in the m_longestLine mutable.
void generateLongestLine() const
Makes the hard work to find the longest line.
static boost::shared_ptr< WPrototyped > m_prototype
Prototype for this dataset.
boost::shared_ptr< WFiber > getLongestLine() const
Returns the center line of this cluster.
const_reference back() const
Wrapper around std::vector member function.
boost::shared_ptr< const WDataSetFiberVector > m_fibs
Reference to the real fibers of the brain this cluster belongs to.
IndexList::const_iterator IndexListConstIterator
Const iterator on the index list.
size_type size() const
Wrapper around std::vector member function.
WFiberCluster()
Constructs an empty cluster.