Initial commit of VolumeResampler and LOD demo.

This commit is contained in:
David Williams
2011-07-02 12:39:04 +01:00
parent 3ab157dc3b
commit ccfa7db1fa
16 changed files with 27636 additions and 2 deletions

View File

@ -61,6 +61,8 @@ SET(CORE_INC_FILES
include/PolyVoxCore/Vector.h
include/PolyVoxCore/Vector.inl
include/PolyVoxCore/VertexTypes.h
include/PolyVoxCore/VolumeResampler.h
include/PolyVoxCore/VolumeResampler.inl
include/PolyVoxCore/VoxelFilters.h
)

View File

@ -63,7 +63,7 @@ namespace PolyVox
{
uint16_t& uDensity = temp[x-croppedRegion.getLowerCorner().getX()][y-croppedRegion.getLowerCorner().getY()][z-croppedRegion.getLowerCorner().getZ()];
MaterialDensityPair44 val = volData.getVoxelAt(x,y,z);
VoxelType val = volData.getVoxelAt(x,y,z);
val.setDensity(uDensity);
volData.setVoxelAt(x,y,z,val);
}

View File

@ -63,6 +63,8 @@ namespace PolyVox
void clear(void);
bool isEmpty(void) const;
void scaleVertices(float amount);
//THESE FUNCTIONS TO BE REMOVED IN THE FUTURE. OR AT LEAST MOVED OUT OF THIS CLASS INTO FREE FUNCTIONS.
//THEY ARE CAUSING PROBLEMS WITH THE SWIG BINDINGS. THE FUNCTIONS REGARDING NORMALS MAKE NO SENSE WHEN
//A VERTEX MIGHT NOT HAVE NORMALS. THE EXTRACT SUBSET FUNCTION SHOULD MAYBE BE APPLICATION CODE, AT ANY

View File

@ -463,4 +463,16 @@ namespace PolyVox
return result;
}
}
template <typename VertexType>
void SurfaceMesh<VertexType>::scaleVertices(float amount)
{
for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++)
{
//TODO: Should rethink accessors here to provide faster access
Vector3DFloat position = m_vecVertices[ct].getPosition();
position *= amount;
m_vecVertices[ct].setPosition(position);
}
}
}

View File

@ -0,0 +1,57 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_VolumeResampler_H__
#define __PolyVox_VolumeResampler_H__
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
namespace PolyVox
{
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
class VolumeResampler
{
public:
VolumeResampler(SrcVolumeType<VoxelType>* pVolSrc, Region regSrc, DestVolumeType<VoxelType>* pVolDst, Region regDst);
void execute();
private:
void resampleSameSize();
void resampleHalfSize();
//Source data
SrcVolumeType<VoxelType>* m_pVolSrc;
Region m_regSrc;
//Destination data
DestVolumeType<VoxelType>* m_pVolDst;
Region m_regDst;
};
}//namespace PolyVox
#include "PolyVoxCore/VolumeResampler.inl"
#endif

View File

@ -0,0 +1,95 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::VolumeResampler(SrcVolumeType<VoxelType>* pVolSrc, Region regSrc, DestVolumeType<VoxelType>* pVolDst, Region regDst)
:m_pVolSrc(pVolSrc)
,m_regSrc(regSrc)
,m_pVolDst(pVolDst)
,m_regDst(regDst)
{
}
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::execute()
{
//resampleSameSize();
resampleHalfSize();
}
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::resampleSameSize()
{
for(int32_t sz = m_regSrc.getLowerCorner().getZ(), dz = m_regDst.getLowerCorner().getZ(); dz <= m_regDst.getUpperCorner().getZ(); sz++, dz++)
{
for(int32_t sy = m_regSrc.getLowerCorner().getY(), dy = m_regDst.getLowerCorner().getY(); dy <= m_regDst.getUpperCorner().getY(); sy++, dy++)
{
for(int32_t sx = m_regSrc.getLowerCorner().getX(), dx = m_regDst.getLowerCorner().getX(); dx <= m_regDst.getUpperCorner().getX(); sx++,dx++)
{
VoxelType voxel = m_pVolSrc->getVoxelAt(sx,sy,sz);
m_pVolDst->setVoxelAt(dx,dy,dz,voxel);
}
}
}
}
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::resampleHalfSize()
{
for(int32_t sz = m_regSrc.getLowerCorner().getZ(), dz = m_regDst.getLowerCorner().getZ(); dz <= m_regDst.getUpperCorner().getZ(); sz+=2, dz++)
{
for(int32_t sy = m_regSrc.getLowerCorner().getY(), dy = m_regDst.getLowerCorner().getY(); dy <= m_regDst.getUpperCorner().getY(); sy+=2, dy++)
{
for(int32_t sx = m_regSrc.getLowerCorner().getX(), dx = m_regDst.getLowerCorner().getX(); dx <= m_regDst.getUpperCorner().getX(); sx+=2,dx++)
{
VoxelType voxel000 = m_pVolSrc->getVoxelAt(sx+0,sy+0,sz+0);
VoxelType voxel001 = m_pVolSrc->getVoxelAt(sx+0,sy+0,sz+1);
VoxelType voxel010 = m_pVolSrc->getVoxelAt(sx+0,sy+1,sz+0);
VoxelType voxel011 = m_pVolSrc->getVoxelAt(sx+0,sy+1,sz+1);
VoxelType voxel100 = m_pVolSrc->getVoxelAt(sx+1,sy+0,sz+0);
VoxelType voxel101 = m_pVolSrc->getVoxelAt(sx+1,sy+0,sz+1);
VoxelType voxel110 = m_pVolSrc->getVoxelAt(sx+1,sy+1,sz+0);
VoxelType voxel111 = m_pVolSrc->getVoxelAt(sx+1,sy+1,sz+1);
uint32_t averageDensity = 0;
averageDensity += voxel000.getDensity();
averageDensity += voxel001.getDensity();
averageDensity += voxel010.getDensity();
averageDensity += voxel011.getDensity();
averageDensity += voxel100.getDensity();
averageDensity += voxel101.getDensity();
averageDensity += voxel110.getDensity();
averageDensity += voxel111.getDensity();
averageDensity /= 8;
VoxelType result;
result.setDensity(averageDensity);
m_pVolDst->setVoxelAt(dx,dy,dz,result);
}
}
}
}
}