Merge branch 'develop' of https://DavidWilliams@bitbucket.org/volumesoffun/polyvox.git into develop
This commit is contained in:
commit
9ec2ebd78c
@ -1,3 +1,52 @@
|
||||
Changes for PolyVox version 0.3
|
||||
===============================
|
||||
This release has focused on... (some introduction here).
|
||||
|
||||
LargeVolume
|
||||
-----------
|
||||
It is now possible to provide custom compressors for the data which is stored in a LargeVolume. Two compressor implementation are provided with PolyVox - RLECompressor which is suitable for cubic-style terrain, and MinizCompressor which uses the 'miniz' zlib implementation for smooth terrain or general purpose use. Users can provide their own implementation of the compressor interface if they wish.
|
||||
|
||||
Note that the setCompressionEnabled() functionality has been removed and a compressor must always be provided when constructing the volume. The ability to disable compression was of questionable benefit and was complicating the logic in the code. In practice it is still possible to mostly disable compression by setting the maximum number of uncompressed blocks to a high value by calling setMaxNumberOfUncompressedBlocks().
|
||||
|
||||
These changes regarding compression and paging have also affected the LargeVolume constructors(s). Please see the API docs to see how they look now.
|
||||
|
||||
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.
|
||||
|
||||
Within the Volume class the getVoxelAt() and setBorderValue() functions have been deprecated. You should now call getVoxel() (which does not perform range checking and will crash when out of range) or getVoxelWithWrapping() (which does perform bounds checks and implements the required wrapping). When you call getVoxelWithWrapping() you are able to specify the required wrap mode for that particular call. For a Sampler you can set the wrap mode once with setWrapMode() and it will persist until you set it again.
|
||||
|
||||
Various algorithms have also been updated to allow wrap modes to be specified when executing them.
|
||||
|
||||
Region class
|
||||
------------
|
||||
The Region class has been tidied up and enhanced with new functionality. It now contains functions for growing and shrinking regions, as well as 'accumulate()' functions which ensure the Region contains a given point. The concept of an invalid region has also been introduced - this is one whose lower corner is greater than it's upper corner.
|
||||
|
||||
Vector class
|
||||
------------
|
||||
The Vector class has been tidied up. Most notably it now makes use of an 'OperationType' which is used for internal calculations and some results. The documentation has also been updated.
|
||||
|
||||
Deprecated functionality
|
||||
------------------------
|
||||
Vector::operator<() has been deprecated. It was only present to allow Vectors to be used as the key to an std::map, but it makes more sense for this to be specified seperatly as a std::map comparison function. This is now done in the OpenGLExample (search for VectorCompare).
|
||||
|
||||
getVoxelAt() and setBorderValue() have been deprecated in the Volume class. See the section of this file on 'Volume wrap modes' for details.
|
||||
|
||||
Removed functionality
|
||||
--------------------
|
||||
Functionality deprecated for the previous release has now been removed. This includes:
|
||||
|
||||
- Region::getWidth() and related functions. You should now use Region::getWidthInVoxels() or Region::getWidthInCells.
|
||||
- The MeshDecimator. We don't have a direct replacement for this so you should consider an alternative such as downsampling the volume or using an external mesh processing library.
|
||||
- The SimpleInterface. This was primarily for the bindings, and we are making other efforts to get those working.
|
||||
- Serialisation. You should implement any required serialisation yourself.
|
||||
- This had a number of problems and was a little too high-level for PolyVox. You should implement change tracking yourself.
|
||||
|
||||
|
||||
Changes for PolyVox version 0.2
|
||||
===============================
|
||||
This is the first revision for which we have produced a changelog, as we are now trying to streamline our development and release process. Hence this changelog entry is not going to be as structured as we hope they will be in the future. We're writing it from memory, rather than having carefully kept track of all the relevant changes as we made them.
|
||||
|
@ -69,14 +69,20 @@ 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)
|
||||
IF(ENABLE_EXAMPLES AND QT_QTOPENGL_FOUND)
|
||||
ADD_SUBDIRECTORY(examples/common)
|
||||
ADD_SUBDIRECTORY(examples/Basic)
|
||||
ADD_SUBDIRECTORY(examples/Paging)
|
||||
ADD_SUBDIRECTORY(examples/OpenGL)
|
||||
ADD_SUBDIRECTORY(examples/SmoothLOD)
|
||||
ADD_SUBDIRECTORY(examples/Python)
|
||||
SET(BUILD_EXAMPLES ON)
|
||||
ELSE()
|
||||
SET(BUILD_EXAMPLES OFF)
|
||||
|
@ -1,3 +1,7 @@
|
||||
David Williams - Lead programmer.
|
||||
Matthew Williams - Linux port, build system, support and maintenance.
|
||||
Oliver Schneider - Very large Volumes
|
||||
|
||||
Acknowledgements
|
||||
----------------
|
||||
PolyVox uses the 'miniz' for data compression. 'miniz' is public domain software and does not affect the license of PolyVox or of code using PolyVox. More details here: http://code.google.com/p/miniz/
|
133
cmake/Modules/CheckCXX11Features.cmake
Normal file
133
cmake/Modules/CheckCXX11Features.cmake
Normal 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)
|
8
cmake/Modules/CheckCXX11Features/cxx11-test-__func__.cpp
Normal file
8
cmake/Modules/CheckCXX11Features/cxx11-test-__func__.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
int main(void)
|
||||
{
|
||||
if (!__func__)
|
||||
return 1;
|
||||
if (!(*__func__))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
12
cmake/Modules/CheckCXX11Features/cxx11-test-auto.cpp
Normal file
12
cmake/Modules/CheckCXX11Features/cxx11-test-auto.cpp
Normal 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;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
int main(void)
|
||||
{
|
||||
// must fail because there is no initializer
|
||||
auto i;
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
auto foo(int i) -> int {
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return foo(1);
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
19
cmake/Modules/CheckCXX11Features/cxx11-test-constexpr.cpp
Normal file
19
cmake/Modules/CheckCXX11Features/cxx11-test-constexpr.cpp
Normal 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;
|
||||
}
|
11
cmake/Modules/CheckCXX11Features/cxx11-test-cstdint.cpp
Normal file
11
cmake/Modules/CheckCXX11Features/cxx11-test-cstdint.cpp
Normal 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;
|
||||
}
|
10
cmake/Modules/CheckCXX11Features/cxx11-test-decltype.cpp
Normal file
10
cmake/Modules/CheckCXX11Features/cxx11-test-decltype.cpp
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
5
cmake/Modules/CheckCXX11Features/cxx11-test-lambda.cpp
Normal file
5
cmake/Modules/CheckCXX11Features/cxx11-test-lambda.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
int main()
|
||||
{
|
||||
int ret = 0;
|
||||
return ([&ret]() -> int { return ret; })();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
int main(void)
|
||||
{
|
||||
long long l;
|
||||
unsigned long long ul;
|
||||
|
||||
return ((sizeof(l) >= 8) && (sizeof(ul) >= 8)) ? 0 : 1;
|
||||
}
|
6
cmake/Modules/CheckCXX11Features/cxx11-test-nullptr.cpp
Normal file
6
cmake/Modules/CheckCXX11Features/cxx11-test-nullptr.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
int main(void)
|
||||
{
|
||||
void *v = nullptr;
|
||||
|
||||
return v ? 1 : 0;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
int main(void)
|
||||
{
|
||||
int i = nullptr;
|
||||
|
||||
return 1;
|
||||
}
|
26
cmake/Modules/CheckCXX11Features/cxx11-test-regex.cpp
Normal file
26
cmake/Modules/CheckCXX11Features/cxx11-test-regex.cpp
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
#include <memory>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::shared_ptr<int> test;
|
||||
return 0;
|
||||
}
|
@ -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;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
struct foo {
|
||||
int baz;
|
||||
double bar;
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return (sizeof(foo::bar) == 4) ? 0 : 1;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
int main(void)
|
||||
{
|
||||
static_assert(0 < 1, "your ordering of integers is screwed");
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
int main(void)
|
||||
{
|
||||
static_assert(1 < 0, "your ordering of integers is screwed");
|
||||
return 0;
|
||||
}
|
@ -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;
|
||||
}
|
@ -25,22 +25,16 @@ PROJECT(BasicExample)
|
||||
|
||||
#Projects source files
|
||||
SET(SRC_FILES
|
||||
glew/glew.cpp
|
||||
|
||||
main.cpp
|
||||
OpenGLWidget.cpp
|
||||
)
|
||||
)
|
||||
|
||||
#Projects headers files
|
||||
SET(INC_FILES
|
||||
glew/glew.h
|
||||
glew/glxew.h
|
||||
glew/wglew.h
|
||||
|
||||
OpenGLWidget.h
|
||||
)
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
add_definitions(-DGLEW_STATIC)
|
||||
|
||||
#"Sources" and "Headers" are the group names in Visual Studio.
|
||||
#They may have other uses too...
|
||||
@ -50,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)
|
||||
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
|
||||
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
|
||||
|
||||
#Build
|
||||
@ -58,7 +52,7 @@ ADD_EXECUTABLE(BasicExample ${SRC_FILES})
|
||||
IF(MSVC)
|
||||
SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127")
|
||||
ENDIF(MSVC)
|
||||
TARGET_LINK_LIBRARIES(BasicExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore)
|
||||
TARGET_LINK_LIBRARIES(BasicExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore)
|
||||
SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples")
|
||||
|
||||
#Install - Only install the example in Windows
|
||||
|
@ -25,7 +25,6 @@ PROJECT(OpenGLExample)
|
||||
|
||||
#Projects source files
|
||||
SET(SRC_FILES
|
||||
glew/glew.cpp
|
||||
main.cpp
|
||||
OpenGLImmediateModeSupport.cpp
|
||||
OpenGLSupport.cpp
|
||||
@ -36,17 +35,14 @@ SET(SRC_FILES
|
||||
|
||||
#Projects headers files
|
||||
SET(INC_FILES
|
||||
glew/glew.h
|
||||
glew/glxew.h
|
||||
glew/wglew.h
|
||||
OpenGLImmediateModeSupport.h
|
||||
OpenGLSupport.h
|
||||
OpenGLVertexBufferObjectSupport.h
|
||||
OpenGLWidget.h
|
||||
Shapes.h
|
||||
)
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
add_definitions(-DGLEW_STATIC)
|
||||
|
||||
#"Sources" and "Headers" are the group names in Visual Studio.
|
||||
#They may have other uses too...
|
||||
@ -56,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)
|
||||
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
|
||||
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
|
||||
|
||||
#Build
|
||||
@ -64,7 +60,7 @@ ADD_EXECUTABLE(OpenGLExample ${SRC_FILES})
|
||||
IF(MSVC)
|
||||
SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127")
|
||||
ENDIF(MSVC)
|
||||
TARGET_LINK_LIBRARIES(OpenGLExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore)
|
||||
TARGET_LINK_LIBRARIES(OpenGLExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore)
|
||||
SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples")
|
||||
|
||||
#Install - Only install the example in Windows
|
||||
|
@ -39,6 +39,22 @@ freely, subject to the following restrictions:
|
||||
|
||||
const int32_t g_uVolumeSideLength = 128;
|
||||
|
||||
struct Vector3DUint8Compare
|
||||
{
|
||||
bool operator() (const PolyVox::Vector3DUint8& a, const PolyVox::Vector3DUint8& b) const
|
||||
{
|
||||
const uint32_t size = 3;
|
||||
for(uint32_t ct = 0; ct < size; ++ct)
|
||||
{
|
||||
if (a.getElement(ct) < b.getElement(ct))
|
||||
return true;
|
||||
if (b.getElement(ct) < a.getElement(ct))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class OpenGLWidget : public QGLWidget
|
||||
{
|
||||
|
||||
@ -71,8 +87,8 @@ class OpenGLWidget : public QGLWidget
|
||||
PolyVox::LargeVolume<PolyVox::MaterialDensityPair44>* m_volData;
|
||||
|
||||
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
|
||||
std::map<PolyVox::Vector3DUint8, OpenGLSurfaceMesh> m_mapOpenGLSurfaceMeshes;
|
||||
std::map<PolyVox::Vector3DUint8, polyvox_shared_ptr<PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> > > m_mapSurfaceMeshes;
|
||||
std::map<PolyVox::Vector3DUint8, OpenGLSurfaceMesh, Vector3DUint8Compare> m_mapOpenGLSurfaceMeshes;
|
||||
std::map<PolyVox::Vector3DUint8, polyvox_shared_ptr<PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> >, Vector3DUint8Compare> m_mapSurfaceMeshes;
|
||||
|
||||
unsigned int m_uRegionSideLength;
|
||||
unsigned int m_uVolumeWidthInRegions;
|
||||
|
@ -1,73 +0,0 @@
|
||||
The OpenGL Extension Wrangler Library
|
||||
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
|
||||
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
|
||||
Copyright (C) 2002, Lev Povalahev
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* The name of the author may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Mesa 3-D graphics library
|
||||
Version: 7.0
|
||||
|
||||
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
Copyright (c) 2007 The Khronos Group Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and/or associated documentation files (the
|
||||
"Materials"), to deal in the Materials without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
permit persons to whom the Materials are furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Materials.
|
||||
|
||||
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -25,24 +25,18 @@ PROJECT(PagingExample)
|
||||
|
||||
#Projects source files
|
||||
SET(SRC_FILES
|
||||
glew/glew.cpp
|
||||
|
||||
main.cpp
|
||||
OpenGLWidget.cpp
|
||||
Perlin.cpp
|
||||
)
|
||||
)
|
||||
|
||||
#Projects headers files
|
||||
SET(INC_FILES
|
||||
glew/glew.h
|
||||
glew/glxew.h
|
||||
glew/wglew.h
|
||||
|
||||
OpenGLWidget.h
|
||||
Perlin.h
|
||||
)
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
add_definitions(-DGLEW_STATIC)
|
||||
|
||||
#"Sources" and "Headers" are the group names in Visual Studio.
|
||||
#They may have other uses too...
|
||||
@ -52,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)
|
||||
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
|
||||
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
|
||||
|
||||
#Build
|
||||
@ -60,7 +54,7 @@ ADD_EXECUTABLE(PagingExample ${SRC_FILES})
|
||||
IF(MSVC)
|
||||
SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127")
|
||||
ENDIF(MSVC)
|
||||
TARGET_LINK_LIBRARIES(PagingExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore)
|
||||
TARGET_LINK_LIBRARIES(PagingExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore)
|
||||
SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples")
|
||||
|
||||
#Install - Only install the example in Windows
|
||||
|
@ -1,73 +0,0 @@
|
||||
The OpenGL Extension Wrangler Library
|
||||
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
|
||||
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
|
||||
Copyright (C) 2002, Lev Povalahev
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* The name of the author may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Mesa 3-D graphics library
|
||||
Version: 7.0
|
||||
|
||||
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
Copyright (c) 2007 The Khronos Group Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and/or associated documentation files (the
|
||||
"Materials"), to deal in the Materials without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
permit persons to whom the Materials are furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Materials.
|
||||
|
||||
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -201,15 +201,15 @@ void load(const ConstVolumeProxy<MaterialDensityPair44>& volume, const PolyVox::
|
||||
{
|
||||
Perlin perlin(2,2,1,234);
|
||||
|
||||
for(int x = reg.getLowerCorner().getX(); x <= reg.getUpperCorner().getX(); x++)
|
||||
for(int x = reg.getLowerX(); x <= reg.getUpperX(); x++)
|
||||
{
|
||||
for(int y = reg.getLowerCorner().getY(); y <= reg.getUpperCorner().getY(); y++)
|
||||
for(int y = reg.getLowerY(); y <= reg.getUpperY(); y++)
|
||||
{
|
||||
float perlinVal = perlin.Get(x / static_cast<float>(255-1), y / static_cast<float>(255-1));
|
||||
perlinVal += 1.0f;
|
||||
perlinVal *= 0.5f;
|
||||
perlinVal *= 255;
|
||||
for(int z = reg.getLowerCorner().getZ(); z <= reg.getUpperCorner().getZ(); z++)
|
||||
for(int z = reg.getLowerZ(); z <= reg.getUpperZ(); z++)
|
||||
{
|
||||
MaterialDensityPair44 voxel;
|
||||
if(z < perlinVal)
|
||||
|
26
examples/Python/CMakeLists.txt
Normal file
26
examples/Python/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2010-2013 Matt Williams
|
||||
#
|
||||
# This software is provided 'as-is', without any express or implied
|
||||
# warranty. In no event will the authors be held liable for any damages
|
||||
# arising from the use of this software.
|
||||
#
|
||||
# Permission is granted to anyone to use this software for any purpose,
|
||||
# including commercial applications, and to alter it and redistribute it
|
||||
# freely, subject to the following restrictions:
|
||||
#
|
||||
# 1. The origin of this software must not be misrepresented; you must not
|
||||
# claim that you wrote the original software. If you use this software
|
||||
# in a product, an acknowledgment in the product documentation would be
|
||||
# appreciated but is not required.
|
||||
#
|
||||
# 2. Altered source versions must be plainly marked as such, and must not be
|
||||
# misrepresented as being the original software.
|
||||
#
|
||||
# 3. This notice may not be removed or altered from any source
|
||||
# distribution.
|
||||
|
||||
PROJECT(PythonExample)
|
||||
|
||||
SOURCE_GROUP("Sources" FILES PythonExample.py)
|
||||
|
||||
configure_file(PythonExample.py PythonExample.py COPYONLY)
|
257
examples/Python/PythonExample.py
Executable file
257
examples/Python/PythonExample.py
Executable file
@ -0,0 +1,257 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
################################################################################
|
||||
# Copyright (c) 2013 Matt Williams
|
||||
#
|
||||
# This software is provided 'as-is', without any express or implied
|
||||
# warranty. In no event will the authors be held liable for any damages
|
||||
# arising from the use of this software.
|
||||
#
|
||||
# Permission is granted to anyone to use this software for any purpose,
|
||||
# including commercial applications, and to alter it and redistribute it
|
||||
# freely, subject to the following restrictions:
|
||||
#
|
||||
# 1. The origin of this software must not be misrepresented; you must not
|
||||
# claim that you wrote the original software. If you use this software
|
||||
# in a product, an acknowledgment in the product documentation would be
|
||||
# appreciated but is not required.
|
||||
#
|
||||
# 2. Altered source versions must be plainly marked as such, and must not be
|
||||
# misrepresented as being the original software.
|
||||
#
|
||||
# 3. This notice may not be removed or altered from any source
|
||||
# distribution.
|
||||
################################################################################
|
||||
|
||||
import sys
|
||||
sys.path.append("../../library/bindings/") #This is just to point to the generated bindings
|
||||
|
||||
import PolyVoxCore as pv
|
||||
|
||||
#Create a 64x64x64 volume of integers
|
||||
r = pv.Region(pv.Vector3Dint32_t(0,0,0), pv.Vector3Dint32_t(63,63,63))
|
||||
vol = pv.SimpleVolumeuint8(r)
|
||||
|
||||
#Now fill the volume with our data (a sphere)
|
||||
v3dVolCenter = pv.Vector3Dint32_t(vol.getWidth() / 2, vol.getHeight() / 2, vol.getDepth() / 2)
|
||||
sphereRadius = 30
|
||||
#This three-level for loop iterates over every voxel in the volume
|
||||
for z in range(vol.getDepth()):
|
||||
for y in range(vol.getHeight()):
|
||||
for x in range(vol.getWidth()):
|
||||
#Store our current position as a vector...
|
||||
v3dCurrentPos = pv.Vector3Dint32_t(x,y,z)
|
||||
#And compute how far the current position is from the center of the volume
|
||||
fDistToCenter = (v3dCurrentPos - v3dVolCenter).length()
|
||||
|
||||
uVoxelValue = 0
|
||||
|
||||
#If the current voxel is less than 'radius' units from the center then we make it solid.
|
||||
if(fDistToCenter <= sphereRadius):
|
||||
#Our new voxel value
|
||||
uVoxelValue = 255
|
||||
|
||||
#Write the voxel value into the volume
|
||||
vol.setVoxelAt(x, y, z, uVoxelValue);
|
||||
|
||||
#Create a mesh, pass it to the extractor and generate the mesh
|
||||
mesh = pv.SurfaceMeshPositionMaterialNormal()
|
||||
extractor = pv.CubicSurfaceExtractorWithNormalsSimpleVolumeuint8(vol, r, mesh)
|
||||
extractor.execute()
|
||||
|
||||
#That's all of the PolyVox generation done, now to convert the output to something OpenGL can read efficiently
|
||||
|
||||
import numpy as np
|
||||
|
||||
indices = np.array(mesh.getIndices(), dtype='uint32') #Throw in the vertex indices into an array
|
||||
#The vertices and normals are placed in an interpolated array like [vvvnnn,vvvnnn,vvvnnn]
|
||||
vertices = np.array([[vertex.getPosition().getX(), vertex.getPosition().getY(), vertex.getPosition().getZ(),
|
||||
vertex.getNormal().getX(), vertex.getNormal().getY(), vertex.getNormal().getZ()]
|
||||
for vertex in mesh.getVertices()],
|
||||
dtype='f')
|
||||
|
||||
#Now that we have our data, everything else here is just OpenGL
|
||||
|
||||
import OpenGL
|
||||
|
||||
from OpenGL.GL import shaders
|
||||
from OpenGL.arrays import vbo
|
||||
from OpenGL.GL import glClear, glEnable, glDepthFunc, GLuint, glEnableVertexAttribArray, glVertexAttribPointer, glDisableVertexAttribArray, \
|
||||
glDrawElements, glGetUniformLocation, glUniformMatrix4fv, glDepthMask, glDepthRange, glGetString, glBindAttribLocation, \
|
||||
GL_COLOR_BUFFER_BIT, GL_TRIANGLES, GL_DEPTH_TEST, GL_LEQUAL, GL_FLOAT, \
|
||||
GL_DEPTH_BUFFER_BIT, GL_ELEMENT_ARRAY_BUFFER, GL_UNSIGNED_INT, GL_STATIC_DRAW, \
|
||||
GL_FALSE, GL_TRUE, GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, GL_CULL_FACE, \
|
||||
GL_VENDOR, GL_RENDERER, GL_VERSION, GL_SHADING_LANGUAGE_VERSION
|
||||
from OpenGL.raw.GL.ARB.vertex_array_object import glGenVertexArrays, glBindVertexArray
|
||||
|
||||
import pygame
|
||||
|
||||
from math import sin, cos, tan, radians
|
||||
|
||||
SCREEN_SIZE = (800, 800)
|
||||
|
||||
def run():
|
||||
#Start OpenGL and ask it for an OpenGL context
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock()
|
||||
screen = pygame.display.set_mode(SCREEN_SIZE, pygame.HWSURFACE|pygame.OPENGL|pygame.DOUBLEBUF)
|
||||
|
||||
#The first thing we do is print some OpenGL details and check that we have a good enough version
|
||||
print "OpenGL Implementation Details:"
|
||||
if glGetString(GL_VENDOR):
|
||||
print "\tGL_VENDOR:", glGetString(GL_VENDOR)
|
||||
if glGetString(GL_RENDERER):
|
||||
print "\tGL_RENDERER:", glGetString(GL_RENDERER)
|
||||
if glGetString(GL_VERSION):
|
||||
print "\tGL_VERSION:", glGetString(GL_VERSION)
|
||||
if glGetString(GL_SHADING_LANGUAGE_VERSION):
|
||||
print "\tGL_SHADING_LANGUAGE_VERSION:", glGetString(GL_SHADING_LANGUAGE_VERSION)
|
||||
|
||||
major_version = int(glGetString(GL_VERSION).split()[0].split('.')[0])
|
||||
minor_version = int(glGetString(GL_VERSION).split()[0].split('.')[1])
|
||||
if major_version < 3 or (major_version < 3 and minor_version < 0):
|
||||
print "OpenGL version must be at least 3.0 (found {0})".format(glGetString(GL_VERSION).split()[0])
|
||||
|
||||
#Now onto the OpenGL initialisation
|
||||
|
||||
#Set up depth culling
|
||||
glEnable(GL_CULL_FACE)
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
glDepthMask(GL_TRUE)
|
||||
glDepthFunc(GL_LEQUAL)
|
||||
glDepthRange(0.0, 1.0)
|
||||
|
||||
#We create out shaders which do little more than set a flat colour for each face
|
||||
|
||||
VERTEX_SHADER = shaders.compileShader("""
|
||||
#version 130
|
||||
|
||||
in vec4 position;
|
||||
in vec4 normal;
|
||||
|
||||
uniform mat4 cameraToClipMatrix;
|
||||
uniform mat4 worldToCameraMatrix;
|
||||
uniform mat4 modelToWorldMatrix;
|
||||
|
||||
flat out float theColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 temp = modelToWorldMatrix * position;
|
||||
temp = worldToCameraMatrix * temp;
|
||||
gl_Position = cameraToClipMatrix * temp;
|
||||
|
||||
theColor = clamp(abs(dot(normalize(normal.xyz), normalize(vec3(0.9,0.1,0.5)))), 0, 1);
|
||||
}
|
||||
""", GL_VERTEX_SHADER)
|
||||
|
||||
FRAGMENT_SHADER = shaders.compileShader("""
|
||||
#version 130
|
||||
|
||||
flat in float theColor;
|
||||
|
||||
out vec4 outputColor;
|
||||
void main()
|
||||
{
|
||||
outputColor = vec4(1.0, 0.5, theColor, 1.0);
|
||||
}
|
||||
""", GL_FRAGMENT_SHADER)
|
||||
|
||||
shader = shaders.compileProgram(VERTEX_SHADER, FRAGMENT_SHADER)
|
||||
|
||||
#And then grab our attribute locations from it
|
||||
glBindAttribLocation(shader, 0, "position")
|
||||
glBindAttribLocation(shader, 1, "normal")
|
||||
|
||||
#Create the Vertex Array Object to hold our volume mesh
|
||||
vertexArrayObject = GLuint(0)
|
||||
glGenVertexArrays(1, vertexArrayObject)
|
||||
glBindVertexArray(vertexArrayObject)
|
||||
|
||||
#Create the index buffer object
|
||||
indexPositions = vbo.VBO(indices, target=GL_ELEMENT_ARRAY_BUFFER, usage=GL_STATIC_DRAW)
|
||||
#Create the VBO
|
||||
vertexPositions = vbo.VBO(vertices, usage=GL_STATIC_DRAW)
|
||||
|
||||
#Bind our VBOs and set up our data layout specifications
|
||||
with indexPositions, vertexPositions:
|
||||
glEnableVertexAttribArray(0)
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, False, 6*vertices.dtype.itemsize, vertexPositions+(0*vertices.dtype.itemsize))
|
||||
glEnableVertexAttribArray(1)
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, False, 6*vertices.dtype.itemsize, vertexPositions+(3*vertices.dtype.itemsize))
|
||||
|
||||
glBindVertexArray(0)
|
||||
glDisableVertexAttribArray(0)
|
||||
|
||||
#Now grab out transformation martix locations
|
||||
modelToWorldMatrixUnif = glGetUniformLocation(shader, "modelToWorldMatrix")
|
||||
worldToCameraMatrixUnif = glGetUniformLocation(shader, "worldToCameraMatrix")
|
||||
cameraToClipMatrixUnif = glGetUniformLocation(shader, "cameraToClipMatrix")
|
||||
|
||||
modelToWorldMatrix = np.array([[1.0,0.0,0.0,-32.0],[0.0,1.0,0.0,-32.0],[0.0,0.0,1.0,-32.0],[0.0,0.0,0.0,1.0]], dtype='f')
|
||||
worldToCameraMatrix = np.array([[1.0,0.0,0.0,0.0],[0.0,1.0,0.0,0.0],[0.0,0.0,1.0,-50.0],[0.0,0.0,0.0,1.0]], dtype='f')
|
||||
cameraToClipMatrix = np.array([[0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0]], dtype='f')
|
||||
|
||||
#These next few lines just set up our camera frustum
|
||||
fovDeg = 45.0
|
||||
frustumScale = 1.0 / tan(radians(fovDeg) / 2.0)
|
||||
|
||||
zNear = 1.0
|
||||
zFar = 1000.0
|
||||
|
||||
cameraToClipMatrix[0][0] = frustumScale
|
||||
cameraToClipMatrix[1][1] = frustumScale
|
||||
cameraToClipMatrix[2][2] = (zFar + zNear) / (zNear - zFar)
|
||||
cameraToClipMatrix[2][3] = -1.0
|
||||
cameraToClipMatrix[3][2] = (2 * zFar * zNear) / (zNear - zFar)
|
||||
|
||||
#worldToCameraMatrix and cameraToClipMatrix don't change ever so just set them once here
|
||||
with shader:
|
||||
glUniformMatrix4fv(cameraToClipMatrixUnif, 1, GL_TRUE, cameraToClipMatrix)
|
||||
glUniformMatrix4fv(worldToCameraMatrixUnif, 1, GL_TRUE, worldToCameraMatrix)
|
||||
|
||||
#These are used to track the rotation of the volume
|
||||
LastFrameMousePos = (0,0)
|
||||
CurrentMousePos = (0,0)
|
||||
xRotation = 0
|
||||
yRotation = 0
|
||||
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
return
|
||||
if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
|
||||
return
|
||||
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
||||
CurrentMousePos = event.pos
|
||||
LastFrameMousePos = CurrentMousePos
|
||||
if event.type == pygame.MOUSEMOTION and 1 in event.buttons:
|
||||
CurrentMousePos = event.pos
|
||||
diff = (CurrentMousePos[0] - LastFrameMousePos[0], CurrentMousePos[1] - LastFrameMousePos[1])
|
||||
xRotation += event.rel[0]
|
||||
yRotation += event.rel[1]
|
||||
LastFrameMousePos = CurrentMousePos
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
|
||||
#Perform the rotation of the mesh
|
||||
moveToOrigin = np.array([[1.0,0.0,0.0,-32.0],[0.0,1.0,0.0,-32.0],[0.0,0.0,1.0,-32.0],[0.0,0.0,0.0,1.0]], dtype='f')
|
||||
rotateAroundX = np.array([[1.0,0.0,0.0,0.0],[0.0,cos(radians(yRotation)),-sin(radians(yRotation)),0.0],[0.0,sin(radians(yRotation)),cos(radians(yRotation)),0.0],[0.0,0.0,0.0,1.0]], dtype='f')
|
||||
rotateAroundY = np.array([[cos(radians(xRotation)),0.0,sin(radians(xRotation)),0.0],[0.0,1.0,0.0,0.0],[-sin(radians(xRotation)),0.0,cos(radians(xRotation)),0.0],[0.0,0.0,0.0,1.0]], dtype='f')
|
||||
|
||||
modelToWorldMatrix = rotateAroundY.dot(rotateAroundX.dot(moveToOrigin))
|
||||
|
||||
with shader:
|
||||
glUniformMatrix4fv(modelToWorldMatrixUnif, 1, GL_TRUE, modelToWorldMatrix)
|
||||
glBindVertexArray(vertexArrayObject)
|
||||
|
||||
glDrawElements(GL_TRIANGLES, len(indices), GL_UNSIGNED_INT, None)
|
||||
|
||||
glBindVertexArray(0)
|
||||
|
||||
# Show the screen
|
||||
pygame.display.flip()
|
||||
|
||||
run()
|
@ -25,22 +25,16 @@ PROJECT(SmoothLODExample)
|
||||
|
||||
#Projects source files
|
||||
SET(SRC_FILES
|
||||
glew/glew.cpp
|
||||
|
||||
main.cpp
|
||||
OpenGLWidget.cpp
|
||||
)
|
||||
)
|
||||
|
||||
#Projects headers files
|
||||
SET(INC_FILES
|
||||
glew/glew.h
|
||||
glew/glxew.h
|
||||
glew/wglew.h
|
||||
|
||||
OpenGLWidget.h
|
||||
)
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
add_definitions(-DGLEW_STATIC)
|
||||
|
||||
#"Sources" and "Headers" are the group names in Visual Studio.
|
||||
#They may have other uses too...
|
||||
@ -50,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)
|
||||
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR})
|
||||
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
|
||||
|
||||
#Build
|
||||
@ -58,7 +52,7 @@ ADD_EXECUTABLE(SmoothLODExample ${SRC_FILES})
|
||||
IF(MSVC)
|
||||
SET_TARGET_PROPERTIES(SmoothLODExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings
|
||||
ENDIF(MSVC)
|
||||
TARGET_LINK_LIBRARIES(SmoothLODExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore)
|
||||
TARGET_LINK_LIBRARIES(SmoothLODExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore)
|
||||
SET_PROPERTY(TARGET SmoothLODExample PROPERTY FOLDER "Examples")
|
||||
|
||||
#Install - Only install the example in Windows
|
||||
|
@ -1,73 +0,0 @@
|
||||
The OpenGL Extension Wrangler Library
|
||||
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
|
||||
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
|
||||
Copyright (C) 2002, Lev Povalahev
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* The name of the author may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Mesa 3-D graphics library
|
||||
Version: 7.0
|
||||
|
||||
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
Copyright (c) 2007 The Khronos Group Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and/or associated documentation files (the
|
||||
"Materials"), to deal in the Materials without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
permit persons to whom the Materials are furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Materials.
|
||||
|
||||
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
31
examples/common/CMakeLists.txt
Normal file
31
examples/common/CMakeLists.txt
Normal file
@ -0,0 +1,31 @@
|
||||
# Copyright (c) 2010-2012 Matt Williams
|
||||
#
|
||||
# This software is provided 'as-is', without any express or implied
|
||||
# warranty. In no event will the authors be held liable for any damages
|
||||
# arising from the use of this software.
|
||||
#
|
||||
# Permission is granted to anyone to use this software for any purpose,
|
||||
# including commercial applications, and to alter it and redistribute it
|
||||
# freely, subject to the following restrictions:
|
||||
#
|
||||
# 1. The origin of this software must not be misrepresented; you must not
|
||||
# claim that you wrote the original software. If you use this software
|
||||
# in a product, an acknowledgment in the product documentation would be
|
||||
# appreciated but is not required.
|
||||
#
|
||||
# 2. Altered source versions must be plainly marked as such, and must not be
|
||||
# misrepresented as being the original software.
|
||||
#
|
||||
# 3. This notice may not be removed or altered from any source
|
||||
# distribution.
|
||||
|
||||
project(GLEW)
|
||||
|
||||
set(SRC_FILES ../common/glew/glew.cpp)
|
||||
|
||||
add_definitions(-DGLEW_STATIC)
|
||||
|
||||
#find_package(OpenGL REQUIRED)
|
||||
#include_directories(${OPENGL_INCLUDE_DIR})
|
||||
add_library(glew STATIC ${SRC_FILES})
|
||||
SET_PROPERTY(TARGET glew PROPERTY FOLDER "Examples/Common")
|
@ -20,18 +20,20 @@
|
||||
# 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
|
||||
source/AStarPathfinder.cpp
|
||||
source/MinizCompressor.cpp
|
||||
source/Log.cpp
|
||||
source/MeshDecimator.cpp
|
||||
source/Region.cpp
|
||||
source/SimpleInterface.cpp
|
||||
source/VertexTypes.cpp
|
||||
)
|
||||
|
||||
@ -47,6 +49,7 @@ SET(CORE_INC_FILES
|
||||
include/PolyVoxCore/BaseVolume.h
|
||||
include/PolyVoxCore/BaseVolume.inl
|
||||
include/PolyVoxCore/BaseVolumeSampler.inl
|
||||
include/PolyVoxCore/Compressor.h
|
||||
include/PolyVoxCore/ConstVolumeProxy.h
|
||||
include/PolyVoxCore/CubicSurfaceExtractor.h
|
||||
include/PolyVoxCore/CubicSurfaceExtractor.inl
|
||||
@ -70,8 +73,7 @@ SET(CORE_INC_FILES
|
||||
include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
|
||||
include/PolyVoxCore/Material.h
|
||||
include/PolyVoxCore/MaterialDensityPair.h
|
||||
include/PolyVoxCore/MeshDecimator.h
|
||||
include/PolyVoxCore/MeshDecimator.inl
|
||||
include/PolyVoxCore/MinizCompressor.h
|
||||
include/PolyVoxCore/PolyVoxForwardDeclarations.h
|
||||
include/PolyVoxCore/RawVolume.h
|
||||
include/PolyVoxCore/RawVolume.inl
|
||||
@ -79,7 +81,8 @@ SET(CORE_INC_FILES
|
||||
include/PolyVoxCore/Raycast.h
|
||||
include/PolyVoxCore/Raycast.inl
|
||||
include/PolyVoxCore/Region.h
|
||||
include/PolyVoxCore/SimpleInterface.h
|
||||
include/PolyVoxCore/RLECompressor.h
|
||||
include/PolyVoxCore/RLECompressor.inl
|
||||
include/PolyVoxCore/SimpleVolume.h
|
||||
include/PolyVoxCore/SimpleVolume.inl
|
||||
include/PolyVoxCore/SimpleVolumeBlock.inl
|
||||
@ -96,6 +99,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
|
||||
@ -108,6 +112,9 @@ SET(IMPL_INC_FILES
|
||||
include/PolyVoxCore/Impl/AStarPathfinderImpl.h
|
||||
include/PolyVoxCore/Impl/Block.h
|
||||
include/PolyVoxCore/Impl/Block.inl
|
||||
include/PolyVoxCore/Impl/CompilerCapabilities.h
|
||||
include/PolyVoxCore/Impl/Config.h
|
||||
include/PolyVoxCore/Impl/ErrorHandling.h
|
||||
include/PolyVoxCore/Impl/MarchingCubesTables.h
|
||||
include/PolyVoxCore/Impl/RandomUnitVectors.h
|
||||
include/PolyVoxCore/Impl/RandomVectors.h
|
||||
@ -128,7 +135,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
|
||||
|
@ -21,6 +21,8 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PolyVoxCore/Impl/ErrorHandling.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -159,7 +161,7 @@ namespace PolyVox
|
||||
if((openNodes.empty()) || (openNodes.getFirst() != endNode))
|
||||
{
|
||||
//In this case we failed to find a valid path.
|
||||
throw std::runtime_error("No path found");
|
||||
POLYVOX_THROW(std::runtime_error, "No path found");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -296,14 +298,14 @@ namespace PolyVox
|
||||
hVal = SixConnectedCost(a, b);
|
||||
break;
|
||||
default:
|
||||
assert(false); //Invalid case.
|
||||
POLYVOX_ASSERT(false, "Invalid case");
|
||||
}
|
||||
|
||||
//Sanity checks in debug mode. These can come out eventually, but I
|
||||
//want to make sure that the heuristics I've come up with make sense.
|
||||
assert((a-b).length() <= TwentySixConnectedCost(a,b));
|
||||
assert(TwentySixConnectedCost(a,b) <= EighteenConnectedCost(a,b));
|
||||
assert(EighteenConnectedCost(a,b) <= SixConnectedCost(a,b));
|
||||
POLYVOX_ASSERT((a-b).length() <= TwentySixConnectedCost(a,b), "A* heuristic error.");
|
||||
POLYVOX_ASSERT(TwentySixConnectedCost(a,b) <= EighteenConnectedCost(a,b), "A* heuristic error.");
|
||||
POLYVOX_ASSERT(EighteenConnectedCost(a,b) <= SixConnectedCost(a,b), "A* heuristic error.");
|
||||
|
||||
//Apply the bias to the computed h value;
|
||||
hVal *= m_params.hBias;
|
||||
@ -334,7 +336,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
// Robert Jenkins' 32 bit integer hash function
|
||||
// http://www.concentric.net/~ttwang/tech/inthash.htm
|
||||
// http://www.burtleburtle.net/bob/hash/integer.html
|
||||
template<typename VolumeType>
|
||||
uint32_t AStarPathfinder<VolumeType>::hash( uint32_t a)
|
||||
{
|
||||
|
@ -34,21 +34,19 @@ namespace PolyVox
|
||||
template<typename VolumeType, typename IsVoxelTransparentCallback>
|
||||
void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback)
|
||||
{
|
||||
typename VolumeType::Sampler m_sampVolume(volInput);
|
||||
|
||||
uint16_t uRandomUnitVectorIndex = 0;
|
||||
uint16_t uRandomVectorIndex = 0;
|
||||
uint16_t uIndexIncreament;
|
||||
|
||||
//Make sure that the size of the volume is an exact multiple of the size of the array.
|
||||
assert(volInput->getWidth() % arrayResult->getDimension(0) == 0);
|
||||
assert(volInput->getHeight() % arrayResult->getDimension(1) == 0);
|
||||
assert(volInput->getDepth() % arrayResult->getDimension(2) == 0);
|
||||
POLYVOX_ASSERT(volInput->getWidth() % arrayResult->getDimension(0) == 0, "Volume width must be an exact multiple of array width.");
|
||||
POLYVOX_ASSERT(volInput->getHeight() % arrayResult->getDimension(1) == 0, "Volume height must be an exact multiple of array height.");
|
||||
POLYVOX_ASSERT(volInput->getDepth() % arrayResult->getDimension(2) == 0, "Volume depth must be an exact multiple of array depth.");
|
||||
|
||||
//Our initial indices. It doesn't matter exactly what we set here, but the code below makes
|
||||
//sure they are different for different regions which helps reduce tiling patterns in the results.
|
||||
uRandomUnitVectorIndex += region.getLowerCorner().getX() + region.getLowerCorner().getY() + region.getLowerCorner().getZ();
|
||||
uRandomVectorIndex += region.getLowerCorner().getX() + region.getLowerCorner().getY() + region.getLowerCorner().getZ();
|
||||
uRandomUnitVectorIndex += region.getLowerX() + region.getLowerY() + region.getLowerZ();
|
||||
uRandomVectorIndex += region.getLowerX() + region.getLowerY() + region.getLowerZ();
|
||||
|
||||
//This value helps us jump around in the array a bit more, so the
|
||||
//nth 'random' value isn't always followed by the n+1th 'random' value.
|
||||
@ -71,11 +69,11 @@ namespace PolyVox
|
||||
const Vector3DFloat v3dOffset(0.5f,0.5f,0.5f);
|
||||
|
||||
//This loop iterates over the bottom-lower-left voxel in each of the cells in the output array
|
||||
for(uint16_t z = region.getLowerCorner().getZ(); z <= region.getUpperCorner().getZ(); z += iRatioZ)
|
||||
for(uint16_t z = region.getLowerZ(); z <= region.getUpperZ(); z += iRatioZ)
|
||||
{
|
||||
for(uint16_t y = region.getLowerCorner().getY(); y <= region.getUpperCorner().getY(); y += iRatioY)
|
||||
for(uint16_t y = region.getLowerY(); y <= region.getUpperY(); y += iRatioY)
|
||||
{
|
||||
for(uint16_t x = region.getLowerCorner().getX(); x <= region.getUpperCorner().getX(); x += iRatioX)
|
||||
for(uint16_t x = region.getLowerX(); x <= region.getUpperX(); x += iRatioX)
|
||||
{
|
||||
//Compute a start position corresponding to
|
||||
//the centre of the cell in the output array.
|
||||
@ -100,6 +98,8 @@ namespace PolyVox
|
||||
AmbientOcclusionCalculatorRaycastCallback<IsVoxelTransparentCallback> ambientOcclusionCalculatorRaycastCallback(isVoxelTransparentCallback);
|
||||
RaycastResult result = raycastWithDirection(volInput, v3dRayStart, v3dRayDirection, ambientOcclusionCalculatorRaycastCallback);
|
||||
|
||||
// Note - The performance of this could actually be improved it we exited as soon
|
||||
// as the ray left the volume. The raycast test has an example of how to do this.
|
||||
if(result == RaycastResults::Completed)
|
||||
{
|
||||
++uVisibleDirections;
|
||||
@ -116,7 +116,7 @@ namespace PolyVox
|
||||
else
|
||||
{
|
||||
fVisibility = static_cast<float>(uVisibleDirections) / static_cast<float>(uNoOfSamplesPerOutputElement);
|
||||
assert((fVisibility >= 0.0f) && (fVisibility <= 1.0f));
|
||||
POLYVOX_ASSERT((fVisibility >= 0.0f) && (fVisibility <= 1.0f), "Visibility value out of range.");
|
||||
}
|
||||
|
||||
(*arrayResult)[z / iRatioZ][y / iRatioY][x / iRatioX] = static_cast<uint8_t>(255.0f * fVisibility);
|
||||
|
@ -73,7 +73,7 @@ namespace PolyVox
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
SubArray<noOfDims-1, ElementType> Array<noOfDims, ElementType>::operator[](uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
POLYVOX_ASSERT(uIndex < m_pDimensions[0], "Index out of range");
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
@ -91,7 +91,7 @@ namespace PolyVox
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
const SubArray<noOfDims-1, ElementType> Array<noOfDims, ElementType>::operator[](uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
POLYVOX_ASSERT(uIndex < m_pDimensions[0], "Index out of range");
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
@ -139,7 +139,7 @@ namespace PolyVox
|
||||
m_uNoOfElements = 1;
|
||||
for (uint32_t i = 0; i<noOfDims; i++)
|
||||
{
|
||||
assert(pDimensions[i] != 0);
|
||||
POLYVOX_ASSERT(pDimensions[i] != 0, "Invalid dimension");
|
||||
|
||||
m_uNoOfElements *= pDimensions[i];
|
||||
m_pDimensions[i] = pDimensions[i];
|
||||
@ -186,7 +186,7 @@ namespace PolyVox
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
uint32_t Array<noOfDims, ElementType>::getDimension(uint32_t uDimension)
|
||||
{
|
||||
assert(uDimension < noOfDims);
|
||||
POLYVOX_ASSERT(uDimension < noOfDims, "Dimension out of range");
|
||||
return m_pDimensions[uDimension];
|
||||
}
|
||||
|
||||
@ -198,14 +198,14 @@ namespace PolyVox
|
||||
,m_uNoOfElements(0)
|
||||
{
|
||||
//Not implemented
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "Not implemented.");
|
||||
}
|
||||
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
Array<noOfDims, ElementType>& Array<noOfDims, ElementType>::operator=(const Array<noOfDims, ElementType>& rhs)
|
||||
{
|
||||
//Not implemented
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "Not implemented.");
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -251,14 +251,14 @@ namespace PolyVox
|
||||
template <typename ElementType>
|
||||
ElementType& Array<1, ElementType>::operator[] (uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
POLYVOX_ASSERT(uIndex < m_pDimensions[0], "Index out of range");
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
template <typename ElementType>
|
||||
const ElementType& Array<1, ElementType>::operator[] (uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
POLYVOX_ASSERT(uIndex < m_pDimensions[0], "Index out of range");
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
@ -307,14 +307,14 @@ namespace PolyVox
|
||||
,m_pDimensions(0)
|
||||
{
|
||||
//Not implemented
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "Not implemented.");
|
||||
}
|
||||
|
||||
template <typename ElementType>
|
||||
Array<1, ElementType>& Array<1, ElementType>::operator=(const Array<1, ElementType>& rhs)
|
||||
{
|
||||
//Not implemented
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "Not implemented.");
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ freely, subject to the following restrictions:
|
||||
#include "PolyVoxCore/Region.h"
|
||||
#include "PolyVoxCore/Vector.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
|
||||
namespace PolyVox
|
||||
@ -38,6 +37,16 @@ namespace PolyVox
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// More details to come...
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
namespace WrapModes
|
||||
{
|
||||
enum WrapMode
|
||||
{
|
||||
Clamp = 0,
|
||||
Border = 1
|
||||
};
|
||||
}
|
||||
typedef WrapModes::WrapMode WrapMode;
|
||||
|
||||
template <typename _VoxelType>
|
||||
class BaseVolume
|
||||
{
|
||||
@ -55,9 +64,12 @@ namespace PolyVox
|
||||
Vector3DInt32 getPosition(void) const;
|
||||
inline VoxelType getVoxel(void) const;
|
||||
|
||||
bool isCurrentPositionValid(void) const;
|
||||
|
||||
void setPosition(const Vector3DInt32& v3dNewPos);
|
||||
void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
|
||||
inline bool setVoxel(VoxelType tValue);
|
||||
void setWrapMode(WrapMode eWrapMode, VoxelType tBorder = VoxelType(0));
|
||||
|
||||
void movePositiveX(void);
|
||||
void movePositiveY(void);
|
||||
@ -98,12 +110,23 @@ namespace PolyVox
|
||||
inline VoxelType peekVoxel1px1py1pz(void) const;
|
||||
|
||||
protected:
|
||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||
|
||||
DerivedVolumeType* mVolume;
|
||||
|
||||
//The current position in the volume
|
||||
int32_t mXPosInVolume;
|
||||
int32_t mYPosInVolume;
|
||||
int32_t mZPosInVolume;
|
||||
|
||||
WrapMode m_eWrapMode;
|
||||
VoxelType m_tBorder;
|
||||
|
||||
//Whether the current position is inside the volume
|
||||
//FIXME - Replace these with flags
|
||||
bool m_bIsCurrentPositionValidInX;
|
||||
bool m_bIsCurrentPositionValidInY;
|
||||
bool m_bIsCurrentPositionValidInZ;
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -111,7 +134,7 @@ namespace PolyVox
|
||||
/// Gets the value used for voxels which are outside the volume
|
||||
VoxelType getBorderValue(void) const;
|
||||
/// Gets a Region representing the extents of the Volume.
|
||||
Region getEnclosingRegion(void) const;
|
||||
const Region& getEnclosingRegion(void) const;
|
||||
/// Gets the width of the volume in voxels.
|
||||
int32_t getWidth(void) const;
|
||||
/// Gets the height of the volume in voxels.
|
||||
@ -125,9 +148,17 @@ namespace PolyVox
|
||||
/// Gets the length of the diagonal in voxels
|
||||
float getDiagonalLength(void) const;
|
||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||
/// Gets a voxel at the position given by a 3D vector
|
||||
VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
|
||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||
/// Gets a voxel at the position given by a 3D vector
|
||||
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||
/// Gets a voxel at the position given by a 3D vector
|
||||
VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||
|
||||
/// Sets the value used for voxels which are outside the volume
|
||||
void setBorderValue(const VoxelType& tBorder);
|
||||
@ -159,6 +190,9 @@ namespace PolyVox
|
||||
int32_t m_uLongestSideLength;
|
||||
int32_t m_uShortestSideLength;
|
||||
float m_fDiagonalLength;
|
||||
|
||||
//The border value
|
||||
VoxelType m_tBorderValue;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -31,20 +31,21 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
BaseVolume<VoxelType>::BaseVolume(const Region& regValid)
|
||||
:m_regValidRegion(regValid)
|
||||
,m_tBorderValue(0)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
|
||||
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
|
||||
/// make a copy of a volume and in this case you should look at the Volumeresampler.
|
||||
/// make a copy of a volume and in this case you should look at the VolumeResampler.
|
||||
///
|
||||
/// \sa VolumeResampler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
BaseVolume<VoxelType>::BaseVolume(const BaseVolume<VoxelType>& /*rhs*/)
|
||||
{
|
||||
assert(false); // See function comment above.
|
||||
POLYVOX_ASSERT(false, "Copy constructor not implemented."); // See function comment above.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -65,7 +66,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
BaseVolume<VoxelType>& BaseVolume<VoxelType>::operator=(const BaseVolume<VoxelType>& /*rhs*/)
|
||||
{
|
||||
assert(false); // See function comment above.
|
||||
POLYVOX_ASSERT(false, "Assignment operator not implemented."); // See function comment above.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -76,15 +77,14 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType BaseVolume<VoxelType>::getBorderValue(void) const
|
||||
{
|
||||
assert(false);
|
||||
return VoxelType();
|
||||
return m_tBorderValue;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \return A Region representing the extent of the volume.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
Region BaseVolume<VoxelType>::getEnclosingRegion(void) const
|
||||
const Region& BaseVolume<VoxelType>::getEnclosingRegion(void) const
|
||||
{
|
||||
return m_regValidRegion;
|
||||
}
|
||||
@ -96,7 +96,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
int32_t BaseVolume<VoxelType>::getWidth(void) const
|
||||
{
|
||||
return m_regValidRegion.getUpperCorner().getX() - m_regValidRegion.getLowerCorner().getX() + 1;
|
||||
return m_regValidRegion.getUpperX() - m_regValidRegion.getLowerX() + 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -106,7 +106,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
int32_t BaseVolume<VoxelType>::getHeight(void) const
|
||||
{
|
||||
return m_regValidRegion.getUpperCorner().getY() - m_regValidRegion.getLowerCorner().getY() + 1;
|
||||
return m_regValidRegion.getUpperY() - m_regValidRegion.getLowerY() + 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -116,7 +116,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
int32_t BaseVolume<VoxelType>::getDepth(void) const
|
||||
{
|
||||
return m_regValidRegion.getUpperCorner().getZ() - m_regValidRegion.getLowerCorner().getZ() + 1;
|
||||
return m_regValidRegion.getUpperZ() - m_regValidRegion.getLowerZ() + 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -153,6 +153,30 @@ namespace PolyVox
|
||||
return m_fDiagonalLength;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param uXPos The \c x position of the voxel
|
||||
/// \param uYPos The \c y position of the voxel
|
||||
/// \param uZPos The \c z position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType BaseVolume<VoxelType>::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const
|
||||
{
|
||||
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
|
||||
return VoxelType();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param v3dPos The 3D position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType BaseVolume<VoxelType>::getVoxel(const Vector3DInt32& /*v3dPos*/) const
|
||||
{
|
||||
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
|
||||
return VoxelType();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param uXPos The \c x position of the voxel
|
||||
/// \param uYPos The \c y position of the voxel
|
||||
@ -162,7 +186,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType BaseVolume<VoxelType>::getVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const
|
||||
{
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
|
||||
return VoxelType();
|
||||
}
|
||||
|
||||
@ -173,7 +197,31 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType BaseVolume<VoxelType>::getVoxelAt(const Vector3DInt32& /*v3dPos*/) const
|
||||
{
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
|
||||
return VoxelType();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param uXPos The \c x position of the voxel
|
||||
/// \param uYPos The \c y position of the voxel
|
||||
/// \param uZPos The \c z position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType BaseVolume<VoxelType>::getVoxelWithWrapping(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
|
||||
{
|
||||
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
|
||||
return VoxelType();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param v3dPos The 3D position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType BaseVolume<VoxelType>::getVoxelWithWrapping(const Vector3DInt32& /*v3dPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
|
||||
{
|
||||
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
|
||||
return VoxelType();
|
||||
}
|
||||
|
||||
@ -181,9 +229,9 @@ namespace PolyVox
|
||||
/// \param tBorder The value to use for voxels outside the volume.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
void BaseVolume<VoxelType>::setBorderValue(const VoxelType& /*tBorder*/)
|
||||
void BaseVolume<VoxelType>::setBorderValue(const VoxelType& tBorder)
|
||||
{
|
||||
assert(false);
|
||||
m_tBorderValue = tBorder;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -196,7 +244,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
bool BaseVolume<VoxelType>::setVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/)
|
||||
{
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -208,7 +256,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
bool BaseVolume<VoxelType>::setVoxelAt(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/)
|
||||
{
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PolyVoxCore/Impl/Utility.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
@ -30,6 +32,11 @@ namespace PolyVox
|
||||
,mXPosInVolume(0)
|
||||
,mYPosInVolume(0)
|
||||
,mZPosInVolume(0)
|
||||
,m_eWrapMode(WrapModes::Border)
|
||||
,m_tBorder(0)
|
||||
,m_bIsCurrentPositionValidInX(false)
|
||||
,m_bIsCurrentPositionValidInY(false)
|
||||
,m_bIsCurrentPositionValidInZ(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -53,13 +60,18 @@ namespace PolyVox
|
||||
return mVolume->getVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
bool inline BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::isCurrentPositionValid(void) const
|
||||
{
|
||||
return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setPosition(const Vector3DInt32& v3dNewPos)
|
||||
{
|
||||
mXPosInVolume = v3dNewPos.getX();
|
||||
mYPosInVolume = v3dNewPos.getY();
|
||||
mZPosInVolume = v3dNewPos.getZ();
|
||||
setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
@ -69,6 +81,10 @@ namespace PolyVox
|
||||
mXPosInVolume = xPos;
|
||||
mYPosInVolume = yPos;
|
||||
mZPosInVolume = zPos;
|
||||
|
||||
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(xPos);
|
||||
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(yPos);
|
||||
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(zPos);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
@ -78,11 +94,20 @@ namespace PolyVox
|
||||
return mVolume->setVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume, tValue);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setWrapMode(WrapMode eWrapMode, VoxelType tBorder)
|
||||
{
|
||||
m_eWrapMode = eWrapMode;
|
||||
m_tBorder = tBorder;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveX(void)
|
||||
{
|
||||
mXPosInVolume++;
|
||||
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
@ -90,6 +115,7 @@ namespace PolyVox
|
||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveY(void)
|
||||
{
|
||||
mYPosInVolume++;
|
||||
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
@ -97,6 +123,7 @@ namespace PolyVox
|
||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveZ(void)
|
||||
{
|
||||
mZPosInVolume++;
|
||||
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
@ -104,6 +131,7 @@ namespace PolyVox
|
||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeX(void)
|
||||
{
|
||||
mXPosInVolume--;
|
||||
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
@ -111,6 +139,7 @@ namespace PolyVox
|
||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeY(void)
|
||||
{
|
||||
mYPosInVolume--;
|
||||
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
@ -118,69 +147,70 @@ namespace PolyVox
|
||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeZ(void)
|
||||
{
|
||||
mZPosInVolume--;
|
||||
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1ny1nz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1);
|
||||
return getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1ny0pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume );
|
||||
return getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume );
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1ny1pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1);
|
||||
return getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx0py1nz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1);
|
||||
return getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx0py0pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume );
|
||||
return getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume );
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx0py1pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1);
|
||||
return getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1py1nz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1);
|
||||
return getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1py0pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume );
|
||||
return getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume );
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1nx1py1pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1);
|
||||
return getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -189,63 +219,63 @@ namespace PolyVox
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1ny1nz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1);
|
||||
return getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1ny0pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume );
|
||||
return getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume );
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1ny1pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1);
|
||||
return getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px0py1nz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1);
|
||||
return getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px0py0pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume );
|
||||
return getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume );
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px0py1pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1);
|
||||
return getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1py1nz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1);
|
||||
return getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1py0pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume );
|
||||
return getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume );
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel0px1py1pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1);
|
||||
return getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -254,62 +284,101 @@ namespace PolyVox
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1ny1nz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1);
|
||||
return getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1ny0pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume );
|
||||
return getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume );
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1ny1pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1);
|
||||
return getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px0py1nz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1);
|
||||
return getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px0py0pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume );
|
||||
return getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume );
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px0py1pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1);
|
||||
return getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1py1nz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1);
|
||||
return getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1py0pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume );
|
||||
return getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume );
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::peekVoxel1px1py1pz(void) const
|
||||
{
|
||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1);
|
||||
return getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
template <typename DerivedVolumeType>
|
||||
VoxelType BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
||||
{
|
||||
if(mVolume->getEnclosingRegion().containsPoint(uXPos, uYPos, uZPos))
|
||||
{
|
||||
return mVolume->getVoxelAt(uXPos, uYPos, uZPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(m_eWrapMode)
|
||||
{
|
||||
case WrapModes::Clamp:
|
||||
{
|
||||
const Vector3DInt32& lowerCorner = mVolume->m_regValidRegion.getLowerCorner();
|
||||
const Vector3DInt32& upperCorner = mVolume->m_regValidRegion.getUpperCorner();
|
||||
|
||||
int32_t iClampedX = clamp(uXPos, lowerCorner.getX(), upperCorner.getX());
|
||||
int32_t iClampedY = clamp(uYPos, lowerCorner.getY(), upperCorner.getY());
|
||||
int32_t iClampedZ = clamp(uZPos, lowerCorner.getZ(), upperCorner.getZ());
|
||||
|
||||
return mVolume->getVoxelAt(iClampedX, iClampedY, iClampedZ);
|
||||
//No need to break as we've returned
|
||||
}
|
||||
case WrapModes::Border:
|
||||
{
|
||||
return m_tBorder;
|
||||
//No need to break as we've returned
|
||||
}
|
||||
default:
|
||||
{
|
||||
//Should never happen
|
||||
POLYVOX_ASSERT(false, "Invalid case.");
|
||||
return VoxelType(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,26 +21,29 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __PolyVox_SimpleInterface_H__
|
||||
#define __PolyVox_SimpleInterface_H__
|
||||
#ifndef __PolyVox_Compressor_H__
|
||||
#define __PolyVox_Compressor_H__
|
||||
|
||||
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h"
|
||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||
#include "PolyVoxCore/SimpleVolume.h"
|
||||
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
|
||||
#include "PolyVoxCore/Impl/TypeDef.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
//The PolyVox simple interface only exposes one voxel type and one volume type. But if you like you can
|
||||
//adjust these typedefs and rebuild the library in order to modify which one volume and voxel is exposed.
|
||||
typedef SimpleVolume<MaterialDensityPair88> Volume;
|
||||
typedef SurfaceMesh<PositionMaterialNormal> Mesh;
|
||||
class Compressor
|
||||
{
|
||||
public:
|
||||
Compressor() {};
|
||||
virtual ~Compressor() {};
|
||||
|
||||
/// \deprecated
|
||||
POLYVOX_DEPRECATED void extractCubicMesh(Volume& volume, const Region& region, Mesh& resultMesh);
|
||||
/// \deprecated
|
||||
POLYVOX_DEPRECATED void extractSmoothMesh(Volume& volume, const Region& region, Mesh& resultMesh);
|
||||
// Computes a worst-case scenario for how big the output can be for a given input size. If
|
||||
// necessary you can use this as a destination buffer size, though it may be somewhat wasteful.
|
||||
virtual uint32_t getMaxCompressedSize(uint32_t uUncompressedInputSize) = 0;
|
||||
|
||||
// Compresses the data.
|
||||
virtual uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) = 0;
|
||||
|
||||
// Decompresses the data.
|
||||
virtual uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //__PolyVox_SimpleInterface_H__
|
||||
#endif //__PolyVox_Compressor_H__
|
@ -37,25 +37,25 @@ namespace PolyVox
|
||||
public:
|
||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
||||
{
|
||||
assert(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
|
||||
POLYVOX_ASSERT(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
|
||||
return m_pVolume.getVoxelAt(uXPos, uYPos, uZPos);
|
||||
}
|
||||
|
||||
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const
|
||||
{
|
||||
assert(m_regValid.containsPoint(v3dPos));
|
||||
POLYVOX_ASSERT(m_regValid.containsPoint(v3dPos), "Position is outside valid region");
|
||||
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||
}
|
||||
|
||||
void setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const
|
||||
{
|
||||
assert(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
|
||||
POLYVOX_ASSERT(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
|
||||
m_pVolume.setVoxelAtConst(uXPos, uYPos, uZPos, tValue);
|
||||
}
|
||||
|
||||
void setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) const
|
||||
{
|
||||
assert(m_regValid.containsPoint(v3dPos));
|
||||
POLYVOX_ASSERT(m_regValid.containsPoint(v3dPos), "Position is outside valid region");
|
||||
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
|
||||
}
|
||||
private:
|
||||
|
@ -26,7 +26,10 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "Impl/TypeDef.h"
|
||||
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include "PolyVoxCore/Array.h"
|
||||
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
||||
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
|
||||
#include "PolyVoxCore/SurfaceMesh.h"
|
||||
|
||||
@ -73,7 +76,7 @@ namespace PolyVox
|
||||
///
|
||||
/// Another scenario which sometimes results in confusion is when you wish to extract a region which corresponds to the whole volume, partcularly when solid voxels extend right to the edge of the volume.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<typename VolumeType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> >
|
||||
template<typename VolumeType, typename IsQuadNeeded>
|
||||
class CubicSurfaceExtractor
|
||||
{
|
||||
struct IndexAndMaterial
|
||||
@ -107,13 +110,19 @@ namespace PolyVox
|
||||
};
|
||||
|
||||
public:
|
||||
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* 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>* 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>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||
#endif
|
||||
|
||||
|
||||
void execute();
|
||||
|
||||
private:
|
||||
int32_t addVertex(float fX, float fY, float fZ, uint32_t uMaterial, Array<3, IndexAndMaterial>& existingVertices);
|
||||
int32_t addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, uint32_t uMaterial, Array<3, IndexAndMaterial>& existingVertices);
|
||||
bool performQuadMerging(std::list<Quad>& quads);
|
||||
bool mergeQuads(Quad& q1, Quad& q2);
|
||||
|
||||
@ -143,6 +152,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;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -26,20 +26,21 @@ namespace PolyVox
|
||||
// We try to avoid duplicate vertices by checking whether a vertex has already been added at a given position.
|
||||
// However, it is possible that vertices have the same position but different materials. In this case, the
|
||||
// vertices are not true duplicates and both must be added to the mesh. As far as I can tell, it is possible to have
|
||||
// at most six vertices with the same position but different materials. This worst-case scenario happens when we
|
||||
// have a 2x2x2 group of voxels (all with different materials) and then we delete two voxels from opposing corners.
|
||||
// The vertex position at the center of this group is then going to be used by six quads all with different materials.
|
||||
// One futher note - we can actually have eight quads sharing a vertex position (imagine two 1x1x10 rows of voxels
|
||||
// sharing a common edge) but in this case all eight quads will not have different materials.
|
||||
// at most eight vertices with the same position but different materials. For example, this worst-case scenario
|
||||
// happens when we have a 2x2x2 group of voxels, all with different materials and some/all partially transparent.
|
||||
// The vertex position at the center of this group is then going to be used by all eight voxels all with different
|
||||
// materials.
|
||||
template<typename VolumeType, typename IsQuadNeeded>
|
||||
const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 6;
|
||||
const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 8;
|
||||
|
||||
template<typename VolumeType, typename IsQuadNeeded>
|
||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* result, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* 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;
|
||||
}
|
||||
@ -49,8 +50,8 @@ namespace PolyVox
|
||||
{
|
||||
m_meshCurrent->clear();
|
||||
|
||||
uint32_t uArrayWidth = m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 2;
|
||||
uint32_t uArrayHeight = m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 2;
|
||||
uint32_t uArrayWidth = m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2;
|
||||
uint32_t uArrayHeight = m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2;
|
||||
|
||||
uint32_t arraySize[3]= {uArrayWidth, uArrayHeight, MaxVerticesPerPosition};
|
||||
m_previousSliceVertices.resize(arraySize);
|
||||
@ -58,30 +59,31 @@ namespace PolyVox
|
||||
memset(m_previousSliceVertices.getRawData(), 0xff, m_previousSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
|
||||
memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
|
||||
|
||||
m_vecQuads[NegativeX].resize(m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 2);
|
||||
m_vecQuads[PositiveX].resize(m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 2);
|
||||
m_vecQuads[NegativeX].resize(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2);
|
||||
m_vecQuads[PositiveX].resize(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2);
|
||||
|
||||
m_vecQuads[NegativeY].resize(m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 2);
|
||||
m_vecQuads[PositiveY].resize(m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 2);
|
||||
m_vecQuads[NegativeY].resize(m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2);
|
||||
m_vecQuads[PositiveY].resize(m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2);
|
||||
|
||||
m_vecQuads[NegativeZ].resize(m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ() + 2);
|
||||
m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ() + 2);
|
||||
m_vecQuads[NegativeZ].resize(m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ() + 2);
|
||||
m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ() + 2);
|
||||
|
||||
typename VolumeType::Sampler volumeSampler(m_volData);
|
||||
volumeSampler.setWrapMode(m_eWrapMode, m_tBorderValue);
|
||||
|
||||
for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ(); z++)
|
||||
for(int32_t z = m_regSizeInVoxels.getLowerZ(); z <= m_regSizeInVoxels.getUpperZ(); z++)
|
||||
{
|
||||
uint32_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ();
|
||||
uint32_t regZ = z - m_regSizeInVoxels.getLowerZ();
|
||||
|
||||
for(int32_t y = m_regSizeInVoxels.getLowerCorner().getY(); y <= m_regSizeInVoxels.getUpperCorner().getY(); y++)
|
||||
for(int32_t y = m_regSizeInVoxels.getLowerY(); y <= m_regSizeInVoxels.getUpperY(); y++)
|
||||
{
|
||||
uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
uint32_t regY = y - m_regSizeInVoxels.getLowerY();
|
||||
|
||||
for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX(); x++)
|
||||
volumeSampler.setPosition(m_regSizeInVoxels.getLowerX(),y,z);
|
||||
|
||||
for(int32_t x = m_regSizeInVoxels.getLowerX(); x <= m_regSizeInVoxels.getUpperX(); x++)
|
||||
{
|
||||
uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
|
||||
volumeSampler.setPosition(x,y,z);
|
||||
uint32_t regX = x - m_regSizeInVoxels.getLowerX();
|
||||
|
||||
uint32_t material; //Filled in by callback
|
||||
typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel();
|
||||
@ -92,20 +94,20 @@ namespace PolyVox
|
||||
// X
|
||||
if(m_funcIsQuadNeededCallback(currentVoxel, negXVoxel, material))
|
||||
{
|
||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
||||
uint32_t v2 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
||||
uint32_t v3 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
|
||||
uint32_t v2 = addVertex(regX , regY + 1, regZ + 1, material, m_currentSliceVertices);
|
||||
uint32_t v3 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
|
||||
|
||||
m_vecQuads[NegativeX][regX].push_back(Quad(v0, v1, v2, v3));
|
||||
}
|
||||
|
||||
if(m_funcIsQuadNeededCallback(negXVoxel, currentVoxel, material))
|
||||
{
|
||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
||||
uint32_t v2 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
||||
uint32_t v3 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
|
||||
uint32_t v2 = addVertex(regX , regY + 1, regZ + 1, material, m_currentSliceVertices);
|
||||
uint32_t v3 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
|
||||
|
||||
m_vecQuads[PositiveX][regX].push_back(Quad(v0, v3, v2, v1));
|
||||
}
|
||||
@ -113,20 +115,20 @@ namespace PolyVox
|
||||
// Y
|
||||
if(m_funcIsQuadNeededCallback(currentVoxel, negYVoxel, material))
|
||||
{
|
||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v2 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
||||
uint32_t v3 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
||||
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
|
||||
uint32_t v2 = addVertex(regX + 1, regY , regZ + 1, material, m_currentSliceVertices);
|
||||
uint32_t v3 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
|
||||
|
||||
m_vecQuads[NegativeY][regY].push_back(Quad(v0, v1, v2, v3));
|
||||
}
|
||||
|
||||
if(m_funcIsQuadNeededCallback(negYVoxel, currentVoxel, material))
|
||||
{
|
||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v2 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
||||
uint32_t v3 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
||||
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
|
||||
uint32_t v2 = addVertex(regX + 1, regY , regZ + 1, material, m_currentSliceVertices);
|
||||
uint32_t v3 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
|
||||
|
||||
m_vecQuads[PositiveY][regY].push_back(Quad(v0, v3, v2, v1));
|
||||
}
|
||||
@ -134,23 +136,25 @@ namespace PolyVox
|
||||
// Z
|
||||
if(m_funcIsQuadNeededCallback(currentVoxel, negZVoxel, material))
|
||||
{
|
||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v2 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v3 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
|
||||
uint32_t v2 = addVertex(regX + 1, regY + 1, regZ , material, m_previousSliceVertices);
|
||||
uint32_t v3 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
|
||||
|
||||
m_vecQuads[NegativeZ][regZ].push_back(Quad(v0, v1, v2, v3));
|
||||
}
|
||||
|
||||
if(m_funcIsQuadNeededCallback(negZVoxel, currentVoxel, material))
|
||||
{
|
||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v2 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v3 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
||||
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||
uint32_t v1 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
|
||||
uint32_t v2 = addVertex(regX + 1, regY + 1, regZ , material, m_previousSliceVertices);
|
||||
uint32_t v3 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
|
||||
|
||||
m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1));
|
||||
}
|
||||
|
||||
volumeSampler.movePositiveX();
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,19 +198,16 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template<typename VolumeType, typename IsQuadNeeded>
|
||||
int32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::addVertex(float fX, float fY, float fZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
||||
int32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
||||
{
|
||||
uint32_t uX = static_cast<uint32_t>(fX + 0.75f);
|
||||
uint32_t uY = static_cast<uint32_t>(fY + 0.75f);
|
||||
|
||||
for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++)
|
||||
{
|
||||
IndexAndMaterial& rEntry = existingVertices[uX][uY][ct];
|
||||
|
||||
if(rEntry.iIndex == -1)
|
||||
{
|
||||
//No vertices matched and we've now hit an empty space. Fill it by creating a vertex.
|
||||
rEntry.iIndex = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(fX, fY, fZ), uMaterialIn));
|
||||
//No vertices matched and we've now hit an empty space. Fill it by creating a vertex. The 0.5f offset is because vertices set between voxels in order to build cubes around them.
|
||||
rEntry.iIndex = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(static_cast<float>(uX) - 0.5f, static_cast<float>(uY) - 0.5f, static_cast<float>(uZ) - 0.5f), uMaterialIn));
|
||||
rEntry.uMaterial = uMaterialIn;
|
||||
|
||||
return rEntry.iIndex;
|
||||
@ -221,7 +222,7 @@ namespace PolyVox
|
||||
|
||||
// If we exit the loop here then apparently all the slots were full but none of them matched. I don't think
|
||||
// this can happen so let's put an assert to make sure. If you hit this assert then please report it to us!
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "All slots full but no matches.");
|
||||
return -1; //Should never happen.
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
@ -38,20 +40,20 @@ namespace PolyVox
|
||||
{
|
||||
m_meshCurrent->clear();
|
||||
|
||||
for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z < m_regSizeInVoxels.getUpperCorner().getZ(); z++)
|
||||
for(int32_t z = m_regSizeInVoxels.getLowerZ(); z < m_regSizeInVoxels.getUpperZ(); z++)
|
||||
{
|
||||
for(int32_t y = m_regSizeInVoxels.getLowerCorner().getY(); y < m_regSizeInVoxels.getUpperCorner().getY(); y++)
|
||||
for(int32_t y = m_regSizeInVoxels.getLowerY(); y < m_regSizeInVoxels.getUpperY(); y++)
|
||||
{
|
||||
for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x < m_regSizeInVoxels.getUpperCorner().getX(); x++)
|
||||
for(int32_t x = m_regSizeInVoxels.getLowerX(); x < m_regSizeInVoxels.getUpperX(); x++)
|
||||
{
|
||||
// these are always positive anyway
|
||||
float regX = static_cast<float>(x - m_regSizeInVoxels.getLowerCorner().getX());
|
||||
float regY = static_cast<float>(y - m_regSizeInVoxels.getLowerCorner().getY());
|
||||
float regZ = static_cast<float>(z - m_regSizeInVoxels.getLowerCorner().getZ());
|
||||
float regX = static_cast<float>(x - m_regSizeInVoxels.getLowerX());
|
||||
float regY = static_cast<float>(y - m_regSizeInVoxels.getLowerY());
|
||||
float regZ = static_cast<float>(z - m_regSizeInVoxels.getLowerZ());
|
||||
|
||||
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)));
|
||||
|
@ -24,38 +24,40 @@ freely, subject to the following restrictions:
|
||||
#ifndef __PolyVox_MarchingCubesController_H__
|
||||
#define __PolyVox_MarchingCubesController_H__
|
||||
|
||||
#include "PolyVoxCore/BaseVolume.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// This class provides a default implementation of a controller for the MarchingCubesSurfaceExtractor. It controls the behaviour of the
|
||||
/// MarchingCubesSurfaceExtractor and provides the required properties from the underlying voxel type.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// PolyVox does not enforce any requirements regarding what data must be present in a voxel, and instead allows any primitive or user-defined
|
||||
/// type to be used. However, the Marching Cubes algorithm does have some requirents about the underlying data in that conceptually it operates
|
||||
/// on a <i>density field</i>. In addition, the PolyVox implementation of the Marching Cubes algorithm also understands the idea of each voxel
|
||||
/// having a material which is copied into the vertex data.
|
||||
///
|
||||
/// Because we want the MarchingCubesSurfaceExtractor to work on <i>any</i> voxel type, we use a <i>Marching Cubes controller</i> (passed as
|
||||
/// a parameter of the MarchingCubesSurfaceExtractor) to expose the required properties. This parameter defaults to the DefaultMarchingCubesController.
|
||||
/// The main implementation of this class is designed to work with primitives data types, and the class is also specialised for the Material,
|
||||
/// Density and MaterialdensityPair classes.
|
||||
///
|
||||
/// If you create a custom class for your voxel data then you probably want to include a specialisation of DefaultMarchingCubesController,
|
||||
/// though you don't have to if you don't want to use the Marching Cubes algorithm or if you prefer to define a seperate Marching Cubes controller
|
||||
/// and pass it as an explicit parameter (rather than relying on the default).
|
||||
///
|
||||
/// For primitive types, the DefaultMarchingCubesController considers the value of the voxel to represent it's density and just returns a constant
|
||||
/// for the material. So you can, for example, run the MarchingCubesSurfaceExtractor on a volume of floats or ints.
|
||||
///
|
||||
/// It is possible to customise the behaviour of the controller by providing a threshold value through the constructor. The extracted surface
|
||||
/// will pass through the density value specified by the threshold, and so you should make sure that the threshold value you choose is between
|
||||
/// the minimum and maximum values found in your volume data. By default it is in the middle of the representable range of the underlying type.
|
||||
///
|
||||
/// \sa MarchingCubesSurfaceExtractor
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* This class provides a default implementation of a controller for the MarchingCubesSurfaceExtractor. It controls the behaviour of the
|
||||
* MarchingCubesSurfaceExtractor and provides the required properties from the underlying voxel type.
|
||||
*
|
||||
* PolyVox does not enforce any requirements regarding what data must be present in a voxel, and instead allows any primitive or user-defined
|
||||
* type to be used. However, the Marching Cubes algorithm does have some requirents about the underlying data in that conceptually it operates
|
||||
* on a <i>density field</i>. In addition, the PolyVox implementation of the Marching Cubes algorithm also understands the idea of each voxel
|
||||
* having a material which is copied into the vertex data.
|
||||
*
|
||||
* Because we want the MarchingCubesSurfaceExtractor to work on <i>any</i> voxel type, we use a <i>Marching Cubes controller</i> (passed as
|
||||
* a parameter of the MarchingCubesSurfaceExtractor) to expose the required properties. This parameter defaults to the DefaultMarchingCubesController.
|
||||
* The main implementation of this class is designed to work with primitives data types, and the class is also specialised for the Material,
|
||||
* Density and MaterialdensityPair classes.
|
||||
*
|
||||
* If you create a custom class for your voxel data then you probably want to include a specialisation of DefaultMarchingCubesController,
|
||||
* though you don't have to if you don't want to use the Marching Cubes algorithm or if you prefer to define a seperate Marching Cubes controller
|
||||
* and pass it as an explicit parameter (rather than relying on the default).
|
||||
*
|
||||
* For primitive types, the DefaultMarchingCubesController considers the value of the voxel to represent it's density and just returns a constant
|
||||
* for the material. So you can, for example, run the MarchingCubesSurfaceExtractor on a volume of floats or ints.
|
||||
*
|
||||
* It is possible to customise the behaviour of the controller by providing a threshold value through the constructor. The extracted surface
|
||||
* will pass through the density value specified by the threshold, and so you should make sure that the threshold value you choose is between
|
||||
* the minimum and maximum values found in your volume data. By default it is in the middle of the representable range of the underlying type.
|
||||
*
|
||||
* \sa MarchingCubesSurfaceExtractor
|
||||
*
|
||||
*/
|
||||
template<typename VoxelType>
|
||||
class DefaultMarchingCubesController
|
||||
{
|
||||
@ -67,63 +69,57 @@ namespace PolyVox
|
||||
/// but this is not really desirable on modern hardware. We'll probably come back to material representation in the future.
|
||||
typedef float MaterialType;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// This version of the constructor takes no parameters and sets the threshold to the middle of the representable range of the underlying type.
|
||||
/// For example, if the voxel type is 'uint8_t' then the representable range is 0-255, and the threshold will be set to 127. On the other hand,
|
||||
/// if the voxel type is 'float' then the representable range is -FLT_MAX to FLT_MAX and the threshold will be set to zero.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* This version of the constructor takes no parameters and sets the threshold to the middle of the representable range of the underlying type.
|
||||
* For example, if the voxel type is 'uint8_t' then the representable range is 0-255, and the threshold will be set to 127. On the other hand,
|
||||
* if the voxel type is 'float' then the representable range is -FLT_MAX to FLT_MAX and the threshold will be set to zero.
|
||||
*/
|
||||
DefaultMarchingCubesController(void)
|
||||
:m_tThreshold(((std::numeric_limits<DensityType>::min)() + (std::numeric_limits<DensityType>::max)()) / 2)
|
||||
{
|
||||
m_tThreshold = ((std::numeric_limits<DensityType>::min)() + (std::numeric_limits<DensityType>::max)()) / 2;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// This version of the constructor allows you to set a custom threshold.
|
||||
/// \param tThreshold The threshold to use.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
DefaultMarchingCubesController(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Converts the underlying voxel type into a density value.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// The default implementation of this function just returns the voxel type directly and is suitable for primitives types. Specialisations of
|
||||
/// this class can modify this behaviour.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Converts the underlying voxel type into a density value.
|
||||
*
|
||||
* The default implementation of this function just returns the voxel type directly and is suitable for primitives types. Specialisations of
|
||||
* this class can modify this behaviour.
|
||||
*/
|
||||
DensityType convertToDensity(VoxelType voxel)
|
||||
{
|
||||
return voxel;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Converts the underlying voxel type into a material value.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// The default implementation of this function just returns the constant '1'. There's not much else it can do, as it needs to work with primitive
|
||||
/// types and the actual value of the type is already being considered to be the density. Specialisations of this class can modify this behaviour.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Converts the underlying voxel type into a material value.
|
||||
*
|
||||
* The default implementation of this function just returns the constant '1'. There's not much else it can do, as it needs to work with primitive
|
||||
* types and the actual value of the type is already being considered to be the density. Specialisations of this class can modify this behaviour.
|
||||
*/
|
||||
MaterialType convertToMaterial(VoxelType /*voxel*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Returns the density value which was passed to the constructor.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// As mentioned in the class description, the extracted surface will pass through the density value specified by the threshold, and so you
|
||||
/// should make sure that the threshold value you choose is between the minimum and maximum values found in your volume data. By default it
|
||||
///is in the middle of the representable range of the underlying type.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Returns the density value which was passed to the constructor.
|
||||
*
|
||||
* As mentioned in the class description, the extracted surface will pass through the density value specified by the threshold, and so you
|
||||
* should make sure that the threshold value you choose is between the minimum and maximum values found in your volume data. By default it
|
||||
* is in the middle of the representable range of the underlying type.
|
||||
*/
|
||||
DensityType getThreshold(void)
|
||||
{
|
||||
return m_tThreshold;
|
||||
}
|
||||
|
||||
void setThreshold(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
}
|
||||
|
||||
private:
|
||||
DensityType m_tThreshold;
|
||||
};
|
||||
|
@ -28,7 +28,6 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "Impl/TypeDef.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
|
||||
#undef min
|
||||
@ -177,6 +176,11 @@ namespace PolyVox
|
||||
return m_tThreshold;
|
||||
}
|
||||
|
||||
void setThreshold(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
}
|
||||
|
||||
private:
|
||||
DensityType m_tThreshold;
|
||||
};
|
||||
|
@ -25,6 +25,8 @@ freely, subject to the following restrictions:
|
||||
#define __PolyVox_Block_H__
|
||||
|
||||
#include "PolyVoxCore/Impl/TypeDef.h"
|
||||
|
||||
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
|
||||
#include "PolyVoxCore/Vector.h"
|
||||
|
||||
#include <limits>
|
||||
@ -56,15 +58,15 @@ namespace PolyVox
|
||||
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
|
||||
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
|
||||
|
||||
void fill(VoxelType tValue);
|
||||
void initialise(uint16_t uSideLength);
|
||||
uint32_t calculateSizeInBytes(void);
|
||||
|
||||
public:
|
||||
void compress(void);
|
||||
void uncompress(void);
|
||||
void compress(Compressor* pCompressor);
|
||||
void uncompress(Compressor* pCompressor);
|
||||
|
||||
std::vector< RunlengthEntry<uint16_t> > m_vecCompressedData;
|
||||
uint8_t* m_pCompressedData;
|
||||
uint32_t m_uCompressedDataLength;
|
||||
VoxelType* m_tUncompressedData;
|
||||
uint16_t m_uSideLength;
|
||||
uint8_t m_uSideLengthPower;
|
||||
|
@ -21,10 +21,14 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PolyVoxCore/Impl/ErrorHandling.h"
|
||||
#include "PolyVoxCore/Impl/Utility.h"
|
||||
|
||||
#include "PolyVoxCore/Compressor.h"
|
||||
#include "PolyVoxCore/Vector.h"
|
||||
|
||||
#include <cassert>
|
||||
#include "PolyVoxCore/Impl/ErrorHandling.h"
|
||||
|
||||
#include <cstring> //For memcpy
|
||||
#include <limits>
|
||||
#include <stdexcept> //for std::invalid_argument
|
||||
@ -33,10 +37,12 @@ namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
Block<VoxelType>::Block(uint16_t uSideLength)
|
||||
:m_tUncompressedData(0)
|
||||
:m_pCompressedData(0)
|
||||
,m_uCompressedDataLength(0)
|
||||
,m_tUncompressedData(0)
|
||||
,m_uSideLength(0)
|
||||
,m_uSideLengthPower(0)
|
||||
,m_bIsCompressed(true)
|
||||
,m_bIsCompressed(false)
|
||||
,m_bIsUncompressedDataModified(true)
|
||||
{
|
||||
if(uSideLength != 0)
|
||||
@ -54,11 +60,11 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType Block<VoxelType>::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
|
||||
{
|
||||
assert(uXPos < m_uSideLength);
|
||||
assert(uYPos < m_uSideLength);
|
||||
assert(uZPos < m_uSideLength);
|
||||
POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block");
|
||||
POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block");
|
||||
POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block");
|
||||
|
||||
assert(m_tUncompressedData);
|
||||
POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels.");
|
||||
|
||||
return m_tUncompressedData
|
||||
[
|
||||
@ -77,11 +83,11 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue)
|
||||
{
|
||||
assert(uXPos < m_uSideLength);
|
||||
assert(uYPos < m_uSideLength);
|
||||
assert(uZPos < m_uSideLength);
|
||||
POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block");
|
||||
POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block");
|
||||
POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block");
|
||||
|
||||
assert(m_tUncompressedData);
|
||||
POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels.");
|
||||
|
||||
m_tUncompressedData
|
||||
[
|
||||
@ -99,93 +105,102 @@ namespace PolyVox
|
||||
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::fill(VoxelType tValue)
|
||||
{
|
||||
if(!m_bIsCompressed)
|
||||
{
|
||||
//The memset *may* be faster than the std::fill(), but it doesn't compile nicely
|
||||
//in 64-bit mode as casting the pointer to an int causes a loss of precision.
|
||||
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||
std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue);
|
||||
|
||||
m_bIsUncompressedDataModified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RunlengthEntry<uint16_t> rle;
|
||||
rle.length = m_uSideLength*m_uSideLength*m_uSideLength;
|
||||
rle.value = tValue;
|
||||
m_vecCompressedData.clear();
|
||||
m_vecCompressedData.push_back(rle);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::initialise(uint16_t uSideLength)
|
||||
{
|
||||
//Debug mode validation
|
||||
assert(isPowerOf2(uSideLength));
|
||||
POLYVOX_ASSERT(isPowerOf2(uSideLength), "Block side length must be a power of two.");
|
||||
|
||||
//Release mode validation
|
||||
if(!isPowerOf2(uSideLength))
|
||||
{
|
||||
throw std::invalid_argument("Block side length must be a power of two.");
|
||||
POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two.");
|
||||
}
|
||||
|
||||
//Compute the side length
|
||||
m_uSideLength = uSideLength;
|
||||
m_uSideLengthPower = logBase2(uSideLength);
|
||||
|
||||
Block<VoxelType>::fill(VoxelType());
|
||||
//Create the block data
|
||||
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
|
||||
|
||||
//Clear it (should we bother?)
|
||||
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||
std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, VoxelType());
|
||||
m_bIsUncompressedDataModified = true;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
uint32_t Block<VoxelType>::calculateSizeInBytes(void)
|
||||
{
|
||||
//FIXME - This function is incomplete.
|
||||
uint32_t uSizeInBytes = sizeof(Block<VoxelType>);
|
||||
uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry<uint16_t>);
|
||||
return uSizeInBytes;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::compress(void)
|
||||
void Block<VoxelType>::compress(Compressor* pCompressor)
|
||||
{
|
||||
assert(m_bIsCompressed == false);
|
||||
assert(m_tUncompressedData != 0);
|
||||
POLYVOX_ASSERT(pCompressor, "Compressor is not valid");
|
||||
POLYVOX_ASSERT(m_bIsCompressed == false, "Attempted to compress block which is already flagged as compressed.");
|
||||
POLYVOX_ASSERT(m_tUncompressedData != 0, "No uncompressed data is present.");
|
||||
|
||||
//If the uncompressed data hasn't actually been
|
||||
//modified then we don't need to redo the compression.
|
||||
if(m_bIsUncompressedDataModified)
|
||||
{
|
||||
uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||
m_vecCompressedData.clear();
|
||||
// Delete the old compressed data as we'll create a new one
|
||||
delete[] m_pCompressedData;
|
||||
m_pCompressedData = 0;
|
||||
|
||||
RunlengthEntry<uint16_t> entry;
|
||||
entry.length = 1;
|
||||
entry.value = m_tUncompressedData[0];
|
||||
void* pSrcData = reinterpret_cast<void*>(m_tUncompressedData);
|
||||
uint32_t uSrcLength = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType);
|
||||
|
||||
for(uint32_t ct = 1; ct < uNoOfVoxels; ++ct)
|
||||
uint8_t tempBuffer[10000];
|
||||
void* pDstData = reinterpret_cast<void*>( tempBuffer );
|
||||
uint32_t uDstLength = 10000;
|
||||
|
||||
uint32_t uCompressedLength = 0;
|
||||
|
||||
try
|
||||
{
|
||||
VoxelType value = m_tUncompressedData[ct];
|
||||
if((value == entry.value) && (entry.length < entry.maxRunlength()))
|
||||
{
|
||||
entry.length++;
|
||||
uCompressedLength = pCompressor->compress(pSrcData, uSrcLength, pDstData, uDstLength);
|
||||
|
||||
// Create new compressed data and copy across
|
||||
m_pCompressedData = new uint8_t[uCompressedLength];
|
||||
memcpy(m_pCompressedData, pDstData, uCompressedLength);
|
||||
m_uCompressedDataLength = uCompressedLength;
|
||||
}
|
||||
else
|
||||
catch(std::exception&)
|
||||
{
|
||||
m_vecCompressedData.push_back(entry);
|
||||
entry.value = value;
|
||||
entry.length = 1;
|
||||
// It is possible for the compression to fail. A common cause for this would be if the destination
|
||||
// buffer is not big enough. So now we try again using a buffer that is definitely big enough.
|
||||
// Note that ideally we will choose our earlier buffer size so that this almost never happens.
|
||||
uint32_t uMaxCompressedSize = pCompressor->getMaxCompressedSize(uSrcLength);
|
||||
uint8_t* buffer = new uint8_t[ uMaxCompressedSize ];
|
||||
|
||||
pDstData = reinterpret_cast<void*>( buffer );
|
||||
uDstLength = uMaxCompressedSize;
|
||||
|
||||
try
|
||||
{
|
||||
uCompressedLength = pCompressor->compress(pSrcData, uSrcLength, pDstData, uDstLength);
|
||||
|
||||
// Create new compressed data and copy across
|
||||
m_pCompressedData = new uint8_t[uCompressedLength];
|
||||
memcpy(m_pCompressedData, pDstData, uCompressedLength);
|
||||
m_uCompressedDataLength = uCompressedLength;
|
||||
}
|
||||
catch(std::exception&)
|
||||
{
|
||||
// At this point it didn't work even with a bigger buffer.
|
||||
// Not much more we can do so just rethrow the exception.
|
||||
delete[] buffer;
|
||||
POLYVOX_THROW(std::runtime_error, "Failed to compress block data");
|
||||
}
|
||||
|
||||
m_vecCompressedData.push_back(entry);
|
||||
|
||||
//Shrink the vectors to their contents (maybe slow?):
|
||||
//http://stackoverflow.com/questions/1111078/reduce-the-capacity-of-an-stl-vector
|
||||
//C++0x may have a shrink_to_fit() function?
|
||||
std::vector< RunlengthEntry<uint16_t> >(m_vecCompressedData).swap(m_vecCompressedData);
|
||||
delete[] buffer;
|
||||
}
|
||||
}
|
||||
|
||||
//Flag the uncompressed data as no longer being used.
|
||||
@ -195,18 +210,26 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::uncompress(void)
|
||||
void Block<VoxelType>::uncompress(Compressor* pCompressor)
|
||||
{
|
||||
assert(m_bIsCompressed == true);
|
||||
assert(m_tUncompressedData == 0);
|
||||
POLYVOX_ASSERT(pCompressor, "Compressor is not valid");
|
||||
POLYVOX_ASSERT(m_bIsCompressed == true, "Attempted to uncompress block which is not flagged as compressed.");
|
||||
POLYVOX_ASSERT(m_tUncompressedData == 0, "Uncompressed data already exists.");
|
||||
|
||||
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
|
||||
|
||||
VoxelType* pUncompressedData = m_tUncompressedData;
|
||||
for(uint32_t ct = 0; ct < m_vecCompressedData.size(); ++ct)
|
||||
{
|
||||
std::fill(pUncompressedData, pUncompressedData + m_vecCompressedData[ct].length, m_vecCompressedData[ct].value);
|
||||
pUncompressedData += m_vecCompressedData[ct].length;
|
||||
}
|
||||
void* pSrcData = reinterpret_cast<void*>(m_pCompressedData);
|
||||
void* pDstData = reinterpret_cast<void*>(m_tUncompressedData);
|
||||
uint32_t uSrcLength = m_uCompressedDataLength;
|
||||
uint32_t uDstLength = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType);
|
||||
|
||||
//MinizCompressor compressor;
|
||||
//RLECompressor<VoxelType, uint16_t> compressor;
|
||||
uint32_t uUncompressedLength = pCompressor->decompress(pSrcData, uSrcLength, pDstData, uDstLength);
|
||||
|
||||
POLYVOX_ASSERT(uUncompressedLength == m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType), "Destination length has changed.");
|
||||
|
||||
//m_tUncompressedData = reinterpret_cast<VoxelType*>(uncompressedResult.ptr);
|
||||
|
||||
m_bIsCompressed = false;
|
||||
m_bIsUncompressedDataModified = false;
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This file describes the capabilities of the C++ compiler and is used to determine which features to enable in PolyVox.
|
||||
* It assumes that if the compiler is from VS2008 or earlier then no C++11 is present, otherwise it assumes full support
|
||||
* is present.
|
||||
*
|
||||
* Not that this file is usually overwritten by CMake which does careful tests of the true compiler capabilities. However,
|
||||
* we provide this default file so that CMake is not actually required for users of PolyVox and they can instead just drop
|
||||
* PolyVox code into their project/makefile if they prefer.
|
||||
*/
|
||||
|
||||
#ifndef __PolyVox_CompilerCapabilities_H__
|
||||
#define __PolyVox_CompilerCapabilities_H__
|
||||
|
||||
// If we are not using Visual Studio (or we are but it
|
||||
// is a recent version) then assume support for these.
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1600)
|
||||
#define HAS_CXX11_CONSTEXPR
|
||||
#define HAS_CXX11_STATIC_ASSERT
|
||||
#define HAS_CXX11_CSTDINT_H
|
||||
#define HAS_CXX11_SHARED_PTR
|
||||
#endif
|
||||
|
||||
#endif
|
@ -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
|
@ -21,23 +21,10 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PolyVoxCore/SimpleInterface.h"
|
||||
#ifndef __PolyVox_Config_H__
|
||||
#define __PolyVox_Config_H__
|
||||
|
||||
//DOESN'T BELONG HERE - JUST FOR TESTING!!
|
||||
#include "PolyVoxCore/Density.h"
|
||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||
#define POLYVOX_ASSERTS_ENABLED
|
||||
#define POLYVOX_THROW_ENABLED
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
void extractCubicMesh(Volume& volume, const Region& region, Mesh& resultMesh)
|
||||
{
|
||||
CubicSurfaceExtractorWithNormals< SimpleVolume<MaterialDensityPair88> > surfaceExtractor(&volume, region, &resultMesh);
|
||||
surfaceExtractor.execute();
|
||||
}
|
||||
|
||||
void extractSmoothMesh(Volume& volume, const Region& region, Mesh& resultMesh)
|
||||
{
|
||||
MarchingCubesSurfaceExtractor< SimpleVolume<MaterialDensityPair88> > surfaceExtractor(&volume, region, &resultMesh);
|
||||
surfaceExtractor.execute();
|
||||
}
|
||||
}
|
||||
#endif
|
123
library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h
Normal file
123
library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h
Normal file
@ -0,0 +1,123 @@
|
||||
/*******************************************************************************
|
||||
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 "PolyVoxCore/Impl/Config.h"
|
||||
|
||||
#include <cstdlib> //For std::exit
|
||||
#include <iostream> //For std::cerr
|
||||
#include <stdexcept>
|
||||
|
||||
#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__
|
@ -21,14 +21,14 @@ misrepresented as being the original software.
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include <cassert>
|
||||
#include "PolyVoxCore/Impl/ErrorHandling.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
POLYVOX_ASSERT(uIndex < m_pDimensions[0], "Index out of range");
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
@ -37,7 +37,7 @@ namespace PolyVox
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
const SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
POLYVOX_ASSERT(uIndex < m_pDimensions[0], "Index out of range");
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
@ -56,14 +56,14 @@ namespace PolyVox
|
||||
template <typename ElementType>
|
||||
ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
POLYVOX_ASSERT(uIndex < m_pDimensions[0], "Index out of range");
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
template <typename ElementType>
|
||||
const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
POLYVOX_ASSERT(uIndex < m_pDimensions[0], "Index out of range");
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
|
@ -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,31 +81,40 @@ freely, subject to the following restrictions:
|
||||
#define polyvox_bind boost::bind
|
||||
#define polyvox_placeholder_1 _1
|
||||
#define polyvox_placeholder_2 _2
|
||||
|
||||
#include <boost/static_assert.hpp>
|
||||
#define static_assert BOOST_STATIC_ASSERT
|
||||
|
||||
|
||||
//As long as we're requiring boost, we'll use it to compensate
|
||||
//for the missing cstdint header too.
|
||||
#include <boost/cstdint.hpp>
|
||||
using boost::int8_t;
|
||||
using boost::int16_t;
|
||||
using boost::int32_t;
|
||||
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>
|
||||
#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
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#if defined(HAS_CXX11_CSTDINT_H)
|
||||
#include <cstdint>
|
||||
#else
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef long int32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_CXX11_SHARED_PTR)
|
||||
#include <memory>
|
||||
#define polyvox_shared_ptr std::shared_ptr
|
||||
#else
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#define polyvox_shared_ptr boost::shared_ptr
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -26,12 +26,31 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "PolyVoxCore/Impl/TypeDef.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
POLYVOX_API uint8_t logBase2(uint32_t uInput);
|
||||
POLYVOX_API bool isPowerOf2(uint32_t uInput);
|
||||
|
||||
int32_t roundTowardsNegInf(float r);
|
||||
int32_t roundToInteger(float r);
|
||||
template <typename Type>
|
||||
Type clamp(const Type& value, const Type& low, const Type& high);
|
||||
|
||||
inline int32_t roundTowardsNegInf(float r)
|
||||
{
|
||||
return (r >= 0.0) ? static_cast<int32_t>(r) : static_cast<int32_t>(r - 1.0f);
|
||||
}
|
||||
|
||||
inline int32_t roundToNearestInteger(float r)
|
||||
{
|
||||
return (r >= 0.0) ? static_cast<int32_t>(r + 0.5f) : static_cast<int32_t>(r - 0.5f);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type clamp(const Type& value, const Type& low, const Type& high)
|
||||
{
|
||||
return (std::min)(high, (std::max)(low, value));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
4766
library/PolyVoxCore/include/PolyVoxCore/Impl/miniz.c
Normal file
4766
library/PolyVoxCore/include/PolyVoxCore/Impl/miniz.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -24,8 +24,6 @@ freely, subject to the following restrictions:
|
||||
#ifndef __PolyVox_Interpolation_H__
|
||||
#define __PolyVox_Interpolation_H__
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename Type>
|
||||
@ -33,10 +31,10 @@ namespace PolyVox
|
||||
const Type& v0,const Type& v1,
|
||||
const float x)
|
||||
{
|
||||
assert((x >= 0.0f) && (x <= 1.0f));
|
||||
POLYVOX_ASSERT((x >= 0.0f) && (x <= 1.0f), "Interpolation input out of 0.0 to 1.0 range.");
|
||||
|
||||
//Interpolate along X
|
||||
Type v0_1 = v0 + x * (v1 - v0);
|
||||
Type v0_1 = (v1 - v0) * x + v0;
|
||||
|
||||
return v0_1;
|
||||
}
|
||||
@ -46,8 +44,8 @@ namespace PolyVox
|
||||
const Type& v00,const Type& v10,const Type& v01,const Type& v11,
|
||||
const float x, const float y)
|
||||
{
|
||||
assert((x >= 0.0f) && (y >= 0.0f) &&
|
||||
(x <= 1.0f) && (y <= 1.0f));
|
||||
POLYVOX_ASSERT((x >= 0.0f) && (y >= 0.0f) &&
|
||||
(x <= 1.0f) && (y <= 1.0f), "Interpolation input out of 0.0 to 1.0 range.");
|
||||
|
||||
// Linearly interpolate along x
|
||||
Type v00_10 = lerp(v00, v10, x);
|
||||
@ -65,8 +63,8 @@ namespace PolyVox
|
||||
const Type& v001,const Type& v101,const Type& v011,const Type& v111,
|
||||
const float x, const float y, const float z)
|
||||
{
|
||||
assert((x >= 0.0f) && (y >= 0.0f) && (z >= 0.0f) &&
|
||||
(x <= 1.0f) && (y <= 1.0f) && (z <= 1.0f));
|
||||
POLYVOX_ASSERT((x >= 0.0f) && (y >= 0.0f) && (z >= 0.0f) &&
|
||||
(x <= 1.0f) && (y <= 1.0f) && (z <= 1.0f), "Interpolation input out of 0.0 to 1.0 range.");
|
||||
|
||||
// Bilinearly interpolate along Y
|
||||
Type v000_v100__v010_v110 = bilerp(v000, v100, v010, v110, x, y);
|
||||
|
@ -34,24 +34,24 @@ namespace PolyVox
|
||||
{
|
||||
Vector3DInt32 v3dInitialPosition(m_Iter->getPosition().getX(), m_Iter->getPosition().getY(), m_Iter->getPosition().getZ());
|
||||
|
||||
if(v3dInitialPosition.getX() < m_regValid.getUpperCorner().getX())
|
||||
if(v3dInitialPosition.getX() < m_regValid.getUpperX())
|
||||
{
|
||||
m_Iter->movePositiveX();
|
||||
return true;
|
||||
}
|
||||
|
||||
v3dInitialPosition.setX(m_regValid.getLowerCorner().getX());
|
||||
v3dInitialPosition.setX(m_regValid.getLowerX());
|
||||
|
||||
if(v3dInitialPosition.getY() < m_regValid.getUpperCorner().getY())
|
||||
if(v3dInitialPosition.getY() < m_regValid.getUpperY())
|
||||
{
|
||||
v3dInitialPosition.setY(v3dInitialPosition.getY() + 1);
|
||||
m_Iter->setPosition(v3dInitialPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
v3dInitialPosition.setY(m_regValid.getLowerCorner().getY());
|
||||
v3dInitialPosition.setY(m_regValid.getLowerY());
|
||||
|
||||
if(v3dInitialPosition.getZ() < m_regValid.getUpperCorner().getZ())
|
||||
if(v3dInitialPosition.getZ() < m_regValid.getUpperZ())
|
||||
{
|
||||
v3dInitialPosition.setZ(v3dInitialPosition.getZ() + 1);
|
||||
m_Iter->setPosition(v3dInitialPosition);
|
||||
|
@ -26,12 +26,12 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "PolyVoxCore/BaseVolume.h"
|
||||
#include "Impl/Block.h"
|
||||
#include "PolyVoxCore/Compressor.h"
|
||||
#include "PolyVoxCore/Log.h"
|
||||
#include "PolyVoxCore/Region.h"
|
||||
#include "PolyVoxCore/Vector.h"
|
||||
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
#include <cstdlib> //For abort()
|
||||
#include <cstring> //For memcpy
|
||||
#include <list>
|
||||
@ -166,6 +166,7 @@ namespace PolyVox
|
||||
//in the future
|
||||
//typedef Volume<VoxelType> VolumeOfVoxelType; //Workaround for GCC/VS2010 differences.
|
||||
//class Sampler : public VolumeOfVoxelType::template Sampler< LargeVolume<VoxelType> >
|
||||
#ifndef SWIG
|
||||
#if defined(_MSC_VER)
|
||||
class Sampler : public BaseVolume<VoxelType>::Sampler< LargeVolume<VoxelType> > //This line works on VS2010
|
||||
#else
|
||||
@ -176,9 +177,8 @@ namespace PolyVox
|
||||
Sampler(LargeVolume<VoxelType>* volume);
|
||||
~Sampler();
|
||||
|
||||
Sampler& operator=(const Sampler& rhs);
|
||||
|
||||
VoxelType getSubSampledVoxel(uint8_t uLevel) const;
|
||||
/// \deprecated
|
||||
POLYVOX_DEPRECATED VoxelType getSubSampledVoxel(uint8_t uLevel) const;
|
||||
inline VoxelType getVoxel(void) const;
|
||||
|
||||
void setPosition(const Vector3DInt32& v3dNewPos);
|
||||
@ -243,6 +243,7 @@ namespace PolyVox
|
||||
Block<VoxelType> block;
|
||||
uint32_t timestamp;
|
||||
};
|
||||
#endif
|
||||
|
||||
public:
|
||||
/// Constructor for creating a very large paging volume.
|
||||
@ -256,6 +257,7 @@ namespace PolyVox
|
||||
LargeVolume
|
||||
(
|
||||
const Region& regValid,
|
||||
Compressor* pCompressor = 0,
|
||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler = 0,
|
||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler = 0,
|
||||
bool bPagingEnabled = false,
|
||||
@ -264,21 +266,23 @@ namespace PolyVox
|
||||
/// Destructor
|
||||
~LargeVolume();
|
||||
|
||||
/// Gets the value used for voxels which are outside the volume
|
||||
VoxelType getBorderValue(void) const;
|
||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||
/// Gets a voxel at the position given by a 3D vector
|
||||
VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
|
||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||
/// Gets a voxel at the position given by a 3D vector
|
||||
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||
/// Gets a voxel at the position given by a 3D vector
|
||||
VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||
|
||||
//Sets whether or not blocks are compressed in memory
|
||||
void setCompressionEnabled(bool bCompressionEnabled);
|
||||
/// Sets the number of blocks for which uncompressed data is stored
|
||||
void setMaxNumberOfUncompressedBlocks(uint32_t uMaxNumberOfUncompressedBlocks);
|
||||
/// Sets the number of blocks which can be in memory before the paging system starts unloading them
|
||||
void setMaxNumberOfBlocksInMemory(uint32_t uMaxNumberOfBlocksInMemory);
|
||||
/// Sets the value used for voxels which are outside the volume
|
||||
void setBorderValue(const VoxelType& tBorder);
|
||||
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
|
||||
/// Sets the voxel at the position given by a 3D vector
|
||||
@ -305,6 +309,22 @@ namespace PolyVox
|
||||
LargeVolume& operator=(const LargeVolume& rhs);
|
||||
|
||||
private:
|
||||
|
||||
struct BlockPositionCompare
|
||||
{
|
||||
bool operator() (const PolyVox::Vector3DInt32& a, const PolyVox::Vector3DInt32& b) const
|
||||
{
|
||||
const uint32_t size = 3;
|
||||
for(uint32_t ct = 0; ct < size; ++ct)
|
||||
{
|
||||
if (a.getElement(ct) < b.getElement(ct))
|
||||
return true;
|
||||
if (b.getElement(ct) < a.getElement(ct))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
void initialise(const Region& regValidRegion, uint16_t uBlockSideLength);
|
||||
|
||||
/// gets called when a new region is allocated and needs to be filled
|
||||
@ -318,12 +338,12 @@ namespace PolyVox
|
||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> m_funcDataOverflowHandler;
|
||||
|
||||
Block<VoxelType>* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
|
||||
void eraseBlock(typename std::map<Vector3DInt32, LoadedBlock >::iterator itBlock) const;
|
||||
void eraseBlock(typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock) const;
|
||||
/// this function can be called by m_funcDataRequiredHandler without causing any weird effects
|
||||
bool setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const;
|
||||
|
||||
//The block data
|
||||
mutable std::map<Vector3DInt32, LoadedBlock > m_pBlocks;
|
||||
mutable std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare> m_pBlocks;
|
||||
|
||||
//The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather
|
||||
//than in the Block class. This is so that in the future each VolumeIterator might to maintain its own cache
|
||||
@ -336,12 +356,6 @@ namespace PolyVox
|
||||
uint32_t m_uMaxNumberOfUncompressedBlocks;
|
||||
uint32_t m_uMaxNumberOfBlocksInMemory;
|
||||
|
||||
//We don't store an actual Block for the border, just the uncompressed data. This is partly because the border
|
||||
//block does not have a position (so can't be passed to getUncompressedBlock()) and partly because there's a
|
||||
//good chance we'll often hit it anyway. It's a chunk of homogenous data (rather than a single value) so that
|
||||
//the VolumeIterator can do it's usual pointer arithmetic without needing to know it's gone outside the volume.
|
||||
VoxelType* m_pUncompressedBorderData;
|
||||
|
||||
//The size of the volume
|
||||
Region m_regValidRegionInBlocks;
|
||||
|
||||
@ -349,7 +363,9 @@ namespace PolyVox
|
||||
uint16_t m_uBlockSideLength;
|
||||
uint8_t m_uBlockSideLengthPower;
|
||||
|
||||
bool m_bCompressionEnabled;
|
||||
//The compressor used by the Blocks to compress their data if required.
|
||||
Compressor* m_pCompressor;
|
||||
|
||||
bool m_bPagingEnabled;
|
||||
};
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PolyVoxCore/Impl/ErrorHandling.h"
|
||||
|
||||
//Included here rather than in the .h because it refers to LargeVolume (avoids forward declaration)
|
||||
#include "PolyVoxCore/ConstVolumeProxy.h"
|
||||
|
||||
@ -51,6 +53,7 @@ namespace PolyVox
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// This constructor creates a volume with a fixed size which is specified as a parameter. By default this constructor will not enable paging but you can override this if desired. If you do wish to enable paging then you are required to provide the call back function (see the other LargeVolume constructor).
|
||||
/// \param regValid Specifies the minimum and maximum valid voxel positions.
|
||||
/// \param pCompressor An implementation of the Compressor interface which is used to compress blocks in memory.
|
||||
/// \param dataRequiredHandler The callback function which will be called when PolyVox tries to use data which is not currently in momory.
|
||||
/// \param dataOverflowHandler The callback function which will be called when PolyVox has too much data and needs to remove some from memory.
|
||||
/// \param bPagingEnabled Controls whether or not paging is enabled for this LargeVolume.
|
||||
@ -60,12 +63,14 @@ namespace PolyVox
|
||||
LargeVolume<VoxelType>::LargeVolume
|
||||
(
|
||||
const Region& regValid,
|
||||
Compressor* pCompressor,
|
||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler,
|
||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler,
|
||||
bool bPagingEnabled,
|
||||
uint16_t uBlockSideLength
|
||||
)
|
||||
:BaseVolume<VoxelType>(regValid)
|
||||
,m_pCompressor(pCompressor)
|
||||
{
|
||||
m_funcDataRequiredHandler = dataRequiredHandler;
|
||||
m_funcDataOverflowHandler = dataOverflowHandler;
|
||||
@ -78,14 +83,14 @@ namespace PolyVox
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
|
||||
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
|
||||
/// make a copy of a volume and in this case you should look at the Volumeresampler.
|
||||
/// make a copy of a volume and in this case you should look at the VolumeResampler.
|
||||
///
|
||||
/// \sa VolumeResampler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
LargeVolume<VoxelType>::LargeVolume(const LargeVolume<VoxelType>& /*rhs*/)
|
||||
{
|
||||
assert(false); // See function comment above.
|
||||
POLYVOX_ASSERT(false, "Copy constructor not implemented."); // See function comment above.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -95,7 +100,6 @@ namespace PolyVox
|
||||
LargeVolume<VoxelType>::~LargeVolume()
|
||||
{
|
||||
flushAll();
|
||||
delete[] m_pUncompressedBorderData;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -108,18 +112,41 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
LargeVolume<VoxelType>& LargeVolume<VoxelType>::operator=(const LargeVolume<VoxelType>& /*rhs*/)
|
||||
{
|
||||
assert(false); // See function comment above.
|
||||
POLYVOX_ASSERT(false, "Assignment operator not implemented."); // See function comment above.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// The border value is returned whenever an atempt is made to read a voxel which
|
||||
/// is outside the extents of the volume.
|
||||
/// \return The value used for voxels outside of the volume
|
||||
/// \param uXPos The \c x position of the voxel
|
||||
/// \param uYPos The \c y position of the voxel
|
||||
/// \param uZPos The \c z position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::getBorderValue(void) const
|
||||
VoxelType LargeVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
||||
{
|
||||
return *m_pUncompressedBorderData;
|
||||
POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
|
||||
|
||||
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||
|
||||
const uint16_t xOffset = static_cast<uint16_t>(uXPos - (blockX << m_uBlockSideLengthPower));
|
||||
const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower));
|
||||
const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower));
|
||||
|
||||
Block<VoxelType>* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ);
|
||||
|
||||
return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param v3dPos The 3D position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::getVoxel(const Vector3DInt32& v3dPos) const
|
||||
{
|
||||
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -147,7 +174,7 @@ namespace PolyVox
|
||||
}
|
||||
else
|
||||
{
|
||||
return getBorderValue();
|
||||
return this->getBorderValue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,27 +189,59 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Enabling compression allows significantly more data to be stored in memory.
|
||||
/// \param bCompressionEnabled Specifies whether compression is enabled.
|
||||
/// \param uXPos The \c x position of the voxel
|
||||
/// \param uYPos The \c y position of the voxel
|
||||
/// \param uZPos The \c z position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::setCompressionEnabled(bool bCompressionEnabled)
|
||||
VoxelType LargeVolume<VoxelType>::getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const
|
||||
{
|
||||
//Early out - nothing to do
|
||||
if(m_bCompressionEnabled == bCompressionEnabled)
|
||||
switch(eWrapMode)
|
||||
{
|
||||
return;
|
||||
case WrapModes::Clamp:
|
||||
{
|
||||
//Perform clamping
|
||||
uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX());
|
||||
uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY());
|
||||
uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ());
|
||||
uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX());
|
||||
uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY());
|
||||
uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ());
|
||||
|
||||
//Get the voxel value
|
||||
return getVoxel(uXPos, uYPos, uZPos);
|
||||
//No need to break as we've returned
|
||||
}
|
||||
case WrapModes::Border:
|
||||
{
|
||||
if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos))
|
||||
{
|
||||
return getVoxel(uXPos, uYPos, uZPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
return tBorder;
|
||||
}
|
||||
//No need to break as we've returned
|
||||
}
|
||||
default:
|
||||
{
|
||||
//Should never happen
|
||||
POLYVOX_ASSERT(false, "Invlaid case.");
|
||||
return VoxelType(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_bCompressionEnabled = bCompressionEnabled;
|
||||
|
||||
if(m_bCompressionEnabled)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param v3dPos The 3D position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const
|
||||
{
|
||||
//If compression has been enabled then we need to start honouring the max number of
|
||||
//uncompressed blocks. Because compression has been disabled for a while we might have
|
||||
//gone above that limit. Easiest solution is just to clear the cache and start again.
|
||||
clearBlockCache();
|
||||
}
|
||||
return getVoxelWithWrapping(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -213,17 +272,6 @@ namespace PolyVox
|
||||
m_uMaxNumberOfBlocksInMemory = uMaxNumberOfBlocksInMemory;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param tBorder The value to use for voxels outside the volume.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::setBorderValue(const VoxelType& tBorder)
|
||||
{
|
||||
/*Block<VoxelType>* pUncompressedBorderBlock = getUncompressedBlock(&m_pBorderBlock);
|
||||
return pUncompressedBorderBlock->fill(tBorder);*/
|
||||
std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength, tBorder);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param uXPos the \c x position of the voxel
|
||||
/// \param uYPos the \c y position of the voxel
|
||||
@ -234,7 +282,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
bool LargeVolume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
|
||||
{
|
||||
assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
|
||||
POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
|
||||
|
||||
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
@ -297,7 +345,7 @@ namespace PolyVox
|
||||
for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++)
|
||||
{
|
||||
Vector3DInt32 pos(x,y,z);
|
||||
typename std::map<Vector3DInt32, LoadedBlock>::iterator itBlock = m_pBlocks.find(pos);
|
||||
typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock = m_pBlocks.find(pos);
|
||||
|
||||
if(itBlock != m_pBlocks.end())
|
||||
{
|
||||
@ -328,7 +376,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::flushAll()
|
||||
{
|
||||
typename std::map<Vector3DInt32, LoadedBlock >::iterator i;
|
||||
typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator i;
|
||||
//Replaced the for loop here as the call to
|
||||
//eraseBlock was invalidating the iterator.
|
||||
while(m_pBlocks.size() > 0)
|
||||
@ -362,7 +410,7 @@ namespace PolyVox
|
||||
for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++)
|
||||
{
|
||||
Vector3DInt32 pos(x,y,z);
|
||||
typename std::map<Vector3DInt32, LoadedBlock>::iterator itBlock = m_pBlocks.find(pos);
|
||||
typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock = m_pBlocks.find(pos);
|
||||
if(itBlock == m_pBlocks.end())
|
||||
{
|
||||
// not loaded, not unloading
|
||||
@ -387,7 +435,7 @@ namespace PolyVox
|
||||
{
|
||||
for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++)
|
||||
{
|
||||
m_vecUncompressedBlockCache[ct]->block.compress();
|
||||
m_vecUncompressedBlockCache[ct]->block.compress(m_pCompressor);
|
||||
}
|
||||
m_vecUncompressedBlockCache.clear();
|
||||
}
|
||||
@ -399,42 +447,43 @@ namespace PolyVox
|
||||
void LargeVolume<VoxelType>::initialise(const Region& regValidRegion, uint16_t uBlockSideLength)
|
||||
{
|
||||
//Debug mode validation
|
||||
assert(uBlockSideLength > 0);
|
||||
POLYVOX_ASSERT(uBlockSideLength > 0, "Block side length cannot be zero.");
|
||||
POLYVOX_ASSERT(isPowerOf2(uBlockSideLength), "Block side length must be a power of two.");
|
||||
POLYVOX_ASSERT(m_pCompressor, "You must provide a compressor for the LargeVolume to use.");
|
||||
|
||||
//Release mode validation
|
||||
if(uBlockSideLength == 0)
|
||||
{
|
||||
throw std::invalid_argument("Block side length cannot be zero.");
|
||||
POLYVOX_THROW(std::invalid_argument, "Block side length cannot be zero.");
|
||||
}
|
||||
if(!isPowerOf2(uBlockSideLength))
|
||||
{
|
||||
throw std::invalid_argument("Block side length must be a power of two.");
|
||||
POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two.");
|
||||
}
|
||||
if(!m_pCompressor)
|
||||
{
|
||||
POLYVOX_THROW(std::invalid_argument, "You must provide a compressor for the LargeVolume to use.");
|
||||
}
|
||||
|
||||
m_uTimestamper = 0;
|
||||
m_uMaxNumberOfUncompressedBlocks = 16;
|
||||
m_uBlockSideLength = uBlockSideLength;
|
||||
m_pUncompressedBorderData = 0;
|
||||
m_uMaxNumberOfBlocksInMemory = 1024;
|
||||
m_v3dLastAccessedBlockPos = Vector3DInt32(0,0,0); //There are no invalid positions, but initially the m_pLastAccessedBlock pointer will be null;
|
||||
m_pLastAccessedBlock = 0;
|
||||
m_bCompressionEnabled = true;
|
||||
|
||||
this->m_regValidRegion = regValidRegion;
|
||||
|
||||
//m_regValidRegionInBlocks.setLowerCorner(this->m_regValidRegion.getLowerCorner() / static_cast<int32_t>(uBlockSideLength));
|
||||
//m_regValidRegionInBlocks.setUpperCorner(this->m_regValidRegion.getUpperCorner() / static_cast<int32_t>(uBlockSideLength));
|
||||
//Compute the block side length
|
||||
m_uBlockSideLength = uBlockSideLength;
|
||||
m_uBlockSideLengthPower = logBase2(m_uBlockSideLength);
|
||||
//m_regValidRegionInBlocks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uBlockSideLengthPower);
|
||||
//m_regValidRegionInBlocks.setLowerY(this->m_regValidRegion.getLowerY() >> m_uBlockSideLengthPower);
|
||||
//m_regValidRegionInBlocks.setLowerZ(this->m_regValidRegion.getLowerZ() >> m_uBlockSideLengthPower);
|
||||
m_regValidRegionInBlocks.setLowerCorner(Vector3DInt32(this->m_regValidRegion.getLowerCorner().getX() >> m_uBlockSideLengthPower, this->m_regValidRegion.getLowerCorner().getY() >> m_uBlockSideLengthPower, this->m_regValidRegion.getLowerCorner().getZ() >> m_uBlockSideLengthPower));
|
||||
//m_regValidRegionInBlocks.setUpperX(this->m_regValidRegion.getUpperX() >> m_uBlockSideLengthPower);
|
||||
//m_regValidRegionInBlocks.setUpperY(this->m_regValidRegion.getUpperY() >> m_uBlockSideLengthPower);
|
||||
//m_regValidRegionInBlocks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uBlockSideLengthPower);
|
||||
m_regValidRegionInBlocks.setUpperCorner(Vector3DInt32(this->m_regValidRegion.getUpperCorner().getX() >> m_uBlockSideLengthPower, this->m_regValidRegion.getUpperCorner().getY() >> m_uBlockSideLengthPower, this->m_regValidRegion.getUpperCorner().getZ() >> m_uBlockSideLengthPower));
|
||||
|
||||
m_regValidRegionInBlocks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uBlockSideLengthPower);
|
||||
m_regValidRegionInBlocks.setLowerY(this->m_regValidRegion.getLowerY() >> m_uBlockSideLengthPower);
|
||||
m_regValidRegionInBlocks.setLowerZ(this->m_regValidRegion.getLowerZ() >> m_uBlockSideLengthPower);
|
||||
m_regValidRegionInBlocks.setUpperX(this->m_regValidRegion.getUpperX() >> m_uBlockSideLengthPower);
|
||||
m_regValidRegionInBlocks.setUpperY(this->m_regValidRegion.getUpperY() >> m_uBlockSideLengthPower);
|
||||
m_regValidRegionInBlocks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uBlockSideLengthPower);
|
||||
|
||||
setMaxNumberOfUncompressedBlocks(m_uMaxNumberOfUncompressedBlocks);
|
||||
|
||||
@ -444,10 +493,6 @@ namespace PolyVox
|
||||
//Clear the previous data
|
||||
m_pBlocks.clear();
|
||||
|
||||
//Create the border block
|
||||
m_pUncompressedBorderData = new VoxelType[m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength];
|
||||
std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength, VoxelType());
|
||||
|
||||
//Other properties we might find useful later
|
||||
this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth());
|
||||
this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth());
|
||||
@ -455,7 +500,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::eraseBlock(typename std::map<Vector3DInt32, LoadedBlock >::iterator itBlock) const
|
||||
void LargeVolume<VoxelType>::eraseBlock(typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock) const
|
||||
{
|
||||
if(m_funcDataOverflowHandler)
|
||||
{
|
||||
@ -468,14 +513,15 @@ namespace PolyVox
|
||||
|
||||
m_funcDataOverflowHandler(ConstVolumeProxy, reg);
|
||||
}
|
||||
if(m_bCompressionEnabled) {
|
||||
if(m_pCompressor)
|
||||
{
|
||||
for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++)
|
||||
{
|
||||
// find the block in the uncompressed cache
|
||||
if(m_vecUncompressedBlockCache[ct] == &(itBlock->second))
|
||||
{
|
||||
// TODO: compression is unneccessary? or will not compressing this cause a memleak?
|
||||
itBlock->second.block.compress();
|
||||
itBlock->second.block.compress(m_pCompressor);
|
||||
// put last object in cache here
|
||||
m_vecUncompressedBlockCache[ct] = m_vecUncompressedBlockCache.back();
|
||||
// decrease cache size by one since last element is now in here twice
|
||||
@ -522,11 +568,11 @@ namespace PolyVox
|
||||
//This check should also provide a significant speed boost as usually it is true.
|
||||
if((v3dBlockPos == m_v3dLastAccessedBlockPos) && (m_pLastAccessedBlock != 0))
|
||||
{
|
||||
assert(m_pLastAccessedBlock->m_tUncompressedData);
|
||||
POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data");
|
||||
return m_pLastAccessedBlock;
|
||||
}
|
||||
|
||||
typename std::map<Vector3DInt32, LoadedBlock >::iterator itBlock = m_pBlocks.find(v3dBlockPos);
|
||||
typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock = m_pBlocks.find(v3dBlockPos);
|
||||
// check whether the block is already loaded
|
||||
if(itBlock == m_pBlocks.end())
|
||||
{
|
||||
@ -539,8 +585,8 @@ namespace PolyVox
|
||||
if(m_pBlocks.size() == m_uMaxNumberOfBlocksInMemory)
|
||||
{
|
||||
// find the least recently used block
|
||||
typename std::map<Vector3DInt32, LoadedBlock >::iterator i;
|
||||
typename std::map<Vector3DInt32, LoadedBlock >::iterator itUnloadBlock = m_pBlocks.begin();
|
||||
typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator i;
|
||||
typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itUnloadBlock = m_pBlocks.begin();
|
||||
for(i = m_pBlocks.begin(); i != m_pBlocks.end(); i++)
|
||||
{
|
||||
if(i->second.timestamp < itUnloadBlock->second.timestamp)
|
||||
@ -554,6 +600,12 @@ namespace PolyVox
|
||||
|
||||
// create the new block
|
||||
LoadedBlock newBlock(m_uBlockSideLength);
|
||||
|
||||
// Blocks start out compressed - should we change this?
|
||||
// Or maybe we should just 'seed' them with compressed data,
|
||||
// rather than creating an empty block and then compressing?
|
||||
newBlock.block.compress(m_pCompressor);
|
||||
|
||||
itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first;
|
||||
|
||||
//We have created the new block. If paging is enabled it should be used to
|
||||
@ -582,12 +634,12 @@ namespace PolyVox
|
||||
|
||||
if(loadedBlock.block.m_bIsCompressed == false)
|
||||
{
|
||||
assert(m_pLastAccessedBlock->m_tUncompressedData);
|
||||
POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data");
|
||||
return m_pLastAccessedBlock;
|
||||
}
|
||||
|
||||
//If we are allowed to compress then check whether we need to
|
||||
if((m_bCompressionEnabled) && (m_vecUncompressedBlockCache.size() == m_uMaxNumberOfUncompressedBlocks))
|
||||
if((m_pCompressor) && (m_vecUncompressedBlockCache.size() == m_uMaxNumberOfUncompressedBlocks))
|
||||
{
|
||||
int32_t leastRecentlyUsedBlockIndex = -1;
|
||||
uint32_t uLeastRecentTimestamp = (std::numeric_limits<uint32_t>::max)();
|
||||
@ -605,7 +657,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
//Compress the least recently used block.
|
||||
m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.compress();
|
||||
m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.compress(m_pCompressor);
|
||||
|
||||
//We don't actually remove any elements from this vector, we
|
||||
//simply change the pointer to point at the new uncompressed bloack.
|
||||
@ -616,10 +668,10 @@ namespace PolyVox
|
||||
m_vecUncompressedBlockCache.push_back(&loadedBlock);
|
||||
}
|
||||
|
||||
loadedBlock.block.uncompress();
|
||||
loadedBlock.block.uncompress(m_pCompressor);
|
||||
|
||||
m_pLastAccessedBlock = &(loadedBlock.block);
|
||||
assert(m_pLastAccessedBlock->m_tUncompressedData);
|
||||
POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data");
|
||||
return m_pLastAccessedBlock;
|
||||
}
|
||||
|
||||
@ -629,8 +681,8 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
float LargeVolume<VoxelType>::calculateCompressionRatio(void)
|
||||
{
|
||||
float fRawSize = m_pBlocks.size() * m_uBlockSideLength * m_uBlockSideLength* m_uBlockSideLength * sizeof(VoxelType);
|
||||
float fCompressedSize = calculateSizeInBytes();
|
||||
float fRawSize = static_cast<float>(m_pBlocks.size() * m_uBlockSideLength * m_uBlockSideLength* m_uBlockSideLength * sizeof(VoxelType));
|
||||
float fCompressedSize = static_cast<float>(calculateSizeInBytes());
|
||||
return fCompressedSize/fRawSize;
|
||||
}
|
||||
|
||||
@ -643,7 +695,7 @@ namespace PolyVox
|
||||
uint32_t uSizeInBytes = sizeof(LargeVolume);
|
||||
|
||||
//Memory used by the blocks
|
||||
typename std::map<Vector3DInt32, LoadedBlock >::iterator i;
|
||||
typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator i;
|
||||
for(i = m_pBlocks.begin(); i != m_pBlocks.end(); i++)
|
||||
{
|
||||
//Inaccurate - account for rest of loaded block.
|
||||
@ -654,12 +706,6 @@ namespace PolyVox
|
||||
uSizeInBytes += m_vecUncompressedBlockCache.capacity() * sizeof(LoadedBlock);
|
||||
uSizeInBytes += m_vecUncompressedBlockCache.size() * m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType);
|
||||
|
||||
//Memory used by border data.
|
||||
if(m_pUncompressedBorderData)
|
||||
{
|
||||
uSizeInBytes += m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType);
|
||||
}
|
||||
|
||||
return uSizeInBytes;
|
||||
}
|
||||
|
||||
|
@ -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().getLowerX()) && (val % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerY()) && (val % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerZ()) && (val % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
@ -39,21 +41,6 @@ namespace PolyVox
|
||||
{
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
typename LargeVolume<VoxelType>::Sampler& LargeVolume<VoxelType>::Sampler::operator=(const typename LargeVolume<VoxelType>::Sampler& rhs)
|
||||
{
|
||||
if(this == &rhs)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
this->mVolume = rhs.mVolume;
|
||||
this->mXPosInVolume = rhs.mXPosInVolume;
|
||||
this->mYPosInVolume = rhs.mYPosInVolume;
|
||||
this->mZPosInVolume = rhs.mZPosInVolume;
|
||||
mCurrentVoxel = rhs.mCurrentVoxel;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::getSubSampledVoxel(uint8_t uLevel) const
|
||||
{
|
||||
@ -94,9 +81,16 @@ namespace PolyVox
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::getVoxel(void) const
|
||||
{
|
||||
if(this->isCurrentPositionValid())
|
||||
{
|
||||
return *mCurrentVoxel;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getVoxelAt(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::Sampler::setPosition(const Vector3DInt32& v3dNewPos)
|
||||
@ -107,10 +101,12 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos)
|
||||
{
|
||||
this->mXPosInVolume = xPos;
|
||||
this->mYPosInVolume = yPos;
|
||||
this->mZPosInVolume = zPos;
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::setPosition(xPos, yPos, zPos);
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if(this->isCurrentPositionValid())
|
||||
{
|
||||
const int32_t uXBlock = this->mXPosInVolume >> this->mVolume->m_uBlockSideLengthPower;
|
||||
const int32_t uYBlock = this->mYPosInVolume >> this->mVolume->m_uBlockSideLengthPower;
|
||||
const int32_t uZBlock = this->mZPosInVolume >> this->mVolume->m_uBlockSideLengthPower;
|
||||
@ -123,32 +119,45 @@ namespace PolyVox
|
||||
uYPosInBlock * this->mVolume->m_uBlockSideLength +
|
||||
uZPosInBlock * this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength;
|
||||
|
||||
if(this->mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock)))
|
||||
{
|
||||
Block<VoxelType>* pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock);
|
||||
|
||||
mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock;
|
||||
}
|
||||
else
|
||||
{
|
||||
mCurrentVoxel = this->mVolume->m_pUncompressedBorderData + uVoxelIndexInBlock;
|
||||
mCurrentVoxel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool LargeVolume<VoxelType>::Sampler::setVoxel(VoxelType tValue)
|
||||
{
|
||||
//*mCurrentVoxel = tValue;
|
||||
/*if(m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ)
|
||||
{
|
||||
*mCurrentVoxel = tValue;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}*/
|
||||
|
||||
//Need to think what effect this has on any existing iterators.
|
||||
assert(false);
|
||||
POLYVOX_ASSERT(false, "This function cnnot be used on LargeVolume samplers.");
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::Sampler::movePositiveX(void)
|
||||
{
|
||||
//Note the *pre* increament here
|
||||
if((++this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0)
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::movePositiveX();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
|
||||
{
|
||||
//No need to compute new block.
|
||||
++mCurrentVoxel;
|
||||
@ -163,8 +172,14 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::Sampler::movePositiveY(void)
|
||||
{
|
||||
//Note the *pre* increament here
|
||||
if((++this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0)
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::movePositiveY();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
|
||||
{
|
||||
//No need to compute new block.
|
||||
mCurrentVoxel += this->mVolume->m_uBlockSideLength;
|
||||
@ -179,8 +194,14 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::Sampler::movePositiveZ(void)
|
||||
{
|
||||
//Note the *pre* increament here
|
||||
if((++this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0)
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::movePositiveZ();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
|
||||
{
|
||||
//No need to compute new block.
|
||||
mCurrentVoxel += this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength;
|
||||
@ -195,8 +216,14 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::Sampler::moveNegativeX(void)
|
||||
{
|
||||
//Note the *post* decreament here
|
||||
if((this->mXPosInVolume--) % this->mVolume->m_uBlockSideLength != 0)
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::moveNegativeX();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mXPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
{
|
||||
//No need to compute new block.
|
||||
--mCurrentVoxel;
|
||||
@ -211,8 +238,14 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::Sampler::moveNegativeY(void)
|
||||
{
|
||||
//Note the *post* decreament here
|
||||
if((this->mYPosInVolume--) % this->mVolume->m_uBlockSideLength != 0)
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::moveNegativeY();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mYPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
{
|
||||
//No need to compute new block.
|
||||
mCurrentVoxel -= this->mVolume->m_uBlockSideLength;
|
||||
@ -227,8 +260,14 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void LargeVolume<VoxelType>::Sampler::moveNegativeZ(void)
|
||||
{
|
||||
//Note the *post* decreament here
|
||||
if((this->mZPosInVolume--) % this->mVolume->m_uBlockSideLength != 0)
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::moveNegativeZ();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mZPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
{
|
||||
//No need to compute new block.
|
||||
mCurrentVoxel -= this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength;
|
||||
@ -243,91 +282,91 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
|
||||
{
|
||||
if( BORDER_LOW(this->mXPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -335,87 +374,91 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
|
||||
{
|
||||
if( BORDER_LOW(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
|
||||
{
|
||||
if( BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px0py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()))
|
||||
{
|
||||
return *mCurrentVoxel;
|
||||
}
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
|
||||
{
|
||||
if( BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
|
||||
{
|
||||
if( BORDER_HIGH(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -423,93 +466,97 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
|
||||
{
|
||||
if( BORDER_HIGH(this->mXPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
|
||||
{
|
||||
if( 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);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
|
@ -39,11 +39,11 @@ namespace PolyVox
|
||||
,m_uKernelSize(uKernelSize)
|
||||
{
|
||||
//Kernel size must be at least three
|
||||
assert(m_uKernelSize >= 3);
|
||||
POLYVOX_ASSERT(m_uKernelSize >= 3, "Kernel size must be at least three");
|
||||
m_uKernelSize = std::max(m_uKernelSize, static_cast<uint32_t>(3)); //For release builds
|
||||
|
||||
//Kernel size must be odd
|
||||
assert(m_uKernelSize % 2 == 1);
|
||||
POLYVOX_ASSERT(m_uKernelSize % 2 == 1, "Kernel size must be odd");
|
||||
if(m_uKernelSize % 2 == 0) //For release builds
|
||||
{
|
||||
m_uKernelSize++;
|
||||
@ -53,21 +53,21 @@ namespace PolyVox
|
||||
template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType>
|
||||
void LowPassFilter<SrcVolumeType, DstVolumeType, AccumulationType>::execute()
|
||||
{
|
||||
int32_t iSrcMinX = m_regSrc.getLowerCorner().getX();
|
||||
int32_t iSrcMinY = m_regSrc.getLowerCorner().getY();
|
||||
int32_t iSrcMinZ = m_regSrc.getLowerCorner().getZ();
|
||||
int32_t iSrcMinX = m_regSrc.getLowerX();
|
||||
int32_t iSrcMinY = m_regSrc.getLowerY();
|
||||
int32_t iSrcMinZ = m_regSrc.getLowerZ();
|
||||
|
||||
int32_t iSrcMaxX = m_regSrc.getUpperCorner().getX();
|
||||
int32_t iSrcMaxY = m_regSrc.getUpperCorner().getY();
|
||||
int32_t iSrcMaxZ = m_regSrc.getUpperCorner().getZ();
|
||||
int32_t iSrcMaxX = m_regSrc.getUpperX();
|
||||
int32_t iSrcMaxY = m_regSrc.getUpperY();
|
||||
int32_t iSrcMaxZ = m_regSrc.getUpperZ();
|
||||
|
||||
int32_t iDstMinX = m_regDst.getLowerCorner().getX();
|
||||
int32_t iDstMinY = m_regDst.getLowerCorner().getY();
|
||||
int32_t iDstMinZ = m_regDst.getLowerCorner().getZ();
|
||||
int32_t iDstMinX = m_regDst.getLowerX();
|
||||
int32_t iDstMinY = m_regDst.getLowerY();
|
||||
int32_t iDstMinZ = m_regDst.getLowerZ();
|
||||
|
||||
//int32_t iDstMaxX = m_regDst.getUpperCorner().getX();
|
||||
//int32_t iDstMaxY = m_regDst.getUpperCorner().getY();
|
||||
//int32_t iDstMaxZ = m_regDst.getUpperCorner().getZ();
|
||||
//int32_t iDstMaxX = m_regDst.getUpperX();
|
||||
//int32_t iDstMaxY = m_regDst.getUpperY();
|
||||
//int32_t iDstMaxZ = m_regDst.getUpperZ();
|
||||
|
||||
typename SrcVolumeType::Sampler srcSampler(m_pVolSrc);
|
||||
|
||||
|
@ -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>* 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>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), Controller controller = Controller());
|
||||
#else
|
||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), Controller controller = Controller());
|
||||
#endif
|
||||
|
||||
void execute();
|
||||
|
||||
@ -197,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;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -24,18 +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>* result, Controller controller)
|
||||
MarchingCubesSurfaceExtractor<VolumeType, Controller>::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* 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(eWrapMode, tBorderValue);
|
||||
}
|
||||
|
||||
template<typename VolumeType, typename Controller>
|
||||
@ -43,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.getUpperX() - m_regSizeInVoxels.getLowerX() + 1;
|
||||
const uint32_t uArrayHeight = m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 1;
|
||||
const uint32_t arraySizes[2]= {uArrayWidth, uArrayHeight}; // Array dimensions
|
||||
|
||||
//For edge indices
|
||||
Array2DInt32 m_pPreviousVertexIndicesX(arraySizes);
|
||||
@ -61,7 +62,7 @@ namespace PolyVox
|
||||
//Create a region corresponding to the first slice
|
||||
m_regSlicePrevious = m_regSizeInVoxels;
|
||||
Vector3DInt32 v3dUpperCorner = m_regSlicePrevious.getUpperCorner();
|
||||
v3dUpperCorner.setZ(m_regSlicePrevious.getLowerCorner().getZ()); //Set the upper z to the lower z to make it one slice thick.
|
||||
v3dUpperCorner.setZ(m_regSlicePrevious.getLowerZ()); //Set the upper z to the lower z to make it one slice thick.
|
||||
m_regSlicePrevious.setUpperCorner(v3dUpperCorner);
|
||||
m_regSliceCurrent = m_regSlicePrevious;
|
||||
|
||||
@ -90,7 +91,7 @@ namespace PolyVox
|
||||
m_regSliceCurrent.shift(Vector3DInt32(0,0,1));
|
||||
|
||||
//Process the other slices (previous slice is available)
|
||||
for(int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ(); uSlice++)
|
||||
for(int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ(); uSlice++)
|
||||
{
|
||||
computeBitmaskForSlice<true>(pPreviousBitmask, pCurrentBitmask);
|
||||
uNoOfNonEmptyCellsForSlice1 = m_uNoOfOccupiedCells;
|
||||
@ -133,28 +134,29 @@ namespace PolyVox
|
||||
{
|
||||
m_uNoOfOccupiedCells = 0;
|
||||
|
||||
const int32_t iMaxXVolSpace = m_regSliceCurrent.getUpperCorner().getX();
|
||||
const int32_t iMaxYVolSpace = m_regSliceCurrent.getUpperCorner().getY();
|
||||
const int32_t iMaxXVolSpace = m_regSliceCurrent.getUpperX();
|
||||
const int32_t iMaxYVolSpace = m_regSliceCurrent.getUpperY();
|
||||
|
||||
int32_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ();
|
||||
const int32_t iZVolSpace = m_regSliceCurrent.getLowerZ();
|
||||
|
||||
//Process the lower left corner
|
||||
int32_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY();
|
||||
int32_t iXVolSpace = m_regSliceCurrent.getLowerCorner().getX();
|
||||
int32_t iYVolSpace = m_regSliceCurrent.getLowerY();
|
||||
int32_t iXVolSpace = m_regSliceCurrent.getLowerX();
|
||||
|
||||
uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX();
|
||||
uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY();
|
||||
|
||||
uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
|
||||
m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace);
|
||||
computeBitmaskForCell<false, false, isPrevZAvail>(pPreviousBitmask, pCurrentBitmask, uXRegSpace, uYRegSpace);
|
||||
|
||||
//Process the edge where x is minimal.
|
||||
iXVolSpace = m_regSliceCurrent.getLowerCorner().getX();
|
||||
m_sampVolume.setPosition(iXVolSpace, m_regSliceCurrent.getLowerCorner().getY(), iZVolSpace);
|
||||
for(iYVolSpace = m_regSliceCurrent.getLowerCorner().getY() + 1; iYVolSpace <= iMaxYVolSpace; iYVolSpace++)
|
||||
iXVolSpace = m_regSliceCurrent.getLowerX();
|
||||
m_sampVolume.setPosition(iXVolSpace, m_regSliceCurrent.getLowerY(), iZVolSpace);
|
||||
for(iYVolSpace = m_regSliceCurrent.getLowerY() + 1; iYVolSpace <= iMaxYVolSpace; iYVolSpace++)
|
||||
{
|
||||
uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX();
|
||||
uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY();
|
||||
|
||||
m_sampVolume.movePositiveY();
|
||||
|
||||
@ -162,12 +164,12 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
//Process the edge where y is minimal.
|
||||
iYVolSpace = m_regSliceCurrent.getLowerCorner().getY();
|
||||
m_sampVolume.setPosition(m_regSliceCurrent.getLowerCorner().getX(), iYVolSpace, iZVolSpace);
|
||||
for(iXVolSpace = m_regSliceCurrent.getLowerCorner().getX() + 1; iXVolSpace <= iMaxXVolSpace; iXVolSpace++)
|
||||
iYVolSpace = m_regSliceCurrent.getLowerY();
|
||||
m_sampVolume.setPosition(m_regSliceCurrent.getLowerX(), iYVolSpace, iZVolSpace);
|
||||
for(iXVolSpace = m_regSliceCurrent.getLowerX() + 1; iXVolSpace <= iMaxXVolSpace; iXVolSpace++)
|
||||
{
|
||||
uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX();
|
||||
uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY();
|
||||
|
||||
m_sampVolume.movePositiveX();
|
||||
|
||||
@ -175,13 +177,13 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
//Process all remaining elemnents of the slice. In this case, previous x and y values are always available
|
||||
for(iYVolSpace = m_regSliceCurrent.getLowerCorner().getY() + 1; iYVolSpace <= iMaxYVolSpace; iYVolSpace++)
|
||||
for(iYVolSpace = m_regSliceCurrent.getLowerY() + 1; iYVolSpace <= iMaxYVolSpace; iYVolSpace++)
|
||||
{
|
||||
m_sampVolume.setPosition(m_regSliceCurrent.getLowerCorner().getX(), iYVolSpace, iZVolSpace);
|
||||
for(iXVolSpace = m_regSliceCurrent.getLowerCorner().getX() + 1; iXVolSpace <= iMaxXVolSpace; iXVolSpace++)
|
||||
m_sampVolume.setPosition(m_regSliceCurrent.getLowerX(), iYVolSpace, iZVolSpace);
|
||||
for(iXVolSpace = m_regSliceCurrent.getLowerX() + 1; iXVolSpace <= iMaxXVolSpace; iXVolSpace++)
|
||||
{
|
||||
uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX();
|
||||
uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY();
|
||||
|
||||
m_sampVolume.movePositiveX();
|
||||
|
||||
@ -398,20 +400,20 @@ namespace PolyVox
|
||||
Array2DInt32& m_pCurrentVertexIndicesY,
|
||||
Array2DInt32& m_pCurrentVertexIndicesZ)
|
||||
{
|
||||
int32_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ();
|
||||
const int32_t iZVolSpace = m_regSliceCurrent.getLowerZ();
|
||||
|
||||
//Iterate over each cell in the region
|
||||
for(int32_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY(); iYVolSpace <= m_regSliceCurrent.getUpperCorner().getY(); iYVolSpace++)
|
||||
for(int32_t iYVolSpace = m_regSliceCurrent.getLowerY(); iYVolSpace <= m_regSliceCurrent.getUpperY(); iYVolSpace++)
|
||||
{
|
||||
const uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
const uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY();
|
||||
|
||||
for(int32_t iXVolSpace = m_regSliceCurrent.getLowerCorner().getX(); iXVolSpace <= m_regSliceCurrent.getUpperCorner().getX(); iXVolSpace++)
|
||||
for(int32_t iXVolSpace = m_regSliceCurrent.getLowerX(); iXVolSpace <= m_regSliceCurrent.getUpperX(); iXVolSpace++)
|
||||
{
|
||||
//Current position
|
||||
const uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
const uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX();
|
||||
|
||||
//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)
|
||||
@ -433,9 +435,9 @@ namespace PolyVox
|
||||
const typename VolumeType::VoxelType v100 = m_sampVolume.getVoxel();
|
||||
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()));
|
||||
const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerX()) + fInterp, static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerY()), static_cast<float>(iZVolSpace - m_regSizeInCells.getLowerZ()));
|
||||
|
||||
Vector3DFloat v3dNormal = (n100*fInterp) + (n000*(1-fInterp));
|
||||
v3dNormal.normalise();
|
||||
@ -443,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);
|
||||
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);
|
||||
|
||||
PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex;
|
||||
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
||||
|
||||
m_sampVolume.moveNegativeX();
|
||||
}
|
||||
@ -459,9 +461,9 @@ namespace PolyVox
|
||||
const typename VolumeType::VoxelType v010 = m_sampVolume.getVoxel();
|
||||
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()));
|
||||
const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerX()), static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerY()) + fInterp, static_cast<float>(iZVolSpace - m_regSizeInVoxels.getLowerZ()));
|
||||
|
||||
Vector3DFloat v3dNormal = (n010*fInterp) + (n000*(1-fInterp));
|
||||
v3dNormal.normalise();
|
||||
@ -469,13 +471,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 uMaterial010 = m_controller.convertToMaterial(v010);
|
||||
typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial010);
|
||||
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);
|
||||
|
||||
PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex;
|
||||
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
||||
|
||||
m_sampVolume.moveNegativeY();
|
||||
}
|
||||
@ -485,9 +487,9 @@ namespace PolyVox
|
||||
const typename VolumeType::VoxelType v001 = m_sampVolume.getVoxel();
|
||||
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);
|
||||
const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerX()), static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerY()), static_cast<float>(iZVolSpace - m_regSizeInVoxels.getLowerZ()) + fInterp);
|
||||
|
||||
Vector3DFloat v3dNormal = (n001*fInterp) + (n000*(1-fInterp));
|
||||
v3dNormal.normalise();
|
||||
@ -495,13 +497,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);
|
||||
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);
|
||||
|
||||
PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex;
|
||||
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
||||
|
||||
m_sampVolume.moveNegativeZ();
|
||||
}
|
||||
@ -523,19 +525,20 @@ namespace PolyVox
|
||||
indlist[i] = -1;
|
||||
}
|
||||
|
||||
for(int32_t iYVolSpace = m_regSlicePrevious.getLowerCorner().getY(); iYVolSpace <= m_regSizeInCells.getUpperCorner().getY(); iYVolSpace++)
|
||||
const int32_t iZVolSpace = m_regSlicePrevious.getLowerZ();
|
||||
|
||||
for(int32_t iYVolSpace = m_regSlicePrevious.getLowerY(); iYVolSpace <= m_regSizeInCells.getUpperY(); iYVolSpace++)
|
||||
{
|
||||
for(int32_t iXVolSpace = m_regSlicePrevious.getLowerCorner().getX(); iXVolSpace <= m_regSizeInCells.getUpperCorner().getX(); iXVolSpace++)
|
||||
for(int32_t iXVolSpace = m_regSlicePrevious.getLowerX(); iXVolSpace <= m_regSizeInCells.getUpperX(); iXVolSpace++)
|
||||
{
|
||||
int32_t iZVolSpace = m_regSlicePrevious.getLowerCorner().getZ();
|
||||
m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace);
|
||||
|
||||
//Current position
|
||||
const uint32_t uXRegSpace = m_sampVolume.getPosition().getX() - m_regSizeInVoxels.getLowerCorner().getX();
|
||||
const uint32_t uYRegSpace = m_sampVolume.getPosition().getY() - m_regSizeInVoxels.getLowerCorner().getY();
|
||||
const uint32_t uXRegSpace = m_sampVolume.getPosition().getX() - m_regSizeInVoxels.getLowerX();
|
||||
const uint32_t uYRegSpace = m_sampVolume.getPosition().getY() - m_regSizeInVoxels.getLowerY();
|
||||
|
||||
//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)
|
||||
@ -547,69 +550,57 @@ namespace PolyVox
|
||||
if (edgeTable[iCubeIndex] & 1)
|
||||
{
|
||||
indlist[0] = m_pPreviousVertexIndicesX[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[0] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 2)
|
||||
{
|
||||
indlist[1] = m_pPreviousVertexIndicesY[uXRegSpace+1][uYRegSpace];
|
||||
//assert(indlist[1] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 4)
|
||||
{
|
||||
indlist[2] = m_pPreviousVertexIndicesX[uXRegSpace][uYRegSpace+1];
|
||||
//assert(indlist[2] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 8)
|
||||
{
|
||||
indlist[3] = m_pPreviousVertexIndicesY[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[3] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 16)
|
||||
{
|
||||
indlist[4] = m_pCurrentVertexIndicesX[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[4] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 32)
|
||||
{
|
||||
indlist[5] = m_pCurrentVertexIndicesY[uXRegSpace+1][uYRegSpace];
|
||||
//assert(indlist[5] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 64)
|
||||
{
|
||||
indlist[6] = m_pCurrentVertexIndicesX[uXRegSpace][uYRegSpace+1];
|
||||
//assert(indlist[6] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 128)
|
||||
{
|
||||
indlist[7] = m_pCurrentVertexIndicesY[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[7] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 256)
|
||||
{
|
||||
indlist[8] = m_pPreviousVertexIndicesZ[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[8] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 512)
|
||||
{
|
||||
indlist[9] = m_pPreviousVertexIndicesZ[uXRegSpace+1][uYRegSpace];
|
||||
//assert(indlist[9] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 1024)
|
||||
{
|
||||
indlist[10] = m_pPreviousVertexIndicesZ[uXRegSpace+1][uYRegSpace+1];
|
||||
//assert(indlist[10] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 2048)
|
||||
{
|
||||
indlist[11] = m_pPreviousVertexIndicesZ[uXRegSpace][uYRegSpace+1];
|
||||
//assert(indlist[11] != -1);
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
|
@ -28,8 +28,6 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "PolyVoxCore/DefaultIsQuadNeeded.h" //we'll specialise this function for this voxel type
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
///This class represents a voxel storing only a material.
|
||||
|
@ -42,6 +42,10 @@ namespace PolyVox
|
||||
{
|
||||
public:
|
||||
MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {}
|
||||
|
||||
// FIXME - This is a bit odd... we need to allow the MaterialDensityPair to be initialised with a single integer
|
||||
// because PolyVox often initialises voxels by calling VoxelType(0). Is there a better way we should handle this?
|
||||
MaterialDensityPair(Type tValue) : m_uMaterial(tValue), m_uDensity(tValue) {}
|
||||
MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {}
|
||||
|
||||
bool operator==(const MaterialDensityPair& rhs) const
|
||||
@ -137,6 +141,11 @@ namespace PolyVox
|
||||
return m_tThreshold;
|
||||
}
|
||||
|
||||
void setThreshold(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
}
|
||||
|
||||
private:
|
||||
DensityType m_tThreshold;
|
||||
};
|
||||
|
@ -1,187 +0,0 @@
|
||||
/*******************************************************************************
|
||||
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_MeshDecimator_H__
|
||||
#define __PolyVox_MeshDecimator_H__
|
||||
|
||||
#include "PolyVoxCore/SurfaceMesh.h"
|
||||
#include "PolyVoxCore/Vector.h"
|
||||
#include "PolyVoxCore/VertexTypes.h"
|
||||
|
||||
#include <bitset>
|
||||
#include <vector>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
/// The MeshDecimator reduces the number of triangles in a mesh.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Meshes generated by the PolyVox surface extractors typically have a very high
|
||||
/// number of triangles in them. This can pose difficulties both for the rendering
|
||||
/// storage of such meshes. The MeshDecimator provides a way of reducing the triangle
|
||||
/// count with minimal visual effect.
|
||||
///
|
||||
/// The MeshDecimator is based on the principle of edge collapse, and currently works
|
||||
/// with meshes generated by the MarchingCubesSurfaceExtractor or CubicSurfaceExtractor. It does
|
||||
/// not work with meshes generated by the CubicSurfaceExtractorWithNormals, although
|
||||
/// this may be addressed in the future. The algorithm iterates over each pair of
|
||||
/// connected vertices in the mesh and attemps to determine if they can be collapsed
|
||||
/// into a single vertex.
|
||||
///
|
||||
/// The main criteria used in deciding whether two vertices can collapse is whether
|
||||
/// they have the same normal. In the case of the cubic surfaces the normals must be
|
||||
/// exactly the same, whereas in the case of the Marching Cubes surfaces a threshold
|
||||
/// is used to determine whether two normals are 'close enough'. Additional constraints
|
||||
/// apply to vertices which lie on the edges of regions or on the boundary between two
|
||||
/// regions - these vertices are much less likely to be collapsed.
|
||||
///
|
||||
/// Given a mesh called 'mesh', you can create a decimated version as follows:
|
||||
/// \code
|
||||
/// SurfaceMesh<PositionMaterial> decimatedMesh;
|
||||
/// MeshDecimator<PositionMaterial> decimator(&mesh, &decimatedMesh);
|
||||
/// decimator.execute();
|
||||
/// \endcode
|
||||
///
|
||||
/// The above applies for a cubic mesh, for a Marching Cubes mesh you need to parametise
|
||||
/// the MeshDecimator and resulting SurfaceMesh on the 'PositionMaterialNormal' type
|
||||
/// instead of the 'PositionMaterial' type.
|
||||
///
|
||||
/// \deprecated
|
||||
template <typename VertexType>
|
||||
class MeshDecimator
|
||||
{
|
||||
//Used to keep track of when a vertex is
|
||||
//on one or more faces of the region
|
||||
enum RegionFaceFlags
|
||||
{
|
||||
RFF_ON_REGION_FACE_NEG_X,
|
||||
RFF_ON_REGION_FACE_POS_X ,
|
||||
RFF_ON_REGION_FACE_NEG_Y ,
|
||||
RFF_ON_REGION_FACE_POS_Y ,
|
||||
RFF_ON_REGION_FACE_NEG_Z ,
|
||||
RFF_ON_REGION_FACE_POS_Z,
|
||||
RFF_NO_OF_REGION_FACE_FLAGS
|
||||
};
|
||||
|
||||
//Data about the initial mesh - this
|
||||
//will be fill in once at the start
|
||||
struct InitialVertexMetadata
|
||||
{
|
||||
Vector3DFloat normal;
|
||||
bool isOnMaterialEdge;
|
||||
std::bitset<RFF_NO_OF_REGION_FACE_FLAGS> isOnRegionFace;
|
||||
};
|
||||
|
||||
//Representing a triangle for decimation purposes.
|
||||
struct Triangle
|
||||
{
|
||||
uint32_t v0;
|
||||
uint32_t v1;
|
||||
uint32_t v2;
|
||||
Vector3DFloat normal;
|
||||
};
|
||||
|
||||
struct IntVertex
|
||||
{
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t z;
|
||||
uint32_t index;
|
||||
|
||||
IntVertex(int32_t xVal, int32_t yVal, int32_t zVal, uint32_t indexVal)
|
||||
:x(xVal)
|
||||
,y(yVal)
|
||||
,z(zVal)
|
||||
,index(indexVal)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const IntVertex& rhs) const
|
||||
{
|
||||
return (x == rhs.x) && (y == rhs.y) && (z == rhs.z);
|
||||
}
|
||||
|
||||
bool operator<(const IntVertex& rhs) const
|
||||
{
|
||||
if (z < rhs.z)
|
||||
return true;
|
||||
if (rhs.z < z)
|
||||
return false;
|
||||
|
||||
if (y < rhs.y)
|
||||
return true;
|
||||
if (rhs.y < y)
|
||||
return false;
|
||||
|
||||
if (x < rhs.x)
|
||||
return true;
|
||||
if (rhs.x < x)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
///Constructor
|
||||
POLYVOX_DEPRECATED MeshDecimator(const SurfaceMesh<VertexType>* pInputMesh, SurfaceMesh<VertexType>* pOutputMesh, float fEdgeCollapseThreshold = 0.95f);
|
||||
|
||||
///Performs the decimation.
|
||||
POLYVOX_DEPRECATED void execute();
|
||||
|
||||
private:
|
||||
|
||||
void fillInitialVertexMetadata(std::vector<InitialVertexMetadata>& vecInitialVertexMetadata);
|
||||
|
||||
void buildConnectivityData(void);
|
||||
|
||||
bool attemptEdgeCollapse(uint32_t uSrc, uint32_t uDst);
|
||||
|
||||
const SurfaceMesh<VertexType>* m_pInputMesh;
|
||||
SurfaceMesh<VertexType>* m_pOutputMesh;
|
||||
|
||||
uint32_t performDecimationPass(float m_fMinDotProductForCollapse);
|
||||
bool isSubset(std::bitset<RFF_NO_OF_REGION_FACE_FLAGS> a, std::bitset<RFF_NO_OF_REGION_FACE_FLAGS> b);
|
||||
|
||||
bool canCollapseEdge(uint32_t uSrc, uint32_t uDst);
|
||||
bool canCollapseNormalEdge(uint32_t uSrc, uint32_t uDst);
|
||||
bool canCollapseRegionEdge(uint32_t uSrc, uint32_t uDst);
|
||||
bool canCollapseMaterialEdge(uint32_t uSrc, uint32_t uDst);
|
||||
bool collapseChangesFaceNormals(uint32_t uSrc, uint32_t uDst, float fThreshold);
|
||||
|
||||
//Data structures used during decimation
|
||||
|
||||
std::vector<bool> vertexLocked;
|
||||
std::vector<uint32_t> vertexMapper;
|
||||
|
||||
std::vector<Triangle> m_vecTriangles;
|
||||
std::vector< std::vector<uint32_t> > trianglesUsingVertex; //Should probably use vector of vectors, and resise in advance.
|
||||
|
||||
std::vector<InitialVertexMetadata> m_vecInitialVertexMetadata;
|
||||
|
||||
float m_fMinDotProductForCollapse;
|
||||
};
|
||||
}
|
||||
|
||||
#include "PolyVoxCore/MeshDecimator.inl"
|
||||
|
||||
#endif //__PolyVox_MeshDecimator_H__
|
@ -1,347 +0,0 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Builds a MeshDecimator.
|
||||
/// \param pInputMesh A pointer to the mesh to be decimated.
|
||||
/// \param[out] pOutputMesh A pointer to where the result should be stored. Any existing
|
||||
/// contents will be deleted.
|
||||
/// \param fEdgeCollapseThreshold This is only use in the case of a Marching Cubes
|
||||
/// surface and controls how close two normals must be to collapse. The dot product
|
||||
/// between the normals is computed and compared to this threshold. A threshold of
|
||||
/// 1.0 means nothing will collapse, a threshold of 0.0 means everything will collapse.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VertexType>
|
||||
MeshDecimator<VertexType>::MeshDecimator(const SurfaceMesh<VertexType>* pInputMesh, SurfaceMesh<VertexType>* pOutputMesh, float fEdgeCollapseThreshold)
|
||||
:m_pInputMesh(pInputMesh)
|
||||
,m_pOutputMesh(pOutputMesh)
|
||||
,m_fMinDotProductForCollapse(fEdgeCollapseThreshold)
|
||||
{
|
||||
*m_pOutputMesh = *m_pInputMesh;
|
||||
}
|
||||
|
||||
template <typename VertexType>
|
||||
void MeshDecimator<VertexType>::execute()
|
||||
{
|
||||
//Sanity check.
|
||||
if((m_pOutputMesh->m_vecVertices.empty()) || (m_pOutputMesh->m_vecTriangleIndices.empty()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
buildConnectivityData();
|
||||
fillInitialVertexMetadata(m_vecInitialVertexMetadata);
|
||||
|
||||
uint32_t noOfEdgesCollapsed;
|
||||
do
|
||||
{
|
||||
noOfEdgesCollapsed = performDecimationPass(m_fMinDotProductForCollapse);
|
||||
m_pOutputMesh->removeDegenerateTris();
|
||||
if(noOfEdgesCollapsed > 0)
|
||||
{
|
||||
//Build the connectivity data for the next pass. If this is slow, then look
|
||||
//at adjusting it (based on vertex mapper?) rather than bulding from scratch.
|
||||
buildConnectivityData();
|
||||
}
|
||||
}while(noOfEdgesCollapsed > 0);
|
||||
|
||||
m_pOutputMesh->removeUnusedVertices();
|
||||
|
||||
//Decimation will have invalidated LOD levels.
|
||||
m_pOutputMesh->m_vecLodRecords.clear();
|
||||
LodRecord lodRecord;
|
||||
lodRecord.beginIndex = 0;
|
||||
lodRecord.endIndex = m_pOutputMesh->getNoOfIndices();
|
||||
m_pOutputMesh->m_vecLodRecords.push_back(lodRecord);
|
||||
}
|
||||
|
||||
template <typename VertexType>
|
||||
void MeshDecimator<VertexType>::buildConnectivityData(void)
|
||||
{
|
||||
//Build a list of all the triangles, complete with face normals.
|
||||
m_vecTriangles.clear();
|
||||
m_vecTriangles.resize(m_pOutputMesh->m_vecTriangleIndices.size() / 3);
|
||||
for(uint32_t triCt = 0; triCt < m_vecTriangles.size(); triCt++)
|
||||
{
|
||||
m_vecTriangles[triCt].v0 = m_pOutputMesh->m_vecTriangleIndices[triCt * 3 + 0];
|
||||
m_vecTriangles[triCt].v1 = m_pOutputMesh->m_vecTriangleIndices[triCt * 3 + 1];
|
||||
m_vecTriangles[triCt].v2 = m_pOutputMesh->m_vecTriangleIndices[triCt * 3 + 2];
|
||||
|
||||
Vector3DFloat v0Pos = m_pOutputMesh->m_vecVertices[m_vecTriangles[triCt].v0].position;
|
||||
Vector3DFloat v1Pos = m_pOutputMesh->m_vecVertices[m_vecTriangles[triCt].v1].position;
|
||||
Vector3DFloat v2Pos = m_pOutputMesh->m_vecVertices[m_vecTriangles[triCt].v2].position;
|
||||
|
||||
Vector3DFloat v0v1 = v1Pos - v0Pos;
|
||||
Vector3DFloat v0v2 = v2Pos - v0Pos;
|
||||
Vector3DFloat normal = v0v1.cross(v0v2);
|
||||
normal.normalise();
|
||||
|
||||
m_vecTriangles[triCt].normal = normal;
|
||||
}
|
||||
|
||||
//For each vertex, determine which triangles are using it.
|
||||
trianglesUsingVertex.clear();
|
||||
trianglesUsingVertex.resize(m_pOutputMesh->m_vecVertices.size());
|
||||
for(uint32_t ct = 0; ct < trianglesUsingVertex.size(); ct++)
|
||||
{
|
||||
trianglesUsingVertex[ct].reserve(6);
|
||||
}
|
||||
for(uint32_t ct = 0; ct < m_vecTriangles.size(); ct++)
|
||||
{
|
||||
trianglesUsingVertex[m_vecTriangles[ct].v0].push_back(ct);
|
||||
trianglesUsingVertex[m_vecTriangles[ct].v1].push_back(ct);
|
||||
trianglesUsingVertex[m_vecTriangles[ct].v2].push_back(ct);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VertexType>
|
||||
uint32_t MeshDecimator<VertexType>::performDecimationPass(float /*m_fMinDotProductForCollapse*/)
|
||||
{
|
||||
// Count how many edges we have collapsed
|
||||
uint32_t noOfEdgesCollapsed = 0;
|
||||
|
||||
// The vertex mapper track whick vertices collapse onto which.
|
||||
vertexMapper.clear();
|
||||
vertexMapper.resize(m_pOutputMesh->m_vecVertices.size());
|
||||
|
||||
// Once a vertex is involved in a collapse (either because it
|
||||
// moves onto a different vertex, or because a different vertex
|
||||
// moves onto it) it is forbidden to take part in another collapse
|
||||
// this pass. We enforce this by setting the vertex locked flag.
|
||||
vertexLocked.clear();
|
||||
vertexLocked.resize(m_pOutputMesh->m_vecVertices.size());
|
||||
|
||||
// Initialise the vectors
|
||||
for(uint32_t ct = 0; ct < m_pOutputMesh->m_vecVertices.size(); ct++)
|
||||
{
|
||||
// Initiall all vertices points to themselves
|
||||
vertexMapper[ct] = ct;
|
||||
// All vertices are initially unlocked
|
||||
vertexLocked[ct] = false;
|
||||
}
|
||||
|
||||
//For each triangle...
|
||||
for(uint32_t ctIter = 0; ctIter < m_vecTriangles.size(); ctIter++)
|
||||
{
|
||||
if(attemptEdgeCollapse(m_vecTriangles[ctIter].v0, m_vecTriangles[ctIter].v1))
|
||||
{
|
||||
++noOfEdgesCollapsed;
|
||||
}
|
||||
|
||||
if(attemptEdgeCollapse(m_vecTriangles[ctIter].v1, m_vecTriangles[ctIter].v2))
|
||||
{
|
||||
++noOfEdgesCollapsed;
|
||||
}
|
||||
|
||||
if(attemptEdgeCollapse(m_vecTriangles[ctIter].v2, m_vecTriangles[ctIter].v0))
|
||||
{
|
||||
++noOfEdgesCollapsed;
|
||||
}
|
||||
}
|
||||
|
||||
if(noOfEdgesCollapsed > 0)
|
||||
{
|
||||
//Fix up the indices
|
||||
for(uint32_t triCt = 0; triCt < m_pOutputMesh->m_vecTriangleIndices.size(); triCt++)
|
||||
{
|
||||
uint32_t before = m_pOutputMesh->m_vecTriangleIndices[triCt];
|
||||
uint32_t after = vertexMapper[m_pOutputMesh->m_vecTriangleIndices[triCt]];
|
||||
if(before != after)
|
||||
{
|
||||
m_pOutputMesh->m_vecTriangleIndices[triCt] = vertexMapper[m_pOutputMesh->m_vecTriangleIndices[triCt]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return noOfEdgesCollapsed;
|
||||
}
|
||||
|
||||
template <typename VertexType>
|
||||
bool MeshDecimator<VertexType>::attemptEdgeCollapse(uint32_t uSrc, uint32_t uDst)
|
||||
{
|
||||
//A vertex will be locked if it has already been involved in a collapse this pass.
|
||||
if(vertexLocked[uSrc] || vertexLocked[uDst])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(canCollapseEdge(uSrc, uDst))
|
||||
{
|
||||
//Move v0 onto v1
|
||||
vertexMapper[uSrc] = uDst; //vertexMapper[v1];
|
||||
vertexLocked[uSrc] = true;
|
||||
vertexLocked[uDst] = true;
|
||||
|
||||
//Increment the counter
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename VertexType>
|
||||
bool MeshDecimator<VertexType>::canCollapseEdge(uint32_t uSrc, uint32_t uDst)
|
||||
{
|
||||
bool bCanCollapse = true;
|
||||
|
||||
if(m_vecInitialVertexMetadata[uSrc].isOnMaterialEdge)
|
||||
{
|
||||
bCanCollapse &= canCollapseMaterialEdge(uSrc, uDst);
|
||||
}
|
||||
|
||||
if(m_vecInitialVertexMetadata[uSrc].isOnRegionFace.any())
|
||||
{
|
||||
bCanCollapse &= canCollapseRegionEdge(uSrc, uDst);
|
||||
}
|
||||
|
||||
if(bCanCollapse) //Only bother with this if the earlier tests passed.
|
||||
{
|
||||
bCanCollapse &= canCollapseNormalEdge(uSrc, uDst);
|
||||
}
|
||||
|
||||
return bCanCollapse;
|
||||
}
|
||||
|
||||
template <typename VertexType>
|
||||
bool MeshDecimator<VertexType>::canCollapseRegionEdge(uint32_t uSrc, uint32_t uDst)
|
||||
{
|
||||
// We can collapse normal vertices onto edge vertices, and edge vertices
|
||||
// onto corner vertices, but not vice-versa. Hence we check whether all
|
||||
// the edge flags in the source vertex are also set in the destination vertex.
|
||||
if(isSubset(m_vecInitialVertexMetadata[uSrc].isOnRegionFace, m_vecInitialVertexMetadata[uDst].isOnRegionFace) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// In general adjacent regions surface meshes may collapse differently
|
||||
// and this can cause cracks. We solve this by only allowing the collapse
|
||||
// is the normals are exactly the same. We do not use the user provided
|
||||
// tolerence here (but do allow for floating point error).
|
||||
if(m_vecInitialVertexMetadata[uSrc].normal.dot(m_vecInitialVertexMetadata[uDst].normal) < 0.999f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename VertexType>
|
||||
bool MeshDecimator<VertexType>::canCollapseMaterialEdge(uint32_t /*uSrc*/, uint32_t /*uDst*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//This function should really use some work. For a start we already have the
|
||||
//faces normals for the input mesh yet we are computing them on the fly here.
|
||||
template <typename VertexType>
|
||||
bool MeshDecimator<VertexType>::collapseChangesFaceNormals(uint32_t uSrc, uint32_t uDst, float fThreshold)
|
||||
{
|
||||
bool faceFlipped = false;
|
||||
std::vector<uint32_t>& triangles = trianglesUsingVertex[uSrc];
|
||||
|
||||
for(std::vector<uint32_t>::iterator triIter = triangles.begin(); triIter != triangles.end(); triIter++)
|
||||
{
|
||||
uint32_t tri = *triIter;
|
||||
|
||||
const uint32_t& v0Old = m_pOutputMesh->m_vecTriangleIndices[tri * 3];
|
||||
const uint32_t& v1Old = m_pOutputMesh->m_vecTriangleIndices[tri * 3 + 1];
|
||||
const uint32_t& v2Old = m_pOutputMesh->m_vecTriangleIndices[tri * 3 + 2];
|
||||
|
||||
//Check if degenerate
|
||||
if((v0Old == v1Old) || (v1Old == v2Old) || (v2Old == v0Old))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t v0New = v0Old;
|
||||
uint32_t v1New = v1Old;
|
||||
uint32_t v2New = v2Old;
|
||||
|
||||
if(v0New == uSrc)
|
||||
v0New = uDst;
|
||||
if(v1New == uSrc)
|
||||
v1New = uDst;
|
||||
if(v2New == uSrc)
|
||||
v2New = uDst;
|
||||
|
||||
//Check if degenerate
|
||||
if((v0New == v1New) || (v1New == v2New) || (v2New == v0New))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const Vector3DFloat& v0OldPos = m_pOutputMesh->m_vecVertices[vertexMapper[v0Old]].getPosition(); //Note: we need the vertex mapper here. These neighbouring vertices may have been moved.
|
||||
const Vector3DFloat& v1OldPos = m_pOutputMesh->m_vecVertices[vertexMapper[v1Old]].getPosition();
|
||||
const Vector3DFloat& v2OldPos = m_pOutputMesh->m_vecVertices[vertexMapper[v2Old]].getPosition();
|
||||
|
||||
const Vector3DFloat& v0NewPos = m_pOutputMesh->m_vecVertices[vertexMapper[v0New]].getPosition();
|
||||
const Vector3DFloat& v1NewPos = m_pOutputMesh->m_vecVertices[vertexMapper[v1New]].getPosition();
|
||||
const Vector3DFloat& v2NewPos = m_pOutputMesh->m_vecVertices[vertexMapper[v2New]].getPosition();
|
||||
|
||||
Vector3DFloat OldNormal = (v1OldPos - v0OldPos).cross(v2OldPos - v1OldPos);
|
||||
Vector3DFloat NewNormal = (v1NewPos - v0NewPos).cross(v2NewPos - v1NewPos);
|
||||
|
||||
OldNormal.normalise();
|
||||
NewNormal.normalise();
|
||||
|
||||
float dotProduct = OldNormal.dot(NewNormal);
|
||||
//NOTE: I don't think we should be using the threshold here, we're just checking for a complete face flip
|
||||
if(dotProduct < fThreshold)
|
||||
{
|
||||
//cout << " Face flipped!!" << endl;
|
||||
|
||||
faceFlipped = true;
|
||||
|
||||
/*vertexLocked[v0] = true;
|
||||
vertexLocked[v1] = true;*/
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return faceFlipped;
|
||||
}
|
||||
|
||||
// Returns true if every bit which is set in 'a' is also set in 'b'. The reverse does not need to be true.
|
||||
template <typename VertexType>
|
||||
bool MeshDecimator<VertexType>::isSubset(std::bitset<RFF_NO_OF_REGION_FACE_FLAGS> a, std::bitset<RFF_NO_OF_REGION_FACE_FLAGS> b)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
for(int ct = 0; ct < RFF_NO_OF_REGION_FACE_FLAGS; ct++)
|
||||
{
|
||||
if(a.test(ct))
|
||||
{
|
||||
if(b.test(ct) == false)
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
28
library/PolyVoxCore/include/PolyVoxCore/MinizCompressor.h
Normal file
28
library/PolyVoxCore/include/PolyVoxCore/MinizCompressor.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef __PolyVox_MinizCompressor_H__
|
||||
#define __PolyVox_MinizCompressor_H__
|
||||
|
||||
#include "PolyVoxCore/Compressor.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class MinizCompressor : public Compressor
|
||||
{
|
||||
public:
|
||||
MinizCompressor(int iCompressionLevel = 6); // Miniz defines MZ_DEFAULT_LEVEL = 6 so we use the same here
|
||||
~MinizCompressor();
|
||||
|
||||
uint32_t getMaxCompressedSize(uint32_t uUncompressedInputSize);
|
||||
uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
|
||||
uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
|
||||
|
||||
private:
|
||||
unsigned int m_uCompressionFlags;
|
||||
|
||||
// tdefl_compressor contains all the state needed by the low-level compressor so it's a pretty big struct (~300k).
|
||||
// We're storing it by void* because miniz does not supply a header and we don't want to include the .c file from
|
||||
// here as it will cause linker problems.
|
||||
void* m_pDeflator;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //__PolyVox_MinizCompressor_H__
|
@ -60,10 +60,16 @@ namespace PolyVox
|
||||
typedef Array<3,int32_t> Array3DInt32;
|
||||
typedef Array<3,uint32_t> Array3DUint32;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Compressor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class Compressor;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// CubicSurfaceExtractor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template< typename VolumeType> class CubicSurfaceExtractor;
|
||||
template<typename VoxelType> class DefaultIsQuadNeeded;
|
||||
template<typename VolumeType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> > class CubicSurfaceExtractor;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Density
|
||||
@ -126,6 +132,11 @@ namespace PolyVox
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class Region;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// SimpleVolume
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType> class SimpleVolume;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// MarchingCubesSurfaceExtractor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -139,15 +150,34 @@ namespace PolyVox
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Vector
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <uint32_t Size, typename Type> class Vector;
|
||||
typedef Vector<3,float> Vector3DFloat;
|
||||
typedef Vector<3,double> Vector3DDouble;
|
||||
typedef Vector<3,int8_t> Vector3DInt8;
|
||||
typedef Vector<3,uint8_t> Vector3DUint8;
|
||||
typedef Vector<3,int16_t> Vector3DInt16;
|
||||
typedef Vector<3,uint16_t> Vector3DUint16;
|
||||
typedef Vector<3,int32_t> Vector3DInt32;
|
||||
typedef Vector<3,uint32_t> Vector3DUint32;
|
||||
template <uint32_t Size, typename StorageType, typename OperationType = StorageType> class Vector;
|
||||
|
||||
typedef Vector<2,float,float> Vector2DFloat;
|
||||
typedef Vector<2,double,double> Vector2DDouble;
|
||||
typedef Vector<2,int8_t,int32_t> Vector2DInt8;
|
||||
typedef Vector<2,uint8_t,int32_t> Vector2DUint8;
|
||||
typedef Vector<2,int16_t,int32_t> Vector2DInt16;
|
||||
typedef Vector<2,uint16_t,int32_t> Vector2DUint16;
|
||||
typedef Vector<2,int32_t,int32_t> Vector2DInt32;
|
||||
typedef Vector<2,uint32_t,int32_t> Vector2DUint32;
|
||||
|
||||
typedef Vector<3,float,float> Vector3DFloat;
|
||||
typedef Vector<3,double,double> Vector3DDouble;
|
||||
typedef Vector<3,int8_t,int32_t> Vector3DInt8;
|
||||
typedef Vector<3,uint8_t,int32_t> Vector3DUint8;
|
||||
typedef Vector<3,int16_t,int32_t> Vector3DInt16;
|
||||
typedef Vector<3,uint16_t,int32_t> Vector3DUint16;
|
||||
typedef Vector<3,int32_t,int32_t> Vector3DInt32;
|
||||
typedef Vector<3,uint32_t,int32_t> Vector3DUint32;
|
||||
|
||||
typedef Vector<4,float,float> Vector4DFloat;
|
||||
typedef Vector<4,double,double> Vector4DDouble;
|
||||
typedef Vector<4,int8_t,int32_t> Vector4DInt8;
|
||||
typedef Vector<4,uint8_t,int32_t> Vector4DUint8;
|
||||
typedef Vector<4,int16_t,int32_t> Vector4DInt16;
|
||||
typedef Vector<4,uint16_t,int32_t> Vector4DUint16;
|
||||
typedef Vector<4,int32_t,int32_t> Vector4DInt32;
|
||||
typedef Vector<4,uint32_t,int32_t> Vector4DUint32;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
28
library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h
Normal file
28
library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef __PolyVox_RLECompressor_H__
|
||||
#define __PolyVox_RLECompressor_H__
|
||||
|
||||
#include "PolyVoxCore/Compressor.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template<typename ValueType, typename LengthType>
|
||||
class RLECompressor : public Compressor
|
||||
{
|
||||
struct Run
|
||||
{
|
||||
ValueType value;
|
||||
LengthType length;
|
||||
};
|
||||
public:
|
||||
RLECompressor();
|
||||
~RLECompressor();
|
||||
|
||||
uint32_t getMaxCompressedSize(uint32_t uUncompressedInputSize);
|
||||
uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
|
||||
uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
|
||||
};
|
||||
}
|
||||
|
||||
#include "RLECompressor.inl"
|
||||
|
||||
#endif //__PolyVox_RLECompressor_H__
|
126
library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl
Normal file
126
library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl
Normal file
@ -0,0 +1,126 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template<typename ValueType, typename LengthType>
|
||||
RLECompressor<ValueType, LengthType>::RLECompressor()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename ValueType, typename LengthType>
|
||||
RLECompressor<ValueType, LengthType>::~RLECompressor()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename ValueType, typename LengthType>
|
||||
uint32_t RLECompressor<ValueType, LengthType>::getMaxCompressedSize(uint32_t uUncompressedInputSize)
|
||||
{
|
||||
// In the worst case we will have a seperate Run (of length one) for each element of the input data.
|
||||
return uUncompressedInputSize * sizeof(Run);
|
||||
}
|
||||
|
||||
template<typename ValueType, typename LengthType>
|
||||
uint32_t RLECompressor<ValueType, LengthType>::compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
|
||||
{
|
||||
if(uSrcLength % sizeof(ValueType) != 0)
|
||||
{
|
||||
POLYVOX_THROW(std::length_error, "Source length must be a integer multiple of the ValueType size");
|
||||
}
|
||||
|
||||
// Lengths provided are in bytes, so convert them to be in terms of our types.
|
||||
uSrcLength /= sizeof(ValueType);
|
||||
uDstLength /= sizeof(Run);
|
||||
|
||||
// Get data pointers in the appropriate type
|
||||
ValueType* pSrcDataAsType = reinterpret_cast<ValueType*>(pSrcData);
|
||||
Run* pDstDataAsRun = reinterpret_cast<Run*>(pDstData);
|
||||
|
||||
// Pointers to just past the end of the data
|
||||
ValueType* pSrcDataEnd = pSrcDataAsType + uSrcLength;
|
||||
Run* pDstDataEnd = pDstDataAsRun + uDstLength;
|
||||
|
||||
//Counter for the output length
|
||||
uint32_t uDstLengthInBytes = 0;
|
||||
|
||||
// Read the first element of the source and set up the first run based on it.
|
||||
pDstDataAsRun->value = *pSrcDataAsType;
|
||||
pSrcDataAsType++;
|
||||
pDstDataAsRun->length = 1;
|
||||
uDstLengthInBytes += sizeof(Run);
|
||||
|
||||
//Now process all remaining elements of the source.
|
||||
while(pSrcDataAsType < pSrcDataEnd)
|
||||
{
|
||||
// If the value is the same as the current run (and we have not
|
||||
// reached the maximum run length) then extend the current run.
|
||||
if((*pSrcDataAsType == pDstDataAsRun->value) && (pDstDataAsRun->length < (std::numeric_limits<LengthType>::max)()))
|
||||
{
|
||||
pDstDataAsRun->length++;
|
||||
}
|
||||
// Otherwise we need to start a new Run.
|
||||
else
|
||||
{
|
||||
pDstDataAsRun++;
|
||||
|
||||
// Check if we have enough space in the destination buffer.
|
||||
if(pDstDataAsRun >= pDstDataEnd)
|
||||
{
|
||||
POLYVOX_THROW(std::runtime_error, "Insufficient space in destination buffer.");
|
||||
}
|
||||
|
||||
// Create the new run.
|
||||
pDstDataAsRun->value = *pSrcDataAsType;
|
||||
pDstDataAsRun->length = 1;
|
||||
uDstLengthInBytes += sizeof(Run);
|
||||
}
|
||||
|
||||
pSrcDataAsType++;
|
||||
}
|
||||
|
||||
return uDstLengthInBytes;
|
||||
}
|
||||
|
||||
template<typename ValueType, typename LengthType>
|
||||
uint32_t RLECompressor<ValueType, LengthType>::decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
|
||||
{
|
||||
if(uSrcLength % sizeof(Run) != 0)
|
||||
{
|
||||
POLYVOX_THROW(std::length_error, "Source length must be a integer multiple of the Run size");
|
||||
}
|
||||
|
||||
// Lengths provided are in bytes, so convert them to be in terms of our types.
|
||||
uSrcLength /= sizeof(Run);
|
||||
uDstLength /= sizeof(ValueType);
|
||||
|
||||
// Get data pointers in the appropriate type
|
||||
Run* pSrcDataAsRun = reinterpret_cast<Run*>(pSrcData);
|
||||
ValueType* pDstDataAsType = reinterpret_cast<ValueType*>(pDstData);
|
||||
|
||||
// Pointers to just past the end of the data
|
||||
Run* pSrcDataEnd = pSrcDataAsRun + uSrcLength;
|
||||
ValueType* pDstDataEnd = pDstDataAsType + uDstLength;
|
||||
|
||||
//Counter for the output length
|
||||
uint32_t uDstLengthInBytes = 0;
|
||||
|
||||
while(pSrcDataAsRun < pSrcDataEnd)
|
||||
{
|
||||
// Check if we have enough space in the destination buffer.
|
||||
if(pDstDataAsType + pSrcDataAsRun->length > pDstDataEnd)
|
||||
{
|
||||
POLYVOX_THROW(std::runtime_error, "Insufficient space in destination buffer.");
|
||||
}
|
||||
|
||||
// Write the run into the destination
|
||||
std::fill(pDstDataAsType, pDstDataAsType + pSrcDataAsRun->length, pSrcDataAsRun->value);
|
||||
pDstDataAsType += pSrcDataAsRun->length;
|
||||
|
||||
uDstLengthInBytes += pSrcDataAsRun->length * sizeof(ValueType);
|
||||
pSrcDataAsRun++;
|
||||
}
|
||||
|
||||
return uDstLengthInBytes;
|
||||
}
|
||||
}
|
@ -29,7 +29,6 @@ freely, subject to the following restrictions:
|
||||
#include "PolyVoxCore/Region.h"
|
||||
#include "PolyVoxCore/Vector.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib> //For abort()
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
@ -104,14 +103,9 @@ namespace PolyVox
|
||||
inline VoxelType peekVoxel1px1py1pz(void) const;
|
||||
|
||||
private:
|
||||
|
||||
//Other current position information
|
||||
VoxelType* mCurrentVoxel;
|
||||
|
||||
//Whether the current position is inside the volume
|
||||
//FIXME - Replace these with flags
|
||||
bool m_bIsCurrentPositionValidInX;
|
||||
bool m_bIsCurrentPositionValidInY;
|
||||
bool m_bIsCurrentPositionValidInZ;
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -122,15 +116,19 @@ namespace PolyVox
|
||||
/// Destructor
|
||||
~RawVolume();
|
||||
|
||||
/// Gets the value used for voxels which are outside the volume
|
||||
VoxelType getBorderValue(void) const;
|
||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||
/// Gets a voxel at the position given by a 3D vector
|
||||
VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
|
||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||
/// Gets a voxel at the position given by a 3D vector
|
||||
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||
/// Gets a voxel at the position given by a 3D vector
|
||||
VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||
|
||||
/// Sets the value used for voxels which are outside the volume
|
||||
void setBorderValue(const VoxelType& tBorder);
|
||||
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
|
||||
/// Sets the voxel at the position given by a 3D vector
|
||||
@ -151,9 +149,6 @@ namespace PolyVox
|
||||
|
||||
//The block data
|
||||
VoxelType* m_pData;
|
||||
|
||||
//The border value
|
||||
VoxelType m_tBorderValue;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
@ -47,7 +47,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
RawVolume<VoxelType>::RawVolume(const RawVolume<VoxelType>& /*rhs*/)
|
||||
{
|
||||
assert(false); // See function comment above.
|
||||
POLYVOX_ASSERT(false, "Copy constructor not implemented."); // See function comment above.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -70,18 +70,41 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
RawVolume<VoxelType>& RawVolume<VoxelType>::operator=(const RawVolume<VoxelType>& /*rhs*/)
|
||||
{
|
||||
assert(false); // See function comment above.
|
||||
POLYVOX_ASSERT(false, "Assignment operator not implemented."); // See function comment above.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// The border value is returned whenever an attempt is made to read a voxel which
|
||||
/// is outside the extents of the volume.
|
||||
/// \return The value used for voxels outside of the volume
|
||||
/// \param uXPos The \c x position of the voxel
|
||||
/// \param uYPos The \c y position of the voxel
|
||||
/// \param uZPos The \c z position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::getBorderValue(void) const
|
||||
VoxelType RawVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
||||
{
|
||||
return m_tBorderValue;
|
||||
POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
|
||||
|
||||
const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
|
||||
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
|
||||
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
|
||||
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
|
||||
|
||||
return m_pData
|
||||
[
|
||||
iLocalXPos +
|
||||
iLocalYPos * this->getWidth() +
|
||||
iLocalZPos * this->getWidth() * this->getHeight()
|
||||
];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param v3dPos The 3D position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::getVoxel(const Vector3DInt32& v3dPos) const
|
||||
{
|
||||
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -124,12 +147,59 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param tBorder The value to use for voxels outside the volume.
|
||||
/// \param uXPos The \c x position of the voxel
|
||||
/// \param uYPos The \c y position of the voxel
|
||||
/// \param uZPos The \c z position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
void RawVolume<VoxelType>::setBorderValue(const VoxelType& tBorder)
|
||||
VoxelType RawVolume<VoxelType>::getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const
|
||||
{
|
||||
m_tBorderValue = tBorder;
|
||||
switch(eWrapMode)
|
||||
{
|
||||
case WrapModes::Clamp:
|
||||
{
|
||||
//Perform clamping
|
||||
uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX());
|
||||
uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY());
|
||||
uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ());
|
||||
uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX());
|
||||
uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY());
|
||||
uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ());
|
||||
|
||||
//Get the voxel value
|
||||
return getVoxel(uXPos, uYPos, uZPos);
|
||||
//No need to break as we've returned
|
||||
}
|
||||
case WrapModes::Border:
|
||||
{
|
||||
if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos))
|
||||
{
|
||||
return getVoxel(uXPos, uYPos, uZPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
return tBorder;
|
||||
}
|
||||
//No need to break as we've returned
|
||||
}
|
||||
default:
|
||||
{
|
||||
//Should never happen
|
||||
POLYVOX_ASSERT(false, "Invalid case.");
|
||||
return VoxelType(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param v3dPos The 3D position of the voxel
|
||||
/// \return The voxel value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const
|
||||
{
|
||||
return getVoxelWithWrapping(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -185,9 +255,9 @@ namespace PolyVox
|
||||
this->m_regValidRegion = regValidRegion;
|
||||
|
||||
//Ensure dimensions of the specified Region are valid
|
||||
assert(this->getWidth() > 0);
|
||||
assert(this->getHeight() > 0);
|
||||
assert(this->getDepth() > 0);
|
||||
POLYVOX_ASSERT(this->getWidth() > 0, "Volume width must be greater than zero.");
|
||||
POLYVOX_ASSERT(this->getHeight() > 0, "Volume width must be greater than zero.");
|
||||
POLYVOX_ASSERT(this->getDepth() > 0, "Volume width must be greater than zero.");
|
||||
|
||||
//Create the data
|
||||
m_pData = new VoxelType[this->getWidth() * this->getHeight()* this->getDepth()];
|
||||
|
@ -21,12 +21,12 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#define BORDER_LOWX(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getX())
|
||||
#define BORDER_HIGHX(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getX())
|
||||
#define BORDER_LOWY(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getY())
|
||||
#define BORDER_HIGHY(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getY())
|
||||
#define BORDER_LOWZ(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ())
|
||||
#define BORDER_HIGHZ(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ())
|
||||
#define CAN_GO_NEG_X(val) (val > this->mVolume->getEnclosingRegion().getLowerX())
|
||||
#define CAN_GO_POS_X(val) (val < this->mVolume->getEnclosingRegion().getUpperX())
|
||||
#define CAN_GO_NEG_Y(val) (val > this->mVolume->getEnclosingRegion().getLowerY())
|
||||
#define CAN_GO_POS_Y(val) (val < this->mVolume->getEnclosingRegion().getUpperY())
|
||||
#define CAN_GO_NEG_Z(val) (val > this->mVolume->getEnclosingRegion().getLowerZ())
|
||||
#define CAN_GO_POS_Z(val) (val < this->mVolume->getEnclosingRegion().getUpperZ())
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
@ -34,9 +34,6 @@ namespace PolyVox
|
||||
RawVolume<VoxelType>::Sampler::Sampler(RawVolume<VoxelType>* volume)
|
||||
:BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >(volume)
|
||||
,mCurrentVoxel(0)
|
||||
,m_bIsCurrentPositionValidInX(false)
|
||||
,m_bIsCurrentPositionValidInY(false)
|
||||
,m_bIsCurrentPositionValidInZ(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -48,7 +45,14 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::getVoxel(void) const
|
||||
{
|
||||
return (m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ) ? *mCurrentVoxel : this->mVolume->getBorderValue();
|
||||
if(this->isCurrentPositionValid())
|
||||
{
|
||||
return *mCurrentVoxel;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getVoxelAt(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
@ -60,10 +64,12 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void RawVolume<VoxelType>::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos)
|
||||
{
|
||||
this->mXPosInVolume = xPos;
|
||||
this->mYPosInVolume = yPos;
|
||||
this->mZPosInVolume = zPos;
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::setPosition(xPos, yPos, zPos);
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if(this->isCurrentPositionValid())
|
||||
{
|
||||
const Vector3DInt32& v3dLowerCorner = this->mVolume->m_regValidRegion.getLowerCorner();
|
||||
int32_t iLocalXPos = xPos - v3dLowerCorner.getX();
|
||||
int32_t iLocalYPos = yPos - v3dLowerCorner.getY();
|
||||
@ -74,17 +80,18 @@ namespace PolyVox
|
||||
iLocalZPos * this->mVolume->getWidth() * this->mVolume->getHeight();
|
||||
|
||||
mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex;
|
||||
|
||||
m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(xPos);
|
||||
m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(yPos);
|
||||
m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(zPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
mCurrentVoxel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool RawVolume<VoxelType>::Sampler::setVoxel(VoxelType tValue)
|
||||
{
|
||||
//return m_bIsCurrentPositionValid ? *mCurrentVoxel : this->mVolume->getBorderValue();
|
||||
if(m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ)
|
||||
if(this->m_bIsCurrentPositionValidInX && this->m_bIsCurrentPositionValidInY && this->m_bIsCurrentPositionValidInZ)
|
||||
{
|
||||
*mCurrentVoxel = tValue;
|
||||
return true;
|
||||
@ -98,139 +105,211 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void RawVolume<VoxelType>::Sampler::movePositiveX(void)
|
||||
{
|
||||
this->mXPosInVolume++;
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::movePositiveX();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if(this->isCurrentPositionValid() && bIsOldPositionValid )
|
||||
{
|
||||
++mCurrentVoxel;
|
||||
m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void RawVolume<VoxelType>::Sampler::movePositiveY(void)
|
||||
{
|
||||
this->mYPosInVolume++;
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::movePositiveY();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if(this->isCurrentPositionValid() && bIsOldPositionValid )
|
||||
{
|
||||
mCurrentVoxel += this->mVolume->getWidth();
|
||||
m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void RawVolume<VoxelType>::Sampler::movePositiveZ(void)
|
||||
{
|
||||
this->mZPosInVolume++;
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::movePositiveZ();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if(this->isCurrentPositionValid() && bIsOldPositionValid )
|
||||
{
|
||||
mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight();
|
||||
m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void RawVolume<VoxelType>::Sampler::moveNegativeX(void)
|
||||
{
|
||||
this->mXPosInVolume--;
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::moveNegativeX();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if(this->isCurrentPositionValid() && bIsOldPositionValid )
|
||||
{
|
||||
--mCurrentVoxel;
|
||||
m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void RawVolume<VoxelType>::Sampler::moveNegativeY(void)
|
||||
{
|
||||
this->mYPosInVolume--;
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::moveNegativeY();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if(this->isCurrentPositionValid() && bIsOldPositionValid )
|
||||
{
|
||||
mCurrentVoxel -= this->mVolume->getWidth();
|
||||
m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void RawVolume<VoxelType>::Sampler::moveNegativeZ(void)
|
||||
{
|
||||
this->mZPosInVolume--;
|
||||
// We'll need this in a moment...
|
||||
bool bIsOldPositionValid = this->isCurrentPositionValid();
|
||||
|
||||
// Base version updates position and validity flags.
|
||||
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::moveNegativeZ();
|
||||
|
||||
// Then we update the voxel pointer
|
||||
if(this->isCurrentPositionValid() && bIsOldPositionValid )
|
||||
{
|
||||
mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight();
|
||||
m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
|
||||
{
|
||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(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->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
|
||||
{
|
||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->getWidth());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
|
||||
{
|
||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(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->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
|
||||
{
|
||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
|
||||
{
|
||||
if( BORDER_LOWX(this->mXPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
|
||||
{
|
||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
|
||||
{
|
||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(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->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
|
||||
{
|
||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->getWidth());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
|
||||
{
|
||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(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->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -238,87 +317,91 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
|
||||
{
|
||||
if( BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
|
||||
{
|
||||
if( BORDER_LOWY(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->getWidth());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
|
||||
{
|
||||
if( BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
|
||||
{
|
||||
if( BORDER_LOWZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()))
|
||||
{
|
||||
return *mCurrentVoxel;
|
||||
}
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
|
||||
{
|
||||
if( BORDER_HIGHZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
|
||||
{
|
||||
if( BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
|
||||
{
|
||||
if( BORDER_HIGHY(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->getWidth());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
|
||||
{
|
||||
if( BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -326,97 +409,97 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
|
||||
{
|
||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(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->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
|
||||
{
|
||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->getWidth());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
|
||||
{
|
||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(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->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
|
||||
{
|
||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
|
||||
{
|
||||
if( BORDER_HIGHX(this->mXPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1);
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
|
||||
{
|
||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
|
||||
{
|
||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(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->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
|
||||
{
|
||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->getWidth());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
|
||||
{
|
||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(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->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||
}
|
||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
||||
return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder);
|
||||
}
|
||||
}
|
||||
|
||||
#undef BORDER_LOWX
|
||||
#undef BORDER_HIGHX
|
||||
#undef BORDER_LOWY
|
||||
#undef BORDER_HIGHY
|
||||
#undef BORDER_LOWZ
|
||||
#undef BORDER_HIGHZ
|
||||
#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
|
||||
|
@ -76,34 +76,34 @@ namespace PolyVox
|
||||
//The doRaycast function is assuming that it is iterating over the areas defined between
|
||||
//voxels. We actually want to define the areas as being centered on voxels (as this is
|
||||
//what the CubicSurfaceExtractor generates). We add 0.5 here to adjust for this.
|
||||
float x1 = v3dStart.getX() + 0.5f;
|
||||
float y1 = v3dStart.getY() + 0.5f;
|
||||
float z1 = v3dStart.getZ() + 0.5f;
|
||||
float x2 = v3dEnd.getX() + 0.5f;
|
||||
float y2 = v3dEnd.getY() + 0.5f;
|
||||
float z2 = v3dEnd.getZ() + 0.5f;
|
||||
const float x1 = v3dStart.getX() + 0.5f;
|
||||
const float y1 = v3dStart.getY() + 0.5f;
|
||||
const float z1 = v3dStart.getZ() + 0.5f;
|
||||
const float x2 = v3dEnd.getX() + 0.5f;
|
||||
const float y2 = v3dEnd.getY() + 0.5f;
|
||||
const float z2 = v3dEnd.getZ() + 0.5f;
|
||||
|
||||
int i = (int)floorf(x1);
|
||||
int j = (int)floorf(y1);
|
||||
int k = (int)floorf(z1);
|
||||
|
||||
int iend = (int)floorf(x2);
|
||||
int jend = (int)floorf(y2);
|
||||
int kend = (int)floorf(z2);
|
||||
const int iend = (int)floorf(x2);
|
||||
const int jend = (int)floorf(y2);
|
||||
const int kend = (int)floorf(z2);
|
||||
|
||||
int di = ((x1 < x2) ? 1 : ((x1 > x2) ? -1 : 0));
|
||||
int dj = ((y1 < y2) ? 1 : ((y1 > y2) ? -1 : 0));
|
||||
int dk = ((z1 < z2) ? 1 : ((z1 > z2) ? -1 : 0));
|
||||
const int di = ((x1 < x2) ? 1 : ((x1 > x2) ? -1 : 0));
|
||||
const int dj = ((y1 < y2) ? 1 : ((y1 > y2) ? -1 : 0));
|
||||
const int dk = ((z1 < z2) ? 1 : ((z1 > z2) ? -1 : 0));
|
||||
|
||||
float deltatx = 1.0f / std::abs(x2 - x1);
|
||||
float deltaty = 1.0f / std::abs(y2 - y1);
|
||||
float deltatz = 1.0f / std::abs(z2 - z1);
|
||||
const float deltatx = 1.0f / std::abs(x2 - x1);
|
||||
const float deltaty = 1.0f / std::abs(y2 - y1);
|
||||
const float deltatz = 1.0f / std::abs(z2 - z1);
|
||||
|
||||
float minx = floorf(x1), maxx = minx + 1.0f;
|
||||
const float minx = floorf(x1), maxx = minx + 1.0f;
|
||||
float tx = ((x1 > x2) ? (x1 - minx) : (maxx - x1)) * deltatx;
|
||||
float miny = floorf(y1), maxy = miny + 1.0f;
|
||||
const float miny = floorf(y1), maxy = miny + 1.0f;
|
||||
float ty = ((y1 > y2) ? (y1 - miny) : (maxy - y1)) * deltaty;
|
||||
float minz = floorf(z1), maxz = minz + 1.0f;
|
||||
const float minz = floorf(z1), maxz = minz + 1.0f;
|
||||
float tz = ((z1 > z2) ? (z1 - minz) : (maxz - z1)) * deltatz;
|
||||
|
||||
sampler.setPosition(i,j,k);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user