Index: trunk/src/lib/math/curve.cc
===================================================================
--- trunk/src/lib/math/curve.cc	(revision 10314)
+++ trunk/src/lib/math/curve.cc	(revision 10368)
@@ -142,4 +142,19 @@
     tmpNode = tmpNode->next;
   return tmpNode->position;
+}
+
+/**
+ * This function returns an approximation of the length of the curve
+ *
+*/
+float Curve::getLength()
+{
+      float length = 0;
+      PathNode* tmpNode = this->firstNode;
+      for(int i = 1; i < this->nodeCount; i++)
+      {
+              length += Vector(tmpNode->next->position - tmpNode->position).len();
+      }
+      return length;
 }
 
@@ -273,5 +288,6 @@
 Vector BezierCurve::calcDir (float t)
 {
-  return this->dirCurve->calcPos(t);
+  return this->calcPos(t + 0.01) - this->calcPos(t);
+  //return this->dirCurve->calcPos(t);
 }
 
Index: trunk/src/lib/math/curve.h
===================================================================
--- trunk/src/lib/math/curve.h	(revision 10314)
+++ trunk/src/lib/math/curve.h	(revision 10368)
@@ -47,4 +47,5 @@
   /** @returns the directional Curve */
   Curve* getDirCurve() const { return this->dirCurve; };
+  float getLength();
 
   /** @param t the value on the curve [0-1] @returns Vector to the position */
Index: trunk/src/lib/math/spline.cc
===================================================================
--- trunk/src/lib/math/spline.cc	(revision 10368)
+++ trunk/src/lib/math/spline.cc	(revision 10368)
@@ -0,0 +1,186 @@
+/*=========================================================================
+
+  Program:   Visualization Toolkit
+  Module:    $RCSfile: Spline.cxx,v $
+
+  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
+  All rights reserved.
+  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notice for more information.
+
+=========================================================================*/
+#include "spline.h"
+
+
+//----------------------------------------------------------------------------
+// Construct a spline wth the folloing defaults:
+// ClampValueOff
+Spline::Spline ()
+{
+  this->ComputeTime = 0;
+  this->ClampValue = 0;
+  this->PiecewiseFunction = vtkPiecewiseFunction::New();
+  this->Intervals = NULL;
+  this->Coefficients = NULL;
+  this->LeftConstraint = 1;
+  this->LeftValue = 0.0;
+  this->RightConstraint = 1;
+  this->RightValue = 0.0;
+  this->Closed = 0;
+
+  this->ParametricRange[0] = -1;
+  this->ParametricRange[1] = -1;
+}
+
+//----------------------------------------------------------------------------
+Spline::~Spline ()
+{
+  this->PiecewiseFunction->Delete();
+  if (this->Coefficients)
+  {
+    delete [] this->Coefficients;
+  }
+  if (this->Intervals)
+  {
+    delete [] this->Intervals;
+  }
+}
+
+//----------------------------------------------------------------------------
+void Spline::SetParametricRange(double tMin, double tMax)
+{
+  if ( tMin != this->ParametricRange[0] || tMax != this->ParametricRange[1] )
+  {
+    if ( tMin >= tMax )
+    {
+      tMax = tMin + 1;
+    }
+
+    this->ParametricRange[0] = tMin;
+    this->ParametricRange[1] = tMax;
+
+    this->Modified();
+  }
+}
+
+//----------------------------------------------------------------------------
+void Spline::GetParametricRange(double tRange[2]) const
+{
+  if ( this->ParametricRange[0] != this->ParametricRange[1] )
+  {
+    tRange[0] = this->ParametricRange[0];
+    tRange[1] = this->ParametricRange[1];
+  }
+  else
+  {
+    tRange[0] = this->PiecewiseFunction->GetRange()[0];
+    tRange[1] = this->PiecewiseFunction->GetRange()[1];
+  }
+}
+
+//----------------------------------------------------------------------------
+double Spline::ComputeLeftDerivative()
+{
+  double *dptr = this->PiecewiseFunction->GetDataPointer();
+  int size = this->PiecewiseFunction->GetSize();
+  if ( dptr == NULL || size < 2 )
+  {
+    return 0.0;
+  }
+  else
+  {
+    return (dptr[2]-dptr[0]);
+  }
+}
+
+//----------------------------------------------------------------------------
+double Spline::ComputeRightDerivative()
+{
+  double *dptr = this->PiecewiseFunction->GetDataPointer();
+  int size = this->PiecewiseFunction->GetSize();
+  if ( dptr == NULL || size < 2 )
+  {
+    return 0.0;
+  }
+  else
+  {
+    return (dptr[(size-1)*2]-dptr[(size-2)*2]);
+  }
+}
+
+//----------------------------------------------------------------------------
+int Spline::GetNumberOfPoints()
+{
+  return this->PiecewiseFunction->GetSize();
+}
+
+
+//----------------------------------------------------------------------------
+// Add a point to the Piecewise Functions containing the data
+void Spline::AddPoint (double t, double x)
+{
+  if ( this->ParametricRange[0] != this->ParametricRange[1] )
+  {
+    t = (t < this->ParametricRange[0] ? this->ParametricRange[0] :
+         (t > this->ParametricRange[1] ? this->ParametricRange[1] : t));
+  }
+  this->PiecewiseFunction->AddPoint (t, x);
+}
+
+//----------------------------------------------------------------------------
+// Remove a point from the Piecewise Functions.
+void Spline::RemovePoint (double t)
+{
+  if ( this->ParametricRange[0] != this->ParametricRange[1] )
+  {
+    t = (t < this->ParametricRange[0] ? this->ParametricRange[0] :
+         (t > this->ParametricRange[1] ? this->ParametricRange[1] : t));
+  }
+  this->PiecewiseFunction->RemovePoint (t);
+}
+
+//----------------------------------------------------------------------------
+// Remove all points from the Piecewise Functions.
+void Spline::RemoveAllPoints ()
+{
+  this->PiecewiseFunction->RemoveAllPoints ();
+}
+
+
+
+
+
+//----------------------------------------------------------------------------
+int Spline::FindIndex(int size, double t)
+{
+  int index=0;
+  if ( size > 2 ) //bisection method for speed
+  {
+    int rightIdx = size - 1;
+    int centerIdx = rightIdx - size/2;
+    for (int converged=0; !converged; )
+    {
+      if ( this->Intervals[index] <= t && t <= this->Intervals[centerIdx] )
+      {
+        rightIdx = centerIdx;
+      }
+      else //if ( this->Intervals[centerIdx] < t && t <= this->Intervals[rightIdx] )
+      {
+        index = centerIdx;
+      }
+      if ( (index + 1) == rightIdx )
+      {
+        converged = 1;
+      }
+      else
+      {
+        centerIdx = index + (rightIdx-index)/2;
+      }
+    }//while not converged
+  }
+  return index;
+}
+
Index: trunk/src/lib/math/spline.h
===================================================================
--- trunk/src/lib/math/spline.h	(revision 10368)
+++ trunk/src/lib/math/spline.h	(revision 10368)
@@ -0,0 +1,102 @@
+
+#ifndef __Spline_h
+#define __Spline_h
+
+#include "vtkObject.h"
+
+class Spline
+{
+public:
+
+  // Description:
+  // Set/Get the parametric range. If not set, the range is determined
+  // implicitly by keeping track of the (min,max) parameter values for
+  // t. If set, the AddPoint() method will clamp the t value to lie
+  // within the specified range.
+  void SetParametricRange(double tMin, double tMax);
+  void SetParametricRange(double tRange[2])
+    {this->SetParametricRange(tRange[0],tRange[1]);}
+  void GetParametricRange(double tRange[2]) const;
+
+
+  // Description:
+  // Compute the coefficients for the spline.
+  virtual void Compute () = 0;
+
+  // Description:
+  // Interpolate the value of the spline at parametric location of t.
+  virtual double Evaluate (double t) = 0;
+
+  // Description:
+  // Return the number of points inserted thus far.
+  int GetNumberOfPoints();
+
+  // Description:
+  // Add a pair of points to be fit with the spline.
+  void AddPoint (double t, double x);
+
+  // Description:
+  // Remove a point from the data to be fit with the spline.
+  void RemovePoint (double t);
+
+  // Description:
+  // Remove all points from the data.
+  void RemoveAllPoints ();
+
+
+
+protected:
+  Spline();
+  ~Spline();
+
+  unsigned long ComputeTime;
+  // Description:
+  // Set/Get ClampValue. If On, results of the interpolation will be
+  // clamped to the min/max of the input data.
+  int ClampValue;
+  double *Intervals;
+  double *Coefficients;
+  int LeftConstraint;
+  // Description:
+  // The values of the derivative on the left and right sides. The value
+  // is used only if the left(right) constraint is type 1-3.
+  double LeftValue;
+  // Description:
+  // Set the type of constraint of the left(right) end points. Four
+  // constraints are available:
+  //
+  // 0: the first derivative at left(right) most point is determined
+  // from the line defined from the first(last) two points.
+  //
+  // 1: the first derivative at left(right) most point is set to
+  // Left(Right)Value.
+  //
+  // 2: the second derivative at left(right) most point is set to
+  // Left(Right)Value.
+  //
+  // 3: the second derivative at left(right)most points is Left(Right)Value
+  // times second derivative at first interior point.
+  int RightConstraint;
+  double RightValue;
+  vtkPiecewiseFunction *PiecewiseFunction;
+  // Description:
+  // Control whether the spline is open or closed. A closed spline forms
+  // a continuous loop: the first and last points are the same, and
+  // derivatives are continuous.
+
+  int Closed;
+
+  // Explicitly specify the parametric range.
+  double ParametricRange[2];
+
+  // Helper methods
+  double ComputeLeftDerivative();
+  double ComputeRightDerivative();
+  int FindIndex(int size, double t);
+
+private:
+  Spline(const Spline&);  // Not implemented.
+  void operator=(const Spline&);  // Not implemented.
+};
+
+#endif
