Templatized Volume class.
This commit is contained in:
parent
7177db44ac
commit
593a26ebd2
@ -7,7 +7,6 @@ SET(SRC_FILES
|
|||||||
source/PolyVoxSceneManager.cpp
|
source/PolyVoxSceneManager.cpp
|
||||||
source/RegionGeometry.cpp
|
source/RegionGeometry.cpp
|
||||||
source/SurfaceVertex.cpp
|
source/SurfaceVertex.cpp
|
||||||
source/Volume.cpp
|
|
||||||
source/VolumeIterator.cpp
|
source/VolumeIterator.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,6 +25,7 @@ SET(INC_FILES
|
|||||||
include/Vector.h
|
include/Vector.h
|
||||||
include/Vector.inl
|
include/Vector.inl
|
||||||
include/Volume.h
|
include/Volume.h
|
||||||
|
include/Volume.inl
|
||||||
include/VolumeIterator.h
|
include/VolumeIterator.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace PolyVox
|
|||||||
class Vector3DDouble;
|
class Vector3DDouble;
|
||||||
class Vector3DInt32;
|
class Vector3DInt32;
|
||||||
class Vector3DUint32;*/
|
class Vector3DUint32;*/
|
||||||
class Volume;
|
template <typename VoxelType> class Volume;
|
||||||
class VolumeIterator;
|
class VolumeIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ namespace PolyVox
|
|||||||
NormalGenerationMethod m_normalGenerationMethod;
|
NormalGenerationMethod m_normalGenerationMethod;
|
||||||
|
|
||||||
|
|
||||||
Volume* volumeData;
|
Volume<boost::uint8_t>* volumeData;
|
||||||
|
|
||||||
bool m_bHaveGeneratedMeshes;
|
bool m_bHaveGeneratedMeshes;
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
class POLYVOX_API Volume
|
template <typename VoxelType>
|
||||||
|
class Volume
|
||||||
{
|
{
|
||||||
//Make VolumeIterator a friend
|
//Make VolumeIterator a friend
|
||||||
friend class VolumeIterator;
|
friend class VolumeIterator;
|
||||||
@ -43,7 +44,7 @@ namespace PolyVox
|
|||||||
Volume& operator=(const Volume& rhs);
|
Volume& operator=(const Volume& rhs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Block<boost::uint8_t>* getBlock(boost::uint16_t index);
|
Block<VoxelType>* getBlock(boost::uint16_t index);
|
||||||
|
|
||||||
bool containsPoint(Vector3DFloat pos, float boundary);
|
bool containsPoint(Vector3DFloat pos, float boundary);
|
||||||
bool containsPoint(Vector3DInt32 pos, boost::uint16_t boundary);
|
bool containsPoint(Vector3DInt32 pos, boost::uint16_t boundary);
|
||||||
@ -55,8 +56,10 @@ namespace PolyVox
|
|||||||
void tidy(void);
|
void tidy(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Block<boost::uint8_t>* mBlocks[POLYVOX_NO_OF_BLOCKS_IN_VOLUME];
|
Block<VoxelType>* mBlocks[POLYVOX_NO_OF_BLOCKS_IN_VOLUME];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "Volume.inl"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,34 +25,36 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "Volume.h"
|
#include "Volume.h"
|
||||||
#include "VolumeIterator.h" //Maybe this shouldn't be here?
|
#include "VolumeIterator.h" //Maybe this shouldn't be here?
|
||||||
|
|
||||||
using namespace boost;
|
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
|
|
||||||
Volume::Volume()
|
template <typename VoxelType>
|
||||||
|
Volume<VoxelType>::Volume()
|
||||||
{
|
{
|
||||||
for(uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i)
|
for(boost::uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i)
|
||||||
{
|
{
|
||||||
mBlocks[i] = new Block<boost::uint8_t>;
|
mBlocks[i] = new Block<VoxelType>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Volume::Volume(const Volume& rhs)
|
template <typename VoxelType>
|
||||||
|
Volume<VoxelType>::Volume(const Volume<VoxelType>& rhs)
|
||||||
{
|
{
|
||||||
std::cout << "Warning - Copying Volume" << std::endl;
|
std::cout << "Warning - Copying Volume" << std::endl;
|
||||||
*this = rhs;
|
*this = rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
Volume::~Volume()
|
template <typename VoxelType>
|
||||||
|
Volume<VoxelType>::~Volume()
|
||||||
{
|
{
|
||||||
for(uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i)
|
for(boost::uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i)
|
||||||
{
|
{
|
||||||
delete mBlocks[i];
|
delete mBlocks[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Volume& Volume::operator=(const Volume& rhs)
|
template <typename VoxelType>
|
||||||
|
Volume<VoxelType>& Volume<VoxelType>::operator=(const Volume& rhs)
|
||||||
{
|
{
|
||||||
std::cout << "Warning - Assigning Volume" << std::endl;
|
std::cout << "Warning - Assigning Volume" << std::endl;
|
||||||
if (this == &rhs)
|
if (this == &rhs)
|
||||||
@ -124,12 +126,14 @@ namespace PolyVox
|
|||||||
block->setVoxelAt(xOffset,yOffset,zOffset, value);
|
block->setVoxelAt(xOffset,yOffset,zOffset, value);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
Block<boost::uint8_t>* Volume::getBlock(uint16_t index)
|
template <typename VoxelType>
|
||||||
|
Block<VoxelType>* Volume<VoxelType>::getBlock(boost::uint16_t index)
|
||||||
{
|
{
|
||||||
return mBlocks[index];
|
return mBlocks[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Volume::containsPoint(Vector3DFloat pos, float boundary)
|
template <typename VoxelType>
|
||||||
|
bool Volume<VoxelType>::containsPoint(Vector3DFloat pos, float boundary)
|
||||||
{
|
{
|
||||||
return (pos.x() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary)
|
return (pos.x() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary)
|
||||||
&& (pos.y() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary)
|
&& (pos.y() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary)
|
||||||
@ -139,7 +143,8 @@ namespace PolyVox
|
|||||||
&& (pos.z() > boundary);
|
&& (pos.z() > boundary);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Volume::containsPoint(Vector3DInt32 pos, uint16_t boundary)
|
template <typename VoxelType>
|
||||||
|
bool Volume<VoxelType>::containsPoint(Vector3DInt32 pos, boost::uint16_t boundary)
|
||||||
{
|
{
|
||||||
return (pos.x() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary)
|
return (pos.x() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary)
|
||||||
&& (pos.y() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary)
|
&& (pos.y() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary)
|
||||||
@ -149,7 +154,8 @@ namespace PolyVox
|
|||||||
&& (pos.z() > boundary);
|
&& (pos.z() > boundary);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Volume::loadFromFile(const std::string& sFilename)
|
template <typename VoxelType>
|
||||||
|
bool Volume<VoxelType>::loadFromFile(const std::string& sFilename)
|
||||||
{
|
{
|
||||||
//Open the file
|
//Open the file
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
@ -196,7 +202,8 @@ namespace PolyVox
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Volume::saveToFile(const std::string& sFilename)
|
template <typename VoxelType>
|
||||||
|
bool Volume<VoxelType>::saveToFile(const std::string& sFilename)
|
||||||
{
|
{
|
||||||
//Open the file
|
//Open the file
|
||||||
std::ofstream file;
|
std::ofstream file;
|
||||||
@ -209,9 +216,9 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Read volume dimensions
|
//Read volume dimensions
|
||||||
uint8_t volumeWidth = 0;
|
boost::uint8_t volumeWidth = 0;
|
||||||
uint8_t volumeHeight = 0;
|
boost::uint8_t volumeHeight = 0;
|
||||||
uint8_t volumeDepth = 0;
|
boost::uint8_t volumeDepth = 0;
|
||||||
file.write(reinterpret_cast<char*>(&volumeWidth), sizeof(volumeWidth));
|
file.write(reinterpret_cast<char*>(&volumeWidth), sizeof(volumeWidth));
|
||||||
file.write(reinterpret_cast<char*>(&volumeHeight), sizeof(volumeHeight));
|
file.write(reinterpret_cast<char*>(&volumeHeight), sizeof(volumeHeight));
|
||||||
file.write(reinterpret_cast<char*>(&volumeDepth), sizeof(volumeDepth));
|
file.write(reinterpret_cast<char*>(&volumeDepth), sizeof(volumeDepth));
|
||||||
@ -223,13 +230,13 @@ namespace PolyVox
|
|||||||
|
|
||||||
//Write data
|
//Write data
|
||||||
VolumeIterator volIter(*this);
|
VolumeIterator volIter(*this);
|
||||||
for(uint16_t z = 0; z < POLYVOX_VOLUME_SIDE_LENGTH; ++z)
|
for(boost::uint16_t z = 0; z < POLYVOX_VOLUME_SIDE_LENGTH; ++z)
|
||||||
{
|
{
|
||||||
for(uint16_t y = 0; y < POLYVOX_VOLUME_SIDE_LENGTH; ++y)
|
for(boost::uint16_t y = 0; y < POLYVOX_VOLUME_SIDE_LENGTH; ++y)
|
||||||
{
|
{
|
||||||
for(uint16_t x = 0; x < POLYVOX_VOLUME_SIDE_LENGTH; ++x)
|
for(boost::uint16_t x = 0; x < POLYVOX_VOLUME_SIDE_LENGTH; ++x)
|
||||||
{
|
{
|
||||||
uint8_t value = volIter.getVoxelAt(x,y,z);
|
boost::uint8_t value = volIter.getVoxelAt(x,y,z);
|
||||||
file.write(reinterpret_cast<char*>(&value), sizeof(value)); //FIXME - check for error here
|
file.write(reinterpret_cast<char*>(&value), sizeof(value)); //FIXME - check for error here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,7 +244,8 @@ namespace PolyVox
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Volume::regionGrow(uint16_t xStart, uint16_t yStart, uint16_t zStart, uint8_t value)
|
template <typename VoxelType>
|
||||||
|
void Volume<VoxelType>::regionGrow(boost::uint16_t xStart, boost::uint16_t yStart, boost::uint16_t zStart, boost::uint8_t value)
|
||||||
{
|
{
|
||||||
//FIXME - introduce integrer 'isInVolume' function
|
//FIXME - introduce integrer 'isInVolume' function
|
||||||
if((xStart > POLYVOX_VOLUME_SIDE_LENGTH-1) || (yStart > POLYVOX_VOLUME_SIDE_LENGTH-1) || (zStart > POLYVOX_VOLUME_SIDE_LENGTH-1)
|
if((xStart > POLYVOX_VOLUME_SIDE_LENGTH-1) || (yStart > POLYVOX_VOLUME_SIDE_LENGTH-1) || (zStart > POLYVOX_VOLUME_SIDE_LENGTH-1)
|
||||||
@ -248,7 +256,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
VolumeIterator volIter(*this);
|
VolumeIterator volIter(*this);
|
||||||
const uint8_t uSeedValue = volIter.getVoxelAt(xStart,yStart,zStart);
|
const boost::uint8_t uSeedValue = volIter.getVoxelAt(xStart,yStart,zStart);
|
||||||
|
|
||||||
if(value == uSeedValue)
|
if(value == uSeedValue)
|
||||||
{
|
{
|
||||||
@ -310,7 +318,8 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Volume::tidy(void)
|
template <typename VoxelType>
|
||||||
|
void Volume<VoxelType>::tidy(void)
|
||||||
{
|
{
|
||||||
//Check for homogeneous blocks
|
//Check for homogeneous blocks
|
||||||
/*for(uint32_t ct = 0; ct < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++ct)
|
/*for(uint32_t ct = 0; ct < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++ct)
|
@ -21,17 +21,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
|
|
||||||
#include "boost/cstdint.hpp"
|
#include "boost/cstdint.hpp"
|
||||||
|
|
||||||
|
#include "PolyVoxForwardDeclarations.h"
|
||||||
#include "TypeDef.h"
|
#include "TypeDef.h"
|
||||||
#include "Vector.h"
|
#include "Vector.h"
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
class Volume;
|
|
||||||
|
|
||||||
class POLYVOX_API VolumeIterator
|
class POLYVOX_API VolumeIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VolumeIterator(Volume& volume);
|
VolumeIterator(Volume<boost::uint8_t>& volume);
|
||||||
~VolumeIterator();
|
~VolumeIterator();
|
||||||
|
|
||||||
void setVoxel(boost::uint8_t value);
|
void setVoxel(boost::uint8_t value);
|
||||||
@ -89,7 +88,7 @@ namespace PolyVox
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//The current volume
|
//The current volume
|
||||||
Volume& mVolume;
|
Volume<boost::uint8_t>& mVolume;
|
||||||
|
|
||||||
//The current position in the volume
|
//The current position in the volume
|
||||||
boost::uint16_t mXPosInVolume;
|
boost::uint16_t mXPosInVolume;
|
||||||
|
@ -151,7 +151,7 @@ namespace PolyVox
|
|||||||
void PolyVoxSceneManager::generateLevelVolume(void)
|
void PolyVoxSceneManager::generateLevelVolume(void)
|
||||||
{
|
{
|
||||||
//volumeData = VolumePtr(new Volume);
|
//volumeData = VolumePtr(new Volume);
|
||||||
volumeData = new Volume();
|
volumeData = new Volume<boost::uint8_t>();
|
||||||
VolumeIterator volIter(*volumeData);
|
VolumeIterator volIter(*volumeData);
|
||||||
for(uint16_t z = 0; z < POLYVOX_VOLUME_SIDE_LENGTH; ++z)
|
for(uint16_t z = 0; z < POLYVOX_VOLUME_SIDE_LENGTH; ++z)
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ using namespace boost;
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
VolumeIterator::VolumeIterator(Volume& volume)
|
VolumeIterator::VolumeIterator(Volume<boost::uint8_t>& volume)
|
||||||
:mVolume(volume)
|
:mVolume(volume)
|
||||||
,mXRegionFirst(0)
|
,mXRegionFirst(0)
|
||||||
,mYRegionFirst(0)
|
,mYRegionFirst(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user