]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageSliceActors.cxx
Widget integration (step 5/6): Just one step leftgit shortlog !
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.cxx
index fc2e1a43e0815d9a6fbf3bb85ce1ede43cd871ff..558fed75946f826b64e4d84f472022cf68a5ac0e 100644 (file)
@@ -101,6 +101,7 @@ Clear( )
   this->ImageMaps.clear( );
   this->SliceMappers.clear( );
   this->ImageActors.clear( );
+  this->AssociatedSlices.clear( );
   this->AssociatedActors.clear( );
 
   // Reconfigure unique objects
@@ -180,6 +181,23 @@ Clear( )
   coord->SetValue( 0.01, 0.01 );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+AssociateSlice( Self* other )
+{
+  this->AssociatedSlices.push_back( other );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+SetSlicesCommand( TCursorCommand cmd, void* data )
+{
+  this->SlicesCommand = cmd;
+  this->SlicesData = data;
+  this->Modified( );
+}
+
 // -------------------------------------------------------------------------
 vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
 GetStyle( )
@@ -783,8 +801,38 @@ SetSliceNumber( const int& slice )
 
   // Update text
   this->UpdateText( );
+
+  // Associated slices
+  for( unsigned int i = 0; i < this->AssociatedSlices.size( ); ++i )
+    if( this->AssociatedSlices[ i ]->GetAxis( ) == this->GetAxis( ) )
+      this->AssociatedSlices[ i ]->SetSliceNumber( slice );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+SetSlice( double* pos )
+{
+  vtkImageData* image;
+  if( this->ImageMaps[ 0 ] != NULL )
+    image =
+      dynamic_cast< vtkImageData* >( this->ImageMaps[ 0 ]->GetInput( ) );
+  else
+    image = this->SliceMappers[ 0 ]->GetInput( );
+
+  int ijk[ 3 ];
+  double pcoords[ 3 ];
+  image->ComputeStructuredCoordinates( pos, ijk, pcoords );
+  this->SetSliceNumber( ijk[ this->GetAxis( ) ] );
+}
+
+// -------------------------------------------------------------------------
+/* TODO
+   void cpExtensions::Visualization::ImageSliceActors::
+   SetSlices( double pos[ 3 ] )
+   {
+   }
+*/
+
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 UpdateText( )
@@ -903,6 +951,8 @@ ImageSliceActors( )
 {
   this->Clear( );
 
+  this->SlicesCommand = NULL;
+
   // Connect this view with a controller
   this->Style = vtkSmartPointer< ImageInteractorStyle >::New( );
   this->Style->AssociateView( this );
@@ -1048,6 +1098,8 @@ _MouseMoveCommand(
   }
   else if( btn == ImageInteractorStyle::ButtonID_Left )
   {
+    if( !alt && ctr && !sft && actors->SlicesCommand != NULL )
+      actors->SlicesCommand( pos, actors->GetAxis( ), actors->SlicesData );
   }
   else if( btn == ImageInteractorStyle::ButtonID_Middle )
   {
@@ -1114,10 +1166,9 @@ _MouseDoubleClickCommand(
   if( btn == ImageInteractorStyle::ButtonID_Left )
   {
     if( !alt && !ctr && !sft )
-    {
       actors->SetCursor( pos );
-
-    } // fi
+    else if( !alt && ctr && !sft && actors->SlicesCommand != NULL )
+      actors->SlicesCommand( pos, actors->GetAxis( ), actors->SlicesData );
   }
   else if( btn == ImageInteractorStyle::ButtonID_Middle )
   {