Another code dump which was supposed to be a feature branch... having some Git issues at the moment.

This commit is contained in:
David Williams 2012-11-24 00:32:29 +01:00
parent 989cd453fe
commit e56fd3ce4f
2 changed files with 97 additions and 111 deletions

View File

@ -54,18 +54,19 @@ namespace PolyVox
public:
static const Region MaxRegion;
static const Region InvertedRegion;
Region();
Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner);
Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ);
///Equality Operator.
/// Equality Operator.
bool operator==(const Region& rhs) const;
///Inequality Operator.
/// Inequality Operator.
bool operator!=(const Region& rhs) const;
const Vector3DInt32& getLowerCorner(void) const;
const Vector3DInt32& getUpperCorner(void) const;
Vector3DInt32 getLowerCorner(void) const;
Vector3DInt32 getUpperCorner(void) const;
/// Gets the width of the region measured in voxels
int32_t getWidthInVoxels(void) const;
@ -85,6 +86,8 @@ namespace PolyVox
/// Gets the dimensions of the region measured in cells
Vector3DInt32 getDimensionsInCells(void) const;
bool isValid(void);
void setLowerCorner(const Vector3DInt32& v3dLowerCorner);
void setUpperCorner(const Vector3DInt32& v3dUpperCorner);
@ -98,28 +101,20 @@ namespace PolyVox
bool containsPointInZ(float pos, float boundary = 0.0f) const;
bool containsPointInZ(int32_t pos, uint8_t boundary = 0) const;
void cropTo(const Region& other);
/// Deprecated and misleading
POLYVOX_DEPRECATED int32_t depth(void) const;
/// Deprecated and misleading
POLYVOX_DEPRECATED int32_t height(void) const;
void shift(const Vector3DInt32& amount);
void shiftLowerCorner(const Vector3DInt32& amount);
void shiftUpperCorner(const Vector3DInt32& amount);
//FIXME - Add dilate and erode functions?
/// Deprecated and misleading
POLYVOX_DEPRECATED Vector3DInt32 dimensions(void);
/// Deprecated and misleading
POLYVOX_DEPRECATED int32_t width(void) const;
private:
Vector3DInt32 m_v3dLowerCorner;
Vector3DInt32 m_v3dUpperCorner;
//FIXME - This variable is unused, but without it the OpenGL example crashes in release mode
//when the volume size is 128^3 and the level of detail is 2. Very strange, but consistant.
//Presubablly some kind of alignment issue? It started after this class was changed to use
//int16's rather than int32's. To be investigated.
uint8_t dummy;
int32_t m_iLowerX;
int32_t m_iLowerY;
int32_t m_iLowerZ;
int32_t m_iUpperX;
int32_t m_iUpperY;
int32_t m_iUpperZ;
};
}

View File

@ -33,31 +33,40 @@ namespace PolyVox
Vector3DInt32((std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)())
);
const Region Region::InvertedRegion
(
Vector3DInt32((std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)()),
Vector3DInt32((std::numeric_limits<int32_t>::min)(), (std::numeric_limits<int32_t>::min)(), (std::numeric_limits<int32_t>::min)())
);
Region::Region()
:m_v3dLowerCorner(0,0,0)
,m_v3dUpperCorner(0,0,0)
:m_iLowerX(0)
,m_iLowerY(0)
,m_iLowerZ(0)
,m_iUpperX(0)
,m_iUpperY(0)
,m_iUpperZ(0)
{
}
Region::Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner)
:m_v3dLowerCorner(v3dLowerCorner)
,m_v3dUpperCorner(v3dUpperCorner)
:m_iLowerX(v3dLowerCorner.getX())
,m_iLowerY(v3dLowerCorner.getY())
,m_iLowerZ(v3dLowerCorner.getZ())
,m_iUpperX(v3dUpperCorner.getX())
,m_iUpperY(v3dUpperCorner.getY())
,m_iUpperZ(v3dUpperCorner.getZ())
{
//Check the region is valid.
assert(m_v3dUpperCorner.getX() >= m_v3dLowerCorner.getX());
assert(m_v3dUpperCorner.getY() >= m_v3dLowerCorner.getY());
assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ());
}
Region::Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ)
:m_v3dLowerCorner(iLowerX, iLowerY, iLowerZ)
,m_v3dUpperCorner(iUpperX, iUpperY, iUpperZ)
:m_iLowerX(iLowerX)
,m_iLowerY(iLowerY)
,m_iLowerZ(iLowerZ)
,m_iUpperX(iUpperX)
,m_iUpperY(iUpperY)
,m_iUpperZ(iUpperZ)
{
//Check the region is valid.
assert(m_v3dUpperCorner.getX() >= m_v3dLowerCorner.getX());
assert(m_v3dUpperCorner.getY() >= m_v3dLowerCorner.getY());
assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ());
}
/**
@ -68,7 +77,8 @@ namespace PolyVox
*/
bool Region::operator==(const Region& rhs) const
{
return ((m_v3dLowerCorner == rhs.m_v3dLowerCorner) && (m_v3dUpperCorner == rhs.m_v3dUpperCorner));
return ((m_iLowerX == rhs.m_iLowerX) && (m_iLowerY == rhs.m_iLowerY) && (m_iLowerZ == rhs.m_iLowerZ)
&& (m_iUpperX == rhs.m_iUpperX) && (m_iUpperY == rhs.m_iUpperY) && (m_iUpperZ == rhs.m_iUpperZ));
}
/**
@ -82,14 +92,14 @@ namespace PolyVox
return !(*this == rhs);
}
const Vector3DInt32& Region::getLowerCorner(void) const
Vector3DInt32 Region::getLowerCorner(void) const
{
return m_v3dLowerCorner;
return Vector3DInt32(m_iLowerX, m_iLowerY, m_iLowerZ);
}
const Vector3DInt32& Region::getUpperCorner(void) const
Vector3DInt32 Region::getUpperCorner(void) const
{
return m_v3dUpperCorner;
return Vector3DInt32(m_iUpperX, m_iUpperY, m_iUpperZ);
}
int32_t Region::getWidthInVoxels(void) const
@ -114,145 +124,126 @@ namespace PolyVox
int32_t Region::getWidthInCells(void) const
{
return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX();
return m_iUpperX - m_iLowerX;
}
int32_t Region::getHeightInCells(void) const
{
return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY();
return m_iUpperY - m_iLowerY;
}
Vector3DInt32 Region::getDimensionsInCells(void) const
{
return m_v3dUpperCorner - m_v3dLowerCorner;
return Vector3DInt32(getWidthInCells(), getHeightInCells(), getDepthInCells());
}
int32_t Region::getDepthInCells(void) const
{
return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ();
return m_iUpperZ - m_iLowerZ;
}
bool Region::isValid(void)
{
return (m_iUpperX >= m_iLowerX) && (m_iUpperY >= m_iLowerY) && (m_iUpperZ >= m_iLowerZ);
}
void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner)
{
m_v3dLowerCorner = v3dLowerCorner;
m_iLowerX = v3dLowerCorner.getX();
m_iLowerY = v3dLowerCorner.getY();
m_iLowerZ = v3dLowerCorner.getZ();
}
void Region::setUpperCorner(const Vector3DInt32& v3dUpperCorner)
{
m_v3dUpperCorner = v3dUpperCorner;
m_iUpperX = v3dUpperCorner.getX();
m_iUpperY = v3dUpperCorner.getY();
m_iUpperZ = v3dUpperCorner.getZ();
}
bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const
{
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
&& (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
&& (pos.getZ() <= m_v3dUpperCorner.getZ() - boundary)
&& (pos.getX() >= m_v3dLowerCorner.getX() + boundary)
&& (pos.getY() >= m_v3dLowerCorner.getY() + boundary)
&& (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
return (pos.getX() <= m_iUpperX - boundary)
&& (pos.getY() <= m_iUpperY - boundary)
&& (pos.getZ() <= m_iUpperZ - boundary)
&& (pos.getX() >= m_iLowerX + boundary)
&& (pos.getY() >= m_iLowerY + boundary)
&& (pos.getZ() >= m_iLowerZ + boundary);
}
bool Region::containsPoint(const Vector3DInt32& pos, uint8_t boundary) const
{
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
&& (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
&& (pos.getZ() <= m_v3dUpperCorner.getZ() - boundary)
&& (pos.getX() >= m_v3dLowerCorner.getX() + boundary)
&& (pos.getY() >= m_v3dLowerCorner.getY() + boundary)
&& (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
return (pos.getX() <= m_iUpperX - boundary)
&& (pos.getY() <= m_iUpperY - boundary)
&& (pos.getZ() <= m_iUpperZ - boundary)
&& (pos.getX() >= m_iLowerX + boundary)
&& (pos.getY() >= m_iLowerY + boundary)
&& (pos.getZ() >= m_iLowerZ + boundary);
}
bool Region::containsPointInX(float pos, float boundary) const
{
return (pos <= m_v3dUpperCorner.getX() - boundary)
&& (pos >= m_v3dLowerCorner.getX() + boundary);
return (pos <= m_iUpperX - boundary)
&& (pos >= m_iLowerX + boundary);
}
bool Region::containsPointInX(int32_t pos, uint8_t boundary) const
{
return (pos <= m_v3dUpperCorner.getX() - boundary)
&& (pos >= m_v3dLowerCorner.getX() + boundary);
return (pos <= m_iUpperX - boundary)
&& (pos >= m_iLowerX + boundary);
}
bool Region::containsPointInY(float pos, float boundary) const
{
return (pos <= m_v3dUpperCorner.getY() - boundary)
&& (pos >= m_v3dLowerCorner.getY() + boundary);
return (pos <= m_iUpperY - boundary)
&& (pos >= m_iLowerY + boundary);
}
bool Region::containsPointInY(int32_t pos, uint8_t boundary) const
{
return (pos <= m_v3dUpperCorner.getY() - boundary)
&& (pos >= m_v3dLowerCorner.getY() + boundary);
return (pos <= m_iUpperY - boundary)
&& (pos >= m_iLowerY + boundary);
}
bool Region::containsPointInZ(float pos, float boundary) const
{
return (pos <= m_v3dUpperCorner.getZ() - boundary)
&& (pos >= m_v3dLowerCorner.getZ() + boundary);
return (pos <= m_iUpperZ - boundary)
&& (pos >= m_iLowerZ + boundary);
}
bool Region::containsPointInZ(int32_t pos, uint8_t boundary) const
{
return (pos <= m_v3dUpperCorner.getZ() - boundary)
&& (pos >= m_v3dLowerCorner.getZ() + boundary);
return (pos <= m_iUpperZ - boundary)
&& (pos >= m_iLowerZ + boundary);
}
void Region::cropTo(const Region& other)
{
m_v3dLowerCorner.setX((std::max)(m_v3dLowerCorner.getX(), other.m_v3dLowerCorner.getX()));
m_v3dLowerCorner.setY((std::max)(m_v3dLowerCorner.getY(), other.m_v3dLowerCorner.getY()));
m_v3dLowerCorner.setZ((std::max)(m_v3dLowerCorner.getZ(), other.m_v3dLowerCorner.getZ()));
m_v3dUpperCorner.setX((std::min)(m_v3dUpperCorner.getX(), other.m_v3dUpperCorner.getX()));
m_v3dUpperCorner.setY((std::min)(m_v3dUpperCorner.getY(), other.m_v3dUpperCorner.getY()));
m_v3dUpperCorner.setZ((std::min)(m_v3dUpperCorner.getZ(), other.m_v3dUpperCorner.getZ()));
}
/// \deprecated Use getDepthInVoxels() or getDepthInCells() instead
int32_t Region::depth(void) const
{
//This function is deprecated and wrong.
assert(false);
return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ();
}
/// \deprecated Use getHeightInVoxels() or getHeightInCells() instead
int32_t Region::height(void) const
{
//This function is deprecated and wrong.
assert(false);
return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY();
m_iLowerX = ((std::max)(m_iLowerX, other.m_iLowerX));
m_iLowerY = ((std::max)(m_iLowerY, other.m_iLowerY));
m_iLowerZ = ((std::max)(m_iLowerZ, other.m_iLowerZ));
m_iUpperX = ((std::min)(m_iUpperX, other.m_iUpperX));
m_iUpperY = ((std::min)(m_iUpperY, other.m_iUpperY));
m_iUpperZ = ((std::min)(m_iUpperZ, other.m_iUpperZ));
}
void Region::shift(const Vector3DInt32& amount)
{
m_v3dLowerCorner += amount;
m_v3dUpperCorner += amount;
shiftLowerCorner(amount);
shiftUpperCorner(amount);
}
void Region::shiftLowerCorner(const Vector3DInt32& amount)
{
m_v3dLowerCorner += amount;
m_iLowerX += amount.getX();
m_iLowerY += amount.getY();
m_iLowerZ += amount.getZ();
}
void Region::shiftUpperCorner(const Vector3DInt32& amount)
{
m_v3dUpperCorner += amount;
}
/// \deprecated Use getDimensionsInVoxels() or getDimensionsInCells() instead
Vector3DInt32 Region::dimensions(void)
{
//This function is deprecated and wrong.
assert(false);
return m_v3dUpperCorner - m_v3dLowerCorner;
}
/// \deprecated Use getWidthInVoxels() or getWidthInCells() instead
int32_t Region::width(void) const
{
//This function is deprecated and wrong.
assert(false);
return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX();
m_iUpperX += amount.getX();
m_iUpperY += amount.getY();
m_iUpperZ += amount.getZ();
}
}