Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vpboundingbox.cpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 // ChangeLog
00006 // Dec 15, 2004 - Bruno de Oliveira Schneider
00007 // - Code typing has been cleaned. DoxyGen documentation started.
00008 // - Attributes were changed from float to double.
00009 // - Removed "vp" prefix from every method name.
00010 // - Changed "center" type from VPPoint3D* to VPPoint4D, along with realted methods.
00011 // - Added "const" modifier wherever possible.
00012 // - Added a copy constructor, operator= and an ouput operator.
00013 // - Added GetGreaterEdge, ConditionalUpdate and MergeWith.
00014 // Mar 01, 2001 - Isabel Harb Manssour
00015 // - File and variables rename.
00016 // Jan 23, 2001 - Fernando Sola Pereira
00017 // - Methods implementation.
00018 // - Class declarations.
00019 
00020 #include <vpboundingbox.h>
00021 
00022 using namespace std;
00023 
00024 VPBoundingBox::VPBoundingBox() {
00025 }
00026 
00027 VPBoundingBox::VPBoundingBox(double minX, double minY, double minZ,
00028                              double maxX, double maxY, double maxZ) {
00029     smallerX = minX;
00030     smallerY = minY;
00031     smallerZ = minZ;
00032     greaterX = maxX;
00033     greaterY = maxY;
00034     greaterZ = maxZ;
00035     ProcessCenter();
00036 }
00037 
00038 VPBoundingBox::VPBoundingBox(const VPBoundingBox& box) {
00039     smallerX = box.smallerX;
00040     smallerY = box.smallerY;
00041     smallerZ = box.smallerZ;
00042     greaterX = box.greaterX;
00043     greaterY = box.greaterY;
00044     greaterZ = box.greaterZ;
00045     center   = box.center;
00046 }
00047 
00048 VPBoundingBox& VPBoundingBox::operator=(const VPBoundingBox& box) {
00049     smallerX = box.smallerX;
00050     smallerY = box.smallerY;
00051     smallerZ = box.smallerZ;
00052     greaterX = box.greaterX;
00053     greaterY = box.greaterY;
00054     greaterZ = box.greaterZ;
00055     center   = box.center;
00056     return *this;
00057 }
00058 
00059 void VPBoundingBox::ProcessCenter() {
00060     center.SetXYZW((greaterX + smallerX)/2,
00061                    (greaterY + smallerY)/2,
00062                    (greaterZ + smallerZ)/2, 1);
00063 }
00064 
00065 double VPBoundingBox::GetGreaterX() const {
00066     return greaterX;
00067 }
00068 
00069 double VPBoundingBox::GetGreaterY() const {
00070     return greaterY;
00071 }
00072 
00073 double VPBoundingBox::GetGreaterZ() const {
00074     return greaterZ;
00075 }
00076 
00077 void VPBoundingBox::SetGreaterX(double v) {
00078     greaterX=v;
00079 }
00080 
00081 void VPBoundingBox::SetGreaterY(double v) {
00082     greaterY=v;
00083 }
00084 
00085 void VPBoundingBox::SetGreaterZ(double v) {
00086     greaterZ=v;
00087 }
00088 
00089 double VPBoundingBox::GetSmallerX() const {
00090     return smallerX;
00091 }
00092 
00093 double VPBoundingBox::GetSmallerY() const {
00094     return smallerY;
00095 }
00096 
00097 double VPBoundingBox::GetSmallerZ() const {
00098     return smallerZ;
00099 }
00100 
00101 void VPBoundingBox::SetSmallerX(double v) {
00102     smallerX=v;
00103 }
00104 
00105 void VPBoundingBox::SetSmallerY(double v) {
00106     smallerY=v;
00107 }
00108 
00109 void VPBoundingBox::SetSmallerZ(double v) {
00110     smallerZ=v;
00111 }
00112 
00113 void VPBoundingBox::SetBoundingBox(double minX, double minY, double minZ,
00114                                    double maxX, double maxY, double maxZ) {
00115     smallerX = minX;
00116     smallerY = minY;
00117     smallerZ = minZ;
00118     greaterX = maxX;
00119     greaterY = maxY;
00120     greaterZ = maxZ;
00121     ProcessCenter();
00122 }
00123 
00124 const VPPoint4D& VPBoundingBox::GetCenter() const {
00125     return center;
00126 }
00127 
00128 void VPBoundingBox::ConditionalUpdate(double x, double y, double z) {
00129     if (x < smallerX)
00130         smallerX = x;
00131     else {
00132         if (x > greaterX) greaterX = x;
00133     }
00134     if (y < smallerY)
00135         smallerY = y;
00136     else {
00137         if (y > greaterY) greaterY = y;
00138     }
00139     if (z < smallerZ)
00140         smallerZ = z;
00141     else {
00142         if (z > greaterZ) greaterZ = z;
00143     }
00144 }
00145 
00146 void VPBoundingBox::ConditionalUpdate(const VPPoint4D& point) {
00147     ConditionalUpdate(point.GetX(), point.GetY(), point.GetZ());
00148 }
00149 
00150 void VPBoundingBox::MergeWith(const VPBoundingBox& box) {
00151     ConditionalUpdate(box.smallerX, box.smallerY, box.smallerZ);
00152     ConditionalUpdate(box.greaterX, box.greaterY, box.greaterZ);
00153 }
00154 
00155 double VPBoundingBox::GetGreaterEdge() const {
00156     double greater = greaterX - smallerX;
00157     double tmp = greaterY - smallerY;
00158 
00159     if (tmp > greater)
00160         greater = tmp;
00161     tmp = greaterZ - smallerZ;
00162     if (tmp > greater)
00163         greater = tmp;
00164     return greater;
00165 }
00166 
00167 ostream& operator<<(ostream& output, const VPBoundingBox& box)
00168 {
00169     output << "(Greaters: " << box.greaterX << "," << box.greaterY << "," 
00170            << box.greaterZ << " Smallers: " << box.smallerX << "," 
00171            << box.smallerY << "," << box.smallerZ << ")";
00172     return output;
00173 }

Generated on Tue Sep 6 10:00:03 2005 for VPAT by  doxygen 1.4.4