typedef Superclass::InputImageType TImage;
typedef std::deque< TVertex > TVertices;
+ typedef Superclass::TEndEvent TEndEvent;
+ typedef Superclass::TBacktrackingEvent TBacktrackingEvent;
+
protected:
typedef std::pair< TCost, TVertex > _TCandidate;
typedef std::multimap< TCost, TVertex > _TCandidates;
if( this->m_Candidates.size( ) == 0 )
return;
+ this->InvokeEvent( TEndEvent( ) );
+
const TImage* input = this->GetInput( );
TImage::SpacingType spacing = input->GetSpacing( );
// are near thin branches
_TCandidates::const_reverse_iterator cIt =
this->m_Candidates.rbegin( );
- for( int leo = 0; leo < 1 && cIt != this->m_Candidates.rend( ); ++cIt )
+ for( int backId = 0; backId < 100 && cIt != this->m_Candidates.rend( ); ++cIt )
{
// If pixel hasn't been visited, continue
TVertex v = cIt->second;
if( marks->GetPixel( max_vertex ) != _TMark( 0 ) )
continue;
- leo++;
- std::cout << "Leaf: " << leo << " " << max_value << " " << max_vertex << std::endl;
+ backId++;
+ std::cout << "Leaf: " << backId << " " << max_value << " " << max_vertex << std::endl;
bool start = true;
do
start = false;
*/
// Next vertex in current path
+ this->InvokeEvent( TBacktrackingEvent( max_vertex, backId ) );
max_vertex = this->_Parent( max_vertex );
} while( max_vertex != this->_Parent( max_vertex ) );
} // rof
*/
- itk::ImageFileWriter< _TMarkImage >::Pointer w =
- itk::ImageFileWriter< _TMarkImage >::New( );
- w->SetInput( marks );
- w->SetFileName( "marks.mhd" );
- w->Update( );
-
/*
-
+ itk::ImageFileWriter< _TMarkImage >::Pointer w =
+ itk::ImageFileWriter< _TMarkImage >::New( );
+ w->SetInput( marks );
+ w->SetFileName( "marks.mhd" );
+ w->Update( );
+
+
this->m_Axes = vtkSmartPointer< vtkPolyData >::New( );
vtkSmartPointer< vtkPoints > points =
vtkSmartPointer< vtkPoints >::New( );
{
- leo++;
- std::cout << "Leaf: " << leo << " " << cIt->first << " " << vIt << std::endl;
+ backId++;
+ std::cout << "Leaf: " << backId << " " << cIt->first << " " << vIt << std::endl;
bool start = true;
do
{
SetRenderWindow( R* rw )
{
this->m_RenderWindow = rw;
- /*
- if( this->m_RenderWindow != NULL )
- {
- vtkRenderer* ren =
- this->m_RenderWindow->GetRenderers( )->GetFirstRenderer( );
- if( ren != NULL )
- {
- ren->AddActor( this->m_PolyDataActor );
- this->m_RenderWindow->Render( );
-
- } // fi
-
- } // fi
- */
}
// -------------------------------------------------------------------------
void fpa::VTK::Image3DObserver< F, R >::
Execute( const itk::Object* c, const itk::EventObject& e )
{
- typedef itk::ImageBase< 3 > _TImage;
- typedef typename F::TEvent _TEvent;
- typedef typename F::TFrontEvent _TFrontEvent;
- typedef typename F::TMarkEvent _TMarkEvent;
- typedef typename F::TCollisionEvent _TCollisionEvent;
- typedef typename F::TEndEvent _TEndEvent;
+ typedef itk::ImageBase< 3 > _TImage;
+ typedef typename F::TEvent _TEvent;
+ typedef typename F::TFrontEvent _TFrontEvent;
+ typedef typename F::TMarkEvent _TMarkEvent;
+ typedef typename F::TCollisionEvent _TCollisionEvent;
+ typedef typename F::TEndEvent _TEndEvent;
+ typedef typename F::TBacktrackingEvent _TBacktrackingEvent;
// Check inputs
if( this->m_RenderWindow == NULL )
this->m_Marks->SetDirection( image->GetDirection( ) );
this->m_Marks->Allocate( );
this->m_Marks->FillBuffer( -1 );
+ this->m_Count = 0;
+ this->m_RenderCount = reg.GetNumberOfPixels( );
} // fi
-
// Get possible events
const _TEvent* evt = dynamic_cast< const _TEvent* >( &e );
_TFrontEvent fevt;
_TMarkEvent mevt;
_TCollisionEvent cevt;
_TEndEvent eevt;
+
if( evt != NULL )
{
if( fevt.CheckEvent( evt ) )
this->m_Data->Modified( );
this->m_Marks->SetPixel( evt->Node.Vertex, pId );
+ this->m_Count++;
- } // fi
- this->m_RenderWindow->Render( );
+ // Render visual debug
+ double per = double( this->m_RenderCount ) * this->m_RenderPercentage;
+ if( double( this->m_Count ) >= per )
+ this->m_RenderWindow->Render( );
+ if( double( this->m_Count ) >= per )
+ this->m_Count = 0;
- /* TODO
- if(
- this->m_Vertices.find( evt->Node.Vertex ) == this->m_Vertices.end( )
- )
- {
- unsigned long pId = this->m_PolyData->GetPoints( )->InsertNextPoint(
- double( pnt[ 0 ] ), double( pnt[ 1 ] ), double( pnt[ 2 ] )
- );
- unsigned long cId = this->m_PolyData->GetVerts( )->InsertNextCell( 1 );
- this->m_PolyData->GetVerts( )->InsertCellPoint( pId );
- this->m_PolyData->Modified( );
- this->m_Vertices[ evt->Node.Vertex ] = TVertexIds( pId, cId );
-
- } // rof
- */
+ } // fi
+ return;
}
else if( mevt.CheckEvent( evt ) )
{
- /*
- typename TVertices::iterator vIt =
- this->m_Vertices.find( evt->Node.Vertex );
- if( vIt != this->m_Vertices.end( ) )
- {
- std::cout << "Erase " << evt->Node.Vertex << " " << vIt->second.second << std::endl;
- } // fi
- */
+ // TODO: std::cout << "mark" << std::endl;
+ return;
+
} // fi
if( cevt.CheckEvent( evt ) )
{
// TODO: std::cout << "collision" << std::endl;
+ return;
+
+ } // fi
+
+ if( eevt.CheckEvent( evt ) )
+ {
+ this->m_RenderWindow->Render( );
+ ren->RemoveActor( this->m_Actor );
+ this->m_RenderWindow->Render( );
+ this->m_Marks = NULL;
+ this->m_Data = NULL;
+ this->m_Mapper = NULL;
+ this->m_Actor = NULL;
+ return;
+
+ } // fi
+ }
+ else
+ {
+ const _TBacktrackingEvent* bevt =
+ dynamic_cast< const _TBacktrackingEvent* >( &e );
+ if( bevt != NULL )
+ {
+ static const unsigned long nColors = 10;
+ double back_id = double( bevt->BackId % nColors ) / double( nColors );
+ typename _TImage::PointType pnt;
+ image->TransformIndexToPhysicalPoint( bevt->Node, pnt );
+
+ long pId = this->m_Data->GetNumberOfPoints( );
+ this->m_Data->GetVerts( )->InsertNextCell( 1 );
+ this->m_Data->GetVerts( )->InsertCellPoint( pId );
+ this->m_Data->GetPoints( )->
+ InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
+ this->m_Data->GetPointData( )->
+ GetScalars( )->InsertNextTuple1( back_id );
+ this->m_Data->Modified( );
+ this->m_RenderWindow->Render( );
+
+ return;
} // fi
- /*
- this->SetPixel(
- evt->Node.Vertex,
- Colors[ evt->Node.FrontId ][ 0 ],
- Colors[ evt->Node.FrontId ][ 1 ],
- Colors[ evt->Node.FrontId ][ 2 ],
- Colors[ evt->Node.FrontId ][ 3 ]
- );
- else if( mevt.CheckEvent( evt ) )
- this->SetPixel( evt->Node.Vertex, 255, 0, 0, 255 );
-
- if( cevt.CheckEvent( evt ) )
- this->SetPixel( evt->Node.Vertex, 100, 50, 25, 255 );
- */
-
- // Update visualization
- /* TODO
- if( this->m_Number == 0 || this->m_Percentage < 0 )
- this->Render( );
- this->m_Number++;
- this->m_Number %= this->m_Percentage;
- if( eevt.CheckEvent( evt ) )
- {
- if( this->m_RenderWindow != NULL )
- {
- vtkRenderer* ren =
- this->m_RenderWindow->GetRenderers( )->GetFirstRenderer( );
- ren->RemoveActor( this->m_PolyDataActor );
- this->Render( );
-
- } // fi
-
- } // fi
- */
} // fi
}
fpa::VTK::Image3DObserver< F, R >::
Image3DObserver( )
: Superclass( ),
- m_RenderWindow( NULL )
+ m_RenderWindow( NULL ),
+ m_RenderPercentage( double( 0.0001 ) )
{
- /*
- this->m_PolyData = vtkSmartPointer< vtkPolyData >::New( );
- this->m_PolyDataMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
- this->m_PolyDataActor = vtkSmartPointer< vtkActor >::New( );
-
- this->m_PolyData->SetPoints( vtkPoints::New( ) );
- this->m_PolyData->SetVerts( vtkCellArray::New( ) );
-
- this->m_PolyDataMapper->SetInputData( this->m_PolyData );
- this->m_PolyDataActor->SetMapper( this->m_PolyDataMapper );
- this->m_PolyDataActor->GetProperty( )->SetColor( 0, 0, 1 );
- */
}
#endif // __FPA__VTK__IMAGE3DOBSERVER__HXX__