Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/mathutil/boundingVolume.h

Go to the documentation of this file.
00001 // Filename: boundingVolume.h
00002 // Created by:  drose (01Oct99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef BOUNDINGVOLUME_H
00020 #define BOUNDINGVOLUME_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "typedObject.h"
00025 #include "typedReferenceCount.h"
00026 
00027 class BoundingSphere;
00028 class BoundingHexahedron;
00029 class BoundingLine;
00030 
00031 
00032 ///////////////////////////////////////////////////////////////////
00033 //       Class : BoundingVolume
00034 // Description : This is an abstract class for any volume in any sense
00035 //               which can be said to define the locality of reference
00036 //               of a node in a graph, along with all of its
00037 //               descendants.  It is not necessarily a geometric
00038 //               volume (although see GeometricBoundingVolume); this
00039 //               is simply an abstract interface for bounds of any
00040 //               sort.
00041 ////////////////////////////////////////////////////////////////////
00042 class EXPCL_PANDA BoundingVolume : public TypedReferenceCount {
00043 PUBLISHED:
00044   INLINE_MATHUTIL BoundingVolume();
00045   virtual BoundingVolume *make_copy() const=0;
00046 
00047   INLINE_MATHUTIL bool is_empty() const;
00048   INLINE_MATHUTIL bool is_infinite() const;
00049 
00050   INLINE_MATHUTIL void set_infinite();
00051 
00052   INLINE_MATHUTIL bool extend_by(const BoundingVolume *vol);
00053 
00054   // It might be nice to make these template member functions so we
00055   // could have true STL-style first/last iterators, but that's
00056   // impossible for virtual functions.
00057   bool around(const BoundingVolume **first,
00058               const BoundingVolume **last);
00059 
00060   // The contains() functions return the union of one or more of these
00061   // bits.
00062   enum IntersectionFlags {
00063     // If no bits are set, it is known that there is no intersection.
00064     IF_no_intersection = 0,
00065 
00066     // IF_possible is set if there might be an intersection.
00067     IF_possible        = 0x01,
00068 
00069     // IF_some is set if there is definitely an intersection.  In this
00070     // case, IF_possible will also be set.
00071     IF_some            = 0x02,
00072 
00073     // IF_all is set if the other bounding volume is known to be
00074     // completely within this bounding volume: that is, there is no
00075     // part of the other bounding volume that does not intersect this
00076     // one.  It does *not* indicate the inverse; it is possible that
00077     // some part of this bounding volume does not intersect the other.
00078 
00079     // Also, the converse is not implied: if IF_all is not set, you
00080     // simply don't know whether the other volume is completely
00081     // contained within this one or not.
00082 
00083     // When IF_all is set, both IF_possible and IF_some will also be
00084     // set.
00085     IF_all             = 0x04,
00086 
00087     // IF_dont_understand is set if the particular volume/volume
00088     // intersection test has not been implemented.
00089     IF_dont_understand = 0x08
00090   };
00091 
00092   INLINE_MATHUTIL int contains(const BoundingVolume *vol) const;
00093 
00094   virtual void output(ostream &out) const=0;
00095   virtual void write(ostream &out, int indent_level = 0) const;
00096 
00097 protected:
00098   enum Flags {
00099     F_empty        = 0x01,
00100     F_infinite     = 0x02
00101   };
00102   int _flags;
00103 
00104 protected:
00105   // The following functions support double-dispatch of virtual
00106   // methods, so we can easily extend_by() various types of bounding
00107   // volumes.
00108 
00109   // These functions are the first dispatch point.
00110   virtual bool extend_other(BoundingVolume *other) const=0;
00111   virtual bool around_other(BoundingVolume *other,
00112                             const BoundingVolume **first,
00113                             const BoundingVolume **last) const=0;
00114   virtual int contains_other(const BoundingVolume *other) const=0;
00115 
00116   // These functions are the second dispatch point.  They actually do
00117   // the work.
00118   virtual bool extend_by_sphere(const BoundingSphere *sphere);
00119   virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron);
00120   virtual bool extend_by_line(const BoundingLine *line);
00121 
00122   virtual bool around_spheres(const BoundingVolume **first,
00123                               const BoundingVolume **last);
00124   virtual bool around_hexahedrons(const BoundingVolume **first,
00125                                   const BoundingVolume **last);
00126   virtual bool around_lines(const BoundingVolume **first,
00127                             const BoundingVolume **last);
00128 
00129   virtual int contains_sphere(const BoundingSphere *sphere) const;
00130   virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const;
00131   virtual int contains_line(const BoundingLine *line) const;
00132 
00133 
00134 public:
00135   static TypeHandle get_class_type() {
00136     return _type_handle;
00137   }
00138   static void init_type() {
00139     TypedReferenceCount::init_type();
00140     register_type(_type_handle, "BoundingVolume",
00141                   TypedReferenceCount::get_class_type());
00142   }
00143   virtual TypeHandle get_type() const {
00144     return get_class_type();
00145   }
00146   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00147 
00148 private:
00149   static TypeHandle _type_handle;
00150 
00151   friend class BoundingSphere;
00152   friend class BoundingHexahedron;
00153   friend class BoundingLine;
00154 };
00155 
00156 INLINE_MATHUTIL ostream &operator << (ostream &out, const BoundingVolume &bound);
00157 
00158 #include "boundingVolume.I"
00159 
00160 #endif

Generated on Fri May 2 00:40:25 2003 for Panda by doxygen1.3