@NotThreadSafe
public class Widget
extends java.lang.Object
Defines a set of geometries and their appearances.
The number of geometries is fixed at construction time.
Various subclasses in this package provide common geometric objects.
Also the user may instantiate a Widget from a Shape3D
, or can
simply populate a raw Widget with geometries.
This class is not internally synchronized. Applications which allow access to a Widget from multiple threads need to implement their own synchronization.
Includes
enabled
enable/disable each geometryrx
to set a local coordinate frame for all geometryprimitiveIterator
for each JOGLGeometry
or GeometryArray
geometry (coords and normals, if available, only)vertexAccessor
for each geometryboundingSphereCenter
and boundingSphereRadius
for
each geometrywidgetLength
which can be used as a scale referencealpha
on top of any individual
Appearance alphasupdateDBGNormals(int, float)
, a facility to generate geometry
that displays line segments along explicit vertex normalsupdateDBGSpheres(int)
, a facility to generate geometry that
displays bounding spherespropertyMap
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 | Field and Description |
---|---|
float |
alpha
Extra multiplicative alpha on top of any individual Appearance
alphas.
|
javax.media.j3d.Appearance[] |
appearance
appearance for each geometry, null if none
|
boolean |
autoSetBoundingSpheres
Whether to automatically update geometry bounding spheres in subclasses
that support such functionality.
|
float[][] |
boundingSphereCenter
bounding sphere ctr for each geom in native frame of this Widget
|
float[][] |
boundingSphereCenterInView
boundingSphereCenter in view frame, alloc if desired by
calling ensureBoundingSpheresInView() . |
float[] |
boundingSphereRadius
Bounding sphere rad for each geom in native frame of this Widget
|
float[] |
boundingSphereRadiusInView
boundingSphereRadius in view frame, alloc if desired by
calling ensureBoundingSpheresInView() . |
private static java.lang.String |
cvsid |
boolean |
dbgEnabled
whether debug spheres and normals are enabled if present
|
JOGLGeometry |
dbgNormalsGeometry
DBG normal geometry if non-null, see
updateDBGNormals(int,
float) . |
java.nio.FloatBuffer |
dbgNormalsVertices
vertex array for
dbgNormalsGeometry , if non-null |
JOGLGeometry |
dbgSpheresGeometry
dbg spheres geometry if non-null, see
updateDBGSpheres(int) |
java.nio.FloatBuffer |
dbgSpheresVertices
vertex array for
dbgSpheresGeometry , if non-null |
static float |
DEF_DBG_NORMAL_LENGTH
line segment length for dbg normal display
|
static float |
DEF_WIDGET_LENGTH
default
widgetLength |
boolean[] |
enabled
enable/disable flag for each geometry, default true
|
javax.media.j3d.Geometry[] |
geometry
the geometries, entries may be null
|
int |
numGeometries
number of geometries in this Widget
|
J3DPrimitiveIterator[] |
primitiveIterator
Primitive iterator for each geometry (colors and normals, if available,
only).
|
protected java.util.Map<java.lang.String,java.lang.Object> |
propertyMap
the property map or null if none
|
RX |
rx
Transforms coordinates in the native frame of this Widget to a parent
frame, or null (i.e.
|
J3DVertexAccessor[] |
vertexAccessor
|
protected float |
widgetLength
current widget length
|
Constructor and Description |
---|
Widget(int numGeometries)
Creates a new Widget that will hold the specified number of
geometries.
|
Widget(javax.media.j3d.Shape3D shape3D)
Covers
Widget(Shape3D, boolean, int, PrintStream) , sets
extractToJOGL, no error stream, extracts all vertex components. |
Widget(javax.media.j3d.Shape3D shape3D,
boolean extractToJOGL,
int j3dFormatMask,
java.io.PrintStream errorStream)
Makes a new Widget by extracting all the
GeometryArray s
of shape3D and its Appearance , if any. |
Widget(javax.media.j3d.Shape3D shape3D,
int j3dFormatMask)
Covers
Widget(Shape3D, boolean, int, PrintStream) , sets
extractToJOGL, no error stream. |
Widget(javax.media.j3d.Shape3D shape3D,
int j3dFormatMask,
java.io.PrintStream errorStream)
covers
Widget(Shape3D, boolean, int, PrintStream) , sets
extractToJOGL |
Modifier and Type | Method and Description |
---|---|
static Widget |
cons(java.lang.String type)
Generic factory method to construct Widget subclass instances.
|
protected static int |
countGeometryArrays(javax.media.j3d.Shape3D shape3D)
count the number of GeometryArrays in shape3D
|
void |
disableBoundingSphere(int index)
disable the bounding sphere at index by setting its radius -1
|
void |
disableBoundingSpheres()
Disable all bounding spheres and turn off
autoSetBoundingSpheres . |
void |
dump()
dump(PrintStream) to System.out |
void |
dump(java.io.PrintStream s)
dump widget details
|
void |
enableDBGGeometry(boolean enable)
Enable or disable debug spheres and normals.
|
void |
enableGeometry(int index,
boolean enable)
set the
enabled flag for geometry at index |
void |
ensureBoundingSpheresInView()
Cons
boundingSphereCenterInView and boundingSphereRadiusInView iff necessary. |
javax.media.j3d.Appearance |
getAppearance(int index)
get a reference to the
appearance at indicated index |
float[] |
getBoundingSphereCenter(int index)
get a reference to
boundingSphereCenter at index |
float |
getBoundingSphereRadius(int index)
get the
boundingSphereRadius at index |
javax.media.j3d.Geometry |
getGeometry(int index)
get a reference to the
geometry at indicated index |
java.lang.Object |
getProperty(java.lang.String key)
get a property
|
static Widget |
getWidget(javax.media.j3d.Geometry geometry)
Convenience to get the
Widget containing geometry by
following the user data ref on geometry. |
float |
getWidgetAlpha()
get
alpha |
boolean |
hasBoundingSphere(int index)
Check if the
geometry at index has a non-negative
boundingSphereRadius . |
boolean |
hasBoundingSphereInView(int index)
Check if view-frame bounding spheres are allocated and that the
geometry at index has a n-negative boundingSphereRadiusInView . |
boolean |
hasProperty(java.lang.String key)
check existence of a property
|
int |
indexOf(javax.media.j3d.Geometry geometry)
Lookup the index of geometry in this Widget.
|
protected void |
populateFrom(javax.media.j3d.Shape3D shape3D,
boolean extractToJOGL,
int j3dFormatMask,
java.io.PrintStream errorStream)
|
void |
recomputeBoundingSphere(int index)
Recompute
boundingSphereCenter and boundingSphereRadius for geometry at index, using vertexAccessor at index, if present. |
void |
recomputeBoundingSpheres()
recomputeBoundingSphere(int) for each geometry |
void |
removeDBGNormals()
remove any debug normals
|
void |
removeDBGSpheres()
remove any debug spheres
|
int |
removeGeometry(javax.media.j3d.Geometry geometry)
Remove (null) indicated
geometry , iff found. |
javax.media.j3d.Geometry |
removeGeometry(int index)
Remove (null)
geometry at indicated index. |
java.lang.Object |
removeProperty(java.lang.String key)
remove a property
|
javax.media.j3d.Appearance |
replaceAppearanceWithClone(int index)
similar to
replaceGeometryWithClone(int) |
javax.media.j3d.Geometry |
replaceGeometryWithClone(int index)
Replace the indicated
geometry with a clone of itself. |
void |
scaleWidget(float scale)
Apply a scale factor in-place to this widget.
|
javax.media.j3d.Appearance |
setAppearance(int index,
javax.media.j3d.Appearance appearance)
Set a the
appearance at indicated index by ref. |
void |
setBoundingSphereCenter(int index,
float... center)
set
boundingSphereCenter at index by copy |
void |
setBoundingSphereRadius(int index,
float radius)
set the
boundingSphereRadius at index |
javax.media.j3d.Geometry |
setGeometry(int index,
javax.media.j3d.Geometry geometry)
Set the geometry at the specified index.
|
void |
setGeometryAlpha(float alpha)
convenience to
setGeometryAlpha(int, float) on all geometries |
void |
setGeometryAlpha(int index,
float alpha)
set transparency alpha for a particular geometry
|
void |
setGeometryAndAppearance(int index,
javax.media.j3d.Geometry geometry,
javax.media.j3d.Appearance appearance)
setGeometry(int, javax.media.j3d.Geometry) and appearance at the specified index |
java.lang.Object |
setProperty(java.lang.String key,
java.lang.Object value)
covers
setProperty(String, Object, boolean) , replaces |
java.lang.Object |
setProperty(java.lang.String key,
java.lang.Object value,
boolean replace)
Set a property.
|
void |
setWidgetAlpha(float alpha)
set
alpha |
void |
setWidgetLength(float widgetLength)
Set
widgetLength , calls widgetLengthChanged() iff
different. |
void |
trackWidgetLength(float... trackFactor)
Subclasses may implement this to store factors that map
widgetLength to their parameters. |
void |
updateAllDBGNormals()
updateDBGNormals(int, float) for all geometry ,
creating them if they don't yet exist, using DEF_DBG_NORMAL_LENGTH . |
void |
updateAllDBGNormals(float normalLength)
updateDBGNormals(int, float) for all geometry ,
creating them if they don't yet exist. |
void |
updateAllDBGSpheres()
updateDBGSpheres(int) for all geometry |
void |
updateDBGNormals(int upToGeometry)
|
void |
updateDBGNormals(int upToGeometry,
float normalLength)
Create or update the
dbgNormalsGeometry which shows line
segments for each normal in each geometry . |
void |
updateDBGSpheres(int upToGeometry)
Create or update the
dbgSpheresGeometry which shows the
bounding spheres for each geometry . |
void |
updateExistingDBGNormals()
updateDBGNormals(int, float) that already exist, using length
of first existing one. |
void |
updateExistingDBGSpheres()
updateDBGSpheres(int) only existing |
protected void |
widgetLengthChanged()
called by
setWidgetLength(float) after the length has changed |
private static final java.lang.String cvsid
public static final float DEF_WIDGET_LENGTH
widgetLength
public static final float DEF_DBG_NORMAL_LENGTH
public final int numGeometries
public final javax.media.j3d.Geometry[] geometry
public final javax.media.j3d.Appearance[] appearance
public final boolean[] enabled
public volatile RX rx
Transforms coordinates in the native frame of this Widget to a parent frame, or null (i.e. use identity).
public volatile float alpha
Extra multiplicative alpha on top of any individual Appearance alphas.
Ignored if outside the range [0, 1]. Otherwise, multiplies the original Appearance alpha for each geometry.
public volatile boolean autoSetBoundingSpheres
Whether to automatically update geometry bounding spheres in subclasses that support such functionality.
public final J3DPrimitiveIterator[] primitiveIterator
Primitive iterator for each geometry (colors and normals, if available, only).
public final J3DVertexAccessor[] vertexAccessor
Vertex accessor (contained in primitiveIterator
) for each
JOGLGeometry
or GeometryArray
geometry.
public final float[][] boundingSphereCenter
public final float[] boundingSphereRadius
Bounding sphere rad for each geom in native frame of this Widget
Convention: set negative to indicate that the corresp bounding sphere is not available.
public float[][] boundingSphereCenterInView
boundingSphereCenter
in view frame, alloc if desired by
calling ensureBoundingSpheresInView()
.
Note, if this is non-null then it must have length at least numGeometries
, each entry must have length at least 3, and boundingSphereCenterInView
must also be non-null.
public float[] boundingSphereRadiusInView
boundingSphereRadius
in view frame, alloc if desired by
calling ensureBoundingSpheresInView()
.
Note, if this is non-null then it must have length at least numGeometries
, and boundingSphereCenterInView
must also be
non-null.
protected float widgetLength
public JOGLGeometry dbgNormalsGeometry
DBG normal geometry if non-null, see updateDBGNormals(int,
float)
.
public java.nio.FloatBuffer dbgNormalsVertices
dbgNormalsGeometry
, if non-nullpublic JOGLGeometry dbgSpheresGeometry
updateDBGSpheres(int)
public java.nio.FloatBuffer dbgSpheresVertices
dbgSpheresGeometry
, if non-nullpublic boolean dbgEnabled
protected java.util.Map<java.lang.String,java.lang.Object> propertyMap
public Widget(int numGeometries)
Creates a new Widget that will hold the specified number of geometries.
All geometries are initially enabled
and all boundingSphereRadius
are initially negative.
public Widget(javax.media.j3d.Shape3D shape3D, boolean extractToJOGL, int j3dFormatMask, java.io.PrintStream errorStream)
Makes a new Widget by extracting all the GeometryArray
s
of shape3D and its Appearance
, if any.
The extracted geometries, if any, and appearance, if any, are stored by ref. No ref is retained for the shape3D itself.
Bounding spheres are automatically computed for the extracted geometries.
extractToJOGL
- if true then an attempt will be made to JOGLGeometry.extract(javax.media.j3d.GeometryArray, int, java.io.PrintStream)
each GeometryArray
geometry; when successful
the resulting JOGLGeometry
is saved, otherwise the original
geometry is savedj3dFormatMask
- see JOGLGeometry.extract(GeometryArray, int,
PrintStream)
errorStream
- see JOGLGeometry.extract(GeometryArray, int,
PrintStream)
public Widget(javax.media.j3d.Shape3D shape3D, int j3dFormatMask, java.io.PrintStream errorStream)
Widget(Shape3D, boolean, int, PrintStream)
, sets
extractToJOGLpublic Widget(javax.media.j3d.Shape3D shape3D, int j3dFormatMask)
Covers Widget(Shape3D, boolean, int, PrintStream)
, sets
extractToJOGL, no error stream.
public Widget(javax.media.j3d.Shape3D shape3D)
Covers Widget(Shape3D, boolean, int, PrintStream)
, sets
extractToJOGL, no error stream, extracts all vertex components.
public static Widget cons(java.lang.String type)
Generic factory method to construct Widget subclass instances.
type
- identifies a Widget sub-class, i.e. a class vona.j3d.<i>Type</i>Widget
, where Type is type with the
first character, if any, capitalizedjava.lang.IllegalArgumentException
- if type does not identify a
known Widget subclass with a no-arg constructor.java.lang.IllegalStateException
- if there was a problem instantiating the
new Widgetprotected static int countGeometryArrays(javax.media.j3d.Shape3D shape3D)
protected void populateFrom(javax.media.j3d.Shape3D shape3D, boolean extractToJOGL, int j3dFormatMask, java.io.PrintStream errorStream)
public javax.media.j3d.Geometry setGeometry(int index, javax.media.j3d.Geometry geometry)
Set the geometry at the specified index.
This also
J3DPrimitiveIterator
for geometry and
stores it in primitiveIterator
[index], iff geometry
is a JOGLGeometry
or a GeometryArray
J3DVertexAccessor
of the primitive
iterator in vertexAccessor
[index]boundingSphereCenter
and boundingSphereRadius
at
index are not modifiedenabled
[index] iff geometry not nullgeometry
- may be nullpublic javax.media.j3d.Geometry getGeometry(int index)
geometry
at indicated indexpublic javax.media.j3d.Geometry removeGeometry(int index)
Remove (null) geometry
at indicated index.
public int removeGeometry(javax.media.j3d.Geometry geometry)
Remove (null) indicated geometry
, iff found.
public javax.media.j3d.Geometry replaceGeometryWithClone(int index)
Replace the indicated geometry
with a clone of itself.
java.lang.IllegalStateException
- if the geometry is a JOGLGeometry
for which clone is TBDpublic static Widget getWidget(javax.media.j3d.Geometry geometry)
Convenience to get the Widget
containing geometry by
following the user data ref on geometry.
public int indexOf(javax.media.j3d.Geometry geometry)
Lookup the index of geometry in this Widget.
public javax.media.j3d.Appearance setAppearance(int index, javax.media.j3d.Appearance appearance)
Set a the appearance
at indicated index by ref.
public javax.media.j3d.Appearance getAppearance(int index)
appearance
at indicated indexpublic javax.media.j3d.Appearance replaceAppearanceWithClone(int index)
replaceGeometryWithClone(int)
public void setGeometryAndAppearance(int index, javax.media.j3d.Geometry geometry, javax.media.j3d.Appearance appearance)
setGeometry(int, javax.media.j3d.Geometry)
and appearance at the specified indexpublic void setGeometryAlpha(int index, float alpha)
public void setGeometryAlpha(float alpha)
setGeometryAlpha(int, float)
on all geometriespublic void setWidgetAlpha(float alpha)
alpha
public float getWidgetAlpha()
alpha
public void setBoundingSphereRadius(int index, float radius)
boundingSphereRadius
at indexpublic float getBoundingSphereRadius(int index)
boundingSphereRadius
at indexpublic void setBoundingSphereCenter(int index, float... center)
boundingSphereCenter
at index by copypublic float[] getBoundingSphereCenter(int index)
boundingSphereCenter
at indexpublic void disableBoundingSphere(int index)
public void disableBoundingSpheres()
Disable all bounding spheres and turn off autoSetBoundingSpheres
.
public boolean hasBoundingSphere(int index)
Check if the geometry
at index has a non-negative
boundingSphereRadius
.
public boolean hasBoundingSphereInView(int index)
Check if view-frame bounding spheres are allocated and that the
geometry
at index has a n-negative boundingSphereRadiusInView
.
public void ensureBoundingSpheresInView()
Cons boundingSphereCenterInView
and boundingSphereRadiusInView
iff necessary.
public void updateDBGNormals(int upToGeometry, float normalLength)
Create or update the dbgNormalsGeometry
which shows line
segments for each normal in each geometry
.
upToGeometry
- only make dbg normals for geometry up to this index,
or negative to update already exisiting normalsnormalLength
- the length of the normal lines, non-positive to use
DEF_DBG_NORMAL_LENGTH
, NaN to use length of first existing
normal, if anypublic void updateAllDBGNormals(float normalLength)
updateDBGNormals(int, float)
for all geometry
,
creating them if they don't yet exist.
public void updateDBGNormals(int upToGeometry)
public void updateAllDBGNormals()
updateDBGNormals(int, float)
for all geometry
,
creating them if they don't yet exist, using DEF_DBG_NORMAL_LENGTH
.
public void updateExistingDBGNormals()
updateDBGNormals(int, float)
that already exist, using length
of first existing one.
public void removeDBGNormals()
public void updateDBGSpheres(int upToGeometry)
Create or update the dbgSpheresGeometry
which shows the
bounding spheres for each geometry
.
upToGeometry
- only make or update dbg spheres for geometry up to
this index, or negative to only update already existing spheres, if anypublic void updateAllDBGSpheres()
updateDBGSpheres(int)
for all geometry
public void updateExistingDBGSpheres()
updateDBGSpheres(int)
only existingpublic void removeDBGSpheres()
public void enableDBGGeometry(boolean enable)
Enable or disable debug spheres and normals.
You still have to compute them by calling updateDBGNormals(int, float)
and/or updateDBGSpheres(int)
as desired.
public void enableGeometry(int index, boolean enable)
enabled
flag for geometry at indexpublic java.lang.Object setProperty(java.lang.String key, java.lang.Object value, boolean replace)
Set a property.
replace
- whether to replace the value if the key is already presentpublic java.lang.Object setProperty(java.lang.String key, java.lang.Object value)
setProperty(String, Object, boolean)
, replacespublic java.lang.Object removeProperty(java.lang.String key)
public java.lang.Object getProperty(java.lang.String key)
public boolean hasProperty(java.lang.String key)
public void setWidgetLength(float widgetLength)
Set widgetLength
, calls widgetLengthChanged()
iff
different.
public void trackWidgetLength(float... trackFactor)
Subclasses may implement this to store factors that map widgetLength
to their parameters.
Default impl does nothing.
public void dump(java.io.PrintStream s)
public void dump()
dump(PrintStream)
to System.outprotected void widgetLengthChanged()
setWidgetLength(float)
after the length has changedpublic void recomputeBoundingSphere(int index)
Recompute boundingSphereCenter
and boundingSphereRadius
for geometry
at index, using vertexAccessor
at index, if present.
This will change the state of the vertex accessor.
public void recomputeBoundingSpheres()
recomputeBoundingSphere(int)
for each geometry
public void scaleWidget(float scale)
Apply a scale factor in-place to this widget.
Current impl only works if all geometry
are JOGLGeometry
.
java.lang.IllegalStateException
- if any geometry
is not a JOGLGeometry