]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 23 Nov 2015 22:58:00 +0000 (17:58 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 23 Nov 2015 22:58:00 +0000 (17:58 -0500)
lib/cpExtensions/Algorithms/SpatialObjectMaskImageFilter.h
lib/cpExtensions/Algorithms/SpatialObjectMaskImageFilter.hxx
lib/cpExtensions/Visualization/ImageBlender.cxx
lib/cpExtensions/Visualization/ImageBlender.h
lib/cpExtensions/Visualization/ImageSliceActors.cxx
lib/cpExtensions/Visualization/ImageSliceActors.h
lib/cpExtensions/Visualization/MPRActors.cxx
lib/cpExtensions/Visualization/MPRActors.h
lib/cpPlugins/Interface/BaseMPRWidget.cxx
lib/cpPlugins/Interface/BaseMPRWidget.h
lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx

index f8fd3546fe11be69f10a014607af700f6a09565d..2b81fb7834baccb730f2f4f4ef5682550cf998c6 100644 (file)
@@ -2,7 +2,7 @@
 #define __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__H__
 
 #include <itkConceptChecking.h>
-#include <itkInPlaceImageFilter.h>
+#include <itkImageToImageFilter.h>
 #include <itkSpatialObject.h>
 
 namespace cpExtensions
@@ -13,11 +13,11 @@ namespace cpExtensions
      */
     template< class I, class O = I >
     class SpatialObjectMaskImageFilter
-      : public itk::InPlaceImageFilter< I, O >
+      : public itk::ImageToImageFilter< I, O >
     {
     public:
       typedef SpatialObjectMaskImageFilter    Self;
-      typedef itk::InPlaceImageFilter< I, O > Superclass;
+      typedef itk::ImageToImageFilter< I, O > Superclass;
       typedef itk::SmartPointer< Self >       Pointer;
       typedef itk::SmartPointer< const Self > ConstPointer;
 
@@ -28,12 +28,10 @@ namespace cpExtensions
       itkStaticConstMacro( OutputDimension, unsigned int, O::ImageDimension );
 
 #ifdef ITK_USE_CONCEPT_CHECKING
-      // Begin concept checking
       itkConceptMacro(
         SameDimensionCheck1,
         ( itk::Concept::SameDimension< InputDimension, OutputDimension > )
         );
-      // End concept checking
 #endif
 
       typedef typename I::RegionType TRegion;
@@ -42,7 +40,7 @@ namespace cpExtensions
 
     public:
       itkNewMacro( Self );
-      itkTypeMacro( SpatialObjectMaskImageFilter, itk::InPlaceImageFilter );
+      itkTypeMacro( SpatialObjectMaskImageFilter, itk::ImageToImageFilter );
 
       itkGetObjectMacro( SpatialObject, TSpatialObject );
       itkGetConstObjectMacro( SpatialObject, TSpatialObject );
@@ -51,6 +49,12 @@ namespace cpExtensions
       itkSetObjectMacro( SpatialObject, TSpatialObject );
       itkSetMacro( OutsideValue, TOutPixel );
 
+    public:
+      O* GetPositiveOutput( );
+      const O* GetPositiveOutput( ) const;
+      O* GetNegativeOutput( );
+      const O* GetNegativeOutput( ) const;
+
     protected:
       SpatialObjectMaskImageFilter( );
       virtual ~SpatialObjectMaskImageFilter( );
index 2df9c6f652848afef28af4b596abbb5c92911267..2c3cac73f33b2fdbd39d060dd5d5d036a0df1e11 100644 (file)
@@ -4,6 +4,38 @@
 #include <itkImageScanlineIterator.h>
 #include <itkProgressReporter.h>
 
+// -------------------------------------------------------------------------
+template< class I, class O >
+O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
+GetPositiveOutput( )
+{
+  return( this->GetOutput( 0 ) );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O >
+const O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
+GetPositiveOutput( ) const
+{
+  return( this->GetOutput( 0 ) );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O >
+O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
+GetNegativeOutput( )
+{
+  return( this->GetOutput( 1 ) );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O >
+const O* cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
+GetNegativeOutput( ) const
+{
+  return( this->GetOutput( 1 ) );
+}
+
 // -------------------------------------------------------------------------
 template< class I, class O >
 cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >::
@@ -11,7 +43,9 @@ SpatialObjectMaskImageFilter( )
   : Superclass( )
 {
   this->SetNumberOfRequiredInputs( 1 );
-  this->InPlaceOff( );
+  this->SetNumberOfRequiredOutputs( 2 );
+  this->SetNthOutput( 0, O::New( ) );
+  this->SetNthOutput( 1, O::New( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -52,7 +86,8 @@ ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
   // Get inputs
   const I* in =
     dynamic_cast< const I* >( this->itk::ProcessObject::GetInput( 0 ) );
-  O* out = this->GetOutput( 0 );
+  O* pos_out = this->GetPositiveOutput( );
+  O* neg_out = this->GetNegativeOutput( );
   const auto size0 = region.GetSize( 0 );
   if( size0 == 0 )
     return;
@@ -60,7 +95,8 @@ ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
 
   // Create iterators
   itk::ImageScanlineConstIterator< I > iIt( in, region );
-  itk::ImageScanlineIterator< O > oIt( out, region );
+  itk::ImageScanlineIterator< O > pos_oIt( pos_out, region );
+  itk::ImageScanlineIterator< O > neg_oIt( neg_out, region );
   itk::ProgressReporter progress( this, threadId, nLines );
 
   // Main loop
@@ -72,15 +108,24 @@ ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
       auto idx = iIt.GetIndex( );
       in->TransformIndexToPhysicalPoint( idx, pnt );
       if( this->m_SpatialObject->IsInside( pnt ) )
-        oIt.Set( TOutPixel( iIt.Get( ) ) );
+      {
+        pos_oIt.Set( TOutPixel( iIt.Get( ) ) );
+        neg_oIt.Set( this->m_OutsideValue );
+      }
       else
-        oIt.Set( this->m_OutsideValue );
+      {
+        neg_oIt.Set( TOutPixel( iIt.Get( ) ) );
+        pos_oIt.Set( this->m_OutsideValue );
+
+      } // fi
       ++iIt;
-      ++oIt;
+      ++pos_oIt;
+      ++neg_oIt;
 
     } // elihw
     iIt.NextLine( );
-    oIt.NextLine( );
+    pos_oIt.NextLine( );
+    neg_oIt.NextLine( );
     progress.CompletedPixel( );
 
   } // elihw
index 88d85672ed784661db555924e380ecb1b348abd1..44a08abc90c9f169d7dd89661b3c82c6dfda4ded 100644 (file)
@@ -15,6 +15,16 @@ New( )
   return( new Self( ) );
 }
 
+// -------------------------------------------------------------------------
+unsigned int cpExtensions::Visualization::ImageBlender::
+GetNumberOfInputs( )
+{
+  unsigned int np = this->GetNumberOfInputPorts( );
+  unsigned int ni = 0;
+  for( unsigned int p = 0; p < np; ++p )
+    ni += this->GetNumberOfInputConnections( p );
+  return( ni );
+}
 
 // -------------------------------------------------------------------------
 cpExtensions::Visualization::ImageBlender::
index deca4aff087025e458f62854865826744f554e23..e4bf27c5bff9aef3653d620ee94e521d7531daa8 100644 (file)
@@ -24,6 +24,8 @@ namespace cpExtensions
     public:
       static Self* New( );
 
+      unsigned int GetNumberOfInputs( );
+
     protected:
       ImageBlender( );
       virtual ~ImageBlender( );
index 008117557ec5b48ba487ed9a7e23978183033713..e2ac88acf22357f4417cbef89cc1e6ccec0bcdb8 100644 (file)
@@ -327,8 +327,8 @@ PushActorsInto( vtkRenderWindow* window, bool force_style )
     }
     else // if( axis == 2 )
     {
-      camera->SetPosition( double( 0 ), double(  0 ), double( 1 ) );
-      camera->SetViewUp  ( double( 0 ), double( -1 ), double( 0 ) );
+      camera->SetPosition( double( 0 ), double(  0 ), double( -1 ) );
+      camera->SetViewUp  ( double( 0 ), double( -1 ), double(  0 ) );
 
     } // fi
 
@@ -359,7 +359,7 @@ PopActorsFrom( vtkRenderWindow* window )
 unsigned int cpExtensions::Visualization::ImageSliceActors::
 GetNumberOfImages( ) const
 {
-  return( this->m_Blender->GetNumberOfInputPorts( ) );
+  return( this->m_Blender->GetNumberOfInputs( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -860,25 +860,6 @@ SetSliceNumber( const int& slice )
   // Update text
   this->UpdateText( );
 
-  // Update lines from associated slices
-  /* TODO
-     auto sIt = this->m_AssociatedSlices.begin( );
-     for( ; sIt != this->m_AssociatedSlices.end( ); ++sIt )
-     {
-     Self* slice = *sIt;
-     for( unsigned int id = 0; id < slice->m_AssociatedSlices.size( ); ++id )
-     {
-     std::cout << id << std::endl;
-     if( slice->m_AssociatedSlices[ id ] != this )
-     continue;
-
-     std::cout << "id : " << id << std::endl;
-
-     } // rof
-
-     } // rof
-  */
-
   // Update camera position
   if( this->m_Window == NULL )
     return;
index 81fc0e123b66ba26d611b3f17ed8cf3f65eb6c23..b4cec90e6fec8e3c7a3c8f28b4eb74c49fb5b717 100644 (file)
@@ -51,7 +51,6 @@ namespace cpExtensions
       typedef void ( *TSlicesCommand )( double*, int, void* );
       typedef void ( *TWindowLevelCommand )( double, double, void* );
       typedef TVoidCommand TRenderCommand;
-      typedef TSlicesCommand TCursorAxesCommand;
 
       typedef cpExtensions::Visualization::ImageBlender TBlender;
 
@@ -61,7 +60,6 @@ namespace cpExtensions
       cpExtensions_BaseInteractorStyle_Commands( Slices );
       cpExtensions_BaseInteractorStyle_Commands( WindowLevel );
       cpExtensions_BaseInteractorStyle_Commands( Render );
-      cpExtensions_BaseInteractorStyle_Commands( CursorAxes );
 
     public:
       // Creation
index 47f1251bf214cd8bc4ea64a6df68e2e9d13898e1..e26651b4dd24098b7df304e741041789419694b0 100644 (file)
@@ -350,6 +350,14 @@ SetSlice( const int& axis, double* pos )
   } // fi
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRActors::
+SetAxesCursor( const int& axis, double* pos )
+{
+  if( axis < 3 )
+    this->Slices[ 0 ][ axis ]->SetAxesCursor( pos );
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
 Render( const int& axis )
@@ -460,6 +468,7 @@ _SlicesCommand( double* pos, int axis, void* data )
     if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis )
     {
       actors->SetSlice( j, pos );
+      actors->SetAxesCursor( j, pos );
       actors->Render( j );
 
     } // fi
index e4d7bf61e62f040e4d1f981995f82e4ab0b02984..91c0b5089d9e19eca6b90ba7a6bda710ae1f0be2 100644 (file)
@@ -89,6 +89,7 @@ namespace cpExtensions
       int GetSliceNumberMaxValue( const int& axis ) const;
       void SetSliceNumber( const int& axis, const int& slice );
       void SetSlice( const int& axis, double* pos );
+      void SetAxesCursor( const int& axis, double* pos );
 
       // Rendering controls
       void Render( const int& axis );
index b84d75c2b39aba1b488ea41fe7ae0807c732ded6..b971b71b215ae2973f08ff3a05d4dfe831a6ffc2 100644 (file)
@@ -183,7 +183,12 @@ ShowData( const std::string& name )
     if( name == this->m_MainImage )
       this->m_MPRObjects->SetInputImage( iIt->second.Image );
     else
+    {
+      std::cout << this->m_MPRObjects->GetNumberOfImages( ) << std::endl;
+
+
       this->m_MPRObjects->AddBinaryImage( iIt->second.Image, 1, 0, 0 );
+    }
     this->m_MPRObjects->Show( );
   }
   else if( iIt->second.Tag == Data::MESH )
@@ -327,7 +332,9 @@ QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
 _FindItemInTree( const std::string& name ) const
 {
   QList< QTreeWidgetItem* > items =
-    this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly );
+    this->m_UI->LoadedData->findItems(
+      name.c_str( ), Qt::MatchExactly | Qt::MatchRecursive
+      );
   if( items.size( ) > 0 )
     return( items[ 0 ] );
   else
index cd269f41e58f0560569d31f8ec4c585e825543c7..a5ba35c31bebd7e5243a7651831b704eb7cb96c0 100644 (file)
@@ -98,6 +98,8 @@ namespace cpPlugins
       void _SyncTop( int a, int b );
 
     protected:
+      static double cm_Colors[ 8 ][ 3 ];
+
       Ui::BaseMPRWidget*             m_UI;
       vtkSmartPointer< TMPRObjects > m_MPRObjects;
       QVTKWidget*                    m_VTK[ 4 ];
index 36bb0e8862e0498a60980d3ae9038b82b22f9c33..916d2ed1e84823475e238c3aacd72d81fbecaaed 100644 (file)
@@ -187,7 +187,8 @@ MacheteFilter( )
     m_PlaneWidget( NULL )
 {
   this->_AddInput( "Input" );
-  this->_MakeOutput< cpPlugins::Interface::DataObject >( "Output" );
+  this->_MakeOutput< cpPlugins::Interface::DataObject >( "PositiveOutput" );
+  this->_MakeOutput< cpPlugins::Interface::DataObject >( "NegativeOutput" );
 
   itk::Point< double, 3 > center;
   itk::Vector< double, 3 > normal;
@@ -252,12 +253,12 @@ _RealImage( itk::DataObject* dobj )
     InfinitePlaneSpatialObject< I::ImageDimension > _TPlane;
   typedef
     cpExtensions::Algorithms::
-    SpatialObjectMaskImageFilter< I > _TFilter;
-  typedef cpPlugins::Interface::DataObject _TDataObject;
+    SpatialObjectMaskImageFilter< I, I > _TFilter;
+  typedef cpPlugins::Interface::DataObject _TObj;
   typedef cpPlugins::Interface::Image      _TImage;
-  typedef typename _TPlane::PointType  _TPoint;
-  typedef typename _TPlane::VectorType _TVector;
-  typedef typename I::PixelType        _TPixel;
+  typedef typename _TPlane::PointType      _TPoint;
+  typedef typename _TPlane::VectorType     _TVector;
+  typedef typename I::PixelType            _TPixel;
 
   I* image = dynamic_cast< I* >( dobj );
 
@@ -279,18 +280,32 @@ _RealImage( itk::DataObject* dobj )
   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 )
+  // Get output names
+  auto pos_name = this->GetOutput< _TObj >( "PositiveOutput" )->GetName( );
+  auto neg_name = this->GetOutput< _TObj >( "NegativeOutput" )->GetName( );
+
+  // Connect outputs (and correct their types and names)
+  _TImage* pos_out = this->GetOutput< _TImage >( "PositiveOutput" );
+  if( pos_out == NULL )
+  {
+    this->_MakeOutput< _TImage >( "PositiveOutput" );
+    pos_out = this->GetOutput< _TImage >( "PositiveOutput" );
+    pos_out->SetName( pos_name );
+
+  } // fi
+  _TImage* neg_out = this->GetOutput< _TImage >( "NegativeOutput" );
+  if( neg_out == NULL )
   {
-    out->SetITK< I >( filter->GetOutput( ) );
-    out->SetName( name );
-    return( "" );
-  }
-  else
-    return( "MacheteFilter: output image not correctly created." );
+    this->_MakeOutput< _TImage >( "NegativeOutput" );
+    neg_out = this->GetOutput< _TImage >( "NegativeOutput" );
+    neg_out->SetName( neg_name );
+
+  } // fi
+
+  // Assign outputs
+  pos_out->SetITK< I >( filter->GetPositiveOutput( ) );
+  neg_out->SetITK< I >( filter->GetNegativeOutput( ) );
+  return( "" );
 }
 
 // eof - $RCSfile$