Merge branch 'develop' into feature/cubiquity-version

Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h
	library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl
	library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
	library/PolyVoxCore/include/PolyVoxCore/Vector.inl
	library/PolyVoxCore/source/Impl/Utility.cpp
This commit is contained in:
David Williams 2012-12-29 16:44:32 +00:00
commit d9dcf8a33c
60 changed files with 1904 additions and 1281 deletions

View File

@ -2,6 +2,10 @@ Changes for PolyVox version 0.3
===============================
This release has focused on... (some introduction here).
Error Handling
--------------
PolyVox now has it's own POLYVOX_ASSERT() macro rather than using the standard assert(). This has some advantages such as allowing a message to be printed and providing file/line information, and it is also possible to enable/disable it independantly of whether you are making a debug or release build
Volume wrap modes
-----------------
This release has seen a overhaul of the way PolyVox handles voxel positions which are outside of the volume. It used to be the case that you could specify a border value which would be returned whenever an out-of-volume access was performed, but this was not flexible enough for all use cases. You can now choose between different wrapping modes (border, clamp, etc) and apply them to both the volume itself or to samplers. If you have multiple samplers pointing at the same volume then you can choose to have different wrap modes for each of them.

View File

@ -26,7 +26,7 @@ PROJECT(PolyVox)
SET(POLYVOX_VERSION_MAJOR "0")
SET(POLYVOX_VERSION_MINOR "2")
SET(POLYVOX_VERSION_PATCH "0")
SET(POLYVOX_VERSION_PATCH "1")
SET(POLYVOX_VERSION "${POLYVOX_VERSION_MAJOR}.${POLYVOX_VERSION_MINOR}.${POLYVOX_VERSION_PATCH}" CACHE STRING "PolyVox version")
MARK_AS_ADVANCED(FORCE POLYVOX_VERSION)
@ -69,6 +69,10 @@ if(CMAKE_CXX_COMPILER MATCHES "clang")
ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode
endif()
if(NOT MSVC) #This is causing problems in Visual Studio so disable it for now
INCLUDE(cmake/Modules/CheckCXX11Features.cmake)
endif()
ADD_SUBDIRECTORY(library)
OPTION(ENABLE_EXAMPLES "Should the examples be built" ON)

View File

@ -0,0 +1,133 @@
# - Check which parts of the C++11 standard the compiler supports
#
# When found it will set the following variables
#
# CXX11_COMPILER_FLAGS - the compiler flags needed to get C++11 features
#
# HAS_CXX11_AUTO - auto keyword
# HAS_CXX11_AUTO_RET_TYPE - function declaration with deduced return types
# HAS_CXX11_CLASS_OVERRIDE - override and final keywords for classes and methods
# HAS_CXX11_CONSTEXPR - constexpr keyword
# HAS_CXX11_CSTDINT_H - cstdint header
# HAS_CXX11_DECLTYPE - decltype keyword
# HAS_CXX11_FUNC - __func__ preprocessor constant
# HAS_CXX11_INITIALIZER_LIST - initializer list
# HAS_CXX11_LAMBDA - lambdas
# HAS_CXX11_LIB_REGEX - regex library
# HAS_CXX11_LONG_LONG - long long signed & unsigned types
# HAS_CXX11_NULLPTR - nullptr
# HAS_CXX11_RVALUE_REFERENCES - rvalue references
# HAS_CXX11_SIZEOF_MEMBER - sizeof() non-static members
# HAS_CXX11_STATIC_ASSERT - static_assert()
# HAS_CXX11_VARIADIC_TEMPLATES - variadic templates
#=============================================================================
# Copyright 2011,2012 Rolf Eike Beer <eike@sf-mail.de>
# Copyright 2012 Andreas Weis
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
if (NOT CMAKE_CXX_COMPILER_LOADED)
message(FATAL_ERROR "CheckCXX11Features modules only works if language CXX is enabled")
endif ()
cmake_minimum_required(VERSION 2.8.3)
#
### Check for needed compiler flags
#
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" _HAS_CXX11_FLAG)
if (NOT _HAS_CXX11_FLAG)
check_cxx_compiler_flag("-std=c++0x" _HAS_CXX0X_FLAG)
endif ()
if (_HAS_CXX11_FLAG)
set(CXX11_COMPILER_FLAGS "-std=c++11")
elseif (_HAS_CXX0X_FLAG)
set(CXX11_COMPILER_FLAGS "-std=c++0x")
endif ()
function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
if (NOT DEFINED ${RESULT_VAR})
set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx11_${FEATURE_NAME}")
set(_SRCFILE_BASE ${CMAKE_CURRENT_LIST_DIR}/CheckCXX11Features/cxx11-test-${FEATURE_NAME})
set(_LOG_NAME "\"${FEATURE_NAME}\"")
message(STATUS "Checking C++11 support for ${_LOG_NAME}")
set(_SRCFILE "${_SRCFILE_BASE}.cpp")
set(_SRCFILE_FAIL "${_SRCFILE_BASE}_fail.cpp")
set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cpp")
if (CROSS_COMPILING)
try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
try_compile(${RESULT_VAR} "${_bindir}_fail" "${_SRCFILE_FAIL}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
else (CROSS_COMPILING)
try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
"${_bindir}" "${_SRCFILE}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
if (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
set(${RESULT_VAR} TRUE)
else (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
set(${RESULT_VAR} FALSE)
endif (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
"${_bindir}_fail" "${_SRCFILE_FAIL}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
if (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
set(${RESULT_VAR} TRUE)
else (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
set(${RESULT_VAR} FALSE)
endif (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
endif (CROSS_COMPILING)
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
if (_TMP_RESULT)
set(${RESULT_VAR} FALSE)
else (_TMP_RESULT)
set(${RESULT_VAR} TRUE)
endif (_TMP_RESULT)
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
if (${RESULT_VAR})
message(STATUS "Checking C++11 support for ${_LOG_NAME}: works")
else (${RESULT_VAR})
message(STATUS "Checking C++11 support for ${_LOG_NAME}: not supported")
endif (${RESULT_VAR})
set(${RESULT_VAR} ${${RESULT_VAR}} CACHE INTERNAL "C++11 support for ${_LOG_NAME}")
endif (NOT DEFINED ${RESULT_VAR})
endfunction(cxx11_check_feature)
#cxx11_check_feature("__func__" HAS_CXX11_FUNC)
#cxx11_check_feature("auto" HAS_CXX11_AUTO)
#cxx11_check_feature("auto_ret_type" HAS_CXX11_AUTO_RET_TYPE)
#cxx11_check_feature("class_override_final" HAS_CXX11_CLASS_OVERRIDE)
cxx11_check_feature("constexpr" HAS_CXX11_CONSTEXPR)
cxx11_check_feature("cstdint" HAS_CXX11_CSTDINT_H)
#cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE)
#cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST)
#cxx11_check_feature("lambda" HAS_CXX11_LAMBDA)
#cxx11_check_feature("long_long" HAS_CXX11_LONG_LONG)
#cxx11_check_feature("nullptr" HAS_CXX11_NULLPTR)
#cxx11_check_feature("regex" HAS_CXX11_LIB_REGEX)
#cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES)
#cxx11_check_feature("sizeof_member" HAS_CXX11_SIZEOF_MEMBER)
cxx11_check_feature("static_assert" HAS_CXX11_STATIC_ASSERT)
#cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES)
cxx11_check_feature("shared_ptr" HAS_CXX11_SHARED_PTR)

View File

@ -0,0 +1,8 @@
int main(void)
{
if (!__func__)
return 1;
if (!(*__func__))
return 1;
return 0;
}

View File

@ -0,0 +1,12 @@
int main()
{
auto i = 5;
auto f = 3.14159f;
auto d = 3.14159;
bool ret = (
(sizeof(f) < sizeof(d)) &&
(sizeof(i) == sizeof(int))
);
return ret ? 0 : 1;
}

View File

@ -0,0 +1,7 @@
int main(void)
{
// must fail because there is no initializer
auto i;
return 0;
}

View File

@ -0,0 +1,8 @@
auto foo(int i) -> int {
return i - 1;
}
int main()
{
return foo(1);
}

View File

@ -0,0 +1,21 @@
class base {
public:
virtual int foo(int a)
{ return 4 + a; }
int bar(int a) final
{ return a - 2; }
};
class sub final : public base {
public:
virtual int foo(int a) override
{ return 8 + 2 * a; };
};
int main(void)
{
base b;
sub s;
return (b.foo(2) * 2 == s.foo(2)) ? 0 : 1;
}

View File

@ -0,0 +1,25 @@
class base {
public:
virtual int foo(int a)
{ return 4 + a; }
virtual int bar(int a) final
{ return a - 2; }
};
class sub final : public base {
public:
virtual int foo(int a) override
{ return 8 + 2 * a; };
virtual int bar(int a)
{ return a; }
};
class impossible : public sub { };
int main(void)
{
base b;
sub s;
return 1;
}

View File

@ -0,0 +1,19 @@
constexpr int square(int x)
{
return x*x;
}
constexpr int the_answer()
{
return 42;
}
int main()
{
int test_arr[square(3)];
bool ret = (
(square(the_answer()) == 1764) &&
(sizeof(test_arr)/sizeof(test_arr[0]) == 9)
);
return ret ? 0 : 1;
}

View File

@ -0,0 +1,11 @@
#include <cstdint>
int main()
{
bool test =
(sizeof(int8_t) == 1) &&
(sizeof(int16_t) == 2) &&
(sizeof(int32_t) == 4) &&
(sizeof(int64_t) == 8);
return test ? 0 : 1;
}

View File

@ -0,0 +1,10 @@
bool check_size(int i)
{
return sizeof(int) == sizeof(decltype(i));
}
int main()
{
bool ret = check_size(42);
return ret ? 0 : 1;
}

View File

@ -0,0 +1,27 @@
#include <vector>
class seq {
public:
seq(std::initializer_list<int> list);
int length() const;
private:
std::vector<int> m_v;
};
seq::seq(std::initializer_list<int> list)
: m_v(list)
{
}
int seq::length() const
{
return m_v.size();
}
int main(void)
{
seq a = {18, 20, 2, 0, 4, 7};
return (a.length() == 6) ? 0 : 1;
}

View File

@ -0,0 +1,5 @@
int main()
{
int ret = 0;
return ([&ret]() -> int { return ret; })();
}

View File

@ -0,0 +1,7 @@
int main(void)
{
long long l;
unsigned long long ul;
return ((sizeof(l) >= 8) && (sizeof(ul) >= 8)) ? 0 : 1;
}

View File

@ -0,0 +1,6 @@
int main(void)
{
void *v = nullptr;
return v ? 1 : 0;
}

View File

@ -0,0 +1,6 @@
int main(void)
{
int i = nullptr;
return 1;
}

View File

@ -0,0 +1,26 @@
#include <algorithm>
#include <regex>
int parse_line(std::string const& line)
{
std::string tmp;
if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+//(-)?(\\d)+(\\s)+"))) {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+//(-)?(\\d)+"), std::string("V"));
} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
} else {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+"), std::string("V"));
}
return static_cast<int>(std::count(tmp.begin(), tmp.end(), 'V'));
}
int main()
{
bool test = (parse_line("f 7/7/7 -3/3/-3 2/-2/2") == 3) &&
(parse_line("f 7//7 3//-3 -2//2") == 3) &&
(parse_line("f 7/7 3/-3 -2/2") == 3) &&
(parse_line("f 7 3 -2") == 3);
return test ? 0 : 1;
}

View File

@ -0,0 +1,57 @@
#include <cassert>
class rvmove {
public:
void *ptr;
char *array;
rvmove()
: ptr(0),
array(new char[10])
{
ptr = this;
}
rvmove(rvmove &&other)
: ptr(other.ptr),
array(other.array)
{
other.array = 0;
other.ptr = 0;
}
~rvmove()
{
assert(((ptr != 0) && (array != 0)) || ((ptr == 0) && (array == 0)));
delete[] array;
}
rvmove &operator=(rvmove &&other)
{
delete[] array;
ptr = other.ptr;
array = other.array;
other.array = 0;
other.ptr = 0;
return *this;
}
static rvmove create()
{
return rvmove();
}
private:
rvmove(const rvmove &);
rvmove &operator=(const rvmove &);
};
int main()
{
rvmove mine;
if (mine.ptr != &mine)
return 1;
mine = rvmove::create();
if (mine.ptr == &mine)
return 1;
return 0;
}

View File

@ -0,0 +1,7 @@
#include <memory>
int main()
{
std::shared_ptr<int> test;
return 0;
}

View File

@ -0,0 +1,14 @@
struct foo {
char bar;
int baz;
};
int main(void)
{
bool ret = (
(sizeof(foo::bar) == 1) &&
(sizeof(foo::baz) >= sizeof(foo::bar)) &&
(sizeof(foo) >= sizeof(foo::bar) + sizeof(foo::baz))
);
return ret ? 0 : 1;
}

View File

@ -0,0 +1,9 @@
struct foo {
int baz;
double bar;
};
int main(void)
{
return (sizeof(foo::bar) == 4) ? 0 : 1;
}

View File

@ -0,0 +1,5 @@
int main(void)
{
static_assert(0 < 1, "your ordering of integers is screwed");
return 0;
}

View File

@ -0,0 +1,5 @@
int main(void)
{
static_assert(1 < 0, "your ordering of integers is screwed");
return 0;
}

View File

@ -0,0 +1,23 @@
int Accumulate()
{
return 0;
}
template<typename T, typename... Ts>
int Accumulate(T v, Ts... vs)
{
return v + Accumulate(vs...);
}
template<int... Is>
int CountElements()
{
return sizeof...(Is);
}
int main()
{
int acc = Accumulate(1, 2, 3, 4, -5);
int count = CountElements<1,2,3,4,5>();
return ((acc == 5) && (count == 5)) ? 0 : 1;
}

View File

@ -44,7 +44,7 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES})
FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
#Build

View File

@ -52,7 +52,7 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES})
FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
#Build

View File

@ -46,7 +46,7 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES})
FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
#Build

View File

@ -44,7 +44,7 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES})
FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
#Build

View File

@ -20,10 +20,13 @@
# 3. This notice may not be removed or altered from any source
# distribution.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(PolyVoxCore)
if(NOT MSVC)
#Set up the C++11 feature header file based on the CheckCXX11Features script
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h)
endif()
#Projects source files
SET(CORE_SRC_FILES
source/ArraySizes.cpp
@ -91,6 +94,7 @@ SET(CORE_INC_FILES
)
SET(IMPL_SRC_FILES
source/Impl/ErrorHandling.cpp
source/Impl/MarchingCubesTables.cpp
source/Impl/RandomUnitVectors.cpp
source/Impl/RandomVectors.cpp
@ -103,6 +107,7 @@ SET(IMPL_INC_FILES
include/PolyVoxCore/Impl/AStarPathfinderImpl.h
include/PolyVoxCore/Impl/Block.h
include/PolyVoxCore/Impl/Block.inl
include/PolyVoxCore/Impl/ErrorHandling.h
include/PolyVoxCore/Impl/MarchingCubesTables.h
include/PolyVoxCore/Impl/RandomUnitVectors.h
include/PolyVoxCore/Impl/RandomVectors.h
@ -123,7 +128,7 @@ SOURCE_GROUP("Sources\\Impl" FILES ${IMPL_SRC_FILES})
SOURCE_GROUP("Headers\\Impl" FILES ${IMPL_INC_FILES})
#Tell CMake the paths
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include)
#Core
#Build

View File

@ -29,6 +29,7 @@ freely, subject to the following restrictions:
#include "PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/Array.h"
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
#include "PolyVoxCore/SurfaceMesh.h"
@ -109,7 +110,13 @@ namespace PolyVox
};
public:
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
#if defined(_MSC_VER)
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
#else
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
#endif
void execute();
@ -144,6 +151,10 @@ namespace PolyVox
//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;
};
}

View File

@ -35,11 +35,13 @@ namespace PolyVox
const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 6;
template<typename VolumeType, typename IsQuadNeeded>
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
:m_volData(volData)
,m_regSizeInVoxels(region)
,m_meshCurrent(result)
,m_bMergeQuads(bMergeQuads)
,m_eWrapMode(eWrapMode)
,m_tBorderValue(tBorderValue)
{
m_funcIsQuadNeededCallback = isQuadNeeded;
}
@ -72,6 +74,7 @@ namespace PolyVox
m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ() + 2);
typename VolumeType::Sampler volumeSampler(m_volData);
volumeSampler.setWrapMode(m_eWrapMode, m_tBorderValue);
for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ(); z++)
{

View File

@ -27,6 +27,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
#include "PolyVoxCore/Array.h"
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
#include "PolyVoxCore/SurfaceMesh.h"
namespace PolyVox
@ -35,7 +36,13 @@ namespace PolyVox
class CubicSurfaceExtractorWithNormals
{
public:
CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
#if defined(_MSC_VER)
CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), IsQuadNeeded isQuadNeeded = IsQuadNeeded());
#else
CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), IsQuadNeeded isQuadNeeded = IsQuadNeeded());
#endif
void execute();
@ -51,6 +58,10 @@ namespace PolyVox
//Information about the region we are currently processing
Region m_regSizeInVoxels;
//The wrap mode
WrapMode m_eWrapMode;
typename VolumeType::VoxelType m_tBorderValue;
};
}

View File

@ -24,11 +24,13 @@ freely, subject to the following restrictions:
namespace PolyVox
{
template<typename VolumeType, typename IsQuadNeeded>
CubicSurfaceExtractorWithNormals<VolumeType, IsQuadNeeded>::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, IsQuadNeeded isQuadNeeded)
CubicSurfaceExtractorWithNormals<VolumeType, IsQuadNeeded>::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, IsQuadNeeded isQuadNeeded)
:m_volData(volData)
,m_sampVolume(volData)
,m_meshCurrent(result)
,m_regSizeInVoxels(region)
,m_eWrapMode(eWrapMode)
,m_tBorderValue(tBorderValue)
{
m_funcIsQuadNeededCallback = isQuadNeeded;
}
@ -51,7 +53,7 @@ namespace PolyVox
uint32_t material = 0;
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x+1,y,z), material))
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), material))
{
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast<float>(material)));
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast<float>(material)));
@ -61,7 +63,7 @@ namespace PolyVox
m_meshCurrent->addTriangleCubic(v0,v2,v1);
m_meshCurrent->addTriangleCubic(v1,v2,v3);
}
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x+1,y,z), m_volData->getVoxelAt(x,y,z), material))
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material))
{
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast<float>(material)));
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast<float>(material)));
@ -72,7 +74,7 @@ namespace PolyVox
m_meshCurrent->addTriangleCubic(v1,v3,v2);
}
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y+1,z), material))
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), material))
{
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast<float>(material)));
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast<float>(material)));
@ -82,7 +84,7 @@ namespace PolyVox
m_meshCurrent->addTriangleCubic(v0,v1,v2);
m_meshCurrent->addTriangleCubic(v1,v3,v2);
}
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y+1,z), m_volData->getVoxelAt(x,y,z), material))
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material))
{
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast<float>(material)));
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast<float>(material)));
@ -93,7 +95,7 @@ namespace PolyVox
m_meshCurrent->addTriangleCubic(v1,v2,v3);
}
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y,z+1), material))
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), material))
{
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast<float>(material)));
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast<float>(material)));
@ -103,7 +105,7 @@ namespace PolyVox
m_meshCurrent->addTriangleCubic(v0,v2,v1);
m_meshCurrent->addTriangleCubic(v1,v2,v3);
}
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z+1), m_volData->getVoxelAt(x,y,z), material))
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material))
{
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast<float>(material)));
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast<float>(material)));

View File

@ -78,8 +78,6 @@ namespace PolyVox
*/
DefaultMarchingCubesController(void)
:m_tThreshold(((std::numeric_limits<DensityType>::min)() + (std::numeric_limits<DensityType>::max)()) / 2)
,m_eWrapMode(WrapModes::Border)
,m_tBorder(VoxelType(0))
{
}
@ -105,11 +103,6 @@ namespace PolyVox
return 1;
}
VoxelType getBorderValue(void)
{
return m_tBorder;
}
/**
* Returns the density value which was passed to the constructor.
*
@ -122,26 +115,13 @@ namespace PolyVox
return m_tThreshold;
}
WrapMode getWrapMode(void)
{
return m_eWrapMode;
}
void setThreshold(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
void setWrapMode(WrapMode eWrapMode, VoxelType tBorder = VoxelType(0))
{
m_eWrapMode = eWrapMode;
m_tBorder = tBorder;
}
private:
DensityType m_tThreshold;
WrapMode m_eWrapMode;
VoxelType m_tBorder;
};
}

View File

@ -155,13 +155,11 @@ namespace PolyVox
{
// Default to a threshold value halfway between the min and max possible values.
m_tThreshold = (Density<Type>::getMinDensity() + Density<Type>::getMaxDensity()) / 2;
m_eWrapMode = WrapModes::Border;
}
DefaultMarchingCubesController(DensityType tThreshold)
{
m_tThreshold = tThreshold;
m_eWrapMode = WrapModes::Border;
}
DensityType convertToDensity(Density<Type> voxel)
@ -174,35 +172,18 @@ namespace PolyVox
return 1;
}
Density<Type> getBorderValue(void)
{
return m_tBorder;
}
DensityType getThreshold(void)
{
return m_tThreshold;
}
WrapMode getWrapMode(void)
{
return m_eWrapMode;
}
void setThreshold(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
void setWrapMode(WrapMode eWrapMode)
{
m_eWrapMode = eWrapMode;
}
private:
DensityType m_tThreshold;
WrapMode m_eWrapMode;
Density<Type> m_tBorder;
};
}

View File

@ -0,0 +1,20 @@
/*
* This file provides the default compiler capabilities for for Visual Studio.
* On other compilers CMake will detect which features are available and create
* a file like this.
*
* To Enable these features in Visual Studio, define the variables in this file.
*/
#ifndef __PolyVox_CompilerCapabilities_H__
#define __PolyVox_CompilerCapabilities_H__
//#undef HAS_CXX11_CONSTEXPR
#define HAS_CXX11_STATIC_ASSERT
#define HAS_CXX11_CSTDINT_H
#define HAS_CXX11_SHARED_PTR
#endif

View File

@ -0,0 +1,17 @@
/*
* This file is an input file for the CMake build system. It is processed and
* placed in the build directory by CMake.
*/
#ifndef __PolyVox_CompilerCapabilities_H__
#define __PolyVox_CompilerCapabilities_H__
#cmakedefine HAS_CXX11_CONSTEXPR
#cmakedefine HAS_CXX11_STATIC_ASSERT
#cmakedefine HAS_CXX11_CSTDINT_H
#cmakedefine HAS_CXX11_SHARED_PTR
#endif

View File

@ -0,0 +1,124 @@
/*******************************************************************************
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_ErrorHandling_H__
#define __PolyVox_ErrorHandling_H__
#include <cstdlib> //For std::exit
#include <iostream> //For std::cerr
#include <stdexcept>
#define POLYVOX_ASSERTS_ENABLED
#define POLYVOX_THROW_ENABLED
#if defined(_MSC_VER)
#define POLYVOX_HALT() __debugbreak()
#else
#define POLYVOX_HALT() std::exit(EXIT_FAILURE)
#endif
#define POLYVOX_UNUSED(x) do { (void)sizeof(x); } while(0)
/*
* Assertions
* ----------
* The code below implements a custom assert function called POLYVOX_ASSERT which has a number of advantages compared
* to the standard C/C++ assert(). It is inspired by http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/
* which provides code under the MIT license.
*/
#ifdef POLYVOX_ASSERTS_ENABLED
#define POLYVOX_ASSERT(condition, message) \
do \
{ \
if (!(condition)) \
{ \
std::cerr << std::endl << std::endl; \
std::cerr << " PolyVox Assertion Failed!" << std::endl; \
std::cerr << " =========================" << std::endl; \
std::cerr << " Condition: " << #condition << std::endl; \
std::cerr << " Message: " << (message) << std::endl; \
std::cerr << " Location: " << "Line " << __LINE__ << " of " << __FILE__ << std::endl << std::endl; \
POLYVOX_HALT(); \
} \
} while(0)
#else
#define POLYVOX_ASSERT(condition, message) \
do { POLYVOX_UNUSED(condition); POLYVOX_UNUSED(message); } while(0)
#endif
/*
* Static Assertions
* -----------------
* These map to C+11 static_assert if available or our own implentation otherwise.
*/
#if defined(HAS_CXX11_STATIC_ASSERT)
//In this case we can just use static_assert
#define POLYVOX_STATIC_ASSERT static_assert
#else
namespace PolyVox
{
// empty default template
template <bool b>
struct StaticAssert {};
// template specialized on true
template <>
struct StaticAssert<true>
{
// If the static assertion is failing then this function won't exist. It will then
// appear in the error message which gives a clue to the user about what is wrong.
static void ERROR_The_static_assertion_has_failed() {}
};
}
#define POLYVOX_STATIC_ASSERT(condition, message) StaticAssert<(condition)>::ERROR_The_static_assertion_has_failed();
#endif
/*
* Exceptions
* ----------
* ...
*/
#ifdef POLYVOX_THROW_ENABLED
#define POLYVOX_THROW(type, message) throw type((message))
#else
namespace PolyVox
{
typedef void (*ThrowHandler)(std::exception& e, const char* file, int line);
ThrowHandler getThrowHandler();
void setThrowHandler(ThrowHandler newHandler);
}
#define POLYVOX_THROW(type, message) \
type except = (type)((message)); \
getThrowHandler()((except), __FILE__, __LINE__)
#endif
#endif //__PolyVox_ErrorHandling_H__

View File

@ -24,6 +24,8 @@ freely, subject to the following restrictions:
#ifndef __PolyVox_TypeDef_H__
#define __PolyVox_TypeDef_H__
#include "PolyVoxCore/Impl/CompilerCapabilities.h"
//Definitions needed to make library functions accessable
// See http://gcc.gnu.org/wiki/Visibility for more info.
#if defined _WIN32 || defined __CYGWIN__
@ -44,6 +46,13 @@ freely, subject to the following restrictions:
#endif
#endif
#if defined SWIG
//Do nothing in this case
#else
#undef POLYVOX_DEPRECATED
#define POLYVOX_DEPRECATED //Define it to nothing to avoid warnings
#endif
// Now we use the generic helper definitions above to define POLYVOX_API and POLYVOX_LOCAL.
// POLYVOX_API is used for the public API symbols. It either imports or exports (or does nothing for static build)
// POLYVOX_LOCAL is used for non-api symbols.
@ -65,9 +74,6 @@ freely, subject to the following restrictions:
//To support old (pre-vc2010) Microsoft compilers we use boost to replace the
//std::shared_ptr and potentially other C++0x features. To use this capability you
//will need to make sure you have boost installed on your system.
#include <boost/smart_ptr.hpp>
#define polyvox_shared_ptr boost::shared_ptr
#include <boost/function.hpp>
#define polyvox_function boost::function
@ -75,13 +81,26 @@ freely, subject to the following restrictions:
#define polyvox_bind boost::bind
#define polyvox_placeholder_1 _1
#define polyvox_placeholder_2 _2
#else
//We have a decent compiler - use real C++0x features
#include <functional>
#define polyvox_function std::function
#define polyvox_bind std::bind
#define polyvox_placeholder_1 std::placeholders::_1
#define polyvox_placeholder_2 std::placeholders::_2
#endif
#include <boost/static_assert.hpp>
#define static_assert(condition, message) BOOST_STATIC_ASSERT(condition)
#if defined(HAS_CXX11_CONSTEXPR)
#define polyvox_constexpr_const constexpr //constexpr which falls back to const
#define polyvox_constexpr constexpr //constexpr which falls back to nothing
#else
#define polyvox_constexpr_const const
#define polyvox_constexpr
#endif
//As long as we're requiring boost, we'll use it to compensate
//for the missing cstdint header too.
#if defined(HAS_CXX11_CSTDINT_H)
#include <cstdint>
#else
#include <boost/cstdint.hpp>
using boost::int8_t;
using boost::int16_t;
@ -89,17 +108,14 @@ freely, subject to the following restrictions:
using boost::uint8_t;
using boost::uint16_t;
using boost::uint32_t;
#else
//We have a decent compiler - use real C++0x features
#include <cstdint>
#include <functional>
#endif
#if defined(HAS_CXX11_SHARED_PTR)
#include <memory>
#define polyvox_shared_ptr std::shared_ptr
#define polyvox_function std::function
#define polyvox_bind std::bind
#define polyvox_placeholder_1 std::placeholders::_1
#define polyvox_placeholder_2 std::placeholders::_2
//#define static_assert static_assert //we can use this
#else
#include <boost/smart_ptr.hpp>
#define polyvox_shared_ptr boost::shared_ptr
#endif
#endif

View File

@ -21,10 +21,12 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#define BORDER_LOW(x) ((( x >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != x)
#define BORDER_HIGH(x) ((( (x+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (x+1))
//#define BORDER_LOW(x) (( x % mVolume->m_uBlockSideLength) != 0)
//#define BORDER_HIGH(x) (( x % mVolume->m_uBlockSideLength) != mVolume->m_uBlockSideLength - 1)
#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
namespace PolyVox
{
@ -280,7 +282,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -290,7 +292,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength);
}
@ -300,7 +302,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -310,7 +312,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -320,7 +322,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) )
{
return *(mCurrentVoxel - 1);
}
@ -330,7 +332,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -340,7 +342,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -350,7 +352,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength);
}
@ -360,7 +362,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -372,7 +374,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -382,7 +384,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength);
}
@ -392,7 +394,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -402,7 +404,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -422,7 +424,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -432,7 +434,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -442,7 +444,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength);
}
@ -452,7 +454,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -464,7 +466,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -474,7 +476,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength);
}
@ -484,7 +486,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -494,7 +496,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -504,7 +506,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) )
{
return *(mCurrentVoxel + 1);
}
@ -514,7 +516,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -524,7 +526,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -534,7 +536,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength);
}
@ -544,7 +546,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -552,5 +554,9 @@ namespace PolyVox
}
}
#undef BORDER_LOW
#undef BORDER_HIGH
#undef CAN_GO_NEG_X
#undef CAN_GO_POS_X
#undef CAN_GO_NEG_Y
#undef CAN_GO_POS_Y
#undef CAN_GO_NEG_Z
#undef CAN_GO_POS_Z

View File

@ -28,6 +28,7 @@ freely, subject to the following restrictions:
#include "Impl/TypeDef.h"
#include "PolyVoxCore/Array.h"
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/DefaultMarchingCubesController.h"
@ -37,7 +38,13 @@ namespace PolyVox
class MarchingCubesSurfaceExtractor
{
public:
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* result, Controller controller = Controller());
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
#if defined(_MSC_VER)
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), Controller controller = Controller());
#else
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), Controller controller = Controller());
#endif
void execute();
@ -48,7 +55,7 @@ namespace PolyVox
//Compute the cell bitmask for a given cell.
template<bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail>
void computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask);
void computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask, uint32_t uXRegSpace, uint32_t uYRegSpace);
//Use the cell bitmasks to generate all the vertices needed for that slice
void generateVerticesForSlice(const Array2DUint8& pCurrentBitmask,
@ -182,16 +189,6 @@ namespace PolyVox
VolumeType* m_volData;
typename VolumeType::Sampler m_sampVolume;
//Holds a position in volume space.
int32_t iXVolSpace;
int32_t iYVolSpace;
int32_t iZVolSpace;
//Holds a position in region space.
uint32_t uXRegSpace;
uint32_t uYRegSpace;
uint32_t uZRegSpace;
//Used to return the number of cells in a slice which contain triangles.
uint32_t m_uNoOfOccupiedCells;
@ -207,11 +204,11 @@ namespace PolyVox
Region m_regSlicePrevious;
Region m_regSliceCurrent;
//Our threshold value
typename Controller::DensityType m_tThreshold;
//Used to convert arbitrary voxel types in densities and materials.
Controller m_controller;
//Our threshold value
typename Controller::DensityType m_tThreshold;
};
}

View File

@ -24,20 +24,19 @@ freely, subject to the following restrictions:
namespace PolyVox
{
template<typename VolumeType, typename Controller>
MarchingCubesSurfaceExtractor<VolumeType, Controller>::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* result, Controller controller)
MarchingCubesSurfaceExtractor<VolumeType, Controller>::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller)
:m_volData(volData)
,m_sampVolume(volData)
,m_meshCurrent(result)
,m_regSizeInVoxels(region)
,m_controller(controller)
,m_tThreshold(m_controller.getThreshold())
{
//m_regSizeInVoxels.cropTo(m_volData->getEnclosingRegion());
m_regSizeInCells = m_regSizeInVoxels;
m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1));
m_controller = controller;
m_tThreshold = m_controller.getThreshold();
m_sampVolume.setWrapMode(m_controller.getWrapMode(), m_controller.getBorderValue());
m_sampVolume.setWrapMode(eWrapMode, tBorderValue);
}
template<typename VolumeType, typename Controller>
@ -45,9 +44,9 @@ namespace PolyVox
{
m_meshCurrent->clear();
uint32_t uArrayWidth = m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 1;
uint32_t uArrayHeight = m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 1;
uint32_t arraySizes[2]= {uArrayWidth, uArrayHeight}; // Array dimensions
const uint32_t uArrayWidth = m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 1;
const uint32_t uArrayHeight = m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 1;
const uint32_t arraySizes[2]= {uArrayWidth, uArrayHeight}; // Array dimensions
//For edge indices
Array2DInt32 m_pPreviousVertexIndicesX(arraySizes);
@ -138,18 +137,18 @@ namespace PolyVox
const int32_t iMaxXVolSpace = m_regSliceCurrent.getUpperCorner().getX();
const int32_t iMaxYVolSpace = m_regSliceCurrent.getUpperCorner().getY();
iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ();
uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ();
const int32_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ();
//Process the lower left corner
iYVolSpace = m_regSliceCurrent.getLowerCorner().getY();
iXVolSpace = m_regSliceCurrent.getLowerCorner().getX();
int32_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY();
int32_t iXVolSpace = m_regSliceCurrent.getLowerCorner().getX();
uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY();
uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY();
m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace);
computeBitmaskForCell<false, false, isPrevZAvail>(pPreviousBitmask, pCurrentBitmask);
computeBitmaskForCell<false, false, isPrevZAvail>(pPreviousBitmask, pCurrentBitmask, uXRegSpace, uYRegSpace);
//Process the edge where x is minimal.
iXVolSpace = m_regSliceCurrent.getLowerCorner().getX();
@ -161,7 +160,7 @@ namespace PolyVox
m_sampVolume.movePositiveY();
computeBitmaskForCell<false, true, isPrevZAvail>(pPreviousBitmask, pCurrentBitmask);
computeBitmaskForCell<false, true, isPrevZAvail>(pPreviousBitmask, pCurrentBitmask, uXRegSpace, uYRegSpace);
}
//Process the edge where y is minimal.
@ -174,7 +173,7 @@ namespace PolyVox
m_sampVolume.movePositiveX();
computeBitmaskForCell<true, false, isPrevZAvail>(pPreviousBitmask, pCurrentBitmask);
computeBitmaskForCell<true, false, isPrevZAvail>(pPreviousBitmask, pCurrentBitmask, uXRegSpace, uYRegSpace);
}
//Process all remaining elemnents of the slice. In this case, previous x and y values are always available
@ -188,7 +187,7 @@ namespace PolyVox
m_sampVolume.movePositiveX();
computeBitmaskForCell<true, true, isPrevZAvail>(pPreviousBitmask, pCurrentBitmask);
computeBitmaskForCell<true, true, isPrevZAvail>(pPreviousBitmask, pCurrentBitmask, uXRegSpace, uYRegSpace);
}
}
@ -197,7 +196,7 @@ namespace PolyVox
template<typename VolumeType, typename Controller>
template<bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail>
void MarchingCubesSurfaceExtractor<VolumeType, Controller>::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask)
void MarchingCubesSurfaceExtractor<VolumeType, Controller>::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask, uint32_t uXRegSpace, uint32_t uYRegSpace)
{
uint8_t iCubeIndex = 0;
@ -387,7 +386,7 @@ namespace PolyVox
}
//Save the bitmask
pCurrentBitmask[uXRegSpace][iYVolSpace- m_regSizeInVoxels.getLowerCorner().getY()] = iCubeIndex;
pCurrentBitmask[uXRegSpace][uYRegSpace] = iCubeIndex;
if(edgeTable[iCubeIndex] != 0)
{
@ -401,7 +400,7 @@ namespace PolyVox
Array2DInt32& m_pCurrentVertexIndicesY,
Array2DInt32& m_pCurrentVertexIndicesZ)
{
int32_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ();
const int32_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ();
//Iterate over each cell in the region
for(int32_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY(); iYVolSpace <= m_regSliceCurrent.getUpperCorner().getY(); iYVolSpace++)
@ -414,7 +413,7 @@ namespace PolyVox
const uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = pCurrentBitmask[uXRegSpace][uYRegSpace];
const uint8_t iCubeIndex = pCurrentBitmask[uXRegSpace][uYRegSpace];
/* Cube is entirely in/out of the surface */
if (edgeTable[iCubeIndex] == 0)
@ -427,16 +426,16 @@ namespace PolyVox
m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace);
const typename VolumeType::VoxelType v000 = m_sampVolume.getVoxel();
const Vector3DFloat n000 = computeSobelGradient(m_sampVolume);
const Vector3DFloat n000 = computeCentralDifferenceGradient(m_sampVolume);
/* Find the vertices where the surface intersects the cube */
if (edgeTable[iCubeIndex] & 1)
{
m_sampVolume.movePositiveX();
const typename VolumeType::VoxelType v100 = m_sampVolume.getVoxel();
const Vector3DFloat n100 = computeSobelGradient(m_sampVolume);
const Vector3DFloat n100 = computeCentralDifferenceGradient(m_sampVolume);
float fInterp = static_cast<float>(m_tThreshold - m_controller.convertToDensity(v000)) / static_cast<float>(m_controller.convertToDensity(v100) - m_controller.convertToDensity(v000));
const float fInterp = static_cast<float>(m_tThreshold - m_controller.convertToDensity(v000)) / static_cast<float>(m_controller.convertToDensity(v100) - m_controller.convertToDensity(v000));
const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()) + fInterp, static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()), static_cast<float>(iZVolSpace - m_regSizeInCells.getLowerCorner().getZ()));
@ -446,13 +445,13 @@ namespace PolyVox
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of
//material IDs does not make sense). We take the largest, so that if we are working on a material-only
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
typename Controller::MaterialType uMaterial100 = m_controller.convertToMaterial(v100);
//typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial100);
typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial100, fInterp);
const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
const typename Controller::MaterialType uMaterial100 = m_controller.convertToMaterial(v100);
//const typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial100);
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial100, fInterp);
PositionMaterialNormal<typename Controller::MaterialType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
const PositionMaterialNormal<typename Controller::MaterialType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex;
m_sampVolume.moveNegativeX();
@ -461,9 +460,9 @@ namespace PolyVox
{
m_sampVolume.movePositiveY();
const typename VolumeType::VoxelType v010 = m_sampVolume.getVoxel();
const Vector3DFloat n010 = computeSobelGradient(m_sampVolume);
const Vector3DFloat n010 = computeCentralDifferenceGradient(m_sampVolume);
float fInterp = static_cast<float>(m_tThreshold - m_controller.convertToDensity(v000)) / static_cast<float>(m_controller.convertToDensity(v010) - m_controller.convertToDensity(v000));
const float fInterp = static_cast<float>(m_tThreshold - m_controller.convertToDensity(v000)) / static_cast<float>(m_controller.convertToDensity(v010) - m_controller.convertToDensity(v000));
const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()), static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()) + fInterp, static_cast<float>(iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ()));
@ -473,10 +472,10 @@ namespace PolyVox
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of
//material IDs does not make sense). We take the largest, so that if we are working on a material-only
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
typename Controller::MaterialType uMaterial010 = m_controller.convertToMaterial(v010);
//typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial010);
typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial010, fInterp);
const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
const typename Controller::MaterialType uMaterial010 = m_controller.convertToMaterial(v010);
//const typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial010);
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial010, fInterp);
PositionMaterialNormal<typename Controller::MaterialType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
@ -488,9 +487,9 @@ namespace PolyVox
{
m_sampVolume.movePositiveZ();
const typename VolumeType::VoxelType v001 = m_sampVolume.getVoxel();
const Vector3DFloat n001 = computeSobelGradient(m_sampVolume);
const Vector3DFloat n001 = computeCentralDifferenceGradient(m_sampVolume);
float fInterp = static_cast<float>(m_tThreshold - m_controller.convertToDensity(v000)) / static_cast<float>(m_controller.convertToDensity(v001) - m_controller.convertToDensity(v000));
const float fInterp = static_cast<float>(m_tThreshold - m_controller.convertToDensity(v000)) / static_cast<float>(m_controller.convertToDensity(v001) - m_controller.convertToDensity(v000));
const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()), static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()), static_cast<float>(iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ()) + fInterp);
@ -500,13 +499,13 @@ namespace PolyVox
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of
//material IDs does not make sense). We take the largest, so that if we are working on a material-only
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
typename Controller::MaterialType uMaterial001 = m_controller.convertToMaterial(v001);
//typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial001);
typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial001, fInterp);
const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
const typename Controller::MaterialType uMaterial001 = m_controller.convertToMaterial(v001);
//const typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial001);
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial001, fInterp);
PositionMaterialNormal<typename Controller::MaterialType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
const PositionMaterialNormal<typename Controller::MaterialType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex;
m_sampVolume.moveNegativeZ();
@ -529,11 +528,12 @@ namespace PolyVox
indlist[i] = -1;
}
const int32_t iZVolSpace = m_regSlicePrevious.getLowerCorner().getZ();
for(int32_t iYVolSpace = m_regSlicePrevious.getLowerCorner().getY(); iYVolSpace <= m_regSizeInCells.getUpperCorner().getY(); iYVolSpace++)
{
for(int32_t iXVolSpace = m_regSlicePrevious.getLowerCorner().getX(); iXVolSpace <= m_regSizeInCells.getUpperCorner().getX(); iXVolSpace++)
{
int32_t iZVolSpace = m_regSlicePrevious.getLowerCorner().getZ();
m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace);
//Current position
@ -541,7 +541,7 @@ namespace PolyVox
const uint32_t uYRegSpace = m_sampVolume.getPosition().getY() - m_regSizeInVoxels.getLowerCorner().getY();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = pPreviousBitmask[uXRegSpace][uYRegSpace];
const uint8_t iCubeIndex = pPreviousBitmask[uXRegSpace][uYRegSpace];
/* Cube is entirely in/out of the surface */
if (edgeTable[iCubeIndex] == 0)
@ -613,9 +613,9 @@ namespace PolyVox
for (int i=0;triTable[iCubeIndex][i]!=-1;i+=3)
{
int32_t ind0 = indlist[triTable[iCubeIndex][i ]];
int32_t ind1 = indlist[triTable[iCubeIndex][i+1]];
int32_t ind2 = indlist[triTable[iCubeIndex][i+2]];
const int32_t ind0 = indlist[triTable[iCubeIndex][i ]];
const int32_t ind1 = indlist[triTable[iCubeIndex][i+1]];
const int32_t ind2 = indlist[triTable[iCubeIndex][i+2]];
if((ind0 != -1) && (ind1 != -1) && (ind2 != -1))
{

View File

@ -119,13 +119,11 @@ namespace PolyVox
{
// 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;
m_eWrapMode = WrapModes::Border;
}
DefaultMarchingCubesController(DensityType tThreshold)
{
m_tThreshold = tThreshold;
m_eWrapMode = WrapModes::Border;
}
DensityType convertToDensity(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> voxel)
@ -138,35 +136,18 @@ namespace PolyVox
return voxel.getMaterial();
}
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> getBorderValue(void)
{
return m_tBorder;
}
DensityType getThreshold(void)
{
return m_tThreshold;
}
WrapMode getWrapMode(void)
{
return m_eWrapMode;
}
void setThreshold(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
void setWrapMode(WrapMode eWrapMode)
{
m_eWrapMode = eWrapMode;
}
private:
DensityType m_tThreshold;
WrapMode m_eWrapMode;
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> m_tBorder;
};
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;

View File

@ -31,7 +31,7 @@ namespace PolyVox
RawVolume<VoxelType>::RawVolume(const Region& regValid)
:BaseVolume<VoxelType>(regValid)
{
setBorderValue(VoxelType());
this->setBorderValue(VoxelType());
//Create a volume of the right size.
initialise(regValid);

View File

@ -21,10 +21,12 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#define BORDER_LOW(x) ((( x >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != x)
#define BORDER_HIGH(x) ((( (x+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (x+1))
//#define BORDER_LOW(x) (( x % this->mVolume->m_uBlockSideLength) != 0)
//#define BORDER_HIGH(x) (( x % this->mVolume->m_uBlockSideLength) != this->mVolume->m_uBlockSideLength - 1)
#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0))
#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
namespace PolyVox
{
@ -299,7 +301,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -309,7 +311,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength);
}
@ -319,7 +321,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -329,7 +331,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -339,7 +341,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) )
{
return *(mCurrentVoxel - 1);
}
@ -349,7 +351,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -359,7 +361,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -369,7 +371,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength);
}
@ -379,7 +381,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -391,7 +393,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -401,7 +403,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength);
}
@ -411,7 +413,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -421,7 +423,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -441,7 +443,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -451,7 +453,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -461,7 +463,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength);
}
@ -471,7 +473,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -483,7 +485,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -493,7 +495,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength);
}
@ -503,7 +505,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -513,7 +515,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -523,7 +525,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) )
{
return *(mCurrentVoxel + 1);
}
@ -533,7 +535,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -543,7 +545,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -553,7 +555,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
{
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength);
}
@ -563,7 +565,7 @@ namespace PolyVox
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
{
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
{
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
}
@ -571,5 +573,9 @@ namespace PolyVox
}
}
#undef BORDER_LOW
#undef BORDER_HIGH
#undef CAN_GO_NEG_X
#undef CAN_GO_POS_X
#undef CAN_GO_NEG_Y
#undef CAN_GO_POS_Y
#undef CAN_GO_NEG_Z
#undef CAN_GO_POS_Z

View File

@ -21,6 +21,8 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#include <cassert>
namespace PolyVox
{
template <typename VertexType>

View File

@ -24,11 +24,11 @@ freely, subject to the following restrictions:
#ifndef __PolyVox_Vector_H__
#define __PolyVox_Vector_H__
#include "Impl/ErrorHandling.h"
#include "Impl/TypeDef.h"
#include "PolyVoxForwardDeclarations.h"
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>

View File

@ -53,9 +53,7 @@ namespace PolyVox
template <uint32_t Size,typename StorageType, typename OperationType>
Vector<Size,StorageType,OperationType>::Vector(StorageType x, StorageType y)
{
#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
//static_assert(Size == 2, "This constructor should only be used for vectors with two elements.");
#endif
POLYVOX_STATIC_ASSERT(Size == 2, "This constructor should only be used for vectors with two elements.");
m_tElements[0] = x;
m_tElements[1] = y;
@ -70,9 +68,7 @@ namespace PolyVox
template <uint32_t Size,typename StorageType, typename OperationType>
Vector<Size,StorageType,OperationType>::Vector(StorageType x, StorageType y, StorageType z)
{
#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
//static_assert(Size == 3, "This constructor should only be used for vectors with three elements.");
#endif
POLYVOX_STATIC_ASSERT(Size == 3, "This constructor should only be used for vectors with three elements.");
m_tElements[0] = x;
m_tElements[1] = y;
@ -90,9 +86,7 @@ namespace PolyVox
template <uint32_t Size,typename StorageType, typename OperationType>
Vector<Size,StorageType,OperationType>::Vector(StorageType x, StorageType y, StorageType z, StorageType w)
{
#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
//static_assert(Size == 4, "This constructor should only be used for vectors with four elements.");
#endif
POLYVOX_STATIC_ASSERT(Size == 4, "This constructor should only be used for vectors with four elements.");
m_tElements[0] = x;
m_tElements[1] = y;
@ -135,14 +129,14 @@ namespace PolyVox
template <uint32_t Size, typename StorageType, typename OperationType>
Vector<Size, StorageType, OperationType>::~Vector(void)
{
// We put the static_asserts in the destructor because there is one one of these,
// We put the static asserts in the destructor because there is one one of these,
// where as there are multiple constructors.
// Force a vector to have a length greater than one. There is no need for a
// vector with one element, and supporting this would cause confusion over the
// behaviour of the constructor taking a single value, as this fills all elements
// to that value rather than just the first one.
//static_assert(Size > 1, "Vector must have a length greater than one.");
POLYVOX_STATIC_ASSERT(Size > 1, "Vector must have a length greater than one.");
}
/**
@ -420,7 +414,7 @@ namespace PolyVox
template <uint32_t Size, typename StorageType, typename OperationType>
inline StorageType Vector<Size, StorageType, OperationType>::getElement(uint32_t index) const
{
assert(index < Size);
POLYVOX_ASSERT(index < Size, "Attempted to access invalid vector element.");
return m_tElements[index];
}
@ -448,9 +442,7 @@ namespace PolyVox
template <uint32_t Size, typename StorageType, typename OperationType>
inline StorageType Vector<Size, StorageType, OperationType>::getZ(void) const
{
#ifndef SWIGPYTHON // SWIG instantiates all getters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
//static_assert(Size >= 3, "You can only get the 'z' component from a vector with at least three elements.");
#endif
POLYVOX_STATIC_ASSERT(Size >= 3, "You can only get the 'z' component from a vector with at least three elements.");
return m_tElements[2];
}
@ -461,9 +453,7 @@ namespace PolyVox
template <uint32_t Size, typename StorageType, typename OperationType>
inline StorageType Vector<Size, StorageType, OperationType>::getW(void) const
{
#ifndef SWIGPYTHON // SWIG instantiates all getters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
//static_assert(Size >= 4, "You can only get the 'w' component from a vector with at least four elements.");
#endif
POLYVOX_STATIC_ASSERT(Size >= 4, "You can only get the 'w' component from a vector with at least four elements.");
return m_tElements[3];
}
@ -475,7 +465,7 @@ namespace PolyVox
template <uint32_t Size, typename StorageType, typename OperationType>
inline void Vector<Size, StorageType, OperationType>::setElement(uint32_t index, StorageType tValue)
{
assert(index < Size);
POLYVOX_ASSERT(index < Size, "Attempted to access invalid vector element.");
m_tElements[index] = tValue;
}
@ -501,9 +491,8 @@ namespace PolyVox
template <uint32_t Size,typename StorageType, typename OperationType>
inline void Vector<Size,StorageType,OperationType>::setElements(StorageType x, StorageType y, StorageType z)
{
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
//static_assert(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements.");
#endif
POLYVOX_STATIC_ASSERT(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements.");
m_tElements[0] = x;
m_tElements[1] = y;
m_tElements[2] = z;
@ -519,9 +508,8 @@ namespace PolyVox
template <uint32_t Size,typename StorageType, typename OperationType>
inline void Vector<Size,StorageType,OperationType>::setElements(StorageType x, StorageType y, StorageType z, StorageType w)
{
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
//static_assert(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements.");
#endif
POLYVOX_STATIC_ASSERT(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements.");
m_tElements[0] = x;
m_tElements[1] = y;
m_tElements[2] = z;
@ -552,9 +540,8 @@ namespace PolyVox
template <uint32_t Size, typename StorageType, typename OperationType>
inline void Vector<Size, StorageType, OperationType>::setZ(StorageType tZ)
{
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
//static_assert(Size >= 3, "You can only set the 'w' component from a vector with at least three elements.");
#endif
POLYVOX_STATIC_ASSERT(Size >= 3, "You can only set the 'w' component from a vector with at least three elements.");
m_tElements[2] = tZ;
}
@ -564,9 +551,8 @@ namespace PolyVox
template <uint32_t Size, typename StorageType, typename OperationType>
inline void Vector<Size, StorageType, OperationType>::setW(StorageType tW)
{
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
//static_assert(Size >= 4, "You can only set the 'w' component from a vector with at least four elements.");
#endif
POLYVOX_STATIC_ASSERT(Size >= 4, "You can only set the 'w' component from a vector with at least four elements.");
m_tElements[3] = tW;
}
@ -663,7 +649,7 @@ namespace PolyVox
{
// Standard float rules apply for divide-by-zero
m_tElements[ct] /= fLength;
assert(m_tElements[ct] == m_tElements[ct]); //Will assert if NAN
POLYVOX_ASSERT(m_tElements[ct] == m_tElements[ct], "Obtained NAN during vector normalisation. Perhaps the input vector was too short?");
}
}
}//namespace PolyVox

View File

@ -21,11 +21,9 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#include "PolyVoxCore/Impl/ErrorHandling.h"
#include "PolyVoxCore/Impl/Utility.h"
#include <cassert>
#include <stdexcept>
namespace PolyVox
{
//Note: this function only works for inputs which are a power of two and not zero
@ -33,17 +31,17 @@ namespace PolyVox
uint8_t logBase2(uint32_t uInput)
{
//Debug mode validation
assert(uInput != 0);
assert(isPowerOf2(uInput));
POLYVOX_ASSERT(uInput != 0, "Cannot compute the log of zero.");
POLYVOX_ASSERT(isPowerOf2(uInput), "Input must be a power of two in order to compute the log.");
//Release mode validation
if(uInput == 0)
{
//throw std::invalid_argument("Cannot compute the log of zero.");
POLYVOX_THROW(std::invalid_argument, "Cannot compute the log of zero.");
}
if(!isPowerOf2(uInput))
{
//throw std::invalid_argument("Input must be a power of two in order to compute the log.");
POLYVOX_THROW(std::invalid_argument, "Input must be a power of two in order to compute the log.");
}
uint32_t uResult = 0;

View File

@ -20,8 +20,6 @@
# 3. This notice may not be removed or altered from any source
# distribution.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(PolyVoxUtil)
#Projects source files
@ -42,7 +40,7 @@ SOURCE_GROUP("Sources" FILES ${UTIL_SRC_FILES})
SOURCE_GROUP("Headers" FILES ${UTIL_INC_FILES})
#Tell CMake the paths
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include)
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})

View File

@ -36,7 +36,7 @@ if(ENABLE_BINDINGS)
include(${SWIG_USE_FILE})
include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore)
include_directories(${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore)
link_directories(${PolyVoxCore_BINARY_DIR})
set(CMAKE_SWIG_FLAGS "")
@ -48,6 +48,11 @@ if(ENABLE_BINDINGS)
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")
swig_add_module(PolyVoxCoreCSharp csharp PolyVoxCore.i)
set(SWIG_MODULE_PolyVoxCoreCSharp_EXTRA_FLAGS "-dllimport;PolyVoxCoreCSharp") #This _should_ be inside UseSWIG.cmake - http://www.cmake.org/Bug/view.php?id=13814
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()

View File

@ -1,6 +1,7 @@
%module PolyVoxCore
#define POLYVOX_API
%include "PolyVoxCore/Impl/CompilerCapabilities.h"
%include "Impl/TypeDef.h"
#define __attribute__(x) //Silence DEPRECATED errors

View File

@ -2,6 +2,8 @@
%{
#include "Raycast.h"
#ifdef SWIGPYTHON
template<typename VolumeType>
class PyCallback
{
@ -43,11 +45,17 @@ PolyVox::RaycastResult raycastWithEndpointsPython(VolumeType* volData, const Pol
return PolyVox::raycastWithEndpoints(volData, v3dStart, v3dEnd, newCallback);
}
#endif
%}
%include "Raycast.h"
#ifdef SWIGPYTHON
template<typename VolumeType, typename Callback>
PolyVox::RaycastResult raycastWithEndpointsPython(VolumeType* volData, const PolyVox::Vector3DFloat& v3dStart, const PolyVox::Vector3DFloat& v3dEnd, PyObject *callback);
%template(raycastWithEndpointsSimpleVolumeuint8) raycastWithEndpointsPython<PolyVox::SimpleVolume<uint8_t>, PyCallback<PolyVox::SimpleVolume<uint8_t> > >;
#endif

View File

@ -34,13 +34,29 @@ PROPERTY(PolyVox::Vector, z, getZ, setZ)
STR()
};
%template(Vector3DFloat) PolyVox::Vector<3,float,float>;
%template(Vector3DDouble) PolyVox::Vector<3,double,double>;
%template(Vector3DInt8) PolyVox::Vector<3,int8_t,int32_t>;
%template(Vector3DUint8) PolyVox::Vector<3,uint8_t,int32_t>;
%template(Vector3DInt16) PolyVox::Vector<3,int16_t,int32_t>;
%template(Vector3DUint16) PolyVox::Vector<3,uint16_t,int32_t>;
%template(Vector3DInt32) PolyVox::Vector<3,int32_t,int32_t>;
%template(Vector3DUint32) PolyVox::Vector<3,uint32_t,int32_t>;
%feature("pythonprepend") PolyVox::Vector::operator< %{
import warnings
warnings.warn("deprecated", DeprecationWarning)
%}
//%csattributes PolyVox::Vector::operator< "[System.Obsolete(\"deprecated\")]"
%define VECTOR3(StorageType,OperationType,ReducedStorageType)
%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

@ -39,7 +39,7 @@ MACRO(CREATE_TEST headerfile sourcefile executablename)
SET_PROPERTY(TARGET ${executablename} PROPERTY FOLDER "Tests")
ENDMACRO(CREATE_TEST)
INCLUDE_DIRECTORIES(${PolyVox_SOURCE_DIR}/PolyVoxCore/include ${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/include ${PolyVox_SOURCE_DIR}/PolyVoxCore/include ${CMAKE_CURRENT_BINARY_DIR})
REMOVE_DEFINITIONS(-DQT_GUI_LIB) #Make sure the tests don't link to the QtGui
# Test Template. Copy and paste this template for consistant naming.

View File

@ -13,16 +13,16 @@ class TestSurfaceExtractor(unittest.TestCase):
def setUp(self):
#Create a small volume
r = PolyVoxCore.Region(PolyVoxCore.Vector3DInt32(0,0,0), PolyVoxCore.Vector3DInt32(31,31,31))
r = PolyVoxCore.Region(PolyVoxCore.Vector3Dint32_t(0,0,0), PolyVoxCore.Vector3Dint32_t(31,31,31))
self.vol = PolyVoxCore.SimpleVolumeuint8(r)
#Set one single voxel to have a reasonably high density
self.vol.setVoxelAt(PolyVoxCore.Vector3DInt32(5, 5, 5), 200)
self.vol.setVoxelAt(PolyVoxCore.Vector3Dint32_t(5, 5, 5), 200)
def test_hit_voxel(self):
self.assertEqual(PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(self.vol, PolyVoxCore.Vector3DFloat(0,0,0), PolyVoxCore.Vector3DFloat(31,31,31), test_functor), 1)
self.assertEqual(PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(self.vol, PolyVoxCore.Vector3Dfloat(0,0,0), PolyVoxCore.Vector3Dfloat(31,31,31), test_functor), 1)
def test_miss_voxel(self):
self.assertEqual(PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(self.vol, PolyVoxCore.Vector3DFloat(0,0,0), PolyVoxCore.Vector3DFloat(0,31,31), test_functor), 0)
self.assertEqual(PolyVoxCore.raycastWithEndpointsSimpleVolumeuint8(self.vol, PolyVoxCore.Vector3Dfloat(0,0,0), PolyVoxCore.Vector3Dfloat(0,31,31), test_functor), 0)
if __name__ == '__main__':
unittest.main()

View File

@ -59,16 +59,6 @@ public:
{
return 50.0f;
}
WrapMode getWrapMode(void)
{
return WrapModes::Border;
}
float getBorderValue(void)
{
return 0.0f;
}
};
// These 'writeDensityValueToVoxel' functions provide a unified interface for writting densities to primative and class voxel types.
@ -132,7 +122,7 @@ void testForType(SurfaceMesh<PositionMaterialNormal>& result)
DefaultMarchingCubesController<VoxelType> controller;
controller.setThreshold(50);
MarchingCubesSurfaceExtractor< SimpleVolume<VoxelType> > extractor(&volData, volData.getEnclosingRegion(), &result, controller);
MarchingCubesSurfaceExtractor< SimpleVolume<VoxelType> > extractor(&volData, volData.getEnclosingRegion(), &result, WrapModes::Border, 0, controller);
extractor.execute();
}
@ -156,7 +146,7 @@ void testCustomController(SurfaceMesh<PositionMaterialNormal>& result)
}
CustomMarchingCubesController controller;
MarchingCubesSurfaceExtractor< SimpleVolume<float>, CustomMarchingCubesController > extractor(&volData, volData.getEnclosingRegion(), &result, controller);
MarchingCubesSurfaceExtractor< SimpleVolume<float>, CustomMarchingCubesController > extractor(&volData, volData.getEnclosingRegion(), &result, WrapModes::Border, 0, controller);
extractor.execute();
}

View File

@ -10,10 +10,10 @@ class TestSurfaceExtractor(unittest.TestCase):
import PolyVoxCore
#Create a small volume
r = PolyVoxCore.Region(PolyVoxCore.Vector3DInt32(0,0,0), PolyVoxCore.Vector3DInt32(31,31,31))
r = PolyVoxCore.Region(PolyVoxCore.Vector3Dint32_t(0,0,0), PolyVoxCore.Vector3Dint32_t(31,31,31))
vol = PolyVoxCore.SimpleVolumeuint8(r)
#Set one single voxel to have a reasonably high density
vol.setVoxelAt(PolyVoxCore.Vector3DInt32(5, 5, 5), 200)
vol.setVoxelAt(PolyVoxCore.Vector3Dint32_t(5, 5, 5), 200)
self.mesh = PolyVoxCore.SurfaceMeshPositionMaterialNormal()
extractor = PolyVoxCore.MarchingCubesSurfaceExtractorSimpleVolumeuint8(vol, r, self.mesh)
extractor.execute()

View File

@ -321,33 +321,33 @@ void TestVolume::testSimpleVolumeDirectAccess()
void TestVolume::testSimpleVolumeSamplers()
{
/*int32_t result = 0;
int32_t result = 0;
QBENCHMARK
{
result = testSamplersWithWrapping(m_pSimpleVolume);
}
QCOMPARE(result, static_cast<int32_t>(-601818385)); //FXME - Wrong value?!*/
QCOMPARE(result, static_cast<int32_t>(-928601007));
}
void TestVolume::testLargeVolumeDirectAccess()
{
/*int32_t result = 0;
int32_t result = 0;
QBENCHMARK
{
result = testDirectAccessWithWrapping(m_pLargeVolume);
}
QCOMPARE(result, static_cast<int32_t>(-601818385)); //FXME - Wrong value?!*/
QCOMPARE(result, static_cast<int32_t>(-928601007));
}
void TestVolume::testLargeVolumeSamplers()
{
int32_t result = 0;
/*QBENCHMARK
QBENCHMARK
{
result = testSamplersWithWrapping(m_pLargeVolume);
}
QCOMPARE(result, static_cast<int32_t>(-601818385)); //FXME - Wrong value?!*/
QCOMPARE(result, static_cast<int32_t>(-928601007));
}
QTEST_MAIN(TestVolume)