]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / MacheteFilter.cxx
index 3eb60061e0f18d4ba7e0e8dcb19fc2e143361dd2..36bb0e8862e0498a60980d3ae9038b82b22f9c33 100644 (file)
 #include "MacheteFilter.h"
 
+#include <cpPlugins/Interface/BaseApplication.h>
+#include <cpPlugins/Interface/Plugins.h>
+
 #include <cpPlugins/Interface/DataObject.h>
 #include <cpPlugins/Interface/Image.h>
 #include <cpPlugins/Interface/Mesh.h>
 
 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
+#include <cpExtensions/DataStructures/InfinitePlaneSpatialObject.h>
+#include <cpExtensions/Algorithms/SpatialObjectMaskImageFilter.h>
 
 #include <itkPlaneSpatialObject.h>
 #include <itkPoint.h>
-#include <itkSpatialObjectToImageFilter.h>
 #include <itkVector.h>
 
 #include <vtkInteractorStyleSwitch.h>
 #include <vtkPlaneWidget.h>
 #include <vtkRenderWindowInteractor.h>
 
+#ifdef cpPlugins_Interface_QT4
+#include <QDialogButtonBox>
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::MacheteFilter_Dialog::
+MacheteFilter_Dialog(
+  QWidget* parent, MacheteFilter* filter, Qt::WindowFlags f
+  )
+  : QDialog( parent, f ),
+    m_Filter( filter )
+{
+  this->m_Title = new QLabel( this );
+  this->m_Title->setText( "Execute machete filter" );
+
+  this->m_MainLayout = new QGridLayout( this );
+  this->m_ToolsLayout = new QVBoxLayout( );
+  this->m_ToolsLayout->addWidget( this->m_Title );
+  this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
+
+  // Add buttons
+  QDialogButtonBox* bb = new QDialogButtonBox(
+    QDialogButtonBox::Cancel | QDialogButtonBox::Ok
+    );
+  QObject::connect( bb, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) );
+  QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) );
+  this->m_ToolsLayout->addWidget( bb );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::MacheteFilter_Dialog::
+~MacheteFilter_Dialog( )
+{
+  delete this->m_Title;
+  delete this->m_ToolsLayout;
+  delete this->m_MainLayout;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::BasicFilters::MacheteFilter_Dialog::
+accept( )
+{
+  // Get interactive widget
+  if( this->m_Filter == NULL )
+    return;
+  vtkPlaneWidget* wdg = this->m_Filter->m_PlaneWidget;
+  if( wdg == NULL )
+    return;
+
+  // Get/Set plane parameters
+  double center[ 3 ], normal[ 3 ];
+  wdg->GetCenter( center );
+  wdg->GetNormal( normal );
+  this->m_Filter->GetParameters( )->SetPoint( "PlaneCenter", 3, center );
+  this->m_Filter->GetParameters( )->SetVector( "PlaneNormal", 3, normal );
+
+  // Update filter
+  auto plugins = this->m_Filter->GetPlugins( );
+  if( plugins != NULL )
+  {
+    auto app = plugins->GetApplication( );
+    if( app != NULL )
+      app->UpdateActualFilter( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::BasicFilters::MacheteFilter_Dialog::
+reject( )
+{
+  std::cout << "reject" << std::endl;
+}
+#endif // cpPlugins_Interface_QT4
+
 // -------------------------------------------------------------------------
 cpPlugins::BasicFilters::MacheteFilter::
 DialogResult cpPlugins::BasicFilters::MacheteFilter::
 ExecConfigurationDialog( QWidget* parent )
 {
+#ifdef cpPlugins_Interface_QT4
+
   typedef cpExtensions::Interaction::ImageInteractorStyle _TImageStyle;
 
   // Choose a valid 3D interactor
@@ -91,7 +171,13 @@ ExecConfigurationDialog( QWidget* parent )
   this->m_PlaneWidget->PlaceWidget( );
   this->m_PlaneWidget->On( );
 
+  this->m_Dialog = new MacheteFilter_Dialog( NULL, this );
+  this->m_Dialog->show( );
+
   return( Self::DialogResult_Modal );
+#else // cpPlugins_Interface_QT4
+  return( Self::DialogResult_Cancel );
+#endif // cpPlugins_Interface_QT4
 }
 
 // -------------------------------------------------------------------------
@@ -156,32 +242,55 @@ _FromMesh( cpPlugins::Interface::Mesh* mesh )
   return( "" );
 }
 
-#include <itkImageFileWriter.h>
-
 // -------------------------------------------------------------------------
 template< class I >
 std::string cpPlugins::BasicFilters::MacheteFilter::
 _RealImage( itk::DataObject* dobj )
 {
-  typedef typename I::PixelType                         _TPixel;
-  typedef itk::PlaneSpatialObject< I::ImageDimension >  _TPlane;
-  typedef itk::SpatialObjectToImageFilter< _TPlane, I > _TMaskFilter;
+  typedef
+    cpExtensions::DataStructures::
+    InfinitePlaneSpatialObject< I::ImageDimension > _TPlane;
+  typedef
+    cpExtensions::Algorithms::
+    SpatialObjectMaskImageFilter< I > _TFilter;
+  typedef cpPlugins::Interface::DataObject _TDataObject;
+  typedef cpPlugins::Interface::Image      _TImage;
+  typedef typename _TPlane::PointType  _TPoint;
+  typedef typename _TPlane::VectorType _TVector;
+  typedef typename I::PixelType        _TPixel;
 
   I* image = dynamic_cast< I* >( dobj );
 
-  typename _TMaskFilter::Pointer mask = _TMaskFilter::New( );
-  mask->SetDirection( image->GetDirection( ) );
-  mask->SetOrigin( image->GetOrigin( ) );
-  mask->SetSize( image->GetRequestedRegion( ).GetSize( ) );
-  mask->SetSpacing( image->GetSpacing( ) );
-  mask->SetInsideValue( _TPixel( 1 ) );
-  mask->SetOutsideValue( _TPixel( 0 ) );
-
-  typename itk::ImageFileWriter< I >::Pointer w = 
-    itk::ImageFileWriter< I >::New( );
-  w->SetInput( mask->GetOutput( ) );
-  w->SetFileName( "mask.mhd" );
-  w->Update( );
+  _TPoint c = this->m_Parameters->GetPoint< _TPoint >(
+    "PlaneCenter", I::ImageDimension
+    );
+  _TVector n = this->m_Parameters->GetVector< _TVector >(
+    "PlaneNormal", I::ImageDimension
+    );
+
+  typename _TPlane::Pointer plane = _TPlane::New( );
+  plane->SetCenter( c );
+  plane->SetNormal( n );
+
+  // Configure filter
+  _TFilter* filter = this->_CreateITK< _TFilter >( );
+  filter->SetInput( image );
+  filter->SetSpatialObject( plane );
+  filter->SetOutsideValue( _TPixel( 0 ) );
+  filter->Update( );
+
+  // Connect output (and correct its type)
+  auto name = this->GetOutput< _TDataObject >( "Output" )->GetName( );
+  this->_MakeOutput< _TImage >( "Output" );
+  _TImage* out = this->GetOutput< _TImage >( "Output" );
+  if( out != NULL )
+  {
+    out->SetITK< I >( filter->GetOutput( ) );
+    out->SetName( name );
+    return( "" );
+  }
+  else
+    return( "MacheteFilter: output image not correctly created." );
 }
 
 // eof - $RCSfile$