Commit fbe714bf authored by Will Schroeder's avatar Will Schroeder
Browse files

ENH:Support for vtkSplineFilter: virtual Evaluate(), MakeObject(), and DeepCopy()

parent 64a5528a
......@@ -18,7 +18,7 @@
#include "vtkCardinalSpline.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkCardinalSpline, "1.16");
vtkCxxRevisionMacro(vtkCardinalSpline, "1.17");
vtkStandardNewMacro(vtkCardinalSpline);
// Construct a Cardinal Spline.
......@@ -26,6 +26,7 @@ vtkCardinalSpline::vtkCardinalSpline ()
{
}
// Evaluate a 1D Spline
float vtkCardinalSpline::Evaluate (float t)
{
......@@ -414,6 +415,19 @@ void vtkCardinalSpline::FitClosed1D (int size, float *x, float *y,
coefficients[N][3] = coefficients[0][3];
}
void vtkCardinalSpline::DeepCopy(vtkSpline *s)
{
vtkCardinalSpline *spline = vtkCardinalSpline::SafeDownCast(s);
if ( spline != NULL )
{
//nothing to do
}
// Now do superclass
this->vtkSpline::DeepCopy(s);
}
void vtkCardinalSpline::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
......
......@@ -39,22 +39,35 @@ public:
vtkTypeRevisionMacro(vtkCardinalSpline,vtkSpline);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Virtual constructor creates a spline of the same type as this one.
// Note that the created spline does not copy the data from this instance.
virtual vtkSpline *MakeObject()
{ return vtkCardinalSpline::New(); }
// Description
// Compute Cardinal Splines for each dependent variable
void Compute ();
// Description:
// Evaluate a 1D cardinal spline.
float Evaluate (float t);
virtual float Evaluate (float t);
// Description:
// Deep copy of cardinal spline data.
virtual void DeepCopy(vtkSpline *s);
protected:
vtkCardinalSpline();
~vtkCardinalSpline() {};
~vtkCardinalSpline() {}
void Fit1D (int n, float *x, float *y, float *w, float coefficients[][4],
int leftConstraint, float leftValue, int rightConstraint, float rightValue);
int leftConstraint, float leftValue, int rightConstraint,
float rightValue);
void FitClosed1D (int n, float *x, float *y, float *w,
float coefficients[][4]);
private:
vtkCardinalSpline(const vtkCardinalSpline&); // Not implemented.
void operator=(const vtkCardinalSpline&); // Not implemented.
......
......@@ -18,7 +18,7 @@
#include "vtkKochanekSpline.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkKochanekSpline, "1.18");
vtkCxxRevisionMacro(vtkKochanekSpline, "1.19");
vtkStandardNewMacro(vtkKochanekSpline);
// Construct a KochanekSpline wth the following defaults:
......@@ -194,10 +194,10 @@ void vtkKochanekSpline::Compute ()
// Compute the coefficients for a 1D spline
void vtkKochanekSpline::Fit1D (int size, float *x, float *y,
float tension, float bias, float continuity,
float coefficients[][4],
int leftConstraint, float leftValue,
int rightConstraint, float rightValue)
float tension, float bias, float continuity,
float coefficients[][4],
int leftConstraint, float leftValue,
int rightConstraint, float rightValue)
{
float cs; /* source chord */
float cd; /* destination chord */
......@@ -336,8 +336,8 @@ void vtkKochanekSpline::Fit1D (int size, float *x, float *y,
}//curve is open
// Compute the Coefficients
for (i=0; i < N; i++) {
for (i=0; i < N; i++)
{
//
// c0 = P ; c1 = DD ;
// i i i i
......@@ -355,7 +355,22 @@ void vtkKochanekSpline::Fit1D (int size, float *x, float *y,
+ (-2 * coefficients[i][1]) + (-1 * coefficients[i+1][2]);
coefficients[i][3] = ( 2 * y[i]) + (-2 * y[i+1])
+ ( 1 * coefficients[i][1]) + ( 1 * coefficients[i+1][2]);
}
}
}
void vtkKochanekSpline::DeepCopy(vtkSpline *s)
{
vtkKochanekSpline *spline = vtkKochanekSpline::SafeDownCast(s);
if ( spline != NULL )
{
this->DefaultBias = spline->DefaultBias;
this->DefaultTension = spline->DefaultTension;
this->DefaultContinuity = spline->DefaultContinuity;
}
// Now do superclass
this->vtkSpline::DeepCopy(s);
}
void vtkKochanekSpline::PrintSelf(ostream& os, vtkIndent indent)
......
......@@ -60,6 +60,12 @@ public:
// DefaultTension = 0, DefaultContinuity = 0.
static vtkKochanekSpline *New();
// Description:
// Virtual constructor creates a spline of the same type as this one.
// Note that the created spline does not copy the data from this instance.
virtual vtkSpline *MakeObject()
{ return vtkKochanekSpline::New(); }
// Description:
// Compute Kochanek Spline coefficients.
void Compute ();
......@@ -83,17 +89,22 @@ public:
vtkSetMacro(DefaultContinuity,float);
vtkGetMacro(DefaultContinuity,float);
// Description:
// Deep copy of cardinal spline data.
virtual void DeepCopy(vtkSpline *s);
protected:
vtkKochanekSpline();
~vtkKochanekSpline() {};
~vtkKochanekSpline() {}
void Fit1D (int n, float *x, float *y, float tension, float bias,
float continuity, float coefficients[][4], int leftConstraint,
float leftValue, int rightConstraint, float rightValue);
void Fit1D (int n, float *x, float *y,
float tension, float bias, float continuity,
float coefficients[][4],
int leftConstraint, float leftValue, int rightConstraint, float rightValue);
float DefaultBias;
float DefaultTension;
float DefaultContinuity;
private:
vtkKochanekSpline(const vtkKochanekSpline&); // Not implemented.
void operator=(const vtkKochanekSpline&); // Not implemented.
......
......@@ -17,7 +17,7 @@
=========================================================================*/
#include "vtkSpline.h"
vtkCxxRevisionMacro(vtkSpline, "1.16");
vtkCxxRevisionMacro(vtkSpline, "1.17");
// Construct a spline wth the folloing defaults:
// ClampValueOff
......@@ -69,6 +69,22 @@ void vtkSpline::RemoveAllPoints ()
this->PiecewiseFunction->RemoveAllPoints ();
}
void vtkSpline::DeepCopy(vtkSpline *s)
{
vtkSpline *spline = vtkSpline::SafeDownCast(s);
if ( spline != NULL )
{
this->ClampValue = s->ClampValue;
this->LeftConstraint = s->LeftConstraint;
this->LeftValue = s->LeftValue;
this->RightConstraint = s->RightConstraint;
this->RightValue = s->RightValue;
this->Closed = s->Closed;
this->PiecewiseFunction->DeepCopy(s->PiecewiseFunction);
}
}
// Overload standard modified time function. If data is modified,
// then this object is modified as well.
unsigned long vtkSpline::GetMTime()
......
......@@ -19,7 +19,7 @@
// .SECTION Description
// vtkSpline is used to create interpolated data points for specified
// data. vtkSpline is an abstract class: its subclasses vtkCardinalSpline
// and vtkKochenekSpline do the interpolation, The current implementation
// and vtkKochenekSpline do the interpolation. The current implementation
// of splines is limited to data dimensions not exceeding four.
//
// Typically a spline is used by adding a sequence of points followed by
......@@ -51,6 +51,11 @@ public:
vtkTypeRevisionMacro(vtkSpline,vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Virtual constructor creates a spline of the same type as this one.
// Note that the created spline does not copy the data from this instance.
virtual vtkSpline *MakeObject() = 0;
// Description:
// Set/Get ClampValue. If On, results of the interpolation will be
// clamped to the min/max of the input data.
......@@ -62,6 +67,10 @@ public:
// Compute the coefficients for the spline.
virtual void Compute () = 0;
// Description:
// Interpolate the value of the spline at parametric location of t.
virtual float Evaluate (float t) = 0;
// Description:
// Add a pair of points to be fit with the spline.
void AddPoint (float t, float x);
......@@ -107,6 +116,10 @@ public:
// Return the MTime also considering the Piecewise function.
unsigned long GetMTime();
// Description:
// Deep copy of spline data.
virtual void DeepCopy(vtkSpline *s);
protected:
vtkSpline();
~vtkSpline ();
......@@ -121,6 +134,7 @@ protected:
float RightValue;
vtkPiecewiseFunction *PiecewiseFunction;
int Closed;
private:
vtkSpline(const vtkSpline&); // Not implemented.
void operator=(const vtkSpline&); // Not implemented.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment