Skip to content

raisim::SegmentationCamera ​

final class · #include <raisim/sensors/SegmentationSensor.hpp>

Inherits: raisim::Sensor

Segmentation camera: which object, body and semantic label each pixel sees.

It fills up to three images of width * height int32 values, row-major (index = row * width + col), row 0 at the top of the image:

Every image holds kBackground (-1) where nothing was hit within [clipNear, clipFar]. The object and body images hold kNotWorldObject (-2) for rayrai visuals that are not RaiSim objects (drawn only when a renderer is asked to include visualization objects). SegmentationType selects the images: SEMANTIC fills the label image, INSTANCE the object and body images, PANOPTIC all three. The images it does not select are empty.

World indices refer to the world at the measurement time: World::removeObject() moves the last object into the freed index.

Sensor frame convention: +x is the optical axis, +y points left and +z up, as for DepthCamera.

Measurement sources: with MANUAL (the default) a renderer writes the images, e.g. rayrai's RayraiWindow::renderSegmentation() and Camera::getRawImage(), or the rayrai TCP viewer for a RaisimServer. With RAISIM, update() ray-casts the collision geometry of the world (the owning body excluded), as DepthCamera::update() does.

Nested classes ​

Public types ​

SegmentationType ​

cpp
enum class SegmentationType : int

Which images the camera fills.

EnumeratorValueDescription
SEMANTIC0Label image only.
INSTANCEObject and body images.
PANOPTICObject, body and label images.

Constructors & destructor ​

SegmentationCamera ​

cpp
SegmentationCamera(
    const SegmentationCameraProperties &prop,
    class ArticulatedSystem *as,
    const Vec<3> &pos,
    const Mat<3, 3> &rot)

Create a segmentation camera and allocate the images its type selects, filled with kBackground. The measurement source is MANUAL.

Parameters

ParameterDescription
prop (in)Camera properties (validated; invalid values cause a fatal error).
as (in)Owning articulated system.
pos (in)Sensor position relative to the body (link) it is defined on.
rot (in)Sensor orientation relative to the body (link) it is defined on.

Public member functions ​

serializeProp ​

cpp
server::BoundedWriter serializeProp(server::BoundedWriter data) const final

Used by the server. Do not use it if you don't know what it does. It serializes the sensor properties

Parameters

ParameterDescription
data (in)where the property is written; throws server::SerializationError if it does not fit

Returns where the next data should be written

getProperties ​

cpp
const SegmentationCameraProperties &getProperties() const

Returns The camera properties.

setProperties ​

cpp
void setProperties(const SegmentationCameraProperties &prop)

Replace the camera properties transactionally. Invalid properties leave the camera unchanged. The images are reallocated for the new type and size and filled with kBackground, and a connected viewer receives the new properties before it renders the camera again.

Parameters

ParameterDescription
prop (in)New properties. name and full_name must match the current ones (fatal error otherwise).

getObjectImage ​

cpp
const std::vector<int32_t> &getObjectImage() const

World index of the object seen in each pixel (see the class comment); empty for SEMANTIC.

cpp
std::vector<int32_t> &getObjectImage()

Mutable access for MANUAL measurements; keep its size.

getBodyImage ​

cpp
const std::vector<int32_t> &getBodyImage() const

Body index within the object seen in each pixel; empty for SEMANTIC.

cpp
std::vector<int32_t> &getBodyImage()

Mutable access for MANUAL measurements; keep its size.

getLabelImage ​

cpp
const std::vector<int32_t> &getLabelImage() const

Semantic label seen in each pixel; empty for INSTANCE.

cpp
std::vector<int32_t> &getLabelImage()

Mutable access for MANUAL measurements; keep its size.

setObjectImage ​

cpp
void setObjectImage(const std::vector<int32_t> &image)

Replace the object image. Fatal error unless it has the current image's size.

Parameters

ParameterDescription
image (in)width * height values, or none when the type has no object image.

setBodyImage ​

cpp
void setBodyImage(const std::vector<int32_t> &image)

Replace the body image. Fatal error unless it has the current image's size.

Parameters

ParameterDescription
image (in)width * height values, or none when the type has no body image.

setLabelImage ​

cpp
void setLabelImage(const std::vector<int32_t> &image)

Replace the label image. Fatal error unless it has the current image's size.

Parameters

ParameterDescription
image (in)width * height values, or none when the type has no label image.

update ​

cpp
void update(class World &world) final

Ray-cast the images: refreshes the sensor pose from its attachment frame, then casts one ray per pixel against the collision bodies of world, ignoring the owning body. Called by RaiSim when the measurement source is RAISIM.

Parameters

ParameterDescription
world (in)the world that the sensor is in

Static member functions ​

getType static ​

cpp
static Type getType()

Returns Sensor::Type::SEGMENTATION.

hasInstanceImages static ​

cpp
static bool hasInstanceImages(SegmentationType type)

Returns True when type fills the object and body images.

hasLabelImage static ​

cpp
static bool hasLabelImage(SegmentationType type)

Returns True when type fills the label image.

imageCount static ​

cpp
static int imageCount(SegmentationType type)

Returns The number of images type fills (1 for SEMANTIC, 2 for INSTANCE, 3 for PANOPTIC).

colorize static ​

cpp
static void colorize(
    const std::vector<int32_t> &ids,
    std::vector<unsigned char> &rgba,
    const std::array<unsigned char, 4> &background={0, 0, 0, 0})

Color an id image for display: each non-negative id gets a fixed, well-separated color that does not depend on the other ids; negative ids get background.

Parameters

ParameterDescription
ids (in)Image of ids (any of the three images).
rgba (out)Resized to ids.size() * 4 bytes, RGBA.
background (in)Color of negative ids.

colorOf static ​

cpp
static std::array<unsigned char, 3> colorOf(int32_t id)

Parameters

ParameterDescription
id (in)Non-negative id.

Returns The RGB color colorize() gives id (alpha is 255).

Public attributes ​

kBackground ​

cpp
static constexpr int32_t kBackground

Pixel value where nothing was hit, in every image.

kNotWorldObject ​

cpp
static constexpr int32_t kNotWorldObject

Object and body image value of rayrai visuals that are not RaiSim objects.

Inherited members ​

From raisim::Sensor: getArticulatedSystem, getFrameId, getFrameOrientation, getFramePosition, getFullName, getMeasurementSource, getName, getOrientation, getOriInSensorFrame, getPosInSensorFrame, getPosition, getSensorSetModel, getSerialNumber, getUpdateRate, getUpdateTimeStamp, isUpdateDue, lock, lockMutex, MeasurementSource, serializeMeasurements, setAttachmentFrame, setMeasurementSource, setSerialNumber, setUpdateRate, setUpdateTimeStamp, try_lock, Type, unlock, unlockMutex, updatePose

RaiSim — physics for robotics and AI.