#ifndef __FPA__VTK__IMAGE3DOBSERVER__HXX__ #define __FPA__VTK__IMAGE3DOBSERVER__HXX__ #include #include #include #include #include /* #include #include #include #include */ // ------------------------------------------------------------------------- template< class F, class R > void fpa::VTK::Image3DObserver< F, R >:: SetImage( const TImage* img, R* rw ) { this->m_Image = img; this->m_RenderWindow = rw; this->m_Vertices.clear( ); /* unsigned int minD = TImage::ImageDimension; minD = ( minD < 3 )? minD: 3; int e[ 6 ] = { 0 }; typename TImage::RegionType reg = this->m_Image->GetRequestedRegion( ); for( unsigned int i = 0; i < minD; i++ ) { e[ ( i << 1 ) + 0 ] = reg.GetIndex( )[ i ]; e[ ( i << 1 ) + 1 ] = reg.GetIndex( )[ i ] + reg.GetSize( )[ i ] - 1; } // rof typename TImage::SpacingType spac = this->m_Image->GetSpacing( ); double s[ 3 ] = { 1, 1, 1 }; for( unsigned int i = 0; i < minD; i++ ) s[ i ] = double( spac[ i ] ); typename TImage::PointType orig = this->m_Image->GetOrigin( ); double o[ 3 ] = { 0 }; for( unsigned int i = 0; i < minD; i++ ) o[ i ] = double( orig[ i ] ); this->m_Stencil->SetExtent( e ); this->m_Stencil->SetSpacing( s ); this->m_Stencil->SetOrigin( o ); this->m_Stencil->AllocateScalars( VTK_UNSIGNED_CHAR, 4 ); for( unsigned int i = 0; i < 3; i++ ) this->m_Stencil->GetPointData( )-> GetScalars( )->FillComponent( i, 255 ); this->m_Stencil->GetPointData( )->GetScalars( )->FillComponent( 3, 0 ); this->m_StencilActor->SetInputData( this->m_Stencil ); this->m_StencilActor->InterpolateOff( ); */ double nPix = double( this->m_Image->GetRequestedRegion( ).GetNumberOfPixels( ) ); this->m_Percentage = ( unsigned long )( nPix * 0.001 ); this->m_Number = 0; if( this->m_RenderWindow != NULL ) { vtkRenderer* ren = this->m_RenderWindow->GetRenderers( )->GetFirstRenderer( ); ren->AddActor( this->m_PolyDataActor ); this->Render( ); } // fi } // ------------------------------------------------------------------------- template< class F, class R > void fpa::VTK::Image3DObserver< F, R >:: Render( ) { if( this->m_RenderWindow != NULL ) this->m_RenderWindow->Render( ); } // ------------------------------------------------------------------------- template< class F, class R > void fpa::VTK::Image3DObserver< F, R >:: Execute( const itk::Object* c, const itk::EventObject& e ) { typedef typename TImage::IndexType TIndex; typedef typename TImage::PointType TPoint; typedef typename TFilter::TEvent TEvent; typedef typename TFilter::TFrontEvent TFrontEvent; typedef typename TFilter::TMarkEvent TMarkEvent; typedef typename TFilter::TCollisionEvent TCollisionEvent; typedef typename TFilter::TEndEvent TEndEvent; if( this->m_RenderWindow == NULL ) return; const TEvent* evt = dynamic_cast< const TEvent* >( &e ); TFrontEvent fevt; TMarkEvent mevt; TCollisionEvent cevt; TEndEvent eevt; if( evt != NULL ) { typename TImage::PointType pnt; this->m_Image->TransformIndexToPhysicalPoint( evt->Node.Vertex, pnt ); if( fevt.CheckEvent( evt ) ) { 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 } 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 */ } // fi if( cevt.CheckEvent( evt ) ) { // std::cout << "Collision"; } // 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 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 } // ------------------------------------------------------------------------- template< class F, class R > fpa::VTK::Image3DObserver< F, R >:: Image3DObserver( ) : Superclass( ), m_RenderWindow( NULL ), m_Number( 0 ), m_Percentage( 0 ) { 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__ // eof - $RCSfile$