Applied patch from ker such that int32_t's are now used instead of uint16_t's for addressing voxel positions.
This commit is contained in:
parent
3c34d401fc
commit
4ef0cfb468
@ -25,6 +25,7 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "MaterialDensityPair.h"
|
||||
#include "CubicSurfaceExtractorWithNormals.h"
|
||||
#include "SurfaceExtractor.h"
|
||||
#include "SurfaceMesh.h"
|
||||
#include "Volume.h"
|
||||
|
||||
@ -436,13 +437,15 @@ void createPerlinTerrain(Volume<MaterialDensityPair44>& volData)
|
||||
|
||||
for(int x = 1; x < volData.getWidth()-1; x++)
|
||||
{
|
||||
std::cout << x << std::endl;
|
||||
if(x%(volData.getWidth()/100) == 0) {
|
||||
std::cout << "." << std::flush;
|
||||
}
|
||||
for(int y = 1; y < volData.getHeight()-1; y++)
|
||||
{
|
||||
float perlinVal = perlin.Get(x / static_cast<float>(volData.getHeight()-1), y / static_cast<float>(volData.getDepth()-1));
|
||||
perlinVal += 1.0f;
|
||||
perlinVal *= 0.5f;
|
||||
perlinVal *= volData.getWidth();
|
||||
perlinVal *= volData.getShortestSideLength();
|
||||
for(int z = 1; z < volData.getDepth()-1; z++)
|
||||
{
|
||||
MaterialDensityPair44 voxel;
|
||||
@ -461,6 +464,7 @@ void createPerlinTerrain(Volume<MaterialDensityPair44>& volData)
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void createSphereInVolume(Volume<MaterialDensityPair44>& volData, Vector3DFloat v3dVolCenter, float fRadius)
|
||||
@ -510,15 +514,15 @@ int main(int argc, char *argv[])
|
||||
openGLWidget.show();
|
||||
|
||||
//Create an empty volume and then place a sphere in it
|
||||
Volume<MaterialDensityPair44> volData(256, 256, 256);
|
||||
Volume<MaterialDensityPair44> volData(1024*128,16,16,16);
|
||||
volData.useCompatibilityMode();
|
||||
//createSphereInVolume(volData, 30);
|
||||
createPerlinTerrain(volData);
|
||||
//createPerlinVolumeSlow(volData);
|
||||
std::cout << "Memory usage: " << volData.calculateSizeInBytes() << std::endl;
|
||||
//volData.setBlockCacheSize(8);
|
||||
std::cout << "Memory usage: " << volData.calculateSizeInBytes() << std::endl;
|
||||
std::cout << "Compression ratio: " << volData.calculateCompressionRatio() << std::endl;
|
||||
std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl;
|
||||
volData.setBlockCacheSize(64);
|
||||
std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl;
|
||||
std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl;
|
||||
|
||||
/*srand(12345);
|
||||
for(int ct = 0; ct < 1000; ct++)
|
||||
@ -535,7 +539,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
//Extract the surface
|
||||
SurfaceMesh<PositionMaterialNormal> mesh;
|
||||
CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
//CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
SurfaceExtractor<MaterialDensityPair44> surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
surfaceExtractor.execute();
|
||||
|
||||
//Pass the surface to the OpenGL window
|
||||
|
@ -74,16 +74,16 @@ void OpenGLWidget::setVolume(PolyVox::Volume<MaterialDensityPair44>* volData)
|
||||
//Compute the extents of the current region
|
||||
//FIXME - This is a little complex? PolyVox could
|
||||
//provide more functions for dealing with regions?
|
||||
uint16_t regionStartX = uRegionX * m_uRegionSideLength;
|
||||
uint16_t regionStartY = uRegionY * m_uRegionSideLength;
|
||||
uint16_t regionStartZ = uRegionZ * m_uRegionSideLength;
|
||||
int32_t regionStartX = uRegionX * m_uRegionSideLength;
|
||||
int32_t regionStartY = uRegionY * m_uRegionSideLength;
|
||||
int32_t regionStartZ = uRegionZ * m_uRegionSideLength;
|
||||
|
||||
uint16_t regionEndX = regionStartX + m_uRegionSideLength;
|
||||
uint16_t regionEndY = regionStartY + m_uRegionSideLength;
|
||||
uint16_t regionEndZ = regionStartZ + m_uRegionSideLength;
|
||||
int32_t regionEndX = regionStartX + m_uRegionSideLength;
|
||||
int32_t regionEndY = regionStartY + m_uRegionSideLength;
|
||||
int32_t regionEndZ = regionStartZ + m_uRegionSideLength;
|
||||
|
||||
Vector3DInt16 regLowerCorner(regionStartX, regionStartY, regionStartZ);
|
||||
Vector3DInt16 regUpperCorner(regionEndX, regionEndY, regionEndZ);
|
||||
Vector3DInt32 regLowerCorner(regionStartX, regionStartY, regionStartZ);
|
||||
Vector3DInt32 regUpperCorner(regionEndX, regionEndY, regionEndZ);
|
||||
|
||||
//Extract the surface for this region
|
||||
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
|
||||
|
@ -55,7 +55,7 @@ void createSphereInVolume(Volume<MaterialDensityPair44>& volData, float fRadius,
|
||||
}
|
||||
}
|
||||
|
||||
void createCubeInVolume(Volume<MaterialDensityPair44>& volData, Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8_t uValue)
|
||||
void createCubeInVolume(Volume<MaterialDensityPair44>& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue)
|
||||
{
|
||||
//This three-level for loop iterates over every voxel between the specified corners
|
||||
for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++)
|
||||
|
@ -28,6 +28,6 @@ freely, subject to the following restrictions:
|
||||
#include "Volume.h"
|
||||
|
||||
void createSphereInVolume(PolyVox::Volume<PolyVox::MaterialDensityPair44>& volData, float fRadius, uint8_t uValue);
|
||||
void createCubeInVolume(PolyVox::Volume<PolyVox::MaterialDensityPair44>& volData, PolyVox::Vector3DUint16 lowerCorner, PolyVox::Vector3DUint16 upperCorner, uint8_t uValue);
|
||||
void createCubeInVolume(PolyVox::Volume<PolyVox::MaterialDensityPair44>& volData, PolyVox::Vector3DInt32 lowerCorner, PolyVox::Vector3DInt32 upperCorner, uint8_t uValue);
|
||||
|
||||
#endif //__OpenGLExample_Shapes_H__
|
@ -75,9 +75,9 @@ int main(int argc, char *argv[])
|
||||
Volume<MaterialDensityPair44> volData(g_uVolumeSideLength, g_uVolumeSideLength, g_uVolumeSideLength);
|
||||
|
||||
//Make our volume contain a sphere in the center.
|
||||
uint16_t minPos = 0;
|
||||
uint16_t midPos = g_uVolumeSideLength / 2;
|
||||
uint16_t maxPos = g_uVolumeSideLength - 1;
|
||||
int32_t minPos = 0;
|
||||
int32_t midPos = g_uVolumeSideLength / 2;
|
||||
int32_t maxPos = g_uVolumeSideLength - 1;
|
||||
|
||||
cout << "Creating sphere 1" << std::endl;
|
||||
createSphereInVolume(volData, 60.0f, 5);
|
||||
@ -91,18 +91,18 @@ int main(int argc, char *argv[])
|
||||
createSphereInVolume(volData, 20.0f, 1);
|
||||
|
||||
cout << "Creating cubes" << std::endl;
|
||||
createCubeInVolume(volData, Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(midPos-1, midPos-1, midPos-1), 0);
|
||||
createCubeInVolume(volData, Vector3DUint16(midPos+1, midPos+1, minPos), Vector3DUint16(maxPos, maxPos, midPos-1), 0);
|
||||
createCubeInVolume(volData, Vector3DUint16(midPos+1, minPos, midPos+1), Vector3DUint16(maxPos, midPos-1, maxPos), 0);
|
||||
createCubeInVolume(volData, Vector3DUint16(minPos, midPos+1, midPos+1), Vector3DUint16(midPos-1, maxPos, maxPos), 0);
|
||||
createCubeInVolume(volData, Vector3DInt32(minPos, minPos, minPos), Vector3DInt32(midPos-1, midPos-1, midPos-1), 0);
|
||||
createCubeInVolume(volData, Vector3DInt32(midPos+1, midPos+1, minPos), Vector3DInt32(maxPos, maxPos, midPos-1), 0);
|
||||
createCubeInVolume(volData, Vector3DInt32(midPos+1, minPos, midPos+1), Vector3DInt32(maxPos, midPos-1, maxPos), 0);
|
||||
createCubeInVolume(volData, Vector3DInt32(minPos, midPos+1, midPos+1), Vector3DInt32(midPos-1, maxPos, maxPos), 0);
|
||||
|
||||
createCubeInVolume(volData, Vector3DUint16(1, midPos-10, midPos-10), Vector3DUint16(maxPos-1, midPos+10, midPos+10), MaterialDensityPair44::getMaxDensity());
|
||||
createCubeInVolume(volData, Vector3DUint16(midPos-10, 1, midPos-10), Vector3DUint16(midPos+10, maxPos-1, midPos+10), MaterialDensityPair44::getMaxDensity());
|
||||
createCubeInVolume(volData, Vector3DUint16(midPos-10, midPos-10 ,1), Vector3DUint16(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity());
|
||||
createCubeInVolume(volData, Vector3DInt32(1, midPos-10, midPos-10), Vector3DInt32(maxPos-1, midPos+10, midPos+10), MaterialDensityPair44::getMaxDensity());
|
||||
createCubeInVolume(volData, Vector3DInt32(midPos-10, 1, midPos-10), Vector3DInt32(midPos+10, maxPos-1, midPos+10), MaterialDensityPair44::getMaxDensity());
|
||||
createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity());
|
||||
|
||||
//Smooth part of the volume
|
||||
smoothRegion<MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt16(62, 62, 62), Vector3DInt16(130, 130, 130)));
|
||||
smoothRegion<MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt16(62, 62, 62), Vector3DInt16(130, 130, 130)));
|
||||
smoothRegion<MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(130, 130, 130)));
|
||||
smoothRegion<MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(130, 130, 130)));
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
|
@ -38,14 +38,14 @@ namespace PolyVox
|
||||
const float sqrt_2 = 1.4143f;
|
||||
const float sqrt_3 = 1.7321f;
|
||||
|
||||
extern const POLYVOXCORE_API Vector3DInt16 arrayPathfinderFaces[6];
|
||||
extern const POLYVOXCORE_API Vector3DInt16 arrayPathfinderEdges[12];
|
||||
extern const POLYVOXCORE_API Vector3DInt16 arrayPathfinderCorners[8];
|
||||
extern const POLYVOXCORE_API Vector3DInt32 arrayPathfinderFaces[6];
|
||||
extern const POLYVOXCORE_API Vector3DInt32 arrayPathfinderEdges[12];
|
||||
extern const POLYVOXCORE_API Vector3DInt32 arrayPathfinderCorners[8];
|
||||
|
||||
/// This function provides the default method for checking whether a given voxel
|
||||
/// is vaid for the path computed by the AStarPathfinder.
|
||||
template <typename VoxelType>
|
||||
bool aStarDefaultVoxelValidator(const Volume<VoxelType>* volData, const Vector3DInt16& v3dPos);
|
||||
bool aStarDefaultVoxelValidator(const Volume<VoxelType>* volData, const Vector3DInt32& v3dPos);
|
||||
|
||||
/// Provides a configuration for the AStarPathfinder.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -65,13 +65,13 @@ namespace PolyVox
|
||||
AStarPathfinderParams
|
||||
(
|
||||
Volume<VoxelType>* volData,
|
||||
const Vector3DInt16& v3dStart,
|
||||
const Vector3DInt16& v3dEnd,
|
||||
std::list<Vector3DInt16>* listResult,
|
||||
const Vector3DInt32& v3dStart,
|
||||
const Vector3DInt32& v3dEnd,
|
||||
std::list<Vector3DInt32>* listResult,
|
||||
float fHBias = 1.0,
|
||||
uint32_t uMaxNoOfNodes = 10000,
|
||||
Connectivity connectivity = TwentySixConnected,
|
||||
polyvox_function<bool (const Volume<VoxelType>*, const Vector3DInt16&)> funcIsVoxelValidForPath = &aStarDefaultVoxelValidator<VoxelType>,
|
||||
polyvox_function<bool (const Volume<VoxelType>*, const Vector3DInt32&)> funcIsVoxelValidForPath = &aStarDefaultVoxelValidator<VoxelType>,
|
||||
polyvox_function<void (float)> funcProgressCallback = 0
|
||||
)
|
||||
:volume(volData)
|
||||
@ -90,14 +90,14 @@ namespace PolyVox
|
||||
Volume<VoxelType>* volume;
|
||||
|
||||
/// The start point for the pathfinding algorithm.
|
||||
Vector3DInt16 start;
|
||||
Vector3DInt32 start;
|
||||
|
||||
/// The end point for the pathfinding algorithm.
|
||||
Vector3DInt16 end;
|
||||
Vector3DInt32 end;
|
||||
|
||||
/// The resulting path will be stored as a series of points in
|
||||
/// this list. Any existing contents will be cleared.
|
||||
std::list<Vector3DInt16>* result;
|
||||
std::list<Vector3DInt32>* result;
|
||||
|
||||
/// The AStarPathfinder performs its search by examining the neighbours
|
||||
/// of each voxel it encounters. This property controls the meaning of
|
||||
@ -126,7 +126,7 @@ namespace PolyVox
|
||||
/// you could check to ensure that the voxel above is empty and the voxel below is solid.
|
||||
///
|
||||
/// \sa aStarDefaultVoxelValidator
|
||||
polyvox_function<bool (const Volume<VoxelType>*, const Vector3DInt16&)> isVoxelValidForPath;
|
||||
polyvox_function<bool (const Volume<VoxelType>*, const Vector3DInt32&)> isVoxelValidForPath;
|
||||
|
||||
/// This function is called by the AStarPathfinder to report on its progress in getting to
|
||||
/// the goal. The progress is reported by computing the distance from the closest node found
|
||||
@ -169,12 +169,12 @@ namespace PolyVox
|
||||
void execute();
|
||||
|
||||
private:
|
||||
void processNeighbour(const Vector3DInt16& neighbourPos, float neighbourGVal);
|
||||
void processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal);
|
||||
|
||||
float SixConnectedCost(const Vector3DInt16& a, const Vector3DInt16& b);
|
||||
float EighteenConnectedCost(const Vector3DInt16& a, const Vector3DInt16& b);
|
||||
float TwentySixConnectedCost(const Vector3DInt16& a, const Vector3DInt16& b);
|
||||
float computeH(const Vector3DInt16& a, const Vector3DInt16& b);
|
||||
float SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b);
|
||||
float EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b);
|
||||
float TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b);
|
||||
float computeH(const Vector3DInt32& a, const Vector3DInt32& b);
|
||||
|
||||
//Node containers
|
||||
AllNodesContainer allNodes;
|
||||
|
@ -31,7 +31,7 @@ namespace PolyVox
|
||||
/// \return true is the voxel is valid for the path
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
bool aStarDefaultVoxelValidator(const Volume<VoxelType>* volData, const Vector3DInt16& v3dPos)
|
||||
bool aStarDefaultVoxelValidator(const Volume<VoxelType>* volData, const Vector3DInt32& v3dPos)
|
||||
{
|
||||
//Voxels are considered valid candidates for the path if they are inside the volume...
|
||||
if(volData->getEnclosingRegion().containsPoint(v3dPos) == false)
|
||||
@ -40,7 +40,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
//and if their density is below the threshold.
|
||||
Material8 voxel = volData->getVoxelAt(static_cast<Vector3DUint16>(v3dPos));
|
||||
Material8 voxel = volData->getVoxelAt(v3dPos);
|
||||
if(voxel.getDensity() >= Material8::getThreshold())
|
||||
{
|
||||
return false;
|
||||
@ -192,7 +192,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void AStarPathfinder<VoxelType>::processNeighbour(const Vector3DInt16& neighbourPos, float neighbourGVal)
|
||||
void AStarPathfinder<VoxelType>::processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal)
|
||||
{
|
||||
bool bIsVoxelValidForPath = m_params.isVoxelValidForPath(m_params.volume, neighbourPos);
|
||||
if(!bIsVoxelValidForPath)
|
||||
@ -248,16 +248,16 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
float AStarPathfinder<VoxelType>::SixConnectedCost(const Vector3DInt16& a, const Vector3DInt16& b)
|
||||
float AStarPathfinder<VoxelType>::SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
|
||||
{
|
||||
//This is the only heuristic I'm sure of - just use the manhatten distance for the 6-connected case.
|
||||
uint16_t faceSteps = abs(a.getX()-b.getX()) + abs(a.getY()-b.getY()) + abs(a.getZ()-b.getZ());
|
||||
uint32_t faceSteps = abs(a.getX()-b.getX()) + abs(a.getY()-b.getY()) + abs(a.getZ()-b.getZ());
|
||||
|
||||
return faceSteps * 1.0f;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
float AStarPathfinder<VoxelType>::EighteenConnectedCost(const Vector3DInt16& a, const Vector3DInt16& b)
|
||||
float AStarPathfinder<VoxelType>::EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
|
||||
{
|
||||
//I'm not sure of the correct heuristic for the 18-connected case, so I'm just letting it fall through to the
|
||||
//6-connected case. This means 'h' will be bigger than it should be, resulting in a faster path which may not
|
||||
@ -267,11 +267,11 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
float AStarPathfinder<VoxelType>::TwentySixConnectedCost(const Vector3DInt16& a, const Vector3DInt16& b)
|
||||
float AStarPathfinder<VoxelType>::TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
|
||||
{
|
||||
//Can't say I'm certain about this heuristic - if anyone has
|
||||
//a better idea of what it should be then please let me know.
|
||||
uint16_t array[3];
|
||||
uint32_t array[3];
|
||||
array[0] = abs(a.getX() - b.getX());
|
||||
array[1] = abs(a.getY() - b.getY());
|
||||
array[2] = abs(a.getZ() - b.getZ());
|
||||
@ -281,15 +281,15 @@ namespace PolyVox
|
||||
//until the profiler says so.
|
||||
std::sort(&array[0], &array[3]);
|
||||
|
||||
uint16_t cornerSteps = array[0];
|
||||
uint16_t edgeSteps = array[1] - array[0];
|
||||
uint16_t faceSteps = array[2] - array[1];
|
||||
uint32_t cornerSteps = array[0];
|
||||
uint32_t edgeSteps = array[1] - array[0];
|
||||
uint32_t faceSteps = array[2] - array[1];
|
||||
|
||||
return cornerSteps * sqrt_3 + edgeSteps * sqrt_2 + faceSteps * sqrt_1;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
float AStarPathfinder<VoxelType>::computeH(const Vector3DInt16& a, const Vector3DInt16& b)
|
||||
float AStarPathfinder<VoxelType>::computeH(const Vector3DInt32& a, const Vector3DInt32& b)
|
||||
{
|
||||
float hVal;
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace PolyVox
|
||||
,m_meshCurrent(result)
|
||||
{
|
||||
m_regSizeInCells = m_regSizeInVoxels;
|
||||
m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt16(1,1,1));
|
||||
m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1));
|
||||
|
||||
m_meshCurrent->clear();
|
||||
}
|
||||
@ -54,15 +54,16 @@ namespace PolyVox
|
||||
memset(m_previousSliceVertices.getRawData(), 0xff, m_previousSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
|
||||
memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
|
||||
|
||||
for(int16_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ() + 1; z++)
|
||||
for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ() + 1; z++)
|
||||
{
|
||||
for(int16_t y = m_regSizeInVoxels.getLowerCorner().getY(); y <= m_regSizeInVoxels.getUpperCorner().getY() + 1; y++)
|
||||
for(int32_t y = m_regSizeInVoxels.getLowerCorner().getY(); y <= m_regSizeInVoxels.getUpperCorner().getY() + 1; y++)
|
||||
{
|
||||
for(int16_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX() + 1; x++)
|
||||
for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX() + 1; x++)
|
||||
{
|
||||
uint16_t regX = x - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
uint16_t regY = y - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
uint16_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
// these are always positive anyway
|
||||
uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
uint32_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
|
||||
bool finalX = (x == m_regSizeInVoxels.getUpperCorner().getX() + 1);
|
||||
bool finalY = (y == m_regSizeInVoxels.getUpperCorner().getY() + 1);
|
||||
@ -166,8 +167,8 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
int32_t CubicSurfaceExtractor<VoxelType>::addVertex(float fX, float fY, float fZ, uint8_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
||||
{
|
||||
uint16_t uX = static_cast<uint16_t>(fX + 0.75f);
|
||||
uint16_t uY = static_cast<uint16_t>(fY + 0.75f);
|
||||
uint32_t uX = static_cast<uint32_t>(fX + 0.75f);
|
||||
uint32_t uY = static_cast<uint32_t>(fY + 0.75f);
|
||||
|
||||
for(uint32_t ct = 0; ct < MaxQuadsSharingVertex; ct++)
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ namespace PolyVox
|
||||
,m_meshCurrent(result)
|
||||
{
|
||||
m_regSizeInCells = m_regSizeInVoxels;
|
||||
m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt16(1,1,1));
|
||||
m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1));
|
||||
|
||||
m_meshCurrent->clear();
|
||||
}
|
||||
@ -45,15 +45,16 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void CubicSurfaceExtractorWithNormals<VoxelType>::execute()
|
||||
{
|
||||
for(int16_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z < m_regSizeInVoxels.getUpperCorner().getZ(); z++)
|
||||
for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z < m_regSizeInVoxels.getUpperCorner().getZ(); z++)
|
||||
{
|
||||
for(int16_t y = m_regSizeInVoxels.getLowerCorner().getY(); y < m_regSizeInVoxels.getUpperCorner().getY(); y++)
|
||||
for(int32_t y = m_regSizeInVoxels.getLowerCorner().getY(); y < m_regSizeInVoxels.getUpperCorner().getY(); y++)
|
||||
{
|
||||
for(int16_t x = m_regSizeInVoxels.getLowerCorner().getX(); x < m_regSizeInVoxels.getUpperCorner().getX(); x++)
|
||||
for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x < m_regSizeInVoxels.getUpperCorner().getX(); x++)
|
||||
{
|
||||
uint16_t regX = x - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
uint16_t regY = y - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
uint16_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
// these are always positive anyway
|
||||
uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
uint32_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
|
||||
int currentVoxel = m_volData->getVoxelAt(x,y,z).getDensity() >= VoxelType::getThreshold();
|
||||
|
||||
|
@ -49,9 +49,9 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
Vector3DFloat computeDecimatedCentralDifferenceGradient(const VolumeSampler<VoxelType>& volIter)
|
||||
{
|
||||
const uint16_t x = volIter.getPosX();
|
||||
const uint16_t y = volIter.getPosY();
|
||||
const uint16_t z = volIter.getPosZ();
|
||||
const int32_t x = volIter.getPosX();
|
||||
const int32_t y = volIter.getPosY();
|
||||
const int32_t z = volIter.getPosZ();
|
||||
|
||||
//FIXME - bitwise way of doing this?
|
||||
VoxelType voxel1nx = volIter.getVoxelAt(x-2, y ,z ) > 0 ? 1: 0;
|
||||
@ -74,9 +74,9 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
Vector3DFloat computeSmoothCentralDifferenceGradient(VolumeSampler<VoxelType>& volIter)
|
||||
{
|
||||
uint16_t initialX = volIter.getPosX();
|
||||
uint16_t initialY = volIter.getPosY();
|
||||
uint16_t initialZ = volIter.getPosZ();
|
||||
int32_t initialX = volIter.getPosX();
|
||||
int32_t initialY = volIter.getPosY();
|
||||
int32_t initialZ = volIter.getPosZ();
|
||||
|
||||
//FIXME - bitwise way of doing this?
|
||||
volIter.setPosition(initialX-1, initialY, initialZ);
|
||||
@ -191,9 +191,9 @@ namespace PolyVox
|
||||
static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, {
|
||||
{3,6,3}, {6,0,6}, {3,6,3} }, { {2,3,2}, {3,6,3}, {2,3,2} } };
|
||||
|
||||
uint16_t initialX = volIter.getPosX();
|
||||
uint16_t initialY = volIter.getPosY();
|
||||
uint16_t initialZ = volIter.getPosZ();
|
||||
int32_t initialX = volIter.getPosX();
|
||||
int32_t initialY = volIter.getPosY();
|
||||
int32_t initialZ = volIter.getPosZ();
|
||||
|
||||
volIter.setPosition(initialX-1, initialY-1, initialZ-1); const float pVoxel1nx1ny1nz = computeSmoothedVoxel(volIter);
|
||||
volIter.setPosition(initialX-1, initialY-1, initialZ ); const float pVoxel1nx1ny0pz = computeSmoothedVoxel(volIter);
|
||||
|
@ -174,7 +174,7 @@ namespace PolyVox
|
||||
for(int ct = 0; ct < vecVertexMetadata.size(); ct++)
|
||||
{
|
||||
Region regTransformed = m_pOutputMesh->m_Region;
|
||||
regTransformed.shift(regTransformed.getLowerCorner() * static_cast<int16_t>(-1));
|
||||
regTransformed.shift(regTransformed.getLowerCorner() * static_cast<int32_t>(-1));
|
||||
|
||||
//Plus and minus X
|
||||
vecVertexMetadata[ct].isOnRegionFace.set(RFF_ON_REGION_FACE_NEG_X, m_pOutputMesh->m_vecVertices[ct].getPosition().getX() < regTransformed.getLowerCorner().getX() + 0.001f);
|
||||
@ -206,7 +206,7 @@ namespace PolyVox
|
||||
for(int ct = 0; ct < vecVertexMetadata.size(); ct++)
|
||||
{
|
||||
Region regTransformed = m_pOutputMesh->m_Region;
|
||||
regTransformed.shift(regTransformed.getLowerCorner() * static_cast<int16_t>(-1));
|
||||
regTransformed.shift(regTransformed.getLowerCorner() * static_cast<int32_t>(-1));
|
||||
|
||||
//Plus and minus X
|
||||
vecVertexMetadata[ct].isOnRegionFace.set(RFF_ON_REGION_FACE_NEG_X, m_pOutputMesh->m_vecVertices[ct].getPosition().getX() < regTransformed.getLowerCorner().getX() + 0.001f);
|
||||
|
@ -84,7 +84,7 @@ namespace PolyVox
|
||||
return false;
|
||||
}
|
||||
|
||||
PolyVox::Vector3DInt16 position;
|
||||
PolyVox::Vector3DInt32 position;
|
||||
Node* parent;
|
||||
float gVal;
|
||||
float hVal;
|
||||
|
@ -25,7 +25,7 @@ freely, subject to the following restrictions:
|
||||
#define __PolyVox_Block_H__
|
||||
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
namespace PolyVox
|
||||
|
@ -37,28 +37,28 @@ namespace PolyVox
|
||||
{
|
||||
public:
|
||||
Region();
|
||||
Region(const Vector3DInt16& v3dLowerCorner, const Vector3DInt16& v3dUpperCorner);
|
||||
Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner);
|
||||
|
||||
const Vector3DInt16& getLowerCorner(void) const;
|
||||
const Vector3DInt16& getUpperCorner(void) const;
|
||||
const Vector3DInt32& getLowerCorner(void) const;
|
||||
const Vector3DInt32& getUpperCorner(void) const;
|
||||
|
||||
void setLowerCorner(const Vector3DInt16& v3dLowerCorner);
|
||||
void setUpperCorner(const Vector3DInt16& v3dUpperCorner);
|
||||
void setLowerCorner(const Vector3DInt32& v3dLowerCorner);
|
||||
void setUpperCorner(const Vector3DInt32& v3dUpperCorner);
|
||||
|
||||
bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const;
|
||||
bool containsPoint(const Vector3DInt16& pos, uint8_t boundary = 0) const;
|
||||
bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const;
|
||||
void cropTo(const Region& other);
|
||||
int16_t depth(void) const;
|
||||
int16_t height(void) const;
|
||||
void shift(const Vector3DInt16& amount);
|
||||
void shiftLowerCorner(const Vector3DInt16& amount);
|
||||
void shiftUpperCorner(const Vector3DInt16& amount);
|
||||
Vector3DInt16 dimensions(void);
|
||||
int16_t width(void) const;
|
||||
int32_t depth(void) const;
|
||||
int32_t height(void) const;
|
||||
void shift(const Vector3DInt32& amount);
|
||||
void shiftLowerCorner(const Vector3DInt32& amount);
|
||||
void shiftUpperCorner(const Vector3DInt32& amount);
|
||||
Vector3DInt32 dimensions(void);
|
||||
int32_t width(void) const;
|
||||
|
||||
private:
|
||||
Vector3DInt16 m_v3dLowerCorner;
|
||||
Vector3DInt16 m_v3dUpperCorner;
|
||||
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.
|
||||
|
@ -71,14 +71,14 @@ namespace PolyVox
|
||||
VolumeSampler<VoxelType> m_sampVolume;
|
||||
|
||||
//Holds a position in volume space.
|
||||
int16_t iXVolSpace;
|
||||
int16_t iYVolSpace;
|
||||
int16_t iZVolSpace;
|
||||
int32_t iXVolSpace;
|
||||
int32_t iYVolSpace;
|
||||
int32_t iZVolSpace;
|
||||
|
||||
//Holds a position in region space.
|
||||
uint16_t uXRegSpace;
|
||||
uint16_t uYRegSpace;
|
||||
uint16_t uZRegSpace;
|
||||
uint32_t uXRegSpace;
|
||||
uint32_t uYRegSpace;
|
||||
uint32_t uZRegSpace;
|
||||
|
||||
//Used to return the number of cells in a slice which contain triangles.
|
||||
uint32_t m_uNoOfOccupiedCells;
|
||||
|
@ -38,7 +38,7 @@ namespace PolyVox
|
||||
{
|
||||
//m_regSizeInVoxels.cropTo(m_volData->getEnclosingRegion());
|
||||
m_regSizeInCells = m_regSizeInVoxels;
|
||||
m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt16(1,1,1));
|
||||
m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1));
|
||||
|
||||
m_meshCurrent->clear();
|
||||
}
|
||||
@ -61,7 +61,7 @@ namespace PolyVox
|
||||
|
||||
//Create a region corresponding to the first slice
|
||||
m_regSlicePrevious = m_regSizeInVoxels;
|
||||
Vector3DInt16 v3dUpperCorner = m_regSlicePrevious.getUpperCorner();
|
||||
Vector3DInt32 v3dUpperCorner = m_regSlicePrevious.getUpperCorner();
|
||||
v3dUpperCorner.setZ(m_regSlicePrevious.getLowerCorner().getZ()); //Set the upper z to the lower z to make it one slice thick.
|
||||
m_regSlicePrevious.setUpperCorner(v3dUpperCorner);
|
||||
m_regSliceCurrent = m_regSlicePrevious;
|
||||
@ -88,10 +88,10 @@ namespace PolyVox
|
||||
m_pPreviousVertexIndicesZ.swap(m_pCurrentVertexIndicesZ);
|
||||
|
||||
m_regSlicePrevious = m_regSliceCurrent;
|
||||
m_regSliceCurrent.shift(Vector3DInt16(0,0,1));
|
||||
m_regSliceCurrent.shift(Vector3DInt32(0,0,1));
|
||||
|
||||
//Process the other slices (previous slice is available)
|
||||
for(int16_t uSlice = 1; uSlice <= m_regSizeInVoxels.depth(); uSlice++)
|
||||
for(int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.depth(); uSlice++)
|
||||
{
|
||||
computeBitmaskForSlice<true>(pPreviousBitmask, pCurrentBitmask);
|
||||
uNoOfNonEmptyCellsForSlice1 = m_uNoOfOccupiedCells;
|
||||
@ -116,7 +116,7 @@ namespace PolyVox
|
||||
m_pPreviousVertexIndicesZ.swap(m_pCurrentVertexIndicesZ);
|
||||
|
||||
m_regSlicePrevious = m_regSliceCurrent;
|
||||
m_regSliceCurrent.shift(Vector3DInt16(0,0,1));
|
||||
m_regSliceCurrent.shift(Vector3DInt32(0,0,1));
|
||||
}
|
||||
|
||||
m_meshCurrent->m_Region = m_regSizeInVoxels;
|
||||
@ -134,8 +134,8 @@ namespace PolyVox
|
||||
{
|
||||
m_uNoOfOccupiedCells = 0;
|
||||
|
||||
const int16_t iMaxXVolSpace = m_regSliceCurrent.getUpperCorner().getX();
|
||||
const int16_t iMaxYVolSpace = m_regSliceCurrent.getUpperCorner().getY();
|
||||
const int32_t iMaxXVolSpace = m_regSliceCurrent.getUpperCorner().getX();
|
||||
const int32_t iMaxYVolSpace = m_regSliceCurrent.getUpperCorner().getY();
|
||||
|
||||
iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ();
|
||||
uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
@ -400,18 +400,18 @@ namespace PolyVox
|
||||
Array2DInt32& m_pCurrentVertexIndicesY,
|
||||
Array2DInt32& m_pCurrentVertexIndicesZ)
|
||||
{
|
||||
int16_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ();
|
||||
const uint16_t uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
int32_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ();
|
||||
const uint32_t uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
|
||||
//Iterate over each cell in the region
|
||||
for(int16_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY(); iYVolSpace <= m_regSliceCurrent.getUpperCorner().getY(); iYVolSpace++)
|
||||
for(int32_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY(); iYVolSpace <= m_regSliceCurrent.getUpperCorner().getY(); iYVolSpace++)
|
||||
{
|
||||
const uint16_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
const uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
|
||||
for(int16_t iXVolSpace = m_regSliceCurrent.getLowerCorner().getX(); iXVolSpace <= m_regSliceCurrent.getUpperCorner().getX(); iXVolSpace++)
|
||||
for(int32_t iXVolSpace = m_regSliceCurrent.getLowerCorner().getX(); iXVolSpace <= m_regSliceCurrent.getUpperCorner().getX(); iXVolSpace++)
|
||||
{
|
||||
//Current position
|
||||
const uint16_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
const uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
|
||||
//Determine the index into the edge table which tells us which vertices are inside of the surface
|
||||
uint8_t iCubeIndex = pCurrentBitmask[uXRegSpace][uYRegSpace];
|
||||
@ -622,17 +622,17 @@ namespace PolyVox
|
||||
indlist[i] = -1;
|
||||
}
|
||||
|
||||
for(int16_t iYVolSpace = m_regSlicePrevious.getLowerCorner().getY(); iYVolSpace <= m_regSizeInCells.getUpperCorner().getY(); iYVolSpace++)
|
||||
for(int32_t iYVolSpace = m_regSlicePrevious.getLowerCorner().getY(); iYVolSpace <= m_regSizeInCells.getUpperCorner().getY(); iYVolSpace++)
|
||||
{
|
||||
for(int16_t iXVolSpace = m_regSlicePrevious.getLowerCorner().getX(); iXVolSpace <= m_regSizeInCells.getUpperCorner().getX(); iXVolSpace++)
|
||||
for(int32_t iXVolSpace = m_regSlicePrevious.getLowerCorner().getX(); iXVolSpace <= m_regSizeInCells.getUpperCorner().getX(); iXVolSpace++)
|
||||
{
|
||||
int16_t iZVolSpace = m_regSlicePrevious.getLowerCorner().getZ();
|
||||
int32_t iZVolSpace = m_regSlicePrevious.getLowerCorner().getZ();
|
||||
m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace);
|
||||
|
||||
//Current position
|
||||
const uint16_t uXRegSpace = m_sampVolume.getPosX() - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
const uint16_t uYRegSpace = m_sampVolume.getPosY() - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
const uint16_t uZRegSpace = m_sampVolume.getPosZ() - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
const uint32_t uXRegSpace = m_sampVolume.getPosX() - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
const uint32_t uYRegSpace = m_sampVolume.getPosY() - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
const uint32_t uZRegSpace = m_sampVolume.getPosZ() - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
|
||||
//Determine the index into the edge table which tells us which vertices are inside of the surface
|
||||
uint8_t iCubeIndex = pPreviousBitmask[uXRegSpace][uYRegSpace];
|
||||
@ -717,9 +717,6 @@ namespace PolyVox
|
||||
assert(ind1 >= 0);
|
||||
assert(ind2 >= 0);
|
||||
|
||||
assert(ind0 < 1000000);
|
||||
assert(ind1 < 1000000);
|
||||
assert(ind2 < 1000000);
|
||||
m_meshCurrent->addTriangle(ind0, ind1, ind2);
|
||||
}
|
||||
}//For each triangle
|
||||
|
@ -122,7 +122,7 @@ namespace PolyVox
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength = 32);
|
||||
Volume(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength = 32);
|
||||
/// Destructor
|
||||
~Volume();
|
||||
|
||||
@ -131,40 +131,40 @@ namespace PolyVox
|
||||
/// Gets a Region representing the extents of the Volume.
|
||||
Region getEnclosingRegion(void) const;
|
||||
/// Gets the width of the volume in voxels.
|
||||
uint16_t getWidth(void) const;
|
||||
int32_t getWidth(void) const;
|
||||
/// Gets the height of the volume in voxels.
|
||||
uint16_t getHeight(void) const;
|
||||
int32_t getHeight(void) const;
|
||||
/// Gets the depth of the volume in voxels.
|
||||
uint16_t getDepth(void) const;
|
||||
int32_t getDepth(void) const;
|
||||
/// Gets the length of the longest side in voxels
|
||||
uint16_t getLongestSideLength(void) const;
|
||||
int32_t getLongestSideLength(void) const;
|
||||
/// Gets the length of the shortest side in voxels
|
||||
uint16_t getShortestSideLength(void) const;
|
||||
int32_t getShortestSideLength(void) const;
|
||||
/// Gets the length of the diagonal in voxels
|
||||
float getDiagonalLength(void) const;
|
||||
/// Gets a voxel by <tt>x,y,z</tt> position
|
||||
VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
|
||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||
/// Gets a voxel by 3D vector position
|
||||
VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
|
||||
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
||||
|
||||
/// Sets the number of blocks for which uncompressed data is stored.
|
||||
void setBlockCacheSize(uint16_t uBlockCacheSize);
|
||||
/// Sets the value used for voxels which are outside the volume
|
||||
void setBorderValue(const VoxelType& tBorder);
|
||||
/// Sets the voxel at an <tt>x,y,z</tt> position
|
||||
bool setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
|
||||
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
|
||||
/// Sets the voxel at a 3D vector position
|
||||
bool setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
|
||||
bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue);
|
||||
|
||||
void clearBlockCache(void);
|
||||
float calculateCompressionRatio(void);
|
||||
uint32_t calculateSizeInBytes(void);
|
||||
void useCompatibilityMode(void);
|
||||
/// Resizes the volume to the specified dimensions
|
||||
void resize(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength = 32);
|
||||
void resize(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength = 32);
|
||||
|
||||
private:
|
||||
Block<VoxelType>* getUncompressedBlock(uint16_t uBlockX, uint16_t uBlockY, uint16_t uBlockZ) const;
|
||||
Block<VoxelType>* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
|
||||
|
||||
//The block data
|
||||
mutable std::vector< Block<VoxelType> > m_pBlocks;
|
||||
@ -187,19 +187,19 @@ namespace PolyVox
|
||||
|
||||
uint32_t m_uNoOfBlocksInVolume;
|
||||
|
||||
uint16_t m_uWidthInBlocks;
|
||||
uint16_t m_uHeightInBlocks;
|
||||
uint16_t m_uDepthInBlocks;
|
||||
int32_t m_uWidthInBlocks;
|
||||
int32_t m_uHeightInBlocks;
|
||||
int32_t m_uDepthInBlocks;
|
||||
|
||||
uint16_t m_uWidth;
|
||||
uint16_t m_uHeight;
|
||||
uint16_t m_uDepth;
|
||||
int32_t m_uWidth;
|
||||
int32_t m_uHeight;
|
||||
int32_t m_uDepth;
|
||||
|
||||
uint8_t m_uBlockSideLengthPower;
|
||||
uint16_t m_uBlockSideLength;
|
||||
|
||||
uint16_t m_uLongestSideLength;
|
||||
uint16_t m_uShortestSideLength;
|
||||
int32_t m_uLongestSideLength;
|
||||
int32_t m_uShortestSideLength;
|
||||
float m_fDiagonalLength;
|
||||
};
|
||||
|
||||
|
@ -27,6 +27,7 @@ freely, subject to the following restrictions:
|
||||
#include "Region.h"
|
||||
#include "Vector.h"
|
||||
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
#include <cstring> //For memcpy
|
||||
#include <list>
|
||||
@ -47,7 +48,7 @@ namespace PolyVox
|
||||
/// the default if you are not sure what to choose here.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
Volume<VoxelType>::Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength)
|
||||
Volume<VoxelType>::Volume(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength)
|
||||
:m_uTimestamper(0)
|
||||
,m_uMaxUncompressedBlockCacheSize(256)
|
||||
,m_uBlockSideLength(uBlockSideLength)
|
||||
@ -90,7 +91,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
Region Volume<VoxelType>::getEnclosingRegion(void) const
|
||||
{
|
||||
return Region(Vector3DInt16(0,0,0), Vector3DInt16(m_uWidth-1,m_uHeight-1,m_uDepth-1));
|
||||
return Region(Vector3DInt32(0,0,0), Vector3DInt32(m_uWidth-1,m_uHeight-1,m_uDepth-1));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -98,7 +99,7 @@ namespace PolyVox
|
||||
/// \sa getHeight(), getDepth()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
uint16_t Volume<VoxelType>::getWidth(void) const
|
||||
int32_t Volume<VoxelType>::getWidth(void) const
|
||||
{
|
||||
return m_uWidth;
|
||||
}
|
||||
@ -108,7 +109,7 @@ namespace PolyVox
|
||||
/// \sa getWidth(), getDepth()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
uint16_t Volume<VoxelType>::getHeight(void) const
|
||||
int32_t Volume<VoxelType>::getHeight(void) const
|
||||
{
|
||||
return m_uHeight;
|
||||
}
|
||||
@ -118,7 +119,7 @@ namespace PolyVox
|
||||
/// \sa getWidth(), getHeight()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
uint16_t Volume<VoxelType>::getDepth(void) const
|
||||
int32_t Volume<VoxelType>::getDepth(void) const
|
||||
{
|
||||
return m_uDepth;
|
||||
}
|
||||
@ -129,7 +130,7 @@ namespace PolyVox
|
||||
/// \sa getLongestSideLength(), getDiagonalLength()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
uint16_t Volume<VoxelType>::getShortestSideLength(void) const
|
||||
int32_t Volume<VoxelType>::getShortestSideLength(void) const
|
||||
{
|
||||
return m_uShortestSideLength;
|
||||
}
|
||||
@ -140,7 +141,7 @@ namespace PolyVox
|
||||
/// \sa getShortestSideLength(), getDiagonalLength()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
uint16_t Volume<VoxelType>::getLongestSideLength(void) const
|
||||
int32_t Volume<VoxelType>::getLongestSideLength(void) const
|
||||
{
|
||||
return m_uLongestSideLength;
|
||||
}
|
||||
@ -164,15 +165,15 @@ namespace PolyVox
|
||||
/// \return the voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType Volume<VoxelType>::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
|
||||
VoxelType Volume<VoxelType>::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
||||
{
|
||||
//We don't use getEnclosingRegion here because we care
|
||||
//about speed and don't need to check the lower bound.
|
||||
if((uXPos < getWidth()) && (uYPos < getHeight()) && (uZPos < getDepth()))
|
||||
//about speed
|
||||
if((uXPos >=0) && (uYPos >=0) && (uZPos >=0) && (uXPos < getWidth()) && (uYPos < getHeight()) && (uZPos < getDepth()))
|
||||
{
|
||||
const uint16_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const uint16_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
const uint16_t blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||
|
||||
const uint16_t xOffset = uXPos - (blockX << m_uBlockSideLengthPower);
|
||||
const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
|
||||
@ -193,7 +194,7 @@ namespace PolyVox
|
||||
/// \return the voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType Volume<VoxelType>::getVoxelAt(const Vector3DUint16& v3dPos) const
|
||||
VoxelType Volume<VoxelType>::getVoxelAt(const Vector3DInt32& v3dPos) const
|
||||
{
|
||||
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||
}
|
||||
@ -231,15 +232,15 @@ namespace PolyVox
|
||||
/// \return whether the requested position is inside the volume
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
bool Volume<VoxelType>::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue)
|
||||
bool Volume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
|
||||
{
|
||||
//We don't use getEnclosingRegion here because we care
|
||||
//about speed and don't need to check the lower bound.
|
||||
if((uXPos < getWidth()) && (uYPos < getHeight()) && (uZPos < getDepth()))
|
||||
//about speed
|
||||
if((uXPos >=0) && (uYPos >=0) && (uZPos >=0) && (uXPos < getWidth()) && (uYPos < getHeight()) && (uZPos < getDepth()))
|
||||
{
|
||||
const uint16_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const uint16_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
const uint16_t blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||
|
||||
const uint16_t xOffset = uXPos - (blockX << m_uBlockSideLengthPower);
|
||||
const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
|
||||
@ -265,7 +266,7 @@ namespace PolyVox
|
||||
/// \return whether the requested position is inside the volume
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
bool Volume<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
|
||||
bool Volume<VoxelType>::setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue)
|
||||
{
|
||||
return setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
|
||||
}
|
||||
@ -294,7 +295,7 @@ namespace PolyVox
|
||||
/// the default if you are not sure what to choose here.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
void Volume<VoxelType>::resize(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength)
|
||||
void Volume<VoxelType>::resize(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength)
|
||||
{
|
||||
//Debug mode validation
|
||||
assert(uBlockSideLength > 0);
|
||||
@ -302,6 +303,9 @@ namespace PolyVox
|
||||
assert(uBlockSideLength <= uWidth);
|
||||
assert(uBlockSideLength <= uHeight);
|
||||
assert(uBlockSideLength <= uDepth);
|
||||
assert(0 < uWidth);
|
||||
assert(0 < uHeight);
|
||||
assert(0 < uDepth);
|
||||
|
||||
//Release mode validation
|
||||
if(uBlockSideLength == 0)
|
||||
@ -324,6 +328,18 @@ namespace PolyVox
|
||||
{
|
||||
throw std::invalid_argument("Block side length cannot be greater than volume depth.");
|
||||
}
|
||||
if(0 >= uWidth)
|
||||
{
|
||||
throw std::invalid_argument("Volume width cannot be smaller than 1.");
|
||||
}
|
||||
if(0 >= uHeight)
|
||||
{
|
||||
throw std::invalid_argument("Volume height cannot be smaller than 1.");
|
||||
}
|
||||
if(0 >= uDepth)
|
||||
{
|
||||
throw std::invalid_argument("Volume depth cannot be smaller than 1.");
|
||||
}
|
||||
|
||||
//Clear the previous data
|
||||
m_pBlocks.clear();
|
||||
@ -367,14 +383,21 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
Block<VoxelType>* Volume<VoxelType>::getUncompressedBlock(uint16_t uBlockX, uint16_t uBlockY, uint16_t uBlockZ) const
|
||||
Block<VoxelType>* Volume<VoxelType>::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const
|
||||
{
|
||||
assert(uBlockX >= 0);
|
||||
assert(uBlockY >= 0);
|
||||
assert(uBlockZ >= 0);
|
||||
assert(uBlockX < m_uWidthInBlocks);
|
||||
assert(uBlockY < m_uHeightInBlocks);
|
||||
assert(uBlockZ < m_uDepthInBlocks);
|
||||
//Compute the block's index from it's position.
|
||||
uint32_t uBlockIndex =
|
||||
const int32_t uBlockIndex =
|
||||
uBlockX +
|
||||
uBlockY * m_uWidthInBlocks +
|
||||
uBlockZ * m_uWidthInBlocks * m_uHeightInBlocks;
|
||||
|
||||
assert(uBlockIndex < m_uNoOfBlocksInVolume);
|
||||
assert(uBlockIndex >= 0);
|
||||
//Get the block
|
||||
Block<VoxelType>* block = &(m_pBlocks[uBlockIndex]);
|
||||
|
||||
@ -396,12 +419,12 @@ namespace PolyVox
|
||||
//Currently we find the oldest block by iterating over the whole array. Of course we could store the blocks sorted by
|
||||
//timestamp (set, priority_queue, etc) but then we'll need to move them around as the timestamp changes. Can come back
|
||||
//to this if it proves to be a bottleneck (compraed to the cost of actually doing the compression/decompression).
|
||||
uint32_t uUncompressedBlockIndex = 100000000;
|
||||
uint32_t uUncompressedBlockIndex = (std::numeric_limits<uint32_t>::max)();
|
||||
assert(m_vecUncompressedBlockCache.size() <= m_uMaxUncompressedBlockCacheSize);
|
||||
if(m_vecUncompressedBlockCache.size() == m_uMaxUncompressedBlockCacheSize)
|
||||
{
|
||||
int32_t leastRecentlyUsedBlockIndex = -1;
|
||||
uint64_t uLeastRecentTimestamp = 1000000000000000;
|
||||
uint32_t uLeastRecentTimestamp = (std::numeric_limits<uint32_t>::max)(); // you said not int64 ;)
|
||||
for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++)
|
||||
{
|
||||
if(m_pUncompressedTimestamps[m_vecUncompressedBlockCache[ct].uBlockIndex] < uLeastRecentTimestamp)
|
||||
@ -469,11 +492,11 @@ namespace PolyVox
|
||||
{
|
||||
setBlockCacheSize(m_uNoOfBlocksInVolume * 2); //Times two gives space to spare
|
||||
|
||||
for(uint32_t z = 0; z < m_uDepthInBlocks; z++)
|
||||
for(int32_t z = 0; z < m_uDepthInBlocks; z++)
|
||||
{
|
||||
for(uint32_t y = 0; y < m_uHeightInBlocks; y++)
|
||||
for(int32_t y = 0; y < m_uHeightInBlocks; y++)
|
||||
{
|
||||
for(uint32_t x = 0; x < m_uWidthInBlocks; x++)
|
||||
for(int32_t x = 0; x < m_uWidthInBlocks; x++)
|
||||
{
|
||||
getUncompressedBlock(x,y,z);
|
||||
}
|
||||
|
@ -37,15 +37,15 @@ namespace PolyVox
|
||||
|
||||
VolumeSampler<VoxelType>& operator=(const VolumeSampler<VoxelType>& rhs) throw();
|
||||
|
||||
uint16_t getPosX(void) const;
|
||||
uint16_t getPosY(void) const;
|
||||
uint16_t getPosZ(void) const;
|
||||
int32_t getPosX(void) const;
|
||||
int32_t getPosY(void) const;
|
||||
int32_t getPosZ(void) const;
|
||||
VoxelType getSubSampledVoxel(uint8_t uLevel) const;
|
||||
const Volume<VoxelType>* getVolume(void) const;
|
||||
inline VoxelType getVoxel(void) const;
|
||||
|
||||
void setPosition(const Vector3DInt16& v3dNewPos);
|
||||
void setPosition(uint16_t xPos, uint16_t yPos, uint16_t zPos);
|
||||
void setPosition(const Vector3DInt32& v3dNewPos);
|
||||
void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
|
||||
|
||||
void movePositiveX(void);
|
||||
void movePositiveY(void);
|
||||
@ -91,9 +91,9 @@ namespace PolyVox
|
||||
Volume<VoxelType>* mVolume;
|
||||
|
||||
//The current position in the volume
|
||||
uint16_t mXPosInVolume;
|
||||
uint16_t mYPosInVolume;
|
||||
uint16_t mZPosInVolume;
|
||||
int32_t mXPosInVolume;
|
||||
int32_t mYPosInVolume;
|
||||
int32_t mZPosInVolume;
|
||||
|
||||
//Other current position information
|
||||
VoxelType* mCurrentVoxel;
|
||||
|
@ -56,19 +56,19 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
uint16_t VolumeSampler<VoxelType>::getPosX(void) const
|
||||
int32_t VolumeSampler<VoxelType>::getPosX(void) const
|
||||
{
|
||||
return mXPosInVolume;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
uint16_t VolumeSampler<VoxelType>::getPosY(void) const
|
||||
int32_t VolumeSampler<VoxelType>::getPosY(void) const
|
||||
{
|
||||
return mYPosInVolume;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
uint16_t VolumeSampler<VoxelType>::getPosZ(void) const
|
||||
int32_t VolumeSampler<VoxelType>::getPosZ(void) const
|
||||
{
|
||||
return mZPosInVolume;
|
||||
}
|
||||
@ -124,21 +124,21 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void VolumeSampler<VoxelType>::setPosition(const Vector3DInt16& v3dNewPos)
|
||||
void VolumeSampler<VoxelType>::setPosition(const Vector3DInt32& v3dNewPos)
|
||||
{
|
||||
setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void VolumeSampler<VoxelType>::setPosition(uint16_t xPos, uint16_t yPos, uint16_t zPos)
|
||||
void VolumeSampler<VoxelType>::setPosition(int32_t xPos, int32_t yPos, int32_t zPos)
|
||||
{
|
||||
mXPosInVolume = xPos;
|
||||
mYPosInVolume = yPos;
|
||||
mZPosInVolume = zPos;
|
||||
|
||||
const uint16_t uXBlock = mXPosInVolume >> mVolume->m_uBlockSideLengthPower;
|
||||
const uint16_t uYBlock = mYPosInVolume >> mVolume->m_uBlockSideLengthPower;
|
||||
const uint16_t uZBlock = mZPosInVolume >> mVolume->m_uBlockSideLengthPower;
|
||||
const int32_t uXBlock = mXPosInVolume >> mVolume->m_uBlockSideLengthPower;
|
||||
const int32_t uYBlock = mYPosInVolume >> mVolume->m_uBlockSideLengthPower;
|
||||
const int32_t uZBlock = mZPosInVolume >> mVolume->m_uBlockSideLengthPower;
|
||||
|
||||
const uint16_t uXPosInBlock = mXPosInVolume - (uXBlock << mVolume->m_uBlockSideLengthPower);
|
||||
const uint16_t uYPosInBlock = mYPosInVolume - (uYBlock << mVolume->m_uBlockSideLengthPower);
|
||||
@ -148,7 +148,7 @@ namespace PolyVox
|
||||
uYPosInBlock * mVolume->m_uBlockSideLength +
|
||||
uZPosInBlock * mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength;
|
||||
|
||||
if((uXBlock < mVolume->m_uWidthInBlocks) && (uYBlock < mVolume->m_uHeightInBlocks) && (uZBlock < mVolume->m_uDepthInBlocks))
|
||||
if((uXBlock < mVolume->m_uWidthInBlocks) && (uYBlock < mVolume->m_uHeightInBlocks) && (uZBlock < mVolume->m_uDepthInBlocks) && (uXBlock >= 0) && (uYBlock >= 0) && (uZBlock >=0))
|
||||
{
|
||||
const uint32_t uBlockIndexInVolume = uXBlock +
|
||||
uYBlock * mVolume->m_uWidthInBlocks +
|
||||
|
@ -29,41 +29,41 @@ using namespace PolyVox;
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
const Vector3DInt16 arrayPathfinderFaces[6] =
|
||||
const Vector3DInt32 arrayPathfinderFaces[6] =
|
||||
{
|
||||
Vector3DInt16(0, 0, -1),
|
||||
Vector3DInt16(0, 0, +1),
|
||||
Vector3DInt16(0, -1, 0),
|
||||
Vector3DInt16(0, +1, 0),
|
||||
Vector3DInt16(-1, 0, 0),
|
||||
Vector3DInt16(+1, 0, 0)
|
||||
Vector3DInt32(0, 0, -1),
|
||||
Vector3DInt32(0, 0, +1),
|
||||
Vector3DInt32(0, -1, 0),
|
||||
Vector3DInt32(0, +1, 0),
|
||||
Vector3DInt32(-1, 0, 0),
|
||||
Vector3DInt32(+1, 0, 0)
|
||||
};
|
||||
|
||||
const Vector3DInt16 arrayPathfinderEdges[12] =
|
||||
const Vector3DInt32 arrayPathfinderEdges[12] =
|
||||
{
|
||||
Vector3DInt16(0, -1, -1),
|
||||
Vector3DInt16(0, -1, +1),
|
||||
Vector3DInt16(0, +1, -1),
|
||||
Vector3DInt16(0, +1, +1),
|
||||
Vector3DInt16(-1, 0, -1),
|
||||
Vector3DInt16(-1, 0, +1),
|
||||
Vector3DInt16(+1, 0, -1),
|
||||
Vector3DInt16(+1, 0, +1),
|
||||
Vector3DInt16(-1, -1, 0),
|
||||
Vector3DInt16(-1, +1, 0),
|
||||
Vector3DInt16(+1, -1, 0),
|
||||
Vector3DInt16(+1, +1, 0)
|
||||
Vector3DInt32(0, -1, -1),
|
||||
Vector3DInt32(0, -1, +1),
|
||||
Vector3DInt32(0, +1, -1),
|
||||
Vector3DInt32(0, +1, +1),
|
||||
Vector3DInt32(-1, 0, -1),
|
||||
Vector3DInt32(-1, 0, +1),
|
||||
Vector3DInt32(+1, 0, -1),
|
||||
Vector3DInt32(+1, 0, +1),
|
||||
Vector3DInt32(-1, -1, 0),
|
||||
Vector3DInt32(-1, +1, 0),
|
||||
Vector3DInt32(+1, -1, 0),
|
||||
Vector3DInt32(+1, +1, 0)
|
||||
};
|
||||
|
||||
const Vector3DInt16 arrayPathfinderCorners[8] =
|
||||
const Vector3DInt32 arrayPathfinderCorners[8] =
|
||||
{
|
||||
Vector3DInt16(-1, -1, -1),
|
||||
Vector3DInt16(-1, -1, +1),
|
||||
Vector3DInt16(-1, +1, -1),
|
||||
Vector3DInt16(-1, +1, +1),
|
||||
Vector3DInt16(+1, -1, -1),
|
||||
Vector3DInt16(+1, -1, +1),
|
||||
Vector3DInt16(+1, +1, -1),
|
||||
Vector3DInt16(+1, +1, +1)
|
||||
Vector3DInt32(-1, -1, -1),
|
||||
Vector3DInt32(-1, -1, +1),
|
||||
Vector3DInt32(-1, +1, -1),
|
||||
Vector3DInt32(-1, +1, +1),
|
||||
Vector3DInt32(+1, -1, -1),
|
||||
Vector3DInt32(+1, -1, +1),
|
||||
Vector3DInt32(+1, +1, -1),
|
||||
Vector3DInt32(+1, +1, +1)
|
||||
};
|
||||
}
|
@ -37,13 +37,13 @@ namespace PolyVox
|
||||
while(iterSurfaceVertex != vecVertices.end())
|
||||
{
|
||||
const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());
|
||||
const Vector3DInt16 v3dFloor = static_cast<Vector3DInt16>(v3dPos);
|
||||
const Vector3DInt32 v3dFloor = static_cast<Vector3DInt32>(v3dPos);
|
||||
|
||||
VolumeSampler<uint8_t> volIter(volumeData);
|
||||
|
||||
//Check all corners are within the volume, allowing a boundary for gradient estimation
|
||||
bool lowerCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor,2);
|
||||
bool upperCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor+Vector3DInt16(1,1,1),2);
|
||||
bool upperCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor+Vector3DInt32(1,1,1),2);
|
||||
|
||||
if(lowerCornerInside && upperCornerInside) //If this test fails the vertex will be left as it was
|
||||
{
|
||||
@ -69,7 +69,7 @@ namespace PolyVox
|
||||
|
||||
const Vector3DInt32 v3dFloor = static_cast<Vector3DInt32>(v3dPos);
|
||||
|
||||
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor));
|
||||
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor));
|
||||
Vector3DFloat gradFloor;
|
||||
switch(normalGenerationMethod)
|
||||
{
|
||||
@ -89,15 +89,15 @@ namespace PolyVox
|
||||
|
||||
if((v3dPos.getX() - v3dFloor.getX()) > 0.25) //The result should be 0.0 or 0.5
|
||||
{
|
||||
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor+Vector3DInt32(1,0,0)));
|
||||
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor+Vector3DInt32(1,0,0)));
|
||||
}
|
||||
if((v3dPos.getY() - v3dFloor.getY()) > 0.25) //The result should be 0.0 or 0.5
|
||||
{
|
||||
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor+Vector3DInt32(0,1,0)));
|
||||
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor+Vector3DInt32(0,1,0)));
|
||||
}
|
||||
if((v3dPos.getZ() - v3dFloor.getZ()) > 0.25) //The result should be 0.0 or 0.5
|
||||
{
|
||||
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor+Vector3DInt32(0,0,1)));
|
||||
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor+Vector3DInt32(0,0,1)));
|
||||
}
|
||||
|
||||
Vector3DFloat gradCeil;
|
||||
@ -126,7 +126,7 @@ namespace PolyVox
|
||||
|
||||
if(normalGenerationMethod == SIMPLE)
|
||||
{
|
||||
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor));
|
||||
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor));
|
||||
const uint8_t uFloor = volIter.getVoxel() > 0 ? 1 : 0;
|
||||
if((v3dPos.getX() - v3dFloor.getX()) > 0.25) //The result should be 0.0 or 0.5
|
||||
{
|
||||
|
@ -31,28 +31,28 @@ namespace PolyVox
|
||||
{
|
||||
}
|
||||
|
||||
Region::Region(const Vector3DInt16& v3dLowerCorner, const Vector3DInt16& v3dUpperCorner)
|
||||
Region::Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner)
|
||||
:m_v3dLowerCorner(v3dLowerCorner)
|
||||
,m_v3dUpperCorner(v3dUpperCorner)
|
||||
{
|
||||
}
|
||||
|
||||
const Vector3DInt16& Region::getLowerCorner(void) const
|
||||
const Vector3DInt32& Region::getLowerCorner(void) const
|
||||
{
|
||||
return m_v3dLowerCorner;
|
||||
}
|
||||
|
||||
const Vector3DInt16& Region::getUpperCorner(void) const
|
||||
const Vector3DInt32& Region::getUpperCorner(void) const
|
||||
{
|
||||
return m_v3dUpperCorner;
|
||||
}
|
||||
|
||||
void Region::setLowerCorner(const Vector3DInt16& v3dLowerCorner)
|
||||
void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner)
|
||||
{
|
||||
m_v3dLowerCorner = v3dLowerCorner;
|
||||
}
|
||||
|
||||
void Region::setUpperCorner(const Vector3DInt16& v3dUpperCorner)
|
||||
void Region::setUpperCorner(const Vector3DInt32& v3dUpperCorner)
|
||||
{
|
||||
m_v3dUpperCorner = v3dUpperCorner;
|
||||
}
|
||||
@ -67,7 +67,7 @@ namespace PolyVox
|
||||
&& (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
|
||||
}
|
||||
|
||||
bool Region::containsPoint(const Vector3DInt16& pos, uint8_t boundary) const
|
||||
bool Region::containsPoint(const Vector3DInt32& pos, uint8_t boundary) const
|
||||
{
|
||||
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
|
||||
&& (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
|
||||
@ -87,38 +87,38 @@ namespace PolyVox
|
||||
m_v3dUpperCorner.setZ((std::min)(m_v3dUpperCorner.getZ(), other.m_v3dUpperCorner.getZ()));
|
||||
}
|
||||
|
||||
int16_t Region::depth(void) const
|
||||
int32_t Region::depth(void) const
|
||||
{
|
||||
return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ();
|
||||
}
|
||||
|
||||
int16_t Region::height(void) const
|
||||
int32_t Region::height(void) const
|
||||
{
|
||||
return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY();
|
||||
}
|
||||
|
||||
void Region::shift(const Vector3DInt16& amount)
|
||||
void Region::shift(const Vector3DInt32& amount)
|
||||
{
|
||||
m_v3dLowerCorner += amount;
|
||||
m_v3dUpperCorner += amount;
|
||||
}
|
||||
|
||||
void Region::shiftLowerCorner(const Vector3DInt16& amount)
|
||||
void Region::shiftLowerCorner(const Vector3DInt32& amount)
|
||||
{
|
||||
m_v3dLowerCorner += amount;
|
||||
}
|
||||
|
||||
void Region::shiftUpperCorner(const Vector3DInt16& amount)
|
||||
void Region::shiftUpperCorner(const Vector3DInt32& amount)
|
||||
{
|
||||
m_v3dUpperCorner += amount;
|
||||
}
|
||||
|
||||
Vector3DInt16 Region::dimensions(void)
|
||||
Vector3DInt32 Region::dimensions(void)
|
||||
{
|
||||
return m_v3dUpperCorner - m_v3dLowerCorner;
|
||||
}
|
||||
|
||||
int16_t Region::width(void) const
|
||||
int32_t Region::width(void) const
|
||||
{
|
||||
return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX();
|
||||
}
|
||||
|
@ -31,15 +31,15 @@ using namespace PolyVox;
|
||||
|
||||
void TestVolume::testSize()
|
||||
{
|
||||
const uint16_t g_uVolumeSideLength = 128;
|
||||
const int32_t g_uVolumeSideLength = 128;
|
||||
Volume<uint8_t> volData(g_uVolumeSideLength, g_uVolumeSideLength, g_uVolumeSideLength);
|
||||
|
||||
//Note: Deliberatly go past each edge by one to test if the bounds checking works.
|
||||
for (uint16_t z = 0; z < g_uVolumeSideLength + 1; z++)
|
||||
for (int32_t z = 0; z < g_uVolumeSideLength + 1; z++)
|
||||
{
|
||||
for (uint16_t y = 0; y < g_uVolumeSideLength + 1; y++)
|
||||
for (int32_t y = 0; y < g_uVolumeSideLength + 1; y++)
|
||||
{
|
||||
for (uint16_t x = 0; x < g_uVolumeSideLength + 1; x++)
|
||||
for (int32_t x = 0; x < g_uVolumeSideLength + 1; x++)
|
||||
{
|
||||
volData.setVoxelAt(x,y,z,255);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user