j3d.org Code

org.j3d.geom.spline
Class PatchGenerator

java.lang.Object
  extended by org.j3d.geom.GeometryGenerator
      extended by org.j3d.geom.spline.PatchGenerator
Direct Known Subclasses:
BezierPatchGenerator, BSplinePatchGenerator

public abstract class PatchGenerator
extends GeometryGenerator

Base geometry generator defintion for all forms of spline-based patches.

Patches of all orders are permitted. Order information is derived from the provided controlPoint coordinates. When generating a patch, the values for the coordinates are nominally provided in the X and Z plane although no explicit checking is performed to ensure that controlPoint coordinates do not self-intersect or do anything nasty. Normals are always generated as the average between the adjacent faces.

A user may optionally provide a weighting for each control point to make for rational patches. By default, all control points start with a weight of one. The implementation automatically resets the weights back to one each time the control points are changed, unless otherwise specified. If the patch coordinate size changes, then the weights will always be reset, otherwise if the size is the same as previously set, then the weights are left alone.

Version:
$Revision: 1.8 $
Author:
Justin Couch

Field Summary
protected  float[][] controlPointCoordinates
          ControlPoint values used to generate patches
protected  float[][] controlPointWeights
          The control point weightings on the patch.
protected  int depthFacetCount
          The number of sections used around the patch depth
protected  boolean normalsChanged
          Flag indicating base values have changed
protected  int numDepthControlPoints
          The number of control points in the depth
protected  int numNormalValues
          The number of patch coordinates in depth
protected  int numPatchValues
          The number of patch coordinates in depth
protected  int numTexcoordValues
          The number of patch coordinates in depth
protected  int numWidthControlPoints
          The number of control points in the width
protected  boolean patchChanged
          Flag indicating base values have changed
protected  float[][] patchCoordinates
          The points on the patch.
protected  float[][] patchNormals
          The smoothed normal for each point on the patch.
protected  float[][] patchTexcoords
          The texture coordinate for each point on the patch.
protected  boolean texCoordsChanged
          Flag indicating base values have changed
protected  boolean useControlPointWeights
          Should we use control point weights.
protected  int widthFacetCount
          The number of sections used around the patch width
 
Constructor Summary
protected PatchGenerator()
          Construct a new generator with no control points set.
 
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.
 int getVertexCount(GeometryData data)
          Get the number of vertices that this generator will create for the shape given in the definition.
 boolean hasControlPointWeights()
          Get the current setting of the control point weight usage flag.
protected  void regenerateNormals()
          Convenience method to regenerate the smoothed normals for the patch.
protected abstract  void regeneratePatch()
          Regenerate the patch coordinate points in accordance with the derived classes algorithm type.
protected  void regenerateTexcoords()
          Regenerate the texture coordinate points.
 void setFacetCount(int widthFacets, int depthFacets)
          Change the number of facets used to create this cone.
 void setPatchControlPoints(double[][] controlPoints)
          Set the patch control points.
 void setPatchControlPoints(double[][] controlPoints, double[][] weights)
          Set the patch control points and weights at the same time.
 void setPatchControlPoints(double[] controlPoints, int numWidth, int numDepth)
          Set the patch controlPoints.
 void setPatchControlPoints(double[] controlPoints, int numWidth, int numDepth, double[] weights)
          Set the patch controlPoints.
 void setPatchControlPoints(float[][] controlPoints)
          Set the patch control points.
 void setPatchControlPoints(float[][] controlPoints, float[][] weights)
          Set the patch control points and weights at the same time.
 void setPatchControlPoints(float[] controlPoints, int numWidth, int numDepth)
          Set the patch controlPoints.
 void setPatchControlPoints(float[] controlPoints, int numWidth, int numDepth, float[] weights)
          Set the patch controlPoints.
 void setPatchWeights(double[][] weights)
          Set the patch control point weights.
 void setPatchWeights(double[] weights, int numWidth, int numDepth)
          Set the patch controlPoints.
 void setPatchWeights(float[][] weights)
          Set the patch control point weights.
 void setPatchWeights(float[] weights, int numWidth, int numDepth)
          Set the patch controlPoints.
 
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

controlPointCoordinates

protected float[][] controlPointCoordinates
ControlPoint values used to generate patches


controlPointWeights

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


numWidthControlPoints

protected int numWidthControlPoints
The number of control points in the width


numDepthControlPoints

protected int numDepthControlPoints
The number of control points in the depth


patchCoordinates

protected float[][] patchCoordinates
The points on the patch.


patchNormals

protected float[][] patchNormals
The smoothed normal for each point on the patch.


patchTexcoords

protected float[][] patchTexcoords
The texture coordinate for each point on the patch.


numPatchValues

protected int numPatchValues
The number of patch coordinates in depth


numNormalValues

protected int numNormalValues
The number of patch coordinates in depth


numTexcoordValues

protected int numTexcoordValues
The number of patch coordinates in depth


patchChanged

protected boolean patchChanged
Flag indicating base values have changed


normalsChanged

protected boolean normalsChanged
Flag indicating base values have changed


texCoordsChanged

protected boolean texCoordsChanged
Flag indicating base values have changed


widthFacetCount

protected int widthFacetCount
The number of sections used around the patch width


depthFacetCount

protected int depthFacetCount
The number of sections used around the patch depth


useControlPointWeights

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

Constructor Detail

PatchGenerator

protected PatchGenerator()
Construct a new generator with no control points set.

Method Detail

regeneratePatch

protected abstract void regeneratePatch()
Regenerate the patch coordinate points in accordance with the derived classes algorithm type.


setFacetCount

public void setFacetCount(int widthFacets,
                          int depthFacets)
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:
widthFacets - The number of facets on the width of the patch
depthFacets - The number of facets on the width of the patch
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3

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

setPatchWeights

public void setPatchWeights(float[][] weights)
Set the patch control point weights. The array is presented as [width][depth] with the coordinates flattened as [Xn, Yn, Zn] in the depth array.

If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
weights - The weight values to use

setPatchWeights

public void setPatchWeights(double[][] weights)
Set the patch control point weights. The array is presented as [width][depth] with the coordinates flattened as [Xn, Yn, Zn] in the depth array.

If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
weights - The weight values to use

setPatchWeights

public void setPatchWeights(float[] weights,
                            int numWidth,
                            int numDepth)
Set the patch controlPoints. The array is presented as a flat array where coordinates are [depth * width Xn, Yn, Zn] in the array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
weights - The weight values to use
numWidth - The number of points in the width
numDepth - The number of points in the depth

setPatchWeights

public void setPatchWeights(double[] weights,
                            int numWidth,
                            int numDepth)
Set the patch controlPoints. The array is presented as a flat array where coordinates are [depth * width Xn, Yn, Zn] in the array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
weights - The weight values to use
numWidth - The number of points in the width
numDepth - The number of points in the depth

setPatchControlPoints

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

Parameters:
controlPoints - The controlPoint coordinate values

setPatchControlPoints

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

Parameters:
controlPoints - The controlPoint coordinate values

setPatchControlPoints

public void setPatchControlPoints(float[][] controlPoints,
                                  float[][] weights)
Set the patch control points and weights at the same time. The array is presented as [width][depth] with the coordinates flattened as [Xn, Yn, Zn] in the depth array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values
weights - The weight values to use

setPatchControlPoints

public void setPatchControlPoints(double[][] controlPoints,
                                  double[][] weights)
Set the patch control points and weights at the same time. The array is presented as [width][depth] with the coordinates flattened as [Xn, Yn, Zn] in the depth array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values
weights - The weight values to use

setPatchControlPoints

public void setPatchControlPoints(float[] controlPoints,
                                  int numWidth,
                                  int numDepth)
Set the patch controlPoints. The array is presented as a flat array where coordinates are [depth * width Xn, Yn, Zn] in the array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values
numWidth - The number of points in the width
numDepth - The number of points in the depth

setPatchControlPoints

public void setPatchControlPoints(double[] controlPoints,
                                  int numWidth,
                                  int numDepth)
Set the patch controlPoints. The array is presented as a flat array where coordinates are [depth * width Xn, Yn, Zn] in the array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values
numWidth - The number of points in the width
numDepth - The number of points in the depth

setPatchControlPoints

public void setPatchControlPoints(float[] controlPoints,
                                  int numWidth,
                                  int numDepth,
                                  float[] weights)
Set the patch controlPoints. The array is presented as a flat array where coordinates are [depth * width Xn, Yn, Zn] in the array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values
numWidth - The number of points in the width
numDepth - The number of points in the depth

setPatchControlPoints

public void setPatchControlPoints(double[] controlPoints,
                                  int numWidth,
                                  int numDepth,
                                  double[] weights)
Set the patch controlPoints. The array is presented as a flat array where coordinates are [depth * width Xn, Yn, Zn] in the array. The order of the patch is determined by the passed array. If the arrays are not of minimum length 3 and equal length an exception is generated.

Parameters:
controlPoints - The controlPoint coordinate values
numWidth - The number of points in the width
numDepth - The number of points in the depth

getVertexCount

public int getVertexCount(GeometryData data)
                   throws UnsupportedTypeException
Get the number of vertices that this generator will create for the shape given in the definition.

Specified by:
getVertexCount in class GeometryGenerator
Parameters:
data - The data to patch 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

regenerateNormals

protected void regenerateNormals()
Convenience method to regenerate the smoothed normals for the patch. It assumes that the patch has been regenerated just before this call.


regenerateTexcoords

protected final void regenerateTexcoords()
Regenerate the texture coordinate points. Assumes regenerateBase has been called before this


j3d.org Code

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