#include <cpExtensions/QT/ImageWidget.h>
-
-#ifdef cpExtensions_QT4
-
#include <cpExtensions/Interaction/ImageSliceStyle.h>
-#include <cpExtensions/Visualization/ImageOutlineActor.h>
+#include <cpExtensions/Visualization/LUTImageActor.h>
+#include <cpExtensions/Visualization/MeshActor.h>
+#include <cpExtensions/Visualization/OutlineSource.h>
#include <cpExtensions/Visualization/WindowLevelImageActor.h>
+#include <vtkActor.h>
+#include <vtkCamera.h>
+#include <vtkImageData.h>
+#include <vtkImageProperty.h>
+#include <vtkProperty.h>
#include <vtkRenderer.h>
-/* TODO
- #include <cpExtensions/Visualization/ImageViewerActors.h>
- #include <cpExtensions/Visualization/LUTImageActor.h>
- #include <vtkCamera.h>
- #include <vtkImageData.h>
- #include <vtkImageProperty.h>
-*/
-
// -------------------------------------------------------------------------
cpExtensions::QT::ImageWidget::
ImageWidget( QWidget* parent, Qt::WindowFlags f )
: Superclass( parent, f ),
- m_ImageName( "" )
+ m_ImageName( "" ),
+ m_OutlineActor( NULL )
{
this->m_Style = vtkSmartPointer< TStyle >::New( );
this->m_Style->SetCurrentRenderer( this->m_Renderer );
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( );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void cpExtensions::QT::ImageWidget::
-SetImage( vtkImageData* image, int orientation, const std::string& name )
+SetImage( vtkImageData* image, const std::string& name, int orientation )
{
if( name == "" )
return;
this->m_WLActor->SetImage( image );
this->m_WLActor->SetOrientation( orientation );
- this->m_OLActor = vtkSmartPointer< TOLActor >::New( );
- this->m_OLActor->SetBounds(
- orientation,
- this->m_WLActor->GetBounds( )[ orientation ],
- this->m_WLActor->GetBounds( )
- );
-
- this->AddViewProp( this->m_WLActor, this->m_ImageName );
- this->AddAuxViewProp( this->m_OLActor, this->m_ImageName );
- this->ResetCamera( );
-}
-
+ this->m_LUTActor = vtkSmartPointer< TLUTActor >::New( );
+ this->m_LUTActor->SetOrientation( orientation );
-/* TODO
-// -------------------------------------------------------------------------
-vtkInteractorStyle* cpExtensions::QT::ImageWidget::
-GetInteractorStyle( )
-{
- return( this->m_ImageSliceStyle );
-}
+ this->m_Outline = vtkSmartPointer< TOutline >::New( );
+ this->m_Outline->SetBounds( image->GetBounds( ) );
+ this->m_Outline->Update( );
-// -------------------------------------------------------------------------
-const vtkInteractorStyle* cpExtensions::QT::ImageWidget::
-GetInteractorStyle( ) const
-{
- return( this->m_ImageSliceStyle );
-}
+ if( this->m_OutlineActor != NULL )
+ delete this->m_OutlineActor;
+ this->m_OutlineActor = new TActor( );
+ this->m_OutlineActor->SetMesh( this->m_Outline->GetOutput( ) );
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetImage( vtkImageData* image, int orientation, const std::string& name )
-{
- if( this->m_ImageName != "" )
+ double cr = double( 0 );
+ double cg = double( 0 );
+ double cb = double( 0 );
+ switch( this->m_WLActor->GetOrientation( ) )
{
- // TODO: Clear visualization
-
- } // fi
- this->m_ImageName = name;
+ case 0: cr = double( 1 ); break;
+ case 1: cg = double( 1 ); break;
+ case 2: cb = double( 1 ); break;
+ default: cr = double( 1 ); break;
+ } // hctiws
+ this->m_OutlineActor->GetActor( )->GetProperty( )->SetColor( cr, cg, cb );
- this->GetActiveCamera( )->ParallelProjectionOn( );
-
- this->m_ImageViewerActors =
- vtkSmartPointer< cpExtensions::Visualization::ImageViewerActors >::New( );
- this->m_ImageViewerActors->SetImage( image, orientation );
-
- this->m_ImageSliceStyle->SetActors( this->m_ImageViewerActors );
-
- this->AddViewProp(
- this->m_ImageViewerActors->GetWindowLevelImageActor( ),
- this->m_ImageName
- );
- this->AddAuxViewProps( this->m_ImageViewerActors, this->m_ImageName );
+ this->AddViewProp( this->m_WLActor, this->m_ImageName );
+ this->AddAuxViewProp( this->m_OutlineActor->GetActor( ), this->m_ImageName );
this->ResetCamera( );
}
Add( vtkDataSet* data, const std::string& name )
{
auto image = dynamic_cast< vtkImageData* >( data );
-
- if( image == NULL )
+ auto pdata = dynamic_cast< vtkPolyData* >( data );
+ if( image != NULL )
{
- if( this->m_ImageName == "" )
- this->SetImage( data, name );
- {
- } // fi
- return;
-
- } // fi
-
- if( this->m_ImageName == "" )
- return;
-
- if( this->m_ImageViewerActors.GetPointer( ) != 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 )
{
- if( this->m_ImageViewerActors->AddLUTImage( image ) > 0 )
- {
- this->AddViewProp(
- this->m_ImageViewerActors->GetLUTImageActor( ),
- name
- );
- this->Render( );
-
- } // fi
+ TActor* actor = new TActor( );
+ actor->SetMesh( pdata );
+ this->m_Actors.push_back( actor );
+ this->AddViewProp( actor->GetActor( ), name );
+ this->Render( );
} // fi
}
-// -------------------------------------------------------------------------
-int cpExtensions::QT::ImageWidget::
-GetOrientation( ) const
-{
- return( this->m_ImageViewerActors->GetOrientation( ) );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetSliceNumber( int slice )
-{
- this->m_ImageViewerActors->SetSliceNumber( slice );
- this->Render( );
-}
-
// -------------------------------------------------------------------------
void cpExtensions::QT::ImageWidget::
ResetCamera( )
{
- if( this->m_ImageViewerActors.GetPointer( ) != NULL )
+ if( this->m_WLActor.GetPointer( ) != NULL )
{
- auto image = this->m_ImageViewerActors->GetImage( );
+ auto image = this->m_WLActor->GetImage( );
if( image != NULL )
{
double bounds[ 6 ];
center[ 1 ] = ( bounds[ 3 ] + bounds[ 2 ] ) / double( 2 );
center[ 2 ] = ( bounds[ 5 ] + bounds[ 4 ] ) / double( 2 );
- int ori = this->m_ImageViewerActors->GetOrientation( );
+ int ori = this->m_WLActor->GetOrientation( );
double pos[ 3 ] = { double( 0 ) };
pos[ ori ] = double( 1 );
pos[ 0 ] += center[ 0 ];
}
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
// Reconfigure camera and return
auto camera = this->m_Renderer->GetActiveCamera( );
+ camera->ParallelProjectionOn( );
camera->SetFocalPoint( center );
camera->SetPosition( pos );
camera->SetViewUp( up );
}
// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-GetScalarRange( double r[ 2 ] ) const
-{
- auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
- if( actor != NULL )
- actor->GetRange( r );
- else
- r[ 0 ] = r[ 1 ] = double( 0 );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-GetWindowLevel( double wl[ 2 ] ) const
-{
- auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
- if( actor != NULL )
- {
- wl[ 0 ] = actor->GetWindow( );
- wl[ 1 ] = actor->GetLevel( );
- }
- else
- wl[ 0 ] = wl[ 1 ] = double( 0 );
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::QT::ImageWidget::
-GetImageOpacity( ) const
-{
- auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
- if( actor != NULL )
- return( actor->GetProperty( )->GetOpacity( ) );
- else
- return( double( 0 ) );
-}
-
-// -------------------------------------------------------------------------
-unsigned char cpExtensions::QT::ImageWidget::
-GetImageInterpolation( ) const
-{
- auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
- if( actor != NULL )
- {
- int int_type = actor->GetProperty( )->GetInterpolationType( );
- char ret = 0;
- switch( int_type )
- {
- case VTK_NEAREST_INTERPOLATION: ret = 'N'; break;
- case VTK_LINEAR_INTERPOLATION: ret = 'L'; break;
- case VTK_CUBIC_INTERPOLATION: ret = 'C'; break;
- default: ret = 0; break;
- } // hctiws
- return( ret );
- }
- else
- return( 0 );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetScalarRange( double r[ 2 ] )
+cpExtensions::QT::ImageWidget::
+TWLActor* cpExtensions::QT::ImageWidget::
+GetImageActor( )
{
- auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
- if( actor != NULL )
- {
- actor->ConfigureWindowLevel( r[ 0 ], r[ 1 ] );
- this->Render( );
-
- } // fi
+ return( this->m_WLActor );
}
// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetWindowLevel( double wl[ 2 ] )
+const cpExtensions::QT::ImageWidget::
+TWLActor* cpExtensions::QT::ImageWidget::
+GetImageActor( ) const
{
- auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
- if( actor != NULL )
- {
- actor->SetWindowLevel( wl[ 0 ], wl[ 1 ] );
- this->Render( );
-
- } // fi
+ return( this->m_WLActor );
}
// -------------------------------------------------------------------------
void cpExtensions::QT::ImageWidget::
-SetImageOpacity( double o )
+SetColor( const std::string& name, double r, double g, double b )
{
- auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
- if( actor != NULL )
+ auto props = this->GetViewProps( name );
+ for( auto p = props.begin( ); p != props.end( ); ++p )
{
- actor->GetProperty( )->SetOpacity( o );
- this->Render( );
+ auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+ if( actor != NULL )
+ actor->GetProperty( )->SetColor( r, g, b );
- } // fi
+ } // rof
+ this->Render( );
}
// -------------------------------------------------------------------------
void cpExtensions::QT::ImageWidget::
-SetImageInterpolation( unsigned char i )
+SetLineWidth( const std::string& name, double w )
{
- auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
- if( actor != NULL )
+ auto props = this->GetViewProps( name );
+ for( auto p = props.begin( ); p != props.end( ); ++p )
{
- int int_type = 0;
- switch( i )
- {
- case 'L': int_type = VTK_LINEAR_INTERPOLATION; break;
- case 'C': int_type = VTK_CUBIC_INTERPOLATION; break;
- default : int_type = VTK_NEAREST_INTERPOLATION; break;
- } // hctiws
- actor->GetProperty( )->SetInterpolationType( int_type );
- this->Render( );
+ auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+ if( actor != NULL )
+ actor->GetProperty( )->SetLineWidth( w );
- } // fi
-}
-
-// -------------------------------------------------------------------------
-vtkProp* cpExtensions::QT::ImageWidget::
-GetImageActor( )
-{
- return( this->m_ImageViewerActors->GetWindowLevelImageActor( ) );
-}
-
-// -------------------------------------------------------------------------
-const vtkProp* cpExtensions::QT::ImageWidget::
-GetImageActor( ) const
-{
- return( this->m_ImageViewerActors->GetWindowLevelImageActor( ) );
+ } // rof
+ this->Render( );
}
-*/
-
-#endif // cpExtensions_QT4
// eof - $RCSfile$