maspack.geometry
Class NURBSSurface

java.lang.Object
  extended by maspack.geometry.NURBSObject
      extended by maspack.geometry.NURBSSurface
All Implemented Interfaces:
GLRenderable, GLSelectable, HasRenderProps, Renderable

public class NURBSSurface
extends NURBSObject

Implements a NURBS surface


Field Summary
 
Fields inherited from interface maspack.render.GLRenderable
TRANSLUCENT, TWO_DIMENSIONAL
 
Constructor Summary
NURBSSurface()
          Creates an empty NURBS surface.
NURBSSurface(int du, int typeu, double[] knotsu, int dv, int typev, double[] knotsv, Vector4d[] ctrlPnts)
          Creates a NURBS surface using degree and knot values in the u and v directions, along with control points.
 
Method Summary
 RenderProps createRenderProps()
          Factory method to create render properties appropriate to this object.
 void eval(Point3d pnt, double u, double v)
          Evaluates the point on this surface corresponding to u and v.
 int getDegreeU()
          Returns the degree of this surface in the u direction.
 int getDegreeV()
          Returns the degree of this surface in the v direction.
 double[] getKnotsU()
          Returns the knots in the u direction.
 double[] getKnotsV()
          Returns the knots in the v direction.
 void getRangeU(double[] uStartEnd)
          Gets the range of the u parameter.
 void getRangeV(double[] vStartEnd)
          Gets the range of the v parameter.
 int getResolutionU()
          Returns the resolution used for rendering this surface along the u parameter.
 int getResolutionV()
          Returns the resolution used for rendering this surface along the v parameter.
 NURBSCurve3d getVCurve()
          Returns the NURBS curve controlling this surface in the v direction.
 int numKnotsU()
          Returns the number of knots in the u direction.
 int numKnotsV()
          Returns the number of knots in the v direction.
 void read(java.io.Reader reader)
          Reads this surface from a text description supplied by a reader.
 void render(GLRenderer renderer, RenderProps props, int flags)
          
 void set(int du, double[] knotsu, int dv, double[] knotsv, Vector4d[] ctrlPnts)
          Sets this NURBS surface using degree and knot values in the u and v directions, along with control points.
 void set(int du, int typeu, double[] knotsu, int dv, int typev, double[] knotsv, Vector4d[] ctrlPnts)
          Sets this NURBS surface using degree and knot values in the u and v directions, along with control points.
 void set(WavefrontReader.Surface surface, Vector4d[] allPnts)
           
 void setRangeU(double ustart, double uend)
          Sets the range of the u parameter.
 void setRangeV(double vstart, double vend)
          Sets the range of the v parameter.
 void setResolutionU(int res)
          Sets the resolution used for rendering this surface along the u parameter.
 void setResolutionV(int res)
          Sets the resolution used for rendering this surface along the v parameter.
 void setSphere(double x, double y, double z, double radius)
          Sets this surface to a 40-point sphere formed by sweeping a 5-point rational quadratic semi-circle about the z axis.
 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
 

Constructor Detail

NURBSSurface

public NURBSSurface()
Creates an empty NURBS surface.


NURBSSurface

public NURBSSurface(int du,
                    int typeu,
                    double[] knotsu,
                    int dv,
                    int typev,
                    double[] knotsv,
                    Vector4d[] ctrlPnts)
Creates a NURBS surface using degree and knot values in the u and v directions, along with control points. The surface may be open or closed in either the u or v directions. For information on how these arguments are constrained, see the general version of set.

Parameters:
du - degree in the u direction
typeu - u direction type, which must be either OPEN or CLOSED.
knotsu - knot values for the u direction
dv - degree in the v direction
typev - v direction type, which must be either OPEN or CLOSED.
knotsv - knot values for the v direction
ctrlPnts - control points
Throws:
java.lang.IllegalArgumentException - if constraints on the arguments are violated
See Also:
set(int,int,double[],int,int,double[],Vector4d[])
Method Detail

setResolutionU

public void setResolutionU(int res)
Sets the resolution used for rendering this surface along the u parameter. This is the number of linear segments used to plot the surface between it's minimum and maximum u values.

Parameters:
res - rendering resolution for u
See Also:
getResolutionU()

getResolutionU

public int getResolutionU()
Returns the resolution used for rendering this surface along the u parameter.

Returns:
rendering resolution for u
See Also:
setResolutionU(int)

setResolutionV

public void setResolutionV(int res)
Sets the resolution used for rendering this surface along the v parameter. This is the number of linear segments used to plot the surface between it's minimum and maximum v values.

Parameters:
res - rendering resolution for v
See Also:
getResolutionV()

getResolutionV

public int getResolutionV()
Returns the resolution used for rendering this surface along the v parameter.

Returns:
rendering resolution for v
See Also:
setResolutionV(int)

setRangeU

public void setRangeU(double ustart,
                      double uend)
Sets the range of the u parameter. 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 degree, knots, and number of knots associated with u.

Parameters:
ustart - minimum u parameter
uend - maximum u parameter
See Also:
getRangeU(double[])

getRangeU

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

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

setRangeV

public void setRangeV(double vstart,
                      double vend)
Sets the range of the v parameter. If necessary, vstart and vend are clipped so that they lie in the range knots[d-1] to knots[numk-d], where d, knots, and numk describe the degree, knots, and number of knots associated with v.

Parameters:
vstart - minimum v parameter
vend - maximum v parameter
See Also:
getRangeV(double[])

getRangeV

public void getRangeV(double[] vStartEnd)
Gets the range of the v parameter.

Parameters:
vStartEnd - returns the vstart and vend values, in elements 0 and 1, respectively.
See Also:
setRangeV(double, double)

set

public void set(int du,
                double[] knotsu,
                int dv,
                double[] knotsv,
                Vector4d[] ctrlPnts)
Sets this NURBS surface using degree and knot values in the u and v directions, along with control points. For information on how these arguments are constrained, see the more general version of set.

Parameters:
du - degree in the u direction
knotsu - knot values for the u direction
dv - degree in the v direction
knotsv - knot values for the v direction
ctrlPnts - control points
Throws:
java.lang.IllegalArgumentException - if constraints on the arguments are violated
See Also:
set(int,int,double[],int,int,double[],Vector4d[])

set

public void set(int du,
                int typeu,
                double[] knotsu,
                int dv,
                int typev,
                double[] knotsv,
                Vector4d[] ctrlPnts)
Sets this NURBS surface using degree and knot values in the u and v directions, along with control points. The surface may be open or closed in either the u or v directions.

Let du, numku, and numcu be the degree, number of knots, and number of control points associated with the u direction. The degree must be 1 or greater. If the u direction is open, then

numcu = numku - du + 1
and if it is closed,
numcu = numku - 2*du + 1
Analogous results hold for the v direction. The total number of control points is numcu*numcv, and so the ctrlPnts argument must be at least this length. Control points should be arranged so that the first set of v control points comes first, followed by the second set, etc.

This method automatically sets ustart, uend, vstart, and vend (see setRangeU and setRangeV) to to knotsu[du-1], knotsu[numku-du], knotsv[dv-1], and knotsv[numkv-dv].

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:
du - degree in the u direction
typeu - u direction type, which must be either OPEN or CLOSED.
knotsu - knot values for the u direction
dv - degree in the v direction
typev - v direction type, which must be either OPEN or CLOSED.
knotsv - knot values for the v direction
ctrlPnts - control points
Throws:
java.lang.IllegalArgumentException - if constraints on the arguments are violated

setSphere

public void setSphere(double x,
                      double y,
                      double z,
                      double radius)
Sets this surface to a 40-point sphere formed by sweeping a 5-point rational quadratic semi-circle about the z axis.

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

eval

public void eval(Point3d pnt,
                 double u,
                 double v)
Evaluates the point on this surface corresponding to u and v. These values are clipped, if necessary, to the range [ustart, uend] and [vstart, vend].

Parameters:
pnt - returns the surface point value
u - u parameter value
v - v parameter value

render

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

Specified by:
render in class NURBSObject

getVCurve

public NURBSCurve3d getVCurve()
Returns the NURBS curve controlling this surface in the v direction.

Returns:
v direction curve

getDegreeU

public int getDegreeU()
Returns the degree of this surface in the u direction.

Returns:
degree in the u direction

numKnotsU

public int numKnotsU()
Returns the number of knots in the u direction.

Returns:
number of knots in the u direction

getKnotsU

public double[] getKnotsU()
Returns the knots in the u direction.

Returns:
knot values in the u direction

getDegreeV

public int getDegreeV()
Returns the degree of this surface in the v direction.

Returns:
degree in the v direction

numKnotsV

public int numKnotsV()
Returns the number of knots in the v direction.

Returns:
number of knots in the v direction

getKnotsV

public double[] getKnotsV()
Returns the knots in the v direction.

Returns:
knot values in the v direction

read

public void read(java.io.Reader reader)
          throws java.io.IOException
Reads this surface from a text description supplied by a reader. The allowed format is a subset of the Alias Wavefront OBJ format for surfaces, 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:

The total number of control points and knots must match as described in the documentation for set. Explicit knot values may be omitted for either u or v, in which case an appropriate number of uniformly-spaced knots is created with start and end values corresponding to 0 and 1.

As an example, here are the statements that define a simple bezier surface patch: v -10.0 0.0 10.0 1.0 v -5.0 5.0 10.0 1.0 v 5.0 5.0 10.0 1.0 v 10.0 0.0 10.0 1.0 v -10.0 0.0 5.0 1.0 v -5.0 5.0 5.0 1.0 v 5.0 5.0 5.0 1.0 v 10.0 0.0 5.0 1.0 v -10.0 0.0 -5.0 1.0 v -5.0 5.0 -5.0 1.0 v 5.0 5.0 -5.0 1.0 v 10.0 0.0 -5.0 1.0 v -10.0 0.0 -10.0 1.0 v -5.0 5.0 -10.0 1.0 v 5.0 5.0 -10.0 1.0 v 10.0 0.0 -10.0 1.0 deg 3 3 surf 0.0 1.0 0.0 1.0 \ 1 2 3 4 5 6 7 8 9 10 \ 11 12 13 14 15 16 parm u 0.0 0.0 0.0 1.0 1.0 1.0 parm v 0.0 0.0 0.0 1.0 1.0 1.0 end

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

set

public void set(WavefrontReader.Surface surface,
                Vector4d[] allPnts)

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