virtual void GenerateData( );
/// Base interface
+ virtual void _BeforeMainLoop ( );
+ virtual void _AfterMainLoop ( );
virtual void _BeforeLoop ( );
virtual void _AfterLoop ( );
virtual void _Loop ( );
this->m_CollisionSites.clear( );
this->m_CollisionSites.
resize( N, _TCollisionSitesRow( N, _TCollision( TVertex( ), false ) ) );
- this->_BeforeLoop( );
+
+ this->_BeforeMainLoop( );
+ this->_InitializeMarks( );
+ this->_InitializeResults( );
+ this->_InitializeQueue( );
this->_Loop( );
- this->_AfterLoop( );
+ this->_AfterMainLoop( );
+}
+
+// -------------------------------------------------------------------------
+template< class T, class B >
+void fpa::Base::Algorithm< T, B >::
+_BeforeMainLoop( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class T, class B >
+void fpa::Base::Algorithm< T, B >::
+_AfterMainLoop( )
+{
}
// -------------------------------------------------------------------------
void fpa::Base::Algorithm< T, B >::
_Loop( )
{
- this->_InitializeMarks( );
- this->_InitializeResults( );
- this->_InitializeQueue( );
+ this->_BeforeLoop( );
while( !( this->_IsQueueEmpty( ) ) )
{
_TNode n = this->_QueuePop( );
} // elihw
this->InvokeEvent( TEndEvent( ) );
+ this->_AfterLoop( );
}
// -------------------------------------------------------------------------
{
typename _TMarks::const_iterator mIt = this->m_Marks.find( v );
if( mIt == this->m_Marks.end( ) )
- {
- TVertex v;
- return( v );
- }
+ return( TVertex( ) );
else
return( mIt->second.Parent );
}
typedef typename Superclass::_TNode _TNode;
typedef typename Superclass::_TNodes _TNodes;
typedef typename Superclass::_TQueue _TQueue;
+ typedef typename Superclass::_TMarks _TMarks;
public:
itkTypeMacro( RegionGrowWithMultipleCriteria, RegionGrow );
RegionGrowWithMultipleCriteria( );
virtual ~RegionGrowWithMultipleCriteria( );
- virtual void _BeforeLoop( );
- virtual _TNode _QueuePop( );
+ virtual void _BeforeMainLoop( );
+ virtual void _AfterLoop( );
+ virtual void _Loop( );
virtual bool _CheckMembership( const _TNode& n ) const;
private:
// -------------------------------------------------------------------------
template< class V, class R, class VV, class VC, class B >
void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
-_BeforeLoop( )
+_BeforeMainLoop( )
{
- this->Superclass::_BeforeLoop( );
+ this->Superclass::_BeforeMainLoop( );
this->m_ActualFunction = this->m_Functions.begin( );
}
// -------------------------------------------------------------------------
template< class V, class R, class VV, class VC, class B >
-typename fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
-_TNode fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
-_QueuePop( )
+void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
+_AfterLoop( )
{
- _TNode node = this->Superclass::_QueuePop( );
- if( this->_IsQueueEmpty( ) )
+ this->Superclass::_AfterLoop( );
+
+ // Replace queue
+ this->_QueueClear( );
+ while( !( this->m_AuxiliaryQueue.empty( ) ) )
{
- // Replace queue
- this->m_Queue = this->m_AuxiliaryQueue;
+ // Get node
+ _TNode node = this->m_AuxiliaryQueue.front( );
+ this->m_AuxiliaryQueue.pop( );
+ this->_QueuePush( node );
- // Move to next function
- this->m_ActualFunction++;
+ // Unmark it
+ typename _TMarks::iterator mIt = this->m_Marks.find( node.Vertex );
+ if( mIt != this->m_Marks.end( ) )
+ this->m_Marks.erase( mIt );
+
+ } // elihw
+
+ // Move to next function
+ this->m_ActualFunction++;
+}
- } // fi
- return( node );
+// -------------------------------------------------------------------------
+template< class V, class R, class VV, class VC, class B >
+void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
+_Loop( )
+{
+ while( this->m_ActualFunction != this->m_Functions.end( ) )
+ this->Superclass::_Loop( );
}
// -------------------------------------------------------------------------
TreeExtractor( );
virtual ~TreeExtractor( );
- virtual void _BeforeLoop( );
- virtual void _AfterLoop( );
+ virtual void _BeforeMainLoop( );
+ virtual void _AfterMainLoop( );
TVertices _Path( const TVertex& s, const TVertex& e );
// -------------------------------------------------------------------------
template< class A >
void fpa::Base::TreeExtractor< A >::
-_BeforeLoop( )
+_BeforeMainLoop( )
{
- this->Superclass::_BeforeLoop( );
+ this->Superclass::_BeforeMainLoop( );
this->m_Tree.clear( );
}
// -------------------------------------------------------------------------
template< class A >
void fpa::Base::TreeExtractor< A >::
-_AfterLoop( )
+_AfterMainLoop( )
{
- this->Superclass::_AfterLoop( );
+ this->Superclass::_AfterMainLoop( );
// Prepare fronts graph using Floyd-Warshall
unsigned long nSeeds = this->GetNumberOfSeeds( );
const I* img = this->GetInputImage( );
if( img != NULL )
{
- /* TODO
- if( this->IsInsideBuffer( idx ) )
- {
- */
TPixel v = img->GetPixel( idx );
- std::cout
- << v << " "
- << this->m_LowerThreshold << " "
- << this->m_UpperThreshold << std::endl;
return(
this->m_LowerThreshold <= v && v < this->m_UpperThreshold
);
- // TODO: } // fi
-
} // fi
return( false );
}
typedef typename Superclass::TMembershipFunction TMembershipFunction;
typedef typename Superclass::TFunctions TFunctions;
- typedef std::set< TPixel > TThresholds;
+ typedef std::set< TPixel > TThresholds;
typedef fpa::Image::Functors::RegionGrowThresholdFunction< I > TFunction;
protected:
RegionGrowWithMultipleThresholds( );
virtual ~RegionGrowWithMultipleThresholds( );
- virtual bool _UpdateResult( _TNode& n );
- virtual void _BeforeLoop( );
+ virtual void _BeforeMainLoop( );
+ virtual void _AfterMainLoop( );
virtual void _AfterLoop( );
+ virtual bool _UpdateResult( _TNode& n );
private:
RegionGrowWithMultipleThresholds( const Self& ); // Not impl.
: Superclass( ),
m_DerivativeThreshold( double( 3 ) )
{
- /* TODO
- typedef
- fpa::Image::Functors::RegionGrowThresholdFunction< I >
- TFunction;
- typename TFunction::Pointer function = TFunction::New( );
- this->SetMembershipFunction( function );
- */
}
// -------------------------------------------------------------------------
{
}
-// -------------------------------------------------------------------------
-template< class I >
-bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
-_UpdateResult( _TNode& n )
-{
- bool ret = this->Superclass::_UpdateResult( n );
- std::cout << "Image:UpdateResult " << ret << std::endl;
-
-
- /* TODO
- if( ret )
- {
- TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) );
-
- typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( );
- while( hIt != this->m_Histogram.rend( ) )
- {
- if( v <= hIt->first )
- {
- hIt->second += 1;
- hIt++;
- }
- else
- hIt = this->m_Histogram.rend( );
-
- } // elihw
- this->GetOutput( )->SetPixel( n.Vertex, v );
-
- } // fi
- */
- return( ret );
-}
-
// -------------------------------------------------------------------------
template< class I >
void fpa::Image::RegionGrowWithMultipleThresholds< I >::
-_BeforeLoop( )
+_BeforeMainLoop( )
{
const I* img = this->GetInput( );
this->ClearMembershipFunctions( );
typename TThresholds::const_iterator tIt = this->m_Thresholds.begin( );
- typename TThresholds::const_iterator prev_tIt = tIt;
- for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt, ++prev_tIt )
+ TPixel min_thr = *tIt;
+ for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt )
{
typename TFunction::Pointer function = TFunction::New( );
function->SetInputImage( img );
- function->SetLowerThreshold( *prev_tIt );
+ function->SetLowerThreshold( min_thr );
function->SetUpperThreshold( *tIt );
this->AddMembershipFunction( function );
- std::cout << *prev_tIt << " " << *tIt << std::endl;
} // rof
- this->Superclass::_BeforeLoop( );
+ this->Superclass::_BeforeMainLoop( );
}
// -------------------------------------------------------------------------
void fpa::Image::RegionGrowWithMultipleThresholds< I >::
_AfterLoop( )
{
- /*
- typename THistogram::iterator prevIt = this->m_Histogram.begin( );
- typename THistogram::iterator currIt = prevIt; currIt++;
- typename THistogram::iterator nextIt = currIt; nextIt++;
- double prev_d1 = double( 0 );
- for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt )
- {
- double d1 = double( nextIt->second ) - double( prevIt->second );
- d1 /= double( nextIt->first ) - double( prevIt->first );
-
- std::cout
- << currIt->first << " "
- << currIt->second << " "
- << d1 << " "
- << ( d1 - prev_d1 ) << std::endl;
-
- prev_d1 = d1;
-
- } // rof
- */
+ if( this->m_ActualFunction != this->m_Functions.end( ) )
+ {
+ TFunction* f =
+ dynamic_cast< TFunction* >( this->m_ActualFunction->GetPointer( ) );
+ // std::cout << f->GetUpperThreshold( ) << " " << this->m_Marks.size( ) << std::endl;
- /*
- double prev = double( 0 );
- while( hIt != this->m_Histogram.end( ) )
- {
- double curr = double( hIt->second );
- double deri = curr - prev;
+ } // fi
+ this->Superclass::_AfterLoop( );
+}
- if( hIt != this->m_Histogram.begin( ) )
- std::cout << hIt->first << " " << curr << " " << deri << std::endl;
+// -------------------------------------------------------------------------
+template< class I >
+void fpa::Image::RegionGrowWithMultipleThresholds< I >::
+_AfterMainLoop( )
+{
+ this->Superclass::_AfterMainLoop( );
+}
- prev = curr;
- hIt++;
+// -------------------------------------------------------------------------
+template< class I >
+bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
+_UpdateResult( _TNode& n )
+{
+ #error ACA VOY -> explicar esto!!!! cambiar salida por una especie de curva de nivel
+ bool ret = this->Superclass::_UpdateResult( n );
+ if( this->m_ActualFunction != this->m_Functions.end( ) )
+ {
+ TFunction* f =
+ dynamic_cast< TFunction* >( this->m_ActualFunction->GetPointer( ) );
+ this->GetOutput( )->SetPixel( n.Vertex, f->GetUpperThreshold( ) );
- } // rof
- */
- this->Superclass::_AfterLoop( );
+ } // fi
+ return( ret );
}
-
#endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
// eof - $RCSfile$
{
vtkRenderer* ren =
this->m_RenderWindow->GetRenderers( )->GetFirstRenderer( );
- ren->RemoveActor( this->m_PolyDataActor );
+ // TODO: ren->RemoveActor( this->m_PolyDataActor );
this->Render( );
} // fi