]> Creatis software - FrontAlgorithms.git/commitdiff
Some tests... Package is unstable right nowgit status!
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 13 Feb 2015 21:57:13 +0000 (16:57 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 13 Feb 2015 21:57:13 +0000 (16:57 -0500)
appli/examples/example_ImageAlgorithmRegionGrow_MultipleThresholds.cxx
lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx
lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx
lib/fpa/VTK/ImageMPR.cxx
lib/fpa/VTK/ImageMPR.h

index 165dafb30cab17e71691118542c66fad4279e4e2..1f4bf3fa51f4204d927d155f148c37d93539c903 100644 (file)
@@ -38,22 +38,18 @@ TObserver;
 // -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
 {
-  if( argc < 8 )
+  if( argc < 5 )
   {
     std::cerr
       << "Usage: " << argv[ 0 ]
-      << " input_image s_x s_y s_z thr_0 thr_1 n_samples" << std::endl;
+      << " input_image thr_0 thr_1 n_samples" << std::endl;
     return( 1 );
 
   } // fi
   std::string input_image_fn = argv[ 1 ];
-  TImage::PointType seed_pnt;
-  seed_pnt[ 0 ] = std::atof( argv[ 2 ] );
-  seed_pnt[ 1 ] = std::atof( argv[ 3 ] );
-  seed_pnt[ 2 ] = std::atof( argv[ 4 ] );
-  TPixel thr_0 = TPixel( std::atof( argv[ 5 ] ) );
-  TPixel thr_1 = TPixel( std::atof( argv[ 6 ] ) );
-  unsigned int n_samples = std::atoi( argv[ 7 ] );
+  TPixel thr_0 = TPixel( std::atof( argv[ 2 ] ) );
+  TPixel thr_1 = TPixel( std::atof( argv[ 3 ] ) );
+  unsigned int n_samples = std::atoi( argv[ 4 ] );
   
   // Read image
   TImageReader::Pointer input_image_reader = TImageReader::New( );
@@ -78,40 +74,43 @@ int main( int argc, char* argv[] )
   vtk_image->SetInput( input_image );
   vtk_image->Update( );
 
-  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( );
+  /* 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( ) );
-  view.AddPolyData( seed->GetOutput( ), 1, 0, 0 );
+  // TODO: view.AddPolyData( seed->GetOutput( ), 1, 0, 0 );
   view.Start( );
 
   // Configure observer
-  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( );
-
+  /* 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( );
+  */
   return( 0 );
 }
 
index 34420b24ad029a8e3164486082e632def436e652..24b3308764b213be9debdd904f92aef89bedb387 100644 (file)
@@ -60,7 +60,11 @@ _QueuePop( )
   _TNode node = this->Superclass::_QueuePop( );
   if( this->_IsQueueEmpty( ) )
   {
-    std::cerr << "ERROR!!!!" << std::endl;
+    // Replace queue
+    this->m_Queue = this->m_AuxiliaryQueue;
+
+    // Move to next function
+    this->m_ActualFunction++;
 
   } // fi
   return( node );
@@ -71,10 +75,15 @@ template< class V, class R, class VV, class VC, class B >
 bool fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
 _CheckMembership( const _TNode& n ) const
 {
-  bool ret = ( *( this->m_ActualFunction ) )->Evaluate( n.Vertex );
-  if( !ret )
-    this->m_AuxiliaryQueue.push( n );
-  return( ret );
+  if( this->m_ActualFunction != this->m_Functions.end( ) )
+  {
+    bool ret = ( *( this->m_ActualFunction ) )->Evaluate( n.Vertex );
+    if( !ret )
+      this->m_AuxiliaryQueue.push( n );
+    return( ret );
+  }
+  else
+    return( false );
 }
 
 #endif // __FPA__BASE__REGIONGROWWITHMULTIPLECRITERIA__HXX__
index 51e474b958b9f41e8caf9c4e3a91dc5990a27a67..0969b0cd59e082ccdf8d33c30778e75d0c171697 100644 (file)
@@ -20,9 +20,10 @@ AddThreshold( const TPixel& v )
   else
     function->SetLowerThreshold( std::numeric_limits< TPixel >::min( ) );
   std::cout
-    << typeid( TPixel ).name( ) << " "
+    << typeid( TPixel ).name( ) << " <<<----->>> "
     << function->GetLowerThreshold( )
     << std::endl;
+  std::exit( 1 );
   function->SetUpperThreshold( v );
   this->AddMembershipFunction( function );
 
index d435bb8e515baa3449f60b51c818785c7d0ebb00..b990900f17ef4a4cbfa04fc3347b8463745c53d2 100644 (file)
@@ -1,13 +1,65 @@
 #include <fpa/VTK/ImageMPR.h>
 
+#include <vtkCommand.h>
 #include <vtkInteractorStyleSwitch.h>
+#include <vtkPickingManager.h>
+
+class vtkUpdateCallback
+  : public vtkCommand
+{
+public:
+  static vtkUpdateCallback *New()
+    {
+      return new vtkUpdateCallback;
+    }
+  virtual void Execute(vtkObject *caller, unsigned long eventId, void*
+                       arguments)
+    {
+      vtkRenderWindowInteractor* iren = 
+        static_cast< vtkRenderWindowInteractor* >( caller );
+      if( caller == NULL )
+        return;
+
+      switch( iren->GetKeyCode( ) )
+      {
+      case 'x':
+      case 'X':
+      {
+        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
+    }
+
+public:
+  vtkImagePlaneWidget* WidgetX;
+  vtkImagePlaneWidget* WidgetY;
+  vtkImagePlaneWidget* WidgetZ;
+  vtkSeedWidget2*       SeedWidget;
+};
 
 // -------------------------------------------------------------------------
 fpa::VTK::ImageMPR::
 ImageMPR( )
 {
-  // vtkSmartPointer< vtkImageData > m_Image;
-
   this->m_Outline = vtkSmartPointer< vtkOutlineSource >::New( );
   this->m_OutlineMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
   this->m_OutlineActor = vtkSmartPointer< vtkActor >::New( );
@@ -18,6 +70,38 @@ ImageMPR( )
   this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( );
   this->m_Window = vtkSmartPointer< vtkRenderWindow >::New( );
   this->m_Interactor = vtkSmartPointer< vtkRenderWindowInteractor >::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_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);
 }
     
 // -------------------------------------------------------------------------
@@ -97,6 +181,16 @@ 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_WidgetX->On( );
+  this->m_WidgetY->On( );
+  this->m_WidgetZ->On( );
+  seedWidget->On( );
+  seedWidget->ProcessEventsOff( );
+  this->m_Interactor->SetPicker( this->m_Picker );
+  this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker );
+  this->m_Interactor->GetPickingManager( )->EnabledOn( );
 }
 
 // -------------------------------------------------------------------------
index e7a65d39b04b27470ed15c71a79897c333b6b2ea..6664d31343a1c9074ac59f5bde801c01a2ee285b 100644 (file)
 #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
@@ -56,6 +95,13 @@ namespace fpa
       std::vector< vtkSmartPointer< vtkPolyData > > m_PolyDatas;
       std::vector< vtkSmartPointer< vtkPolyDataMapper > > m_Mappers;
       std::vector< vtkSmartPointer< vtkActor > > m_Actors;
+
+
+      // Create the widget and its representation
+      vtkSmartPointer<vtkPointHandleRepresentation3D> handlePointRep3D;
+      vtkSmartPointer<vtkSeedRepresentation> seedRep;
+      vtkSmartPointer<vtkSeedWidget2> seedWidget;
+
     };
 
   } // ecapseman