From 2107128f7c74ccd15f2574afa052e6e227036cd7 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 27 Apr 2008 21:31:02 +0000 Subject: [PATCH] Only the region size constants remain. --- include/GradientEstimators.inl | 18 ------------------ include/PolyVoxSceneManager.h | 3 --- include/Volume.h | 3 ++- include/Volume.inl | 6 ++++++ source/PolyVoxSceneManager.cpp | 26 ++++++++++++++++++-------- 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/include/GradientEstimators.inl b/include/GradientEstimators.inl index c7d4421f..439be9db 100644 --- a/include/GradientEstimators.inl +++ b/include/GradientEstimators.inl @@ -3,15 +3,6 @@ namespace PolyVox template Vector3DFloat computeCentralDifferenceGradient(const VolumeIterator& volIter) { - //FIXME - should this test be here? - if((volIter.getPosX() < 1) || (volIter.getPosX() > POLYVOX_VOLUME_SIDE_LENGTH-2) || - (volIter.getPosY() < 1) || (volIter.getPosY() > POLYVOX_VOLUME_SIDE_LENGTH-2) || - (volIter.getPosZ() < 1) || (volIter.getPosZ() > POLYVOX_VOLUME_SIDE_LENGTH-2)) - { - //LogManager::getSingleton().logMessage("Out of range"); - return Vector3DFloat(0.0,0.0,0.0); - } - //FIXME - bitwise way of doing this? VoxelType voxel1nx = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0; VoxelType voxel1px = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0; @@ -33,15 +24,6 @@ namespace PolyVox template Vector3DFloat computeSobelGradient(const VolumeIterator& volIter) { - //FIXME - should this test be here? - if((volIter.getPosX() < 1) || (volIter.getPosX() > POLYVOX_VOLUME_SIDE_LENGTH-2) || - (volIter.getPosY() < 1) || (volIter.getPosY() > POLYVOX_VOLUME_SIDE_LENGTH-2) || - (volIter.getPosZ() < 1) || (volIter.getPosZ() > POLYVOX_VOLUME_SIDE_LENGTH-2)) - { - //LogManager::getSingleton().logMessage("Out of range"); - return Vector3DFloat(0.0,0.0,0.0); - } - 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} } }; diff --git a/include/PolyVoxSceneManager.h b/include/PolyVoxSceneManager.h index b1a77443..0a7d912d 100644 --- a/include/PolyVoxSceneManager.h +++ b/include/PolyVoxSceneManager.h @@ -71,9 +71,6 @@ namespace PolyVox bool surfaceUpToDate[POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS]; bool regionIsHomogenous[POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS]; - //SurfacePatchRenderable* m_singleMaterialSurfaces[POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS]; - //SurfacePatchRenderable* m_multiMaterialSurfaces[POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS]; - Vector3DFloat computeNormal(const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod) const; public: diff --git a/include/Volume.h b/include/Volume.h index e4f1ebf4..13061427 100644 --- a/include/Volume.h +++ b/include/Volume.h @@ -48,6 +48,7 @@ namespace PolyVox bool containsPoint(Vector3DInt32 pos, boost::uint16_t boundary); boost::uint16_t getSideLength(void); + boost::uint8_t getSideLengthPower(void); boost::uint16_t getSideLengthInBlocks(void); boost::uint16_t getBlockSideLength(void); @@ -61,7 +62,7 @@ namespace PolyVox boost::uint32_t m_uNoOfBlocksInVolume; boost::uint16_t m_uSideLengthInBlocks; - boost::uint16_t m_uSideLengthPower; + boost::uint8_t m_uSideLengthPower; boost::uint16_t m_uSideLength; boost::uint16_t m_uBlockSideLengthPower; diff --git a/include/Volume.inl b/include/Volume.inl index b42d3421..aa11538d 100644 --- a/include/Volume.inl +++ b/include/Volume.inl @@ -165,6 +165,12 @@ namespace PolyVox return m_uSideLength; } + template + boost::uint8_t Volume::getSideLengthPower(void) + { + return m_uSideLengthPower; + } + template boost::uint16_t Volume::getSideLengthInBlocks(void) { diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index 1266cbaa..8b779e87 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -117,9 +117,9 @@ namespace PolyVox firstY = std::max(firstY,0); firstZ = std::max(firstZ,0); - lastX = std::min(lastX,int(POLYVOX_VOLUME_SIDE_LENGTH-1)); - lastY = std::min(lastY,int(POLYVOX_VOLUME_SIDE_LENGTH-1)); - lastZ = std::min(lastZ,int(POLYVOX_VOLUME_SIDE_LENGTH-1)); + lastX = std::min(lastX,int(volumeData->getSideLength()-1)); + lastY = std::min(lastY,int(volumeData->getSideLength()-1)); + lastZ = std::min(lastZ,int(volumeData->getSideLength()-1)); VolumeIterator volIter(*volumeData); volIter.setValidRegion(firstX,firstY,firstZ,lastX,lastY,lastZ); @@ -242,9 +242,9 @@ namespace PolyVox const uint16_t firstX = regionX * POLYVOX_REGION_SIDE_LENGTH; const uint16_t firstY = regionY * POLYVOX_REGION_SIDE_LENGTH; const uint16_t firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH; - const uint16_t lastX = (std::min)(firstX + POLYVOX_REGION_SIDE_LENGTH-1,static_cast(POLYVOX_VOLUME_SIDE_LENGTH-2)); - const uint16_t lastY = (std::min)(firstY + POLYVOX_REGION_SIDE_LENGTH-1,static_cast(POLYVOX_VOLUME_SIDE_LENGTH-2)); - const uint16_t lastZ = (std::min)(firstZ + POLYVOX_REGION_SIDE_LENGTH-1,static_cast(POLYVOX_VOLUME_SIDE_LENGTH-2)); + const uint16_t lastX = (std::min)(firstX + POLYVOX_REGION_SIDE_LENGTH-1,static_cast(volumeData->getSideLength()-2)); + const uint16_t lastY = (std::min)(firstY + POLYVOX_REGION_SIDE_LENGTH-1,static_cast(volumeData->getSideLength()-2)); + const uint16_t lastZ = (std::min)(firstZ + POLYVOX_REGION_SIDE_LENGTH-1,static_cast(volumeData->getSideLength()-2)); //Offset from lower block corner const Vector3DFloat offset(firstX,firstY,firstZ); @@ -544,7 +544,7 @@ namespace PolyVox Vector3DFloat PolyVoxSceneManager::computeNormal(const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod) const { - VolumeIterator volIter(*volumeData); //FIXME - save this somewhere - could be expensive to create? + const float posX = position.x(); const float posY = position.y(); @@ -554,8 +554,18 @@ namespace PolyVox const uint16_t floorY = static_cast(posY); const uint16_t floorZ = static_cast(posZ); + //Check all corners are within the volume, allowing a boundary for gradient estimation + bool lowerCornerInside = volumeData->containsPoint(Vector3DInt32(floorX, floorY, floorZ),1); + bool upperCornerInside = volumeData->containsPoint(Vector3DInt32(floorX+1, floorY+1, floorZ+1),1); + if((!lowerCornerInside) || (!upperCornerInside)) + { + normalGenerationMethod = SIMPLE; + } + Vector3DFloat result; + VolumeIterator volIter(*volumeData); //FIXME - save this somewhere - could be expensive to create? + if(normalGenerationMethod == SOBEL) { @@ -691,7 +701,7 @@ namespace PolyVox uint16_t PolyVoxSceneManager::getSideLength(void) { - return POLYVOX_VOLUME_SIDE_LENGTH; + return volumeData->getSideLength(); } uint8_t PolyVoxSceneManager::getMaterialIndexAt(uint16_t uX, uint16_t uY, uint16_t uZ)