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:
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user