Skip to content

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 ​

cpp
VoxelMap(
    double voxelSize,
    const std::array<int, 3> &minKey,
    const std::array<int, 3> &size)

Empty map over a domain.

Parameters

ParameterDescription
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.
cpp
explicit VoxelMap(const VoxelMapResource &resource)

Map that shares the occupancy of a resource until its first edit.

~VoxelMap ​

cpp
~VoxelMap() override

Public member functions ​

getVoxelSize ​

cpp
double getVoxelSize() const

Returns voxel side length (m)

getMinKey ​

cpp
const std::array<int, 3> &getMinKey() const

Returns key of the first voxel of the domain along each axis

getDomainSize ​

cpp
const std::array<int, 3> &getDomainSize() const

Returns domain size in voxels along each axis

getOccupiedCount ​

cpp
std::uint64_t getOccupiedCount() const

Returns number of occupied voxels

isOccupied ​

cpp
bool isOccupied(int x, int y, int z) const

Returns true if voxel (x, y, z) is occupied (false outside the domain)

cpp
bool isOccupied(const std::array<int, 3> &key) const

Returns true if the voxel is occupied (false outside the domain)

getKey ​

cpp
std::array<int, 3> getKey(const Vec<3> &pointInMapFrame) const

Returns key of the voxel containing a point given in the map frame (m)

getKeyAtWorldPosition ​

cpp
std::array<int, 3> getKeyAtWorldPosition(const Vec<3> &worldPoint) const

Returns key of the voxel containing a point given in the world frame (m)

getVoxelCenter ​

cpp
Vec<3> getVoxelCenter(const std::array<int, 3> &key) const

Returns world-frame center of a voxel (m)

setVoxel ​

cpp
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 ​

cpp
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 ​

cpp
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 ​

cpp
std::uint64_t fillSphere(
    const Vec<3> &centerInMapFrame,
    double radius,
    bool occupied)

Set or clear every voxel whose center lies within a sphere, clipped to the domain.

Parameters

ParameterDescription
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 ​

cpp
void setOccupancy(const std::vector<std::uint8_t> &occupancy)

Replace the whole occupancy with a dense array over the domain (see VoxelMapResource::fromOccupancy()).

clear ​

cpp
void clear()

Clear every voxel.

getOccupiedKeys ​

cpp
std::vector<std::array<int, 3>> getOccupiedKeys() const

Returns keys of every occupied voxel, ordered by brick

getGrid ​

cpp
const ::contact::VoxelGrid &getGrid() const

Returns the occupancy grid

getRevision ​

cpp
std::uint64_t getRevision() const

Returns changes whenever a voxel changes, to a value no other occupancy has had (also across checkpoint restores)

makeResource ​

cpp
VoxelMapResource makeResource() const

Returns a resource holding a copy of the current occupancy

consumeEditedRegion ​

cpp
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 ​

cpp
void updateCollision() final

Internal: synchronizes the collision geometry with the current pose.

updateContactAabbs ​

cpp
void updateContactAabbs() override

Internal: recomputes the world-frame AABBs used by the broadphase.

destroyCollisionBodies ​

cpp
void destroyCollisionBodies() final

Internal: releases collision bodies before removal.

setBodyType ​

cpp
void setBodyType(BodyType type) override

A voxel map has no mass: it is STATIC or KINEMATIC. DYNAMIC is a fatal error.

Parameters

ParameterDescription
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

RaiSim — physics for robotics and AI.