#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->AssociatedActors.clear( );
// Reconfigure unique objects
- this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( );
- this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
- this->TextActor = vtkSmartPointer< vtkTextActor >::New( );
- this->PlaneActor = vtkSmartPointer< vtkActor >::New( );
+ this->PlaneFunction = vtkSmartPointer< vtkPlane >::New( );
+ this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( );
+ this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+ this->TextActor = vtkSmartPointer< vtkTextActor >::New( );
+ this->PlaneActor = vtkSmartPointer< vtkActor >::New( );
this->TextBuffer[ 0 ] = '\0';
// Unique objects configuration
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
return( this->PlaneActor );
}
+// -------------------------------------------------------------------------
+vtkPlane* cpExtensions::Visualization::ImageSliceActors::
+GetPlaneFunction( )
+{
+ return( this->PlaneFunction );
+}
+
+// -------------------------------------------------------------------------
+const vtkPlane* cpExtensions::Visualization::ImageSliceActors::
+GetPlaneFunction( ) const
+{
+ return( this->PlaneFunction );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+AddActor( vtkAlgorithm* algorithm, vtkActor* actor )
+{
+ this->AssociatedActors.push_back( TAssociatedActor( algorithm, actor ) );
+ this->AddItem( actor );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+AddActor( vtkActor* actor )
+{
+ this->AddActor( NULL, actor );
+}
+
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
SetInterpolate( bool v )
} // fi
+ // Plane function origin
+ this->PlaneFunction->SetOrigin( pos );
+
+ // Configure visualization and implicit plane orientation
int axis = this->SliceMappers[ 0 ]->GetOrientation( );
this->PlaneActor->GetProperty( )->SetRepresentationToWireframe( );
this->PlaneActor->GetProperty( )->SetLineWidth( 2 );
vtkPoints* plane_points = this->PlaneSource->GetPoints( );
if( axis == 0 ) // YZ, x-normal
{
+ this->PlaneFunction->SetNormal( 1, 0, 0 );
plane_points->SetPoint( 0, pos[ 0 ], ybnds[ 0 ], zbnds[ 0 ] );
plane_points->SetPoint( 1, pos[ 0 ], ybnds[ 1 ], zbnds[ 0 ] );
plane_points->SetPoint( 2, pos[ 0 ], ybnds[ 1 ], zbnds[ 1 ] );
}
else if( axis == 1 ) // ZX, y-normal
{
+ this->PlaneFunction->SetNormal( 0, 1, 0 );
plane_points->SetPoint( 0, xbnds[ 0 ], pos[ 1 ], zbnds[ 0 ] );
plane_points->SetPoint( 1, xbnds[ 0 ], pos[ 1 ], zbnds[ 1 ] );
plane_points->SetPoint( 2, xbnds[ 1 ], pos[ 1 ], zbnds[ 1 ] );
}
else // XY, z-normal
{
+ this->PlaneFunction->SetNormal( 0, 0, 1 );
plane_points->SetPoint( 0, xbnds[ 0 ], ybnds[ 0 ], pos[ 2 ] );
plane_points->SetPoint( 1, xbnds[ 1 ], ybnds[ 0 ], pos[ 2 ] );
plane_points->SetPoint( 2, xbnds[ 1 ], ybnds[ 1 ], pos[ 2 ] );
this->PlaneActor->GetProperty( )->SetColor( 0, 0, 1 );
} // fi
+ this->PlaneFunction->Modified( );
this->PlaneSource->Modified( );
this->PlaneMapper->Modified( );
this->PlaneActor->Modified( );
+
+ // Prepare other actors to 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
+
+ if( this->OtherActors[ i ].second.GetPointer( ) != NULL )
+ {
+ this->OtherActors[ i ].second->GetMapper( )->Modified( );
+ this->OtherActors[ i ].second->Modified( );
+
+ } // fi
+
+ } // rof
+
+ 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 )
: Superclass( ),
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$