box3.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: box3.h
00004 
00005     DESCRIPTION: 3D Box class
00006 
00007     CREATED BY: Dan Silva
00008 
00009     HISTORY:
00010 
00011  *> Copyright (c) 1994, All Rights Reserved.
00012  **********************************************************************/
00013 #pragma once
00014 
00015 #include "GeomExport.h"
00016 #include "maxheap.h"
00017 #include "point3.h"
00018 #include "matrix3.h"
00019 
00030 class Box3: public MaxHeapOperators {
00031     public:
00032         Point3 pmin,pmax;
00035         GEOMEXPORT Box3();
00038         Box3(const Point3& p, const Point3& q) { pmin = p; pmax = q;}
00042         GEOMEXPORT void Init();
00043 
00052         GEOMEXPORT void MakeCube(const Point3& p, float side);
00053 
00054         // Access
00056         Point3 Min() const { return pmin; }
00058         Point3 Max() const { return pmax; }
00060         Point3 Center() const { return(pmin+pmax)/(float)2.0; }
00063         Point3 Width() const { return(pmax-pmin); }
00064 
00065         /* operator[] returns ith corner point: (i == (0..7) )
00066             Mapping:
00067                     X   Y   Z
00068             [0] : (min,min,min)
00069             [1] : (max,min,min)
00070             [2] : (min,max,min)
00071             [3] : (max,max,min)
00072             [4] : (min,min,max)
00073             [5] : (max,min,max)
00074             [6] : (min,max,max)
00075             [7] : (max,max,max)
00076             */
00091         GEOMEXPORT Point3 operator[](int i) const;    
00092 
00093         // Modifiers
00098         GEOMEXPORT Box3& operator+=(const Point3& p);   // expand this box to include Point3
00103         GEOMEXPORT Box3& operator+=(const Box3& b);   // expand this box to include  Box3
00104 
00109         GEOMEXPORT void Scale(float s); // scale box about center
00115         GEOMEXPORT void Translate(const Point3 &p); // translate box
00120         GEOMEXPORT void EnlargeBy(float s); // enlarge by this amount on all sides
00121 
00122         // include an array of points, optionally transformed by tm
00123         GEOMEXPORT void IncludePoints(Point3 *pts, int numpoints, Matrix3 *tm=NULL); 
00124 
00125         // Returns a box that bounds the 8 transformed corners of the input box.
00131         GEOMEXPORT Box3 operator*(const Matrix3& tm) const;
00132 
00133         // Tests
00137         GEOMEXPORT int IsEmpty() const;   // is this box empty?
00145         GEOMEXPORT int Contains(const Point3& p) const;  // is point in this box?
00155         GEOMEXPORT int Contains(const Box3& b) const;  // is box b totally in this box?
00156         GEOMEXPORT int Intersects(const Box3& b) const;  // does  box b intersect this box at all?
00157         
00158         
00159 
00160     };
00161 
00162