Tidying up...

This commit is contained in:
David Williams
2008-06-25 20:16:58 +00:00
parent e6a7174b53
commit 9a58b83b6d
10 changed files with 155 additions and 109 deletions

View File

@ -20,6 +20,7 @@ SET(SRC_FILES
source/SurfaceVertex.cpp
source/Utility.cpp
source/VolumeChangeTracker.cpp
source/VoxelFilters.cpp
)
#Projects headers files
@ -50,6 +51,7 @@ SET(INC_FILES
include/Vector.h
include/Vector.inl
include/VolumeChangeTracker.h
include/VoxelFilters.h
)
FIND_PACKAGE(Boost REQUIRED)

View File

@ -43,10 +43,10 @@ namespace PolyVox
bool operator<=(const BlockVolumeIterator& rhs);
bool operator>=(const BlockVolumeIterator& rhs);
VoxelType getMaxedVoxel(boost::uint8_t uLevel) const;
boost::uint16_t getPosX(void) const;
boost::uint16_t getPosY(void) const;
boost::uint16_t getPosZ(void) const;
VoxelType getSubSampledVoxel(boost::uint8_t uLevel) const;
const BlockVolume<VoxelType>& getVolume(void) const;
VoxelType getVoxel(void) const;

View File

@ -105,7 +105,25 @@ namespace PolyVox
#pragma region Getters
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::getMaxedVoxel(boost::uint8_t uLevel) const
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>::getSubSampledVoxel(boost::uint8_t uLevel) const
{
if(uLevel == 0)
{
@ -142,24 +160,6 @@ namespace PolyVox
}
}
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>
const BlockVolume<VoxelType>& BlockVolumeIterator<VoxelType>::getVolume(void) const
{

View File

@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
******************************************************************************/
#pragma endregion
#include "SurfaceAdjusters.h"
#include "VoxelFilters.h"
namespace PolyVox
{

View File

@ -33,7 +33,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
namespace PolyVox
{
POLYVOX_API void smoothRegionGeometry(BlockVolume<boost::uint8_t>* volumeData, RegionGeometry& regGeom);
float computeSmoothedVoxel(BlockVolumeIterator<boost::uint8_t>& volIter);
}
#endif

View File

@ -0,0 +1,36 @@
#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_VoxelFilters_H__
#define __PolyVox_VoxelFilters_H__
#pragma region Headers
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
#pragma endregion
namespace PolyVox
{
float computeSmoothedVoxel(BlockVolumeIterator<boost::uint8_t>& volIter);
}
#endif

View File

@ -5,6 +5,7 @@
#include "IndexedSurfacePatch.h"
#include "RegionGeometry.h"
#include "Utility.h"
#include "VoxelFilters.h"
#include <vector>
@ -73,49 +74,4 @@ namespace PolyVox
++iterSurfaceVertex;
} //while(iterSurfaceVertex != vecVertices.end())
}
float computeSmoothedVoxel(BlockVolumeIterator<boost::uint8_t>& volIter)
{
assert(volIter.getPosX() >= 1);
assert(volIter.getPosY() >= 1);
assert(volIter.getPosZ() >= 1);
assert(volIter.getPosX() < volIter.getVolume().getSideLength() - 2);
assert(volIter.getPosY() < volIter.getVolume().getSideLength() - 2);
assert(volIter.getPosZ() < volIter.getVolume().getSideLength() - 2);
float sum = 0.0;
if(volIter.peekVoxel1nx1ny1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1ny0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1ny1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx0py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx0py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx0py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1ny1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1ny0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1ny1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px0py1nz() != 0) sum += 1.0f;
if(volIter.getVoxel() != 0) sum += 1.0f;
if(volIter.peekVoxel0px0py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1ny1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1ny0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1ny1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px0py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px0py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px0py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1py1pz() != 0) sum += 1.0f;
sum /= 27.0f;
return sum;
}
}

View File

@ -129,22 +129,22 @@ namespace PolyVox
if((x==regSlice.getLowerCorner().getX()) && (y==regSlice.getLowerCorner().getY()))
{
volIter.setPosition(x,y,regSlice.getLowerCorner().getZ());
const uint8_t v000 = volIter.getMaxedVoxel(uLevel);
const uint8_t v000 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ());
const uint8_t v100 = volIter.getMaxedVoxel(uLevel);
const uint8_t v100 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8_t v010 = volIter.getMaxedVoxel(uLevel);
const uint8_t v010 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8_t v110 = volIter.getMaxedVoxel(uLevel);
const uint8_t v110 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v001 = volIter.getMaxedVoxel(uLevel);
const uint8_t v001 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v101 = volIter.getMaxedVoxel(uLevel);
const uint8_t v101 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v011 = volIter.getMaxedVoxel(uLevel);
const uint8_t v011 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v111 = volIter.getMaxedVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
if (v000 == 0) iCubeIndex |= 1;
if (v100 == 0) iCubeIndex |= 2;
@ -158,14 +158,14 @@ namespace PolyVox
else if((x>regSlice.getLowerCorner().getX()) && y==regSlice.getLowerCorner().getY())
{
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ());
const uint8_t v100 = volIter.getMaxedVoxel(uLevel);
const uint8_t v100 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8_t v110 = volIter.getMaxedVoxel(uLevel);
const uint8_t v110 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v101 = volIter.getMaxedVoxel(uLevel);
const uint8_t v101 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v111 = volIter.getMaxedVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//x
uint8_t iPreviousCubeIndexX = bitmask[getDecimatedIndex(x- offset.getX()-uStepSize,y- offset.getY())];
@ -193,14 +193,14 @@ namespace PolyVox
else if((x==regSlice.getLowerCorner().getX()) && (y>regSlice.getLowerCorner().getY()))
{
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8_t v010 = volIter.getMaxedVoxel(uLevel);
const uint8_t v010 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8_t v110 = volIter.getMaxedVoxel(uLevel);
const uint8_t v110 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v011 = volIter.getMaxedVoxel(uLevel);
const uint8_t v011 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v111 = volIter.getMaxedVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//y
uint8_t iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize)];
@ -228,10 +228,10 @@ namespace PolyVox
else
{
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8_t v110 = volIter.getMaxedVoxel(uLevel);
const uint8_t v110 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v111 = volIter.getMaxedVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//y
uint8_t iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize)];
@ -298,13 +298,13 @@ namespace PolyVox
if((x==regSlice.getLowerCorner().getX()) && (y==regSlice.getLowerCorner().getY()))
{
volIter.setPosition(x,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v001 = volIter.getMaxedVoxel(uLevel);
const uint8_t v001 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v101 = volIter.getMaxedVoxel(uLevel);
const uint8_t v101 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v011 = volIter.getMaxedVoxel(uLevel);
const uint8_t v011 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v111 = volIter.getMaxedVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//z
uint8_t iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY())];
@ -318,9 +318,9 @@ namespace PolyVox
else if((x>regSlice.getLowerCorner().getX()) && y==regSlice.getLowerCorner().getY())
{
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v101 = volIter.getMaxedVoxel(uLevel);
const uint8_t v101 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v111 = volIter.getMaxedVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//z
uint8_t iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY())];
@ -342,9 +342,9 @@ namespace PolyVox
else if((x==regSlice.getLowerCorner().getX()) && (y>regSlice.getLowerCorner().getY()))
{
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v011 = volIter.getMaxedVoxel(uLevel);
const uint8_t v011 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v111 = volIter.getMaxedVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//z
uint8_t iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY())];
@ -366,7 +366,7 @@ namespace PolyVox
else
{
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8_t v111 = volIter.getMaxedVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//z
uint8_t iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY())];
@ -418,7 +418,7 @@ namespace PolyVox
const uint16_t z = regSlice.getLowerCorner().getZ();
volIter.setPosition(x,y,z);
const uint8_t v000 = volIter.getMaxedVoxel(uLevel);
const uint8_t v000 = volIter.getSubSampledVoxel(uLevel);
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = bitmask[getDecimatedIndex(x - offset.getX(),y - offset.getY())];
@ -435,7 +435,7 @@ namespace PolyVox
if(x != regSlice.getUpperCorner().getX())
{
volIter.setPosition(x + uStepSize,y,z);
const uint8_t v100 = volIter.getMaxedVoxel(uLevel);
const uint8_t v100 = volIter.getSubSampledVoxel(uLevel);
const Vector3DFloat v3dPosition(x - offset.getX() + 0.5f * uStepSize, y - offset.getY(), z - offset.getZ());
const Vector3DFloat v3dNormal(v000 > v100 ? 1.0f : -1.0f,0.0,0.0);
const uint8_t uMaterial = v000 | v100; //Because one of these is 0, the or operation takes the max.
@ -449,7 +449,7 @@ namespace PolyVox
if(y != regSlice.getUpperCorner().getY())
{
volIter.setPosition(x,y + uStepSize,z);
const uint8_t v010 = volIter.getMaxedVoxel(uLevel);
const uint8_t v010 = volIter.getSubSampledVoxel(uLevel);
const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY() + 0.5f * uStepSize, z - offset.getZ());
const Vector3DFloat v3dNormal(0.0,v000 > v010 ? 1.0f : -1.0f,0.0);
const uint8_t uMaterial = v000 | v010; //Because one of these is 0, the or operation takes the max.
@ -463,7 +463,7 @@ namespace PolyVox
//if(z != regSlice.getUpperCorner.getZ())
{
volIter.setPosition(x,y,z + uStepSize);
const uint8_t v001 = volIter.getMaxedVoxel(uLevel);
const uint8_t v001 = volIter.getSubSampledVoxel(uLevel);
const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY(), z - offset.getZ() + 0.5f * uStepSize);
const Vector3DFloat v3dNormal(0.0,0.0,v000 > v001 ? 1.0f : -1.0f);
const uint8_t uMaterial = v000 | v001; //Because one of these is 0, the or operation takes the max.
@ -606,21 +606,21 @@ namespace PolyVox
//while(volIter.moveForwardInRegionXYZ())
//{
volIter.setPosition(x,y,z);
const uint8_t v000 = volIter.getMaxedVoxel(1);
const uint8_t v000 = volIter.getSubSampledVoxel(1);
volIter.setPosition(x+2,y,z);
const uint8_t v100 = volIter.getMaxedVoxel(1);
const uint8_t v100 = volIter.getSubSampledVoxel(1);
volIter.setPosition(x,y+2,z);
const uint8_t v010 = volIter.getMaxedVoxel(1);
const uint8_t v010 = volIter.getSubSampledVoxel(1);
volIter.setPosition(x+2,y+2,z);
const uint8_t v110 = volIter.getMaxedVoxel(1);
const uint8_t v110 = volIter.getSubSampledVoxel(1);
volIter.setPosition(x,y,z+2);
const uint8_t v001 = volIter.getMaxedVoxel(1);
const uint8_t v001 = volIter.getSubSampledVoxel(1);
volIter.setPosition(x+2,y,z+2);
const uint8_t v101 = volIter.getMaxedVoxel(1);
const uint8_t v101 = volIter.getSubSampledVoxel(1);
volIter.setPosition(x,y+2,z+2);
const uint8_t v011 = volIter.getMaxedVoxel(1);
const uint8_t v011 = volIter.getSubSampledVoxel(1);
volIter.setPosition(x+2,y+2,z+2);
const uint8_t v111 = volIter.getMaxedVoxel(1);
const uint8_t v111 = volIter.getSubSampledVoxel(1);
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = 0;

View File

@ -0,0 +1,51 @@
#include "VoxelFilters.h"
#include "BlockVolumeIterator.h"
namespace PolyVox
{
float computeSmoothedVoxel(BlockVolumeIterator<boost::uint8_t>& volIter)
{
assert(volIter.getPosX() >= 1);
assert(volIter.getPosY() >= 1);
assert(volIter.getPosZ() >= 1);
assert(volIter.getPosX() < volIter.getVolume().getSideLength() - 2);
assert(volIter.getPosY() < volIter.getVolume().getSideLength() - 2);
assert(volIter.getPosZ() < volIter.getVolume().getSideLength() - 2);
float sum = 0.0;
if(volIter.peekVoxel1nx1ny1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1ny0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1ny1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx0py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx0py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx0py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1nx1py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1ny1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1ny0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1ny1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px0py1nz() != 0) sum += 1.0f;
if(volIter.getVoxel() != 0) sum += 1.0f;
if(volIter.peekVoxel0px0py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel0px1py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1ny1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1ny0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1ny1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px0py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px0py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px0py1pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1py1nz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1py0pz() != 0) sum += 1.0f;
if(volIter.peekVoxel1px1py1pz() != 0) sum += 1.0f;
sum /= 27.0f;
return sum;
}
}