#include <cpExtensions/Interaction/ImageSliceStyle.h>
+#include <cpExtensions/Visualization/CursorActors.h>
#include <cpExtensions/Visualization/WindowLevelImageActor.h>
-#include <cpExtensions/Visualization/ImageViewerActors.h>
+#include <vtkAssemblyPath.h>
+#include <vtkImageData.h>
+#include <vtkImageSlice.h>
+#include <vtkProperty.h>
+#include <vtkPropCollection.h>
#include <vtkPropPicker.h>
+#include <vtkRenderer.h>
+/* TODO
+ #include <cpExtensions/Visualization/ImageViewerActors.h>
+*/
// -------------------------------------------------------------------------
cpExtensions::Interaction::ImageSliceStyle::
}
// -------------------------------------------------------------------------
+void cpExtensions::Interaction::ImageSliceStyle::
+OnMouseMove( )
+{
+ static bool cursor_visible = false;
+
+ int idx[ 2 ];
+ double pnt[ 3 ];
+ if( this->_PickPointOnImageActor( idx, pnt ) )
+ {
+ this->m_Cursor->SetCursor( pnt, false );
+ if( !cursor_visible )
+ {
+ this->m_Cursor->VisibilityOn( );
+ cursor_visible = true;
+
+ } // fi
+ this->Interactor->Render( );
+ }
+ else
+ {
+ if( cursor_visible )
+ {
+ this->m_Cursor->VisibilityOff( );
+ cursor_visible = false;
+ this->Interactor->Render( );
+
+ } // fi
+
+ } // fi
+
+ this->Superclass::OnMouseMove( );
+}
+
+/* TODO
cpExtensions::Visualization::ImageViewerActors*
cpExtensions::Interaction::ImageSliceStyle::
GetActors( )
OnChar( )
{
}
+*/
// -------------------------------------------------------------------------
cpExtensions::Interaction::ImageSliceStyle::
ImageSliceStyle( )
: Superclass( )
{
+ this->SetInteractionModeToImage2D( );
+ this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
+ this->m_PropPicker->PickFromListOn( );
+
+ this->m_Cursor = vtkSmartPointer< TCursor >::New( );
+ this->m_Cursor->VisibilityOff( );
+ this->m_Cursor->GetProperty( 0 )->SetColor( 1, 1, 0 );
+ this->m_Cursor->GetProperty( 1 )->SetColor( 1, 1, 0 );
}
// -------------------------------------------------------------------------
{
}
+// -------------------------------------------------------------------------
+vtkProp* cpExtensions::Interaction::ImageSliceStyle::
+_ImageActor( int i )
+{
+ if( !this->CurrentRenderer )
+ return( NULL );
+
+ vtkPropCollection* props = this->CurrentRenderer->GetViewProps( );
+ vtkProp* prop = 0;
+ vtkAssemblyPath* path;
+ vtkImageSlice* imageProp = NULL;
+ vtkCollectionSimpleIterator pit;
+
+ for( int k = 0; k < 2; k++ )
+ {
+ int j = 0;
+ for( props->InitTraversal( pit ); ( prop = props->GetNextProp( pit ) ); )
+ {
+ bool foundImageProp = false;
+ for( prop->InitPathTraversal( ); ( path = prop->GetNextPath( ) ); )
+ {
+ vtkProp* tryProp = path->GetLastNode( )->GetViewProp( );
+ if( ( imageProp = vtkImageSlice::SafeDownCast( tryProp ) ) != 0 )
+ {
+ if( j == i )
+ {
+ foundImageProp = true;
+ break;
+
+ } // fi
+ imageProp = 0;
+ j++;
+
+ } // fi
+
+ } // rof
+ if( foundImageProp )
+ break;
+ } // rof
+ if( i < 0 )
+ i += j;
+
+ } // rof
+ return( imageProp );
+}
+
// -------------------------------------------------------------------------
bool cpExtensions::Interaction::ImageSliceStyle::
-_PickPosition( int idx[ 2 ], double pos[ 3 ] )
+_PickPointOnImageActor( int idx[ 2 ], double pnt[ 3 ] )
{
+ // Check if data is valid
if(
this->Interactor == NULL ||
this->CurrentRenderer == NULL ||
idx[ 1 ] = this->Interactor->GetEventPosition( )[ 1 ];
this->FindPokedRenderer( double( idx[ 0 ] ), double( idx[ 1 ] ) );
+ // Check if the image has changed
+ this->Interactor->GetPicker( )->
+ Pick( idx[ 0 ], idx[ 1 ], 0.0, this->CurrentRenderer );
+ auto picker =
+ vtkAbstractPropPicker::SafeDownCast( this->Interactor->GetPicker( ) );
+ if( picker == NULL )
+ return( false );
+ TWLActor* curr_actor = dynamic_cast< TWLActor* >( picker->GetProp3D( ) );
+ if( curr_actor != this->m_WLActor.GetPointer( ) && curr_actor != NULL )
+ {
+ this->m_WLActor = curr_actor;
+ this->m_PropPicker->GetPickList( )->RemoveAllItems( );
+ this->m_PropPicker->AddPickList( curr_actor );
+
+ this->m_Cursor->SetImageBounds( curr_actor->GetImage( )->GetBounds( ) );
+ this->m_Cursor->SetImageOrientation( curr_actor->GetOrientation( ) );
+ this->m_Cursor->InitTraversal( );
+ while( vtkProp* prop = this->m_Cursor->GetNextProp( ) )
+ this->CurrentRenderer->AddViewProp( prop );
+
+ } // fi
+ if( this->m_WLActor.GetPointer( ) == NULL )
+ {
+ this->m_PropPicker->GetPickList( )->RemoveAllItems( );
+ return( false );
+
+ } // fi
+
// Pick a 3D position
int r = this->m_PropPicker->Pick(
double( idx[ 0 ] ), double( idx[ 1 ] ), double( 0 ),
);
if( r == 0 )
return( false );
- this->m_PropPicker->GetPickPosition( pos );
+ this->m_PropPicker->GetPickPosition( pnt );
return( true );
}