Fixed bug with RawVolume always starting coordinates at (0,0,0).
Removed Filters.h/.inl Added Summed Area Table support to LowPassFilter. Added test for low pass filter.
This commit is contained in:
@ -21,10 +21,11 @@ freely, subject to the following restrictions:
|
|||||||
distribution.
|
distribution.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include "PolyVoxCore/Filters.h"
|
|
||||||
#include "PolyVoxCore/Log.h"
|
#include "PolyVoxCore/Log.h"
|
||||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||||
#include "PolyVoxCore/LargeVolume.h"
|
#include "PolyVoxCore/LargeVolume.h"
|
||||||
|
#include "PolyVoxCore/LowPassFilter.h"
|
||||||
|
#include "PolyVoxCore/RawVolume.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/SurfaceMesh.h"
|
||||||
#include "PolyVoxImpl/Utility.h"
|
#include "PolyVoxImpl/Utility.h"
|
||||||
|
|
||||||
@ -101,8 +102,11 @@ int main(int argc, char *argv[])
|
|||||||
createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity());
|
createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity());
|
||||||
|
|
||||||
//Smooth part of the volume
|
//Smooth part of the volume
|
||||||
smoothRegion<LargeVolume, MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127)));
|
RawVolume<MaterialDensityPair44> tempVolume(Region(0,0,0,128, 128, 128));
|
||||||
smoothRegion<LargeVolume, MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127)));
|
LowPassFilter<LargeVolume, RawVolume, MaterialDensityPair44> pass1(&volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3);
|
||||||
|
pass1.executeSAT();
|
||||||
|
LowPassFilter<RawVolume, LargeVolume, MaterialDensityPair44> pass2(&tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3);
|
||||||
|
pass2.executeSAT();
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxCore/SurfaceExtractor.h"
|
#include "PolyVoxCore/SurfaceExtractor.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/SurfaceMesh.h"
|
||||||
#include "PolyVoxCore/LargeVolume.h"
|
#include "PolyVoxCore/LargeVolume.h"
|
||||||
#include "PolyVoxCore/Filters.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ freely, subject to the following restrictions:
|
|||||||
#include "OpenGLWidget.h"
|
#include "OpenGLWidget.h"
|
||||||
|
|
||||||
#include "PolyVoxCore/Density.h"
|
#include "PolyVoxCore/Density.h"
|
||||||
#include "PolyVoxCore/Filters.h"
|
|
||||||
#include "PolyVoxCore/SurfaceExtractor.h"
|
#include "PolyVoxCore/SurfaceExtractor.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/SurfaceMesh.h"
|
||||||
#include "PolyVoxCore/RawVolume.h"
|
#include "PolyVoxCore/RawVolume.h"
|
||||||
@ -86,10 +85,10 @@ int main(int argc, char *argv[])
|
|||||||
SimpleVolume<Density8> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
|
SimpleVolume<Density8> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
|
||||||
createSphereInVolume(volData, 28);
|
createSphereInVolume(volData, 28);
|
||||||
|
|
||||||
//Smooth the data
|
//Smooth the data - should reimplement this using LowPassFilter
|
||||||
smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
//smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
||||||
smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
//smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
||||||
smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
//smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
||||||
|
|
||||||
RawVolume<Density8> volDataLowLOD(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(15, 31, 31)));
|
RawVolume<Density8> volDataLowLOD(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(15, 31, 31)));
|
||||||
|
|
||||||
|
@ -29,8 +29,6 @@ SET(CORE_INC_FILES
|
|||||||
include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h
|
include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h
|
||||||
include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl
|
include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl
|
||||||
include/PolyVoxCore/Density.h
|
include/PolyVoxCore/Density.h
|
||||||
include/PolyVoxCore/Filters.h
|
|
||||||
include/PolyVoxCore/Filters.inl
|
|
||||||
include/PolyVoxCore/GradientEstimators.h
|
include/PolyVoxCore/GradientEstimators.h
|
||||||
include/PolyVoxCore/GradientEstimators.inl
|
include/PolyVoxCore/GradientEstimators.inl
|
||||||
include/PolyVoxCore/LargeVolume.h
|
include/PolyVoxCore/LargeVolume.h
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
|
||||||
|
|
||||||
namespace PolyVox
|
|
||||||
{
|
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
|
||||||
void smoothRegion(VolumeType<VoxelType>& volData, const Region& regionToSmooth)
|
|
||||||
{
|
|
||||||
Region croppedRegion = regionToSmooth;
|
|
||||||
|
|
||||||
uint32_t uArrayWidth = croppedRegion.getUpperCorner().getX() - croppedRegion.getLowerCorner().getX() + 1;
|
|
||||||
uint32_t uArrayHeight = croppedRegion.getUpperCorner().getY() - croppedRegion.getLowerCorner().getY() + 1;
|
|
||||||
uint32_t uArrayDepth = croppedRegion.getUpperCorner().getZ() - croppedRegion.getLowerCorner().getZ() + 1;
|
|
||||||
Array<3, uint16_t> temp(ArraySizes(uArrayWidth)(uArrayHeight)(uArrayDepth));
|
|
||||||
|
|
||||||
for (int32_t z = croppedRegion.getLowerCorner().getZ(); z <= croppedRegion.getUpperCorner().getZ(); z++)
|
|
||||||
{
|
|
||||||
for (int32_t y = croppedRegion.getLowerCorner().getY(); y <= croppedRegion.getUpperCorner().getY(); y++)
|
|
||||||
{
|
|
||||||
for (int32_t 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 (int32_t z = croppedRegion.getLowerCorner().getZ(); z < croppedRegion.getUpperCorner().getZ(); z++)
|
|
||||||
{
|
|
||||||
for (int32_t y = croppedRegion.getLowerCorner().getY(); y < croppedRegion.getUpperCorner().getY(); y++)
|
|
||||||
{
|
|
||||||
for (int32_t 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()];
|
|
||||||
|
|
||||||
VoxelType val = volData.getVoxelAt(x,y,z);
|
|
||||||
val.setDensity(uDensity);
|
|
||||||
volData.setVoxelAt(x,y,z,val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -33,9 +33,10 @@ namespace PolyVox
|
|||||||
class LowPassFilter
|
class LowPassFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LowPassFilter(SrcVolumeType<VoxelType>* pVolSrc, Region regSrc, DestVolumeType<VoxelType>* pVolDst, Region regDst);
|
LowPassFilter(SrcVolumeType<VoxelType>* pVolSrc, Region regSrc, DestVolumeType<VoxelType>* pVolDst, Region regDst, uint32_t uKernelSize);
|
||||||
|
|
||||||
void execute();
|
void execute();
|
||||||
|
void executeSAT();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//Source data
|
//Source data
|
||||||
@ -45,6 +46,9 @@ namespace PolyVox
|
|||||||
//Destination data
|
//Destination data
|
||||||
DestVolumeType<VoxelType>* m_pVolDst;
|
DestVolumeType<VoxelType>* m_pVolDst;
|
||||||
Region m_regDst;
|
Region m_regDst;
|
||||||
|
|
||||||
|
//Kernel size
|
||||||
|
uint32_t m_uKernelSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace PolyVox
|
}//namespace PolyVox
|
||||||
|
@ -21,15 +21,28 @@ freely, subject to the following restrictions:
|
|||||||
distribution.
|
distribution.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "PolyVoxCore/RawVolume.h"
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
LowPassFilter<SrcVolumeType, DestVolumeType, VoxelType>::LowPassFilter(SrcVolumeType<VoxelType>* pVolSrc, Region regSrc, DestVolumeType<VoxelType>* pVolDst, Region regDst)
|
LowPassFilter<SrcVolumeType, DestVolumeType, VoxelType>::LowPassFilter(SrcVolumeType<VoxelType>* pVolSrc, Region regSrc, DestVolumeType<VoxelType>* pVolDst, Region regDst, uint32_t uKernelSize)
|
||||||
:m_pVolSrc(pVolSrc)
|
:m_pVolSrc(pVolSrc)
|
||||||
,m_regSrc(regSrc)
|
,m_regSrc(regSrc)
|
||||||
,m_pVolDst(pVolDst)
|
,m_pVolDst(pVolDst)
|
||||||
,m_regDst(regDst)
|
,m_regDst(regDst)
|
||||||
|
,m_uKernelSize(uKernelSize)
|
||||||
{
|
{
|
||||||
|
//Kernel size must be at least three
|
||||||
|
assert(m_uKernelSize >= 3);
|
||||||
|
m_uKernelSize = std::max(m_uKernelSize, static_cast<uint32_t>(3)); //For release builds
|
||||||
|
|
||||||
|
//Kernel size must be odd
|
||||||
|
assert(m_uKernelSize % 2 == 1);
|
||||||
|
if(m_uKernelSize % 2 == 0) //For release builds
|
||||||
|
{
|
||||||
|
m_uKernelSize++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
@ -103,4 +116,126 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
|
void LowPassFilter<SrcVolumeType, DestVolumeType, VoxelType>::executeSAT()
|
||||||
|
{
|
||||||
|
const int border = m_uKernelSize - 1;
|
||||||
|
|
||||||
|
Vector3DInt32 satLowerCorner = m_regSrc.getLowerCorner() - Vector3DInt32(border+1, border+1, border+1);
|
||||||
|
Vector3DInt32 satUpperCorner = m_regSrc.getUpperCorner() + Vector3DInt32(border, border, border);
|
||||||
|
|
||||||
|
RawVolume<uint32_t> satVolume(Region(satLowerCorner, satUpperCorner));
|
||||||
|
|
||||||
|
//Clear to zeros (necessary?)
|
||||||
|
for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++)
|
||||||
|
{
|
||||||
|
for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++)
|
||||||
|
{
|
||||||
|
for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++)
|
||||||
|
{
|
||||||
|
satVolume.setVoxelAt(x,y,z,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Build SAT in three passes
|
||||||
|
for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++)
|
||||||
|
{
|
||||||
|
for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++)
|
||||||
|
{
|
||||||
|
for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++)
|
||||||
|
{
|
||||||
|
uint32_t previousSum = satVolume.getVoxelAt(x-1,y,z);
|
||||||
|
uint32_t currentVal = m_pVolSrc->getVoxelAt(x,y,z).getDensity();
|
||||||
|
|
||||||
|
satVolume.setVoxelAt(x,y,z,previousSum + currentVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++)
|
||||||
|
{
|
||||||
|
for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++)
|
||||||
|
{
|
||||||
|
for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++)
|
||||||
|
{
|
||||||
|
uint32_t previousSum = satVolume.getVoxelAt(x,y-1,z);
|
||||||
|
uint32_t currentSum = satVolume.getVoxelAt(x,y,z);
|
||||||
|
|
||||||
|
satVolume.setVoxelAt(x,y,z,previousSum + currentSum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++)
|
||||||
|
{
|
||||||
|
for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++)
|
||||||
|
{
|
||||||
|
for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++)
|
||||||
|
{
|
||||||
|
uint32_t previousSum = satVolume.getVoxelAt(x,y,z-1);
|
||||||
|
uint32_t currentSum = satVolume.getVoxelAt(x,y,z);
|
||||||
|
|
||||||
|
satVolume.setVoxelAt(x,y,z,previousSum + currentSum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Now compute the average
|
||||||
|
const Vector3DInt32& v3dDestLowerCorner = m_regDst.getLowerCorner();
|
||||||
|
const Vector3DInt32& v3dDestUpperCorner = m_regDst.getUpperCorner();
|
||||||
|
|
||||||
|
const Vector3DInt32& v3dSrcLowerCorner = m_regSrc.getLowerCorner();
|
||||||
|
const Vector3DInt32& v3dSrcUpperCorner = m_regSrc.getUpperCorner();
|
||||||
|
|
||||||
|
for(int32_t iDstZ = v3dDestLowerCorner.getZ(), iSrcZ = v3dSrcLowerCorner.getZ(); iDstZ <= v3dDestUpperCorner.getZ(); iDstZ++, iSrcZ++)
|
||||||
|
{
|
||||||
|
for(int32_t iDstY = v3dDestLowerCorner.getY(), iSrcY = v3dSrcLowerCorner.getY(); iDstY <= v3dDestUpperCorner.getY(); iDstY++, iSrcY++)
|
||||||
|
{
|
||||||
|
for(int32_t iDstX = v3dDestLowerCorner.getX(), iSrcX = v3dSrcLowerCorner.getX(); iDstX <= v3dDestUpperCorner.getX(); iDstX++, iSrcX++)
|
||||||
|
{
|
||||||
|
int32_t satLowerX = iSrcX - border - 1;
|
||||||
|
int32_t satLowerY = iSrcY - border - 1;
|
||||||
|
int32_t satLowerZ = iSrcZ - border - 1;
|
||||||
|
|
||||||
|
int32_t satUpperX = iSrcX + border;
|
||||||
|
int32_t satUpperY = iSrcY + border;
|
||||||
|
int32_t satUpperZ = iSrcZ + border;
|
||||||
|
|
||||||
|
int32_t a = satVolume.getVoxelAt(satLowerX,satLowerY,satLowerZ);
|
||||||
|
int32_t b = satVolume.getVoxelAt(satUpperX,satLowerY,satLowerZ);
|
||||||
|
int32_t c = satVolume.getVoxelAt(satLowerX,satUpperY,satLowerZ);
|
||||||
|
int32_t d = satVolume.getVoxelAt(satUpperX,satUpperY,satLowerZ);
|
||||||
|
int32_t e = satVolume.getVoxelAt(satLowerX,satLowerY,satUpperZ);
|
||||||
|
int32_t f = satVolume.getVoxelAt(satUpperX,satLowerY,satUpperZ);
|
||||||
|
int32_t g = satVolume.getVoxelAt(satLowerX,satUpperY,satUpperZ);
|
||||||
|
int32_t h = satVolume.getVoxelAt(satUpperX,satUpperY,satUpperZ);
|
||||||
|
|
||||||
|
int32_t sum = h+c-d-g-f-a+b+e;
|
||||||
|
|
||||||
|
int32_t sideLength = border * 2 + 1;
|
||||||
|
|
||||||
|
int32_t average = sum / (sideLength*sideLength*sideLength);
|
||||||
|
|
||||||
|
VoxelType voxel = m_pVolSrc->getVoxelAt(iDstX, iDstY, iDstZ);
|
||||||
|
|
||||||
|
voxel.setDensity(average);
|
||||||
|
|
||||||
|
m_pVolDst->setVoxelAt(iDstX, iDstY, iDstZ, voxel);
|
||||||
|
|
||||||
|
|
||||||
|
//float maxSolid = border * 2/* + 1*/;
|
||||||
|
/*maxSolid = maxSolid * maxSolid * maxSolid;
|
||||||
|
|
||||||
|
float percentSolid = noSolid / maxSolid;
|
||||||
|
float percentEmpty = 1.0f - percentSolid;
|
||||||
|
|
||||||
|
(*mAmbientOcclusionVolume)[ambVolZ][ambVolY][ambVolX] = 255 * percentEmpty;*/
|
||||||
|
|
||||||
|
//(*mAmbientOcclusionVolume)[ambVolZ][ambVolY][ambVolX] = 255 - ((h+c-d-g-f-a+b+e) * 19); //FIXME - should not be 9
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,8 @@ namespace PolyVox
|
|||||||
)
|
)
|
||||||
:Volume<VoxelType>(regValid)
|
:Volume<VoxelType>(regValid)
|
||||||
{
|
{
|
||||||
|
setBorderValue(VoxelType());
|
||||||
|
|
||||||
//Create a volume of the right size.
|
//Create a volume of the right size.
|
||||||
resize(regValid);
|
resize(regValid);
|
||||||
}
|
}
|
||||||
@ -85,11 +87,16 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
|
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
|
||||||
{
|
{
|
||||||
|
const Vector3DInt32& v3dLowerCorner = m_regValidRegion.getLowerCorner();
|
||||||
|
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
|
||||||
|
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
|
||||||
|
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
|
||||||
|
|
||||||
return m_pData
|
return m_pData
|
||||||
[
|
[
|
||||||
uXPos +
|
iLocalXPos +
|
||||||
uYPos * this->getWidth() +
|
iLocalYPos * this->getWidth() +
|
||||||
uZPos * this->getWidth() * this->getHeight()
|
iLocalZPos * this->getWidth() * this->getHeight()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -127,17 +134,27 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
bool RawVolume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
|
bool RawVolume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
|
||||||
{
|
{
|
||||||
assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
|
if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
|
||||||
|
{
|
||||||
|
const Vector3DInt32& v3dLowerCorner = m_regValidRegion.getLowerCorner();
|
||||||
|
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
|
||||||
|
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
|
||||||
|
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
|
||||||
|
|
||||||
m_pData
|
m_pData
|
||||||
[
|
[
|
||||||
uXPos +
|
iLocalXPos +
|
||||||
uYPos * this->getWidth() +
|
iLocalYPos * this->getWidth() +
|
||||||
uZPos * this->getWidth() * this->getHeight()
|
iLocalZPos * this->getWidth() * this->getHeight()
|
||||||
] = tValue;
|
] = tValue;
|
||||||
|
|
||||||
//Return true to indicate that we modified a voxel.
|
//Return true to indicate that we modified a voxel.
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -79,13 +79,26 @@ namespace PolyVox
|
|||||||
this->mYPosInVolume = yPos;
|
this->mYPosInVolume = yPos;
|
||||||
this->mZPosInVolume = zPos;
|
this->mZPosInVolume = zPos;
|
||||||
|
|
||||||
const uint32_t uVoxelIndex = xPos +
|
if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos)))
|
||||||
yPos * this->mVolume->getWidth() +
|
{
|
||||||
zPos * this->mVolume->getWidth() * this->mVolume->getHeight();
|
const Vector3DInt32& v3dLowerCorner = this->mVolume->m_regValidRegion.getLowerCorner();
|
||||||
|
int32_t iLocalXPos = xPos - v3dLowerCorner.getX();
|
||||||
|
int32_t iLocalYPos = yPos - v3dLowerCorner.getY();
|
||||||
|
int32_t iLocalZPos = zPos - v3dLowerCorner.getZ();
|
||||||
|
|
||||||
mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex;
|
const uint32_t uVoxelIndex = iLocalXPos +
|
||||||
|
iLocalYPos * this->mVolume->getWidth() +
|
||||||
|
iLocalZPos * this->mVolume->getWidth() * this->mVolume->getHeight();
|
||||||
|
|
||||||
m_bIsCurrentPositionValid = this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos));
|
mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex;
|
||||||
|
|
||||||
|
m_bIsCurrentPositionValid = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mCurrentVoxel = 0;
|
||||||
|
m_bIsCurrentPositionValid = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
|
@ -140,7 +140,7 @@ namespace PolyVox
|
|||||||
/// Calculates approximatly how many bytes of memory the volume is currently using.
|
/// Calculates approximatly how many bytes of memory the volume is currently using.
|
||||||
uint32_t calculateSizeInBytes(void);
|
uint32_t calculateSizeInBytes(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//The size of the volume
|
//The size of the volume
|
||||||
Region m_regValidRegion;
|
Region m_regValidRegion;
|
||||||
|
|
||||||
|
@ -197,7 +197,6 @@ namespace PolyVox
|
|||||||
uint32_t Volume<VoxelType>::calculateSizeInBytes(void)
|
uint32_t Volume<VoxelType>::calculateSizeInBytes(void)
|
||||||
{
|
{
|
||||||
return getWidth() * getHeight() * getDepth() * sizeof(VoxelType);
|
return getWidth() * getHeight() * getDepth() * sizeof(VoxelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,10 @@ ADD_TEST(ArrayReadWriteTest ${LATEST_TEST} testReadWrite)
|
|||||||
CREATE_TEST(TestAStarPathfinder.h TestAStarPathfinder.cpp TestAStarPathfinder)
|
CREATE_TEST(TestAStarPathfinder.h TestAStarPathfinder.cpp TestAStarPathfinder)
|
||||||
ADD_TEST(AStarPathfinderExecuteTest ${LATEST_TEST} testExecute)
|
ADD_TEST(AStarPathfinderExecuteTest ${LATEST_TEST} testExecute)
|
||||||
|
|
||||||
|
# Low pass filter tests
|
||||||
|
CREATE_TEST(TestLowPassFilter.h TestLowPassFilter.cpp TestLowPassFilter)
|
||||||
|
ADD_TEST(LowPassFilterExecuteTest ${LATEST_TEST} testExecute)
|
||||||
|
|
||||||
# LargeVolume tests
|
# LargeVolume tests
|
||||||
CREATE_TEST(testvolume.h testvolume.cpp testvolume)
|
CREATE_TEST(testvolume.h testvolume.cpp testvolume)
|
||||||
ADD_TEST(VolumeSizeTest ${LATEST_TEST} testSize)
|
ADD_TEST(VolumeSizeTest ${LATEST_TEST} testSize)
|
||||||
|
66
tests/TestLowPassFilter.cpp
Normal file
66
tests/TestLowPassFilter.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
Copyright (c) 2010 Matt Williams
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "TestLowPassFilter.h"
|
||||||
|
|
||||||
|
#include "PolyVoxCore/Density.h"
|
||||||
|
#include "PolyVoxCore/LowPassFilter.h"
|
||||||
|
#include "PolyVoxCore/RawVolume.h"
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
using namespace PolyVox;
|
||||||
|
|
||||||
|
void TestLowPassFilter::testExecute()
|
||||||
|
{
|
||||||
|
const int32_t g_uVolumeSideLength = 16;
|
||||||
|
|
||||||
|
Region reg(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1));
|
||||||
|
|
||||||
|
//Create empty volume
|
||||||
|
RawVolume<Density8> volData(reg);
|
||||||
|
|
||||||
|
//Create two solid walls at opposite sides of the volume
|
||||||
|
for (int32_t z = 0; z < g_uVolumeSideLength; z++)
|
||||||
|
{
|
||||||
|
for (int32_t y = 0; y < g_uVolumeSideLength; y++)
|
||||||
|
{
|
||||||
|
for (int32_t x = 0; x < g_uVolumeSideLength; x++)
|
||||||
|
{
|
||||||
|
if(x % 2 == 0)
|
||||||
|
{
|
||||||
|
Density8 voxel(32);
|
||||||
|
volData.setVoxelAt(x, y, z, voxel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RawVolume<Density8> resultVolume(reg);
|
||||||
|
|
||||||
|
LowPassFilter<RawVolume, RawVolume, Density8> pass1(&volData, reg, &resultVolume, reg, 5);
|
||||||
|
|
||||||
|
pass1.executeSAT();
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(TestLowPassFilter)
|
@ -1,38 +1,37 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
Copyright (c) 2005-2009 David Williams
|
Copyright (c) 2010 Matt Williams
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
arising from the use of this software.
|
arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it
|
including commercial applications, and to alter it and redistribute it
|
||||||
freely, subject to the following restrictions:
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
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
|
claim that you wrote the original software. If you use this software
|
||||||
in a product, an acknowledgment in the product documentation would be
|
in a product, an acknowledgment in the product documentation would be
|
||||||
appreciated but is not required.
|
appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
misrepresented as being the original software.
|
misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#ifndef __PolyVox_Filters_H__
|
#ifndef __PolyVox_TestLowPassFilter_H__
|
||||||
#define __PolyVox_Filters_H__
|
#define __PolyVox_TestLowPassFilter_H__
|
||||||
|
|
||||||
#include "PolyVoxCore/Array.h"
|
#include <QObject>
|
||||||
#include "PolyVoxCore/Region.h"
|
|
||||||
|
class TestLowPassFilter: public QObject
|
||||||
namespace PolyVox
|
{
|
||||||
{
|
Q_OBJECT
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
|
||||||
void smoothRegion(VolumeType<VoxelType>& volData, const Region& regionToSmooth);
|
private slots:
|
||||||
}//namespace PolyVox
|
void testExecute();
|
||||||
|
};
|
||||||
#include "PolyVoxCore/Filters.inl"
|
|
||||||
|
#endif
|
||||||
#endif
|
|
Reference in New Issue
Block a user