15 #include "intersectionBoundingVolume.h"
16 #include "unionBoundingVolume.h"
17 #include "config_mathutil.h"
20 TypeHandle IntersectionBoundingVolume::_type_handle;
30 _components(copy._components)
49 LPoint3 IntersectionBoundingVolume::
50 get_approx_center()
const {
55 for (Components::const_iterator ci = _components.begin();
56 ci != _components.end();
58 center += (*ci)->get_approx_center();
61 return center / (PN_stdfloat)_components.size();
69 void IntersectionBoundingVolume::
73 for (Components::iterator ci = _components.begin();
74 ci != _components.end();
88 output(ostream &out)
const {
90 out <<
"intersection, empty";
92 out <<
"intersection, infinite";
94 out <<
"intersection [";
95 for (Components::const_iterator ci = _components.begin();
96 ci != _components.end();
109 void IntersectionBoundingVolume::
110 write(ostream &out,
int indent_level)
const {
112 indent(out, indent_level) <<
"intersection, empty\n";
114 indent(out, indent_level) <<
"intersection, infinite\n";
116 indent(out, indent_level) <<
"intersection {\n";
117 for (Components::const_iterator ci = _components.begin();
118 ci != _components.end();
120 (*ci)->write(out, indent_level + 2);
122 indent(out, indent_level) <<
"}\n";
150 CPT(GeometricBoundingVolume) gbv;
152 if (component->
is_exact_type(UnionBoundingVolume::get_class_type())) {
158 unionv->filter_intersection(
this);
163 if (unionv->get_num_components() == 1) {
165 gbv = unionv->get_component(0);
178 }
else if (component->
is_exact_type(IntersectionBoundingVolume::get_class_type())) {
181 for (Components::const_iterator ci = other->_components.begin();
182 ci != other->_components.end();
190 while (i < _components.size()) {
191 const GeometricBoundingVolume *existing = _components[i];
194 int result = component->
contains(existing);
195 if ((result & IF_all) != 0) {
200 }
else if (result == 0) {
207 result = existing->
contains(component);
208 if ((result & IF_all) != 0) {
212 _components.erase(_components.begin() + i);
214 }
else if (result == 0) {
222 _flags &= ~F_infinite;
223 _components.push_back(component);
232 bool IntersectionBoundingVolume::
234 return other->extend_by_intersection(
this);
242 bool IntersectionBoundingVolume::
246 return other->around_intersections(first, last);
254 int IntersectionBoundingVolume::
256 return other->contains_intersection(
this);
264 int IntersectionBoundingVolume::
265 contains_point(
const LPoint3 &point)
const {
266 nassertr(!point.
is_nan(), IF_no_intersection);
268 int result = IF_possible | IF_some | IF_all;
269 for (Components::const_iterator ci = _components.begin();
270 ci != _components.end();
272 int this_result = (*ci)->contains(point);
273 if ((this_result & IF_dont_understand) != 0) {
274 result |= IF_dont_understand;
277 result &= this_result;
278 if ((result & IF_possible) == 0) {
292 int IntersectionBoundingVolume::
294 nassertr(!a.
is_nan() && !b.
is_nan(), IF_no_intersection);
296 int result = IF_possible | IF_some | IF_all;
297 for (Components::const_iterator ci = _components.begin();
298 ci != _components.end();
300 int this_result = (*ci)->contains(a, b);
301 if ((this_result & IF_dont_understand) != 0) {
302 result |= IF_dont_understand;
305 result &= this_result;
306 if ((result & IF_possible) == 0) {
322 int IntersectionBoundingVolume::
324 int result = IF_possible | IF_some | IF_all;
325 for (Components::const_iterator ci = _components.begin();
326 ci != _components.end();
328 int this_result = (*ci)->contains_sphere(sphere);
329 if ((this_result & IF_dont_understand) != 0) {
330 result |= IF_dont_understand;
333 result &= this_result;
334 if ((result & IF_possible) == 0) {
350 int IntersectionBoundingVolume::
352 int result = IF_possible | IF_some | IF_all;
353 for (Components::const_iterator ci = _components.begin();
354 ci != _components.end();
356 int this_result = (*ci)->contains_box(box);
357 if ((this_result & IF_dont_understand) != 0) {
358 result |= IF_dont_understand;
361 result &= this_result;
362 if ((result & IF_possible) == 0) {
378 int IntersectionBoundingVolume::
380 int result = IF_possible | IF_some | IF_all;
381 for (Components::const_iterator ci = _components.begin();
382 ci != _components.end();
384 int this_result = (*ci)->contains_hexahedron(hexahedron);
385 if ((this_result & IF_dont_understand) != 0) {
386 result |= IF_dont_understand;
389 result &= this_result;
390 if ((result & IF_possible) == 0) {
406 int IntersectionBoundingVolume::
408 int result = IF_possible | IF_some | IF_all;
409 for (Components::const_iterator ci = _components.begin();
410 ci != _components.end();
412 int this_result = (*ci)->contains_line(line);
413 if ((this_result & IF_dont_understand) != 0) {
414 result |= IF_dont_understand;
417 result &= this_result;
418 if ((result & IF_possible) == 0) {
434 int IntersectionBoundingVolume::
436 int result = IF_possible | IF_some | IF_all;
437 for (Components::const_iterator ci = _components.begin();
438 ci != _components.end();
440 int this_result = (*ci)->contains_plane(plane);
441 if ((this_result & IF_dont_understand) != 0) {
442 result |= IF_dont_understand;
445 result &= this_result;
446 if ((result & IF_possible) == 0) {
462 int IntersectionBoundingVolume::
464 int result = IF_possible | IF_some | IF_all;
465 for (Components::const_iterator ci = _components.begin();
466 ci != _components.end();
468 int this_result = (*ci)->contains_union(unionv);
469 if ((this_result & IF_dont_understand) != 0) {
470 result |= IF_dont_understand;
473 result &= this_result;
474 if ((result & IF_possible) == 0) {
490 int IntersectionBoundingVolume::
492 int result = IF_possible | IF_some | IF_all;
493 for (Components::const_iterator ci = _components.begin();
494 ci != _components.end();
496 int this_result = (*ci)->contains_intersection(intersection);
497 if ((this_result & IF_dont_understand) != 0) {
498 result |= IF_dont_understand;
501 result &= this_result;
502 if ((result & IF_possible) == 0) {
516 int IntersectionBoundingVolume::
518 int result = IF_possible | IF_some | IF_all;
519 for (Components::const_iterator ci = _components.begin();
520 ci != _components.end();
522 int this_result = (*ci)->contains_finite(volume);
523 if ((this_result & IF_dont_understand) != 0) {
524 result |= IF_dont_understand;
527 result &= this_result;
528 if ((result & IF_possible) == 0) {
542 int IntersectionBoundingVolume::
543 contains_geometric(
const GeometricBoundingVolume *volume)
const {
544 int result = IF_possible | IF_some | IF_all;
545 for (Components::const_iterator ci = _components.begin();
546 ci != _components.end();
548 int this_result = (*ci)->contains_geometric(volume);
549 if ((this_result & IF_dont_understand) != 0) {
550 result |= IF_dont_understand;
553 result &= this_result;
554 if ((result & IF_possible) == 0) {
572 int IntersectionBoundingVolume::
574 int result = IF_possible | IF_some | IF_all;
575 for (Components::const_iterator ci = _components.begin();
576 ci != _components.end();
578 int this_result = volume->
contains(*ci);
579 if ((this_result & IF_dont_understand) != 0) {
580 result |= IF_dont_understand;
583 result &= this_result;
584 if ((result & IF_possible) == 0) {
An axis-aligned bounding box; that is, a minimum and maximum coordinate triple.
This defines a bounding sphere, consisting of a center and a radius.
static const LPoint3f & zero()
Returns a zero-length point.
bool is_exact_type(TypeHandle handle) const
Returns true if the current object is the indicated type exactly.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
int contains(const GeometricBoundingVolume *vol) const
Returns the appropriate set of IntersectionFlags to indicate the amount of intersection with the indi...
This funny bounding volume is an infinite plane that divides space into two regions: the part behind ...
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
This special bounding volume is the intersection of all of its constituent bounding volumes...
This special bounding volume is the union of all of its constituent bounding volumes.
This is a 4-by-4 transform matrix.
void clear_components()
Removes all components from the volume.
A special kind of GeometricBoundingVolume that is known to be finite.
bool is_infinite() const
The other side of the empty coin is an infinite volume.
bool is_empty() const
Any kind of volume might be empty.
TypeHandle is the identifier used to differentiate C++ class types.
int contains(const BoundingVolume *vol) const
Returns the appropriate set of IntersectionFlags to indicate the amount of intersection with the indi...
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
This defines a bounding convex hexahedron.
void add_component(const GeometricBoundingVolume *component)
Adds a new component to the volume.
This funny bounding volume is an infinite line with no thickness and extending to infinity in both di...
IntersectionBoundingVolume()
Constructs an empty intersection.