Tidying up Block and FilePager.
This commit is contained in:
parent
e80fa3de7d
commit
59505d47e9
@ -26,14 +26,17 @@ freely, subject to the following restrictions:
|
||||
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h"
|
||||
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
|
||||
#include "PolyVoxCore/SurfaceMesh.h"
|
||||
#include "PolyVoxCore/SimpleVolume.h"
|
||||
//#include "PolyVoxCore/SimpleVolume.h"
|
||||
#include "PolyVoxCore/LargeVolume.h"
|
||||
#include "PolyVoxCore/RLECompressor.h"
|
||||
#include "PolyVoxCore/FilePager.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
//Use the PolyVox namespace
|
||||
using namespace PolyVox;
|
||||
|
||||
void createSphereInVolume(SimpleVolume<uint8_t>& volData, float fRadius)
|
||||
void createSphereInVolume(LargeVolume<uint8_t>& volData, float fRadius)
|
||||
{
|
||||
//This vector hold the position of the center of the volume
|
||||
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
|
||||
@ -68,21 +71,32 @@ void createSphereInVolume(SimpleVolume<uint8_t>& volData, float fRadius)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setTraceStream(&(std::cout));
|
||||
setDebugStream(&(std::cout));
|
||||
setInfoStream(&(std::cout));
|
||||
|
||||
//Create and show the Qt OpenGL window
|
||||
QApplication app(argc, argv);
|
||||
OpenGLWidget openGLWidget(0);
|
||||
openGLWidget.show();
|
||||
|
||||
//Create an empty volume and then place a sphere in it
|
||||
SimpleVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
|
||||
RLECompressor<uint8_t, uint16_t>* pCompressor = new RLECompressor<uint8_t, uint16_t>();
|
||||
FilePager<uint8_t>* pFilePager = new FilePager<uint8_t>("D:/temp/voldata/");
|
||||
|
||||
LargeVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)), pCompressor, pFilePager, 32);
|
||||
//volData.setMaxNumberOfUncompressedBlocks(6);
|
||||
//volData.setMaxNumberOfBlocksInMemory(7);
|
||||
|
||||
|
||||
createSphereInVolume(volData, 30);
|
||||
|
||||
//A mesh object to hold the result of surface extraction
|
||||
SurfaceMesh<PositionMaterialNormal> mesh;
|
||||
|
||||
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
|
||||
CubicSurfaceExtractorWithNormals< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
//MarchingCubesSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
CubicSurfaceExtractorWithNormals< LargeVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
//MarchingCubesSurfaceExtractor< LargeVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
|
||||
//Execute the surface extractor.
|
||||
surfaceExtractor.execute();
|
||||
|
@ -54,7 +54,7 @@ namespace PolyVox
|
||||
virtual void pageIn(const Region& region, Block<VoxelType>* pBlockData)
|
||||
{
|
||||
POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block");
|
||||
POLYVOX_ASSERT(pBlockData->m_bIsCompressed, "Attempting to page in uncompressed block");
|
||||
POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page in uncompressed block");
|
||||
|
||||
std::stringstream ss;
|
||||
ss << region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_"
|
||||
@ -71,13 +71,13 @@ namespace PolyVox
|
||||
logTrace() << "Paging in data for " << region;
|
||||
|
||||
fseek(pFile, 0L, SEEK_END);
|
||||
pBlockData->m_uCompressedDataLength = ftell(pFile);
|
||||
size_t fileSizeInBytes = ftell(pFile);
|
||||
fseek(pFile, 0L, SEEK_SET);
|
||||
|
||||
delete[] pBlockData->m_pCompressedData;
|
||||
pBlockData->m_pCompressedData = new uint8_t[pBlockData->m_uCompressedDataLength];
|
||||
|
||||
fread(pBlockData->m_pCompressedData, sizeof(uint8_t), pBlockData->m_uCompressedDataLength, pFile);
|
||||
|
||||
uint8_t* buffer = new uint8_t[fileSizeInBytes];
|
||||
fread(buffer, sizeof(uint8_t), fileSizeInBytes, pFile);
|
||||
pBlockData->setCompressedData(buffer, fileSizeInBytes);
|
||||
delete[] buffer;
|
||||
|
||||
if(ferror(pFile))
|
||||
{
|
||||
@ -95,7 +95,7 @@ namespace PolyVox
|
||||
virtual void pageOut(const Region& region, Block<VoxelType>* pBlockData)
|
||||
{
|
||||
POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block");
|
||||
POLYVOX_ASSERT(pBlockData->m_bIsCompressed, "Attempting to page out uncompressed block");
|
||||
POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page out uncompressed block");
|
||||
|
||||
logTrace() << "Paging out data for " << region;
|
||||
|
||||
@ -114,7 +114,7 @@ namespace PolyVox
|
||||
POLYVOX_THROW(std::runtime_error, "Unable to open file to write out block data.");
|
||||
}
|
||||
|
||||
fwrite(pBlockData->m_pCompressedData, sizeof(uint8_t), pBlockData->m_uCompressedDataLength, pFile);
|
||||
fwrite(pBlockData->getCompressedData(), sizeof(uint8_t), pBlockData->getCompressedDataLength(), pFile);
|
||||
|
||||
if(ferror(pFile))
|
||||
{
|
||||
|
@ -51,12 +51,14 @@ namespace PolyVox
|
||||
public:
|
||||
Block(uint16_t uSideLength = 0);
|
||||
|
||||
const uint8_t* getCompressedData(void) const;
|
||||
const uint8_t* const getCompressedData(void) const;
|
||||
const uint32_t getCompressedDataLength(void) const;
|
||||
uint16_t getSideLength(void) const;
|
||||
VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
|
||||
VoxelType getVoxel(const Vector3DUint16& v3dPos) const;
|
||||
|
||||
bool isCompressed(void);
|
||||
|
||||
void setCompressedData(const uint8_t* const data, uint32_t dataLength);
|
||||
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
|
||||
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
|
||||
|
@ -52,7 +52,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
const uint8_t* Block<VoxelType>::getCompressedData(void) const
|
||||
const uint8_t* const Block<VoxelType>::getCompressedData(void) const
|
||||
{
|
||||
POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed");
|
||||
POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL");
|
||||
@ -99,6 +99,12 @@ namespace PolyVox
|
||||
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool Block<VoxelType>::isCompressed(void)
|
||||
{
|
||||
return m_bIsCompressed;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::setCompressedData(const uint8_t* const data, uint32_t dataLength)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user