From 6d25d6e3da5a4551d4b3a9b47388e297fb2ea638 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 12 Oct 2011 22:34:54 +0100 Subject: [PATCH 1/5] Fix to make normal calculation work with float volumes. --- .../include/PolyVoxCore/SurfaceExtractor.h | 86 ++++++++++--------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h index 484944fc..f634dcb5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h @@ -61,20 +61,23 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter) { - uint8_t voxel1nx = volIter.peekVoxel1nx0py0pz().getDensity(); - uint8_t voxel1px = volIter.peekVoxel1px0py0pz().getDensity(); + //FIXME - Should actually use DensityType here, both in principle and because the maths may be + //faster (and to reduce casts). So it would be good to add a way to get DensityType from a voxel. + //But watch out for when the DensityType is unsigned and the difference could be negative. + float voxel1nx = static_cast(volIter.peekVoxel1nx0py0pz().getDensity()); + float voxel1px = static_cast(volIter.peekVoxel1px0py0pz().getDensity()); - uint8_t voxel1ny = volIter.peekVoxel0px1ny0pz().getDensity(); - uint8_t voxel1py = volIter.peekVoxel0px1py0pz().getDensity(); + float voxel1ny = static_cast(volIter.peekVoxel0px1ny0pz().getDensity()); + float voxel1py = static_cast(volIter.peekVoxel0px1py0pz().getDensity()); - uint8_t voxel1nz = volIter.peekVoxel0px0py1nz().getDensity(); - uint8_t voxel1pz = volIter.peekVoxel0px0py1pz().getDensity(); + float voxel1nz = static_cast(volIter.peekVoxel0px0py1nz().getDensity()); + float voxel1pz = static_cast(volIter.peekVoxel0px0py1pz().getDensity()); return Vector3DFloat ( - static_cast(voxel1nx) - static_cast(voxel1px), - static_cast(voxel1ny) - static_cast(voxel1py), - static_cast(voxel1nz) - static_cast(voxel1pz) + voxel1nx - voxel1px, + voxel1ny - voxel1py, + voxel1nz - voxel1pz ); } @@ -83,37 +86,40 @@ 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} } }; - const uint8_t pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz().getDensity(); - const uint8_t pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz().getDensity(); - const uint8_t pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz().getDensity(); - const uint8_t pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz().getDensity(); - const uint8_t pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz().getDensity(); - const uint8_t pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz().getDensity(); - const uint8_t pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz().getDensity(); - const uint8_t pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz().getDensity(); - const uint8_t pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz().getDensity(); + //FIXME - Should actually use DensityType here, both in principle and because the maths may be + //faster (and to reduce casts). So it would be good to add a way to get DensityType from a voxel. + //But watch out for when the DensityType is unsigned and the difference could be negative. + const float pVoxel1nx1ny1nz = static_cast(volIter.peekVoxel1nx1ny1nz().getDensity()); + const float pVoxel1nx1ny0pz = static_cast(volIter.peekVoxel1nx1ny0pz().getDensity()); + const float pVoxel1nx1ny1pz = static_cast(volIter.peekVoxel1nx1ny1pz().getDensity()); + const float pVoxel1nx0py1nz = static_cast(volIter.peekVoxel1nx0py1nz().getDensity()); + const float pVoxel1nx0py0pz = static_cast(volIter.peekVoxel1nx0py0pz().getDensity()); + const float pVoxel1nx0py1pz = static_cast(volIter.peekVoxel1nx0py1pz().getDensity()); + const float pVoxel1nx1py1nz = static_cast(volIter.peekVoxel1nx1py1nz().getDensity()); + const float pVoxel1nx1py0pz = static_cast(volIter.peekVoxel1nx1py0pz().getDensity()); + const float pVoxel1nx1py1pz = static_cast(volIter.peekVoxel1nx1py1pz().getDensity()); - const uint8_t pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz().getDensity(); - const uint8_t pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz().getDensity(); - const uint8_t pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz().getDensity(); - const uint8_t pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz().getDensity(); - //const uint8_t pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz().getDensity(); - const uint8_t pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz().getDensity(); - const uint8_t pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz().getDensity(); - const uint8_t pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz().getDensity(); - const uint8_t pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz().getDensity(); + const float pVoxel0px1ny1nz = static_cast(volIter.peekVoxel0px1ny1nz().getDensity()); + const float pVoxel0px1ny0pz = static_cast(volIter.peekVoxel0px1ny0pz().getDensity()); + const float pVoxel0px1ny1pz = static_cast(volIter.peekVoxel0px1ny1pz().getDensity()); + const float pVoxel0px0py1nz = static_cast(volIter.peekVoxel0px0py1nz().getDensity()); + //const float pVoxel0px0py0pz = static_cast(volIter.peekVoxel0px0py0pz().getDensity()); + const float pVoxel0px0py1pz = static_cast(volIter.peekVoxel0px0py1pz().getDensity()); + const float pVoxel0px1py1nz = static_cast(volIter.peekVoxel0px1py1nz().getDensity()); + const float pVoxel0px1py0pz = static_cast(volIter.peekVoxel0px1py0pz().getDensity()); + const float pVoxel0px1py1pz = static_cast(volIter.peekVoxel0px1py1pz().getDensity()); - const uint8_t pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz().getDensity(); - const uint8_t pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz().getDensity(); - const uint8_t pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz().getDensity(); - const uint8_t pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz().getDensity(); - const uint8_t pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz().getDensity(); - const uint8_t pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz().getDensity(); - const uint8_t pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz().getDensity(); - const uint8_t pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz().getDensity(); - const uint8_t pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz().getDensity(); + const float pVoxel1px1ny1nz = static_cast(volIter.peekVoxel1px1ny1nz().getDensity()); + const float pVoxel1px1ny0pz = static_cast(volIter.peekVoxel1px1ny0pz().getDensity()); + const float pVoxel1px1ny1pz = static_cast(volIter.peekVoxel1px1ny1pz().getDensity()); + const float pVoxel1px0py1nz = static_cast(volIter.peekVoxel1px0py1nz().getDensity()); + const float pVoxel1px0py0pz = static_cast(volIter.peekVoxel1px0py0pz().getDensity()); + const float pVoxel1px0py1pz = static_cast(volIter.peekVoxel1px0py1pz().getDensity()); + const float pVoxel1px1py1nz = static_cast(volIter.peekVoxel1px1py1nz().getDensity()); + const float pVoxel1px1py0pz = static_cast(volIter.peekVoxel1px1py0pz().getDensity()); + const float pVoxel1px1py1pz = static_cast(volIter.peekVoxel1px1py1pz().getDensity()); - const int xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz - + const float xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz - weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz - weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] * @@ -127,7 +133,7 @@ namespace PolyVox weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] * pVoxel1px1py1pz); - const int yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz - + const float yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz - weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] * pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz + weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] * @@ -141,7 +147,7 @@ namespace PolyVox weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] * pVoxel1px1py1pz); - const int zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz + + const float zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz + weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] * @@ -157,7 +163,7 @@ namespace PolyVox //Note: The above actually give gradients going from low density to high density. //For our normals we want the the other way around, so we switch the components as we return them. - return Vector3DFloat(static_cast(-xGrad),static_cast(-yGrad),static_cast(-zGrad)); + return Vector3DFloat(-xGrad,-yGrad,-zGrad); } //////////////////////////////////////////////////////////////////////////////// // End of compiler bug workaroumd. From 6f31898fd7c80a413a0deb2b02a58542f82d61c8 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 14 Oct 2011 23:57:10 +0100 Subject: [PATCH 2/5] Renamed Volume base class to BaseVolume. Added initial version of simple interface. --- examples/Basic/main.cpp | 20 ++--- library/PolyVoxCore/CMakeLists.txt | 8 +- .../PolyVoxCore/{Volume.h => BaseVolume.h} | 16 ++-- .../{Volume.inl => BaseVolume.inl} | 32 +++---- ...olumeSampler.inl => BaseVolumeSampler.inl} | 84 +++++++++---------- .../include/PolyVoxCore/LargeVolume.h | 8 +- .../include/PolyVoxCore/LargeVolume.inl | 4 +- .../PolyVoxCore/LargeVolumeSampler.inl | 2 +- .../include/PolyVoxCore/MaterialDensityPair.h | 1 + .../include/PolyVoxCore/RawVolume.h | 8 +- .../include/PolyVoxCore/RawVolume.inl | 2 +- .../include/PolyVoxCore/RawVolumeSampler.inl | 2 +- .../include/PolyVoxCore/SimpleInterface.h | 52 ++++++++++++ .../include/PolyVoxCore/SimpleVolume.h | 8 +- .../include/PolyVoxCore/SimpleVolume.inl | 2 +- .../PolyVoxCore/SimpleVolumeSampler.inl | 2 +- .../PolyVoxCore/source/SimpleInterface.cpp | 33 ++++++++ tests/TestVolumeSubclass.cpp | 22 +++-- 18 files changed, 201 insertions(+), 105 deletions(-) rename library/PolyVoxCore/include/PolyVoxCore/{Volume.h => BaseVolume.h} (93%) rename library/PolyVoxCore/include/PolyVoxCore/{Volume.inl => BaseVolume.inl} (85%) rename library/PolyVoxCore/include/PolyVoxCore/{VolumeSampler.inl => BaseVolumeSampler.inl} (64%) create mode 100644 library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h create mode 100644 library/PolyVoxCore/source/SimpleInterface.cpp diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 5674948c..04f9c3b6 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -23,17 +23,14 @@ freely, subject to the following restrictions: #include "OpenGLWidget.h" -#include "PolyVoxCore/MaterialDensityPair.h" -#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" -#include "PolyVoxCore/SurfaceMesh.h" -#include "PolyVoxCore/SimpleVolume.h" +#include "PolyVoxCore/SimpleInterface.h" #include //Use the PolyVox namespace using namespace PolyVox; -void createSphereInVolume(SimpleVolume& volData, float fRadius) +void createSphereInVolume(BasicVolume& 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); @@ -54,10 +51,10 @@ void createSphereInVolume(SimpleVolume& volData, float fR if(fDistToCenter <= fRadius) { //Our new density value - uint8_t uDensity = MaterialDensityPair44::getMaxDensity(); + uint8_t uDensity = MaterialDensityPair88::getMaxDensity(); //Get the old voxel - MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z); + MaterialDensityPair88 voxel = volData.getVoxelAt(x,y,z); //Modify the density voxel.setDensity(uDensity); @@ -78,13 +75,14 @@ int main(int argc, char *argv[]) openGLWidget.show(); //Create an empty volume and then place a sphere in it - SimpleVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); + BasicVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); createSphereInVolume(volData, 30); //Extract the surface - SurfaceMesh mesh; - CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); - surfaceExtractor.execute(); + BasicMesh mesh; + //CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); + //surfaceExtractor.execute(); + extractCubicMesh(volData, volData.getEnclosingRegion(), mesh); //Pass the surface to the OpenGL window openGLWidget.setSurfaceMeshToRender(mesh); diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index b5d63110..8a4574f8 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -10,6 +10,7 @@ SET(CORE_SRC_FILES source/Log.cpp source/MeshDecimator.cpp source/Region.cpp + source/SimpleInterface.cpp source/VertexTypes.cpp source/VoxelFilters.cpp ) @@ -23,6 +24,9 @@ SET(CORE_INC_FILES include/PolyVoxCore/ArraySizes.h include/PolyVoxCore/AStarPathfinder.h include/PolyVoxCore/AStarPathfinder.inl + include/PolyVoxCore/BaseVolume.h + include/PolyVoxCore/BaseVolume.inl + include/PolyVoxCore/BaseVolumeSampler.inl include/PolyVoxCore/ConstVolumeProxy.h include/PolyVoxCore/CubicSurfaceExtractor.h include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -52,6 +56,7 @@ SET(CORE_INC_FILES include/PolyVoxCore/RaycastWithCallback.h include/PolyVoxCore/RaycastWithCallback.inl include/PolyVoxCore/Region.h + include/PolyVoxCore/SimpleInterface.h include/PolyVoxCore/SimpleVolume.h include/PolyVoxCore/SimpleVolume.inl include/PolyVoxCore/SimpleVolumeBlock.inl @@ -63,9 +68,6 @@ SET(CORE_INC_FILES include/PolyVoxCore/Vector.h include/PolyVoxCore/Vector.inl include/PolyVoxCore/VertexTypes.h - include/PolyVoxCore/Volume.h - include/PolyVoxCore/Volume.inl - include/PolyVoxCore/VolumeSampler.inl include/PolyVoxCore/VolumeResampler.h include/PolyVoxCore/VolumeResampler.inl include/PolyVoxCore/VoxelFilters.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h similarity index 93% rename from library/PolyVoxCore/include/PolyVoxCore/Volume.h rename to library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 3a3368b5..ad606409 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -21,8 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#ifndef __PolyVox_Volume_H__ -#define __PolyVox_Volume_H__ +#ifndef __PolyVox_BaseVolume_H__ +#define __PolyVox_BaseVolume_H__ #include "PolyVoxCore/Log.h" #include "PolyVoxCore/Region.h" @@ -34,7 +34,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - class Volume + class BaseVolume { public: #ifndef SWIG @@ -104,12 +104,12 @@ namespace PolyVox public: /// Constructor for creating a fixed size volume. - Volume + BaseVolume ( const Region& regValid ); /// Destructor - ~Volume(); + ~BaseVolume(); /// Gets the value used for voxels which are outside the volume VoxelType getBorderValue(void) const; @@ -153,7 +153,7 @@ namespace PolyVox }; } -#include "PolyVoxCore/Volume.inl" -#include "PolyVoxCore/VolumeSampler.inl" +#include "PolyVoxCore/BaseVolume.inl" +#include "PolyVoxCore/BaseVolumeSampler.inl" -#endif //__PolyVox_Volume_H__ +#endif //__PolyVox_BaseVolume_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl similarity index 85% rename from library/PolyVoxCore/include/PolyVoxCore/Volume.inl rename to library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index 0db51e3a..c211edb9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -24,7 +24,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - Volume::Volume + BaseVolume::BaseVolume ( const Region& regValid ) @@ -36,7 +36,7 @@ namespace PolyVox /// Destroys the volume //////////////////////////////////////////////////////////////////////////////// template - Volume::~Volume() + BaseVolume::~BaseVolume() { } @@ -46,7 +46,7 @@ namespace PolyVox /// \return The value used for voxels outside of the volume //////////////////////////////////////////////////////////////////////////////// template - VoxelType Volume::getBorderValue(void) const + VoxelType BaseVolume::getBorderValue(void) const { assert(false); return VoxelType(); @@ -56,7 +56,7 @@ namespace PolyVox /// \return A Region representing the extent of the volume. //////////////////////////////////////////////////////////////////////////////// template - Region Volume::getEnclosingRegion(void) const + Region BaseVolume::getEnclosingRegion(void) const { return m_regValidRegion; } @@ -66,7 +66,7 @@ namespace PolyVox /// \sa getHeight(), getDepth() //////////////////////////////////////////////////////////////////////////////// template - int32_t Volume::getWidth(void) const + int32_t BaseVolume::getWidth(void) const { return m_regValidRegion.getUpperCorner().getX() - m_regValidRegion.getLowerCorner().getX() + 1; } @@ -76,7 +76,7 @@ namespace PolyVox /// \sa getWidth(), getDepth() //////////////////////////////////////////////////////////////////////////////// template - int32_t Volume::getHeight(void) const + int32_t BaseVolume::getHeight(void) const { return m_regValidRegion.getUpperCorner().getY() - m_regValidRegion.getLowerCorner().getY() + 1; } @@ -86,7 +86,7 @@ namespace PolyVox /// \sa getWidth(), getHeight() //////////////////////////////////////////////////////////////////////////////// template - int32_t Volume::getDepth(void) const + int32_t BaseVolume::getDepth(void) const { return m_regValidRegion.getUpperCorner().getZ() - m_regValidRegion.getLowerCorner().getZ() + 1; } @@ -97,7 +97,7 @@ namespace PolyVox /// \sa getLongestSideLength(), getDiagonalLength() //////////////////////////////////////////////////////////////////////////////// template - int32_t Volume::getShortestSideLength(void) const + int32_t BaseVolume::getShortestSideLength(void) const { return m_uShortestSideLength; } @@ -108,7 +108,7 @@ namespace PolyVox /// \sa getShortestSideLength(), getDiagonalLength() //////////////////////////////////////////////////////////////////////////////// template - int32_t Volume::getLongestSideLength(void) const + int32_t BaseVolume::getLongestSideLength(void) const { return m_uLongestSideLength; } @@ -120,7 +120,7 @@ namespace PolyVox /// \sa getShortestSideLength(), getLongestSideLength() //////////////////////////////////////////////////////////////////////////////// template - float Volume::getDiagonalLength(void) const + float BaseVolume::getDiagonalLength(void) const { return m_fDiagonalLength; } @@ -132,7 +132,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType Volume::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + VoxelType BaseVolume::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const { assert(false); return VoxelType(); @@ -143,7 +143,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType Volume::getVoxelAt(const Vector3DInt32& v3dPos) const + VoxelType BaseVolume::getVoxelAt(const Vector3DInt32& v3dPos) const { assert(false); return VoxelType(); @@ -153,7 +153,7 @@ namespace PolyVox /// \param tBorder The value to use for voxels outside the volume. //////////////////////////////////////////////////////////////////////////////// template - void Volume::setBorderValue(const VoxelType& tBorder) + void BaseVolume::setBorderValue(const VoxelType& tBorder) { assert(false); } @@ -166,7 +166,7 @@ namespace PolyVox /// \return whether the requested position is inside the volume //////////////////////////////////////////////////////////////////////////////// template - bool Volume::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) + bool BaseVolume::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) { assert(false); return false; @@ -178,7 +178,7 @@ namespace PolyVox /// \return whether the requested position is inside the volume //////////////////////////////////////////////////////////////////////////////// template - bool Volume::setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) + bool BaseVolume::setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) { assert(false); return false; @@ -188,7 +188,7 @@ namespace PolyVox /// Note: This function needs reviewing for accuracy... //////////////////////////////////////////////////////////////////////////////// template - uint32_t Volume::calculateSizeInBytes(void) + uint32_t BaseVolume::calculateSizeInBytes(void) { return getWidth() * getHeight() * getDepth() * sizeof(VoxelType); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl similarity index 64% rename from library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl rename to library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index 57fdeb09..01fcca4a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -25,7 +25,7 @@ namespace PolyVox { template template - Volume::Sampler::Sampler(DerivedVolumeType* volume) + BaseVolume::Sampler::Sampler(DerivedVolumeType* volume) :mVolume(volume) ,mXPosInVolume(0) ,mYPosInVolume(0) @@ -35,41 +35,41 @@ namespace PolyVox template template - Volume::Sampler::~Sampler() + BaseVolume::Sampler::~Sampler() { } template template - int32_t Volume::Sampler::getPosX(void) const + int32_t BaseVolume::Sampler::getPosX(void) const { return mXPosInVolume; } template template - int32_t Volume::Sampler::getPosY(void) const + int32_t BaseVolume::Sampler::getPosY(void) const { return mYPosInVolume; } template template - int32_t Volume::Sampler::getPosZ(void) const + int32_t BaseVolume::Sampler::getPosZ(void) const { return mZPosInVolume; } template template - VoxelType Volume::Sampler::getVoxel(void) const + VoxelType BaseVolume::Sampler::getVoxel(void) const { return mVolume->getVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume); } template template - void Volume::Sampler::setPosition(const Vector3DInt32& v3dNewPos) + void BaseVolume::Sampler::setPosition(const Vector3DInt32& v3dNewPos) { mXPosInVolume = v3dNewPos.getX(); mYPosInVolume = v3dNewPos.getY(); @@ -78,7 +78,7 @@ namespace PolyVox template template - void Volume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) + void BaseVolume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) { mXPosInVolume = xPos; mYPosInVolume = yPos; @@ -87,112 +87,112 @@ namespace PolyVox template template - bool Volume::Sampler::setVoxel(VoxelType tValue) + bool BaseVolume::Sampler::setVoxel(VoxelType tValue) { return mVolume->setVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume, tValue); } template template - void Volume::Sampler::movePositiveX(void) + void BaseVolume::Sampler::movePositiveX(void) { mXPosInVolume++; } template template - void Volume::Sampler::movePositiveY(void) + void BaseVolume::Sampler::movePositiveY(void) { mYPosInVolume++; } template template - void Volume::Sampler::movePositiveZ(void) + void BaseVolume::Sampler::movePositiveZ(void) { mZPosInVolume++; } template template - void Volume::Sampler::moveNegativeX(void) + void BaseVolume::Sampler::moveNegativeX(void) { mXPosInVolume--; } template template - void Volume::Sampler::moveNegativeY(void) + void BaseVolume::Sampler::moveNegativeY(void) { mYPosInVolume--; } template template - void Volume::Sampler::moveNegativeZ(void) + void BaseVolume::Sampler::moveNegativeZ(void) { mZPosInVolume--; } template template - VoxelType Volume::Sampler::peekVoxel1nx1ny1nz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1nx1ny1nz(void) const { return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1); } template template - VoxelType Volume::Sampler::peekVoxel1nx1ny0pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1nx1ny0pz(void) const { return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume ); } template template - VoxelType Volume::Sampler::peekVoxel1nx1ny1pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1nx1ny1pz(void) const { return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1); } template template - VoxelType Volume::Sampler::peekVoxel1nx0py1nz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1nx0py1nz(void) const { return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1); } template template - VoxelType Volume::Sampler::peekVoxel1nx0py0pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1nx0py0pz(void) const { return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume ); } template template - VoxelType Volume::Sampler::peekVoxel1nx0py1pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1nx0py1pz(void) const { return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1); } template template - VoxelType Volume::Sampler::peekVoxel1nx1py1nz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1nx1py1nz(void) const { return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1); } template template - VoxelType Volume::Sampler::peekVoxel1nx1py0pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1nx1py0pz(void) const { return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume ); } template template - VoxelType Volume::Sampler::peekVoxel1nx1py1pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1nx1py1pz(void) const { return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1); } @@ -201,63 +201,63 @@ namespace PolyVox template template - VoxelType Volume::Sampler::peekVoxel0px1ny1nz(void) const + VoxelType BaseVolume::Sampler::peekVoxel0px1ny1nz(void) const { return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1); } template template - VoxelType Volume::Sampler::peekVoxel0px1ny0pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel0px1ny0pz(void) const { return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume ); } template template - VoxelType Volume::Sampler::peekVoxel0px1ny1pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel0px1ny1pz(void) const { return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1); } template template - VoxelType Volume::Sampler::peekVoxel0px0py1nz(void) const + VoxelType BaseVolume::Sampler::peekVoxel0px0py1nz(void) const { return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1); } template template - VoxelType Volume::Sampler::peekVoxel0px0py0pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel0px0py0pz(void) const { return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume ); } template template - VoxelType Volume::Sampler::peekVoxel0px0py1pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel0px0py1pz(void) const { return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1); } template template - VoxelType Volume::Sampler::peekVoxel0px1py1nz(void) const + VoxelType BaseVolume::Sampler::peekVoxel0px1py1nz(void) const { return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1); } template template - VoxelType Volume::Sampler::peekVoxel0px1py0pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel0px1py0pz(void) const { return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume ); } template template - VoxelType Volume::Sampler::peekVoxel0px1py1pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel0px1py1pz(void) const { return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1); } @@ -266,63 +266,63 @@ namespace PolyVox template template - VoxelType Volume::Sampler::peekVoxel1px1ny1nz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1px1ny1nz(void) const { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1); } template template - VoxelType Volume::Sampler::peekVoxel1px1ny0pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1px1ny0pz(void) const { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume ); } template template - VoxelType Volume::Sampler::peekVoxel1px1ny1pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1px1ny1pz(void) const { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1); } template template - VoxelType Volume::Sampler::peekVoxel1px0py1nz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1px0py1nz(void) const { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1); } template template - VoxelType Volume::Sampler::peekVoxel1px0py0pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1px0py0pz(void) const { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume ); } template template - VoxelType Volume::Sampler::peekVoxel1px0py1pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1px0py1pz(void) const { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1); } template template - VoxelType Volume::Sampler::peekVoxel1px1py1nz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1px1py1nz(void) const { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1); } template template - VoxelType Volume::Sampler::peekVoxel1px1py0pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1px1py0pz(void) const { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume ); } template template - VoxelType Volume::Sampler::peekVoxel1px1py1pz(void) const + VoxelType BaseVolume::Sampler::peekVoxel1px1py1pz(void) const { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index ba6e5523..9399f669 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -24,11 +24,11 @@ freely, subject to the following restrictions: #ifndef __PolyVox_LargeVolume_H__ #define __PolyVox_LargeVolume_H__ +#include "PolyVoxCore/BaseVolume.h" #include "PolyVoxImpl/Block.h" #include "PolyVoxCore/Log.h" #include "PolyVoxCore/Region.h" #include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Volume.h" #include #include @@ -150,7 +150,7 @@ namespace PolyVox template class ConstVolumeProxy; template - class LargeVolume : public Volume + class LargeVolume : public BaseVolume { public: //There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared. @@ -161,9 +161,9 @@ namespace PolyVox //typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. //class Sampler : public VolumeOfVoxelType::template Sampler< LargeVolume > #if defined(_MSC_VER) - class Sampler : public Volume::Sampler< LargeVolume > //This line works on VS2010 + class Sampler : public BaseVolume::Sampler< LargeVolume > //This line works on VS2010 #else - class Sampler : public Volume::template Sampler< LargeVolume > //This line works on GCC + class Sampler : public BaseVolume::template Sampler< LargeVolume > //This line works on GCC #endif { public: diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 721488e0..d5ae0004 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -39,7 +39,7 @@ namespace PolyVox polyvox_function&, const Region&)> dataOverflowHandler, uint16_t uBlockSideLength ) - :Volume(Region::MaxRegion) + :BaseVolume(Region::MaxRegion) { m_funcDataRequiredHandler = dataRequiredHandler; m_funcDataOverflowHandler = dataOverflowHandler; @@ -86,7 +86,7 @@ namespace PolyVox bool bPagingEnabled, uint16_t uBlockSideLength ) - :Volume(regValid) + :BaseVolume(regValid) { m_funcDataRequiredHandler = dataRequiredHandler; m_funcDataOverflowHandler = dataOverflowHandler; diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 86f9dcac..be063dc7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -30,7 +30,7 @@ namespace PolyVox { template LargeVolume::Sampler::Sampler(LargeVolume* volume) - :Volume::template Sampler< LargeVolume >(volume) + :BaseVolume::template Sampler< LargeVolume >(volume) { } diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 03bff183..1bb3a31f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -75,6 +75,7 @@ namespace PolyVox }; typedef MaterialDensityPair MaterialDensityPair44; + typedef MaterialDensityPair MaterialDensityPair88; } #endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index f5106e7d..3bef1a8a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -24,10 +24,10 @@ freely, subject to the following restrictions: #ifndef __PolyVox_RawVolume_H__ #define __PolyVox_RawVolume_H__ +#include "PolyVoxCore/BaseVolume.h" #include "PolyVoxCore/Log.h" #include "PolyVoxCore/Region.h" #include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Volume.h" #include #include //For abort() @@ -38,7 +38,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - class RawVolume : public Volume + class RawVolume : public BaseVolume { public: #ifndef SWIG @@ -50,9 +50,9 @@ namespace PolyVox //typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. //class Sampler : public VolumeOfVoxelType::template Sampler< RawVolume > #if defined(_MSC_VER) - class Sampler : public Volume::Sampler< RawVolume > //This line works on VS2010 + class Sampler : public BaseVolume::Sampler< RawVolume > //This line works on VS2010 #else - class Sampler : public Volume::template Sampler< RawVolume > //This line works on GCC + class Sampler : public BaseVolume::template Sampler< RawVolume > //This line works on GCC #endif { public: diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 93e41ca1..25265eff 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -36,7 +36,7 @@ namespace PolyVox ( const Region& regValid ) - :Volume(regValid) + :BaseVolume(regValid) { setBorderValue(VoxelType()); diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 6bc9891f..aede84fc 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -32,7 +32,7 @@ namespace PolyVox { template RawVolume::Sampler::Sampler(RawVolume* volume) - :Volume::template Sampler< RawVolume >(volume) + :BaseVolume::template Sampler< RawVolume >(volume) ,mCurrentVoxel(0) ,m_bIsCurrentPositionValidInX(false) ,m_bIsCurrentPositionValidInY(false) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h new file mode 100644 index 00000000..eb8123b2 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h @@ -0,0 +1,52 @@ +/******************************************************************************* +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. +*******************************************************************************/ + +#ifndef __PolyVox_SimpleInterface_H__ +#define __PolyVox_SimpleInterface_H__ + +//Available voxel types +#include "PolyVoxCore\Density.h" +#include "PolyVoxCore\Material.h" +#include "PolyVoxCore\MaterialDensityPair.h" + +//Available volumes +#include "PolyVoxCore\LargeVolume.h" +#include "PolyVoxCore\RawVolume.h" +#include "PolyVoxCore\SimpleVolume.h" + +//Available extractors +#include "PolyVoxCore\CubicSurfaceExtractorWithNormals.h" +#include "PolyVoxCore\SurfaceExtractor.h" + +namespace PolyVox +{ + //The PolyVox simple interface only exposes one voxel type and one volume type. But if you like you can + //adjust these typedefs and rebuild the library in order to modify which one volume and voxel is exposed. + typedef SimpleVolume BasicVolume; + typedef SurfaceMesh BasicMesh; + + void extractCubicMesh(BasicVolume& volume, const Region& region, BasicMesh& resultMesh); + +} + +#endif //__PolyVox_SimpleInterface_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 0a45eb0b..447f0f18 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -26,10 +26,10 @@ freely, subject to the following restrictions: #include "PolyVoxImpl/Utility.h" +#include "PolyVoxCore/BaseVolume.h" #include "PolyVoxCore/Log.h" #include "PolyVoxCore/Region.h" #include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Volume.h" #include #include //For abort() @@ -41,7 +41,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - class SimpleVolume : public Volume + class SimpleVolume : public BaseVolume { public: #ifndef SWIG @@ -76,9 +76,9 @@ namespace PolyVox //typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. //class Sampler : public VolumeOfVoxelType::template Sampler< SimpleVolume > #if defined(_MSC_VER) - class Sampler : public Volume::Sampler< SimpleVolume > //This line works on VS2010 + class Sampler : public BaseVolume::Sampler< SimpleVolume > //This line works on VS2010 #else - class Sampler : public Volume::template Sampler< SimpleVolume > //This line works on GCC + class Sampler : public BaseVolume::template Sampler< SimpleVolume > //This line works on GCC #endif { public: diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 21f960a9..f91a17ab 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -58,7 +58,7 @@ namespace PolyVox const Region& regValid, uint16_t uBlockSideLength ) - :Volume(regValid) + :BaseVolume(regValid) { //Create a volume of the right size. resize(regValid,uBlockSideLength); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index 6b1bf725..091a18a8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -30,7 +30,7 @@ namespace PolyVox { template SimpleVolume::Sampler::Sampler(SimpleVolume* volume) - :Volume::template Sampler< SimpleVolume >(volume) + :BaseVolume::template Sampler< SimpleVolume >(volume) { } diff --git a/library/PolyVoxCore/source/SimpleInterface.cpp b/library/PolyVoxCore/source/SimpleInterface.cpp new file mode 100644 index 00000000..2a863928 --- /dev/null +++ b/library/PolyVoxCore/source/SimpleInterface.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* +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 "PolyVoxCore\SimpleInterface.h" + +namespace PolyVox +{ + void extractCubicMesh(BasicVolume& volume, const Region& region, BasicMesh& resultMesh) + { + CubicSurfaceExtractorWithNormals surfaceExtractor(&volume, region, &resultMesh); + surfaceExtractor.execute(); + } +} diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp index 4ed1e4aa..ef61cbf4 100644 --- a/tests/TestVolumeSubclass.cpp +++ b/tests/TestVolumeSubclass.cpp @@ -24,25 +24,35 @@ freely, subject to the following restrictions: #include "TestVolumeSubclass.h" #include "PolyVoxCore/Array.h" +#include "PolyVoxCore/BaseVolume.h" #include "PolyVoxCore/CubicSurfaceExtractor.h" #include "PolyVoxCore/Material.h" #include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Volume.h" #include using namespace PolyVox; template -class VolumeSubclass : public Volume +class VolumeSubclass : public BaseVolume { public: - typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. See http://goo.gl/qu1wn - class Sampler : public VolumeOfVoxelType::template Sampler< VolumeSubclass > + //There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared. + //There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but + //which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler + //option. For now it seems best to 'fix' it with the preprocessor insstead, but maybe the workaround can be reinstated + //in the future + //typedef BaseVolume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. See http://goo.gl/qu1wn + //class Sampler : public VolumeOfVoxelType::template Sampler< VolumeSubclass > + #if defined(_MSC_VER) + class Sampler : public BaseVolume::Sampler< VolumeSubclass > //This line works on VS2010 + #else + class Sampler : public BaseVolume::template Sampler< VolumeSubclass > //This line works on GCC + #endif { public: Sampler(VolumeSubclass* volume) - :Volume::template Sampler< VolumeSubclass >(volume) + :BaseVolume::template Sampler< VolumeSubclass >(volume) { this->mVolume = volume; } @@ -51,7 +61,7 @@ public: /// Constructor for creating a fixed size volume. VolumeSubclass(const Region& regValid) - :Volume(regValid) + :BaseVolume(regValid) { mVolumeData.resize(ArraySizes(this->getWidth())(this->getHeight())(this->getDepth())); } From db81e1bc3f751e4d142ce1cbb5d565b05c73510b Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 15 Oct 2011 00:01:17 +0100 Subject: [PATCH 3/5] Work on simple interface. --- examples/Basic/main.cpp | 6 +++--- .../include/PolyVoxCore/SimpleInterface.h | 20 ++++++------------- .../PolyVoxCore/source/SimpleInterface.cpp | 10 ++++++++-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 04f9c3b6..944a17e3 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -30,7 +30,7 @@ freely, subject to the following restrictions: //Use the PolyVox namespace using namespace PolyVox; -void createSphereInVolume(BasicVolume& volData, float fRadius) +void createSphereInVolume(Volume& 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); @@ -75,11 +75,11 @@ int main(int argc, char *argv[]) openGLWidget.show(); //Create an empty volume and then place a sphere in it - BasicVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); + Volume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); createSphereInVolume(volData, 30); //Extract the surface - BasicMesh mesh; + Mesh mesh; //CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); //surfaceExtractor.execute(); extractCubicMesh(volData, volData.getEnclosingRegion(), mesh); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h index eb8123b2..ff5ac761 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h @@ -24,28 +24,20 @@ freely, subject to the following restrictions: #ifndef __PolyVox_SimpleInterface_H__ #define __PolyVox_SimpleInterface_H__ -//Available voxel types -#include "PolyVoxCore\Density.h" -#include "PolyVoxCore\Material.h" -#include "PolyVoxCore\MaterialDensityPair.h" - -//Available volumes -#include "PolyVoxCore\LargeVolume.h" -#include "PolyVoxCore\RawVolume.h" -#include "PolyVoxCore\SimpleVolume.h" - -//Available extractors #include "PolyVoxCore\CubicSurfaceExtractorWithNormals.h" +#include "PolyVoxCore\MaterialDensityPair.h" +#include "PolyVoxCore\SimpleVolume.h" #include "PolyVoxCore\SurfaceExtractor.h" namespace PolyVox { //The PolyVox simple interface only exposes one voxel type and one volume type. But if you like you can //adjust these typedefs and rebuild the library in order to modify which one volume and voxel is exposed. - typedef SimpleVolume BasicVolume; - typedef SurfaceMesh BasicMesh; + typedef SimpleVolume Volume; + typedef SurfaceMesh Mesh; - void extractCubicMesh(BasicVolume& volume, const Region& region, BasicMesh& resultMesh); + void extractCubicMesh(Volume& volume, const Region& region, Mesh& resultMesh); + void extractSmoothMesh(Volume& volume, const Region& region, Mesh& resultMesh); } diff --git a/library/PolyVoxCore/source/SimpleInterface.cpp b/library/PolyVoxCore/source/SimpleInterface.cpp index 2a863928..710aa3e4 100644 --- a/library/PolyVoxCore/source/SimpleInterface.cpp +++ b/library/PolyVoxCore/source/SimpleInterface.cpp @@ -18,16 +18,22 @@ freely, subject to the following restrictions: misrepresented as being the original software. 3. This notice may not be removed or altered from any source - distribution. + distribution. *******************************************************************************/ #include "PolyVoxCore\SimpleInterface.h" namespace PolyVox { - void extractCubicMesh(BasicVolume& volume, const Region& region, BasicMesh& resultMesh) + void extractCubicMesh(Volume& volume, const Region& region, Mesh& resultMesh) { CubicSurfaceExtractorWithNormals surfaceExtractor(&volume, region, &resultMesh); surfaceExtractor.execute(); } + + void extractSmoothMesh(Volume& volume, const Region& region, Mesh& resultMesh) + { + SurfaceExtractor surfaceExtractor(&volume, region, &resultMesh); + surfaceExtractor.execute(); + } } From 46d63ddcd135646252953846b083944ae271835f Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 15 Oct 2011 11:06:01 +0100 Subject: [PATCH 4/5] Fixed slashes in include paths. --- library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h | 8 ++++---- library/PolyVoxCore/source/SimpleInterface.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h index ff5ac761..234b6808 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleInterface.h @@ -24,10 +24,10 @@ freely, subject to the following restrictions: #ifndef __PolyVox_SimpleInterface_H__ #define __PolyVox_SimpleInterface_H__ -#include "PolyVoxCore\CubicSurfaceExtractorWithNormals.h" -#include "PolyVoxCore\MaterialDensityPair.h" -#include "PolyVoxCore\SimpleVolume.h" -#include "PolyVoxCore\SurfaceExtractor.h" +#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" +#include "PolyVoxCore/MaterialDensityPair.h" +#include "PolyVoxCore/SimpleVolume.h" +#include "PolyVoxCore/SurfaceExtractor.h" namespace PolyVox { diff --git a/library/PolyVoxCore/source/SimpleInterface.cpp b/library/PolyVoxCore/source/SimpleInterface.cpp index 710aa3e4..f241747a 100644 --- a/library/PolyVoxCore/source/SimpleInterface.cpp +++ b/library/PolyVoxCore/source/SimpleInterface.cpp @@ -21,7 +21,7 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore\SimpleInterface.h" +#include "PolyVoxCore/SimpleInterface.h" namespace PolyVox { From 462295cf8b47ebded06bb00a001929b225db39f4 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 16 Oct 2011 23:03:04 +0100 Subject: [PATCH 5/5] Switched BasicExample back to 'advanced' API (not SimpleInterface). --- examples/Basic/main.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 944a17e3..5674948c 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -23,14 +23,17 @@ freely, subject to the following restrictions: #include "OpenGLWidget.h" -#include "PolyVoxCore/SimpleInterface.h" +#include "PolyVoxCore/MaterialDensityPair.h" +#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" +#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/SimpleVolume.h" #include //Use the PolyVox namespace using namespace PolyVox; -void createSphereInVolume(Volume& volData, float fRadius) +void createSphereInVolume(SimpleVolume& 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); @@ -51,10 +54,10 @@ void createSphereInVolume(Volume& volData, float fRadius) if(fDistToCenter <= fRadius) { //Our new density value - uint8_t uDensity = MaterialDensityPair88::getMaxDensity(); + uint8_t uDensity = MaterialDensityPair44::getMaxDensity(); //Get the old voxel - MaterialDensityPair88 voxel = volData.getVoxelAt(x,y,z); + MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z); //Modify the density voxel.setDensity(uDensity); @@ -75,14 +78,13 @@ int main(int argc, char *argv[]) openGLWidget.show(); //Create an empty volume and then place a sphere in it - Volume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); + SimpleVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); createSphereInVolume(volData, 30); //Extract the surface - Mesh mesh; - //CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); - //surfaceExtractor.execute(); - extractCubicMesh(volData, volData.getEnclosingRegion(), mesh); + SurfaceMesh mesh; + CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); + surfaceExtractor.execute(); //Pass the surface to the OpenGL window openGLWidget.setSurfaceMeshToRender(mesh);