Panda3D

boundingVolume.h
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file boundingVolume.h
10 * @author drose
11 * @date 1999-10-01
12 */
13
14 #ifndef BOUNDINGVOLUME_H
15 #define BOUNDINGVOLUME_H
16
17 #include "pandabase.h"
18
19 #include "typedObject.h"
20 #include "typedReferenceCount.h"
21 #include "deletedChain.h"
22
23 class GeometricBoundingVolume;
24 class FiniteBoundingVolume;
25 class BoundingSphere;
26 class BoundingBox;
27 class BoundingHexahedron;
28 class BoundingLine;
29 class BoundingPlane;
30 class UnionBoundingVolume;
31 class IntersectionBoundingVolume;
32
33
34 /**
35 * This is an abstract class for any volume in any sense which can be said to
36 * define the locality of reference of a node in a graph, along with all of
37 * its descendants. It is not necessarily a geometric volume (although see
38 * GeometricBoundingVolume); this is simply an abstract interface for bounds
39 * of any sort.
40 */
41 class EXPCL_PANDA_MATHUTIL BoundingVolume : public TypedReferenceCount {
42 public:
43 INLINE_MATHUTIL BoundingVolume();
44
45 PUBLISHED:
46 virtual BoundingVolume *make_copy() const=0;
47
48 INLINE_MATHUTIL bool is_empty() const;
49 INLINE_MATHUTIL bool is_infinite() const;
50
51 INLINE_MATHUTIL void set_infinite();
52
53 INLINE_MATHUTIL bool extend_by(const BoundingVolume *vol);
54
55 public:
56 // It might be nice to make these template member functions so we could have
57 // true STL-style firstlast iterators, but that's impossible for virtual
58 // functions.
59 bool around(const BoundingVolume **first,
60 const BoundingVolume **last);
61
62 PUBLISHED:
63 // The contains() functions return the union of one or more of these bits.
64 enum IntersectionFlags {
65 // If no bits are set, it is known that there is no intersection.
66 IF_no_intersection = 0,
67
68 // IF_possible is set if there might be an intersection.
69 IF_possible = 0x01,
70
71 // IF_some is set if there is definitely an intersection. In this case,
72 // IF_possible will also be set.
73 IF_some = 0x02,
74
75 // IF_all is set if the other bounding volume is known to be completely
76 // within this bounding volume: that is, there is no part of the other
77 // bounding volume that does not intersect this one. It does *not*
78 // indicate the inverse; it is possible that some part of this bounding
79 // volume does not intersect the other.
80
81 // Also, the converse is not implied: if IF_all is not set, you simply
82 // don't know whether the other volume is completely contained within this
83 // one or not.
84
85 // When IF_all is set, both IF_possible and IF_some will also be set.
86 IF_all = 0x04,
87
88 // IF_dont_understand is set if the particular volumevolume intersection
89 // test has not been implemented.
90 IF_dont_understand = 0x08
91 };
92
93 INLINE_MATHUTIL int contains(const BoundingVolume *vol) const;
94
95 virtual void output(std::ostream &out) const=0;
96 virtual void write(std::ostream &out, int indent_level = 0) const;
97
98 // This enum is used to control the automatic generation of bounding
99 // volumes.
100 enum BoundsType {
101 BT_default,
102 BT_best,
103 BT_sphere,
104 BT_box,
105 BT_fastest,
106 };
107
108 public:
109 virtual GeometricBoundingVolume *as_geometric_bounding_volume();
110 virtual const GeometricBoundingVolume *as_geometric_bounding_volume() const;
111 virtual const FiniteBoundingVolume *as_finite_bounding_volume() const;
112 virtual const BoundingSphere *as_bounding_sphere() const;
113 virtual const BoundingBox *as_bounding_box() const;
114 virtual const BoundingHexahedron *as_bounding_hexahedron() const;
115 virtual const BoundingLine *as_bounding_line() const;
116 virtual const BoundingPlane *as_bounding_plane() const;
117
118 static BoundsType string_bounds_type(const std::string &str);
119
120 protected:
121 enum Flags {
122 F_empty = 0x01,
123 F_infinite = 0x02
124 };
125 int _flags;
126
127 protected:
128 // The following functions support double-dispatch of virtual methods, so we
129 // can easily extend_by() various types of bounding volumes.
130
131 // These functions are the first dispatch point.
132 virtual bool extend_other(BoundingVolume *other) const=0;
133 virtual bool around_other(BoundingVolume *other,
134 const BoundingVolume **first,
135 const BoundingVolume **last) const=0;
136 virtual int contains_other(const BoundingVolume *other) const=0;
137
138 // These functions are the second dispatch point. They actually do the
139 // work.
140 virtual bool extend_by_sphere(const BoundingSphere *sphere);
141 virtual bool extend_by_box(const BoundingBox *box);
142 virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron);
143 virtual bool extend_by_line(const BoundingLine *line);
144 virtual bool extend_by_plane(const BoundingPlane *plane);
145 virtual bool extend_by_union(const UnionBoundingVolume *unionv);
146 virtual bool extend_by_intersection(const IntersectionBoundingVolume *intersection);
147 virtual bool extend_by_finite(const FiniteBoundingVolume *volume);
148 virtual bool extend_by_geometric(const GeometricBoundingVolume *volume);
149
150 virtual bool around_spheres(const BoundingVolume **first,
151 const BoundingVolume **last);
152 virtual bool around_boxes(const BoundingVolume **first,
153 const BoundingVolume **last);
154 virtual bool around_hexahedrons(const BoundingVolume **first,
155 const BoundingVolume **last);
156 virtual bool around_lines(const BoundingVolume **first,
157 const BoundingVolume **last);
158 virtual bool around_planes(const BoundingVolume **first,
159 const BoundingVolume **last);
160 virtual bool around_unions(const BoundingVolume **first,
161 const BoundingVolume **last);
162 virtual bool around_intersections(const BoundingVolume **first,
163 const BoundingVolume **last);
164 virtual bool around_finite(const BoundingVolume **first,
165 const BoundingVolume **last);
166 virtual bool around_geometric(const BoundingVolume **first,
167 const BoundingVolume **last);
168
169 virtual int contains_sphere(const BoundingSphere *sphere) const;
170 virtual int contains_box(const BoundingBox *box) const;
171 virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const;
172 virtual int contains_line(const BoundingLine *line) const;
173 virtual int contains_plane(const BoundingPlane *plane) const;
174 virtual int contains_union(const UnionBoundingVolume *unionv) const;
175 virtual int contains_intersection(const IntersectionBoundingVolume *intersection) const;
176 virtual int contains_finite(const FiniteBoundingVolume *volume) const;
177 virtual int contains_geometric(const GeometricBoundingVolume *volume) const;
178
179
180 public:
181 static TypeHandle get_class_type() {
182 return _type_handle;
183 }
184 static void init_type() {
185 TypedReferenceCount::init_type();
186 register_type(_type_handle, "BoundingVolume",
187 TypedReferenceCount::get_class_type());
188 }
189 virtual TypeHandle get_type() const {
190 return get_class_type();
191 }
192 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
193
194 private:
195 static TypeHandle _type_handle;
196
197 friend class BoundingSphere;
198 friend class BoundingBox;
199 friend class BoundingHexahedron;
200 friend class BoundingLine;
201 friend class BoundingPlane;
202 friend class UnionBoundingVolume;
203 friend class IntersectionBoundingVolume;
204 };
205
206 INLINE_MATHUTIL std::ostream &operator << (std::ostream &out, const BoundingVolume &bound);
207
208 #include "boundingVolume.I"
209
210 EXPCL_PANDA_MATHUTIL std::ostream &operator << (std::ostream &out, BoundingVolume::BoundsType type);
211 EXPCL_PANDA_MATHUTIL std::istream &operator >> (std::istream &in, BoundingVolume::BoundsType &type);
212
213 #endif
boundingVolume.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BoundingBox
An axis-aligned bounding box; that is, a minimum and maximum coordinate triple.
Definition: boundingBox.h:29
BoundingHexahedron
This defines a bounding convex hexahedron.
Definition: boundingHexahedron.h:32
BoundingLine
This funny bounding volume is an infinite line with no thickness and extending to infinity in both di...
Definition: boundingLine.h:29
BoundingPlane
This funny bounding volume is an infinite plane that divides space into two regions: the part behind ...
Definition: boundingPlane.h:28
BoundingSphere
This defines a bounding sphere, consisting of a center and a radius.
Definition: boundingSphere.h:25
BoundingVolume
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
Definition: boundingVolume.h:41
FiniteBoundingVolume
A special kind of GeometricBoundingVolume that is known to be finite.
Definition: finiteBoundingVolume.h:27
GeometricBoundingVolume
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
Definition: geometricBoundingVolume.h:29
IntersectionBoundingVolume
This special bounding volume is the intersection of all of its constituent bounding volumes.
Definition: intersectionBoundingVolume.h:29
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypedReferenceCount
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Definition: typedReferenceCount.h:31
UnionBoundingVolume
This special bounding volume is the union of all of its constituent bounding volumes.
Definition: unionBoundingVolume.h:29
deletedChain.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
typedObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.