j3d.org Code

org.j3d.geom.spline
Class BSplineGenerator

java.lang.Object
  extended by org.j3d.geom.GeometryGenerator
      extended by org.j3d.geom.spline.BSplineGenerator

public class BSplineGenerator
extends GeometryGenerator

Geometry generator for generating a single B-Splinecurve.

BSpline curves of all orders are permitted.

The implementation of the algorithm is based on Paul Bourke's C code found at http://astronomy.swin.edu.au/~pbourke/curves/spline/.

Version:
$Revision: 1.8 $
Author:
Justin Couch

Field Summary
protected  float[] controlPointWeights
          The control point weightings on the patch.
protected  boolean useControlPointWeights
          Should we use control point weights.
 
Constructor Summary
BSplineGenerator()
          Construct a new generator of degree 3 with default number of segments.
BSplineGenerator(int t)
          Construct a new generator with the given degree but fixed number of segments.
BSplineGenerator(int t, int facets)
          Construct a new generator with the specified number of tessellations over the length of the curve, regardless of extents.
 
Method Summary
 void enableControlPointWeights(boolean state)
          Set the flag to say that calculations should be using the control point weights.
 void generate(GeometryData data)
          Generate a new set of geometry items patchd on the passed data.
 void generateSmoothKnots()
          Convenience method to set knots that give a better looking curve shape using the existing curve degree.
 void generateSmoothKnots(int t)
          Convenience method to set knots that give a better looking curve shape and set a new degree for the curve directly.
 int getDegree()
          Get the degree of the curve being generated.
 float[] getKnots()
          Return a copy of the knot values.
 int getVertexCount(GeometryData data)
          Get the number of vertices that this generator will create for the curve.
 boolean hasControlPointWeights()
          Get the current setting of the control point weight usage flag.
 void setControlPoints(double[] controlPoints)
          Set the curve controlPoints.
 void setControlPoints(double[] controlPoints, double[] weights)
          Set the curve controlPoints.
 void setControlPoints(double[] controlPoints, int numValid)
          Set the curve controlPoints from a subset of the given array.
 void setControlPoints(double[] controlPoints, int numValid, double[] weights)
          Set the curve controlPoints from a subset of the given array.
 void setControlPoints(float[] controlPoints)
          Set the curve controlPoints.
 void setControlPoints(float[] controlPoints, float[] weights)
          Set the curve controlPoints.
 void setControlPoints(float[] controlPoints, int numValid)
          Set the curve controlPoints from a subset of the given array.
 void setControlPoints(float[] controlPoints, int numValid, float[] weights)
          Set the curve controlPoints from a subset of the given array.
 void setFacetCount(int facets)
          Change the number of facets used to create this cone.
 void setKnots(int n, double[] knts)
          Set the curve degree and knots.
 void setKnots(int n, float[] knts)
          Set the curve degree and knots.
 void setWeights(double[] weights)
          Set the control point weights to use with the existing control points.
 void setWeights(double[] weights, int numValid)
          Set the control point weights to use with the existing control points.
 void setWeights(float[] weights)
          Set the control point weights to use with the existing control points.
 void setWeights(float[] weights, int numValid)
          Set the control point weights to use with the existing control points.
 double splineBlend(int i, int k, double t)
          Calculate the blending value, this is done recursively.
 
Methods inherited from class org.j3d.geom.GeometryGenerator
createFaceNormal, createFaceNormal, createRadialNormal, createRadialNormal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

controlPointWeights

protected float[] controlPointWeights
The control point weightings on the patch. This will be the same size as controlPointCoordinates.


useControlPointWeights

protected boolean useControlPointWeights
Should we use control point weights. Defaults to false.

Constructor Detail

BSplineGenerator

public BSplineGenerator()
Construct a new generator of degree 3 with default number of segments. The default number of segments is 16, regardless of the length of the line.


BSplineGenerator

public BSplineGenerator(int t)
Construct a new generator with the given degree but fixed number of segments.

Parameters:
t - The degree of the curve > 1
Throws:
java.lang.IllegalArgumentException - The degree < 2

BSplineGenerator

public BSplineGenerator(int t,
                        int facets)
Construct a new generator with the specified number of tessellations over the length of the curve, regardless of extents.

Parameters:
t - The degree of the curve > 1
facets - The number of facets on the side of the curve
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3 or degree < 2
Method Detail

enableControlPointWeights

public void enableControlPointWeights(boolean state)
Set the flag to say that calculations should be using the control point weights. Initially this starts as false, so if the user wants to create a rational surface then they should call this method with a value of true.

Parameters:
state - true if the weights should be used

hasControlPointWeights

public boolean hasControlPointWeights()
Get the current setting of the control point weight usage flag.

Returns:
true if the control point weights are in use

setFacetCount

public void setFacetCount(int facets)
Change the number of facets used to create this cone. This will cause the geometry to be regenerated next time they are asked for. The minimum number of facets is 3.

Parameters:
facets - The number of facets on the side of the cone
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3

setWeights

public void setWeights(float[] weights)
Set the control point weights to use with the existing control points. Will automatically turn on the use of control point weight calculations (rational form).

Parameters:
weights - Weight values to go with the points

setWeights

public void setWeights(double[] weights)
Set the control point weights to use with the existing control points. Will automatically turn on the use of control point weight calculations (rational form).

Parameters:
weights - Weight values to go with the points

setWeights

public void setWeights(float[] weights,
                       int numValid)
Set the control point weights to use with the existing control points. Will automatically turn on the use of control point weight calculations (rational form).

Parameters:
weights - Weight values to go with the points
numValid - The number of valid points in the array

setWeights

public void setWeights(double[] weights,
                       int numValid)
Set the control point weights to use with the existing control points. Will automatically turn on the use of control point weight calculations (rational form).

Parameters:
weights - Weight values to go with the points
numValid - The number of valid points in the array

setControlPoints

public void setControlPoints(float[] controlPoints)
Set the curve controlPoints. The array is presented with the coordinates flattened as [Xn, Yn, Zn] in the width array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values

setControlPoints

public void setControlPoints(double[] controlPoints)
Set the curve controlPoints. The array is presented with the coordinates flattened as [Xn, Yn, Zn] in the width array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values

setControlPoints

public void setControlPoints(float[] controlPoints,
                             float[] weights)
Set the curve controlPoints. The array is presented with the coordinates flattened as [Xn, Yn, Zn] in the width array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 an exception is generated.

Will automatically turn on the use of control point weight calculations (rational form).

Parameters:
controlPoints - The controlPoint coordinate values
weights - Weight values to go with the points

setControlPoints

public void setControlPoints(double[] controlPoints,
                             double[] weights)
Set the curve controlPoints. The array is presented with the coordinates flattened as [Xn, Yn, Zn] in the width array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 an exception is generated.

Will automatically turn on the use of control point weight calculations (rational form).

Parameters:
controlPoints - The controlPoint coordinate values
weights - Weight values to go with the points

setControlPoints

public void setControlPoints(float[] controlPoints,
                             int numValid)
Set the curve controlPoints from a subset of the given array. The array is presented with the coordinates flattened as [Xn, Yn, Zn] in the width array. The order of the patch is determined by the and number of points. If the arrays are not of minimum length 3 an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values
numValid - The number of valid points in the array

setControlPoints

public void setControlPoints(double[] controlPoints,
                             int numValid)
Set the curve controlPoints from a subset of the given array. The array is presented with the coordinates flattened as [Xn, Yn, Zn] in the width array. The order of the patch is determined by the and number of points. If the arrays are not of minimum length 3 an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values
numValid - The number of valid points in the array

setControlPoints

public void setControlPoints(float[] controlPoints,
                             int numValid,
                             float[] weights)
Set the curve controlPoints from a subset of the given array. The array is presented with the coordinates flattened as [Xn, Yn, Zn] in the width array. The order of the patch is determined by the and number of points. If the arrays are not of minimum length 3 an exception is generated.

Will automatically turn on the use of control point weight calculations (rational form).

Parameters:
controlPoints - The controlPoint coordinate values
numValid - The number of valid points in the array
weights - Weight values to go with the points

setControlPoints

public void setControlPoints(double[] controlPoints,
                             int numValid,
                             double[] weights)
Set the curve controlPoints from a subset of the given array. The array is presented with the coordinates flattened as [Xn, Yn, Zn] in the width array. The order of the patch is determined by the and number of points. If the arrays are not of minimum length 3 an exception is generated.

Will automatically turn on the use of control point weight calculations (rational form).

Parameters:
controlPoints - The controlPoint coordinate values
numValid - The number of valid points in the array
weights - Weight values to go with the points

setKnots

public void setKnots(int n,
                     float[] knts)
Set the curve degree and knots. The degree must be of order 2 or greater. If the array is not of minimum length 3 an exception is generated.

Parameters:
n - The degree of the curve
knts - The knot values to control the curve

setKnots

public void setKnots(int n,
                     double[] knts)
Set the curve degree and knots. The degree must be of order 2 or greater. If the array is not of minimum length 3 an exception is generated.

Parameters:
n - The degree of the curve
knts - The knot values to control the curve

getDegree

public int getDegree()
Get the degree of the curve being generated.

Returns:
A value >= 2

getKnots

public float[] getKnots()
Return a copy of the knot values.

Returns:
The knot values

generateSmoothKnots

public void generateSmoothKnots(int t)
Convenience method to set knots that give a better looking curve shape and set a new degree for the curve directly. The traditional way of setting these is to have knot[i] = i, but whenever curves change this results in a lot of extra calculations. This smoothing function will localize the changes at any particular breakpoint in the line.

Parameters:
t - The degree of the curve

generateSmoothKnots

public void generateSmoothKnots()
Convenience method to set knots that give a better looking curve shape using the existing curve degree. The traditional way of setting these is to have knot[i] = i, but whenever curves change this results in a lot of extra calculations. This smoothing function will localize the changes at any particular breakpoint in the line.


getVertexCount

public int getVertexCount(GeometryData data)
                   throws UnsupportedTypeException
Get the number of vertices that this generator will create for the curve. This is just the number of facets + 1.

Specified by:
getVertexCount in class GeometryGenerator
Parameters:
data - The data to base the calculations on
Returns:
The vertex count for the object
Throws:
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested

generate

public void generate(GeometryData data)
              throws UnsupportedTypeException,
                     InvalidArraySizeException
Generate a new set of geometry items patchd on the passed data. If the data does not contain the right minimum array lengths an exception will be generated. If the array reference is null, this will create arrays of the correct length and assign them to the return value.

Specified by:
generate in class GeometryGenerator
Parameters:
data - The data to patch the calculations on
Throws:
InvalidArraySizeException - The array is not big enough to contain the requested geometry
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested

splineBlend

public double splineBlend(int i,
                          int k,
                          double t)
Calculate the blending value, this is done recursively. If the numerator and denominator are 0 the expression is 0. If the deonimator is 0 the expression is 0.

Parameters:
i - The basis function to check
k - The order of the curve
t - The position along the curve to check ie N(t)

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org