#include <cpExtensions/Visualization/ImageSliceActors.h>
+#include <sstream>
+
#include <vtkAlgorithmOutput.h>
#include <vtkCellArray.h>
#include <vtkImageData.h>
#include <vtkPlane.h>
#include <vtkPoints.h>
#include <vtkProperty.h>
+#include <vtkRenderer.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkTextProperty.h>
// Delete all images
this->SliceMappers.clear( );
this->ImageActors.clear( );
- this->OtherActors.clear( );
+ this->AssociatedActors.clear( );
// Reconfigure unique objects
this->PlaneFunction = vtkSmartPointer< vtkPlane >::New( );
coord->SetValue( 0.01, 0.01 );
}
+// -------------------------------------------------------------------------
+vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
+GetStyle( )
+{
+ return( this->Style.GetPointer( ) );
+}
+
+// -------------------------------------------------------------------------
+const vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
+GetStyle( ) const
+{
+ return( this->Style.GetPointer( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+PushActorsInto( vtkRenderer* renderer )
+{
+ unsigned int N = this->GetNumberOfImageActors( );
+ for( unsigned int n = 0; n < N; ++n )
+ renderer->AddActor( this->GetImageActor( n ) );
+ renderer->AddActor( this->GetTextActor( ) );
+ renderer->AddActor( this->GetPlaneActor( ) );
+ renderer->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+PopActorsFrom( vtkRenderer* renderer )
+{
+ unsigned int N = this->GetNumberOfImageActors( );
+ for( unsigned int n = 0; n < N; ++n )
+ renderer->RemoveActor( this->GetImageActor( n ) );
+ renderer->RemoveActor( this->GetTextActor( ) );
+ renderer->RemoveActor( this->GetPlaneActor( ) );
+ renderer->Modified( );
+}
+
// -------------------------------------------------------------------------
unsigned int cpExtensions::Visualization::ImageSliceActors::
GetNumberOfImageActors( ) const
void cpExtensions::Visualization::ImageSliceActors::
AddActor( vtkAlgorithm* algorithm, vtkActor* actor )
{
- this->OtherActors.push_back( TActorPair( algorithm, actor ) );
+ this->AssociatedActors.push_back( TAssociatedActor( algorithm, actor ) );
this->AddItem( actor );
}
this->PlaneActor->Modified( );
// Prepare other actors to update
- for( unsigned int i = 0; i < this->OtherActors.size( ); ++i )
- {
- if( this->OtherActors[ i ].first.GetPointer( ) != NULL )
- {
- this->OtherActors[ i ].first->Modified( );
- this->OtherActors[ i ].first->Update( );
+ /* TODO
+ for( unsigned int i = 0; i < this->OtherActors.size( ); ++i )
+ {
+ if( this->OtherActors[ i ].first.GetPointer( ) != NULL )
+ {
+ this->OtherActors[ i ].first->Modified( );
+ this->OtherActors[ i ].first->Update( );
- } // fi
+ } // fi
- if( this->OtherActors[ i ].second.GetPointer( ) != NULL )
- {
- this->OtherActors[ i ].second->GetMapper( )->Modified( );
- this->OtherActors[ i ].second->Modified( );
+ if( this->OtherActors[ i ].second.GetPointer( ) != NULL )
+ {
+ this->OtherActors[ i ].second->GetMapper( )->Modified( );
+ this->OtherActors[ i ].second->Modified( );
- } // fi
+ } // fi
- } // rof
+ } // rof
- if( this->m_UpdateCommand != NULL )
- this->m_UpdateCommand( this->m_UpdateData );
+ if( this->m_UpdateCommand != NULL )
+ this->m_UpdateCommand( this->m_UpdateData );
+ */
// Update text
this->UpdateText( );
this->Modified( );
}
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+UpdateText( double pos[ 3 ] )
+{
+ if( this->SliceMappers.size( ) > 0 )
+ {
+ char axis;
+ int axId = this->SliceMappers[ 0 ]->GetOrientation( );
+ if ( axId == 0 ) axis = 'X';
+ else if( axId == 1 ) axis = 'Y';
+ else if( axId == 2 ) axis = 'Z';
+
+ vtkImageData* image = this->SliceMappers[ 0 ]->GetInput( );
+
+ int ijk[ 3 ];
+ double pcoords[ 3 ];
+ image->ComputeStructuredCoordinates( pos, ijk, pcoords );
+ {
+ int nScl = image->GetNumberOfScalarComponents( );
+ std::stringstream str;
+ str
+ << "[" << ijk[ 0 ]
+ << "," << ijk[ 1 ]
+ << "," << ijk[ 2 ] << "]=(";
+ str <<
+ image->GetScalarComponentAsFloat(
+ ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0
+ );
+ for( int n = 1; n < nScl; ++n )
+ str
+ << " "
+ << image->GetScalarComponentAsFloat(
+ ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], n
+ );
+ str << ")";
+ std::sprintf(
+ this->TextBuffer, "Axis: %c (%d) | Pixel %s",
+ axis,
+ this->SliceMappers[ 0 ]->GetSliceNumber( ),
+ str.str( ).c_str( )
+ );
+
+ } // fi
+ }
+ else
+ this->TextBuffer[ 0 ] = '\0';
+ this->TextActor->SetInput( this->TextBuffer );
+ this->TextActor->Modified( );
+ this->Modified( );
+}
+
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
UpdateText( const double& w, const double& l )
cpExtensions::Visualization::ImageSliceActors::
ImageSliceActors( )
: Superclass( ),
- Interpolate( false ),
- m_UpdateCommand( NULL ),
- m_UpdateData( NULL )
+ Interpolate( false )
{
+ // Connect this view with a controller
+ this->Style = vtkSmartPointer< ImageInteractorStyle >::New( );
+ this->Style->AssociateView( this );
+ this->Style->SetMouseMoveCommand( Self::_MouseMoveCommand );
+ this->Style->SetMouseClickCommand( Self::_MouseClickCommand );
+ this->Style->SetMouseDoubleClickCommand( Self::_MouseDoubleClickCommand );
+ this->Style->SetMouseWheelCommand( Self::_MouseWheelCommand );
+ this->Style->SetKeyCommand( Self::_KeyCommand );
+
this->Clear( );
}
{
this->AddItem( this->TextActor );
this->AddItem( this->PlaneActor );
+ this->Style->AssociateImageActor( actor );
} // fi
this->AddItem( actor );
this->Modified( );
}
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_MouseMoveCommand(
+ void* data,
+ const ImageInteractorStyle::ButtonID& btn, double* pos,
+ bool alt, bool ctr, bool sft
+ )
+{
+ ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
+ if( actors == NULL )
+ return;
+
+ if( btn == ImageInteractorStyle::ButtonID_None )
+ {
+ actors->UpdateText( pos );
+ }
+ else if( btn == ImageInteractorStyle::ButtonID_Left )
+ {
+ }
+ else if( btn == ImageInteractorStyle::ButtonID_Middle )
+ {
+ }
+ else if( btn == ImageInteractorStyle::ButtonID_Right )
+ {
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_MouseClickCommand(
+ void* data,
+ const ImageInteractorStyle::ButtonID& btn, double* pos,
+ bool alt, bool ctr, bool sft
+ )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_MouseDoubleClickCommand(
+ void* data,
+ const ImageInteractorStyle::ButtonID& btn, double* pos,
+ bool alt, bool ctr, bool sft
+ )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_MouseWheelCommand(
+ void* data,
+ const int& dir, bool alt, bool ctr, bool sft
+ )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_KeyCommand(
+ void* data,
+ const char& key
+ )
+{
+}
+
// eof - $RCSfile$