Merge branch 'develop' into feature/cubiquity-version
Conflicts: library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl library/PolyVoxCore/include/PolyVoxCore/Vector.inl library/PolyVoxCore/source/Impl/Utility.cpp
This commit is contained in:
@ -20,10 +20,13 @@
|
||||
# 3. This notice may not be removed or altered from any source
|
||||
# distribution.
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
||||
|
||||
PROJECT(PolyVoxCore)
|
||||
|
||||
if(NOT MSVC)
|
||||
#Set up the C++11 feature header file based on the CheckCXX11Features script
|
||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/PolyVoxCore/Impl/CompilerCapabilities.h)
|
||||
endif()
|
||||
|
||||
#Projects source files
|
||||
SET(CORE_SRC_FILES
|
||||
source/ArraySizes.cpp
|
||||
@ -91,6 +94,7 @@ SET(CORE_INC_FILES
|
||||
)
|
||||
|
||||
SET(IMPL_SRC_FILES
|
||||
source/Impl/ErrorHandling.cpp
|
||||
source/Impl/MarchingCubesTables.cpp
|
||||
source/Impl/RandomUnitVectors.cpp
|
||||
source/Impl/RandomVectors.cpp
|
||||
@ -103,6 +107,7 @@ SET(IMPL_INC_FILES
|
||||
include/PolyVoxCore/Impl/AStarPathfinderImpl.h
|
||||
include/PolyVoxCore/Impl/Block.h
|
||||
include/PolyVoxCore/Impl/Block.inl
|
||||
include/PolyVoxCore/Impl/ErrorHandling.h
|
||||
include/PolyVoxCore/Impl/MarchingCubesTables.h
|
||||
include/PolyVoxCore/Impl/RandomUnitVectors.h
|
||||
include/PolyVoxCore/Impl/RandomVectors.h
|
||||
@ -123,7 +128,7 @@ SOURCE_GROUP("Sources\\Impl" FILES ${IMPL_SRC_FILES})
|
||||
SOURCE_GROUP("Headers\\Impl" FILES ${IMPL_INC_FILES})
|
||||
|
||||
#Tell CMake the paths
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
#Core
|
||||
#Build
|
||||
|
@ -29,6 +29,7 @@ freely, subject to the following restrictions:
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include "PolyVoxCore/Array.h"
|
||||
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
||||
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
|
||||
#include "PolyVoxCore/SurfaceMesh.h"
|
||||
|
||||
@ -109,7 +110,13 @@ namespace PolyVox
|
||||
};
|
||||
|
||||
public:
|
||||
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
|
||||
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
|
||||
#if defined(_MSC_VER)
|
||||
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||
#else
|
||||
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||
#endif
|
||||
|
||||
void execute();
|
||||
|
||||
@ -144,6 +151,10 @@ namespace PolyVox
|
||||
//This constant defines the maximum number of quads which can share a
|
||||
//vertex in a cubic style mesh. See the initialisation for more details.
|
||||
static const uint32_t MaxVerticesPerPosition;
|
||||
|
||||
//The wrap mode
|
||||
WrapMode m_eWrapMode;
|
||||
typename VolumeType::VoxelType m_tBorderValue;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,13 @@ namespace PolyVox
|
||||
const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 6;
|
||||
|
||||
template<typename VolumeType, typename IsQuadNeeded>
|
||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||
:m_volData(volData)
|
||||
,m_regSizeInVoxels(region)
|
||||
,m_meshCurrent(result)
|
||||
,m_bMergeQuads(bMergeQuads)
|
||||
,m_eWrapMode(eWrapMode)
|
||||
,m_tBorderValue(tBorderValue)
|
||||
{
|
||||
m_funcIsQuadNeededCallback = isQuadNeeded;
|
||||
}
|
||||
@ -72,6 +74,7 @@ namespace PolyVox
|
||||
m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ() + 2);
|
||||
|
||||
typename VolumeType::Sampler volumeSampler(m_volData);
|
||||
volumeSampler.setWrapMode(m_eWrapMode, m_tBorderValue);
|
||||
|
||||
for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ(); z++)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
@ -51,7 +53,7 @@ namespace PolyVox
|
||||
|
||||
uint32_t material = 0;
|
||||
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x+1,y,z), material))
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), material))
|
||||
{
|
||||
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast<float>(material)));
|
||||
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast<float>(material)));
|
||||
@ -61,7 +63,7 @@ namespace PolyVox
|
||||
m_meshCurrent->addTriangleCubic(v0,v2,v1);
|
||||
m_meshCurrent->addTriangleCubic(v1,v2,v3);
|
||||
}
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x+1,y,z), m_volData->getVoxelAt(x,y,z), material))
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material))
|
||||
{
|
||||
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast<float>(material)));
|
||||
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast<float>(material)));
|
||||
@ -72,7 +74,7 @@ namespace PolyVox
|
||||
m_meshCurrent->addTriangleCubic(v1,v3,v2);
|
||||
}
|
||||
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y+1,z), material))
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), material))
|
||||
{
|
||||
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast<float>(material)));
|
||||
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast<float>(material)));
|
||||
@ -82,7 +84,7 @@ namespace PolyVox
|
||||
m_meshCurrent->addTriangleCubic(v0,v1,v2);
|
||||
m_meshCurrent->addTriangleCubic(v1,v3,v2);
|
||||
}
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y+1,z), m_volData->getVoxelAt(x,y,z), material))
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material))
|
||||
{
|
||||
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast<float>(material)));
|
||||
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast<float>(material)));
|
||||
@ -93,7 +95,7 @@ namespace PolyVox
|
||||
m_meshCurrent->addTriangleCubic(v1,v2,v3);
|
||||
}
|
||||
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y,z+1), material))
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), material))
|
||||
{
|
||||
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast<float>(material)));
|
||||
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast<float>(material)));
|
||||
@ -103,7 +105,7 @@ namespace PolyVox
|
||||
m_meshCurrent->addTriangleCubic(v0,v2,v1);
|
||||
m_meshCurrent->addTriangleCubic(v1,v2,v3);
|
||||
}
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z+1), m_volData->getVoxelAt(x,y,z), material))
|
||||
if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material))
|
||||
{
|
||||
uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast<float>(material)));
|
||||
uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast<float>(material)));
|
||||
|
@ -1,148 +1,128 @@
|
||||
/*******************************************************************************
|
||||
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_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
|
||||
*
|
||||
*/
|
||||
template<typename VoxelType>
|
||||
class DefaultMarchingCubesController
|
||||
{
|
||||
public:
|
||||
/// Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing densities.
|
||||
typedef VoxelType DensityType;
|
||||
/// Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing materials. We're using a float here
|
||||
/// because this implementation always returns a constant value off 1.0f. PolyVox also uses floats to store the materials in the mesh vertices
|
||||
/// 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.
|
||||
*/
|
||||
DefaultMarchingCubesController(void)
|
||||
:m_tThreshold(((std::numeric_limits<DensityType>::min)() + (std::numeric_limits<DensityType>::max)()) / 2)
|
||||
,m_eWrapMode(WrapModes::Border)
|
||||
,m_tBorder(VoxelType(0))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
MaterialType convertToMaterial(VoxelType /*voxel*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
VoxelType getBorderValue(void)
|
||||
{
|
||||
return m_tBorder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
WrapMode getWrapMode(void)
|
||||
{
|
||||
return m_eWrapMode;
|
||||
}
|
||||
|
||||
void setThreshold(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
}
|
||||
|
||||
void setWrapMode(WrapMode eWrapMode, VoxelType tBorder = VoxelType(0))
|
||||
{
|
||||
m_eWrapMode = eWrapMode;
|
||||
m_tBorder = tBorder;
|
||||
}
|
||||
|
||||
private:
|
||||
DensityType m_tThreshold;
|
||||
WrapMode m_eWrapMode;
|
||||
VoxelType m_tBorder;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __PolyVox_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
|
||||
*
|
||||
*/
|
||||
template<typename VoxelType>
|
||||
class DefaultMarchingCubesController
|
||||
{
|
||||
public:
|
||||
/// Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing densities.
|
||||
typedef VoxelType DensityType;
|
||||
/// Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing materials. We're using a float here
|
||||
/// because this implementation always returns a constant value off 1.0f. PolyVox also uses floats to store the materials in the mesh vertices
|
||||
/// 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.
|
||||
*/
|
||||
DefaultMarchingCubesController(void)
|
||||
:m_tThreshold(((std::numeric_limits<DensityType>::min)() + (std::numeric_limits<DensityType>::max)()) / 2)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
DensityType getThreshold(void)
|
||||
{
|
||||
return m_tThreshold;
|
||||
}
|
||||
|
||||
void setThreshold(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
}
|
||||
|
||||
private:
|
||||
DensityType m_tThreshold;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -155,13 +155,11 @@ namespace PolyVox
|
||||
{
|
||||
// Default to a threshold value halfway between the min and max possible values.
|
||||
m_tThreshold = (Density<Type>::getMinDensity() + Density<Type>::getMaxDensity()) / 2;
|
||||
m_eWrapMode = WrapModes::Border;
|
||||
}
|
||||
|
||||
DefaultMarchingCubesController(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
m_eWrapMode = WrapModes::Border;
|
||||
}
|
||||
|
||||
DensityType convertToDensity(Density<Type> voxel)
|
||||
@ -174,35 +172,18 @@ namespace PolyVox
|
||||
return 1;
|
||||
}
|
||||
|
||||
Density<Type> getBorderValue(void)
|
||||
{
|
||||
return m_tBorder;
|
||||
}
|
||||
|
||||
DensityType getThreshold(void)
|
||||
{
|
||||
return m_tThreshold;
|
||||
}
|
||||
|
||||
WrapMode getWrapMode(void)
|
||||
{
|
||||
return m_eWrapMode;
|
||||
}
|
||||
|
||||
void setThreshold(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
}
|
||||
|
||||
void setWrapMode(WrapMode eWrapMode)
|
||||
{
|
||||
m_eWrapMode = eWrapMode;
|
||||
}
|
||||
|
||||
private:
|
||||
DensityType m_tThreshold;
|
||||
WrapMode m_eWrapMode;
|
||||
Density<Type> m_tBorder;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* This file provides the default compiler capabilities for for Visual Studio.
|
||||
* On other compilers CMake will detect which features are available and create
|
||||
* a file like this.
|
||||
*
|
||||
* To Enable these features in Visual Studio, define the variables in this file.
|
||||
*/
|
||||
|
||||
#ifndef __PolyVox_CompilerCapabilities_H__
|
||||
#define __PolyVox_CompilerCapabilities_H__
|
||||
|
||||
//#undef HAS_CXX11_CONSTEXPR
|
||||
|
||||
#define HAS_CXX11_STATIC_ASSERT
|
||||
|
||||
#define HAS_CXX11_CSTDINT_H
|
||||
|
||||
#define HAS_CXX11_SHARED_PTR
|
||||
|
||||
#endif
|
@ -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
|
124
library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h
Normal file
124
library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h
Normal file
@ -0,0 +1,124 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __PolyVox_ErrorHandling_H__
|
||||
#define __PolyVox_ErrorHandling_H__
|
||||
|
||||
#include <cstdlib> //For std::exit
|
||||
#include <iostream> //For std::cerr
|
||||
#include <stdexcept>
|
||||
|
||||
#define POLYVOX_ASSERTS_ENABLED
|
||||
#define POLYVOX_THROW_ENABLED
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define POLYVOX_HALT() __debugbreak()
|
||||
#else
|
||||
#define POLYVOX_HALT() std::exit(EXIT_FAILURE)
|
||||
#endif
|
||||
|
||||
#define POLYVOX_UNUSED(x) do { (void)sizeof(x); } while(0)
|
||||
|
||||
/*
|
||||
* Assertions
|
||||
* ----------
|
||||
* The code below implements a custom assert function called POLYVOX_ASSERT which has a number of advantages compared
|
||||
* to the standard C/C++ assert(). It is inspired by http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/
|
||||
* which provides code under the MIT license.
|
||||
*/
|
||||
|
||||
#ifdef POLYVOX_ASSERTS_ENABLED
|
||||
|
||||
#define POLYVOX_ASSERT(condition, message) \
|
||||
do \
|
||||
{ \
|
||||
if (!(condition)) \
|
||||
{ \
|
||||
std::cerr << std::endl << std::endl; \
|
||||
std::cerr << " PolyVox Assertion Failed!" << std::endl; \
|
||||
std::cerr << " =========================" << std::endl; \
|
||||
std::cerr << " Condition: " << #condition << std::endl; \
|
||||
std::cerr << " Message: " << (message) << std::endl; \
|
||||
std::cerr << " Location: " << "Line " << __LINE__ << " of " << __FILE__ << std::endl << std::endl; \
|
||||
POLYVOX_HALT(); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#else
|
||||
|
||||
#define POLYVOX_ASSERT(condition, message) \
|
||||
do { POLYVOX_UNUSED(condition); POLYVOX_UNUSED(message); } while(0)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Static Assertions
|
||||
* -----------------
|
||||
* These map to C+11 static_assert if available or our own implentation otherwise.
|
||||
*/
|
||||
|
||||
#if defined(HAS_CXX11_STATIC_ASSERT)
|
||||
//In this case we can just use static_assert
|
||||
#define POLYVOX_STATIC_ASSERT static_assert
|
||||
#else
|
||||
namespace PolyVox
|
||||
{
|
||||
// empty default template
|
||||
template <bool b>
|
||||
struct StaticAssert {};
|
||||
|
||||
// template specialized on true
|
||||
template <>
|
||||
struct StaticAssert<true>
|
||||
{
|
||||
// If the static assertion is failing then this function won't exist. It will then
|
||||
// appear in the error message which gives a clue to the user about what is wrong.
|
||||
static void ERROR_The_static_assertion_has_failed() {}
|
||||
};
|
||||
}
|
||||
|
||||
#define POLYVOX_STATIC_ASSERT(condition, message) StaticAssert<(condition)>::ERROR_The_static_assertion_has_failed();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Exceptions
|
||||
* ----------
|
||||
* ...
|
||||
*/
|
||||
#ifdef POLYVOX_THROW_ENABLED
|
||||
#define POLYVOX_THROW(type, message) throw type((message))
|
||||
#else
|
||||
namespace PolyVox
|
||||
{
|
||||
typedef void (*ThrowHandler)(std::exception& e, const char* file, int line);
|
||||
|
||||
ThrowHandler getThrowHandler();
|
||||
void setThrowHandler(ThrowHandler newHandler);
|
||||
}
|
||||
|
||||
#define POLYVOX_THROW(type, message) \
|
||||
type except = (type)((message)); \
|
||||
getThrowHandler()((except), __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#endif //__PolyVox_ErrorHandling_H__
|
@ -24,6 +24,8 @@ freely, subject to the following restrictions:
|
||||
#ifndef __PolyVox_TypeDef_H__
|
||||
#define __PolyVox_TypeDef_H__
|
||||
|
||||
#include "PolyVoxCore/Impl/CompilerCapabilities.h"
|
||||
|
||||
//Definitions needed to make library functions accessable
|
||||
// See http://gcc.gnu.org/wiki/Visibility for more info.
|
||||
#if defined _WIN32 || defined __CYGWIN__
|
||||
@ -44,6 +46,13 @@ freely, subject to the following restrictions:
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined SWIG
|
||||
//Do nothing in this case
|
||||
#else
|
||||
#undef POLYVOX_DEPRECATED
|
||||
#define POLYVOX_DEPRECATED //Define it to nothing to avoid warnings
|
||||
#endif
|
||||
|
||||
// Now we use the generic helper definitions above to define POLYVOX_API and POLYVOX_LOCAL.
|
||||
// POLYVOX_API is used for the public API symbols. It either imports or exports (or does nothing for static build)
|
||||
// POLYVOX_LOCAL is used for non-api symbols.
|
||||
@ -65,9 +74,6 @@ freely, subject to the following restrictions:
|
||||
//To support old (pre-vc2010) Microsoft compilers we use boost to replace the
|
||||
//std::shared_ptr and potentially other C++0x features. To use this capability you
|
||||
//will need to make sure you have boost installed on your system.
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#define polyvox_shared_ptr boost::shared_ptr
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#define polyvox_function boost::function
|
||||
|
||||
@ -75,13 +81,26 @@ freely, subject to the following restrictions:
|
||||
#define polyvox_bind boost::bind
|
||||
#define polyvox_placeholder_1 _1
|
||||
#define polyvox_placeholder_2 _2
|
||||
|
||||
#include <boost/static_assert.hpp>
|
||||
#define static_assert(condition, message) BOOST_STATIC_ASSERT(condition)
|
||||
#else
|
||||
//We have a decent compiler - use real C++0x features
|
||||
#include <functional>
|
||||
#define polyvox_function std::function
|
||||
#define polyvox_bind std::bind
|
||||
#define polyvox_placeholder_1 std::placeholders::_1
|
||||
#define polyvox_placeholder_2 std::placeholders::_2
|
||||
#endif
|
||||
|
||||
#if defined(HAS_CXX11_CONSTEXPR)
|
||||
#define polyvox_constexpr_const constexpr //constexpr which falls back to const
|
||||
#define polyvox_constexpr constexpr //constexpr which falls back to nothing
|
||||
#else
|
||||
#define polyvox_constexpr_const const
|
||||
#define polyvox_constexpr
|
||||
#endif
|
||||
|
||||
//As long as we're requiring boost, we'll use it to compensate
|
||||
//for the missing cstdint header too.
|
||||
#if defined(HAS_CXX11_CSTDINT_H)
|
||||
#include <cstdint>
|
||||
#else
|
||||
#include <boost/cstdint.hpp>
|
||||
using boost::int8_t;
|
||||
using boost::int16_t;
|
||||
@ -89,17 +108,14 @@ freely, subject to the following restrictions:
|
||||
using boost::uint8_t;
|
||||
using boost::uint16_t;
|
||||
using boost::uint32_t;
|
||||
#else
|
||||
//We have a decent compiler - use real C++0x features
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#endif
|
||||
|
||||
#if defined(HAS_CXX11_SHARED_PTR)
|
||||
#include <memory>
|
||||
#define polyvox_shared_ptr std::shared_ptr
|
||||
#define polyvox_function std::function
|
||||
#define polyvox_bind std::bind
|
||||
#define polyvox_placeholder_1 std::placeholders::_1
|
||||
#define polyvox_placeholder_2 std::placeholders::_2
|
||||
//#define static_assert static_assert //we can use this
|
||||
#else
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#define polyvox_shared_ptr boost::shared_ptr
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -21,10 +21,12 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#define BORDER_LOW(x) ((( x >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != x)
|
||||
#define BORDER_HIGH(x) ((( (x+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (x+1))
|
||||
//#define BORDER_LOW(x) (( x % mVolume->m_uBlockSideLength) != 0)
|
||||
//#define BORDER_HIGH(x) (( x % mVolume->m_uBlockSideLength) != mVolume->m_uBlockSideLength - 1)
|
||||
#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
@ -280,7 +282,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -290,7 +292,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -300,7 +302,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -310,7 +312,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -320,7 +322,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1);
|
||||
}
|
||||
@ -330,7 +332,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -340,7 +342,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -350,7 +352,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -360,7 +362,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -372,7 +374,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -382,7 +384,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -392,7 +394,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -402,7 +404,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -422,7 +424,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -432,7 +434,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -442,7 +444,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -452,7 +454,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -464,7 +466,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -474,7 +476,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -484,7 +486,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -494,7 +496,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -504,7 +506,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1);
|
||||
}
|
||||
@ -514,7 +516,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -524,7 +526,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -534,7 +536,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -544,7 +546,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType LargeVolume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -552,5 +554,9 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
|
||||
#undef BORDER_LOW
|
||||
#undef BORDER_HIGH
|
||||
#undef CAN_GO_NEG_X
|
||||
#undef CAN_GO_POS_X
|
||||
#undef CAN_GO_NEG_Y
|
||||
#undef CAN_GO_POS_Y
|
||||
#undef CAN_GO_NEG_Z
|
||||
#undef CAN_GO_POS_Z
|
||||
|
@ -1,220 +1,217 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __PolyVox_SurfaceExtractor_H__
|
||||
#define __PolyVox_SurfaceExtractor_H__
|
||||
|
||||
#include "Impl/MarchingCubesTables.h"
|
||||
#include "Impl/TypeDef.h"
|
||||
|
||||
#include "PolyVoxCore/Array.h"
|
||||
#include "PolyVoxCore/SurfaceMesh.h"
|
||||
#include "PolyVoxCore/DefaultMarchingCubesController.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template< typename VolumeType, typename Controller = DefaultMarchingCubesController<typename VolumeType::VoxelType> >
|
||||
class MarchingCubesSurfaceExtractor
|
||||
{
|
||||
public:
|
||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* result, Controller controller = Controller());
|
||||
|
||||
void execute();
|
||||
|
||||
private:
|
||||
//Compute the cell bitmask for a particular slice in z.
|
||||
template<bool isPrevZAvail>
|
||||
uint32_t computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask);
|
||||
|
||||
//Compute the cell bitmask for a given cell.
|
||||
template<bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail>
|
||||
void computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask);
|
||||
|
||||
//Use the cell bitmasks to generate all the vertices needed for that slice
|
||||
void generateVerticesForSlice(const Array2DUint8& pCurrentBitmask,
|
||||
Array2DInt32& m_pCurrentVertexIndicesX,
|
||||
Array2DInt32& m_pCurrentVertexIndicesY,
|
||||
Array2DInt32& m_pCurrentVertexIndicesZ);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// NOTE: These two functions are in the .h file rather than the .inl due to an apparent bug in VC2010.
|
||||
//See http://stackoverflow.com/questions/1484885/strange-vc-compile-error-c2244 for details.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter)
|
||||
{
|
||||
//FIXME - Should actually use DensityType here, both in principle and because the maths may be
|
||||
//faster (and to reduce casts). So it would be good to add a way to get DensityType from a voxel.
|
||||
//But watch out for when the DensityType is unsigned and the difference could be negative.
|
||||
float voxel1nx = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx0py0pz()));
|
||||
float voxel1px = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px0py0pz()));
|
||||
|
||||
float voxel1ny = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1ny0pz()));
|
||||
float voxel1py = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1py0pz()));
|
||||
|
||||
float voxel1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py1nz()));
|
||||
float voxel1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py1pz()));
|
||||
|
||||
return Vector3DFloat
|
||||
(
|
||||
voxel1nx - voxel1px,
|
||||
voxel1ny - voxel1py,
|
||||
voxel1nz - voxel1pz
|
||||
);
|
||||
}
|
||||
|
||||
Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter)
|
||||
{
|
||||
static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, {
|
||||
{3,6,3}, {6,0,6}, {3,6,3} }, { {2,3,2}, {3,6,3}, {2,3,2} } };
|
||||
|
||||
//FIXME - Should actually use DensityType here, both in principle and because the maths may be
|
||||
//faster (and to reduce casts). So it would be good to add a way to get DensityType from a voxel.
|
||||
//But watch out for when the DensityType is unsigned and the difference could be negative.
|
||||
const float pVoxel1nx1ny1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1ny1nz()));
|
||||
const float pVoxel1nx1ny0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1ny0pz()));
|
||||
const float pVoxel1nx1ny1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1ny1pz()));
|
||||
const float pVoxel1nx0py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx0py1nz()));
|
||||
const float pVoxel1nx0py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx0py0pz()));
|
||||
const float pVoxel1nx0py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx0py1pz()));
|
||||
const float pVoxel1nx1py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1py1nz()));
|
||||
const float pVoxel1nx1py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1py0pz()));
|
||||
const float pVoxel1nx1py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1py1pz()));
|
||||
|
||||
const float pVoxel0px1ny1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1ny1nz()));
|
||||
const float pVoxel0px1ny0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1ny0pz()));
|
||||
const float pVoxel0px1ny1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1ny1pz()));
|
||||
const float pVoxel0px0py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py1nz()));
|
||||
//const float pVoxel0px0py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py0pz()));
|
||||
const float pVoxel0px0py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py1pz()));
|
||||
const float pVoxel0px1py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1py1nz()));
|
||||
const float pVoxel0px1py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1py0pz()));
|
||||
const float pVoxel0px1py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1py1pz()));
|
||||
|
||||
const float pVoxel1px1ny1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1ny1nz()));
|
||||
const float pVoxel1px1ny0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1ny0pz()));
|
||||
const float pVoxel1px1ny1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1ny1pz()));
|
||||
const float pVoxel1px0py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px0py1nz()));
|
||||
const float pVoxel1px0py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px0py0pz()));
|
||||
const float pVoxel1px0py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px0py1pz()));
|
||||
const float pVoxel1px1py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1py1nz()));
|
||||
const float pVoxel1px1py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1py0pz()));
|
||||
const float pVoxel1px1py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1py1pz()));
|
||||
|
||||
const float xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
|
||||
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
|
||||
pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz -
|
||||
weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] *
|
||||
pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz -
|
||||
weights[1][2][0] * pVoxel1nx1py0pz - weights[2][2][0] *
|
||||
pVoxel1nx1py1pz + weights[0][0][2] * pVoxel1px1ny1nz +
|
||||
weights[1][0][2] * pVoxel1px1ny0pz + weights[2][0][2] *
|
||||
pVoxel1px1ny1pz + weights[0][1][2] * pVoxel1px0py1nz +
|
||||
weights[1][1][2] * pVoxel1px0py0pz + weights[2][1][2] *
|
||||
pVoxel1px0py1pz + weights[0][2][2] * pVoxel1px1py1nz +
|
||||
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
|
||||
pVoxel1px1py1pz);
|
||||
|
||||
const float yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
|
||||
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
|
||||
pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz +
|
||||
weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] *
|
||||
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz -
|
||||
weights[1][0][1] * pVoxel0px1ny0pz - weights[2][0][1] *
|
||||
pVoxel0px1ny1pz + weights[0][2][1] * pVoxel0px1py1nz +
|
||||
weights[1][2][1] * pVoxel0px1py0pz + weights[2][2][1] *
|
||||
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz -
|
||||
weights[1][0][2] * pVoxel1px1ny0pz - weights[2][0][2] *
|
||||
pVoxel1px1ny1pz + weights[0][2][2] * pVoxel1px1py1nz +
|
||||
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
|
||||
pVoxel1px1py1pz);
|
||||
|
||||
const float zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz +
|
||||
weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] *
|
||||
pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz -
|
||||
weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] *
|
||||
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz +
|
||||
weights[2][0][1] * pVoxel0px1ny1pz - weights[0][1][1] *
|
||||
pVoxel0px0py1nz + weights[2][1][1] * pVoxel0px0py1pz -
|
||||
weights[0][2][1] * pVoxel0px1py1nz + weights[2][2][1] *
|
||||
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz +
|
||||
weights[2][0][2] * pVoxel1px1ny1pz - weights[0][1][2] *
|
||||
pVoxel1px0py1nz + weights[2][1][2] * pVoxel1px0py1pz -
|
||||
weights[0][2][2] * pVoxel1px1py1nz + weights[2][2][2] *
|
||||
pVoxel1px1py1pz);
|
||||
|
||||
//Note: The above actually give gradients going from low density to high density.
|
||||
//For our normals we want the the other way around, so we switch the components as we return them.
|
||||
return Vector3DFloat(-xGrad,-yGrad,-zGrad);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// End of compiler bug workaroumd.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Use the cell bitmasks to generate all the indices needed for that slice
|
||||
void generateIndicesForSlice(const Array2DUint8& pPreviousBitmask,
|
||||
const Array2DInt32& m_pPreviousVertexIndicesX,
|
||||
const Array2DInt32& m_pPreviousVertexIndicesY,
|
||||
const Array2DInt32& m_pPreviousVertexIndicesZ,
|
||||
const Array2DInt32& m_pCurrentVertexIndicesX,
|
||||
const Array2DInt32& m_pCurrentVertexIndicesY);
|
||||
|
||||
//The volume data and a sampler to access it.
|
||||
VolumeType* m_volData;
|
||||
typename VolumeType::Sampler m_sampVolume;
|
||||
|
||||
//Holds a position in volume space.
|
||||
int32_t iXVolSpace;
|
||||
int32_t iYVolSpace;
|
||||
int32_t iZVolSpace;
|
||||
|
||||
//Holds a position in region space.
|
||||
uint32_t uXRegSpace;
|
||||
uint32_t uYRegSpace;
|
||||
uint32_t uZRegSpace;
|
||||
|
||||
//Used to return the number of cells in a slice which contain triangles.
|
||||
uint32_t m_uNoOfOccupiedCells;
|
||||
|
||||
//The surface patch we are currently filling.
|
||||
SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* m_meshCurrent;
|
||||
|
||||
//Information about the region we are currently processing
|
||||
Region m_regSizeInVoxels;
|
||||
Region m_regSizeInCells;
|
||||
/*Region m_regSizeInVoxelsCropped;
|
||||
Region m_regSizeInVoxelsUncropped;
|
||||
Region m_regVolumeCropped;*/
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.inl"
|
||||
|
||||
#endif
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __PolyVox_SurfaceExtractor_H__
|
||||
#define __PolyVox_SurfaceExtractor_H__
|
||||
|
||||
#include "Impl/MarchingCubesTables.h"
|
||||
#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"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template< typename VolumeType, typename Controller = DefaultMarchingCubesController<typename VolumeType::VoxelType> >
|
||||
class MarchingCubesSurfaceExtractor
|
||||
{
|
||||
public:
|
||||
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
|
||||
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
|
||||
#if defined(_MSC_VER)
|
||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), Controller controller = Controller());
|
||||
#else
|
||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(0), Controller controller = Controller());
|
||||
#endif
|
||||
|
||||
void execute();
|
||||
|
||||
private:
|
||||
//Compute the cell bitmask for a particular slice in z.
|
||||
template<bool isPrevZAvail>
|
||||
uint32_t computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask);
|
||||
|
||||
//Compute the cell bitmask for a given cell.
|
||||
template<bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail>
|
||||
void computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask, uint32_t uXRegSpace, uint32_t uYRegSpace);
|
||||
|
||||
//Use the cell bitmasks to generate all the vertices needed for that slice
|
||||
void generateVerticesForSlice(const Array2DUint8& pCurrentBitmask,
|
||||
Array2DInt32& m_pCurrentVertexIndicesX,
|
||||
Array2DInt32& m_pCurrentVertexIndicesY,
|
||||
Array2DInt32& m_pCurrentVertexIndicesZ);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// NOTE: These two functions are in the .h file rather than the .inl due to an apparent bug in VC2010.
|
||||
//See http://stackoverflow.com/questions/1484885/strange-vc-compile-error-c2244 for details.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter)
|
||||
{
|
||||
//FIXME - Should actually use DensityType here, both in principle and because the maths may be
|
||||
//faster (and to reduce casts). So it would be good to add a way to get DensityType from a voxel.
|
||||
//But watch out for when the DensityType is unsigned and the difference could be negative.
|
||||
float voxel1nx = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx0py0pz()));
|
||||
float voxel1px = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px0py0pz()));
|
||||
|
||||
float voxel1ny = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1ny0pz()));
|
||||
float voxel1py = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1py0pz()));
|
||||
|
||||
float voxel1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py1nz()));
|
||||
float voxel1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py1pz()));
|
||||
|
||||
return Vector3DFloat
|
||||
(
|
||||
voxel1nx - voxel1px,
|
||||
voxel1ny - voxel1py,
|
||||
voxel1nz - voxel1pz
|
||||
);
|
||||
}
|
||||
|
||||
Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter)
|
||||
{
|
||||
static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, {
|
||||
{3,6,3}, {6,0,6}, {3,6,3} }, { {2,3,2}, {3,6,3}, {2,3,2} } };
|
||||
|
||||
//FIXME - Should actually use DensityType here, both in principle and because the maths may be
|
||||
//faster (and to reduce casts). So it would be good to add a way to get DensityType from a voxel.
|
||||
//But watch out for when the DensityType is unsigned and the difference could be negative.
|
||||
const float pVoxel1nx1ny1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1ny1nz()));
|
||||
const float pVoxel1nx1ny0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1ny0pz()));
|
||||
const float pVoxel1nx1ny1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1ny1pz()));
|
||||
const float pVoxel1nx0py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx0py1nz()));
|
||||
const float pVoxel1nx0py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx0py0pz()));
|
||||
const float pVoxel1nx0py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx0py1pz()));
|
||||
const float pVoxel1nx1py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1py1nz()));
|
||||
const float pVoxel1nx1py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1py0pz()));
|
||||
const float pVoxel1nx1py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1nx1py1pz()));
|
||||
|
||||
const float pVoxel0px1ny1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1ny1nz()));
|
||||
const float pVoxel0px1ny0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1ny0pz()));
|
||||
const float pVoxel0px1ny1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1ny1pz()));
|
||||
const float pVoxel0px0py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py1nz()));
|
||||
//const float pVoxel0px0py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py0pz()));
|
||||
const float pVoxel0px0py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px0py1pz()));
|
||||
const float pVoxel0px1py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1py1nz()));
|
||||
const float pVoxel0px1py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1py0pz()));
|
||||
const float pVoxel0px1py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel0px1py1pz()));
|
||||
|
||||
const float pVoxel1px1ny1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1ny1nz()));
|
||||
const float pVoxel1px1ny0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1ny0pz()));
|
||||
const float pVoxel1px1ny1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1ny1pz()));
|
||||
const float pVoxel1px0py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px0py1nz()));
|
||||
const float pVoxel1px0py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px0py0pz()));
|
||||
const float pVoxel1px0py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px0py1pz()));
|
||||
const float pVoxel1px1py1nz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1py1nz()));
|
||||
const float pVoxel1px1py0pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1py0pz()));
|
||||
const float pVoxel1px1py1pz = static_cast<float>(m_controller.convertToDensity(volIter.peekVoxel1px1py1pz()));
|
||||
|
||||
const float xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
|
||||
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
|
||||
pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz -
|
||||
weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] *
|
||||
pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz -
|
||||
weights[1][2][0] * pVoxel1nx1py0pz - weights[2][2][0] *
|
||||
pVoxel1nx1py1pz + weights[0][0][2] * pVoxel1px1ny1nz +
|
||||
weights[1][0][2] * pVoxel1px1ny0pz + weights[2][0][2] *
|
||||
pVoxel1px1ny1pz + weights[0][1][2] * pVoxel1px0py1nz +
|
||||
weights[1][1][2] * pVoxel1px0py0pz + weights[2][1][2] *
|
||||
pVoxel1px0py1pz + weights[0][2][2] * pVoxel1px1py1nz +
|
||||
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
|
||||
pVoxel1px1py1pz);
|
||||
|
||||
const float yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
|
||||
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
|
||||
pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz +
|
||||
weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] *
|
||||
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz -
|
||||
weights[1][0][1] * pVoxel0px1ny0pz - weights[2][0][1] *
|
||||
pVoxel0px1ny1pz + weights[0][2][1] * pVoxel0px1py1nz +
|
||||
weights[1][2][1] * pVoxel0px1py0pz + weights[2][2][1] *
|
||||
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz -
|
||||
weights[1][0][2] * pVoxel1px1ny0pz - weights[2][0][2] *
|
||||
pVoxel1px1ny1pz + weights[0][2][2] * pVoxel1px1py1nz +
|
||||
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
|
||||
pVoxel1px1py1pz);
|
||||
|
||||
const float zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz +
|
||||
weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] *
|
||||
pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz -
|
||||
weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] *
|
||||
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz +
|
||||
weights[2][0][1] * pVoxel0px1ny1pz - weights[0][1][1] *
|
||||
pVoxel0px0py1nz + weights[2][1][1] * pVoxel0px0py1pz -
|
||||
weights[0][2][1] * pVoxel0px1py1nz + weights[2][2][1] *
|
||||
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz +
|
||||
weights[2][0][2] * pVoxel1px1ny1pz - weights[0][1][2] *
|
||||
pVoxel1px0py1nz + weights[2][1][2] * pVoxel1px0py1pz -
|
||||
weights[0][2][2] * pVoxel1px1py1nz + weights[2][2][2] *
|
||||
pVoxel1px1py1pz);
|
||||
|
||||
//Note: The above actually give gradients going from low density to high density.
|
||||
//For our normals we want the the other way around, so we switch the components as we return them.
|
||||
return Vector3DFloat(-xGrad,-yGrad,-zGrad);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// End of compiler bug workaroumd.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Use the cell bitmasks to generate all the indices needed for that slice
|
||||
void generateIndicesForSlice(const Array2DUint8& pPreviousBitmask,
|
||||
const Array2DInt32& m_pPreviousVertexIndicesX,
|
||||
const Array2DInt32& m_pPreviousVertexIndicesY,
|
||||
const Array2DInt32& m_pPreviousVertexIndicesZ,
|
||||
const Array2DInt32& m_pCurrentVertexIndicesX,
|
||||
const Array2DInt32& m_pCurrentVertexIndicesY);
|
||||
|
||||
//The volume data and a sampler to access it.
|
||||
VolumeType* m_volData;
|
||||
typename VolumeType::Sampler m_sampVolume;
|
||||
|
||||
//Used to return the number of cells in a slice which contain triangles.
|
||||
uint32_t m_uNoOfOccupiedCells;
|
||||
|
||||
//The surface patch we are currently filling.
|
||||
SurfaceMesh<PositionMaterialNormal<typename Controller::MaterialType> >* m_meshCurrent;
|
||||
|
||||
//Information about the region we are currently processing
|
||||
Region m_regSizeInVoxels;
|
||||
Region m_regSizeInCells;
|
||||
/*Region m_regSizeInVoxelsCropped;
|
||||
Region m_regSizeInVoxelsUncropped;
|
||||
Region m_regVolumeCropped;*/
|
||||
Region m_regSlicePrevious;
|
||||
Region m_regSliceCurrent;
|
||||
|
||||
//Used to convert arbitrary voxel types in densities and materials.
|
||||
Controller m_controller;
|
||||
|
||||
//Our threshold value
|
||||
typename Controller::DensityType m_tThreshold;
|
||||
};
|
||||
}
|
||||
|
||||
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.inl"
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -119,13 +119,11 @@ namespace PolyVox
|
||||
{
|
||||
// Default to a threshold value halfway between the min and max possible values.
|
||||
m_tThreshold = (MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getMinDensity() + MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getMaxDensity()) / 2;
|
||||
m_eWrapMode = WrapModes::Border;
|
||||
}
|
||||
|
||||
DefaultMarchingCubesController(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
m_eWrapMode = WrapModes::Border;
|
||||
}
|
||||
|
||||
DensityType convertToDensity(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> voxel)
|
||||
@ -138,35 +136,18 @@ namespace PolyVox
|
||||
return voxel.getMaterial();
|
||||
}
|
||||
|
||||
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> getBorderValue(void)
|
||||
{
|
||||
return m_tBorder;
|
||||
}
|
||||
|
||||
DensityType getThreshold(void)
|
||||
{
|
||||
return m_tThreshold;
|
||||
}
|
||||
|
||||
WrapMode getWrapMode(void)
|
||||
{
|
||||
return m_eWrapMode;
|
||||
}
|
||||
|
||||
void setThreshold(DensityType tThreshold)
|
||||
{
|
||||
m_tThreshold = tThreshold;
|
||||
}
|
||||
|
||||
void setWrapMode(WrapMode eWrapMode)
|
||||
{
|
||||
m_eWrapMode = eWrapMode;
|
||||
}
|
||||
|
||||
private:
|
||||
DensityType m_tThreshold;
|
||||
WrapMode m_eWrapMode;
|
||||
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> m_tBorder;
|
||||
};
|
||||
|
||||
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
|
||||
|
@ -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);
|
||||
|
@ -21,10 +21,12 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#define BORDER_LOW(x) ((( x >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != x)
|
||||
#define BORDER_HIGH(x) ((( (x+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (x+1))
|
||||
//#define BORDER_LOW(x) (( x % this->mVolume->m_uBlockSideLength) != 0)
|
||||
//#define BORDER_HIGH(x) (( x % this->mVolume->m_uBlockSideLength) != this->mVolume->m_uBlockSideLength - 1)
|
||||
#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0))
|
||||
#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0))
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
@ -299,7 +301,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -309,7 +311,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -319,7 +321,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -329,7 +331,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -339,7 +341,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1);
|
||||
}
|
||||
@ -349,7 +351,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -359,7 +361,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -369,7 +371,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -379,7 +381,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -391,7 +393,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -401,7 +403,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -411,7 +413,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -421,7 +423,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -441,7 +443,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -451,7 +453,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -461,7 +463,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -471,7 +473,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -483,7 +485,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -493,7 +495,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -503,7 +505,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -513,7 +515,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -523,7 +525,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1);
|
||||
}
|
||||
@ -533,7 +535,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -543,7 +545,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -553,7 +555,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -563,7 +565,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType SimpleVolume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
|
||||
{
|
||||
if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) )
|
||||
if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) )
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength);
|
||||
}
|
||||
@ -571,5 +573,9 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
|
||||
#undef BORDER_LOW
|
||||
#undef BORDER_HIGH
|
||||
#undef CAN_GO_NEG_X
|
||||
#undef CAN_GO_POS_X
|
||||
#undef CAN_GO_NEG_Y
|
||||
#undef CAN_GO_POS_Y
|
||||
#undef CAN_GO_NEG_Z
|
||||
#undef CAN_GO_POS_Z
|
||||
|
@ -21,6 +21,8 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VertexType>
|
||||
|
@ -24,11 +24,11 @@ freely, subject to the following restrictions:
|
||||
#ifndef __PolyVox_Vector_H__
|
||||
#define __PolyVox_Vector_H__
|
||||
|
||||
#include "Impl/ErrorHandling.h"
|
||||
#include "Impl/TypeDef.h"
|
||||
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
@ -52,10 +52,8 @@ namespace PolyVox
|
||||
*/
|
||||
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||
Vector<Size,StorageType,OperationType>::Vector(StorageType x, StorageType y)
|
||||
{
|
||||
#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||
//static_assert(Size == 2, "This constructor should only be used for vectors with two elements.");
|
||||
#endif
|
||||
{
|
||||
POLYVOX_STATIC_ASSERT(Size == 2, "This constructor should only be used for vectors with two elements.");
|
||||
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
@ -69,10 +67,8 @@ namespace PolyVox
|
||||
*/
|
||||
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||
Vector<Size,StorageType,OperationType>::Vector(StorageType x, StorageType y, StorageType z)
|
||||
{
|
||||
#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||
//static_assert(Size == 3, "This constructor should only be used for vectors with three elements.");
|
||||
#endif
|
||||
{
|
||||
POLYVOX_STATIC_ASSERT(Size == 3, "This constructor should only be used for vectors with three elements.");
|
||||
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
@ -89,10 +85,8 @@ namespace PolyVox
|
||||
*/
|
||||
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||
Vector<Size,StorageType,OperationType>::Vector(StorageType x, StorageType y, StorageType z, StorageType w)
|
||||
{
|
||||
#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||
//static_assert(Size == 4, "This constructor should only be used for vectors with four elements.");
|
||||
#endif
|
||||
{
|
||||
POLYVOX_STATIC_ASSERT(Size == 4, "This constructor should only be used for vectors with four elements.");
|
||||
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
@ -135,14 +129,14 @@ namespace PolyVox
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
Vector<Size, StorageType, OperationType>::~Vector(void)
|
||||
{
|
||||
// We put the static_asserts in the destructor because there is one one of these,
|
||||
// We put the static asserts in the destructor because there is one one of these,
|
||||
// where as there are multiple constructors.
|
||||
|
||||
// Force a vector to have a length greater than one. There is no need for a
|
||||
// vector with one element, and supporting this would cause confusion over the
|
||||
// behaviour of the constructor taking a single value, as this fills all elements
|
||||
// to that value rather than just the first one.
|
||||
//static_assert(Size > 1, "Vector must have a length greater than one.");
|
||||
// to that value rather than just the first one.
|
||||
POLYVOX_STATIC_ASSERT(Size > 1, "Vector must have a length greater than one.");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -420,7 +414,7 @@ namespace PolyVox
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline StorageType Vector<Size, StorageType, OperationType>::getElement(uint32_t index) const
|
||||
{
|
||||
assert(index < Size);
|
||||
POLYVOX_ASSERT(index < Size, "Attempted to access invalid vector element.");
|
||||
return m_tElements[index];
|
||||
}
|
||||
|
||||
@ -447,10 +441,8 @@ namespace PolyVox
|
||||
*/
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline StorageType Vector<Size, StorageType, OperationType>::getZ(void) const
|
||||
{
|
||||
#ifndef SWIGPYTHON // SWIG instantiates all getters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||
//static_assert(Size >= 3, "You can only get the 'z' component from a vector with at least three elements.");
|
||||
#endif
|
||||
{
|
||||
POLYVOX_STATIC_ASSERT(Size >= 3, "You can only get the 'z' component from a vector with at least three elements.");
|
||||
|
||||
return m_tElements[2];
|
||||
}
|
||||
@ -460,10 +452,8 @@ namespace PolyVox
|
||||
*/
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline StorageType Vector<Size, StorageType, OperationType>::getW(void) const
|
||||
{
|
||||
#ifndef SWIGPYTHON // SWIG instantiates all getters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||
//static_assert(Size >= 4, "You can only get the 'w' component from a vector with at least four elements.");
|
||||
#endif
|
||||
{
|
||||
POLYVOX_STATIC_ASSERT(Size >= 4, "You can only get the 'w' component from a vector with at least four elements.");
|
||||
|
||||
return m_tElements[3];
|
||||
}
|
||||
@ -475,7 +465,7 @@ namespace PolyVox
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline void Vector<Size, StorageType, OperationType>::setElement(uint32_t index, StorageType tValue)
|
||||
{
|
||||
assert(index < Size);
|
||||
POLYVOX_ASSERT(index < Size, "Attempted to access invalid vector element.");
|
||||
m_tElements[index] = tValue;
|
||||
}
|
||||
|
||||
@ -500,10 +490,9 @@ namespace PolyVox
|
||||
*/
|
||||
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||
inline void Vector<Size,StorageType,OperationType>::setElements(StorageType x, StorageType y, StorageType z)
|
||||
{
|
||||
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||
//static_assert(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements.");
|
||||
#endif
|
||||
{
|
||||
POLYVOX_STATIC_ASSERT(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements.");
|
||||
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
m_tElements[2] = z;
|
||||
@ -518,10 +507,9 @@ namespace PolyVox
|
||||
*/
|
||||
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||
inline void Vector<Size,StorageType,OperationType>::setElements(StorageType x, StorageType y, StorageType z, StorageType w)
|
||||
{
|
||||
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||
//static_assert(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements.");
|
||||
#endif
|
||||
{
|
||||
POLYVOX_STATIC_ASSERT(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements.");
|
||||
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
m_tElements[2] = z;
|
||||
@ -551,11 +539,10 @@ namespace PolyVox
|
||||
*/
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline void Vector<Size, StorageType, OperationType>::setZ(StorageType tZ)
|
||||
{
|
||||
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||
//static_assert(Size >= 3, "You can only set the 'w' component from a vector with at least three elements.");
|
||||
#endif
|
||||
m_tElements[2] = tZ;
|
||||
{
|
||||
POLYVOX_STATIC_ASSERT(Size >= 3, "You can only set the 'w' component from a vector with at least three elements.");
|
||||
|
||||
m_tElements[2] = tZ;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -563,11 +550,10 @@ namespace PolyVox
|
||||
*/
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline void Vector<Size, StorageType, OperationType>::setW(StorageType tW)
|
||||
{
|
||||
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||
//static_assert(Size >= 4, "You can only set the 'w' component from a vector with at least four elements.");
|
||||
#endif
|
||||
m_tElements[3] = tW;
|
||||
{
|
||||
POLYVOX_STATIC_ASSERT(Size >= 4, "You can only set the 'w' component from a vector with at least four elements.");
|
||||
|
||||
m_tElements[3] = tW;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -663,7 +649,7 @@ namespace PolyVox
|
||||
{
|
||||
// Standard float rules apply for divide-by-zero
|
||||
m_tElements[ct] /= fLength;
|
||||
assert(m_tElements[ct] == m_tElements[ct]); //Will assert if NAN
|
||||
POLYVOX_ASSERT(m_tElements[ct] == m_tElements[ct], "Obtained NAN during vector normalisation. Perhaps the input vector was too short?");
|
||||
}
|
||||
}
|
||||
}//namespace PolyVox
|
||||
|
@ -1,65 +1,63 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PolyVoxCore/Impl/Utility.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
//Note: this function only works for inputs which are a power of two and not zero
|
||||
//If this is not the case then the output is undefined.
|
||||
uint8_t logBase2(uint32_t uInput)
|
||||
{
|
||||
//Debug mode validation
|
||||
assert(uInput != 0);
|
||||
assert(isPowerOf2(uInput));
|
||||
|
||||
//Release mode validation
|
||||
if(uInput == 0)
|
||||
{
|
||||
//throw std::invalid_argument("Cannot compute the log of zero.");
|
||||
}
|
||||
if(!isPowerOf2(uInput))
|
||||
{
|
||||
//throw std::invalid_argument("Input must be a power of two in order to compute the log.");
|
||||
}
|
||||
|
||||
uint32_t uResult = 0;
|
||||
while( (uInput >> uResult) != 0)
|
||||
{
|
||||
++uResult;
|
||||
}
|
||||
return static_cast<uint8_t>(uResult-1);
|
||||
}
|
||||
|
||||
|
||||
bool isPowerOf2(uint32_t uInput)
|
||||
{
|
||||
if(uInput == 0)
|
||||
return false;
|
||||
else
|
||||
return ((uInput & (uInput-1)) == 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PolyVoxCore/Impl/ErrorHandling.h"
|
||||
#include "PolyVoxCore/Impl/Utility.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
//Note: this function only works for inputs which are a power of two and not zero
|
||||
//If this is not the case then the output is undefined.
|
||||
uint8_t logBase2(uint32_t uInput)
|
||||
{
|
||||
//Debug mode validation
|
||||
POLYVOX_ASSERT(uInput != 0, "Cannot compute the log of zero.");
|
||||
POLYVOX_ASSERT(isPowerOf2(uInput), "Input must be a power of two in order to compute the log.");
|
||||
|
||||
//Release mode validation
|
||||
if(uInput == 0)
|
||||
{
|
||||
POLYVOX_THROW(std::invalid_argument, "Cannot compute the log of zero.");
|
||||
}
|
||||
if(!isPowerOf2(uInput))
|
||||
{
|
||||
POLYVOX_THROW(std::invalid_argument, "Input must be a power of two in order to compute the log.");
|
||||
}
|
||||
|
||||
uint32_t uResult = 0;
|
||||
while( (uInput >> uResult) != 0)
|
||||
{
|
||||
++uResult;
|
||||
}
|
||||
return static_cast<uint8_t>(uResult-1);
|
||||
}
|
||||
|
||||
|
||||
bool isPowerOf2(uint32_t uInput)
|
||||
{
|
||||
if(uInput == 0)
|
||||
return false;
|
||||
else
|
||||
return ((uInput & (uInput-1)) == 0);
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,6 @@
|
||||
# 3. This notice may not be removed or altered from any source
|
||||
# distribution.
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
||||
|
||||
PROJECT(PolyVoxUtil)
|
||||
|
||||
#Projects source files
|
||||
@ -42,7 +40,7 @@ SOURCE_GROUP("Sources" FILES ${UTIL_SRC_FILES})
|
||||
SOURCE_GROUP("Headers" FILES ${UTIL_INC_FILES})
|
||||
|
||||
#Tell CMake the paths
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include)
|
||||
#There has to be a better way!
|
||||
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release ${PolyVoxCore_BINARY_DIR})
|
||||
|
||||
|
@ -36,7 +36,7 @@ if(ENABLE_BINDINGS)
|
||||
include(${SWIG_USE_FILE})
|
||||
|
||||
include_directories(${PYTHON_INCLUDE_PATH})
|
||||
include_directories(${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore)
|
||||
include_directories(${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include/PolyVoxCore)
|
||||
link_directories(${PolyVoxCore_BINARY_DIR})
|
||||
|
||||
set(CMAKE_SWIG_FLAGS "")
|
||||
@ -48,6 +48,11 @@ if(ENABLE_BINDINGS)
|
||||
set_target_properties(${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTIES OUTPUT_NAME _PolyVoxCore)
|
||||
#set_target_properties(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTIES SUFFIX ".pyd")
|
||||
SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTY FOLDER "Bindings")
|
||||
|
||||
swig_add_module(PolyVoxCoreCSharp csharp PolyVoxCore.i)
|
||||
set(SWIG_MODULE_PolyVoxCoreCSharp_EXTRA_FLAGS "-dllimport;PolyVoxCoreCSharp") #This _should_ be inside UseSWIG.cmake - http://www.cmake.org/Bug/view.php?id=13814
|
||||
swig_link_libraries(PolyVoxCoreCSharp PolyVoxCore)
|
||||
SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCoreCSharp_REAL_NAME} PROPERTY FOLDER "Bindings")
|
||||
else()
|
||||
set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE)
|
||||
endif()
|
||||
|
@ -1,6 +1,7 @@
|
||||
%module PolyVoxCore
|
||||
|
||||
#define POLYVOX_API
|
||||
%include "PolyVoxCore/Impl/CompilerCapabilities.h"
|
||||
%include "Impl/TypeDef.h"
|
||||
#define __attribute__(x) //Silence DEPRECATED errors
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
%{
|
||||
#include "Raycast.h"
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
|
||||
template<typename VolumeType>
|
||||
class PyCallback
|
||||
{
|
||||
@ -43,11 +45,17 @@ PolyVox::RaycastResult raycastWithEndpointsPython(VolumeType* volData, const Pol
|
||||
return PolyVox::raycastWithEndpoints(volData, v3dStart, v3dEnd, newCallback);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%include "Raycast.h"
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
|
||||
template<typename VolumeType, typename Callback>
|
||||
PolyVox::RaycastResult raycastWithEndpointsPython(VolumeType* volData, const PolyVox::Vector3DFloat& v3dStart, const PolyVox::Vector3DFloat& v3dEnd, PyObject *callback);
|
||||
|
||||
%template(raycastWithEndpointsSimpleVolumeuint8) raycastWithEndpointsPython<PolyVox::SimpleVolume<uint8_t>, PyCallback<PolyVox::SimpleVolume<uint8_t> > >;
|
||||
|
||||
#endif
|
||||
|
@ -34,13 +34,29 @@ PROPERTY(PolyVox::Vector, z, getZ, setZ)
|
||||
STR()
|
||||
};
|
||||
|
||||
%template(Vector3DFloat) PolyVox::Vector<3,float,float>;
|
||||
%template(Vector3DDouble) PolyVox::Vector<3,double,double>;
|
||||
%template(Vector3DInt8) PolyVox::Vector<3,int8_t,int32_t>;
|
||||
%template(Vector3DUint8) PolyVox::Vector<3,uint8_t,int32_t>;
|
||||
%template(Vector3DInt16) PolyVox::Vector<3,int16_t,int32_t>;
|
||||
%template(Vector3DUint16) PolyVox::Vector<3,uint16_t,int32_t>;
|
||||
%template(Vector3DInt32) PolyVox::Vector<3,int32_t,int32_t>;
|
||||
%template(Vector3DUint32) PolyVox::Vector<3,uint32_t,int32_t>;
|
||||
%feature("pythonprepend") PolyVox::Vector::operator< %{
|
||||
import warnings
|
||||
warnings.warn("deprecated", DeprecationWarning)
|
||||
%}
|
||||
|
||||
//%csattributes PolyVox::Vector::operator< "[System.Obsolete(\"deprecated\")]"
|
||||
|
||||
%define VECTOR3(StorageType,OperationType,ReducedStorageType)
|
||||
%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType);
|
||||
%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType);
|
||||
%ignore PolyVox::Vector<3,StorageType,OperationType>::getW() const;
|
||||
%ignore PolyVox::Vector<3,StorageType,OperationType>::setW(ReducedStorageType);
|
||||
%ignore PolyVox::Vector<3,StorageType,OperationType>::setElements(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType);
|
||||
%template(Vector3D ## StorageType) PolyVox::Vector<3,StorageType,OperationType>;
|
||||
%enddef
|
||||
|
||||
VECTOR3(float,float,float)
|
||||
VECTOR3(double,double,double)
|
||||
VECTOR3(int8_t,int32_t,signed char)
|
||||
VECTOR3(uint8_t,int32_t,unsigned char)
|
||||
VECTOR3(int16_t,int32_t,signed short)
|
||||
VECTOR3(uint16_t,int32_t,unsigned short)
|
||||
VECTOR3(int32_t,int32_t,signed int)
|
||||
VECTOR3(uint32_t,int32_t,unsigned int)
|
||||
|
||||
//%rename(assign) Vector3DFloat::operator=;
|
||||
|
Reference in New Issue
Block a user