]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Algorithms/BezierCurveFunction.h
First dump for version 0.1.0
[cpPlugins.git] / lib / cpExtensions / Algorithms / BezierCurveFunction.h
diff --git a/lib/cpExtensions/Algorithms/BezierCurveFunction.h b/lib/cpExtensions/Algorithms/BezierCurveFunction.h
new file mode 100644 (file)
index 0000000..2deba45
--- /dev/null
@@ -0,0 +1,76 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __CPEXTENSIONS__ALGORITHMS__BEZIERCURVEFUNCTION__H__
+#define __CPEXTENSIONS__ALGORITHMS__BEZIERCURVEFUNCTION__H__
+
+#include <vector>
+#include <itkFunctionBase.h>
+#include <itkMatrix.h>
+
+namespace cpExtensions
+{
+  namespace Algorithms
+  {
+    /**
+     * Uses the De Casteljau's algorithm.
+     */
+    template< class V >
+    class BezierCurveFunction
+      : public itk::FunctionBase< typename V::ValueType, V >
+    {
+    public:
+      typedef BezierCurveFunction                           Self;
+      typedef itk::FunctionBase< typename V::ValueType, V > Superclass;
+      typedef itk::SmartPointer< Self >                     Pointer;
+      typedef itk::SmartPointer< const Self >               ConstPointer;
+
+      typedef V                     TVector;
+      typedef typename V::ValueType TScalar;
+
+      typedef
+      itk::Matrix< TScalar, TVector::Dimension, TVector::Dimension >
+      TFrame;
+      typedef std::vector< TVector > TVectorsContainer;
+
+    public:
+      itkNewMacro( Self );
+      itkTypeMacro( BezierCurveFunction, itkFunctionBase );
+
+    public:
+      virtual void AddPoint( const TVector& v );
+      virtual unsigned int GetNumberOfPoints( ) const;
+
+      virtual TVector Evaluate( const TScalar& u ) const;
+      virtual TFrame EvaluateFrenetFrame( const TScalar& u ) const;
+      virtual TScalar EvaluateLength( ) const;
+
+    protected:
+      BezierCurveFunction( );
+      virtual ~BezierCurveFunction( ) { }
+
+      void _UpdateDerivative( ) const;
+
+    private:
+      // Purposely not implemented
+      BezierCurveFunction( const Self& other );
+      Self& operator=( const Self& other );
+
+    protected:
+      TVectorsContainer m_Vectors;
+      mutable Pointer   m_Derivative;
+      mutable bool      m_DerivativeUpdated;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include <cpExtensions/Algorithms/BezierCurveFunction.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __CPEXTENSIONS__ALGORITHMS__BEZIERCURVEFUNCTION__H__
+
+// eof - $RCSfile$