28 #include <boost/shared_ptr.hpp>
30 #include "../../common/math/WMath.h"
31 #include "../../common/math/WPlane.h"
32 #include "../../common/WLimits.h"
33 #include "../../common/WTransferable.h"
34 #include "../WDataSetFiberVector.h"
35 #include "WFiberCluster.h"
43 boost::shared_ptr< WPrototyped > WFiberCluster::m_prototype = boost::shared_ptr< WPrototyped >();
48 m_centerLineCreationLock( new boost::shared_mutex() ),
49 m_longestLineCreationLock( new boost::shared_mutex() )
55 m_centerLineCreationLock( new boost::shared_mutex() ),
56 m_longestLineCreationLock( new boost::shared_mutex() )
63 m_memberIndices( other.m_memberIndices ),
64 m_fibs( other.m_fibs ),
65 m_color( other.m_color ),
66 m_centerLineCreationLock( new boost::shared_mutex() ),
68 m_longestLineCreationLock( new boost::shared_mutex() ),
91 std::list< size_t >::const_iterator cit = other.
m_memberIndices.begin();
104 void WFiberCluster::setDataSetReference( boost::shared_ptr< const WDataSetFiberVector > fibs )
109 boost::shared_ptr< const WDataSetFiberVector > WFiberCluster::getDataSetReference()
const
118 boost::shared_ptr< WPrototyped > WFiberCluster::getPrototype()
122 m_prototype = boost::shared_ptr< WPrototyped >(
new WFiberCluster() );
131 boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( *m_centerLineCreationLock );
141 size_t avgFiberSize = 0;
144 fibs->push_back(
m_fibs->at( *cit ) );
145 avgFiberSize += fibs->back().size();
147 avgFiberSize /= fibs->size();
153 cit->resampleByNumberOfPoints( avgFiberSize );
158 for(
size_t i = 0; i < avgFiberSize; ++i )
163 avgPosition += cit->at( i );
165 avgPosition /=
static_cast< double >( fibs->size() );
176 boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( *m_longestLineCreationLock );
193 size_t longestID = 0;
194 for(
size_t cit = 0; cit <
m_fibs->size(); ++cit )
196 if(
m_fibs->at( cit ).size() > longest )
198 longest =
m_fibs->at( cit ).size();
216 WPlane p( cL[0] - cL[1], cL[0] + ( cL[0] - cL[1] ) );
217 boost::shared_ptr< WPosition > cutPoint(
new WPosition( 0, 0, 0 ) );
218 bool intersectionFound =
true;
224 fibs->push_back(
m_fibs->at( *cit ) );
227 while( intersectionFound )
229 intersectionFound =
false;
230 size_t intersectingFibers = 0;
234 if( intersectPlaneLineNearCP( p, *cit, cutPoint ) )
239 intersectingFibers++;
240 intersectionFound =
true;
245 cit = fibs->erase( cit );
250 cit = fibs->erase( cit );
253 if( intersectingFibers > 10 )
255 cL.insert( cL.begin(), cL[0] + ( cL[0] - cL[1] ) );
273 fobs->push_back(
m_fibs->at( *cit ) );
278 WPlane q( cL.back() - cL[ cL.size() - 2 ], cL.back() + ( cL.back() - cL[ cL.size() - 2 ] ) );
279 intersectionFound =
true;
280 while( intersectionFound )
282 intersectionFound =
false;
283 size_t intersectingFibers = 0;
287 if( intersectPlaneLineNearCP( q, *cit, cutPoint ) )
292 intersectingFibers++;
293 intersectionFound =
true;
298 cit = fobs->erase( cit );
303 cit = fobs->erase( cit );
306 if( intersectingFibers > 10 )
308 cL.push_back( cL.back() + ( cL.back() - cL[ cL.size() - 2 ] ) );
309 q.
resetPosition( cL.back() + ( cL.back() - cL[ cL.size() - 2 ] ) );
327 if( fibs->size() < 2 )
332 assert( !( fibs->at( 0 ).empty() ) &&
"WFiberCluster.unifyDirection: Empty fiber processed.. aborting" );
343 const WFiber& other = *cit;
344 double distance = length2( start - other.
front() ) +
345 length2( m1 - other.
at( other.
size() * 1.0 / 3.0 ) ) +
346 length2( m2 - other.
at( other.
size() * 2.0 / 3.0 ) ) +
347 length2( end - other.
back() );
348 double inverseDistance = length2( start - other.
back() ) +
349 length2( m1 - other.
at( other.
size() * 2.0 / 3.0 ) ) +
350 length2( m2 - other.
at( other.
size() * 1.0 / 3.0 ) ) +
351 length2( end - other.
front() );
353 inverseDistance /= 4.0;
354 if( inverseDistance < distance )