Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PolyVoxCore/Region.h"
00025
00026 #include <limits>
00027
00028 namespace PolyVox
00029 {
00030 const Region Region::MaxRegion
00031 (
00032 Vector3DInt32((std::numeric_limits<int32_t>::min)(), (std::numeric_limits<int32_t>::min)(), (std::numeric_limits<int32_t>::min)()),
00033 Vector3DInt32((std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)())
00034 );
00035
00036
00037 Region::Region()
00038 :m_v3dLowerCorner(0,0,0)
00039 ,m_v3dUpperCorner(0,0,0)
00040 {
00041 }
00042
00043 Region::Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner)
00044 :m_v3dLowerCorner(v3dLowerCorner)
00045 ,m_v3dUpperCorner(v3dUpperCorner)
00046 {
00047
00048 assert(m_v3dUpperCorner.getX() >= m_v3dLowerCorner.getX());
00049 assert(m_v3dUpperCorner.getY() >= m_v3dLowerCorner.getY());
00050 assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ());
00051 }
00052
00053 Region::Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ)
00054 :m_v3dLowerCorner(iLowerX, iLowerY, iLowerZ)
00055 ,m_v3dUpperCorner(iUpperX, iUpperY, iUpperZ)
00056 {
00057
00058 assert(m_v3dUpperCorner.getX() >= m_v3dLowerCorner.getX());
00059 assert(m_v3dUpperCorner.getY() >= m_v3dLowerCorner.getY());
00060 assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ());
00061 }
00062
00069 bool Region::operator==(const Region& rhs) const throw()
00070 {
00071 return ((m_v3dLowerCorner == rhs.m_v3dLowerCorner) && (m_v3dUpperCorner == rhs.m_v3dUpperCorner));
00072 }
00073
00080 bool Region::operator!=(const Region& rhs) const throw()
00081 {
00082 return !(*this == rhs);
00083 }
00084
00085 const Vector3DInt32& Region::getLowerCorner(void) const
00086 {
00087 return m_v3dLowerCorner;
00088 }
00089
00090 const Vector3DInt32& Region::getUpperCorner(void) const
00091 {
00092 return m_v3dUpperCorner;
00093 }
00094
00095 void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner)
00096 {
00097 m_v3dLowerCorner = v3dLowerCorner;
00098 }
00099
00100 void Region::setUpperCorner(const Vector3DInt32& v3dUpperCorner)
00101 {
00102 m_v3dUpperCorner = v3dUpperCorner;
00103 }
00104
00105 bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const
00106 {
00107 return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
00108 && (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
00109 && (pos.getZ() <= m_v3dUpperCorner.getZ() - boundary)
00110 && (pos.getX() >= m_v3dLowerCorner.getX() + boundary)
00111 && (pos.getY() >= m_v3dLowerCorner.getY() + boundary)
00112 && (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
00113 }
00114
00115 bool Region::containsPoint(const Vector3DInt32& pos, uint8_t boundary) const
00116 {
00117 return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
00118 && (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
00119 && (pos.getZ() <= m_v3dUpperCorner.getZ() - boundary)
00120 && (pos.getX() >= m_v3dLowerCorner.getX() + boundary)
00121 && (pos.getY() >= m_v3dLowerCorner.getY() + boundary)
00122 && (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
00123 }
00124
00125 bool Region::containsPointInX(float pos, float boundary) const
00126 {
00127 return (pos <= m_v3dUpperCorner.getX() - boundary)
00128 && (pos >= m_v3dLowerCorner.getX() + boundary);
00129 }
00130
00131 bool Region::containsPointInX(int32_t pos, uint8_t boundary) const
00132 {
00133 return (pos <= m_v3dUpperCorner.getX() - boundary)
00134 && (pos >= m_v3dLowerCorner.getX() + boundary);
00135 }
00136
00137 bool Region::containsPointInY(float pos, float boundary) const
00138 {
00139 return (pos <= m_v3dUpperCorner.getY() - boundary)
00140 && (pos >= m_v3dLowerCorner.getY() + boundary);
00141 }
00142
00143 bool Region::containsPointInY(int32_t pos, uint8_t boundary) const
00144 {
00145 return (pos <= m_v3dUpperCorner.getY() - boundary)
00146 && (pos >= m_v3dLowerCorner.getY() + boundary);
00147 }
00148
00149 bool Region::containsPointInZ(float pos, float boundary) const
00150 {
00151 return (pos <= m_v3dUpperCorner.getZ() - boundary)
00152 && (pos >= m_v3dLowerCorner.getZ() + boundary);
00153 }
00154
00155 bool Region::containsPointInZ(int32_t pos, uint8_t boundary) const
00156 {
00157 return (pos <= m_v3dUpperCorner.getZ() - boundary)
00158 && (pos >= m_v3dLowerCorner.getZ() + boundary);
00159 }
00160
00161 void Region::cropTo(const Region& other)
00162 {
00163 m_v3dLowerCorner.setX((std::max)(m_v3dLowerCorner.getX(), other.m_v3dLowerCorner.getX()));
00164 m_v3dLowerCorner.setY((std::max)(m_v3dLowerCorner.getY(), other.m_v3dLowerCorner.getY()));
00165 m_v3dLowerCorner.setZ((std::max)(m_v3dLowerCorner.getZ(), other.m_v3dLowerCorner.getZ()));
00166 m_v3dUpperCorner.setX((std::min)(m_v3dUpperCorner.getX(), other.m_v3dUpperCorner.getX()));
00167 m_v3dUpperCorner.setY((std::min)(m_v3dUpperCorner.getY(), other.m_v3dUpperCorner.getY()));
00168 m_v3dUpperCorner.setZ((std::min)(m_v3dUpperCorner.getZ(), other.m_v3dUpperCorner.getZ()));
00169 }
00170
00171 int32_t Region::depth(void) const
00172 {
00173
00174 assert(false);
00175 return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ();
00176 }
00177
00178 int32_t Region::height(void) const
00179 {
00180
00181 assert(false);
00182 return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY();
00183 }
00184
00185 void Region::shift(const Vector3DInt32& amount)
00186 {
00187 m_v3dLowerCorner += amount;
00188 m_v3dUpperCorner += amount;
00189 }
00190
00191 void Region::shiftLowerCorner(const Vector3DInt32& amount)
00192 {
00193 m_v3dLowerCorner += amount;
00194 }
00195
00196 void Region::shiftUpperCorner(const Vector3DInt32& amount)
00197 {
00198 m_v3dUpperCorner += amount;
00199 }
00200
00201 Vector3DInt32 Region::dimensions(void)
00202 {
00203
00204 assert(false);
00205 return m_v3dUpperCorner - m_v3dLowerCorner;
00206 }
00207
00208 int32_t Region::width(void) const
00209 {
00210
00211 assert(false);
00212 return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX();
00213 }
00214 }