15 #include "unionBoundingVolume.h" 16 #include "config_mathutil.h" 30 _components(copy._components)
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 UnionBoundingVolume::
73 for (Components::iterator ci = _components.begin();
74 ci != _components.end();
87 void UnionBoundingVolume::
88 output(ostream &out)
const {
90 out <<
"union, empty";
92 out <<
"union, infinite";
95 for (Components::const_iterator ci = _components.begin();
96 ci != _components.end();
109 void UnionBoundingVolume::
110 write(ostream &out,
int indent_level)
const {
112 indent(out, indent_level) <<
"union, empty\n";
114 indent(out, indent_level) <<
"union, infinite\n";
116 indent(out, indent_level) <<
"union {\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";
159 while (i < _components.size()) {
163 int result = existing->
contains(component);
164 if ((result & IF_all) != 0) {
170 result = component->
contains(existing);
171 if ((result & IF_all) != 0) {
175 _components.erase(_components.begin() + i);
180 _components.push_back(component);
193 while (i < _components.size()) {
197 int result = volume->
contains(existing);
198 if ((result & IF_possible) == 0) {
201 _components.erase(_components.begin() + i);
205 if (_components.empty()) {
215 bool UnionBoundingVolume::
217 return other->extend_by_union(
this);
225 bool UnionBoundingVolume::
229 return other->around_unions(first, last);
237 int UnionBoundingVolume::
239 return other->contains_union(
this);
247 bool UnionBoundingVolume::
258 bool UnionBoundingVolume::
261 nassertr(first != last,
false);
267 nassertr(!(*p)->is_infinite(),
false);
268 if (!(*p)->is_empty()) {
288 int UnionBoundingVolume::
289 contains_point(
const LPoint3 &point)
const {
290 nassertr(!point.
is_nan(), IF_no_intersection);
293 for (Components::const_iterator ci = _components.begin();
294 ci != _components.end();
296 result |= (*ci)->contains(point);
297 if ((result & (IF_all | IF_dont_understand)) != 0) {
311 int UnionBoundingVolume::
313 nassertr(!a.
is_nan() && !b.
is_nan(), IF_no_intersection);
316 for (Components::const_iterator ci = _components.begin();
317 ci != _components.end();
319 result |= (*ci)->contains(a, b);
320 if ((result & (IF_all | IF_dont_understand)) != 0) {
336 int UnionBoundingVolume::
339 for (Components::const_iterator ci = _components.begin();
340 ci != _components.end();
342 result |= (*ci)->contains_sphere(sphere);
343 if ((result & (IF_all | IF_dont_understand)) != 0) {
359 int UnionBoundingVolume::
362 for (Components::const_iterator ci = _components.begin();
363 ci != _components.end();
365 result |= (*ci)->contains_box(box);
366 if ((result & (IF_all | IF_dont_understand)) != 0) {
382 int UnionBoundingVolume::
385 for (Components::const_iterator ci = _components.begin();
386 ci != _components.end();
388 result |= (*ci)->contains_hexahedron(hexahedron);
389 if ((result & (IF_all | IF_dont_understand)) != 0) {
405 int UnionBoundingVolume::
408 for (Components::const_iterator ci = _components.begin();
409 ci != _components.end();
411 result |= (*ci)->contains_line(line);
412 if ((result & (IF_all | IF_dont_understand)) != 0) {
428 int UnionBoundingVolume::
431 for (Components::const_iterator ci = _components.begin();
432 ci != _components.end();
434 result |= (*ci)->contains_plane(plane);
435 if ((result & (IF_all | IF_dont_understand)) != 0) {
451 int UnionBoundingVolume::
454 for (Components::const_iterator ci = _components.begin();
455 ci != _components.end();
457 result |= (*ci)->contains_union(unionv);
458 if ((result & (IF_all | IF_dont_understand)) != 0) {
474 int UnionBoundingVolume::
477 for (Components::const_iterator ci = _components.begin();
478 ci != _components.end();
480 result |= (*ci)->contains_intersection(intersection);
481 if ((result & (IF_all | IF_dont_understand)) != 0) {
495 int UnionBoundingVolume::
498 for (Components::const_iterator ci = _components.begin();
499 ci != _components.end();
501 result |= (*ci)->contains_finite(volume);
502 if ((result & (IF_all | IF_dont_understand)) != 0) {
516 int UnionBoundingVolume::
519 for (Components::const_iterator ci = _components.begin();
520 ci != _components.end();
522 result |= (*ci)->contains_geometric(volume);
523 if ((result & (IF_all | IF_dont_understand)) != 0) {
540 int UnionBoundingVolume::
542 int all_result = IF_possible | IF_some | IF_all;
544 for (Components::const_iterator ci = _components.begin();
545 ci != _components.end();
547 int this_result = volume->
contains(*ci);
548 if ((this_result & IF_dont_understand) != 0) {
549 some_result |= IF_dont_understand;
552 all_result &= this_result;
553 some_result |= this_result;
556 some_result &= ~IF_all;
557 return some_result | all_result;
An axis-aligned bounding box; that is, a minimum and maximum coordinate triple.
int contains(const BoundingVolume *vol) const
Returns the appropriate set of IntersectionFlags to indicate the amount of intersection with the indi...
int contains(const GeometricBoundingVolume *vol) const
Returns the appropriate set of IntersectionFlags to indicate the amount of intersection with the indi...
void add_component(const GeometricBoundingVolume *component)
Adds a new component to the volume.
bool is_empty() const
Any kind of volume might be empty.
UnionBoundingVolume()
Constructs an empty union.
This defines a bounding sphere, consisting of a center and a radius.
bool is_infinite() const
The other side of the empty coin is an infinite volume.
static const LPoint3f & zero()
Returns a zero-length point.
void filter_intersection(const BoundingVolume *volume)
Removes from the union any components that have no intersection with the indicated volume...
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.
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
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...
void set_infinite()
Marks the volume as infinite, even if it is normally finite.
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.
A special kind of GeometricBoundingVolume that is known to be finite.
void clear_components()
Removes all components from the volume.
TypeHandle is the identifier used to differentiate C++ class types.
virtual const GeometricBoundingVolume * as_geometric_bounding_volume() const
Virtual downcast method.
This defines a bounding convex hexahedron.
This funny bounding volume is an infinite line with no thickness and extending to infinity in both di...