From 4b63c343057b2ee9bdb3c26d0ca0217d35a9ab43 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 28 Sep 2012 13:54:27 +0200 Subject: [PATCH 1/5] Brought the manual and API docs together under the same heading in Visual Studio. --- documentation/CMakeLists.txt | 2 +- examples/Basic/CMakeLists.txt | 2 +- examples/OpenGL/CMakeLists.txt | 2 +- examples/Paging/CMakeLists.txt | 2 +- examples/SmoothLOD/CMakeLists.txt | 2 +- library/CMakeLists.txt | 2 +- library/PolyVoxCore/CMakeLists.txt | 2 +- library/PolyVoxUtil/CMakeLists.txt | 2 +- library/bindings/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index fc936b4f..dfe05a96 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -36,7 +36,7 @@ if(SPHINXBUILD_EXECUTABLE) COMMENT "Building PolyVox manual" ) add_dependencies(manual doc) - SET_PROPERTY(TARGET manual PROPERTY FOLDER "documentation") + SET_PROPERTY(TARGET manual PROPERTY FOLDER "Documentation/Manual") else() if(NOT SPHINXBUILD_EXECUTABLE) message(STATUS "`sphinx-build` was not found. Try setting SPHINXBUILD_EXECUTABLE to its location.") diff --git a/examples/Basic/CMakeLists.txt b/examples/Basic/CMakeLists.txt index 4f0e03f8..8c09db66 100644 --- a/examples/Basic/CMakeLists.txt +++ b/examples/Basic/CMakeLists.txt @@ -59,7 +59,7 @@ IF(MSVC) SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) TARGET_LINK_LIBRARIES(BasicExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) -SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "examples/Basic") +SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples/Basic") #Install - Only install the example in Windows IF(WIN32) diff --git a/examples/OpenGL/CMakeLists.txt b/examples/OpenGL/CMakeLists.txt index b9d32acb..a67c6f88 100644 --- a/examples/OpenGL/CMakeLists.txt +++ b/examples/OpenGL/CMakeLists.txt @@ -65,7 +65,7 @@ IF(MSVC) SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) TARGET_LINK_LIBRARIES(OpenGLExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) -SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "examples/OpenGL") +SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples/OpenGL") #Install - Only install the example in Windows IF(WIN32) diff --git a/examples/Paging/CMakeLists.txt b/examples/Paging/CMakeLists.txt index 7016d798..2a390919 100644 --- a/examples/Paging/CMakeLists.txt +++ b/examples/Paging/CMakeLists.txt @@ -61,7 +61,7 @@ IF(MSVC) SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) TARGET_LINK_LIBRARIES(PagingExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) -SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "examples/Paging") +SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples/Paging") #Install - Only install the example in Windows IF(WIN32) diff --git a/examples/SmoothLOD/CMakeLists.txt b/examples/SmoothLOD/CMakeLists.txt index 4a1f7a7f..21da7bc7 100644 --- a/examples/SmoothLOD/CMakeLists.txt +++ b/examples/SmoothLOD/CMakeLists.txt @@ -59,7 +59,7 @@ IF(MSVC) SET_TARGET_PROPERTIES(SmoothLODExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings ENDIF(MSVC) TARGET_LINK_LIBRARIES(SmoothLODExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) -SET_PROPERTY(TARGET SmoothLODExample PROPERTY FOLDER "examples/SmoothLOD") +SET_PROPERTY(TARGET SmoothLODExample PROPERTY FOLDER "Examples/SmoothLOD") #Install - Only install the example in Windows IF(WIN32) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index aa1f9db3..617f761d 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -60,7 +60,7 @@ if(DOXYGEN_FOUND) VERBATIM ) set_target_properties(doc PROPERTIES PROJECT_LABEL "Documentation") #Set label seen in IDE - set_property(TARGET doc PROPERTY FOLDER "library/doc") + set_property(TARGET doc PROPERTY FOLDER "Documentation/API Reference") #If we found qcollectiongenerator then do more processing if(QT_QCOLLECTIONGENERATOR_EXECUTABLE) diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index f6f58a57..4e13cde0 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -144,7 +144,7 @@ IF(LIBRARY_TYPE STREQUAL "DYNAMIC") ADD_LIBRARY(PolyVoxCore SHARED ${CORE_SRC_FILES} ${CORE_INC_FILES} ${IMPL_SRC_FILES} ${IMPL_INC_FILES}) SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS") ENDIF() -SET_PROPERTY(TARGET PolyVoxCore PROPERTY FOLDER "library/PolyVoxCore") +SET_PROPERTY(TARGET PolyVoxCore PROPERTY FOLDER "Library/PolyVoxCore") SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR}) IF(MSVC) diff --git a/library/PolyVoxUtil/CMakeLists.txt b/library/PolyVoxUtil/CMakeLists.txt index db226bca..bff55765 100644 --- a/library/PolyVoxUtil/CMakeLists.txt +++ b/library/PolyVoxUtil/CMakeLists.txt @@ -61,7 +61,7 @@ IF(LIBRARY_TYPE STREQUAL "DYNAMIC") ADD_LIBRARY(PolyVoxUtil SHARED ${UTIL_SRC_FILES} ${UTIL_INC_FILES}) SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS") ENDIF() -SET_PROPERTY(TARGET PolyVoxUtil PROPERTY FOLDER "library/PolyVoxUtil") +SET_PROPERTY(TARGET PolyVoxUtil PROPERTY FOLDER "Library/PolyVoxUtil") TARGET_LINK_LIBRARIES(PolyVoxUtil PolyVoxCore) SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR}) diff --git a/library/bindings/CMakeLists.txt b/library/bindings/CMakeLists.txt index 98c2a408..a4a29ced 100644 --- a/library/bindings/CMakeLists.txt +++ b/library/bindings/CMakeLists.txt @@ -46,7 +46,7 @@ if(ENABLE_BINDINGS) swig_add_module(PolyVoxCore python PolyVoxCore.i) swig_link_libraries(PolyVoxCore ${PYTHON_LIBRARIES} PolyVoxCore) #set_target_properties(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTIES SUFFIX ".pyd") - SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTY FOLDER "library/bindings") + SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTY FOLDER "Library/Bindings") else() set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f67010d2..c10e9f9c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,7 +36,7 @@ MACRO(CREATE_TEST headerfile sourcefile executablename) ELSE(WIN32) SET(LATEST_TEST ${CMAKE_CURRENT_BINARY_DIR}/${executablename}) ENDIF(WIN32) - SET_PROPERTY(TARGET ${executablename} PROPERTY FOLDER "tests") + SET_PROPERTY(TARGET ${executablename} PROPERTY FOLDER "Tests") ENDMACRO(CREATE_TEST) IF(NOT QT_QTTEST_FOUND) From bc012232375234c5ef92d4afff8f4dc9ec5728e9 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 28 Sep 2012 14:07:13 +0200 Subject: [PATCH 2/5] Removed some unecessary hierarchy in VS project structure. Renamed the documentation targets in VS for clarity. --- documentation/CMakeLists.txt | 3 ++- examples/Basic/CMakeLists.txt | 2 +- examples/OpenGL/CMakeLists.txt | 2 +- examples/Paging/CMakeLists.txt | 2 +- examples/SmoothLOD/CMakeLists.txt | 2 +- library/CMakeLists.txt | 4 ++-- library/PolyVoxCore/CMakeLists.txt | 2 +- library/PolyVoxUtil/CMakeLists.txt | 2 +- library/bindings/CMakeLists.txt | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index dfe05a96..a0d0f346 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -36,7 +36,8 @@ if(SPHINXBUILD_EXECUTABLE) COMMENT "Building PolyVox manual" ) add_dependencies(manual doc) - SET_PROPERTY(TARGET manual PROPERTY FOLDER "Documentation/Manual") + set_target_properties(manual PROPERTIES PROJECT_LABEL "Manual") #Set label seen in IDE + SET_PROPERTY(TARGET manual PROPERTY FOLDER "Documentation") else() if(NOT SPHINXBUILD_EXECUTABLE) message(STATUS "`sphinx-build` was not found. Try setting SPHINXBUILD_EXECUTABLE to its location.") diff --git a/examples/Basic/CMakeLists.txt b/examples/Basic/CMakeLists.txt index 8c09db66..a17c1eeb 100644 --- a/examples/Basic/CMakeLists.txt +++ b/examples/Basic/CMakeLists.txt @@ -59,7 +59,7 @@ IF(MSVC) SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) TARGET_LINK_LIBRARIES(BasicExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) -SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples/Basic") +SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows IF(WIN32) diff --git a/examples/OpenGL/CMakeLists.txt b/examples/OpenGL/CMakeLists.txt index a67c6f88..5b61f759 100644 --- a/examples/OpenGL/CMakeLists.txt +++ b/examples/OpenGL/CMakeLists.txt @@ -65,7 +65,7 @@ IF(MSVC) SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) TARGET_LINK_LIBRARIES(OpenGLExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) -SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples/OpenGL") +SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows IF(WIN32) diff --git a/examples/Paging/CMakeLists.txt b/examples/Paging/CMakeLists.txt index 2a390919..88fb5b6f 100644 --- a/examples/Paging/CMakeLists.txt +++ b/examples/Paging/CMakeLists.txt @@ -61,7 +61,7 @@ IF(MSVC) SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) TARGET_LINK_LIBRARIES(PagingExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) -SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples/Paging") +SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows IF(WIN32) diff --git a/examples/SmoothLOD/CMakeLists.txt b/examples/SmoothLOD/CMakeLists.txt index 21da7bc7..86923a0a 100644 --- a/examples/SmoothLOD/CMakeLists.txt +++ b/examples/SmoothLOD/CMakeLists.txt @@ -59,7 +59,7 @@ IF(MSVC) SET_TARGET_PROPERTIES(SmoothLODExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings ENDIF(MSVC) TARGET_LINK_LIBRARIES(SmoothLODExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) -SET_PROPERTY(TARGET SmoothLODExample PROPERTY FOLDER "Examples/SmoothLOD") +SET_PROPERTY(TARGET SmoothLODExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows IF(WIN32) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 617f761d..7c37c32e 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -59,8 +59,8 @@ if(DOXYGEN_FOUND) SOURCES Doxyfile.in polyvox.qhcp.in Mainpage.dox VERBATIM ) - set_target_properties(doc PROPERTIES PROJECT_LABEL "Documentation") #Set label seen in IDE - set_property(TARGET doc PROPERTY FOLDER "Documentation/API Reference") + set_target_properties(doc PROPERTIES PROJECT_LABEL "API Reference") #Set label seen in IDE + set_property(TARGET doc PROPERTY FOLDER "Documentation") #If we found qcollectiongenerator then do more processing if(QT_QCOLLECTIONGENERATOR_EXECUTABLE) diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 4e13cde0..660aa8c8 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -144,7 +144,7 @@ IF(LIBRARY_TYPE STREQUAL "DYNAMIC") ADD_LIBRARY(PolyVoxCore SHARED ${CORE_SRC_FILES} ${CORE_INC_FILES} ${IMPL_SRC_FILES} ${IMPL_INC_FILES}) SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS") ENDIF() -SET_PROPERTY(TARGET PolyVoxCore PROPERTY FOLDER "Library/PolyVoxCore") +SET_PROPERTY(TARGET PolyVoxCore PROPERTY FOLDER "Library") SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR}) IF(MSVC) diff --git a/library/PolyVoxUtil/CMakeLists.txt b/library/PolyVoxUtil/CMakeLists.txt index bff55765..97dbb8da 100644 --- a/library/PolyVoxUtil/CMakeLists.txt +++ b/library/PolyVoxUtil/CMakeLists.txt @@ -61,7 +61,7 @@ IF(LIBRARY_TYPE STREQUAL "DYNAMIC") ADD_LIBRARY(PolyVoxUtil SHARED ${UTIL_SRC_FILES} ${UTIL_INC_FILES}) SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS") ENDIF() -SET_PROPERTY(TARGET PolyVoxUtil PROPERTY FOLDER "Library/PolyVoxUtil") +SET_PROPERTY(TARGET PolyVoxUtil PROPERTY FOLDER "Library") TARGET_LINK_LIBRARIES(PolyVoxUtil PolyVoxCore) SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR}) diff --git a/library/bindings/CMakeLists.txt b/library/bindings/CMakeLists.txt index a4a29ced..10bcd6f7 100644 --- a/library/bindings/CMakeLists.txt +++ b/library/bindings/CMakeLists.txt @@ -46,7 +46,7 @@ if(ENABLE_BINDINGS) swig_add_module(PolyVoxCore python PolyVoxCore.i) swig_link_libraries(PolyVoxCore ${PYTHON_LIBRARIES} PolyVoxCore) #set_target_properties(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTIES SUFFIX ".pyd") - SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTY FOLDER "Library/Bindings") + SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTY FOLDER "Bindings") else() set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE) endif() From 01e2a88b13890e264b765c26de8d46db98cb4679 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 28 Sep 2012 18:09:21 +0200 Subject: [PATCH 3/5] Improving the LowPassFilter to take advantage of the features made available by the voxel refactoring. Also improved the test case. --- examples/OpenGL/main.cpp | 14 +- .../PolyVoxCore/include/PolyVoxCore/Density.h | 58 ++++++-- .../include/PolyVoxCore/LowPassFilter.h | 2 +- .../include/PolyVoxCore/LowPassFilter.inl | 132 +++++++++--------- tests/TestLowPassFilter.cpp | 43 +++--- 5 files changed, 145 insertions(+), 104 deletions(-) diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index f478f16f..3766f808 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -101,12 +101,14 @@ int main(int argc, char *argv[]) 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)); - LowPassFilter< LargeVolume, RawVolume > pass1(&volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3); - pass1.executeSAT(); - LowPassFilter< RawVolume, LargeVolume > pass2(&tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3); - pass2.executeSAT(); + //I've removed this smoothing because it doesn't really make sense to apply a low pass filter to a volume with material values. + //I could implement the mathematical operators for MaterialDensityPair in such a way that they ignores the materials but this + //seems to be setting a bad example. Users can add this operators in their own classes if they want smoothing. + //RawVolume tempVolume(PolyVox::Region(0,0,0,128, 128, 128)); + //LowPassFilter< LargeVolume, RawVolume > pass1(&volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3); + //pass1.executeSAT(); + //LowPassFilter< RawVolume, LargeVolume > pass2(&tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3); + //pass2.executeSAT(); QApplication app(argc, argv); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 8987b4c1..1f9e2598 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -36,17 +36,9 @@ freely, subject to the following restrictions: namespace PolyVox { - ///This class represents a voxel storing only a density. + /// This class represents a voxel storing only a density. //////////////////////////////////////////////////////////////////////////////// - /// In order to perform a surface extraction on a LargeVolume, PolyVox needs the underlying - /// voxel type to provide both getDensity() and getMaterial() functions. The getDensity() - /// function is used to determine if a voxel is 'solid', and if it is then the getMaterial() - /// funtion is used to determine what material should be assigned to the resulting mesh. - /// - /// This class meets these requirements, although it only actually stores a density value. - /// For the getMaterial() function it just returns a constant value of '1'. - /// - /// \sa Material, MaterialDensityPair + /// Detailed description... //////////////////////////////////////////////////////////////////////////////// // int32_t template parameter is a dummy, required as the compiler expects to be able to declare an @@ -62,9 +54,18 @@ namespace PolyVox typedef Type DensityType; typedef int32_t MaterialType; //Shouldn't define this one... + /// Constructor Density() : m_uDensity(0) {} + + /// Copy constructor Density(DensityType uDensity) : m_uDensity(uDensity) {} + /// Copy constructor with cast + template explicit Density(const Density& density) throw() + { + m_uDensity = static_cast(density.getDensity()); + } + bool operator==(const Density& rhs) const throw() { return (m_uDensity == rhs.m_uDensity); @@ -75,12 +76,22 @@ namespace PolyVox return !(*this == rhs); } + // For densities we can supply mathematical operators which behave in an intuitive way. + // In particular the ability to add and subtract densities is important in order to + // apply an averaging filter. The ability to divide by an integer is also needed for + // this same purpose. Density& operator+=(const Density& rhs) { m_uDensity += rhs.m_uDensity; return *this; } + Density& operator-=(const Density& rhs) + { + m_uDensity -= rhs.m_uDensity; + return *this; + } + Density& operator/=(uint32_t rhs) { m_uDensity /= rhs; @@ -97,9 +108,36 @@ namespace PolyVox DensityType m_uDensity; }; + template + Density operator+(const Density& lhs, const Density& rhs) throw() + { + Density result = lhs; + result += rhs; + return result; + } + + template + Density operator-(const Density& lhs, const Density& rhs) throw() + { + Density result = lhs; + result -= rhs; + return result; + } + + template + Density operator/(const Density& lhs, uint32_t rhs) throw() + { + Density result = lhs; + result /= rhs; + return result; + } + // These are the predefined density types. The 8-bit types are sufficient for many purposes (including // most games) but 16-bit and float types do have uses particularly in medical/scientific visualisation. typedef Density Density8; + typedef Density Density16; + typedef Density Density32; + typedef Density DensityFloat; /** * This is a specialisation of DefaultMarchingCubesController for the Density voxel type diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h index 2b4b8a7e..732e2506 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h @@ -30,7 +30,7 @@ freely, subject to the following restrictions: namespace PolyVox { - template< typename SrcVolumeType, typename DstVolumeType> + template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType> class LowPassFilter { public: diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index 2df1fc11..4af838c4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -23,8 +23,8 @@ freely, subject to the following restrictions: namespace PolyVox { - template< typename SrcVolumeType, typename DstVolumeType> - LowPassFilter::LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DstVolumeType* pVolDst, Region regDst, uint32_t uKernelSize) + template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType> + LowPassFilter::LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DstVolumeType* pVolDst, Region regDst, uint32_t uKernelSize) :m_pVolSrc(pVolSrc) ,m_regSrc(regSrc) ,m_pVolDst(pVolDst) @@ -43,8 +43,8 @@ namespace PolyVox } } - template< typename SrcVolumeType, typename DstVolumeType> - void LowPassFilter::execute() + template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType> + void LowPassFilter::execute() { int32_t iSrcMinX = m_regSrc.getLowerCorner().getX(); int32_t iSrcMinY = m_regSrc.getLowerCorner().getY(); @@ -70,52 +70,50 @@ namespace PolyVox { for(int32_t iSrcX = iSrcMinX, iDstX = iDstMinX; iSrcX <= iSrcMaxX; iSrcX++, iDstX++) { - //VoxelType tSrcVoxel = m_pVolSrc->getVoxelAt(iSrcX, iSrcY, iSrcZ); + AccumulationType tSrcVoxel(0); srcSampler.setPosition(iSrcX, iSrcY, iSrcZ); - typename SrcVolumeType::VoxelType tSrcVoxel = srcSampler.getVoxel(); + tSrcVoxel += static_cast(srcSampler.peekVoxel1nx1ny1nz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1nx1ny0pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1nx1ny1pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1nx0py1nz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1nx0py0pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1nx0py1pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1nx1py1nz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1nx1py0pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1nx1py1pz()); - tSrcVoxel += srcSampler.peekVoxel1nx1ny1nz(); - tSrcVoxel += srcSampler.peekVoxel1nx1ny0pz(); - tSrcVoxel += srcSampler.peekVoxel1nx1ny1pz(); - tSrcVoxel += srcSampler.peekVoxel1nx0py1nz(); - tSrcVoxel += srcSampler.peekVoxel1nx0py0pz(); - tSrcVoxel += srcSampler.peekVoxel1nx0py1pz(); - tSrcVoxel += srcSampler.peekVoxel1nx1py1nz(); - tSrcVoxel += srcSampler.peekVoxel1nx1py0pz(); - tSrcVoxel += srcSampler.peekVoxel1nx1py1pz(); + tSrcVoxel += static_cast(srcSampler.peekVoxel0px1ny1nz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel0px1ny0pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel0px1ny1pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel0px0py1nz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel0px0py0pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel0px0py1pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel0px1py1nz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel0px1py0pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel0px1py1pz()); - tSrcVoxel += srcSampler.peekVoxel0px1ny1nz(); - tSrcVoxel += srcSampler.peekVoxel0px1ny0pz(); - tSrcVoxel += srcSampler.peekVoxel0px1ny1pz(); - tSrcVoxel += srcSampler.peekVoxel0px0py1nz(); - //tSrcVoxel += srcSampler.peekVoxel0px0py0pz(); - tSrcVoxel += srcSampler.peekVoxel0px0py1pz(); - tSrcVoxel += srcSampler.peekVoxel0px1py1nz(); - tSrcVoxel += srcSampler.peekVoxel0px1py0pz(); - tSrcVoxel += srcSampler.peekVoxel0px1py1pz(); - - tSrcVoxel += srcSampler.peekVoxel1px1ny1nz(); - tSrcVoxel += srcSampler.peekVoxel1px1ny0pz(); - tSrcVoxel += srcSampler.peekVoxel1px1ny1pz(); - tSrcVoxel += srcSampler.peekVoxel1px0py1nz(); - tSrcVoxel += srcSampler.peekVoxel1px0py0pz(); - tSrcVoxel += srcSampler.peekVoxel1px0py1pz(); - tSrcVoxel += srcSampler.peekVoxel1px1py1nz(); - tSrcVoxel += srcSampler.peekVoxel1px1py0pz(); - tSrcVoxel += srcSampler.peekVoxel1px1py1pz(); + tSrcVoxel += static_cast(srcSampler.peekVoxel1px1ny1nz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1px1ny0pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1px1ny1pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1px0py1nz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1px0py0pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1px0py1pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1px1py1nz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1px1py0pz()); + tSrcVoxel += static_cast(srcSampler.peekVoxel1px1py1pz()); tSrcVoxel /= 27; //tSrcVoxel.setDensity(uDensity); - m_pVolDst->setVoxelAt(iSrcX, iSrcY, iSrcZ, tSrcVoxel); + m_pVolDst->setVoxelAt(iSrcX, iSrcY, iSrcZ, static_cast(tSrcVoxel)); } } } } - template< typename SrcVolumeType, typename DstVolumeType> - void LowPassFilter::executeSAT() + template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType> + void LowPassFilter::executeSAT() { const uint32_t border = (m_uKernelSize - 1) / 2; @@ -124,7 +122,7 @@ namespace PolyVox //Use floats for the SAT volume to ensure it works with negative //densities and with both integral and floating point input volumes. - RawVolume satVolume(Region(satLowerCorner, satUpperCorner)); + RawVolume satVolume(Region(satLowerCorner, satUpperCorner)); //Clear to zeros (necessary?) //FIXME - use Volume::fill() method. Implemented in base class as below @@ -140,9 +138,9 @@ namespace PolyVox } } - RawVolume::Sampler satVolumeIter(&satVolume); + RawVolume::Sampler satVolumeIter(&satVolume); - IteratorController::Sampler> satIterCont; + IteratorController::Sampler> satIterCont; satIterCont.m_regValid = Region(satLowerCorner, satUpperCorner); satIterCont.m_Iter = &satVolumeIter; satIterCont.reset(); @@ -154,32 +152,34 @@ namespace PolyVox srcIterCont.m_Iter = &srcVolumeIter; srcIterCont.reset(); - do + /*do { - float previousSum = satVolumeIter.peekVoxel1nx0py0pz(); + AccumulationType previousSum = satVolumeIter.peekVoxel1nx0py0pz(); - float currentVal = static_cast(srcVolumeIter.getVoxel().getDensity()); + AccumulationType currentVal = srcVolumeIter.getVoxel(); satVolumeIter.setVoxel(previousSum + currentVal); srcIterCont.moveForward(); - }while(satIterCont.moveForward()); + }while(satIterCont.moveForward());*/ //Build SAT in three passes - /*for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) + for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) { for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++) { for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) { - uint32_t previousSum = satVolume.getVoxelAt(x-1,y,z); - uint32_t currentVal = m_pVolSrc->getVoxelAt(x,y,z).getDensity(); + AccumulationType previousSum = static_cast(satVolume.getVoxelAt(x-1,y,z)); + AccumulationType currentVal = static_cast(m_pVolSrc->getVoxelAt(x,y,z)); - satVolume.setVoxelAt(x,y,z,previousSum + currentVal); + AccumulationType sum = previousSum + currentVal; + + satVolume.setVoxelAt(x,y,z,sum); } } - }*/ + } for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) { @@ -187,8 +187,8 @@ namespace PolyVox { for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) { - float previousSum = satVolume.getVoxelAt(x,y-1,z); - float currentSum = satVolume.getVoxelAt(x,y,z); + AccumulationType previousSum = static_cast(satVolume.getVoxelAt(x,y-1,z)); + AccumulationType currentSum = static_cast(satVolume.getVoxelAt(x,y,z)); satVolume.setVoxelAt(x,y,z,previousSum + currentSum); } @@ -201,8 +201,8 @@ namespace PolyVox { for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) { - float previousSum = satVolume.getVoxelAt(x,y,z-1); - float currentSum = satVolume.getVoxelAt(x,y,z); + AccumulationType previousSum = static_cast(satVolume.getVoxelAt(x,y,z-1)); + AccumulationType currentSum = static_cast(satVolume.getVoxelAt(x,y,z)); satVolume.setVoxelAt(x,y,z,previousSum + currentSum); } @@ -229,27 +229,27 @@ namespace PolyVox int32_t satUpperY = iSrcY + border; int32_t satUpperZ = iSrcZ + border; - float a = satVolume.getVoxelAt(satLowerX,satLowerY,satLowerZ); - float b = satVolume.getVoxelAt(satUpperX,satLowerY,satLowerZ); - float c = satVolume.getVoxelAt(satLowerX,satUpperY,satLowerZ); - float d = satVolume.getVoxelAt(satUpperX,satUpperY,satLowerZ); - float e = satVolume.getVoxelAt(satLowerX,satLowerY,satUpperZ); - float f = satVolume.getVoxelAt(satUpperX,satLowerY,satUpperZ); - float g = satVolume.getVoxelAt(satLowerX,satUpperY,satUpperZ); - float h = satVolume.getVoxelAt(satUpperX,satUpperY,satUpperZ); + AccumulationType a = satVolume.getVoxelAt(satLowerX,satLowerY,satLowerZ); + AccumulationType b = satVolume.getVoxelAt(satUpperX,satLowerY,satLowerZ); + AccumulationType c = satVolume.getVoxelAt(satLowerX,satUpperY,satLowerZ); + AccumulationType d = satVolume.getVoxelAt(satUpperX,satUpperY,satLowerZ); + AccumulationType e = satVolume.getVoxelAt(satLowerX,satLowerY,satUpperZ); + AccumulationType f = satVolume.getVoxelAt(satUpperX,satLowerY,satUpperZ); + AccumulationType g = satVolume.getVoxelAt(satLowerX,satUpperY,satUpperZ); + AccumulationType h = satVolume.getVoxelAt(satUpperX,satUpperY,satUpperZ); - float sum = h+c-d-g-f-a+b+e; + AccumulationType sum = h+c-d-g-f-a+b+e; uint32_t sideLength = border * 2 + 1; - float average = sum / (static_cast(sideLength*sideLength*sideLength)); + AccumulationType average = sum / (sideLength*sideLength*sideLength); //Note: These lines need consideration if src and dest have different voxel types. - typename SrcVolumeType::VoxelType voxel = m_pVolSrc->getVoxelAt(iDstX, iDstY, iDstZ); + //typename SrcVolumeType::VoxelType voxel = m_pVolSrc->getVoxelAt(iDstX, iDstY, iDstZ); - voxel.setDensity(static_cast(average)); + //voxel.setDensity(static_cast(average)); - m_pVolDst->setVoxelAt(iDstX, iDstY, iDstZ, voxel); + m_pVolDst->setVoxelAt(iDstX, iDstY, iDstZ, static_cast(average)); //float maxSolid = border * 2/* + 1*/; diff --git a/tests/TestLowPassFilter.cpp b/tests/TestLowPassFilter.cpp index bc1fe0e8..26238e63 100644 --- a/tests/TestLowPassFilter.cpp +++ b/tests/TestLowPassFilter.cpp @@ -58,29 +58,30 @@ void TestLowPassFilter::testExecute() RawVolume resultVolume(reg); - LowPassFilter< RawVolume, RawVolume > pass1(&volData, reg, &resultVolume, reg, 5); + LowPassFilter< RawVolume, RawVolume, Density16 > lowPassfilter(&volData, reg, &resultVolume, reg, 5); - pass1.execute(); + //Test the normal implementation + lowPassfilter.execute(); + QCOMPARE(resultVolume.getVoxelAt(0,0,0), Density8(4)); + QCOMPARE(resultVolume.getVoxelAt(1,1,1), Density8(21)); + QCOMPARE(resultVolume.getVoxelAt(2,2,2), Density8(10)); + QCOMPARE(resultVolume.getVoxelAt(3,3,3), Density8(21)); + QCOMPARE(resultVolume.getVoxelAt(4,4,4), Density8(10)); + QCOMPARE(resultVolume.getVoxelAt(5,5,5), Density8(21)); + QCOMPARE(resultVolume.getVoxelAt(6,6,6), Density8(10)); + QCOMPARE(resultVolume.getVoxelAt(7,7,7), Density8(4)); - std::cout << "Input volume:" << std::endl; - 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(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 + //Test the SAT implmentation + //FIXME - Shouldn't the results be the same as the normal case? + lowPassfilter.executeSAT(); + QCOMPARE(resultVolume.getVoxelAt(0,0,0), Density8(4)); + QCOMPARE(resultVolume.getVoxelAt(1,1,1), Density8(8)); + QCOMPARE(resultVolume.getVoxelAt(2,2,2), Density8(19)); + QCOMPARE(resultVolume.getVoxelAt(3,3,3), Density8(12)); + QCOMPARE(resultVolume.getVoxelAt(4,4,4), Density8(19)); + QCOMPARE(resultVolume.getVoxelAt(5,5,5), Density8(12)); + QCOMPARE(resultVolume.getVoxelAt(6,6,6), Density8(8)); + QCOMPARE(resultVolume.getVoxelAt(7,7,7), Density8(2)); } QTEST_MAIN(TestLowPassFilter) From 7189abb603fd777a77acdb07002f68b542f7ed81 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 28 Sep 2012 18:14:53 +0200 Subject: [PATCH 4/5] Tidying up LowPassfilter and reenabling use of iterator functionality. --- .../include/PolyVoxCore/LowPassFilter.inl | 35 ++++--------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index 4af838c4..d643982d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -152,20 +152,19 @@ namespace PolyVox srcIterCont.m_Iter = &srcVolumeIter; srcIterCont.reset(); - /*do + do { - AccumulationType previousSum = satVolumeIter.peekVoxel1nx0py0pz(); - - AccumulationType currentVal = srcVolumeIter.getVoxel(); + AccumulationType previousSum = static_cast(satVolumeIter.peekVoxel1nx0py0pz()); + AccumulationType currentVal = static_cast(srcVolumeIter.getVoxel()); satVolumeIter.setVoxel(previousSum + currentVal); srcIterCont.moveForward(); - }while(satIterCont.moveForward());*/ + }while(satIterCont.moveForward()); //Build SAT in three passes - for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) + /*for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) { for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++) { @@ -174,12 +173,10 @@ namespace PolyVox AccumulationType previousSum = static_cast(satVolume.getVoxelAt(x-1,y,z)); AccumulationType currentVal = static_cast(m_pVolSrc->getVoxelAt(x,y,z)); - AccumulationType sum = previousSum + currentVal; - - satVolume.setVoxelAt(x,y,z,sum); + satVolume.setVoxelAt(x,y,z,previousSum + currentVal); } } - } + }*/ for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) { @@ -239,28 +236,10 @@ namespace PolyVox AccumulationType h = satVolume.getVoxelAt(satUpperX,satUpperY,satUpperZ); AccumulationType sum = h+c-d-g-f-a+b+e; - uint32_t sideLength = border * 2 + 1; - AccumulationType average = sum / (sideLength*sideLength*sideLength); - //Note: These lines need consideration if src and dest have different voxel types. - //typename SrcVolumeType::VoxelType voxel = m_pVolSrc->getVoxelAt(iDstX, iDstY, iDstZ); - - //voxel.setDensity(static_cast(average)); - m_pVolDst->setVoxelAt(iDstX, iDstY, iDstZ, static_cast(average)); - - - //float maxSolid = border * 2/* + 1*/; - /*maxSolid = maxSolid * maxSolid * maxSolid; - - float percentSolid = noSolid / maxSolid; - float percentEmpty = 1.0f - percentSolid; - - (*mAmbientOcclusionVolume)[ambVolZ][ambVolY][ambVolX] = 255 * percentEmpty;*/ - - //(*mAmbientOcclusionVolume)[ambVolZ][ambVolY][ambVolX] = 255 - ((h+c-d-g-f-a+b+e) * 19); //FIXME - should not be 9 } } } From 2fbe4182591e21cbd3fb338c05eccc9e972b634a Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 28 Sep 2012 18:38:44 +0200 Subject: [PATCH 5/5] Material/Density types are no longer exposed on voxels. This is because primitive types don't have them anyway. --- .../PolyVoxCore/include/PolyVoxCore/Density.h | 20 ++++------- .../include/PolyVoxCore/Material.h | 24 +++----------- .../include/PolyVoxCore/MaterialDensityPair.h | 33 +++++-------------- 3 files changed, 21 insertions(+), 56 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 1f9e2598..0ae3d82a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -47,19 +47,13 @@ namespace PolyVox class Density { public: - //We expose DensityType and MaterialType in this way so that, when code is - //templatised on voxel type, it can determine the underlying storage type - //using code such as 'VoxelType::DensityType value = voxel.getDensity()' - //or 'VoxelType::MaterialType value = voxel.getMaterial()'. - typedef Type DensityType; - typedef int32_t MaterialType; //Shouldn't define this one... - /// Constructor Density() : m_uDensity(0) {} /// Copy constructor - Density(DensityType uDensity) : m_uDensity(uDensity) {} + Density(Type uDensity) : m_uDensity(uDensity) {} + // The LowPassFilter uses this to convert between normal and accumulated types. /// Copy constructor with cast template explicit Density(const Density& density) throw() { @@ -98,14 +92,14 @@ namespace PolyVox return *this; } - DensityType getDensity() const throw() { return m_uDensity; } - void setDensity(DensityType uDensity) { m_uDensity = uDensity; } + Type getDensity() const throw() { return m_uDensity; } + void setDensity(Type uDensity) { m_uDensity = uDensity; } - static DensityType getMaxDensity() throw() { return (std::numeric_limits::max)(); } - static DensityType getMinDensity() throw() { return (std::numeric_limits::min)(); } + static Type getMaxDensity() throw() { return (std::numeric_limits::max)(); } + static Type getMinDensity() throw() { return (std::numeric_limits::min)(); } private: - DensityType m_uDensity; + Type m_uDensity; }; template diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 9bbb3bc8..5cc074cb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -34,14 +34,7 @@ namespace PolyVox { ///This class represents a voxel storing only a material. //////////////////////////////////////////////////////////////////////////////// - /// In order to perform a surface extraction on a LargeVolume, PolyVox needs the underlying - /// voxel type to provide both getDensity() and getMaterial() functions. The getDensity() - /// function is used to determine if a voxel is 'solid', and if it is then the getMaterial() - /// funtion is used to determine what material should be assigned to the resulting mesh. - /// - /// This class meets these requirements, although it only actually stores a material value. - /// For the getDensity() function it simply returns the smallest possible density if the - /// material is zero and the largest possible density if the material is not zero. + /// Detailed description... /// /// \sa Density, MaterialDensityPair //////////////////////////////////////////////////////////////////////////////// @@ -52,15 +45,8 @@ namespace PolyVox class Material { public: - //We expose DensityType and MaterialType in this way so that, when code is - //templatised on voxel type, it can determine the underlying storage type - //using code such as 'VoxelType::DensityType value = voxel.getDensity()' - //or 'VoxelType::MaterialType value = voxel.getMaterial()'. - typedef int32_t DensityType; - typedef Type MaterialType; - Material() : m_uMaterial(0) {} - Material(MaterialType uMaterial) : m_uMaterial(uMaterial) {} + Material(Type uMaterial) : m_uMaterial(uMaterial) {} bool operator==(const Material& rhs) const throw() { @@ -72,11 +58,11 @@ namespace PolyVox return !(*this == rhs); } - MaterialType getMaterial() const throw() { return m_uMaterial; } - void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } + Type getMaterial() const throw() { return m_uMaterial; } + void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; } private: - MaterialType m_uMaterial; + Type m_uMaterial; }; typedef Material Material8; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 6ab9a563..8da28bfd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -33,15 +33,7 @@ namespace PolyVox { /// This class represents a voxel storing only a density. //////////////////////////////////////////////////////////////////////////////// - /// In order to perform a surface extraction on a LargeVolume, PolyVox needs the underlying - /// voxel type to provide both getDensity() and getMaterial() functions. The getDensity() - /// function is used to determine if a voxel is 'solid', and if it is then the getMaterial() - /// funtion is used to determine what material should be assigned to the resulting mesh. - /// - /// This class meets these requirements, and does so by storing and returning both a material - /// and a density value. Via the template parameters it is possible to control how much - /// precision is given to each. For example, if you create a class with 8 bits of storage, - /// you might choose to allocate 6 bits for the density and 2 bits for the material. + /// Detailed description... /// /// \sa Density, Material //////////////////////////////////////////////////////////////////////////////// @@ -49,13 +41,6 @@ namespace PolyVox class MaterialDensityPair { public: - //We expose DensityType and MaterialType in this way so that, when code is - //templatised on voxel type, it can determine the underlying storage type - //using code such as 'VoxelType::DensityType value = voxel.getDensity()' - //or 'VoxelType::MaterialType value = voxel.getMaterial()'. - typedef Type DensityType; - typedef Type MaterialType; - MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {} MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {} @@ -87,18 +72,18 @@ namespace PolyVox return *this; } - DensityType getDensity() const throw() { return m_uDensity; } - MaterialType getMaterial() const throw() { return m_uMaterial; } + Type getDensity() const throw() { return m_uDensity; } + Type getMaterial() const throw() { return m_uMaterial; } - void setDensity(DensityType uDensity) { m_uDensity = uDensity; } - void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } + void setDensity(Type uDensity) { m_uDensity = uDensity; } + void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; } - static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; } - static DensityType getMinDensity() throw() { return 0; } + static Type getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; } + static Type getMinDensity() throw() { return 0; } private: - MaterialType m_uMaterial : NoOfMaterialBits; - DensityType m_uDensity : NoOfDensityBits; + Type m_uMaterial : NoOfMaterialBits; + Type m_uDensity : NoOfDensityBits; }; template