Modified SurfaceExtractor to use template template parameters.

This commit is contained in:
David Williams 2011-04-30 23:51:04 +01:00
parent 36a9be83db
commit 3a171e698b
15 changed files with 174 additions and 168 deletions

View File

@ -91,4 +91,4 @@ int main(int argc, char *argv[])
//Run the message pump.
return app.exec();
}
}

View File

@ -89,7 +89,7 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume<MaterialDensityPair44>* volDat
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
polyvox_shared_ptr< SurfaceMesh<PositionMaterialNormal> > mesh(new SurfaceMesh<PositionMaterialNormal>);
SurfaceExtractor<MaterialDensityPair44> surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
SurfaceExtractor<LargeVolume, MaterialDensityPair44> surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
surfaceExtractor.execute();
polyvox_shared_ptr< SurfaceMesh<PositionMaterialNormal> > decimatedMesh(new SurfaceMesh<PositionMaterialNormal>);

View File

@ -101,8 +101,8 @@ int main(int argc, char *argv[])
createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity());
//Smooth part of the volume
smoothRegion<MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127)));
smoothRegion<MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127)));
smoothRegion<LargeVolume, MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127)));
smoothRegion<LargeVolume, MaterialDensityPair44>(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127)));
QApplication app(argc, argv);

View File

@ -287,7 +287,7 @@ int main(int argc, char *argv[])
//Extract the surface
SurfaceMesh<PositionMaterialNormal> mesh;
//CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
SurfaceExtractor<MaterialDensityPair44> surfaceExtractor(&volData, reg, &mesh);
SurfaceExtractor<LargeVolume, MaterialDensityPair44> surfaceExtractor(&volData, reg, &mesh);
//CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, reg, &mesh);
surfaceExtractor.execute();
std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl;

View File

@ -26,12 +26,11 @@ freely, subject to the following restrictions:
#include "Array.h"
#include "Region.h"
#include "LargeVolume.h"
namespace PolyVox
{
template <typename VoxelType>
void smoothRegion(LargeVolume<VoxelType>& volData, const Region& regionToSmooth);
template< template<typename> class VolumeType, typename VoxelType>
void smoothRegion(VolumeType<VoxelType>& volData, const Region& regionToSmooth);
}//namespace PolyVox
#include "Filters.inl"

View File

@ -2,8 +2,8 @@
namespace PolyVox
{
template <typename VoxelType>
void smoothRegion(LargeVolume<VoxelType>& volData, const Region& regionToSmooth)
template< template<typename> class VolumeType, typename VoxelType>
void smoothRegion(VolumeType<VoxelType>& volData, const Region& regionToSmooth)
{
Region croppedRegion = regionToSmooth;

View File

@ -26,10 +26,10 @@ freely, subject to the following restrictions:
#ifndef __PolyVox_GradientEstimators_H__
#define __PolyVox_GradientEstimators_H__
#include "LargeVolume.h"
#include <vector>
#include "Vector.h"
namespace PolyVox
{
enum NormalGenerationMethod
@ -41,22 +41,23 @@ namespace PolyVox
SOBEL_SMOOTHED ///<Smoothest
};
template <typename VoxelType>
Vector3DFloat computeCentralDifferenceGradient(const typename LargeVolume<VoxelType>::Sampler& volIter);
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType<VoxelType>::Sampler& volIter);
template <typename VoxelType>
Vector3DFloat computeSmoothCentralDifferenceGradient(typename LargeVolume<VoxelType>::Sampler& volIter);
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeSmoothCentralDifferenceGradient(typename VolumeType<VoxelType>::Sampler& volIter);
template <typename VoxelType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(typename LargeVolume<VoxelType>::Sampler& volIter);
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(typename VolumeType<VoxelType>::Sampler& volIter);
template <typename VoxelType>
Vector3DFloat computeSobelGradient(const typename LargeVolume<VoxelType>::Sampler& volIter);
template <typename VoxelType>
Vector3DFloat computeSmoothSobelGradient(typename LargeVolume<VoxelType>::Sampler& volIter);
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeSobelGradient(const typename VolumeType<VoxelType>::Sampler& volIter);
POLYVOX_API void computeNormalsForVertices(LargeVolume<uint8_t>* volumeData, SurfaceMesh<PositionMaterialNormal>& mesh, NormalGenerationMethod normalGenerationMethod);
POLYVOX_API Vector3DFloat computeNormal(LargeVolume<uint8_t>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod);
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeSmoothSobelGradient(typename VolumeType<VoxelType>::Sampler& volIter);
//POLYVOX_API void computeNormalsForVertices(VolumeType<uint8_t>* volumeData, SurfaceMesh<PositionMaterialNormal>& mesh, NormalGenerationMethod normalGenerationMethod);
//POLYVOX_API Vector3DFloat computeNormal(VolumeType<uint8_t>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod);
}
#include "GradientEstimators.inl"

View File

@ -27,8 +27,8 @@ freely, subject to the following restrictions:
namespace PolyVox
{
template <typename VoxelType>
Vector3DFloat computeCentralDifferenceGradient(const typename LargeVolume<VoxelType>::Sampler& volIter)
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType<VoxelType>::Sampler& volIter)
{
//FIXME - bitwise way of doing this?
VoxelType voxel1nx = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
@ -48,8 +48,8 @@ namespace PolyVox
);
}
template <typename VoxelType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(const typename LargeVolume<VoxelType>::Sampler& volIter)
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(const typename VolumeType<VoxelType>::Sampler& volIter)
{
const int32_t x = volIter.getPosX();
const int32_t y = volIter.getPosY();
@ -73,8 +73,8 @@ namespace PolyVox
);
}
template <typename VoxelType>
Vector3DFloat computeSmoothCentralDifferenceGradient(typename LargeVolume<VoxelType>::Sampler& volIter)
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeSmoothCentralDifferenceGradient(typename VolumeType<VoxelType>::Sampler& volIter)
{
int32_t initialX = volIter.getPosX();
int32_t initialY = volIter.getPosY();
@ -104,8 +104,8 @@ namespace PolyVox
);
}
template <typename VoxelType>
Vector3DFloat computeSobelGradient(const typename LargeVolume<VoxelType>::Sampler& volIter)
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeSobelGradient(const typename VolumeType<VoxelType>::Sampler& 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} } };
@ -187,8 +187,8 @@ namespace PolyVox
return Vector3DFloat(static_cast<float>(-xGrad),static_cast<float>(-yGrad),static_cast<float>(-zGrad));
}
template <typename VoxelType>
Vector3DFloat computeSmoothSobelGradient(typename LargeVolume<VoxelType>::Sampler& volIter)
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeSmoothSobelGradient(typename VolumeType<VoxelType>::Sampler& 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} } };

View File

@ -84,8 +84,8 @@ namespace PolyVox
class Region;
class PositionMaterial;
class PositionMaterialNormal;
template <typename VoxelType> class CubicSurfaceExtractor;
template <typename VoxelType> class SurfaceExtractor;
template< template<typename> class VolumeType, typename VoxelType> class CubicSurfaceExtractor;
template< template<typename> class VolumeType, typename VoxelType> class SurfaceExtractor;
//---------- Vector ----------
template <uint32_t Size, typename Type> class Vector;

View File

@ -155,7 +155,7 @@ namespace PolyVox
if(mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock)))
{
Block<VoxelType>* pUncompressedCurrentBlock = mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock);
Block* pUncompressedCurrentBlock = mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock);
mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock;
}

View File

@ -31,11 +31,11 @@ freely, subject to the following restrictions:
namespace PolyVox
{
template <typename VoxelType>
template< template<typename> class VolumeType, typename VoxelType>
class SurfaceExtractor
{
public:
SurfaceExtractor(LargeVolume<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result);
SurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result);
void execute();
@ -54,8 +54,115 @@ namespace PolyVox
Array2DInt32& m_pCurrentVertexIndicesY,
Array2DInt32& m_pCurrentVertexIndicesZ);
Vector3DFloat computeCentralDifferenceGradient(const typename LargeVolume<VoxelType>::Sampler& volIter);
Vector3DFloat computeSobelGradient(const typename LargeVolume<VoxelType>::Sampler& volIter);
////////////////////////////////////////////////////////////////////////////////
// NOTE: These two functions are in the .h file rather than the .inl due to an apparent bug in VC2010.
//See http://stackoverflow.com/questions/1484885/strange-vc-compile-error-c2244 for details.
////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType<VoxelType>::Sampler& volIter)
{
uint8_t voxel1nx = volIter.peekVoxel1nx0py0pz().getDensity();
uint8_t voxel1px = volIter.peekVoxel1px0py0pz().getDensity();
uint8_t voxel1ny = volIter.peekVoxel0px1ny0pz().getDensity();
uint8_t voxel1py = volIter.peekVoxel0px1py0pz().getDensity();
uint8_t voxel1nz = volIter.peekVoxel0px0py1nz().getDensity();
uint8_t voxel1pz = volIter.peekVoxel0px0py1pz().getDensity();
return Vector3DFloat
(
static_cast<float>(voxel1nx) - static_cast<float>(voxel1px),
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
);
}
template< template<typename> class VolumeType, typename VoxelType>
Vector3DFloat computeSobelGradient(const typename VolumeType<VoxelType>::Sampler& 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 uint8_t pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz().getDensity();
const uint8_t pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz().getDensity();
const uint8_t pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz().getDensity();
const uint8_t pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz().getDensity();
const uint8_t pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz().getDensity();
const uint8_t pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz().getDensity();
const uint8_t pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz().getDensity();
const uint8_t pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz().getDensity();
const uint8_t pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz().getDensity();
const uint8_t pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz().getDensity();
const uint8_t pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz().getDensity();
const uint8_t pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz().getDensity();
const uint8_t pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz().getDensity();
//const uint8_t pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz().getDensity();
const uint8_t pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz().getDensity();
const uint8_t pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz().getDensity();
const uint8_t pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz().getDensity();
const uint8_t pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz().getDensity();
const uint8_t pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz().getDensity();
const uint8_t pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz().getDensity();
const uint8_t pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz().getDensity();
const uint8_t pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz().getDensity();
const uint8_t pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz().getDensity();
const uint8_t pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz().getDensity();
const uint8_t pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz().getDensity();
const uint8_t pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz().getDensity();
const uint8_t pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz().getDensity();
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);
//Note: The above actually give gradients going from low density to high density.
//For our normals we want the the other way around, so we switch the components as we return them.
return Vector3DFloat(static_cast<float>(-xGrad),static_cast<float>(-yGrad),static_cast<float>(-zGrad));
}
////////////////////////////////////////////////////////////////////////////////
// End of compiler bug workaroumd.
////////////////////////////////////////////////////////////////////////////////
//Use the cell bitmasks to generate all the indices needed for that slice
void generateIndicesForSlice(const Array2DUint8& pPreviousBitmask,
@ -67,8 +174,8 @@ namespace PolyVox
const Array2DInt32& m_pCurrentVertexIndicesZ);
//The volume data and a sampler to access it.
LargeVolume<VoxelType>* m_volData;
typename LargeVolume<VoxelType>::Sampler m_sampVolume;
VolumeType<VoxelType>* m_volData;
typename VolumeType<VoxelType>::Sampler m_sampVolume;
//Holds a position in volume space.
int32_t iXVolSpace;

View File

@ -29,8 +29,8 @@ freely, subject to the following restrictions:
namespace PolyVox
{
template <typename VoxelType>
SurfaceExtractor<VoxelType>::SurfaceExtractor(LargeVolume<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result)
template< template<typename> class VolumeType, typename VoxelType>
SurfaceExtractor<VolumeType, VoxelType>::SurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result)
:m_volData(volData)
,m_sampVolume(volData)
,m_regSizeInVoxels(region)
@ -43,8 +43,8 @@ namespace PolyVox
m_meshCurrent->clear();
}
template <typename VoxelType>
void SurfaceExtractor<VoxelType>::execute()
template< template<typename> class VolumeType, typename VoxelType>
void SurfaceExtractor<VolumeType, VoxelType>::execute()
{
uint32_t uArrayWidth = m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 1;
uint32_t uArrayHeight = m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 1;
@ -130,9 +130,9 @@ namespace PolyVox
m_meshCurrent->m_vecLodRecords.push_back(lodRecord);
}
template<typename VoxelType>
template< template<typename> class VolumeType, typename VoxelType>
template<bool isPrevZAvail>
uint32_t SurfaceExtractor<VoxelType>::computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask)
uint32_t SurfaceExtractor<VolumeType, VoxelType>::computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask)
{
m_uNoOfOccupiedCells = 0;
@ -196,9 +196,9 @@ namespace PolyVox
return m_uNoOfOccupiedCells;
}
template<typename VoxelType>
template< template<typename> class VolumeType, typename VoxelType>
template<bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail>
void SurfaceExtractor<VoxelType>::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask)
void SurfaceExtractor<VolumeType, VoxelType>::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask)
{
uint8_t iCubeIndex = 0;
@ -396,8 +396,8 @@ namespace PolyVox
}
}
template <typename VoxelType>
void SurfaceExtractor<VoxelType>::generateVerticesForSlice(const Array2DUint8& pCurrentBitmask,
template< template<typename> class VolumeType, typename VoxelType>
void SurfaceExtractor<VolumeType, VoxelType>::generateVerticesForSlice(const Array2DUint8& pCurrentBitmask,
Array2DInt32& m_pCurrentVertexIndicesX,
Array2DInt32& m_pCurrentVertexIndicesY,
Array2DInt32& m_pCurrentVertexIndicesZ)
@ -429,14 +429,14 @@ namespace PolyVox
m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace);
const VoxelType v000 = m_sampVolume.getVoxel();
const Vector3DFloat n000 = computeCentralDifferenceGradient(m_sampVolume);
const Vector3DFloat n000 = computeCentralDifferenceGradient<VolumeType, VoxelType>(m_sampVolume);
/* Find the vertices where the surface intersects the cube */
if (edgeTable[iCubeIndex] & 1)
{
m_sampVolume.movePositiveX();
const VoxelType v100 = m_sampVolume.getVoxel();
const Vector3DFloat n100 = computeCentralDifferenceGradient(m_sampVolume);
const Vector3DFloat n100 = computeCentralDifferenceGradient<VolumeType, VoxelType>(m_sampVolume);
//float fInterp = static_cast<float>(v100.getDensity() - VoxelType::getMinDensity()) / static_cast<float>(VoxelType::getMaxDensity() - VoxelType::getMinDensity());
float fInterp = static_cast<float>(VoxelType::getThreshold() - v000.getDensity()) / static_cast<float>(v100.getDensity() - v000.getDensity());
@ -460,7 +460,7 @@ namespace PolyVox
{
m_sampVolume.movePositiveY();
const VoxelType v010 = m_sampVolume.getVoxel();
const Vector3DFloat n010 = computeCentralDifferenceGradient(m_sampVolume);
const Vector3DFloat n010 = computeCentralDifferenceGradient<VolumeType, VoxelType>(m_sampVolume);
float fInterp = static_cast<float>(VoxelType::getThreshold() - v000.getDensity()) / static_cast<float>(v010.getDensity() - v000.getDensity());
//fInterp = 0.5f;
@ -483,7 +483,7 @@ namespace PolyVox
{
m_sampVolume.movePositiveZ();
const VoxelType v001 = m_sampVolume.getVoxel();
const Vector3DFloat n001 = computeCentralDifferenceGradient(m_sampVolume);
const Vector3DFloat n001 = computeCentralDifferenceGradient<VolumeType, VoxelType>(m_sampVolume);
float fInterp = static_cast<float>(VoxelType::getThreshold() - v000.getDensity()) / static_cast<float>(v001.getDensity() - v000.getDensity());
//fInterp = 0.5f;
@ -506,111 +506,8 @@ namespace PolyVox
}
}
template <typename VoxelType>
Vector3DFloat SurfaceExtractor<VoxelType>::computeCentralDifferenceGradient(const typename LargeVolume<VoxelType>::Sampler& volIter)
{
uint8_t voxel1nx = volIter.peekVoxel1nx0py0pz().getDensity();
uint8_t voxel1px = volIter.peekVoxel1px0py0pz().getDensity();
uint8_t voxel1ny = volIter.peekVoxel0px1ny0pz().getDensity();
uint8_t voxel1py = volIter.peekVoxel0px1py0pz().getDensity();
uint8_t voxel1nz = volIter.peekVoxel0px0py1nz().getDensity();
uint8_t voxel1pz = volIter.peekVoxel0px0py1pz().getDensity();
return Vector3DFloat
(
static_cast<float>(voxel1nx) - static_cast<float>(voxel1px),
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
);
}
template <typename VoxelType>
Vector3DFloat SurfaceExtractor<VoxelType>::computeSobelGradient(const typename LargeVolume<VoxelType>::Sampler& 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 uint8_t pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz().getDensity();
const uint8_t pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz().getDensity();
const uint8_t pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz().getDensity();
const uint8_t pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz().getDensity();
const uint8_t pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz().getDensity();
const uint8_t pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz().getDensity();
const uint8_t pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz().getDensity();
const uint8_t pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz().getDensity();
const uint8_t pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz().getDensity();
const uint8_t pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz().getDensity();
const uint8_t pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz().getDensity();
const uint8_t pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz().getDensity();
const uint8_t pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz().getDensity();
//const uint8_t pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz().getDensity();
const uint8_t pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz().getDensity();
const uint8_t pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz().getDensity();
const uint8_t pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz().getDensity();
const uint8_t pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz().getDensity();
const uint8_t pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz().getDensity();
const uint8_t pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz().getDensity();
const uint8_t pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz().getDensity();
const uint8_t pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz().getDensity();
const uint8_t pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz().getDensity();
const uint8_t pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz().getDensity();
const uint8_t pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz().getDensity();
const uint8_t pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz().getDensity();
const uint8_t pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz().getDensity();
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);
//Note: The above actually give gradients going from low density to high density.
//For our normals we want the the other way around, so we switch the components as we return them.
return Vector3DFloat(static_cast<float>(-xGrad),static_cast<float>(-yGrad),static_cast<float>(-zGrad));
}
template <typename VoxelType>
void SurfaceExtractor<VoxelType>::generateIndicesForSlice(const Array2DUint8& pPreviousBitmask,
template< template<typename> class VolumeType, typename VoxelType>
void SurfaceExtractor<VolumeType, VoxelType>::generateIndicesForSlice(const Array2DUint8& pPreviousBitmask,
const Array2DInt32& m_pPreviousVertexIndicesX,
const Array2DInt32& m_pPreviousVertexIndicesY,
const Array2DInt32& m_pPreviousVertexIndicesZ,

View File

@ -31,7 +31,8 @@ freely, subject to the following restrictions:
namespace PolyVox
{
float computeSmoothedVoxel(LargeVolume<uint8_t>::Sampler& volIter);
template< template<typename> class VolumeType>
float computeSmoothedVoxel(typename VolumeType<uint8_t>::Sampler& volIter);
}
#endif

View File

@ -32,7 +32,7 @@ using namespace std;
namespace PolyVox
{
void computeNormalsForVertices(LargeVolume<uint8_t>* volumeData, SurfaceMesh<PositionMaterialNormal>& mesh, NormalGenerationMethod normalGenerationMethod)
/*void computeNormalsForVertices(LargeVolume<uint8_t>* volumeData, SurfaceMesh<PositionMaterialNormal>& mesh, NormalGenerationMethod normalGenerationMethod)
{
std::vector<PositionMaterialNormal>& vecVertices = mesh.getRawVertexData();
std::vector<PositionMaterialNormal>::iterator iterSurfaceVertex = vecVertices.begin();
@ -61,9 +61,9 @@ namespace PolyVox
} //(lowerCornerInside && upperCornerInside)
++iterSurfaceVertex;
}
}
}*/
Vector3DFloat computeNormal(LargeVolume<uint8_t>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod)
/*Vector3DFloat computeNormal(LargeVolume<uint8_t>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod)
{
Vector3DFloat v3dGradient; //To store the result
@ -147,5 +147,5 @@ namespace PolyVox
}
}
return v3dGradient;
}
}*/
}

View File

@ -25,7 +25,8 @@ freely, subject to the following restrictions:
namespace PolyVox
{
float computeSmoothedVoxel(LargeVolume<uint8_t>::Sampler& volIter)
template< template<typename> class VolumeType>
float computeSmoothedVoxel(typename VolumeType<uint8_t>::Sampler& volIter)
{
assert(volIter.getPosX() >= 1);
assert(volIter.getPosY() >= 1);