com.graphbuilder.curve
Class BSpline

java.lang.Object
  extended bycom.graphbuilder.curve.Curve
      extended bycom.graphbuilder.curve.ParametricCurve
          extended bycom.graphbuilder.curve.BSpline
Direct Known Subclasses:
NURBSpline

public class BSpline
extends ParametricCurve

General non-rational B-Spline implementation where the degree can be specified.

For the B-Spline, there are 3 types of knot-vectors, uniform clamped, uniform unclamped, and non-uniform. A uniform knot-vector means that the knots are equally spaced. A clamped knot-vector means that the first k-knots and last k-knots are repeated, where k is the degree + 1. Non-uniform means that the knot-values have no specific properties. For all 3 types, the knot-values must be non-decreasing.

Here are some examples of uniform clamped knot vectors for degree 3:

number of control points = 4: [0, 0, 0, 0, 1, 1, 1, 1]
number of control points = 7: [0, 0, 0, 0, 0.25, 0.5, 0.75, 1, 1, 1, 1]

The following is a figure of a B-Spline generated using a uniform clamped knot vector:

Here are some examples of uniform unclamped knot vectors for degree 3:

number of control points = 4: [0, 0.14, 0.29, 0.43, 0.57, 0.71, 0.86, 1] (about)
number of control points = 7: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]

The following is a figure of a B-Spline generated using a uniform unclamped knot vector:

Note: Although the knot-values in the examples are between 0 and 1, this is not a requirement.

When the knot-vector is uniform clamped, the default interval is [0, 1]. When the knot-vector is uniform unclamped, the default interval is [grad * degree, 1 - grad * degree], where grad is the gradient or the knot-span. Specifying the knotVectorType as UNIFORM_CLAMPED or UNIFORM_UNCLAMPED means that the internal knot-vector will not be used.

Note: The computation required is O(2^degree) or exponential. Increasing the degree by 1 means that twice as many computations are done.


Field Summary
static int NON_UNIFORM
           
static int UNIFORM_CLAMPED
           
static int UNIFORM_UNCLAMPED
           
 
Fields inherited from class com.graphbuilder.curve.Curve
connect, cp, gi
 
Constructor Summary
BSpline(ControlPath cp, GroupIterator gi)
           
 
Method Summary
 void appendTo(MultiPath mp)
          There are two types of requirements for this curve, common requirements and requirements that depend on the knotVectorType.
protected  void eval(double[] p)
          The eval method evaluates a point on a curve given a parametric value "t".
 int getDegree()
          Returns the degree of the curve.
 ValueVector getKnotVector()
          Returns the knot-vector for this curve.
 int getKnotVectorType()
          Returns the type of knot-vector to use.
 int getSampleLimit()
          The sample limit specifies how many additional subdivisions are done to ensure that there are no missed pieces of the curve.
 boolean getUseDefaultInterval()
          Returns the value of the useDefaultInterval flag.
protected  double N(double t, int i)
          Non-recursive implementation of the N-function.
 void resetMemory()
          Resets the shared memory to the initial state.
 void setDegree(int d)
          Sets the degree of the curve.
 void setInterval(double t_min, double t_max)
          Specifies the interval that the curve should define itself on.
 void setKnotVector(ValueVector v)
          Sets the knot-vector for this curve.
 void setKnotVectorType(int type)
          Sets the type of knot-vector to use.
 void setSampleLimit(int limit)
          Sets the sample-limit.
 void setUseDefaultInterval(boolean b)
          Sets the value of the useDefaultInterval flag.
 double t_max()
          Returns the finishing interval value.
 double t_min()
          Returns the starting interval value.
 
Methods inherited from class com.graphbuilder.curve.Curve
getConnect, getControlPath, getGroupIterator, setConnect, setControlPath, setGroupIterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIFORM_CLAMPED

public static final int UNIFORM_CLAMPED
See Also:
Constant Field Values

UNIFORM_UNCLAMPED

public static final int UNIFORM_UNCLAMPED
See Also:
Constant Field Values

NON_UNIFORM

public static final int NON_UNIFORM
See Also:
Constant Field Values
Constructor Detail

BSpline

public BSpline(ControlPath cp,
               GroupIterator gi)
Method Detail

eval

protected void eval(double[] p)
Description copied from class: ParametricCurve
The eval method evaluates a point on a curve given a parametric value "t". The parametric value "t" is stored in the last index location of the specified double array. This value should not be changed. The dimension of the point to evaluate is p.length - 1. The result of the evaluation is placed in index locations 0 .. p.length - 2 (inclusive). The eval method should remain protected except for those curves that do no need any preparation to be done in the appendTo method.

Specified by:
eval in class ParametricCurve

setInterval

public void setInterval(double t_min,
                        double t_max)
Specifies the interval that the curve should define itself on. The default interval is [0.0, 1.0]. When the knot-vector type is one of UNIFORM_CLAMPED or UNIFORM_UNCLAMPED and the useDefaultInterval flag is true, then these values will not be used.

Throws:
java.lang.IllegalArgumentException - If t_min > t_max.
See Also:
t_min(), t_max()

t_min

public double t_min()
Returns the starting interval value.

See Also:
setInterval(double, double), t_max()

t_max

public double t_max()
Returns the finishing interval value.

See Also:
setInterval(double, double), t_min()

getSampleLimit

public int getSampleLimit()
Description copied from class: ParametricCurve
The sample limit specifies how many additional subdivisions are done to ensure that there are no missed pieces of the curve. The sample limit must be >= 0.

Specified by:
getSampleLimit in class ParametricCurve

setSampleLimit

public void setSampleLimit(int limit)
Sets the sample-limit. For more information on the sample-limit, see the BinaryCurveApproximationAlgorithm class. The default sample-limit is 1.

Throws:
java.lang.IllegalArgumentException - If sample-limit < 0.
See Also:
BinaryCurveApproximationAlgorithm, getSampleLimit()

getDegree

public int getDegree()
Returns the degree of the curve.

See Also:
setDegree(int)

setDegree

public void setDegree(int d)
Sets the degree of the curve. The degree specifies how many controls points have influence when computing a single point on the curve. Specifically, degree + 1 control points are used. The degree must be greater than 0. A degree of 1 is linear, 2 is quadratic, 3 is cubic, etc. Warning: Increasing the degree by 1 doubles the number of computations required. The default degree is 3 (cubic).

Throws:
java.lang.IllegalArgumentException - If degree <= 0.
See Also:
getDegree()

getKnotVector

public ValueVector getKnotVector()
Returns the knot-vector for this curve.

See Also:
setKnotVector(ValueVector)

setKnotVector

public void setKnotVector(ValueVector v)
Sets the knot-vector for this curve. When the knot-vector type is one of UNIFORM_CLAMPED or UNIFORM_UNCLAMPED then the values in the knot-vector will not be used.

Throws:
java.lang.IllegalArgumentException - If the value-vector is null.
See Also:
getKnotVector()

getUseDefaultInterval

public boolean getUseDefaultInterval()
Returns the value of the useDefaultInterval flag.

See Also:
setUseDefaultInterval(boolean)

setUseDefaultInterval

public void setUseDefaultInterval(boolean b)
Sets the value of the useDefaultInterval flag. When the knot-vector type is one of UNIFORM_CLAMPED or UNIFORM_UNCLAMPED and the useDefaultInterval flag is true, then default values will be computed for t_min and t_max. Otherwise t_min and t_max are used as the interval.

See Also:
getUseDefaultInterval()

getKnotVectorType

public int getKnotVectorType()
Returns the type of knot-vector to use.

See Also:
setKnotVectorType(int)

setKnotVectorType

public void setKnotVectorType(int type)
Sets the type of knot-vector to use. There are 3 types, UNIFORM_CLAMPED, UNIFORM_UNCLAMPED and NON_UNIFORM. NON_UNIFORM can be thought of as user specified. UNIFORM_CLAMPED and UNIFORM_UNCLAMPED are standard knot-vectors for the B-Spline.

Throws:
java.lang.IllegalArgumentException - If the knot-vector type is unknown.
See Also:
getKnotVectorType()

appendTo

public void appendTo(MultiPath mp)
There are two types of requirements for this curve, common requirements and requirements that depend on the knotVectorType. The common requirements are that the group-iterator must be in range and the number of points (group size) must be greater than the degree. If the knot-vector type is NON_UNIFORM (user specified) then there are additional requirements, otherwise there are no additional requirements. The additional requirements when the knotVectorType is NON_UNIFORM are that the internal-knot vector must have an exact size of degree + numPts + 1, where degree is specified by the setDegree method and numPts is the group size. Also, the knot-vector values must be non-decreasing. If any of these requirements are not met, then this method returns quietly.

Specified by:
appendTo in class Curve
See Also:
MultiPath, BinaryCurveApproximationAlgorithm

N

protected double N(double t,
                   int i)
Non-recursive implementation of the N-function.


resetMemory

public void resetMemory()
Description copied from class: Curve
Resets the shared memory to the initial state.

Overrides:
resetMemory in class Curve