public class J3DPrimitiveIterator
extends java.lang.Object
Read primitives in a JOGLGeometry
or a Java3D GeometryArray
.
Provides an abstraction layer above the numerous vertex formats and data storage options available in Java3D.
A primitive iterator is not ready until it has been reset(...)
at
least once with valid parameters. Normally an iterator of the correct type
is acquired from the factory cons(...)
, which also performs an
initial reset.
The first call to next()
will load the enabled and present
components of the first primitive into texCoord
, color
,
normal
, and coord
(which are also referenced by component
. Subsequent calls will load subsequent primitives until hasNext(int)
returns false, at which point all primitives have been read.
The vertices of quad and triangle primitives are always presented in CCW order around the outside face of the primitive.
GL_POLYGON primitives are treated as triangle fans.
Most operations return this
to facilitate operation chaining.
Copyright (C) 2008 Marsette A. Vona, III
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Modifier and Type | Class and Description |
---|---|
static class |
J3DPrimitiveIterator.J3DLineStripIterator
This impl iterates line strips.
|
static class |
J3DPrimitiveIterator.J3DStripIterator
This is a base impl for stripped geometry.
|
static class |
J3DPrimitiveIterator.J3DTriangleFanIterator
This impl iterates triangle fans.
|
static class |
J3DPrimitiveIterator.J3DTriangleStripIterator
This impl iterates triangle strips.
|
static class |
J3DPrimitiveIterator.JOGLQuadStripIterator
This impl iterates quad strips.
|
Modifier and Type | Field and Description |
---|---|
float[][] |
color
Most recently read color per vertex, null if not reading this
component, NaN if first vertex not yet read.
|
float[][][] |
component
|
float[][] |
coord
Most recently read coordinates per vertex, null if not reading this
component, NaN if first vertex not yet read.
|
private static java.lang.String |
cvsid |
int |
enabledVertexCount
Number of enabled vertices.
|
protected javax.media.j3d.GeometryArray |
ga
currently referenced
GeometryArray , if any |
protected JOGLGeometry |
jg
currently referenced
JOGLGeometry , if any |
boolean |
loop
whether to consider each strip a loop
|
float[][] |
normal
Most recently read normal per vertex, null if not reading this
component, NaN if first vertex not yet read.
|
int |
numEnabledStrips
Number of enabled strips.
|
int |
numStrips
number of strips, or 0 if
ga is not stripped |
protected float[] |
pickB
workspace for
pickLine(float[], float[], float, int) |
protected float[] |
pickU
workspace for
pickLine(float[], float[], float, int) |
int |
prim
current primitive index
|
int |
primCount
total number of primitives
|
int |
primInStrip
current primitive index in current strip
|
int |
primsInStrip
number of prims in current strip
|
private static J3DPrimitiveIterator[] |
protos
set of prototype implementations for
cons(javax.media.j3d.GeometryArray, boolean...) |
int |
strip
current strip index
|
float[][] |
texCoord
Most recently read texture coordinates per vertex, null if not reading
this component, NaN if first vertex not yet read.
|
int |
validVertexCount
number of valid vertices (or valid indices if
ga is indexed) |
J3DVertexAccessor |
vertexAccessor
current vertex accessor
|
int |
vertsInStrip
number of vertices in current strip
|
int |
vertsPerPrim
vertices per prim
|
int |
vertsPerStripPrim
vertices per strip prim
|
Constructor and Description |
---|
J3DPrimitiveIterator() |
Modifier and Type | Method and Description |
---|---|
boolean |
checkFormat(javax.media.j3d.GeometryArray ga)
Check if the class, storage type, and vertex format of ga is
compatible with this implementation.
|
boolean |
checkFormat(JOGLGeometry jg)
similar to
checkFormat(GeometryArray) |
static J3DPrimitiveIterator |
cons(javax.media.j3d.GeometryArray ga,
boolean... enableComponent)
Factory method to cons a new iterator of the appropriate type for the
class, storage type, and vertex format of ga.
|
static J3DPrimitiveIterator |
cons(JOGLGeometry jg,
boolean... enableComponent)
similar to
cons(GeometryArray, boolean...) |
static J3DPrimitiveIterator[] |
consAll()
covers
consAll(J3DPrimitiveIterator[]) , makes a new array |
static J3DPrimitiveIterator[] |
consAll(J3DPrimitiveIterator[] impls)
Cons a new instance of each available implementation.
|
protected void |
copyFromAccessor(int v)
copy all components of vertex v with the accessor
|
void |
dump(java.io.PrintStream s)
dump current state
|
static int |
getNumImplementations()
get the number of available implementations
|
java.lang.String |
getPrimName()
get the name of the prim type based on
vertsPerPrim |
java.lang.String |
getPrimsName()
plural of
getPrimName() |
boolean |
hasNext()
covers
hasNext(int) with num = 1 |
boolean |
hasNext(int num)
Check if the next num subsequent calls to
next() will
succeed. |
protected J3DPrimitiveIterator |
newInstance()
make a new instance of this implementation
|
J3DPrimitiveIterator |
next()
read the next primitive
|
float |
pick(float[] pickStart,
float[] pickExtent,
float threshold,
int cullFace)
Compute a pick intersection with the current primitive.
|
float |
pickLine(float[] pickStart,
float[] pickExtent,
float threshold,
int cullFace)
pick(float[], float[], float, int) assuming that the primitive
is a line segment. |
float |
pickPoint(float[] pickStart,
float[] pickExtent,
float threshold,
int cullFace)
pick(float[], float[], float, int) assuming that the primitive
is a point. |
float |
pickQuad(float[] pickStart,
float[] pickExtent,
float threshold,
int cullFace)
pick(float[], float[], float, int) assuming that the primitive
is a quad. |
float |
pickTriangle(float[] pickStart,
float[] pickExtent,
float threshold,
int cullFace)
pick(float[], float[], float, int) assuming that the primitive
is a triangle. |
J3DPrimitiveIterator |
reset()
reset internal indices but continue referencing current
ga |
J3DPrimitiveIterator |
reset(javax.media.j3d.GeometryArray ga,
boolean... enableComponent)
Reset this iterator so that the subsequent call to
next() reads
the first primitive in ga. |
J3DPrimitiveIterator |
reset(JOGLGeometry jg,
boolean... enableComponent)
similar to
reset(GeometryArray, boolean...) |
protected J3DPrimitiveIterator |
resetImpl(boolean... enableComponent)
Common impl of
reset(GeometryArray, boolean...) and reset(JOGLGeometry, boolean...) . |
protected void |
swap(int v0,
int v1)
swap all components of vertices v0 and v1
|
private static final java.lang.String cvsid
public int strip
public int prim
public int primInStrip
public int primsInStrip
public int vertsInStrip
public int vertsPerPrim
public int vertsPerStripPrim
public int numStrips
ga
is not strippedpublic boolean loop
public int numEnabledStrips
Number of enabled strips.
This will be the same as numStrips
except when
iterating a JOGLGeometry
that contains negative array counts.
public int validVertexCount
ga
is indexed)public int enabledVertexCount
Number of enabled vertices.
This will be the same as validVertexCount
except when
iterating a JOGLGeometry
that contains negative array counts.
public int primCount
public float[][] texCoord
Most recently read texture coordinates per vertex, null if not reading this component, NaN if first vertex not yet read.
If non-null, length [2-4] gives texture space dimension.
public float[][] color
Most recently read color per vertex, null if not reading this component, NaN if first vertex not yet read.
If non-null, length (3 or 4) gives color space dimension.
public float[][] normal
Most recently read normal per vertex, null if not reading this component, NaN if first vertex not yet read.
public float[][] coord
Most recently read coordinates per vertex, null if not reading this component, NaN if first vertex not yet read.
public float[][][] component
protected javax.media.j3d.GeometryArray ga
GeometryArray
, if anyprotected JOGLGeometry jg
JOGLGeometry
, if anypublic J3DVertexAccessor vertexAccessor
protected final float[] pickB
pickLine(float[], float[], float, int)
protected final float[] pickU
pickLine(float[], float[], float, int)
private static final J3DPrimitiveIterator[] protos
cons(javax.media.j3d.GeometryArray, boolean...)
public static int getNumImplementations()
public static J3DPrimitiveIterator[] consAll(J3DPrimitiveIterator[] impls)
Cons a new instance of each available implementation.
impls
- if non-null and at least length getNumImplementations()
the new instances are collected here, else a new
array is consedgetNumImplementations()
elements are
set to instances of each available implementationpublic static J3DPrimitiveIterator[] consAll()
consAll(J3DPrimitiveIterator[])
, makes a new arraypublic static J3DPrimitiveIterator cons(javax.media.j3d.GeometryArray ga, boolean... enableComponent)
Factory method to cons a new iterator of the appropriate type for the class, storage type, and vertex format of ga.
The returned iterator is newly consed and already reset(GeometryArray, boolean...)
given the passed parameters. It may be
re-used by further reset()
s.
public static J3DPrimitiveIterator cons(JOGLGeometry jg, boolean... enableComponent)
cons(GeometryArray, boolean...)
public J3DPrimitiveIterator reset(javax.media.j3d.GeometryArray ga, boolean... enableComponent)
Reset this iterator so that the subsequent call to next()
reads
the first primitive in ga.
ga
- the geometry, or null to clear the previous internal referenceenableComponent
- see J3DVertexAccessor.reset(GeometryArray,
boolean...)
java.lang.IllegalArgumentException
- if ga is non-null and fails
checkFormat(javax.media.j3d.GeometryArray)
public J3DPrimitiveIterator reset(JOGLGeometry jg, boolean... enableComponent)
reset(GeometryArray, boolean...)
protected J3DPrimitiveIterator resetImpl(boolean... enableComponent)
Common impl of reset(GeometryArray, boolean...)
and reset(JOGLGeometry, boolean...)
.
public J3DPrimitiveIterator reset()
ga
public boolean hasNext(int num)
Check if the next num subsequent calls to next()
will
succeed.
public boolean hasNext()
hasNext(int)
with num = 1public J3DPrimitiveIterator next()
public java.lang.String getPrimName()
vertsPerPrim
public java.lang.String getPrimsName()
getPrimName()
public void dump(java.io.PrintStream s)
public float pick(float[] pickStart, float[] pickExtent, float threshold, int cullFace)
Compute a pick intersection with the current primitive.
A threshold is provided to compare the perpendicular distance from the pick segment to the primitive for lines and points. The threshold is ignored for all two-dimensional primitives.
pickStart
- the start 3D coordinates of the pick segment in the same
coordinate frame as the geometry of this iteratorpickExtent
- the 3D extension vector from pickStart of the
pick segment in the same coordinate frame as the geometry of this iteratorthreshold
- the pick threshold, or NaN for none, see abovepublic float pickPoint(float[] pickStart, float[] pickExtent, float threshold, int cullFace)
pick(float[], float[], float, int)
assuming that the primitive
is a point.
public float pickLine(float[] pickStart, float[] pickExtent, float threshold, int cullFace)
pick(float[], float[], float, int)
assuming that the primitive
is a line segment.
public float pickTriangle(float[] pickStart, float[] pickExtent, float threshold, int cullFace)
pick(float[], float[], float, int)
assuming that the primitive
is a triangle.
public float pickQuad(float[] pickStart, float[] pickExtent, float threshold, int cullFace)
pick(float[], float[], float, int)
assuming that the primitive
is a quad.
public boolean checkFormat(javax.media.j3d.GeometryArray ga)
Check if the class, storage type, and vertex format of ga is compatible with this implementation.
public boolean checkFormat(JOGLGeometry jg)
checkFormat(GeometryArray)
protected J3DPrimitiveIterator newInstance()
protected void swap(int v0, int v1)
protected void copyFromAccessor(int v)