Work on VolumeResampler and smooth LOD.
This commit is contained in:
parent
ed63e9c335
commit
b7cb97513d
@ -100,13 +100,13 @@ int main(int argc, char *argv[])
|
|||||||
SurfaceMesh<PositionMaterialNormal> meshLowLOD;
|
SurfaceMesh<PositionMaterialNormal> meshLowLOD;
|
||||||
SurfaceExtractor<RawVolume, Density8 > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD);
|
SurfaceExtractor<RawVolume, Density8 > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD);
|
||||||
surfaceExtractor.execute();
|
surfaceExtractor.execute();
|
||||||
meshLowLOD.scaleVertices(2.0f);
|
meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f);
|
||||||
|
|
||||||
//Extract the surface
|
//Extract the surface
|
||||||
SurfaceMesh<PositionMaterialNormal> meshHighLOD;
|
SurfaceMesh<PositionMaterialNormal> meshHighLOD;
|
||||||
SurfaceExtractor<SimpleVolume, Density8 > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(32,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD);
|
SurfaceExtractor<SimpleVolume, Density8 > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(30,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD);
|
||||||
surfaceExtractorHigh.execute();
|
surfaceExtractorHigh.execute();
|
||||||
meshHighLOD.translateVertices(Vector3DFloat(32, 0, 0));
|
meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0));
|
||||||
|
|
||||||
//Pass the surface to the OpenGL window
|
//Pass the surface to the OpenGL window
|
||||||
openGLWidget.setSurfaceMeshToRender(meshHighLOD);
|
openGLWidget.setSurfaceMeshToRender(meshHighLOD);
|
||||||
|
@ -47,10 +47,6 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
resampleSameSize();
|
resampleSameSize();
|
||||||
}
|
}
|
||||||
else if((uSrcWidth == uDstWidth * 2) && (uSrcHeight == uDstHeight * 2) && (uSrcDepth == uDstDepth * 2))
|
|
||||||
{
|
|
||||||
resampleHalfSize();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
resampleArbitrary();
|
resampleArbitrary();
|
||||||
@ -74,14 +70,34 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::resampleHalfSize()
|
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::resampleArbitrary()
|
||||||
{
|
{
|
||||||
for(int32_t sz = m_regSrc.getLowerCorner().getZ(), dz = m_regDst.getLowerCorner().getZ(); dz <= m_regDst.getUpperCorner().getZ(); sz+=2, dz++)
|
float srcWidth = m_regSrc.getUpperCorner().getX() - m_regSrc.getLowerCorner().getX();
|
||||||
|
float srcHeight = m_regSrc.getUpperCorner().getY() - m_regSrc.getLowerCorner().getY();
|
||||||
|
float srcDepth = m_regSrc.getUpperCorner().getZ() - m_regSrc.getLowerCorner().getZ();
|
||||||
|
|
||||||
|
float dstWidth = m_regDst.getUpperCorner().getX() - m_regDst.getLowerCorner().getX();
|
||||||
|
float dstHeight = m_regDst.getUpperCorner().getY() - m_regDst.getLowerCorner().getY();
|
||||||
|
float dstDepth = m_regDst.getUpperCorner().getZ() - m_regDst.getLowerCorner().getZ();
|
||||||
|
|
||||||
|
for(int32_t dz = m_regDst.getLowerCorner().getZ(); dz <= m_regDst.getUpperCorner().getZ(); 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 dy = m_regDst.getLowerCorner().getY(); dy <= m_regDst.getUpperCorner().getY(); dy++)
|
||||||
{
|
{
|
||||||
for(int32_t sx = m_regSrc.getLowerCorner().getX(), dx = m_regDst.getLowerCorner().getX(); dx <= m_regDst.getUpperCorner().getX(); sx+=2,dx++)
|
for(int32_t dx = m_regDst.getLowerCorner().getX(); dx <= m_regDst.getUpperCorner().getX(); dx++)
|
||||||
{
|
{
|
||||||
|
float sx = (dx - m_regDst.getLowerCorner().getX()) / dstWidth;
|
||||||
|
float sy = (dy - m_regDst.getLowerCorner().getY()) / dstHeight;
|
||||||
|
float sz = (dz - m_regDst.getLowerCorner().getZ()) / dstDepth;
|
||||||
|
|
||||||
|
sx *= srcWidth;
|
||||||
|
sy *= srcHeight;
|
||||||
|
sz *= srcDepth;
|
||||||
|
|
||||||
|
sx += m_regSrc.getLowerCorner().getX();
|
||||||
|
sy += m_regSrc.getLowerCorner().getY();
|
||||||
|
sz += m_regSrc.getLowerCorner().getZ();
|
||||||
|
|
||||||
VoxelType voxel000 = m_pVolSrc->getVoxelAt(sx+0,sy+0,sz+0);
|
VoxelType voxel000 = m_pVolSrc->getVoxelAt(sx+0,sy+0,sz+0);
|
||||||
VoxelType voxel001 = m_pVolSrc->getVoxelAt(sx+0,sy+0,sz+1);
|
VoxelType voxel001 = m_pVolSrc->getVoxelAt(sx+0,sy+0,sz+1);
|
||||||
VoxelType voxel010 = m_pVolSrc->getVoxelAt(sx+0,sy+1,sz+0);
|
VoxelType voxel010 = m_pVolSrc->getVoxelAt(sx+0,sy+1,sz+0);
|
||||||
@ -91,30 +107,28 @@ namespace PolyVox
|
|||||||
VoxelType voxel110 = m_pVolSrc->getVoxelAt(sx+1,sy+1,sz+0);
|
VoxelType voxel110 = m_pVolSrc->getVoxelAt(sx+1,sy+1,sz+0);
|
||||||
VoxelType voxel111 = m_pVolSrc->getVoxelAt(sx+1,sy+1,sz+1);
|
VoxelType voxel111 = m_pVolSrc->getVoxelAt(sx+1,sy+1,sz+1);
|
||||||
|
|
||||||
uint32_t averageDensity = 0;
|
uint8_t voxel000Den = voxel000.getDensity();
|
||||||
averageDensity += voxel000.getDensity();
|
uint8_t voxel001Den = voxel001.getDensity();
|
||||||
averageDensity += voxel001.getDensity();
|
uint8_t voxel010Den = voxel010.getDensity();
|
||||||
averageDensity += voxel010.getDensity();
|
uint8_t voxel011Den = voxel011.getDensity();
|
||||||
averageDensity += voxel011.getDensity();
|
uint8_t voxel100Den = voxel100.getDensity();
|
||||||
averageDensity += voxel100.getDensity();
|
uint8_t voxel101Den = voxel101.getDensity();
|
||||||
averageDensity += voxel101.getDensity();
|
uint8_t voxel110Den = voxel110.getDensity();
|
||||||
averageDensity += voxel110.getDensity();
|
uint8_t voxel111Den = voxel111.getDensity();
|
||||||
averageDensity += voxel111.getDensity();
|
|
||||||
averageDensity /= 8;
|
float dummy;
|
||||||
|
sx = modf(sx, &dummy);
|
||||||
|
sy = modf(sy, &dummy);
|
||||||
|
sz = modf(sz, &dummy);
|
||||||
|
|
||||||
|
uint8_t uInterpolatedDensity = trilinearlyInterpolate<float>(voxel000Den,voxel100Den,voxel010Den,voxel110Den,voxel001Den,voxel101Den,voxel011Den,voxel111Den,sx,sy,sz);
|
||||||
|
|
||||||
VoxelType result;
|
VoxelType result;
|
||||||
result.setDensity(averageDensity);
|
result.setDensity(uInterpolatedDensity);
|
||||||
|
|
||||||
m_pVolDst->setVoxelAt(dx,dy,dz,result);
|
m_pVolDst->setVoxelAt(dx,dy,dz,result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
|
||||||
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::resampleArbitrary()
|
|
||||||
{
|
|
||||||
//ARBITRARY RESAMPLING NOT YET IMPLEMENTED.
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user