From: Leonardo Florez-Valencia Date: Mon, 10 Oct 2016 00:09:14 +0000 (-0500) Subject: PolyLine updated. X-Git-Tag: v0.1~91 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=211cd32b53b9739923f6c5135a704ce1852deca1;p=cpPlugins.git PolyLine updated. --- diff --git a/lib/Instances/CMakeLists.txt b/lib/Instances/CMakeLists.txt index bf7d665..455a407 100644 --- a/lib/Instances/CMakeLists.txt +++ b/lib/Instances/CMakeLists.txt @@ -7,7 +7,7 @@ SET(_all_instances) FOREACH(_instance ${_instances}) CompileInstances( _lib_name - ${PROJECT_BINARY_DIR}/lib + ${PROJECT_BINARY_DIR}/lib ${_instance} ${cpPlugins_NUMBER_OF_FILES} "" "${prj_VERSION}" "${prj_SHORT_VERSION}" ) diff --git a/lib/Instances/cpPlugins_Paths.i b/lib/Instances/cpPlugins_Paths.i index 2b8c8a8..7be53ab 100644 --- a/lib/Instances/cpPlugins_Paths.i +++ b/lib/Instances/cpPlugins_Paths.i @@ -7,6 +7,7 @@ ** ============== i cpPlugins_Images.h +t cpExtensions/Algorithms/BezierCurveFunction t cpExtensions/DataStructures/PolyLineParametricPath t itkPath t itkParametricPath @@ -21,6 +22,7 @@ t itkVectorContainer ** == Instances == ** =============== +c cpExtensions::Algorithms::BezierCurveFunction< itk::Vector< #reals#, #process?_dims# > > c itk::Path< double, itk::ContinuousIndex< double, #process_dims# >, #process_dims# > c itk::ParametricPath< #process_dims# > c itk::PolyLineParametricPath< #process_dims# > diff --git a/lib/cpBaseQtApplication/Block.cxx b/lib/cpBaseQtApplication/Block.cxx index 36b579f..5ee8f08 100644 --- a/lib/cpBaseQtApplication/Block.cxx +++ b/lib/cpBaseQtApplication/Block.cxx @@ -13,6 +13,7 @@ #include #include #include +#include // ------------------------------------------------------------------------- cpBaseQtApplication::Block:: @@ -296,14 +297,27 @@ contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ) QMenu menu; QAction* configureAction = menu.addAction( "Configure" ); QAction* updateAction = menu.addAction( "Update" ); - QAction* selectedAction = menu.exec( evt->screenPos( ) ); + auto widget = + dynamic_cast< cpPlugins::BaseObjects::Widget* >( + this->m_Filter.GetPointer( ) + ); + QAction* enableAction = NULL; + if( widget != NULL ) + enableAction = + menu.addAction( ( widget->GetEnabled( ) )? "Disable": "Enable" ); + QAction* selectedAction = menu.exec( evt->screenPos( ) ); if( selectedAction == configureAction ) { auto dlg = this->m_Filter->CreateQDialog( ); if( dlg != NULL ) dlg->exec( ); } + else if( selectedAction == enableAction ) + { + if( widget != NULL ) + widget->SetEnabled( !( widget->GetEnabled( ) ) ); + } else if( selectedAction == updateAction ) this->m_Editor->updateFilter( this->namePort( ).toStdString( ) ); } diff --git a/lib/cpExtensions/DataStructures/PolyLineParametricPath.h b/lib/cpExtensions/DataStructures/PolyLineParametricPath.h index e8046ea..3358d0f 100644 --- a/lib/cpExtensions/DataStructures/PolyLineParametricPath.h +++ b/lib/cpExtensions/DataStructures/PolyLineParametricPath.h @@ -3,6 +3,7 @@ #include #include +#include namespace cpExtensions { @@ -26,6 +27,9 @@ namespace cpExtensions typedef typename TImageBase::DirectionType TDirection; typedef typename Superclass::ContinuousIndexType TContinuousIndex; + typedef typename TPoint::VectorType TVector; + typedef cpExtensions::Algorithms::BezierCurveFunction< TVector > TBezier; + public: itkNewMacro( Self ); itkTypeMacro( PolyLineParametricPath, itk::PolyLineParametricPath ); @@ -38,9 +42,11 @@ namespace cpExtensions itkSetMacro( Origin, TPoint ); public: + void AddVertex( const TContinuousIndex& vertex ); unsigned long GetSize( ) const; TContinuousIndex GetVertex( unsigned long i ) const; TPoint GetPoint( unsigned long i ) const; + TPoint GetSmoothPoint( double u ) const; virtual void SetSpacing( const TSpacing& spac ); virtual void SetSpacing( const double spac[ _VDim ] ); @@ -69,6 +75,8 @@ namespace cpExtensions Self& operator=( const Self& other ); protected: + typename TBezier::Pointer m_Bezier; + TSpacing m_Spacing; TPoint m_Origin; TDirection m_Direction; diff --git a/lib/cpExtensions/DataStructures/PolyLineParametricPath.hxx b/lib/cpExtensions/DataStructures/PolyLineParametricPath.hxx index 306ab79..5e26816 100644 --- a/lib/cpExtensions/DataStructures/PolyLineParametricPath.hxx +++ b/lib/cpExtensions/DataStructures/PolyLineParametricPath.hxx @@ -4,6 +4,18 @@ #include #include +// ------------------------------------------------------------------------- +template< unsigned int _VDim > +void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >:: +AddVertex( const TContinuousIndex& vertex ) +{ + this->Superclass::AddVertex( vertex ); + this->m_Bezier->AddPoint( + this->GetPoint( this->GetSize( ) - 1 ).GetVectorFromOrigin( ) + ); + this->Modified( ); +} + // ------------------------------------------------------------------------- template< unsigned int _VDim > unsigned long cpExtensions::DataStructures::PolyLineParametricPath< _VDim >:: @@ -42,6 +54,18 @@ GetPoint( unsigned long i ) const return( pnt ); } +// ------------------------------------------------------------------------- +template< unsigned int _VDim > +typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >:: +TPoint cpExtensions::DataStructures::PolyLineParametricPath< _VDim >:: +GetSmoothPoint( double u ) const +{ + TPoint p; + p.Fill( 0 ); + p += this->m_Bezier->Evaluate( u ); + return( p ); +} + // ------------------------------------------------------------------------- template< unsigned int _VDim > void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >:: @@ -129,6 +153,8 @@ cpExtensions::DataStructures::PolyLineParametricPath< _VDim >:: PolyLineParametricPath( ) : Superclass( ) { + this->m_Bezier = TBezier::New( ); + this->m_Spacing.Fill( 1.0 ); this->m_Origin.Fill( 0.0 ); this->m_Direction.SetIdentity( ); diff --git a/lib/cpExtensions/Utility.h b/lib/cpExtensions/Utility.h index 2867786..b79f379 100644 --- a/lib/cpExtensions/Utility.h +++ b/lib/cpExtensions/Utility.h @@ -17,9 +17,9 @@ #endif // cpExtensions_OS_Windows // ------------------------------------------------------------------------- -#define cpExtensions_CHRONO \ - std::chrono::duration_cast< std::chrono::milliseconds >( \ - std::chrono::system_clock::now( ).time_since_epoch( ) \ +#define cpExtensions_CHRONO \ + std::chrono::duration_cast< std::chrono::milliseconds >( \ + std::chrono::system_clock::now( ).time_since_epoch( ) \ ).count( ) // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/BaseObjects/Widget.h b/lib/cpPlugins/BaseObjects/Widget.h index 1451b7b..83960e6 100644 --- a/lib/cpPlugins/BaseObjects/Widget.h +++ b/lib/cpPlugins/BaseObjects/Widget.h @@ -32,6 +32,7 @@ namespace cpPlugins virtual void EnabledOff( ); virtual void Clear( ) = 0; virtual void SetEnabled( bool v ) = 0; + virtual bool GetEnabled( ) const = 0; protected: Widget( ); diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx index 260172e..c114404 100644 --- a/lib/cpPlugins/Interface/Plugins.cxx +++ b/lib/cpPlugins/Interface/Plugins.cxx @@ -127,15 +127,15 @@ LoadEnvironments( ) { if( fname.substr( pos ) == ext ) { - std::regex re( lib ); -std::smatch match; -if( std::regex_search( fname, match, re ) && match.size( ) >= 1 ) - { - std::stringstream str; - str - << pth << cpPlugins_PATH_SEPARATOR << fname; - libs.insert( str.str( ) ); - } // fi + std::regex re( lib ); + std::smatch match; + if( std::regex_search( fname, match, re ) && match.size( ) >= 1 ) + { + std::stringstream str; + str + << pth << cpPlugins_PATH_SEPARATOR << fname; + libs.insert( str.str( ) ); + } // fi } // fi @@ -169,13 +169,13 @@ if( std::regex_search( fname, match, re ) && match.size( ) >= 1 ) if( lib != "" ) { if( this->m_Libraries.find( lib ) == this->m_Libraries.end( ) ) -{ - std::string error = ""; - void* hnd = cpPlugins::OS::DLLManager::Load( lib, error ); - if( hnd != NULL ) - this->m_Libraries[ lib ] = hnd; + { + std::string error = ""; + void* hnd = cpPlugins::OS::DLLManager::Load( lib, error ); + if( hnd != NULL ) + this->m_Libraries[ lib ] = hnd; -} // fi + } // fi } // fi @@ -191,16 +191,16 @@ LoadPaths( const std::string& dir ) if( !cpExtensions::IsPathSeparator( dir.back( ) ) ) fname << cpExtensions_PATH_SEPARATOR; fname << cpPlugins_PATHS; - std::string buffer; - if( cpExtensions::Read( buffer, fname.str( ) ) ) - { - std::istringstream input( buffer ); - for( std::string line; std::getline( input, line ); ) - envs << line << cpPlugins_ENV_SEPARATOR; + std::string buffer; + if( cpExtensions::Read( buffer, fname.str( ) ) ) + { + std::istringstream input( buffer ); + for( std::string line; std::getline( input, line ); ) + envs << line << cpPlugins_ENV_SEPARATOR; - } // fi - if( envs.str( ).size( ) > 0 ) - this->AddEnvironments( envs.str( ) ); + } // fi + if( envs.str( ).size( ) > 0 ) + this->AddEnvironments( envs.str( ) ); } // ------------------------------------------------------------------------- diff --git a/plugins/Widgets/LineWidget.cxx b/plugins/Widgets/LineWidget.cxx index 8887463..953aa4d 100644 --- a/plugins/Widgets/LineWidget.cxx +++ b/plugins/Widgets/LineWidget.cxx @@ -30,6 +30,20 @@ SetEnabled( bool v ) } // fi } +// ------------------------------------------------------------------------- +bool cpPluginsWidgets::LineWidget:: +GetEnabled( ) const +{ + auto wdg = this->GetVTK< const vtkLineWidget2 >( ); + if( wdg != NULL ) + { + vtkLineWidget2* w = const_cast< vtkLineWidget2* >( wdg ); + return( w->GetEnabled( ) != 0 ); + } + else + return( false ); +} + // ------------------------------------------------------------------------- cpPluginsWidgets::LineWidget:: LineWidget( ) diff --git a/plugins/Widgets/LineWidget.h b/plugins/Widgets/LineWidget.h index 281cacd..bd65e84 100644 --- a/plugins/Widgets/LineWidget.h +++ b/plugins/Widgets/LineWidget.h @@ -22,6 +22,7 @@ namespace cpPluginsWidgets public: virtual void Clear( ) cpPlugins_OVERRIDE; virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE; + virtual bool GetEnabled( ) const cpPlugins_OVERRIDE; protected: typedef std::set< vtkProp* > TProps; diff --git a/plugins/Widgets/SeedWidget.cxx b/plugins/Widgets/SeedWidget.cxx index f0c9094..fe19381 100644 --- a/plugins/Widgets/SeedWidget.cxx +++ b/plugins/Widgets/SeedWidget.cxx @@ -36,6 +36,20 @@ SetEnabled( bool v ) } // rof } +// ------------------------------------------------------------------------- +bool cpPluginsWidgets::SeedWidget:: +GetEnabled( ) const +{ + if( this->m_Widgets.size( ) > 0 ) + { + auto i = this->m_Widgets.begin( ); + TWidget* w = const_cast< TWidget* >( i->second.GetPointer( ) ); + return( w->GetEnabled( ) != 0 ); + } + else + return( false ); +} + // ------------------------------------------------------------------------- cpPluginsWidgets::SeedWidget:: SeedWidget( ) diff --git a/plugins/Widgets/SeedWidget.h b/plugins/Widgets/SeedWidget.h index 7449b94..945ee03 100644 --- a/plugins/Widgets/SeedWidget.h +++ b/plugins/Widgets/SeedWidget.h @@ -41,6 +41,7 @@ namespace cpPluginsWidgets public: virtual void Clear( ) cpPlugins_OVERRIDE; virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE; + virtual bool GetEnabled( ) const cpPlugins_OVERRIDE; protected: /** diff --git a/plugins/Widgets/SplineWidget.cxx b/plugins/Widgets/SplineWidget.cxx index 057d4e7..a1b1538 100644 --- a/plugins/Widgets/SplineWidget.cxx +++ b/plugins/Widgets/SplineWidget.cxx @@ -26,6 +26,20 @@ SetEnabled( bool v ) } // fi } +// ------------------------------------------------------------------------- +bool cpPluginsWidgets::SplineWidget:: +GetEnabled( ) const +{ + auto wdg = this->GetVTK< const vtkSplineWidget >( ); + if( wdg != NULL ) + { + vtkSplineWidget* w = const_cast< vtkSplineWidget* >( wdg ); + return( w->GetEnabled( ) != 0 ); + } + else + return( false ); +} + // ------------------------------------------------------------------------- cpPluginsWidgets::SplineWidget:: SplineWidget( ) diff --git a/plugins/Widgets/SplineWidget.h b/plugins/Widgets/SplineWidget.h index 7eaeccd..d89ccb7 100644 --- a/plugins/Widgets/SplineWidget.h +++ b/plugins/Widgets/SplineWidget.h @@ -32,6 +32,7 @@ namespace cpPluginsWidgets public: virtual void Clear( ) cpPlugins_OVERRIDE; virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE; + virtual bool GetEnabled( ) const cpPlugins_OVERRIDE; protected: bool m_Configured;