]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/EndPointsFilter.hxx
...
[FrontAlgorithms.git] / lib / fpa / Image / EndPointsFilter.hxx
1 #ifndef __fpa__Image__EndPointsFilter__hxx__
2 #define __fpa__Image__EndPointsFilter__hxx__
3
4 #include <functional>
5 #include <map>
6 #include <queue>
7 #include <itkImageRegionConstIteratorWithIndex.h>
8
9 // -------------------------------------------------------------------------
10 template< class _TDistanceMap, class _TCostMap >
11 const typename fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap >::
12 TIndices& fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap >::
13 GetBifurcations( ) const
14 {
15   return( this->m_Bifurcations );
16 }
17
18 // -------------------------------------------------------------------------
19 template< class _TDistanceMap, class _TCostMap >
20 const typename fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap >::
21 TIndices& fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap >::
22 GetEndPoints( ) const
23 {
24   return( this->m_EndPoints );
25 }
26
27 // -------------------------------------------------------------------------
28 template< class _TDistanceMap, class _TCostMap >
29 void fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap >::
30 Compute( )
31 {
32   /* TODO
33      typedef itk::ImageRegionConstIteratorWithIndex< _TDistanceMap > _TDistMapIt;
34      typedef itk::ImageRegionConstIteratorWithIndex< _TCostMap > _TCostMapIt;
35      typedef std::multimap< double, TIndex, std::greater< double > > _TQueue;
36      typedef typename _TQueue::value_type _TQueueValue;
37
38      // Create queue
39      _TQueue queue;
40      _TDistMapIt dIt(
41      this->m_DistanceMap, this->m_DistanceMap->GetRequestedRegion( )
42      );
43      _TCostMapIt cIt(
44      this->m_CostMap, this->m_CostMap->GetRequestedRegion( )
45      );
46      dIt.GoToBegin( );
47      cIt.GoToBegin( );
48      for( ; !dIt.IsAtEnd( ) && !cIt.IsAtEnd( ); ++dIt, ++cIt )
49      {
50      double d = double( dIt.Get( ) );
51      if( d > 0 )
52      {
53      double v = double( cIt.Get( ) ) * d;
54      queue.insert( _TQueueValue( v, dIt.GetIndex( ) ) );
55
56      } // fi
57
58      } // rof
59
60      TIndices marks;
61      while( queue.size( ) > 0 )
62      {
63      auto nIt = queue.begin( );
64      auto n = *nIt;
65      queue.erase( nIt );
66
67      if( marks.find( n.second ) == marks.end( ) )
68      {
69      std::cout << queue.size( ) << " " << n.first << std::endl;
70      marks.insert( n.second );
71      this->m_EndPoints.insert( n.second );
72      auto path = this->m_MST->GetPath( n.second );
73      std::cout << path.size( ) << std::endl;
74      for( auto pIt = path.begin( ); pIt != path.end( ); ++pIt )
75      {
76      double d = double( this->m_DistanceMap->GetPixel( *pIt ) );
77      d = std::sqrt( std::fabs( d ) );
78      typename _TCostMap::PointType center;
79      this->m_CostMap->TransformIndexToPhysicalPoint( *pIt, center );
80
81      std::queue< TIndex > q;
82      TIndices m;
83      q.push( *pIt );
84      while( q.size( ) > 0 )
85      {
86      TIndex idx = q.front( );
87      q.pop( );
88      if( m.find( idx ) != m.end( ) )
89      continue;
90      m.insert( idx );
91      marks.insert( idx );
92      for( unsigned int x = 0; x < _TCostMap::ImageDimension; ++x )
93      {
94      for( int y = -1; y <= 1; y += 2 )
95      {
96      TIndex idx2 = idx;
97      idx2[ x ] += y;
98      typename _TCostMap::PointType c;
99      this->m_CostMap->TransformIndexToPhysicalPoint( idx2, c );
100      if( this->m_CostMap->GetRequestedRegion( ).IsInside( idx2 ) )
101      {
102      if( center.EuclideanDistanceTo( c ) <= ( d * 1.5 ) )
103      q.push( idx2 );
104
105      } // fi
106
107      } // rof
108
109      } // rof
110
111      } // elihw
112
113      } // rof
114
115      } // fi
116
117      } // elihw
118   */
119 }
120
121 // -------------------------------------------------------------------------
122 template< class _TDistanceMap, class _TCostMap >
123 fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap >::
124 EndPointsFilter( )
125   : Superclass( )
126 {
127 }
128
129 // -------------------------------------------------------------------------
130 template< class _TDistanceMap, class _TCostMap >
131 fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap >::
132 ~EndPointsFilter( )
133 {
134 }
135
136 #endif // __fpa__Image__EndPointsFilter__hxx__
137
138 // eof - $RCSfile$