I want to publish a 3D array as a std_msgs::Float32MultiArray in ROS. It should have the dimensions [1920,1080,10], which corresponds to [image_width, image_height, depth]. However, I didn't find a clear documentation on how to initialize and fill this multi-array. Here is what I did so far:
std_msgs::Float32MultiArray my_array;
my_array.layout.dim.push_back(std_msgs::MultiArrayDimension());
my_array.layout.dim[0].label = "width";
my_array.layout.dim[0].size = 1920;
my_array.layout.dim.push_back(std_msgs::MultiArrayDimension());
my_array.layout.dim[1].label = "height";
my_array.layout.dim[1].size = 1080;
my_array.layout.dim.push_back(std_msgs::MultiArrayDimension());
my_array.layout.dim[2].label = "depth";
my_array.layout.dim[2].size = 10;
my_array.layout.data_offset = 0;
my_array.data.clear();
// Initialize the data with 0
// ???
// Fill in values from a list to this array
// PSEUDOCODE
for (point &p : 3d_points_buffer)
{
// Fill the array like this:
//my_array[p.x, p.y, p.z] = p.value;
//???
}
Unfortunately, this is as far as I get. Could anyone show me how I could initialize the whole data array with zeros and how to set a specific entry my_array[x,y,z] to a certain value?
Thank you very much!