32 #include "../../common/WLimits.h"
33 #include "../../common/WTransferable.h"
34 #include "../../common/math/WMath.h"
35 #include "../../common/math/WPlane.h"
36 #include "../WDataSetFiberVector.h"
37 #include "WFiberCluster.h"
44 m_centerLineCreationLock( new std::shared_mutex() ),
45 m_longestLineCreationLock( new std::shared_mutex() )
51 m_centerLineCreationLock( new std::shared_mutex() ),
52 m_longestLineCreationLock( new std::shared_mutex() )
59 m_memberIndices( indices ),
61 m_annotation( annotation ),
62 m_centerLineCreationLock( new std::shared_mutex() ),
63 m_longestLineCreationLock( new std::shared_mutex() )
71 std::string
const& annotation )
74 m_annotation( annotation ),
75 m_centerLineCreationLock( new std::shared_mutex() ),
76 m_longestLineCreationLock( new std::shared_mutex() )
84 m_memberIndices( other.m_memberIndices ),
85 m_fibs( other.m_fibs ),
86 m_color( other.m_color ),
87 m_annotation( other.m_annotation ),
88 m_centerLineCreationLock( new std::shared_mutex() ),
90 m_longestLineCreationLock( new std::shared_mutex() ),
113 WFiberCluster::IndexList::const_iterator cit = other.
m_memberIndices.begin();
133 void WFiberCluster::setDataSetReference( std::shared_ptr< const WDataSetFiberVector > fibs )
138 std::shared_ptr< const WDataSetFiberVector > WFiberCluster::getDataSetReference()
const
170 size_t avgFiberSize = 0;
173 fibs->push_back(
m_fibs->at( *cit ) );
174 avgFiberSize += fibs->back().size();
176 avgFiberSize /= fibs->size();
182 cit->resampleByNumberOfPoints( avgFiberSize );
187 for(
size_t i = 0; i < avgFiberSize; ++i )
192 avgPosition += cit->at( i );
194 avgPosition /=
static_cast< double >( fibs->size() );
222 size_t longestID = 0;
223 for(
size_t cit = 0; cit <
m_fibs->size(); ++cit )
225 if(
m_fibs->at( cit ).size() > longest )
227 longest =
m_fibs->at( cit ).size();
245 WPlane p( cL[0] - cL[1], cL[0] + ( cL[0] - cL[1] ) );
246 std::shared_ptr< WPosition > cutPoint(
new WPosition( 0, 0, 0 ) );
247 bool intersectionFound =
true;
253 fibs->push_back(
m_fibs->at( *cit ) );
256 while( intersectionFound )
258 intersectionFound =
false;
259 size_t intersectingFibers = 0;
263 if( intersectPlaneLineNearCP( p, *cit, cutPoint ) )
268 intersectingFibers++;
269 intersectionFound =
true;
274 cit = fibs->erase( cit );
279 cit = fibs->erase( cit );
282 if( intersectingFibers > 10 )
284 cL.
insert( cL.
begin(), cL[0] + ( cL[0] - cL[1] ) );
302 fobs->push_back(
m_fibs->at( *cit ) );
308 intersectionFound =
true;
309 while( intersectionFound )
311 intersectionFound =
false;
312 size_t intersectingFibers = 0;
316 if( intersectPlaneLineNearCP( q, *cit, cutPoint ) )
321 intersectingFibers++;
322 intersectionFound =
true;
327 cit = fobs->erase( cit );
332 cit = fobs->erase( cit );
335 if( intersectingFibers > 10 )
356 if( fibs->size() < 2 )
361 assert( !( fibs->at( 0 ).empty() ) &&
"WFiberCluster.unifyDirection: Empty fiber processed.. aborting" );
372 const WFiber& other = *cit;
373 double distance = length2( start - other.
front() ) +
374 length2( m1 - other.
at( other.
size() * 1.0 / 3.0 ) ) +
375 length2( m2 - other.
at( other.
size() * 2.0 / 3.0 ) ) +
376 length2( end - other.
back() );
377 double inverseDistance = length2( start - other.
back() ) +
378 length2( m1 - other.
at( other.
size() * 2.0 / 3.0 ) ) +
379 length2( m2 - other.
at( other.
size() * 1.0 / 3.0 ) ) +
380 length2( end - other.
front() );
382 inverseDistance /= 4.0;
383 if( inverseDistance < distance )
void expandBy(const WBoundingBoxImpl< VT > &bb)
Expands this bounding box to include the given bounding box.
Represents a simple set of WFibers.
Represents a cluster of indices of a WDataSetFiberVector.
std::shared_ptr< WFiber > m_centerLine
Average fiber for this cluster representing the main direction and curvature of this cluster.
std::shared_ptr< WFiber > m_longestLine
The longest fiber in the dataset.
IndexList m_memberIndices
All indices in this set are members of this cluster.
void elongateCenterLine() const
The centerline may be shortened due to the averaging of outliers.
static std::shared_ptr< WPrototyped > m_prototype
Prototype for this dataset.
void clear()
Make this cluster empty.
IndexList::const_iterator IndexListConstIterator
Const iterator on the index list.
virtual ~WFiberCluster()
Destructs.
std::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.
void generateLongestLine() const
Makes the hard work to find the longest line.
std::shared_ptr< WFiber > getLongestLine() const
Returns the center line of this cluster.
std::shared_ptr< const WDataSetFiberVector > m_fibs
Reference to the real fibers of the brain this cluster belongs to.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
void merge(WFiberCluster &other)
Merge the fibers of the other cluster with the fibers of this cluster.
WFiberCluster()
Constructs an empty cluster.
void unifyDirection(std::shared_ptr< WDataSetFiberVector > fibs) const
Alings all fibers within the given dataset to be in one main direction.
void generateCenterLine() const
Makes the hard work to compute the center line.
std::shared_mutex * m_centerLineCreationLock
Lock the modification in the m_centerLine mutable.
std::shared_mutex * m_longestLineCreationLock
Lock the modification in the m_longestLine mutable.
WBoundingBox getBoundingBox() const
Recomputes on every call the axis aligned bounding box incorporating all tracts in this cluster.
Represents a neural pathway.
vector_type::iterator iterator
Compares to std::vector type.
size_type size() const
Wrapper around std::vector member function.
void push_back(const value_type &value)
Wrapper around std::vector member function.
const_reference back() const
Wrapper around std::vector member function.
const_reference front() const
Wrapper around std::vector member function.
iterator insert(iterator where, const value_type &value)
Wrapper around std::vector member function.
const_iterator begin() const
Wrapper around std::vector member function.
const_reference at(size_type index) const
Wrapper around std::vector member function.
vector_type::const_iterator const_iterator
Compares to std::vector type.
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.
This only is a 3d double vector.
Class building the interface for classes that might be transferred using WModuleConnector.