27 _components(copy._components)
42 LPoint3 UnionBoundingVolume::
43 get_approx_center()
const {
44 nassertr(!
is_empty(), LPoint3::zero());
47 LPoint3 center = LPoint3::zero();
48 for (Components::const_iterator ci = _components.begin();
49 ci != _components.end();
51 center += (*ci)->get_approx_center();
54 return center / (PN_stdfloat)_components.size();
60 void UnionBoundingVolume::
61 xform(
const LMatrix4 &mat) {
62 nassertv(!mat.is_nan());
64 for (Components::iterator ci = _components.begin();
65 ci != _components.end();
76 void UnionBoundingVolume::
77 output(std::ostream &out)
const {
79 out <<
"union, empty";
81 out <<
"union, infinite";
84 for (Components::const_iterator ci = _components.begin();
85 ci != _components.end();
96 void UnionBoundingVolume::
97 write(std::ostream &out,
int indent_level)
const {
99 indent(out, indent_level) <<
"union, empty\n";
101 indent(out, indent_level) <<
"union, infinite\n";
103 indent(out, indent_level) <<
"union {\n";
104 for (Components::const_iterator ci = _components.begin();
105 ci != _components.end();
107 (*ci)->write(out, indent_level + 2);
109 indent(out, indent_level) <<
"}\n";
140 while (i < _components.size()) {
144 int result = existing->
contains(component);
145 if ((result & IF_all) != 0) {
151 result = component->
contains(existing);
152 if ((result & IF_all) != 0) {
156 _components.erase(_components.begin() + i);
161 _components.push_back(component);
172 while (i < _components.size()) {
176 int result = volume->
contains(existing);
177 if ((result & IF_possible) == 0) {
180 _components.erase(_components.begin() + i);
184 if (_components.empty()) {
192 bool UnionBoundingVolume::
194 return other->extend_by_union(
this);
200 bool UnionBoundingVolume::
204 return other->around_unions(first, last);
210 int UnionBoundingVolume::
212 return other->contains_union(
this);
218 bool UnionBoundingVolume::
227 bool UnionBoundingVolume::
230 nassertr(first != last,
false);
236 nassertr(!(*p)->is_infinite(),
false);
237 if (!(*p)->is_empty()) {
239 if (volume !=
nullptr) {
255 int UnionBoundingVolume::
256 contains_point(
const LPoint3 &point)
const {
257 nassertr(!point.is_nan(), IF_no_intersection);
260 for (Components::const_iterator ci = _components.begin();
261 ci != _components.end();
263 result |= (*ci)->contains(point);
264 if ((result & (IF_all | IF_dont_understand)) != 0) {
276 int UnionBoundingVolume::
277 contains_lineseg(
const LPoint3 &a,
const LPoint3 &b)
const {
278 nassertr(!a.is_nan() && !b.is_nan(), IF_no_intersection);
281 for (Components::const_iterator ci = _components.begin();
282 ci != _components.end();
284 result |= (*ci)->contains(a, b);
285 if ((result & (IF_all | IF_dont_understand)) != 0) {
298 int UnionBoundingVolume::
301 for (Components::const_iterator ci = _components.begin();
302 ci != _components.end();
304 result |= (*ci)->contains_sphere(sphere);
305 if ((result & (IF_all | IF_dont_understand)) != 0) {
318 int UnionBoundingVolume::
321 for (Components::const_iterator ci = _components.begin();
322 ci != _components.end();
324 result |= (*ci)->contains_box(box);
325 if ((result & (IF_all | IF_dont_understand)) != 0) {
338 int UnionBoundingVolume::
341 for (Components::const_iterator ci = _components.begin();
342 ci != _components.end();
344 result |= (*ci)->contains_hexahedron(hexahedron);
345 if ((result & (IF_all | IF_dont_understand)) != 0) {
358 int UnionBoundingVolume::
361 for (Components::const_iterator ci = _components.begin();
362 ci != _components.end();
364 result |= (*ci)->contains_line(line);
365 if ((result & (IF_all | IF_dont_understand)) != 0) {
378 int UnionBoundingVolume::
381 for (Components::const_iterator ci = _components.begin();
382 ci != _components.end();
384 result |= (*ci)->contains_plane(plane);
385 if ((result & (IF_all | IF_dont_understand)) != 0) {
398 int UnionBoundingVolume::
401 for (Components::const_iterator ci = _components.begin();
402 ci != _components.end();
404 result |= (*ci)->contains_union(unionv);
405 if ((result & (IF_all | IF_dont_understand)) != 0) {
418 int UnionBoundingVolume::
421 for (Components::const_iterator ci = _components.begin();
422 ci != _components.end();
424 result |= (*ci)->contains_intersection(intersection);
425 if ((result & (IF_all | IF_dont_understand)) != 0) {
437 int UnionBoundingVolume::
440 for (Components::const_iterator ci = _components.begin();
441 ci != _components.end();
443 result |= (*ci)->contains_finite(volume);
444 if ((result & (IF_all | IF_dont_understand)) != 0) {
456 int UnionBoundingVolume::
459 for (Components::const_iterator ci = _components.begin();
460 ci != _components.end();
462 result |= (*ci)->contains_geometric(volume);
463 if ((result & (IF_all | IF_dont_understand)) != 0) {
477 int UnionBoundingVolume::
479 int all_result = IF_possible | IF_some | IF_all;
481 for (Components::const_iterator ci = _components.begin();
482 ci != _components.end();
484 int this_result = volume->
contains(*ci);
485 if ((this_result & IF_dont_understand) != 0) {
486 some_result |= IF_dont_understand;
489 all_result &= this_result;
490 some_result |= this_result;
493 some_result &= ~IF_all;
494 return some_result | all_result;
An axis-aligned bounding box; that is, a minimum and maximum coordinate triple.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual GeometricBoundingVolume * as_geometric_bounding_volume() final
Virtual downcast method.
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.
void filter_intersection(const BoundingVolume *volume)
Removes from the union any components that have no intersection with the indicated volume.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines a bounding convex hexahedron.
This funny bounding volume is an infinite line with no thickness and extending to infinity in both di...