Moved some code around...
This commit is contained in:
91
library/CMakeLists.txt
Normal file
91
library/CMakeLists.txt
Normal file
@ -0,0 +1,91 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
||||
|
||||
PROJECT(PolyVox)
|
||||
|
||||
SET(POLYVOX_VERSION_MAJOR "0")
|
||||
SET(POLYVOX_VERSION_MINOR "1")
|
||||
SET(POLYVOX_VERSION_PATCH "0")
|
||||
SET(POLYVOX_VERSION "${POLYVOX_VERSION_MAJOR}.${POLYVOX_VERSION_MINOR}.${POLYVOX_VERSION_PATCH}")
|
||||
|
||||
#ADD_SUBDIRECTORY(examples/OpenGL)
|
||||
|
||||
#Projects source files
|
||||
SET(SRC_FILES
|
||||
source/IndexedSurfacePatch.cpp
|
||||
source/MarchingCubesTables.cpp
|
||||
source/Region.cpp
|
||||
source/RegionGeometry.cpp
|
||||
source/SurfaceExtractors.cpp
|
||||
source/SurfaceVertex.cpp
|
||||
source/Utility.cpp
|
||||
source/VolumeChangeTracker.cpp
|
||||
)
|
||||
|
||||
#Projects headers files
|
||||
SET(INC_FILES
|
||||
include/Block.h
|
||||
include/Block.inl
|
||||
include/BlockVolume.h
|
||||
include/BlockVolume.inl
|
||||
include/BlockVolumeIterator.h
|
||||
include/BlockVolumeIterator.inl
|
||||
include/Constants.h
|
||||
include/Enums.h
|
||||
include/GradientEstimators.h
|
||||
include/GradientEstimators.inl
|
||||
include/LinearVolume.h
|
||||
include/LinearVolume.inl
|
||||
include/IndexedSurfacePatch.h
|
||||
include/MarchingCubesTables.h
|
||||
include/PolyVoxForwardDeclarations.h
|
||||
include/Region.h
|
||||
include/RegionGeometry.h
|
||||
include/SurfaceExtractors.h
|
||||
include/SurfaceVertex.h
|
||||
include/TypeDef.h
|
||||
include/Utility.h
|
||||
include/Vector.h
|
||||
include/Vector.inl
|
||||
include/VolumeChangeTracker.h
|
||||
)
|
||||
|
||||
FIND_PACKAGE(Boost REQUIRED)
|
||||
|
||||
#under windows boost linking is automatic. Under Linux it is specified here. Might need changing for MinGW
|
||||
#IF(NOT WIN32)
|
||||
# SET(BOOST_LIBRARIES boost_program_options boost_filesystem)
|
||||
#ENDIF(NOT WIN32)
|
||||
|
||||
|
||||
|
||||
ADD_DEFINITIONS(-DPOLYVOX_EXPORT) #Export symbols in the .dll
|
||||
|
||||
#Appends "_d" to the generated library when in debug mode
|
||||
SET(CMAKE_DEBUG_POSTFIX "_d")
|
||||
|
||||
#"Sources" and "Headers" are the group names in Visual Studio.
|
||||
#They may have other uses too...
|
||||
SOURCE_GROUP("Sources" FILES ${SRC_FILES})
|
||||
SOURCE_GROUP("Headers" FILES ${INC_FILES})
|
||||
|
||||
#Tell CMake the paths
|
||||
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
#Build
|
||||
ADD_LIBRARY(PolyVox SHARED ${SRC_FILES} ${INC_FILES})
|
||||
#TARGET_LINK_LIBRARIES(PolyVox)
|
||||
SET_TARGET_PROPERTIES(PolyVox PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
|
||||
IF(WIN32)
|
||||
SET_TARGET_PROPERTIES(PolyVox PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports
|
||||
ENDIF(WIN32)
|
||||
|
||||
#Install
|
||||
INSTALL(TARGETS PolyVox
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
||||
|
||||
INSTALL(FILES ${INC_FILES} DESTINATION include/PolyVox)
|
||||
|
||||
ADD_SUBDIRECTORY(examples/OpenGL)
|
61
library/include/Block.h
Normal file
61
library/include/Block.h
Normal file
@ -0,0 +1,61 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_Block_H__
|
||||
#define __PolyVox_Block_H__
|
||||
|
||||
#pragma region Headers
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
class Block
|
||||
{
|
||||
//Make BlockVolumeIterator a friend
|
||||
friend class BlockVolumeIterator<VoxelType>;
|
||||
public:
|
||||
Block(boost::uint8_t uSideLengthPower);
|
||||
Block(const Block& rhs);
|
||||
~Block();
|
||||
|
||||
Block& operator=(const Block& rhs);
|
||||
|
||||
boost::uint16_t getSideLength(void) const;
|
||||
VoxelType getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const;
|
||||
|
||||
void setVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos, VoxelType tValue);
|
||||
|
||||
void fill(VoxelType tValue);
|
||||
|
||||
private:
|
||||
boost::uint8_t m_uSideLengthPower;
|
||||
boost::uint16_t m_uSideLength;
|
||||
VoxelType* m_tData;
|
||||
};
|
||||
}
|
||||
|
||||
#include "Block.inl"
|
||||
|
||||
#endif
|
124
library/include/Block.inl
Normal file
124
library/include/Block.inl
Normal file
@ -0,0 +1,124 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Headers
|
||||
#include <cassert>
|
||||
#include <cstring> //For memcpy
|
||||
#include <stdexcept> //for std::invalid_argument
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
#pragma region Constructors/Destructors
|
||||
template <typename VoxelType>
|
||||
Block<VoxelType>::Block(boost::uint8_t uSideLengthPower)
|
||||
:m_tData(0)
|
||||
{
|
||||
//Check the block size is sensible. This corresponds to a side length of 256 voxels
|
||||
if(uSideLengthPower > 8)
|
||||
{
|
||||
throw std::invalid_argument("Block side length power must be less than or equal to eight");
|
||||
}
|
||||
|
||||
//Compute the side length
|
||||
m_uSideLengthPower = uSideLengthPower;
|
||||
m_uSideLength = 0x01 << uSideLengthPower;
|
||||
|
||||
//If this fails an exception will be thrown. Memory is not
|
||||
//allocated and there is nothing else in this class to clean up
|
||||
m_tData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
Block<VoxelType>::Block(const Block<VoxelType>& rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
Block<VoxelType>::~Block()
|
||||
{
|
||||
delete[] m_tData;
|
||||
m_tData = 0;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Operators
|
||||
template <typename VoxelType>
|
||||
Block<VoxelType>& Block<VoxelType>::operator=(const Block<VoxelType>& rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
memcpy(m_tData, rhs.m_tData, m_uSideLength * m_uSideLength * m_uSideLength);
|
||||
return *this;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Getters
|
||||
template <typename VoxelType>
|
||||
boost::uint16_t Block<VoxelType>::getSideLength(void) const
|
||||
{
|
||||
return m_uSideLength;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType Block<VoxelType>::getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const
|
||||
{
|
||||
assert(uXPos < m_uSideLength);
|
||||
assert(uYPos < m_uSideLength);
|
||||
assert(uZPos < m_uSideLength);
|
||||
|
||||
return m_tData
|
||||
[
|
||||
uXPos +
|
||||
uYPos * m_uSideLength +
|
||||
uZPos * m_uSideLength * m_uSideLength
|
||||
];
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Setters
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::setVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos, VoxelType tValue)
|
||||
{
|
||||
assert(uXPos < m_uSideLength);
|
||||
assert(uYPos < m_uSideLength);
|
||||
assert(uZPos < m_uSideLength);
|
||||
|
||||
m_tData
|
||||
[
|
||||
uXPos +
|
||||
uYPos * m_uSideLength +
|
||||
uZPos * m_uSideLength * m_uSideLength
|
||||
] = tValue;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Other
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::fill(VoxelType tValue)
|
||||
{
|
||||
memset(m_tData, tValue, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
|
||||
}
|
||||
#pragma endregion
|
||||
}
|
86
library/include/BlockVolume.h
Normal file
86
library/include/BlockVolume.h
Normal file
@ -0,0 +1,86 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_BlockVolume_H__
|
||||
#define __PolyVox_BlockVolume_H__
|
||||
|
||||
#pragma region Headers
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
|
||||
#include <map>
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
class BlockVolume
|
||||
{
|
||||
//Make BlockVolumeIterator a friend
|
||||
friend class BlockVolumeIterator<VoxelType>;
|
||||
|
||||
public:
|
||||
BlockVolume(boost::uint8_t uSideLengthPower, boost::uint8_t uBlockSideLengthPower = 5);
|
||||
BlockVolume(const BlockVolume& rhs);
|
||||
~BlockVolume();
|
||||
|
||||
BlockVolume& operator=(const BlockVolume& rhs);
|
||||
|
||||
Region getEnclosingRegion(void) const;
|
||||
boost::uint16_t getSideLength(void) const;
|
||||
VoxelType getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const;
|
||||
VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
|
||||
|
||||
bool containsPoint(const Vector3DFloat& pos, float boundary) const;
|
||||
bool containsPoint(const Vector3DInt32& pos, boost::uint16_t boundary) const;
|
||||
BlockVolumeIterator<VoxelType> firstVoxel(void);
|
||||
void idle(boost::uint32_t uAmount);
|
||||
BlockVolumeIterator<VoxelType> lastVoxel(void);
|
||||
|
||||
private:
|
||||
Block<VoxelType>* getHomogenousBlock(VoxelType tHomogenousValue) const;
|
||||
|
||||
Block<VoxelType>** m_pBlocks;
|
||||
bool* m_pIsShared;
|
||||
bool* m_pIsPotentiallySharable;
|
||||
VoxelType* m_pHomogenousValue;
|
||||
mutable std::map<VoxelType, Block<VoxelType>*> m_pHomogenousBlocks;
|
||||
|
||||
boost::uint32_t m_uNoOfBlocksInVolume;
|
||||
boost::uint16_t m_uSideLengthInBlocks;
|
||||
|
||||
boost::uint8_t m_uSideLengthPower;
|
||||
boost::uint16_t m_uSideLength;
|
||||
|
||||
boost::uint8_t m_uBlockSideLengthPower;
|
||||
boost::uint16_t m_uBlockSideLength;
|
||||
};
|
||||
|
||||
//Some handy typedefs
|
||||
typedef BlockVolume<float> FloatBlockVolume;
|
||||
typedef BlockVolume<boost::uint8_t> UInt8BlockVolume;
|
||||
typedef BlockVolume<boost::uint16_t> UInt16BlockVolume;
|
||||
}
|
||||
|
||||
#include "BlockVolume.inl"
|
||||
|
||||
#endif
|
231
library/include/BlockVolume.inl
Normal file
231
library/include/BlockVolume.inl
Normal file
@ -0,0 +1,231 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Headers
|
||||
#include "Block.h"
|
||||
#include "Region.h"
|
||||
#include "Vector.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring> //For memcpy
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
#pragma region Constructors/Destructors
|
||||
template <typename VoxelType>
|
||||
BlockVolume<VoxelType>::BlockVolume(boost::uint8_t uSideLengthPower, boost::uint8_t uBlockSideLengthPower)
|
||||
:m_pBlocks(0)
|
||||
{
|
||||
//Check the volume size is sensible. This corresponds to a side length of 65536 voxels
|
||||
if(uSideLengthPower > 16)
|
||||
{
|
||||
throw std::invalid_argument("Volume side length power must be less than or equal to 16");
|
||||
}
|
||||
|
||||
//Compute the volume side length
|
||||
m_uSideLengthPower = uSideLengthPower;
|
||||
m_uSideLength = 0x01 << uSideLengthPower;
|
||||
|
||||
//Compute the block side length
|
||||
m_uBlockSideLengthPower = uBlockSideLengthPower;
|
||||
m_uBlockSideLength = 0x01 << uBlockSideLengthPower;
|
||||
|
||||
//Compute the side length in blocks
|
||||
m_uSideLengthInBlocks = m_uSideLength / m_uBlockSideLength;
|
||||
|
||||
//Compute number of blocks in the volume
|
||||
m_uNoOfBlocksInVolume = m_uSideLengthInBlocks * m_uSideLengthInBlocks * m_uSideLengthInBlocks;
|
||||
|
||||
//Create the blocks
|
||||
m_pBlocks = new Block<VoxelType>*[m_uNoOfBlocksInVolume];
|
||||
m_pIsShared = new bool[m_uNoOfBlocksInVolume];
|
||||
m_pIsPotentiallySharable = new bool[m_uNoOfBlocksInVolume];
|
||||
m_pHomogenousValue = new VoxelType[m_uNoOfBlocksInVolume];
|
||||
for(boost::uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
|
||||
{
|
||||
m_pBlocks[i] = getHomogenousBlock(0); //new Block<VoxelType>(uBlockSideLengthPower);
|
||||
m_pIsShared[i] = true;
|
||||
m_pIsPotentiallySharable[i] = false;
|
||||
m_pHomogenousValue[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
BlockVolume<VoxelType>::BlockVolume(const BlockVolume<VoxelType>& rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
BlockVolume<VoxelType>::~BlockVolume()
|
||||
{
|
||||
for(boost::uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
|
||||
{
|
||||
delete m_pBlocks[i];
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Operators
|
||||
template <typename VoxelType>
|
||||
BlockVolume<VoxelType>& BlockVolume<VoxelType>::operator=(const BlockVolume& rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*for(uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i)
|
||||
{
|
||||
//FIXME - Add checking...
|
||||
m_pBlocks[i] = SharedPtr<Block>(new Block);
|
||||
}*/
|
||||
|
||||
for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
|
||||
{
|
||||
//I think this is OK... If a block is in the homogeneous array it's ref count will be greater
|
||||
//than 1 as there will be the pointer in the volume and the pointer in the static homogeneous array.
|
||||
/*if(rhs.m_pBlocks[i].unique())
|
||||
{
|
||||
m_pBlocks[i] = SharedPtr<Block>(new Block(*(rhs.m_pBlocks[i])));
|
||||
}
|
||||
else
|
||||
{*/
|
||||
//we have a block in the homogeneous array - just copy the pointer.
|
||||
m_pBlocks[i] = rhs.m_pBlocks[i];
|
||||
//}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Getters
|
||||
template <typename VoxelType>
|
||||
Region BlockVolume<VoxelType>::getEnclosingRegion(void) const
|
||||
{
|
||||
return Region(Vector3DInt32(0,0,0), Vector3DInt32(m_uSideLength-1,m_uSideLength-1,m_uSideLength-1));
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
boost::uint16_t BlockVolume<VoxelType>::getSideLength(void) const
|
||||
{
|
||||
return m_uSideLength;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolume<VoxelType>::getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const
|
||||
{
|
||||
assert(uXPos < getSideLength());
|
||||
assert(uYPos < getSideLength());
|
||||
assert(uZPos < getSideLength());
|
||||
|
||||
const uint16_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const uint16_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
const uint16_t blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||
|
||||
const uint16_t xOffset = uXPos - (blockX << m_uBlockSideLengthPower);
|
||||
const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
|
||||
const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower);
|
||||
|
||||
const Block<VoxelType>* block = m_pBlocks
|
||||
[
|
||||
blockX +
|
||||
blockY * m_uSideLengthInBlocks +
|
||||
blockZ * m_uSideLengthInBlocks * m_uSideLengthInBlocks
|
||||
];
|
||||
|
||||
return block->getVoxelAt(xOffset,yOffset,zOffset);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolume<VoxelType>::getVoxelAt(const Vector3DUint16& v3dPos) const
|
||||
{
|
||||
assert(v3dPos.getX() < m_uSideLength);
|
||||
assert(v3dPos.getY() < m_uSideLength);
|
||||
assert(v3dPos.getZ() < m_uSideLength);
|
||||
|
||||
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Other
|
||||
template <typename VoxelType>
|
||||
bool BlockVolume<VoxelType>::containsPoint(const Vector3DFloat& pos, float boundary) const
|
||||
{
|
||||
return (pos.getX() <= m_uSideLength - 1 - boundary)
|
||||
&& (pos.getY() <= m_uSideLength - 1 - boundary)
|
||||
&& (pos.getZ() <= m_uSideLength - 1 - boundary)
|
||||
&& (pos.getX() >= boundary)
|
||||
&& (pos.getY() >= boundary)
|
||||
&& (pos.getZ() >= boundary);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool BlockVolume<VoxelType>::containsPoint(const Vector3DInt32& pos, boost::uint16_t boundary) const
|
||||
{
|
||||
return (pos.getX() <= m_uSideLength - 1 - boundary)
|
||||
&& (pos.getY() <= m_uSideLength - 1 - boundary)
|
||||
&& (pos.getZ() <= m_uSideLength - 1 - boundary)
|
||||
&& (pos.getX() >= boundary)
|
||||
&& (pos.getY() >= boundary)
|
||||
&& (pos.getZ() >= boundary);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
BlockVolumeIterator<VoxelType> BlockVolume<VoxelType>::firstVoxel(void)
|
||||
{
|
||||
BlockVolumeIterator<VoxelType> iter(*this);
|
||||
iter.setPosition(0,0,0);
|
||||
return iter;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void BlockVolume<VoxelType>::idle(boost::uint32_t uAmount)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
BlockVolumeIterator<VoxelType> BlockVolume<VoxelType>::lastVoxel(void)
|
||||
{
|
||||
BlockVolumeIterator<VoxelType> iter(*this);
|
||||
iter.setPosition(m_uSideLength-1,m_uSideLength-1,m_uSideLength-1);
|
||||
return iter;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Private Implementation
|
||||
template <typename VoxelType>
|
||||
Block<VoxelType>* BlockVolume<VoxelType>::getHomogenousBlock(VoxelType tHomogenousValue) const
|
||||
{
|
||||
typename std::map<VoxelType, Block<VoxelType>*>::iterator iterResult = m_pHomogenousBlocks.find(tHomogenousValue);
|
||||
if(iterResult == m_pHomogenousBlocks.end())
|
||||
{
|
||||
Block<VoxelType>* pBlock = new Block<VoxelType>(m_uBlockSideLengthPower);
|
||||
pBlock->fill(tHomogenousValue);
|
||||
m_pHomogenousBlocks.insert(std::make_pair(tHomogenousValue, pBlock));
|
||||
return pBlock;
|
||||
}
|
||||
return iterResult->second;
|
||||
}
|
||||
#pragma endregion
|
||||
}
|
137
library/include/BlockVolumeIterator.h
Normal file
137
library/include/BlockVolumeIterator.h
Normal file
@ -0,0 +1,137 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __VolumeIterator_H__
|
||||
#define __VolumeIterator_H__
|
||||
|
||||
#pragma region Headers
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
class BlockVolumeIterator
|
||||
{
|
||||
public:
|
||||
BlockVolumeIterator(BlockVolume<VoxelType>& volume);
|
||||
~BlockVolumeIterator();
|
||||
|
||||
bool operator==(const BlockVolumeIterator& rhs);
|
||||
bool operator<(const BlockVolumeIterator& rhs);
|
||||
bool operator>(const BlockVolumeIterator& rhs);
|
||||
bool operator<=(const BlockVolumeIterator& rhs);
|
||||
bool operator>=(const BlockVolumeIterator& rhs);
|
||||
|
||||
float getAveragedVoxel(boost::uint16_t size) const;
|
||||
boost::uint16_t getPosX(void) const;
|
||||
boost::uint16_t getPosY(void) const;
|
||||
boost::uint16_t getPosZ(void) const;
|
||||
VoxelType getVoxel(void) const;
|
||||
|
||||
void setPosition(const Vector3DInt16& v3dNewPos);
|
||||
void setPosition(boost::uint16_t xPos, boost::uint16_t yPos, boost::uint16_t zPos);
|
||||
void setValidRegion(const Region& region);
|
||||
void setValidRegion(boost::uint16_t xFirst, boost::uint16_t yFirst, boost::uint16_t zFirst, boost::uint16_t xLast, boost::uint16_t yLast, boost::uint16_t zLast);
|
||||
void setVoxel(VoxelType tValue);
|
||||
|
||||
bool isValidForRegion(void) const;
|
||||
void moveForwardInRegionFast(void);
|
||||
bool moveForwardInRegionXYZ(void);
|
||||
|
||||
VoxelType peekVoxel1nx1ny1nz(void) const;
|
||||
VoxelType peekVoxel1nx1ny0pz(void) const;
|
||||
VoxelType peekVoxel1nx1ny1pz(void) const;
|
||||
VoxelType peekVoxel1nx0py1nz(void) const;
|
||||
VoxelType peekVoxel1nx0py0pz(void) const;
|
||||
VoxelType peekVoxel1nx0py1pz(void) const;
|
||||
VoxelType peekVoxel1nx1py1nz(void) const;
|
||||
VoxelType peekVoxel1nx1py0pz(void) const;
|
||||
VoxelType peekVoxel1nx1py1pz(void) const;
|
||||
|
||||
VoxelType peekVoxel0px1ny1nz(void) const;
|
||||
VoxelType peekVoxel0px1ny0pz(void) const;
|
||||
VoxelType peekVoxel0px1ny1pz(void) const;
|
||||
VoxelType peekVoxel0px0py1nz(void) const;
|
||||
VoxelType peekVoxel0px0py0pz(void) const;
|
||||
VoxelType peekVoxel0px0py1pz(void) const;
|
||||
VoxelType peekVoxel0px1py1nz(void) const;
|
||||
VoxelType peekVoxel0px1py0pz(void) const;
|
||||
VoxelType peekVoxel0px1py1pz(void) const;
|
||||
|
||||
VoxelType peekVoxel1px1ny1nz(void) const;
|
||||
VoxelType peekVoxel1px1ny0pz(void) const;
|
||||
VoxelType peekVoxel1px1ny1pz(void) const;
|
||||
VoxelType peekVoxel1px0py1nz(void) const;
|
||||
VoxelType peekVoxel1px0py0pz(void) const;
|
||||
VoxelType peekVoxel1px0py1pz(void) const;
|
||||
VoxelType peekVoxel1px1py1nz(void) const;
|
||||
VoxelType peekVoxel1px1py0pz(void) const;
|
||||
VoxelType peekVoxel1px1py1pz(void) const;
|
||||
|
||||
private:
|
||||
|
||||
//The current volume
|
||||
BlockVolume<VoxelType>& mVolume;
|
||||
|
||||
//The current position in the volume
|
||||
boost::uint16_t mXPosInVolume;
|
||||
boost::uint16_t mYPosInVolume;
|
||||
boost::uint16_t mZPosInVolume;
|
||||
|
||||
//The position of the current block
|
||||
boost::uint16_t mXBlock;
|
||||
boost::uint16_t mYBlock;
|
||||
boost::uint16_t mZBlock;
|
||||
|
||||
//The offset into the current block
|
||||
boost::uint16_t mXPosInBlock;
|
||||
boost::uint16_t mYPosInBlock;
|
||||
boost::uint16_t mZPosInBlock;
|
||||
|
||||
//Other current position information
|
||||
VoxelType* mCurrentVoxel;
|
||||
boost::uint32_t mBlockIndexInVolume;
|
||||
boost::uint32_t mVoxelIndexInBlock;
|
||||
|
||||
boost::uint16_t mXRegionFirst;
|
||||
boost::uint16_t mYRegionFirst;
|
||||
boost::uint16_t mZRegionFirst;
|
||||
boost::uint16_t mXRegionLast;
|
||||
boost::uint16_t mYRegionLast;
|
||||
boost::uint16_t mZRegionLast;
|
||||
|
||||
boost::uint16_t mXRegionFirstBlock;
|
||||
boost::uint16_t mYRegionFirstBlock;
|
||||
boost::uint16_t mZRegionFirstBlock;
|
||||
boost::uint16_t mXRegionLastBlock;
|
||||
boost::uint16_t mYRegionLastBlock;
|
||||
boost::uint16_t mZRegionLastBlock;
|
||||
|
||||
bool mIsValidForRegion;
|
||||
};
|
||||
}
|
||||
|
||||
#include "BlockVolumeIterator.inl"
|
||||
|
||||
#endif
|
672
library/include/BlockVolumeIterator.inl
Normal file
672
library/include/BlockVolumeIterator.inl
Normal file
@ -0,0 +1,672 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Headers
|
||||
#include "Block.h"
|
||||
#include "BlockVolume.h"
|
||||
#include "Vector.h"
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
#pragma region Constructors/Destructors
|
||||
template <typename VoxelType>
|
||||
BlockVolumeIterator<VoxelType>::BlockVolumeIterator(BlockVolume<VoxelType>& volume)
|
||||
:mVolume(volume)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
BlockVolumeIterator<VoxelType>::~BlockVolumeIterator()
|
||||
{
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Operators
|
||||
template <typename VoxelType>
|
||||
bool BlockVolumeIterator<VoxelType>::operator==(const BlockVolumeIterator<VoxelType>& rhs)
|
||||
{
|
||||
//We could just check whether the two mCurrentVoxel pointers are equal, but this may not
|
||||
//be safe in the future if we decide to allow blocks to be shared between volumes
|
||||
//So we really check whether the positions are the same.
|
||||
//NOTE: With all iterator comparisons it is the users job to ensure they at least point
|
||||
//to the same volume. Otherwise they are not comparible.
|
||||
assert(&mVolume == &rhs.mVolume);
|
||||
return
|
||||
(
|
||||
(mXPosInVolume == rhs.mXPosInVolume) &&
|
||||
(mYPosInVolume == rhs.mYPosInVolume) &&
|
||||
(mZPosInVolume == rhs.mZPosInVolume)
|
||||
);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool BlockVolumeIterator<VoxelType>::operator<(const BlockVolumeIterator<VoxelType>& rhs)
|
||||
{
|
||||
assert(&mVolume == &rhs.mVolume);
|
||||
|
||||
if(mZPosInVolume < rhs.mZPosInVolume)
|
||||
return true;
|
||||
if(mZPosInVolume > rhs.mZPosInVolume)
|
||||
return false;
|
||||
|
||||
if(mYPosInVolume < rhs.mYPosInVolume)
|
||||
return true;
|
||||
if(mYPosInVolume > rhs.mYPosInVolume)
|
||||
return false;
|
||||
|
||||
if(mXPosInVolume < rhs.mXPosInVolume)
|
||||
return true;
|
||||
if(mXPosInVolume > rhs.mXPosInVolume)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool BlockVolumeIterator<VoxelType>::operator>(const BlockVolumeIterator<VoxelType>& rhs)
|
||||
{
|
||||
assert(&mVolume == &rhs.mVolume);
|
||||
return (rhs < *this);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool BlockVolumeIterator<VoxelType>::operator<=(const BlockVolumeIterator<VoxelType>& rhs)
|
||||
{
|
||||
assert(&mVolume == &rhs.mVolume);
|
||||
return (rhs > *this);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool BlockVolumeIterator<VoxelType>::operator>=(const BlockVolumeIterator<VoxelType>& rhs)
|
||||
{
|
||||
assert(&mVolume == &rhs.mVolume);
|
||||
return (rhs < *this);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Getters
|
||||
template <typename VoxelType>
|
||||
float BlockVolumeIterator<VoxelType>::getAveragedVoxel(boost::uint16_t size) const
|
||||
{
|
||||
assert(mXPosInVolume >= size);
|
||||
assert(mYPosInVolume >= size);
|
||||
assert(mZPosInVolume >= size);
|
||||
assert(mXPosInVolume < mVolume.getSideLength() - (size + 1));
|
||||
assert(mYPosInVolume < mVolume.getSideLength() - (size + 1));
|
||||
assert(mZPosInVolume < mVolume.getSideLength() - (size + 1));
|
||||
|
||||
float sum = 0.0;
|
||||
for(uint16_t z = mZPosInVolume-size; z <= mZPosInVolume+size; ++z)
|
||||
{
|
||||
for(uint16_t y = mYPosInVolume-size; y <= mYPosInVolume+size; ++y)
|
||||
{
|
||||
for(uint16_t x = mXPosInVolume-size; x <= mXPosInVolume+size; ++x)
|
||||
{
|
||||
if(mVolume.getVoxelAt(x,y,z) != 0)
|
||||
{
|
||||
sum += 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t kernelSideLength = size * 2 + 1;
|
||||
uint16_t kernelVolume = kernelSideLength * kernelSideLength * kernelSideLength;
|
||||
|
||||
sum /= static_cast<float>(kernelVolume);
|
||||
return sum;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
boost::uint16_t BlockVolumeIterator<VoxelType>::getPosX(void) const
|
||||
{
|
||||
return mXPosInVolume;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
boost::uint16_t BlockVolumeIterator<VoxelType>::getPosY(void) const
|
||||
{
|
||||
return mYPosInVolume;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
boost::uint16_t BlockVolumeIterator<VoxelType>::getPosZ(void) const
|
||||
{
|
||||
return mZPosInVolume;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::getVoxel(void) const
|
||||
{
|
||||
return *mCurrentVoxel;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Setters
|
||||
template <typename VoxelType>
|
||||
void BlockVolumeIterator<VoxelType>::setPosition(const Vector3DInt16& v3dNewPos)
|
||||
{
|
||||
setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void BlockVolumeIterator<VoxelType>::setPosition(boost::uint16_t xPos, boost::uint16_t yPos, boost::uint16_t zPos)
|
||||
{
|
||||
mXPosInVolume = xPos;
|
||||
mYPosInVolume = yPos;
|
||||
mZPosInVolume = zPos;
|
||||
|
||||
mXBlock = mXPosInVolume >> mVolume.m_uBlockSideLengthPower;
|
||||
mYBlock = mYPosInVolume >> mVolume.m_uBlockSideLengthPower;
|
||||
mZBlock = mZPosInVolume >> mVolume.m_uBlockSideLengthPower;
|
||||
|
||||
mXPosInBlock = mXPosInVolume - (mXBlock << mVolume.m_uBlockSideLengthPower);
|
||||
mYPosInBlock = mYPosInVolume - (mYBlock << mVolume.m_uBlockSideLengthPower);
|
||||
mZPosInBlock = mZPosInVolume - (mZBlock << mVolume.m_uBlockSideLengthPower);
|
||||
|
||||
mBlockIndexInVolume = mXBlock +
|
||||
mYBlock * mVolume.m_uSideLengthInBlocks +
|
||||
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
|
||||
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
||||
|
||||
mVoxelIndexInBlock = mXPosInBlock +
|
||||
mYPosInBlock * mVolume.m_uBlockSideLength +
|
||||
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
|
||||
|
||||
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void BlockVolumeIterator<VoxelType>::setValidRegion(const Region& region)
|
||||
{
|
||||
setValidRegion(region.getLowerCorner().getX(),region.getLowerCorner().getY(),region.getLowerCorner().getZ(),region.getUpperCorner().getX(),region.getUpperCorner().getY(),region.getUpperCorner().getZ());
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void BlockVolumeIterator<VoxelType>::setValidRegion(boost::uint16_t xFirst, boost::uint16_t yFirst, boost::uint16_t zFirst, boost::uint16_t xLast, boost::uint16_t yLast, boost::uint16_t zLast)
|
||||
{
|
||||
mXRegionFirst = xFirst;
|
||||
mYRegionFirst = yFirst;
|
||||
mZRegionFirst = zFirst;
|
||||
|
||||
mXRegionLast = xLast;
|
||||
mYRegionLast = yLast;
|
||||
mZRegionLast = zLast;
|
||||
|
||||
mXRegionFirstBlock = mXRegionFirst >> mVolume.m_uBlockSideLengthPower;
|
||||
mYRegionFirstBlock = mYRegionFirst >> mVolume.m_uBlockSideLengthPower;
|
||||
mZRegionFirstBlock = mZRegionFirst >> mVolume.m_uBlockSideLengthPower;
|
||||
|
||||
mXRegionLastBlock = mXRegionLast >> mVolume.m_uBlockSideLengthPower;
|
||||
mYRegionLastBlock = mYRegionLast >> mVolume.m_uBlockSideLengthPower;
|
||||
mZRegionLastBlock = mZRegionLast >> mVolume.m_uBlockSideLengthPower;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void BlockVolumeIterator<VoxelType>::setVoxel(VoxelType tValue)
|
||||
{
|
||||
const boost::uint32_t uBlockIndex =
|
||||
mXBlock +
|
||||
mYBlock * mVolume.m_uSideLengthInBlocks +
|
||||
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
|
||||
|
||||
const bool bIsShared = mVolume.m_pIsShared[uBlockIndex];
|
||||
const VoxelType tHomogenousValue = mVolume.m_pHomogenousValue[uBlockIndex];
|
||||
if(bIsShared)
|
||||
{
|
||||
if(tHomogenousValue != tValue)
|
||||
{
|
||||
mVolume.m_pBlocks[uBlockIndex] = new Block<VoxelType>(mVolume.m_uBlockSideLengthPower);
|
||||
mVolume.m_pIsShared[uBlockIndex] = false;
|
||||
mVolume.m_pBlocks[uBlockIndex]->fill(tHomogenousValue);
|
||||
mCurrentVoxel = mVolume.m_pBlocks[uBlockIndex]->m_tData + mVoxelIndexInBlock;
|
||||
*mCurrentVoxel = tValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//There is a chance that setting this voxel makes the block homogenous and therefore shareable.
|
||||
mVolume.m_pIsPotentiallySharable[uBlockIndex] = true;
|
||||
*mCurrentVoxel = tValue;
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Other
|
||||
template <typename VoxelType>
|
||||
bool BlockVolumeIterator<VoxelType>::isValidForRegion(void) const
|
||||
{
|
||||
return mIsValidForRegion;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void BlockVolumeIterator<VoxelType>::moveForwardInRegionFast(void)
|
||||
{
|
||||
mXPosInBlock++;
|
||||
mCurrentVoxel++;
|
||||
mXPosInVolume++;
|
||||
if((mXPosInBlock == mVolume.m_uBlockSideLength) || (mXPosInVolume > mXRegionLast))
|
||||
{
|
||||
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * mVolume.m_uBlockSideLength));
|
||||
mXPosInBlock = mXPosInVolume - (mXBlock << mVolume.m_uBlockSideLengthPower);
|
||||
mVoxelIndexInBlock = mXPosInBlock +
|
||||
mYPosInBlock * mVolume.m_uBlockSideLength +
|
||||
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
|
||||
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
||||
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
|
||||
|
||||
mYPosInBlock++;
|
||||
mYPosInVolume++;
|
||||
mCurrentVoxel += mVolume.m_uBlockSideLength;
|
||||
if((mYPosInBlock == mVolume.m_uBlockSideLength) || (mYPosInVolume > mYRegionLast))
|
||||
{
|
||||
mYPosInVolume = (std::max)(mYRegionFirst,uint16_t(mYBlock * mVolume.m_uBlockSideLength));
|
||||
mYPosInBlock = mYPosInVolume - (mYBlock << mVolume.m_uBlockSideLengthPower);
|
||||
mVoxelIndexInBlock = mXPosInBlock +
|
||||
mYPosInBlock * mVolume.m_uBlockSideLength +
|
||||
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
|
||||
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
||||
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
|
||||
|
||||
mZPosInBlock++;
|
||||
mZPosInVolume++;
|
||||
mCurrentVoxel += mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
|
||||
|
||||
if((mZPosInBlock == mVolume.m_uBlockSideLength) || (mZPosInVolume > mZRegionLast))
|
||||
{
|
||||
//At this point we've left the current block. Find a new one...
|
||||
|
||||
++mXBlock;
|
||||
++mBlockIndexInVolume;
|
||||
if(mXBlock > mXRegionLastBlock)
|
||||
{
|
||||
mXBlock = mXRegionFirstBlock;
|
||||
mBlockIndexInVolume = mXBlock +
|
||||
mYBlock * mVolume.m_uSideLengthInBlocks +
|
||||
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
|
||||
|
||||
++mYBlock;
|
||||
mBlockIndexInVolume += mVolume.m_uSideLengthInBlocks;
|
||||
if(mYBlock > mYRegionLastBlock)
|
||||
{
|
||||
mYBlock = mYRegionFirstBlock;
|
||||
mBlockIndexInVolume = mXBlock +
|
||||
mYBlock * mVolume.m_uSideLengthInBlocks +
|
||||
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
|
||||
|
||||
++mZBlock;
|
||||
mBlockIndexInVolume += mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
|
||||
if(mZBlock > mZRegionLastBlock)
|
||||
{
|
||||
mIsValidForRegion = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
||||
//mCurrentBlock = mVolume->m_pBlocks[mBlockIndexInVolume];
|
||||
|
||||
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * mVolume.m_uBlockSideLength));
|
||||
mYPosInVolume = (std::max)(mYRegionFirst,uint16_t(mYBlock * mVolume.m_uBlockSideLength));
|
||||
mZPosInVolume = (std::max)(mZRegionFirst,uint16_t(mZBlock * mVolume.m_uBlockSideLength));
|
||||
|
||||
mXPosInBlock = mXPosInVolume - (mXBlock << mVolume.m_uBlockSideLengthPower);
|
||||
mYPosInBlock = mYPosInVolume - (mYBlock << mVolume.m_uBlockSideLengthPower);
|
||||
mZPosInBlock = mZPosInVolume - (mZBlock << mVolume.m_uBlockSideLengthPower);
|
||||
|
||||
mVoxelIndexInBlock = mXPosInBlock +
|
||||
mYPosInBlock * mVolume.m_uBlockSideLength +
|
||||
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
|
||||
|
||||
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool BlockVolumeIterator<VoxelType>::moveForwardInRegionXYZ(void)
|
||||
{
|
||||
if(mXPosInVolume < mXRegionLast)
|
||||
{
|
||||
++mXPosInVolume;
|
||||
if(mXPosInVolume % mVolume.m_uBlockSideLength != 0)
|
||||
{
|
||||
//No need to compute new block.
|
||||
++mVoxelIndexInBlock;
|
||||
++mCurrentVoxel;
|
||||
}
|
||||
else
|
||||
{
|
||||
//A more complex situation. Just call setPosition().
|
||||
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mXPosInVolume = mXRegionFirst;
|
||||
if(mYPosInVolume < mYRegionLast)
|
||||
{
|
||||
++mYPosInVolume;
|
||||
//In the case of 'X' we used a trick to avoid calling this evey time. It's hard to use the same
|
||||
//trick here because the x position has been reset and so is likely to be in a different block.
|
||||
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
mYPosInVolume = mYRegionFirst;
|
||||
if(mZPosInVolume < mZRegionLast)
|
||||
{
|
||||
++mZPosInVolume;
|
||||
//In the case of 'X' we used a trick to avoid calling this evey time. It's hard to use the same
|
||||
//trick here because the x position has been reset and so is likely to be in a different block.
|
||||
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
//We've hit the end of the region. Reset x and y positions to where they were.
|
||||
mXPosInVolume = mXRegionLast;
|
||||
mYPosInVolume = mYRegionLast;
|
||||
|
||||
//Return false to indicate we failed to move forward.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Peekers
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1ny1nz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume-1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1ny0pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1ny1pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume+1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx0py1nz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel - 1 - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume-1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx0py0pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel - 1);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx0py1pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume+1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1py1nz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume-1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1py0pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1py1pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel - 1 + mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume+1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1ny1nz(void) const
|
||||
{
|
||||
if((mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel - mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume-1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1ny0pz(void) const
|
||||
{
|
||||
if((mYPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel - mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1ny1pz(void) const
|
||||
{
|
||||
if((mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel - mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume+1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px0py1nz(void) const
|
||||
{
|
||||
if((mZPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume-1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px0py0pz(void) const
|
||||
{
|
||||
return *mCurrentVoxel;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px0py1pz(void) const
|
||||
{
|
||||
if((mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume+1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1py1nz(void) const
|
||||
{
|
||||
if((mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel + mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume-1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1py0pz(void) const
|
||||
{
|
||||
if((mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel + mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1py1pz(void) const
|
||||
{
|
||||
if((mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel + mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume+1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1ny1nz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume-1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1ny0pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1ny1pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume+1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px0py1nz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel + 1 - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume-1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px0py0pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel + 1);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px0py1pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume+1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1py1nz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume-1);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1py0pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1py1pz(void) const
|
||||
{
|
||||
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
|
||||
{
|
||||
return *(mCurrentVoxel + 1 + mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
|
||||
}
|
||||
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume+1);
|
||||
}
|
||||
#pragma endregion
|
||||
}
|
45
library/include/Constants.h
Normal file
45
library/include/Constants.h
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_Constants_H__
|
||||
#define __PolyVox_Constants_H__
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
//FIXME - i think we can define mod using a bitmask which flattens the upper bits. Should define that here.
|
||||
//const boost::uint32_t POLYVOX_BLOCK_SIDE_LENGTH_POWER = 5;
|
||||
//const boost::uint32_t POLYVOX_BLOCK_SIDE_LENGTH = (0x0001 << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
|
||||
//const boost::uint32_t POLYVOX_NO_OF_VOXELS_IN_BLOCK = (POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH);
|
||||
|
||||
const boost::uint16_t POLYVOX_VOLUME_SIDE_LENGTH_POWER = 8;
|
||||
const boost::uint16_t POLYVOX_VOLUME_SIDE_LENGTH = (0x0001 << POLYVOX_VOLUME_SIDE_LENGTH_POWER);
|
||||
//const boost::uint32_t POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS = (POLYVOX_VOLUME_SIDE_LENGTH >> POLYVOX_BLOCK_SIDE_LENGTH_POWER);
|
||||
//const boost::uint32_t POLYVOX_NO_OF_BLOCKS_IN_VOLUME = (POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS);
|
||||
//const boost::uint32_t POLYVOX_NO_OF_VOXELS_IN_VOLUME = (POLYVOX_VOLUME_SIDE_LENGTH * POLYVOX_VOLUME_SIDE_LENGTH * POLYVOX_VOLUME_SIDE_LENGTH);
|
||||
|
||||
const boost::uint16_t POLYVOX_REGION_SIDE_LENGTH_POWER = 4;
|
||||
const boost::uint16_t POLYVOX_REGION_SIDE_LENGTH = (0x0001 << POLYVOX_REGION_SIDE_LENGTH_POWER);
|
||||
const boost::uint16_t POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS = (POLYVOX_VOLUME_SIDE_LENGTH >> POLYVOX_REGION_SIDE_LENGTH_POWER);
|
||||
}
|
||||
|
||||
#endif
|
35
library/include/Enums.h
Normal file
35
library/include/Enums.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_Enums_H__
|
||||
#define __PolyVox_Enums_H__
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
enum NormalGenerationMethod
|
||||
{
|
||||
SIMPLE,
|
||||
CENTRAL_DIFFERENCE,
|
||||
SOBEL
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
41
library/include/GradientEstimators.h
Normal file
41
library/include/GradientEstimators.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_GradientEstimators_H__
|
||||
#define __PolyVox_GradientEstimators_H__
|
||||
|
||||
#include "BlockVolumeIterator.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
Vector3DFloat computeCentralDifferenceGradient(const BlockVolumeIterator<VoxelType>& volIter);
|
||||
|
||||
template <typename VoxelType>
|
||||
Vector3DFloat computeSmoothCentralDifferenceGradient(BlockVolumeIterator<VoxelType>& volIter);
|
||||
|
||||
template <typename VoxelType>
|
||||
Vector3DFloat computeSobelGradient(const BlockVolumeIterator<VoxelType>& volIter);
|
||||
}
|
||||
|
||||
#include "GradientEstimators.inl"
|
||||
|
||||
#endif //__PolyVox_GradientEstimators_H__
|
158
library/include/GradientEstimators.inl
Normal file
158
library/include/GradientEstimators.inl
Normal file
@ -0,0 +1,158 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
Vector3DFloat computeCentralDifferenceGradient(const BlockVolumeIterator<VoxelType>& volIter)
|
||||
{
|
||||
//FIXME - bitwise way of doing this?
|
||||
VoxelType voxel1nx = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
|
||||
VoxelType voxel1px = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
|
||||
|
||||
VoxelType voxel1ny = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
|
||||
VoxelType voxel1py = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
|
||||
|
||||
VoxelType voxel1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
|
||||
VoxelType voxel1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
|
||||
|
||||
return Vector3DFloat
|
||||
(
|
||||
static_cast<float>(voxel1px) - static_cast<float>(voxel1nx),
|
||||
static_cast<float>(voxel1py) - static_cast<float>(voxel1ny),
|
||||
static_cast<float>(voxel1pz) - static_cast<float>(voxel1nz)
|
||||
);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
Vector3DFloat computeSmoothCentralDifferenceGradient(BlockVolumeIterator<VoxelType>& volIter)
|
||||
{
|
||||
boost::uint16_t initialX = volIter.getPosX();
|
||||
boost::uint16_t initialY = volIter.getPosY();
|
||||
boost::uint16_t initialZ = volIter.getPosZ();
|
||||
|
||||
//FIXME - bitwise way of doing this?
|
||||
volIter.setPosition(initialX-1, initialY, initialZ);
|
||||
float voxel1nx = volIter.getAveragedVoxel(1);
|
||||
volIter.setPosition(initialX+1, initialY, initialZ);
|
||||
float voxel1px = volIter.getAveragedVoxel(1);
|
||||
|
||||
volIter.setPosition(initialX, initialY-1, initialZ);
|
||||
float voxel1ny = volIter.getAveragedVoxel(1);
|
||||
volIter.setPosition(initialX, initialY+1, initialZ);
|
||||
float voxel1py = volIter.getAveragedVoxel(1);
|
||||
|
||||
volIter.setPosition(initialX, initialY, initialZ-1);
|
||||
float voxel1nz = volIter.getAveragedVoxel(1);
|
||||
volIter.setPosition(initialX, initialY, initialZ+1);
|
||||
float voxel1pz = volIter.getAveragedVoxel(1);
|
||||
|
||||
return Vector3DFloat
|
||||
(
|
||||
voxel1px - voxel1nx,
|
||||
voxel1py - voxel1ny,
|
||||
voxel1pz - voxel1nz
|
||||
);
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
Vector3DFloat computeSobelGradient(const BlockVolumeIterator<VoxelType>& volIter)
|
||||
{
|
||||
static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, {
|
||||
{3,6,3}, {6,0,6}, {3,6,3} }, { {2,3,2}, {3,6,3}, {2,3,2} } };
|
||||
|
||||
const VoxelType pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz() > 0 ? 1: 0;
|
||||
|
||||
const VoxelType pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
|
||||
//const VoxelType pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz() > 0 ? 1: 0;
|
||||
|
||||
const VoxelType pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz() > 0 ? 1: 0;
|
||||
|
||||
|
||||
|
||||
const int xGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) -
|
||||
weights[1][0][0] * ( pVoxel1nx1ny0pz) - weights[2][0][0] *
|
||||
( pVoxel1nx1ny1pz) - weights[0][1][0] * ( pVoxel1nx0py1nz) -
|
||||
weights[1][1][0] * ( pVoxel1nx0py0pz) - weights[2][1][0] *
|
||||
( pVoxel1nx0py1pz) - weights[0][2][0] * ( pVoxel1nx1py1nz) -
|
||||
weights[1][2][0] * ( pVoxel1nx1py0pz) - weights[2][2][0] *
|
||||
( pVoxel1nx1py1pz) + weights[0][0][2] * ( pVoxel1px1ny1nz) +
|
||||
weights[1][0][2] * ( pVoxel1px1ny0pz) + weights[2][0][2] *
|
||||
( pVoxel1px1ny1pz) + weights[0][1][2] * ( pVoxel1px0py1nz) +
|
||||
weights[1][1][2] * ( pVoxel1px0py0pz) + weights[2][1][2] *
|
||||
( pVoxel1px0py1pz) + weights[0][2][2] * ( pVoxel1px1py1nz) +
|
||||
weights[1][2][2] * ( pVoxel1px1py0pz) + weights[2][2][2] *
|
||||
( pVoxel1px1py1pz));
|
||||
|
||||
const int yGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) -
|
||||
weights[1][0][0] * ( pVoxel1nx1ny0pz) - weights[2][0][0] *
|
||||
( pVoxel1nx1ny1pz) + weights[0][2][0] * ( pVoxel1nx1py1nz) +
|
||||
weights[1][2][0] * ( pVoxel1nx1py0pz) + weights[2][2][0] *
|
||||
( pVoxel1nx1py1pz) - weights[0][0][1] * ( pVoxel0px1ny1nz) -
|
||||
weights[1][0][1] * ( pVoxel0px1ny0pz) - weights[2][0][1] *
|
||||
( pVoxel0px1ny1pz) + weights[0][2][1] * ( pVoxel0px1py1nz) +
|
||||
weights[1][2][1] * ( pVoxel0px1py0pz) + weights[2][2][1] *
|
||||
( pVoxel0px1py1pz) - weights[0][0][2] * ( pVoxel1px1ny1nz) -
|
||||
weights[1][0][2] * ( pVoxel1px1ny0pz) - weights[2][0][2] *
|
||||
( pVoxel1px1ny1pz) + weights[0][2][2] * ( pVoxel1px1py1nz) +
|
||||
weights[1][2][2] * ( pVoxel1px1py0pz) + weights[2][2][2] *
|
||||
( pVoxel1px1py1pz));
|
||||
|
||||
const int zGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) +
|
||||
weights[2][0][0] * ( pVoxel1nx1ny1pz) - weights[0][1][0] *
|
||||
( pVoxel1nx0py1nz) + weights[2][1][0] * ( pVoxel1nx0py1pz) -
|
||||
weights[0][2][0] * ( pVoxel1nx1py1nz) + weights[2][2][0] *
|
||||
( pVoxel1nx1py1pz) - weights[0][0][1] * ( pVoxel0px1ny1nz) +
|
||||
weights[2][0][1] * ( pVoxel0px1ny1pz) - weights[0][1][1] *
|
||||
( pVoxel0px0py1nz) + weights[2][1][1] * ( pVoxel0px0py1pz) -
|
||||
weights[0][2][1] * ( pVoxel0px1py1nz) + weights[2][2][1] *
|
||||
( pVoxel0px1py1pz) - weights[0][0][2] * ( pVoxel1px1ny1nz) +
|
||||
weights[2][0][2] * ( pVoxel1px1ny1pz) - weights[0][1][2] *
|
||||
( pVoxel1px0py1nz) + weights[2][1][2] * ( pVoxel1px0py1pz) -
|
||||
weights[0][2][2] * ( pVoxel1px1py1nz) + weights[2][2][2] *
|
||||
( pVoxel1px1py1pz));
|
||||
|
||||
return Vector3DFloat(static_cast<float>(xGrad),static_cast<float>(yGrad),static_cast<float>(zGrad));
|
||||
}
|
||||
}
|
73
library/include/IndexedSurfacePatch.h
Normal file
73
library/include/IndexedSurfacePatch.h
Normal file
@ -0,0 +1,73 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_IndexedSurfacePatch_H__
|
||||
#define __PolyVox_IndexedSurfacePatch_H__
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
#include "SurfaceVertex.h"
|
||||
#include "TypeDef.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class POLYVOX_API IndexedSurfacePatch
|
||||
{
|
||||
public:
|
||||
IndexedSurfacePatch(bool allowDuplicateVertices);
|
||||
~IndexedSurfacePatch();
|
||||
|
||||
void addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2);
|
||||
void fillVertexAndIndexData(std::vector<SurfaceVertex>& vecVertices, std::vector<boost::uint32_t>& vecIndices);
|
||||
|
||||
const std::vector<SurfaceVertex>& getVertices(void) const;
|
||||
std::vector<SurfaceVertex>& getVertices(void); //FIXME - non const version should be removed.
|
||||
const std::vector<boost::uint32_t>& getIndices(void) const;
|
||||
|
||||
unsigned short getNoNonUniformTrianges(void);
|
||||
unsigned short getNoUniformTrianges(void);
|
||||
|
||||
public:
|
||||
std::vector<boost::uint32_t> m_vecTriangleIndices;
|
||||
std::vector<SurfaceVertex> m_vecVertices;
|
||||
|
||||
static boost::int32_t vertexIndicesX[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
|
||||
static boost::int32_t vertexIndicesY[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
|
||||
static boost::int32_t vertexIndicesZ[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
|
||||
|
||||
static boost::int32_t noOfVerticesSubmitted;
|
||||
static boost::int32_t noOfVerticesAccepted;
|
||||
static boost::int32_t noOfTrianglesSubmitted;
|
||||
|
||||
boost::int32_t getIndexFor(const Vector3DFloat& pos);
|
||||
void setIndexFor(const Vector3DFloat& pos, boost::int32_t newIndex);
|
||||
|
||||
public:
|
||||
bool m_AllowDuplicateVertices;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* __IndexedSurfacePatch_H__ */
|
64
library/include/LinearVolume.h
Normal file
64
library/include/LinearVolume.h
Normal file
@ -0,0 +1,64 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_LinearVolume_H__
|
||||
#define __PolyVox_LinearVolume_H__
|
||||
|
||||
#pragma region Headers
|
||||
#include "Constants.h"
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
#include "TypeDef.h"
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
class LinearVolume
|
||||
{
|
||||
public:
|
||||
LinearVolume(boost::uint8_t uSideLengthPower);
|
||||
LinearVolume(const LinearVolume& rhs);
|
||||
~LinearVolume();
|
||||
|
||||
LinearVolume& operator=(const LinearVolume& rhs);
|
||||
|
||||
//bool isHomogeneous(void);
|
||||
|
||||
boost::uint16_t getSideLength(void);
|
||||
|
||||
VoxelType getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const;
|
||||
void setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value);
|
||||
|
||||
//void fillWithValue(const VoxelType value);
|
||||
|
||||
private:
|
||||
boost::uint32_t getNoOfVoxels(void);
|
||||
boost::uint8_t m_uSideLengthPower;
|
||||
boost::uint16_t m_uSideLength;
|
||||
VoxelType* m_tData;
|
||||
};
|
||||
}
|
||||
|
||||
#include "LinearVolume.inl"
|
||||
|
||||
#endif
|
102
library/include/LinearVolume.inl
Normal file
102
library/include/LinearVolume.inl
Normal file
@ -0,0 +1,102 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
|
||||
template <typename VoxelType>
|
||||
LinearVolume<VoxelType>::LinearVolume(boost::uint8_t uSideLengthPower)
|
||||
:m_tData(0)
|
||||
{
|
||||
//Check the block size is sensible. This corresponds to a side length of 256 voxels
|
||||
assert(uSideLengthPower <= 8);
|
||||
|
||||
//Compute the side length
|
||||
m_uSideLengthPower = uSideLengthPower;
|
||||
m_uSideLength = 0x01 << uSideLengthPower;
|
||||
|
||||
//If this fails an exception will be thrown. Memory is not
|
||||
//allocated and there is nothing else in this class to clean up
|
||||
m_tData = new VoxelType[getNoOfVoxels()];
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
LinearVolume<VoxelType>::LinearVolume(const LinearVolume<VoxelType>& rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
LinearVolume<VoxelType>::~LinearVolume()
|
||||
{
|
||||
delete[] m_tData;
|
||||
m_tData = 0;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
LinearVolume<VoxelType>& LinearVolume<VoxelType>::operator=(const LinearVolume<VoxelType>& rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
memcpy(m_tData,rhs.m_tData,getNoOfVoxels());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType LinearVolume<VoxelType>::getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const
|
||||
{
|
||||
return m_tData
|
||||
[
|
||||
xPosition +
|
||||
yPosition * m_uSideLength +
|
||||
zPosition * m_uSideLength * m_uSideLength
|
||||
];
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void LinearVolume<VoxelType>::setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value)
|
||||
{
|
||||
m_tData
|
||||
[
|
||||
xPosition +
|
||||
yPosition * m_uSideLength +
|
||||
zPosition * m_uSideLength * m_uSideLength
|
||||
] = value;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
boost::uint16_t LinearVolume<VoxelType>::getSideLength(void)
|
||||
{
|
||||
return m_uSideLength;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
boost::uint32_t LinearVolume<VoxelType>::getNoOfVoxels(void)
|
||||
{
|
||||
return m_uSideLength * m_uSideLength * m_uSideLength;
|
||||
}
|
||||
}
|
31
library/include/MarchingCubesTables.h
Normal file
31
library/include/MarchingCubesTables.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_MarchingCubeTables_H__
|
||||
#define __PolyVox_MarchingCubeTables_H__
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
extern int edgeTable[256];
|
||||
extern int triTable[256][16];
|
||||
}
|
||||
|
||||
#endif
|
63
library/include/PolyVoxForwardDeclarations.h
Normal file
63
library/include/PolyVoxForwardDeclarations.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_ForwardDeclarations_H__
|
||||
#define __PolyVox_ForwardDeclarations_H__
|
||||
|
||||
#include "Enums.h"
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType> class Block;
|
||||
|
||||
//---------- BlockVolume ----------
|
||||
template <typename VoxelType> class BlockVolume;
|
||||
typedef BlockVolume<float> FloatBlockVolume;
|
||||
typedef BlockVolume<boost::uint8_t> UInt8BlockVolume;
|
||||
typedef BlockVolume<boost::uint16_t> UInt16BlockVolume;
|
||||
//---------------------------------
|
||||
|
||||
class IndexedSurfacePatch;
|
||||
class IntegrealVector3;
|
||||
template <typename VoxelType> class LinearVolume;
|
||||
class Region;
|
||||
class RegionGeometry;
|
||||
class SurfaceVertex;
|
||||
|
||||
//---------- Vector ----------
|
||||
template <boost::uint32_t Size, typename Type> class Vector;
|
||||
typedef Vector<3,float> Vector3DFloat;
|
||||
typedef Vector<3,double> Vector3DDouble;
|
||||
typedef Vector<3,boost::int8_t> Vector3DInt8;
|
||||
typedef Vector<3,boost::uint8_t> Vector3DUint8;
|
||||
typedef Vector<3,boost::int16_t> Vector3DInt16;
|
||||
typedef Vector<3,boost::uint16_t> Vector3DUint16;
|
||||
typedef Vector<3,boost::int32_t> Vector3DInt32;
|
||||
typedef Vector<3,boost::uint32_t> Vector3DUint32;
|
||||
//----------------------------
|
||||
|
||||
class VolumeChangeTracker;
|
||||
template <typename VoxelType> class BlockVolumeIterator;
|
||||
}
|
||||
|
||||
#endif
|
55
library/include/Region.h
Normal file
55
library/include/Region.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_Region_H__
|
||||
#define __PolyVox_Region_H__
|
||||
|
||||
#pragma region Headers
|
||||
#include "TypeDef.h"
|
||||
#include "Vector.h"
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class POLYVOX_API Region
|
||||
{
|
||||
public:
|
||||
Region();
|
||||
Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner);
|
||||
|
||||
const Vector3DInt32& getLowerCorner(void) const;
|
||||
const Vector3DInt32& getUpperCorner(void) const;
|
||||
|
||||
void setLowerCorner(const Vector3DInt32& v3dLowerCorner);
|
||||
void setUpperCorner(const Vector3DInt32& v3dUpperCorner);
|
||||
|
||||
bool containsPoint(const Vector3DFloat& pos, float boundary) const;
|
||||
bool containsPoint(const Vector3DInt32& pos, boost::uint8_t boundary) const;
|
||||
void cropTo(const Region& other);
|
||||
void shift(const Vector3DInt32& amount);
|
||||
|
||||
private:
|
||||
Vector3DInt32 m_v3dLowerCorner;
|
||||
Vector3DInt32 m_v3dUpperCorner;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
44
library/include/RegionGeometry.h
Normal file
44
library/include/RegionGeometry.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_RegionGeometry_H__
|
||||
#define __PolyVox_RegionGeometry_H__
|
||||
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
#include "TypeDef.h"
|
||||
#include "Vector.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class POLYVOX_API RegionGeometry
|
||||
{
|
||||
public:
|
||||
RegionGeometry();
|
||||
|
||||
bool m_bIsEmpty;
|
||||
bool m_bContainsSingleMaterialPatch;
|
||||
|
||||
Vector3DInt32 m_v3dRegionPosition;
|
||||
IndexedSurfacePatch* m_patchSingleMaterial;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
65
library/include/SurfaceEdge.h
Normal file
65
library/include/SurfaceEdge.h
Normal file
@ -0,0 +1,65 @@
|
||||
/******************************************************************************
|
||||
This file is part of a voxel plugin for OGRE
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __PolyVox_SurfaceEdge_H__
|
||||
#define __PolyVox_SurfaceEdge_H__
|
||||
|
||||
#include "SurfaceTypes.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class SurfaceEdge
|
||||
{
|
||||
public:
|
||||
SurfaceEdge(const SurfaceVertexIterator& targetToSet,const SurfaceVertexIterator& sourceToSet);
|
||||
|
||||
friend bool operator == (const SurfaceEdge& lhs, const SurfaceEdge& rhs);
|
||||
friend bool operator < (const SurfaceEdge& lhs, const SurfaceEdge& rhs);
|
||||
|
||||
|
||||
std::string tostring(void);
|
||||
|
||||
bool isDegenerate(void);
|
||||
|
||||
const SurfaceVertexIterator& getTarget(void) const;
|
||||
const SurfaceVertexIterator& getSource(void) const;
|
||||
const SurfaceEdgeIterator& getOtherHalfEdge(void) const;
|
||||
const SurfaceEdgeIterator& getPreviousHalfEdge(void) const;
|
||||
const SurfaceEdgeIterator& getNextHalfEdge(void) const;
|
||||
const SurfaceTriangleIterator& getTriangle(void) const;
|
||||
|
||||
void setPreviousHalfEdge(const SurfaceEdgeIterator& previousHalfEdgeToSet);
|
||||
void setNextHalfEdge(const SurfaceEdgeIterator& nextHalfEdgeToSet);
|
||||
void setTriangle(const SurfaceTriangleIterator& triangleToSet);
|
||||
|
||||
void pairWithOtherHalfEdge(const SurfaceEdgeIterator& otherHalfEdgeToPair);
|
||||
|
||||
private:
|
||||
SurfaceVertexIterator target;
|
||||
SurfaceVertexIterator source;
|
||||
|
||||
SurfaceEdgeIterator previousHalfEdge;
|
||||
SurfaceEdgeIterator nextHalfEdge;
|
||||
SurfaceEdgeIterator otherHalfEdge;
|
||||
|
||||
SurfaceTriangleIterator triangle;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
54
library/include/SurfaceExtractors.h
Normal file
54
library/include/SurfaceExtractors.h
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_SurfaceExtractors_H__
|
||||
#define __PolyVox_SurfaceExtractors_H__
|
||||
|
||||
#pragma region Headers
|
||||
#include "Constants.h"
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
#include "TypeDef.h"
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
|
||||
#include <list>
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
POLYVOX_API std::list<RegionGeometry> getChangedRegionGeometry(VolumeChangeTracker& volume);
|
||||
|
||||
boost::uint32_t getIndex(boost::uint32_t x, boost::uint32_t y);
|
||||
|
||||
POLYVOX_API void generateRoughMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
|
||||
POLYVOX_API boost::uint32_t computeInitialRoughBitmaskForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask);
|
||||
POLYVOX_API boost::uint32_t computeRoughBitmaskForSliceFromPrevious(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask, boost::uint8_t *previousBitmask);
|
||||
POLYVOX_API void generateRoughIndicesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, boost::uint8_t* bitmask0, boost::uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[]);
|
||||
POLYVOX_API void generateRoughVerticesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, boost::uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[], Vector3DFloat vertlist[], boost::uint8_t vertMaterials[]);
|
||||
|
||||
POLYVOX_API void generateReferenceMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
|
||||
POLYVOX_API Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
|
||||
|
||||
POLYVOX_API void generateSmoothMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
|
||||
POLYVOX_API Vector3DFloat computeSmoothNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
|
||||
}
|
||||
|
||||
#endif
|
50
library/include/SurfaceTriangle.h
Normal file
50
library/include/SurfaceTriangle.h
Normal file
@ -0,0 +1,50 @@
|
||||
/******************************************************************************
|
||||
This file is part of a voxel plugin for OGRE
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __PolyVox_SurfaceTriangle_H__
|
||||
#define __PolyVox_SurfaceTriangle_H__
|
||||
|
||||
#include "SurfaceTypes.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class SurfaceTriangle
|
||||
{
|
||||
public:
|
||||
SurfaceTriangle();
|
||||
|
||||
friend bool operator == (const SurfaceTriangle& lhs, const SurfaceTriangle& rhs);
|
||||
friend bool operator < (const SurfaceTriangle& lhs, const SurfaceTriangle& rhs);
|
||||
|
||||
const SurfaceEdgeIterator& getEdge(void) const;
|
||||
|
||||
void setEdge(const SurfaceEdgeIterator& edgeToSet);
|
||||
|
||||
//std::string tostring(void);
|
||||
|
||||
private:
|
||||
SurfaceEdgeIterator edge;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//bool operator < (const SurfaceTriangleIterator& lhs, const SurfaceTriangleIterator& rhs);
|
||||
}
|
||||
|
||||
#endif
|
19
library/include/SurfaceTypes.h
Normal file
19
library/include/SurfaceTypes.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef __PolyVox_SurfaceTypes_H__
|
||||
#define __PolyVox_SurfaceTypes_H__
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class SurfaceVertex;
|
||||
typedef std::set<SurfaceVertex>::iterator SurfaceVertexIterator;
|
||||
typedef std::set<SurfaceVertex>::const_iterator SurfaceVertexConstIterator;
|
||||
class SurfaceTriangle;
|
||||
typedef std::set<SurfaceTriangle>::iterator SurfaceTriangleIterator;
|
||||
typedef std::set<SurfaceTriangle>::const_iterator SurfaceTriangleConstIterator;
|
||||
class SurfaceEdge;
|
||||
typedef std::set<SurfaceEdge>::iterator SurfaceEdgeIterator;
|
||||
typedef std::set<SurfaceEdge>::const_iterator SurfaceEdgeConstIterator;
|
||||
}
|
||||
|
||||
#endif
|
65
library/include/SurfaceVertex.h
Normal file
65
library/include/SurfaceVertex.h
Normal file
@ -0,0 +1,65 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_SurfaceVertex_H__
|
||||
#define __PolyVox_SurfaceVertex_H__
|
||||
|
||||
#include "TypeDef.h"
|
||||
#include "Vector.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class POLYVOX_API SurfaceVertex
|
||||
{
|
||||
public:
|
||||
SurfaceVertex();
|
||||
SurfaceVertex(Vector3DFloat positionToSet, float materialToSet, float alphaToSet);
|
||||
SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet);
|
||||
|
||||
friend bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
||||
friend bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs);
|
||||
|
||||
float getAlpha(void) const;
|
||||
float getMaterial(void) const;
|
||||
const Vector3DFloat& getNormal(void) const;
|
||||
const Vector3DFloat& getPosition(void) const;
|
||||
|
||||
void setAlpha(float alphaToSet);
|
||||
void setMaterial(float materialToSet);
|
||||
void setNormal(const Vector3DFloat& normalToSet);
|
||||
|
||||
std::string tostring(void) const;
|
||||
|
||||
private:
|
||||
Vector3DFloat position;
|
||||
Vector3DFloat normal;
|
||||
float material;
|
||||
float alpha;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//bool operator < (const SurfaceVertexIterator& lhs, const SurfaceVertexIterator& rhs);
|
||||
}
|
||||
|
||||
#endif
|
37
library/include/TypeDef.h
Normal file
37
library/include/TypeDef.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
//Dave, maybe make use of OgrePlatform.h instead?
|
||||
// I think use _OgreExport instead of POLYVOX_API and define OGRE_NONCLIENT_BUILD instead of POLYVOX_EXPORT?
|
||||
#ifndef __PolyVox_TypeDef_H__
|
||||
#define __PolyVox_TypeDef_H__
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef POLYVOX_EXPORT
|
||||
#define POLYVOX_API __declspec(dllexport)
|
||||
#else
|
||||
#define POLYVOX_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define POLYVOX_API __attribute__ ((visibility("default")))
|
||||
#endif
|
||||
|
||||
#endif
|
35
library/include/Utility.h
Normal file
35
library/include/Utility.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_Utility_H__
|
||||
#define __PolyVox_Utility_H__
|
||||
|
||||
#include "TypeDef.h"
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
POLYVOX_API boost::uint8_t logBase2(boost::uint32_t uInput);
|
||||
POLYVOX_API bool isPowerOf2(boost::uint32_t uInput);
|
||||
}
|
||||
|
||||
#endif
|
150
library/include/Vector.h
Normal file
150
library/include/Vector.h
Normal file
@ -0,0 +1,150 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_Vector_H__
|
||||
#define __PolyVox_Vector_H__
|
||||
|
||||
#pragma region Headers
|
||||
#include "boost/cstdint.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
///Represents a vector in space.
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
class Vector
|
||||
{
|
||||
public:
|
||||
///Constructor.
|
||||
Vector(Type x, Type y) throw();
|
||||
///Constructor.
|
||||
Vector(Type x, Type y, Type z) throw();
|
||||
///Constructor.
|
||||
Vector(Type x, Type y, Type z, Type w) throw();
|
||||
///Constructor
|
||||
Vector(void) throw();
|
||||
///Copy Constructor.
|
||||
Vector(const Vector<Size,Type>& vector) throw();
|
||||
///Copy Constructor which performs casting.
|
||||
template <typename CastType> explicit Vector(const Vector<Size,CastType>& vector) throw();
|
||||
///Destructor.
|
||||
~Vector(void) throw();
|
||||
|
||||
///Assignment Operator.
|
||||
Vector<Size,Type>& operator=(const Vector<Size,Type>& rhs) throw();
|
||||
///Equality Operator.
|
||||
bool operator==(const Vector<Size,Type>& rhs) const throw();
|
||||
///Comparison Operator.
|
||||
bool operator<(const Vector<Size,Type>& rhs) const throw();
|
||||
///Addition and Assignment Operator.
|
||||
Vector<Size,Type>& operator+=(const Vector<Size,Type> &rhs) throw();
|
||||
///Subtraction and Assignment Operator.
|
||||
Vector<Size,Type>& operator-=(const Vector<Size,Type> &rhs) throw();
|
||||
///Multiplication and Assignment Operator.
|
||||
Vector<Size,Type>& operator*=(const Type& rhs) throw();
|
||||
///Division and Assignment Operator.
|
||||
Vector<Size,Type>& operator/=(const Type& rhs) throw();
|
||||
|
||||
///Element Access
|
||||
Type getElement(boost::uint32_t index) const throw();
|
||||
///Get the x component of the vector.
|
||||
Type getX(void) const throw();
|
||||
///Get the y component of the vector.
|
||||
Type getY(void) const throw();
|
||||
///Get the z component of the vector.
|
||||
Type getZ(void) const throw();
|
||||
///Get the w component of the vector.
|
||||
Type getW(void) const throw();
|
||||
|
||||
///Element Access
|
||||
void setElement(boost::uint32_t index, Type tValue) throw();
|
||||
///Set the x component of the vector.
|
||||
void setX(Type tX) throw();
|
||||
///Set the y component of the vector.
|
||||
void setY(Type tY) throw();
|
||||
///Set the z component of the vector.
|
||||
void setZ(Type tZ) throw();
|
||||
///Set the w component of the vector.
|
||||
void setW(Type tW) throw();
|
||||
|
||||
///Get the length of the vector.
|
||||
double length(void) const throw();
|
||||
///Get the squared length of the vector.
|
||||
double lengthSquared(void) const throw();
|
||||
///Find the angle between this vector and that which is passed as a parameter.
|
||||
double angleTo(const Vector<Size,Type>& vector) const throw();
|
||||
///Find the cross product between this vector and the vector passed as a parameter.
|
||||
Vector<Size,Type> cross(const Vector<Size,Type>& vector) const throw();
|
||||
///Find the dot product between this vector and the vector passed as a parameter.
|
||||
Type dot(const Vector<Size,Type>& rhs) const throw();
|
||||
///Normalise the vector.
|
||||
void normalise(void) throw();
|
||||
|
||||
private:
|
||||
//Values for the vector
|
||||
Type m_tElements[Size];
|
||||
};
|
||||
|
||||
//Non-member overloaded operators.
|
||||
///Addition operator.
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
|
||||
///Subtraction operator.
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
|
||||
///Multiplication operator.
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw();
|
||||
///Division operator.
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs) throw();
|
||||
///Stream insertion operator.
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
std::ostream& operator<<(std::ostream& os, const Vector<Size,Type>& vector) throw();
|
||||
|
||||
//Some handy typedefs
|
||||
///A 3D Vector of floats.
|
||||
typedef Vector<3,float> Vector3DFloat;
|
||||
///A 3D Vector of doubles.
|
||||
typedef Vector<3,double> Vector3DDouble;
|
||||
///A 3D Vector of signed 8-bit values.
|
||||
typedef Vector<3,boost::int8_t> Vector3DInt8;
|
||||
///A 3D Vector of unsigned 8-bit values.
|
||||
typedef Vector<3,boost::uint8_t> Vector3DUint8;
|
||||
///A 3D Vector of signed 16-bit values.
|
||||
typedef Vector<3,boost::int16_t> Vector3DInt16;
|
||||
///A 3D Vector of unsigned 16-bit values.
|
||||
typedef Vector<3,boost::uint16_t> Vector3DUint16;
|
||||
///A 3D Vector of signed 32-bit values.
|
||||
typedef Vector<3,boost::int32_t> Vector3DInt32;
|
||||
///A 3D Vector of unsigned 32-bit values.
|
||||
typedef Vector<3,boost::uint32_t> Vector3DUint32;
|
||||
|
||||
|
||||
|
||||
}//namespace Thermite
|
||||
|
||||
#include "Vector.inl"
|
||||
|
||||
#endif
|
||||
|
536
library/include/Vector.inl
Normal file
536
library/include/Vector.inl
Normal file
@ -0,0 +1,536 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
/**
|
||||
This Vector class is templated on both size and data type. It is designed to be
|
||||
generic but so far had only been tested with vectors of size 2 and 3. Also note
|
||||
that some of the operations do not make sense with integer types, for example it
|
||||
does not make conceptual sense to try and normalise an integer Vector.
|
||||
|
||||
The elements of the Vector are accessed via the overloaded () operator which takes
|
||||
an index indicating the element to fetch. They are set using the set() function which
|
||||
takes an index indicating the element to set and a new value for that element. For
|
||||
convienience, the functions getX(), setX(), getY(), setY(), getZ(), setZ, w() and setW()
|
||||
do the same thing for the first 4 elements of the Vector.
|
||||
|
||||
A variety of overloaded operators are also provided for comparison and arithmetic
|
||||
operations. For most of these arithmetic operators only the unary versions are
|
||||
documented below - however often binary versions are also generated by boost::operators.
|
||||
|
||||
Lastly, note that for convienience a set of typedefs are included for 2 and 3 dimentionsal
|
||||
vectors with type float, double, boost::int32_t, and boost::uint32_t. They are used as follows:
|
||||
|
||||
Vector2DInt4 test(1,2); //Declares a 2 dimensional Vector of type int4.
|
||||
*/
|
||||
|
||||
#pragma region Constructors/Destructors
|
||||
//-------------------------- Constructors, etc ---------------------------------
|
||||
/**
|
||||
Creates a Vector object and initialises it with given values.
|
||||
\param x x component to set.
|
||||
\param y y component to set.
|
||||
*/
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type>::Vector(Type x, Type y) throw()
|
||||
{
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a Vector3D object and initialises it with given values.
|
||||
\param x x component to set.
|
||||
\param y y component to set.
|
||||
\param z z component to set.
|
||||
*/
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type>::Vector(Type x, Type y, Type z) throw()
|
||||
{
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
m_tElements[2] = z;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a Vector3D object and initialises it with given values.
|
||||
\param x x component to set.
|
||||
\param y y component to set.
|
||||
\param z z component to set.
|
||||
\param w w component to set.
|
||||
*/
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type>::Vector(Type x, Type y, Type z, Type w) throw()
|
||||
{
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
m_tElements[2] = z;
|
||||
m_tElements[3] = w;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a Vector object but does not initialise it.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
Vector<Size, Type>::Vector(void) throw()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
Copy constructor builds object based on object passed as parameter.
|
||||
\param vector A reference to the Vector to be copied.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
Vector<Size, Type>::Vector(const Vector<Size, Type>& vector) throw()
|
||||
{
|
||||
std::memcpy(m_tElements, vector.m_tElements, sizeof(Type) * Size);
|
||||
}
|
||||
|
||||
/**
|
||||
This copy constructor allows casting between vectors with different data types.
|
||||
It is now possible to use code such as:
|
||||
|
||||
Vector3DDouble v3dDouble(1.0,2.0,3.0);
|
||||
Vector3DFloat v3dFloat = static_cast<Vector3DFloat>(v3dDouble); //Casting
|
||||
|
||||
\param vector A reference to the Vector to be copied.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
template <typename CastType>
|
||||
Vector<Size, Type>::Vector(const Vector<Size, CastType>& vector) throw()
|
||||
{
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
m_tElements[ct] = static_cast<CastType>(vector.getElement(ct));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Destroys the Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
Vector<Size, Type>::~Vector(void) throw()
|
||||
{
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Operators
|
||||
/**
|
||||
Assignment operator copies each element of first Vector to the second.
|
||||
\param rhs Vector to assign to.
|
||||
\return A reference to the result to allow chaining.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
Vector<Size, Type>& Vector<Size, Type>::operator=(const Vector<Size, Type>& rhs) throw()
|
||||
{
|
||||
if(this == &rhs)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
std::memcpy(m_tElements, rhs.m_tElements, sizeof(Type) * Size);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
Checks whether two Vectors are equal.
|
||||
\param rhs The Vector to compare to.
|
||||
\return true if the Vectors match.
|
||||
\see operator!=
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline bool Vector<Size, Type>::operator==(const Vector<Size, Type> &rhs) const throw()
|
||||
{
|
||||
bool equal = true;
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
if(m_tElements[ct] != rhs(ct))
|
||||
{
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
|
||||
/**
|
||||
Checks whether this vector is less than the parameter. The metric is
|
||||
meaningless but it allows Vectors to me used as key in sdt::map, etc.
|
||||
\param rhs The Vector to compare to.
|
||||
\return true if this is less than the parameter
|
||||
\see operator!=
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline bool Vector<Size, Type>::operator<(const Vector<Size, Type> &rhs) const throw()
|
||||
{
|
||||
for(int ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
if (m_tElements[ct] < rhs.m_tElements[ct])
|
||||
return true;
|
||||
if (rhs.m_tElements[ct] < m_tElements[ct])
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Addition operator adds corresponding elements of the two Vectors.
|
||||
\param rhs Vector to add
|
||||
\return The resulting Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Vector<Size, Type>& Vector<Size, Type>::operator+=(const Vector<Size, Type>& rhs) throw()
|
||||
{
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
m_tElements[ct] += rhs.m_tElements[ct];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
Addition operator adds corresponding elements of the two Vectors.
|
||||
\param lhs Vector to add to.
|
||||
\param rhs Vector to add.
|
||||
\return The resulting Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
|
||||
{
|
||||
Vector<Size,Type> result = lhs;
|
||||
result += rhs;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
Subtraction operator subtracts corresponding elements of one Vector from the other.
|
||||
\param rhs Vector to subtract
|
||||
\return The resulting Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Vector<Size, Type>& Vector<Size, Type>::operator-=(const Vector<Size, Type>& rhs) throw()
|
||||
{
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
m_tElements[ct] -= rhs.m_tElements[ct];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
Subtraction operator subtracts corresponding elements of one Vector from the other.
|
||||
\param lhs Vector to subtract from.
|
||||
\param rhs Vector to subtract.
|
||||
\return The resulting Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
|
||||
{
|
||||
Vector<Size,Type> result = lhs;
|
||||
result -= rhs;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
Multiplication operator multiplies each element of the Vector by a number.
|
||||
\param rhs the number the Vector is multiplied by.
|
||||
\return The resulting Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Vector<Size, Type>& Vector<Size, Type>::operator*=(const Type& rhs) throw()
|
||||
{
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
m_tElements[ct] *= rhs;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
Multiplication operator multiplies each element of the Vector by a number.
|
||||
\param lhs the Vector to multiply.
|
||||
\param rhs the number the Vector is multiplied by.
|
||||
\return The resulting Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw()
|
||||
{
|
||||
Vector<Size,Type> result = lhs;
|
||||
result *= rhs;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
Division operator divides each element of the Vector by a number.
|
||||
\param rhs the number the Vector is divided by.
|
||||
\return The resulting Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Vector<Size, Type>& Vector<Size, Type>::operator/=(const Type& rhs) throw()
|
||||
{
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
m_tElements[ct] /= rhs;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
Division operator divides each element of the Vector by a number.
|
||||
\param lhs the Vector to divide.
|
||||
\param rhs the number the Vector is divided by.
|
||||
\return The resulting Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size,typename Type>
|
||||
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs) throw()
|
||||
{
|
||||
Vector<Size,Type> result = lhs;
|
||||
result /= rhs;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
Enables the Vector to be used intuitively with output streams such as cout.
|
||||
\param os The output stream to write to.
|
||||
\param vector The Vector to write to the stream.
|
||||
\return A reference to the output stream to allow chaining.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
std::ostream& operator<<(std::ostream& os, const Vector<Size, Type>& vector) throw()
|
||||
{
|
||||
os << "(";
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
os << vector.getElement(ct);
|
||||
if(ct < (Size-1))
|
||||
{
|
||||
os << ",";
|
||||
}
|
||||
}
|
||||
os << ")";
|
||||
return os;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Getters
|
||||
/**
|
||||
Returns the element at the given position.
|
||||
\param index The index of the element to return.
|
||||
\return The element.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Type Vector<Size, Type>::getElement(boost::uint32_t index) const throw()
|
||||
{
|
||||
return m_tElements[index];
|
||||
}
|
||||
|
||||
/**
|
||||
\return A const reference to the X component of a 1, 2, 3, or 4 dimensional Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Type Vector<Size, Type>::getX(void) const throw()
|
||||
{
|
||||
return m_tElements[0];
|
||||
}
|
||||
|
||||
/**
|
||||
\return A const reference to the Y component of a 2, 3, or 4 dimensional Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Type Vector<Size, Type>::getY(void) const throw()
|
||||
{
|
||||
return m_tElements[1];
|
||||
}
|
||||
|
||||
/**
|
||||
\return A const reference to the Z component of a 3 or 4 dimensional Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Type Vector<Size, Type>::getZ(void) const throw()
|
||||
{
|
||||
return m_tElements[2];
|
||||
}
|
||||
|
||||
/**
|
||||
\return A const reference to the W component of a 4 dimensional Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Type Vector<Size, Type>::getW(void) const throw()
|
||||
{
|
||||
return m_tElements[3];
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Setters
|
||||
/**
|
||||
\param index The index of the element to set.
|
||||
\param tValue The new value for the element.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline void Vector<Size, Type>::setElement(boost::uint32_t index, Type tValue) throw()
|
||||
{
|
||||
m_tElements[index] = tValue;
|
||||
}
|
||||
|
||||
/**
|
||||
\param tX The new value for the X component of a 1, 2, 3, or 4 dimensional Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline void Vector<Size, Type>::setX(Type tX) throw()
|
||||
{
|
||||
m_tElements[0] = tX;
|
||||
}
|
||||
|
||||
/**
|
||||
\param tX The new value for the Y component of a 2, 3, or 4 dimensional Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline void Vector<Size, Type>::setY(Type tY) throw()
|
||||
{
|
||||
m_tElements[1] = tY;
|
||||
}
|
||||
|
||||
/**
|
||||
\param tX The new value for the Z component of a 3 or 4 dimensional Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline void Vector<Size, Type>::setZ(Type tZ) throw()
|
||||
{
|
||||
m_tElements[2] = tZ;
|
||||
}
|
||||
|
||||
/**
|
||||
\param tX The new value for the W component of a 4 dimensional Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline void Vector<Size, Type>::setW(Type tW) throw()
|
||||
{
|
||||
m_tElements[3] = tW;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Others
|
||||
/**
|
||||
NOTE: This function does not make much sense on integer Vectors.
|
||||
\return Length of the Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline double Vector<Size, Type>::length(void) const throw()
|
||||
{
|
||||
return sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
/**
|
||||
\return Squared length of the Vector.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline double Vector<Size, Type>::lengthSquared(void) const throw()
|
||||
{
|
||||
double result = 0.0f;
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
result += m_tElements[ct] * m_tElements[ct];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
This function is commutative, such that a.angleTo(b) == b.angleTo(a). The angle
|
||||
returned is in radians and varies between 0 and 3.14(pi). It is always positive.
|
||||
|
||||
NOTE: This function does not make much sense on integer Vectors.
|
||||
|
||||
\param Vector3D The Vector to find the angle to.
|
||||
\return The angle between them in radians.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline double Vector<Size, Type>::angleTo(const Vector<Size, Type>& vector) const throw()
|
||||
{
|
||||
return acos(dot(vector) / (vector.length() * this->length()));
|
||||
}
|
||||
|
||||
/**
|
||||
This function is used to calculate the cross product of two Vectors.
|
||||
The cross product is the Vector which is perpendicular to the two
|
||||
given Vectors. It is worth remembering that, unlike the dot product,
|
||||
it is not commutative. E.g a.b != b.a. The cross product obeys the
|
||||
right-hand rule such that if the two vectors are given by the index
|
||||
finger and middle finger respectively then the cross product is given
|
||||
by the thumb.
|
||||
\param a first Vector.
|
||||
\param b Second Vector.
|
||||
\return The value of the cross product.
|
||||
\see dot()
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Vector<Size, Type> Vector<Size, Type>::cross(const Vector<Size, Type>& vector) const throw()
|
||||
{
|
||||
Type i = vector.getZ() * this->getY() - vector.getY() * this->getZ();
|
||||
Type j = vector.getX() * this->getZ() - vector.getZ() * this->getX();
|
||||
Type k = vector.getY() * this->getX() - vector.getX() * this->getY();
|
||||
return Vector<Size, Type>(i,j,k);
|
||||
}
|
||||
|
||||
/**
|
||||
Calculates the dot product of the Vector and the parameter.
|
||||
This function is commutative, such that a.dot(b) == b.dot(a).
|
||||
\param rhs The Vector to find the dot product with.
|
||||
\return The value of the dot product.
|
||||
\see cross()
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline Type Vector<Size, Type>::dot(const Vector<Size, Type>& rhs) const throw()
|
||||
{
|
||||
Type dotProduct = static_cast<Type>(0);
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
dotProduct += m_tElements[ct] * rhs.m_tElements[ct];
|
||||
}
|
||||
return dotProduct;
|
||||
}
|
||||
|
||||
/**
|
||||
Divides the i, j, and k components by the length to give a Vector of length 1.0.
|
||||
|
||||
NOTE: This function does not make much sense on integer Vectors.
|
||||
*/
|
||||
template <boost::uint32_t Size, typename Type>
|
||||
inline void Vector<Size, Type>::normalise(void) throw()
|
||||
{
|
||||
double length = this->length();
|
||||
//FIXME - throw div by zero exception?
|
||||
if(length < 0.0001f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(boost::uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
m_tElements[ct] /= static_cast<Type>(length);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
}//namespace Thermite
|
71
library/include/VolumeChangeTracker.h
Normal file
71
library/include/VolumeChangeTracker.h
Normal file
@ -0,0 +1,71 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_VolumeChangeTracker_H__
|
||||
#define __PolyVox_VolumeChangeTracker_H__
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
#include "Region.h"
|
||||
#include "TypeDef.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
/// Voxel scene manager
|
||||
class POLYVOX_API VolumeChangeTracker
|
||||
{
|
||||
public:
|
||||
//Constructors, etc
|
||||
VolumeChangeTracker();
|
||||
~VolumeChangeTracker();
|
||||
|
||||
//Getters
|
||||
void getChangedRegions(std::list<Region>& listToFill) const;
|
||||
Region getEnclosingRegion(void) const;
|
||||
boost::uint16_t getSideLength(void);
|
||||
BlockVolume<boost::uint8_t>* getVolumeData(void) const;
|
||||
boost::uint8_t getVoxelAt(const Vector3DUint16& pos);
|
||||
boost::uint8_t getVoxelAt(boost::uint16_t uX, boost::uint16_t uY, boost::uint16_t uZ);
|
||||
|
||||
//Setters
|
||||
void setAllRegionsUpToDate(bool newUpToDateValue);
|
||||
void setLockedVoxelAt(boost::uint16_t x, boost::uint16_t y, boost::uint16_t z, boost::uint8_t value);
|
||||
void setVolumeData(BlockVolume<boost::uint8_t>* volumeDataToSet);
|
||||
void setVoxelAt(boost::uint16_t x, boost::uint16_t y, boost::uint16_t z, boost::uint8_t value);
|
||||
|
||||
//Others
|
||||
void lockRegion(const Region& regToLock);
|
||||
void unlockRegion(void);
|
||||
//void markRegionChanged(boost::uint16_t firstX, boost::uint16_t firstY, boost::uint16_t firstZ, boost::uint16_t lastX, boost::uint16_t lastY, boost::uint16_t lastZ);
|
||||
|
||||
private:
|
||||
bool m_bIsLocked;
|
||||
Region m_regLastLocked;
|
||||
BlockVolume<boost::uint8_t>* volumeData;
|
||||
LinearVolume<bool>* volRegionUpToDate;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
233
library/source/IndexedSurfacePatch.cpp
Normal file
233
library/source/IndexedSurfacePatch.cpp
Normal file
@ -0,0 +1,233 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include "IndexedSurfacePatch.h"
|
||||
|
||||
using namespace boost;
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
int32_t IndexedSurfacePatch::noOfVerticesSubmitted = 0;
|
||||
int32_t IndexedSurfacePatch::noOfVerticesAccepted = 0;
|
||||
int32_t IndexedSurfacePatch::noOfTrianglesSubmitted = 0;
|
||||
int32_t IndexedSurfacePatch::vertexIndicesX[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
|
||||
int32_t IndexedSurfacePatch::vertexIndicesY[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
|
||||
int32_t IndexedSurfacePatch::vertexIndicesZ[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
|
||||
|
||||
IndexedSurfacePatch::IndexedSurfacePatch(bool allowDuplicateVertices)
|
||||
:m_AllowDuplicateVertices(allowDuplicateVertices)
|
||||
{
|
||||
memset(vertexIndicesX,0xFF,sizeof(vertexIndicesX)); //0xFF is -1 as two's complement - this may not be portable...
|
||||
memset(vertexIndicesY,0xFF,sizeof(vertexIndicesY));
|
||||
memset(vertexIndicesZ,0xFF,sizeof(vertexIndicesZ));
|
||||
}
|
||||
|
||||
IndexedSurfacePatch::~IndexedSurfacePatch()
|
||||
{
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2)
|
||||
{
|
||||
noOfTrianglesSubmitted++;
|
||||
noOfVerticesSubmitted += 3;
|
||||
if(!m_AllowDuplicateVertices)
|
||||
{
|
||||
int32_t index = getIndexFor(v0.getPosition());
|
||||
if(index == -1)
|
||||
{
|
||||
m_vecVertices.push_back(v0);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
setIndexFor(v0.getPosition(), m_vecVertices.size()-1);
|
||||
|
||||
noOfVerticesAccepted++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vecTriangleIndices.push_back(index);
|
||||
}
|
||||
|
||||
index = getIndexFor(v1.getPosition());
|
||||
if(index == -1)
|
||||
{
|
||||
m_vecVertices.push_back(v1);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
setIndexFor(v1.getPosition(), m_vecVertices.size()-1);
|
||||
|
||||
noOfVerticesAccepted++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vecTriangleIndices.push_back(index);
|
||||
}
|
||||
|
||||
index = getIndexFor(v2.getPosition());
|
||||
if(index == -1)
|
||||
{
|
||||
m_vecVertices.push_back(v2);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
setIndexFor(v2.getPosition(), m_vecVertices.size()-1);
|
||||
|
||||
noOfVerticesAccepted++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vecTriangleIndices.push_back(index);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vecVertices.push_back(v0);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
m_vecVertices.push_back(v1);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
m_vecVertices.push_back(v2);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
|
||||
noOfVerticesAccepted += 3;
|
||||
}
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::fillVertexAndIndexData(std::vector<SurfaceVertex>& vecVertices, std::vector<uint32_t>& vecIndices)
|
||||
{
|
||||
vecVertices.resize(m_vecVertices.size());
|
||||
std::copy(m_vecVertices.begin(), m_vecVertices.end(), vecVertices.begin());
|
||||
|
||||
vecIndices.resize(m_vecTriangleIndices.size());
|
||||
std::copy(m_vecTriangleIndices.begin(), m_vecTriangleIndices.end(), vecIndices.begin());
|
||||
|
||||
/*for(std::vector<SurfaceVertexIterator>::iterator iterVertices = m_vecTriangleIndices.begin(); iterVertices != m_vecTriangleIndices.end(); ++iterVertices)
|
||||
{
|
||||
std::vector<SurfaceVertex>::iterator iterVertex = lower_bound(vecVertices.begin(), vecVertices.end(), **iterVertices);
|
||||
vecIndices.push_back(iterVertex - vecVertices.begin());
|
||||
}*/
|
||||
}
|
||||
|
||||
boost::int32_t IndexedSurfacePatch::getIndexFor(const Vector3DFloat& pos)
|
||||
{
|
||||
assert(pos.getX() >= 0.0f);
|
||||
assert(pos.getY() >= 0.0f);
|
||||
assert(pos.getZ() >= 0.0f);
|
||||
assert(pos.getX() <= POLYVOX_REGION_SIDE_LENGTH);
|
||||
assert(pos.getY() <= POLYVOX_REGION_SIDE_LENGTH);
|
||||
assert(pos.getZ() <= POLYVOX_REGION_SIDE_LENGTH);
|
||||
|
||||
float xIntPart;
|
||||
float xFracPart = std::modf(pos.getX(), &xIntPart);
|
||||
float yIntPart;
|
||||
float yFracPart = std::modf(pos.getY(), &yIntPart);
|
||||
float zIntPart;
|
||||
float zFracPart = std::modf(pos.getZ(), &zIntPart);
|
||||
|
||||
//Of all the fractional parts, two should be zero and one should have a value.
|
||||
if(xFracPart > 0.000001f)
|
||||
{
|
||||
return vertexIndicesX[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)];
|
||||
}
|
||||
if(yFracPart > 0.000001f)
|
||||
{
|
||||
return vertexIndicesY[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)];
|
||||
}
|
||||
if(zFracPart > 0.000001f)
|
||||
{
|
||||
return vertexIndicesZ[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)];
|
||||
}
|
||||
while(true);
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::setIndexFor(const Vector3DFloat& pos, boost::int32_t newIndex)
|
||||
{
|
||||
assert(pos.getX() >= 0.0f);
|
||||
assert(pos.getY() >= 0.0f);
|
||||
assert(pos.getZ() >= 0.0f);
|
||||
assert(pos.getX() <= POLYVOX_REGION_SIDE_LENGTH);
|
||||
assert(pos.getY() <= POLYVOX_REGION_SIDE_LENGTH);
|
||||
assert(pos.getZ() <= POLYVOX_REGION_SIDE_LENGTH);
|
||||
|
||||
assert(newIndex < 10000);
|
||||
|
||||
float xIntPart;
|
||||
float xFracPart = std::modf(pos.getX(), &xIntPart);
|
||||
float yIntPart;
|
||||
float yFracPart = std::modf(pos.getY(), &yIntPart);
|
||||
float zIntPart;
|
||||
float zFracPart = std::modf(pos.getZ(), &zIntPart);
|
||||
|
||||
//Of all the fractional parts, two should be zero and one should have a value.
|
||||
if(xFracPart > 0.000001f)
|
||||
{
|
||||
vertexIndicesX[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)] = newIndex;
|
||||
}
|
||||
if(yFracPart > 0.000001f)
|
||||
{
|
||||
vertexIndicesY[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)] = newIndex;
|
||||
}
|
||||
if(zFracPart > 0.000001f)
|
||||
{
|
||||
vertexIndicesZ[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)] = newIndex;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<SurfaceVertex>& IndexedSurfacePatch::getVertices(void) const
|
||||
{
|
||||
return m_vecVertices;
|
||||
}
|
||||
|
||||
std::vector<SurfaceVertex>& IndexedSurfacePatch::getVertices(void)
|
||||
{
|
||||
return m_vecVertices;
|
||||
}
|
||||
|
||||
const std::vector<boost::uint32_t>& IndexedSurfacePatch::getIndices(void) const
|
||||
{
|
||||
return m_vecTriangleIndices;
|
||||
}
|
||||
|
||||
unsigned short IndexedSurfacePatch::getNoNonUniformTrianges(void)
|
||||
{
|
||||
unsigned short result = 0;
|
||||
for(int i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
|
||||
{
|
||||
if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial())
|
||||
&& (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial()))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned short IndexedSurfacePatch::getNoUniformTrianges(void)
|
||||
{
|
||||
unsigned short result = 0;
|
||||
for(int i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
|
||||
{
|
||||
if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial())
|
||||
&& (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial()))
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
326
library/source/MarchingCubesTables.cpp
Normal file
326
library/source/MarchingCubesTables.cpp
Normal file
@ -0,0 +1,326 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
//Based on code by Paul Bourke
|
||||
//From the article "Polygonising a scalar field"
|
||||
|
||||
// http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/index.html
|
||||
|
||||
#include "MarchingCubesTables.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
int edgeTable[256]=
|
||||
{
|
||||
0x0 , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
|
||||
0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
|
||||
0x190, 0x99 , 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
|
||||
0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90,
|
||||
0x230, 0x339, 0x33 , 0x13a, 0x636, 0x73f, 0x435, 0x53c,
|
||||
0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30,
|
||||
0x3a0, 0x2a9, 0x1a3, 0xaa , 0x7a6, 0x6af, 0x5a5, 0x4ac,
|
||||
0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0,
|
||||
0x460, 0x569, 0x663, 0x76a, 0x66 , 0x16f, 0x265, 0x36c,
|
||||
0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60,
|
||||
0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff , 0x3f5, 0x2fc,
|
||||
0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0,
|
||||
0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55 , 0x15c,
|
||||
0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950,
|
||||
0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc ,
|
||||
0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0,
|
||||
0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc,
|
||||
0xcc , 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
|
||||
0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c,
|
||||
0x15c, 0x55 , 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
|
||||
0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc,
|
||||
0x2fc, 0x3f5, 0xff , 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
|
||||
0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c,
|
||||
0x36c, 0x265, 0x16f, 0x66 , 0x76a, 0x663, 0x569, 0x460,
|
||||
0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac,
|
||||
0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa , 0x1a3, 0x2a9, 0x3a0,
|
||||
0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c,
|
||||
0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33 , 0x339, 0x230,
|
||||
0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c,
|
||||
0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99 , 0x190,
|
||||
0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c,
|
||||
0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0
|
||||
};
|
||||
|
||||
int triTable[256][16] =
|
||||
{
|
||||
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1},
|
||||
{8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1},
|
||||
{3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1},
|
||||
{4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1},
|
||||
{4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
|
||||
{5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1},
|
||||
{9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1},
|
||||
{10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1},
|
||||
{5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1},
|
||||
{5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1},
|
||||
{10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1},
|
||||
{8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1},
|
||||
{2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1},
|
||||
{7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1},
|
||||
{2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1},
|
||||
{11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1},
|
||||
{5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1},
|
||||
{11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1},
|
||||
{11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1},
|
||||
{5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1},
|
||||
{2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
|
||||
{5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1},
|
||||
{6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1},
|
||||
{3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1},
|
||||
{6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1},
|
||||
{5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
|
||||
{10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1},
|
||||
{6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1},
|
||||
{8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1},
|
||||
{7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1},
|
||||
{3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
|
||||
{5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1},
|
||||
{0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1},
|
||||
{9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1},
|
||||
{8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1},
|
||||
{5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1},
|
||||
{0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1},
|
||||
{6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1},
|
||||
{10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1},
|
||||
{10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1},
|
||||
{8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1},
|
||||
{1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1},
|
||||
{0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1},
|
||||
{10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1},
|
||||
{3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1},
|
||||
{6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1},
|
||||
{9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1},
|
||||
{8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1},
|
||||
{3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1},
|
||||
{6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1},
|
||||
{10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1},
|
||||
{10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1},
|
||||
{2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1},
|
||||
{7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1},
|
||||
{7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1},
|
||||
{2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1},
|
||||
{1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1},
|
||||
{11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1},
|
||||
{8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1},
|
||||
{0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1},
|
||||
{7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
|
||||
{10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
|
||||
{6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1},
|
||||
{7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1},
|
||||
{10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1},
|
||||
{10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1},
|
||||
{0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1},
|
||||
{7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1},
|
||||
{6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1},
|
||||
{8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1},
|
||||
{6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1},
|
||||
{4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1},
|
||||
{10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1},
|
||||
{8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1},
|
||||
{1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1},
|
||||
{8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1},
|
||||
{10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1},
|
||||
{10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
|
||||
{5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
|
||||
{11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1},
|
||||
{9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
|
||||
{6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1},
|
||||
{7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1},
|
||||
{3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1},
|
||||
{7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1},
|
||||
{3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1},
|
||||
{6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1},
|
||||
{9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1},
|
||||
{1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1},
|
||||
{4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1},
|
||||
{7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1},
|
||||
{6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1},
|
||||
{0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1},
|
||||
{6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1},
|
||||
{0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1},
|
||||
{11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1},
|
||||
{6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1},
|
||||
{5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1},
|
||||
{9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1},
|
||||
{1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1},
|
||||
{10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1},
|
||||
{0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1},
|
||||
{5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1},
|
||||
{10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1},
|
||||
{11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1},
|
||||
{9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1},
|
||||
{7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1},
|
||||
{2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1},
|
||||
{8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1},
|
||||
{9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1},
|
||||
{9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1},
|
||||
{1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1},
|
||||
{5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1},
|
||||
{0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1},
|
||||
{10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1},
|
||||
{2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1},
|
||||
{0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1},
|
||||
{0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1},
|
||||
{9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1},
|
||||
{5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1},
|
||||
{5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1},
|
||||
{8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1},
|
||||
{9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1},
|
||||
{1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1},
|
||||
{3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1},
|
||||
{4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1},
|
||||
{9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1},
|
||||
{11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1},
|
||||
{11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1},
|
||||
{2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1},
|
||||
{9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1},
|
||||
{3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1},
|
||||
{1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1},
|
||||
{4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1},
|
||||
{0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1},
|
||||
{9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1},
|
||||
{1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
|
||||
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
|
||||
};
|
||||
}
|
72
library/source/Region.cpp
Normal file
72
library/source/Region.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
#include "Region.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
Region::Region()
|
||||
:m_v3dLowerCorner(0,0,0)
|
||||
,m_v3dUpperCorner(0,0,0)
|
||||
{
|
||||
}
|
||||
|
||||
Region::Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner)
|
||||
:m_v3dLowerCorner(v3dLowerCorner)
|
||||
,m_v3dUpperCorner(v3dUpperCorner)
|
||||
{
|
||||
}
|
||||
|
||||
const Vector3DInt32& Region::getLowerCorner(void) const
|
||||
{
|
||||
return m_v3dLowerCorner;
|
||||
}
|
||||
|
||||
const Vector3DInt32& Region::getUpperCorner(void) const
|
||||
{
|
||||
return m_v3dUpperCorner;
|
||||
}
|
||||
|
||||
void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner)
|
||||
{
|
||||
m_v3dLowerCorner = v3dLowerCorner;
|
||||
}
|
||||
|
||||
void Region::setUpperCorner(const Vector3DInt32& v3dUpperCorner)
|
||||
{
|
||||
m_v3dUpperCorner = v3dUpperCorner;
|
||||
}
|
||||
|
||||
bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const
|
||||
{
|
||||
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
|
||||
&& (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
|
||||
&& (pos.getZ() <= m_v3dUpperCorner.getZ() - boundary)
|
||||
&& (pos.getX() >= m_v3dLowerCorner.getX() + boundary)
|
||||
&& (pos.getY() >= m_v3dLowerCorner.getY() + boundary)
|
||||
&& (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
|
||||
}
|
||||
|
||||
bool Region::containsPoint(const Vector3DInt32& pos, boost::uint8_t boundary) const
|
||||
{
|
||||
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
|
||||
&& (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
|
||||
&& (pos.getZ() <= m_v3dUpperCorner.getZ() - boundary)
|
||||
&& (pos.getX() >= m_v3dLowerCorner.getX() + boundary)
|
||||
&& (pos.getY() >= m_v3dLowerCorner.getY() + boundary)
|
||||
&& (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
|
||||
}
|
||||
|
||||
void Region::cropTo(const Region& other)
|
||||
{
|
||||
m_v3dLowerCorner.setX((std::max)(m_v3dLowerCorner.getX(), other.m_v3dLowerCorner.getX()));
|
||||
m_v3dLowerCorner.setY((std::max)(m_v3dLowerCorner.getY(), other.m_v3dLowerCorner.getY()));
|
||||
m_v3dLowerCorner.setZ((std::max)(m_v3dLowerCorner.getZ(), other.m_v3dLowerCorner.getZ()));
|
||||
m_v3dUpperCorner.setX((std::min)(m_v3dUpperCorner.getX(), other.m_v3dUpperCorner.getX()));
|
||||
m_v3dUpperCorner.setY((std::min)(m_v3dUpperCorner.getY(), other.m_v3dUpperCorner.getY()));
|
||||
m_v3dUpperCorner.setZ((std::min)(m_v3dUpperCorner.getZ(), other.m_v3dUpperCorner.getZ()));
|
||||
}
|
||||
|
||||
void Region::shift(const Vector3DInt32& amount)
|
||||
{
|
||||
m_v3dLowerCorner += amount;
|
||||
m_v3dUpperCorner += amount;
|
||||
}
|
||||
}
|
30
library/source/RegionGeometry.cpp
Normal file
30
library/source/RegionGeometry.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include "IndexedSurfacePatch.h"
|
||||
#include "RegionGeometry.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
RegionGeometry::RegionGeometry()
|
||||
{
|
||||
}
|
||||
}
|
106
library/source/SurfaceEdge.cpp
Normal file
106
library/source/SurfaceEdge.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "SurfaceEdge.h"
|
||||
#include "SurfaceTriangle.h"
|
||||
#include "SurfaceVertex.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
SurfaceEdge::SurfaceEdge(const SurfaceVertexIterator& targetToSet,const SurfaceVertexIterator& sourceToSet)
|
||||
{
|
||||
target = targetToSet;
|
||||
source = sourceToSet;
|
||||
}
|
||||
|
||||
std::string SurfaceEdge::tostring(void)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "SurfaceEdge: Target Vertex = " << target->tostring() << "Source Vertex = " << source->tostring();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool operator == (const SurfaceEdge& lhs, const SurfaceEdge& rhs)
|
||||
{
|
||||
//Vertices are unique in the set, so if the two positions are the same the
|
||||
//two iterators must also be the same. So we just check the iterators.
|
||||
return
|
||||
(
|
||||
(lhs.target == rhs.target) &&
|
||||
(lhs.source == rhs.source)
|
||||
);
|
||||
}
|
||||
|
||||
bool SurfaceEdge::isDegenerate(void)
|
||||
{
|
||||
return (target == source);
|
||||
}
|
||||
|
||||
bool operator < (const SurfaceEdge& lhs, const SurfaceEdge& rhs)
|
||||
{
|
||||
//Unlike the equality operator, we can't compare iterators.
|
||||
//So dereference and compare the results.
|
||||
if ((*lhs.target) < (*rhs.target))
|
||||
return true;
|
||||
if ((*rhs.target) < (*lhs.target))
|
||||
return false;
|
||||
|
||||
if ((*lhs.source) < (*rhs.source))
|
||||
return true;
|
||||
if ((*rhs.source) < (*lhs.source))
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const SurfaceVertexIterator& SurfaceEdge::getTarget(void) const
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
const SurfaceVertexIterator& SurfaceEdge::getSource(void) const
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
void SurfaceEdge::pairWithOtherHalfEdge(const SurfaceEdgeIterator& otherHalfEdgeToPair)
|
||||
{
|
||||
otherHalfEdge = otherHalfEdgeToPair;
|
||||
previousHalfEdge = otherHalfEdgeToPair;
|
||||
nextHalfEdge = otherHalfEdgeToPair;
|
||||
}
|
||||
|
||||
const SurfaceEdgeIterator& SurfaceEdge::getOtherHalfEdge(void) const
|
||||
{
|
||||
return otherHalfEdge;
|
||||
}
|
||||
|
||||
const SurfaceEdgeIterator& SurfaceEdge::getPreviousHalfEdge(void) const
|
||||
{
|
||||
return previousHalfEdge;
|
||||
}
|
||||
|
||||
const SurfaceEdgeIterator& SurfaceEdge::getNextHalfEdge(void) const
|
||||
{
|
||||
return nextHalfEdge;
|
||||
}
|
||||
|
||||
const SurfaceTriangleIterator& SurfaceEdge::getTriangle(void) const
|
||||
{
|
||||
return triangle;
|
||||
}
|
||||
|
||||
void SurfaceEdge::setPreviousHalfEdge(const SurfaceEdgeIterator& previousHalfEdgeToSet)
|
||||
{
|
||||
previousHalfEdge = previousHalfEdgeToSet;
|
||||
}
|
||||
|
||||
void SurfaceEdge::setNextHalfEdge(const SurfaceEdgeIterator& nextHalfEdgeToSet)
|
||||
{
|
||||
nextHalfEdge = nextHalfEdgeToSet;
|
||||
}
|
||||
|
||||
void SurfaceEdge::setTriangle(const SurfaceTriangleIterator& triangleToSet)
|
||||
{
|
||||
triangle = triangleToSet;
|
||||
}
|
||||
}
|
1170
library/source/SurfaceExtractors.cpp
Normal file
1170
library/source/SurfaceExtractors.cpp
Normal file
File diff suppressed because it is too large
Load Diff
59
library/source/SurfaceTriangle.cpp
Normal file
59
library/source/SurfaceTriangle.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "SurfaceTriangle.h"
|
||||
#include "SurfaceVertex.h"
|
||||
#include "SurfaceEdge.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
SurfaceTriangle::SurfaceTriangle()
|
||||
{
|
||||
}
|
||||
|
||||
const SurfaceEdgeIterator& SurfaceTriangle::getEdge(void) const
|
||||
{
|
||||
return edge;
|
||||
}
|
||||
|
||||
void SurfaceTriangle::setEdge(const SurfaceEdgeIterator& edgeToSet)
|
||||
{
|
||||
edge = edgeToSet;
|
||||
}
|
||||
|
||||
/*std::string SurfaceTriangle::tostring(void)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
uint16_t ct = 0;
|
||||
SurfaceEdgeIterator edgeIter = edge;
|
||||
ss << "SurfaceTriangle:";
|
||||
do
|
||||
{
|
||||
ss << "\n Edge " << ct << " = " << edgeIter->tostring();
|
||||
if(edgeIter->hasOtherHalfEdge)
|
||||
{
|
||||
ss << "\n Opp Edge " << ct << " = " << edgeIter->otherHalfEdge->tostring();
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << "\n No Other Half";
|
||||
}
|
||||
edgeIter = edgeIter->nextHalfEdge;
|
||||
++ct;
|
||||
}
|
||||
while(edgeIter != edge);
|
||||
return ss.str();
|
||||
}*/
|
||||
|
||||
bool operator == (const SurfaceTriangle& lhs, const SurfaceTriangle& rhs)
|
||||
{
|
||||
//Edges are unique in the set, so if the two positions are the same the
|
||||
//two iterators must also be the same. So we just check the iterators.
|
||||
return (lhs.edge == rhs.edge);
|
||||
}
|
||||
|
||||
bool operator < (const SurfaceTriangle& lhs, const SurfaceTriangle& rhs)
|
||||
{
|
||||
//Unlike the equality operator, we can't compare iterators.
|
||||
//So dereference and compare the results.
|
||||
return (*lhs.edge < *rhs.edge);
|
||||
}
|
||||
}
|
89
library/source/SurfaceVertex.cpp
Normal file
89
library/source/SurfaceVertex.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "SurfaceVertex.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
SurfaceVertex::SurfaceVertex()
|
||||
{
|
||||
}
|
||||
|
||||
SurfaceVertex::SurfaceVertex(Vector3DFloat positionToSet, float materialToSet, float alphaToSet)
|
||||
:material(materialToSet)
|
||||
,alpha(alphaToSet)
|
||||
,position(positionToSet)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SurfaceVertex::SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet)
|
||||
:position(positionToSet)
|
||||
,normal(normalToSet)
|
||||
{
|
||||
}
|
||||
|
||||
float SurfaceVertex::getAlpha(void) const
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
|
||||
float SurfaceVertex::getMaterial(void) const
|
||||
{
|
||||
return material;
|
||||
}
|
||||
|
||||
const Vector3DFloat& SurfaceVertex::getNormal(void) const
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
|
||||
const Vector3DFloat& SurfaceVertex::getPosition(void) const
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
void SurfaceVertex::setAlpha(float alphaToSet)
|
||||
{
|
||||
alpha = alphaToSet;
|
||||
}
|
||||
|
||||
void SurfaceVertex::setMaterial(float materialToSet)
|
||||
{
|
||||
material = materialToSet;
|
||||
}
|
||||
|
||||
void SurfaceVertex::setNormal(const Vector3DFloat& normalToSet)
|
||||
{
|
||||
normal = normalToSet;
|
||||
normal.normalise();
|
||||
}
|
||||
|
||||
std::string SurfaceVertex::tostring(void) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "SurfaceVertex: Position = (" << position.getX() << "," << position.getY() << "," << position.getZ() << "), Normal = " << normal;
|
||||
return ss.str();
|
||||
}
|
||||
}
|
59
library/source/Utility.cpp
Normal file
59
library/source/Utility.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include "Utility.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
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.
|
||||
boost::uint8_t logBase2(boost::uint32_t uInput)
|
||||
{
|
||||
assert(uInput != 0);
|
||||
assert(isPowerOf2(uInput));
|
||||
|
||||
boost::uint8_t result = 0;
|
||||
uInput = uInput >> 1;
|
||||
while(uInput)
|
||||
{
|
||||
uInput = uInput >> 1;
|
||||
++result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool isPowerOf2(boost::uint32_t uInput)
|
||||
{
|
||||
boost::uint8_t uNonZeroBits = 0;
|
||||
boost::uint32_t uMask = 0x00000001;
|
||||
for(boost::uint8_t ct = 0; ct < 32; ++ct)
|
||||
{
|
||||
if(uInput & uMask)
|
||||
{
|
||||
++uNonZeroBits;
|
||||
}
|
||||
uMask = uMask << 1;
|
||||
}
|
||||
return uNonZeroBits == 1 ? true : false;
|
||||
}
|
||||
}
|
230
library/source/VolumeChangeTracker.cpp
Normal file
230
library/source/VolumeChangeTracker.cpp
Normal file
@ -0,0 +1,230 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include "GradientEstimators.h"
|
||||
#include "IndexedSurfacePatch.h"
|
||||
#include "LinearVolume.h"
|
||||
#include "MarchingCubesTables.h"
|
||||
#include "VolumeChangeTracker.h"
|
||||
#include "RegionGeometry.h"
|
||||
#include "SurfaceExtractors.h"
|
||||
#include "SurfaceVertex.h"
|
||||
#include "Utility.h"
|
||||
#include "Vector.h"
|
||||
#include "BlockVolume.h"
|
||||
#include "BlockVolumeIterator.h"
|
||||
|
||||
using namespace boost;
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// VolumeChangeTracker
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
VolumeChangeTracker::VolumeChangeTracker()
|
||||
:m_bIsLocked(false)
|
||||
,volumeData(0)
|
||||
{
|
||||
}
|
||||
|
||||
VolumeChangeTracker::~VolumeChangeTracker()
|
||||
{
|
||||
}
|
||||
|
||||
void VolumeChangeTracker::setVolumeData(BlockVolume<boost::uint8_t>* volumeDataToSet)
|
||||
{
|
||||
volumeData = volumeDataToSet;
|
||||
volRegionUpToDate = new LinearVolume<bool>(PolyVox::logBase2(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void VolumeChangeTracker::getChangedRegions(std::list<Region>& listToFill) const
|
||||
{
|
||||
//Clear the list
|
||||
listToFill.clear();
|
||||
|
||||
//Regenerate meshes.
|
||||
for(uint16_t regionZ = 0; regionZ < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionZ)
|
||||
//for(uint16_t regionZ = 0; regionZ < 1; ++regionZ)
|
||||
{
|
||||
for(uint16_t regionY = 0; regionY < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionY)
|
||||
//for(uint16_t regionY = 0; regionY < 2; ++regionY)
|
||||
{
|
||||
for(uint16_t regionX = 0; regionX < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionX)
|
||||
//for(uint16_t regionX = 0; regionX < 2; ++regionX)
|
||||
{
|
||||
if(volRegionUpToDate->getVoxelAt(regionX, regionY, regionZ) == false)
|
||||
{
|
||||
const uint16_t firstX = regionX * POLYVOX_REGION_SIDE_LENGTH;
|
||||
const uint16_t firstY = regionY * POLYVOX_REGION_SIDE_LENGTH;
|
||||
const uint16_t firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH;
|
||||
const uint16_t lastX = firstX + POLYVOX_REGION_SIDE_LENGTH;
|
||||
const uint16_t lastY = firstY + POLYVOX_REGION_SIDE_LENGTH;
|
||||
const uint16_t lastZ = firstZ + POLYVOX_REGION_SIDE_LENGTH;
|
||||
|
||||
listToFill.push_back(Region(Vector3DInt32(firstX, firstY, firstZ), Vector3DInt32(lastX, lastY, lastZ)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VolumeChangeTracker::setAllRegionsUpToDate(bool newUpToDateValue)
|
||||
{
|
||||
for(uint16_t blockZ = 0; blockZ < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockZ)
|
||||
{
|
||||
for(uint16_t blockY = 0; blockY < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockY)
|
||||
{
|
||||
for(uint16_t blockX = 0; blockX < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockX)
|
||||
{
|
||||
volRegionUpToDate->setVoxelAt(blockX, blockY, blockZ, newUpToDateValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t VolumeChangeTracker::getSideLength(void)
|
||||
{
|
||||
return volumeData->getSideLength();
|
||||
}
|
||||
|
||||
Region VolumeChangeTracker::getEnclosingRegion(void) const
|
||||
{
|
||||
return volumeData->getEnclosingRegion();
|
||||
}
|
||||
|
||||
uint8_t VolumeChangeTracker::getVoxelAt(const Vector3DUint16& pos)
|
||||
{
|
||||
return getVoxelAt(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
uint8_t VolumeChangeTracker::getVoxelAt(uint16_t uX, uint16_t uY, uint16_t uZ)
|
||||
{
|
||||
assert(uX < volumeData->getSideLength());
|
||||
assert(uY < volumeData->getSideLength());
|
||||
assert(uZ < volumeData->getSideLength());
|
||||
|
||||
BlockVolumeIterator<boost::uint8_t> volIter(*volumeData);
|
||||
volIter.setPosition(uX,uY,uZ);
|
||||
return volIter.getVoxel();
|
||||
}
|
||||
|
||||
BlockVolume<boost::uint8_t>* VolumeChangeTracker::getVolumeData(void) const
|
||||
{
|
||||
return volumeData;
|
||||
}
|
||||
|
||||
void VolumeChangeTracker::setVoxelAt(boost::uint16_t x, boost::uint16_t y, boost::uint16_t z, boost::uint8_t value)
|
||||
{
|
||||
//FIXME - rather than creating a iterator each time we should have one stored
|
||||
BlockVolumeIterator<boost::uint8_t> iterVol(*volumeData);
|
||||
iterVol.setPosition(x,y,z);
|
||||
iterVol.setVoxel(value);
|
||||
|
||||
//If we are not on a boundary, just mark one region.
|
||||
if((x % POLYVOX_REGION_SIDE_LENGTH != 0) &&
|
||||
(x % POLYVOX_REGION_SIDE_LENGTH != POLYVOX_REGION_SIDE_LENGTH-1) &&
|
||||
(y % POLYVOX_REGION_SIDE_LENGTH != 0) &&
|
||||
(y % POLYVOX_REGION_SIDE_LENGTH != POLYVOX_REGION_SIDE_LENGTH-1) &&
|
||||
(z % POLYVOX_REGION_SIDE_LENGTH != 0) &&
|
||||
(z % POLYVOX_REGION_SIDE_LENGTH != POLYVOX_REGION_SIDE_LENGTH-1))
|
||||
{
|
||||
volRegionUpToDate->setVoxelAt(x >> POLYVOX_REGION_SIDE_LENGTH_POWER, y >> POLYVOX_REGION_SIDE_LENGTH_POWER, z >> POLYVOX_REGION_SIDE_LENGTH_POWER, false);
|
||||
}
|
||||
else //Mark surrounding regions as well
|
||||
{
|
||||
const uint16_t regionX = x >> POLYVOX_REGION_SIDE_LENGTH_POWER;
|
||||
const uint16_t regionY = y >> POLYVOX_REGION_SIDE_LENGTH_POWER;
|
||||
const uint16_t regionZ = z >> POLYVOX_REGION_SIDE_LENGTH_POWER;
|
||||
|
||||
const uint16_t minRegionX = (std::max)(uint16_t(0),uint16_t(regionX-1));
|
||||
const uint16_t minRegionY = (std::max)(uint16_t(0),uint16_t(regionY-1));
|
||||
const uint16_t minRegionZ = (std::max)(uint16_t(0),uint16_t(regionZ-1));
|
||||
|
||||
const uint16_t maxRegionX = (std::min)(uint16_t(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS-1),uint16_t(regionX+1));
|
||||
const uint16_t maxRegionY = (std::min)(uint16_t(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS-1),uint16_t(regionY+1));
|
||||
const uint16_t maxRegionZ = (std::min)(uint16_t(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS-1),uint16_t(regionZ+1));
|
||||
|
||||
for(uint16_t zCt = minRegionZ; zCt <= maxRegionZ; zCt++)
|
||||
{
|
||||
for(uint16_t yCt = minRegionY; yCt <= maxRegionY; yCt++)
|
||||
{
|
||||
for(uint16_t xCt = minRegionX; xCt <= maxRegionX; xCt++)
|
||||
{
|
||||
volRegionUpToDate->setVoxelAt(xCt,yCt,zCt,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VolumeChangeTracker::setLockedVoxelAt(boost::uint16_t x, boost::uint16_t y, boost::uint16_t z, boost::uint8_t value)
|
||||
{
|
||||
assert(m_bIsLocked);
|
||||
|
||||
//FIXME - rather than creating a iterator each time we should have one stored
|
||||
BlockVolumeIterator<boost::uint8_t> iterVol(*volumeData);
|
||||
iterVol.setPosition(x,y,z);
|
||||
iterVol.setVoxel(value);
|
||||
}
|
||||
|
||||
void VolumeChangeTracker::lockRegion(const Region& regToLock)
|
||||
{
|
||||
if(m_bIsLocked)
|
||||
{
|
||||
throw std::logic_error("A region is already locked. Please unlock it before locking another.");
|
||||
}
|
||||
|
||||
m_regLastLocked = regToLock;
|
||||
m_bIsLocked = true;
|
||||
}
|
||||
|
||||
void VolumeChangeTracker::unlockRegion(void)
|
||||
{
|
||||
if(!m_bIsLocked)
|
||||
{
|
||||
throw std::logic_error("No region is locked. You must lock a region before you can unlock it.");
|
||||
}
|
||||
|
||||
const uint16_t firstRegionX = m_regLastLocked.getLowerCorner().getX() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
|
||||
const uint16_t firstRegionY = m_regLastLocked.getLowerCorner().getY() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
|
||||
const uint16_t firstRegionZ = m_regLastLocked.getLowerCorner().getZ() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
|
||||
|
||||
const uint16_t lastRegionX = m_regLastLocked.getUpperCorner().getX() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
|
||||
const uint16_t lastRegionY = m_regLastLocked.getUpperCorner().getY() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
|
||||
const uint16_t lastRegionZ = m_regLastLocked.getUpperCorner().getZ() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
|
||||
|
||||
for(uint16_t zCt = firstRegionZ; zCt <= lastRegionZ; zCt++)
|
||||
{
|
||||
for(uint16_t yCt = firstRegionY; yCt <= lastRegionY; yCt++)
|
||||
{
|
||||
for(uint16_t xCt = firstRegionX; xCt <= lastRegionX; xCt++)
|
||||
{
|
||||
volRegionUpToDate->setVoxelAt(xCt,yCt,zCt,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_bIsLocked = false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user