LowPassFilter no longer requires convertToDensity() but instead assumes voxel types define operator+=, operator/=, etc.
This commit is contained in:
parent
63c5d510d1
commit
ec8b2f374c
@ -12,3 +12,4 @@ Because algorithms now know nothing about the structure of the underlying voxels
|
||||
|
||||
We have continued to provide the Density, Material, and MaterialDensityPair classes to ease the transition into the new system, but really they should just be considered as examples of how you might create your own voxel types.
|
||||
|
||||
Some algothms assume that basic mathematical operations can be applied to voxel types. For example, the LowPassFilter needs to compute the average of a set of voxels, and to do this it need to be possible to add voxels together and divide by an integer. Obviously these operations are provided by primitive types, but it means that if you want to use the LowPassfilter on custom voxel types then these types need to provide operator+=, operator/=, etc. These have been added to the Density and MaterialDensityPair classes, but not to the Material class. This reflects the fact that applying a low pass filter to a material volume does not make conceptual sense.
|
@ -76,6 +76,18 @@ namespace PolyVox
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
Density<Type>& operator+=(const Density<Type>& rhs)
|
||||
{
|
||||
m_uDensity += rhs.m_uDensity;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Density<Type>& operator/=(uint32_t rhs)
|
||||
{
|
||||
m_uDensity /= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
DensityType getDensity() const throw() { return m_uDensity; }
|
||||
//MaterialType getMaterial() const throw() { return 1; }
|
||||
|
||||
|
@ -75,40 +75,39 @@ namespace PolyVox
|
||||
|
||||
typename SrcVolumeType::VoxelType tSrcVoxel = srcSampler.getVoxel();
|
||||
|
||||
uint32_t uDensity = 0;
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1nx1ny1nz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1nx1ny0pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1nx1ny1pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1nx0py1nz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1nx0py0pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1nx0py1pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1nx1py1nz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1nx1py0pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1nx1py1pz());
|
||||
tSrcVoxel += srcSampler.peekVoxel1nx1ny1nz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1nx1ny0pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1nx1ny1pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1nx0py1nz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1nx0py0pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1nx0py1pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1nx1py1nz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1nx1py0pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1nx1py1pz();
|
||||
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel0px1ny1nz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel0px1ny0pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel0px1ny1pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel0px0py1nz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel0px0py0pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel0px0py1pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel0px1py1nz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel0px1py0pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel0px1py1pz());
|
||||
tSrcVoxel += srcSampler.peekVoxel0px1ny1nz();
|
||||
tSrcVoxel += srcSampler.peekVoxel0px1ny0pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel0px1ny1pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel0px0py1nz();
|
||||
//tSrcVoxel += srcSampler.peekVoxel0px0py0pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel0px0py1pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel0px1py1nz();
|
||||
tSrcVoxel += srcSampler.peekVoxel0px1py0pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel0px1py1pz();
|
||||
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1px1ny1nz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1px1ny0pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1px1ny1pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1px0py1nz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1px0py0pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1px0py1pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1px1py1nz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1px1py0pz());
|
||||
uDensity += convertToDensity(srcSampler.peekVoxel1px1py1pz());
|
||||
tSrcVoxel += srcSampler.peekVoxel1px1ny1nz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1px1ny0pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1px1ny1pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1px0py1nz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1px0py0pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1px0py1pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1px1py1nz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1px1py0pz();
|
||||
tSrcVoxel += srcSampler.peekVoxel1px1py1pz();
|
||||
|
||||
uDensity /= 27;
|
||||
tSrcVoxel /= 27;
|
||||
|
||||
tSrcVoxel.setDensity(uDensity);
|
||||
//tSrcVoxel.setDensity(uDensity);
|
||||
m_pVolDst->setVoxelAt(iSrcX, iSrcY, iSrcZ, tSrcVoxel);
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,24 @@ namespace PolyVox
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& operator+=(const MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& rhs)
|
||||
{
|
||||
m_uDensity += rhs.m_uDensity;
|
||||
|
||||
// What should we do with the material? Conceptually the idea of adding materials makes no sense, but for our
|
||||
// purposes we consider the 'sum' of two materials to just be the max. At least this way it is commutative.
|
||||
m_uMaterial = (std::max)(m_uMaterial, rhs.m_uMaterial);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& operator/=(uint32_t rhs)
|
||||
{
|
||||
// There's nothing sensible we can do with the material, so this function only affects the density.
|
||||
m_uDensity /= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
DensityType getDensity() const throw() { return m_uDensity; }
|
||||
MaterialType getMaterial() const throw() { return m_uMaterial; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user