Added smoothRegion function to smooth part of a volume.
This commit is contained in:
@ -22,6 +22,8 @@ SET(CORE_INC_FILES
|
||||
include/Array.h
|
||||
include/Array.inl
|
||||
include/ArraySizes.h
|
||||
include/Filters.h
|
||||
include/Filters.inl
|
||||
include/GradientEstimators.inl
|
||||
include/Log.h
|
||||
include/MaterialDensityPair.h
|
||||
|
@ -28,6 +28,7 @@ distribution.
|
||||
|
||||
#pragma region Headers
|
||||
#include "PolyVoxImpl/ArraySizesImpl.h"
|
||||
#include "PolyVoxImpl/Typedef.h"
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
@ -56,7 +57,7 @@ namespace PolyVox
|
||||
/// behind it may appear complex. For reference, it is based upon the article here:
|
||||
/// http://www.drdobbs.com/cpp/184401319/
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class ArraySizes
|
||||
class POLYVOXCORE_API ArraySizes
|
||||
{
|
||||
typedef const uint32_t (&UIntArray1)[1];
|
||||
|
||||
|
43
library/PolyVoxCore/include/Filters.h
Normal file
43
library/PolyVoxCore/include/Filters.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma region License
|
||||
/*******************************************************************************
|
||||
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.
|
||||
*******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_Filters_H__
|
||||
#define __PolyVox_Filters_H__
|
||||
|
||||
#pragma region Headers
|
||||
#include "Array.h"
|
||||
#include "Region.h"
|
||||
#include "Volume.h"
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
void smoothRegion(Volume<VoxelType>& volData, const Region& regionToSmooth);
|
||||
}//namespace PolyVox
|
||||
|
||||
#include "Filters.inl"
|
||||
|
||||
#endif
|
69
library/PolyVoxCore/include/Filters.inl
Normal file
69
library/PolyVoxCore/include/Filters.inl
Normal file
@ -0,0 +1,69 @@
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
void smoothRegion(Volume<VoxelType>& volData, const Region& regionToSmooth)
|
||||
{
|
||||
Region croppedRegion = regionToSmooth;
|
||||
croppedRegion.cropTo(volData.getEnclosingRegion());
|
||||
|
||||
Array<3, uint16_t> temp(ArraySizes(croppedRegion.width())(croppedRegion.height())(croppedRegion.depth()));
|
||||
|
||||
for (int z = croppedRegion.getLowerCorner().getZ(); z < croppedRegion.getUpperCorner().getZ(); z++)
|
||||
{
|
||||
for (int y = croppedRegion.getLowerCorner().getY(); y < croppedRegion.getUpperCorner().getY(); y++)
|
||||
{
|
||||
for (int x = croppedRegion.getLowerCorner().getX(); x < croppedRegion.getUpperCorner().getX(); x++)
|
||||
{
|
||||
uint16_t& uDensity = temp[x-croppedRegion.getLowerCorner().getX()][y-croppedRegion.getLowerCorner().getY()][z-croppedRegion.getLowerCorner().getZ()];
|
||||
|
||||
uDensity=0;
|
||||
uDensity += volData.getVoxelAt(x-1,y-1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-1,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-0,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-0,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-0,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y+1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y+1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y+1,z+1).getDensity();
|
||||
|
||||
uDensity += volData.getVoxelAt(x-0,y-1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-1,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-0,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-0,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-0,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y+1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y+1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y+1,z+1).getDensity();
|
||||
|
||||
uDensity += volData.getVoxelAt(x+1,y-1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-1,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-0,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-0,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-0,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y+1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y+1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y+1,z+1).getDensity();
|
||||
uDensity /= 27;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int z = croppedRegion.getLowerCorner().getZ(); z < croppedRegion.getUpperCorner().getZ(); z++)
|
||||
{
|
||||
for (int y = croppedRegion.getLowerCorner().getY(); y < croppedRegion.getUpperCorner().getY(); y++)
|
||||
{
|
||||
for (int x = croppedRegion.getLowerCorner().getX(); x < croppedRegion.getUpperCorner().getX(); x++)
|
||||
{
|
||||
uint16_t& uDensity = temp[x-croppedRegion.getLowerCorner().getX()][y-croppedRegion.getLowerCorner().getY()][z-croppedRegion.getLowerCorner().getZ()];
|
||||
|
||||
MaterialDensityPair44 val = volData.getVoxelAt(x,y,z);
|
||||
val.setDensity(uDensity);
|
||||
volData.setVoxelAt(x,y,z,val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user