Voxelyze
Public Types | Public Member Functions
CVoxelyze Class Reference

Defines and simulates a configuration of voxels. More...

#include <Voxelyze.h>

List of all members.

Public Types

enum  stateInfoType {
  DISPLACEMENT, VELOCITY, KINETIC_ENERGY, ANGULAR_DISPLACEMENT,
  ANGULAR_VELOCITY, ENG_STRESS, ENG_STRAIN, STRAIN_ENERGY,
  PRESSURE, MASS
}
 Defines various types of information to query about the state of a voxelyze object. More...
enum  valueType { MIN, MAX, TOTAL, AVERAGE }
 The type if value desired for a given stateInfoType. Considers all voxels or all links (depending on stateInfoType). More...

Public Member Functions

 CVoxelyze (double voxelSize=DEFAULT_VOXEL_SIZE)
 Constructs an empty voxelyze object.
 CVoxelyze (const char *jsonFilePath)
 Constructs a voxelyze object from a *.vxl.json file. The details of this file format are available in the Voxelyze user guide.
 CVoxelyze (rapidjson::Value *pV)
 Constructs a voxelyze object from a rapidjson parser node that contains valid voxelyze sub-nodes.
 ~CVoxelyze (void)
 Destructor.
 CVoxelyze (CVoxelyze &VIn)
 Copy constructor.
CVoxelyzeoperator= (CVoxelyze &VIn)
 Equals operator.
void clear ()
 Erases all voxels and materials and restores the voxelyze object to its default (empty) state.
bool loadJSON (const char *jsonFilePath)
 Clears this voxelyze instance and loads fresh from a *.vxl.json file. The details of this file format are available in the Voxelyze user guide.
bool saveJSON (const char *jsonFilePath)
 Saves this voxelyze instance to a json file. All voxels are saved at their default locations - the state is not captured. It is recommended to specify the standard *.vxl.json file suffix.
bool doLinearSolve ()
 Linearizes the voxelyze object and does a one-time linear solution to set the position and orientation of all voxels. The current state of the voxel object will be discarded. Currently only the pardiso solver is supported. To make use of this feature voxelyze must be built with PARDISO_5 defined in the preprocessor. A valid pardiso 5 license file and library file (i.e libpardiso500-WIN-X86-64.dll for windows) should be obtained from www.pardiso-project.org and placed in the directory your executable will be run from.
bool doTimeStep (float dt=-1.0f)
 Executes a single timestep on this voxelyze object and updates all state information (voxel positions and orientations) accordingly. In most situations this function will be called repeatedly until the desired result is obtained.
float recommendedTimeStep () const
 Returns an estimate of the largest stable time step based on the current state of the simulation. If poisson's ratios are all zero and material properties do not otherwise change this can be called once and the same timestep value used for all subsequent doTimeStep() calls. Otherwise the timestep should be recalculated whenever the simulation has changed.
void resetTime ()
 Resets all voxels to their initial state and zeroes the elapsed time counter. Call this to "start over" without changing any of the voxels.
CVX_MaterialaddMaterial (float youngsModulus=1e6f, float density=1e3f)
 Adds a material to this voxelyze object with the minimum necessary information for dynamic simulation (stiffness, density). Returns a pointer to the newly created material that can be used to further specify properties using CVX_Material public memer functions. See CVX_Material documentation. This function does not create any voxels, but a returned CVX_material pointer is a necessary parameter for the setVoxel() function that does add voxels.
CVX_MaterialaddMaterial (rapidjson::Value &mat)
 Adds a material to this voxelyze object from a rapidjson parser node that contains valid CVX_Material sub-nodes.
CVX_MaterialaddMaterial (const CVX_Material &mat)
 Adds a material to this voxelyse object and copies all material properties from the specified CVX_Material.
bool removeMaterial (CVX_Material *toRemove)
 Removes the specified material from the voxelyze object and deletes all voxels currently using it.
bool replaceMaterial (CVX_Material *replaceMe, CVX_Material *replaceWith)
 Replaces all voxels of one material with another material.
int materialCount ()
 Returns the number of materials currently in this voxelyze object.
CVX_Materialmaterial (int materialIndex)
 Returns a pointer to a material that has been added to this voxelyze object. CVX_Material public member functions can be safely called on this pointer to modify the material. A given index may or may not always return the same material - Use material pointers to keep permanent handles to specific materials. This function is primarily used while iterating through all materials in conjuntion with materialCount().
CVX_VoxelsetVoxel (CVX_Material *material, int xIndex, int yIndex, int zIndex)
 Adds a voxel made of material at the specified index. If a voxel already exists here it is replaced. The returned pointer can be safely modified by calling any CVX_Voxel public member function on it.
CVX_Voxelvoxel (int xIndex, int yIndex, int zIndex) const
 Returns a pointer to the voxel at this location if one exists, or null otherwise. The returned pointer can be safely modified by calling any CVX_Voxel public member function on it.
int voxelCount () const
 Returns the number of voxels currently in this voxelyze object.
CVX_Voxelvoxel (int voxelIndex) const
 Returns a pointer to a voxel that has been added to this voxelyze object. CVX_Voxel public member functions can be safely called on this pointer to query or modify the voxel. A given index may or may not always return the same voxel - Use voxel pointers to keep permanent handles to specific voxels. This function is primarily used while iterating through all voxels in conjuntion with voxelCount().
const std::vector< CVX_Voxel * > * voxelList () const
 Returns a pointer to the internal list of voxels in this voxelyze object. In some situations where all voxels must be iterated over quickly there may be performance gains from iterating directly on the underlying std::vector container accessed with this function.
int indexMinX () const
 The minimum X index of any voxel in this voxelyze object. Use to determine limits.
int indexMaxX () const
 The minimum Y index of any voxel in this voxelyze object. Use to determine limits.
int indexMinY () const
 The minimum Z index of any voxel in this voxelyze object. Use to determine limits.
int indexMaxY () const
 The maximum X index of any voxel in this voxelyze object. Use to determine limits.
int indexMinZ () const
 The maximum Y index of any voxel in this voxelyze object. Use to determine limits.
int indexMaxZ () const
 The maximum Z index of any voxel in this voxelyze object. Use to determine limits.
CVX_Linklink (int xIndex, int yIndex, int zIndex, CVX_Voxel::linkDirection direction) const
 Returns a pointer to the link at this voxel location in the direction indicated if one exists, or null otherwise. The returned pointer can be safely modified by calling any CVX_Link public member function on it.
int linkCount () const
 Returns the number of links currently in this voxelyze object.
CVX_Linklink (int linkIndex)
 Returns a pointer to a link that is a part of this voxelyze object. CVX_Link public member functions can be safely called on this pointer to query the link. A given index may or may not always return the same link - Use link pointers to keep permanent handles to specific voxels. This function is primarily used while iterating through all links in conjuntion with linkCount().
const std::vector< CVX_Link * > * linkList () const
 Returns a pointer to the internal list of links in this voxelyze object. In some situations where all links must be iterated over quickly there may be performance gains from iterating directly on the underlying std::vector container accessed with this function.
const std::vector
< CVX_Collision * > * 
collisionList () const
 Returns a pointer to the internal list of collisions in this voxelyze object. See CVX_Collision documentation for more information on collision objects.
void setVoxelSize (double voxelSize)
 Sets the base voxel size for the entire voxelyze object.
double voxelSize () const
 Returns the base voxel size in meters.
void setAmbientTemperature (float relativeTemperature, bool allVoxels=false)
 Sets the relative ambient temperature of the environment. A relative temperature of zero indicates that materials will experience zero thermal expansion.
float ambientTemperature (void) const
 Returns the current relative ambient temperature.
void setGravity (float g=1.0f)
 Sets the gravitational acceleration to apply to all voxels. Gravity acts in the -Z direction. Set to 0 to disable.
float gravity (void) const
 Returns the current gravitational acceleration in g's. 1 g = -9.80665 m/s^2.
void enableFloor (bool enabled=true)
 Enables or disables a floor that resists voxel penetration at z=0.
bool isFloorEnabled (void) const
 Returns a boolean value indication if the floor is enabled or not.
void enableCollisions (bool enabled=true)
 Enables or disables a collision watcher that results in voxels resisting penetration with one another. This may slow down the simulation significantly.
bool isCollisionsEnabled (void) const
 Returns a boolean value indication if the collision watcher is enabled or not.
float stateInfo (stateInfoType info, valueType type)
 Returns a specific piece of information about the current state of the simulation. This method is not gaurenteed threadafe.

Detailed Description

Defines and simulates a configuration of voxels.

The primary user-accesible concepts of Voxelyze are materials, voxels, and links.

Materials represent an abstract material with physical properties and must be added via one of the addMaterial() functions before any voxels may be added. Materials hold no state - they are essentially just a container for a set of material properties.

Voxels are added using setVoxel() and use a previously added material. Voxels always begin as cubes on a regular lattice - therefore only x, y, and z indices are need to fully specify where to add a voxel. A voxel object may have an "external" influence (such as being fixed to ground in one or more degrees of freedom, or an external force applied) which is accessed through its external() member function. A voxel also contains state information such as its current position and velocity.

Links are never added directly. Instead whenenver a voxel is added a link is automatically created to any adjacent voxels. Links hold all the structural information of the simulated Euler-Bernoulli beam connecting two adjacent voxels. In the case of two voxels with dissimilar materials, the link object automatically calculates the appropriate composite material properties. Links hold state information such as stress, strain, and strain energy.

The pointers returned for materials, voxels, and links are valid for the entire lifetime of that particular material, voxel, or link. It is also possible to iterate over all materials, voxels, or links using, for example, materialCount() and material().

Once the desired voxels are set up, the simulation is run by simply calling doTimeStep() repeatedly until the desired result is acheived. Because Voxelyze utilizes numerical integration, too large of a timestep will cause divergent instability. This depends on many things, most notably the stiffness and density of voxels in use. Heavy, stiff voxels will be stable for larger timesteps. Calling doTimeStep() without an argument will use a good estimation of the larger stable timestep duration. This timestep is used synchronously for all voxels, so the entire simulation will run at the slowest timestep (as determined usually by the stiffest/lightest material in use).


Member Enumeration Documentation

Defines various types of information to query about the state of a voxelyze object.

Enumerator:
DISPLACEMENT 

Displacement from a nominal position in meters.

VELOCITY 

Velocity in meters per second.

KINETIC_ENERGY 

Kinetic energy in joules.

ANGULAR_DISPLACEMENT 

Angular displacement from nominal orientation in radians.

ANGULAR_VELOCITY 

Angular velocity in radians per second.

ENG_STRESS 

Engineering stress in pascals.

ENG_STRAIN 

Engineering strain (unitless)

STRAIN_ENERGY 

Strain energy in joules.

PRESSURE 

pressure in pascals

MASS 

mass in Kg

The type if value desired for a given stateInfoType. Considers all voxels or all links (depending on stateInfoType).

Enumerator:
MIN 

Minimum of all values.

MAX 

Maximum of all values.

TOTAL 

Total (sum) of all values.

AVERAGE 

Average of all values.


Constructor & Destructor Documentation

CVoxelyze::CVoxelyze ( double  voxelSize = DEFAULT_VOXEL_SIZE)

Constructs an empty voxelyze object.

Parameters:
[in]voxelSizebase size of the voxels in this instance in meters.
CVoxelyze::CVoxelyze ( const char *  jsonFilePath) [inline]

Constructs a voxelyze object from a *.vxl.json file. The details of this file format are available in the Voxelyze user guide.

Parameters:
[in]jsonFilePathpath to the json file
CVoxelyze::CVoxelyze ( rapidjson::Value *  pV)

Constructs a voxelyze object from a rapidjson parser node that contains valid voxelyze sub-nodes.

Parameters:
[in]pVpointer to a rapidjson Value that contains Voxelyze information. See rapidjson documentation and the *.vxl.json format info in the voxelyze user guide.

Member Function Documentation

CVX_Material * CVoxelyze::addMaterial ( float  youngsModulus = 1e6f,
float  density = 1e3f 
)

Adds a material to this voxelyze object with the minimum necessary information for dynamic simulation (stiffness, density). Returns a pointer to the newly created material that can be used to further specify properties using CVX_Material public memer functions. See CVX_Material documentation. This function does not create any voxels, but a returned CVX_material pointer is a necessary parameter for the setVoxel() function that does add voxels.

Parameters:
[in]youngsModulusthe desired stiffness (Young's Modulus) of this material in Pa (N/m^2).
[in]densitythe desired density of this material in Kg/m^3.
CVX_Material * CVoxelyze::addMaterial ( rapidjson::Value &  mat)

Adds a material to this voxelyze object from a rapidjson parser node that contains valid CVX_Material sub-nodes.

Parameters:
[in]matreference to a rapidjson Value that contains CVX_Material information. See rapidjson documentation and the *.vxl.json format info in the voxelyze user guide.

Adds a material to this voxelyse object and copies all material properties from the specified CVX_Material.

Parameters:
[in]matthe material to copy all information from. This material is not affected, and can either be a part of this voxelyze object or constructed externally.
bool CVoxelyze::doTimeStep ( float  dt = -1.0f)

Executes a single timestep on this voxelyze object and updates all state information (voxel positions and orientations) accordingly. In most situations this function will be called repeatedly until the desired result is obtained.

Parameters:
[in]dtThe timestep to take in seconds. If this value is too large the system will display divergent instability. Use recommendedTimeStep() to get a conservative estimate of the largest stable timestep. Also the default value of -1.0f will blindly use this recommended timestep.
void CVoxelyze::enableCollisions ( bool  enabled = true)

Enables or disables a collision watcher that results in voxels resisting penetration with one another. This may slow down the simulation significantly.

Parameters:
[in]enabledIf true, enables the collision detection. Otherwise disables it.
void CVoxelyze::enableFloor ( bool  enabled = true)

Enables or disables a floor that resists voxel penetration at z=0.

Parameters:
[in]enabledIf true, enables the floor. Otherwise disables it.
CVX_Link * CVoxelyze::link ( int  xIndex,
int  yIndex,
int  zIndex,
CVX_Voxel::linkDirection  direction 
) const

Returns a pointer to the link at this voxel location in the direction indicated if one exists, or null otherwise. The returned pointer can be safely modified by calling any CVX_Link public member function on it.

Parameters:
[in]xIndexthe X index of the voxel to query.
[in]yIndexthe Y index of the voxel to query.
[in]zIndexthe Z index of the voxel to query.
directionthe direction from the specified voxel to look for a link.
CVX_Link* CVoxelyze::link ( int  linkIndex) [inline]

Returns a pointer to a link that is a part of this voxelyze object. CVX_Link public member functions can be safely called on this pointer to query the link. A given index may or may not always return the same link - Use link pointers to keep permanent handles to specific voxels. This function is primarily used while iterating through all links in conjuntion with linkCount().

Parameters:
[in]linkIndexthe current index of a link. Valid range from 0 to linkCount()-1.
bool CVoxelyze::loadJSON ( const char *  jsonFilePath)

Clears this voxelyze instance and loads fresh from a *.vxl.json file. The details of this file format are available in the Voxelyze user guide.

Parameters:
[in]jsonFilePathpath to the json file
CVX_Material* CVoxelyze::material ( int  materialIndex) [inline]

Returns a pointer to a material that has been added to this voxelyze object. CVX_Material public member functions can be safely called on this pointer to modify the material. A given index may or may not always return the same material - Use material pointers to keep permanent handles to specific materials. This function is primarily used while iterating through all materials in conjuntion with materialCount().

Parameters:
[in]materialIndexthe current index of a material. Valid range from 0 to materialCount()-1.

Removes the specified material from the voxelyze object and deletes all voxels currently using it.

Parameters:
[in]toRemovepointer to a material to remove from this voxelyze object.
bool CVoxelyze::replaceMaterial ( CVX_Material replaceMe,
CVX_Material replaceWith 
)

Replaces all voxels of one material with another material.

Parameters:
[in]replaceMematerial to be replaced
[in]replaceWithmaterial to replace with. This material must already be a part of the simulation - the pointer will have originated from addMaterial() or material().
bool CVoxelyze::saveJSON ( const char *  jsonFilePath)

Saves this voxelyze instance to a json file. All voxels are saved at their default locations - the state is not captured. It is recommended to specify the standard *.vxl.json file suffix.

Parameters:
[in]jsonFilePathpath to the desired json file. Will create or overwrite a file at this path.
void CVoxelyze::setAmbientTemperature ( float  relativeTemperature,
bool  allVoxels = false 
)

Sets the relative ambient temperature of the environment. A relative temperature of zero indicates that materials will experience zero thermal expansion.

Parameters:
[in]relativeTemperatureRelative temperature in degrees celsius.
[in]allVoxelsFlag to denote whether all voxels should take this temperature immediately. If true any diffusion time is skipped and thermal energy is added (or removed) from each voxel to reach this temperature. If false voxels will not change temperature.
void CVoxelyze::setGravity ( float  g = 1.0f)

Sets the gravitational acceleration to apply to all voxels. Gravity acts in the -Z direction. Set to 0 to disable.

Parameters:
[in]gGravitational acceleration in g's. 1 g = -9.80665 m/s^2.
CVX_Voxel * CVoxelyze::setVoxel ( CVX_Material material,
int  xIndex,
int  yIndex,
int  zIndex 
)

Adds a voxel made of material at the specified index. If a voxel already exists here it is replaced. The returned pointer can be safely modified by calling any CVX_Voxel public member function on it.

Parameters:
[in]materialmaterial this voxel is made from. This material must already be a part of the simulation - the pointer will have originated from addMaterial() or material().
[in]xIndexthe X index of this voxel.
[in]yIndexthe Y index of this voxel.
[in]zIndexthe Z index of this voxel.
void CVoxelyze::setVoxelSize ( double  voxelSize)

Sets the base voxel size for the entire voxelyze object.

Parameters:
[in]voxelSizebase size of the voxels in this instance in meters.
float CVoxelyze::stateInfo ( stateInfoType  info,
valueType  type 
)

Returns a specific piece of information about the current state of the simulation. This method is not gaurenteed threadafe.

Parameters:
[in]infoThe class of information desired.
[in]typeThe type of the value to be returned.
CVX_Voxel* CVoxelyze::voxel ( int  xIndex,
int  yIndex,
int  zIndex 
) const [inline]

Returns a pointer to the voxel at this location if one exists, or null otherwise. The returned pointer can be safely modified by calling any CVX_Voxel public member function on it.

Parameters:
[in]xIndexthe X index to query.
[in]yIndexthe Y index to query.
[in]zIndexthe Z index to query.
CVX_Voxel* CVoxelyze::voxel ( int  voxelIndex) const [inline]

Returns a pointer to a voxel that has been added to this voxelyze object. CVX_Voxel public member functions can be safely called on this pointer to query or modify the voxel. A given index may or may not always return the same voxel - Use voxel pointers to keep permanent handles to specific voxels. This function is primarily used while iterating through all voxels in conjuntion with voxelCount().

Parameters:
[in]voxelIndexthe current index of a voxel. Valid range from 0 to voxelCount()-1.

The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations Enumerator Friends