Initial commit of new Volume base class, which will be a base for the other volume classes. It's not working at this point...

This commit is contained in:
David Williams 2011-07-20 22:34:44 +01:00
parent ef30a13aef
commit ca8da0b0f3
5 changed files with 391 additions and 34 deletions

View File

@ -38,14 +38,12 @@ namespace PolyVox
{
public:
#ifndef SWIG
class Sampler
class Sampler : public Volume<VoxelType>::Sampler
{
public:
Sampler(RawVolume<VoxelType>* volume);
~Sampler();
Sampler& operator=(const Sampler& rhs) throw();
int32_t getPosX(void) const;
int32_t getPosY(void) const;
int32_t getPosZ(void) const;
@ -95,18 +93,18 @@ namespace PolyVox
private:
//The current volume
RawVolume<VoxelType>* mVolume;
RawVolume<VoxelType>* mRawVolume;
//The current position in the volume
int32_t mXPosInVolume;
/*int32_t mXPosInVolume;
int32_t mYPosInVolume;
int32_t mZPosInVolume;
int32_t mZPosInVolume;*/
//Other current position information
VoxelType* mCurrentVoxel;
//Whether the current position is inside the volume
bool m_bIsCurrentPositionValid;
//bool m_bIsCurrentPositionValid;
};
#endif

View File

@ -31,12 +31,13 @@ namespace PolyVox
{
template <typename VoxelType>
RawVolume<VoxelType>::Sampler::Sampler(RawVolume<VoxelType>* volume)
:mVolume(volume)
,mXPosInVolume(0)
,mYPosInVolume(0)
,mZPosInVolume(0)
:Volume<VoxelType>::Sampler(volume)
//,mXPosInVolume(0)
//,mYPosInVolume(0)
//,mZPosInVolume(0)
,mRawVolume(volume)
,mCurrentVoxel(0)
,m_bIsCurrentPositionValid(false)
//,m_bIsCurrentPositionValid(false)
{
}
@ -45,21 +46,6 @@ namespace PolyVox
{
}
template <typename VoxelType>
typename RawVolume<VoxelType>::Sampler& RawVolume<VoxelType>::Sampler::operator=(const typename RawVolume<VoxelType>::Sampler& rhs) throw()
{
if(this == &rhs)
{
return *this;
}
mVolume = rhs.mVolume;
mXPosInVolume = rhs.mXPosInVolume;
mYPosInVolume = rhs.mYPosInVolume;
mZPosInVolume = rhs.mZPosInVolume;
mCurrentVoxel = rhs.mCurrentVoxel;
return *this;
}
template <typename VoxelType>
int32_t RawVolume<VoxelType>::Sampler::getPosX(void) const
{
@ -87,7 +73,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::Sampler::getVoxel(void) const
{
return m_bIsCurrentPositionValid ? *mCurrentVoxel : mVolume->m_tBorderValue;
return m_bIsCurrentPositionValid ? *mCurrentVoxel : mVolume->getBorderValue();
}
template <typename VoxelType>
@ -107,9 +93,9 @@ namespace PolyVox
yPos * mVolume->getWidth() +
zPos * mVolume->getWidth() * mVolume->getHeight();
mCurrentVoxel = mVolume->m_pData + uVoxelIndex;
mCurrentVoxel = mRawVolume->m_pData + uVoxelIndex;
m_bIsCurrentPositionValid = mVolume->m_regValidRegion.containsPoint(Vector3DInt32(xPos, yPos, zPos));
m_bIsCurrentPositionValid = mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos));
}
template <typename VoxelType>
@ -131,7 +117,7 @@ namespace PolyVox
template <typename VoxelType>
void RawVolume<VoxelType>::Sampler::movePositiveZ(void)
{
mZPosInVolume--;
mZPosInVolume++;
mCurrentVoxel += mVolume->getWidth() * mVolume->getHeight();
m_bIsCurrentPositionValid = mZPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getZ();
}

View File

@ -35,6 +35,75 @@ namespace PolyVox
template <typename VoxelType>
class Volume
{
public:
#ifndef SWIG
class Sampler
{
public:
Sampler(Volume<VoxelType>* volume);
~Sampler();
int32_t getPosX(void) const;
int32_t getPosY(void) const;
int32_t getPosZ(void) const;
const Volume<VoxelType>* getVolume(void) const;
inline VoxelType getVoxel(void) const;
void setPosition(const Vector3DInt32& v3dNewPos);
void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
void movePositiveX(void);
void movePositiveY(void);
void movePositiveZ(void);
void moveNegativeX(void);
void moveNegativeY(void);
void moveNegativeZ(void);
inline VoxelType peekVoxel1nx1ny1nz(void) const;
inline VoxelType peekVoxel1nx1ny0pz(void) const;
inline VoxelType peekVoxel1nx1ny1pz(void) const;
inline VoxelType peekVoxel1nx0py1nz(void) const;
inline VoxelType peekVoxel1nx0py0pz(void) const;
inline VoxelType peekVoxel1nx0py1pz(void) const;
inline VoxelType peekVoxel1nx1py1nz(void) const;
inline VoxelType peekVoxel1nx1py0pz(void) const;
inline VoxelType peekVoxel1nx1py1pz(void) const;
inline VoxelType peekVoxel0px1ny1nz(void) const;
inline VoxelType peekVoxel0px1ny0pz(void) const;
inline VoxelType peekVoxel0px1ny1pz(void) const;
inline VoxelType peekVoxel0px0py1nz(void) const;
inline VoxelType peekVoxel0px0py0pz(void) const;
inline VoxelType peekVoxel0px0py1pz(void) const;
inline VoxelType peekVoxel0px1py1nz(void) const;
inline VoxelType peekVoxel0px1py0pz(void) const;
inline VoxelType peekVoxel0px1py1pz(void) const;
inline VoxelType peekVoxel1px1ny1nz(void) const;
inline VoxelType peekVoxel1px1ny0pz(void) const;
inline VoxelType peekVoxel1px1ny1pz(void) const;
inline VoxelType peekVoxel1px0py1nz(void) const;
inline VoxelType peekVoxel1px0py0pz(void) const;
inline VoxelType peekVoxel1px0py1pz(void) const;
inline VoxelType peekVoxel1px1py1nz(void) const;
inline VoxelType peekVoxel1px1py0pz(void) const;
inline VoxelType peekVoxel1px1py1pz(void) const;
protected:
//The current volume
Volume<VoxelType>* mVolume;
//The current position in the volume
int32_t mXPosInVolume;
int32_t mYPosInVolume;
int32_t mZPosInVolume;
//Whether the current position is inside the volume
bool m_bIsCurrentPositionValid;
};
#endif
public:
/// Constructor for creating a fixed size volume.
Volume
@ -46,7 +115,7 @@ namespace PolyVox
/// Gets the value used for voxels which are outside the volume
VoxelType getBorderValue(void) const;
/// Gets a Region representing the extents of the RawVolume.
/// Gets a Region representing the extents of the Volume.
Region getEnclosingRegion(void) const;
/// Gets the width of the volume in voxels.
int32_t getWidth(void) const;

View File

@ -140,7 +140,7 @@ namespace PolyVox
VoxelType Volume<VoxelType>::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
{
assert(false);
return VoxelType; //Default constructor
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
@ -151,7 +151,7 @@ namespace PolyVox
VoxelType Volume<VoxelType>::getVoxelAt(const Vector3DInt32& v3dPos) const
{
assert(false);
return VoxelType; //Default constructor
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,304 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxImpl/Block.h"
#include "PolyVoxCore/Volume.h"
#include "PolyVoxCore/Vector.h"
#include "PolyVoxCore/Region.h"
#include <limits>
namespace PolyVox
{
template <typename VoxelType>
Volume<VoxelType>::Sampler::Sampler(Volume<VoxelType>* volume)
:mVolume(volume)
,mXPosInVolume(0)
,mYPosInVolume(0)
,mZPosInVolume(0)
,m_bIsCurrentPositionValid(false)
{
}
template <typename VoxelType>
Volume<VoxelType>::Sampler::~Sampler()
{
}
template <typename VoxelType>
int32_t Volume<VoxelType>::Sampler::getPosX(void) const
{
return mXPosInVolume;
}
template <typename VoxelType>
int32_t Volume<VoxelType>::Sampler::getPosY(void) const
{
return mYPosInVolume;
}
template <typename VoxelType>
int32_t Volume<VoxelType>::Sampler::getPosZ(void) const
{
return mZPosInVolume;
}
template <typename VoxelType>
const Volume<VoxelType>* Volume<VoxelType>::Sampler::getVolume(void) const
{
return mVolume;
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::getVoxel(void) const
{
return m_bIsCurrentPositionValid ? mVolume->getVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume) : mVolume->m_tBorderValue;
}
template <typename VoxelType>
void Volume<VoxelType>::Sampler::setPosition(const Vector3DInt32& v3dNewPos)
{
setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
}
template <typename VoxelType>
void Volume<VoxelType>::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos)
{
mXPosInVolume = xPos;
mYPosInVolume = yPos;
mZPosInVolume = zPos;
const uint32_t uVoxelIndex = xPos +
yPos * mVolume->getWidth() +
zPos * mVolume->getWidth() * mVolume->getHeight();
m_bIsCurrentPositionValid = mVolume->m_regValidRegion.containsPoint(Vector3DInt32(xPos, yPos, zPos));
}
template <typename VoxelType>
void Volume<VoxelType>::Sampler::movePositiveX(void)
{
mXPosInVolume++;
m_bIsCurrentPositionValid = mXPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getX();
}
template <typename VoxelType>
void Volume<VoxelType>::Sampler::movePositiveY(void)
{
mYPosInVolume++;
m_bIsCurrentPositionValid = mYPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getY();
}
template <typename VoxelType>
void Volume<VoxelType>::Sampler::movePositiveZ(void)
{
mZPosInVolume++;
m_bIsCurrentPositionValid = mZPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getZ();
}
template <typename VoxelType>
void Volume<VoxelType>::Sampler::moveNegativeX(void)
{
mXPosInVolume--;
m_bIsCurrentPositionValid = mXPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getX();
}
template <typename VoxelType>
void Volume<VoxelType>::Sampler::moveNegativeY(void)
{
mYPosInVolume--;
m_bIsCurrentPositionValid = mYPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getY();
}
template <typename VoxelType>
void Volume<VoxelType>::Sampler::moveNegativeZ(void)
{
mZPosInVolume--;
m_bIsCurrentPositionValid =mZPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getZ();
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume+1);
}
//////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel0px0py0pz(void) const
{
return *mCurrentVoxel;
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume+1);
}
//////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
{
return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume+1);
}
}