More merging for Cubiquity version of PolyVox.

This commit is contained in:
David Williams 2012-12-16 14:43:18 +01:00
parent a1ac75022c
commit 342efec3fa
2 changed files with 710 additions and 694 deletions

View File

@ -30,34 +30,34 @@ freely, subject to the following restrictions:
namespace PolyVox namespace PolyVox
{ {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /**
/// This class provides a default implementation of a controller for the MarchingCubesSurfaceExtractor. It controls the behaviour of the * This class provides a default implementation of a controller for the MarchingCubesSurfaceExtractor. It controls the behaviour of the
/// MarchingCubesSurfaceExtractor and provides the required properties from the underlying voxel type. * MarchingCubesSurfaceExtractor and provides the required properties from the underlying voxel type.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// *
/// PolyVox does not enforce any requirements regarding what data must be present in a voxel, and instead allows any primitive or user-defined * PolyVox does not enforce any requirements regarding what data must be present in a voxel, and instead allows any primitive or user-defined
/// type to be used. However, the Marching Cubes algorithm does have some requirents about the underlying data in that conceptually it operates * type to be used. However, the Marching Cubes algorithm does have some requirents about the underlying data in that conceptually it operates
/// on a <i>density field</i>. In addition, the PolyVox implementation of the Marching Cubes algorithm also understands the idea of each voxel * on a <i>density field</i>. In addition, the PolyVox implementation of the Marching Cubes algorithm also understands the idea of each voxel
/// having a material which is copied into the vertex data. * having a material which is copied into the vertex data.
/// *
/// Because we want the MarchingCubesSurfaceExtractor to work on <i>any</i> voxel type, we use a <i>Marching Cubes controller</i> (passed as * Because we want the MarchingCubesSurfaceExtractor to work on <i>any</i> voxel type, we use a <i>Marching Cubes controller</i> (passed as
/// a parameter of the MarchingCubesSurfaceExtractor) to expose the required properties. This parameter defaults to the DefaultMarchingCubesController. * a parameter of the MarchingCubesSurfaceExtractor) to expose the required properties. This parameter defaults to the DefaultMarchingCubesController.
/// The main implementation of this class is designed to work with primitives data types, and the class is also specialised for the Material, * The main implementation of this class is designed to work with primitives data types, and the class is also specialised for the Material,
/// Density and MaterialdensityPair classes. * Density and MaterialdensityPair classes.
/// *
/// If you create a custom class for your voxel data then you probably want to include a specialisation of DefaultMarchingCubesController, * If you create a custom class for your voxel data then you probably want to include a specialisation of DefaultMarchingCubesController,
/// though you don't have to if you don't want to use the Marching Cubes algorithm or if you prefer to define a seperate Marching Cubes controller * though you don't have to if you don't want to use the Marching Cubes algorithm or if you prefer to define a seperate Marching Cubes controller
/// and pass it as an explicit parameter (rather than relying on the default). * and pass it as an explicit parameter (rather than relying on the default).
/// *
/// For primitive types, the DefaultMarchingCubesController considers the value of the voxel to represent it's density and just returns a constant * For primitive types, the DefaultMarchingCubesController considers the value of the voxel to represent it's density and just returns a constant
/// for the material. So you can, for example, run the MarchingCubesSurfaceExtractor on a volume of floats or ints. * for the material. So you can, for example, run the MarchingCubesSurfaceExtractor on a volume of floats or ints.
/// *
/// It is possible to customise the behaviour of the controller by providing a threshold value through the constructor. The extracted surface * It is possible to customise the behaviour of the controller by providing a threshold value through the constructor. The extracted surface
/// will pass through the density value specified by the threshold, and so you should make sure that the threshold value you choose is between * will pass through the density value specified by the threshold, and so you should make sure that the threshold value you choose is between
/// the minimum and maximum values found in your volume data. By default it is in the middle of the representable range of the underlying type. * the minimum and maximum values found in your volume data. By default it is in the middle of the representable range of the underlying type.
/// *
/// \sa MarchingCubesSurfaceExtractor * \sa MarchingCubesSurfaceExtractor
/// *
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
template<typename VoxelType> template<typename VoxelType>
class DefaultMarchingCubesController class DefaultMarchingCubesController
{ {
@ -69,65 +69,79 @@ namespace PolyVox
/// but this is not really desirable on modern hardware. We'll probably come back to material representation in the future. /// but this is not really desirable on modern hardware. We'll probably come back to material representation in the future.
typedef float MaterialType; typedef float MaterialType;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /**
/// Constructor * Constructor
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// *
/// This version of the constructor takes no parameters and sets the threshold to the middle of the representable range of the underlying type. * This version of the constructor takes no parameters and sets the threshold to the middle of the representable range of the underlying type.
/// For example, if the voxel type is 'uint8_t' then the representable range is 0-255, and the threshold will be set to 127. On the other hand, * For example, if the voxel type is 'uint8_t' then the representable range is 0-255, and the threshold will be set to 127. On the other hand,
/// if the voxel type is 'float' then the representable range is -FLT_MAX to FLT_MAX and the threshold will be set to zero. * if the voxel type is 'float' then the representable range is -FLT_MAX to FLT_MAX and the threshold will be set to zero.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
DefaultMarchingCubesController(void) DefaultMarchingCubesController(void)
:m_tThreshold(((std::numeric_limits<DensityType>::min)() + (std::numeric_limits<DensityType>::max)()) / 2)
,m_eWrapMode(WrapModes::Border)
,m_tBorder(VoxelType(0))
{ {
m_tThreshold = ((std::numeric_limits<DensityType>::min)() + (std::numeric_limits<DensityType>::max)()) / 2;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /**
/// Constructor * Converts the underlying voxel type into a density value.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// *
/// This version of the constructor allows you to set a custom threshold. * The default implementation of this function just returns the voxel type directly and is suitable for primitives types. Specialisations of
/// \param tThreshold The threshold to use. * this class can modify this behaviour.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
DefaultMarchingCubesController(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Converts the underlying voxel type into a density value.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// The default implementation of this function just returns the voxel type directly and is suitable for primitives types. Specialisations of
/// this class can modify this behaviour.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DensityType convertToDensity(VoxelType voxel) DensityType convertToDensity(VoxelType voxel)
{ {
return voxel; return voxel;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /**
/// Converts the underlying voxel type into a material value. * Converts the underlying voxel type into a material value.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// *
/// The default implementation of this function just returns the constant '1'. There's not much else it can do, as it needs to work with primitive * The default implementation of this function just returns the constant '1'. There's not much else it can do, as it needs to work with primitive
/// types and the actual value of the type is already being considered to be the density. Specialisations of this class can modify this behaviour. * types and the actual value of the type is already being considered to be the density. Specialisations of this class can modify this behaviour.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
MaterialType convertToMaterial(VoxelType voxel) MaterialType convertToMaterial(VoxelType /*voxel*/)
{ {
return 1; return 1;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// VoxelType getBorderValue(void)
/// Returns the density value which was passed to the constructor. {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// return m_tBorder;
/// As mentioned in the class description, the extracted surface will pass through the density value specified by the threshold, and so you }
/// should make sure that the threshold value you choose is between the minimum and maximum values found in your volume data. By default it
///is in the middle of the representable range of the underlying type. /**
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// * Returns the density value which was passed to the constructor.
*
* As mentioned in the class description, the extracted surface will pass through the density value specified by the threshold, and so you
* should make sure that the threshold value you choose is between the minimum and maximum values found in your volume data. By default it
* is in the middle of the representable range of the underlying type.
*/
DensityType getThreshold(void) DensityType getThreshold(void)
{ {
return m_tThreshold; return m_tThreshold;
} }
WrapMode getWrapMode(void)
{
return m_eWrapMode;
}
void setThreshold(DensityType tThreshold)
{
m_tThreshold = tThreshold;
}
void setWrapMode(WrapMode eWrapMode, VoxelType tBorder = VoxelType(0))
{
m_eWrapMode = eWrapMode;
m_tBorder = tBorder;
}
private: private:
DensityType m_tThreshold; DensityType m_tThreshold;
WrapMode m_eWrapMode;
VoxelType m_tBorder;
}; };
} }

View File

@ -36,6 +36,8 @@ namespace PolyVox
m_controller = controller; m_controller = controller;
m_tThreshold = m_controller.getThreshold(); m_tThreshold = m_controller.getThreshold();
m_sampVolume.setWrapMode(m_controller.getWrapMode(), m_controller.getBorderValue());
} }
template<typename VolumeType, typename Controller> template<typename VolumeType, typename Controller>