raisim::VoxelMap
final class · #include <raisim/object/terrain/VoxelMap.hpp>
Inherits: raisim::SingleBodyObject
A static, editable 3D occupancy map of cubic voxels (create it with World::addVoxelMap()).
Voxel key (i, j, k) occupies the cube [i s, (i + 1) s) x [j s, (j + 1) s) x [k s, (k + 1) s) of the map frame, s being getVoxelSize(). Keys are limited to the domain [minKey, minKey + size) chosen at creation; every voxel outside it is empty. The map frame is placed by the object pose (setPosition(), setOrientation()) like every other object and starts at the world frame.
Bodies collide with the exposed faces, edges and corners of the occupied voxels: the shared face between two occupied voxels is never a contact surface, so a body slides across a flat voxel surface without catching on the seams between voxels. Rays (World::rayTest(), lidars, depth cameras) hit the first occupied voxel along them.
Edits take effect immediately. Sleeping bodies that reach an edited region wake at the next step. An edit that throws std::bad_alloc keeps, and accounts for, the voxels it changed before the failure.
Constructors & destructor
VoxelMap
VoxelMap(
double voxelSize,
const std::array<int, 3> &minKey,
const std::array<int, 3> &size)Empty map over a domain.
Parameters
| Parameter | Description |
|---|---|
voxelSize (in) | voxel side length (m), finite and positive |
minKey (in) | key of the first voxel of the domain along each axis |
size (in) | domain size in voxels along each axis, each in [1, 2^24]. The domain is indexed by root cells of 64^3 voxels, and their number, ceil(size[0] / 64) * ceil(size[1] / 64) * ceil(size[2] / 64), may not exceed 2^26 (fatal otherwise). This root index takes 4 bytes per root cell and is allocated up front, also for an empty map (up to 256 MiB); beyond it, memory grows only with the 64^3- and 16^3-voxel blocks that hold occupied voxels. |
explicit VoxelMap(const VoxelMapResource &resource)Map that shares the occupancy of a resource until its first edit.
~VoxelMap
~VoxelMap() overridePublic member functions
getVoxelSize
double getVoxelSize() constReturns voxel side length (m)
getMinKey
const std::array<int, 3> &getMinKey() constReturns key of the first voxel of the domain along each axis
getDomainSize
const std::array<int, 3> &getDomainSize() constReturns domain size in voxels along each axis
getOccupiedCount
std::uint64_t getOccupiedCount() constReturns number of occupied voxels
isOccupied
bool isOccupied(int x, int y, int z) constReturns true if voxel (x, y, z) is occupied (false outside the domain)
bool isOccupied(const std::array<int, 3> &key) constReturns true if the voxel is occupied (false outside the domain)
getKey
std::array<int, 3> getKey(const Vec<3> &pointInMapFrame) constReturns key of the voxel containing a point given in the map frame (m)
getKeyAtWorldPosition
std::array<int, 3> getKeyAtWorldPosition(const Vec<3> &worldPoint) constReturns key of the voxel containing a point given in the world frame (m)
getVoxelCenter
Vec<3> getVoxelCenter(const std::array<int, 3> &key) constReturns world-frame center of a voxel (m)
setVoxel
bool setVoxel(int x, int y, int z, bool occupied)Set or clear one voxel. Keys outside the domain are ignored.
Returns true if the voxel changed
setVoxels
std::uint64_t setVoxels(
const std::vector<std::array<int, 3>> &keys,
bool occupied)Set or clear voxels. Keys outside the domain are ignored.
Returns number of voxels that changed
fillBox
std::uint64_t fillBox(
const std::array<int, 3> &lo,
const std::array<int, 3> &hi,
bool occupied)Set or clear every voxel of the key box [lo, hi] (inclusive), clipped to the domain.
Returns number of voxels that changed
fillSphere
std::uint64_t fillSphere(
const Vec<3> ¢erInMapFrame,
double radius,
bool occupied)Set or clear every voxel whose center lies within a sphere, clipped to the domain.
Parameters
| Parameter | Description |
|---|---|
centerInMapFrame (in) | sphere center in the map frame (m) |
radius (in) | sphere radius (m) |
occupied (in) | true to fill, false to carve |
Returns number of voxels that changed
setOccupancy
void setOccupancy(const std::vector<std::uint8_t> &occupancy)Replace the whole occupancy with a dense array over the domain (see VoxelMapResource::fromOccupancy()).
clear
void clear()Clear every voxel.
getOccupiedKeys
std::vector<std::array<int, 3>> getOccupiedKeys() constReturns keys of every occupied voxel, ordered by brick
getGrid
const ::contact::VoxelGrid &getGrid() constReturns the occupancy grid
getRevision
std::uint64_t getRevision() constReturns changes whenever a voxel changes, to a value no other occupancy has had (also across checkpoint restores)
makeResource
VoxelMapResource makeResource() constReturns a resource holding a copy of the current occupancy
consumeEditedRegion
bool consumeEditedRegion(std::array<int, 3> &lo, std::array<int, 3> &hi)Internal: the key box (inclusive) edited since the last call, used to wake sleeping bodies.
Returns false if nothing was edited
updateCollision
void updateCollision() finalInternal: synchronizes the collision geometry with the current pose.
updateContactAabbs
void updateContactAabbs() overrideInternal: recomputes the world-frame AABBs used by the broadphase.
destroyCollisionBodies
void destroyCollisionBodies() finalInternal: releases collision bodies before removal.
setBodyType
void setBodyType(BodyType type) overrideA voxel map has no mass: it is STATIC or KINEMATIC. DYNAMIC is a fatal error.
Parameters
| Parameter | Description |
|---|---|
type (in) | new body type |
Inherited members
From raisim::SingleBodyObject: clearExternalForcesAndTorques, fluidSampleDelay, getAngularVelocity, getAppearance, getBodyToComPosition_rs, getCollisionBody, getCollisionGroup, getCollisionMask, getCom, getComPosition, getComPosition_rs, getContactPointVel, getDOF, getEnergy, getFluidBodyState, getGeneralizedCoordinateDim, getGyroscopicMode, getInertiaMatrix_B, getInertiaMatrix_B_rs, getInertiaMatrix_W, getInertiaMatrix_W_rs, getKineticEnergy, getLinearMomentum, getLinearVelocity, getMass, getObjectType, getOrientation, getPosition, getPotentialEnergy, getQuaternion, getRotationMatrix, getVelocity, integrate, preContactSolverUpdate1, preContactSolverUpdate2, setAngularDamping, setAngularVelocity, setAppearance, setCom, setConstraintForce, setExternalForce, setExternalTorque, setGyroscopicMode, setInertia, setLinearDamping, setLinearVelocity, setMass, setOrientation, setPose, setPosition, setVelocity
From raisim::Object: addContactToPerObjectContact, clearPerObjectContact, getBodyType, getContactAabb, getContactAabbCount, getContacts, getExternalForce, getExternalForcePosition, getExternalTorque, getExternalTorquePosition, getFluidForce, getFluidTorque, getId, getIndexInWorld, getName, getRenderRevision, getSegmentationLabel, Id, lock, lockMutex, setIndexInWorld, setName, setSegmentationLabel, try_lock, unlock, unlockMutex