diff --git a/examples/OpenGL/Shapes.cpp b/examples/OpenGL/Shapes.cpp index 36fbd5f7..3e69d800 100644 --- a/examples/OpenGL/Shapes.cpp +++ b/examples/OpenGL/Shapes.cpp @@ -48,7 +48,7 @@ void createSphereInVolume(LargeVolume& volData, float fRa //then we make it solid, otherwise we make it empty space. if(fDistToCenter <= fRadius) { - volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? VoxelTypeTraits::maxDensity() : VoxelTypeTraits::minDensity())); + volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? MaterialDensityPair44::getMaxDensity() : MaterialDensityPair44::getMinDensity())); } } } @@ -57,8 +57,8 @@ void createSphereInVolume(LargeVolume& volData, float fRa void createCubeInVolume(LargeVolume& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue) { - int maxDen = VoxelTypeTraits::maxDensity(); - int minDen = VoxelTypeTraits::minDensity(); + int maxDen = MaterialDensityPair44::getMaxDensity(); + int minDen = MaterialDensityPair44::getMinDensity(); //This three-level for loop iterates over every voxel between the specified corners for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++) { diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 80f2ec42..f478f16f 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -97,9 +97,9 @@ int main(int argc, char *argv[]) createCubeInVolume(volData, Vector3DInt32(midPos+1, minPos, midPos+1), Vector3DInt32(maxPos, midPos-1, maxPos), 0); createCubeInVolume(volData, Vector3DInt32(minPos, midPos+1, midPos+1), Vector3DInt32(midPos-1, maxPos, maxPos), 0); - createCubeInVolume(volData, Vector3DInt32(1, midPos-10, midPos-10), Vector3DInt32(maxPos-1, midPos+10, midPos+10), VoxelTypeTraits::maxDensity()); - createCubeInVolume(volData, Vector3DInt32(midPos-10, 1, midPos-10), Vector3DInt32(midPos+10, maxPos-1, midPos+10), VoxelTypeTraits::maxDensity()); - createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), VoxelTypeTraits::maxDensity()); + createCubeInVolume(volData, Vector3DInt32(1, midPos-10, midPos-10), Vector3DInt32(maxPos-1, midPos+10, midPos+10), MaterialDensityPair44::getMaxDensity()); + createCubeInVolume(volData, Vector3DInt32(midPos-10, 1, midPos-10), Vector3DInt32(midPos+10, maxPos-1, midPos+10), MaterialDensityPair44::getMaxDensity()); + createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity()); //Smooth part of the volume RawVolume tempVolume(PolyVox::Region(0,0,0,128, 128, 128)); diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index bf32a5ce..29ffadbd 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -50,7 +50,7 @@ void createPerlinVolumeSlow(LargeVolume& volData) perlinVal += 1.0f; perlinVal *= 0.5f; - perlinVal *= VoxelTypeTraits::maxDensity(); + perlinVal *= MaterialDensityPair44::getMaxDensity(); MaterialDensityPair44 voxel; @@ -60,12 +60,12 @@ void createPerlinVolumeSlow(LargeVolume& volData) /*if(perlinVal < 0.0f) { voxel.setMaterial(245); - voxel.setDensity(VoxelTypeTraits::maxDensity()); + voxel.setDensity(MaterialDensityPair44::getMaxDensity()); } else { voxel.setMaterial(0); - voxel.setDensity(VoxelTypeTraits::minDensity()); + voxel.setDensity(MaterialDensityPair44::getMinDensity()); }*/ volData.setVoxelAt(x, y, z, voxel); @@ -105,12 +105,12 @@ void createPerlinVolumeSlow(LargeVolume& volData) if(perlinVal < 0.0f) { voxel.setMaterial(245); - voxel.setDensity(VoxelTypeTraits::maxDensity()); + voxel.setDensity(MaterialDensityPair44::getMaxDensity()); } else { voxel.setMaterial(0); - voxel.setDensity(VoxelTypeTraits::minDensity()); + voxel.setDensity(MaterialDensityPair44::getMinDensity()); } volData.setVoxelAt(x, y, z, voxel); @@ -143,12 +143,12 @@ void createPerlinTerrain(LargeVolume& volData) if(z < perlinVal) { voxel.setMaterial(245); - voxel.setDensity(VoxelTypeTraits::maxDensity()); + voxel.setDensity(MaterialDensityPair44::getMaxDensity()); } else { voxel.setMaterial(0); - voxel.setDensity(VoxelTypeTraits::minDensity()); + voxel.setDensity(MaterialDensityPair44::getMinDensity()); } volData.setVoxelAt(x, y, z, voxel); @@ -181,7 +181,7 @@ void createSphereInVolume(LargeVolume& volData, Vector3DF if(fDistToCenter <= fRadius) { //Our new density value - uint8_t uDensity = VoxelTypeTraits::maxDensity(); + uint8_t uDensity = MaterialDensityPair44::getMaxDensity(); //Get the old voxel MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z); @@ -219,17 +219,17 @@ void load(const ConstVolumeProxy& volume, const PolyVox:: if((x-xpos)*(x-xpos) + (z-zpos)*(z-zpos) < 200) { // tunnel voxel.setMaterial(0); - voxel.setDensity(VoxelTypeTraits::minDensity()); + voxel.setDensity(MaterialDensityPair44::getMinDensity()); } else { // solid voxel.setMaterial(245); - voxel.setDensity(VoxelTypeTraits::maxDensity()); + voxel.setDensity(MaterialDensityPair44::getMaxDensity()); } } else { voxel.setMaterial(0); - voxel.setDensity(VoxelTypeTraits::minDensity()); + voxel.setDensity(MaterialDensityPair44::getMinDensity()); } volume.setVoxelAt(x, y, z, voxel); diff --git a/examples/SmoothLOD/main.cpp b/examples/SmoothLOD/main.cpp index e788980c..6597ed17 100644 --- a/examples/SmoothLOD/main.cpp +++ b/examples/SmoothLOD/main.cpp @@ -56,7 +56,7 @@ void createSphereInVolume(SimpleVolume& volData, float fRadius) { //Our new density value //uint8_t uDensity = Density8::getmaxDensity()(); - uint8_t uDensity = VoxelTypeTraits::maxDensity(); + uint8_t uDensity = std::numeric_limits::max(); //Get the old voxel //uint8_t voxel = volData.getVoxelAt(x,y,z); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 5228f748..ccc97eac 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -89,14 +89,10 @@ namespace PolyVox } DensityType getDensity() const throw() { return m_uDensity; } - //MaterialType getMaterial() const throw() { return 1; } - void setDensity(DensityType uDensity) { m_uDensity = uDensity; } - //void setMaterial(MaterialType /*uMaterial*/) { assert(false); } //Cannot set material on voxel of type Density - //static DensityType getmaxDensity()() throw() { return (std::numeric_limits::max)(); } - //static DensityType getminDensity()() throw() { return (std::numeric_limits::min)(); } - static DensityType getThreshold() throw() { return (std::numeric_limits::max)() / 2; } + static DensityType getMaxDensity() throw() { return (std::numeric_limits::max)(); } + static DensityType getMinDensity() throw() { return (std::numeric_limits::min)(); } private: DensityType m_uDensity; @@ -132,15 +128,13 @@ namespace PolyVox { return 1; } + + DensityType getThreshold(void) + { + // Returns a threshold value halfway between the min and max possible values. + return (Density::getMinDensity() + Density::getMaxDensity()) / 2; + } }; } -#include "PolyVoxCore/SurfaceExtractor.h" //VERY UGLY THAT WE NEED THIS!!! TO BE CONSIDERED... - -namespace PolyVox -{ - template<> - VoxelTypeTraits::DensityType convertToDensity(Density8 voxel); -} - #endif //__PolyVox_Density_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 407cb540..10f8fe34 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -72,30 +72,9 @@ namespace PolyVox return !(*this == rhs); } - DensityType getDensity() const throw() - { - //We don't actually have a density, so make one up based on the material. - if(m_uMaterial == 0) - { - //return getminDensity()(); - return 0; - } - else - { - //return getmaxDensity()(); - return 2; - } - } - MaterialType getMaterial() const throw() { return m_uMaterial; } - - void setDensity(DensityType /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } - //static DensityType getmaxDensity()() throw() { return 2; } - //static DensityType getminDensity()() throw() { return 0; } - static DensityType getThreshold() throw() { return 1; } - static bool isQuadNeeded(Material from, Material to, float& materialToUse) { if((from.getMaterial() > 0) && (to.getMaterial() == 0)) diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 0ccba009..aea988bd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -93,9 +93,8 @@ namespace PolyVox void setDensity(DensityType uDensity) { m_uDensity = uDensity; } void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } - //static DensityType getmaxDensity()() throw() { return (0x01 << NoOfDensityBits) - 1; } - //static DensityType getminDensity()() throw() { return 0; } - static DensityType getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);} + static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; } + static DensityType getMinDensity() throw() { return 0; } static bool isQuadNeeded(MaterialDensityPair from, MaterialDensityPair to, float& materialToUse) { @@ -131,6 +130,12 @@ namespace PolyVox { return voxel.getMaterial(); } + + DensityType getThreshold(void) + { + // Returns a threshold value halfway between the min and max possible values. + return (MaterialDensityPair::getMinDensity() + MaterialDensityPair::getMaxDensity()) / 2; + } }; typedef MaterialDensityPair MaterialDensityPair44; @@ -157,33 +162,4 @@ namespace PolyVox }; } -#include "PolyVoxCore/SurfaceExtractor.h" - -namespace PolyVox -{ - template<> - VoxelTypeTraits::DensityType convertToDensity(MaterialDensityPair44 voxel); - - template<> - VoxelTypeTraits::DensityType convertToDensity(MaterialDensityPair88 voxel); - - template<> - class ConvertToMaterial - { - public: - typedef uint32_t MaterialType; - - MaterialType operator()(MaterialDensityPair44 voxel); - }; - - template<> - class ConvertToMaterial - { - public: - typedef uint32_t MaterialType; - - MaterialType operator()(MaterialDensityPair88 voxel); - }; -} - #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractionController.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractionController.h index de594546..a43ff1b0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractionController.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractionController.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_SurfaceExtractionController_H__ #define __PolyVox_SurfaceExtractionController_H__ +#include + namespace PolyVox { template @@ -42,6 +44,12 @@ namespace PolyVox { return 1; } + + 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; + } }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h index 3858943b..17055686 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h @@ -43,22 +43,11 @@ namespace PolyVox static uint8_t maxDensity() { return 255; } }; - template - class ConvertToMaterial - { - public: - typedef float MaterialType; - MaterialType operator()(VoxelType voxel) - { - return 1; - } - }; - template< typename VolumeType> class SurfaceExtractor { public: - SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, typename VoxelTypeTraits::DensityType tThreshold = (VoxelTypeTraits::minDensity() + VoxelTypeTraits::maxDensity()) / 2); + SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result); void execute(); @@ -86,14 +75,14 @@ namespace PolyVox //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(convertToDensity(volIter.peekVoxel1nx0py0pz())); - float voxel1px = static_cast(convertToDensity(volIter.peekVoxel1px0py0pz())); + float voxel1nx = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx0py0pz())); + float voxel1px = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px0py0pz())); - float voxel1ny = static_cast(convertToDensity(volIter.peekVoxel0px1ny0pz())); - float voxel1py = static_cast(convertToDensity(volIter.peekVoxel0px1py0pz())); + float voxel1ny = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px1ny0pz())); + float voxel1py = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px1py0pz())); - float voxel1nz = static_cast(convertToDensity(volIter.peekVoxel0px0py1nz())); - float voxel1pz = static_cast(convertToDensity(volIter.peekVoxel0px0py1pz())); + float voxel1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px0py1nz())); + float voxel1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px0py1pz())); return Vector3DFloat ( @@ -111,35 +100,35 @@ namespace PolyVox //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(convertToDnsity(volIter.peekVoxel1nx1ny1nz())); - const float pVoxel1nx1ny0pz = static_cast(convertToDnsity(volIter.peekVoxel1nx1ny0pz())); - const float pVoxel1nx1ny1pz = static_cast(convertToDnsity(volIter.peekVoxel1nx1ny1pz())); - const float pVoxel1nx0py1nz = static_cast(convertToDnsity(volIter.peekVoxel1nx0py1nz())); - const float pVoxel1nx0py0pz = static_cast(convertToDnsity(volIter.peekVoxel1nx0py0pz())); - const float pVoxel1nx0py1pz = static_cast(convertToDnsity(volIter.peekVoxel1nx0py1pz())); - const float pVoxel1nx1py1nz = static_cast(convertToDnsity(volIter.peekVoxel1nx1py1nz())); - const float pVoxel1nx1py0pz = static_cast(convertToDnsity(volIter.peekVoxel1nx1py0pz())); - const float pVoxel1nx1py1pz = static_cast(convertToDnsity(volIter.peekVoxel1nx1py1pz())); + const float pVoxel1nx1ny1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx1ny1nz())); + const float pVoxel1nx1ny0pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx1ny0pz())); + const float pVoxel1nx1ny1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx1ny1pz())); + const float pVoxel1nx0py1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx0py1nz())); + const float pVoxel1nx0py0pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx0py0pz())); + const float pVoxel1nx0py1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx0py1pz())); + const float pVoxel1nx1py1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx1py1nz())); + const float pVoxel1nx1py0pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx1py0pz())); + const float pVoxel1nx1py1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1nx1py1pz())); - const float pVoxel0px1ny1nz = static_cast(convertToDnsity(volIter.peekVoxel0px1ny1nz())); - const float pVoxel0px1ny0pz = static_cast(convertToDnsity(volIter.peekVoxel0px1ny0pz())); - const float pVoxel0px1ny1pz = static_cast(convertToDnsity(volIter.peekVoxel0px1ny1pz())); - const float pVoxel0px0py1nz = static_cast(convertToDnsity(volIter.peekVoxel0px0py1nz())); - //const float pVoxel0px0py0pz = static_cast(convertToDnsity(volIter.peekVoxel0px0py0pz())); - const float pVoxel0px0py1pz = static_cast(convertToDnsity(volIter.peekVoxel0px0py1pz())); - const float pVoxel0px1py1nz = static_cast(convertToDnsity(volIter.peekVoxel0px1py1nz())); - const float pVoxel0px1py0pz = static_cast(convertToDnsity(volIter.peekVoxel0px1py0pz())); - const float pVoxel0px1py1pz = static_cast(convertToDnsity(volIter.peekVoxel0px1py1pz())); + const float pVoxel0px1ny1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px1ny1nz())); + const float pVoxel0px1ny0pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px1ny0pz())); + const float pVoxel0px1ny1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px1ny1pz())); + const float pVoxel0px0py1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px0py1nz())); + //const float pVoxel0px0py0pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px0py0pz())); + const float pVoxel0px0py1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px0py1pz())); + const float pVoxel0px1py1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px1py1nz())); + const float pVoxel0px1py0pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px1py0pz())); + const float pVoxel0px1py1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel0px1py1pz())); - const float pVoxel1px1ny1nz = static_cast(convertToDnsity(volIter.peekVoxel1px1ny1nz())); - const float pVoxel1px1ny0pz = static_cast(convertToDnsity(volIter.peekVoxel1px1ny0pz())); - const float pVoxel1px1ny1pz = static_cast(convertToDnsity(volIter.peekVoxel1px1ny1pz())); - const float pVoxel1px0py1nz = static_cast(convertToDnsity(volIter.peekVoxel1px0py1nz())); - const float pVoxel1px0py0pz = static_cast(convertToDnsity(volIter.peekVoxel1px0py0pz())); - const float pVoxel1px0py1pz = static_cast(convertToDnsity(volIter.peekVoxel1px0py1pz())); - const float pVoxel1px1py1nz = static_cast(convertToDnsity(volIter.peekVoxel1px1py1nz())); - const float pVoxel1px1py0pz = static_cast(convertToDnsity(volIter.peekVoxel1px1py0pz())); - const float pVoxel1px1py1pz = static_cast(convertToDnsity(volIter.peekVoxel1px1py1pz())); + const float pVoxel1px1ny1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px1ny1nz())); + const float pVoxel1px1ny0pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px1ny0pz())); + const float pVoxel1px1ny1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px1ny1pz())); + const float pVoxel1px0py1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px0py1nz())); + const float pVoxel1px0py0pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px0py0pz())); + const float pVoxel1px0py1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px0py1pz())); + const float pVoxel1px1py1nz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px1py1nz())); + const float pVoxel1px1py0pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px1py0pz())); + const float pVoxel1px1py1pz = static_cast(m_controller.convertToDensity(volIter.peekVoxel1px1py1pz())); const float xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz - weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] * diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl index fabc50c8..727be65e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl @@ -24,16 +24,18 @@ freely, subject to the following restrictions: namespace PolyVox { template - SurfaceExtractor::SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, typename VoxelTypeTraits::DensityType tThreshold) + SurfaceExtractor::SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) ,m_regSizeInVoxels(region) - ,m_tThreshold(tThreshold) { //m_regSizeInVoxels.cropTo(m_volData->getEnclosingRegion()); 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_tThreshold = m_controller.getThreshold(); } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/Voxel.h b/library/PolyVoxCore/include/PolyVoxCore/Voxel.h index 82c228f9..1ed0a405 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Voxel.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Voxel.h @@ -56,12 +56,6 @@ namespace PolyVox static int32_t minDensity() { assert(false); return 0; } static int32_t maxDensity() { assert(false); return 0; } }; - - template - typename VoxelTypeTraits::DensityType convertToDensity(VoxelType voxel) - { - return voxel; - } } #endif //__PolyVox_Voxel_H__ diff --git a/library/PolyVoxCore/source/Density.cpp b/library/PolyVoxCore/source/Density.cpp index 0a3748c2..71fada1d 100644 --- a/library/PolyVoxCore/source/Density.cpp +++ b/library/PolyVoxCore/source/Density.cpp @@ -25,9 +25,4 @@ freely, subject to the following restrictions: namespace PolyVox { - template<> - VoxelTypeTraits::DensityType convertToDensity(Density8 voxel) - { - return voxel.getDensity(); - } } diff --git a/library/PolyVoxCore/source/MaterialDensityPair.cpp b/library/PolyVoxCore/source/MaterialDensityPair.cpp index f6d2c916..ccdfe5d9 100644 --- a/library/PolyVoxCore/source/MaterialDensityPair.cpp +++ b/library/PolyVoxCore/source/MaterialDensityPair.cpp @@ -25,27 +25,4 @@ freely, subject to the following restrictions: namespace PolyVox { - template<> - VoxelTypeTraits::DensityType convertToDensity(MaterialDensityPair44 voxel) - { - return voxel.getDensity(); - } - - template<> - VoxelTypeTraits::DensityType convertToDensity(MaterialDensityPair88 voxel) - { - return voxel.getDensity(); - } - - //template<> - ConvertToMaterial::MaterialType ConvertToMaterial::operator()(MaterialDensityPair44 voxel) - { - return voxel.getMaterial(); - } - - //template<> - ConvertToMaterial::MaterialType ConvertToMaterial::operator()(MaterialDensityPair88 voxel) - { - return voxel.getMaterial(); - } } diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index bd262dca..c9cad668 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -38,32 +38,32 @@ using namespace PolyVox; // 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 useful to other tests so we cold move them into a 'Tests.h' or something in the future. template -void writeDensityValueToVoxel(typename VoxelTypeTraits::DensityType valueToWrite, VoxelType& voxel) +void writeDensityValueToVoxel(int valueToWrite, VoxelType& voxel) { voxel = valueToWrite; } template<> -void writeDensityValueToVoxel(VoxelTypeTraits::DensityType valueToWrite, Density8& voxel) +void writeDensityValueToVoxel(int valueToWrite, Density8& voxel) { voxel.setDensity(valueToWrite); } template<> -void writeDensityValueToVoxel(VoxelTypeTraits::DensityType valueToWrite, MaterialDensityPair88& voxel) +void writeDensityValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) { voxel.setDensity(valueToWrite); } template -void writeMaterialValueToVoxel(typename VoxelTypeTraits::MaterialType valueToWrite, VoxelType& voxel) +void writeMaterialValueToVoxel(int valueToWrite, VoxelType& voxel) { //Most types don't have a material return; } template<> -void writeMaterialValueToVoxel(VoxelTypeTraits::MaterialType valueToWrite, MaterialDensityPair88& voxel) +void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) { voxel.setMaterial(valueToWrite); } diff --git a/tests/TestLowPassFilter.cpp b/tests/TestLowPassFilter.cpp index a20db6af..bc1fe0e8 100644 --- a/tests/TestLowPassFilter.cpp +++ b/tests/TestLowPassFilter.cpp @@ -63,24 +63,24 @@ void TestLowPassFilter::testExecute() pass1.execute(); std::cout << "Input volume:" << std::endl; - std::cout << "Voxel = " << static_cast(convertToDensity(volData.getVoxelAt(0,0,0))) << std::endl; // 32 - std::cout << "Voxel = " << static_cast(convertToDensity(volData.getVoxelAt(1,1,1))) << std::endl; // 0 - std::cout << "Voxel = " << static_cast(convertToDensity(volData.getVoxelAt(2,2,2))) << std::endl; // 3 - std::cout << "Voxel = " << static_cast(convertToDensity(volData.getVoxelAt(3,3,3))) << std::endl; // 0 - std::cout << "Voxel = " << static_cast(convertToDensity(volData.getVoxelAt(4,4,4))) << std::endl; // 32 - std::cout << "Voxel = " << static_cast(convertToDensity(volData.getVoxelAt(5,5,5))) << std::endl; // 0 - std::cout << "Voxel = " << static_cast(convertToDensity(volData.getVoxelAt(6,6,6))) << std::endl; // 32 - std::cout << "Voxel = " << static_cast(convertToDensity(volData.getVoxelAt(7,7,7))) << std::endl; // 0 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(0,0,0).getDensity()) << std::endl; // 32 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(1,1,1).getDensity()) << std::endl; // 0 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(2,2,2).getDensity()) << std::endl; // 3 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(3,3,3).getDensity()) << std::endl; // 0 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(4,4,4).getDensity()) << std::endl; // 32 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(5,5,5).getDensity()) << std::endl; // 0 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(6,6,6).getDensity()) << std::endl; // 32 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(7,7,7).getDensity()) << std::endl; // 0 std::cout << std::endl << "Output volume:" << std::endl; - std::cout << "Voxel = " << static_cast(convertToDensity(resultVolume.getVoxelAt(0,0,0))) << std::endl; // 4 - std::cout << "Voxel = " << static_cast(convertToDensity(resultVolume.getVoxelAt(1,1,1))) << std::endl; // 21 - std::cout << "Voxel = " << static_cast(convertToDensity(resultVolume.getVoxelAt(2,2,2))) << std::endl; // 10 - std::cout << "Voxel = " << static_cast(convertToDensity(resultVolume.getVoxelAt(3,3,3))) << std::endl; // 21 - std::cout << "Voxel = " << static_cast(convertToDensity(resultVolume.getVoxelAt(4,4,4))) << std::endl; // 10 - std::cout << "Voxel = " << static_cast(convertToDensity(resultVolume.getVoxelAt(5,5,5))) << std::endl; // 21 - std::cout << "Voxel = " << static_cast(convertToDensity(resultVolume.getVoxelAt(6,6,6))) << std::endl; // 10 - std::cout << "Voxel = " << static_cast(convertToDensity(resultVolume.getVoxelAt(7,7,7))) << std::endl; // 4 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(0,0,0).getDensity()) << std::endl; // 4 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(1,1,1).getDensity()) << std::endl; // 21 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(2,2,2).getDensity()) << std::endl; // 10 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(3,3,3).getDensity()) << std::endl; // 21 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(4,4,4).getDensity()) << std::endl; // 10 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(5,5,5).getDensity()) << std::endl; // 21 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(6,6,6).getDensity()) << std::endl; // 10 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(7,7,7).getDensity()) << std::endl; // 4 } QTEST_MAIN(TestLowPassFilter) diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index c0c981d1..77ef1abe 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -37,32 +37,32 @@ using namespace PolyVox; // 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. template -void writeDensityValueToVoxel(typename VoxelTypeTraits::DensityType valueToWrite, VoxelType& voxel) +void writeDensityValueToVoxel(int valueToWrite, VoxelType& voxel) { voxel = valueToWrite; } template<> -void writeDensityValueToVoxel(VoxelTypeTraits::DensityType valueToWrite, Density8& voxel) +void writeDensityValueToVoxel(int valueToWrite, Density8& voxel) { voxel.setDensity(valueToWrite); } template<> -void writeDensityValueToVoxel(VoxelTypeTraits::DensityType valueToWrite, MaterialDensityPair88& voxel) +void writeDensityValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) { voxel.setDensity(valueToWrite); } template -void writeMaterialValueToVoxel(typename VoxelTypeTraits::MaterialType valueToWrite, VoxelType& voxel) +void writeMaterialValueToVoxel(int valueToWrite, VoxelType& voxel) { //Most types don't have a material return; } template<> -void writeMaterialValueToVoxel(VoxelTypeTraits::MaterialType valueToWrite, MaterialDensityPair88& voxel) +void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) { voxel.setMaterial(valueToWrite); } @@ -92,7 +92,8 @@ void testForType(SurfaceMesh& result) } } - SurfaceExtractor< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result, 50); + // THIS TEST IS BROKEN BECAUSE CUSTOM THRESHOLDS ARE TEMOPRARILY NOT WORKING. + SurfaceExtractor< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result/*, 50*/); extractor.execute(); }