00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "boundingVolume.h"
00016 #include "finiteBoundingVolume.h"
00017 #include "unionBoundingVolume.h"
00018 #include "intersectionBoundingVolume.h"
00019
00020 #include "indent.h"
00021
00022 TypeHandle BoundingVolume::_type_handle;
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 bool BoundingVolume::
00033 around(const BoundingVolume **first, const BoundingVolume **last) {
00034 _flags = F_empty;
00035
00036
00037
00038 while (first != last && (*first)->is_empty()) {
00039 if ((*first)->is_infinite()) {
00040
00041 _flags = F_infinite;
00042 return true;
00043 }
00044 ++first;
00045 }
00046
00047 bool okflag = true;
00048
00049 if (first != last) {
00050
00051 const BoundingVolume **bvi;
00052 for (bvi = first; bvi != last; ++bvi) {
00053 if ((*bvi)->is_infinite()) {
00054 _flags = F_infinite;
00055 return true;
00056 }
00057 }
00058
00059
00060
00061
00062
00063 if (!(*first)->around_other(this, first, last)) {
00064 okflag = false;
00065 }
00066 }
00067
00068 return okflag;
00069 }
00070
00071
00072
00073
00074
00075
00076 void BoundingVolume::
00077 write(ostream &out, int indent_level) const {
00078 indent(out, indent_level) << *this << "\n";
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088 const GeometricBoundingVolume *BoundingVolume::
00089 as_geometric_bounding_volume() const {
00090 return NULL;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100 const FiniteBoundingVolume *BoundingVolume::
00101 as_finite_bounding_volume() const {
00102 return NULL;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112 const BoundingSphere *BoundingVolume::
00113 as_bounding_sphere() const {
00114 return NULL;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124 const BoundingBox *BoundingVolume::
00125 as_bounding_box() const {
00126 return NULL;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136 const BoundingHexahedron *BoundingVolume::
00137 as_bounding_hexahedron() const {
00138 return NULL;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148 const BoundingLine *BoundingVolume::
00149 as_bounding_line() const {
00150 return NULL;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160 const BoundingPlane *BoundingVolume::
00161 as_bounding_plane() const {
00162 return NULL;
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 BoundingVolume::BoundsType BoundingVolume::
00172 string_bounds_type(const string &str) {
00173 if (strcmp(str.c_str(), "default") == 0) {
00174 return BT_default;
00175
00176 } else if (strcmp(str.c_str(), "best") == 0) {
00177 return BT_best;
00178
00179 } else if (strcmp(str.c_str(), "sphere") == 0) {
00180 return BT_sphere;
00181
00182 } else if (strcmp(str.c_str(), "box") == 0) {
00183 return BT_box;
00184 }
00185
00186 return BT_default;
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196 bool BoundingVolume::
00197 extend_by_sphere(const BoundingSphere *sphere) {
00198 return extend_by_finite(sphere);
00199 }
00200
00201
00202
00203
00204
00205
00206
00207
00208 bool BoundingVolume::
00209 extend_by_box(const BoundingBox *box) {
00210 return extend_by_finite(box);
00211 }
00212
00213
00214
00215
00216
00217
00218
00219
00220 bool BoundingVolume::
00221 extend_by_hexahedron(const BoundingHexahedron *hexahedron) {
00222 return extend_by_finite(hexahedron);
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232 bool BoundingVolume::
00233 extend_by_line(const BoundingLine *line) {
00234 return extend_by_geometric(line);
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244 bool BoundingVolume::
00245 extend_by_plane(const BoundingPlane *plane) {
00246 return extend_by_geometric(plane);
00247 }
00248
00249
00250
00251
00252
00253
00254
00255
00256 bool BoundingVolume::
00257 extend_by_union(const UnionBoundingVolume *unionv) {
00258 return extend_by_geometric(unionv);
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268 bool BoundingVolume::
00269 extend_by_intersection(const IntersectionBoundingVolume *intersection) {
00270 return extend_by_geometric(intersection);
00271 }
00272
00273
00274
00275
00276
00277
00278 bool BoundingVolume::
00279 extend_by_finite(const FiniteBoundingVolume *volume) {
00280 return extend_by_geometric(volume);
00281 }
00282
00283
00284
00285
00286
00287
00288 bool BoundingVolume::
00289 extend_by_geometric(const GeometricBoundingVolume *volume) {
00290 mathutil_cat.warning()
00291 << get_type() << "::extend_by_geometric() called with " << volume->get_type() << "\n";
00292 _flags = F_infinite;
00293 return false;
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303 bool BoundingVolume::
00304 around_spheres(const BoundingVolume **first, const BoundingVolume **last) {
00305 return around_finite(first, last);
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315 bool BoundingVolume::
00316 around_boxes(const BoundingVolume **first, const BoundingVolume **last) {
00317 return around_finite(first, last);
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327 bool BoundingVolume::
00328 around_hexahedrons(const BoundingVolume **first, const BoundingVolume **last) {
00329 return around_finite(first, last);
00330 }
00331
00332
00333
00334
00335
00336
00337
00338
00339 bool BoundingVolume::
00340 around_lines(const BoundingVolume **first, const BoundingVolume **last) {
00341 return around_geometric(first, last);
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351 bool BoundingVolume::
00352 around_planes(const BoundingVolume **first, const BoundingVolume **last) {
00353 return around_geometric(first, last);
00354 }
00355
00356
00357
00358
00359
00360
00361
00362
00363 bool BoundingVolume::
00364 around_unions(const BoundingVolume **first, const BoundingVolume **last) {
00365 return around_geometric(first, last);
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375 bool BoundingVolume::
00376 around_intersections(const BoundingVolume **first, const BoundingVolume **last) {
00377 return around_geometric(first, last);
00378 }
00379
00380
00381
00382
00383
00384
00385 bool BoundingVolume::
00386 around_finite(const BoundingVolume **first, const BoundingVolume **last) {
00387 return around_geometric(first, last);
00388 }
00389
00390
00391
00392
00393
00394
00395 bool BoundingVolume::
00396 around_geometric(const BoundingVolume **first, const BoundingVolume **last) {
00397 mathutil_cat.warning()
00398 << get_type() << "::extend_by_geometric() called with " << first[0]->get_type() << "\n";
00399 _flags = F_infinite;
00400 return false;
00401 }
00402
00403
00404
00405
00406
00407
00408
00409
00410 int BoundingVolume::
00411 contains_sphere(const BoundingSphere *sphere) const {
00412 return contains_finite(sphere);
00413 }
00414
00415
00416
00417
00418
00419
00420
00421
00422 int BoundingVolume::
00423 contains_box(const BoundingBox *box) const {
00424 return contains_finite(box);
00425 }
00426
00427
00428
00429
00430
00431
00432
00433
00434 int BoundingVolume::
00435 contains_hexahedron(const BoundingHexahedron *hexahedron) const {
00436 return contains_finite(hexahedron);
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446 int BoundingVolume::
00447 contains_line(const BoundingLine *line) const {
00448 return contains_geometric(line);
00449 }
00450
00451
00452
00453
00454
00455
00456
00457
00458 int BoundingVolume::
00459 contains_plane(const BoundingPlane *plane) const {
00460 return contains_geometric(plane);
00461 }
00462
00463
00464
00465
00466
00467
00468
00469
00470 int BoundingVolume::
00471 contains_union(const UnionBoundingVolume *unionv) const {
00472 return unionv->other_contains_union(this);
00473 }
00474
00475
00476
00477
00478
00479
00480
00481
00482 int BoundingVolume::
00483 contains_intersection(const IntersectionBoundingVolume *intersection) const {
00484 return intersection->other_contains_intersection(this);
00485 }
00486
00487
00488
00489
00490
00491
00492 int BoundingVolume::
00493 contains_finite(const FiniteBoundingVolume *volume) const {
00494 return contains_geometric(volume);
00495 }
00496
00497
00498
00499
00500
00501
00502 int BoundingVolume::
00503 contains_geometric(const GeometricBoundingVolume *volume) const {
00504 mathutil_cat.warning()
00505 << get_type() << "::contains_geometric() called with " << volume->get_type() << "\n";
00506 return IF_dont_understand;
00507 }
00508
00509 ostream &
00510 operator << (ostream &out, BoundingVolume::BoundsType type) {
00511 switch (type) {
00512 case BoundingVolume::BT_default:
00513 return out << "default";
00514
00515 case BoundingVolume::BT_best:
00516 return out << "best";
00517
00518 case BoundingVolume::BT_sphere:
00519 return out << "sphere";
00520
00521 case BoundingVolume::BT_box:
00522 return out << "box";
00523 }
00524
00525 mathutil_cat.error()
00526 << "Invalid BoundingVolume::BoundsType value: " << (int)type << "\n";
00527 nassertr(false, out);
00528 return out;
00529 }
00530
00531 istream &
00532 operator >> (istream &in, BoundingVolume::BoundsType &type) {
00533 string word;
00534 in >> word;
00535 type = BoundingVolume::string_bounds_type(word);
00536 if (type == BoundingVolume::BT_default) {
00537 mathutil_cat->error()
00538 << "Invalid BoundingVolume::BoundsType string: " << word << "\n";
00539 }
00540 return in;
00541 }
00542