]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/Widgets/SeedWidget.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / Widgets / SeedWidget.cxx
index 58cbed574e677b8953c389c94d0e4a83ce1ef19e..fbd30d2cfce27a860169f054eef3a052acc16972 100644 (file)
@@ -4,6 +4,7 @@
 #include <cpPlugins/Interface/PointList.h>
 #include <cpPlugins/Interface/SimpleMPRWidget.h>
 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
+#include <cpExtensions/DataStructures/VectorValuesContainer.h>
 
 #include <vtkRenderWindowInteractor.h>
 
@@ -41,8 +42,7 @@ _GenerateData( )
   typedef itk::ImageBase< 2 > _2DImage;
   typedef itk::ImageBase< 3 > _3DImage;
 
-  auto image =
-    this->GetInputData< cpPlugins::Interface::Image >( "ReferenceImage" );
+  auto image = this->GetInputData( "ReferenceImage" );
   itk::DataObject* itk_image = image->GetITK< _2DImage >( );
   if( itk_image != NULL )
     return( this->_GD0< _2DImage >( itk_image ) );
@@ -60,19 +60,28 @@ _GenerateData( )
 template< class I >
 std::string cpPlugins::Widgets::SeedWidget::
 _GD0( itk::DataObject* image )
+{
+  if( this->m_Parameters->GetBool( "SeedsAreInRealSpace" ) )
+    return( this->_GD1_Points< I >( dynamic_cast< I* >( image ) ) );
+  else
+    return( this->_GD1_Vertices< I >( dynamic_cast< I* >( image ) ) );
+}
+
+// -------------------------------------------------------------------------
+template< class I >
+std::string cpPlugins::Widgets::SeedWidget::
+_GD1_Points( I* image )
 {
   typedef cpExtensions::Interaction::ImageInteractorStyle _S;
+  typedef itk::Point< double, I::ImageDimension > _P;
+  typedef cpExtensions::DataStructures::VectorValuesContainer< _P > _Container;
+
+  auto container = this->_CreateITK< _Container >( );
 
-  I* base_image = dynamic_cast< I* >( image );
-  auto out =
-    this->GetOutputData< cpPlugins::Interface::PointList >( "Output" );
   double aux_pnt[ 3 ];
   unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
-  bool real_space = this->m_Parameters->GetBool( "SeedsAreInRealSpace" );
 
-  // Prepare output
-  out->Clear( );
-  out->SetHaveEuclideanPoints( real_space );
+  container->Get( ).clear( );
 
   // MPR
   if( this->m_MPRViewer != NULL )
@@ -90,18 +99,10 @@ _GD0( itk::DataObject* image )
           for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
           {
             s->GetSeedAsPoint( i, aux_pnt );
-            typename I::PointType seed;
+            _P seed;
             for( unsigned int d = 0; d < dim; ++d )
               seed[ d ] = aux_pnt[ d ];
-
-            if( !real_space )
-            {
-              typename I::IndexType index;
-              if( base_image->TransformPhysicalPointToIndex( seed, index ) )
-                out->AddPoint( index );
-            }
-            else
-              out->AddPoint( seed );
+            container->PushBack( seed );
 
           } // rof
         }
@@ -123,17 +124,88 @@ _GD0( itk::DataObject* image )
       for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
       {
         s->GetSeedAsPoint( i, aux_pnt );
-        typename I::PointType seed;
+        _P seed;
         for( unsigned int d = 0; d < dim; ++d )
           seed[ d ] = aux_pnt[ d ];
-        if( !real_space )
+        container->PushBack( seed );
+
+      } // rof
+    }
+    else
+      s->SeedWidgetOn( );
+
+  } // fi
+  this->m_Configured = true;
+
+  auto out = this->GetOutputData( "Output" );
+  out->SetITK( container );
+  return( "" );
+}
+
+// -------------------------------------------------------------------------
+template< class I >
+std::string cpPlugins::Widgets::SeedWidget::
+_GD1_Vertices( I* image )
+{
+  typedef cpExtensions::Interaction::ImageInteractorStyle _S;
+  typedef cpExtensions::DataStructures::VectorValuesContainer< typename I::IndexType > _Container;
+
+  auto container = this->_CreateITK< _Container >( );
+
+  double aux_pnt[ 3 ];
+  unsigned int dim = ( I::ImageDimension < 3 )? I::ImageDimension: 3;
+
+  container->Get( ).clear( );
+
+  // MPR
+  if( this->m_MPRViewer != NULL )
+  {
+    for( unsigned int i = 0; i < 4; ++i )
+    {
+      _S* s =
+        dynamic_cast< _S* >(
+          this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
+          );
+      if( s != NULL )
+      {
+        if( this->m_Configured )
         {
-          typename I::IndexType index;
-          if( base_image->TransformPhysicalPointToIndex( seed, index ) )
-            out->AddPoint( index );
+          for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
+          {
+            s->GetSeedAsPoint( i, aux_pnt );
+            typename I::PointType seed;
+            for( unsigned int d = 0; d < dim; ++d )
+              seed[ d ] = aux_pnt[ d ];
+            typename I::IndexType idx;
+            if( image->TransformPhysicalPointToIndex( seed, idx ) )
+              container->PushBack( idx );
+
+          } // rof
         }
         else
-          out->AddPoint( seed );
+          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 I::PointType seed;
+        for( unsigned int d = 0; d < dim; ++d )
+          seed[ d ] = aux_pnt[ d ];
+        typename I::IndexType idx;
+        if( image->TransformPhysicalPointToIndex( seed, idx ) )
+          container->PushBack( idx );
 
       } // rof
     }
@@ -142,6 +214,9 @@ _GD0( itk::DataObject* image )
 
   } // fi
   this->m_Configured = true;
+
+  auto out = this->GetOutputData( "Output" );
+  out->SetITK( container );
   return( "" );
 }