-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for dynamic PointCloud2 creation #108
base: jade-devel
Are you sure you want to change the base?
Changes from 2 commits
8911f10
7928bb5
89bb853
695b643
71b7b42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,9 +161,23 @@ class PointCloud2Modifier | |
* WARNING: THIS FUNCTION DOES ADD ANY NECESSARY PADDING TRANSPARENTLY | ||
*/ | ||
void setPointCloud2FieldsByString(int n_fields, ...); | ||
|
||
class PointFieldInfo{ | ||
public: | ||
PointFieldInfo(std::string name, std::string datatype) | ||
: name(name), datatype(datatype){} | ||
std::string name; | ||
std::string datatype; | ||
}; | ||
|
||
void addPointCloud2Fields(std::vector<PointFieldInfo> fields); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mirror the setPointCloud2Fields API here instead of defining a new datatype. |
||
bool addPointCloud2Field(std::string name, std::string datatype); | ||
|
||
protected: | ||
/** A reference to the original sensor_msgs::PointCloud2 that we read */ | ||
PointCloud2& cloud_msg_; | ||
/** The current offset for all point fields */ | ||
int current_offset_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to mirror the local storage of cloud_msg_.point_step ? Can you not query, mutate and reset without adding another data field? |
||
}; | ||
|
||
namespace impl | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ | |
#ifndef SENSOR_MSGS_POINT_FIELD_CONVERSION_H | ||
#define SENSOR_MSGS_POINT_FIELD_CONVERSION_H | ||
|
||
#include<string> | ||
|
||
/** | ||
* \brief This file provides a type to enum mapping for the different | ||
* PointField types and methods to read and write in | ||
|
@@ -79,6 +81,51 @@ namespace sensor_msgs{ | |
template<> struct typeAsPointFieldType<float> { static const uint8_t value = sensor_msgs::PointField::FLOAT32; }; | ||
template<> struct typeAsPointFieldType<double> { static const uint8_t value = sensor_msgs::PointField::FLOAT64; }; | ||
|
||
/*! | ||
* \Type names of the PointField data type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add docblock info for the parameter like the other functions. |
||
*/ | ||
int getPointFieldTypeFromString(const std::string field_name){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is not templated it needs to be inline with the implementation in the header. Also please switch to a const reference instead of pass by value of the string. |
||
if(field_name == "int8") return sensor_msgs::PointField::INT8; | ||
if(field_name == "uint8") return sensor_msgs::PointField::UINT8; | ||
if(field_name == "int16") return sensor_msgs::PointField::INT16; | ||
if(field_name == "uint16") return sensor_msgs::PointField::UINT16; | ||
if(field_name == "int32") return sensor_msgs::PointField::INT32; | ||
if(field_name == "uint32") return sensor_msgs::PointField::UINT32; | ||
if(field_name == "float32") return sensor_msgs::PointField::FLOAT32; | ||
if(field_name == "float64") return sensor_msgs::PointField::FLOAT64; | ||
|
||
std::cerr << "Unknown type: \"" << field_name << "\"! Supported types are: int8, uint8, int16, uint16, int32, uint32, float32, float64" << std::endl; | ||
return -1; | ||
} | ||
|
||
/** Return the size of a datatype (which is an enum of sensor_msgs::PointField::) in bytes | ||
* @param datatype one of the enums of sensor_msgs::PointField:: | ||
*/ | ||
inline int sizeOfPointField(int datatype) | ||
{ | ||
switch(datatype){ | ||
case sensor_msgs::PointField::INT8: | ||
return sizeof( pointFieldTypeAsType<sensor_msgs::PointField::INT8>::type ); | ||
case sensor_msgs::PointField::UINT8: | ||
return sizeof( pointFieldTypeAsType<sensor_msgs::PointField::UINT8>::type ); | ||
case sensor_msgs::PointField::INT16: | ||
return sizeof( pointFieldTypeAsType<sensor_msgs::PointField::INT16>::type ); | ||
case sensor_msgs::PointField::UINT16: | ||
return sizeof( pointFieldTypeAsType<sensor_msgs::PointField::UINT16>::type ); | ||
case sensor_msgs::PointField::INT32: | ||
return sizeof( pointFieldTypeAsType<sensor_msgs::PointField::INT32>::type ); | ||
case sensor_msgs::PointField::UINT32: | ||
return sizeof( pointFieldTypeAsType<sensor_msgs::PointField::UINT32>::type ); | ||
case sensor_msgs::PointField::FLOAT32: | ||
return sizeof( pointFieldTypeAsType<sensor_msgs::PointField::FLOAT32>::type ); | ||
case sensor_msgs::PointField::FLOAT64: | ||
return sizeof( pointFieldTypeAsType<sensor_msgs::PointField::FLOAT64>::type ); | ||
default: | ||
std::cerr << "unknown datatype with the number: " << datatype; | ||
return -1; | ||
} | ||
} | ||
|
||
/*! | ||
* \Converts a value at the given pointer position, interpreted as the datatype | ||
* specified by the given template argument point_field_type, to the given | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this is void not at least bool?