From 1217ea1fd84fd72f82e91cb5c9e41fa464a6c250 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jul 2012 17:24:55 +0200 Subject: [PATCH] Work on custom thresholds in SurfaceExtractionController. --- .../PolyVoxCore/include/PolyVoxCore/Density.h | 19 ++++++++++++++--- .../include/PolyVoxCore/MaterialDensityPair.h | 21 +++++++++++++++---- .../PolyVoxCore/SurfaceExtractionController.h | 15 ++++++++++++- .../include/PolyVoxCore/SurfaceExtractor.h | 2 +- .../include/PolyVoxCore/SurfaceExtractor.inl | 4 ++-- tests/TestSurfaceExtractor.cpp | 5 ++--- 6 files changed, 52 insertions(+), 14 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 90b66905..801bebfb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -109,6 +109,17 @@ namespace PolyVox typedef Type DensityType; typedef float MaterialType; + SurfaceExtractionController(void) + { + // Default to a threshold value halfway between the min and max possible values. + m_tThreshold = (Density::getMinDensity() + Density::getMaxDensity()) / 2; + } + + SurfaceExtractionController(DensityType tThreshold) + { + m_tThreshold = tThreshold; + } + DensityType convertToDensity(Density voxel) { return voxel.getDensity(); @@ -120,10 +131,12 @@ namespace PolyVox } DensityType getThreshold(void) - { - // Returns a threshold value halfway between the min and max possible values. - return (Density::getMinDensity() + Density::getMaxDensity()) / 2; + { + return m_tThreshold; } + + private: + DensityType m_tThreshold; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 2e8e892f..ca087161 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -121,6 +121,17 @@ namespace PolyVox typedef Type DensityType; typedef Type MaterialType; + SurfaceExtractionController(void) + { + // Default to a threshold value halfway between the min and max possible values. + m_tThreshold = (MaterialDensityPair::getMinDensity() + MaterialDensityPair::getMaxDensity()) / 2; + } + + SurfaceExtractionController(DensityType tThreshold) + { + m_tThreshold = tThreshold; + } + DensityType convertToDensity(MaterialDensityPair voxel) { return voxel.getDensity(); @@ -132,10 +143,12 @@ namespace PolyVox } DensityType getThreshold(void) - { - // Returns a threshold value halfway between the min and max possible values. - return (MaterialDensityPair::getMinDensity() + MaterialDensityPair::getMaxDensity()) / 2; - } + { + return m_tThreshold; + } + + private: + DensityType m_tThreshold; }; typedef MaterialDensityPair MaterialDensityPair44; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractionController.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractionController.h index a43ff1b0..9851dc9d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractionController.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractionController.h @@ -35,6 +35,16 @@ namespace PolyVox typedef VoxelType DensityType; typedef float MaterialType; + SurfaceExtractionController(void) + { + m_tThreshold = ((std::numeric_limits::min)() + (std::numeric_limits::max)()) / 2; + } + + SurfaceExtractionController(DensityType tThreshold) + { + m_tThreshold = tThreshold; + } + DensityType convertToDensity(VoxelType voxel) { return voxel; @@ -48,8 +58,11 @@ namespace PolyVox DensityType getThreshold(void) { // Returns a threshold value halfway between the min and max possible values. - return ((std::numeric_limits::min)() + (std::numeric_limits::max)()) / 2; + return m_tThreshold; } + + private: + DensityType m_tThreshold; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h index f7d94422..1d00ffd3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h @@ -37,7 +37,7 @@ namespace PolyVox class SurfaceExtractor { public: - SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result); + SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, Controller controller = Controller()); void execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl index 0125e8c2..4e3e08d0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl @@ -24,7 +24,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - SurfaceExtractor::SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result) + SurfaceExtractor::SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, Controller controller = Controller()) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) @@ -34,7 +34,7 @@ namespace PolyVox m_regSizeInCells = m_regSizeInVoxels; m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1)); - //FIXME - Check is m_controller is guarenteed to be valid at this point?! + m_controller = controller; m_tThreshold = m_controller.getThreshold(); } diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 77ef1abe..b061e569 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -32,7 +32,6 @@ freely, subject to the following restrictions: using namespace PolyVox; - // These 'writeDensityValueToVoxel' functions provide a unified interface for writting densities to primative and class voxel types. // They are conceptually the inverse of the 'convertToDensity' function used by the SurfaceExtractor. They probably shouldn't be part // of PolyVox, but they might be usful to other tests so we cold move them into a 'Tests.h' or something in the future. @@ -92,8 +91,8 @@ void testForType(SurfaceMesh& result) } } - // THIS TEST IS BROKEN BECAUSE CUSTOM THRESHOLDS ARE TEMOPRARILY NOT WORKING. - SurfaceExtractor< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result/*, 50*/); + SurfaceExtractionController controller(50); + SurfaceExtractor< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result, controller); extractor.execute(); }