typedef itk::SmartPointer< const Self > ConstPointer;
public:
+ itkNewMacro( Self );
itkTypeMacro( DataObject, Object );
cpPlugins_Id_Macro( DataObject, "BasicObject" );
cpPlugins_Parameters_List_Configure( Real );
cpPlugins_Parameters_List_Configure( Index );
cpPlugins_Parameters_List_Configure( Point );
+cpPlugins_Parameters_List_Configure( Vector );
// -------------------------------------------------------------------------
void cpPlugins::Interface::Parameters::
cpPlugins_Parameters_Has( Real );
cpPlugins_Parameters_Has( Index );
cpPlugins_Parameters_Has( Point );
+cpPlugins_Parameters_Has( Vector );
cpPlugins_Parameters_Has( StringList );
cpPlugins_Parameters_Has( BoolList );
cpPlugins_Parameters_Has( IntList );
cpPlugins_Parameters_Has( RealList );
cpPlugins_Parameters_Has( IndexList );
cpPlugins_Parameters_Has( PointList );
+cpPlugins_Parameters_Has( VectorList );
cpPlugins_Parameters_Has( Choices );
// -------------------------------------------------------------------------
cpPlugins_Parameters_Clear( Real );
cpPlugins_Parameters_Clear( Index );
cpPlugins_Parameters_Clear( Point );
+cpPlugins_Parameters_Clear( Vector );
// -------------------------------------------------------------------------
bool cpPlugins::Interface::Parameters::
enum Type
{
- String , Bool , Int ,
- Uint , Real , Index ,
- Point , StringList , BoolList ,
- IntList , UintList , RealList ,
- IndexList , PointList , Choices ,
- NoType
+ String , Bool , Int ,
+ Uint , Real , Index ,
+ Point , Vector , StringList ,
+ BoolList , IntList , UintList ,
+ RealList , IndexList , PointList ,
+ VectorList , Choices , NoType
};
typedef bool TBool;
inline void ConfigureAsPoint(
const TString& name, const TUint& dim, const P& v
);
+ template< class V >
+ inline void ConfigureAsVector(
+ const TString& name, const TUint& dim, const V& v
+ );
void ConfigureAsStringList( const TString& name );
void ConfigureAsBoolList( const TString& name );
void ConfigureAsRealList( const TString& name );
void ConfigureAsIndexList( const TString& name );
void ConfigureAsPointList( const TString& name );
+ void ConfigureAsVectorList( const TString& name );
void ConfigureAsChoices(
const TString& name, const std::vector< TString >& choices
);
bool HasReal( const TString& name ) const;
bool HasIndex( const TString& name ) const;
bool HasPoint( const TString& name ) const;
+ bool HasVector( const TString& name ) const;
bool HasStringList( const TString& name ) const;
bool HasBoolList( const TString& name ) const;
bool HasIntList( const TString& name ) const;
bool HasRealList( const TString& name ) const;
bool HasIndexList( const TString& name ) const;
bool HasPointList( const TString& name ) const;
+ bool HasVectorList( const TString& name ) const;
bool HasChoices( const TString& name ) const;
TString GetString( const TString& name ) const;
inline I GetIndex( const TString& name, const TUint& dim ) const;
template< class P >
inline P GetPoint( const TString& name, const TUint& dim ) const;
+ template< class V >
+ inline V GetVector( const TString& name, const TUint& dim ) const;
template< class I >
inline void GetIndexList(
inline void GetPointList(
std::vector< P >& lst, const TString& name, const TUint& dim
) const;
+ template< class V >
+ inline void GetVectorList(
+ std::vector< V >& lst, const TString& name, const TUint& dim
+ ) const;
// Set methods
void SetString( const TString& name, const TString& v );
inline void SetPoint(
const TString& name, const TUint& dim, const P& v
);
+ template< class V >
+ inline void SetVector(
+ const TString& name, const TUint& dim, const V& v
+ );
void AddToStringList( const TString& name, const TString& v );
void AddToBoolList( const TString& name, const TBool& v );
inline void AddToPointList(
const TString& name, const TUint& dim, const P& v
);
+ template< class P >
+ inline void AddToVectorList(
+ const TString& name, const TUint& dim, const P& v
+ );
void ClearStringList( const TString& name );
void ClearBoolList( const TString& name );
void ClearRealList( const TString& name );
void ClearIndexList( const TString& name );
void ClearPointList( const TString& name );
+ void ClearVectorList( const TString& name );
bool SetSelectedChoice( const TString& name, const TString& choice );
this->Modified( );
}
+// -------------------------------------------------------------------------
+template< class V >
+void cpPlugins::Interface::Parameters::
+ConfigureAsVector( const TString& name, const TUint& dim, const V& v )
+{
+ std::stringstream str;
+ str << v[ 0 ];
+ for( unsigned int d = 1; d < dim; ++d )
+ str << ";" << v[ d ];
+ std::string s = str.str( );
+ this->m_Parameters[ name ] =
+ TParameter( Self::Vector, TValues( s, s ) );
+ this->Modified( );
+}
+
// -------------------------------------------------------------------------
template< class I >
I cpPlugins::Interface::Parameters::
return( v );
}
+// -------------------------------------------------------------------------
+template< class V >
+V cpPlugins::Interface::Parameters::
+GetVector( const TString& name, const TUint& dim ) const
+{
+ V v;
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i != this->m_Parameters.end( ) )
+ {
+ if( i->second.first == Self::Vector )
+ {
+ std::istringstream str( i->second.second.second );
+ std::string token;
+ unsigned int d = 0;
+ while( std::getline( str, token, ';' ) && d < dim )
+ {
+ v[ d ] = std::atof( token.c_str( ) );
+ d++;
+
+ } // elihw
+ return( v );
+
+ } // fi
+
+ } // fi
+
+ // If parameter not found
+ for( unsigned int d = 0; d < dim; ++d )
+ v[ d ] = float( 0 );
+ return( v );
+}
+
// -------------------------------------------------------------------------
template< class I >
void cpPlugins::Interface::Parameters::
} // elihw
}
+// -------------------------------------------------------------------------
+template< class V >
+void cpPlugins::Interface::Parameters::
+GetVectorList(
+ std::vector< V >& lst, const TString& name, const TUint& dim
+ ) const
+{
+ lst.clear( );
+
+ TParameters::const_iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return;
+ if( i->second.first == Self::VectorList )
+ return;
+
+ std::istringstream str( i->second.second.second );
+ std::string token;
+ unsigned int d = 0;
+ while( std::getline( str, token, '#' ) )
+ {
+ std::istringstream str2( token );
+ std::string token2;
+ unsigned int d = 0;
+ V v;
+ while( std::getline( str2, token2, ';' ) && d < dim )
+ {
+ v[ d ] = std::atof( token.c_str( ) );
+ d++;
+
+ } // elihw
+ lst.push_back( v );
+
+ } // elihw
+}
+
// -------------------------------------------------------------------------
template< class I >
void cpPlugins::Interface::Parameters::
this->Modified( );
}
+// -------------------------------------------------------------------------
+template< class V >
+void cpPlugins::Interface::Parameters::
+SetVector( const TString& name, const TUint& dim, const V& v )
+{
+ TParameters::iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return;
+ if( i->second.first != Self::Vector )
+ return;
+
+ std::stringstream str;
+ str << v[ 0 ];
+ for( unsigned int d = 1; d < dim; ++d )
+ str << ";" << v[ d ];
+ i->second.second.second = str.str( );
+ this->Modified( );
+}
+
// -------------------------------------------------------------------------
template< class I >
void cpPlugins::Interface::Parameters::
this->Modified( );
}
+// -------------------------------------------------------------------------
+template< class V >
+void cpPlugins::Interface::Parameters::
+AddToVectorList( const TString& name, const TUint& dim, const V& v )
+{
+ TParameters::iterator i = this->m_Parameters.find( name );
+ if( i == this->m_Parameters.end( ) )
+ return;
+ if( i->second.first != Self::VectorList )
+ return;
+
+ std::stringstream str;
+ if( i->second.second.second == "" )
+ str << v[ 0 ];
+ else
+ str << "#" << v[ 0 ];
+ for( unsigned int d = 1; d < dim; ++d )
+ str << ";" << v[ d ];
+ i->second.second.second += str.str( );
+ this->Modified( );
+}
+
#endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
// eof - $RCSfile$
this->m_Interactors.insert( interactor );
}
+// -------------------------------------------------------------------------
+cpPlugins::Interface::ParametersQtDialog::
+TInteractors& cpPlugins::Interface::ParametersQtDialog::
+getInteractors( )
+{
+ return( this->m_Interactors );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::ParametersQtDialog::
+TInteractors& cpPlugins::Interface::ParametersQtDialog::
+getInteractors( ) const
+{
+ return( this->m_Interactors );
+}
+
// -------------------------------------------------------------------------
bool cpPlugins::Interface::ParametersQtDialog::
setParameters( Parameters* parameters )
public:
typedef cpExtensions::Interaction::ImageInteractorStyle TStyle;
+ typedef std::set< vtkRenderWindowInteractor* > TInteractors;
+
public:
ParametersQtDialog( QWidget* parent = 0, Qt::WindowFlags f = 0 );
virtual ~ParametersQtDialog( );
bool IsModal( ) const;
Parameters* getParameters( ) const;
void addInteractor( vtkRenderWindowInteractor* interactor );
+ TInteractors& getInteractors( );
+ const TInteractors& getInteractors( ) const;
bool setParameters( Parameters* parameters );
void setTitle( const std::string& title );
QVBoxLayout* m_ToolsLayout;
bool m_IsModal;
- std::set< vtkRenderWindowInteractor* > m_Interactors;
+ TInteractors m_Interactors;
};
} // ecapseman
this->m_ParametersDialog = new ParametersQtDialog( );
this->m_ParametersDialog->addInteractor( interactor );
#endif // cpPlugins_Interface_QT4
+ this->m_Interactors.insert( interactor );
}
// -------------------------------------------------------------------------
typedef itk::SmartPointer< const Self > ConstPointer;
typedef Parameters TParameters;
+ typedef std::set< vtkRenderWindowInteractor* > TInteractors;
enum DialogResult
{
Parameters::Pointer m_Parameters;
ParametersQtDialog* m_ParametersDialog;
+ TInteractors m_Interactors;
Plugins* m_Plugins;
bool m_Interactive;
--- /dev/null
+#include "MacheteFilter.h"
+
+#include <cpPlugins/Interface/DataObject.h>
+#include <cpPlugins/Interface/Image.h>
+#include <cpPlugins/Interface/Mesh.h>
+
+#include <cpExtensions/Interaction/ImageInteractorStyle.h>
+
+#include <itkPlaneSpatialObject.h>
+#include <itkPoint.h>
+#include <itkSpatialObjectToImageFilter.h>
+#include <itkVector.h>
+
+#include <vtkInteractorStyleSwitch.h>
+#include <vtkPlaneWidget.h>
+#include <vtkRenderWindowInteractor.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::MacheteFilter::
+DialogResult cpPlugins::BasicFilters::MacheteFilter::
+ExecConfigurationDialog( QWidget* parent )
+{
+ typedef cpExtensions::Interaction::ImageInteractorStyle _TImageStyle;
+
+ // Choose a valid 3D interactor
+ vtkRenderWindowInteractor* iren = NULL;
+ auto iIt = this->m_Interactors.begin( );
+ for( ; iIt != this->m_Interactors.end( ) && iren == NULL; ++iIt )
+ {
+ _TImageStyle* istyle =
+ dynamic_cast< _TImageStyle* >(
+ ( *iIt )->GetInteractorStyle( )
+ );
+ if( istyle == NULL )
+ iren = *iIt;
+
+ } // rof
+ if( iren == NULL )
+ return( Self::DialogResult_Cancel );
+
+ // Get bounding box
+ double bbox[ 6 ];
+ cpPlugins::Interface::Image* image =
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
+ bool input_found = false;
+ if( image != NULL )
+ {
+ image->GetVTK< vtkImageData >( )->GetBounds( bbox );
+ input_found = true;
+
+ } // fi
+ cpPlugins::Interface::Mesh* mesh =
+ this->GetInput< cpPlugins::Interface::Mesh >( "Input" );
+ if( mesh != NULL )
+ {
+ mesh->GetVTK< vtkPolyData >( )->GetBounds( bbox );
+ input_found = true;
+
+ } // fi
+ if( !input_found )
+ return( Self::DialogResult_Cancel );
+
+ // Create plane widget
+ if( this->m_PlaneWidget != NULL )
+ this->m_PlaneWidget->Delete( );
+ this->m_PlaneWidget = vtkPlaneWidget::New( );
+ this->m_PlaneWidget->NormalToXAxisOn( );
+ this->m_PlaneWidget->SetCenter(
+ ( bbox[ 1 ] + bbox[ 0 ] ) * double( 0.5 ),
+ ( bbox[ 3 ] + bbox[ 2 ] ) * double( 0.5 ),
+ ( bbox[ 5 ] + bbox[ 4 ] ) * double( 0.5 )
+ );
+ this->m_PlaneWidget->SetOrigin(
+ ( bbox[ 1 ] + bbox[ 0 ] ) * double( 0.5 ),
+ bbox[ 2 ],
+ bbox[ 4 ]
+ );
+ this->m_PlaneWidget->SetPoint1(
+ ( bbox[ 1 ] + bbox[ 0 ] ) * double( 0.5 ),
+ bbox[ 3 ],
+ bbox[ 4 ]
+ );
+ this->m_PlaneWidget->SetPoint2(
+ ( bbox[ 1 ] + bbox[ 0 ] ) * double( 0.5 ),
+ bbox[ 2 ],
+ bbox[ 5 ]
+ );
+ this->m_PlaneWidget->SetResolution( 15 );
+ this->m_PlaneWidget->SetRepresentationToWireframe( );
+ this->m_PlaneWidget->SetInteractor( iren );
+ this->m_PlaneWidget->PlaceWidget( );
+ this->m_PlaneWidget->On( );
+
+ return( Self::DialogResult_Modal );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::MacheteFilter::
+MacheteFilter( )
+ : Superclass( ),
+ m_PlaneWidget( NULL )
+{
+ this->_AddInput( "Input" );
+ this->_MakeOutput< cpPlugins::Interface::DataObject >( "Output" );
+
+ itk::Point< double, 3 > center;
+ itk::Vector< double, 3 > normal;
+
+ center.Fill( double( 0 ) );
+ normal.Fill( double( 0 ) );
+ normal[ 0 ] = double( 1 );
+
+ this->m_Parameters->ConfigureAsPoint( "PlaneCenter", 3, center );
+ this->m_Parameters->ConfigureAsVector( "PlaneNormal", 3, normal );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::MacheteFilter::
+~MacheteFilter( )
+{
+ if( this->m_PlaneWidget != NULL )
+ this->m_PlaneWidget->Delete( );
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::BasicFilters::MacheteFilter::
+_GenerateData( )
+{
+ cpPlugins::Interface::Image* image =
+ this->GetInput< cpPlugins::Interface::Image >( "Input" );
+ if( image != NULL )
+ return( this->_FromImage( image ) );
+ cpPlugins::Interface::Mesh* mesh =
+ this->GetInput< cpPlugins::Interface::Mesh >( "Input" );
+ if( mesh == NULL )
+ return( this->_FromMesh( mesh ) );
+ return( "MacheteFilter: No valid input." );
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::BasicFilters::MacheteFilter::
+_FromImage( cpPlugins::Interface::Image* image )
+{
+ itk::DataObject* itk_image = NULL;
+ std::string r = "";
+ cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _RealImage );
+ else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _RealImage );
+ else r = "MacheteFilter: Input image type not supported.";
+ return( r );
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::BasicFilters::MacheteFilter::
+_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;
+
+ 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( );
+}
+
+// eof - $RCSfile$
--- /dev/null
+#ifndef __CPPLUGINS__PLUGINS__MACHETEFILTER__H__
+#define __CPPLUGINS__PLUGINS__MACHETEFILTER__H__
+
+#include <cpPlugins/BasicFilters/cpPluginsBasicFilters_Export.h>
+#include <cpPlugins/Interface/BaseProcessObjects.h>
+
+// Some forward declarations
+class vtkPlaneWidget;
+
+namespace cpPlugins
+{
+ // Some forward declarations
+ namespace Interface
+ {
+ class Image;
+ class Mesh;
+
+ } // ecapseman
+
+ namespace BasicFilters
+ {
+ /**
+ */
+ class cpPluginsBasicFilters_EXPORT MacheteFilter
+ : public cpPlugins::Interface::FilterObject
+ {
+ public:
+ typedef MacheteFilter Self;
+ typedef cpPlugins::Interface::FilterObject Superclass;
+ typedef itk::SmartPointer< Self > Pointer;
+ typedef itk::SmartPointer< const Self > ConstPointer;
+
+ public:
+ itkNewMacro( Self );
+ itkTypeMacro( MacheteFilter, FilterObject );
+ cpPlugins_Id_Macro(
+ cpPlugins::BasicFilters::MacheteFilter, "FilterObject"
+ );
+
+ public:
+ virtual DialogResult ExecConfigurationDialog( QWidget* parent );
+
+ protected:
+ MacheteFilter( );
+ virtual ~MacheteFilter( );
+
+ virtual std::string _GenerateData( );
+
+ std::string _FromImage( cpPlugins::Interface::Image* image );
+ std::string _FromMesh( cpPlugins::Interface::Mesh* mesh );
+
+ template< class I >
+ inline std::string _RealImage( itk::DataObject* dobj );
+
+ private:
+ // Purposely not implemented
+ MacheteFilter( const Self& );
+ Self& operator=( const Self& );
+
+ protected:
+ vtkPlaneWidget* m_PlaneWidget;
+ };
+
+ // ---------------------------------------------------------------------
+ CPPLUGINS_INHERIT_PROVIDER( MacheteFilter );
+
+ } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__PLUGINS__MACHETEFILTER__H__
+
+// eof - $RCSfile$