Normalized line endings

This commit is contained in:
David Williams
2014-09-25 22:38:01 +02:00
parent c560e84be5
commit 86357d66b7
106 changed files with 50344 additions and 50344 deletions

View File

@ -1,86 +1,86 @@
# Copyright (c) 2008-2012 Matt Williams
# Copyright (c) 2008-2012 David Williams
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(PolyVox)
add_subdirectory(PolyVoxCore)
add_subdirectory(PolyVoxUtil)
add_subdirectory(bindings)
#Set up install paths e.g. for PolyVoxConfig.cmake
if(WIN32)
set(CONFIG_FILE_DIR "CMake")
set(PolyVoxCore_LIBRARY_INSTALL_DIRS "PolyVoxCore/lib")
set(PolyVoxUtil_LIBRARY_INSTALL_DIRS "PolyVoxUtil/lib")
set(PolyVoxCore_INCLUDE_INSTALL_DIRS "PolyVoxCore/include")
set(PolyVoxUtil_INCLUDE_INSTALL_DIRS "PolyVoxUtil/include")
set(PolyVox_DOC_INSTALL_DIR "PolyVox/doc")
else(WIN32)
set(CONFIG_FILE_DIR "share/PolyVox/cmake")
set(PolyVoxCore_LIBRARY_INSTALL_DIRS "lib")
set(PolyVoxUtil_LIBRARY_INSTALL_DIRS "lib")
set(PolyVoxCore_INCLUDE_INSTALL_DIRS "include/PolyVoxCore")
set(PolyVoxUtil_INCLUDE_INSTALL_DIRS "include/PolyVoxUtil")
set(PolyVox_DOC_INSTALL_DIR "share/doc/packages/polyvox")
endif(WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/PolyVoxConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/PolyVoxConfig.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PolyVoxConfig.cmake DESTINATION ${CONFIG_FILE_DIR} COMPONENT development)
if(DOXYGEN_FOUND)
#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/polyvox.css ${CMAKE_CURRENT_BINARY_DIR}/polyvox.css)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
#This is just the default doc target which only runs Doxygen
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Building documentation"
SOURCES Doxyfile.in polyvox.qhcp.in Mainpage.dox
VERBATIM
)
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)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/polyvox.qhcp.in ${CMAKE_CURRENT_BINARY_DIR}/doc/qthelp/polyvox.qhcp) #The QtHelp config file
#We attach this command to the doc target so it will be run automatically
add_custom_command(TARGET doc POST_BUILD
COMMAND ${QT_QCOLLECTIONGENERATOR_EXECUTABLE} polyvox.qhcp -o polyvox.qhc
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/qthelp
COMMENT "Compiling API documentation to Qt Help format"
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/doc/qthelp/polyvox.qhc
${CMAKE_CURRENT_BINARY_DIR}/doc/qthelp/polyvox.qch
DESTINATION ${PolyVox_DOC_INSTALL_DIR}/qthelp
COMPONENT development
OPTIONAL
)
endif()
endif()
#add_subdirectory(bindings)
# Copyright (c) 2008-2012 Matt Williams
# Copyright (c) 2008-2012 David Williams
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(PolyVox)
add_subdirectory(PolyVoxCore)
add_subdirectory(PolyVoxUtil)
add_subdirectory(bindings)
#Set up install paths e.g. for PolyVoxConfig.cmake
if(WIN32)
set(CONFIG_FILE_DIR "CMake")
set(PolyVoxCore_LIBRARY_INSTALL_DIRS "PolyVoxCore/lib")
set(PolyVoxUtil_LIBRARY_INSTALL_DIRS "PolyVoxUtil/lib")
set(PolyVoxCore_INCLUDE_INSTALL_DIRS "PolyVoxCore/include")
set(PolyVoxUtil_INCLUDE_INSTALL_DIRS "PolyVoxUtil/include")
set(PolyVox_DOC_INSTALL_DIR "PolyVox/doc")
else(WIN32)
set(CONFIG_FILE_DIR "share/PolyVox/cmake")
set(PolyVoxCore_LIBRARY_INSTALL_DIRS "lib")
set(PolyVoxUtil_LIBRARY_INSTALL_DIRS "lib")
set(PolyVoxCore_INCLUDE_INSTALL_DIRS "include/PolyVoxCore")
set(PolyVoxUtil_INCLUDE_INSTALL_DIRS "include/PolyVoxUtil")
set(PolyVox_DOC_INSTALL_DIR "share/doc/packages/polyvox")
endif(WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/PolyVoxConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/PolyVoxConfig.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PolyVoxConfig.cmake DESTINATION ${CONFIG_FILE_DIR} COMPONENT development)
if(DOXYGEN_FOUND)
#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/polyvox.css ${CMAKE_CURRENT_BINARY_DIR}/polyvox.css)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
#This is just the default doc target which only runs Doxygen
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Building documentation"
SOURCES Doxyfile.in polyvox.qhcp.in Mainpage.dox
VERBATIM
)
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)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/polyvox.qhcp.in ${CMAKE_CURRENT_BINARY_DIR}/doc/qthelp/polyvox.qhcp) #The QtHelp config file
#We attach this command to the doc target so it will be run automatically
add_custom_command(TARGET doc POST_BUILD
COMMAND ${QT_QCOLLECTIONGENERATOR_EXECUTABLE} polyvox.qhcp -o polyvox.qhc
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/qthelp
COMMENT "Compiling API documentation to Qt Help format"
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/doc/qthelp/polyvox.qhc
${CMAKE_CURRENT_BINARY_DIR}/doc/qthelp/polyvox.qch
DESTINATION ${PolyVox_DOC_INSTALL_DIR}/qthelp
COMPONENT development
OPTIONAL
)
endif()
endif()
#add_subdirectory(bindings)

View File

@ -1,164 +1,164 @@
# Copyright (c) 2008-2012 Matt Williams
# Copyright (c) 2008-2012 David Williams
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
PROJECT(PolyVoxCore)
#Projects source files
SET(CORE_SRC_FILES
source/AStarPathfinder.cpp
source/Region.cpp
)
#Projects headers files
SET(CORE_INC_FILES
include/PolyVoxCore/AmbientOcclusionCalculator.h
include/PolyVoxCore/AmbientOcclusionCalculator.inl
include/PolyVoxCore/Array.h
include/PolyVoxCore/AStarPathfinder.h
include/PolyVoxCore/AStarPathfinder.inl
include/PolyVoxCore/BaseVolume.h
include/PolyVoxCore/BaseVolume.inl
include/PolyVoxCore/BaseVolumeSampler.inl
include/PolyVoxCore/CubicSurfaceExtractor.h
include/PolyVoxCore/CubicSurfaceExtractor.inl
include/PolyVoxCore/DefaultIsQuadNeeded.h
include/PolyVoxCore/DefaultMarchingCubesController.h
include/PolyVoxCore/Density.h
include/PolyVoxCore/FilePager.h
include/PolyVoxCore/GradientEstimators.h
include/PolyVoxCore/GradientEstimators.inl
include/PolyVoxCore/Interpolation.h
include/PolyVoxCore/IteratorController.h
include/PolyVoxCore/IteratorController.inl
include/PolyVoxCore/LargeVolume.h
include/PolyVoxCore/LowPassFilter.h
include/PolyVoxCore/LowPassFilter.inl
include/PolyVoxCore/MarchingCubesSurfaceExtractor.h
include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
include/PolyVoxCore/Material.h
include/PolyVoxCore/MaterialDensityPair.h
include/PolyVoxCore/Mesh.h
include/PolyVoxCore/Mesh.inl
include/PolyVoxCore/PagedVolume.h
include/PolyVoxCore/PagedVolume.inl
include/PolyVoxCore/PagedVolumeChunk.inl
include/PolyVoxCore/PagedVolumeSampler.inl
include/PolyVoxCore/PolyVoxForwardDeclarations.h
include/PolyVoxCore/Picking.h
include/PolyVoxCore/Picking.inl
include/PolyVoxCore/RawVolume.h
include/PolyVoxCore/RawVolume.inl
include/PolyVoxCore/RawVolumeSampler.inl
include/PolyVoxCore/Raycast.h
include/PolyVoxCore/Raycast.inl
include/PolyVoxCore/Region.h
include/PolyVoxCore/SimpleVolume.h
include/PolyVoxCore/Vector.h
include/PolyVoxCore/Vector.inl
include/PolyVoxCore/Vertex.h
include/PolyVoxCore/VolumeResampler.h
include/PolyVoxCore/VolumeResampler.inl
include/PolyVoxCore/VoxelFilters.h
include/PolyVoxCore/VoxelFilters.inl
)
SET(IMPL_SRC_FILES
source/Impl/ErrorHandling.cpp
source/Impl/Logging.cpp
source/Impl/MarchingCubesTables.cpp
source/Impl/RandomUnitVectors.cpp
source/Impl/RandomVectors.cpp
source/Impl/Timer.cpp
source/Impl/Utility.cpp
)
SET(IMPL_INC_FILES
include/PolyVoxCore/Impl/AStarPathfinderImpl.h
include/PolyVoxCore/Impl/Config.h
include/PolyVoxCore/Impl/ErrorHandling.h
include/PolyVoxCore/Impl/Logging.h
include/PolyVoxCore/Impl/MarchingCubesTables.h
include/PolyVoxCore/Impl/RandomUnitVectors.h
include/PolyVoxCore/Impl/RandomVectors.h
include/PolyVoxCore/Impl/Timer.h
include/PolyVoxCore/Impl/TypeDef.h
include/PolyVoxCore/Impl/Utility.h
)
#NOTE: The following line should be uncommented when building shared libs.
#"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too...
SOURCE_GROUP("Source Files" FILES ${CORE_SRC_FILES})
SOURCE_GROUP("Header Files" FILES ${CORE_INC_FILES})
SOURCE_GROUP("Source Files\\Impl" FILES ${IMPL_SRC_FILES})
SOURCE_GROUP("Header Files\\Impl" FILES ${IMPL_INC_FILES})
#Tell CMake the paths
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include)
#Core
#Build
IF(LIBRARY_TYPE STREQUAL "STATIC")
ADD_LIBRARY(PolyVoxCore STATIC ${CORE_SRC_FILES} ${CORE_INC_FILES} ${IMPL_SRC_FILES} ${IMPL_INC_FILES})
IF(UNIX)
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS -fPIC)
ENDIF()
ENDIF()
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")
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS "/W4 /wd4251") #Disable warning on STL exports
ENDIF(MSVC)
#Install
IF(WIN32)
INSTALL(TARGETS PolyVoxCore
RUNTIME DESTINATION PolyVoxCore/bin COMPONENT library
LIBRARY DESTINATION PolyVoxCore/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxCore/lib COMPONENT library
)
#Install the core header files, including the ones in the Impl subfolder.
INSTALL(DIRECTORY include DESTINATION PolyVoxCore COMPONENT development PATTERN "*.svn*" EXCLUDE)
#On windows, we also install the debug information. It's unfortunate that we have to hard-code
#the 'Debug' part of the path, but CMake doesn't seem to provide a way around this. The best I
#found was: http://www.cmake.org/pipermail/cmake/2007-October/016924.html (and it is a bit ugly).
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/PolyVoxCore.pdb DESTINATION PolyVoxCore/lib CONFIGURATIONS Debug)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/PolyVoxCore.pdb DESTINATION PolyVoxCore/lib CONFIGURATIONS RelWithDebInfo)
ELSE(WIN32)
INSTALL(TARGETS PolyVoxCore
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
#Install the core header files, including the ones in the Impl subfolder.
INSTALL(DIRECTORY include/ DESTINATION include/PolyVoxCore COMPONENT development PATTERN "*.svn*" EXCLUDE)
ENDIF(WIN32)
# Copyright (c) 2008-2012 Matt Williams
# Copyright (c) 2008-2012 David Williams
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
PROJECT(PolyVoxCore)
#Projects source files
SET(CORE_SRC_FILES
source/AStarPathfinder.cpp
source/Region.cpp
)
#Projects headers files
SET(CORE_INC_FILES
include/PolyVoxCore/AmbientOcclusionCalculator.h
include/PolyVoxCore/AmbientOcclusionCalculator.inl
include/PolyVoxCore/Array.h
include/PolyVoxCore/AStarPathfinder.h
include/PolyVoxCore/AStarPathfinder.inl
include/PolyVoxCore/BaseVolume.h
include/PolyVoxCore/BaseVolume.inl
include/PolyVoxCore/BaseVolumeSampler.inl
include/PolyVoxCore/CubicSurfaceExtractor.h
include/PolyVoxCore/CubicSurfaceExtractor.inl
include/PolyVoxCore/DefaultIsQuadNeeded.h
include/PolyVoxCore/DefaultMarchingCubesController.h
include/PolyVoxCore/Density.h
include/PolyVoxCore/FilePager.h
include/PolyVoxCore/GradientEstimators.h
include/PolyVoxCore/GradientEstimators.inl
include/PolyVoxCore/Interpolation.h
include/PolyVoxCore/IteratorController.h
include/PolyVoxCore/IteratorController.inl
include/PolyVoxCore/LargeVolume.h
include/PolyVoxCore/LowPassFilter.h
include/PolyVoxCore/LowPassFilter.inl
include/PolyVoxCore/MarchingCubesSurfaceExtractor.h
include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
include/PolyVoxCore/Material.h
include/PolyVoxCore/MaterialDensityPair.h
include/PolyVoxCore/Mesh.h
include/PolyVoxCore/Mesh.inl
include/PolyVoxCore/PagedVolume.h
include/PolyVoxCore/PagedVolume.inl
include/PolyVoxCore/PagedVolumeChunk.inl
include/PolyVoxCore/PagedVolumeSampler.inl
include/PolyVoxCore/PolyVoxForwardDeclarations.h
include/PolyVoxCore/Picking.h
include/PolyVoxCore/Picking.inl
include/PolyVoxCore/RawVolume.h
include/PolyVoxCore/RawVolume.inl
include/PolyVoxCore/RawVolumeSampler.inl
include/PolyVoxCore/Raycast.h
include/PolyVoxCore/Raycast.inl
include/PolyVoxCore/Region.h
include/PolyVoxCore/SimpleVolume.h
include/PolyVoxCore/Vector.h
include/PolyVoxCore/Vector.inl
include/PolyVoxCore/Vertex.h
include/PolyVoxCore/VolumeResampler.h
include/PolyVoxCore/VolumeResampler.inl
include/PolyVoxCore/VoxelFilters.h
include/PolyVoxCore/VoxelFilters.inl
)
SET(IMPL_SRC_FILES
source/Impl/ErrorHandling.cpp
source/Impl/Logging.cpp
source/Impl/MarchingCubesTables.cpp
source/Impl/RandomUnitVectors.cpp
source/Impl/RandomVectors.cpp
source/Impl/Timer.cpp
source/Impl/Utility.cpp
)
SET(IMPL_INC_FILES
include/PolyVoxCore/Impl/AStarPathfinderImpl.h
include/PolyVoxCore/Impl/Config.h
include/PolyVoxCore/Impl/ErrorHandling.h
include/PolyVoxCore/Impl/Logging.h
include/PolyVoxCore/Impl/MarchingCubesTables.h
include/PolyVoxCore/Impl/RandomUnitVectors.h
include/PolyVoxCore/Impl/RandomVectors.h
include/PolyVoxCore/Impl/Timer.h
include/PolyVoxCore/Impl/TypeDef.h
include/PolyVoxCore/Impl/Utility.h
)
#NOTE: The following line should be uncommented when building shared libs.
#"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too...
SOURCE_GROUP("Source Files" FILES ${CORE_SRC_FILES})
SOURCE_GROUP("Header Files" FILES ${CORE_INC_FILES})
SOURCE_GROUP("Source Files\\Impl" FILES ${IMPL_SRC_FILES})
SOURCE_GROUP("Header Files\\Impl" FILES ${IMPL_INC_FILES})
#Tell CMake the paths
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include)
#Core
#Build
IF(LIBRARY_TYPE STREQUAL "STATIC")
ADD_LIBRARY(PolyVoxCore STATIC ${CORE_SRC_FILES} ${CORE_INC_FILES} ${IMPL_SRC_FILES} ${IMPL_INC_FILES})
IF(UNIX)
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS -fPIC)
ENDIF()
ENDIF()
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")
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS "/W4 /wd4251") #Disable warning on STL exports
ENDIF(MSVC)
#Install
IF(WIN32)
INSTALL(TARGETS PolyVoxCore
RUNTIME DESTINATION PolyVoxCore/bin COMPONENT library
LIBRARY DESTINATION PolyVoxCore/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxCore/lib COMPONENT library
)
#Install the core header files, including the ones in the Impl subfolder.
INSTALL(DIRECTORY include DESTINATION PolyVoxCore COMPONENT development PATTERN "*.svn*" EXCLUDE)
#On windows, we also install the debug information. It's unfortunate that we have to hard-code
#the 'Debug' part of the path, but CMake doesn't seem to provide a way around this. The best I
#found was: http://www.cmake.org/pipermail/cmake/2007-October/016924.html (and it is a bit ugly).
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/PolyVoxCore.pdb DESTINATION PolyVoxCore/lib CONFIGURATIONS Debug)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/PolyVoxCore.pdb DESTINATION PolyVoxCore/lib CONFIGURATIONS RelWithDebInfo)
ELSE(WIN32)
INSTALL(TARGETS PolyVoxCore
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
#Install the core header files, including the ones in the Impl subfolder.
INSTALL(DIRECTORY include/ DESTINATION include/PolyVoxCore COMPONENT development PATTERN "*.svn*" EXCLUDE)
ENDIF(WIN32)

View File

@ -1,195 +1,195 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_AStarPathfinder_H__
#define __PolyVox_AStarPathfinder_H__
#include "Impl/AStarPathfinderImpl.h"
#include "Impl/TypeDef.h"
#include <functional>
#include <list>
#include <stdexcept> //For runtime_error
namespace PolyVox
{
const float sqrt_1 = 1.0f;
const float sqrt_2 = 1.4143f;
const float sqrt_3 = 1.7321f;
extern const POLYVOX_API Vector3DInt32 arrayPathfinderFaces[6];
extern const POLYVOX_API Vector3DInt32 arrayPathfinderEdges[12];
extern const POLYVOX_API Vector3DInt32 arrayPathfinderCorners[8];
/// This function provides the default method for checking whether a given voxel
/// is valid for the path computed by the AStarPathfinder.
template<typename VolumeType>
bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos);
/// Provides a configuration for the AStarPathfinder.
////////////////////////////////////////////////////////////////////////////////
/// This structure stores the AStarPathfinder%s configuration options, because this
/// is simpler than providing a large number of get/set properties within the
/// AStarPathfinder itself. In order to create an instance of this structure you
/// must provide at least a volume, a start and end point, and a list to store
/// the result. All the other option have sensible default values which can
/// optionally be changed for more precise control over the pathfinder's behaviour.
///
/// \sa AStarPathfinder
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType>
struct AStarPathfinderParams
{
public:
AStarPathfinderParams
(
VolumeType* volData,
const Vector3DInt32& v3dStart,
const Vector3DInt32& v3dEnd,
std::list<Vector3DInt32>* listResult,
float fHBias = 1.0,
uint32_t uMaxNoOfNodes = 10000,
Connectivity requiredConnectivity = TwentySixConnected,
std::function<bool (const VolumeType*, const Vector3DInt32&)> funcIsVoxelValidForPath = &aStarDefaultVoxelValidator,
std::function<void (float)> funcProgressCallback = nullptr
)
:volume(volData)
,start(v3dStart)
,end(v3dEnd)
,result(listResult)
,connectivity(requiredConnectivity)
,hBias(fHBias)
,maxNumberOfNodes(uMaxNoOfNodes)
,isVoxelValidForPath(funcIsVoxelValidForPath)
,progressCallback(funcProgressCallback)
{
}
/// This is the volume through which the AStarPathfinder must find a path.
VolumeType* volume;
/// The start point for the pathfinding algorithm.
Vector3DInt32 start;
/// The end point for the pathfinding algorithm.
Vector3DInt32 end;
/// The resulting path will be stored as a series of points in
/// this list. Any existing contents will be cleared.
std::list<Vector3DInt32>* result;
/// The AStarPathfinder performs its search by examining the neighbours
/// of each voxel it encounters. This property controls the meaning of
/// neighbour - e.g. whether two voxels must share a face, edge, or corner.
Connectivity connectivity;
/// For each voxel the pathfinder tracks its distance to the start (known as g())
/// and estimates its distance to the end (known as h()). Increasing or decreasing
/// h() has an effect on the way the pathfinder behaves. If h() is an underestimate
/// of the true distance then the pathfinder will act more like a greedy search -
/// always finding the shortest path but taking longer to do so. If h() is an over
/// estimate then the pathfinder will behave more like a best-first search - returning
/// a potentially suboptimal path but finding it more quickly. The hBias is multiplied
/// by the estimated h() value to control this behaviour.
float hBias;
/// Volumes can be pretty huge (millions of voxels) and processing each one of these
/// can take a long time. In A* terminology each voxel is a node, and this property
/// controls the maximum number of nodes that will be considered when finding the path,
/// before giving up and throwing an exception because a path can't be found.
uint32_t maxNumberOfNodes;
/// This function is called to determine whether the path can pass though a given voxel. The
/// default behaviour is specified by aStarDefaultVoxelValidator(), but users can specify thier
/// own criteria if desired. For example, if you always want a path to follow a surface then
/// you could check to ensure that the voxel above is empty and the voxel below is solid.
///
/// \sa aStarDefaultVoxelValidator
std::function<bool (const VolumeType*, const Vector3DInt32&)> isVoxelValidForPath;
/// This function is called by the AStarPathfinder to report on its progress in getting to
/// the goal. The progress is reported by computing the distance from the closest node found
/// so far to the end node, and comparing this with the distance from the start node to the
/// end node. This progress value is guarenteed to never decrease, but it may stop increasing
///for short periods of time. It may even stop increasing altogether if a path cannot be found.
std::function<void (float)> progressCallback;
};
/// The AStarPathfinder compute a path from one point in the volume to another.
////////////////////////////////////////////////////////////////////////////////
/// A* is a well known pathfinding algorithm commonly used in computer games. It
/// takes as input a pair of points in the world, and works out a path between
/// them which avoids obstacles and adheres to other user defined criteria. The
/// resulting path is usually the shortest possible, but a less optimal path can
/// be exchanged for reduced computation time.
///
/// For an excellent overview of the A* algorithm please see Amit Patel's Game
/// Programming page here: http://theory.stanford.edu/~amitp/GameProgramming/
/// Much of this class is based on the principles described in those pages.
///
/// Usage of this class if very strightforward. You create an instance of it
/// by passing an instance of the AStarPathfinderParams structure to the constructor.
/// The details of the AStarPathfinderParams and the options it provides are described
/// in the documentation for that class.
///
/// Next you call the execute() function and wait for it to return. If a path is
/// found then this is stored in the list which was set as the 'result' field of
/// the AStarPathfinderParams. If a path cannot be found then an exception of type
/// std::runtime_error is thrown.
///
/// \sa AStarPathfinderParams
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType>
class AStarPathfinder
{
public:
AStarPathfinder(const AStarPathfinderParams<VolumeType>& params);
void execute();
private:
void processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal);
float SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b);
float EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b);
float TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b);
float computeH(const Vector3DInt32& a, const Vector3DInt32& b);
uint32_t hash(uint32_t a);
//Node containers
AllNodesContainer allNodes;
OpenNodesContainer openNodes;
ClosedNodesContainer closedNodes;
//The current node
AllNodesContainer::iterator current;
float m_fProgress;
AStarPathfinderParams<VolumeType> m_params;
};
}
#include "PolyVoxCore/AStarPathfinder.inl"
#endif //__PolyVox_AStarPathfinder_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_AStarPathfinder_H__
#define __PolyVox_AStarPathfinder_H__
#include "Impl/AStarPathfinderImpl.h"
#include "Impl/TypeDef.h"
#include <functional>
#include <list>
#include <stdexcept> //For runtime_error
namespace PolyVox
{
const float sqrt_1 = 1.0f;
const float sqrt_2 = 1.4143f;
const float sqrt_3 = 1.7321f;
extern const POLYVOX_API Vector3DInt32 arrayPathfinderFaces[6];
extern const POLYVOX_API Vector3DInt32 arrayPathfinderEdges[12];
extern const POLYVOX_API Vector3DInt32 arrayPathfinderCorners[8];
/// This function provides the default method for checking whether a given voxel
/// is valid for the path computed by the AStarPathfinder.
template<typename VolumeType>
bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos);
/// Provides a configuration for the AStarPathfinder.
////////////////////////////////////////////////////////////////////////////////
/// This structure stores the AStarPathfinder%s configuration options, because this
/// is simpler than providing a large number of get/set properties within the
/// AStarPathfinder itself. In order to create an instance of this structure you
/// must provide at least a volume, a start and end point, and a list to store
/// the result. All the other option have sensible default values which can
/// optionally be changed for more precise control over the pathfinder's behaviour.
///
/// \sa AStarPathfinder
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType>
struct AStarPathfinderParams
{
public:
AStarPathfinderParams
(
VolumeType* volData,
const Vector3DInt32& v3dStart,
const Vector3DInt32& v3dEnd,
std::list<Vector3DInt32>* listResult,
float fHBias = 1.0,
uint32_t uMaxNoOfNodes = 10000,
Connectivity requiredConnectivity = TwentySixConnected,
std::function<bool (const VolumeType*, const Vector3DInt32&)> funcIsVoxelValidForPath = &aStarDefaultVoxelValidator,
std::function<void (float)> funcProgressCallback = nullptr
)
:volume(volData)
,start(v3dStart)
,end(v3dEnd)
,result(listResult)
,connectivity(requiredConnectivity)
,hBias(fHBias)
,maxNumberOfNodes(uMaxNoOfNodes)
,isVoxelValidForPath(funcIsVoxelValidForPath)
,progressCallback(funcProgressCallback)
{
}
/// This is the volume through which the AStarPathfinder must find a path.
VolumeType* volume;
/// The start point for the pathfinding algorithm.
Vector3DInt32 start;
/// The end point for the pathfinding algorithm.
Vector3DInt32 end;
/// The resulting path will be stored as a series of points in
/// this list. Any existing contents will be cleared.
std::list<Vector3DInt32>* result;
/// The AStarPathfinder performs its search by examining the neighbours
/// of each voxel it encounters. This property controls the meaning of
/// neighbour - e.g. whether two voxels must share a face, edge, or corner.
Connectivity connectivity;
/// For each voxel the pathfinder tracks its distance to the start (known as g())
/// and estimates its distance to the end (known as h()). Increasing or decreasing
/// h() has an effect on the way the pathfinder behaves. If h() is an underestimate
/// of the true distance then the pathfinder will act more like a greedy search -
/// always finding the shortest path but taking longer to do so. If h() is an over
/// estimate then the pathfinder will behave more like a best-first search - returning
/// a potentially suboptimal path but finding it more quickly. The hBias is multiplied
/// by the estimated h() value to control this behaviour.
float hBias;
/// Volumes can be pretty huge (millions of voxels) and processing each one of these
/// can take a long time. In A* terminology each voxel is a node, and this property
/// controls the maximum number of nodes that will be considered when finding the path,
/// before giving up and throwing an exception because a path can't be found.
uint32_t maxNumberOfNodes;
/// This function is called to determine whether the path can pass though a given voxel. The
/// default behaviour is specified by aStarDefaultVoxelValidator(), but users can specify thier
/// own criteria if desired. For example, if you always want a path to follow a surface then
/// you could check to ensure that the voxel above is empty and the voxel below is solid.
///
/// \sa aStarDefaultVoxelValidator
std::function<bool (const VolumeType*, const Vector3DInt32&)> isVoxelValidForPath;
/// This function is called by the AStarPathfinder to report on its progress in getting to
/// the goal. The progress is reported by computing the distance from the closest node found
/// so far to the end node, and comparing this with the distance from the start node to the
/// end node. This progress value is guarenteed to never decrease, but it may stop increasing
///for short periods of time. It may even stop increasing altogether if a path cannot be found.
std::function<void (float)> progressCallback;
};
/// The AStarPathfinder compute a path from one point in the volume to another.
////////////////////////////////////////////////////////////////////////////////
/// A* is a well known pathfinding algorithm commonly used in computer games. It
/// takes as input a pair of points in the world, and works out a path between
/// them which avoids obstacles and adheres to other user defined criteria. The
/// resulting path is usually the shortest possible, but a less optimal path can
/// be exchanged for reduced computation time.
///
/// For an excellent overview of the A* algorithm please see Amit Patel's Game
/// Programming page here: http://theory.stanford.edu/~amitp/GameProgramming/
/// Much of this class is based on the principles described in those pages.
///
/// Usage of this class if very strightforward. You create an instance of it
/// by passing an instance of the AStarPathfinderParams structure to the constructor.
/// The details of the AStarPathfinderParams and the options it provides are described
/// in the documentation for that class.
///
/// Next you call the execute() function and wait for it to return. If a path is
/// found then this is stored in the list which was set as the 'result' field of
/// the AStarPathfinderParams. If a path cannot be found then an exception of type
/// std::runtime_error is thrown.
///
/// \sa AStarPathfinderParams
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType>
class AStarPathfinder
{
public:
AStarPathfinder(const AStarPathfinderParams<VolumeType>& params);
void execute();
private:
void processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal);
float SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b);
float EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b);
float TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b);
float computeH(const Vector3DInt32& a, const Vector3DInt32& b);
uint32_t hash(uint32_t a);
//Node containers
AllNodesContainer allNodes;
OpenNodesContainer openNodes;
ClosedNodesContainer closedNodes;
//The current node
AllNodesContainer::iterator current;
float m_fProgress;
AStarPathfinderParams<VolumeType> m_params;
};
}
#include "PolyVoxCore/AStarPathfinder.inl"
#endif //__PolyVox_AStarPathfinder_H__

View File

@ -1,351 +1,351 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Impl/ErrorHandling.h"
namespace PolyVox
{
////////////////////////////////////////////////////////////////////////////////
/// Using this function, a voxel is considered valid for the path if it is inside the
/// volume and if its density is below that returned by the voxel's getDensity() function.
/// \return true is the voxel is valid for the path
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType>
bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos)
{
//Voxels are considered valid candidates for the path if they are inside the volume...
if(volData->getEnclosingRegion().containsPoint(v3dPos) == false)
{
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
// AStarPathfinder Class
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType>
AStarPathfinder<VolumeType>::AStarPathfinder(const AStarPathfinderParams<VolumeType>& params)
:m_params(params)
{
}
template<typename VolumeType>
void AStarPathfinder<VolumeType>::execute()
{
//Clear any existing nodes
allNodes.clear();
openNodes.clear();
closedNodes.clear();
//Clear the result
m_params.result->clear();
//Iterators to start and end node.
AllNodesContainer::iterator startNode = allNodes.insert(Node(m_params.start.getX(), m_params.start.getY(), m_params.start.getZ())).first;
AllNodesContainer::iterator endNode = allNodes.insert(Node(m_params.end.getX(), m_params.end.getY(), m_params.end.getZ())).first;
//Regarding the const_cast - normally you should not modify an object which is in an sdt::set.
//The reason is that objects in a set are stored sorted in a tree so they can be accessed quickly,
//and changing the object directly can break the sorting. However, in our case we have provided a
//custom sort operator for the set which we know only uses the position to sort. Hence we can safely
//modify other properties of the object while it is in the set.
Node* tempStart = const_cast<Node*>(&(*startNode));
tempStart->gVal = 0;
tempStart->hVal = computeH(startNode->position, endNode->position);
Node* tempEnd = const_cast<Node*>(&(*endNode));
tempEnd->hVal = 0.0f;
openNodes.insert(startNode);
float fDistStartToEnd = (endNode->position - startNode->position).length();
m_fProgress = 0.0f;
if(m_params.progressCallback)
{
m_params.progressCallback(m_fProgress);
}
while((openNodes.empty() == false) && (openNodes.getFirst() != endNode))
{
//Move the first node from open to closed.
current = openNodes.getFirst();
openNodes.removeFirst();
closedNodes.insert(current);
//Update the user on our progress
if(m_params.progressCallback)
{
const float fMinProgresIncreament = 0.001f;
float fDistCurrentToEnd = (endNode->position - current->position).length();
float fDistNormalised = fDistCurrentToEnd / fDistStartToEnd;
float fProgress = 1.0f - fDistNormalised;
if(fProgress >= m_fProgress + fMinProgresIncreament)
{
m_fProgress = fProgress;
m_params.progressCallback(m_fProgress);
}
}
//The distance from one cell to another connected by face, edge, or corner.
const float fFaceCost = sqrt_1;
const float fEdgeCost = sqrt_2;
const float fCornerCost = sqrt_3;
//Process the neighbours. Note the deliberate lack of 'break'
//statements, larger connectivities include smaller ones.
switch(m_params.connectivity)
{
case TwentySixConnected:
processNeighbour(current->position + arrayPathfinderCorners[0], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[1], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[2], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[3], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[4], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[5], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[6], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[7], current->gVal + fCornerCost);
case EighteenConnected:
processNeighbour(current->position + arrayPathfinderEdges[ 0], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 1], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 2], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 3], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 4], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 5], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 6], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 7], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 8], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 9], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[10], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[11], current->gVal + fEdgeCost);
case SixConnected:
processNeighbour(current->position + arrayPathfinderFaces[0], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[1], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[2], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[3], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[4], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[5], current->gVal + fFaceCost);
}
if(allNodes.size() > m_params.maxNumberOfNodes)
{
//We've reached the specified maximum number
//of nodes. Just give up on the search.
break;
}
}
if((openNodes.empty()) || (openNodes.getFirst() != endNode))
{
//In this case we failed to find a valid path.
POLYVOX_THROW(std::runtime_error, "No path found");
}
else
{
//Regarding the const_cast - normally you should not modify an object which is in an sdt::set.
//The reason is that objects in a set are stored sorted in a tree so they can be accessed quickly,
//and changing the object directly can break the sorting. However, in our case we have provided a
//custom sort operator for the set which we know only uses the position to sort. Hence we can safely
//modify other properties of the object while it is in the set.
Node* n = const_cast<Node*>(&(*endNode));
while(n != 0)
{
m_params.result->push_front(n->position);
n = n->parent;
}
}
if(m_params.progressCallback)
{
m_params.progressCallback(1.0f);
}
}
template<typename VolumeType>
void AStarPathfinder<VolumeType>::processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal)
{
bool bIsVoxelValidForPath = m_params.isVoxelValidForPath(m_params.volume, neighbourPos);
if(!bIsVoxelValidForPath)
{
return;
}
float cost = neighbourGVal;
std::pair<AllNodesContainer::iterator, bool> insertResult = allNodes.insert(Node(neighbourPos.getX(), neighbourPos.getY(), neighbourPos.getZ()));
AllNodesContainer::iterator neighbour = insertResult.first;
if(insertResult.second == true) //New node, compute h.
{
Node* tempNeighbour = const_cast<Node*>(&(*neighbour));
tempNeighbour -> hVal = computeH(neighbour->position, m_params.end);
}
OpenNodesContainer::iterator openIter = openNodes.find(neighbour);
if(openIter != openNodes.end())
{
if(cost < neighbour->gVal)
{
openNodes.remove(openIter);
openIter = openNodes.end();
}
}
//TODO - Nodes could keep track of if they are in open or closed? And a pointer to where they are?
ClosedNodesContainer::iterator closedIter = closedNodes.find(neighbour);
if(closedIter != closedNodes.end())
{
if(cost < neighbour->gVal)
{
//Probably shouldn't happen?
closedNodes.remove(closedIter);
closedIter = closedNodes.end();
}
}
if((openIter == openNodes.end()) && (closedIter == closedNodes.end()))
{
//Regarding the const_cast - normally you should not modify an object which is in an sdt::set.
//The reason is that objects in a set are stored sorted in a tree so they can be accessed quickly,
//and changing the object directly can break the sorting. However, in our case we have provided a
//custom sort operator for the set which we know only uses the position to sort. Hence we can safely
//modify other properties of the object while it is in the set.
Node* temp = const_cast<Node*>(&(*neighbour));
temp->gVal = cost;
openNodes.insert(neighbour);
temp->parent = const_cast<Node*>(&(*current));
}
}
template<typename VolumeType>
float AStarPathfinder<VolumeType>::SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
{
//This is the only heuristic I'm sure of - just use the manhatten distance for the 6-connected case.
uint32_t faceSteps = std::abs(a.getX()-b.getX()) + std::abs(a.getY()-b.getY()) + std::abs(a.getZ()-b.getZ());
return faceSteps * 1.0f;
}
template<typename VolumeType>
float AStarPathfinder<VolumeType>::EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
{
//I'm not sure of the correct heuristic for the 18-connected case, so I'm just letting it fall through to the
//6-connected case. This means 'h' will be bigger than it should be, resulting in a faster path which may not
//actually be the shortest one. If you have a correct heuristic for the 18-connected case then please let me know.
return SixConnectedCost(a,b);
}
template<typename VolumeType>
float AStarPathfinder<VolumeType>::TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
{
//Can't say I'm certain about this heuristic - if anyone has
//a better idea of what it should be then please let me know.
uint32_t array[3];
array[0] = std::abs(a.getX() - b.getX());
array[1] = std::abs(a.getY() - b.getY());
array[2] = std::abs(a.getZ() - b.getZ());
//Maybe this is better implemented directly
//using three compares and two swaps... but not
//until the profiler says so.
std::sort(&array[0], &array[3]);
uint32_t cornerSteps = array[0];
uint32_t edgeSteps = array[1] - array[0];
uint32_t faceSteps = array[2] - array[1];
return cornerSteps * sqrt_3 + edgeSteps * sqrt_2 + faceSteps * sqrt_1;
}
template<typename VolumeType>
float AStarPathfinder<VolumeType>::computeH(const Vector3DInt32& a, const Vector3DInt32& b)
{
float hVal;
switch(m_params.connectivity)
{
case TwentySixConnected:
hVal = TwentySixConnectedCost(a, b);
break;
case EighteenConnected:
hVal = EighteenConnectedCost(a, b);
break;
case SixConnected:
hVal = SixConnectedCost(a, b);
break;
default:
POLYVOX_THROW(std::invalid_argument, "Connectivity parameter has an unrecognised value.");
}
//Sanity checks in debug mode. These can come out eventually, but I
//want to make sure that the heuristics I've come up with make sense.
POLYVOX_ASSERT((a-b).length() <= TwentySixConnectedCost(a,b), "A* heuristic error.");
POLYVOX_ASSERT(TwentySixConnectedCost(a,b) <= EighteenConnectedCost(a,b), "A* heuristic error.");
POLYVOX_ASSERT(EighteenConnectedCost(a,b) <= SixConnectedCost(a,b), "A* heuristic error.");
//Apply the bias to the computed h value;
hVal *= m_params.hBias;
//Having computed hVal, we now apply some random bias to break ties.
//This needs to be deterministic on the input position. This random
//bias means it is much les likely that two paths are exactly the same
//length, and so far fewer nodes must be expanded to find the shortest path.
//See http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#S12
//Note that if the hash is zero we can have differences between the Linux vs. Windows
//(or perhaps GCC vs. VS) versions of the code. This is probably because of the way
//sorting inside the std::set works (i.e. one system swaps values which are identical
//while the other one doesn't - both approaches are valid). For the same reason we want
//to make sure that position (x,y,z) has a differnt hash from e.g. position (x,z,y).
uint32_t aX = (a.getX() << 16) & 0x00FF0000;
uint32_t aY = (a.getY() << 8) & 0x0000FF00;
uint32_t aZ = (a.getZ() ) & 0x000000FF;
uint32_t hashVal = hash(aX | aY | aZ);
//Stop hashVal going over 65535, and divide by 1000000 to make sure it is small.
hashVal &= 0x0000FFFF;
float fHash = hashVal / 1000000.0f;
//Apply the hash and return
hVal += fHash;
return hVal;
}
// Robert Jenkins' 32 bit integer hash function
// http://www.burtleburtle.net/bob/hash/integer.html
template<typename VolumeType>
uint32_t AStarPathfinder<VolumeType>::hash( uint32_t a)
{
a = (a+0x7ed55d16) + (a<<12);
a = (a^0xc761c23c) ^ (a>>19);
a = (a+0x165667b1) + (a<<5);
a = (a+0xd3a2646c) ^ (a<<9);
a = (a+0xfd7046c5) + (a<<3);
a = (a^0xb55a4f09) ^ (a>>16);
return a;
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Impl/ErrorHandling.h"
namespace PolyVox
{
////////////////////////////////////////////////////////////////////////////////
/// Using this function, a voxel is considered valid for the path if it is inside the
/// volume and if its density is below that returned by the voxel's getDensity() function.
/// \return true is the voxel is valid for the path
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType>
bool aStarDefaultVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos)
{
//Voxels are considered valid candidates for the path if they are inside the volume...
if(volData->getEnclosingRegion().containsPoint(v3dPos) == false)
{
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
// AStarPathfinder Class
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType>
AStarPathfinder<VolumeType>::AStarPathfinder(const AStarPathfinderParams<VolumeType>& params)
:m_params(params)
{
}
template<typename VolumeType>
void AStarPathfinder<VolumeType>::execute()
{
//Clear any existing nodes
allNodes.clear();
openNodes.clear();
closedNodes.clear();
//Clear the result
m_params.result->clear();
//Iterators to start and end node.
AllNodesContainer::iterator startNode = allNodes.insert(Node(m_params.start.getX(), m_params.start.getY(), m_params.start.getZ())).first;
AllNodesContainer::iterator endNode = allNodes.insert(Node(m_params.end.getX(), m_params.end.getY(), m_params.end.getZ())).first;
//Regarding the const_cast - normally you should not modify an object which is in an sdt::set.
//The reason is that objects in a set are stored sorted in a tree so they can be accessed quickly,
//and changing the object directly can break the sorting. However, in our case we have provided a
//custom sort operator for the set which we know only uses the position to sort. Hence we can safely
//modify other properties of the object while it is in the set.
Node* tempStart = const_cast<Node*>(&(*startNode));
tempStart->gVal = 0;
tempStart->hVal = computeH(startNode->position, endNode->position);
Node* tempEnd = const_cast<Node*>(&(*endNode));
tempEnd->hVal = 0.0f;
openNodes.insert(startNode);
float fDistStartToEnd = (endNode->position - startNode->position).length();
m_fProgress = 0.0f;
if(m_params.progressCallback)
{
m_params.progressCallback(m_fProgress);
}
while((openNodes.empty() == false) && (openNodes.getFirst() != endNode))
{
//Move the first node from open to closed.
current = openNodes.getFirst();
openNodes.removeFirst();
closedNodes.insert(current);
//Update the user on our progress
if(m_params.progressCallback)
{
const float fMinProgresIncreament = 0.001f;
float fDistCurrentToEnd = (endNode->position - current->position).length();
float fDistNormalised = fDistCurrentToEnd / fDistStartToEnd;
float fProgress = 1.0f - fDistNormalised;
if(fProgress >= m_fProgress + fMinProgresIncreament)
{
m_fProgress = fProgress;
m_params.progressCallback(m_fProgress);
}
}
//The distance from one cell to another connected by face, edge, or corner.
const float fFaceCost = sqrt_1;
const float fEdgeCost = sqrt_2;
const float fCornerCost = sqrt_3;
//Process the neighbours. Note the deliberate lack of 'break'
//statements, larger connectivities include smaller ones.
switch(m_params.connectivity)
{
case TwentySixConnected:
processNeighbour(current->position + arrayPathfinderCorners[0], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[1], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[2], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[3], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[4], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[5], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[6], current->gVal + fCornerCost);
processNeighbour(current->position + arrayPathfinderCorners[7], current->gVal + fCornerCost);
case EighteenConnected:
processNeighbour(current->position + arrayPathfinderEdges[ 0], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 1], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 2], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 3], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 4], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 5], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 6], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 7], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 8], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[ 9], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[10], current->gVal + fEdgeCost);
processNeighbour(current->position + arrayPathfinderEdges[11], current->gVal + fEdgeCost);
case SixConnected:
processNeighbour(current->position + arrayPathfinderFaces[0], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[1], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[2], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[3], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[4], current->gVal + fFaceCost);
processNeighbour(current->position + arrayPathfinderFaces[5], current->gVal + fFaceCost);
}
if(allNodes.size() > m_params.maxNumberOfNodes)
{
//We've reached the specified maximum number
//of nodes. Just give up on the search.
break;
}
}
if((openNodes.empty()) || (openNodes.getFirst() != endNode))
{
//In this case we failed to find a valid path.
POLYVOX_THROW(std::runtime_error, "No path found");
}
else
{
//Regarding the const_cast - normally you should not modify an object which is in an sdt::set.
//The reason is that objects in a set are stored sorted in a tree so they can be accessed quickly,
//and changing the object directly can break the sorting. However, in our case we have provided a
//custom sort operator for the set which we know only uses the position to sort. Hence we can safely
//modify other properties of the object while it is in the set.
Node* n = const_cast<Node*>(&(*endNode));
while(n != 0)
{
m_params.result->push_front(n->position);
n = n->parent;
}
}
if(m_params.progressCallback)
{
m_params.progressCallback(1.0f);
}
}
template<typename VolumeType>
void AStarPathfinder<VolumeType>::processNeighbour(const Vector3DInt32& neighbourPos, float neighbourGVal)
{
bool bIsVoxelValidForPath = m_params.isVoxelValidForPath(m_params.volume, neighbourPos);
if(!bIsVoxelValidForPath)
{
return;
}
float cost = neighbourGVal;
std::pair<AllNodesContainer::iterator, bool> insertResult = allNodes.insert(Node(neighbourPos.getX(), neighbourPos.getY(), neighbourPos.getZ()));
AllNodesContainer::iterator neighbour = insertResult.first;
if(insertResult.second == true) //New node, compute h.
{
Node* tempNeighbour = const_cast<Node*>(&(*neighbour));
tempNeighbour -> hVal = computeH(neighbour->position, m_params.end);
}
OpenNodesContainer::iterator openIter = openNodes.find(neighbour);
if(openIter != openNodes.end())
{
if(cost < neighbour->gVal)
{
openNodes.remove(openIter);
openIter = openNodes.end();
}
}
//TODO - Nodes could keep track of if they are in open or closed? And a pointer to where they are?
ClosedNodesContainer::iterator closedIter = closedNodes.find(neighbour);
if(closedIter != closedNodes.end())
{
if(cost < neighbour->gVal)
{
//Probably shouldn't happen?
closedNodes.remove(closedIter);
closedIter = closedNodes.end();
}
}
if((openIter == openNodes.end()) && (closedIter == closedNodes.end()))
{
//Regarding the const_cast - normally you should not modify an object which is in an sdt::set.
//The reason is that objects in a set are stored sorted in a tree so they can be accessed quickly,
//and changing the object directly can break the sorting. However, in our case we have provided a
//custom sort operator for the set which we know only uses the position to sort. Hence we can safely
//modify other properties of the object while it is in the set.
Node* temp = const_cast<Node*>(&(*neighbour));
temp->gVal = cost;
openNodes.insert(neighbour);
temp->parent = const_cast<Node*>(&(*current));
}
}
template<typename VolumeType>
float AStarPathfinder<VolumeType>::SixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
{
//This is the only heuristic I'm sure of - just use the manhatten distance for the 6-connected case.
uint32_t faceSteps = std::abs(a.getX()-b.getX()) + std::abs(a.getY()-b.getY()) + std::abs(a.getZ()-b.getZ());
return faceSteps * 1.0f;
}
template<typename VolumeType>
float AStarPathfinder<VolumeType>::EighteenConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
{
//I'm not sure of the correct heuristic for the 18-connected case, so I'm just letting it fall through to the
//6-connected case. This means 'h' will be bigger than it should be, resulting in a faster path which may not
//actually be the shortest one. If you have a correct heuristic for the 18-connected case then please let me know.
return SixConnectedCost(a,b);
}
template<typename VolumeType>
float AStarPathfinder<VolumeType>::TwentySixConnectedCost(const Vector3DInt32& a, const Vector3DInt32& b)
{
//Can't say I'm certain about this heuristic - if anyone has
//a better idea of what it should be then please let me know.
uint32_t array[3];
array[0] = std::abs(a.getX() - b.getX());
array[1] = std::abs(a.getY() - b.getY());
array[2] = std::abs(a.getZ() - b.getZ());
//Maybe this is better implemented directly
//using three compares and two swaps... but not
//until the profiler says so.
std::sort(&array[0], &array[3]);
uint32_t cornerSteps = array[0];
uint32_t edgeSteps = array[1] - array[0];
uint32_t faceSteps = array[2] - array[1];
return cornerSteps * sqrt_3 + edgeSteps * sqrt_2 + faceSteps * sqrt_1;
}
template<typename VolumeType>
float AStarPathfinder<VolumeType>::computeH(const Vector3DInt32& a, const Vector3DInt32& b)
{
float hVal;
switch(m_params.connectivity)
{
case TwentySixConnected:
hVal = TwentySixConnectedCost(a, b);
break;
case EighteenConnected:
hVal = EighteenConnectedCost(a, b);
break;
case SixConnected:
hVal = SixConnectedCost(a, b);
break;
default:
POLYVOX_THROW(std::invalid_argument, "Connectivity parameter has an unrecognised value.");
}
//Sanity checks in debug mode. These can come out eventually, but I
//want to make sure that the heuristics I've come up with make sense.
POLYVOX_ASSERT((a-b).length() <= TwentySixConnectedCost(a,b), "A* heuristic error.");
POLYVOX_ASSERT(TwentySixConnectedCost(a,b) <= EighteenConnectedCost(a,b), "A* heuristic error.");
POLYVOX_ASSERT(EighteenConnectedCost(a,b) <= SixConnectedCost(a,b), "A* heuristic error.");
//Apply the bias to the computed h value;
hVal *= m_params.hBias;
//Having computed hVal, we now apply some random bias to break ties.
//This needs to be deterministic on the input position. This random
//bias means it is much les likely that two paths are exactly the same
//length, and so far fewer nodes must be expanded to find the shortest path.
//See http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#S12
//Note that if the hash is zero we can have differences between the Linux vs. Windows
//(or perhaps GCC vs. VS) versions of the code. This is probably because of the way
//sorting inside the std::set works (i.e. one system swaps values which are identical
//while the other one doesn't - both approaches are valid). For the same reason we want
//to make sure that position (x,y,z) has a differnt hash from e.g. position (x,z,y).
uint32_t aX = (a.getX() << 16) & 0x00FF0000;
uint32_t aY = (a.getY() << 8) & 0x0000FF00;
uint32_t aZ = (a.getZ() ) & 0x000000FF;
uint32_t hashVal = hash(aX | aY | aZ);
//Stop hashVal going over 65535, and divide by 1000000 to make sure it is small.
hashVal &= 0x0000FFFF;
float fHash = hashVal / 1000000.0f;
//Apply the hash and return
hVal += fHash;
return hVal;
}
// Robert Jenkins' 32 bit integer hash function
// http://www.burtleburtle.net/bob/hash/integer.html
template<typename VolumeType>
uint32_t AStarPathfinder<VolumeType>::hash( uint32_t a)
{
a = (a+0x7ed55d16) + (a<<12);
a = (a^0xc761c23c) ^ (a>>19);
a = (a+0x165667b1) + (a<<5);
a = (a+0xd3a2646c) ^ (a<<9);
a = (a+0xfd7046c5) + (a<<3);
a = (a^0xb55a4f09) ^ (a>>16);
return a;
}
}

View File

@ -1,82 +1,82 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __AmbientOcclusionCalculator_H__
#define __AmbientOcclusionCalculator_H__
#include "Impl/RandomUnitVectors.h"
#include "Impl/RandomVectors.h"
#include "PolyVoxCore/Array.h"
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Raycast.h"
//These two should not be here!
#include "PolyVoxCore/Material.h"
#include "PolyVoxCore/PagedVolume.h"
#include <algorithm>
namespace PolyVox
{
/**
* \file
*
* Ambient occlusion
*/
template<typename IsVoxelTransparentCallback>
class AmbientOcclusionCalculatorRaycastCallback
{
public:
AmbientOcclusionCalculatorRaycastCallback(IsVoxelTransparentCallback isVoxelTransparentCallback) : mIsVoxelTransparentCallback(isVoxelTransparentCallback)
{
}
bool operator()(const PagedVolume<uint8_t>::Sampler& sampler)
{
uint8_t sample = sampler.getVoxel();
bool func = mIsVoxelTransparentCallback(sample);
return func;
}
IsVoxelTransparentCallback mIsVoxelTransparentCallback;
};
// NOTE: The callback needs to be a functor not a function. I haven't been
// able to work the required template magic to get functions working as well.
//
// Matt: If you make the function take a "IsVoxelTransparentCallback&&" then
// it will forward it on. Works for functors, functions and lambdas.
// This will be 'perfect forwarding' using 'universal references'
// This will require C++11 rvalue references which is why I haven't made the
// change yet.
/// Calculate the ambient occlusion for the volume
template<typename VolumeType, typename IsVoxelTransparentCallback>
void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback);
}
#include "PolyVoxCore/AmbientOcclusionCalculator.inl"
#endif //__AmbientOcclusionCalculator_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __AmbientOcclusionCalculator_H__
#define __AmbientOcclusionCalculator_H__
#include "Impl/RandomUnitVectors.h"
#include "Impl/RandomVectors.h"
#include "PolyVoxCore/Array.h"
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Raycast.h"
//These two should not be here!
#include "PolyVoxCore/Material.h"
#include "PolyVoxCore/PagedVolume.h"
#include <algorithm>
namespace PolyVox
{
/**
* \file
*
* Ambient occlusion
*/
template<typename IsVoxelTransparentCallback>
class AmbientOcclusionCalculatorRaycastCallback
{
public:
AmbientOcclusionCalculatorRaycastCallback(IsVoxelTransparentCallback isVoxelTransparentCallback) : mIsVoxelTransparentCallback(isVoxelTransparentCallback)
{
}
bool operator()(const PagedVolume<uint8_t>::Sampler& sampler)
{
uint8_t sample = sampler.getVoxel();
bool func = mIsVoxelTransparentCallback(sample);
return func;
}
IsVoxelTransparentCallback mIsVoxelTransparentCallback;
};
// NOTE: The callback needs to be a functor not a function. I haven't been
// able to work the required template magic to get functions working as well.
//
// Matt: If you make the function take a "IsVoxelTransparentCallback&&" then
// it will forward it on. Works for functors, functions and lambdas.
// This will be 'perfect forwarding' using 'universal references'
// This will require C++11 rvalue references which is why I haven't made the
// change yet.
/// Calculate the ambient occlusion for the volume
template<typename VolumeType, typename IsVoxelTransparentCallback>
void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback);
}
#include "PolyVoxCore/AmbientOcclusionCalculator.inl"
#endif //__AmbientOcclusionCalculator_H__

View File

@ -1,136 +1,136 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
/**
* \param volInput The volume to calculate the ambient occlusion for
* \param[out] arrayResult The output of the calculator
* \param region The region of the volume for which the occlusion should be calculated
* \param fRayLength The length for each test ray
* \param uNoOfSamplesPerOutputElement The number of samples to calculate the occlusion
* \param isVoxelTransparentCallback A callback which takes a \a VoxelType and returns a \a bool whether the voxel is transparent
*/
template<typename VolumeType, typename IsVoxelTransparentCallback>
void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback)
{
//Make sure that the size of the volume is an exact multiple of the size of the array.
if(volInput->getWidth() % arrayResult->getDimension(0) != 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume width must be an exact multiple of array width.");
}
if(volInput->getHeight() % arrayResult->getDimension(1) != 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume width must be an exact multiple of array height.");
}
if(volInput->getDepth() % arrayResult->getDimension(2) != 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume width must be an exact multiple of array depth.");
}
uint16_t uRandomUnitVectorIndex = 0;
uint16_t uRandomVectorIndex = 0;
uint16_t uIndexIncreament;
//Our initial indices. It doesn't matter exactly what we set here, but the code below makes
//sure they are different for different regions which helps reduce tiling patterns in the results.
uRandomUnitVectorIndex += region.getLowerX() + region.getLowerY() + region.getLowerZ();
uRandomVectorIndex += region.getLowerX() + region.getLowerY() + region.getLowerZ();
//This value helps us jump around in the array a bit more, so the
//nth 'random' value isn't always followed by the n+1th 'random' value.
uIndexIncreament = 1;
const int iRatioX = volInput->getWidth() / arrayResult->getDimension(0);
const int iRatioY = volInput->getHeight() / arrayResult->getDimension(1);
const int iRatioZ = volInput->getDepth() / arrayResult->getDimension(2);
const float fRatioX = iRatioX;
const float fRatioY = iRatioY;
const float fRatioZ = iRatioZ;
const Vector3DFloat v3dRatio(fRatioX, fRatioY, fRatioZ);
const float fHalfRatioX = fRatioX * 0.5f;
const float fHalfRatioY = fRatioY * 0.5f;
const float fHalfRatioZ = fRatioZ * 0.5f;
const Vector3DFloat v3dHalfRatio(fHalfRatioX, fHalfRatioY, fHalfRatioZ);
const Vector3DFloat v3dOffset(0.5f,0.5f,0.5f);
//This loop iterates over the bottom-lower-left voxel in each of the cells in the output array
for(uint16_t z = region.getLowerZ(); z <= region.getUpperZ(); z += iRatioZ)
{
for(uint16_t y = region.getLowerY(); y <= region.getUpperY(); y += iRatioY)
{
for(uint16_t x = region.getLowerX(); x <= region.getUpperX(); x += iRatioX)
{
//Compute a start position corresponding to
//the centre of the cell in the output array.
Vector3DFloat v3dStart(x, y, z);
v3dStart -= v3dOffset;
v3dStart += v3dHalfRatio;
//Keep track of how many rays did not hit anything
uint8_t uVisibleDirections = 0;
for(int ct = 0; ct < uNoOfSamplesPerOutputElement; ct++)
{
//We take a random vector with components going from -1 to 1 and scale it to go from -halfRatio to +halfRatio.
//This jitter value moves our sample point from the centre of the array cell to somewhere else in the array cell
Vector3DFloat v3dJitter = randomVectors[(uRandomVectorIndex += (++uIndexIncreament)) % 1019]; //Prime number helps avoid repetition on successive loops.
v3dJitter *= v3dHalfRatio;
const Vector3DFloat v3dRayStart = v3dStart + v3dJitter;
Vector3DFloat v3dRayDirection = randomUnitVectors[(uRandomUnitVectorIndex += (++uIndexIncreament)) % 1021]; //Different prime number.
v3dRayDirection *= fRayLength;
AmbientOcclusionCalculatorRaycastCallback<IsVoxelTransparentCallback> ambientOcclusionCalculatorRaycastCallback(isVoxelTransparentCallback);
RaycastResult result = raycastWithDirection(volInput, v3dRayStart, v3dRayDirection, ambientOcclusionCalculatorRaycastCallback);
// Note - The performance of this could actually be improved it we exited as soon
// as the ray left the volume. The raycast test has an example of how to do this.
if(result == RaycastResults::Completed)
{
++uVisibleDirections;
}
}
float fVisibility;
if(uNoOfSamplesPerOutputElement == 0)
{
//The user might request zero samples (I've done this in the past while debugging - I don't want to
//wait for ambient occlusion but I do want as valid result for rendering). Avoid the divide by zero.
fVisibility = 1.0f;
}
else
{
fVisibility = static_cast<float>(uVisibleDirections) / static_cast<float>(uNoOfSamplesPerOutputElement);
POLYVOX_ASSERT((fVisibility >= 0.0f) && (fVisibility <= 1.0f), "Visibility value out of range.");
}
(*arrayResult)(z / iRatioZ, y / iRatioY, x / iRatioX) = static_cast<uint8_t>(255.0f * fVisibility);
}
}
}
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
/**
* \param volInput The volume to calculate the ambient occlusion for
* \param[out] arrayResult The output of the calculator
* \param region The region of the volume for which the occlusion should be calculated
* \param fRayLength The length for each test ray
* \param uNoOfSamplesPerOutputElement The number of samples to calculate the occlusion
* \param isVoxelTransparentCallback A callback which takes a \a VoxelType and returns a \a bool whether the voxel is transparent
*/
template<typename VolumeType, typename IsVoxelTransparentCallback>
void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback)
{
//Make sure that the size of the volume is an exact multiple of the size of the array.
if(volInput->getWidth() % arrayResult->getDimension(0) != 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume width must be an exact multiple of array width.");
}
if(volInput->getHeight() % arrayResult->getDimension(1) != 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume width must be an exact multiple of array height.");
}
if(volInput->getDepth() % arrayResult->getDimension(2) != 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume width must be an exact multiple of array depth.");
}
uint16_t uRandomUnitVectorIndex = 0;
uint16_t uRandomVectorIndex = 0;
uint16_t uIndexIncreament;
//Our initial indices. It doesn't matter exactly what we set here, but the code below makes
//sure they are different for different regions which helps reduce tiling patterns in the results.
uRandomUnitVectorIndex += region.getLowerX() + region.getLowerY() + region.getLowerZ();
uRandomVectorIndex += region.getLowerX() + region.getLowerY() + region.getLowerZ();
//This value helps us jump around in the array a bit more, so the
//nth 'random' value isn't always followed by the n+1th 'random' value.
uIndexIncreament = 1;
const int iRatioX = volInput->getWidth() / arrayResult->getDimension(0);
const int iRatioY = volInput->getHeight() / arrayResult->getDimension(1);
const int iRatioZ = volInput->getDepth() / arrayResult->getDimension(2);
const float fRatioX = iRatioX;
const float fRatioY = iRatioY;
const float fRatioZ = iRatioZ;
const Vector3DFloat v3dRatio(fRatioX, fRatioY, fRatioZ);
const float fHalfRatioX = fRatioX * 0.5f;
const float fHalfRatioY = fRatioY * 0.5f;
const float fHalfRatioZ = fRatioZ * 0.5f;
const Vector3DFloat v3dHalfRatio(fHalfRatioX, fHalfRatioY, fHalfRatioZ);
const Vector3DFloat v3dOffset(0.5f,0.5f,0.5f);
//This loop iterates over the bottom-lower-left voxel in each of the cells in the output array
for(uint16_t z = region.getLowerZ(); z <= region.getUpperZ(); z += iRatioZ)
{
for(uint16_t y = region.getLowerY(); y <= region.getUpperY(); y += iRatioY)
{
for(uint16_t x = region.getLowerX(); x <= region.getUpperX(); x += iRatioX)
{
//Compute a start position corresponding to
//the centre of the cell in the output array.
Vector3DFloat v3dStart(x, y, z);
v3dStart -= v3dOffset;
v3dStart += v3dHalfRatio;
//Keep track of how many rays did not hit anything
uint8_t uVisibleDirections = 0;
for(int ct = 0; ct < uNoOfSamplesPerOutputElement; ct++)
{
//We take a random vector with components going from -1 to 1 and scale it to go from -halfRatio to +halfRatio.
//This jitter value moves our sample point from the centre of the array cell to somewhere else in the array cell
Vector3DFloat v3dJitter = randomVectors[(uRandomVectorIndex += (++uIndexIncreament)) % 1019]; //Prime number helps avoid repetition on successive loops.
v3dJitter *= v3dHalfRatio;
const Vector3DFloat v3dRayStart = v3dStart + v3dJitter;
Vector3DFloat v3dRayDirection = randomUnitVectors[(uRandomUnitVectorIndex += (++uIndexIncreament)) % 1021]; //Different prime number.
v3dRayDirection *= fRayLength;
AmbientOcclusionCalculatorRaycastCallback<IsVoxelTransparentCallback> ambientOcclusionCalculatorRaycastCallback(isVoxelTransparentCallback);
RaycastResult result = raycastWithDirection(volInput, v3dRayStart, v3dRayDirection, ambientOcclusionCalculatorRaycastCallback);
// Note - The performance of this could actually be improved it we exited as soon
// as the ray left the volume. The raycast test has an example of how to do this.
if(result == RaycastResults::Completed)
{
++uVisibleDirections;
}
}
float fVisibility;
if(uNoOfSamplesPerOutputElement == 0)
{
//The user might request zero samples (I've done this in the past while debugging - I don't want to
//wait for ambient occlusion but I do want as valid result for rendering). Avoid the divide by zero.
fVisibility = 1.0f;
}
else
{
fVisibility = static_cast<float>(uVisibleDirections) / static_cast<float>(uNoOfSamplesPerOutputElement);
POLYVOX_ASSERT((fVisibility >= 0.0f) && (fVisibility <= 1.0f), "Visibility value out of range.");
}
(*arrayResult)(z / iRatioZ, y / iRatioY, x / iRatioX) = static_cast<uint8_t>(255.0f * fVisibility);
}
}
}
}
}

View File

@ -1,193 +1,193 @@
/*******************************************************************************
Copyright (c) 2005-20014 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Array_H__
#define __PolyVox_Array_H__
#include <PolyVoxCore/Impl/ErrorHandling.h>
#include <cstdint>
namespace PolyVox
{
template <uint32_t noOfDims, typename ElementType>
class Array
{
public:
Array(uint32_t width)
:m_pElements(0)
{
static_assert(noOfDims == 1, "This constructor can only be used with a one-dimensional array");
m_uDimensions[0] = width;
initialize();
}
Array(uint32_t width, uint32_t height)
:m_pElements(0)
{
static_assert(noOfDims == 2, "This constructor can only be used with a two-dimensional array");
m_uDimensions[0] = width;
m_uDimensions[1] = height;
initialize();
}
Array(uint32_t width, uint32_t height, uint32_t depth)
:m_pElements(0)
{
static_assert(noOfDims == 3, "This constructor can only be used with a three-dimensional array");
m_uDimensions[0] = width;
m_uDimensions[1] = height;
m_uDimensions[2] = depth;
initialize();
}
// These are deleted to avoid accidental copying.
Array<noOfDims, ElementType>(const Array<noOfDims, ElementType>&) = delete;
Array<noOfDims, ElementType>& operator=(const Array<noOfDims, ElementType>&) = delete;
~Array()
{
delete[] m_pElements;
}
ElementType& operator()(uint32_t x) const
{
static_assert(noOfDims == 1, "This accessor can only be used with a one-dimensional array");
POLYVOX_ASSERT(x < m_uDimensions[0], "Array access is out-of-range.");
return m_pElements[x];
}
ElementType& operator()(uint32_t x, uint32_t y) const
{
static_assert(noOfDims == 2, "This accessor can only be used with a two-dimensional array");
POLYVOX_ASSERT(x < m_uDimensions[0] && y < m_uDimensions[1], "Array access is out-of-range.");
return m_pElements[y * m_uDimensions[0] + x];
}
ElementType& operator()(uint32_t x, uint32_t y, uint32_t z) const
{
static_assert(noOfDims == 3, "This accessor can only be used with a three-dimensional array");
POLYVOX_ASSERT(x < m_uDimensions[0] && y < m_uDimensions[1] && z < m_uDimensions[2], "Array access is out-of-range.");
return m_pElements[z * m_uDimensions[0] * m_uDimensions[1] + y * m_uDimensions[0] + x];
}
uint32_t getDimension(uint32_t dimension)
{
return m_uDimensions[dimension];
}
ElementType* getRawData()
{
return m_pElements;
}
uint32_t getNoOfElements()
{
return m_uNoOfElements;
}
void swap(Array& other)
{
ElementType* temp = other.m_pElements;
other.m_pElements = m_pElements;
m_pElements = temp;
}
private:
void initialize(void)
{
// Calculate the total number of elements in the array.
m_uNoOfElements = 1;
for (uint32_t i = 0; i < noOfDims; i++)
{
m_uNoOfElements *= m_uDimensions[i];
}
m_pElements = new ElementType[m_uNoOfElements];
}
uint32_t m_uDimensions[noOfDims];
uint32_t m_uNoOfElements;
ElementType* m_pElements;
};
///A 1D Array of floats.
typedef Array<1, float> Array1DFloat;
///A 1D Array of doubles.
typedef Array<1, double> Array1DDouble;
///A 1D Array of signed 8-bit values.
typedef Array<1, int8_t> Array1DInt8;
///A 1D Array of unsigned 8-bit values.
typedef Array<1, uint8_t> Array1DUint8;
///A 1D Array of signed 16-bit values.
typedef Array<1, int16_t> Array1DInt16;
///A 1D Array of unsigned 16-bit values.
typedef Array<1, uint16_t> Array1DUint16;
///A 1D Array of signed 32-bit values.
typedef Array<1, int32_t> Array1DInt32;
///A 1D Array of unsigned 32-bit values.
typedef Array<1, uint32_t> Array1DUint32;
///A 2D Array of floats.
typedef Array<2, float> Array2DFloat;
///A 2D Array of doubles.
typedef Array<2, double> Array2DDouble;
///A 2D Array of signed 8-bit values.
typedef Array<2, int8_t> Array2DInt8;
///A 2D Array of unsigned 8-bit values.
typedef Array<2, uint8_t> Array2DUint8;
///A 2D Array of signed 16-bit values.
typedef Array<2, int16_t> Array2DInt16;
///A 2D Array of unsigned 16-bit values.
typedef Array<2, uint16_t> Array2DUint16;
///A 2D Array of signed 32-bit values.
typedef Array<2, int32_t> Array2DInt32;
///A 2D Array of unsigned 32-bit values.
typedef Array<2, uint32_t> Array2DUint32;
///A 3D Array of floats.
typedef Array<3, float> Array3DFloat;
///A 3D Array of doubles.
typedef Array<3, double> Array3DDouble;
///A 3D Array of signed 8-bit values.
typedef Array<3, int8_t> Array3DInt8;
///A 3D Array of unsigned 8-bit values.
typedef Array<3, uint8_t> Array3DUint8;
///A 3D Array of signed 16-bit values.
typedef Array<3, int16_t> Array3DInt16;
///A 3D Array of unsigned 16-bit values.
typedef Array<3, uint16_t> Array3DUint16;
///A 3D Array of signed 32-bit values.
typedef Array<3, int32_t> Array3DInt32;
///A 3D Array of unsigned 32-bit values.
typedef Array<3, uint32_t> Array3DUint32;
}
/*******************************************************************************
Copyright (c) 2005-20014 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Array_H__
#define __PolyVox_Array_H__
#include <PolyVoxCore/Impl/ErrorHandling.h>
#include <cstdint>
namespace PolyVox
{
template <uint32_t noOfDims, typename ElementType>
class Array
{
public:
Array(uint32_t width)
:m_pElements(0)
{
static_assert(noOfDims == 1, "This constructor can only be used with a one-dimensional array");
m_uDimensions[0] = width;
initialize();
}
Array(uint32_t width, uint32_t height)
:m_pElements(0)
{
static_assert(noOfDims == 2, "This constructor can only be used with a two-dimensional array");
m_uDimensions[0] = width;
m_uDimensions[1] = height;
initialize();
}
Array(uint32_t width, uint32_t height, uint32_t depth)
:m_pElements(0)
{
static_assert(noOfDims == 3, "This constructor can only be used with a three-dimensional array");
m_uDimensions[0] = width;
m_uDimensions[1] = height;
m_uDimensions[2] = depth;
initialize();
}
// These are deleted to avoid accidental copying.
Array<noOfDims, ElementType>(const Array<noOfDims, ElementType>&) = delete;
Array<noOfDims, ElementType>& operator=(const Array<noOfDims, ElementType>&) = delete;
~Array()
{
delete[] m_pElements;
}
ElementType& operator()(uint32_t x) const
{
static_assert(noOfDims == 1, "This accessor can only be used with a one-dimensional array");
POLYVOX_ASSERT(x < m_uDimensions[0], "Array access is out-of-range.");
return m_pElements[x];
}
ElementType& operator()(uint32_t x, uint32_t y) const
{
static_assert(noOfDims == 2, "This accessor can only be used with a two-dimensional array");
POLYVOX_ASSERT(x < m_uDimensions[0] && y < m_uDimensions[1], "Array access is out-of-range.");
return m_pElements[y * m_uDimensions[0] + x];
}
ElementType& operator()(uint32_t x, uint32_t y, uint32_t z) const
{
static_assert(noOfDims == 3, "This accessor can only be used with a three-dimensional array");
POLYVOX_ASSERT(x < m_uDimensions[0] && y < m_uDimensions[1] && z < m_uDimensions[2], "Array access is out-of-range.");
return m_pElements[z * m_uDimensions[0] * m_uDimensions[1] + y * m_uDimensions[0] + x];
}
uint32_t getDimension(uint32_t dimension)
{
return m_uDimensions[dimension];
}
ElementType* getRawData()
{
return m_pElements;
}
uint32_t getNoOfElements()
{
return m_uNoOfElements;
}
void swap(Array& other)
{
ElementType* temp = other.m_pElements;
other.m_pElements = m_pElements;
m_pElements = temp;
}
private:
void initialize(void)
{
// Calculate the total number of elements in the array.
m_uNoOfElements = 1;
for (uint32_t i = 0; i < noOfDims; i++)
{
m_uNoOfElements *= m_uDimensions[i];
}
m_pElements = new ElementType[m_uNoOfElements];
}
uint32_t m_uDimensions[noOfDims];
uint32_t m_uNoOfElements;
ElementType* m_pElements;
};
///A 1D Array of floats.
typedef Array<1, float> Array1DFloat;
///A 1D Array of doubles.
typedef Array<1, double> Array1DDouble;
///A 1D Array of signed 8-bit values.
typedef Array<1, int8_t> Array1DInt8;
///A 1D Array of unsigned 8-bit values.
typedef Array<1, uint8_t> Array1DUint8;
///A 1D Array of signed 16-bit values.
typedef Array<1, int16_t> Array1DInt16;
///A 1D Array of unsigned 16-bit values.
typedef Array<1, uint16_t> Array1DUint16;
///A 1D Array of signed 32-bit values.
typedef Array<1, int32_t> Array1DInt32;
///A 1D Array of unsigned 32-bit values.
typedef Array<1, uint32_t> Array1DUint32;
///A 2D Array of floats.
typedef Array<2, float> Array2DFloat;
///A 2D Array of doubles.
typedef Array<2, double> Array2DDouble;
///A 2D Array of signed 8-bit values.
typedef Array<2, int8_t> Array2DInt8;
///A 2D Array of unsigned 8-bit values.
typedef Array<2, uint8_t> Array2DUint8;
///A 2D Array of signed 16-bit values.
typedef Array<2, int16_t> Array2DInt16;
///A 2D Array of unsigned 16-bit values.
typedef Array<2, uint16_t> Array2DUint16;
///A 2D Array of signed 32-bit values.
typedef Array<2, int32_t> Array2DInt32;
///A 2D Array of unsigned 32-bit values.
typedef Array<2, uint32_t> Array2DUint32;
///A 3D Array of floats.
typedef Array<3, float> Array3DFloat;
///A 3D Array of doubles.
typedef Array<3, double> Array3DDouble;
///A 3D Array of signed 8-bit values.
typedef Array<3, int8_t> Array3DInt8;
///A 3D Array of unsigned 8-bit values.
typedef Array<3, uint8_t> Array3DUint8;
///A 3D Array of signed 16-bit values.
typedef Array<3, int16_t> Array3DInt16;
///A 3D Array of unsigned 16-bit values.
typedef Array<3, uint16_t> Array3DUint16;
///A 3D Array of signed 32-bit values.
typedef Array<3, int32_t> Array3DInt32;
///A 3D Array of unsigned 32-bit values.
typedef Array<3, uint32_t> Array3DUint32;
}
#endif //__PolyVox_Array_H__

View File

@ -1,217 +1,217 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_BaseVolume_H__
#define __PolyVox_BaseVolume_H__
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Vector.h"
#include <limits>
namespace PolyVox
{
/// The BaseVolume class provides common functionality and an interface for other volume classes to implement. You should not try to create an instance of this
/// class directly. Instead you should use RawVolume or PagedVolume.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// More details to come...
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace WrapModes
{
enum WrapMode
{
Validate = 0,
Clamp = 1,
Border = 2,
AssumeValid = 3
};
}
typedef WrapModes::WrapMode WrapMode;
// Required for a trick to implement specialization of template member
// functions in template classes. See http://stackoverflow.com/a/4951057
template <WrapMode W> struct WrapModeType{};
template <typename _VoxelType>
class BaseVolume
{
public:
typedef _VoxelType VoxelType;
#ifndef SWIG
template <typename DerivedVolumeType>
class Sampler
{
public:
Sampler(DerivedVolumeType* volume);
~Sampler();
Vector3DInt32 getPosition(void) const;
inline VoxelType getVoxel(void) const;
bool isCurrentPositionValid(void) const;
void setPosition(const Vector3DInt32& v3dNewPos);
void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
inline bool setVoxel(VoxelType tValue);
void setWrapMode(WrapMode eWrapMode, VoxelType tBorder = VoxelType());
void movePositiveX(void);
void movePositiveY(void);
void movePositiveZ(void);
void moveNegativeX(void);
void moveNegativeY(void);
void moveNegativeZ(void);
inline VoxelType peekVoxel1nx1ny1nz(void) const;
inline VoxelType peekVoxel1nx1ny0pz(void) const;
inline VoxelType peekVoxel1nx1ny1pz(void) const;
inline VoxelType peekVoxel1nx0py1nz(void) const;
inline VoxelType peekVoxel1nx0py0pz(void) const;
inline VoxelType peekVoxel1nx0py1pz(void) const;
inline VoxelType peekVoxel1nx1py1nz(void) const;
inline VoxelType peekVoxel1nx1py0pz(void) const;
inline VoxelType peekVoxel1nx1py1pz(void) const;
inline VoxelType peekVoxel0px1ny1nz(void) const;
inline VoxelType peekVoxel0px1ny0pz(void) const;
inline VoxelType peekVoxel0px1ny1pz(void) const;
inline VoxelType peekVoxel0px0py1nz(void) const;
inline VoxelType peekVoxel0px0py0pz(void) const;
inline VoxelType peekVoxel0px0py1pz(void) const;
inline VoxelType peekVoxel0px1py1nz(void) const;
inline VoxelType peekVoxel0px1py0pz(void) const;
inline VoxelType peekVoxel0px1py1pz(void) const;
inline VoxelType peekVoxel1px1ny1nz(void) const;
inline VoxelType peekVoxel1px1ny0pz(void) const;
inline VoxelType peekVoxel1px1ny1pz(void) const;
inline VoxelType peekVoxel1px0py1nz(void) const;
inline VoxelType peekVoxel1px0py0pz(void) const;
inline VoxelType peekVoxel1px0py1pz(void) const;
inline VoxelType peekVoxel1px1py1nz(void) const;
inline VoxelType peekVoxel1px1py0pz(void) const;
inline VoxelType peekVoxel1px1py1pz(void) const;
protected:
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
DerivedVolumeType* mVolume;
//The current position in the volume
int32_t mXPosInVolume;
int32_t mYPosInVolume;
int32_t mZPosInVolume;
WrapMode m_eWrapMode;
VoxelType m_tBorder;
//Whether the current position is inside the volume
//FIXME - Replace these with flags
bool m_bIsCurrentPositionValidInX;
bool m_bIsCurrentPositionValidInY;
bool m_bIsCurrentPositionValidInZ;
};
#endif
public:
/// Gets the value used for voxels which are outside the volume
VoxelType getBorderValue(void) const;
/// Gets a Region representing the extents of the Volume.
const Region& getEnclosingRegion(void) const;
/// Gets the width of the volume in voxels.
int32_t getWidth(void) const;
/// Gets the height of the volume in voxels.
int32_t getHeight(void) const;
/// Gets the depth of the volume in voxels.
int32_t getDepth(void) const;
/// Gets the length of the longest side in voxels
int32_t getLongestSideLength(void) const;
/// Gets the length of the shortest side in voxels
int32_t getShortestSideLength(void) const;
/// Gets the length of the diagonal in voxels
float getDiagonalLength(void) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
template <WrapMode eWrapMode>
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by a 3D vector
template <WrapMode eWrapMode>
VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by a 3D vector
VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector
POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
/// Sets the value used for voxels which are outside the volume
void setBorderValue(const VoxelType& tBorder);
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate);
/// Sets the voxel at the position given by a 3D vector
void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate);
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
/// Sets the voxel at the position given by a 3D vector
bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue);
/// Calculates approximatly how many bytes of memory the volume is currently using.
uint32_t calculateSizeInBytes(void);
protected:
/// Constructor for creating a fixed size volume.
BaseVolume(const Region& regValid);
/// Copy constructor
BaseVolume(const BaseVolume& rhs);
/// Destructor
~BaseVolume();
/// Assignment operator
BaseVolume& operator=(const BaseVolume& rhs);
//The size of the volume
Region m_regValidRegion;
//Some useful sizes
int32_t m_uLongestSideLength;
int32_t m_uShortestSideLength;
float m_fDiagonalLength;
//The border value
VoxelType m_tBorderValue;
};
}
#include "PolyVoxCore/BaseVolume.inl"
#include "PolyVoxCore/BaseVolumeSampler.inl"
#endif //__PolyVox_BaseVolume_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_BaseVolume_H__
#define __PolyVox_BaseVolume_H__
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Vector.h"
#include <limits>
namespace PolyVox
{
/// The BaseVolume class provides common functionality and an interface for other volume classes to implement. You should not try to create an instance of this
/// class directly. Instead you should use RawVolume or PagedVolume.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// More details to come...
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace WrapModes
{
enum WrapMode
{
Validate = 0,
Clamp = 1,
Border = 2,
AssumeValid = 3
};
}
typedef WrapModes::WrapMode WrapMode;
// Required for a trick to implement specialization of template member
// functions in template classes. See http://stackoverflow.com/a/4951057
template <WrapMode W> struct WrapModeType{};
template <typename _VoxelType>
class BaseVolume
{
public:
typedef _VoxelType VoxelType;
#ifndef SWIG
template <typename DerivedVolumeType>
class Sampler
{
public:
Sampler(DerivedVolumeType* volume);
~Sampler();
Vector3DInt32 getPosition(void) const;
inline VoxelType getVoxel(void) const;
bool isCurrentPositionValid(void) const;
void setPosition(const Vector3DInt32& v3dNewPos);
void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
inline bool setVoxel(VoxelType tValue);
void setWrapMode(WrapMode eWrapMode, VoxelType tBorder = VoxelType());
void movePositiveX(void);
void movePositiveY(void);
void movePositiveZ(void);
void moveNegativeX(void);
void moveNegativeY(void);
void moveNegativeZ(void);
inline VoxelType peekVoxel1nx1ny1nz(void) const;
inline VoxelType peekVoxel1nx1ny0pz(void) const;
inline VoxelType peekVoxel1nx1ny1pz(void) const;
inline VoxelType peekVoxel1nx0py1nz(void) const;
inline VoxelType peekVoxel1nx0py0pz(void) const;
inline VoxelType peekVoxel1nx0py1pz(void) const;
inline VoxelType peekVoxel1nx1py1nz(void) const;
inline VoxelType peekVoxel1nx1py0pz(void) const;
inline VoxelType peekVoxel1nx1py1pz(void) const;
inline VoxelType peekVoxel0px1ny1nz(void) const;
inline VoxelType peekVoxel0px1ny0pz(void) const;
inline VoxelType peekVoxel0px1ny1pz(void) const;
inline VoxelType peekVoxel0px0py1nz(void) const;
inline VoxelType peekVoxel0px0py0pz(void) const;
inline VoxelType peekVoxel0px0py1pz(void) const;
inline VoxelType peekVoxel0px1py1nz(void) const;
inline VoxelType peekVoxel0px1py0pz(void) const;
inline VoxelType peekVoxel0px1py1pz(void) const;
inline VoxelType peekVoxel1px1ny1nz(void) const;
inline VoxelType peekVoxel1px1ny0pz(void) const;
inline VoxelType peekVoxel1px1ny1pz(void) const;
inline VoxelType peekVoxel1px0py1nz(void) const;
inline VoxelType peekVoxel1px0py0pz(void) const;
inline VoxelType peekVoxel1px0py1pz(void) const;
inline VoxelType peekVoxel1px1py1nz(void) const;
inline VoxelType peekVoxel1px1py0pz(void) const;
inline VoxelType peekVoxel1px1py1pz(void) const;
protected:
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
DerivedVolumeType* mVolume;
//The current position in the volume
int32_t mXPosInVolume;
int32_t mYPosInVolume;
int32_t mZPosInVolume;
WrapMode m_eWrapMode;
VoxelType m_tBorder;
//Whether the current position is inside the volume
//FIXME - Replace these with flags
bool m_bIsCurrentPositionValidInX;
bool m_bIsCurrentPositionValidInY;
bool m_bIsCurrentPositionValidInZ;
};
#endif
public:
/// Gets the value used for voxels which are outside the volume
VoxelType getBorderValue(void) const;
/// Gets a Region representing the extents of the Volume.
const Region& getEnclosingRegion(void) const;
/// Gets the width of the volume in voxels.
int32_t getWidth(void) const;
/// Gets the height of the volume in voxels.
int32_t getHeight(void) const;
/// Gets the depth of the volume in voxels.
int32_t getDepth(void) const;
/// Gets the length of the longest side in voxels
int32_t getLongestSideLength(void) const;
/// Gets the length of the shortest side in voxels
int32_t getShortestSideLength(void) const;
/// Gets the length of the diagonal in voxels
float getDiagonalLength(void) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
template <WrapMode eWrapMode>
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by a 3D vector
template <WrapMode eWrapMode>
VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by a 3D vector
VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector
POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
/// Sets the value used for voxels which are outside the volume
void setBorderValue(const VoxelType& tBorder);
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate);
/// Sets the voxel at the position given by a 3D vector
void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate);
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
/// Sets the voxel at the position given by a 3D vector
bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue);
/// Calculates approximatly how many bytes of memory the volume is currently using.
uint32_t calculateSizeInBytes(void);
protected:
/// Constructor for creating a fixed size volume.
BaseVolume(const Region& regValid);
/// Copy constructor
BaseVolume(const BaseVolume& rhs);
/// Destructor
~BaseVolume();
/// Assignment operator
BaseVolume& operator=(const BaseVolume& rhs);
//The size of the volume
Region m_regValidRegion;
//Some useful sizes
int32_t m_uLongestSideLength;
int32_t m_uShortestSideLength;
float m_fDiagonalLength;
//The border value
VoxelType m_tBorderValue;
};
}
#include "PolyVoxCore/BaseVolume.inl"
#include "PolyVoxCore/BaseVolumeSampler.inl"
#endif //__PolyVox_BaseVolume_H__

View File

@ -1,314 +1,314 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
////////////////////////////////////////////////////////////////////////////////
/// This is protected because you should never create a BaseVolume directly, you should instead use one of the derived classes.
///
/// \sa RawVolume, PagedVolume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>::BaseVolume(const Region& regValid)
:m_regValidRegion(regValid)
,m_tBorderValue()
{
}
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the VolumeResampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>::BaseVolume(const BaseVolume<VoxelType>& /*rhs*/)
{
POLYVOX_THROW(not_implemented, "Volume copy constructor not implemented for performance reasons.");
}
////////////////////////////////////////////////////////////////////////////////
/// Destroys the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>::~BaseVolume()
{
}
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the VolumeResampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>& BaseVolume<VoxelType>::operator=(const BaseVolume<VoxelType>& /*rhs*/)
{
POLYVOX_THROW(not_implemented, "Volume assignment operator not implemented for performance reasons.");
}
////////////////////////////////////////////////////////////////////////////////
/// The border value is returned whenever an attempt is made to read a voxel which
/// is outside the extents of the volume.
/// \return The value used for voxels outside of the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getBorderValue(void) const
{
return m_tBorderValue;
}
////////////////////////////////////////////////////////////////////////////////
/// \return A Region representing the extent of the volume.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
const Region& BaseVolume<VoxelType>::getEnclosingRegion(void) const
{
return m_regValidRegion;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The width of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the width is 64.
/// \sa getHeight(), getDepth()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getWidth(void) const
{
return m_regValidRegion.getUpperX() - m_regValidRegion.getLowerX() + 1;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The height of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the height is 64.
/// \sa getWidth(), getDepth()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getHeight(void) const
{
return m_regValidRegion.getUpperY() - m_regValidRegion.getLowerY() + 1;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The depth of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the depth is 64.
/// \sa getWidth(), getHeight()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getDepth(void) const
{
return m_regValidRegion.getUpperZ() - m_regValidRegion.getLowerZ() + 1;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The length of the shortest side in voxels. For example, if a volume has
/// dimensions 256x512x1024 this function will return 256.
/// \sa getLongestSideLength(), getDiagonalLength()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getShortestSideLength(void) const
{
return m_uShortestSideLength;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The length of the longest side in voxels. For example, if a volume has
/// dimensions 256x512x1024 this function will return 1024.
/// \sa getShortestSideLength(), getDiagonalLength()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getLongestSideLength(void) const
{
return m_uLongestSideLength;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The length of the diagonal in voxels. For example, if a volume has
/// dimensions 256x512x1024 this function will return sqrt(256*256+512*512+1024*1024)
/// = 1173.139. This value is computed on volume creation so retrieving it is fast.
/// \sa getShortestSideLength(), getLongestSideLength()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
float BaseVolume<VoxelType>::getDiagonalLength(void) const
{
return m_fDiagonalLength;
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function requires the wrap mode to be specified as a
/// template parameter, which can provide better performance.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType BaseVolume<VoxelType>::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tBorder*/) const
{
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function requires the wrap mode to be specified as a
/// template parameter, which can provide better performance.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType BaseVolume<VoxelType>::getVoxel(const Vector3DInt32& /*v3dPos*/, VoxelType /*tBorder*/) const
{
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function is provided so that the wrap mode does not need
/// to be specified as a template parameter, as it may be confusing to some users.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
{
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function is provided so that the wrap mode does not need
/// to be specified as a template parameter, as it may be confusing to some users.
/// \param v3dPos The 3D position of the voxel
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxel(const Vector3DInt32& /*v3dPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
{
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos The 3D position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxelAt(const Vector3DInt32& /*v3dPos*/) const
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// \param tBorder The value to use for voxels outside the volume.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void BaseVolume<VoxelType>::setBorderValue(const VoxelType& tBorder)
{
m_tBorderValue = tBorder;
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel
/// \param uZPos the \c z position of the voxel
/// \param tValue the value to which the voxel will be set
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void BaseVolume<VoxelType>::setVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/, WrapMode /*eWrapMode*/)
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos the 3D position of the voxel
/// \param tValue the value to which the voxel will be set
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void BaseVolume<VoxelType>::setVoxel(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/, WrapMode /*eWrapMode*/)
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel
/// \param uZPos the \c z position of the voxel
/// \param tValue the value to which the voxel will be set
/// \return whether the requested position is inside the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
bool BaseVolume<VoxelType>::setVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/)
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos the 3D position of the voxel
/// \param tValue the value to which the voxel will be set
/// \return whether the requested position is inside the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
bool BaseVolume<VoxelType>::setVoxelAt(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/)
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// Note: This function needs reviewing for accuracy...
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
uint32_t BaseVolume<VoxelType>::calculateSizeInBytes(void)
{
return getWidth() * getHeight() * getDepth() * sizeof(VoxelType);
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
////////////////////////////////////////////////////////////////////////////////
/// This is protected because you should never create a BaseVolume directly, you should instead use one of the derived classes.
///
/// \sa RawVolume, PagedVolume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>::BaseVolume(const Region& regValid)
:m_regValidRegion(regValid)
,m_tBorderValue()
{
}
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the VolumeResampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>::BaseVolume(const BaseVolume<VoxelType>& /*rhs*/)
{
POLYVOX_THROW(not_implemented, "Volume copy constructor not implemented for performance reasons.");
}
////////////////////////////////////////////////////////////////////////////////
/// Destroys the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>::~BaseVolume()
{
}
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the VolumeResampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
BaseVolume<VoxelType>& BaseVolume<VoxelType>::operator=(const BaseVolume<VoxelType>& /*rhs*/)
{
POLYVOX_THROW(not_implemented, "Volume assignment operator not implemented for performance reasons.");
}
////////////////////////////////////////////////////////////////////////////////
/// The border value is returned whenever an attempt is made to read a voxel which
/// is outside the extents of the volume.
/// \return The value used for voxels outside of the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getBorderValue(void) const
{
return m_tBorderValue;
}
////////////////////////////////////////////////////////////////////////////////
/// \return A Region representing the extent of the volume.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
const Region& BaseVolume<VoxelType>::getEnclosingRegion(void) const
{
return m_regValidRegion;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The width of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the width is 64.
/// \sa getHeight(), getDepth()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getWidth(void) const
{
return m_regValidRegion.getUpperX() - m_regValidRegion.getLowerX() + 1;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The height of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the height is 64.
/// \sa getWidth(), getDepth()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getHeight(void) const
{
return m_regValidRegion.getUpperY() - m_regValidRegion.getLowerY() + 1;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The depth of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the depth is 64.
/// \sa getWidth(), getHeight()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getDepth(void) const
{
return m_regValidRegion.getUpperZ() - m_regValidRegion.getLowerZ() + 1;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The length of the shortest side in voxels. For example, if a volume has
/// dimensions 256x512x1024 this function will return 256.
/// \sa getLongestSideLength(), getDiagonalLength()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getShortestSideLength(void) const
{
return m_uShortestSideLength;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The length of the longest side in voxels. For example, if a volume has
/// dimensions 256x512x1024 this function will return 1024.
/// \sa getShortestSideLength(), getDiagonalLength()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
int32_t BaseVolume<VoxelType>::getLongestSideLength(void) const
{
return m_uLongestSideLength;
}
////////////////////////////////////////////////////////////////////////////////
/// \return The length of the diagonal in voxels. For example, if a volume has
/// dimensions 256x512x1024 this function will return sqrt(256*256+512*512+1024*1024)
/// = 1173.139. This value is computed on volume creation so retrieving it is fast.
/// \sa getShortestSideLength(), getLongestSideLength()
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
float BaseVolume<VoxelType>::getDiagonalLength(void) const
{
return m_fDiagonalLength;
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function requires the wrap mode to be specified as a
/// template parameter, which can provide better performance.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType BaseVolume<VoxelType>::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tBorder*/) const
{
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function requires the wrap mode to be specified as a
/// template parameter, which can provide better performance.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType BaseVolume<VoxelType>::getVoxel(const Vector3DInt32& /*v3dPos*/, VoxelType /*tBorder*/) const
{
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function is provided so that the wrap mode does not need
/// to be specified as a template parameter, as it may be confusing to some users.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
{
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function is provided so that the wrap mode does not need
/// to be specified as a template parameter, as it may be confusing to some users.
/// \param v3dPos The 3D position of the voxel
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxel(const Vector3DInt32& /*v3dPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
{
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos The 3D position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxelAt(const Vector3DInt32& /*v3dPos*/) const
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return VoxelType();
}
////////////////////////////////////////////////////////////////////////////////
/// \param tBorder The value to use for voxels outside the volume.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void BaseVolume<VoxelType>::setBorderValue(const VoxelType& tBorder)
{
m_tBorderValue = tBorder;
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel
/// \param uZPos the \c z position of the voxel
/// \param tValue the value to which the voxel will be set
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void BaseVolume<VoxelType>::setVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/, WrapMode /*eWrapMode*/)
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos the 3D position of the voxel
/// \param tValue the value to which the voxel will be set
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void BaseVolume<VoxelType>::setVoxel(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/, WrapMode /*eWrapMode*/)
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel
/// \param uZPos the \c z position of the voxel
/// \param tValue the value to which the voxel will be set
/// \return whether the requested position is inside the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
bool BaseVolume<VoxelType>::setVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/)
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos the 3D position of the voxel
/// \param tValue the value to which the voxel will be set
/// \return whether the requested position is inside the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
bool BaseVolume<VoxelType>::setVoxelAt(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/)
{
POLYVOX_THROW(not_implemented, "You should never call the base class version of this function.");
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// Note: This function needs reviewing for accuracy...
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
uint32_t BaseVolume<VoxelType>::calculateSizeInBytes(void)
{
return getWidth() * getHeight() * getDepth() * sizeof(VoxelType);
}
}

View File

@ -1,366 +1,366 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Impl/Utility.h"
namespace PolyVox
{
template <typename VoxelType>
template <typename DerivedVolumeType>
BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::Sampler(DerivedVolumeType* volume)
:mVolume(volume)
,mXPosInVolume(0)
,mYPosInVolume(0)
,mZPosInVolume(0)
,m_eWrapMode(WrapModes::Border)
,m_tBorder()
,m_bIsCurrentPositionValidInX(false)
,m_bIsCurrentPositionValidInY(false)
,m_bIsCurrentPositionValidInZ(false)
{
}
template <typename VoxelType>
template <typename DerivedVolumeType>
BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::~Sampler()
{
}
template <typename VoxelType>
template <typename DerivedVolumeType>
Vector3DInt32 BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::getPosition(void) const
{
return Vector3DInt32(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::getVoxel(void) const
{
return mVolume->getVoxel(mXPosInVolume, mYPosInVolume, mZPosInVolume, WrapModes::Validate); // FIXME - Use templatised version instead but watch for Linux compile errors.
}
template <typename VoxelType>
template <typename DerivedVolumeType>
bool inline BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::isCurrentPositionValid(void) const
{
return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ;
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setPosition(const Vector3DInt32& v3dNewPos)
{
setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setPosition(int32_t xPos, int32_t yPos, int32_t zPos)
{
mXPosInVolume = xPos;
mYPosInVolume = yPos;
mZPosInVolume = zPos;
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(xPos);
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(yPos);
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(zPos);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
bool BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setVoxel(VoxelType tValue)
{
return mVolume->setVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume, tValue);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setWrapMode(WrapMode eWrapMode, VoxelType tBorder)
{
m_eWrapMode = eWrapMode;
m_tBorder = tBorder;
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveX(void)
{
mXPosInVolume++;
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveY(void)
{
mYPosInVolume++;
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveZ(void)
{
mZPosInVolume++;
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeX(void)
{
mXPosInVolume--;
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeY(void)
{
mYPosInVolume--;
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeZ(void)
{
mZPosInVolume--;
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1ny1nz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1ny0pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1ny1pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx0py1nz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx0py0pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx0py1pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1py1nz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1py0pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1py1pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1);
}
//////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1ny1nz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1ny0pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1ny1pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px0py1nz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px0py0pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume , mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px0py1pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1py1nz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1py0pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1py1pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1);
}
//////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1ny1nz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1ny0pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1ny1pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px0py1nz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px0py0pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px0py1pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1py1nz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1py0pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1py1pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
{
switch(m_eWrapMode)
{
case WrapModes::Validate:
return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Validate, m_tBorder);
case WrapModes::Clamp:
return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Clamp, m_tBorder);
case WrapModes::Border:
return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Border, m_tBorder);
case WrapModes::AssumeValid:
return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::AssumeValid, m_tBorder);
default:
// Should never happen
POLYVOX_ASSERT(false, "Invalid wrap mode");
return VoxelType();
}
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Impl/Utility.h"
namespace PolyVox
{
template <typename VoxelType>
template <typename DerivedVolumeType>
BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::Sampler(DerivedVolumeType* volume)
:mVolume(volume)
,mXPosInVolume(0)
,mYPosInVolume(0)
,mZPosInVolume(0)
,m_eWrapMode(WrapModes::Border)
,m_tBorder()
,m_bIsCurrentPositionValidInX(false)
,m_bIsCurrentPositionValidInY(false)
,m_bIsCurrentPositionValidInZ(false)
{
}
template <typename VoxelType>
template <typename DerivedVolumeType>
BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::~Sampler()
{
}
template <typename VoxelType>
template <typename DerivedVolumeType>
Vector3DInt32 BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::getPosition(void) const
{
return Vector3DInt32(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::getVoxel(void) const
{
return mVolume->getVoxel(mXPosInVolume, mYPosInVolume, mZPosInVolume, WrapModes::Validate); // FIXME - Use templatised version instead but watch for Linux compile errors.
}
template <typename VoxelType>
template <typename DerivedVolumeType>
bool inline BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::isCurrentPositionValid(void) const
{
return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ;
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setPosition(const Vector3DInt32& v3dNewPos)
{
setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setPosition(int32_t xPos, int32_t yPos, int32_t zPos)
{
mXPosInVolume = xPos;
mYPosInVolume = yPos;
mZPosInVolume = zPos;
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(xPos);
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(yPos);
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(zPos);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
bool BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setVoxel(VoxelType tValue)
{
return mVolume->setVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume, tValue);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setWrapMode(WrapMode eWrapMode, VoxelType tBorder)
{
m_eWrapMode = eWrapMode;
m_tBorder = tBorder;
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveX(void)
{
mXPosInVolume++;
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveY(void)
{
mYPosInVolume++;
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveZ(void)
{
mZPosInVolume++;
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeX(void)
{
mXPosInVolume--;
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeY(void)
{
mYPosInVolume--;
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeZ(void)
{
mZPosInVolume--;
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1ny1nz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1ny0pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1ny1pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx0py1nz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx0py0pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx0py1pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1py1nz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1py0pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1py1pz(void) const
{
return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1);
}
//////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1ny1nz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1ny0pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1ny1pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px0py1nz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px0py0pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume , mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px0py1pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1py1nz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1py0pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1py1pz(void) const
{
return getVoxelImpl(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1);
}
//////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1ny1nz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1ny0pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1ny1pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px0py1nz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px0py0pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px0py1pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1py1nz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1py0pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume );
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1py1pz(void) const
{
return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1);
}
template <typename VoxelType>
template <typename DerivedVolumeType>
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
{
switch(m_eWrapMode)
{
case WrapModes::Validate:
return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Validate, m_tBorder);
case WrapModes::Clamp:
return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Clamp, m_tBorder);
case WrapModes::Border:
return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Border, m_tBorder);
case WrapModes::AssumeValid:
return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::AssumeValid, m_tBorder);
default:
// Should never happen
POLYVOX_ASSERT(false, "Invalid wrap mode");
return VoxelType();
}
}
}

View File

@ -1,158 +1,158 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_CubicSurfaceExtractor_H__
#define __PolyVox_CubicSurfaceExtractor_H__
#include "Impl/TypeDef.h"
#include "PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/Array.h"
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
#include "PolyVoxCore/Mesh.h"
#include "PolyVoxCore/Vertex.h"
namespace PolyVox
{
#ifdef SWIG
struct CubicVertex
#else
template<typename _DataType>
struct POLYVOX_API CubicVertex
#endif
{
typedef _DataType DataType;
// Each component of the position is stored as a single unsigned byte.
// The true position is found by offseting each component by 0.5f.
Vector3DUint8 encodedPosition;
// User data
DataType data;
};
// Convienient shorthand for declaring a mesh of 'cubic' vertices
// Currently disabled because it requires GCC 4.7
//template <typename VertexDataType, typename IndexType = DefaultIndexType>
//using CubicMesh = Mesh< CubicVertex<VertexDataType>, IndexType >;
/// Decodes a position from a CubicVertex
inline Vector3DFloat decodePosition(const Vector3DUint8& encodedPosition)
{
Vector3DFloat result(encodedPosition.getX(), encodedPosition.getY(), encodedPosition.getZ());
result -= 0.5f; // Apply the required offset
return result;
}
/// Decodes a MarchingCubesVertex by converting it into a regular Vertex which can then be directly used for rendering.
template<typename DataType>
Vertex<DataType> decodeVertex(const CubicVertex<DataType>& cubicVertex)
{
Vertex<DataType> result;
result.position = decodePosition(cubicVertex.encodedPosition);
result.normal.setElements(0.0f, 0.0f, 0.0f); // Currently not calculated
result.data = cubicVertex.data; // Data is not encoded
return result;
}
/// Do not use this class directly. Use the 'extractCubicSurface' function instead (see examples).
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
class CubicSurfaceExtractor
{
struct IndexAndMaterial
{
int32_t iIndex;
typename VolumeType::VoxelType uMaterial;
};
enum FaceNames
{
PositiveX,
PositiveY,
PositiveZ,
NegativeX,
NegativeY,
NegativeZ,
NoOfFaces
};
struct Quad
{
Quad(uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3)
{
vertices[0] = v0;
vertices[1] = v1;
vertices[2] = v2;
vertices[3] = v3;
}
uint32_t vertices[4];
};
public:
CubicSurfaceExtractor(VolumeType* volData, Region region, MeshType* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded(), WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true);
void execute();
private:
int32_t addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterial, Array<3, IndexAndMaterial>& existingVertices);
bool performQuadMerging(std::list<Quad>& quads);
bool mergeQuads(Quad& q1, Quad& q2);
IsQuadNeeded m_funcIsQuadNeededCallback;
//The volume data and a sampler to access it.
VolumeType* m_volData;
//Information about the region we are currently processing
Region m_regSizeInVoxels;
//The surface patch we are currently filling.
MeshType* m_meshCurrent;
//Used to avoid creating duplicate vertices.
Array<3, IndexAndMaterial> m_previousSliceVertices;
Array<3, IndexAndMaterial> m_currentSliceVertices;
//During extraction we create a number of different lists of quads. All the
//quads in a given list are in the same plane and facing in the same direction.
std::vector< std::list<Quad> > m_vecQuads[NoOfFaces];
//Controls whether quad merging should be performed. This might be undesirable
//is the user needs per-vertex attributes, or to perform per vertex lighting.
bool m_bMergeQuads;
//This constant defines the maximum number of quads which can share a
//vertex in a cubic style mesh. See the initialisation for more details.
static const uint32_t MaxVerticesPerPosition;
//The wrap mode
WrapMode m_eWrapMode;
typename VolumeType::VoxelType m_tBorderValue;
};
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_CubicSurfaceExtractor_H__
#define __PolyVox_CubicSurfaceExtractor_H__
#include "Impl/TypeDef.h"
#include "PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/Array.h"
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
#include "PolyVoxCore/Mesh.h"
#include "PolyVoxCore/Vertex.h"
namespace PolyVox
{
#ifdef SWIG
struct CubicVertex
#else
template<typename _DataType>
struct POLYVOX_API CubicVertex
#endif
{
typedef _DataType DataType;
// Each component of the position is stored as a single unsigned byte.
// The true position is found by offseting each component by 0.5f.
Vector3DUint8 encodedPosition;
// User data
DataType data;
};
// Convienient shorthand for declaring a mesh of 'cubic' vertices
// Currently disabled because it requires GCC 4.7
//template <typename VertexDataType, typename IndexType = DefaultIndexType>
//using CubicMesh = Mesh< CubicVertex<VertexDataType>, IndexType >;
/// Decodes a position from a CubicVertex
inline Vector3DFloat decodePosition(const Vector3DUint8& encodedPosition)
{
Vector3DFloat result(encodedPosition.getX(), encodedPosition.getY(), encodedPosition.getZ());
result -= 0.5f; // Apply the required offset
return result;
}
/// Decodes a MarchingCubesVertex by converting it into a regular Vertex which can then be directly used for rendering.
template<typename DataType>
Vertex<DataType> decodeVertex(const CubicVertex<DataType>& cubicVertex)
{
Vertex<DataType> result;
result.position = decodePosition(cubicVertex.encodedPosition);
result.normal.setElements(0.0f, 0.0f, 0.0f); // Currently not calculated
result.data = cubicVertex.data; // Data is not encoded
return result;
}
/// Do not use this class directly. Use the 'extractCubicSurface' function instead (see examples).
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
class CubicSurfaceExtractor
{
struct IndexAndMaterial
{
int32_t iIndex;
typename VolumeType::VoxelType uMaterial;
};
enum FaceNames
{
PositiveX,
PositiveY,
PositiveZ,
NegativeX,
NegativeY,
NegativeZ,
NoOfFaces
};
struct Quad
{
Quad(uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3)
{
vertices[0] = v0;
vertices[1] = v1;
vertices[2] = v2;
vertices[3] = v3;
}
uint32_t vertices[4];
};
public:
CubicSurfaceExtractor(VolumeType* volData, Region region, MeshType* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded(), WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true);
void execute();
private:
int32_t addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterial, Array<3, IndexAndMaterial>& existingVertices);
bool performQuadMerging(std::list<Quad>& quads);
bool mergeQuads(Quad& q1, Quad& q2);
IsQuadNeeded m_funcIsQuadNeededCallback;
//The volume data and a sampler to access it.
VolumeType* m_volData;
//Information about the region we are currently processing
Region m_regSizeInVoxels;
//The surface patch we are currently filling.
MeshType* m_meshCurrent;
//Used to avoid creating duplicate vertices.
Array<3, IndexAndMaterial> m_previousSliceVertices;
Array<3, IndexAndMaterial> m_currentSliceVertices;
//During extraction we create a number of different lists of quads. All the
//quads in a given list are in the same plane and facing in the same direction.
std::vector< std::list<Quad> > m_vecQuads[NoOfFaces];
//Controls whether quad merging should be performed. This might be undesirable
//is the user needs per-vertex attributes, or to perform per vertex lighting.
bool m_bMergeQuads;
//This constant defines the maximum number of quads which can share a
//vertex in a cubic style mesh. See the initialisation for more details.
static const uint32_t MaxVerticesPerPosition;
//The wrap mode
WrapMode m_eWrapMode;
typename VolumeType::VoxelType m_tBorderValue;
};
// This version of the function performs the extraction into a user-provided mesh rather than allocating a mesh automatically.
// There are a few reasons why this might be useful to more advanced users:
//
@ -165,64 +165,64 @@ namespace PolyVox
//
// Note: This function is called 'extractCubicMeshCustom' rather than 'extractCubicMesh' to avoid ambiguity when only three parameters
// are provided (would the third parameter be a controller or a mesh?). It seems this can be fixed by using enable_if/static_assert to emulate concepts,
// but this is relatively complex and I haven't done it yet. Could always add it later as another overload.
template<typename VolumeType, typename MeshType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> >
void extractCubicMeshCustom(VolumeType* volData, Region region, MeshType* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded(), WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true)
{
CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded> extractor(volData, region, result, isQuadNeeded, eWrapMode, tBorderValue, bMergeQuads);
extractor.execute();
}
/// The CubicSurfaceExtractor creates a mesh in which each voxel appears to be rendered as a cube
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Introduction
/// ------------
/// Games such as Minecraft and Voxatron have a unique graphical style in which each voxel in the world appears to be rendered as a single cube. Actually rendering a cube for each voxel would be very expensive, but in practice the only faces which need to be drawn are those which lie on the boundary between solid and empty voxels. The CubicSurfaceExtractor can be used to create such a mesh from PolyVox volume data. As an example, images from Minecraft and Voxatron are shown below:
///
/// \image html MinecraftAndVoxatron.jpg
///
/// Before we get into the specifics of the CubicSurfaceExtractor, it is useful to understand the principles which apply to *all* PolyVox surface extractors and which are described in the Surface Extraction document (ADD LINK). From here on, it is assumed that you are familier with PolyVox regions and how they are used to limit surface extraction to a particular part of the volume. The principles of allowing dynamic terrain are also common to all surface extractors and are described here (ADD LINK).
///
/// Basic Operation
/// ---------------
/// At its core, the CubicSurfaceExtractor works by by looking at pairs of adjacent voxels and determining whether a quad should be placed between then. The most simple situation to imagine is a binary volume where every voxel is either solid or empty. In this case a quad should be generated whenever a solid voxel is next to an empty voxel as this represents part of the surface of the solid object. There is no need to generate a quad between two solid voxels (this quad would never be seen as it is inside the object) and there is no need to generate a quad between two empty voxels (there is no object here). PolyVox allows the principle to be extended far beyond such simple binary volumes but they provide a useful starting point for understanding how the algorithm works.
///
/// As an example, lets consider the part of a volume shown below. We are going to explain the principles in only two dimensions as this makes it much simpler to illustrate, so you will need to mentally extend the process into the third dimension. Hopefully you will find this intuitive. The diagram below shows a small part of a larger volume (as indicated by the voxel coordinates on the axes) which contains only solid and empty voxels represented by solid and hollow circles respectively. The region on which we are running the surface extractor is marked in pink, and for the purpose of this example it corresponds to the whole of the diagram.
///
/// \image html CubicSurfaceExtractor1.png
///
/// The output of the surface extractor is the mesh marked in red. As you can see, this forms a closed object which corrsponds to the shape of the underlying voxel data. We won't describe the rendering of such meshes here - for details of this please see (SOME LINK HERE).
///
/// Working with Regions
/// --------------------
/// So far the behaviour is easy to understand, but let's look at what happens when the extraction is limited to a particular region of the volume. The figure below shows the same data set as the previous figure, but the extraction region (still marked in pink) has been limited to 13 to 16 in x and 47 to 51 in y:
///
/// \image html CubicSurfaceExtractor2.png
///
/// As you can see, the extractor continues to generate a number of quads as indicated by the solid red lines. However, you can also see that the shape is no longer closed. This is because the solid voxels actually extend outside the region which is being processed, and so the extractor does not encounter a boundary between solid and empty voxels. Although this may initially appear problematic, the hole in the mesh does not actually matter because it will be hidden by the mesh corresponding to the region adjacent to it (see next diagram).
///
/// More interestingly, the diagram also contains a couple of dotted red lines lying on the bottom and right hand side of the extracted region. These are present to illustrate a common point of confusion, which is that *no quads are generated at this position even though it is a boundary between solid and empty voxels*. This is indeed somewhat counter intuitive but there is a rational reasaoning behind it.
/// If you consider the dashed line on the righthand side of the extracted region, then it is clear that this lies on a boundary between solid and empty voxels and so we do need to create quads here. But what is not so clear is whether these quads should be assigned to the mesh which corresponds to the region in pink, or whether they should be assigned to the region to the right of it which is marked in blue in the diagram below:
///
/// \image html CubicSurfaceExtractor3.png
///
/// We could choose to add the quads to *both* regions, but this can cause confusion when one of the region is modified (causing the face to disappear or a new one to be created) as *both* regions need to have their mesh regenerated to correctly represent the new state of the volume data. Such pairs of coplanar quads can also cause problems with physics engines, and may prevent transparent voxels from rendering correctly. Therefore we choose to instead only add the quad to one of the the regions and we always choose the one with the greater coordinate value in the direction in which they differ. In the above example the regions differ by the 'x' component of their position, and so the quad is added to the region with the greater 'x' value (the one marked in blue).
///
/// **Note:** *This behaviour has changed recently (September 2012). Earlier versions of PolyVox tried to be smart about this problem by looking beyond the region which was being processed, but this complicated the code and didn't work very well. Ultimatly we decided to simply stick with the convention outlined above.*
///
/// One of the practical implications of this is that when you modify a voxel *you may have to re-extract the mesh for regions other than region which actually contains the voxel you modified.* This happens when the voxel lies on the upper x,y or z face of a region. Assuming that you have some management code which can mark a region as needing re-extraction when a voxel changes, you should probably extend this to mark the regions of neighbouring voxels as invalid (this will have no effect when the voxel is well within a region, but will mark the neighbouring region as needing an update if the voxel lies on a region face).
///
/// Another scenario which sometimes results in confusion is when you wish to extract a region which corresponds to the whole volume, partcularly when solid voxels extend right to the edge of the volume.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> >
Mesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, IsQuadNeeded isQuadNeeded = IsQuadNeeded(), WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true)
{
Mesh< CubicVertex<typename VolumeType::VoxelType> > result;
extractCubicMeshCustom(volData, region, &result, isQuadNeeded, eWrapMode, tBorderValue, bMergeQuads);
return result;
}
}
#include "PolyVoxCore/CubicSurfaceExtractor.inl"
#endif
// but this is relatively complex and I haven't done it yet. Could always add it later as another overload.
template<typename VolumeType, typename MeshType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> >
void extractCubicMeshCustom(VolumeType* volData, Region region, MeshType* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded(), WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true)
{
CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded> extractor(volData, region, result, isQuadNeeded, eWrapMode, tBorderValue, bMergeQuads);
extractor.execute();
}
/// The CubicSurfaceExtractor creates a mesh in which each voxel appears to be rendered as a cube
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Introduction
/// ------------
/// Games such as Minecraft and Voxatron have a unique graphical style in which each voxel in the world appears to be rendered as a single cube. Actually rendering a cube for each voxel would be very expensive, but in practice the only faces which need to be drawn are those which lie on the boundary between solid and empty voxels. The CubicSurfaceExtractor can be used to create such a mesh from PolyVox volume data. As an example, images from Minecraft and Voxatron are shown below:
///
/// \image html MinecraftAndVoxatron.jpg
///
/// Before we get into the specifics of the CubicSurfaceExtractor, it is useful to understand the principles which apply to *all* PolyVox surface extractors and which are described in the Surface Extraction document (ADD LINK). From here on, it is assumed that you are familier with PolyVox regions and how they are used to limit surface extraction to a particular part of the volume. The principles of allowing dynamic terrain are also common to all surface extractors and are described here (ADD LINK).
///
/// Basic Operation
/// ---------------
/// At its core, the CubicSurfaceExtractor works by by looking at pairs of adjacent voxels and determining whether a quad should be placed between then. The most simple situation to imagine is a binary volume where every voxel is either solid or empty. In this case a quad should be generated whenever a solid voxel is next to an empty voxel as this represents part of the surface of the solid object. There is no need to generate a quad between two solid voxels (this quad would never be seen as it is inside the object) and there is no need to generate a quad between two empty voxels (there is no object here). PolyVox allows the principle to be extended far beyond such simple binary volumes but they provide a useful starting point for understanding how the algorithm works.
///
/// As an example, lets consider the part of a volume shown below. We are going to explain the principles in only two dimensions as this makes it much simpler to illustrate, so you will need to mentally extend the process into the third dimension. Hopefully you will find this intuitive. The diagram below shows a small part of a larger volume (as indicated by the voxel coordinates on the axes) which contains only solid and empty voxels represented by solid and hollow circles respectively. The region on which we are running the surface extractor is marked in pink, and for the purpose of this example it corresponds to the whole of the diagram.
///
/// \image html CubicSurfaceExtractor1.png
///
/// The output of the surface extractor is the mesh marked in red. As you can see, this forms a closed object which corrsponds to the shape of the underlying voxel data. We won't describe the rendering of such meshes here - for details of this please see (SOME LINK HERE).
///
/// Working with Regions
/// --------------------
/// So far the behaviour is easy to understand, but let's look at what happens when the extraction is limited to a particular region of the volume. The figure below shows the same data set as the previous figure, but the extraction region (still marked in pink) has been limited to 13 to 16 in x and 47 to 51 in y:
///
/// \image html CubicSurfaceExtractor2.png
///
/// As you can see, the extractor continues to generate a number of quads as indicated by the solid red lines. However, you can also see that the shape is no longer closed. This is because the solid voxels actually extend outside the region which is being processed, and so the extractor does not encounter a boundary between solid and empty voxels. Although this may initially appear problematic, the hole in the mesh does not actually matter because it will be hidden by the mesh corresponding to the region adjacent to it (see next diagram).
///
/// More interestingly, the diagram also contains a couple of dotted red lines lying on the bottom and right hand side of the extracted region. These are present to illustrate a common point of confusion, which is that *no quads are generated at this position even though it is a boundary between solid and empty voxels*. This is indeed somewhat counter intuitive but there is a rational reasaoning behind it.
/// If you consider the dashed line on the righthand side of the extracted region, then it is clear that this lies on a boundary between solid and empty voxels and so we do need to create quads here. But what is not so clear is whether these quads should be assigned to the mesh which corresponds to the region in pink, or whether they should be assigned to the region to the right of it which is marked in blue in the diagram below:
///
/// \image html CubicSurfaceExtractor3.png
///
/// We could choose to add the quads to *both* regions, but this can cause confusion when one of the region is modified (causing the face to disappear or a new one to be created) as *both* regions need to have their mesh regenerated to correctly represent the new state of the volume data. Such pairs of coplanar quads can also cause problems with physics engines, and may prevent transparent voxels from rendering correctly. Therefore we choose to instead only add the quad to one of the the regions and we always choose the one with the greater coordinate value in the direction in which they differ. In the above example the regions differ by the 'x' component of their position, and so the quad is added to the region with the greater 'x' value (the one marked in blue).
///
/// **Note:** *This behaviour has changed recently (September 2012). Earlier versions of PolyVox tried to be smart about this problem by looking beyond the region which was being processed, but this complicated the code and didn't work very well. Ultimatly we decided to simply stick with the convention outlined above.*
///
/// One of the practical implications of this is that when you modify a voxel *you may have to re-extract the mesh for regions other than region which actually contains the voxel you modified.* This happens when the voxel lies on the upper x,y or z face of a region. Assuming that you have some management code which can mark a region as needing re-extraction when a voxel changes, you should probably extend this to mark the regions of neighbouring voxels as invalid (this will have no effect when the voxel is well within a region, but will mark the neighbouring region as needing an update if the voxel lies on a region face).
///
/// Another scenario which sometimes results in confusion is when you wish to extract a region which corresponds to the whole volume, partcularly when solid voxels extend right to the edge of the volume.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> >
Mesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, IsQuadNeeded isQuadNeeded = IsQuadNeeded(), WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true)
{
Mesh< CubicVertex<typename VolumeType::VoxelType> > result;
extractCubicMeshCustom(volData, region, &result, isQuadNeeded, eWrapMode, tBorderValue, bMergeQuads);
return result;
}
}
#include "PolyVoxCore/CubicSurfaceExtractor.inl"
#endif

View File

@ -1,310 +1,310 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Impl/Timer.h"
namespace PolyVox
{
// We try to avoid duplicate vertices by checking whether a vertex has already been added at a given position.
// However, it is possible that vertices have the same position but different materials. In this case, the
// vertices are not true duplicates and both must be added to the mesh. As far as I can tell, it is possible to have
// at most eight vertices with the same position but different materials. For example, this worst-case scenario
// happens when we have a 2x2x2 group of voxels, all with different materials and some/all partially transparent.
// The vertex position at the center of this group is then going to be used by all eight voxels all with different
// materials.
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
const uint32_t CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::MaxVerticesPerPosition = 8;
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, MeshType* result, IsQuadNeeded isQuadNeeded, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads)
:m_volData(volData)
,m_regSizeInVoxels(region)
,m_meshCurrent(result)
,m_bMergeQuads(bMergeQuads)
,m_eWrapMode(eWrapMode)
,m_tBorderValue(tBorderValue)
,m_previousSliceVertices(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2, m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2, MaxVerticesPerPosition)
,m_currentSliceVertices(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2, m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2, MaxVerticesPerPosition)
{
m_funcIsQuadNeededCallback = isQuadNeeded;
// This extractor has a limit as to how large the extracted region can be, because the vertex positions are encoded with a single byte per component.
int32_t maxReionDimension = 256;
POLYVOX_THROW_IF(region.getWidthInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions");
POLYVOX_THROW_IF(region.getHeightInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions");
POLYVOX_THROW_IF(region.getDepthInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions");
}
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
void CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::execute()
{
Timer timer;
m_meshCurrent->clear();
//uint32_t uArrayWidth = m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2;
//uint32_t uArrayHeight = m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2;
//uint32_t arraySize[3]= {uArrayWidth, uArrayHeight, MaxVerticesPerPosition};
//m_previousSliceVertices.resize(arraySize);
//m_currentSliceVertices.resize(arraySize);
memset(m_previousSliceVertices.getRawData(), 0xff, m_previousSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
m_vecQuads[NegativeX].resize(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2);
m_vecQuads[PositiveX].resize(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2);
m_vecQuads[NegativeY].resize(m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2);
m_vecQuads[PositiveY].resize(m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2);
m_vecQuads[NegativeZ].resize(m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ() + 2);
m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ() + 2);
typename VolumeType::Sampler volumeSampler(m_volData);
volumeSampler.setWrapMode(m_eWrapMode, m_tBorderValue);
for(int32_t z = m_regSizeInVoxels.getLowerZ(); z <= m_regSizeInVoxels.getUpperZ(); z++)
{
uint32_t regZ = z - m_regSizeInVoxels.getLowerZ();
for(int32_t y = m_regSizeInVoxels.getLowerY(); y <= m_regSizeInVoxels.getUpperY(); y++)
{
uint32_t regY = y - m_regSizeInVoxels.getLowerY();
volumeSampler.setPosition(m_regSizeInVoxels.getLowerX(),y,z);
for(int32_t x = m_regSizeInVoxels.getLowerX(); x <= m_regSizeInVoxels.getUpperX(); x++)
{
uint32_t regX = x - m_regSizeInVoxels.getLowerX();
typename VolumeType::VoxelType material; //Filled in by callback
typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel();
typename VolumeType::VoxelType negXVoxel = volumeSampler.peekVoxel1nx0py0pz();
typename VolumeType::VoxelType negYVoxel = volumeSampler.peekVoxel0px1ny0pz();
typename VolumeType::VoxelType negZVoxel = volumeSampler.peekVoxel0px0py1nz();
// X
if(m_funcIsQuadNeededCallback(currentVoxel, negXVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
uint32_t v2 = addVertex(regX , regY + 1, regZ + 1, material, m_currentSliceVertices);
uint32_t v3 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
m_vecQuads[NegativeX][regX].push_back(Quad(v0, v1, v2, v3));
}
if(m_funcIsQuadNeededCallback(negXVoxel, currentVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
uint32_t v2 = addVertex(regX , regY + 1, regZ + 1, material, m_currentSliceVertices);
uint32_t v3 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
m_vecQuads[PositiveX][regX].push_back(Quad(v0, v3, v2, v1));
}
// Y
if(m_funcIsQuadNeededCallback(currentVoxel, negYVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
uint32_t v2 = addVertex(regX + 1, regY , regZ + 1, material, m_currentSliceVertices);
uint32_t v3 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
m_vecQuads[NegativeY][regY].push_back(Quad(v0, v1, v2, v3));
}
if(m_funcIsQuadNeededCallback(negYVoxel, currentVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
uint32_t v2 = addVertex(regX + 1, regY , regZ + 1, material, m_currentSliceVertices);
uint32_t v3 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
m_vecQuads[PositiveY][regY].push_back(Quad(v0, v3, v2, v1));
}
// Z
if(m_funcIsQuadNeededCallback(currentVoxel, negZVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
uint32_t v2 = addVertex(regX + 1, regY + 1, regZ , material, m_previousSliceVertices);
uint32_t v3 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
m_vecQuads[NegativeZ][regZ].push_back(Quad(v0, v1, v2, v3));
}
if(m_funcIsQuadNeededCallback(negZVoxel, currentVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
uint32_t v2 = addVertex(regX + 1, regY + 1, regZ , material, m_previousSliceVertices);
uint32_t v3 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1));
}
volumeSampler.movePositiveX();
}
}
m_previousSliceVertices.swap(m_currentSliceVertices);
memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
}
for(uint32_t uFace = 0; uFace < NoOfFaces; uFace++)
{
std::vector< std::list<Quad> >& vecListQuads = m_vecQuads[uFace];
for(uint32_t slice = 0; slice < vecListQuads.size(); slice++)
{
std::list<Quad>& listQuads = vecListQuads[slice];
if(m_bMergeQuads)
{
//Repeatedly call this function until it returns
//false to indicate nothing more can be done.
while(performQuadMerging(listQuads)){}
}
typename std::list<Quad>::iterator iterEnd = listQuads.end();
for(typename std::list<Quad>::iterator quadIter = listQuads.begin(); quadIter != iterEnd; quadIter++)
{
Quad& quad = *quadIter;
m_meshCurrent->addTriangle(quad.vertices[0], quad.vertices[1],quad.vertices[2]);
m_meshCurrent->addTriangle(quad.vertices[0], quad.vertices[2],quad.vertices[3]);
}
}
}
m_meshCurrent->setOffset(m_regSizeInVoxels.getLowerCorner());
m_meshCurrent->removeUnusedVertices();
POLYVOX_LOG_TRACE("Cubic surface extraction took " << timer.elapsedTimeInMilliSeconds()
<< "ms (Region size = " << m_regSizeInVoxels.getWidthInVoxels() << "x" << m_regSizeInVoxels.getHeightInVoxels()
<< "x" << m_regSizeInVoxels.getDepthInVoxels() << ")");
}
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
int32_t CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
{
for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++)
{
IndexAndMaterial& rEntry = existingVertices(uX, uY, ct);
if(rEntry.iIndex == -1)
{
//No vertices matched and we've now hit an empty space. Fill it by creating a vertex. The 0.5f offset is because vertices set between voxels in order to build cubes around them.
CubicVertex<typename VolumeType::VoxelType> cubicVertex;
cubicVertex.encodedPosition.setElements(static_cast<uint8_t>(uX), static_cast<uint8_t>(uY), static_cast<uint8_t>(uZ));
cubicVertex.data = uMaterialIn;
rEntry.iIndex = m_meshCurrent->addVertex(cubicVertex);
rEntry.uMaterial = uMaterialIn;
return rEntry.iIndex;
}
//If we have an existing vertex and the material matches then we can return it.
if(rEntry.uMaterial == uMaterialIn)
{
return rEntry.iIndex;
}
}
// If we exit the loop here then apparently all the slots were full but none of them matched.
// This shouldn't ever happen, so if it does it is probably a bug in PolyVox. Please report it to us!
POLYVOX_THROW(std::runtime_error, "All slots full but no matches during cubic surface extraction. This is probably a bug in PolyVox");
return -1; //Should never happen.
}
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
bool CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::performQuadMerging(std::list<Quad>& quads)
{
bool bDidMerge = false;
for(typename std::list<Quad>::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++)
{
typename std::list<Quad>::iterator innerIter = outerIter;
innerIter++;
while(innerIter != quads.end())
{
Quad& q1 = *outerIter;
Quad& q2 = *innerIter;
bool result = mergeQuads(q1,q2);
if(result)
{
bDidMerge = true;
innerIter = quads.erase(innerIter);
}
else
{
innerIter++;
}
}
}
return bDidMerge;
}
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
bool CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::mergeQuads(Quad& q1, Quad& q2)
{
//All four vertices of a given quad have the same data,
//so just check that the first pair of vertices match.
if (m_meshCurrent->getVertices()[q1.vertices[0]].data == m_meshCurrent->getVertices()[q2.vertices[0]].data)
{
//Now check whether quad 2 is adjacent to quad one by comparing vertices.
//Adjacent quads must share two vertices, and the second quad could be to the
//top, bottom, left, of right of the first one. This gives four combinations to test.
if((q1.vertices[0] == q2.vertices[1]) && ((q1.vertices[3] == q2.vertices[2])))
{
q1.vertices[0] = q2.vertices[0];
q1.vertices[3] = q2.vertices[3];
return true;
}
else if((q1.vertices[3] == q2.vertices[0]) && ((q1.vertices[2] == q2.vertices[1])))
{
q1.vertices[3] = q2.vertices[3];
q1.vertices[2] = q2.vertices[2];
return true;
}
else if((q1.vertices[1] == q2.vertices[0]) && ((q1.vertices[2] == q2.vertices[3])))
{
q1.vertices[1] = q2.vertices[1];
q1.vertices[2] = q2.vertices[2];
return true;
}
else if((q1.vertices[0] == q2.vertices[3]) && ((q1.vertices[1] == q2.vertices[2])))
{
q1.vertices[0] = q2.vertices[0];
q1.vertices[1] = q2.vertices[1];
return true;
}
}
//Quads cannot be merged.
return false;
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Impl/Timer.h"
namespace PolyVox
{
// We try to avoid duplicate vertices by checking whether a vertex has already been added at a given position.
// However, it is possible that vertices have the same position but different materials. In this case, the
// vertices are not true duplicates and both must be added to the mesh. As far as I can tell, it is possible to have
// at most eight vertices with the same position but different materials. For example, this worst-case scenario
// happens when we have a 2x2x2 group of voxels, all with different materials and some/all partially transparent.
// The vertex position at the center of this group is then going to be used by all eight voxels all with different
// materials.
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
const uint32_t CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::MaxVerticesPerPosition = 8;
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, MeshType* result, IsQuadNeeded isQuadNeeded, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads)
:m_volData(volData)
,m_regSizeInVoxels(region)
,m_meshCurrent(result)
,m_bMergeQuads(bMergeQuads)
,m_eWrapMode(eWrapMode)
,m_tBorderValue(tBorderValue)
,m_previousSliceVertices(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2, m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2, MaxVerticesPerPosition)
,m_currentSliceVertices(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2, m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2, MaxVerticesPerPosition)
{
m_funcIsQuadNeededCallback = isQuadNeeded;
// This extractor has a limit as to how large the extracted region can be, because the vertex positions are encoded with a single byte per component.
int32_t maxReionDimension = 256;
POLYVOX_THROW_IF(region.getWidthInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions");
POLYVOX_THROW_IF(region.getHeightInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions");
POLYVOX_THROW_IF(region.getDepthInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions");
}
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
void CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::execute()
{
Timer timer;
m_meshCurrent->clear();
//uint32_t uArrayWidth = m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2;
//uint32_t uArrayHeight = m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2;
//uint32_t arraySize[3]= {uArrayWidth, uArrayHeight, MaxVerticesPerPosition};
//m_previousSliceVertices.resize(arraySize);
//m_currentSliceVertices.resize(arraySize);
memset(m_previousSliceVertices.getRawData(), 0xff, m_previousSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
m_vecQuads[NegativeX].resize(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2);
m_vecQuads[PositiveX].resize(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2);
m_vecQuads[NegativeY].resize(m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2);
m_vecQuads[PositiveY].resize(m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2);
m_vecQuads[NegativeZ].resize(m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ() + 2);
m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ() + 2);
typename VolumeType::Sampler volumeSampler(m_volData);
volumeSampler.setWrapMode(m_eWrapMode, m_tBorderValue);
for(int32_t z = m_regSizeInVoxels.getLowerZ(); z <= m_regSizeInVoxels.getUpperZ(); z++)
{
uint32_t regZ = z - m_regSizeInVoxels.getLowerZ();
for(int32_t y = m_regSizeInVoxels.getLowerY(); y <= m_regSizeInVoxels.getUpperY(); y++)
{
uint32_t regY = y - m_regSizeInVoxels.getLowerY();
volumeSampler.setPosition(m_regSizeInVoxels.getLowerX(),y,z);
for(int32_t x = m_regSizeInVoxels.getLowerX(); x <= m_regSizeInVoxels.getUpperX(); x++)
{
uint32_t regX = x - m_regSizeInVoxels.getLowerX();
typename VolumeType::VoxelType material; //Filled in by callback
typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel();
typename VolumeType::VoxelType negXVoxel = volumeSampler.peekVoxel1nx0py0pz();
typename VolumeType::VoxelType negYVoxel = volumeSampler.peekVoxel0px1ny0pz();
typename VolumeType::VoxelType negZVoxel = volumeSampler.peekVoxel0px0py1nz();
// X
if(m_funcIsQuadNeededCallback(currentVoxel, negXVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
uint32_t v2 = addVertex(regX , regY + 1, regZ + 1, material, m_currentSliceVertices);
uint32_t v3 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
m_vecQuads[NegativeX][regX].push_back(Quad(v0, v1, v2, v3));
}
if(m_funcIsQuadNeededCallback(negXVoxel, currentVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
uint32_t v2 = addVertex(regX , regY + 1, regZ + 1, material, m_currentSliceVertices);
uint32_t v3 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
m_vecQuads[PositiveX][regX].push_back(Quad(v0, v3, v2, v1));
}
// Y
if(m_funcIsQuadNeededCallback(currentVoxel, negYVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
uint32_t v2 = addVertex(regX + 1, regY , regZ + 1, material, m_currentSliceVertices);
uint32_t v3 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
m_vecQuads[NegativeY][regY].push_back(Quad(v0, v1, v2, v3));
}
if(m_funcIsQuadNeededCallback(negYVoxel, currentVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
uint32_t v2 = addVertex(regX + 1, regY , regZ + 1, material, m_currentSliceVertices);
uint32_t v3 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
m_vecQuads[PositiveY][regY].push_back(Quad(v0, v3, v2, v1));
}
// Z
if(m_funcIsQuadNeededCallback(currentVoxel, negZVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
uint32_t v2 = addVertex(regX + 1, regY + 1, regZ , material, m_previousSliceVertices);
uint32_t v3 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
m_vecQuads[NegativeZ][regZ].push_back(Quad(v0, v1, v2, v3));
}
if(m_funcIsQuadNeededCallback(negZVoxel, currentVoxel, material))
{
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
uint32_t v1 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
uint32_t v2 = addVertex(regX + 1, regY + 1, regZ , material, m_previousSliceVertices);
uint32_t v3 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1));
}
volumeSampler.movePositiveX();
}
}
m_previousSliceVertices.swap(m_currentSliceVertices);
memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
}
for(uint32_t uFace = 0; uFace < NoOfFaces; uFace++)
{
std::vector< std::list<Quad> >& vecListQuads = m_vecQuads[uFace];
for(uint32_t slice = 0; slice < vecListQuads.size(); slice++)
{
std::list<Quad>& listQuads = vecListQuads[slice];
if(m_bMergeQuads)
{
//Repeatedly call this function until it returns
//false to indicate nothing more can be done.
while(performQuadMerging(listQuads)){}
}
typename std::list<Quad>::iterator iterEnd = listQuads.end();
for(typename std::list<Quad>::iterator quadIter = listQuads.begin(); quadIter != iterEnd; quadIter++)
{
Quad& quad = *quadIter;
m_meshCurrent->addTriangle(quad.vertices[0], quad.vertices[1],quad.vertices[2]);
m_meshCurrent->addTriangle(quad.vertices[0], quad.vertices[2],quad.vertices[3]);
}
}
}
m_meshCurrent->setOffset(m_regSizeInVoxels.getLowerCorner());
m_meshCurrent->removeUnusedVertices();
POLYVOX_LOG_TRACE("Cubic surface extraction took " << timer.elapsedTimeInMilliSeconds()
<< "ms (Region size = " << m_regSizeInVoxels.getWidthInVoxels() << "x" << m_regSizeInVoxels.getHeightInVoxels()
<< "x" << m_regSizeInVoxels.getDepthInVoxels() << ")");
}
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
int32_t CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
{
for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++)
{
IndexAndMaterial& rEntry = existingVertices(uX, uY, ct);
if(rEntry.iIndex == -1)
{
//No vertices matched and we've now hit an empty space. Fill it by creating a vertex. The 0.5f offset is because vertices set between voxels in order to build cubes around them.
CubicVertex<typename VolumeType::VoxelType> cubicVertex;
cubicVertex.encodedPosition.setElements(static_cast<uint8_t>(uX), static_cast<uint8_t>(uY), static_cast<uint8_t>(uZ));
cubicVertex.data = uMaterialIn;
rEntry.iIndex = m_meshCurrent->addVertex(cubicVertex);
rEntry.uMaterial = uMaterialIn;
return rEntry.iIndex;
}
//If we have an existing vertex and the material matches then we can return it.
if(rEntry.uMaterial == uMaterialIn)
{
return rEntry.iIndex;
}
}
// If we exit the loop here then apparently all the slots were full but none of them matched.
// This shouldn't ever happen, so if it does it is probably a bug in PolyVox. Please report it to us!
POLYVOX_THROW(std::runtime_error, "All slots full but no matches during cubic surface extraction. This is probably a bug in PolyVox");
return -1; //Should never happen.
}
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
bool CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::performQuadMerging(std::list<Quad>& quads)
{
bool bDidMerge = false;
for(typename std::list<Quad>::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++)
{
typename std::list<Quad>::iterator innerIter = outerIter;
innerIter++;
while(innerIter != quads.end())
{
Quad& q1 = *outerIter;
Quad& q2 = *innerIter;
bool result = mergeQuads(q1,q2);
if(result)
{
bDidMerge = true;
innerIter = quads.erase(innerIter);
}
else
{
innerIter++;
}
}
}
return bDidMerge;
}
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
bool CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::mergeQuads(Quad& q1, Quad& q2)
{
//All four vertices of a given quad have the same data,
//so just check that the first pair of vertices match.
if (m_meshCurrent->getVertices()[q1.vertices[0]].data == m_meshCurrent->getVertices()[q2.vertices[0]].data)
{
//Now check whether quad 2 is adjacent to quad one by comparing vertices.
//Adjacent quads must share two vertices, and the second quad could be to the
//top, bottom, left, of right of the first one. This gives four combinations to test.
if((q1.vertices[0] == q2.vertices[1]) && ((q1.vertices[3] == q2.vertices[2])))
{
q1.vertices[0] = q2.vertices[0];
q1.vertices[3] = q2.vertices[3];
return true;
}
else if((q1.vertices[3] == q2.vertices[0]) && ((q1.vertices[2] == q2.vertices[1])))
{
q1.vertices[3] = q2.vertices[3];
q1.vertices[2] = q2.vertices[2];
return true;
}
else if((q1.vertices[1] == q2.vertices[0]) && ((q1.vertices[2] == q2.vertices[3])))
{
q1.vertices[1] = q2.vertices[1];
q1.vertices[2] = q2.vertices[2];
return true;
}
else if((q1.vertices[0] == q2.vertices[3]) && ((q1.vertices[1] == q2.vertices[2])))
{
q1.vertices[0] = q2.vertices[0];
q1.vertices[1] = q2.vertices[1];
return true;
}
}
//Quads cannot be merged.
return false;
}
}

View File

@ -1,52 +1,52 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_DefaultIsQuadNeeded_H__
#define __PolyVox_DefaultIsQuadNeeded_H__
#include "PolyVoxCore/Impl/TypeDef.h"
#include <cstdint>
namespace PolyVox
{
template<typename VoxelType>
class DefaultIsQuadNeeded
{
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_DefaultIsQuadNeeded_H__
#define __PolyVox_DefaultIsQuadNeeded_H__
#include "PolyVoxCore/Impl/TypeDef.h"
#include <cstdint>
namespace PolyVox
{
template<typename VoxelType>
class DefaultIsQuadNeeded
{
public:
bool operator()(VoxelType back, VoxelType front, VoxelType& materialToUse)
{
if((back > 0) && (front == 0))
{
bool operator()(VoxelType back, VoxelType front, VoxelType& materialToUse)
{
if((back > 0) && (front == 0))
{
materialToUse = static_cast<VoxelType>(back);
return true;
}
else
{
return false;
}
}
};
}
return true;
}
else
{
return false;
}
}
};
}
#endif //__PolyVox_DefaultIsQuadNeeded_H__

View File

@ -1,191 +1,191 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Density_H__
#define __PolyVox_Density_H__
#include "PolyVoxCore/DefaultMarchingCubesController.h" //We'll specialise the controller contained in here
#include "Impl/TypeDef.h"
#include <limits>
#undef min
#undef max
namespace PolyVox
{
/// This class represents a voxel storing only a density.
////////////////////////////////////////////////////////////////////////////////
/// Detailed description...
////////////////////////////////////////////////////////////////////////////////
template <typename Type>
class Density
{
public:
/// Constructor
Density() : m_uDensity(0) {}
/// Copy constructor
Density(Type uDensity) : m_uDensity(uDensity) {}
// The LowPassFilter uses this to convert between normal and accumulated types.
/// Copy constructor with cast
template <typename CastType> explicit Density(const Density<CastType>& density)
{
m_uDensity = static_cast<Type>(density.getDensity());
}
bool operator==(const Density& rhs) const
{
return (m_uDensity == rhs.m_uDensity);
};
bool operator!=(const Density& rhs) const
{
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<Type>& operator+=(const Density<Type>& rhs)
{
m_uDensity += rhs.m_uDensity;
return *this;
}
Density<Type>& operator-=(const Density<Type>& rhs)
{
m_uDensity -= rhs.m_uDensity;
return *this;
}
Density<Type>& operator/=(uint32_t rhs)
{
m_uDensity /= rhs;
return *this;
}
/// \return The current density of the voxel
Type getDensity() const { return m_uDensity; }
/**
* Set the density of the voxel
*
* \param uDensity The density to set to
*/
void setDensity(Type uDensity) { m_uDensity = uDensity; }
/// \return The maximum allowed density of the voxel
static Type getMaxDensity() { return (std::numeric_limits<Type>::max)(); }
/// \return The minimum allowed density of the voxel
static Type getMinDensity() { return (std::numeric_limits<Type>::min)(); }
private:
Type m_uDensity;
};
template <typename Type>
Density<Type> operator+(const Density<Type>& lhs, const Density<Type>& rhs)
{
Density<Type> result = lhs;
result += rhs;
return result;
}
template <typename Type>
Density<Type> operator-(const Density<Type>& lhs, const Density<Type>& rhs)
{
Density<Type> result = lhs;
result -= rhs;
return result;
}
template <typename Type>
Density<Type> operator/(const Density<Type>& lhs, uint32_t rhs)
{
Density<Type> 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<uint8_t> Density8;
typedef Density<uint16_t> Density16;
typedef Density<uint32_t> Density32;
typedef Density<float> DensityFloat;
/**
* This is a specialisation of DefaultMarchingCubesController for the Density voxel type
*/
template <typename Type>
class DefaultMarchingCubesController< Density<Type> >
{
public:
typedef Type DensityType;
typedef float MaterialType;
DefaultMarchingCubesController(void)
{
// Default to a threshold value halfway between the min and max possible values.
m_tThreshold = (Density<Type>::getMinDensity() + Density<Type>::getMaxDensity()) / 2;
}
DefaultMarchingCubesController(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
DensityType convertToDensity(Density<Type> voxel)
{
return voxel.getDensity();
}
MaterialType convertToMaterial(Density<Type> /*voxel*/)
{
return 1;
}
MaterialType blendMaterials(Density<Type> /*a*/, Density<Type> /*b*/, float /*weight*/)
{
return 1;
}
DensityType getThreshold(void)
{
return m_tThreshold;
}
void setThreshold(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
private:
DensityType m_tThreshold;
};
}
#endif //__PolyVox_Density_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Density_H__
#define __PolyVox_Density_H__
#include "PolyVoxCore/DefaultMarchingCubesController.h" //We'll specialise the controller contained in here
#include "Impl/TypeDef.h"
#include <limits>
#undef min
#undef max
namespace PolyVox
{
/// This class represents a voxel storing only a density.
////////////////////////////////////////////////////////////////////////////////
/// Detailed description...
////////////////////////////////////////////////////////////////////////////////
template <typename Type>
class Density
{
public:
/// Constructor
Density() : m_uDensity(0) {}
/// Copy constructor
Density(Type uDensity) : m_uDensity(uDensity) {}
// The LowPassFilter uses this to convert between normal and accumulated types.
/// Copy constructor with cast
template <typename CastType> explicit Density(const Density<CastType>& density)
{
m_uDensity = static_cast<Type>(density.getDensity());
}
bool operator==(const Density& rhs) const
{
return (m_uDensity == rhs.m_uDensity);
};
bool operator!=(const Density& rhs) const
{
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<Type>& operator+=(const Density<Type>& rhs)
{
m_uDensity += rhs.m_uDensity;
return *this;
}
Density<Type>& operator-=(const Density<Type>& rhs)
{
m_uDensity -= rhs.m_uDensity;
return *this;
}
Density<Type>& operator/=(uint32_t rhs)
{
m_uDensity /= rhs;
return *this;
}
/// \return The current density of the voxel
Type getDensity() const { return m_uDensity; }
/**
* Set the density of the voxel
*
* \param uDensity The density to set to
*/
void setDensity(Type uDensity) { m_uDensity = uDensity; }
/// \return The maximum allowed density of the voxel
static Type getMaxDensity() { return (std::numeric_limits<Type>::max)(); }
/// \return The minimum allowed density of the voxel
static Type getMinDensity() { return (std::numeric_limits<Type>::min)(); }
private:
Type m_uDensity;
};
template <typename Type>
Density<Type> operator+(const Density<Type>& lhs, const Density<Type>& rhs)
{
Density<Type> result = lhs;
result += rhs;
return result;
}
template <typename Type>
Density<Type> operator-(const Density<Type>& lhs, const Density<Type>& rhs)
{
Density<Type> result = lhs;
result -= rhs;
return result;
}
template <typename Type>
Density<Type> operator/(const Density<Type>& lhs, uint32_t rhs)
{
Density<Type> 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<uint8_t> Density8;
typedef Density<uint16_t> Density16;
typedef Density<uint32_t> Density32;
typedef Density<float> DensityFloat;
/**
* This is a specialisation of DefaultMarchingCubesController for the Density voxel type
*/
template <typename Type>
class DefaultMarchingCubesController< Density<Type> >
{
public:
typedef Type DensityType;
typedef float MaterialType;
DefaultMarchingCubesController(void)
{
// Default to a threshold value halfway between the min and max possible values.
m_tThreshold = (Density<Type>::getMinDensity() + Density<Type>::getMaxDensity()) / 2;
}
DefaultMarchingCubesController(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
DensityType convertToDensity(Density<Type> voxel)
{
return voxel.getDensity();
}
MaterialType convertToMaterial(Density<Type> /*voxel*/)
{
return 1;
}
MaterialType blendMaterials(Density<Type> /*a*/, Density<Type> /*b*/, float /*weight*/)
{
return 1;
}
DensityType getThreshold(void)
{
return m_tThreshold;
}
void setThreshold(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
private:
DensityType m_tThreshold;
};
}
#endif //__PolyVox_Density_H__

View File

@ -1,64 +1,64 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_GradientEstimators_H__
#define __PolyVox_GradientEstimators_H__
#include "PolyVoxCore/Vector.h"
#include "PolyVoxCore/VoxelFilters.h"
#include <vector>
namespace PolyVox
{
enum NormalGenerationMethod
{
SIMPLE, ///<Fastest
CENTRAL_DIFFERENCE,
SOBEL,
CENTRAL_DIFFERENCE_SMOOTHED,
SOBEL_SMOOTHED ///<Smoothest
};
template<typename VolumeType>
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter);
template<typename VolumeType>
Vector3DFloat computeSmoothCentralDifferenceGradient(typename VolumeType::Sampler& volIter);
template<typename VolumeType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(typename VolumeType::Sampler& volIter);
template<typename VolumeType>
Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter);
template<typename VolumeType>
Vector3DFloat computeSmoothSobelGradient(typename VolumeType::Sampler& volIter);
//POLYVOX_API void computeNormalsForVertices(VolumeType<uint8_t>* volumeData, Mesh<PositionMaterialNormal>& mesh, NormalGenerationMethod normalGenerationMethod);
//POLYVOX_API Vector3DFloat computeNormal(VolumeType<uint8_t>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod);
}
#include "PolyVoxCore/GradientEstimators.inl"
#endif //__PolyVox_GradientEstimators_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_GradientEstimators_H__
#define __PolyVox_GradientEstimators_H__
#include "PolyVoxCore/Vector.h"
#include "PolyVoxCore/VoxelFilters.h"
#include <vector>
namespace PolyVox
{
enum NormalGenerationMethod
{
SIMPLE, ///<Fastest
CENTRAL_DIFFERENCE,
SOBEL,
CENTRAL_DIFFERENCE_SMOOTHED,
SOBEL_SMOOTHED ///<Smoothest
};
template<typename VolumeType>
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter);
template<typename VolumeType>
Vector3DFloat computeSmoothCentralDifferenceGradient(typename VolumeType::Sampler& volIter);
template<typename VolumeType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(typename VolumeType::Sampler& volIter);
template<typename VolumeType>
Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter);
template<typename VolumeType>
Vector3DFloat computeSmoothSobelGradient(typename VolumeType::Sampler& volIter);
//POLYVOX_API void computeNormalsForVertices(VolumeType<uint8_t>* volumeData, Mesh<PositionMaterialNormal>& mesh, NormalGenerationMethod normalGenerationMethod);
//POLYVOX_API Vector3DFloat computeNormal(VolumeType<uint8_t>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod);
}
#include "PolyVoxCore/GradientEstimators.inl"
#endif //__PolyVox_GradientEstimators_H__

View File

@ -1,302 +1,302 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
template<typename VolumeType>
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter)
{
//FIXME - bitwise way of doing this?
typename VolumeType::VoxelType voxel1nx = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1px = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1ny = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1py = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
return Vector3DFloat
(
static_cast<float>(voxel1nx) - static_cast<float>(voxel1px),
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
);
}
template<typename VolumeType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(const typename VolumeType::Sampler& volIter)
{
const int32_t x = volIter.getPosition().getX();
const int32_t y = volIter.getPosition().getY();
const int32_t z = volIter.getPosition().getZ();
//FIXME - bitwise way of doing this?
typename VolumeType::VoxelType voxel1nx = volIter.getVoxel(x-2, y ,z ) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1px = volIter.getVoxel(x-2, y ,z ) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1ny = volIter.getVoxel(x , y-2,z ) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1py = volIter.getVoxel(x , y-2,z ) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1nz = volIter.getVoxel(x , y ,z-2) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1pz = volIter.getVoxel(x , y ,z-2) > 0 ? 1: 0;
return Vector3DFloat
(
static_cast<float>(voxel1nx) - static_cast<float>(voxel1px),
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
);
}
template<typename VolumeType>
Vector3DFloat computeSmoothCentralDifferenceGradient(typename VolumeType::Sampler& volIter)
{
int32_t initialX = volIter.getPosition().getX();
int32_t initialY = volIter.getPosition().getY();
int32_t initialZ = volIter.getPosition().getZ();
//FIXME - bitwise way of doing this?
volIter.setPosition(initialX-1, initialY, initialZ);
float voxel1nx = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY, initialZ);
float voxel1px = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY-1, initialZ);
float voxel1ny = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY+1, initialZ);
float voxel1py = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY, initialZ-1);
float voxel1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY, initialZ+1);
float voxel1pz = computeSmoothedVoxel(volIter);
return Vector3DFloat
(
voxel1nx - voxel1px,
voxel1ny - voxel1py,
voxel1nz - voxel1pz
);
}
template<typename VolumeType>
Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter)
{
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} } };
const typename VolumeType::VoxelType pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
//const VolumeType::VoxelType pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz() > 0 ? 1: 0;
const int xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz -
weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] *
pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz -
weights[1][2][0] * pVoxel1nx1py0pz - weights[2][2][0] *
pVoxel1nx1py1pz + weights[0][0][2] * pVoxel1px1ny1nz +
weights[1][0][2] * pVoxel1px1ny0pz + weights[2][0][2] *
pVoxel1px1ny1pz + weights[0][1][2] * pVoxel1px0py1nz +
weights[1][1][2] * pVoxel1px0py0pz + weights[2][1][2] *
pVoxel1px0py1pz + weights[0][2][2] * pVoxel1px1py1nz +
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
pVoxel1px1py1pz);
const int yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz +
weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] *
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz -
weights[1][0][1] * pVoxel0px1ny0pz - weights[2][0][1] *
pVoxel0px1ny1pz + weights[0][2][1] * pVoxel0px1py1nz +
weights[1][2][1] * pVoxel0px1py0pz + weights[2][2][1] *
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz -
weights[1][0][2] * pVoxel1px1ny0pz - weights[2][0][2] *
pVoxel1px1ny1pz + weights[0][2][2] * pVoxel1px1py1nz +
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
pVoxel1px1py1pz);
const int zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz +
weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] *
pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz -
weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] *
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz +
weights[2][0][1] * pVoxel0px1ny1pz - weights[0][1][1] *
pVoxel0px0py1nz + weights[2][1][1] * pVoxel0px0py1pz -
weights[0][2][1] * pVoxel0px1py1nz + weights[2][2][1] *
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz +
weights[2][0][2] * pVoxel1px1ny1pz - weights[0][1][2] *
pVoxel1px0py1nz + weights[2][1][2] * pVoxel1px0py1pz -
weights[0][2][2] * pVoxel1px1py1nz + weights[2][2][2] *
pVoxel1px1py1pz);
//Note: The above actually give gradients going from low density to high density.
//For our normals we want the the other way around, so we switch the components as we return them.
return Vector3DFloat(static_cast<float>(-xGrad),static_cast<float>(-yGrad),static_cast<float>(-zGrad));
}
template<typename VolumeType>
Vector3DFloat computeSmoothSobelGradient(typename VolumeType::Sampler& volIter)
{
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} } };
int32_t initialX = volIter.getPosition().getX();
int32_t initialY = volIter.getPosition().getY();
int32_t initialZ = volIter.getPosition().getZ();
volIter.setPosition(initialX-1, initialY-1, initialZ-1); const float pVoxel1nx1ny1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY-1, initialZ ); const float pVoxel1nx1ny0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY-1, initialZ+1); const float pVoxel1nx1ny1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY , initialZ-1); const float pVoxel1nx0py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY , initialZ ); const float pVoxel1nx0py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY , initialZ+1); const float pVoxel1nx0py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY+1, initialZ-1); const float pVoxel1nx1py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY+1, initialZ ); const float pVoxel1nx1py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY+1, initialZ+1); const float pVoxel1nx1py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY-1, initialZ-1); const float pVoxel0px1ny1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY-1, initialZ ); const float pVoxel0px1ny0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY-1, initialZ+1); const float pVoxel0px1ny1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY , initialZ-1); const float pVoxel0px0py1nz = computeSmoothedVoxel(volIter);
//volIter.setPosition(initialX , initialY , initialZ ); const float pVoxel0px0py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY , initialZ+1); const float pVoxel0px0py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY+1, initialZ-1); const float pVoxel0px1py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY+1, initialZ ); const float pVoxel0px1py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY+1, initialZ+1); const float pVoxel0px1py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY-1, initialZ-1); const float pVoxel1px1ny1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY-1, initialZ ); const float pVoxel1px1ny0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY-1, initialZ+1); const float pVoxel1px1ny1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY , initialZ-1); const float pVoxel1px0py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY , initialZ ); const float pVoxel1px0py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY , initialZ+1); const float pVoxel1px0py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY+1, initialZ-1); const float pVoxel1px1py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY+1, initialZ ); const float pVoxel1px1py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY+1, initialZ+1); const float pVoxel1px1py1pz = computeSmoothedVoxel(volIter);
/*const VoxelType pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
//const VoxelType pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz() > 0 ? 1: 0;*/
const float xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz -
weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] *
pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz -
weights[1][2][0] * pVoxel1nx1py0pz - weights[2][2][0] *
pVoxel1nx1py1pz + weights[0][0][2] * pVoxel1px1ny1nz +
weights[1][0][2] * pVoxel1px1ny0pz + weights[2][0][2] *
pVoxel1px1ny1pz + weights[0][1][2] * pVoxel1px0py1nz +
weights[1][1][2] * pVoxel1px0py0pz + weights[2][1][2] *
pVoxel1px0py1pz + weights[0][2][2] * pVoxel1px1py1nz +
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
pVoxel1px1py1pz);
const float yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz +
weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] *
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz -
weights[1][0][1] * pVoxel0px1ny0pz - weights[2][0][1] *
pVoxel0px1ny1pz + weights[0][2][1] * pVoxel0px1py1nz +
weights[1][2][1] * pVoxel0px1py0pz + weights[2][2][1] *
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz -
weights[1][0][2] * pVoxel1px1ny0pz - weights[2][0][2] *
pVoxel1px1ny1pz + weights[0][2][2] * pVoxel1px1py1nz +
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
pVoxel1px1py1pz);
const float zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz +
weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] *
pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz -
weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] *
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz +
weights[2][0][1] * pVoxel0px1ny1pz - weights[0][1][1] *
pVoxel0px0py1nz + weights[2][1][1] * pVoxel0px0py1pz -
weights[0][2][1] * pVoxel0px1py1nz + weights[2][2][1] *
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz +
weights[2][0][2] * pVoxel1px1ny1pz - weights[0][1][2] *
pVoxel1px0py1nz + weights[2][1][2] * pVoxel1px0py1pz -
weights[0][2][2] * pVoxel1px1py1nz + weights[2][2][2] *
pVoxel1px1py1pz);
//Note: The above actually give gradients going from low density to high density.
//For our normals we want the the other way around, so we switch the components as we return them.
return Vector3DFloat(-xGrad,-yGrad,-zGrad);
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
template<typename VolumeType>
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter)
{
//FIXME - bitwise way of doing this?
typename VolumeType::VoxelType voxel1nx = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1px = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1ny = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1py = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
return Vector3DFloat
(
static_cast<float>(voxel1nx) - static_cast<float>(voxel1px),
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
);
}
template<typename VolumeType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(const typename VolumeType::Sampler& volIter)
{
const int32_t x = volIter.getPosition().getX();
const int32_t y = volIter.getPosition().getY();
const int32_t z = volIter.getPosition().getZ();
//FIXME - bitwise way of doing this?
typename VolumeType::VoxelType voxel1nx = volIter.getVoxel(x-2, y ,z ) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1px = volIter.getVoxel(x-2, y ,z ) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1ny = volIter.getVoxel(x , y-2,z ) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1py = volIter.getVoxel(x , y-2,z ) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1nz = volIter.getVoxel(x , y ,z-2) > 0 ? 1: 0;
typename VolumeType::VoxelType voxel1pz = volIter.getVoxel(x , y ,z-2) > 0 ? 1: 0;
return Vector3DFloat
(
static_cast<float>(voxel1nx) - static_cast<float>(voxel1px),
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
);
}
template<typename VolumeType>
Vector3DFloat computeSmoothCentralDifferenceGradient(typename VolumeType::Sampler& volIter)
{
int32_t initialX = volIter.getPosition().getX();
int32_t initialY = volIter.getPosition().getY();
int32_t initialZ = volIter.getPosition().getZ();
//FIXME - bitwise way of doing this?
volIter.setPosition(initialX-1, initialY, initialZ);
float voxel1nx = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY, initialZ);
float voxel1px = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY-1, initialZ);
float voxel1ny = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY+1, initialZ);
float voxel1py = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY, initialZ-1);
float voxel1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY, initialZ+1);
float voxel1pz = computeSmoothedVoxel(volIter);
return Vector3DFloat
(
voxel1nx - voxel1px,
voxel1ny - voxel1py,
voxel1nz - voxel1pz
);
}
template<typename VolumeType>
Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter)
{
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} } };
const typename VolumeType::VoxelType pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
//const VolumeType::VoxelType pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz() > 0 ? 1: 0;
const typename VolumeType::VoxelType pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz() > 0 ? 1: 0;
const int xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz -
weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] *
pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz -
weights[1][2][0] * pVoxel1nx1py0pz - weights[2][2][0] *
pVoxel1nx1py1pz + weights[0][0][2] * pVoxel1px1ny1nz +
weights[1][0][2] * pVoxel1px1ny0pz + weights[2][0][2] *
pVoxel1px1ny1pz + weights[0][1][2] * pVoxel1px0py1nz +
weights[1][1][2] * pVoxel1px0py0pz + weights[2][1][2] *
pVoxel1px0py1pz + weights[0][2][2] * pVoxel1px1py1nz +
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
pVoxel1px1py1pz);
const int yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz +
weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] *
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz -
weights[1][0][1] * pVoxel0px1ny0pz - weights[2][0][1] *
pVoxel0px1ny1pz + weights[0][2][1] * pVoxel0px1py1nz +
weights[1][2][1] * pVoxel0px1py0pz + weights[2][2][1] *
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz -
weights[1][0][2] * pVoxel1px1ny0pz - weights[2][0][2] *
pVoxel1px1ny1pz + weights[0][2][2] * pVoxel1px1py1nz +
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
pVoxel1px1py1pz);
const int zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz +
weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] *
pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz -
weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] *
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz +
weights[2][0][1] * pVoxel0px1ny1pz - weights[0][1][1] *
pVoxel0px0py1nz + weights[2][1][1] * pVoxel0px0py1pz -
weights[0][2][1] * pVoxel0px1py1nz + weights[2][2][1] *
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz +
weights[2][0][2] * pVoxel1px1ny1pz - weights[0][1][2] *
pVoxel1px0py1nz + weights[2][1][2] * pVoxel1px0py1pz -
weights[0][2][2] * pVoxel1px1py1nz + weights[2][2][2] *
pVoxel1px1py1pz);
//Note: The above actually give gradients going from low density to high density.
//For our normals we want the the other way around, so we switch the components as we return them.
return Vector3DFloat(static_cast<float>(-xGrad),static_cast<float>(-yGrad),static_cast<float>(-zGrad));
}
template<typename VolumeType>
Vector3DFloat computeSmoothSobelGradient(typename VolumeType::Sampler& volIter)
{
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} } };
int32_t initialX = volIter.getPosition().getX();
int32_t initialY = volIter.getPosition().getY();
int32_t initialZ = volIter.getPosition().getZ();
volIter.setPosition(initialX-1, initialY-1, initialZ-1); const float pVoxel1nx1ny1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY-1, initialZ ); const float pVoxel1nx1ny0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY-1, initialZ+1); const float pVoxel1nx1ny1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY , initialZ-1); const float pVoxel1nx0py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY , initialZ ); const float pVoxel1nx0py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY , initialZ+1); const float pVoxel1nx0py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY+1, initialZ-1); const float pVoxel1nx1py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY+1, initialZ ); const float pVoxel1nx1py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX-1, initialY+1, initialZ+1); const float pVoxel1nx1py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY-1, initialZ-1); const float pVoxel0px1ny1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY-1, initialZ ); const float pVoxel0px1ny0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY-1, initialZ+1); const float pVoxel0px1ny1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY , initialZ-1); const float pVoxel0px0py1nz = computeSmoothedVoxel(volIter);
//volIter.setPosition(initialX , initialY , initialZ ); const float pVoxel0px0py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY , initialZ+1); const float pVoxel0px0py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY+1, initialZ-1); const float pVoxel0px1py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY+1, initialZ ); const float pVoxel0px1py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX , initialY+1, initialZ+1); const float pVoxel0px1py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY-1, initialZ-1); const float pVoxel1px1ny1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY-1, initialZ ); const float pVoxel1px1ny0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY-1, initialZ+1); const float pVoxel1px1ny1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY , initialZ-1); const float pVoxel1px0py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY , initialZ ); const float pVoxel1px0py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY , initialZ+1); const float pVoxel1px0py1pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY+1, initialZ-1); const float pVoxel1px1py1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY+1, initialZ ); const float pVoxel1px1py0pz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY+1, initialZ+1); const float pVoxel1px1py1pz = computeSmoothedVoxel(volIter);
/*const VoxelType pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
//const VoxelType pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz() > 0 ? 1: 0;*/
const float xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz -
weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] *
pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz -
weights[1][2][0] * pVoxel1nx1py0pz - weights[2][2][0] *
pVoxel1nx1py1pz + weights[0][0][2] * pVoxel1px1ny1nz +
weights[1][0][2] * pVoxel1px1ny0pz + weights[2][0][2] *
pVoxel1px1ny1pz + weights[0][1][2] * pVoxel1px0py1nz +
weights[1][1][2] * pVoxel1px0py0pz + weights[2][1][2] *
pVoxel1px0py1pz + weights[0][2][2] * pVoxel1px1py1nz +
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
pVoxel1px1py1pz);
const float yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz +
weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] *
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz -
weights[1][0][1] * pVoxel0px1ny0pz - weights[2][0][1] *
pVoxel0px1ny1pz + weights[0][2][1] * pVoxel0px1py1nz +
weights[1][2][1] * pVoxel0px1py0pz + weights[2][2][1] *
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz -
weights[1][0][2] * pVoxel1px1ny0pz - weights[2][0][2] *
pVoxel1px1ny1pz + weights[0][2][2] * pVoxel1px1py1nz +
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
pVoxel1px1py1pz);
const float zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz +
weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] *
pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz -
weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] *
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz +
weights[2][0][1] * pVoxel0px1ny1pz - weights[0][1][1] *
pVoxel0px0py1nz + weights[2][1][1] * pVoxel0px0py1pz -
weights[0][2][1] * pVoxel0px1py1nz + weights[2][2][1] *
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz +
weights[2][0][2] * pVoxel1px1ny1pz - weights[0][1][2] *
pVoxel1px0py1nz + weights[2][1][2] * pVoxel1px0py1pz -
weights[0][2][2] * pVoxel1px1py1nz + weights[2][2][2] *
pVoxel1px1py1pz);
//Note: The above actually give gradients going from low density to high density.
//For our normals we want the the other way around, so we switch the components as we return them.
return Vector3DFloat(-xGrad,-yGrad,-zGrad);
}
}

View File

@ -1,59 +1,59 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Utility_H__
#define __PolyVox_Utility_H__
#include "PolyVoxCore/Impl/TypeDef.h"
#include <cstdint>
namespace PolyVox
{
POLYVOX_API uint8_t logBase2(uint32_t uInput);
POLYVOX_API bool isPowerOf2(uint32_t uInput);
int32_t roundTowardsNegInf(float r);
int32_t roundToInteger(float r);
template <typename Type>
Type clamp(const Type& value, const Type& low, const Type& high);
uint32_t upperPowerOfTwo(uint32_t v);
inline int32_t roundTowardsNegInf(float r)
{
return (r >= 0.0) ? static_cast<int32_t>(r) : static_cast<int32_t>(r - 1.0f);
}
inline int32_t roundToNearestInteger(float r)
{
return (r >= 0.0) ? static_cast<int32_t>(r + 0.5f) : static_cast<int32_t>(r - 0.5f);
}
template <typename Type>
inline Type clamp(const Type& value, const Type& low, const Type& high)
{
return (std::min)(high, (std::max)(low, value));
}
}
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Utility_H__
#define __PolyVox_Utility_H__
#include "PolyVoxCore/Impl/TypeDef.h"
#include <cstdint>
namespace PolyVox
{
POLYVOX_API uint8_t logBase2(uint32_t uInput);
POLYVOX_API bool isPowerOf2(uint32_t uInput);
int32_t roundTowardsNegInf(float r);
int32_t roundToInteger(float r);
template <typename Type>
Type clamp(const Type& value, const Type& low, const Type& high);
uint32_t upperPowerOfTwo(uint32_t v);
inline int32_t roundTowardsNegInf(float r)
{
return (r >= 0.0) ? static_cast<int32_t>(r) : static_cast<int32_t>(r - 1.0f);
}
inline int32_t roundToNearestInteger(float r)
{
return (r >= 0.0) ? static_cast<int32_t>(r + 0.5f) : static_cast<int32_t>(r - 0.5f);
}
template <typename Type>
inline Type clamp(const Type& value, const Type& low, const Type& high)
{
return (std::min)(high, (std::max)(low, value));
}
}
#endif

View File

@ -1,46 +1,46 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_IteratorController_H__
#define __PolyVox_IteratorController_H__
#include "PolyVoxCore/Region.h"
namespace PolyVox
{
template <typename IteratorType>
class IteratorController
{
public:
void reset(void);
bool moveForward(void);
public:
Region m_regValid;
IteratorType* m_Iter;
};
}
#include "PolyVoxCore/IteratorController.inl"
#endif //__PolyVox_IteratorController_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_IteratorController_H__
#define __PolyVox_IteratorController_H__
#include "PolyVoxCore/Region.h"
namespace PolyVox
{
template <typename IteratorType>
class IteratorController
{
public:
void reset(void);
bool moveForward(void);
public:
Region m_regValid;
IteratorType* m_Iter;
};
}
#include "PolyVoxCore/IteratorController.inl"
#endif //__PolyVox_IteratorController_H__

View File

@ -1,63 +1,63 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
template <typename IteratorType>
void IteratorController<IteratorType>::reset(void)
{
m_Iter->setPosition(m_regValid.getLowerCorner());
}
template <typename IteratorType>
bool IteratorController<IteratorType>::moveForward(void)
{
Vector3DInt32 v3dInitialPosition(m_Iter->getPosition().getX(), m_Iter->getPosition().getY(), m_Iter->getPosition().getZ());
if(v3dInitialPosition.getX() < m_regValid.getUpperX())
{
m_Iter->movePositiveX();
return true;
}
v3dInitialPosition.setX(m_regValid.getLowerX());
if(v3dInitialPosition.getY() < m_regValid.getUpperY())
{
v3dInitialPosition.setY(v3dInitialPosition.getY() + 1);
m_Iter->setPosition(v3dInitialPosition);
return true;
}
v3dInitialPosition.setY(m_regValid.getLowerY());
if(v3dInitialPosition.getZ() < m_regValid.getUpperZ())
{
v3dInitialPosition.setZ(v3dInitialPosition.getZ() + 1);
m_Iter->setPosition(v3dInitialPosition);
return true;
}
return false;
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
template <typename IteratorType>
void IteratorController<IteratorType>::reset(void)
{
m_Iter->setPosition(m_regValid.getLowerCorner());
}
template <typename IteratorType>
bool IteratorController<IteratorType>::moveForward(void)
{
Vector3DInt32 v3dInitialPosition(m_Iter->getPosition().getX(), m_Iter->getPosition().getY(), m_Iter->getPosition().getZ());
if(v3dInitialPosition.getX() < m_regValid.getUpperX())
{
m_Iter->movePositiveX();
return true;
}
v3dInitialPosition.setX(m_regValid.getLowerX());
if(v3dInitialPosition.getY() < m_regValid.getUpperY())
{
v3dInitialPosition.setY(v3dInitialPosition.getY() + 1);
m_Iter->setPosition(v3dInitialPosition);
return true;
}
v3dInitialPosition.setY(m_regValid.getLowerY());
if(v3dInitialPosition.getZ() < m_regValid.getUpperZ())
{
v3dInitialPosition.setZ(v3dInitialPosition.getZ() + 1);
m_Iter->setPosition(v3dInitialPosition);
return true;
}
return false;
}
}

View File

@ -1,9 +1,9 @@
#ifndef __PolyVox_LargeVolume_H__
#define __PolyVox_LargeVolume_H__
#pragma message("WARNING - The LargeVolume class has been replaced by PagedVolume. Please use that instead.")
#include "PagedVolume.h"
#include "PolyVoxForwardDeclarations.h"
#ifndef __PolyVox_LargeVolume_H__
#define __PolyVox_LargeVolume_H__
#pragma message("WARNING - The LargeVolume class has been replaced by PagedVolume. Please use that instead.")
#include "PagedVolume.h"
#include "PolyVoxForwardDeclarations.h"
#endif //__PolyVox_LargeVolume_H__

View File

@ -1,60 +1,60 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_LowPassFilter_H__
#define __PolyVox_LowPassFilter_H__
#include "PolyVoxCore/IteratorController.h"
#include "PolyVoxCore/RawVolume.h" //Is this desirable?
#include "PolyVoxCore/Region.h"
namespace PolyVox
{
template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType>
class LowPassFilter
{
public:
LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DstVolumeType* pVolDst, Region regDst, uint32_t uKernelSize);
void execute();
void executeSAT();
private:
//Source data
SrcVolumeType* m_pVolSrc;
Region m_regSrc;
//Destination data
DstVolumeType* m_pVolDst;
Region m_regDst;
//Kernel size
uint32_t m_uKernelSize;
};
}//namespace PolyVox
#include "PolyVoxCore/LowPassFilter.inl"
#endif //__PolyVox_LowPassFilter_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_LowPassFilter_H__
#define __PolyVox_LowPassFilter_H__
#include "PolyVoxCore/IteratorController.h"
#include "PolyVoxCore/RawVolume.h" //Is this desirable?
#include "PolyVoxCore/Region.h"
namespace PolyVox
{
template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType>
class LowPassFilter
{
public:
LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DstVolumeType* pVolDst, Region regDst, uint32_t uKernelSize);
void execute();
void executeSAT();
private:
//Source data
SrcVolumeType* m_pVolSrc;
Region m_regSrc;
//Destination data
DstVolumeType* m_pVolDst;
Region m_regDst;
//Kernel size
uint32_t m_uKernelSize;
};
}//namespace PolyVox
#include "PolyVoxCore/LowPassFilter.inl"
#endif //__PolyVox_LowPassFilter_H__

View File

@ -1,255 +1,255 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
/**
* \param pVolSrc
* \param regSrc
* \param[out] pVolDst
* \param regDst
* \param uKernelSize
*/
template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType>
LowPassFilter<SrcVolumeType, DstVolumeType, AccumulationType>::LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DstVolumeType* pVolDst, Region regDst, uint32_t uKernelSize)
:m_pVolSrc(pVolSrc)
,m_regSrc(regSrc)
,m_pVolDst(pVolDst)
,m_regDst(regDst)
,m_uKernelSize(uKernelSize)
{
//Kernel size must be at least three
if(m_uKernelSize < 3)
{
POLYVOX_THROW(std::invalid_argument, "Kernel size must be at least three");
}
//Kernel size must be odd
if(m_uKernelSize % 2 == 0)
{
POLYVOX_THROW(std::invalid_argument, "Kernel size must be odd");
}
}
template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType>
void LowPassFilter<SrcVolumeType, DstVolumeType, AccumulationType>::execute()
{
int32_t iSrcMinX = m_regSrc.getLowerX();
int32_t iSrcMinY = m_regSrc.getLowerY();
int32_t iSrcMinZ = m_regSrc.getLowerZ();
int32_t iSrcMaxX = m_regSrc.getUpperX();
int32_t iSrcMaxY = m_regSrc.getUpperY();
int32_t iSrcMaxZ = m_regSrc.getUpperZ();
int32_t iDstMinX = m_regDst.getLowerX();
int32_t iDstMinY = m_regDst.getLowerY();
int32_t iDstMinZ = m_regDst.getLowerZ();
//int32_t iDstMaxX = m_regDst.getUpperX();
//int32_t iDstMaxY = m_regDst.getUpperY();
//int32_t iDstMaxZ = m_regDst.getUpperZ();
typename SrcVolumeType::Sampler srcSampler(m_pVolSrc);
for(int32_t iSrcZ = iSrcMinZ, iDstZ = iDstMinZ; iSrcZ <= iSrcMaxZ; iSrcZ++, iDstZ++)
{
for(int32_t iSrcY = iSrcMinY, iDstY = iDstMinY; iSrcY <= iSrcMaxY; iSrcY++, iDstY++)
{
for(int32_t iSrcX = iSrcMinX, iDstX = iDstMinX; iSrcX <= iSrcMaxX; iSrcX++, iDstX++)
{
AccumulationType tSrcVoxel(0);
srcSampler.setPosition(iSrcX, iSrcY, iSrcZ);
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1ny1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1ny0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1ny1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx0py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx0py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx0py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1ny1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1ny0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1ny1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px0py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px0py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px0py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1ny1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1ny0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1ny1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px0py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px0py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px0py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1py1pz());
tSrcVoxel /= 27;
//tSrcVoxel.setDensity(uDensity);
m_pVolDst->setVoxelAt(iSrcX, iSrcY, iSrcZ, static_cast<typename DstVolumeType::VoxelType>(tSrcVoxel));
}
}
}
}
template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType>
void LowPassFilter<SrcVolumeType, DstVolumeType, AccumulationType>::executeSAT()
{
const uint32_t border = (m_uKernelSize - 1) / 2;
Vector3DInt32 satLowerCorner = m_regSrc.getLowerCorner() - Vector3DInt32(border, border, border);
Vector3DInt32 satUpperCorner = m_regSrc.getUpperCorner() + Vector3DInt32(border, border, border);
//Use floats for the SAT volume to ensure it works with negative
//densities and with both integral and floating point input volumes.
RawVolume<AccumulationType> satVolume(Region(satLowerCorner, satUpperCorner));
//Clear to zeros (necessary?)
//FIXME - use Volume::fill() method. Implemented in base class as below
//but with optimised implementations in subclasses?
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++)
{
satVolume.setVoxelAt(x,y,z,0);
}
}
}
typename RawVolume<AccumulationType>::Sampler satVolumeIter(&satVolume);
IteratorController<typename RawVolume<AccumulationType>::Sampler> satIterCont;
satIterCont.m_regValid = Region(satLowerCorner, satUpperCorner);
satIterCont.m_Iter = &satVolumeIter;
satIterCont.reset();
typename SrcVolumeType::Sampler srcVolumeIter(m_pVolSrc);
IteratorController<typename SrcVolumeType::Sampler> srcIterCont;
srcIterCont.m_regValid = Region(satLowerCorner, satUpperCorner);
srcIterCont.m_Iter = &srcVolumeIter;
srcIterCont.reset();
do
{
AccumulationType previousSum = static_cast<AccumulationType>(satVolumeIter.peekVoxel1nx0py0pz());
AccumulationType currentVal = static_cast<AccumulationType>(srcVolumeIter.getVoxel());
satVolumeIter.setVoxel(previousSum + currentVal);
srcIterCont.moveForward();
}while(satIterCont.moveForward());
//Build SAT in three passes
/*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++)
{
AccumulationType previousSum = static_cast<AccumulationType>(satVolume.getVoxelAt(x-1,y,z));
AccumulationType currentVal = static_cast<AccumulationType>(m_pVolSrc->getVoxelAt(x,y,z));
satVolume.setVoxelAt(x,y,z,previousSum + currentVal);
}
}
}*/
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++)
{
AccumulationType previousSum = static_cast<AccumulationType>(satVolume.getVoxel(x,y-1,z, WrapModes::Border));
AccumulationType currentSum = static_cast<AccumulationType>(satVolume.getVoxel(x,y,z, WrapModes::Border));
satVolume.setVoxelAt(x,y,z,previousSum + currentSum);
}
}
}
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++)
{
AccumulationType previousSum = static_cast<AccumulationType>(satVolume.getVoxel(x,y,z-1, WrapModes::Border));
AccumulationType currentSum = static_cast<AccumulationType>(satVolume.getVoxel(x,y,z, WrapModes::Border));
satVolume.setVoxelAt(x,y,z,previousSum + currentSum);
}
}
}
//Now compute the average
const Vector3DInt32& v3dDstLowerCorner = m_regDst.getLowerCorner();
const Vector3DInt32& v3dDstUpperCorner = m_regDst.getUpperCorner();
const Vector3DInt32& v3dSrcLowerCorner = m_regSrc.getLowerCorner();
for(int32_t iDstZ = v3dDstLowerCorner.getZ(), iSrcZ = v3dSrcLowerCorner.getZ(); iDstZ <= v3dDstUpperCorner.getZ(); iDstZ++, iSrcZ++)
{
for(int32_t iDstY = v3dDstLowerCorner.getY(), iSrcY = v3dSrcLowerCorner.getY(); iDstY <= v3dDstUpperCorner.getY(); iDstY++, iSrcY++)
{
for(int32_t iDstX = v3dDstLowerCorner.getX(), iSrcX = v3dSrcLowerCorner.getX(); iDstX <= v3dDstUpperCorner.getX(); iDstX++, iSrcX++)
{
int32_t satLowerX = iSrcX - border - 1;
int32_t satLowerY = iSrcY - border - 1;
int32_t satLowerZ = iSrcZ - border - 1;
int32_t satUpperX = iSrcX + border;
int32_t satUpperY = iSrcY + border;
int32_t satUpperZ = iSrcZ + border;
AccumulationType a = satVolume.getVoxel(satLowerX,satLowerY,satLowerZ, WrapModes::Border);
AccumulationType b = satVolume.getVoxel(satUpperX,satLowerY,satLowerZ, WrapModes::Border);
AccumulationType c = satVolume.getVoxel(satLowerX,satUpperY,satLowerZ, WrapModes::Border);
AccumulationType d = satVolume.getVoxel(satUpperX,satUpperY,satLowerZ, WrapModes::Border);
AccumulationType e = satVolume.getVoxel(satLowerX,satLowerY,satUpperZ, WrapModes::Border);
AccumulationType f = satVolume.getVoxel(satUpperX,satLowerY,satUpperZ, WrapModes::Border);
AccumulationType g = satVolume.getVoxel(satLowerX,satUpperY,satUpperZ, WrapModes::Border);
AccumulationType h = satVolume.getVoxel(satUpperX,satUpperY,satUpperZ, WrapModes::Border);
AccumulationType sum = h+c-d-g-f-a+b+e;
uint32_t sideLength = border * 2 + 1;
AccumulationType average = sum / (sideLength*sideLength*sideLength);
m_pVolDst->setVoxelAt(iDstX, iDstY, iDstZ, static_cast<typename DstVolumeType::VoxelType>(average));
}
}
}
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
/**
* \param pVolSrc
* \param regSrc
* \param[out] pVolDst
* \param regDst
* \param uKernelSize
*/
template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType>
LowPassFilter<SrcVolumeType, DstVolumeType, AccumulationType>::LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DstVolumeType* pVolDst, Region regDst, uint32_t uKernelSize)
:m_pVolSrc(pVolSrc)
,m_regSrc(regSrc)
,m_pVolDst(pVolDst)
,m_regDst(regDst)
,m_uKernelSize(uKernelSize)
{
//Kernel size must be at least three
if(m_uKernelSize < 3)
{
POLYVOX_THROW(std::invalid_argument, "Kernel size must be at least three");
}
//Kernel size must be odd
if(m_uKernelSize % 2 == 0)
{
POLYVOX_THROW(std::invalid_argument, "Kernel size must be odd");
}
}
template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType>
void LowPassFilter<SrcVolumeType, DstVolumeType, AccumulationType>::execute()
{
int32_t iSrcMinX = m_regSrc.getLowerX();
int32_t iSrcMinY = m_regSrc.getLowerY();
int32_t iSrcMinZ = m_regSrc.getLowerZ();
int32_t iSrcMaxX = m_regSrc.getUpperX();
int32_t iSrcMaxY = m_regSrc.getUpperY();
int32_t iSrcMaxZ = m_regSrc.getUpperZ();
int32_t iDstMinX = m_regDst.getLowerX();
int32_t iDstMinY = m_regDst.getLowerY();
int32_t iDstMinZ = m_regDst.getLowerZ();
//int32_t iDstMaxX = m_regDst.getUpperX();
//int32_t iDstMaxY = m_regDst.getUpperY();
//int32_t iDstMaxZ = m_regDst.getUpperZ();
typename SrcVolumeType::Sampler srcSampler(m_pVolSrc);
for(int32_t iSrcZ = iSrcMinZ, iDstZ = iDstMinZ; iSrcZ <= iSrcMaxZ; iSrcZ++, iDstZ++)
{
for(int32_t iSrcY = iSrcMinY, iDstY = iDstMinY; iSrcY <= iSrcMaxY; iSrcY++, iDstY++)
{
for(int32_t iSrcX = iSrcMinX, iDstX = iDstMinX; iSrcX <= iSrcMaxX; iSrcX++, iDstX++)
{
AccumulationType tSrcVoxel(0);
srcSampler.setPosition(iSrcX, iSrcY, iSrcZ);
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1ny1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1ny0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1ny1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx0py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx0py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx0py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1nx1py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1ny1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1ny0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1ny1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px0py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px0py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px0py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel0px1py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1ny1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1ny0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1ny1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px0py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px0py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px0py1pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1py1nz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1py0pz());
tSrcVoxel += static_cast<AccumulationType>(srcSampler.peekVoxel1px1py1pz());
tSrcVoxel /= 27;
//tSrcVoxel.setDensity(uDensity);
m_pVolDst->setVoxelAt(iSrcX, iSrcY, iSrcZ, static_cast<typename DstVolumeType::VoxelType>(tSrcVoxel));
}
}
}
}
template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType>
void LowPassFilter<SrcVolumeType, DstVolumeType, AccumulationType>::executeSAT()
{
const uint32_t border = (m_uKernelSize - 1) / 2;
Vector3DInt32 satLowerCorner = m_regSrc.getLowerCorner() - Vector3DInt32(border, border, border);
Vector3DInt32 satUpperCorner = m_regSrc.getUpperCorner() + Vector3DInt32(border, border, border);
//Use floats for the SAT volume to ensure it works with negative
//densities and with both integral and floating point input volumes.
RawVolume<AccumulationType> satVolume(Region(satLowerCorner, satUpperCorner));
//Clear to zeros (necessary?)
//FIXME - use Volume::fill() method. Implemented in base class as below
//but with optimised implementations in subclasses?
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++)
{
satVolume.setVoxelAt(x,y,z,0);
}
}
}
typename RawVolume<AccumulationType>::Sampler satVolumeIter(&satVolume);
IteratorController<typename RawVolume<AccumulationType>::Sampler> satIterCont;
satIterCont.m_regValid = Region(satLowerCorner, satUpperCorner);
satIterCont.m_Iter = &satVolumeIter;
satIterCont.reset();
typename SrcVolumeType::Sampler srcVolumeIter(m_pVolSrc);
IteratorController<typename SrcVolumeType::Sampler> srcIterCont;
srcIterCont.m_regValid = Region(satLowerCorner, satUpperCorner);
srcIterCont.m_Iter = &srcVolumeIter;
srcIterCont.reset();
do
{
AccumulationType previousSum = static_cast<AccumulationType>(satVolumeIter.peekVoxel1nx0py0pz());
AccumulationType currentVal = static_cast<AccumulationType>(srcVolumeIter.getVoxel());
satVolumeIter.setVoxel(previousSum + currentVal);
srcIterCont.moveForward();
}while(satIterCont.moveForward());
//Build SAT in three passes
/*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++)
{
AccumulationType previousSum = static_cast<AccumulationType>(satVolume.getVoxelAt(x-1,y,z));
AccumulationType currentVal = static_cast<AccumulationType>(m_pVolSrc->getVoxelAt(x,y,z));
satVolume.setVoxelAt(x,y,z,previousSum + currentVal);
}
}
}*/
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++)
{
AccumulationType previousSum = static_cast<AccumulationType>(satVolume.getVoxel(x,y-1,z, WrapModes::Border));
AccumulationType currentSum = static_cast<AccumulationType>(satVolume.getVoxel(x,y,z, WrapModes::Border));
satVolume.setVoxelAt(x,y,z,previousSum + currentSum);
}
}
}
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++)
{
AccumulationType previousSum = static_cast<AccumulationType>(satVolume.getVoxel(x,y,z-1, WrapModes::Border));
AccumulationType currentSum = static_cast<AccumulationType>(satVolume.getVoxel(x,y,z, WrapModes::Border));
satVolume.setVoxelAt(x,y,z,previousSum + currentSum);
}
}
}
//Now compute the average
const Vector3DInt32& v3dDstLowerCorner = m_regDst.getLowerCorner();
const Vector3DInt32& v3dDstUpperCorner = m_regDst.getUpperCorner();
const Vector3DInt32& v3dSrcLowerCorner = m_regSrc.getLowerCorner();
for(int32_t iDstZ = v3dDstLowerCorner.getZ(), iSrcZ = v3dSrcLowerCorner.getZ(); iDstZ <= v3dDstUpperCorner.getZ(); iDstZ++, iSrcZ++)
{
for(int32_t iDstY = v3dDstLowerCorner.getY(), iSrcY = v3dSrcLowerCorner.getY(); iDstY <= v3dDstUpperCorner.getY(); iDstY++, iSrcY++)
{
for(int32_t iDstX = v3dDstLowerCorner.getX(), iSrcX = v3dSrcLowerCorner.getX(); iDstX <= v3dDstUpperCorner.getX(); iDstX++, iSrcX++)
{
int32_t satLowerX = iSrcX - border - 1;
int32_t satLowerY = iSrcY - border - 1;
int32_t satLowerZ = iSrcZ - border - 1;
int32_t satUpperX = iSrcX + border;
int32_t satUpperY = iSrcY + border;
int32_t satUpperZ = iSrcZ + border;
AccumulationType a = satVolume.getVoxel(satLowerX,satLowerY,satLowerZ, WrapModes::Border);
AccumulationType b = satVolume.getVoxel(satUpperX,satLowerY,satLowerZ, WrapModes::Border);
AccumulationType c = satVolume.getVoxel(satLowerX,satUpperY,satLowerZ, WrapModes::Border);
AccumulationType d = satVolume.getVoxel(satUpperX,satUpperY,satLowerZ, WrapModes::Border);
AccumulationType e = satVolume.getVoxel(satLowerX,satLowerY,satUpperZ, WrapModes::Border);
AccumulationType f = satVolume.getVoxel(satUpperX,satLowerY,satUpperZ, WrapModes::Border);
AccumulationType g = satVolume.getVoxel(satLowerX,satUpperY,satUpperZ, WrapModes::Border);
AccumulationType h = satVolume.getVoxel(satUpperX,satUpperY,satUpperZ, WrapModes::Border);
AccumulationType sum = h+c-d-g-f-a+b+e;
uint32_t sideLength = border * 2 + 1;
AccumulationType average = sum / (sideLength*sideLength*sideLength);
m_pVolDst->setVoxelAt(iDstX, iDstY, iDstZ, static_cast<typename DstVolumeType::VoxelType>(average));
}
}
}
}
}

View File

@ -35,121 +35,121 @@ freely, subject to the following restrictions:
namespace PolyVox
{
#ifdef SWIG
struct MarchingCubesVertex
#else
template<typename _DataType>
struct POLYVOX_API MarchingCubesVertex
#endif
{
typedef _DataType DataType;
// Each component of the position is stored using 8.8 fixed-point encoding.
Vector3DUint16 encodedPosition;
// The normal is encoded as a 16-bit unsigned integer using the 'oct16'
// encoding described here: http://jcgt.org/published/0003/02/01/
uint16_t encodedNormal;
// User data
DataType data;
};
// Convienient shorthand for declaring a mesh of marching cubes vertices
// Currently disabled because it requires GCC 4.7
//template <typename VertexDataType, typename IndexType = DefaultIndexType>
//using MarchingCubesMesh = Mesh< MarchingCubesVertex<VertexDataType>, IndexType >;
/// Decodes a position from a MarchingCubesVertex
inline Vector3DFloat decodePosition(const Vector3DUint16& encodedPosition)
{
Vector3DFloat result(encodedPosition.getX(), encodedPosition.getY(), encodedPosition.getZ());
result *= (1.0f / 256.0f); // Division is compile-time constant
return result;
}
inline uint16_t encodeNormal(const Vector3DFloat& normal)
{
// The first part of this function is based off the code in Listing 1 of http://jcgt.org/published/0003/02/01/
// It was rewritten in C++ and is restructued for the CPU rather than the GPU.
// Get the input components
float vx = normal.getX();
float vy = normal.getY();
float vz = normal.getZ();
// Project the sphere onto the octahedron, and then onto the xy plane
float px = vx * (1.0f / (std::abs(vx) + std::abs(vy) + std::abs(vz)));
float py = vy * (1.0f / (std::abs(vx) + std::abs(vy) + std::abs(vz)));
// Reflect the folds of the lower hemisphere over the diagonals.
if (vz <= 0.0f)
{
float refx = ((1.0f - std::abs(py)) * (px >= 0.0f ? +1.0f : -1.0f));
float refy = ((1.0f - std::abs(px)) * (py >= 0.0f ? +1.0f : -1.0f));
px = refx;
py = refy;
}
// The next part was not given in the paper. We map our two
// floats into two bytes and store them in a single uint16_t
// Move from range [-1.0f, 1.0f] to [0.0f, 255.0f]
px = (px + 1.0f) * 127.5f;
py = (py + 1.0f) * 127.5f;
// Convert to uints
uint16_t resultX = static_cast<uint16_t>(px + 0.5f);
uint16_t resultY = static_cast<uint16_t>(py + 0.5f);
// Make sure only the lower bits are set. Probably
// not necessary but we're just being careful really.
resultX &= 0xFF;
resultY &= 0xFF;
// Contatenate the bytes and return the result.
return (resultX << 8) | resultY;
}
inline Vector3DFloat decodeNormal(const uint16_t& encodedNormal)
{
// Extract the two bytes from the uint16_t.
uint16_t ux = (encodedNormal >> 8) & 0xFF;
uint16_t uy = (encodedNormal ) & 0xFF;
// Convert to floats in the range [-1.0f, +1.0f].
float ex = ux / 127.5f - 1.0f;
float ey = uy / 127.5f - 1.0f;
// Reconstruct the origninal vector. This is a C++ implementation
// of Listing 2 of http://jcgt.org/published/0003/02/01/
float vx = ex;
float vy = ey;
float vz = 1.0f - std::abs(ex) - std::abs(ey);
if (vz < 0.0f)
{
float refX = ((1.0f - std::abs(vy)) * (vx >= 0.0f ? +1.0f : -1.0f));
float refY = ((1.0f - std::abs(vx)) * (vy >= 0.0f ? +1.0f : -1.0f));
vx = refX;
vy = refY;
}
// Normalise and return the result.
Vector3DFloat v(vx, vy, vz);
v.normalise();
return v;
}
/// Decodes a MarchingCubesVertex by converting it into a regular Vertex which can then be directly used for rendering.
template<typename DataType>
Vertex<DataType> decodeVertex(const MarchingCubesVertex<DataType>& marchingCubesVertex)
{
Vertex<DataType> result;
result.position = decodePosition(marchingCubesVertex.encodedPosition);
result.normal = decodeNormal(marchingCubesVertex.encodedNormal);
result.data = marchingCubesVertex.data; // Data is not encoded
return result;
#ifdef SWIG
struct MarchingCubesVertex
#else
template<typename _DataType>
struct POLYVOX_API MarchingCubesVertex
#endif
{
typedef _DataType DataType;
// Each component of the position is stored using 8.8 fixed-point encoding.
Vector3DUint16 encodedPosition;
// The normal is encoded as a 16-bit unsigned integer using the 'oct16'
// encoding described here: http://jcgt.org/published/0003/02/01/
uint16_t encodedNormal;
// User data
DataType data;
};
// Convienient shorthand for declaring a mesh of marching cubes vertices
// Currently disabled because it requires GCC 4.7
//template <typename VertexDataType, typename IndexType = DefaultIndexType>
//using MarchingCubesMesh = Mesh< MarchingCubesVertex<VertexDataType>, IndexType >;
/// Decodes a position from a MarchingCubesVertex
inline Vector3DFloat decodePosition(const Vector3DUint16& encodedPosition)
{
Vector3DFloat result(encodedPosition.getX(), encodedPosition.getY(), encodedPosition.getZ());
result *= (1.0f / 256.0f); // Division is compile-time constant
return result;
}
inline uint16_t encodeNormal(const Vector3DFloat& normal)
{
// The first part of this function is based off the code in Listing 1 of http://jcgt.org/published/0003/02/01/
// It was rewritten in C++ and is restructued for the CPU rather than the GPU.
// Get the input components
float vx = normal.getX();
float vy = normal.getY();
float vz = normal.getZ();
// Project the sphere onto the octahedron, and then onto the xy plane
float px = vx * (1.0f / (std::abs(vx) + std::abs(vy) + std::abs(vz)));
float py = vy * (1.0f / (std::abs(vx) + std::abs(vy) + std::abs(vz)));
// Reflect the folds of the lower hemisphere over the diagonals.
if (vz <= 0.0f)
{
float refx = ((1.0f - std::abs(py)) * (px >= 0.0f ? +1.0f : -1.0f));
float refy = ((1.0f - std::abs(px)) * (py >= 0.0f ? +1.0f : -1.0f));
px = refx;
py = refy;
}
// The next part was not given in the paper. We map our two
// floats into two bytes and store them in a single uint16_t
// Move from range [-1.0f, 1.0f] to [0.0f, 255.0f]
px = (px + 1.0f) * 127.5f;
py = (py + 1.0f) * 127.5f;
// Convert to uints
uint16_t resultX = static_cast<uint16_t>(px + 0.5f);
uint16_t resultY = static_cast<uint16_t>(py + 0.5f);
// Make sure only the lower bits are set. Probably
// not necessary but we're just being careful really.
resultX &= 0xFF;
resultY &= 0xFF;
// Contatenate the bytes and return the result.
return (resultX << 8) | resultY;
}
inline Vector3DFloat decodeNormal(const uint16_t& encodedNormal)
{
// Extract the two bytes from the uint16_t.
uint16_t ux = (encodedNormal >> 8) & 0xFF;
uint16_t uy = (encodedNormal ) & 0xFF;
// Convert to floats in the range [-1.0f, +1.0f].
float ex = ux / 127.5f - 1.0f;
float ey = uy / 127.5f - 1.0f;
// Reconstruct the origninal vector. This is a C++ implementation
// of Listing 2 of http://jcgt.org/published/0003/02/01/
float vx = ex;
float vy = ey;
float vz = 1.0f - std::abs(ex) - std::abs(ey);
if (vz < 0.0f)
{
float refX = ((1.0f - std::abs(vy)) * (vx >= 0.0f ? +1.0f : -1.0f));
float refY = ((1.0f - std::abs(vx)) * (vy >= 0.0f ? +1.0f : -1.0f));
vx = refX;
vy = refY;
}
// Normalise and return the result.
Vector3DFloat v(vx, vy, vz);
v.normalise();
return v;
}
/// Decodes a MarchingCubesVertex by converting it into a regular Vertex which can then be directly used for rendering.
template<typename DataType>
Vertex<DataType> decodeVertex(const MarchingCubesVertex<DataType>& marchingCubesVertex)
{
Vertex<DataType> result;
result.position = decodePosition(marchingCubesVertex.encodedPosition);
result.normal = decodeNormal(marchingCubesVertex.encodedNormal);
result.data = marchingCubesVertex.data; // Data is not encoded
return result;
}
/// Do not use this class directly. Use the 'extractMarchingCubesSurface' function instead (see examples).

View File

@ -1,91 +1,91 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Material_H__
#define __PolyVox_Material_H__
#include "Impl/TypeDef.h"
#include "PolyVoxCore/DefaultIsQuadNeeded.h" //we'll specialise this function for this voxel type
namespace PolyVox
{
///This class represents a voxel storing only a material.
////////////////////////////////////////////////////////////////////////////////
/// Detailed description...
///
/// \sa Density, MaterialDensityPair
////////////////////////////////////////////////////////////////////////////////
template <typename Type>
class Material
{
public:
Material() : m_uMaterial(0) {}
Material(Type uMaterial) : m_uMaterial(uMaterial) {}
bool operator==(const Material& rhs) const
{
return (m_uMaterial == rhs.m_uMaterial);
};
bool operator!=(const Material& rhs) const
{
return !(*this == rhs);
}
/// \return The current material value of the voxel
Type getMaterial() const { return m_uMaterial; }
/**
* Set the material value of the voxel
*
* \param uMaterial The material to set to
*/
void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; }
private:
Type m_uMaterial;
};
typedef Material<uint8_t> Material8;
typedef Material<uint16_t> Material16;
template<typename Type>
class DefaultIsQuadNeeded< Material<Type> >
{
public:
bool operator()(Material<Type> back, Material<Type> front, Material<Type>& materialToUse)
{
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
{
materialToUse = back;
return true;
}
else
{
return false;
}
}
};
}
#endif //__PolyVox_Material_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Material_H__
#define __PolyVox_Material_H__
#include "Impl/TypeDef.h"
#include "PolyVoxCore/DefaultIsQuadNeeded.h" //we'll specialise this function for this voxel type
namespace PolyVox
{
///This class represents a voxel storing only a material.
////////////////////////////////////////////////////////////////////////////////
/// Detailed description...
///
/// \sa Density, MaterialDensityPair
////////////////////////////////////////////////////////////////////////////////
template <typename Type>
class Material
{
public:
Material() : m_uMaterial(0) {}
Material(Type uMaterial) : m_uMaterial(uMaterial) {}
bool operator==(const Material& rhs) const
{
return (m_uMaterial == rhs.m_uMaterial);
};
bool operator!=(const Material& rhs) const
{
return !(*this == rhs);
}
/// \return The current material value of the voxel
Type getMaterial() const { return m_uMaterial; }
/**
* Set the material value of the voxel
*
* \param uMaterial The material to set to
*/
void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; }
private:
Type m_uMaterial;
};
typedef Material<uint8_t> Material8;
typedef Material<uint16_t> Material16;
template<typename Type>
class DefaultIsQuadNeeded< Material<Type> >
{
public:
bool operator()(Material<Type> back, Material<Type> front, Material<Type>& materialToUse)
{
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
{
materialToUse = back;
return true;
}
else
{
return false;
}
}
};
}
#endif //__PolyVox_Material_H__

View File

@ -1,165 +1,165 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_MaterialDensityPair_H__
#define __PolyVox_MaterialDensityPair_H__
#include "PolyVoxCore/DefaultIsQuadNeeded.h" //we'll specialise this function for this voxel type
#include "PolyVoxCore/DefaultMarchingCubesController.h" //We'll specialise the controller contained in here
#include "Impl/TypeDef.h"
namespace PolyVox
{
/// This class represents a voxel storing only a density.
////////////////////////////////////////////////////////////////////////////////
/// Detailed description...
///
/// \sa Density, Material
////////////////////////////////////////////////////////////////////////////////
template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
class MaterialDensityPair
{
public:
MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {}
MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {}
bool operator==(const MaterialDensityPair& rhs) const
{
return (m_uMaterial == rhs.m_uMaterial) && (m_uDensity == rhs.m_uDensity);
};
bool operator!=(const MaterialDensityPair& rhs) const
{
return !(*this == rhs);
}
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& operator+=(const MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& rhs)
{
m_uDensity += rhs.m_uDensity;
// What should we do with the material? Conceptually the idea of adding materials makes no sense, but for our
// purposes we consider the 'sum' of two materials to just be the max. At least this way it is commutative.
m_uMaterial = (std::max)(m_uMaterial, rhs.m_uMaterial);
return *this;
}
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& operator/=(uint32_t rhs)
{
// There's nothing sensible we can do with the material, so this function only affects the density.
m_uDensity /= rhs;
return *this;
}
Type getDensity() const { return m_uDensity; }
Type getMaterial() const { return m_uMaterial; }
void setDensity(Type uDensity) { m_uDensity = uDensity; }
void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; }
static Type getMaxDensity() { return (0x01 << NoOfDensityBits) - 1; }
static Type getMinDensity() { return 0; }
private:
Type m_uMaterial : NoOfMaterialBits;
Type m_uDensity : NoOfDensityBits;
};
template<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
class DefaultIsQuadNeeded< MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> >
{
public:
bool operator()(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> back, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> front, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& materialToUse)
{
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
{
materialToUse = back;
return true;
}
else
{
return false;
}
}
};
template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
class DefaultMarchingCubesController< MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> >
{
public:
typedef Type DensityType;
typedef Type MaterialType;
DefaultMarchingCubesController(void)
{
// Default to a threshold value halfway between the min and max possible values.
m_tThreshold = (MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getMinDensity() + MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getMaxDensity()) / 2;
}
DefaultMarchingCubesController(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
DensityType convertToDensity(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> voxel)
{
return voxel.getDensity();
}
MaterialType convertToMaterial(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> voxel)
{
return voxel.getMaterial();
}
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> blendMaterials(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> a, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> b, float /*weight*/)
{
if(convertToDensity(a) > convertToDensity(b))
{
return a;
}
else
{
return b;
}
}
DensityType getThreshold(void)
{
return m_tThreshold;
}
void setThreshold(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
private:
DensityType m_tThreshold;
};
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
typedef MaterialDensityPair<uint16_t, 8, 8> MaterialDensityPair88;
}
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_MaterialDensityPair_H__
#define __PolyVox_MaterialDensityPair_H__
#include "PolyVoxCore/DefaultIsQuadNeeded.h" //we'll specialise this function for this voxel type
#include "PolyVoxCore/DefaultMarchingCubesController.h" //We'll specialise the controller contained in here
#include "Impl/TypeDef.h"
namespace PolyVox
{
/// This class represents a voxel storing only a density.
////////////////////////////////////////////////////////////////////////////////
/// Detailed description...
///
/// \sa Density, Material
////////////////////////////////////////////////////////////////////////////////
template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
class MaterialDensityPair
{
public:
MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {}
MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {}
bool operator==(const MaterialDensityPair& rhs) const
{
return (m_uMaterial == rhs.m_uMaterial) && (m_uDensity == rhs.m_uDensity);
};
bool operator!=(const MaterialDensityPair& rhs) const
{
return !(*this == rhs);
}
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& operator+=(const MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& rhs)
{
m_uDensity += rhs.m_uDensity;
// What should we do with the material? Conceptually the idea of adding materials makes no sense, but for our
// purposes we consider the 'sum' of two materials to just be the max. At least this way it is commutative.
m_uMaterial = (std::max)(m_uMaterial, rhs.m_uMaterial);
return *this;
}
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& operator/=(uint32_t rhs)
{
// There's nothing sensible we can do with the material, so this function only affects the density.
m_uDensity /= rhs;
return *this;
}
Type getDensity() const { return m_uDensity; }
Type getMaterial() const { return m_uMaterial; }
void setDensity(Type uDensity) { m_uDensity = uDensity; }
void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; }
static Type getMaxDensity() { return (0x01 << NoOfDensityBits) - 1; }
static Type getMinDensity() { return 0; }
private:
Type m_uMaterial : NoOfMaterialBits;
Type m_uDensity : NoOfDensityBits;
};
template<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
class DefaultIsQuadNeeded< MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> >
{
public:
bool operator()(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> back, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> front, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& materialToUse)
{
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
{
materialToUse = back;
return true;
}
else
{
return false;
}
}
};
template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
class DefaultMarchingCubesController< MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> >
{
public:
typedef Type DensityType;
typedef Type MaterialType;
DefaultMarchingCubesController(void)
{
// Default to a threshold value halfway between the min and max possible values.
m_tThreshold = (MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getMinDensity() + MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getMaxDensity()) / 2;
}
DefaultMarchingCubesController(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
DensityType convertToDensity(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> voxel)
{
return voxel.getDensity();
}
MaterialType convertToMaterial(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> voxel)
{
return voxel.getMaterial();
}
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> blendMaterials(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> a, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> b, float /*weight*/)
{
if(convertToDensity(a) > convertToDensity(b))
{
return a;
}
else
{
return b;
}
}
DensityType getThreshold(void)
{
return m_tThreshold;
}
void setThreshold(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
private:
DensityType m_tThreshold;
};
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
typedef MaterialDensityPair<uint16_t, 8, 8> MaterialDensityPair88;
}
#endif

View File

@ -1,195 +1,195 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_ForwardDeclarations_H__
#define __PolyVox_ForwardDeclarations_H__
#include "Impl/TypeDef.h"
#include <cstdint>
namespace PolyVox
{
////////////////////////////////////////////////////////////////////////////////
// Array
////////////////////////////////////////////////////////////////////////////////
/*template<uint32_t dimensions, typename ElementType> class Array;
typedef Array<1,float> Array1DFloat;
typedef Array<1,double> Array1DDouble;
typedef Array<1,int8_t> Array1DInt8;
typedef Array<1,uint8_t> Array1DUint8;
typedef Array<1,int16_t> Array1DInt16;
typedef Array<1,uint16_t> Array1DUint16;
typedef Array<1,int32_t> Array1DInt32;
typedef Array<1,uint32_t> Array1DUint32;*/
/*typedef Array<2,float> Array2DFloat;
typedef Array<2,double> Array2DDouble;
typedef Array<2,int8_t> Array2DInt8;
typedef Array<2,uint8_t> Array2DUint8;
typedef Array<2,int16_t> Array2DInt16;
typedef Array<2,uint16_t> Array2DUint16;
typedef Array<2,int32_t> Array2DInt32;
typedef Array<2,uint32_t> Array2DUint32;*/
/*typedef Array<3,float> Array3DFloat;
typedef Array<3,double> Array3DDouble;
typedef Array<3,int8_t> Array3DInt8;
typedef Array<3,uint8_t> Array3DUint8;
typedef Array<3,int16_t> Array3DInt16;
typedef Array<3,uint16_t> Array3DUint16;
typedef Array<3,int32_t> Array3DInt32;
typedef Array<3,uint32_t> Array3DUint32;*/
////////////////////////////////////////////////////////////////////////////////
// Compressor
////////////////////////////////////////////////////////////////////////////////
class Compressor;
////////////////////////////////////////////////////////////////////////////////
// CubicSurfaceExtractor
////////////////////////////////////////////////////////////////////////////////
template<typename VoxelType> class DefaultIsQuadNeeded;
template<typename VolumeType, typename MeshType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> > class CubicSurfaceExtractor;
////////////////////////////////////////////////////////////////////////////////
// CubicVertex
////////////////////////////////////////////////////////////////////////////////
template<typename VoxelType> struct CubicVertex;
////////////////////////////////////////////////////////////////////////////////
// Density
////////////////////////////////////////////////////////////////////////////////
template <typename Type> class Density;
typedef Density<int8_t> DensityI8;
typedef Density<uint8_t> DensityU8;
typedef Density<int16_t> DensityI16;
typedef Density<uint16_t> DensityU16;
typedef Density<float> DensityFloat;
typedef Density<double> DensityDouble;
typedef DensityU8 Density8; //Backwards compatibility
typedef DensityU16 Density16; //Backwards compatibility
////////////////////////////////////////////////////////////////////////////////
// FilePager
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class FilePager;
////////////////////////////////////////////////////////////////////////////////
// MarchingCubesSurfaceExtractor
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType, typename MeshType, typename ControllerType> class MarchingCubesSurfaceExtractor;
////////////////////////////////////////////////////////////////////////////////
// MarchingCubesVertex
////////////////////////////////////////////////////////////////////////////////
template<typename VoxelType> struct MarchingCubesVertex;
////////////////////////////////////////////////////////////////////////////////
// Material
////////////////////////////////////////////////////////////////////////////////
template <typename Type> class Material;
typedef Material<uint8_t> MaterialU8;
typedef Material<uint16_t> MaterialU16;
typedef Material<uint32_t> MaterialU32;
typedef MaterialU8 Material8;
typedef MaterialU16 Material16;
typedef MaterialU32 Material32;
////////////////////////////////////////////////////////////////////////////////
// MaterialDensityPair
////////////////////////////////////////////////////////////////////////////////
template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> class MaterialDensityPair;
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
typedef MaterialDensityPair<uint16_t, 8, 8> MaterialDensityPair88;
////////////////////////////////////////////////////////////////////////////////
// Mesh
////////////////////////////////////////////////////////////////////////////////
typedef uint32_t DefaultIndexType;
template <typename VertexType, typename IndexType = DefaultIndexType> class Mesh;
////////////////////////////////////////////////////////////////////////////////
// PagedVolume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class PagedVolume;
template <typename VoxelType>
using LargeVolume = PagedVolume<VoxelType>;
template <typename VoxelType>
using SimpleVolume = PagedVolume<VoxelType>;
////////////////////////////////////////////////////////////////////////////////
// Pager
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class Pager;
////////////////////////////////////////////////////////////////////////////////
// RawVolume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class RawVolume;
////////////////////////////////////////////////////////////////////////////////
// Region
////////////////////////////////////////////////////////////////////////////////
class Region;
////////////////////////////////////////////////////////////////////////////////
// Vector
////////////////////////////////////////////////////////////////////////////////
template <uint32_t Size, typename StorageType, typename OperationType = StorageType> class Vector;
typedef Vector<2,float,float> Vector2DFloat;
typedef Vector<2,double,double> Vector2DDouble;
typedef Vector<2,int8_t,int32_t> Vector2DInt8;
typedef Vector<2,uint8_t,int32_t> Vector2DUint8;
typedef Vector<2,int16_t,int32_t> Vector2DInt16;
typedef Vector<2,uint16_t,int32_t> Vector2DUint16;
typedef Vector<2,int32_t,int32_t> Vector2DInt32;
typedef Vector<2,uint32_t,int32_t> Vector2DUint32;
typedef Vector<3,float,float> Vector3DFloat;
typedef Vector<3,double,double> Vector3DDouble;
typedef Vector<3,int8_t,int32_t> Vector3DInt8;
typedef Vector<3,uint8_t,int32_t> Vector3DUint8;
typedef Vector<3,int16_t,int32_t> Vector3DInt16;
typedef Vector<3,uint16_t,int32_t> Vector3DUint16;
typedef Vector<3,int32_t,int32_t> Vector3DInt32;
typedef Vector<3,uint32_t,int32_t> Vector3DUint32;
typedef Vector<4,float,float> Vector4DFloat;
typedef Vector<4,double,double> Vector4DDouble;
typedef Vector<4,int8_t,int32_t> Vector4DInt8;
typedef Vector<4,uint8_t,int32_t> Vector4DUint8;
typedef Vector<4,int16_t,int32_t> Vector4DInt16;
typedef Vector<4,uint16_t,int32_t> Vector4DUint16;
typedef Vector<4,int32_t,int32_t> Vector4DInt32;
typedef Vector<4,uint32_t,int32_t> Vector4DUint32;
}
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_ForwardDeclarations_H__
#define __PolyVox_ForwardDeclarations_H__
#include "Impl/TypeDef.h"
#include <cstdint>
namespace PolyVox
{
////////////////////////////////////////////////////////////////////////////////
// Array
////////////////////////////////////////////////////////////////////////////////
/*template<uint32_t dimensions, typename ElementType> class Array;
typedef Array<1,float> Array1DFloat;
typedef Array<1,double> Array1DDouble;
typedef Array<1,int8_t> Array1DInt8;
typedef Array<1,uint8_t> Array1DUint8;
typedef Array<1,int16_t> Array1DInt16;
typedef Array<1,uint16_t> Array1DUint16;
typedef Array<1,int32_t> Array1DInt32;
typedef Array<1,uint32_t> Array1DUint32;*/
/*typedef Array<2,float> Array2DFloat;
typedef Array<2,double> Array2DDouble;
typedef Array<2,int8_t> Array2DInt8;
typedef Array<2,uint8_t> Array2DUint8;
typedef Array<2,int16_t> Array2DInt16;
typedef Array<2,uint16_t> Array2DUint16;
typedef Array<2,int32_t> Array2DInt32;
typedef Array<2,uint32_t> Array2DUint32;*/
/*typedef Array<3,float> Array3DFloat;
typedef Array<3,double> Array3DDouble;
typedef Array<3,int8_t> Array3DInt8;
typedef Array<3,uint8_t> Array3DUint8;
typedef Array<3,int16_t> Array3DInt16;
typedef Array<3,uint16_t> Array3DUint16;
typedef Array<3,int32_t> Array3DInt32;
typedef Array<3,uint32_t> Array3DUint32;*/
////////////////////////////////////////////////////////////////////////////////
// Compressor
////////////////////////////////////////////////////////////////////////////////
class Compressor;
////////////////////////////////////////////////////////////////////////////////
// CubicSurfaceExtractor
////////////////////////////////////////////////////////////////////////////////
template<typename VoxelType> class DefaultIsQuadNeeded;
template<typename VolumeType, typename MeshType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> > class CubicSurfaceExtractor;
////////////////////////////////////////////////////////////////////////////////
// CubicVertex
////////////////////////////////////////////////////////////////////////////////
template<typename VoxelType> struct CubicVertex;
////////////////////////////////////////////////////////////////////////////////
// Density
////////////////////////////////////////////////////////////////////////////////
template <typename Type> class Density;
typedef Density<int8_t> DensityI8;
typedef Density<uint8_t> DensityU8;
typedef Density<int16_t> DensityI16;
typedef Density<uint16_t> DensityU16;
typedef Density<float> DensityFloat;
typedef Density<double> DensityDouble;
typedef DensityU8 Density8; //Backwards compatibility
typedef DensityU16 Density16; //Backwards compatibility
////////////////////////////////////////////////////////////////////////////////
// FilePager
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class FilePager;
////////////////////////////////////////////////////////////////////////////////
// MarchingCubesSurfaceExtractor
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType, typename MeshType, typename ControllerType> class MarchingCubesSurfaceExtractor;
////////////////////////////////////////////////////////////////////////////////
// MarchingCubesVertex
////////////////////////////////////////////////////////////////////////////////
template<typename VoxelType> struct MarchingCubesVertex;
////////////////////////////////////////////////////////////////////////////////
// Material
////////////////////////////////////////////////////////////////////////////////
template <typename Type> class Material;
typedef Material<uint8_t> MaterialU8;
typedef Material<uint16_t> MaterialU16;
typedef Material<uint32_t> MaterialU32;
typedef MaterialU8 Material8;
typedef MaterialU16 Material16;
typedef MaterialU32 Material32;
////////////////////////////////////////////////////////////////////////////////
// MaterialDensityPair
////////////////////////////////////////////////////////////////////////////////
template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> class MaterialDensityPair;
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
typedef MaterialDensityPair<uint16_t, 8, 8> MaterialDensityPair88;
////////////////////////////////////////////////////////////////////////////////
// Mesh
////////////////////////////////////////////////////////////////////////////////
typedef uint32_t DefaultIndexType;
template <typename VertexType, typename IndexType = DefaultIndexType> class Mesh;
////////////////////////////////////////////////////////////////////////////////
// PagedVolume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class PagedVolume;
template <typename VoxelType>
using LargeVolume = PagedVolume<VoxelType>;
template <typename VoxelType>
using SimpleVolume = PagedVolume<VoxelType>;
////////////////////////////////////////////////////////////////////////////////
// Pager
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class Pager;
////////////////////////////////////////////////////////////////////////////////
// RawVolume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class RawVolume;
////////////////////////////////////////////////////////////////////////////////
// Region
////////////////////////////////////////////////////////////////////////////////
class Region;
////////////////////////////////////////////////////////////////////////////////
// Vector
////////////////////////////////////////////////////////////////////////////////
template <uint32_t Size, typename StorageType, typename OperationType = StorageType> class Vector;
typedef Vector<2,float,float> Vector2DFloat;
typedef Vector<2,double,double> Vector2DDouble;
typedef Vector<2,int8_t,int32_t> Vector2DInt8;
typedef Vector<2,uint8_t,int32_t> Vector2DUint8;
typedef Vector<2,int16_t,int32_t> Vector2DInt16;
typedef Vector<2,uint16_t,int32_t> Vector2DUint16;
typedef Vector<2,int32_t,int32_t> Vector2DInt32;
typedef Vector<2,uint32_t,int32_t> Vector2DUint32;
typedef Vector<3,float,float> Vector3DFloat;
typedef Vector<3,double,double> Vector3DDouble;
typedef Vector<3,int8_t,int32_t> Vector3DInt8;
typedef Vector<3,uint8_t,int32_t> Vector3DUint8;
typedef Vector<3,int16_t,int32_t> Vector3DInt16;
typedef Vector<3,uint16_t,int32_t> Vector3DUint16;
typedef Vector<3,int32_t,int32_t> Vector3DInt32;
typedef Vector<3,uint32_t,int32_t> Vector3DUint32;
typedef Vector<4,float,float> Vector4DFloat;
typedef Vector<4,double,double> Vector4DDouble;
typedef Vector<4,int8_t,int32_t> Vector4DInt8;
typedef Vector<4,uint8_t,int32_t> Vector4DUint8;
typedef Vector<4,int16_t,int32_t> Vector4DInt16;
typedef Vector<4,uint16_t,int32_t> Vector4DUint16;
typedef Vector<4,int32_t,int32_t> Vector4DInt32;
typedef Vector<4,uint32_t,int32_t> Vector4DUint32;
}
#endif

View File

@ -1,173 +1,173 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_RawVolume_H__
#define __PolyVox_RawVolume_H__
#include "PolyVoxCore/BaseVolume.h"
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Vector.h"
#include <cstdlib> //For abort()
#include <limits>
#include <memory>
#include <stdexcept> //For invalid_argument
namespace PolyVox
{
template <typename VoxelType>
class RawVolume : public BaseVolume<VoxelType>
{
public:
#ifndef SWIG
//There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared.
//There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but
//which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler
//option. For now it seems best to 'fix' it with the preprocessor insstead, but maybe the workaround can be reinstated
//in the future
//typedef Volume<VoxelType> VolumeOfVoxelType; //Workaround for GCC/VS2010 differences.
//class Sampler : public VolumeOfVoxelType::template Sampler< RawVolume<VoxelType> >
#if defined(_MSC_VER)
class Sampler : public BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> > //This line works on VS2010
#else
class Sampler : public BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> > //This line works on GCC
#endif
{
public:
Sampler(RawVolume<VoxelType>* volume);
~Sampler();
inline VoxelType getVoxel(void) const;
void setPosition(const Vector3DInt32& v3dNewPos);
void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
inline bool setVoxel(VoxelType tValue);
void movePositiveX(void);
void movePositiveY(void);
void movePositiveZ(void);
void moveNegativeX(void);
void moveNegativeY(void);
void moveNegativeZ(void);
inline VoxelType peekVoxel1nx1ny1nz(void) const;
inline VoxelType peekVoxel1nx1ny0pz(void) const;
inline VoxelType peekVoxel1nx1ny1pz(void) const;
inline VoxelType peekVoxel1nx0py1nz(void) const;
inline VoxelType peekVoxel1nx0py0pz(void) const;
inline VoxelType peekVoxel1nx0py1pz(void) const;
inline VoxelType peekVoxel1nx1py1nz(void) const;
inline VoxelType peekVoxel1nx1py0pz(void) const;
inline VoxelType peekVoxel1nx1py1pz(void) const;
inline VoxelType peekVoxel0px1ny1nz(void) const;
inline VoxelType peekVoxel0px1ny0pz(void) const;
inline VoxelType peekVoxel0px1ny1pz(void) const;
inline VoxelType peekVoxel0px0py1nz(void) const;
inline VoxelType peekVoxel0px0py0pz(void) const;
inline VoxelType peekVoxel0px0py1pz(void) const;
inline VoxelType peekVoxel0px1py1nz(void) const;
inline VoxelType peekVoxel0px1py0pz(void) const;
inline VoxelType peekVoxel0px1py1pz(void) const;
inline VoxelType peekVoxel1px1ny1nz(void) const;
inline VoxelType peekVoxel1px1ny0pz(void) const;
inline VoxelType peekVoxel1px1ny1pz(void) const;
inline VoxelType peekVoxel1px0py1nz(void) const;
inline VoxelType peekVoxel1px0py0pz(void) const;
inline VoxelType peekVoxel1px0py1pz(void) const;
inline VoxelType peekVoxel1px1py1nz(void) const;
inline VoxelType peekVoxel1px1py0pz(void) const;
inline VoxelType peekVoxel1px1py1pz(void) const;
private:
//Other current position information
VoxelType* mCurrentVoxel;
};
#endif
public:
/// Constructor for creating a fixed size volume.
RawVolume(const Region& regValid);
/// Destructor
~RawVolume();
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
template <WrapMode eWrapMode>
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by a 3D vector
template <WrapMode eWrapMode>
VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by a 3D vector
VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector
POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate);
/// Sets the voxel at the position given by a 3D vector
void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate);
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
/// Sets the voxel at the position given by a 3D vector
bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue);
/// Calculates approximatly how many bytes of memory the volume is currently using.
uint32_t calculateSizeInBytes(void);
protected:
/// Copy constructor
RawVolume(const RawVolume& rhs);
/// Assignment operator
RawVolume& operator=(const RawVolume& rhs);
private:
void initialise(const Region& regValidRegion);
// A trick to implement specialization of template member functions in template classes. See http://stackoverflow.com/a/4951057
template <WrapMode eWrapMode>
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<eWrapMode>, VoxelType tBorder) const;
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Validate>, VoxelType tBorder) const;
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Clamp>, VoxelType tBorder) const;
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Border>, VoxelType tBorder) const;
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::AssumeValid>, VoxelType tBorder) const;
//The voxel data
VoxelType* m_pData;
};
}
#include "PolyVoxCore/RawVolume.inl"
#include "PolyVoxCore/RawVolumeSampler.inl"
#endif //__PolyVox_RawVolume_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_RawVolume_H__
#define __PolyVox_RawVolume_H__
#include "PolyVoxCore/BaseVolume.h"
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Vector.h"
#include <cstdlib> //For abort()
#include <limits>
#include <memory>
#include <stdexcept> //For invalid_argument
namespace PolyVox
{
template <typename VoxelType>
class RawVolume : public BaseVolume<VoxelType>
{
public:
#ifndef SWIG
//There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared.
//There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but
//which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler
//option. For now it seems best to 'fix' it with the preprocessor insstead, but maybe the workaround can be reinstated
//in the future
//typedef Volume<VoxelType> VolumeOfVoxelType; //Workaround for GCC/VS2010 differences.
//class Sampler : public VolumeOfVoxelType::template Sampler< RawVolume<VoxelType> >
#if defined(_MSC_VER)
class Sampler : public BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> > //This line works on VS2010
#else
class Sampler : public BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> > //This line works on GCC
#endif
{
public:
Sampler(RawVolume<VoxelType>* volume);
~Sampler();
inline VoxelType getVoxel(void) const;
void setPosition(const Vector3DInt32& v3dNewPos);
void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
inline bool setVoxel(VoxelType tValue);
void movePositiveX(void);
void movePositiveY(void);
void movePositiveZ(void);
void moveNegativeX(void);
void moveNegativeY(void);
void moveNegativeZ(void);
inline VoxelType peekVoxel1nx1ny1nz(void) const;
inline VoxelType peekVoxel1nx1ny0pz(void) const;
inline VoxelType peekVoxel1nx1ny1pz(void) const;
inline VoxelType peekVoxel1nx0py1nz(void) const;
inline VoxelType peekVoxel1nx0py0pz(void) const;
inline VoxelType peekVoxel1nx0py1pz(void) const;
inline VoxelType peekVoxel1nx1py1nz(void) const;
inline VoxelType peekVoxel1nx1py0pz(void) const;
inline VoxelType peekVoxel1nx1py1pz(void) const;
inline VoxelType peekVoxel0px1ny1nz(void) const;
inline VoxelType peekVoxel0px1ny0pz(void) const;
inline VoxelType peekVoxel0px1ny1pz(void) const;
inline VoxelType peekVoxel0px0py1nz(void) const;
inline VoxelType peekVoxel0px0py0pz(void) const;
inline VoxelType peekVoxel0px0py1pz(void) const;
inline VoxelType peekVoxel0px1py1nz(void) const;
inline VoxelType peekVoxel0px1py0pz(void) const;
inline VoxelType peekVoxel0px1py1pz(void) const;
inline VoxelType peekVoxel1px1ny1nz(void) const;
inline VoxelType peekVoxel1px1ny0pz(void) const;
inline VoxelType peekVoxel1px1ny1pz(void) const;
inline VoxelType peekVoxel1px0py1nz(void) const;
inline VoxelType peekVoxel1px0py0pz(void) const;
inline VoxelType peekVoxel1px0py1pz(void) const;
inline VoxelType peekVoxel1px1py1nz(void) const;
inline VoxelType peekVoxel1px1py0pz(void) const;
inline VoxelType peekVoxel1px1py1pz(void) const;
private:
//Other current position information
VoxelType* mCurrentVoxel;
};
#endif
public:
/// Constructor for creating a fixed size volume.
RawVolume(const Region& regValid);
/// Destructor
~RawVolume();
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
template <WrapMode eWrapMode>
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by a 3D vector
template <WrapMode eWrapMode>
VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by a 3D vector
VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector
POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate);
/// Sets the voxel at the position given by a 3D vector
void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate);
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
/// Sets the voxel at the position given by a 3D vector
bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue);
/// Calculates approximatly how many bytes of memory the volume is currently using.
uint32_t calculateSizeInBytes(void);
protected:
/// Copy constructor
RawVolume(const RawVolume& rhs);
/// Assignment operator
RawVolume& operator=(const RawVolume& rhs);
private:
void initialise(const Region& regValidRegion);
// A trick to implement specialization of template member functions in template classes. See http://stackoverflow.com/a/4951057
template <WrapMode eWrapMode>
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<eWrapMode>, VoxelType tBorder) const;
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Validate>, VoxelType tBorder) const;
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Clamp>, VoxelType tBorder) const;
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Border>, VoxelType tBorder) const;
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::AssumeValid>, VoxelType tBorder) const;
//The voxel data
VoxelType* m_pData;
};
}
#include "PolyVoxCore/RawVolume.inl"
#include "PolyVoxCore/RawVolumeSampler.inl"
#endif //__PolyVox_RawVolume_H__

View File

@ -1,390 +1,390 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
////////////////////////////////////////////////////////////////////////////////
/// This constructor creates a volume with a fixed size which is specified as a parameter.
/// \param regValid Specifies the minimum and maximum valid voxel positions.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>::RawVolume(const Region& regValid)
:BaseVolume<VoxelType>(regValid)
{
this->setBorderValue(VoxelType());
//Create a volume of the right size.
initialise(regValid);
}
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>::RawVolume(const RawVolume<VoxelType>& /*rhs*/)
{
POLYVOX_THROW(not_implemented, "Volume copy constructor not implemented for performance reasons.");
}
////////////////////////////////////////////////////////////////////////////////
/// Destroys the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>::~RawVolume()
{
delete[] m_pData;
m_pData = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>& RawVolume<VoxelType>::operator=(const RawVolume<VoxelType>& /*rhs*/)
{
POLYVOX_THROW(not_implemented, "Volume assignment operator not implemented for performance reasons.");
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function requires the wrap mode to be specified as a
/// template parameter, which can provide better performance.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType RawVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder) const
{
// Simply call through to the real implementation
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<eWrapMode>(), tBorder);
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function requires the wrap mode to be specified as a
/// template parameter, which can provide better performance.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType RawVolume<VoxelType>::getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder) const
{
// Simply call through to the real implementation
return getVoxel<eWrapMode>(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tBorder);
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function is provided so that the wrap mode does not need
/// to be specified as a template parameter, as it may be confusing to some users.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const
{
switch(eWrapMode)
{
case WrapModes::Validate:
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::Validate>(), tBorder);
case WrapModes::Clamp:
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::Clamp>(), tBorder);
case WrapModes::Border:
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::Border>(), tBorder);
case WrapModes::AssumeValid:
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::AssumeValid>(), tBorder);
default:
// Should never happen
POLYVOX_ASSERT(false, "Invalid wrap mode");
return VoxelType();
}
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function is provided so that the wrap mode does not need
/// to be specified as a template parameter, as it may be confusing to some users.
/// \param v3dPos The 3D position of the voxel
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const
{
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder);
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
{
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
{
const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
return m_pData
[
iLocalXPos +
iLocalYPos * this->getWidth() +
iLocalZPos * this->getWidth() * this->getHeight()
];
}
else
{
return this->getBorderValue();
}
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos The 3D position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelAt(const Vector3DInt32& v3dPos) const
{
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel
/// \param uZPos the \c z position of the voxel
/// \param tValue the value to which the voxel will be set
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void RawVolume<VoxelType>::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode)
{
if((eWrapMode != WrapModes::Validate) && (eWrapMode != WrapModes::AssumeValid))
{
POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'.");
}
// This validation is skipped if the wrap mode is 'DontCheck'
if(eWrapMode == WrapModes::Validate)
{
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false)
{
POLYVOX_THROW(std::out_of_range, "Position is outside valid region");
}
}
const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
m_pData
[
iLocalXPos +
iLocalYPos * this->getWidth() +
iLocalZPos * this->getWidth() * this->getHeight()
] = tValue;
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos the 3D position of the voxel
/// \param tValue the value to which the voxel will be set
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void RawVolume<VoxelType>::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode)
{
setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eWrapMode);
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel
/// \param uZPos the \c z position of the voxel
/// \param tValue the value to which the voxel will be set
/// \return whether the requested position is inside the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
bool RawVolume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
{
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
{
const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
m_pData
[
iLocalXPos +
iLocalYPos * this->getWidth() +
iLocalZPos * this->getWidth() * this->getHeight()
] = tValue;
//Return true to indicate that we modified a voxel.
return true;
}
else
{
return false;
}
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos the 3D position of the voxel
/// \param tValue the value to which the voxel will be set
/// \return whether the requested position is inside the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
bool RawVolume<VoxelType>::setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue)
{
return setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
}
////////////////////////////////////////////////////////////////////////////////
/// This function should probably be made internal...
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void RawVolume<VoxelType>::initialise(const Region& regValidRegion)
{
this->m_regValidRegion = regValidRegion;
if(this->getWidth() <= 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume width must be greater than zero.");
}
if(this->getHeight() <= 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume height must be greater than zero.");
}
if(this->getDepth() <= 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume depth must be greater than zero.");
}
//Create the data
m_pData = new VoxelType[this->getWidth() * this->getHeight()* this->getDepth()];
//Other properties we might find useful later
this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth());
this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth());
this->m_fDiagonalLength = sqrtf(static_cast<float>(this->getWidth() * this->getWidth() + this->getHeight() * this->getHeight() + this->getDepth() * this->getDepth()));
}
////////////////////////////////////////////////////////////////////////////////
/// Note: This function needs reviewing for accuracy...
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
uint32_t RawVolume<VoxelType>::calculateSizeInBytes(void)
{
return this->getWidth() * this->getHeight() * this->getDepth() * sizeof(VoxelType);
}
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<eWrapMode>, VoxelType tBorder) const
{
// This function should never be called because one of the specialisations should always match.
POLYVOX_ASSERT(false, "This function is not implemented and should never be called!");
}
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Validate>, VoxelType tBorder) const
{
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false)
{
POLYVOX_THROW(std::out_of_range, "Position is outside valid region");
}
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::AssumeValid>(), tBorder); // No wrapping as we've just validated the position.
}
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Clamp>, VoxelType tBorder) const
{
//Perform clamping
uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX());
uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY());
uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ());
uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX());
uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY());
uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ());
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::AssumeValid>(), tBorder); // No wrapping as we've just validated the position.
}
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Border>, VoxelType tBorder) const
{
if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos))
{
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::AssumeValid>(), tBorder); // No wrapping as we've just validated the position.
}
else
{
return tBorder;
}
}
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::AssumeValid>, VoxelType /*tBorder*/) const
{
const Region& regValidRegion = this->m_regValidRegion;
int32_t iLocalXPos = uXPos - regValidRegion.getLowerX();
int32_t iLocalYPos = uYPos - regValidRegion.getLowerY();
int32_t iLocalZPos = uZPos - regValidRegion.getLowerZ();
return m_pData
[
iLocalXPos +
iLocalYPos * this->getWidth() +
iLocalZPos * this->getWidth() * this->getHeight()
];
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
////////////////////////////////////////////////////////////////////////////////
/// This constructor creates a volume with a fixed size which is specified as a parameter.
/// \param regValid Specifies the minimum and maximum valid voxel positions.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>::RawVolume(const Region& regValid)
:BaseVolume<VoxelType>(regValid)
{
this->setBorderValue(VoxelType());
//Create a volume of the right size.
initialise(regValid);
}
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>::RawVolume(const RawVolume<VoxelType>& /*rhs*/)
{
POLYVOX_THROW(not_implemented, "Volume copy constructor not implemented for performance reasons.");
}
////////////////////////////////////////////////////////////////////////////////
/// Destroys the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>::~RawVolume()
{
delete[] m_pData;
m_pData = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler.
///
/// \sa VolumeResampler
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
RawVolume<VoxelType>& RawVolume<VoxelType>::operator=(const RawVolume<VoxelType>& /*rhs*/)
{
POLYVOX_THROW(not_implemented, "Volume assignment operator not implemented for performance reasons.");
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function requires the wrap mode to be specified as a
/// template parameter, which can provide better performance.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType RawVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder) const
{
// Simply call through to the real implementation
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<eWrapMode>(), tBorder);
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function requires the wrap mode to be specified as a
/// template parameter, which can provide better performance.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType RawVolume<VoxelType>::getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder) const
{
// Simply call through to the real implementation
return getVoxel<eWrapMode>(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tBorder);
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function is provided so that the wrap mode does not need
/// to be specified as a template parameter, as it may be confusing to some users.
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const
{
switch(eWrapMode)
{
case WrapModes::Validate:
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::Validate>(), tBorder);
case WrapModes::Clamp:
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::Clamp>(), tBorder);
case WrapModes::Border:
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::Border>(), tBorder);
case WrapModes::AssumeValid:
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::AssumeValid>(), tBorder);
default:
// Should never happen
POLYVOX_ASSERT(false, "Invalid wrap mode");
return VoxelType();
}
}
////////////////////////////////////////////////////////////////////////////////
/// This version of the function is provided so that the wrap mode does not need
/// to be specified as a template parameter, as it may be confusing to some users.
/// \param v3dPos The 3D position of the voxel
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// \param tBorder The border value to use if the wrap mode is set to 'Border'.
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const
{
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder);
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
{
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
{
const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
return m_pData
[
iLocalXPos +
iLocalYPos * this->getWidth() +
iLocalZPos * this->getWidth() * this->getHeight()
];
}
else
{
return this->getBorderValue();
}
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos The 3D position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelAt(const Vector3DInt32& v3dPos) const
{
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel
/// \param uZPos the \c z position of the voxel
/// \param tValue the value to which the voxel will be set
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void RawVolume<VoxelType>::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode)
{
if((eWrapMode != WrapModes::Validate) && (eWrapMode != WrapModes::AssumeValid))
{
POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'.");
}
// This validation is skipped if the wrap mode is 'DontCheck'
if(eWrapMode == WrapModes::Validate)
{
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false)
{
POLYVOX_THROW(std::out_of_range, "Position is outside valid region");
}
}
const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
m_pData
[
iLocalXPos +
iLocalYPos * this->getWidth() +
iLocalZPos * this->getWidth() * this->getHeight()
] = tValue;
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos the 3D position of the voxel
/// \param tValue the value to which the voxel will be set
/// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume.
/// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void RawVolume<VoxelType>::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode)
{
setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eWrapMode);
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel
/// \param uZPos the \c z position of the voxel
/// \param tValue the value to which the voxel will be set
/// \return whether the requested position is inside the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
bool RawVolume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
{
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
{
const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
m_pData
[
iLocalXPos +
iLocalYPos * this->getWidth() +
iLocalZPos * this->getWidth() * this->getHeight()
] = tValue;
//Return true to indicate that we modified a voxel.
return true;
}
else
{
return false;
}
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos the 3D position of the voxel
/// \param tValue the value to which the voxel will be set
/// \return whether the requested position is inside the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
bool RawVolume<VoxelType>::setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue)
{
return setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
}
////////////////////////////////////////////////////////////////////////////////
/// This function should probably be made internal...
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void RawVolume<VoxelType>::initialise(const Region& regValidRegion)
{
this->m_regValidRegion = regValidRegion;
if(this->getWidth() <= 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume width must be greater than zero.");
}
if(this->getHeight() <= 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume height must be greater than zero.");
}
if(this->getDepth() <= 0)
{
POLYVOX_THROW(std::invalid_argument, "Volume depth must be greater than zero.");
}
//Create the data
m_pData = new VoxelType[this->getWidth() * this->getHeight()* this->getDepth()];
//Other properties we might find useful later
this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth());
this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth());
this->m_fDiagonalLength = sqrtf(static_cast<float>(this->getWidth() * this->getWidth() + this->getHeight() * this->getHeight() + this->getDepth() * this->getDepth()));
}
////////////////////////////////////////////////////////////////////////////////
/// Note: This function needs reviewing for accuracy...
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
uint32_t RawVolume<VoxelType>::calculateSizeInBytes(void)
{
return this->getWidth() * this->getHeight() * this->getDepth() * sizeof(VoxelType);
}
template <typename VoxelType>
template <WrapMode eWrapMode>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<eWrapMode>, VoxelType tBorder) const
{
// This function should never be called because one of the specialisations should always match.
POLYVOX_ASSERT(false, "This function is not implemented and should never be called!");
}
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Validate>, VoxelType tBorder) const
{
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false)
{
POLYVOX_THROW(std::out_of_range, "Position is outside valid region");
}
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::AssumeValid>(), tBorder); // No wrapping as we've just validated the position.
}
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Clamp>, VoxelType tBorder) const
{
//Perform clamping
uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX());
uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY());
uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ());
uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX());
uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY());
uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ());
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::AssumeValid>(), tBorder); // No wrapping as we've just validated the position.
}
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Border>, VoxelType tBorder) const
{
if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos))
{
return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType<WrapModes::AssumeValid>(), tBorder); // No wrapping as we've just validated the position.
}
else
{
return tBorder;
}
}
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::AssumeValid>, VoxelType /*tBorder*/) const
{
const Region& regValidRegion = this->m_regValidRegion;
int32_t iLocalXPos = uXPos - regValidRegion.getLowerX();
int32_t iLocalYPos = uYPos - regValidRegion.getLowerY();
int32_t iLocalZPos = uZPos - regValidRegion.getLowerZ();
return m_pData
[
iLocalXPos +
iLocalYPos * this->getWidth() +
iLocalZPos * this->getWidth() * this->getHeight()
];
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,103 +1,103 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Raycast_H__
#define __PolyVox_Raycast_H__
#include "PolyVoxCore/Vector.h"
namespace PolyVox
{
namespace RaycastResults
{
/**
* The results of a raycast
*/
enum RaycastResult
{
Completed, ///< If the ray passed through the volume without being interupted
Interupted ///< If the ray was interupted while travelling
};
}
typedef RaycastResults::RaycastResult RaycastResult;
/// OUT OF DATE SINCE UNCLASSING
////////////////////////////////////////////////////////////////////////////////
/// \file Raycast.h
///
/// The principle behind raycasting is to fire a 'ray' through the volume and determine
/// what (if anything) that ray hits. This simple test can be used for the purpose of
/// picking, visibility checks, lighting calculations, or numerous other applications.
///
/// A ray is a stright line in space define by a start point and a direction vector.
/// The length of the direction vector represents the length of the ray. When you call a
/// Raycast object's execute() method it will iterate over each voxel which lies on the ray,
/// starting from the defined start point. It will examine each voxel and terminate
/// either when it encounters a solid voxel or when it reaches the end of the ray. If a
/// solid voxel is encountered then its position is stored in the intersectionVoxel field
/// of the RaycastResult structure and the intersectionFound flag is set to true, otherwise
/// the intersectionFound flag is set to false.
///
/// **Important Note:** These has been confusion in the past with people not realising
/// that the length of the direction vector is important. Most graphics API can provide
/// a camera position and view direction for picking purposes, but the view direction is
/// usually normalised (i.e. of length one). If you use this view direction directly you
/// will only iterate over a single voxel and won't find what you are looking for. Instead
/// you must scale the direction vector so that it's length represents the maximum distance
/// over which you want the ray to be cast.
///
/// The following code snippet shows how the class is used:
/// \code
/// Vector3DFloat start(rayOrigin.x(), rayOrigin.y(), rayOrigin.z());
/// Vector3DFloat direction(rayDir.x(), rayDir.y(), rayDir.z());
/// direction.normalise();
/// direction *= 1000.0f; //Casts ray of length 1000
///
/// RaycastResult raycastResult;
/// Raycast<Material8> raycast(m_pPolyVoxVolume, start, direction, raycastResult);
/// raycast.execute();
///
/// if(raycastResult.foundIntersection)
/// {
/// //...
/// }
/// \endcode
///
/// Some further notes, the Raycast uses full 26-connectivity, which basically means it
/// will examine every voxel the ray touches, even if it just passes through the corner.
/// Also, it peforms a simple binary test against a voxel's threshold, rather than making
/// use of it's density. Therefore it will work best in conjunction with one of the 'cubic'
/// surace extractors. It's behaviour with the Marching Cubes surface extractor has not
/// been tested yet.
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType, typename Callback>
RaycastResult raycastWithEndpoints(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dEnd, Callback& callback);
template<typename VolumeType, typename Callback>
RaycastResult raycastWithDirection(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, Callback& callback);
}
#include "PolyVoxCore/Raycast.inl"
#endif //__PolyVox_Raycast_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Raycast_H__
#define __PolyVox_Raycast_H__
#include "PolyVoxCore/Vector.h"
namespace PolyVox
{
namespace RaycastResults
{
/**
* The results of a raycast
*/
enum RaycastResult
{
Completed, ///< If the ray passed through the volume without being interupted
Interupted ///< If the ray was interupted while travelling
};
}
typedef RaycastResults::RaycastResult RaycastResult;
/// OUT OF DATE SINCE UNCLASSING
////////////////////////////////////////////////////////////////////////////////
/// \file Raycast.h
///
/// The principle behind raycasting is to fire a 'ray' through the volume and determine
/// what (if anything) that ray hits. This simple test can be used for the purpose of
/// picking, visibility checks, lighting calculations, or numerous other applications.
///
/// A ray is a stright line in space define by a start point and a direction vector.
/// The length of the direction vector represents the length of the ray. When you call a
/// Raycast object's execute() method it will iterate over each voxel which lies on the ray,
/// starting from the defined start point. It will examine each voxel and terminate
/// either when it encounters a solid voxel or when it reaches the end of the ray. If a
/// solid voxel is encountered then its position is stored in the intersectionVoxel field
/// of the RaycastResult structure and the intersectionFound flag is set to true, otherwise
/// the intersectionFound flag is set to false.
///
/// **Important Note:** These has been confusion in the past with people not realising
/// that the length of the direction vector is important. Most graphics API can provide
/// a camera position and view direction for picking purposes, but the view direction is
/// usually normalised (i.e. of length one). If you use this view direction directly you
/// will only iterate over a single voxel and won't find what you are looking for. Instead
/// you must scale the direction vector so that it's length represents the maximum distance
/// over which you want the ray to be cast.
///
/// The following code snippet shows how the class is used:
/// \code
/// Vector3DFloat start(rayOrigin.x(), rayOrigin.y(), rayOrigin.z());
/// Vector3DFloat direction(rayDir.x(), rayDir.y(), rayDir.z());
/// direction.normalise();
/// direction *= 1000.0f; //Casts ray of length 1000
///
/// RaycastResult raycastResult;
/// Raycast<Material8> raycast(m_pPolyVoxVolume, start, direction, raycastResult);
/// raycast.execute();
///
/// if(raycastResult.foundIntersection)
/// {
/// //...
/// }
/// \endcode
///
/// Some further notes, the Raycast uses full 26-connectivity, which basically means it
/// will examine every voxel the ray touches, even if it just passes through the corner.
/// Also, it peforms a simple binary test against a voxel's threshold, rather than making
/// use of it's density. Therefore it will work best in conjunction with one of the 'cubic'
/// surace extractors. It's behaviour with the Marching Cubes surface extractor has not
/// been tested yet.
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType, typename Callback>
RaycastResult raycastWithEndpoints(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dEnd, Callback& callback);
template<typename VolumeType, typename Callback>
RaycastResult raycastWithDirection(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, Callback& callback);
}
#include "PolyVoxCore/Raycast.inl"
#endif //__PolyVox_Raycast_H__

View File

@ -1,178 +1,178 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
// This function is based on Christer Ericson's code and description of the 'Uniform Grid Intersection Test' in
// 'Real Time Collision Detection'. The following information from the errata on the book website is also relevent:
//
// pages 326-327. In the function VisitCellsOverlapped() the two lines calculating tx and ty are incorrect.
// The less-than sign in each line should be a greater-than sign. That is, the two lines should read:
//
// float tx = ((x1 > x2) ? (x1 - minx) : (maxx - x1)) / Abs(x2 - x1);
// float ty = ((y1 > y2) ? (y1 - miny) : (maxy - y1)) / Abs(y2 - y1);
//
// Thanks to Jetro Lauha of Fathammer in Helsinki, Finland for reporting this error.
//
// Jetro also points out that the computations of i, j, iend, and jend are incorrectly rounded if the line
// coordinates are allowed to go negative. While that was not really the intent of the code -- that is, I
// assumed grids to be numbered from (0, 0) to (m, n) -- I'm at fault for not making my assumption clear.
// Where it is important to handle negative line coordinates the computation of these variables should be
// changed to something like this:
//
// // Determine start grid cell coordinates (i, j)
// int i = (int)floorf(x1 / CELL_SIDE);
// int j = (int)floorf(y1 / CELL_SIDE);
//
// // Determine end grid cell coordinates (iend, jend)
// int iend = (int)floorf(x2 / CELL_SIDE);
// int jend = (int)floorf(y2 / CELL_SIDE);
//
// page 328. The if-statement that reads "if (ty <= tx && ty <= tz)" has a superfluous condition.
// It should simply read "if (ty <= tz)".
//
// This error was reported by Joey Hammer (PixelActive).
/**
* Cast a ray through a volume by specifying the start and end positions
*
* The ray will move from \a v3dStart to \a v3dEnd, calling \a callback for each
* voxel it passes through until \a callback returns \a false. In this case it
* returns a RaycastResults::Interupted. If it passes from start to end
* without \a callback returning \a false, it returns RaycastResults::Completed.
*
* \param volData The volume to pass the ray though
* \param v3dStart The start position in the volume
* \param v3dEnd The end position in the volume
* \param callback The callback to call for each voxel
*
* \return A RaycastResults designating whether the ray hit anything or not
*/
template<typename VolumeType, typename Callback>
RaycastResult raycastWithEndpoints(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dEnd, Callback& callback)
{
typename VolumeType::Sampler sampler(volData);
//The doRaycast function is assuming that it is iterating over the areas defined between
//voxels. We actually want to define the areas as being centered on voxels (as this is
//what the CubicSurfaceExtractor generates). We add 0.5 here to adjust for this.
const float x1 = v3dStart.getX() + 0.5f;
const float y1 = v3dStart.getY() + 0.5f;
const float z1 = v3dStart.getZ() + 0.5f;
const float x2 = v3dEnd.getX() + 0.5f;
const float y2 = v3dEnd.getY() + 0.5f;
const float z2 = v3dEnd.getZ() + 0.5f;
int i = (int)floorf(x1);
int j = (int)floorf(y1);
int k = (int)floorf(z1);
const int iend = (int)floorf(x2);
const int jend = (int)floorf(y2);
const int kend = (int)floorf(z2);
const int di = ((x1 < x2) ? 1 : ((x1 > x2) ? -1 : 0));
const int dj = ((y1 < y2) ? 1 : ((y1 > y2) ? -1 : 0));
const int dk = ((z1 < z2) ? 1 : ((z1 > z2) ? -1 : 0));
const float deltatx = 1.0f / std::abs(x2 - x1);
const float deltaty = 1.0f / std::abs(y2 - y1);
const float deltatz = 1.0f / std::abs(z2 - z1);
const float minx = floorf(x1), maxx = minx + 1.0f;
float tx = ((x1 > x2) ? (x1 - minx) : (maxx - x1)) * deltatx;
const float miny = floorf(y1), maxy = miny + 1.0f;
float ty = ((y1 > y2) ? (y1 - miny) : (maxy - y1)) * deltaty;
const float minz = floorf(z1), maxz = minz + 1.0f;
float tz = ((z1 > z2) ? (z1 - minz) : (maxz - z1)) * deltatz;
sampler.setPosition(i,j,k);
for(;;)
{
if(!callback(sampler))
{
return RaycastResults::Interupted;
}
if(tx <= ty && tx <= tz)
{
if(i == iend) break;
tx += deltatx;
i += di;
if(di == 1) sampler.movePositiveX();
if(di == -1) sampler.moveNegativeX();
} else if (ty <= tz)
{
if(j == jend) break;
ty += deltaty;
j += dj;
if(dj == 1) sampler.movePositiveY();
if(dj == -1) sampler.moveNegativeY();
} else
{
if(k == kend) break;
tz += deltatz;
k += dk;
if(dk == 1) sampler.movePositiveZ();
if(dk == -1) sampler.moveNegativeZ();
}
}
return RaycastResults::Completed;
}
/**
* Cast a ray through a volume by specifying the start and a direction
*
* The ray will move from \a v3dStart along \a v3dDirectionAndLength, calling
* \a callback for each voxel it passes through until \a callback returns
* \a false. In this case it returns a RaycastResults::Interupted. If it
* passes from start to end without \a callback returning \a false, it
* returns RaycastResults::Completed.
*
* \note These has been confusion in the past with people not realising
* that the length of the direction vector is important. Most graphics API can provide
* a camera position and view direction for picking purposes, but the view direction is
* usually normalised (i.e. of length one). If you use this view direction directly you
* will only iterate over a single voxel and won't find what you are looking for. Instead
* you must scale the direction vector so that it's length represents the maximum distance
* over which you want the ray to be cast.
*
* \param volData The volume to pass the ray though
* \param v3dStart The start position in the volume
* \param v3dDirectionAndLength The direction and length of the ray
* \param callback The callback to call for each voxel
*
* \return A RaycastResults designating whether the ray hit anything or not
*/
template<typename VolumeType, typename Callback>
RaycastResult raycastWithDirection(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, Callback& callback)
{
Vector3DFloat v3dEnd = v3dStart + v3dDirectionAndLength;
return raycastWithEndpoints<VolumeType, Callback>(volData, v3dStart, v3dEnd, callback);
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
// This function is based on Christer Ericson's code and description of the 'Uniform Grid Intersection Test' in
// 'Real Time Collision Detection'. The following information from the errata on the book website is also relevent:
//
// pages 326-327. In the function VisitCellsOverlapped() the two lines calculating tx and ty are incorrect.
// The less-than sign in each line should be a greater-than sign. That is, the two lines should read:
//
// float tx = ((x1 > x2) ? (x1 - minx) : (maxx - x1)) / Abs(x2 - x1);
// float ty = ((y1 > y2) ? (y1 - miny) : (maxy - y1)) / Abs(y2 - y1);
//
// Thanks to Jetro Lauha of Fathammer in Helsinki, Finland for reporting this error.
//
// Jetro also points out that the computations of i, j, iend, and jend are incorrectly rounded if the line
// coordinates are allowed to go negative. While that was not really the intent of the code -- that is, I
// assumed grids to be numbered from (0, 0) to (m, n) -- I'm at fault for not making my assumption clear.
// Where it is important to handle negative line coordinates the computation of these variables should be
// changed to something like this:
//
// // Determine start grid cell coordinates (i, j)
// int i = (int)floorf(x1 / CELL_SIDE);
// int j = (int)floorf(y1 / CELL_SIDE);
//
// // Determine end grid cell coordinates (iend, jend)
// int iend = (int)floorf(x2 / CELL_SIDE);
// int jend = (int)floorf(y2 / CELL_SIDE);
//
// page 328. The if-statement that reads "if (ty <= tx && ty <= tz)" has a superfluous condition.
// It should simply read "if (ty <= tz)".
//
// This error was reported by Joey Hammer (PixelActive).
/**
* Cast a ray through a volume by specifying the start and end positions
*
* The ray will move from \a v3dStart to \a v3dEnd, calling \a callback for each
* voxel it passes through until \a callback returns \a false. In this case it
* returns a RaycastResults::Interupted. If it passes from start to end
* without \a callback returning \a false, it returns RaycastResults::Completed.
*
* \param volData The volume to pass the ray though
* \param v3dStart The start position in the volume
* \param v3dEnd The end position in the volume
* \param callback The callback to call for each voxel
*
* \return A RaycastResults designating whether the ray hit anything or not
*/
template<typename VolumeType, typename Callback>
RaycastResult raycastWithEndpoints(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dEnd, Callback& callback)
{
typename VolumeType::Sampler sampler(volData);
//The doRaycast function is assuming that it is iterating over the areas defined between
//voxels. We actually want to define the areas as being centered on voxels (as this is
//what the CubicSurfaceExtractor generates). We add 0.5 here to adjust for this.
const float x1 = v3dStart.getX() + 0.5f;
const float y1 = v3dStart.getY() + 0.5f;
const float z1 = v3dStart.getZ() + 0.5f;
const float x2 = v3dEnd.getX() + 0.5f;
const float y2 = v3dEnd.getY() + 0.5f;
const float z2 = v3dEnd.getZ() + 0.5f;
int i = (int)floorf(x1);
int j = (int)floorf(y1);
int k = (int)floorf(z1);
const int iend = (int)floorf(x2);
const int jend = (int)floorf(y2);
const int kend = (int)floorf(z2);
const int di = ((x1 < x2) ? 1 : ((x1 > x2) ? -1 : 0));
const int dj = ((y1 < y2) ? 1 : ((y1 > y2) ? -1 : 0));
const int dk = ((z1 < z2) ? 1 : ((z1 > z2) ? -1 : 0));
const float deltatx = 1.0f / std::abs(x2 - x1);
const float deltaty = 1.0f / std::abs(y2 - y1);
const float deltatz = 1.0f / std::abs(z2 - z1);
const float minx = floorf(x1), maxx = minx + 1.0f;
float tx = ((x1 > x2) ? (x1 - minx) : (maxx - x1)) * deltatx;
const float miny = floorf(y1), maxy = miny + 1.0f;
float ty = ((y1 > y2) ? (y1 - miny) : (maxy - y1)) * deltaty;
const float minz = floorf(z1), maxz = minz + 1.0f;
float tz = ((z1 > z2) ? (z1 - minz) : (maxz - z1)) * deltatz;
sampler.setPosition(i,j,k);
for(;;)
{
if(!callback(sampler))
{
return RaycastResults::Interupted;
}
if(tx <= ty && tx <= tz)
{
if(i == iend) break;
tx += deltatx;
i += di;
if(di == 1) sampler.movePositiveX();
if(di == -1) sampler.moveNegativeX();
} else if (ty <= tz)
{
if(j == jend) break;
ty += deltaty;
j += dj;
if(dj == 1) sampler.movePositiveY();
if(dj == -1) sampler.moveNegativeY();
} else
{
if(k == kend) break;
tz += deltatz;
k += dk;
if(dk == 1) sampler.movePositiveZ();
if(dk == -1) sampler.moveNegativeZ();
}
}
return RaycastResults::Completed;
}
/**
* Cast a ray through a volume by specifying the start and a direction
*
* The ray will move from \a v3dStart along \a v3dDirectionAndLength, calling
* \a callback for each voxel it passes through until \a callback returns
* \a false. In this case it returns a RaycastResults::Interupted. If it
* passes from start to end without \a callback returning \a false, it
* returns RaycastResults::Completed.
*
* \note These has been confusion in the past with people not realising
* that the length of the direction vector is important. Most graphics API can provide
* a camera position and view direction for picking purposes, but the view direction is
* usually normalised (i.e. of length one). If you use this view direction directly you
* will only iterate over a single voxel and won't find what you are looking for. Instead
* you must scale the direction vector so that it's length represents the maximum distance
* over which you want the ray to be cast.
*
* \param volData The volume to pass the ray though
* \param v3dStart The start position in the volume
* \param v3dDirectionAndLength The direction and length of the ray
* \param callback The callback to call for each voxel
*
* \return A RaycastResults designating whether the ray hit anything or not
*/
template<typename VolumeType, typename Callback>
RaycastResult raycastWithDirection(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, Callback& callback)
{
Vector3DFloat v3dEnd = v3dStart + v3dDirectionAndLength;
return raycastWithEndpoints<VolumeType, Callback>(volData, v3dStart, v3dEnd, callback);
}
}

View File

@ -1,461 +1,461 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Region_H__
#define __PolyVox_Region_H__
#include "Impl/TypeDef.h"
#include "PolyVoxCore/Vector.h"
namespace PolyVox
{
/** Represents a part of a Volume.
*
* Many operations in PolyVox are constrained to only part of a volume. For example, when running the surface extractors
* it is unlikely that you will want to run it on the whole volume at once, as this will give a very large mesh which may
* be too much to render. Instead you will probably want to run a surface extractor a number of times on different parts
* of the volume, there by giving a number of meshes which can be culled and rendered seperately.
*
* The Region class is used to define these parts (regions) of the volume. Essentially it consists of an upper and lower
* bound which specify the range of voxels positions considered to be part of the region. Note that these bounds are
* <em>inclusive</em>.
*
* As well as the expected set of getters and setters, this class also provide utility functions for increasing and decresing
* the size of the Region, shifting the Region in 3D space, testing whether it contains a given position, enlarging it so that
* it does contain a given position, croppng it to another Region, and various other utility functions.
*
* \Note The dimensions of a region can be measured either in voxels or in cells. See the manual for more information
* about these definitions.
*
*/
#ifdef SWIG
class Region
#else
class POLYVOX_API Region
#endif
{
public:
/// A Region with the lower corner set as low as possible and the upper corner set as high as possible.
static const Region MaxRegion;
/// A Region with the lower corner set as high as possible and the upper corner set as low as possible.
static const Region InvertedRegion;
/// Constructor
Region();
/// Constructor
Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner);
/// Constructor
Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ);
/// Equality Operator.
bool operator==(const Region& rhs) const;
/// Inequality Operator.
bool operator!=(const Region& rhs) const;
/// Gets the 'x' position of the centre.
int32_t getCentreX(void) const;
/// Gets the 'y' position of the centre.
int32_t getCentreY(void) const;
/// Gets the 'z' position of the centrer.
int32_t getCentreZ(void) const;
/// Gets the 'x' position of the lower corner.
int32_t getLowerX(void) const;
/// Gets the 'y' position of the lower corner.
int32_t getLowerY(void) const;
/// Gets the 'z' position of the lower corner.
int32_t getLowerZ(void) const;
/// Gets the 'x' position of the upper corner.
int32_t getUpperX(void) const;
/// Gets the 'y' position of the upper corner.
int32_t getUpperY(void) const;
/// Gets the 'z' position of the upper corner.
int32_t getUpperZ(void) const;
/// Gets the centre of the region
Vector3DInt32 getCentre(void) const;
/// Gets the position of the lower corner.
Vector3DInt32 getLowerCorner(void) const;
/// Gets the position of the upper corner.
Vector3DInt32 getUpperCorner(void) const;
/// Gets the width of the region measured in voxels.
int32_t getWidthInVoxels(void) const;
/// Gets the height of the region measured in voxels.
int32_t getHeightInVoxels(void) const;
/// Gets the depth of the region measured in voxels.
int32_t getDepthInVoxels(void) const;
/// Gets the dimensions of the region measured in voxels.
Vector3DInt32 getDimensionsInVoxels(void) const;
/// Gets the width of the region measured in cells.
int32_t getWidthInCells(void) const;
/// Gets the height of the region measured in cells.
int32_t getHeightInCells(void) const;
/// Gets the depth of the region measured in cells.
int32_t getDepthInCells(void) const;
/// Gets the dimensions of the region measured in cells.
Vector3DInt32 getDimensionsInCells(void) const;
/// Sets the 'x' position of the lower corner.
void setLowerX(int32_t iX);
/// Sets the 'y' position of the lower corner.
void setLowerY(int32_t iY);
/// Sets the 'z' position of the lower corner.
void setLowerZ(int32_t iZ);
/// Sets the 'x' position of the upper corner.
void setUpperX(int32_t iX);
/// Sets the 'y' position of the upper corner.
void setUpperY(int32_t iY);
/// Sets the 'z' position of the upper corner.
void setUpperZ(int32_t iZ);
/// Sets the position of the lower corner.
void setLowerCorner(const Vector3DInt32& v3dLowerCorner);
/// Sets the position of the upper corner.
void setUpperCorner(const Vector3DInt32& v3dUpperCorner);
/// Tests whether the given point is contained in this Region.
bool containsPoint(float fX, float fY, float fZ, float boundary = 0.0f) const;
/// Tests whether the given point is contained in this Region.
bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const;
/// Tests whether the given point is contained in this Region.
bool containsPoint(int32_t iX, int32_t iY, int32_t iZ, uint8_t boundary = 0) const;
/// Tests whether the given point is contained in this Region.
bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const;
/// Tests whether the given position is contained in the 'x' range of this Region.
bool containsPointInX(float pos, float boundary = 0.0f) const;
/// Tests whether the given position is contained in the 'x' range of this Region.
bool containsPointInX(int32_t pos, uint8_t boundary = 0) const;
/// Tests whether the given position is contained in the 'y' range of this Region.
bool containsPointInY(float pos, float boundary = 0.0f) const;
/// Tests whether the given position is contained in the 'y' range of this Region.
bool containsPointInY(int32_t pos, uint8_t boundary = 0) const;
/// Tests whether the given position is contained in the 'z' range of this Region.
bool containsPointInZ(float pos, float boundary = 0.0f) const;
/// Tests whether the given position is contained in the 'z' range of this Region.
bool containsPointInZ(int32_t pos, uint8_t boundary = 0) const;
/// Tests whether the given Region is contained in this Region.
bool containsRegion(const Region& reg, uint8_t boundary = 0) const;
/// Enlarges the Region so that it contains the specified position.
void accumulate(int32_t iX, int32_t iY, int32_t iZ);
/// Enlarges the Region so that it contains the specified position.
void accumulate(const Vector3DInt32& v3dPos);
/// Enlarges the Region so that it contains the specified Region.
void accumulate(const Region& reg);
/// Crops the extents of this Region accoring to another Region.
void cropTo(const Region& other);
/// Grows this region by the amount specified.
void grow(int32_t iAmount);
/// Grows this region by the amounts specified.
void grow(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Grows this region by the amounts specified.
void grow(const Vector3DInt32& v3dAmount);
/// Tests whether all components of the upper corner are at least
/// as great as the corresponding components of the lower corner.
bool isValid(void) const;
/// Moves the Region by the amount specified.
void shift(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Moves the Region by the amount specified.
void shift(const Vector3DInt32& v3dAmount);
/// Moves the lower corner of the Region by the amount specified.
void shiftLowerCorner(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Moves the lower corner of the Region by the amount specified.
void shiftLowerCorner(const Vector3DInt32& v3dAmount);
/// Moves the upper corner of the Region by the amount specified.
void shiftUpperCorner(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Moves the upper corner of the Region by the amount specified.
void shiftUpperCorner(const Vector3DInt32& v3dAmount);
/// Shrinks this region by the amount specified.
void shrink(int32_t iAmount);
/// Shrinks this region by the amounts specified.
void shrink(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Shrinks this region by the amounts specified.
void shrink(const Vector3DInt32& v3dAmount);
private:
int32_t m_iLowerX;
int32_t m_iLowerY;
int32_t m_iLowerZ;
int32_t m_iUpperX;
int32_t m_iUpperY;
int32_t m_iUpperZ;
};
// Non-member functions
bool intersects(const Region& a, const Region& b);
// Non-member overloaded operators.
/// Stream insertion operator.
std::ostream& operator<<(std::ostream& os, const Region& region);
// Functions to be inlined to to be in the header rather than the .cpp.
// 'inline' keyword is used for the definition rather than the declaration.
// See also http://www.parashift.com/c++-faq-lite/inline-functions.html
/**
* \return The 'x' position of the centre.
*/
inline int32_t Region::getCentreX(void) const
{
return (m_iLowerX + m_iUpperX) / 2;
}
/**
* \return The 'y' position of the centre.
*/
inline int32_t Region::getCentreY(void) const
{
return (m_iLowerY + m_iUpperY) / 2;
}
/**
* \return The 'z' position of the centre.
*/
inline int32_t Region::getCentreZ(void) const
{
return (m_iLowerZ + m_iUpperZ) / 2;
}
/**
* \return The 'x' position of the lower corner.
*/
inline int32_t Region::getLowerX(void) const
{
return m_iLowerX;
}
/**
* \return The 'y' position of the lower corner.
*/
inline int32_t Region::getLowerY(void) const
{
return m_iLowerY;
}
/**
* \return The 'z' position of the lower corner.
*/
inline int32_t Region::getLowerZ(void) const
{
return m_iLowerZ;
}
/**
* \return The 'x' position of the upper corner.
*/
inline int32_t Region::getUpperX(void) const
{
return m_iUpperX;
}
/**
* \return The 'y' position of the upper corner.
*/
inline int32_t Region::getUpperY(void) const
{
return m_iUpperY;
}
/**
* \return The 'z' position of the upper corner.
*/
inline int32_t Region::getUpperZ(void) const
{
return m_iUpperZ;
}
/**
* \return The position of the lower corner.
*/
inline Vector3DInt32 Region::getCentre(void) const
{
return Vector3DInt32(getCentreX(), getCentreY(), getCentreZ());
}
/**
* \return The position of the lower corner.
*/
inline Vector3DInt32 Region::getLowerCorner(void) const
{
return Vector3DInt32(m_iLowerX, m_iLowerY, m_iLowerZ);
}
/**
* \return The position of the upper corner.
*/
inline Vector3DInt32 Region::getUpperCorner(void) const
{
return Vector3DInt32(m_iUpperX, m_iUpperY, m_iUpperZ);
}
/**
* \return The width of the region measured in voxels.
* \sa getWidthInCells()
*/
inline int32_t Region::getWidthInVoxels(void) const
{
return getWidthInCells() + 1;
}
/**
* \return The height of the region measured in voxels.
* \sa getHeightInCells()
*/
inline int32_t Region::getHeightInVoxels(void) const
{
return getHeightInCells() + 1;
}
/**
* \return The depth of the region measured in voxels.
* \sa getDepthInCells()
*/
inline int32_t Region::getDepthInVoxels(void) const
{
return getDepthInCells() + 1;
}
/**
* \return The dimensions of the region measured in voxels.
* \sa getDimensionsInCells()
*/
inline Vector3DInt32 Region::getDimensionsInVoxels(void) const
{
return getDimensionsInCells() + Vector3DInt32(1, 1, 1);
}
/**
* \return The width of the region measured in cells.
* \sa getWidthInVoxels()
*/
inline int32_t Region::getWidthInCells(void) const
{
return m_iUpperX - m_iLowerX;
}
/**
* \return The height of the region measured in cells.
* \sa getHeightInVoxels()
*/
inline int32_t Region::getHeightInCells(void) const
{
return m_iUpperY - m_iLowerY;
}
/**
* \return The depth of the region measured in cells.
* \sa getDepthInVoxels()
*/
inline int32_t Region::getDepthInCells(void) const
{
return m_iUpperZ - m_iLowerZ;
}
/**
* \return The dimensions of the region measured in cells.
* \sa getDimensionsInVoxels()
*/
inline Vector3DInt32 Region::getDimensionsInCells(void) const
{
return Vector3DInt32(getWidthInCells(), getHeightInCells(), getDepthInCells());
}
/**
* \param iX The new 'x' position of the lower corner.
*/
inline void Region::setLowerX(int32_t iX)
{
m_iLowerX = iX;
}
/**
* \param iY The new 'y' position of the lower corner.
*/
inline void Region::setLowerY(int32_t iY)
{
m_iLowerY = iY;
}
/**
* \param iZ The new 'z' position of the lower corner.
*/
inline void Region::setLowerZ(int32_t iZ)
{
m_iLowerZ = iZ;
}
/**
* \param iX The new 'x' position of the upper corner.
*/
inline void Region::setUpperX(int32_t iX)
{
m_iUpperX = iX;
}
/**
* \param iY The new 'y' position of the upper corner.
*/
inline void Region::setUpperY(int32_t iY)
{
m_iUpperY = iY;
}
/**
* \param iZ The new 'z' position of the upper corner.
*/
inline void Region::setUpperZ(int32_t iZ)
{
m_iUpperZ = iZ;
}
/**
* \param v3dLowerCorner The new position of the lower corner.
*/
inline void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner)
{
m_iLowerX = v3dLowerCorner.getX();
m_iLowerY = v3dLowerCorner.getY();
m_iLowerZ = v3dLowerCorner.getZ();
}
/**
* \param v3dUpperCorner The new position of the upper corner.
*/
inline void Region::setUpperCorner(const Vector3DInt32& v3dUpperCorner)
{
m_iUpperX = v3dUpperCorner.getX();
m_iUpperY = v3dUpperCorner.getY();
m_iUpperZ = v3dUpperCorner.getZ();
}
}
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Region_H__
#define __PolyVox_Region_H__
#include "Impl/TypeDef.h"
#include "PolyVoxCore/Vector.h"
namespace PolyVox
{
/** Represents a part of a Volume.
*
* Many operations in PolyVox are constrained to only part of a volume. For example, when running the surface extractors
* it is unlikely that you will want to run it on the whole volume at once, as this will give a very large mesh which may
* be too much to render. Instead you will probably want to run a surface extractor a number of times on different parts
* of the volume, there by giving a number of meshes which can be culled and rendered seperately.
*
* The Region class is used to define these parts (regions) of the volume. Essentially it consists of an upper and lower
* bound which specify the range of voxels positions considered to be part of the region. Note that these bounds are
* <em>inclusive</em>.
*
* As well as the expected set of getters and setters, this class also provide utility functions for increasing and decresing
* the size of the Region, shifting the Region in 3D space, testing whether it contains a given position, enlarging it so that
* it does contain a given position, croppng it to another Region, and various other utility functions.
*
* \Note The dimensions of a region can be measured either in voxels or in cells. See the manual for more information
* about these definitions.
*
*/
#ifdef SWIG
class Region
#else
class POLYVOX_API Region
#endif
{
public:
/// A Region with the lower corner set as low as possible and the upper corner set as high as possible.
static const Region MaxRegion;
/// A Region with the lower corner set as high as possible and the upper corner set as low as possible.
static const Region InvertedRegion;
/// Constructor
Region();
/// Constructor
Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner);
/// Constructor
Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ);
/// Equality Operator.
bool operator==(const Region& rhs) const;
/// Inequality Operator.
bool operator!=(const Region& rhs) const;
/// Gets the 'x' position of the centre.
int32_t getCentreX(void) const;
/// Gets the 'y' position of the centre.
int32_t getCentreY(void) const;
/// Gets the 'z' position of the centrer.
int32_t getCentreZ(void) const;
/// Gets the 'x' position of the lower corner.
int32_t getLowerX(void) const;
/// Gets the 'y' position of the lower corner.
int32_t getLowerY(void) const;
/// Gets the 'z' position of the lower corner.
int32_t getLowerZ(void) const;
/// Gets the 'x' position of the upper corner.
int32_t getUpperX(void) const;
/// Gets the 'y' position of the upper corner.
int32_t getUpperY(void) const;
/// Gets the 'z' position of the upper corner.
int32_t getUpperZ(void) const;
/// Gets the centre of the region
Vector3DInt32 getCentre(void) const;
/// Gets the position of the lower corner.
Vector3DInt32 getLowerCorner(void) const;
/// Gets the position of the upper corner.
Vector3DInt32 getUpperCorner(void) const;
/// Gets the width of the region measured in voxels.
int32_t getWidthInVoxels(void) const;
/// Gets the height of the region measured in voxels.
int32_t getHeightInVoxels(void) const;
/// Gets the depth of the region measured in voxels.
int32_t getDepthInVoxels(void) const;
/// Gets the dimensions of the region measured in voxels.
Vector3DInt32 getDimensionsInVoxels(void) const;
/// Gets the width of the region measured in cells.
int32_t getWidthInCells(void) const;
/// Gets the height of the region measured in cells.
int32_t getHeightInCells(void) const;
/// Gets the depth of the region measured in cells.
int32_t getDepthInCells(void) const;
/// Gets the dimensions of the region measured in cells.
Vector3DInt32 getDimensionsInCells(void) const;
/// Sets the 'x' position of the lower corner.
void setLowerX(int32_t iX);
/// Sets the 'y' position of the lower corner.
void setLowerY(int32_t iY);
/// Sets the 'z' position of the lower corner.
void setLowerZ(int32_t iZ);
/// Sets the 'x' position of the upper corner.
void setUpperX(int32_t iX);
/// Sets the 'y' position of the upper corner.
void setUpperY(int32_t iY);
/// Sets the 'z' position of the upper corner.
void setUpperZ(int32_t iZ);
/// Sets the position of the lower corner.
void setLowerCorner(const Vector3DInt32& v3dLowerCorner);
/// Sets the position of the upper corner.
void setUpperCorner(const Vector3DInt32& v3dUpperCorner);
/// Tests whether the given point is contained in this Region.
bool containsPoint(float fX, float fY, float fZ, float boundary = 0.0f) const;
/// Tests whether the given point is contained in this Region.
bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const;
/// Tests whether the given point is contained in this Region.
bool containsPoint(int32_t iX, int32_t iY, int32_t iZ, uint8_t boundary = 0) const;
/// Tests whether the given point is contained in this Region.
bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const;
/// Tests whether the given position is contained in the 'x' range of this Region.
bool containsPointInX(float pos, float boundary = 0.0f) const;
/// Tests whether the given position is contained in the 'x' range of this Region.
bool containsPointInX(int32_t pos, uint8_t boundary = 0) const;
/// Tests whether the given position is contained in the 'y' range of this Region.
bool containsPointInY(float pos, float boundary = 0.0f) const;
/// Tests whether the given position is contained in the 'y' range of this Region.
bool containsPointInY(int32_t pos, uint8_t boundary = 0) const;
/// Tests whether the given position is contained in the 'z' range of this Region.
bool containsPointInZ(float pos, float boundary = 0.0f) const;
/// Tests whether the given position is contained in the 'z' range of this Region.
bool containsPointInZ(int32_t pos, uint8_t boundary = 0) const;
/// Tests whether the given Region is contained in this Region.
bool containsRegion(const Region& reg, uint8_t boundary = 0) const;
/// Enlarges the Region so that it contains the specified position.
void accumulate(int32_t iX, int32_t iY, int32_t iZ);
/// Enlarges the Region so that it contains the specified position.
void accumulate(const Vector3DInt32& v3dPos);
/// Enlarges the Region so that it contains the specified Region.
void accumulate(const Region& reg);
/// Crops the extents of this Region accoring to another Region.
void cropTo(const Region& other);
/// Grows this region by the amount specified.
void grow(int32_t iAmount);
/// Grows this region by the amounts specified.
void grow(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Grows this region by the amounts specified.
void grow(const Vector3DInt32& v3dAmount);
/// Tests whether all components of the upper corner are at least
/// as great as the corresponding components of the lower corner.
bool isValid(void) const;
/// Moves the Region by the amount specified.
void shift(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Moves the Region by the amount specified.
void shift(const Vector3DInt32& v3dAmount);
/// Moves the lower corner of the Region by the amount specified.
void shiftLowerCorner(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Moves the lower corner of the Region by the amount specified.
void shiftLowerCorner(const Vector3DInt32& v3dAmount);
/// Moves the upper corner of the Region by the amount specified.
void shiftUpperCorner(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Moves the upper corner of the Region by the amount specified.
void shiftUpperCorner(const Vector3DInt32& v3dAmount);
/// Shrinks this region by the amount specified.
void shrink(int32_t iAmount);
/// Shrinks this region by the amounts specified.
void shrink(int32_t iAmountX, int32_t iAmountY, int32_t iAmountZ);
/// Shrinks this region by the amounts specified.
void shrink(const Vector3DInt32& v3dAmount);
private:
int32_t m_iLowerX;
int32_t m_iLowerY;
int32_t m_iLowerZ;
int32_t m_iUpperX;
int32_t m_iUpperY;
int32_t m_iUpperZ;
};
// Non-member functions
bool intersects(const Region& a, const Region& b);
// Non-member overloaded operators.
/// Stream insertion operator.
std::ostream& operator<<(std::ostream& os, const Region& region);
// Functions to be inlined to to be in the header rather than the .cpp.
// 'inline' keyword is used for the definition rather than the declaration.
// See also http://www.parashift.com/c++-faq-lite/inline-functions.html
/**
* \return The 'x' position of the centre.
*/
inline int32_t Region::getCentreX(void) const
{
return (m_iLowerX + m_iUpperX) / 2;
}
/**
* \return The 'y' position of the centre.
*/
inline int32_t Region::getCentreY(void) const
{
return (m_iLowerY + m_iUpperY) / 2;
}
/**
* \return The 'z' position of the centre.
*/
inline int32_t Region::getCentreZ(void) const
{
return (m_iLowerZ + m_iUpperZ) / 2;
}
/**
* \return The 'x' position of the lower corner.
*/
inline int32_t Region::getLowerX(void) const
{
return m_iLowerX;
}
/**
* \return The 'y' position of the lower corner.
*/
inline int32_t Region::getLowerY(void) const
{
return m_iLowerY;
}
/**
* \return The 'z' position of the lower corner.
*/
inline int32_t Region::getLowerZ(void) const
{
return m_iLowerZ;
}
/**
* \return The 'x' position of the upper corner.
*/
inline int32_t Region::getUpperX(void) const
{
return m_iUpperX;
}
/**
* \return The 'y' position of the upper corner.
*/
inline int32_t Region::getUpperY(void) const
{
return m_iUpperY;
}
/**
* \return The 'z' position of the upper corner.
*/
inline int32_t Region::getUpperZ(void) const
{
return m_iUpperZ;
}
/**
* \return The position of the lower corner.
*/
inline Vector3DInt32 Region::getCentre(void) const
{
return Vector3DInt32(getCentreX(), getCentreY(), getCentreZ());
}
/**
* \return The position of the lower corner.
*/
inline Vector3DInt32 Region::getLowerCorner(void) const
{
return Vector3DInt32(m_iLowerX, m_iLowerY, m_iLowerZ);
}
/**
* \return The position of the upper corner.
*/
inline Vector3DInt32 Region::getUpperCorner(void) const
{
return Vector3DInt32(m_iUpperX, m_iUpperY, m_iUpperZ);
}
/**
* \return The width of the region measured in voxels.
* \sa getWidthInCells()
*/
inline int32_t Region::getWidthInVoxels(void) const
{
return getWidthInCells() + 1;
}
/**
* \return The height of the region measured in voxels.
* \sa getHeightInCells()
*/
inline int32_t Region::getHeightInVoxels(void) const
{
return getHeightInCells() + 1;
}
/**
* \return The depth of the region measured in voxels.
* \sa getDepthInCells()
*/
inline int32_t Region::getDepthInVoxels(void) const
{
return getDepthInCells() + 1;
}
/**
* \return The dimensions of the region measured in voxels.
* \sa getDimensionsInCells()
*/
inline Vector3DInt32 Region::getDimensionsInVoxels(void) const
{
return getDimensionsInCells() + Vector3DInt32(1, 1, 1);
}
/**
* \return The width of the region measured in cells.
* \sa getWidthInVoxels()
*/
inline int32_t Region::getWidthInCells(void) const
{
return m_iUpperX - m_iLowerX;
}
/**
* \return The height of the region measured in cells.
* \sa getHeightInVoxels()
*/
inline int32_t Region::getHeightInCells(void) const
{
return m_iUpperY - m_iLowerY;
}
/**
* \return The depth of the region measured in cells.
* \sa getDepthInVoxels()
*/
inline int32_t Region::getDepthInCells(void) const
{
return m_iUpperZ - m_iLowerZ;
}
/**
* \return The dimensions of the region measured in cells.
* \sa getDimensionsInVoxels()
*/
inline Vector3DInt32 Region::getDimensionsInCells(void) const
{
return Vector3DInt32(getWidthInCells(), getHeightInCells(), getDepthInCells());
}
/**
* \param iX The new 'x' position of the lower corner.
*/
inline void Region::setLowerX(int32_t iX)
{
m_iLowerX = iX;
}
/**
* \param iY The new 'y' position of the lower corner.
*/
inline void Region::setLowerY(int32_t iY)
{
m_iLowerY = iY;
}
/**
* \param iZ The new 'z' position of the lower corner.
*/
inline void Region::setLowerZ(int32_t iZ)
{
m_iLowerZ = iZ;
}
/**
* \param iX The new 'x' position of the upper corner.
*/
inline void Region::setUpperX(int32_t iX)
{
m_iUpperX = iX;
}
/**
* \param iY The new 'y' position of the upper corner.
*/
inline void Region::setUpperY(int32_t iY)
{
m_iUpperY = iY;
}
/**
* \param iZ The new 'z' position of the upper corner.
*/
inline void Region::setUpperZ(int32_t iZ)
{
m_iUpperZ = iZ;
}
/**
* \param v3dLowerCorner The new position of the lower corner.
*/
inline void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner)
{
m_iLowerX = v3dLowerCorner.getX();
m_iLowerY = v3dLowerCorner.getY();
m_iLowerZ = v3dLowerCorner.getZ();
}
/**
* \param v3dUpperCorner The new position of the upper corner.
*/
inline void Region::setUpperCorner(const Vector3DInt32& v3dUpperCorner)
{
m_iUpperX = v3dUpperCorner.getX();
m_iUpperY = v3dUpperCorner.getY();
m_iUpperZ = v3dUpperCorner.getZ();
}
}
#endif

View File

@ -1,9 +1,9 @@
#ifndef __PolyVox_SimpleVolume_H__
#define __PolyVox_SimpleVolume_H__
#pragma message("WARNING - The SimpleVolume class has been replaced by PagedVolume. Please use that instead.")
#include "PagedVolume.h"
#include "PolyVoxForwardDeclarations.h"
#ifndef __PolyVox_SimpleVolume_H__
#define __PolyVox_SimpleVolume_H__
#pragma message("WARNING - The SimpleVolume class has been replaced by PagedVolume. Please use that instead.")
#include "PagedVolume.h"
#include "PolyVoxForwardDeclarations.h"
#endif //__PolyVox_SimpleVolume_H__

View File

@ -1,248 +1,248 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Vector_H__
#define __PolyVox_Vector_H__
#include "Impl/ErrorHandling.h"
#include "Impl/TypeDef.h"
#include "PolyVoxForwardDeclarations.h"
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
namespace PolyVox
{
/**
* Represents a vector in space.
*
* This is a generl purpose vector class designed to represent both positions and directions. It is templatised
* on both size and data type but note that some of the operations do not make sense with integer types. For
* example it does not make conceptual sense to try and normalise an integer Vector.
*
* Every Vector must have at at least two elements, and the first four elements of any vector are known as the
* X, Y, Z and W elements. Note that W is last even though it comes before X in the alphabet. These elements can
* be accessed through getX(), setX(), getY(), setY(), getZ(), setZ(), getW() and setW(), while other elements
* can be accessed through getElemen() and setElement().
*
* This class includes a number of common mathematical operations (addition, subtraction, etc) as well as vector
* specific operations such as the dot and cross products. Note that this class is also templatised on an
* OperationType which is used for many internal calculations and some results. For example, the square of a
* vector's length will always be an integer if all the elements are integers, but the value might be outside
* that which can be represented by the StorageType. You don't need to worry about this as long as you are using
* the built in typedefs for common configurations.
*
* Typedefs are provided for 2, 3 and 4 dimensional vector with int8_t, uint8_t, int16_t, uint6_t, int32_t,
* uint32_t, float and double types. These typedefs are used as follows:
*
* \code
* Vector2DInt32 test(1,2); //Declares a 2 dimensional Vector of type int32_t.
* \endcode
*/
template <uint32_t Size, typename StorageType, typename OperationType>
class Vector
{
public:
/// Constructor
Vector(void);
/// Constructor.
Vector(StorageType tFillValue);
/// Constructor.
Vector(StorageType x, StorageType y);
/// Constructor.
Vector(StorageType x, StorageType y, StorageType z);
/// Constructor.
Vector(StorageType x, StorageType y, StorageType z, StorageType w);
/// Copy Constructor.
Vector(const Vector<Size,StorageType,OperationType>& vector);
/// Copy Constructor which performs casting.
template <typename CastType> explicit Vector(const Vector<Size,CastType>& vector);
/// Destructor.
~Vector(void);
/// Assignment Operator.
Vector<Size,StorageType,OperationType>& operator=(const Vector<Size,StorageType,OperationType>& rhs);
/// Equality Operator.
bool operator==(const Vector<Size,StorageType,OperationType>& rhs) const;
/// Inequality Operator.
bool operator!=(const Vector<Size,StorageType,OperationType>& rhs) const;
/// Comparison Operator.
POLYVOX_DEPRECATED bool operator<(const Vector<Size,StorageType,OperationType>& rhs) const;
/// Addition and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator+=(const Vector<Size,StorageType,OperationType> &rhs);
/// Subtraction and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator-=(const Vector<Size,StorageType,OperationType> &rhs);
/// Multiplication and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator*=(const Vector<Size,StorageType,OperationType> &rhs);
/// Division and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator/=(const Vector<Size,StorageType,OperationType> &rhs);
/// Multiplication and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator*=(const StorageType& rhs);
/// Division and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator/=(const StorageType& rhs);
/// Element Access.
StorageType getElement(uint32_t index) const;
/// Get the x component of the vector.
StorageType getX(void) const;
/// Get the y component of the vector.
StorageType getY(void) const;
/// Get the z component of the vector.
StorageType getZ(void) const;
/// Get the w component of the vector.
StorageType getW(void) const;
/// Element Access.
void setElement(uint32_t index, StorageType tValue);
/// Element Access.
void setElements(StorageType x, StorageType y);
/// Element Access.
void setElements(StorageType x, StorageType y, StorageType z);
/// Element Access.
void setElements(StorageType x, StorageType y, StorageType z, StorageType w);
/// Set the x component of the vector.
void setX(StorageType tX);
/// Set the y component of the vector.
void setY(StorageType tY);
/// Set the z component of the vector.
void setZ(StorageType tZ);
/// Set the w component of the vector.
void setW(StorageType tW);
/// Get the length of the vector.
float length(void) const;
/// Get the squared length of the vector.
OperationType lengthSquared(void) const;
/// Find the angle between this vector and that which is passed as a parameter.
float angleTo(const Vector<Size,StorageType,OperationType>& vector) const;
/// Find the cross product between this vector and the vector passed as a parameter.
Vector<Size,StorageType,OperationType> cross(const Vector<Size,StorageType,OperationType>& vector) const;
/// Find the dot product between this vector and the vector passed as a parameter.
OperationType dot(const Vector<Size,StorageType,OperationType>& rhs) const;
/// Normalise the vector.
void normalise(void);
private:
// Values for the vector
StorageType m_tElements[Size];
};
// Non-member overloaded operators.
/// Addition operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator+(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
/// Subtraction operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator-(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
/// Multiplication operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator*(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
/// Division operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator/(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
/// Multiplication operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator*(const Vector<Size,StorageType,OperationType>& lhs, const StorageType& rhs);
/// Division operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator/(const Vector<Size,StorageType,OperationType>& lhs, const StorageType& rhs);
/// Stream insertion operator.
template <uint32_t Size, typename StorageType,typename OperationType>
std::ostream& operator<<(std::ostream& os, const Vector<Size,StorageType,OperationType>& vector);
//Some handy typedefs
/// A 2D Vector of floats.
typedef Vector<2,float,float> Vector2DFloat;
/// A 2D Vector of doubles.
typedef Vector<2,double,double> Vector2DDouble;
/// A 2D Vector of signed 8-bit values.
typedef Vector<2,int8_t,int32_t> Vector2DInt8;
/// A 2D Vector of unsigned 8-bit values.
typedef Vector<2,uint8_t,int32_t> Vector2DUint8;
/// A 2D Vector of signed 16-bit values.
typedef Vector<2,int16_t,int32_t> Vector2DInt16;
/// A 2D Vector of unsigned 16-bit values.
typedef Vector<2,uint16_t,int32_t> Vector2DUint16;
/// A 2D Vector of signed 32-bit values.
typedef Vector<2,int32_t,int32_t> Vector2DInt32;
/// A 2D Vector of unsigned 32-bit values.
typedef Vector<2,uint32_t,int32_t> Vector2DUint32;
/// A 3D Vector of floats.
typedef Vector<3,float,float> Vector3DFloat;
/// A 3D Vector of doubles.
typedef Vector<3,double,double> Vector3DDouble;
/// A 3D Vector of signed 8-bit values.
typedef Vector<3,int8_t,int32_t> Vector3DInt8;
/// A 3D Vector of unsigned 8-bit values.
typedef Vector<3,uint8_t,int32_t> Vector3DUint8;
/// A 3D Vector of signed 16-bit values.
typedef Vector<3,int16_t,int32_t> Vector3DInt16;
/// A 3D Vector of unsigned 16-bit values.
typedef Vector<3,uint16_t,int32_t> Vector3DUint16;
/// A 3D Vector of signed 32-bit values.
typedef Vector<3,int32_t,int32_t> Vector3DInt32;
/// A 3D Vector of unsigned 32-bit values.
typedef Vector<3,uint32_t,int32_t> Vector3DUint32;
/// A 4D Vector of floats.
typedef Vector<4,float,float> Vector4DFloat;
/// A 4D Vector of doubles.
typedef Vector<4,double,double> Vector4DDouble;
/// A 4D Vector of signed 8-bit values.
typedef Vector<4,int8_t,int32_t> Vector4DInt8;
/// A 4D Vector of unsigned 8-bit values.
typedef Vector<4,uint8_t,int32_t> Vector4DUint8;
/// A 4D Vector of signed 16-bit values.
typedef Vector<4,int16_t,int32_t> Vector4DInt16;
/// A 4D Vector of unsigned 16-bit values.
typedef Vector<4,uint16_t,int32_t> Vector4DUint16;
/// A 4D Vector of signed 32-bit values.
typedef Vector<4,int32_t,int32_t> Vector4DInt32;
/// A 4D Vector of unsigned 32-bit values.
typedef Vector<4,uint32_t,int32_t> Vector4DUint32;
}//namespace PolyVox
namespace std
{
template <>
struct hash<PolyVox::Vector3DInt32>
{
std::size_t operator()(const PolyVox::Vector3DInt32& vec) const
{
return ((vec.getX() & 0xFF)) | ((vec.getY() & 0xFF) << 8) | ((vec.getZ() & 0xFF) << 16);
}
};
}
#include "PolyVoxCore/Vector.inl"
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Vector_H__
#define __PolyVox_Vector_H__
#include "Impl/ErrorHandling.h"
#include "Impl/TypeDef.h"
#include "PolyVoxForwardDeclarations.h"
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
namespace PolyVox
{
/**
* Represents a vector in space.
*
* This is a generl purpose vector class designed to represent both positions and directions. It is templatised
* on both size and data type but note that some of the operations do not make sense with integer types. For
* example it does not make conceptual sense to try and normalise an integer Vector.
*
* Every Vector must have at at least two elements, and the first four elements of any vector are known as the
* X, Y, Z and W elements. Note that W is last even though it comes before X in the alphabet. These elements can
* be accessed through getX(), setX(), getY(), setY(), getZ(), setZ(), getW() and setW(), while other elements
* can be accessed through getElemen() and setElement().
*
* This class includes a number of common mathematical operations (addition, subtraction, etc) as well as vector
* specific operations such as the dot and cross products. Note that this class is also templatised on an
* OperationType which is used for many internal calculations and some results. For example, the square of a
* vector's length will always be an integer if all the elements are integers, but the value might be outside
* that which can be represented by the StorageType. You don't need to worry about this as long as you are using
* the built in typedefs for common configurations.
*
* Typedefs are provided for 2, 3 and 4 dimensional vector with int8_t, uint8_t, int16_t, uint6_t, int32_t,
* uint32_t, float and double types. These typedefs are used as follows:
*
* \code
* Vector2DInt32 test(1,2); //Declares a 2 dimensional Vector of type int32_t.
* \endcode
*/
template <uint32_t Size, typename StorageType, typename OperationType>
class Vector
{
public:
/// Constructor
Vector(void);
/// Constructor.
Vector(StorageType tFillValue);
/// Constructor.
Vector(StorageType x, StorageType y);
/// Constructor.
Vector(StorageType x, StorageType y, StorageType z);
/// Constructor.
Vector(StorageType x, StorageType y, StorageType z, StorageType w);
/// Copy Constructor.
Vector(const Vector<Size,StorageType,OperationType>& vector);
/// Copy Constructor which performs casting.
template <typename CastType> explicit Vector(const Vector<Size,CastType>& vector);
/// Destructor.
~Vector(void);
/// Assignment Operator.
Vector<Size,StorageType,OperationType>& operator=(const Vector<Size,StorageType,OperationType>& rhs);
/// Equality Operator.
bool operator==(const Vector<Size,StorageType,OperationType>& rhs) const;
/// Inequality Operator.
bool operator!=(const Vector<Size,StorageType,OperationType>& rhs) const;
/// Comparison Operator.
POLYVOX_DEPRECATED bool operator<(const Vector<Size,StorageType,OperationType>& rhs) const;
/// Addition and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator+=(const Vector<Size,StorageType,OperationType> &rhs);
/// Subtraction and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator-=(const Vector<Size,StorageType,OperationType> &rhs);
/// Multiplication and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator*=(const Vector<Size,StorageType,OperationType> &rhs);
/// Division and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator/=(const Vector<Size,StorageType,OperationType> &rhs);
/// Multiplication and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator*=(const StorageType& rhs);
/// Division and Assignment Operator.
Vector<Size,StorageType,OperationType>& operator/=(const StorageType& rhs);
/// Element Access.
StorageType getElement(uint32_t index) const;
/// Get the x component of the vector.
StorageType getX(void) const;
/// Get the y component of the vector.
StorageType getY(void) const;
/// Get the z component of the vector.
StorageType getZ(void) const;
/// Get the w component of the vector.
StorageType getW(void) const;
/// Element Access.
void setElement(uint32_t index, StorageType tValue);
/// Element Access.
void setElements(StorageType x, StorageType y);
/// Element Access.
void setElements(StorageType x, StorageType y, StorageType z);
/// Element Access.
void setElements(StorageType x, StorageType y, StorageType z, StorageType w);
/// Set the x component of the vector.
void setX(StorageType tX);
/// Set the y component of the vector.
void setY(StorageType tY);
/// Set the z component of the vector.
void setZ(StorageType tZ);
/// Set the w component of the vector.
void setW(StorageType tW);
/// Get the length of the vector.
float length(void) const;
/// Get the squared length of the vector.
OperationType lengthSquared(void) const;
/// Find the angle between this vector and that which is passed as a parameter.
float angleTo(const Vector<Size,StorageType,OperationType>& vector) const;
/// Find the cross product between this vector and the vector passed as a parameter.
Vector<Size,StorageType,OperationType> cross(const Vector<Size,StorageType,OperationType>& vector) const;
/// Find the dot product between this vector and the vector passed as a parameter.
OperationType dot(const Vector<Size,StorageType,OperationType>& rhs) const;
/// Normalise the vector.
void normalise(void);
private:
// Values for the vector
StorageType m_tElements[Size];
};
// Non-member overloaded operators.
/// Addition operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator+(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
/// Subtraction operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator-(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
/// Multiplication operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator*(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
/// Division operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator/(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
/// Multiplication operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator*(const Vector<Size,StorageType,OperationType>& lhs, const StorageType& rhs);
/// Division operator.
template <uint32_t Size,typename StorageType,typename OperationType>
Vector<Size,StorageType,OperationType> operator/(const Vector<Size,StorageType,OperationType>& lhs, const StorageType& rhs);
/// Stream insertion operator.
template <uint32_t Size, typename StorageType,typename OperationType>
std::ostream& operator<<(std::ostream& os, const Vector<Size,StorageType,OperationType>& vector);
//Some handy typedefs
/// A 2D Vector of floats.
typedef Vector<2,float,float> Vector2DFloat;
/// A 2D Vector of doubles.
typedef Vector<2,double,double> Vector2DDouble;
/// A 2D Vector of signed 8-bit values.
typedef Vector<2,int8_t,int32_t> Vector2DInt8;
/// A 2D Vector of unsigned 8-bit values.
typedef Vector<2,uint8_t,int32_t> Vector2DUint8;
/// A 2D Vector of signed 16-bit values.
typedef Vector<2,int16_t,int32_t> Vector2DInt16;
/// A 2D Vector of unsigned 16-bit values.
typedef Vector<2,uint16_t,int32_t> Vector2DUint16;
/// A 2D Vector of signed 32-bit values.
typedef Vector<2,int32_t,int32_t> Vector2DInt32;
/// A 2D Vector of unsigned 32-bit values.
typedef Vector<2,uint32_t,int32_t> Vector2DUint32;
/// A 3D Vector of floats.
typedef Vector<3,float,float> Vector3DFloat;
/// A 3D Vector of doubles.
typedef Vector<3,double,double> Vector3DDouble;
/// A 3D Vector of signed 8-bit values.
typedef Vector<3,int8_t,int32_t> Vector3DInt8;
/// A 3D Vector of unsigned 8-bit values.
typedef Vector<3,uint8_t,int32_t> Vector3DUint8;
/// A 3D Vector of signed 16-bit values.
typedef Vector<3,int16_t,int32_t> Vector3DInt16;
/// A 3D Vector of unsigned 16-bit values.
typedef Vector<3,uint16_t,int32_t> Vector3DUint16;
/// A 3D Vector of signed 32-bit values.
typedef Vector<3,int32_t,int32_t> Vector3DInt32;
/// A 3D Vector of unsigned 32-bit values.
typedef Vector<3,uint32_t,int32_t> Vector3DUint32;
/// A 4D Vector of floats.
typedef Vector<4,float,float> Vector4DFloat;
/// A 4D Vector of doubles.
typedef Vector<4,double,double> Vector4DDouble;
/// A 4D Vector of signed 8-bit values.
typedef Vector<4,int8_t,int32_t> Vector4DInt8;
/// A 4D Vector of unsigned 8-bit values.
typedef Vector<4,uint8_t,int32_t> Vector4DUint8;
/// A 4D Vector of signed 16-bit values.
typedef Vector<4,int16_t,int32_t> Vector4DInt16;
/// A 4D Vector of unsigned 16-bit values.
typedef Vector<4,uint16_t,int32_t> Vector4DUint16;
/// A 4D Vector of signed 32-bit values.
typedef Vector<4,int32_t,int32_t> Vector4DInt32;
/// A 4D Vector of unsigned 32-bit values.
typedef Vector<4,uint32_t,int32_t> Vector4DUint32;
}//namespace PolyVox
namespace std
{
template <>
struct hash<PolyVox::Vector3DInt32>
{
std::size_t operator()(const PolyVox::Vector3DInt32& vec) const
{
return ((vec.getX() & 0xFF)) | ((vec.getY() & 0xFF) << 8) | ((vec.getZ() & 0xFF) << 16);
}
};
}
#include "PolyVoxCore/Vector.inl"
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,57 +1,57 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_VolumeResampler_H__
#define __PolyVox_VolumeResampler_H__
#include "PolyVoxCore/Region.h"
namespace PolyVox
{
template< typename SrcVolumeType, typename DstVolumeType>
class VolumeResampler
{
public:
VolumeResampler(SrcVolumeType* pVolSrc, const Region& regSrc, DstVolumeType* pVolDst, const Region& regDst);
void execute();
private:
void resampleSameSize();
void resampleArbitrary();
//Source data
SrcVolumeType* m_pVolSrc;
Region m_regSrc;
//Destination data
DstVolumeType* m_pVolDst;
Region m_regDst;
};
}//namespace PolyVox
#include "PolyVoxCore/VolumeResampler.inl"
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_VolumeResampler_H__
#define __PolyVox_VolumeResampler_H__
#include "PolyVoxCore/Region.h"
namespace PolyVox
{
template< typename SrcVolumeType, typename DstVolumeType>
class VolumeResampler
{
public:
VolumeResampler(SrcVolumeType* pVolSrc, const Region& regSrc, DstVolumeType* pVolDst, const Region& regDst);
void execute();
private:
void resampleSameSize();
void resampleArbitrary();
//Source data
SrcVolumeType* m_pVolSrc;
Region m_regSrc;
//Destination data
DstVolumeType* m_pVolDst;
Region m_regDst;
};
}//namespace PolyVox
#include "PolyVoxCore/VolumeResampler.inl"
#endif

View File

@ -1,138 +1,138 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Interpolation.h"
#include <cmath>
namespace PolyVox
{
/**
* \param pVolSrc
* \param regSrc
* \param[out] pVolDst
* \param regDst
*/
template< typename SrcVolumeType, typename DstVolumeType>
VolumeResampler<SrcVolumeType, DstVolumeType>::VolumeResampler(SrcVolumeType* pVolSrc, const Region &regSrc, DstVolumeType* pVolDst, const Region& regDst)
:m_pVolSrc(pVolSrc)
,m_regSrc(regSrc)
,m_pVolDst(pVolDst)
,m_regDst(regDst)
{
}
template< typename SrcVolumeType, typename DstVolumeType>
void VolumeResampler<SrcVolumeType, DstVolumeType>::execute()
{
int32_t uSrcWidth = m_regSrc.getUpperX() - m_regSrc.getLowerX() + 1;
int32_t uSrcHeight = m_regSrc.getUpperY() - m_regSrc.getLowerY() + 1;
int32_t uSrcDepth = m_regSrc.getUpperZ() - m_regSrc.getLowerZ() + 1;
int32_t uDstWidth = m_regDst.getUpperX() - m_regDst.getLowerX() + 1;
int32_t uDstHeight = m_regDst.getUpperY() - m_regDst.getLowerY() + 1;
int32_t uDstDepth = m_regDst.getUpperZ() - m_regDst.getLowerZ() + 1;
if((uSrcWidth == uDstWidth) && (uSrcHeight == uDstHeight) && (uSrcDepth == uDstDepth))
{
resampleSameSize();
}
else
{
resampleArbitrary();
}
}
template< typename SrcVolumeType, typename DstVolumeType>
void VolumeResampler<SrcVolumeType, DstVolumeType>::resampleSameSize()
{
for(int32_t sz = m_regSrc.getLowerZ(), dz = m_regDst.getLowerZ(); dz <= m_regDst.getUpperZ(); sz++, dz++)
{
for(int32_t sy = m_regSrc.getLowerY(), dy = m_regDst.getLowerY(); dy <= m_regDst.getUpperY(); sy++, dy++)
{
for(int32_t sx = m_regSrc.getLowerX(), dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); sx++,dx++)
{
const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxel(sx,sy,sz, WrapModes::AssumeValid); // FIXME use templatised version of getVoxel(), but watch out for Linux compile issues.
const typename DstVolumeType::VoxelType& tDstVoxel = static_cast<typename DstVolumeType::VoxelType>(tSrcVoxel);
m_pVolDst->setVoxelAt(dx,dy,dz,tDstVoxel);
}
}
}
}
template< typename SrcVolumeType, typename DstVolumeType>
void VolumeResampler<SrcVolumeType, DstVolumeType>::resampleArbitrary()
{
float srcWidth = m_regSrc.getWidthInCells();
float srcHeight = m_regSrc.getHeightInCells();
float srcDepth = m_regSrc.getDepthInCells();
float dstWidth = m_regDst.getWidthInCells();
float dstHeight = m_regDst.getHeightInCells();
float dstDepth = m_regDst.getDepthInCells();
float fScaleX = srcWidth / dstWidth;
float fScaleY = srcHeight / dstHeight;
float fScaleZ = srcDepth / dstDepth;
typename SrcVolumeType::Sampler sampler(m_pVolSrc);
for(int32_t dz = m_regDst.getLowerZ(); dz <= m_regDst.getUpperZ(); dz++)
{
for(int32_t dy = m_regDst.getLowerY(); dy <= m_regDst.getUpperY(); dy++)
{
for(int32_t dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); dx++)
{
float sx = (dx - m_regDst.getLowerX()) * fScaleX;
float sy = (dy - m_regDst.getLowerY()) * fScaleY;
float sz = (dz - m_regDst.getLowerZ()) * fScaleZ;
sx += m_regSrc.getLowerX();
sy += m_regSrc.getLowerY();
sz += m_regSrc.getLowerZ();
sampler.setPosition(sx,sy,sz);
const typename SrcVolumeType::VoxelType& voxel000 = sampler.peekVoxel0px0py0pz();
const typename SrcVolumeType::VoxelType& voxel001 = sampler.peekVoxel0px0py1pz();
const typename SrcVolumeType::VoxelType& voxel010 = sampler.peekVoxel0px1py0pz();
const typename SrcVolumeType::VoxelType& voxel011 = sampler.peekVoxel0px1py1pz();
const typename SrcVolumeType::VoxelType& voxel100 = sampler.peekVoxel1px0py0pz();
const typename SrcVolumeType::VoxelType& voxel101 = sampler.peekVoxel1px0py1pz();
const typename SrcVolumeType::VoxelType& voxel110 = sampler.peekVoxel1px1py0pz();
const typename SrcVolumeType::VoxelType& voxel111 = sampler.peekVoxel1px1py1pz();
//FIXME - should accept all float parameters, but GCC complains?
double dummy;
sx = modf(sx, &dummy);
sy = modf(sy, &dummy);
sz = modf(sz, &dummy);
typename SrcVolumeType::VoxelType tInterpolatedValue = trilerp<float>(voxel000,voxel100,voxel010,voxel110,voxel001,voxel101,voxel011,voxel111,sx,sy,sz);
typename DstVolumeType::VoxelType result = static_cast<typename DstVolumeType::VoxelType>(tInterpolatedValue);
m_pVolDst->setVoxelAt(dx,dy,dz,result);
}
}
}
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Interpolation.h"
#include <cmath>
namespace PolyVox
{
/**
* \param pVolSrc
* \param regSrc
* \param[out] pVolDst
* \param regDst
*/
template< typename SrcVolumeType, typename DstVolumeType>
VolumeResampler<SrcVolumeType, DstVolumeType>::VolumeResampler(SrcVolumeType* pVolSrc, const Region &regSrc, DstVolumeType* pVolDst, const Region& regDst)
:m_pVolSrc(pVolSrc)
,m_regSrc(regSrc)
,m_pVolDst(pVolDst)
,m_regDst(regDst)
{
}
template< typename SrcVolumeType, typename DstVolumeType>
void VolumeResampler<SrcVolumeType, DstVolumeType>::execute()
{
int32_t uSrcWidth = m_regSrc.getUpperX() - m_regSrc.getLowerX() + 1;
int32_t uSrcHeight = m_regSrc.getUpperY() - m_regSrc.getLowerY() + 1;
int32_t uSrcDepth = m_regSrc.getUpperZ() - m_regSrc.getLowerZ() + 1;
int32_t uDstWidth = m_regDst.getUpperX() - m_regDst.getLowerX() + 1;
int32_t uDstHeight = m_regDst.getUpperY() - m_regDst.getLowerY() + 1;
int32_t uDstDepth = m_regDst.getUpperZ() - m_regDst.getLowerZ() + 1;
if((uSrcWidth == uDstWidth) && (uSrcHeight == uDstHeight) && (uSrcDepth == uDstDepth))
{
resampleSameSize();
}
else
{
resampleArbitrary();
}
}
template< typename SrcVolumeType, typename DstVolumeType>
void VolumeResampler<SrcVolumeType, DstVolumeType>::resampleSameSize()
{
for(int32_t sz = m_regSrc.getLowerZ(), dz = m_regDst.getLowerZ(); dz <= m_regDst.getUpperZ(); sz++, dz++)
{
for(int32_t sy = m_regSrc.getLowerY(), dy = m_regDst.getLowerY(); dy <= m_regDst.getUpperY(); sy++, dy++)
{
for(int32_t sx = m_regSrc.getLowerX(), dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); sx++,dx++)
{
const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxel(sx,sy,sz, WrapModes::AssumeValid); // FIXME use templatised version of getVoxel(), but watch out for Linux compile issues.
const typename DstVolumeType::VoxelType& tDstVoxel = static_cast<typename DstVolumeType::VoxelType>(tSrcVoxel);
m_pVolDst->setVoxelAt(dx,dy,dz,tDstVoxel);
}
}
}
}
template< typename SrcVolumeType, typename DstVolumeType>
void VolumeResampler<SrcVolumeType, DstVolumeType>::resampleArbitrary()
{
float srcWidth = m_regSrc.getWidthInCells();
float srcHeight = m_regSrc.getHeightInCells();
float srcDepth = m_regSrc.getDepthInCells();
float dstWidth = m_regDst.getWidthInCells();
float dstHeight = m_regDst.getHeightInCells();
float dstDepth = m_regDst.getDepthInCells();
float fScaleX = srcWidth / dstWidth;
float fScaleY = srcHeight / dstHeight;
float fScaleZ = srcDepth / dstDepth;
typename SrcVolumeType::Sampler sampler(m_pVolSrc);
for(int32_t dz = m_regDst.getLowerZ(); dz <= m_regDst.getUpperZ(); dz++)
{
for(int32_t dy = m_regDst.getLowerY(); dy <= m_regDst.getUpperY(); dy++)
{
for(int32_t dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); dx++)
{
float sx = (dx - m_regDst.getLowerX()) * fScaleX;
float sy = (dy - m_regDst.getLowerY()) * fScaleY;
float sz = (dz - m_regDst.getLowerZ()) * fScaleZ;
sx += m_regSrc.getLowerX();
sy += m_regSrc.getLowerY();
sz += m_regSrc.getLowerZ();
sampler.setPosition(sx,sy,sz);
const typename SrcVolumeType::VoxelType& voxel000 = sampler.peekVoxel0px0py0pz();
const typename SrcVolumeType::VoxelType& voxel001 = sampler.peekVoxel0px0py1pz();
const typename SrcVolumeType::VoxelType& voxel010 = sampler.peekVoxel0px1py0pz();
const typename SrcVolumeType::VoxelType& voxel011 = sampler.peekVoxel0px1py1pz();
const typename SrcVolumeType::VoxelType& voxel100 = sampler.peekVoxel1px0py0pz();
const typename SrcVolumeType::VoxelType& voxel101 = sampler.peekVoxel1px0py1pz();
const typename SrcVolumeType::VoxelType& voxel110 = sampler.peekVoxel1px1py0pz();
const typename SrcVolumeType::VoxelType& voxel111 = sampler.peekVoxel1px1py1pz();
//FIXME - should accept all float parameters, but GCC complains?
double dummy;
sx = modf(sx, &dummy);
sy = modf(sy, &dummy);
sz = modf(sz, &dummy);
typename SrcVolumeType::VoxelType tInterpolatedValue = trilerp<float>(voxel000,voxel100,voxel010,voxel110,voxel001,voxel101,voxel011,voxel111,sx,sy,sz);
typename DstVolumeType::VoxelType result = static_cast<typename DstVolumeType::VoxelType>(tInterpolatedValue);
m_pVolDst->setVoxelAt(dx,dy,dz,result);
}
}
}
}
}

View File

@ -1,37 +1,37 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_VoxelFilters_H__
#define __PolyVox_VoxelFilters_H__
#include "Impl/TypeDef.h"
namespace PolyVox
{
template< typename VolumeType >
float computeSmoothedVoxel(typename VolumeType::Sampler& volIter);
}
#include "PolyVoxCore/VoxelFilters.inl"
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_VoxelFilters_H__
#define __PolyVox_VoxelFilters_H__
#include "Impl/TypeDef.h"
namespace PolyVox
{
template< typename VolumeType >
float computeSmoothedVoxel(typename VolumeType::Sampler& volIter);
}
#include "PolyVoxCore/VoxelFilters.inl"
#endif

View File

@ -1,67 +1,67 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/AStarPathfinder.h"
using namespace PolyVox;
namespace PolyVox
{
const Vector3DInt32 arrayPathfinderFaces[6] =
{
Vector3DInt32(0, 0, -1),
Vector3DInt32(0, 0, +1),
Vector3DInt32(0, -1, 0),
Vector3DInt32(0, +1, 0),
Vector3DInt32(-1, 0, 0),
Vector3DInt32(+1, 0, 0)
};
const Vector3DInt32 arrayPathfinderEdges[12] =
{
Vector3DInt32(0, -1, -1),
Vector3DInt32(0, -1, +1),
Vector3DInt32(0, +1, -1),
Vector3DInt32(0, +1, +1),
Vector3DInt32(-1, 0, -1),
Vector3DInt32(-1, 0, +1),
Vector3DInt32(+1, 0, -1),
Vector3DInt32(+1, 0, +1),
Vector3DInt32(-1, -1, 0),
Vector3DInt32(-1, +1, 0),
Vector3DInt32(+1, -1, 0),
Vector3DInt32(+1, +1, 0)
};
const Vector3DInt32 arrayPathfinderCorners[8] =
{
Vector3DInt32(-1, -1, -1),
Vector3DInt32(-1, -1, +1),
Vector3DInt32(-1, +1, -1),
Vector3DInt32(-1, +1, +1),
Vector3DInt32(+1, -1, -1),
Vector3DInt32(+1, -1, +1),
Vector3DInt32(+1, +1, -1),
Vector3DInt32(+1, +1, +1)
};
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/AStarPathfinder.h"
using namespace PolyVox;
namespace PolyVox
{
const Vector3DInt32 arrayPathfinderFaces[6] =
{
Vector3DInt32(0, 0, -1),
Vector3DInt32(0, 0, +1),
Vector3DInt32(0, -1, 0),
Vector3DInt32(0, +1, 0),
Vector3DInt32(-1, 0, 0),
Vector3DInt32(+1, 0, 0)
};
const Vector3DInt32 arrayPathfinderEdges[12] =
{
Vector3DInt32(0, -1, -1),
Vector3DInt32(0, -1, +1),
Vector3DInt32(0, +1, -1),
Vector3DInt32(0, +1, +1),
Vector3DInt32(-1, 0, -1),
Vector3DInt32(-1, 0, +1),
Vector3DInt32(+1, 0, -1),
Vector3DInt32(+1, 0, +1),
Vector3DInt32(-1, -1, 0),
Vector3DInt32(-1, +1, 0),
Vector3DInt32(+1, -1, 0),
Vector3DInt32(+1, +1, 0)
};
const Vector3DInt32 arrayPathfinderCorners[8] =
{
Vector3DInt32(-1, -1, -1),
Vector3DInt32(-1, -1, +1),
Vector3DInt32(-1, +1, -1),
Vector3DInt32(-1, +1, +1),
Vector3DInt32(+1, -1, -1),
Vector3DInt32(+1, -1, +1),
Vector3DInt32(+1, +1, -1),
Vector3DInt32(+1, +1, +1)
};
}

File diff suppressed because it is too large Load Diff

View File

@ -1,92 +1,92 @@
# Copyright (c) 2008-2012 Matt Williams
# Copyright (c) 2008-2012 David Williams
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
PROJECT(PolyVoxUtil)
#Projects source files
SET(UTIL_SRC_FILES
source/Dummy.cpp
)
#Projects headers files
SET(UTIL_INC_FILES
#Nothing here at the moment...
)
ADD_DEFINITIONS(-DPOLYVOX_SHARED_EXPORTS) #Export symbols in the .dll
#"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too...
SOURCE_GROUP("Source Files" FILES ${UTIL_SRC_FILES})
SOURCE_GROUP("Header Files" FILES ${UTIL_INC_FILES})
#Tell CMake the paths
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include)
#There has to be a better way!
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release ${PolyVoxCore_BINARY_DIR})
#Util
#Build
IF(LIBRARY_TYPE STREQUAL "STATIC")
ADD_LIBRARY(PolyVoxUtil STATIC ${UTIL_SRC_FILES} ${UTIL_INC_FILES})
IF(UNIX)
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS -fPIC)
ENDIF()
ENDIF()
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")
TARGET_LINK_LIBRARIES(PolyVoxUtil PolyVoxCore)
SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES COMPILE_FLAGS "/W4 /wd4251 /wd4127") #Disable warning on STL exports
ENDIF(MSVC)
#Install
IF(WIN32)
INSTALL(TARGETS PolyVoxUtil
RUNTIME DESTINATION PolyVoxUtil/bin COMPONENT library
LIBRARY DESTINATION PolyVoxUtil/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxUtil/lib COMPONENT library
)
#Install the util header files.
INSTALL(DIRECTORY include DESTINATION PolyVoxUtil COMPONENT development PATTERN "*.svn*" EXCLUDE)
#On windows, we also install the debug information. It's unfortunate that we have to hard-code
#the 'Debug' part of the path, but CMake doesn't seem to provide a way around this. The best I
#found was: http://www.cmake.org/pipermail/cmake/2007-October/016924.html (and it is a bit ugly).
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/PolyVoxUtil.pdb DESTINATION PolyVoxUtil/lib CONFIGURATIONS Debug)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/PolyVoxUtil.pdb DESTINATION PolyVoxUtil/lib CONFIGURATIONS RelWithDebInfo)
ELSE(WIN32)
INSTALL(TARGETS PolyVoxUtil
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
#Install the util header files.
INSTALL(DIRECTORY include/ DESTINATION include/PolyVoxUtil COMPONENT development PATTERN "*.svn*" EXCLUDE)
ENDIF(WIN32)
# Copyright (c) 2008-2012 Matt Williams
# Copyright (c) 2008-2012 David Williams
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
PROJECT(PolyVoxUtil)
#Projects source files
SET(UTIL_SRC_FILES
source/Dummy.cpp
)
#Projects headers files
SET(UTIL_INC_FILES
#Nothing here at the moment...
)
ADD_DEFINITIONS(-DPOLYVOX_SHARED_EXPORTS) #Export symbols in the .dll
#"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too...
SOURCE_GROUP("Source Files" FILES ${UTIL_SRC_FILES})
SOURCE_GROUP("Header Files" FILES ${UTIL_INC_FILES})
#Tell CMake the paths
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include)
#There has to be a better way!
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release ${PolyVoxCore_BINARY_DIR})
#Util
#Build
IF(LIBRARY_TYPE STREQUAL "STATIC")
ADD_LIBRARY(PolyVoxUtil STATIC ${UTIL_SRC_FILES} ${UTIL_INC_FILES})
IF(UNIX)
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS -fPIC)
ENDIF()
ENDIF()
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")
TARGET_LINK_LIBRARIES(PolyVoxUtil PolyVoxCore)
SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES COMPILE_FLAGS "/W4 /wd4251 /wd4127") #Disable warning on STL exports
ENDIF(MSVC)
#Install
IF(WIN32)
INSTALL(TARGETS PolyVoxUtil
RUNTIME DESTINATION PolyVoxUtil/bin COMPONENT library
LIBRARY DESTINATION PolyVoxUtil/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxUtil/lib COMPONENT library
)
#Install the util header files.
INSTALL(DIRECTORY include DESTINATION PolyVoxUtil COMPONENT development PATTERN "*.svn*" EXCLUDE)
#On windows, we also install the debug information. It's unfortunate that we have to hard-code
#the 'Debug' part of the path, but CMake doesn't seem to provide a way around this. The best I
#found was: http://www.cmake.org/pipermail/cmake/2007-October/016924.html (and it is a bit ugly).
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/PolyVoxUtil.pdb DESTINATION PolyVoxUtil/lib CONFIGURATIONS Debug)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/PolyVoxUtil.pdb DESTINATION PolyVoxUtil/lib CONFIGURATIONS RelWithDebInfo)
ELSE(WIN32)
INSTALL(TARGETS PolyVoxUtil
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
#Install the util header files.
INSTALL(DIRECTORY include/ DESTINATION include/PolyVoxUtil COMPONENT development PATTERN "*.svn*" EXCLUDE)
ENDIF(WIN32)

View File

@ -1,16 +1,16 @@
#include "PolyVoxCore/Impl/TypeDef.h"
namespace PolyVox
{
class POLYVOX_API DummyClass
{
public:
int getx(void);
int x;
};
int DummyClass::getx(void)
{
return x;
}
}
#include "PolyVoxCore/Impl/TypeDef.h"
namespace PolyVox
{
class POLYVOX_API DummyClass
{
public:
int getx(void);
int x;
};
int DummyClass::getx(void)
{
return x;
}
}

View File

@ -1,10 +1,10 @@
%module Array
%{
#include "PolyVoxImpl\SubArray.h"
#include "Array.h"
%}
%include "PolyVoxImpl\SubArray.h"
%include "Array.h"
%template(Array3IndexAndMaterial) PolyVox::Array<3, PolyVox::IndexAndMaterial>;
%module Array
%{
#include "PolyVoxImpl\SubArray.h"
#include "Array.h"
%}
%include "PolyVoxImpl\SubArray.h"
%include "Array.h"
%template(Array3IndexAndMaterial) PolyVox::Array<3, PolyVox::IndexAndMaterial>;

View File

@ -1,65 +1,65 @@
# Copyright (c) 2009-2013 Matt Williams
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
option(ENABLE_BINDINGS "Build bindings" ON)
if(ENABLE_BINDINGS)
find_package(SWIG)
mark_as_advanced(SWIG_DIR SWIG_VERSION)
find_package(PythonLibs 3)
if(CMAKE_VERSION VERSION_LESS "2.8.6")
set_package_info(SWIG "Bindings generator" http://www.swig.org)
set_package_info(PythonLibs "Programming language" http://www.python.org)
else()
set_package_properties(SWIG PROPERTIES DESCRIPTION "Bindings generator" URL http://www.swig.org)
set_package_properties(PythonLibs PROPERTIES DESCRIPTION "Programming language" URL http://www.python.org)
endif()
if(SWIG_FOUND)
set(BUILD_BINDINGS ON CACHE BOOL "Will the bindings be built" FORCE)
include(${SWIG_USE_FILE})
set(CMAKE_SWIG_FLAGS "")
set_source_files_properties(PolyVoxCore.i PROPERTIES CPLUSPLUS ON)
include_directories(${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore)
if(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_PATH})
link_directories(${PolyVoxCore_BINARY_DIR})
#set_source_files_properties(PolyVoxCore.i PROPERTIES SWIG_FLAGS "-builtin")
set(SWIG_MODULE_PolyVoxCorePython_EXTRA_FLAGS "-py3")
swig_add_module(PolyVoxCorePython python PolyVoxCore.i)
swig_link_libraries(PolyVoxCorePython ${PYTHON_LIBRARIES} PolyVoxCore)
set_target_properties(${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTIES OUTPUT_NAME _PolyVoxCore)
#set_target_properties(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTIES SUFFIX ".pyd")
SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTY FOLDER "Bindings")
endif()
set(SWIG_MODULE_PolyVoxCoreCSharp_EXTRA_FLAGS "-dllimport;PolyVoxCoreCSharp") #This _should_ be inside UseSWIG.cmake - http://www.cmake.org/Bug/view.php?id=13814
swig_add_module(PolyVoxCoreCSharp csharp PolyVoxCore.i)
swig_link_libraries(PolyVoxCoreCSharp PolyVoxCore)
SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCoreCSharp_REAL_NAME} PROPERTY FOLDER "Bindings")
else()
set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE)
endif()
else()
set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE)
endif()
mark_as_advanced(FORCE BUILD_BINDINGS)
# Copyright (c) 2009-2013 Matt Williams
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
option(ENABLE_BINDINGS "Build bindings" ON)
if(ENABLE_BINDINGS)
find_package(SWIG)
mark_as_advanced(SWIG_DIR SWIG_VERSION)
find_package(PythonLibs 3)
if(CMAKE_VERSION VERSION_LESS "2.8.6")
set_package_info(SWIG "Bindings generator" http://www.swig.org)
set_package_info(PythonLibs "Programming language" http://www.python.org)
else()
set_package_properties(SWIG PROPERTIES DESCRIPTION "Bindings generator" URL http://www.swig.org)
set_package_properties(PythonLibs PROPERTIES DESCRIPTION "Programming language" URL http://www.python.org)
endif()
if(SWIG_FOUND)
set(BUILD_BINDINGS ON CACHE BOOL "Will the bindings be built" FORCE)
include(${SWIG_USE_FILE})
set(CMAKE_SWIG_FLAGS "")
set_source_files_properties(PolyVoxCore.i PROPERTIES CPLUSPLUS ON)
include_directories(${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore)
if(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_PATH})
link_directories(${PolyVoxCore_BINARY_DIR})
#set_source_files_properties(PolyVoxCore.i PROPERTIES SWIG_FLAGS "-builtin")
set(SWIG_MODULE_PolyVoxCorePython_EXTRA_FLAGS "-py3")
swig_add_module(PolyVoxCorePython python PolyVoxCore.i)
swig_link_libraries(PolyVoxCorePython ${PYTHON_LIBRARIES} PolyVoxCore)
set_target_properties(${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTIES OUTPUT_NAME _PolyVoxCore)
#set_target_properties(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTIES SUFFIX ".pyd")
SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTY FOLDER "Bindings")
endif()
set(SWIG_MODULE_PolyVoxCoreCSharp_EXTRA_FLAGS "-dllimport;PolyVoxCoreCSharp") #This _should_ be inside UseSWIG.cmake - http://www.cmake.org/Bug/view.php?id=13814
swig_add_module(PolyVoxCoreCSharp csharp PolyVoxCore.i)
swig_link_libraries(PolyVoxCoreCSharp PolyVoxCore)
SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCoreCSharp_REAL_NAME} PROPERTY FOLDER "Bindings")
else()
set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE)
endif()
else()
set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE)
endif()
mark_as_advanced(FORCE BUILD_BINDINGS)

View File

@ -1,9 +1,9 @@
%module CubicSurfaceExtractor
%{
#include "CubicSurfaceExtractor.h"
%}
%include "CubicSurfaceExtractor.h"
%template(CubicSurfaceExtractorSimpleVolumeuint8) PolyVox::CubicSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>, PolyVox::DefaultIsQuadNeeded<uint8_t> >;
//EXTRACTORS(CubicSurfaceExtractor)
%module CubicSurfaceExtractor
%{
#include "CubicSurfaceExtractor.h"
%}
%include "CubicSurfaceExtractor.h"
%template(CubicSurfaceExtractorSimpleVolumeuint8) PolyVox::CubicSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>, PolyVox::DefaultIsQuadNeeded<uint8_t> >;
//EXTRACTORS(CubicSurfaceExtractor)

View File

@ -1,8 +1,8 @@
%module CubicSurfaceExtractorWithNormals
%{
#include "CubicSurfaceExtractorWithNormals.h"
%}
%include "CubicSurfaceExtractorWithNormals.h"
%template(CubicSurfaceExtractorWithNormalsSimpleVolumeuint8) PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>, PolyVox::DefaultIsQuadNeeded<uint8_t> >;
%module CubicSurfaceExtractorWithNormals
%{
#include "CubicSurfaceExtractorWithNormals.h"
%}
%include "CubicSurfaceExtractorWithNormals.h"
%template(CubicSurfaceExtractorWithNormalsSimpleVolumeuint8) PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>, PolyVox::DefaultIsQuadNeeded<uint8_t> >;

View File

@ -5,5 +5,5 @@
%include "MeshDecimator.h"
%template(MeshDecimatorMaterial8) PolyVox::MeshDecimator<PolyVox::Material8>;
%template(MeshDecimatorMaterial8) PolyVox::MeshDecimator<PolyVox::Material8>;
%template(MeshDecimatorDensity8) PolyVox::MeshDecimator<PolyVox::Density8>;

View File

@ -1,98 +1,98 @@
%module PolyVoxCore
#define POLYVOX_API
%include "Impl/TypeDef.h"
#define __attribute__(x) //Silence DEPRECATED errors
//This macro allows us to use Python properties on our classes
%define PROPERTY(type,name,getter,setter)
%extend type {
%pythoncode %{
__swig_getmethods__["name"] = getter
__swig_setmethods__["name"] = setter
if _newclass: name = property(getter, setter)
%}
};
%enddef
//Put this in an %extend section to wrap operator<< as __str__
%define STR()
const char* __str__() {
std::ostringstream out;
out << *$self;
return out.str().c_str();
}
%enddef
//Centralise this to avoid repeating ourselves
//This macro will be called in the volume interface files to define the various volume types.
%define VOLUMETYPES(class)
%template(class ## int8) PolyVox::class<int8_t>;
%template(class ## int16) PolyVox::class<int16_t>;
%template(class ## int32) PolyVox::class<int32_t>;
%template(class ## uint8) PolyVox::class<uint8_t>;
%template(class ## uint16) PolyVox::class<uint16_t>;
%template(class ## uint32) PolyVox::class<uint32_t>;
%template(class ## float) PolyVox::class<float>;
%enddef
//Template based on voxel type
%define EXTRACTOR(class, volumetype)
%template(class ## volumetype ## int8) PolyVox::class<PolyVox::volumetype<int8_t> >;
%template(class ## volumetype ## int16) PolyVox::class<PolyVox::volumetype<int16_t> >;
%template(class ## volumetype ## int32) PolyVox::class<PolyVox::volumetype<int32_t> >;
%template(class ## volumetype ## uint8) PolyVox::class<PolyVox::volumetype<uint8_t> >;
%template(class ## volumetype ## uint16) PolyVox::class<PolyVox::volumetype<uint16_t> >;
%template(class ## volumetype ## uint32) PolyVox::class<PolyVox::volumetype<uint32_t> >;
%template(class ## volumetype ## float) PolyVox::class<PolyVox::volumetype<float> >;
%enddef
//Template based on volume type
%define EXTRACTORS(shortname)
EXTRACTOR(shortname, SimpleVolume)
EXTRACTOR(shortname, RawVolume)
EXTRACTOR(shortname, LargeVolume)
%enddef
%feature("autodoc", "1");
#ifdef SWIGPYTHON
//This will rename "operator=" to "assign" since Python doesn't have assignment
%rename(assign) *::operator=;
#endif
#ifdef SWIGCSHARP
//These operators are not wrappable in C# and their function is provided by other means
%ignore *::operator=;
%ignore *::operator+=;
%ignore *::operator-=;
%ignore *::operator*=;
%ignore *::operator/=;
%ignore *::operator<<; //This is covered by STR()
#endif
%include "stdint.i"
%include "std_vector.i"
%include "Vector.i"
%include "DefaultMarchingCubesController.i"
%include "Region.i"
%include "Block.i"
%include "CompressedBlock.i"
%include "UncompressedBlock.i"
%include "BlockCompressor.i"
%include "Pager.i"
%include "FilePager.i"
%include "MinizBlockCompressor.i"
%include "RLEBlockCompressor.i"
%include "BaseVolume.i"
%include "SimpleVolume.i"
%include "RawVolume.i"
%include "LargeVolume.i"
//%include "SubArray.i"
//%include "Array.i"
%include "VertexTypes.i"
%include "SurfaceMesh.i"
%include "MarchingCubesSurfaceExtractor.i"
%include "CubicSurfaceExtractor.i"
%include "CubicSurfaceExtractorWithNormals.i"
%include "Raycast.i"
%include "Picking.i"
%module PolyVoxCore
#define POLYVOX_API
%include "Impl/TypeDef.h"
#define __attribute__(x) //Silence DEPRECATED errors
//This macro allows us to use Python properties on our classes
%define PROPERTY(type,name,getter,setter)
%extend type {
%pythoncode %{
__swig_getmethods__["name"] = getter
__swig_setmethods__["name"] = setter
if _newclass: name = property(getter, setter)
%}
};
%enddef
//Put this in an %extend section to wrap operator<< as __str__
%define STR()
const char* __str__() {
std::ostringstream out;
out << *$self;
return out.str().c_str();
}
%enddef
//Centralise this to avoid repeating ourselves
//This macro will be called in the volume interface files to define the various volume types.
%define VOLUMETYPES(class)
%template(class ## int8) PolyVox::class<int8_t>;
%template(class ## int16) PolyVox::class<int16_t>;
%template(class ## int32) PolyVox::class<int32_t>;
%template(class ## uint8) PolyVox::class<uint8_t>;
%template(class ## uint16) PolyVox::class<uint16_t>;
%template(class ## uint32) PolyVox::class<uint32_t>;
%template(class ## float) PolyVox::class<float>;
%enddef
//Template based on voxel type
%define EXTRACTOR(class, volumetype)
%template(class ## volumetype ## int8) PolyVox::class<PolyVox::volumetype<int8_t> >;
%template(class ## volumetype ## int16) PolyVox::class<PolyVox::volumetype<int16_t> >;
%template(class ## volumetype ## int32) PolyVox::class<PolyVox::volumetype<int32_t> >;
%template(class ## volumetype ## uint8) PolyVox::class<PolyVox::volumetype<uint8_t> >;
%template(class ## volumetype ## uint16) PolyVox::class<PolyVox::volumetype<uint16_t> >;
%template(class ## volumetype ## uint32) PolyVox::class<PolyVox::volumetype<uint32_t> >;
%template(class ## volumetype ## float) PolyVox::class<PolyVox::volumetype<float> >;
%enddef
//Template based on volume type
%define EXTRACTORS(shortname)
EXTRACTOR(shortname, SimpleVolume)
EXTRACTOR(shortname, RawVolume)
EXTRACTOR(shortname, LargeVolume)
%enddef
%feature("autodoc", "1");
#ifdef SWIGPYTHON
//This will rename "operator=" to "assign" since Python doesn't have assignment
%rename(assign) *::operator=;
#endif
#ifdef SWIGCSHARP
//These operators are not wrappable in C# and their function is provided by other means
%ignore *::operator=;
%ignore *::operator+=;
%ignore *::operator-=;
%ignore *::operator*=;
%ignore *::operator/=;
%ignore *::operator<<; //This is covered by STR()
#endif
%include "stdint.i"
%include "std_vector.i"
%include "Vector.i"
%include "DefaultMarchingCubesController.i"
%include "Region.i"
%include "Block.i"
%include "CompressedBlock.i"
%include "UncompressedBlock.i"
%include "BlockCompressor.i"
%include "Pager.i"
%include "FilePager.i"
%include "MinizBlockCompressor.i"
%include "RLEBlockCompressor.i"
%include "BaseVolume.i"
%include "SimpleVolume.i"
%include "RawVolume.i"
%include "LargeVolume.i"
//%include "SubArray.i"
//%include "Array.i"
%include "VertexTypes.i"
%include "SurfaceMesh.i"
%include "MarchingCubesSurfaceExtractor.i"
%include "CubicSurfaceExtractor.i"
%include "CubicSurfaceExtractorWithNormals.i"
%include "Raycast.i"
%include "Picking.i"

View File

@ -1,9 +1,9 @@
%module SimpleVolumeSampler
%{
#include "SimpleVolume.h"
%}
%include "SimpleVolume.h"
%template(SimpleVolumeSamplerMaterial8) PolyVox::SimpleVolume::Sampler<PolyVox::Material8>;
%module SimpleVolumeSampler
%{
#include "SimpleVolume.h"
%}
%include "SimpleVolume.h"
%template(SimpleVolumeSamplerMaterial8) PolyVox::SimpleVolume::Sampler<PolyVox::Material8>;
%template(SimpleVolumeSamplerDensity8) PolyVox::SimpleVolume::Sampler<PolyVox::Density8>;

View File

@ -1,9 +1,9 @@
%module SubArray
%{
#include "PolyVoxImpl\SubArray.h"
%}
%include "PolyVoxImpl\SubArray.h"
//%template(SubArray) PolyVox::SubArray<uint32_t, PolyVox::IndexAndMaterial>;
%module SubArray
%{
#include "PolyVoxImpl\SubArray.h"
%}
%include "PolyVoxImpl\SubArray.h"
//%template(SubArray) PolyVox::SubArray<uint32_t, PolyVox::IndexAndMaterial>;
//%template(SubArray) PolyVox::SubArray<uint32_t, PolyVox::IndexAndMaterial>;

View File

@ -1,20 +1,20 @@
%module SurfaceMesh
%{
#include "Region.h"
#include "VertexTypes.h"
#include "SurfaceMesh.h"
%}
%include "Region.h"
%include "VertexTypes.h"
%include "SurfaceMesh.h"
//%template(VertexTypeVector) std::vector<PolyVox::VertexType>;
%template(PositionMaterialVector) std::vector<PolyVox::PositionMaterial>;
%template(PositionMaterialNormalVector) std::vector<PolyVox::PositionMaterialNormal>;
%template(LodRecordVector) std::vector<PolyVox::LodRecord>;
%template(uint8Vector) std::vector<uint8_t>;
%template(uint32Vector) std::vector<uint32_t>;
%template(SurfaceMeshPositionMaterial) PolyVox::SurfaceMesh<PolyVox::PositionMaterial>;
%module SurfaceMesh
%{
#include "Region.h"
#include "VertexTypes.h"
#include "SurfaceMesh.h"
%}
%include "Region.h"
%include "VertexTypes.h"
%include "SurfaceMesh.h"
//%template(VertexTypeVector) std::vector<PolyVox::VertexType>;
%template(PositionMaterialVector) std::vector<PolyVox::PositionMaterial>;
%template(PositionMaterialNormalVector) std::vector<PolyVox::PositionMaterialNormal>;
%template(LodRecordVector) std::vector<PolyVox::LodRecord>;
%template(uint8Vector) std::vector<uint8_t>;
%template(uint32Vector) std::vector<uint32_t>;
%template(SurfaceMeshPositionMaterial) PolyVox::SurfaceMesh<PolyVox::PositionMaterial>;
%template(SurfaceMeshPositionMaterialNormal) PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>;

View File

@ -1,6 +1,6 @@
%module TypeDef
%{
#include "PolyVoxImpl/TypeDef.h"
%}
%module TypeDef
%{
#include "PolyVoxImpl/TypeDef.h"
%}
%include "PolyVoxImpl/TypeDef.h"

View File

@ -1,121 +1,121 @@
%module Vector
%{
#include "Vector.h"
#include <sstream>
%}
%include "Vector.h"
#ifdef SWIGPYTHON
PROPERTY(PolyVox::Vector, x, getX, setX)
PROPERTY(PolyVox::Vector, y, getY, setY)
PROPERTY(PolyVox::Vector, z, getZ, setZ)
#endif
%rename(Plus) operator +;
%rename(Minus) operator -;
%rename(Multiply) operator *;
%rename(Divide) operator /;
%rename(Equal) operator ==;
%rename(NotEqual) operator !=;
%extend PolyVox::Vector {
#ifdef SWIGPYTHON
PolyVox::Vector __add__(const PolyVox::Vector& rhs) {
return *$self + rhs;
}
PolyVox::Vector __sub__(const PolyVox::Vector& rhs) {
return *$self - rhs;
}
PolyVox::Vector __div__(const PolyVox::Vector& rhs) {
return *$self / rhs;
}
PolyVox::Vector __div__(const StorageType& rhs) {
return *$self / rhs;
}
PolyVox::Vector __mul__(const PolyVox::Vector& rhs) {
return *$self * rhs;
}
PolyVox::Vector __mul__(const StorageType& rhs) {
return *$self * rhs;
}
#endif
STR()
};
%feature("pythonprepend") PolyVox::Vector::operator< %{
import warnings
warnings.warn("deprecated", DeprecationWarning)
%}
//%csattributes PolyVox::Vector::operator< "[System.Obsolete(\"deprecated\")]"
%define VECTOR3(StorageType,OperationType,ReducedStorageType)
#if SWIGCSHARP
%extend PolyVox::Vector<3,StorageType,OperationType> {
PolyVox::Vector<3,StorageType,OperationType> operator+(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self + rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator-(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self - rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator*(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self * rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator/(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self / rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator*(const StorageType& rhs) {return *$self * rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator/(const StorageType& rhs) {return *$self / rhs;}
};
%typemap(cscode) PolyVox::Vector<3,StorageType,OperationType> %{
public static Vector3D##StorageType operator+(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Plus(rhs);
return newVec;
}
public static Vector3D##StorageType operator-(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Minus(rhs);
return newVec;
}
public static Vector3D##StorageType operator*(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Multiply(rhs);
return newVec;
}
public static Vector3D##StorageType operator/(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Divide(rhs);
return newVec;
}
public static Vector3D##StorageType operator*(Vector3D##StorageType lhs, $typemap(cstype, StorageType) rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Multiply(rhs);
return newVec;
}
public static Vector3D##StorageType operator/(Vector3D##StorageType lhs, $typemap(cstype, StorageType) rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Divide(rhs);
return newVec;
}
public bool Equals(Vector3D##StorageType rhs) {
if ((object)rhs == null)
{
return false;
}
return Equal(rhs);
}
%}
%ignore PolyVox::Vector<3,StorageType,OperationType>::operator<; //This is deprecated
#endif
%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType);
%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType);
%ignore PolyVox::Vector<3,StorageType,OperationType>::getW() const;
%ignore PolyVox::Vector<3,StorageType,OperationType>::setW(ReducedStorageType);
%ignore PolyVox::Vector<3,StorageType,OperationType>::setElements(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType);
%template(Vector3D ## StorageType) PolyVox::Vector<3,StorageType,OperationType>;
%enddef
VECTOR3(float,float,float)
VECTOR3(double,double,double)
VECTOR3(int8_t,int32_t,signed char)
VECTOR3(uint8_t,int32_t,unsigned char)
VECTOR3(int16_t,int32_t,signed short)
VECTOR3(uint16_t,int32_t,unsigned short)
VECTOR3(int32_t,int32_t,signed int)
VECTOR3(uint32_t,int32_t,unsigned int)
//%rename(assign) Vector3DFloat::operator=;
%module Vector
%{
#include "Vector.h"
#include <sstream>
%}
%include "Vector.h"
#ifdef SWIGPYTHON
PROPERTY(PolyVox::Vector, x, getX, setX)
PROPERTY(PolyVox::Vector, y, getY, setY)
PROPERTY(PolyVox::Vector, z, getZ, setZ)
#endif
%rename(Plus) operator +;
%rename(Minus) operator -;
%rename(Multiply) operator *;
%rename(Divide) operator /;
%rename(Equal) operator ==;
%rename(NotEqual) operator !=;
%extend PolyVox::Vector {
#ifdef SWIGPYTHON
PolyVox::Vector __add__(const PolyVox::Vector& rhs) {
return *$self + rhs;
}
PolyVox::Vector __sub__(const PolyVox::Vector& rhs) {
return *$self - rhs;
}
PolyVox::Vector __div__(const PolyVox::Vector& rhs) {
return *$self / rhs;
}
PolyVox::Vector __div__(const StorageType& rhs) {
return *$self / rhs;
}
PolyVox::Vector __mul__(const PolyVox::Vector& rhs) {
return *$self * rhs;
}
PolyVox::Vector __mul__(const StorageType& rhs) {
return *$self * rhs;
}
#endif
STR()
};
%feature("pythonprepend") PolyVox::Vector::operator< %{
import warnings
warnings.warn("deprecated", DeprecationWarning)
%}
//%csattributes PolyVox::Vector::operator< "[System.Obsolete(\"deprecated\")]"
%define VECTOR3(StorageType,OperationType,ReducedStorageType)
#if SWIGCSHARP
%extend PolyVox::Vector<3,StorageType,OperationType> {
PolyVox::Vector<3,StorageType,OperationType> operator+(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self + rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator-(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self - rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator*(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self * rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator/(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self / rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator*(const StorageType& rhs) {return *$self * rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator/(const StorageType& rhs) {return *$self / rhs;}
};
%typemap(cscode) PolyVox::Vector<3,StorageType,OperationType> %{
public static Vector3D##StorageType operator+(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Plus(rhs);
return newVec;
}
public static Vector3D##StorageType operator-(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Minus(rhs);
return newVec;
}
public static Vector3D##StorageType operator*(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Multiply(rhs);
return newVec;
}
public static Vector3D##StorageType operator/(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Divide(rhs);
return newVec;
}
public static Vector3D##StorageType operator*(Vector3D##StorageType lhs, $typemap(cstype, StorageType) rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Multiply(rhs);
return newVec;
}
public static Vector3D##StorageType operator/(Vector3D##StorageType lhs, $typemap(cstype, StorageType) rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Divide(rhs);
return newVec;
}
public bool Equals(Vector3D##StorageType rhs) {
if ((object)rhs == null)
{
return false;
}
return Equal(rhs);
}
%}
%ignore PolyVox::Vector<3,StorageType,OperationType>::operator<; //This is deprecated
#endif
%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType);
%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType);
%ignore PolyVox::Vector<3,StorageType,OperationType>::getW() const;
%ignore PolyVox::Vector<3,StorageType,OperationType>::setW(ReducedStorageType);
%ignore PolyVox::Vector<3,StorageType,OperationType>::setElements(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType);
%template(Vector3D ## StorageType) PolyVox::Vector<3,StorageType,OperationType>;
%enddef
VECTOR3(float,float,float)
VECTOR3(double,double,double)
VECTOR3(int8_t,int32_t,signed char)
VECTOR3(uint8_t,int32_t,unsigned char)
VECTOR3(int16_t,int32_t,signed short)
VECTOR3(uint16_t,int32_t,unsigned short)
VECTOR3(int32_t,int32_t,signed int)
VECTOR3(uint32_t,int32_t,unsigned int)
//%rename(assign) Vector3DFloat::operator=;

View File

@ -1,13 +1,13 @@
%module VertexTypes
%{
#include "Impl/TypeDef.h"
#include "Vector.h"
#include "VertexTypes.h"
%}
%include "Impl/TypeDef.h"
%include "Vector.h"
%include "VertexTypes.h"
//%template (PositionMaterial) PolyVox::PositionMaterial;
%module VertexTypes
%{
#include "Impl/TypeDef.h"
#include "Vector.h"
#include "VertexTypes.h"
%}
%include "Impl/TypeDef.h"
%include "Vector.h"
%include "VertexTypes.h"
//%template (PositionMaterial) PolyVox::PositionMaterial;
//%template (PositionMaterialNormal) PolyVox::PositionMaterialNormal;