]> Creatis software - cpPlugins.git/blobdiff - plugins/cpPluginsWidgets/SeedWidget.cxx
...
[cpPlugins.git] / plugins / cpPluginsWidgets / SeedWidget.cxx
index 03e721572851e1d1dbbd80bff1153df355af75c8..b65d29f06de5e4f97f3d965d66721a2e0d23077f 100644 (file)
@@ -1,6 +1,7 @@
 #include "SeedWidget.h"
 
 #include <cpPlugins/Image.h>
+#include <cpExtensions/DataStructures/ImageIndexesContainer.h>
 #include <cpExtensions/QT/SimpleMPRWidget.h>
 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
 #include <vtkRenderWindowInteractor.h>
@@ -23,9 +24,6 @@ SeedWidget( )
 {
   this->_AddInput( "ReferenceImage" );
   this->_AddOutput< cpPlugins::DataObject >( "Output" );
-
-  this->m_Parameters.ConfigureAsBool( "SeedsAreInRealSpace" );
-  this->m_Parameters.SetBool( "SeedsAreInRealSpace", false );
 }
 
 // -------------------------------------------------------------------------
@@ -49,167 +47,81 @@ template< class _TImage >
 std::string cpPluginsWidgets::SeedWidget::
 _GD0( _TImage* image )
 {
-  if( image != NULL )
-  {
-    if( this->m_Parameters.GetBool( "SeedsAreInRealSpace" ) )
-      return( this->_GD1_Points( image ) );
-    else
-      return( this->_GD1_Vertices( image ) );
-  }
-  else
-    return( "Widgets::SeedWidget: Input image dimension not supported." );
-}
-
-// -------------------------------------------------------------------------
-template< class _TImage >
-std::string cpPluginsWidgets::SeedWidget::
-_GD1_Points( _TImage* image )
-{
+  typedef
+    cpExtensions::DataStructures::ImageIndexesContainer< _TImage::ImageDimension >
+    _TContainer;
   typedef cpExtensions::Interaction::ImageInteractorStyle _S;
-  typedef itk::Point< double, _TImage::ImageDimension > _P;
-  typedef itk::SimpleDataObjectDecorator< std::vector< _P > > _Container;
-
-  auto container = this->_CreateITK< _Container >( );
 
-  double aux_pnt[ 3 ];
-  unsigned int dim = ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
-
-  container->Get( ).clear( );
-
-  // MPR
-  if( this->m_MPRViewer != NULL )
+  if( image != NULL )
   {
-    for( unsigned int i = 0; i < 4; ++i )
+    auto container = this->_CreateITK< _TContainer >( );
+    double aux_pnt[ 3 ];
+    unsigned int dim = ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
+    container->Get( ).clear( );
+
+    // MPR
+    if( this->m_MPRViewer != NULL )
     {
-      _S* s =
-        dynamic_cast< _S* >(
-          this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
-          );
-      if( s != NULL )
+      for( unsigned int i = 0; i < 4; ++i )
       {
-        if( this->m_Configured )
+        _S* s =
+          dynamic_cast< _S* >(
+            this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
+            );
+        if( s != NULL )
         {
-          for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
+          if( this->m_Configured )
           {
-            s->GetSeedAsPoint( i, aux_pnt );
-            _P seed;
-            for( unsigned int d = 0; d < dim; ++d )
-              seed[ d ] = aux_pnt[ d ];
-            container->Get( ).push_back( seed );
-
-          } // rof
-        }
-        else
-          s->SeedWidgetOn( );
-
-      } // fi
-
-    } // rof
-
-  } // fi
-
-  // Single interactor
-  _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
-  if( s != NULL )
-  {
-    if( this->m_Configured )
-    {
-      for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
-      {
-        s->GetSeedAsPoint( i, aux_pnt );
-        _P seed;
-        for( unsigned int d = 0; d < dim; ++d )
-          seed[ d ] = aux_pnt[ d ];
-        container->Get( ).push_back( seed );
+            for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
+            {
+              s->GetSeedAsPoint( i, aux_pnt );
+              typename _TImage::PointType seed;
+              for( unsigned int d = 0; d < dim; ++d )
+                seed[ d ] = aux_pnt[ d ];
+              typename _TImage::IndexType idx;
+              if( image->TransformPhysicalPointToIndex( seed, idx ) )
+                container->Get( ).push_back( idx );
+
+            } // rof
+          }
+          else
+            s->SeedWidgetOn( );
+
+        } // fi
 
       } // rof
-    }
-    else
-      s->SeedWidgetOn( );
-
-  } // fi
-  this->m_Configured = true;
 
-  this->GetOutputData( "Output" )->SetITK( container );
-  return( "" );
-}
-
-// -------------------------------------------------------------------------
-template< class _TImage >
-std::string cpPluginsWidgets::SeedWidget::
-_GD1_Vertices( _TImage* image )
-{
-  typedef cpExtensions::Interaction::ImageInteractorStyle _S;
-  typedef
-    itk::SimpleDataObjectDecorator< std::vector< typename _TImage::IndexType > >
-    _Container;
-  auto container = this->_CreateITK< _Container >( );
-
-  double aux_pnt[ 3 ];
-  unsigned int dim = ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
+    } // fi
 
-  container->Get( ).clear( );
-
-  // MPR
-  if( this->m_MPRViewer != NULL )
-  {
-    for( unsigned int i = 0; i < 4; ++i )
+    // Single interactor
+    _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
+    if( s != NULL )
     {
-      _S* s =
-        dynamic_cast< _S* >(
-          this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
-          );
-      if( s != NULL )
+      if( this->m_Configured )
       {
-        if( this->m_Configured )
+        for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
         {
-          for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
-          {
-            s->GetSeedAsPoint( i, aux_pnt );
-            typename _TImage::PointType seed;
-            for( unsigned int d = 0; d < dim; ++d )
-              seed[ d ] = aux_pnt[ d ];
-            typename _TImage::IndexType idx;
-            if( image->TransformPhysicalPointToIndex( seed, idx ) )
-              container->Get( ).push_back( idx );
-
-          } // rof
-        }
-        else
-          s->SeedWidgetOn( );
-
-      } // fi
-
-    } // rof
-
-  } // fi
-
-  // Single interactor
-  _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
-  if( s != NULL )
-  {
-    if( this->m_Configured )
-    {
-      for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
-      {
-        s->GetSeedAsPoint( i, aux_pnt );
-        typename _TImage::PointType seed;
-        for( unsigned int d = 0; d < dim; ++d )
-          seed[ d ] = aux_pnt[ d ];
-        typename _TImage::IndexType idx;
-        if( image->TransformPhysicalPointToIndex( seed, idx ) )
-          container->Get( ).push_back( idx );
-
-      } // rof
-    }
-    else
-      s->SeedWidgetOn( );
-
-  } // fi
-  this->m_Configured = true;
-
-  this->GetOutputData( "Output" )->SetITK( container );
-  return( "" );
+          s->GetSeedAsPoint( i, aux_pnt );
+          typename _TImage::PointType seed;
+          for( unsigned int d = 0; d < dim; ++d )
+            seed[ d ] = aux_pnt[ d ];
+          typename _TImage::IndexType idx;
+          if( image->TransformPhysicalPointToIndex( seed, idx ) )
+            container->Get( ).push_back( idx );
+
+        } // rof
+      }
+      else
+        s->SeedWidgetOn( );
+
+    } // fi
+    this->m_Configured = true;
+    container->SetReferenceImage( image );
+    this->GetOutputData( "Output" )->SetITK( container );
+    return( "" );
+  }
+  else
+    return( "Widgets::SeedWidget: Input image dimension not supported." );
 }
 
 // eof - $RCSfile$