Removed template template parameters from SurfaceExtractor.

This commit is contained in:
unknown 2012-05-18 15:38:18 +02:00
parent fec1191a73
commit 29d816d416
8 changed files with 39 additions and 39 deletions

View File

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

View File

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

View File

@ -98,13 +98,13 @@ int main(int argc, char *argv[])
//Extract the surface //Extract the surface
SurfaceMesh<PositionMaterialNormal> meshLowLOD; SurfaceMesh<PositionMaterialNormal> meshLowLOD;
SurfaceExtractor<RawVolume, uint8_t > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD); SurfaceExtractor< RawVolume<uint8_t> > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD);
surfaceExtractor.execute(); surfaceExtractor.execute();
meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f); meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f);
//Extract the surface //Extract the surface
SurfaceMesh<PositionMaterialNormal> meshHighLOD; SurfaceMesh<PositionMaterialNormal> meshHighLOD;
SurfaceExtractor<SimpleVolume, uint8_t > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(30,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD); SurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(30,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD);
surfaceExtractorHigh.execute(); surfaceExtractorHigh.execute();
meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0)); meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0));

View File

@ -63,7 +63,7 @@ namespace PolyVox
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// CubicSurfaceExtractor // CubicSurfaceExtractor
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType> class CubicSurfaceExtractor; template< typename VolumeType> class CubicSurfaceExtractor;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Density // Density
@ -129,7 +129,7 @@ namespace PolyVox
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// SurfaceExtractor // SurfaceExtractor
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template< template<typename> class VolumeType, typename VoxelType> class SurfaceExtractor; template<typename VolumeType> class SurfaceExtractor;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// SurfaceMesh // SurfaceMesh

View File

@ -48,11 +48,11 @@ namespace PolyVox
return 1; return 1;
} }
template< template<typename> class VolumeType, typename VoxelType> template< typename VolumeType>
class SurfaceExtractor class SurfaceExtractor
{ {
public: public:
SurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, typename VoxelTypeTraits<VoxelType>::DensityType tThreshold = (VoxelTypeTraits<VoxelType>::minDensity() + VoxelTypeTraits<VoxelType>::maxDensity()) / 2); SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, typename VoxelTypeTraits<typename VolumeType::VoxelType>::DensityType tThreshold = (VoxelTypeTraits<typename VolumeType::VoxelType>::minDensity() + VoxelTypeTraits<typename VolumeType::VoxelType>::maxDensity()) / 2);
void execute(); void execute();
@ -75,7 +75,7 @@ namespace PolyVox
// NOTE: These two functions are in the .h file rather than the .inl due to an apparent bug in VC2010. // 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. //See http://stackoverflow.com/questions/1484885/strange-vc-compile-error-c2244 for details.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType<VoxelType>::Sampler& volIter) Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter)
{ {
//FIXME - Should actually use DensityType here, both in principle and because the maths may be //FIXME - Should actually use DensityType here, both in principle and because the maths may be
//faster (and to reduce casts). So it would be good to add a way to get DensityType from a voxel. //faster (and to reduce casts). So it would be good to add a way to get DensityType from a voxel.
@ -97,7 +97,7 @@ namespace PolyVox
); );
} }
Vector3DFloat computeSobelGradient(const typename VolumeType<VoxelType>::Sampler& volIter) Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter)
{ {
static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, { 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} } }; {3,6,3}, {6,0,6}, {3,6,3} }, { {2,3,2}, {3,6,3}, {2,3,2} } };
@ -194,8 +194,8 @@ namespace PolyVox
const Array2DInt32& m_pCurrentVertexIndicesY); const Array2DInt32& m_pCurrentVertexIndicesY);
//The volume data and a sampler to access it. //The volume data and a sampler to access it.
VolumeType<VoxelType>* m_volData; VolumeType* m_volData;
typename VolumeType<VoxelType>::Sampler m_sampVolume; typename VolumeType::Sampler m_sampVolume;
//Holds a position in volume space. //Holds a position in volume space.
int32_t iXVolSpace; int32_t iXVolSpace;
@ -223,7 +223,7 @@ namespace PolyVox
Region m_regSliceCurrent; Region m_regSliceCurrent;
//Our threshold value //Our threshold value
typename VoxelTypeTraits<VoxelType>::DensityType m_tThreshold; typename VoxelTypeTraits<typename VolumeType::VoxelType>::DensityType m_tThreshold;
}; };
} }

View File

@ -23,8 +23,8 @@ freely, subject to the following restrictions:
namespace PolyVox namespace PolyVox
{ {
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
SurfaceExtractor<VolumeType, VoxelType>::SurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, typename VoxelTypeTraits<VoxelType>::DensityType tThreshold) SurfaceExtractor<VolumeType>::SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, typename VoxelTypeTraits<typename VolumeType::VoxelType>::DensityType tThreshold)
:m_volData(volData) :m_volData(volData)
,m_sampVolume(volData) ,m_sampVolume(volData)
,m_meshCurrent(result) ,m_meshCurrent(result)
@ -36,8 +36,8 @@ namespace PolyVox
m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1)); m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1));
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
void SurfaceExtractor<VolumeType, VoxelType>::execute() void SurfaceExtractor<VolumeType>::execute()
{ {
m_meshCurrent->clear(); m_meshCurrent->clear();
@ -125,9 +125,9 @@ namespace PolyVox
m_meshCurrent->m_vecLodRecords.push_back(lodRecord); m_meshCurrent->m_vecLodRecords.push_back(lodRecord);
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
template<bool isPrevZAvail> template<bool isPrevZAvail>
uint32_t SurfaceExtractor<VolumeType, VoxelType>::computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) uint32_t SurfaceExtractor<VolumeType>::computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask)
{ {
m_uNoOfOccupiedCells = 0; m_uNoOfOccupiedCells = 0;
@ -191,20 +191,20 @@ namespace PolyVox
return m_uNoOfOccupiedCells; return m_uNoOfOccupiedCells;
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
template<bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail> template<bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail>
void SurfaceExtractor<VolumeType, VoxelType>::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) void SurfaceExtractor<VolumeType>::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask)
{ {
uint8_t iCubeIndex = 0; uint8_t iCubeIndex = 0;
VoxelType v000; VolumeType::VoxelType v000;
VoxelType v100; VolumeType::VoxelType v100;
VoxelType v010; VolumeType::VoxelType v010;
VoxelType v110; VolumeType::VoxelType v110;
VoxelType v001; VolumeType::VoxelType v001;
VoxelType v101; VolumeType::VoxelType v101;
VoxelType v011; VolumeType::VoxelType v011;
VoxelType v111; VolumeType::VoxelType v111;
if(isPrevZAvail) if(isPrevZAvail)
{ {
@ -391,8 +391,8 @@ namespace PolyVox
} }
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
void SurfaceExtractor<VolumeType, VoxelType>::generateVerticesForSlice(const Array2DUint8& pCurrentBitmask, void SurfaceExtractor<VolumeType>::generateVerticesForSlice(const Array2DUint8& pCurrentBitmask,
Array2DInt32& m_pCurrentVertexIndicesX, Array2DInt32& m_pCurrentVertexIndicesX,
Array2DInt32& m_pCurrentVertexIndicesY, Array2DInt32& m_pCurrentVertexIndicesY,
Array2DInt32& m_pCurrentVertexIndicesZ) Array2DInt32& m_pCurrentVertexIndicesZ)
@ -423,14 +423,14 @@ namespace PolyVox
m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace); m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace);
const VoxelType v000 = m_sampVolume.getVoxel(); const VolumeType::VoxelType v000 = m_sampVolume.getVoxel();
const Vector3DFloat n000 = computeCentralDifferenceGradient(m_sampVolume); const Vector3DFloat n000 = computeCentralDifferenceGradient(m_sampVolume);
/* Find the vertices where the surface intersects the cube */ /* Find the vertices where the surface intersects the cube */
if (edgeTable[iCubeIndex] & 1) if (edgeTable[iCubeIndex] & 1)
{ {
m_sampVolume.movePositiveX(); m_sampVolume.movePositiveX();
const VoxelType v100 = m_sampVolume.getVoxel(); const VolumeType::VoxelType v100 = m_sampVolume.getVoxel();
const Vector3DFloat n100 = computeCentralDifferenceGradient(m_sampVolume); const Vector3DFloat n100 = computeCentralDifferenceGradient(m_sampVolume);
float fInterp = static_cast<float>(m_tThreshold - convertToDensity(v000)) / static_cast<float>(convertToDensity(v100) - convertToDensity(v000)); float fInterp = static_cast<float>(m_tThreshold - convertToDensity(v000)) / static_cast<float>(convertToDensity(v100) - convertToDensity(v000));
@ -456,7 +456,7 @@ namespace PolyVox
if (edgeTable[iCubeIndex] & 8) if (edgeTable[iCubeIndex] & 8)
{ {
m_sampVolume.movePositiveY(); m_sampVolume.movePositiveY();
const VoxelType v010 = m_sampVolume.getVoxel(); const VolumeType::VoxelType v010 = m_sampVolume.getVoxel();
const Vector3DFloat n010 = computeCentralDifferenceGradient(m_sampVolume); const Vector3DFloat n010 = computeCentralDifferenceGradient(m_sampVolume);
float fInterp = static_cast<float>(m_tThreshold - convertToDensity(v000)) / static_cast<float>(convertToDensity(v010) - convertToDensity(v000)); float fInterp = static_cast<float>(m_tThreshold - convertToDensity(v000)) / static_cast<float>(convertToDensity(v010) - convertToDensity(v000));
@ -482,7 +482,7 @@ namespace PolyVox
if (edgeTable[iCubeIndex] & 256) if (edgeTable[iCubeIndex] & 256)
{ {
m_sampVolume.movePositiveZ(); m_sampVolume.movePositiveZ();
const VoxelType v001 = m_sampVolume.getVoxel(); const VolumeType::VoxelType v001 = m_sampVolume.getVoxel();
const Vector3DFloat n001 = computeCentralDifferenceGradient(m_sampVolume); const Vector3DFloat n001 = computeCentralDifferenceGradient(m_sampVolume);
float fInterp = static_cast<float>(m_tThreshold - convertToDensity(v000)) / static_cast<float>(convertToDensity(v001) - convertToDensity(v000)); float fInterp = static_cast<float>(m_tThreshold - convertToDensity(v000)) / static_cast<float>(convertToDensity(v001) - convertToDensity(v000));
@ -509,8 +509,8 @@ namespace PolyVox
} }
} }
template< template<typename> class VolumeType, typename VoxelType> template<typename VolumeType>
void SurfaceExtractor<VolumeType, VoxelType>::generateIndicesForSlice(const Array2DUint8& pPreviousBitmask, void SurfaceExtractor<VolumeType>::generateIndicesForSlice(const Array2DUint8& pPreviousBitmask,
const Array2DInt32& m_pPreviousVertexIndicesX, const Array2DInt32& m_pPreviousVertexIndicesX,
const Array2DInt32& m_pPreviousVertexIndicesY, const Array2DInt32& m_pPreviousVertexIndicesY,
const Array2DInt32& m_pPreviousVertexIndicesZ, const Array2DInt32& m_pPreviousVertexIndicesZ,

View File

@ -37,7 +37,7 @@ namespace PolyVox
void extractSmoothMesh(Volume& volume, const Region& region, Mesh& resultMesh) void extractSmoothMesh(Volume& volume, const Region& region, Mesh& resultMesh)
{ {
SurfaceExtractor<SimpleVolume, MaterialDensityPair88 > surfaceExtractor(&volume, region, &resultMesh); SurfaceExtractor< SimpleVolume<MaterialDensityPair88> > surfaceExtractor(&volume, region, &resultMesh);
surfaceExtractor.execute(); surfaceExtractor.execute();
} }
} }

View File

@ -92,7 +92,7 @@ void testForType(SurfaceMesh<PositionMaterialNormal>& result)
} }
} }
SurfaceExtractor<SimpleVolume, VoxelType > extractor(&volData, volData.getEnclosingRegion(), &result, 50); SurfaceExtractor< SimpleVolume<VoxelType> > extractor(&volData, volData.getEnclosingRegion(), &result, 50);
extractor.execute(); extractor.execute();
} }