// Invoke possible events
this->MouseWheelCommand( this->Data, 1, alt, ctr, sft );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
// Invoke possible events
this->MouseWheelCommand( this->Data, -1, alt, ctr, sft );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
// Invoke possible events
this->MouseClickCommand( this->Data, Self::ButtonID_Left, pos, alt, ctr, sft );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
// Invoke possible events
this->MouseDoubleClickCommand( this->Data, Self::ButtonID_Left, pos, alt, ctr, sft );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
// Invoke possible events
this->MouseClickCommand( this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
// Invoke possible events
this->MouseDoubleClickCommand( this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
// Invoke possible events
this->MouseClickCommand( this->Data, Self::ButtonID_Right, pos, alt, ctr, sft );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
// Invoke possible events
this->MouseDoubleClickCommand( this->Data, Self::ButtonID_Right, pos, alt, ctr, sft );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
if( rwi == NULL || this->KeyCommand == NULL )
return;
this->KeyCommand( this->Data, rwi->GetKeyCode( ) );
+ rwi->Render( );
}
// -------------------------------------------------------------------------
vtkRenderWindowInteractor* rwi = this->GetInteractor( );
if( rwi == NULL )
return;
+ rwi->Render( );
}
// -------------------------------------------------------------------------
vtkRenderWindowInteractor* rwi = this->GetInteractor( );
if( rwi == NULL )
return;
+ rwi->Render( );
}
// -------------------------------------------------------------------------
vtkRenderWindowInteractor* rwi = this->GetInteractor( );
if( rwi == NULL )
return;
+ rwi->Render( );
}
// -------------------------------------------------------------------------
vtkRenderWindowInteractor* rwi = this->GetInteractor( );
if( rwi == NULL )
return;
+ rwi->Render( );
}
// -------------------------------------------------------------------------
#include <sstream>
#include <vtkAlgorithmOutput.h>
+#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkImageData.h>
#include <vtkInformation.h>
#include <vtkPoints.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
+#include <vtkRendererCollection.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkTextProperty.h>
this->AssociatedActors.clear( );
// Reconfigure unique objects
+ this->Cursor = vtkSmartPointer< vtkPolyData >::New( );
+ this->CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+ this->CursorActor = vtkSmartPointer< vtkActor >::New( );
this->PlaneFunction = vtkSmartPointer< vtkPlane >::New( );
this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( );
this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
this->TextBuffer[ 0 ] = '\0';
// Unique objects configuration
+ vtkSmartPointer< vtkPoints > cursor_points =
+ vtkSmartPointer< vtkPoints >::New( );
+ vtkSmartPointer< vtkCellArray > cursor_lines =
+ vtkSmartPointer< vtkCellArray >::New( );
+ cursor_points->InsertNextPoint( 0, 0, 0 );
+ cursor_points->InsertNextPoint( 0, 0, 0 );
+ cursor_points->InsertNextPoint( 0, 0, 0 );
+ cursor_points->InsertNextPoint( 0, 0, 0 );
+ cursor_lines->InsertNextCell( 2 );
+ cursor_lines->InsertCellPoint( 0 );
+ cursor_lines->InsertCellPoint( 1 );
+ cursor_lines->InsertNextCell( 2 );
+ cursor_lines->InsertCellPoint( 2 );
+ cursor_lines->InsertCellPoint( 3 );
+ this->Cursor->SetPoints( cursor_points );
+ this->Cursor->SetLines( cursor_lines );
+ this->CursorMapper->SetInputData( this->Cursor );
+ this->CursorActor->SetMapper( this->CursorMapper );
+
vtkSmartPointer< vtkPoints > plane_points =
vtkSmartPointer< vtkPoints >::New( );
vtkSmartPointer< vtkCellArray > plane_lines =
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-PushActorsInto( vtkRenderer* renderer )
+PushActorsInto( vtkRenderWindow* window )
{
- 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( );
+ vtkRenderWindowInteractor* rwi = window->GetInteractor( );
+ vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( );
+
+ // Update style
+ if( rwi != NULL )
+ {
+ if( rwi->GetInteractorStyle( ) != this->Style.GetPointer( ) )
+ rwi->SetInteractorStyle( this->Style );
+
+ } // fi
+
+ if( renderer != NULL )
+ {
+ // Configure camera
+ vtkCamera* camera = renderer->GetActiveCamera( );
+ if( camera == NULL )
+ return;
+
+ // Parallel projections are better when displaying 2D images
+ int axis = this->GetAxis( );
+ camera->ParallelProjectionOn( );
+ camera->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
+ if( axis == 0 )
+ {
+ camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
+ camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
+ }
+ else if( axis == 1 )
+ {
+ camera->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
+ camera->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) );
+ }
+ else // if( axis == 2 )
+ {
+ camera->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
+ camera->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
+
+ } // fi
+ renderer->ResetCamera( );
+
+ // Update actors
+ unsigned int N = this->GetNumberOfImageActors( );
+ for( unsigned int n = 0; n < N; ++n )
+ renderer->AddActor( this->GetImageActor( n ) );
+ renderer->AddActor( this->CursorActor );
+ renderer->AddActor( this->PlaneActor );
+ renderer->AddActor( this->TextActor );
+ renderer->Modified( );
+
+ } // fi
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-PopActorsFrom( vtkRenderer* renderer )
+PopActorsFrom( vtkRenderWindow* window )
{
+ /*
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( );
+ */
}
// -------------------------------------------------------------------------
this->ImageActors[ 0 ]->GetDisplayBounds( bounds );
}
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+ResetCursor( )
+{
+ vtkPoints* points = this->Cursor->GetPoints( );
+ points->SetPoint( 0, 0, 0, 0 );
+ points->SetPoint( 1, 0, 0, 0 );
+ points->SetPoint( 2, 0, 0, 0 );
+ points->SetPoint( 3, 0, 0, 0 );
+ this->Cursor->Modified( );
+ this->CursorMapper->Modified( );
+ this->CursorActor->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+SetCursor( double pos[ 3 ] )
+{
+ if( this->SliceMappers.size( ) == 0 )
+ return;
+
+ int a0 = this->GetAxis( );
+ int a1 = ( a0 + 1 ) % 3;
+ int a2 = ( a0 + 2 ) % 3;
+
+ double bounds[ 6 ];
+ this->SliceMappers[ 0 ]->GetBounds( bounds );
+
+ double p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ];
+ p0[ a0 ] = p1[ a0 ] = p2[ a0 ] = p3[ a0 ] = pos[ a0 ];
+ p0[ a2 ] = p1[ a2 ] = pos[ a2 ];
+ p2[ a1 ] = p3[ a1 ] = pos[ a1 ];
+ p0[ a1 ] = bounds[ a1 << 1 ];
+ p1[ a1 ] = bounds[ ( a1 << 1 ) + 1 ];
+ p2[ a2 ] = bounds[ a2 << 1 ];
+ p3[ a2 ] = bounds[ ( a2 << 1 ) + 1 ];
+
+ vtkPoints* points = this->Cursor->GetPoints( );
+ points->SetPoint( 0, p0 );
+ points->SetPoint( 1, p1 );
+ points->SetPoint( 2, p2 );
+ points->SetPoint( 3, p3 );
+ this->Cursor->Modified( );
+ this->CursorMapper->Modified( );
+ this->CursorActor->Modified( );
+}
+
// -------------------------------------------------------------------------
int cpExtensions::Visualization::ImageSliceActors::
GetAxis( ) const
if ( axId == 0 ) axis = 'X';
else if( axId == 1 ) axis = 'Y';
else if( axId == 2 ) axis = 'Z';
+ int slice = this->GetSliceNumber( );
vtkImageData* image = this->SliceMappers[ 0 ]->GetInput( );
int ijk[ 3 ];
double pcoords[ 3 ];
image->ComputeStructuredCoordinates( pos, ijk, pcoords );
+ ijk[ axId ] = slice;
+
+ int ext[ 6 ];
+ image->GetExtent( ext );
+ if(
+ ext[ 0 ] <= ijk[ 0 ] && ijk[ 0 ] <= ext[ 1 ] &&
+ ext[ 2 ] <= ijk[ 1 ] && ijk[ 1 ] <= ext[ 3 ] &&
+ ext[ 4 ] <= ijk[ 2 ] && ijk[ 2 ] <= ext[ 5 ]
+ )
{
int nScl = image->GetNumberOfScalarComponents( );
std::stringstream str;
<< "," << ijk[ 1 ]
<< "," << ijk[ 2 ] << "]=(";
str <<
- image->GetScalarComponentAsFloat(
- ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0
- );
+ image->GetScalarComponentAsFloat( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 );
for( int n = 1; n < nScl; ++n )
str
<< " "
str << ")";
std::sprintf(
this->TextBuffer, "Axis: %c (%d) | Pixel %s",
- axis,
- this->SliceMappers[ 0 ]->GetSliceNumber( ),
- str.str( ).c_str( )
+ axis, slice, str.str( ).c_str( )
);
} // fi
if( nImages == 0 )
{
- this->AddItem( this->TextActor );
+ this->AddItem( this->CursorActor );
this->AddItem( this->PlaneActor );
+ this->AddItem( this->TextActor );
this->Style->AssociateImageActor( actor );
} // fi
bool alt, bool ctr, bool sft
)
{
+ ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
+ if( actors == NULL )
+ return;
+
+ if( btn == ImageInteractorStyle::ButtonID_Left )
+ {
+ if( !alt && !ctr && !sft )
+ {
+ actors->SetCursor( pos );
+
+ } // fi
+ }
+ else if( btn == ImageInteractorStyle::ButtonID_Middle )
+ {
+ }
+ else if( btn == ImageInteractorStyle::ButtonID_Right )
+ {
+ } // fi
}
// -------------------------------------------------------------------------
const int& dir, bool alt, bool ctr, bool sft
)
{
+ ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
+ if( actors == NULL )
+ return;
+
+ if( !alt && !ctr && !sft )
+ {
+ actors->SetSliceNumber( actors->GetSliceNumber( ) + dir );
+ }
+ else if( !alt && !ctr && sft )
+ {
+ actors->SetSliceNumber( actors->GetSliceNumber( ) + ( dir * 10 ) );
+
+ } // fi
}
// -------------------------------------------------------------------------