maspack.geometry
Class NURBSCurveBase

java.lang.Object
  extended by maspack.geometry.NURBSObject
      extended by maspack.geometry.NURBSCurveBase
All Implemented Interfaces:
GLRenderable, GLSelectable, HasRenderProps, Renderable
Direct Known Subclasses:
NURBSCurve2d, NURBSCurve3d

public abstract class NURBSCurveBase
extends NURBSObject

Base class for 2 and 3 dimensional NURBS curves


Field Summary
static int CLOSED
          Specifies a closed curve.
static boolean init
           
static int OPEN
          Specifies an open curve.
 
Fields inherited from interface maspack.render.GLRenderable
TRANSLUCENT, TWO_DIMENSIONAL
 
Constructor Summary
NURBSCurveBase()
           
 
Method Summary
 void addControlPoint(Vector4d pnt, double h)
          Add an additional control point and knot to the end of this curve.
 double computeControlPolygonLength()
           
 void convertToBezier()
           
 RenderProps createRenderProps()
          Factory method to create render properties appropriate to this object.
static double[] createUniformKnots(int numi, int d, boolean open)
          Creates an array of evenly spaced knots.
abstract  void eval(Point3d pnt, double u)
          Evaluates the point on this curve for parameter u.
 int getDegree()
          Returns the degree of this curve.
 double getKnot(int i)
          Returns the i-th knot used by this curve.
 int getKnotIndex(double u)
          Gets the lower knot point index for the knot interval which contains the parameter value u.
 double[] getKnots()
          Returns the knots used by this curve.
 void getRange(double[] uStartEnd)
          Gets the range of the curve parameter u.
 int getResolution()
          Returns the resolution used for rendering this curve.
 int getType()
           
 void insertKnot(int k, double uval)
           
 boolean isBezier()
          Returns true if this curve represents a piecewise bezier curve.
 boolean isBSpline()
          Returns true if this curve represents a B-spline (i.e., if all control points have unity weights).
 boolean isClosed()
          Returns true if this curve is closed.
 int numKnots()
          Returns the number of knots used by this curve.
 void read(java.io.Reader reader)
          Reads this curve from a text description supplied by a reader.
 void read(ReaderTokenizer rtok)
          Reads this curve in from a ReaderTokenizer, using the same format as read(Reader).
 void removeControlPoint()
          Remove the control point at the end of this curve.
 void render(GLRenderer renderer, RenderProps props, int flags)
          
 void reset(int d, int type, double[] knots)
          Resets the degrees, type, and knots of this curve.
 void set(int d, int type, Vector4d[] ctrlPnts, double[] knots)
          Sets this NURBS curve to either an open or closed curve with a specified degree, knots, and control points.
 void set(int d, Vector4d[] ctrlPnts, double[] knots)
          Sets this NURBS curve to an open curve with a specified degree, knot points, and control points.
 void set(WavefrontReader.Curve curve, Vector4d[] allPnts)
           
 void setBezier(int d, Vector4d[] ctrlPnts)
          Sets this curve to a piecewise Bezier curve with a prescribed degree and set of control points.
 void setCircle(double x, double y, double radius)
          Sets this curve to an eight-point circle formed using rational cubics.
 void setRange(double ustart, double uend)
          Sets the range of the curve parameter u.
 void setResolution(int res)
          Sets the resolution used for rendering this curve.
 void setUniformCubic(int type, Vector4d[] ctrlPnts)
          Sets this NURBS curve to a curve of third degree with uniform unity knot spacing and a specified number of control points.
 void write(java.io.PrintWriter pw, NumberFormat fmt, boolean relative)
           
 void write(java.io.PrintWriter pw, java.lang.String fmtStr, boolean relative)
          Writes a text description of this NURBS object to a PrintWriter, using a subset of the Wavefront OBJ format as described in the documentation for the read method for this object.
 
Methods inherited from class maspack.geometry.NURBSObject
controlPointIsSelected, getControlPoint, getControlPoints, getDrawControlShape, getLineWidth, getObjToWorld, getObjToWorld, getPointSize, getRenderHints, getRenderProps, getSelection, isSelectable, numControlPoints, numSelectionQueriesNeeded, prerender, render, selectControlPoint, setDrawControlShape, setLineWidth, setObjToWorld, setPointSize, setRenderProps, transform, updateBounds, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN

public static final int OPEN
Specifies an open curve.

See Also:
Constant Field Values

CLOSED

public static final int CLOSED
Specifies a closed curve.

See Also:
Constant Field Values

init

public static boolean init
Constructor Detail

NURBSCurveBase

public NURBSCurveBase()
Method Detail

isClosed

public boolean isClosed()
Returns true if this curve is closed.

Returns:
true if the curve is closed

getType

public int getType()

setResolution

public void setResolution(int res)
Sets the resolution used for rendering this curve. This is the approximate number of pixels in each of the lines segments used to approximate the curve.

Parameters:
res - rendering resolution
See Also:
getResolution()

eval

public abstract void eval(Point3d pnt,
                          double u)
Evaluates the point on this curve for parameter u. If necessary, u is clipped to the range [ustart, uend].

Parameters:
pnt - returns the curve point value
u - curve parameter value

getResolution

public int getResolution()
Returns the resolution used for rendering this curve.

Returns:
rendering resolution
See Also:
setResolution(int)

setRange

public void setRange(double ustart,
                     double uend)
Sets the range of the curve parameter u. If necessary, ustart and uend are clipped so that they lie in the range knots[d-1] to knots[numk-d], where d, knots, and numk describe the curve's degree, knots, and number of knots.

Parameters:
ustart - minimum curve parameter
uend - maximum curve parameter
See Also:
getRange(double[])

getRange

public void getRange(double[] uStartEnd)
Gets the range of the curve parameter u.

Parameters:
uStartEnd - returns the ustart and uend values, in elements 0 and 1, respectively.
See Also:
setRange(double, double)

createUniformKnots

public static double[] createUniformKnots(int numi,
                                          int d,
                                          boolean open)
Creates an array of evenly spaced knots. For a curve of degree d, the number of knots numk will be numi+2*d-1, where numi is the number of active knot intervals. Knot values will increase in unit increments from 0 to numi over the active knot interval from knots[d-1] to knots[d-1+numi]. The values of the remaining knots depend on whether the curve is open or closed. For open curves, the remaining knot values are extrapolated so that knots[i+1] - knots[i] = 1. Otherwise, for closed curves, the d knots at the beginning and end are clamped to 0 and numi, respectively.

Parameters:
numi - number of active intervals
d - degree of the curve
open - true if the curve is open and false if it is closed
Returns:
an array of knot values
Throws:
java.lang.IllegalArgumentException - if constraints on the arguments are violated

set

public void set(int d,
                Vector4d[] ctrlPnts,
                double[] knots)
Sets this NURBS curve to an open curve with a specified degree, knot points, and control points. For information on how these arguments are constrained, see the more general version of set.

Parameters:
d - degree of the curve
ctrlPnts - control points
knots - knot values * @throws IllegalArgumentException if constraints on the arguments are violated
See Also:
set(int,int,Vector4d[],double[])

setUniformCubic

public void setUniformCubic(int type,
                            Vector4d[] ctrlPnts)
Sets this NURBS curve to a curve of third degree with uniform unity knot spacing and a specified number of control points.

Parameters:
type - should be OPEN for open curves and CLOSED for closed curves.
ctrlPnts - control points for this curve

isBSpline

public boolean isBSpline()
Returns true if this curve represents a B-spline (i.e., if all control points have unity weights).


isBezier

public boolean isBezier()
Returns true if this curve represents a piecewise bezier curve.


convertToBezier

public void convertToBezier()

insertKnot

public void insertKnot(int k,
                       double uval)

addControlPoint

public void addControlPoint(Vector4d pnt,
                            double h)
Add an additional control point and knot to the end of this curve. The knot spacing can be given by h. If this is specified as -1, then the default uniform knot spacing (typically 1) is used.


removeControlPoint

public void removeControlPoint()
Remove the control point at the end of this curve. The number of remaining control points must be sufficient for the degree of the curve.


set

public void set(int d,
                int type,
                Vector4d[] ctrlPnts,
                double[] knots)
Sets this NURBS curve to either an open or closed curve with a specified degree, knots, and control points.

Let d, numk, and numc be the degree of the curve, the number of knots, and the number of control points. The degree must be 1 or greater. For open curves,

numc = numk - d + 1
and for closed curves,
numc = numk - 2*d + 1

The knots argument may be set to null, in which case an appropriate number of uniformly spaced knots will be created, in the range [0, 1]. Otherwise, if knots is specified, the ctrlPnts argument must contain at least numc elements.

This method automatically sets ustart and uend (see setRange) to knots[d-1] and knots[numk-d].

The control points are specified as 4-vectors, where their spatial location is given by x, y, and z and their weight is given by w. The points should not be in homogeneous form; i.e., x, y, and z should not be premultipled by w.

Parameters:
d - degree of the curve
type - curve type, which must be either OPEN or CLOSED.
knots - knot values
ctrlPnts - control points
Throws:
java.lang.IllegalArgumentException - if constraints on the arguments are violated

reset

public void reset(int d,
                  int type,
                  double[] knots)
Resets the degrees, type, and knots of this curve. The requested settings must be consistent with the current set of control points. If knots is null, then appropriate uniform knots are computed for the curve type.

Parameters:
d - degree of the curve
type - curve type, which must be either OPEN or CLOSED.
knots - knot values (optional)

setBezier

public void setBezier(int d,
                      Vector4d[] ctrlPnts)
Sets this curve to a piecewise Bezier curve with a prescribed degree and set of control points. The required knots are computed automatically. If numc is the number of control points and d is the degree, then the number of pieces nump for such a curve is (numc - 1)/d. numc and d must be such that this number is a positive integer. Knots will be created and assigned such that the range of u is 0 to nump.

Parameters:
d - degree for the curve
ctrlPnts - control points
Throws:
java.lang.IllegalArgumentException - if constraints on the arguments are violated

setCircle

public void setCircle(double x,
                      double y,
                      double radius)
Sets this curve to an eight-point circle formed using rational cubics.

Parameters:
x - center x coordinate
y - center y coordinate
radius - circle radius
Throws:
java.lang.IllegalArgumentException - if radius is non-positive

getKnotIndex

public int getKnotIndex(double u)
Gets the lower knot point index for the knot interval which contains the parameter value u. If necessary, u is clipped so that it lies in the range of active intervals defined by knots[d-1] and knots[numKnots-d], where d is the degree of the curve and numKnots is the number of knots. This if u is less than knots[d-1], d-1 is returned, while if u is greater than knots[numKnots-d], numKnots-d-1 is returned.

Parameters:
u - curve parameter value
Returns:
lower knot point index for interval containing u

computeControlPolygonLength

public double computeControlPolygonLength()

render

public void render(GLRenderer renderer,
                   RenderProps props,
                   int flags)

Specified by:
render in class NURBSObject

getDegree

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

Returns:
degree of the curve

numKnots

public int numKnots()
Returns the number of knots used by this curve.

Returns:
number of knots

getKnot

public double getKnot(int i)
Returns the i-th knot used by this curve.

Returns:
i-th knot value

getKnots

public double[] getKnots()
Returns the knots used by this curve.

Returns:
knot values

read

public void read(java.io.Reader reader)
          throws java.io.IOException
Reads this curve from a text description supplied by a reader. The allowed format is a subset of the Alias Wavefront OBJ format for curves, and consists of a set of statements, one per line (lines can be continued, if necessary, using the line continuation character \).

The allowed statements are:

As an example, here are the statements that define an eight point NURBS circle:

    v  1  0  0  1
    v  1  1  0  0.35355339059327
    v  0  1  0  1
    v -1  1  0  0.35355339059327
    v -1  0  0  1
    v -1 -1  0  0.35355339059327
    v  0 -1  0  1
    v  1 -1  0  0.35355339059327
    deg 3
    curv 0 1  1 2 3 4 5 6 7 8 
    parm u closed
    end
 

Parameters:
reader - providing the text input
Throws:
java.io.IOException - if an I/O or format error occurs

read

public void read(ReaderTokenizer rtok)
          throws java.io.IOException
Reads this curve in from a ReaderTokenizer, using the same format as read(Reader).

Parameters:
rtok - tokenizer which provides the input
Throws:
java.io.IOException - if an I/O or format error occurs

set

public void set(WavefrontReader.Curve curve,
                Vector4d[] allPnts)

write

public void write(java.io.PrintWriter pw,
                  NumberFormat fmt,
                  boolean relative)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.io.PrintWriter pw,
                  java.lang.String fmtStr,
                  boolean relative)
           throws java.io.IOException
Writes a text description of this NURBS object to a PrintWriter, using a subset of the Wavefront OBJ format as described in the documentation for the read method for this object.

Specified by:
write in class NURBSObject
Parameters:
pw - PrintWriter for outputing the text description
fmtStr - printf-style format string for formatting the floating point values (e.g., "%g", "%10.3f").
relative - if true, then control point indices are written as negative values giving their location relative to the curv statement.
Throws:
java.io.IOException - if an I/O error occurs

createRenderProps

public RenderProps createRenderProps()
Factory method to create render properties appropriate to this object.

Returns:
new render properties for this object