]> Creatis software - cpPlugins.git/blobdiff - appli/ImageMPR/ImageMPR.cxx
Widget integration (step 6/6): Interactive architecture finished. Needs to be tested...
[cpPlugins.git] / appli / ImageMPR / ImageMPR.cxx
index ada90eaa9ac06e67c5694d300146987a99c7a394..58276cb7433b6b7027347130614d0e8ee7c057d2 100644 (file)
@@ -13,10 +13,14 @@ ImageMPR::
 ImageMPR( QWidget* parent )
   : QMainWindow( parent ),
     m_UI( new Ui::ImageMPR ),
-    m_ImageLoaded( false )
+    m_ImageLoaded( "" ),
+    m_Flooding( false )
 {
   this->m_UI->setupUi( this );
 
+  // Associate callbacks
+  this->m_UI->MPR->AddCursorCommand( Self::_CursorCommand, this );
+
   // Connect actions
   ImageMPR_ConnectAction( OpenImage );
   ImageMPR_ConnectAction( OpenSegmentation );
@@ -47,7 +51,7 @@ ImageMPR::
 void ImageMPR::
 _aOpenImage( )
 {
-  if( this->m_ImageLoaded )
+  if( this->m_ImageLoaded != "" )
     this->m_UI->MPR->ClearAll( );
   this->m_ImageLoaded = this->m_UI->MPR->LoadImage( );
 }
@@ -56,7 +60,7 @@ _aOpenImage( )
 void ImageMPR::
 _aOpenSegmentation( )
 {
-  if( this->m_ImageLoaded )
+  if( this->m_ImageLoaded != "" )
     this->m_ImageLoaded = this->m_UI->MPR->LoadImage( );
 }
 
@@ -121,7 +125,19 @@ _execPlugin( )
   if( action == NULL )
     return;
   std::string name = action->text( ).toStdString( );
-  this->m_UI->MPR->ExecuteFilter( name, 0 );
+
+  if( name == "cpPlugins::BasicFilters::FloodFillImageFilter" )
+  {
+    this->m_Flooding = true;
+  }
+  else
+  {
+    this->m_Flooding = false;
+    this->m_UI->MPR->ExecuteFilter(
+      name, this->m_ImageLoaded, "SegmentedImage"
+      );
+
+  } // fi
 
   // Configure filter
   /*
@@ -165,6 +181,50 @@ _execPlugin( )
   */
 }
 
+// -------------------------------------------------------------------------
+void ImageMPR::
+_CursorCommand( double* pos, int axis, void* data )
+{
+  Self* app = reinterpret_cast< Self* >( data );
+  if( app == NULL )
+    return;
+  if( !( app->m_Flooding ) )
+    return;
+
+  cpPlugins::Interface::ProcessObject::Pointer filter =
+    app->m_UI->MPR->CreateFilter(
+      "cpPlugins::BasicFilters::FloodFillImageFilter"
+      );
+  if( filter.IsNull( ) )
+    return;
+
+  cpPlugins::Interface::Parameters* params = filter->GetParameters( );
+  params->SetPoint( "Seed", 3, pos );
+  params->SetReal( "Window", app->m_UI->MPR->GetWindow( ) );
+  params->SetReal( "Level", app->m_UI->MPR->GetLevel( ) );
+  params->SetUint( "InsideValue", 1 );
+  params->SetUint( "OutsideValue", 0 );
+  filter->SetInput( "Input", app->m_UI->MPR->GetImage( app->m_ImageLoaded ) );
+  app->m_UI->MPR->Block( );
+  std::string err = filter->Update( );
+  cpPlugins::Interface::BaseMPRWindow::TImage::Pointer image = filter->GetOutput< cpPlugins::Interface::BaseMPRWindow::TImage >( "Output" );
+  filter->DisconnectOutputs( );
+  app->m_UI->MPR->AddImage( "Segmentation", image );
+  app->m_UI->MPR->Unblock( );
+
+
+
+  /* TODO
+     std::cout
+     << "CursorCommand ==> "
+     << pos[ 0 ] << " "
+     << pos[ 1 ] << " "
+    << pos[ 2 ] << " : "
+    << axis << " "
+    << data << std::endl;
+  */
+}
+
 /*
 #include "MementoState.h"