PolyVox  0.2.1
Open source voxel management library
Public Types | Public Member Functions
PolyVox::DefaultMarchingCubesController< VoxelType > Class Template Reference

This class provides a default implementation of a controller for the MarchingCubesSurfaceExtractor. More...

#include <DefaultMarchingCubesController.h>

List of all members.

Public Types

typedef VoxelType DensityType
 Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing densities.
typedef float MaterialType
 Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing materials.

Public Member Functions

 DefaultMarchingCubesController (void)
 Constructor.
 DefaultMarchingCubesController (DensityType tThreshold)
 Constructor.
DensityType convertToDensity (VoxelType voxel)
 Converts the underlying voxel type into a density value.
MaterialType convertToMaterial (VoxelType)
 Converts the underlying voxel type into a material value.
DensityType getThreshold (void)
 Returns the density value which was passed to the constructor.

Detailed Description

template<typename VoxelType>
class PolyVox::DefaultMarchingCubesController< VoxelType >

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.

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 on a density field. 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.

Because we want the MarchingCubesSurfaceExtractor to work on any voxel type, we use a Marching Cubes controller (passed as 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, Density and MaterialdensityPair classes.

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 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 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 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.

See also:
MarchingCubesSurfaceExtractor

Definition at line 60 of file DefaultMarchingCubesController.h.


Member Typedef Documentation

template<typename VoxelType >
typedef VoxelType PolyVox::DefaultMarchingCubesController< VoxelType >::DensityType

Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing densities.

Definition at line 64 of file DefaultMarchingCubesController.h.

template<typename VoxelType >
typedef float PolyVox::DefaultMarchingCubesController< VoxelType >::MaterialType

Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing materials.

We're using a float here because this implementation always returns a constant value off 1.0f. PolyVox also uses floats to store the materials in the mesh vertices but this is not really desirable on modern hardware. We'll probably come back to material representation in the future.

Definition at line 68 of file DefaultMarchingCubesController.h.


Constructor & Destructor Documentation

template<typename VoxelType >
PolyVox::DefaultMarchingCubesController< VoxelType >::DefaultMarchingCubesController ( void  )
inline

Constructor.

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, if the voxel type is 'float' then the representable range is -FLT_MAX to FLT_MAX and the threshold will be set to zero.

Definition at line 77 of file DefaultMarchingCubesController.h.

template<typename VoxelType >
PolyVox::DefaultMarchingCubesController< VoxelType >::DefaultMarchingCubesController ( DensityType  tThreshold)
inline

Constructor.

This version of the constructor allows you to set a custom threshold.

Parameters:
tThresholdThe threshold to use.

Definition at line 88 of file DefaultMarchingCubesController.h.


Member Function Documentation

template<typename VoxelType >
DensityType PolyVox::DefaultMarchingCubesController< VoxelType >::convertToDensity ( VoxelType  voxel)
inline

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.

Definition at line 99 of file DefaultMarchingCubesController.h.

template<typename VoxelType >
MaterialType PolyVox::DefaultMarchingCubesController< VoxelType >::convertToMaterial ( VoxelType  )
inline

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 types and the actual value of the type is already being considered to be the density. Specialisations of this class can modify this behaviour.

Definition at line 110 of file DefaultMarchingCubesController.h.

template<typename VoxelType >
DensityType PolyVox::DefaultMarchingCubesController< VoxelType >::getThreshold ( void  )
inline

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.

Definition at line 122 of file DefaultMarchingCubesController.h.


The documentation for this class was generated from the following file: