From 22fd38b25562131eef40e289b0466f95777765c9 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 25 May 2008 21:06:58 +0000 Subject: [PATCH] Moved some stuff from VolumeChangeTracker to SurfaceExtractors. --- include/BlockVolume.h | 2 +- include/BlockVolume.inl | 2 +- include/SurfaceExtractors.h | 13 +++++--- include/VolumeChangeTracker.h | 7 ++--- source/SurfaceExtractors.cpp | 28 +++++++++++++++++ source/VolumeChangeTracker.cpp | 55 +++------------------------------- 6 files changed, 46 insertions(+), 61 deletions(-) diff --git a/include/BlockVolume.h b/include/BlockVolume.h index 212780dd..5f47e370 100644 --- a/include/BlockVolume.h +++ b/include/BlockVolume.h @@ -45,7 +45,7 @@ namespace PolyVox BlockVolume& operator=(const BlockVolume& rhs); - Region getEnclosingRegion(void); + Region getEnclosingRegion(void) const; boost::uint16_t getSideLength(void) const; VoxelType getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const; VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const; diff --git a/include/BlockVolume.inl b/include/BlockVolume.inl index b8f38c16..935bfec0 100644 --- a/include/BlockVolume.inl +++ b/include/BlockVolume.inl @@ -121,7 +121,7 @@ namespace PolyVox #pragma region Getters template - Region BlockVolume::getEnclosingRegion(void) + Region BlockVolume::getEnclosingRegion(void) const { return Region(Vector3DInt32(0,0,0), Vector3DInt32(m_uSideLength-1,m_uSideLength-1,m_uSideLength-1)); } diff --git a/include/SurfaceExtractors.h b/include/SurfaceExtractors.h index f8debade..03b349c7 100644 --- a/include/SurfaceExtractors.h +++ b/include/SurfaceExtractors.h @@ -24,17 +24,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #pragma region Headers #include "PolyVoxForwardDeclarations.h" +#include "TypeDef.h" #include "boost/cstdint.hpp" + +#include #pragma endregion namespace PolyVox { - void generateRoughMeshDataForRegion(BlockVolume* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch); - Vector3DFloat computeNormal(BlockVolume* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod); + POLYVOX_API std::list getChangedRegionGeometry(VolumeChangeTracker& volume); - void generateSmoothMeshDataForRegion(BlockVolume* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch); - Vector3DFloat computeSmoothNormal(BlockVolume* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod); + POLYVOX_API void generateRoughMeshDataForRegion(BlockVolume* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch); + POLYVOX_API Vector3DFloat computeNormal(BlockVolume* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod); + + POLYVOX_API void generateSmoothMeshDataForRegion(BlockVolume* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch); + POLYVOX_API Vector3DFloat computeSmoothNormal(BlockVolume* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod); } #endif diff --git a/include/VolumeChangeTracker.h b/include/VolumeChangeTracker.h index a1b40d16..f7adb206 100644 --- a/include/VolumeChangeTracker.h +++ b/include/VolumeChangeTracker.h @@ -42,11 +42,10 @@ namespace PolyVox ~VolumeChangeTracker(); //Getters - std::list getChangedRegionGeometry(void); - void getChangedRegions(std::list& listToFill); - Region getEnclosingRegion(void); + void getChangedRegions(std::list& listToFill) const; + Region getEnclosingRegion(void) const; boost::uint16_t getSideLength(void); - const BlockVolume* getVolumeData(void) const; + BlockVolume* getVolumeData(void) const; boost::uint8_t getVoxelAt(const Vector3DUint16& pos); boost::uint8_t getVoxelAt(boost::uint16_t uX, boost::uint16_t uY, boost::uint16_t uZ); diff --git a/source/SurfaceExtractors.cpp b/source/SurfaceExtractors.cpp index b01d553c..83e3ce24 100644 --- a/source/SurfaceExtractors.cpp +++ b/source/SurfaceExtractors.cpp @@ -5,12 +5,40 @@ #include "IndexedSurfacePatch.h" #include "MarchingCubesTables.h" #include "Region.h" +#include "RegionGeometry.h" +#include "VolumeChangeTracker.h" #include "VolumeIterator.h" using namespace boost; namespace PolyVox { + std::list getChangedRegionGeometry(VolumeChangeTracker& volume) + { + std::list listChangedRegions; + volume.getChangedRegions(listChangedRegions); + + std::list listChangedRegionGeometry; + for(std::list::const_iterator iterChangedRegions = listChangedRegions.begin(); iterChangedRegions != listChangedRegions.end(); ++iterChangedRegions) + { + //Generate the surface + RegionGeometry regionGeometry; + regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false); + regionGeometry.m_patchMultiMaterial = new IndexedSurfacePatch(true); + regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner(); + + generateRoughMeshDataForRegion(volume.getVolumeData(), *iterChangedRegions, regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial); + + regionGeometry.m_bContainsSingleMaterialPatch = regionGeometry.m_patchSingleMaterial->getVertices().size() > 0; + regionGeometry.m_bContainsMultiMaterialPatch = regionGeometry.m_patchMultiMaterial->getVertices().size() > 0; + regionGeometry.m_bIsEmpty = ((regionGeometry.m_patchSingleMaterial->getVertices().size() == 0) && (regionGeometry.m_patchMultiMaterial->getIndices().size() == 0)); + + listChangedRegionGeometry.push_back(regionGeometry); + } + + return listChangedRegionGeometry; + } + void generateRoughMeshDataForRegion(BlockVolume* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch) { //When generating the mesh for a region we actually look one voxel outside it in the diff --git a/source/VolumeChangeTracker.cpp b/source/VolumeChangeTracker.cpp index 2e410a6a..b05f8a94 100644 --- a/source/VolumeChangeTracker.cpp +++ b/source/VolumeChangeTracker.cpp @@ -56,33 +56,9 @@ namespace PolyVox volRegionUpToDate = new LinearVolume(PolyVox::logBase2(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS)); } - std::list VolumeChangeTracker::getChangedRegionGeometry(void) - { - std::list listChangedRegions; - getChangedRegions(listChangedRegions); + - std::list listChangedRegionGeometry; - for(std::list::const_iterator iterChangedRegions = listChangedRegions.begin(); iterChangedRegions != listChangedRegions.end(); ++iterChangedRegions) - { - //Generate the surface - RegionGeometry regionGeometry; - regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false); - regionGeometry.m_patchMultiMaterial = new IndexedSurfacePatch(true); - regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner(); - - generateRoughMeshDataForRegion(volumeData, *iterChangedRegions, regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial); - - regionGeometry.m_bContainsSingleMaterialPatch = regionGeometry.m_patchSingleMaterial->getVertices().size() > 0; - regionGeometry.m_bContainsMultiMaterialPatch = regionGeometry.m_patchMultiMaterial->getVertices().size() > 0; - regionGeometry.m_bIsEmpty = ((regionGeometry.m_patchSingleMaterial->getVertices().size() == 0) && (regionGeometry.m_patchMultiMaterial->getIndices().size() == 0)); - - listChangedRegionGeometry.push_back(regionGeometry); - } - - return listChangedRegionGeometry; - } - - void VolumeChangeTracker::getChangedRegions(std::list& listToFill) + void VolumeChangeTracker::getChangedRegions(std::list& listToFill) const { //Clear the list listToFill.clear(); @@ -127,35 +103,12 @@ namespace PolyVox } } - /*void VolumeChangeTracker::markRegionChanged(uint16_t firstX, uint16_t firstY, uint16_t firstZ, uint16_t lastX, uint16_t lastY, uint16_t lastZ) - { - const uint16_t firstRegionX = firstX >> POLYVOX_REGION_SIDE_LENGTH_POWER; - const uint16_t firstRegionY = firstY >> POLYVOX_REGION_SIDE_LENGTH_POWER; - const uint16_t firstRegionZ = firstZ >> POLYVOX_REGION_SIDE_LENGTH_POWER; - - const uint16_t lastRegionX = lastX >> POLYVOX_REGION_SIDE_LENGTH_POWER; - const uint16_t lastRegionY = lastY >> POLYVOX_REGION_SIDE_LENGTH_POWER; - const uint16_t lastRegionZ = lastZ >> POLYVOX_REGION_SIDE_LENGTH_POWER; - - for(uint16_t zCt = firstRegionZ; zCt <= lastRegionZ; zCt++) - { - for(uint16_t yCt = firstRegionY; yCt <= lastRegionY; yCt++) - { - for(uint16_t xCt = firstRegionX; xCt <= lastRegionX; xCt++) - { - //surfaceUpToDate[xCt][yCt][zCt] = false; - volRegionUpToDate->setVoxelAt(xCt,yCt,zCt,false); - } - } - } - }*/ - uint16_t VolumeChangeTracker::getSideLength(void) { return volumeData->getSideLength(); } - Region VolumeChangeTracker::getEnclosingRegion(void) + Region VolumeChangeTracker::getEnclosingRegion(void) const { return volumeData->getEnclosingRegion(); } @@ -176,7 +129,7 @@ namespace PolyVox return volIter.getVoxel(); } - const BlockVolume* VolumeChangeTracker::getVolumeData(void) const + BlockVolume* VolumeChangeTracker::getVolumeData(void) const { return volumeData; }