00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }