]> Creatis software - cpPlugins.git/commitdiff
PolyLine updated.
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 10 Oct 2016 00:09:14 +0000 (19:09 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 10 Oct 2016 00:09:14 +0000 (19:09 -0500)
14 files changed:
lib/Instances/CMakeLists.txt
lib/Instances/cpPlugins_Paths.i
lib/cpBaseQtApplication/Block.cxx
lib/cpExtensions/DataStructures/PolyLineParametricPath.h
lib/cpExtensions/DataStructures/PolyLineParametricPath.hxx
lib/cpExtensions/Utility.h
lib/cpPlugins/BaseObjects/Widget.h
lib/cpPlugins/Interface/Plugins.cxx
plugins/Widgets/LineWidget.cxx
plugins/Widgets/LineWidget.h
plugins/Widgets/SeedWidget.cxx
plugins/Widgets/SeedWidget.h
plugins/Widgets/SplineWidget.cxx
plugins/Widgets/SplineWidget.h

index bf7d665..455a407 100644 (file)
@@ -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}"
     )
index 2b8c8a8..7be53ab 100644 (file)
@@ -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# >
index 36b579f..5ee8f08 100644 (file)
@@ -13,6 +13,7 @@
 #include <cpBaseQtApplication/Port.h>\r
 #include <cpBaseQtApplication/Connection.h>\r
 #include <cpBaseQtApplication/Editor.h>\r
+#include <cpPlugins/BaseObjects/Widget.h>\r
 \r
 // -------------------------------------------------------------------------\r
 cpBaseQtApplication::Block::\r
@@ -296,14 +297,27 @@ contextMenuEvent( QGraphicsSceneContextMenuEvent* evt )
   QMenu menu;\r
   QAction* configureAction = menu.addAction( "Configure" );\r
   QAction* updateAction = menu.addAction( "Update" );\r
-  QAction* selectedAction = menu.exec( evt->screenPos( ) );\r
+  auto widget =\r
+    dynamic_cast< cpPlugins::BaseObjects::Widget* >(\r
+      this->m_Filter.GetPointer( )\r
+      );\r
+  QAction* enableAction = NULL;\r
+  if( widget != NULL )\r
+    enableAction =\r
+      menu.addAction( ( widget->GetEnabled( ) )? "Disable": "Enable" );\r
 \r
+  QAction* selectedAction = menu.exec( evt->screenPos( ) );\r
   if( selectedAction == configureAction )\r
   {\r
     auto dlg = this->m_Filter->CreateQDialog( );\r
     if( dlg != NULL )\r
       dlg->exec( );\r
   }\r
+  else if( selectedAction == enableAction )\r
+  {\r
+    if( widget != NULL )\r
+      widget->SetEnabled( !( widget->GetEnabled( ) ) );\r
+  }\r
   else if( selectedAction == updateAction )\r
     this->m_Editor->updateFilter( this->namePort( ).toStdString( ) );\r
 }\r
index e8046ea..3358d0f 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <itkPolyLineParametricPath.h>
 #include <itkImageBase.h>
+#include <cpExtensions/Algorithms/BezierCurveFunction.h>
 
 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;
index 306ab79..5e26816 100644 (file)
@@ -4,6 +4,18 @@
 #include <itkMath.h>
 #include <itkNumericTraits.h>
 
+// -------------------------------------------------------------------------
+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( );
index 2867786..b79f379 100644 (file)
@@ -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( )
 
 // -------------------------------------------------------------------------
index 1451b7b..83960e6 100644 (file)
@@ -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( );
index 260172e..c114404 100644 (file)
@@ -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( ) );
 }
 
 // -------------------------------------------------------------------------
index 8887463..953aa4d 100644 (file)
@@ -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( )
index 281cacd..bd65e84 100644 (file)
@@ -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;
index f0c9094..fe19381 100644 (file)
@@ -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( )
index 7449b94..945ee03 100644 (file)
@@ -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:
     /**
index 057d4e7..a1b1538 100644 (file)
@@ -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( )
index 7eaeccd..d89ccb7 100644 (file)
@@ -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;