/* * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code 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 * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. * */ package javax.media.j3d; import java.util.ArrayList; import java.util.Enumeration; import java.util.Vector; /** * A Locale object defines a high-resolution position within a * VirtualUniverse, and serves as a container for a collection of * BranchGroup-rooted subgraphs (branch graphs), at that position. * Objects within a Locale are defined using standard double-precision * coordinates, relative to the origin of the Locale. This origin * defines the Virtual World coordinate system for that Locale. *
* A Locale object defines methods to set and get its high-resolution * coordinates, and methods to add, remove, and enumerate the branch * graphs. * *
* For more information, see the
* Introduction to the Java 3D API and
* Scene Graph Superstructure
* documents.
*
* @see VirtualUniverse
* @see HiResCoord
* @see BranchGroup
*/
public class Locale extends Object {
/**
* The virtual universe that this Locale object is contained within.
*/
VirtualUniverse universe;
/**
* The high resolution coordinate associated with this Locale object.
*/
HiResCoord hiRes;
/**
* List of BranchGroup objects included in this Locale
*/
VectorLocale
that intersect with PickShape.
* The resultant array is unordered.
*
* @param pickShape the description of this picking volume or area.
*
* @exception IllegalStateException if this Locale has been
* removed from its VirtualUniverse.
*
* @see BranchGroup#pickAll
*/
public SceneGraphPath[] pickAll( PickShape pickShape ) {
if (universe == null) {
throw new IllegalStateException(J3dI18N.getString("Locale4"));
}
PickInfo[] pickInfoArr = pickAll( PickInfo.PICK_BOUNDS,
PickInfo.SCENEGRAPHPATH, pickShape);
if(pickInfoArr == null) {
return null;
}
SceneGraphPath[] sgpArr = new SceneGraphPath[pickInfoArr.length];
for( int i=0; iPickInfo.PICK_BOUNDS
or PickInfo.PICK_GEOMETRY
.
*
* @param flags a mask indicating which components are present in each PickInfo object.
* This is specified as one or more individual bits that are bitwise "OR"ed together to
* describe the PickInfo data. The flags include :
*
*
*
* @param pickShape the description of this picking volume or area.
*
* @exception IllegalArgumentException if flags contains both CLOSEST_GEOM_INFO and
* ALL_GEOM_INFO.
*
* @exception IllegalArgumentException if pickShape is a PickPoint and pick mode
* is set to PICK_GEOMETRY.
*
* @exception IllegalArgumentException if pick mode is neither PICK_BOUNDS
* nor PICK_GEOMETRY.
*
* @exception IllegalArgumentException if pick mode is PICK_BOUNDS
* and flags includes any of CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE,
* CLOSEST_GEOM_INFO or ALL_GEOM_INFO.
*
* @exception IllegalArgumentException if pickShape is PickBounds
* and flags includes any of CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE,
* CLOSEST_GEOM_INFO or ALL_GEOM_INFO.
*
* @exception IllegalStateException if this Locale has been
* removed from its VirtualUniverse.
*
* @exception CapabilityNotSetException if the mode is
* PICK_GEOMETRY and the Geometry.ALLOW_INTERSECT capability bit
* is not set in any Geometry objects referred to by any shape
* node whose bounds intersects the PickShape.
*
* @exception CapabilityNotSetException if flags contains any of
* CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE, CLOSEST_GEOM_INFO
* or ALL_GEOM_INFO, and the capability bits that control reading of
* coordinate data are not set in any GeometryArray object referred
* to by any shape node that intersects the PickShape.
* The capability bits that must be set to avoid this exception are as follows :
* PickInfo.SCENEGRAPHPATH
- request for computed SceneGraphPath.
* PickInfo.NODE
- request for computed intersected Node.
* PickInfo.LOCAL_TO_VWORLD
- request for computed local to virtual world transform.
* PickInfo.CLOSEST_INTERSECTION_POINT
- request for closest intersection point.
* PickInfo.CLOSEST_DISTANCE
- request for the distance of closest intersection.
* PickInfo.CLOSEST_GEOM_INFO
- request for only the closest intersection geometry information.
* PickInfo.ALL_GEOM_INFO
- request for all intersection geometry information.
*
*
*
* @see BranchGroup#pickAll(int,int,javax.media.j3d.PickShape)
* @see PickInfo
*
* @since Java 3D 1.4
*
*/
public PickInfo[] pickAll( int mode, int flags, PickShape pickShape ) {
validateModeFlagAndPickShape(mode, flags, pickShape);
GeometryAtom geomAtoms[] = universe.geometryStructure.pickAll(this, pickShape);
return PickInfo.pick(this, geomAtoms, mode, flags, pickShape, PickInfo.PICK_ALL);
}
/**
* Returns a sorted array of references to all the pickable items
* that intersect with the pickShape. Element [0] references the
* item closest to origin of PickShape successive array
* elements are further from the origin
*
* NOTE: If pickShape is of type PickBounds, the resulting array
* is unordered.
*
* @param pickShape the description of this picking volume or area.
*
* @exception IllegalStateException if this Locale has been
* removed from its VirtualUniverse.
*
* @see BranchGroup#pickAllSorted
*/
public SceneGraphPath[] pickAllSorted( PickShape pickShape ) {
if (universe == null) {
throw new IllegalStateException(J3dI18N.getString("Locale4"));
}
PickInfo[] pickInfoArr = pickAllSorted( PickInfo.PICK_BOUNDS,
PickInfo.SCENEGRAPHPATH, pickShape);
if(pickInfoArr == null) {
return null;
}
SceneGraphPath[] sgpArr = new SceneGraphPath[pickInfoArr.length];
for( int i=0; iPickInfo.PICK_BOUNDS
or PickInfo.PICK_GEOMETRY
.
*
* @param flags a mask indicating which components are present in each PickInfo object.
* This is specified as one or more individual bits that are bitwise "OR"ed together to
* describe the PickInfo data. The flags include :
*
*
*
* @param pickShape the description of this picking volume or area.
*
* @exception IllegalArgumentException if flags contains both CLOSEST_GEOM_INFO and
* ALL_GEOM_INFO.
*
* @exception IllegalArgumentException if pickShape is a PickPoint and pick mode
* is set to PICK_GEOMETRY.
*
* @exception IllegalArgumentException if pick mode is neither PICK_BOUNDS
* nor PICK_GEOMETRY.
*
* @exception IllegalArgumentException if pick mode is PICK_BOUNDS
* and flags includes any of CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE,
* CLOSEST_GEOM_INFO or ALL_GEOM_INFO.
*
* @exception IllegalArgumentException if pickShape is PickBounds
* and flags includes any of CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE,
* CLOSEST_GEOM_INFO or ALL_GEOM_INFO.
*
* @exception IllegalStateException if this Locale has been
* removed from its VirtualUniverse.
*
* @exception CapabilityNotSetException if the mode is
* PICK_GEOMETRY and the Geometry.ALLOW_INTERSECT capability bit
* is not set in any Geometry objects referred to by any shape
* node whose bounds intersects the PickShape.
*
* @exception CapabilityNotSetException if flags contains any of
* CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE, CLOSEST_GEOM_INFO
* or ALL_GEOM_INFO, and the capability bits that control reading of
* coordinate data are not set in any GeometryArray object referred
* to by any shape node that intersects the PickShape.
* The capability bits that must be set to avoid this exception are as follows :
* PickInfo.SCENEGRAPHPATH
- request for computed SceneGraphPath.
* PickInfo.NODE
- request for computed intersected Node.
* PickInfo.LOCAL_TO_VWORLD
- request for computed local to virtual world transform.
* PickInfo.CLOSEST_INTERSECTION_POINT
- request for closest intersection point.
* PickInfo.CLOSEST_DISTANCE
- request for the distance of closest intersection.
* PickInfo.CLOSEST_GEOM_INFO
- request for only the closest intersection geometry information.
* PickInfo.ALL_GEOM_INFO
- request for all intersection geometry information.
*
*
*
* @see BranchGroup#pickAllSorted(int,int,javax.media.j3d.PickShape)
* @see PickInfo
*
* @since Java 3D 1.4
*
*/
public PickInfo[] pickAllSorted( int mode, int flags, PickShape pickShape ) {
validateModeFlagAndPickShape(mode, flags, pickShape);
GeometryAtom geomAtoms[] = universe.geometryStructure.pickAll(this, pickShape);
if ((geomAtoms == null) || (geomAtoms.length == 0)) {
return null;
}
PickInfo[] pickInfoArr = null;
if (mode == PickInfo.PICK_GEOMETRY) {
// Need to have closestDistance set
flags |= PickInfo.CLOSEST_DISTANCE;
pickInfoArr= PickInfo.pick(this, geomAtoms, mode, flags, pickShape, PickInfo.PICK_ALL);
if (pickInfoArr != null) {
PickInfo.sortPickInfoArray(pickInfoArr);
}
}
else {
PickInfo.sortGeomAtoms(geomAtoms, pickShape);
pickInfoArr= PickInfo.pick(this, geomAtoms, mode, flags, pickShape, PickInfo.PICK_ALL);
}
return pickInfoArr;
}
/**
* Returns a SceneGraphPath which references the pickable item
* which is closest to the origin of pickShape
.
*
* NOTE: If pickShape is of type PickBounds, the return is any
* pickable node below this Locale.
*
* @param pickShape the description of this picking volume or area.
*
* @exception IllegalStateException if this Locale has been
* removed from its VirtualUniverse.
*
* @see BranchGroup#pickClosest
*/
public SceneGraphPath pickClosest( PickShape pickShape ) {
if (universe == null) {
throw new IllegalStateException(J3dI18N.getString("Locale4"));
}
PickInfo pickInfo = pickClosest( PickInfo.PICK_BOUNDS,
PickInfo.SCENEGRAPHPATH, pickShape);
if(pickInfo == null) {
return null;
}
return pickInfo.getSceneGraphPath();
}
/**
* Returns a PickInfo which references the pickable item
* which is closest to the origin of pickShape
.
* The accuracy of the pick is set by the pick mode. The mode include :
* PickInfo.PICK_BOUNDS and PickInfo.PICK_GEOMETRY. The amount of information returned
* is specified via a masked variable, flags, indicating which components are
* present in each returned PickInfo object.
*
* @param mode picking mode, one of PickInfo.PICK_BOUNDS
or PickInfo.PICK_GEOMETRY
.
*
* @param flags a mask indicating which components are present in each PickInfo object.
* This is specified as one or more individual bits that are bitwise "OR"ed together to
* describe the PickInfo data. The flags include :
*
*
*
* @param pickShape the description of this picking volume or area.
*
* @exception IllegalArgumentException if flags contains both CLOSEST_GEOM_INFO and
* ALL_GEOM_INFO.
*
* @exception IllegalArgumentException if pickShape is a PickPoint and pick mode
* is set to PICK_GEOMETRY.
*
* @exception IllegalArgumentException if pick mode is neither PICK_BOUNDS
* nor PICK_GEOMETRY.
*
* @exception IllegalArgumentException if pick mode is PICK_BOUNDS
* and flags includes any of CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE,
* CLOSEST_GEOM_INFO or ALL_GEOM_INFO.
*
* @exception IllegalArgumentException if pickShape is PickBounds
* and flags includes any of CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE,
* CLOSEST_GEOM_INFO or ALL_GEOM_INFO.
*
* @exception IllegalStateException if this Locale has been
* removed from its VirtualUniverse.
*
* @exception CapabilityNotSetException if the mode is
* PICK_GEOMETRY and the Geometry.ALLOW_INTERSECT capability bit
* is not set in any Geometry objects referred to by any shape
* node whose bounds intersects the PickShape.
*
* @exception CapabilityNotSetException if flags contains any of
* CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE, CLOSEST_GEOM_INFO
* or ALL_GEOM_INFO, and the capability bits that control reading of
* coordinate data are not set in any GeometryArray object referred
* to by any shape node that intersects the PickShape.
* The capability bits that must be set to avoid this exception are as follows :
* PickInfo.SCENEGRAPHPATH
- request for computed SceneGraphPath.
* PickInfo.NODE
- request for computed intersected Node.
* PickInfo.LOCAL_TO_VWORLD
- request for computed local to virtual world transform.
* PickInfo.CLOSEST_INTERSECTION_POINT
- request for closest intersection point.
* PickInfo.CLOSEST_DISTANCE
- request for the distance of closest intersection.
* PickInfo.CLOSEST_GEOM_INFO
- request for only the closest intersection geometry information.
* PickInfo.ALL_GEOM_INFO
- request for all intersection geometry information.
*
*
*
* @see BranchGroup#pickClosest(int,int,javax.media.j3d.PickShape)
* @see PickInfo
*
* @since Java 3D 1.4
*
*/
public PickInfo pickClosest( int mode, int flags, PickShape pickShape ) {
PickInfo[] pickInfoArr = null;
pickInfoArr = pickAllSorted( mode, flags, pickShape );
if(pickInfoArr == null) {
return null;
}
return pickInfoArr[0];
}
/**
* Returns a reference to any item that is Pickable below this
* Locale which intersects with pickShape
.
*
* @param pickShape the description of this picking volume or area.
*
* @exception IllegalStateException if this Locale has been
* removed from its VirtualUniverse.
*
* @see BranchGroup#pickAny
*/
public SceneGraphPath pickAny( PickShape pickShape ) {
if (universe == null) {
throw new IllegalStateException(J3dI18N.getString("Locale4"));
}
PickInfo pickInfo = pickAny( PickInfo.PICK_BOUNDS,
PickInfo.SCENEGRAPHPATH, pickShape);
if(pickInfo == null) {
return null;
}
return pickInfo.getSceneGraphPath();
}
/**
* Returns a PickInfo which references the pickable item below this
* Locale which intersects with pickShape
.
* The accuracy of the pick is set by the pick mode. The mode include :
* PickInfo.PICK_BOUNDS and PickInfo.PICK_GEOMETRY. The amount of information returned
* is specified via a masked variable, flags, indicating which components are
* present in each returned PickInfo object.
*
* @param mode picking mode, one of PickInfo.PICK_BOUNDS
or PickInfo.PICK_GEOMETRY
.
*
* @param flags a mask indicating which components are present in each PickInfo object.
* This is specified as one or more individual bits that are bitwise "OR"ed together to
* describe the PickInfo data. The flags include :
*
*
*
* @param pickShape the description of this picking volume or area.
*
* @exception IllegalArgumentException if flags contains both CLOSEST_GEOM_INFO and
* ALL_GEOM_INFO.
*
* @exception IllegalArgumentException if pickShape is a PickPoint and pick mode
* is set to PICK_GEOMETRY.
*
* @exception IllegalArgumentException if pick mode is neither PICK_BOUNDS
* nor PICK_GEOMETRY.
*
* @exception IllegalArgumentException if pick mode is PICK_BOUNDS
* and flags includes any of CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE,
* CLOSEST_GEOM_INFO or ALL_GEOM_INFO.
*
* @exception IllegalArgumentException if pickShape is PickBounds
* and flags includes any of CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE,
* CLOSEST_GEOM_INFO or ALL_GEOM_INFO.
*
* @exception IllegalStateException if this Locale has been
* removed from its VirtualUniverse.
*
* @exception CapabilityNotSetException if the mode is
* PICK_GEOMETRY and the Geometry.ALLOW_INTERSECT capability bit
* is not set in any Geometry objects referred to by any shape
* node whose bounds intersects the PickShape.
*
* @exception CapabilityNotSetException if flags contains any of
* CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE, CLOSEST_GEOM_INFO
* or ALL_GEOM_INFO, and the capability bits that control reading of
* coordinate data are not set in any GeometryArray object referred
* to by any shape node that intersects the PickShape.
* The capability bits that must be set to avoid this exception are as follows :
* PickInfo.SCENEGRAPHPATH
- request for computed SceneGraphPath.
* PickInfo.NODE
- request for computed intersected Node.
* PickInfo.LOCAL_TO_VWORLD
- request for computed local to virtual world transform.
* PickInfo.CLOSEST_INTERSECTION_POINT
- request for closest intersection point.
* PickInfo.CLOSEST_DISTANCE
- request for the distance of closest intersection.
* PickInfo.CLOSEST_GEOM_INFO
- request for only the closest intersection geometry information.
* PickInfo.ALL_GEOM_INFO
- request for all intersection geometry information.
*
*
*
* @see BranchGroup#pickAny(int,int,javax.media.j3d.PickShape)
* @see PickInfo
*
* @since Java 3D 1.4
*
*/
public PickInfo pickAny( int mode, int flags, PickShape pickShape ) {
validateModeFlagAndPickShape(mode, flags, pickShape);
GeometryAtom geomAtoms[] = universe.geometryStructure.pickAll(this, pickShape);
PickInfo[] pickInfoArr = PickInfo.pick(this, geomAtoms, mode, flags, pickShape, PickInfo.PICK_ANY);
if(pickInfoArr == null) {
return null;
}
return pickInfoArr[0];
}
}