From: Leonardo Flórez-Valencia Date: Fri, 16 Sep 2016 02:12:03 +0000 (-0500) Subject: Raster filter updated. LUT image visualization strange bug :-( X-Git-Tag: v0.1~110 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=f6e163be0bf2ffeb19239bb31c1df936017cdc8e;p=cpPlugins.git Raster filter updated. LUT image visualization strange bug :-( --- diff --git a/appli/examples/plugins/ImageTracer.cxx b/appli/examples/plugins/ImageTracer.cxx index 00ff0e8..cff73bd 100644 --- a/appli/examples/plugins/ImageTracer.cxx +++ b/appli/examples/plugins/ImageTracer.cxx @@ -63,6 +63,8 @@ int main( int argc, char* argv[] ) auto spline = ws->GetFilter( "spline" ); auto seeds = ws->GetFilter( "seeds" ); auto axis = ws->GetFilter( "axis" ); + auto writer = ws->GetFilter( "writer" ); + auto raster = ws->GetFilter( "raster" ); // Execute reader try @@ -85,8 +87,8 @@ int main( int argc, char* argv[] ) reader->GetOutputData< vtkImageData >( "Output" ), 2, "image" ); spline->AddInteractor( view.GetInteractor( ) ); - spline->Update( ); seeds->AddInteractor( view.GetInteractor( ) ); + spline->Update( ); seeds->Update( ); // Start application and show data @@ -95,6 +97,8 @@ int main( int argc, char* argv[] ) app.exec( ); spline->Modified( ); spline->Update( ); + raster->Update( ); + writer->Update( ); wnd.show( ); app.exec( ); diff --git a/lib/cpExtensions/Algorithms/RasterContourFilter.h b/lib/cpExtensions/Algorithms/RasterContourFilter.h new file mode 100644 index 0000000..8d22bba --- /dev/null +++ b/lib/cpExtensions/Algorithms/RasterContourFilter.h @@ -0,0 +1,92 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __cpExtensions__Algorithms__RasterContourFilter__h__ +#define __cpExtensions__Algorithms__RasterContourFilter__h__ + +#include +#include +#include + +// ------------------------------------------------------------------------- +class vtkPoints; +class vtkPolygon; + +// ------------------------------------------------------------------------- +namespace cpExtensions +{ + namespace Algorithms + { + /** + */ + template< class _TImage > + class RasterContourFilter + : public itk::ImageSource< _TImage > + { + public: + // Basic types + typedef RasterContourFilter Self; + typedef itk::ImageSource< _TImage > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef _TImage TImage; + typedef typename _TImage::IndexType TIndex; + typedef typename _TImage::PixelType TPixel; + typedef typename _TImage::PointType TPoint; + typedef typename _TImage::RegionType TRegion; + typedef itk::ImageBase< 2 > TImageBase; + + public: + itkNewMacro( Self ); + itkTypeMacro( RasterContourFilter, itk::ImageSource ); + + itkGetConstObjectMacro( Template, TImageBase ); + itkGetConstMacro( InsideValue, TPixel ); + itkGetConstMacro( OutsideValue, TPixel ); + + itkSetConstObjectMacro( Template, TImageBase ); + itkSetMacro( InsideValue, TPixel ); + itkSetMacro( OutsideValue, TPixel ); + + public: + void AddPoint( double x, double y ); + void AddPoint( double p[ 2 ] ); + void AddPoints( vtkPoints* points ); + void ClearPoints( ); + + protected: + RasterContourFilter( ); + virtual ~RasterContourFilter( ); + + virtual void AllocateOutputs( ) cpExtensions_OVERRIDE; + virtual void BeforeThreadedGenerateData( ) cpExtensions_OVERRIDE; + virtual void AfterThreadedGenerateData( ) cpExtensions_OVERRIDE; + virtual void ThreadedGenerateData( + const TRegion& region, itk::ThreadIdType id + ) cpExtensions_OVERRIDE; + + private: + // Purposely not implemented + RasterContourFilter( const Self& ); + void operator=( const Self& ); + + protected: + vtkSmartPointer< vtkPolygon > m_Polygon; + typename TImageBase::ConstPointer m_Template; + TPixel m_InsideValue; + TPixel m_OutsideValue; + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __cpExtensions__Algorithms__RasterContourFilter__h__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Algorithms/RasterContourFilter.hxx b/lib/cpExtensions/Algorithms/RasterContourFilter.hxx new file mode 100644 index 0000000..2f7481f --- /dev/null +++ b/lib/cpExtensions/Algorithms/RasterContourFilter.hxx @@ -0,0 +1,151 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------ + +// Inclusion test taken from: +// https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html + +#ifndef __cpExtensions__Algorithms__RasterContourFilter__hxx__ +#define __cpExtensions__Algorithms__RasterContourFilter__hxx__ + +#include +#include + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +AddPoint( double x, double y ) +{ + this->m_Polygon->GetPoints( )->InsertNextPoint( x, y, 0 ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +AddPoint( double p[ 2 ] ) +{ + this->m_Polygon->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +AddPoints( vtkPoints* points ) +{ + double p[ 3 ]; + for( unsigned long i = 0; i < points->GetNumberOfPoints( ); ++i ) + { + points->GetPoint( i, p ); + this->m_Polygon->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 ); + + } // rof + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +ClearPoints( ) +{ + this->m_Polygon = vtkSmartPointer< vtkPolygon >::New( ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +RasterContourFilter( ) + : Superclass( ), + m_InsideValue( TPixel( 1 ) ), + m_OutsideValue( TPixel( 0 ) ) +{ + this->ClearPoints( ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +~RasterContourFilter( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +AllocateOutputs( ) +{ + _TImage* out = this->GetOutput( 0 ); + out->SetSpacing( this->m_Template->GetSpacing( ) ); + out->SetRegions( this->m_Template->GetRequestedRegion( ) ); + out->SetOrigin( this->m_Template->GetOrigin( ) ); + out->SetDirection( this->m_Template->GetDirection( ) ); + out->Allocate( ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +BeforeThreadedGenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +AfterThreadedGenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void cpExtensions::Algorithms::RasterContourFilter< _TImage >:: +ThreadedGenerateData( const TRegion& region, itk::ThreadIdType id ) +{ + vtkPoints* points = this->m_Polygon->GetPoints( ); + unsigned long nPoints = points->GetNumberOfPoints( ); + double* arr = + static_cast< double* >( points->GetData()->GetVoidPointer( 0 ) ); + double p[ 3 ], n[ 3 ], b[ 6 ]; + this->m_Polygon->GetPoints( )->GetBounds( b ); + n[ 0 ] = n[ 1 ] = double( 0 ); + n[ 2 ] = double( 1 ); + + _TImage* out = this->GetOutput( ); + itk::ImageRegionIteratorWithIndex< _TImage > iIt( out, region ); + for( iIt.GoToBegin( ); !iIt.IsAtEnd( ); ++iIt ) + { + TIndex idx = iIt.GetIndex( ); + TPoint pnt; + out->TransformIndexToPhysicalPoint( idx, pnt ); + p[ 0 ] = pnt[ 0 ]; + p[ 1 ] = pnt[ 1 ]; + p[ 2 ] = double( 0 ); + + int i, j, c = 0; + int nvert = nPoints; + for( i = 0, j = nvert - 1; i < nvert; j = i++ ) + { + double pi[ 3 ], pj[ 3 ]; + points->GetPoint( i, pi ); + points->GetPoint( j, pj ); + + if( + ( ( pi[ 1 ] > p[ 1 ] ) != ( pj[ 1 ] > p[ 1 ] ) ) && + ( p[ 0 ] < ( pj[ 0 ] - pi[ 0 ] ) * ( p[ 1 ] - pi[ 1 ] ) / ( pj[ 1 ] - pi[ 1 ] ) + pi[ 0 ] ) + ) + c = !c; + + } // rof + + if( c != 0 ) + iIt.Set( this->m_InsideValue ); + else + iIt.Set( this->m_OutsideValue ); + + } // rof +} + +#endif // __cpExtensions__Algorithms__RasterContourFilter__hxx__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Interaction/ImageSliceStyle.cxx b/lib/cpExtensions/Interaction/ImageSliceStyle.cxx index a4770c0..93cb1eb 100644 --- a/lib/cpExtensions/Interaction/ImageSliceStyle.cxx +++ b/lib/cpExtensions/Interaction/ImageSliceStyle.cxx @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -93,6 +94,8 @@ OnMouseWheelForward( ) s += ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1; this->m_WLActor->SetSliceNumber( s ); s = this->m_WLActor->GetSliceNumber( ); + if( this->m_LUTActor.GetPointer( ) != NULL ) + this->m_LUTActor->SetSliceNumber( s ); this->InvokeEvent( vtkCommand::UserEvent + 2, &s ); this->Interactor->Render( ); this->OnMouseMove( ); @@ -109,6 +112,8 @@ OnMouseWheelBackward( ) s -= ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1; this->m_WLActor->SetSliceNumber( s ); s = this->m_WLActor->GetSliceNumber( ); + if( this->m_LUTActor.GetPointer( ) != NULL ) + this->m_LUTActor->SetSliceNumber( s ); this->InvokeEvent( vtkCommand::UserEvent + 2, &s ); this->Interactor->Render( ); this->OnMouseMove( ); @@ -307,6 +312,13 @@ _PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] ) this->m_PropPicker->GetPickList( )->RemoveAllItems( ); this->m_PropPicker->AddPickList( curr_actor ); + auto props = this->CurrentRenderer->GetViewProps( ); + this->m_LUTActor = NULL; + props->InitTraversal( ); + vtkProp* prop; + while( ( ( prop = props->GetNextProp( ) ) != NULL ) && ( this->m_LUTActor.GetPointer( ) == NULL ) ) + this->m_LUTActor = dynamic_cast< TLUTActor* >( prop ); + this->m_Cursor->SetImageBounds( curr_actor->GetImage( )->GetBounds( ) ); this->m_Cursor->SetImageOrientation( curr_actor->GetOrientation( ) ); this->m_Cursor->InitTraversal( ); diff --git a/lib/cpExtensions/Interaction/ImageSliceStyle.h b/lib/cpExtensions/Interaction/ImageSliceStyle.h index 9fa3449..6d2b114 100644 --- a/lib/cpExtensions/Interaction/ImageSliceStyle.h +++ b/lib/cpExtensions/Interaction/ImageSliceStyle.h @@ -15,6 +15,7 @@ namespace cpExtensions namespace Visualization { class CursorActors; + class LUTImageActor; class WindowLevelImageActor; } namespace Interaction @@ -27,6 +28,7 @@ namespace cpExtensions public: typedef ImageSliceStyle Self; typedef cpExtensions::Visualization::CursorActors TCursor; + typedef cpExtensions::Visualization::LUTImageActor TLUTActor; typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor; public: @@ -70,6 +72,7 @@ namespace cpExtensions protected: vtkSmartPointer< vtkPropPicker > m_PropPicker; + vtkSmartPointer< TLUTActor > m_LUTActor; vtkSmartPointer< TWLActor > m_WLActor; vtkSmartPointer< TCursor > m_Cursor; vtkSmartPointer< vtkTextActor > m_Text; diff --git a/lib/cpExtensions/Interaction/SeedWidget.cxx b/lib/cpExtensions/Interaction/SeedWidget.cxx index 1dcf223..b6e348f 100644 --- a/lib/cpExtensions/Interaction/SeedWidget.cxx +++ b/lib/cpExtensions/Interaction/SeedWidget.cxx @@ -93,6 +93,7 @@ void cpExtensions::Interaction::SeedWidget:: _CompletedAction( vtkAbstractWidget* wdg ) { // Do nothing + Self::CompletedAction( wdg ); } // ------------------------------------------------------------------------- @@ -100,6 +101,7 @@ void cpExtensions::Interaction::SeedWidget:: _MoveAction( vtkAbstractWidget* wdg ) { // Do nothing + Self::MoveAction( wdg ); } // ------------------------------------------------------------------------- @@ -107,6 +109,7 @@ void cpExtensions::Interaction::SeedWidget:: _EndSelectAction( vtkAbstractWidget* wdg ) { // Do nothing + Self::EndSelectAction( wdg ); } // ------------------------------------------------------------------------- @@ -114,6 +117,7 @@ void cpExtensions::Interaction::SeedWidget:: _DeleteAction( vtkAbstractWidget* wdg ) { // Do nothing + Self::DeleteAction( wdg ); } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/QT/ImageWidget.cxx b/lib/cpExtensions/QT/ImageWidget.cxx index 60ca9a0..35557f5 100644 --- a/lib/cpExtensions/QT/ImageWidget.cxx +++ b/lib/cpExtensions/QT/ImageWidget.cxx @@ -3,12 +3,15 @@ #ifdef cpExtensions_QT4 #include +#include #include #include #include +#include #include #include +#include #include #include @@ -35,8 +38,12 @@ ImageWidget( QWidget* parent, Qt::WindowFlags f ) cpExtensions::QT::ImageWidget:: ~ImageWidget( ) { + this->Clear( ); if( this->m_OutlineActor != NULL ) delete this->m_OutlineActor; + for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a ) + delete *a; + this->m_Actors.clear( ); } // ------------------------------------------------------------------------- @@ -61,6 +68,9 @@ SetImage( vtkImageData* image, int orientation, const std::string& name ) this->m_WLActor->SetImage( image ); this->m_WLActor->SetOrientation( orientation ); + this->m_LUTActor = vtkSmartPointer< TLUTActor >::New( ); + this->m_LUTActor->SetOrientation( orientation ); + this->m_Outline = vtkSmartPointer< TOutline >::New( ); this->m_Outline->SetBounds( image->GetBounds( ) ); this->m_Outline->Update( ); @@ -87,6 +97,30 @@ SetImage( vtkImageData* image, int orientation, const std::string& name ) this->ResetCamera( ); } +// ------------------------------------------------------------------------- +void cpExtensions::QT::ImageWidget:: +Add( vtkDataSet* data, const std::string& name ) +{ + auto image = dynamic_cast< vtkImageData* >( data ); + auto pdata = dynamic_cast< vtkPolyData* >( data ); + if( image != NULL ) + { + this->m_LUTActor->AddImage( image ); + this->m_LUTActor->GetProperty( )->SetOpacity( 0.5 ); + this->AddViewProp( this->m_LUTActor, "__LUT_IMAGE__" ); + this->Render( ); + } + else if( pdata != NULL ) + { + TActor* actor = new TActor( ); + actor->SetMesh( pdata ); + this->m_Actors.push_back( actor ); + this->AddViewProp( actor->GetActor( ), name ); + this->Render( ); + + } // fi +} + // ------------------------------------------------------------------------- void cpExtensions::QT::ImageWidget:: ResetCamera( ) @@ -129,10 +163,10 @@ ResetCamera( ) } else if( ori == 2 ) { - if ( this->m_Quadrant == 0 ) up[ 1 ] = double( 1 ); - else if( this->m_Quadrant == 1 ) up[ 1 ] = double( 1 ); - else if( this->m_Quadrant == 2 ) up[ 1 ] = double( 1 ); - else if( this->m_Quadrant == 3 ) up[ 1 ] = double( 1 ); + if ( this->m_Quadrant == 0 ) up[ 1 ] = double( -1 ); + else if( this->m_Quadrant == 1 ) up[ 1 ] = double( -1 ); + else if( this->m_Quadrant == 2 ) up[ 1 ] = double( -1 ); + else if( this->m_Quadrant == 3 ) up[ 1 ] = double( -1 ); pos[ 2 ] *= double( -1 ); } // fi @@ -168,6 +202,36 @@ GetImageActor( ) const return( this->m_WLActor ); } +// ------------------------------------------------------------------------- +void cpExtensions::QT::ImageWidget:: +SetColor( const std::string& name, double r, double g, double b ) +{ + auto props = this->GetViewProps( name ); + for( auto p = props.begin( ); p != props.end( ); ++p ) + { + auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) ); + if( actor != NULL ) + actor->GetProperty( )->SetColor( r, g, b ); + + } // rof + this->Render( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::ImageWidget:: +SetLineWidth( const std::string& name, double w ) +{ + auto props = this->GetViewProps( name ); + for( auto p = props.begin( ); p != props.end( ); ++p ) + { + auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) ); + if( actor != NULL ) + actor->GetProperty( )->SetLineWidth( w ); + + } // rof + this->Render( ); +} + /* TODO // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/QT/ImageWidget.h b/lib/cpExtensions/QT/ImageWidget.h index c278557..3e3721e 100644 --- a/lib/cpExtensions/QT/ImageWidget.h +++ b/lib/cpExtensions/QT/ImageWidget.h @@ -5,19 +5,18 @@ #ifdef cpExtensions_QT4 -// TODO: class vtkDataSet; +// ------------------------------------------------------------------------- +class vtkDataSet; +// ------------------------------------------------------------------------- namespace cpExtensions { namespace Visualization { class OutlineSource; + class LUTImageActor; class WindowLevelImageActor; class MeshActor; - /* TODO - class ImageSliceActors; - class ImageViewerActors; - */ } namespace Interaction { class ImageSliceStyle; } @@ -36,6 +35,7 @@ namespace cpExtensions typedef cpExtensions::Visualization::OutlineSource TOutline; typedef cpExtensions::Visualization::MeshActor TActor; + typedef cpExtensions::Visualization::LUTImageActor TLUTActor; typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor; typedef cpExtensions::Interaction::ImageSliceStyle TStyle; @@ -47,16 +47,19 @@ namespace cpExtensions void SetImage( vtkImageData* image, int orientation, const std::string& name ); + void Add( vtkDataSet* data, const std::string& name ); virtual void ResetCamera( ) cpExtensions_OVERRIDE; TWLActor* GetImageActor( ); const TWLActor* GetImageActor( ) const; + void SetColor( const std::string& name, double r, double g, double b ); + void SetLineWidth( const std::string& name, double w ); + /* TODO void SetImage( vtkImageData* image, int orientation, const std::string& name ); - void Add( vtkDataSet* data, const std::string& name ); // TODO: std::vector< vtkProp* > GetActors( const std::string& name ) const; int GetOrientation( ) const; @@ -81,8 +84,10 @@ namespace cpExtensions std::string m_ImageName; vtkSmartPointer< TWLActor > m_WLActor; + vtkSmartPointer< TLUTActor > m_LUTActor; vtkSmartPointer< TOutline > m_Outline; TActor* m_OutlineActor; + std::vector< TActor* > m_Actors; vtkSmartPointer< TStyle > m_Style; diff --git a/lib/cpExtensions/QT/MPR3DWidget.cxx b/lib/cpExtensions/QT/MPR3DWidget.cxx index 788fb22..b4224a7 100644 --- a/lib/cpExtensions/QT/MPR3DWidget.cxx +++ b/lib/cpExtensions/QT/MPR3DWidget.cxx @@ -3,17 +3,18 @@ #ifdef cpExtensions_QT4 #include +#include #include #include #include +#include /* TODO #include #include #include - #include */ // ------------------------------------------------------------------------- @@ -32,6 +33,9 @@ MPR3DWidget( QWidget* parent, Qt::WindowFlags f ) cpExtensions::QT::MPR3DWidget:: ~MPR3DWidget( ) { + for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a ) + delete *a; + this->m_Actors.clear( ); } // ------------------------------------------------------------------------- @@ -70,6 +74,35 @@ SetImage( vtkImageData* image, const std::string& name ) } // rof } +// ------------------------------------------------------------------------- +void cpExtensions::QT::MPR3DWidget:: +Add( vtkDataSet* data, const std::string& name ) +{ + auto image = dynamic_cast< vtkImageData* >( data ); + auto pdata = dynamic_cast< vtkPolyData* >( data ); + if( image != NULL ) + { + /* TODO + if( this->m_ImageName != "" ) + { + } + else + this->SetImage( image, name ); + */ + } + else if( pdata != NULL ) + { + TActor* actor = new TActor( ); + actor->SetMesh( pdata ); + this->m_Actors.push_back( actor ); + this->AddViewProp( actor->GetActor( ), name ); + this->Render( ); + if( this->m_ImageName == "" ) + this->ResetCamera( ); + + } // fi +} + // ------------------------------------------------------------------------- cpExtensions::QT::MPR3DWidget:: TWLActor* cpExtensions::QT::MPR3DWidget:: @@ -145,50 +178,6 @@ SetImage( vtkImageData* image, const std::string& name ) this->Render( ); } -// ------------------------------------------------------------------------- -void cpExtensions::QT::MPR3DWidget:: -Add( vtkDataSet* data, const std::string& name ) -{ - auto image = dynamic_cast< vtkImageData* >( data ); - auto pdata = dynamic_cast< vtkPolyData* >( data ); - if( image != NULL ) - { - if( this->m_ImageName != "" ) - { - } - else - this->SetImage( image, name ); - } - else if( pdata != NULL ) - { - this->AddViewProp( this->m_Actors->AddMesh( pdata ), name ); - this->Render( ); - if( this->m_ImageName == "" ) - this->ResetCamera( ); - - } // fi - - return; - - auto image = dynamic_cast< vtkImageData* >( data ); - auto pdata = dynamic_cast< vtkPolyData* >( data ); - if( image != NULL ) - { - this->m_Actors->AddLUTImage( image ); - vtkSmartPointer< vtkPropCollection > coll = - vtkSmartPointer< vtkPropCollection >::New( ); - coll->AddItem( this->m_Actors->GetLUTImageActor( 0 ) ); - coll->AddItem( this->m_Actors->GetLUTImageActor( 1 ) ); - coll->AddItem( this->m_Actors->GetLUTImageActor( 2 ) ); - this->AddViewProps( coll, name ); - this->Render( ); - } - else if( pdata != NULL ) - { - - } // fi -} - // ------------------------------------------------------------------------- void cpExtensions::QT::MPR3DWidget:: SetSliceNumber( int orientation, int slice ) diff --git a/lib/cpExtensions/QT/MPR3DWidget.h b/lib/cpExtensions/QT/MPR3DWidget.h index 6dcd864..667e0e2 100644 --- a/lib/cpExtensions/QT/MPR3DWidget.h +++ b/lib/cpExtensions/QT/MPR3DWidget.h @@ -14,6 +14,7 @@ namespace cpExtensions namespace Visualization { class ImageOutlineActor; + class MeshActor; class WindowLevelImageActor; } @@ -30,6 +31,7 @@ namespace cpExtensions typedef MPR3DWidget Self; typedef cpExtensions::QT::RendererWidget Superclass; + typedef cpExtensions::Visualization::MeshActor TActor; typedef cpExtensions::Visualization::ImageOutlineActor TOLActor; typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor; @@ -39,6 +41,7 @@ namespace cpExtensions void Clear( ); void SetImage( vtkImageData* image, const std::string& name ); + void Add( vtkDataSet* data, const std::string& name ); TWLActor* GetImageActor( int o ); const TWLActor* GetImageActor( int o ) const; @@ -48,7 +51,6 @@ namespace cpExtensions /* TODO void SetImage( vtkImageData* image, const std::string& name ); - void Add( vtkDataSet* data, const std::string& name ); void SetScalarRange( double r[ 2 ] ); @@ -62,6 +64,7 @@ namespace cpExtensions vtkSmartPointer< TWLActor > m_WLActors[ 3 ]; vtkSmartPointer< TOLActor > m_OLActors[ 3 ]; + std::vector< TActor* > m_Actors; /* TODO vtkSmartPointer< cpExtensions::Visualization::MPR3DActors > m_Actors; diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index 95af5ab..665b0a1 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -180,7 +180,6 @@ bool cpExtensions::QT::SimpleMPRWidget:: Add( vtkDataSet* data, const std::string& name ) { bool success = true; -/* auto image = dynamic_cast< vtkImageData* >( data ); auto pdata = dynamic_cast< vtkPolyData* >( data ); @@ -191,7 +190,7 @@ Add( vtkDataSet* data, const std::string& name ) this->m_XImage->Add( image, name ); this->m_YImage->Add( image, name ); this->m_ZImage->Add( image, name ); - this->m_3DView->Add( image, name ); + // TODO: this->m_3DView->Add( image, name ); } else this->SetImage( image, name ); @@ -200,7 +199,6 @@ Add( vtkDataSet* data, const std::string& name ) this->m_3DView->Add( pdata, name ); else success = false; -*/ return( success ); } diff --git a/lib/cpExtensions/Visualization/LUTImageActor.cxx b/lib/cpExtensions/Visualization/LUTImageActor.cxx index 1c9f9fa..a022b30 100644 --- a/lib/cpExtensions/Visualization/LUTImageActor.cxx +++ b/lib/cpExtensions/Visualization/LUTImageActor.cxx @@ -99,15 +99,26 @@ SetLUTColor( vtkImageData* image, double r, double g, double b, double a ) this->SetLUTColor( this->GetImageId( image ), r, g, b, a ); } +// TODO: !!!!! +#include + // ------------------------------------------------------------------------- unsigned int cpExtensions::Visualization::LUTImageActor:: AddImage( vtkImageData* image, double r, double g, double b, double a ) { + static vtkSmartPointer< vtkImageCast > cast; + cast = vtkSmartPointer< vtkImageCast >::New( ); + if( image != NULL ) { + cast->SetOutputScalarTypeToUnsignedChar( ); + cast->SetInputData( image ); + cast->Update( ); + this->m_Images.push_back( image ); this->SetLUTColor( this->m_Images.size( ), r, g, b, a ); - this->m_Blender->AddInputData( image ); + this->m_Blender->AddInputData( cast->GetOutput( ) ); + this->m_Blender->Update( ); if( this->m_Images.size( ) == 1 ) { @@ -117,8 +128,6 @@ AddImage( vtkImageData* image, double r, double g, double b, double a ) SetInputConnection( this->m_ImageMap->GetOutputPort( ) ); } // fi - this->m_Blender->Modified( ); - this->m_ImageMap->Modified( ); this->Modified( ); this->GetProperty( )->SetInterpolationTypeToNearest( ); diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx index 8887f89..3e68371 100644 --- a/lib/cpPlugins/Interface/Plugins.cxx +++ b/lib/cpPlugins/Interface/Plugins.cxx @@ -426,6 +426,12 @@ Plugins( ) str << p << cpPlugins_ENV_SEPARATOR; str << "."; this->AddEnvironments( str.str( ) ); + + // Try to read locally defined paths + std::vector< std::string > tokens; + cpExtensions::Tokenize( tokens, str.str( ), cpPlugins_ENV_SEPARATOR ); + for( auto t = tokens.begin( ); t != tokens.end( ); ++t ) + this->OpenEnvironments( *t ); } // ------------------------------------------------------------------------- diff --git a/plugins/ImageDistanceMaps/SignedMaurerDistanceMapImageFilter.cxx b/plugins/ImageDistanceMaps/SignedMaurerDistanceMapImageFilter.cxx index c3ba0b5..4100194 100644 --- a/plugins/ImageDistanceMaps/SignedMaurerDistanceMapImageFilter.cxx +++ b/plugins/ImageDistanceMaps/SignedMaurerDistanceMapImageFilter.cxx @@ -46,7 +46,7 @@ _GenerateData( ) auto o = this->GetInputData( "Input" ); cpPlugins_Demangle_ImageScalars( o, _GD0, 2 ); else cpPlugins_Demangle_ImageScalars( o, _GD0, 3 ); - else this->_Error( "No valid input image." ); + else this->_Error( "Invalid input image." ); } // ------------------------------------------------------------------------- diff --git a/plugins/ImageMeshFilters/RasterMeshFilter.cxx b/plugins/ImageMeshFilters/RasterMeshFilter.cxx index f2ac07f..4124cb1 100644 --- a/plugins/ImageMeshFilters/RasterMeshFilter.cxx +++ b/plugins/ImageMeshFilters/RasterMeshFilter.cxx @@ -1,15 +1,12 @@ #include #include #include - -#include -#include -#include -#include -#include +#include #include +#include #include +#include // ------------------------------------------------------------------------- cpPluginsImageMeshFilters::RasterMeshFilter:: @@ -72,125 +69,24 @@ template< class _TMesh > void cpPluginsImageMeshFilters::RasterMeshFilter:: _GD0_2D( _TMesh* mesh ) { + typedef unsigned char _TPixel; typedef itk::ImageBase< 2 > _TImageBase; - typedef itk::Image< unsigned char, 2 > _TImage; - typedef cpPlugins::DataObjects::BoundingBox _TBB; - typedef typename _TImage::PointType _TPoint; + typedef itk::Image< _TPixel, 2 > _TImage; + typedef cpExtensions::Algorithms::RasterContourFilter< _TImage > _TFilter; - static const unsigned int PAD = 10; - - _TImage::Pointer white = this->GetOutputData< _TImage >( "Output" ); - if( white.IsNull( ) ) - white = _TImage::New( ); - - // Get configuration values - typename _TImage::SpacingType spac; - typename _TImage::SizeType size; - typename _TImage::PointType origin; - typename _TImage::DirectionType direction; - typename _TImage::IndexType index; - - auto in_bb = this->GetInput< _TBB >( "Template" ); auto in_im = this->GetInputData< _TImageBase >( "Template" ); - if( in_im != NULL ) - { - spac = in_im->GetSpacing( ); - size = in_im->GetLargestPossibleRegion( ).GetSize( ); - origin = in_im->GetOrigin( ); - direction = in_im->GetDirection( ); - index = in_im->GetLargestPossibleRegion( ).GetIndex( ); - } - else - { - _TPoint minBB, maxBB; - if( in_bb != NULL ) - { - minBB = in_bb->GetMinimum< _TPoint >( ); - maxBB = in_bb->GetMaximum< _TPoint >( ); - } - else - { - double bounds[ 6 ]; - mesh->GetBounds( bounds ); - minBB[ 0 ] = bounds[ 0 ]; - minBB[ 1 ] = bounds[ 1 ]; - maxBB[ 0 ] = bounds[ 2 ]; - maxBB[ 1 ] = bounds[ 3 ]; - - } // fi - - double lx = double( maxBB[ 0 ] - minBB[ 0 ] ); - double ly = double( maxBB[ 1 ] - minBB[ 1 ] ); - double lm = ( lx < ly )? lx: ly; - - // Compute spacing - spac.Fill( lm / double( this->m_Parameters.GetUint( "MinimumSize" ) ) ); - - // Compute size - size[ 0 ] = ( unsigned long )( std::ceil( lx / spac[ 0 ] ) ); - size[ 1 ] = ( unsigned long )( std::ceil( ly / spac[ 1 ] ) ); - - // ... add some padding pixels - size[ 0 ] += PAD; - size[ 1 ] += PAD; - - // Set origin - origin = minBB; - origin[ 0 ] -= double( PAD >> 1 ) * spac[ 0 ]; - origin[ 1 ] -= double( PAD >> 1 ) * spac[ 1 ]; - - // Remaining values - direction.SetIdentity( ); - index.Fill( 0 ); - - } // fi - - // Configure output image - _TImage::RegionType region; - region.SetSize( size ); - region.SetIndex( index ); - white->SetSpacing( spac ); - white->SetRegions( region ); - white->SetOrigin( origin ); - white->SetDirection( direction ); - white->Allocate( ); - white->FillBuffer( this->m_Parameters.GetUint( "InsideValue" ) ); - if( this->m_WhiteImage.IsNull( ) ) - this->m_WhiteImage = TImage::New( ); - this->m_WhiteImage->SetITK( white ); - vtkImageData* white_vtk = this->m_WhiteImage->GetVTK< vtkImageData >( ); - - // Configure mini-pipeline - if( this->m_Stripper.GetPointer( ) == NULL ) - this->m_Stripper = vtkSmartPointer< vtkStripper >::New( ); - this->m_Stripper->SetInputData( mesh ); - this->m_Stripper->Update( ); - - if( this->m_Extruder.GetPointer( ) == NULL ) - this->m_Extruder = vtkSmartPointer< vtkLinearExtrusionFilter >::New( ); - this->m_Extruder->SetInputConnection( this->m_Stripper->GetOutputPort( ) ); - this->m_Extruder->SetScaleFactor( double( 1 ) ); - this->m_Extruder->SetExtrusionTypeToNormalExtrusion( ); - this->m_Extruder->SetVector( 0, 0, 1 ); - this->m_Extruder->Update( ); - - if( this->m_PolyDataToStencil.GetPointer( ) == NULL ) - this->m_PolyDataToStencil = - vtkSmartPointer< vtkPolyDataToImageStencil >::New( ); - this->m_PolyDataToStencil->SetTolerance( 0 ); - this->m_PolyDataToStencil->SetInputConnection( this->m_Extruder->GetOutputPort( ) ); - this->m_PolyDataToStencil->SetOutputOrigin( white_vtk->GetOrigin( ) ); - this->m_PolyDataToStencil->SetOutputSpacing( white_vtk->GetSpacing( ) ); - this->m_PolyDataToStencil->SetOutputWholeExtent( white_vtk->GetExtent( ) ); - this->m_PolyDataToStencil->Update( ); - - this->m_ImageStencil = this->_CreateVTK< vtkImageStencil >( ); - this->m_ImageStencil->SetInputData( white_vtk ); - this->m_ImageStencil->SetStencilConnection( this->m_PolyDataToStencil->GetOutputPort( ) ); - this->m_ImageStencil->ReverseStencilOff( ); - this->m_ImageStencil->SetBackgroundValue( this->m_Parameters.GetUint( "OutsideValue" ) ); - this->m_ImageStencil->Update( ); - this->GetOutput( "Output" )->SetVTK( this->m_ImageStencil->GetOutput( ) ); + if( in_im == NULL ) + this->_Error( "A template is needed for 2D raster (this is temporal)." ); + _TPixel inside = _TPixel( this->m_Parameters.GetUint( "InsideValue" ) ); + _TPixel outside = _TPixel( this->m_Parameters.GetUint( "OutsideValue" ) ); + + auto filter = this->_CreateITK< _TFilter >( ); + filter->AddPoints( mesh->GetPoints( ) ); + filter->SetTemplate( in_im ); + filter->SetInsideValue( inside ); + filter->SetOutsideValue( outside ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); } // ------------------------------------------------------------------------- @@ -208,11 +104,6 @@ _GD0_3D( _TMesh* mesh ) static const unsigned int PAD = 10; _TFilter* filter = this->_CreateITK< _TFilter >( ); - this->m_WhiteImage = NULL; - this->m_Stripper = NULL; - this->m_Extruder = NULL; - this->m_PolyDataToStencil = NULL; - this->m_ImageStencil = NULL; // Get configuration values typename _TImage::SpacingType spac; diff --git a/plugins/ImageMeshFilters/RasterMeshFilter.h b/plugins/ImageMeshFilters/RasterMeshFilter.h index d6c1953..50f9859 100644 --- a/plugins/ImageMeshFilters/RasterMeshFilter.h +++ b/plugins/ImageMeshFilters/RasterMeshFilter.h @@ -6,13 +6,6 @@ #include #include -// ------------------------------------------------------------------------- -class vtkStripper; -class vtkLinearExtrusionFilter; -class vtkPolyDataToImageStencil; -class vtkImageStencil; - -// ------------------------------------------------------------------------- namespace cpPluginsImageMeshFilters { /** @@ -35,13 +28,6 @@ namespace cpPluginsImageMeshFilters template< class _TMesh > inline void _GD0_3D( _TMesh* mesh ); - - protected: - TImage::Pointer m_WhiteImage; - vtkSmartPointer< vtkStripper > m_Stripper; - vtkSmartPointer< vtkLinearExtrusionFilter > m_Extruder; - vtkSmartPointer< vtkPolyDataToImageStencil > m_PolyDataToStencil; - vtkSmartPointer< vtkImageStencil > m_ImageStencil; }; } // ecapseman diff --git a/plugins/Widgets/SplineWidget.cxx b/plugins/Widgets/SplineWidget.cxx index 74680df..1bba488 100644 --- a/plugins/Widgets/SplineWidget.cxx +++ b/plugins/Widgets/SplineWidget.cxx @@ -115,200 +115,6 @@ _GenerateData( ) this->m_Configured = true; } // fi - - /* TODO - - if( this->m_Configured ) - { - if( points->GetNumberOfPoints( ) == 0 ) - { - std::stringstream text; - bool start = true; - for( auto w = this->m_Widgets.begin( ); w != this->m_Widgets.end( ); ++w ) - { - for( auto r = ( *w )->Widgets.begin( ); r != ( *w )->Widgets.end( ); ++r ) - { - auto rep = - dynamic_cast< vtkSeedRepresentation* >( - ( *r )->GetRepresentation( ) - ); - if( rep != NULL ) - { - double pos[ 3 ]; - for( unsigned int i = 0; i < rep->GetNumberOfSeeds( ); ++i ) - { - rep->GetSeedWorldPosition( i, pos ); - if( !start ) - text << "#"; - start = false; - text << pos[ 0 ] << " " << pos[ 1 ] << " " << pos[ 2 ]; - points->InsertNextPoint( pos ); - - } // rof - - } // rof - ( *r )->EnabledOff( ); - - } // rof - - } // rof - this->m_Parameters.SetString( "Text", text.str( ) ); - - } // fi - } - else - { - auto init_seeds = this->m_Parameters.GetString( "Text" ); - std::vector< std::string > tokens; - cpExtensions::Tokenize( tokens, init_seeds, "#" ); - for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt ) - { - std::vector< std::string > coords; - cpExtensions::Tokenize( coords, *tIt, " \t" ); - int dim = ( coords.size( ) < 3 )? coords.size( ): 3; - double pos[ 3 ]; - for( unsigned int d = 0; d < 3; ++d ) - { - pos[ d ] = double( 0 ); - if( d < dim ) - { - std::istringstream value( coords[ d ] ); - value >> pos[ d ]; - - } // fi - - } // rof - verts->InsertNextCell( 1 ); - verts->InsertCellPoint( points->GetNumberOfPoints( ) ); - points->InsertNextPoint( pos ); - - } // rof - this->_Configure( ); - this->Modified( ); - this->m_Configured = true; - - } // fi - this->GetOutput( "Output" )->SetVTK( pdata ); - */ -} - -// ------------------------------------------------------------------------- -/* TODO -void cpPluginsWidgets::SplineWidget:: -_Configure( ) -{ - typedef cpPlugins::DataObjects::Image _TImage; - - auto image = this->GetInput< _TImage >( "Input" ); - if( image != NULL ) - { - // Update actors - auto vtk_image = image->GetVTK< vtkImageData >( ); - auto iIt = this->m_Interactors.begin( ); - for( ; iIt != this->m_Interactors.end( ); ++iIt ) - { - auto ren = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( ); - if( ren != NULL ) - { - auto props = ren->GetViewProps( ); - if( props != NULL ) - { - props->InitTraversal( ); - while( vtkProp* prop = props->GetNextProp( ) ) - { - auto actor = dynamic_cast< TImageActor* >( prop ); - if( actor != NULL ) - if( actor->GetImage( ) == vtk_image ) - this->m_Props[ actor ] = *iIt; - - } // elihw - - } // fi - - } // fi - - } // rof - - // Process image - if( this->m_Props.size( ) > 0 ) - { - cpPlugins_Demangle_ImageVisualDims( image->GetITK( ), _GD0_Image ); - else this->_Error( "Invalid input image." ); - } - else - this->_Error( "Could not create a valid widget: no actors." ); - } - else - this->_Error( "Could not create a valid widget: no input." ); -} - -// ------------------------------------------------------------------------- -template< class _TImage > -void cpPluginsWidgets::SplineWidget:: -_GD0_Image( _TImage* image ) -{ - for( auto p = this->m_Props.begin( ); p != this->m_Props.end( ); ++p ) - { - TWidgetData* d = - new TWidgetData( - this, dynamic_cast< TImageActor* >( p->first ), p->second - ); - this->m_Widgets.push_back( d ); - - } // rof -} - -// ------------------------------------------------------------------------- -cpPluginsWidgets::SplineWidget::TWidgetData:: -TWidgetData( - SplineWidget* seedWidget, - TImageActor* actor, - vtkRenderWindowInteractor* iren - ) -{ - auto cb = vtkSmartPointer< SplineWidgetCallback >::New( ); - cb->Widget = seedWidget; - cb->Data = this; - this->Command = cb; - actor->AddObserver( vtkCommand::InteractionEvent, cb ); - - auto image = actor->GetImage( ); - int ori = actor->GetOrientation( ); - int ext[ 6 ]; - image->GetExtent( ext ); - for( int i = ext[ ori << 1 ]; i <= ext[ ( ori << 1 ) + 1 ]; ++i ) - { - auto placer = vtkSmartPointer< _TPlacer >::New( ); - auto handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); - auto rep = vtkSmartPointer< vtkSeedRepresentation >::New( ); - auto wdg = vtkSmartPointer< _TWidget >::New( ); - - placer->SetImageSlice( actor ); - handle->GetProperty( )->SetColor( 1, 0, 0 ); - handle->SetPointPlacer( placer ); - rep->SetHandleRepresentation( handle ); - wdg->SetRepresentation( rep ); - wdg->SetInteractor( iren ); - wdg->AddObserver( vtkCommand::PlacePointEvent, cb ); - wdg->AddObserver( vtkCommand::CursorChangedEvent, cb ); - wdg->EnabledOff( ); - - this->Widgets.push_back( wdg ); - this->Placers.push_back( placer ); - this->Handles.push_back( handle ); - this->Representations.push_back( rep ); - - } // rof - - this->ActualWidgetId = actor->GetSliceNumber( ); - this->Widgets[ this->ActualWidgetId ]->EnabledOn( ); -} - -// ------------------------------------------------------------------------- -cpPluginsWidgets::SplineWidget::TWidgetData:: -~TWidgetData( ) -{ } -*/ // eof - $RCSfile$