]> Creatis software - FrontAlgorithms.git/commitdiff
Some more debug... almost there
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 16 Feb 2015 23:41:44 +0000 (18:41 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 16 Feb 2015 23:41:44 +0000 (18:41 -0500)
appli/examples/example_ImageAlgorithmRegionGrow_MultipleThresholds.cxx
lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx
lib/fpa/Image/Functors/RegionGrowThresholdFunction.h
lib/fpa/Image/RegionGrowWithMultipleThresholds.h
lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx
lib/fpa/VTK/ImageMPR.cxx
lib/fpa/VTK/ImageMPR.h
lib/fpa/VTK/SeedWidgetCorrector.cxx [new file with mode: 0644]
lib/fpa/VTK/SeedWidgetCorrector.h [new file with mode: 0644]

index 1f4bf3fa51f4204d927d155f148c37d93539c903..ff821034776c889ffcd7cf53accbb754a63c90cb 100644 (file)
@@ -74,43 +74,42 @@ int main( int argc, char* argv[] )
   vtk_image->SetInput( input_image );
   vtk_image->Update( );
 
-  /* TODO
-     vtkSmartPointer< vtkSphereSource > seed =
-     vtkSmartPointer< vtkSphereSource >::New( );
-     seed->SetCenter( seed_pnt[ 0 ], seed_pnt[ 1 ], seed_pnt[ 2 ] );
-     seed->SetRadius( min_spac * double( 5 ) );
-     seed->Update( );
-  */
-
   fpa::VTK::ImageMPR view;
   view.SetBackground( 0.3, 0.2, 0.8 );
   view.SetSize( 800, 800 );
   view.SetImage( vtk_image->GetOutput( ) );
-  // TODO: view.AddPolyData( seed->GetOutput( ), 1, 0, 0 );
-  view.Start( );
+
+  // Wait for a seed to be given
+  while( view.GetNumberOfSeeds( ) == 0 )
+    view.Start( );
+
+  // Convert seed
+  double seed[ 3 ];
+  view.GetSeed( 0, seed );
+  TImage::PointType seed_pnt;
+  seed_pnt[ 0 ] = seed[ 0 ];
+  seed_pnt[ 1 ] = seed[ 1 ];
+  seed_pnt[ 2 ] = seed[ 2 ];
+  TImage::IndexType seed_idx;
+  input_image->TransformPhysicalPointToIndex( seed_pnt, seed_idx );
 
   // Configure observer
-  /* TODO
-     TObserver::Pointer obs = TObserver::New( );
-     obs->SetImage( input_image, view.GetWindow( ) );
-
-     // Configure algorithm
-     TFrontAlgorithm::Pointer algorithm = TFrontAlgorithm::New( );
-     algorithm->AddThresholds( thr_0, thr_1, n_samples );
-
-     TImage::IndexType seed_idx;
-     input_image->TransformPhysicalPointToIndex( seed_pnt, seed_idx );
-     algorithm->AddSeed( seed_idx, 0 );
-
-     algorithm->AddObserver( itk::AnyEvent( ), obs );
-     algorithm->ThrowEventsOn( );
-     algorithm->SetInput( input_image );
-     algorithm->SetNeighborhoodOrder( 1 );
-     algorithm->SetDerivativeThreshold( double( 3 ) );
-     algorithm->Update( );
-
-     view.Start( );
-  */
+  TObserver::Pointer obs = TObserver::New( );
+  obs->SetImage( input_image, view.GetWindow( ) );
+
+  // Configure algorithm
+  TFrontAlgorithm::Pointer algorithm = TFrontAlgorithm::New( );
+  algorithm->AddThresholds( thr_0, thr_1, n_samples );
+  algorithm->AddSeed( seed_idx, 0 );
+  algorithm->AddObserver( itk::AnyEvent( ), obs );
+  algorithm->ThrowEventsOn( );
+  algorithm->SetInput( input_image );
+  algorithm->SetNeighborhoodOrder( 1 );
+  algorithm->SetDerivativeThreshold( double( 3 ) );
+  algorithm->Update( );
+
+  // Let some interaction and close program
+  view.Start( );
   return( 0 );
 }
 
index 24b3308764b213be9debdd904f92aef89bedb387..5ec51ec6681fe044d2794a6c09d6199a31a7966c 100644 (file)
@@ -47,7 +47,7 @@ template< class V, class R, class VV, class VC, class B >
 void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
 _BeforeLoop( )
 {
-  this->_BeforeLoop( );
+  this->Superclass::_BeforeLoop( );
   this->m_ActualFunction = this->m_Functions.begin( );
 }
 
index 44cccc274e083f7408c976569bcfc80ff7a735b3..6da586d2249271f1017dcf78399993d2846d7bb9 100644 (file)
@@ -53,9 +53,12 @@ namespace fpa
                  {
               */
               TPixel v = img->GetPixel( idx );
+              std::cout
+                << v << " "
+                << this->m_LowerThreshold << " "
+                << this->m_UpperThreshold << std::endl;
               return(
-                this->m_LowerThreshold <= v &&
-                v <= this->m_UpperThreshold
+                this->m_LowerThreshold <= v && v < this->m_UpperThreshold
                 );
 
               // TODO: } // fi
index 41fba37baae72af994d8b7881600a8e30f0f504c..b4c3e4e536480c084c1ba040fa3120c3918e99fc 100644 (file)
@@ -2,7 +2,9 @@
 #define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__H__
 
 #include <map>
+#include <set>
 #include <fpa/Image/RegionGrowWithMultipleCriteria.h>
+#include <fpa/Image/Functors/RegionGrowThresholdFunction.h>
 
 namespace fpa
 {
@@ -28,6 +30,9 @@ namespace fpa
       typedef typename Superclass::TMembershipFunction TMembershipFunction;
       typedef typename Superclass::TFunctions          TFunctions;
 
+      typedef std::set< TPixel >                                     TThresholds;
+      typedef fpa::Image::Functors::RegionGrowThresholdFunction< I > TFunction;
+
     protected:
       typedef typename TBaseAlgorithm::_TNode _TNode;
 
@@ -59,6 +64,7 @@ namespace fpa
       void operator=( const Self& );                   // Not impl.
 
     protected:
+      TThresholds m_Thresholds;
       double m_DerivativeThreshold;
       THistogram m_Histogram;
     };
index 0969b0cd59e082ccdf8d33c30778e75d0c171697..a5b2075b3819a45d4eff92e57b347d1a474c4f21 100644 (file)
@@ -2,43 +2,14 @@
 #define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
 
 #include <limits>
-#include <fpa/Image/Functors/RegionGrowThresholdFunction.h>
 
 // -------------------------------------------------------------------------
 template< class I >
 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
 AddThreshold( const TPixel& v )
 {
-  typedef
-    fpa::Image::Functors::RegionGrowThresholdFunction< I >
-    TFunction;
-  typename TFunction::Pointer function = TFunction::New( );
-
-  if( this->GetNumberOfMembershipFunctions( ) > 0 )
-  {
-  }
-  else
-    function->SetLowerThreshold( std::numeric_limits< TPixel >::min( ) );
-  std::cout
-    << typeid( TPixel ).name( ) << " <<<----->>> "
-    << function->GetLowerThreshold( )
-    << std::endl;
-  std::exit( 1 );
-  function->SetUpperThreshold( v );
-  this->AddMembershipFunction( function );
-
-  /* TODO
-     this->m_Histogram[ v ] = 0;
-
-     TFunction* function =
-     dynamic_cast< TFunction* >( this->GetMembershipFunction( ) );
-     if( function != NULL )
-     {
-     function->SetLowerThreshold( this->m_Histogram.begin( )->first );
-
-     } // fi
-     this->Modified( );
-  */
+  this->m_Thresholds.insert( v );
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
@@ -80,7 +51,9 @@ bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
 _UpdateResult( _TNode& n )
 {
   bool ret = this->Superclass::_UpdateResult( n );
+  std::cout << "Image:UpdateResult " << ret << std::endl;
 
+  
   /* TODO
      if( ret )
      {
@@ -110,18 +83,22 @@ template< class I >
 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
 _BeforeLoop( )
 {
-  std::cout << "**1" << std::endl;
   const I* img = this->GetInput( );
-  std::cout << "**2" << std::endl;
-  typename TFunctions::iterator fIt = this->m_Functions.begin( );
-  for( ; fIt != this->m_Functions.end( ); ++fIt )
+
+  this->ClearMembershipFunctions( );
+  typename TThresholds::const_iterator tIt = this->m_Thresholds.begin( );
+  typename TThresholds::const_iterator prev_tIt = tIt;
+  for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt, ++prev_tIt )
   {
-    TMembershipFunction* f =
-      dynamic_cast< TMembershipFunction* >( fIt->GetPointer( ) );
-    if( f != NULL )
-      f->SetInputImage( this->GetInput( ) );
+    typename TFunction::Pointer function = TFunction::New( );
+    function->SetInputImage( img );
+    function->SetLowerThreshold( *prev_tIt );
+    function->SetUpperThreshold( *tIt );
+    this->AddMembershipFunction( function );
+    std::cout << *prev_tIt << " " << *tIt << std::endl;
 
   } // rof
+
   this->Superclass::_BeforeLoop( );
 }
 
index b990900f17ef4a4cbfa04fc3347b8463745c53d2..fc5883e6f724aa0c307e4c47930bcba921ad7355 100644 (file)
@@ -2,58 +2,65 @@
 
 #include <vtkCommand.h>
 #include <vtkInteractorStyleSwitch.h>
-#include <vtkPickingManager.h>
 
-class vtkUpdateCallback
+#include <fpa/VTK/SeedWidgetCorrector.h>
+
+/**
+ */
+class fpa_VTK_InteractionModeCallback
   : public vtkCommand
 {
 public:
-  static vtkUpdateCallback *New()
+  static fpa_VTK_InteractionModeCallback* New( )
     {
-      return new vtkUpdateCallback;
+      return( new fpa_VTK_InteractionModeCallback );
     }
-  virtual void Execute(vtkObject *caller, unsigned long eventId, void*
-                       arguments)
+  virtual void Execute(
+    vtkObject* caller, unsigned long eventId, void* arguments )
     {
-      vtkRenderWindowInteractor* iren = 
-        static_cast< vtkRenderWindowInteractor* >( caller );
-      if( caller == NULL )
-        return;
-
-      switch( iren->GetKeyCode( ) )
+      if( eventId == vtkCommand::KeyPressEvent )
       {
-      case 'x':
-      case 'X':
-      {
-        bool eSeed = ( this->SeedWidget->GetProcessEvents( ) == 1 );
-        if( eSeed )
+        vtkRenderWindowInteractor* iren = 
+          static_cast< vtkRenderWindowInteractor* >( caller );
+        if( caller == NULL )
+          return;
+
+        switch( iren->GetKeyCode( ) )
         {
-          this->SeedWidget->ProcessEventsOff( );
-          this->WidgetX->InteractionOn( );
-          this->WidgetY->InteractionOn( );
-          this->WidgetZ->InteractionOn( );
-        }
-        else
+        case 'x':
+        case 'X':
         {
-          this->SeedWidget->ProcessEventsOn( );
-          this->WidgetX->InteractionOff( );
-          this->WidgetY->InteractionOff( );
-          this->WidgetZ->InteractionOff( );
-
-        } // fi
-      }
-      break;
-      default:
+          bool eSeed = ( this->SeedWidget->GetProcessEvents( ) == 1 );
+          if( eSeed )
+          {
+            this->SeedWidget->ProcessEventsOff( );
+            this->WidgetX->InteractionOn( );
+            this->WidgetY->InteractionOn( );
+            this->WidgetZ->InteractionOn( );
+          }
+          else
+          {
+            this->SeedWidget->ProcessEventsOn( );
+            this->WidgetX->InteractionOff( );
+            this->WidgetY->InteractionOff( );
+            this->WidgetZ->InteractionOff( );
+
+          } // fi
+        }
         break;
+        default:
+          break;
+
+        } // hctiws
 
-      } // hctiws
+      } // fi
     }
 
 public:
   vtkImagePlaneWidget* WidgetX;
   vtkImagePlaneWidget* WidgetY;
   vtkImagePlaneWidget* WidgetZ;
-  vtkSeedWidget2*       SeedWidget;
+  vtkSeedWidget*       SeedWidget;
 };
 
 // -------------------------------------------------------------------------
@@ -70,40 +77,36 @@ ImageMPR( )
   this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( );
   this->m_Window = vtkSmartPointer< vtkRenderWindow >::New( );
   this->m_Interactor = vtkSmartPointer< vtkRenderWindowInteractor >::New( );
+  this->m_SeedHandleRepresentation =
+    vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
+  this->m_SeedRepresentation =
+    vtkSmartPointer< vtkSeedRepresentation >::New( );
+  this->m_SeedWidget = vtkSmartPointer<vtkSeedWidget>::New();
 
-
-
-
-
-
-  handlePointRep3D =
-    vtkSmartPointer<vtkPointHandleRepresentation3D>::New();
-  //handlePointRep3D->AllOn();
-  handlePointRep3D->GetProperty()->SetColor(1.,0.,1.);
-  seedRep =
-    vtkSmartPointer<vtkSeedRepresentation>::New();
-  seedRep->SetHandleRepresentation(handlePointRep3D);
-  seedWidget = vtkSmartPointer<vtkSeedWidget2>::New();
-
-  seedWidget->SetRepresentation(seedRep);
+  this->m_SeedHandleRepresentation->GetProperty()->SetColor( 1, 0, 1 );
+  this->m_SeedRepresentation->
+    SetHandleRepresentation( this->m_SeedHandleRepresentation );
+  this->m_SeedWidget->SetRepresentation( this->m_SeedRepresentation );
 
   this->m_WidgetX->KeyPressActivationOff( );
   this->m_WidgetY->KeyPressActivationOff( );
   this->m_WidgetZ->KeyPressActivationOff( );
-  seedWidget->KeyPressActivationOff( );
-
-  // this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker );
-
-
-  vtkUpdateCallback* onUpdate = vtkUpdateCallback::New();
-  onUpdate->WidgetX = this->m_WidgetX;
-  onUpdate->WidgetY = this->m_WidgetY;
-  onUpdate->WidgetZ = this->m_WidgetZ;
-  onUpdate->SeedWidget = this->seedWidget;
-
-  this->m_Interactor->AddObserver(vtkCommand::KeyPressEvent, onUpdate);
+  this->m_SeedWidget->KeyPressActivationOff( );
+
+  vtkSmartPointer< fpa_VTK_InteractionModeCallback > int_cb =
+    vtkSmartPointer< fpa_VTK_InteractionModeCallback >::New( );
+  int_cb->WidgetX = this->m_WidgetX;
+  int_cb->WidgetY = this->m_WidgetY;
+  int_cb->WidgetZ = this->m_WidgetZ;
+  int_cb->SeedWidget = this->m_SeedWidget;
+  this->m_Interactor->AddObserver( vtkCommand::KeyPressEvent, int_cb );
+
+  vtkSmartPointer< fpa::VTK::SeedWidgetCorrector > corr_cb =
+    vtkSmartPointer< fpa::VTK::SeedWidgetCorrector >::New( );
+  corr_cb->Configure( this->m_Picker );
+  this->m_SeedWidget->AddObserver( vtkCommand::PlacePointEvent, corr_cb );
 }
-    
+
 // -------------------------------------------------------------------------
 fpa::VTK::ImageMPR::
 ~ImageMPR( )
@@ -181,16 +184,18 @@ SetImage( vtkImageData* image )
   this->m_WidgetX->SetInteractor( this->m_Interactor );
   this->m_WidgetY->SetInteractor( this->m_Interactor );
   this->m_WidgetZ->SetInteractor( this->m_Interactor );
-  seedWidget->SetInteractor(this->m_Interactor);
+  this->m_SeedWidget->SetInteractor( this->m_Interactor );
 
   this->m_WidgetX->On( );
   this->m_WidgetY->On( );
   this->m_WidgetZ->On( );
-  seedWidget->On( );
-  seedWidget->ProcessEventsOff( );
+  this->m_SeedWidget->On( );
+  this->m_SeedWidget->ProcessEventsOff( );
   this->m_Interactor->SetPicker( this->m_Picker );
-  this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker );
-  this->m_Interactor->GetPickingManager( )->EnabledOn( );
+  /*
+    this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker );
+    this->m_Interactor->GetPickingManager( )->EnabledOn( );
+  */
 }
 
 // -------------------------------------------------------------------------
@@ -223,6 +228,27 @@ AddPolyData( vtkPolyData* pd, double r, double g, double b )
   this->m_Renderer->AddActor( this->m_Actors[ i ] );
 }
 
+// -------------------------------------------------------------------------
+unsigned int fpa::VTK::ImageMPR::
+GetNumberOfSeeds( ) const
+{
+  return( this->m_SeedRepresentation->GetNumberOfSeeds( ) );
+}
+
+// -------------------------------------------------------------------------
+void fpa::VTK::ImageMPR::
+GetSeed( int n, double* s ) const
+{
+  vtkHandleWidget* hWdg = this->m_SeedWidget->GetSeed( n );
+  if( hWdg == NULL )
+    return;
+  vtkHandleRepresentation* hRep =
+    dynamic_cast< vtkHandleRepresentation* >( hWdg->GetRepresentation( ) );
+  if( hRep == NULL )
+    return;
+  hRep->GetWorldPosition( s );
+}
+
 // -------------------------------------------------------------------------
 vtkRenderWindow* fpa::VTK::ImageMPR::
 GetWindow( ) const
index 6664d31343a1c9074ac59f5bde801c01a2ee285b..ba82b9571fa4008c899025a6bc99467552087523 100644 (file)
@@ -5,57 +5,22 @@
 
 #include <vtkActor.h>
 #include <vtkCellPicker.h>
+#include <vtkHandleWidget.h>
 #include <vtkImageData.h>
 #include <vtkImagePlaneWidget.h>
 #include <vtkOutlineSource.h>
+#include <vtkPointHandleRepresentation3D.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkProperty.h>
 #include <vtkRenderer.h>
 #include <vtkRendererCollection.h>
 #include <vtkRenderWindow.h>
 #include <vtkRenderWindowInteractor.h>
+#include <vtkSeedRepresentation.h>
+#include <vtkSeedWidget.h>
 #include <vtkSmartPointer.h>
 #include <vtkSphereSource.h>
 
-#include <vtkSeedWidget.h>
-#include <vtkSeedRepresentation.h>
-#include <vtkHandleWidget.h>
-#include <vtkPointHandleRepresentation3D.h>
-
-class vtkSeedWidget2
-  : public vtkSeedWidget
-{
-public:
-  // Description:
-  // Instantiate this class.
-  static vtkSeedWidget2 *New()
-    {
-      return new vtkSeedWidget2;
-    }
-
-  // Description:
-  // Standard methods for a VTK class.
-  vtkTypeMacro(vtkSeedWidget2, vtkSeedWidget);
-
-  virtual vtkPickingManager* GetPickingManager( )
-    {
-      return( this->Superclass::GetPickingManager( ) );
-    }
-
-protected:
-  vtkSeedWidget2()
-    : Superclass( )
-    {
-    }
-  virtual ~vtkSeedWidget2()
-    {
-    }
-
-private:
-  vtkSeedWidget2(const vtkSeedWidget2&);  //Not implemented
-  void operator=(const vtkSeedWidget2&);  //Not implemented
-};
-
 namespace fpa
 {
   namespace VTK
@@ -74,34 +39,36 @@ namespace fpa
 
       void AddPolyData( vtkPolyData* pd, double r, double g, double b );
 
+      unsigned int GetNumberOfSeeds( ) const;
+      void GetSeed( int n, double* s ) const;
+
       vtkRenderWindow* GetWindow( ) const;
       vtkRenderer* GetRenderer( ) const;
 
       void Start( );
 
     protected:
-      vtkSmartPointer< vtkImageData > m_Image;
-      vtkSmartPointer< vtkOutlineSource > m_Outline;
-      vtkSmartPointer< vtkPolyDataMapper > m_OutlineMapper;
-      vtkSmartPointer< vtkActor > m_OutlineActor;
-      vtkSmartPointer< vtkCellPicker > m_Picker;
-      vtkSmartPointer< vtkImagePlaneWidget > m_WidgetX;
-      vtkSmartPointer< vtkImagePlaneWidget > m_WidgetY;
-      vtkSmartPointer< vtkImagePlaneWidget > m_WidgetZ;
-      vtkSmartPointer< vtkRenderer > m_Renderer;
-      vtkSmartPointer< vtkRenderWindow > m_Window;
+      vtkSmartPointer< vtkImageData >              m_Image;
+      vtkSmartPointer< vtkOutlineSource >          m_Outline;
+      vtkSmartPointer< vtkPolyDataMapper >         m_OutlineMapper;
+      vtkSmartPointer< vtkActor >                  m_OutlineActor;
+      vtkSmartPointer< vtkCellPicker >             m_Picker;
+      vtkSmartPointer< vtkImagePlaneWidget >       m_WidgetX;
+      vtkSmartPointer< vtkImagePlaneWidget >       m_WidgetY;
+      vtkSmartPointer< vtkImagePlaneWidget >       m_WidgetZ;
+      vtkSmartPointer< vtkRenderer >               m_Renderer;
+      vtkSmartPointer< vtkRenderWindow >           m_Window;
       vtkSmartPointer< vtkRenderWindowInteractor > m_Interactor;
 
-      std::vector< vtkSmartPointer< vtkPolyData > > m_PolyDatas;
+      std::vector< vtkSmartPointer< vtkPolyData > >       m_PolyDatas;
       std::vector< vtkSmartPointer< vtkPolyDataMapper > > m_Mappers;
-      std::vector< vtkSmartPointer< vtkActor > > m_Actors;
-
+      std::vector< vtkSmartPointer< vtkActor > >          m_Actors;
 
       // Create the widget and its representation
-      vtkSmartPointer<vtkPointHandleRepresentation3D> handlePointRep3D;
-      vtkSmartPointer<vtkSeedRepresentation> seedRep;
-      vtkSmartPointer<vtkSeedWidget2> seedWidget;
-
+      vtkSmartPointer< vtkPointHandleRepresentation3D >
+        m_SeedHandleRepresentation;
+      vtkSmartPointer< vtkSeedRepresentation > m_SeedRepresentation;
+      vtkSmartPointer< vtkSeedWidget >         m_SeedWidget;
     };
 
   } // ecapseman
diff --git a/lib/fpa/VTK/SeedWidgetCorrector.cxx b/lib/fpa/VTK/SeedWidgetCorrector.cxx
new file mode 100644 (file)
index 0000000..93f32a1
--- /dev/null
@@ -0,0 +1,79 @@
+#include <fpa/VTK/SeedWidgetCorrector.h>
+
+#include <vtkCellPicker.h>
+#include <vtkSeedWidget.h>
+
+#include <vtkHandleRepresentation.h>
+#include <vtkHandleWidget.h>
+#include <vtkRenderWindowInteractor.h>
+
+// -------------------------------------------------------------------------
+fpa::VTK::SeedWidgetCorrector*
+fpa::VTK::SeedWidgetCorrector::
+New( )
+{
+  return( new fpa::VTK::SeedWidgetCorrector );
+}
+
+// -------------------------------------------------------------------------
+void fpa::VTK::SeedWidgetCorrector::
+Configure( vtkCellPicker* picker )
+{
+  this->m_Picker = picker;
+}
+
+// -------------------------------------------------------------------------
+void fpa::VTK::SeedWidgetCorrector::
+Execute( vtkObject* caller, unsigned long eventId, void* arguments )
+{
+  vtkSeedWidget* wdg = dynamic_cast< vtkSeedWidget* >( caller );
+  if( wdg == NULL || this->m_Picker == NULL )
+    return;
+
+  if( eventId == vtkCommand::PlacePointEvent )
+  {
+    // Get newly added handle and its associated objects
+    int hId = *( reinterpret_cast< int* >( arguments ) );
+    vtkHandleWidget* hWdg = wdg->GetSeed( hId );
+    if( hWdg == NULL )
+      return;
+    vtkHandleRepresentation* hRep =
+      dynamic_cast< vtkHandleRepresentation* >( hWdg->GetRepresentation( ) );
+    if( hRep == NULL )
+      return;
+
+    // Get clicked point and 3D scene
+    double p[ 3 ];
+    hRep->GetDisplayPosition( p );
+    vtkRenderWindowInteractor* iren = wdg->GetInteractor( );
+    if( iren == NULL )
+      return;
+    vtkRenderer* ren =
+      iren->FindPokedRenderer( int( p[ 0 ] ), int( p[ 1 ] ) );
+    if( ren == NULL )
+      return;
+
+    // Correct point with given picker
+    double q[ 3 ];
+    this->m_Picker->Pick( p[ 0 ], p[ 1 ], p[ 2 ], ren );
+    this->m_Picker->GetPickPosition( q );
+    hRep->SetWorldPosition( q );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+fpa::VTK::SeedWidgetCorrector::
+SeedWidgetCorrector( )
+  : vtkCommand( ),
+    m_Picker( NULL )
+{
+}
+
+// -------------------------------------------------------------------------
+fpa::VTK::SeedWidgetCorrector::
+~SeedWidgetCorrector( )
+{
+}
+
+// eof - $RCSfile$
diff --git a/lib/fpa/VTK/SeedWidgetCorrector.h b/lib/fpa/VTK/SeedWidgetCorrector.h
new file mode 100644 (file)
index 0000000..426a75a
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef __FPA__VTK__SEEDWIDGETCORRECTOR__H__
+#define __FPA__VTK__SEEDWIDGETCORRECTOR__H__
+
+#include <fpa/FrontAlgorithms_Export.h>
+#include <vtkCommand.h>
+
+class vtkCellPicker;
+class vtkSeedWidget;
+
+namespace fpa
+{
+  namespace VTK
+  {
+    /**
+     */
+    class FrontAlgorithms_EXPORT SeedWidgetCorrector
+      : public vtkCommand
+    {
+    public:
+      static SeedWidgetCorrector* New( );
+
+      void Configure( vtkCellPicker* picker );
+
+      virtual void Execute(
+        vtkObject* caller,
+        unsigned long eventId,
+        void* arguments
+        );
+
+    protected:
+      SeedWidgetCorrector( );
+      virtual ~SeedWidgetCorrector( );
+
+    protected:
+      vtkCellPicker* m_Picker;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __FPA__VTK__SEEDWIDGETCORRECTOR__H__
+
+// eof - $RCSfile$