001: /*
002: * Copyright (c) 2001 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: * @Author: Silvere Martin-Michiellot
032: *
033: */
034:
035: /**
036: * A class that extends the BoundingBox class to provide additional methods. We are only able to compute bounds for BoundingBox, BoundingSphere, BoundingPolytope or their sub-classes.
037: */package com.db.server;
038:
039: import javax.media.j3d.*;
040: import javax.vecmath.*;
041:
042: public class ExtendedBoundingBox extends BoundingBox implements
043: ExtendedBounds {
044:
045: private BoundingBox boundingBox;
046:
047: public ExtendedBoundingBox() {
048:
049: super ();
050:
051: }
052:
053: public ExtendedBoundingBox(Bounds boundsObject) {
054:
055: super (boundsObject);
056:
057: }
058:
059: public ExtendedBoundingBox(Bounds[] bounds) {
060:
061: super (bounds);
062:
063: }
064:
065: public ExtendedBoundingBox(Point3d lower, Point3d upper) {
066:
067: super (lower, upper);
068:
069: }
070:
071: public double getVolume() {
072:
073: Point3d lower;
074: Point3d upper;
075:
076: lower = new Point3d();
077: upper = new Point3d();
078:
079: this .getLower(lower);
080: this .getUpper(upper);
081:
082: return (upper.x - lower.x) * (upper.y - lower.y)
083: * (upper.z - lower.z);
084:
085: }
086:
087: public boolean contains(Point3d point3d) {
088:
089: BoundingBox boundingBoxPoint3d;
090: double delta;
091:
092: delta = 0.00001;
093:
094: boundingBoxPoint3d = new BoundingBox(new Point3d(point3d.x
095: - delta, point3d.y - delta, point3d.z - delta),
096: new Point3d(point3d.x + delta, point3d.y + delta,
097: point3d.z + delta));
098:
099: return contains(boundingBoxPoint3d);
100:
101: }
102:
103: public boolean contains(Bounds bounds) {
104:
105: Bounds[] boundsArray;
106:
107: boundsArray = new Bounds[1];
108: boundsArray[0] = bounds;
109:
110: return contains(boundsArray);
111:
112: }
113:
114: public boolean contains(Bounds[] bounds) {
115:
116: BoundingBox aBoundingBox;
117: Point3d lower1;
118: Point3d upper1;
119: Point3d lower2;
120: Point3d upper2;
121:
122: aBoundingBox = new BoundingBox(bounds);
123:
124: lower1 = new Point3d();
125: upper1 = new Point3d();
126: lower2 = new Point3d();
127: upper2 = new Point3d();
128:
129: this .getLower(lower1);
130: this .getUpper(upper1);
131:
132: aBoundingBox.getLower(lower2);
133: aBoundingBox.getUpper(upper2);
134:
135: return ((lower1.x < lower2.x) && (lower1.y < lower2.y)
136: && (lower1.y < lower2.y) && (upper1.x > upper2.x)
137: && (upper1.y > upper2.y) && (upper1.z > upper2.z));
138:
139: }
140:
141: public Bounds subtract(Bounds bounds) {
142:
143: Bounds[] boundsArray;
144:
145: boundsArray = new Bounds[1];
146: boundsArray[0] = bounds;
147:
148: return subtract(boundsArray);
149:
150: }
151:
152: //this object remains unaffected by the operation
153: public Bounds subtract(Bounds[] bounds) {
154:
155: BoundingBox aBoundingBox;
156: Point3d lower1;
157: Point3d upper1;
158: Point3d lower2;
159: Point3d upper2;
160: Point3d lower3;
161: Point3d upper3;
162: BoundingBox newBounds;
163: int i;
164: BoundingBox[] newBoundsArray;
165:
166: aBoundingBox = new BoundingBox(bounds);
167:
168: lower1 = new Point3d();
169: upper1 = new Point3d();
170: lower2 = new Point3d();
171: upper2 = new Point3d();
172:
173: this .getLower(lower1);
174: this .getUpper(upper1);
175:
176: aBoundingBox.getLower(lower2);
177: aBoundingBox.getUpper(upper2);
178:
179: //ugly but fast
180: i = 0;
181: if ((lower2.x > lower1.x) && (lower2.x < upper1.x)) {
182: i++;
183: }
184: if ((upper2.x > lower1.x) && (upper2.x < upper1.x)) {
185: i++;
186: }
187: if ((lower2.y > lower1.y) && (lower2.y < upper1.y)) {
188: i++;
189: }
190: if ((upper2.y > lower1.y) && (upper2.y < upper1.y)) {
191: i++;
192: }
193: if ((lower2.z > lower1.z) && (lower2.z < upper1.z)) {
194: i++;
195: }
196: if ((upper2.z > lower1.z) && (upper2.z < upper1.z)) {
197: i++;
198: }
199:
200: newBoundsArray = new BoundingBox[i];
201: i = 0;
202:
203: newBounds = new BoundingBox();
204:
205: if ((lower2.x > lower1.x) && (lower2.x < upper1.x)) {
206: lower3 = new Point3d(lower1.x,
207: Math.max(lower1.y, lower2.y), Math.max(lower1.z,
208: lower2.z));
209: upper3 = new Point3d(lower2.x,
210: Math.min(upper1.y, upper2.y), Math.min(upper1.z,
211: upper2.z));
212: newBounds = new BoundingBox(lower3, upper3);
213: newBoundsArray[i] = newBounds;
214: i++;
215: }
216: if ((upper2.x > lower1.x) && (upper2.x < upper1.x)) {
217: lower3 = new Point3d(upper2.x,
218: Math.max(lower1.y, lower2.y), Math.max(lower1.z,
219: lower2.z));
220: upper3 = new Point3d(upper1.x,
221: Math.min(upper1.y, upper2.y), Math.min(upper1.z,
222: upper2.z));
223: newBounds = new BoundingBox(lower3, upper3);
224: newBoundsArray[i] = newBounds;
225: i++;
226: }
227: if ((lower2.y > lower1.y) && (lower2.y < upper1.y)) {
228: lower3 = new Point3d(Math.max(lower1.x, lower2.x),
229: lower1.y, Math.max(lower1.z, lower2.z));
230: upper3 = new Point3d(Math.min(upper1.x, upper2.x),
231: lower2.y, Math.min(upper1.z, upper2.z));
232: newBounds = new BoundingBox(lower3, upper3);
233: newBoundsArray[i] = newBounds;
234: i++;
235: }
236: if ((upper2.y > lower1.y) && (upper2.y < upper1.y)) {
237: lower3 = new Point3d(Math.max(lower1.x, lower2.x),
238: upper2.y, Math.max(lower1.z, lower2.z));
239: upper3 = new Point3d(Math.min(upper1.x, upper2.x),
240: upper1.y, Math.min(upper1.z, upper2.z));
241: newBounds = new BoundingBox(lower3, upper3);
242: newBoundsArray[i] = newBounds;
243: i++;
244: }
245: if ((lower2.z > lower1.z) && (lower2.z < upper1.z)) {
246: lower3 = new Point3d(Math.max(lower1.x, lower2.x), Math
247: .max(lower1.y, lower2.y), lower1.z);
248: upper3 = new Point3d(Math.min(upper1.x, upper2.x), Math
249: .min(upper1.y, upper2.y), lower2.z);
250: newBounds = new BoundingBox(lower3, upper3);
251: newBoundsArray[i] = newBounds;
252: i++;
253: }
254: if ((upper2.z > lower1.z) && (upper2.z < upper1.z)) {
255: lower3 = new Point3d(Math.max(lower1.x, lower2.x), Math
256: .max(lower1.y, lower2.y), upper2.z);
257: upper3 = new Point3d(Math.min(upper1.x, upper2.x), Math
258: .min(upper1.y, upper2.y), upper1.z);
259: newBounds = new BoundingBox(lower3, upper3);
260: newBoundsArray[i] = newBounds;
261: i++;
262: }
263:
264: return newBounds;
265:
266: }
267:
268: }
|