40 #include <pcl/conversions.h>
41 #include <pcl/point_cloud.h>
42 #include <pcl/PCLPointCloud2.h>
45 #include <Eigen/Geometry>
46 #include <boost/numeric/conversion/cast.hpp>
47 #include <boost/algorithm/string/predicate.hpp>
87 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation,
88 int &file_version,
int &data_type,
unsigned int &data_idx,
const int offset = 0) = 0;
104 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation,
int &file_version,
105 const int offset = 0) = 0;
126 Eigen::Vector4f origin;
127 Eigen::Quaternionf orientation;
129 return (
read (file_name, cloud, origin, orientation, file_version, offset));
141 template<
typename Po
intT>
inline int
147 file_version, offset);
181 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
182 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (),
183 const bool binary =
false) = 0;
195 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
196 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (),
197 const bool binary =
false)
199 return (
write (file_name, *cloud, origin, orientation, binary));
208 template<
typename Po
intT>
inline int
209 write (
const std::string &file_name,
211 const bool binary =
false)
220 return (
write (file_name, blob, origin, orientation, binary));
235 template <
typename Type>
inline
236 std::enable_if_t<std::is_floating_point<Type>::value>
239 const int point_size,
240 const unsigned int field_idx,
241 const unsigned int fields_count,
242 std::ostream &stream)
245 memcpy (&value, &cloud.
data[point_index * point_size + cloud.
fields[field_idx].offset + fields_count * sizeof (Type)],
sizeof (Type));
246 if (std::isnan (value))
252 template <
typename Type>
inline
253 std::enable_if_t<std::is_integral<Type>::value>
256 const int point_size,
257 const unsigned int field_idx,
258 const unsigned int fields_count,
259 std::ostream &stream)
262 memcpy (&value, &cloud.
data[point_index * point_size + cloud.
fields[field_idx].offset + fields_count * sizeof (Type)],
sizeof (Type));
266 template <>
inline void
269 const int point_size,
270 const unsigned int field_idx,
271 const unsigned int fields_count,
272 std::ostream &stream)
275 memcpy (&value, &cloud.
data[point_index * point_size + cloud.
fields[field_idx].offset + fields_count * sizeof (std::int8_t)],
sizeof (std::int8_t));
277 stream << boost::numeric_cast<int>(value);
280 template <>
inline void
283 const int point_size,
284 const unsigned int field_idx,
285 const unsigned int fields_count,
286 std::ostream &stream)
289 memcpy (&value, &cloud.
data[point_index * point_size + cloud.
fields[field_idx].offset + fields_count * sizeof (std::uint8_t)],
sizeof (std::uint8_t));
291 stream << boost::numeric_cast<unsigned int>(value);
304 template <
typename Type>
inline
305 std::enable_if_t<std::is_floating_point<Type>::value,
bool>
308 const int point_size,
309 const unsigned int field_idx,
310 const unsigned int fields_count)
313 memcpy (&value, &cloud.
data[point_index * point_size + cloud.
fields[field_idx].offset + fields_count * sizeof (Type)],
sizeof (Type));
314 return std::isfinite (value);
317 template <
typename Type>
inline
318 std::enable_if_t<std::is_integral<Type>::value,
bool>
329 template <
typename Type>
334 unsigned int field_idx,
335 unsigned int fields_count,
336 std::istringstream& is)
339 if (boost::iequals(st,
"nan")) {
340 value = std::numeric_limits<Type>::quiet_NaN();
347 value =
static_cast<Type
>(atof(st.c_str()));
351 fields_count *
sizeof(Type)],
352 reinterpret_cast<char*
>(&value),
358 copyStringValue<std::int8_t>(
const std::string& st,
361 unsigned int field_idx,
362 unsigned int fields_count,
363 std::istringstream& is)
371 val =
static_cast<int>(atof(st.c_str()));
373 value =
static_cast<std::int8_t
>(val);
376 fields_count *
sizeof(std::int8_t)],
377 reinterpret_cast<char*
>(&value),
378 sizeof(std::int8_t));
383 copyStringValue<std::uint8_t>(
const std::string& st,
386 unsigned int field_idx,
387 unsigned int fields_count,
388 std::istringstream& is)
397 val =
static_cast<int>(atof(st.c_str()));
399 value =
static_cast<std::uint8_t
>(val);
402 fields_count *
sizeof(std::uint8_t)],
403 reinterpret_cast<char*
>(&value),
404 sizeof(std::uint8_t));
419 template <
typename Type>
inline void
421 pcl::index_t point_index,
unsigned int field_idx,
unsigned int fields_count)
423 std::istringstream is;
424 is.imbue (std::locale::classic ());
425 detail::copyStringValue<Type> (st, cloud,point_index, field_idx, fields_count, is);
439 template <
typename Type>
inline void
441 pcl::index_t point_index,
unsigned int field_idx,
unsigned int fields_count,
442 std::istringstream& is)
444 detail::copyStringValue<Type> (st, cloud,point_index, field_idx, fields_count, is);
Point Cloud Data (FILE) file format reader interface.
virtual int read(const std::string &file_name, pcl::PCLPointCloud2 &cloud, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &file_version, const int offset=0)=0
Read a point cloud data from a FILE file and store it into a pcl/PCLPointCloud2.
FileReader()=default
empty constructor
int read(const std::string &file_name, pcl::PointCloud< PointT > &cloud, const int offset=0)
Read a point cloud data from any FILE file, and convert it to the given template format.
int read(const std::string &file_name, pcl::PCLPointCloud2 &cloud, const int offset=0)
Read a point cloud data from a FILE file (FILE_V6 only!) and store it into a pcl/PCLPointCloud2.
virtual ~FileReader()=default
empty destructor
virtual int readHeader(const std::string &file_name, pcl::PCLPointCloud2 &cloud, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &file_version, int &data_type, unsigned int &data_idx, const int offset=0)=0
Read a point cloud data header from a FILE file.
Point Cloud Data (FILE) file format writer.
virtual int write(const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), const bool binary=false)=0
Save point cloud data to a FILE file containing n-D points.
FileWriter()=default
Empty constructor.
int write(const std::string &file_name, const pcl::PointCloud< PointT > &cloud, const bool binary=false)
Save point cloud data to a FILE file containing n-D points.
virtual ~FileWriter()=default
Empty destructor.
int write(const std::string &file_name, const pcl::PCLPointCloud2::ConstPtr &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), const bool binary=false)
Save point cloud data to a FILE file containing n-D points.
PointCloud represents the base class in PCL for storing collections of 3D points.
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
void copyStringValue(const std::string &st, pcl::PCLPointCloud2 &cloud, pcl::index_t point_index, unsigned int field_idx, unsigned int fields_count, std::istringstream &is)
void read(std::istream &stream, Type &value)
Function for reading data from a stream.
std::enable_if_t< std::is_floating_point< Type >::value, bool > isValueFinite(const pcl::PCLPointCloud2 &cloud, const pcl::index_t point_index, const int point_size, const unsigned int field_idx, const unsigned int fields_count)
Check whether a given value of type Type (uchar, char, uint, int, float, double, ....
std::enable_if_t< std::is_floating_point< Type >::value > copyValueString(const pcl::PCLPointCloud2 &cloud, const pcl::index_t point_index, const int point_size, const unsigned int field_idx, const unsigned int fields_count, std::ostream &stream)
inserts a value of type Type (uchar, char, uint, int, float, double, ...) into a stringstream.
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
void copyStringValue(const std::string &st, pcl::PCLPointCloud2 &cloud, pcl::index_t point_index, unsigned int field_idx, unsigned int fields_count)
Copy one single value of type T (uchar, char, uint, int, float, double, ...) from a string.
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map, const std::uint8_t *msg_data)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
void toPCLPointCloud2(const pcl::PointCloud< PointT > &cloud, pcl::PCLPointCloud2 &msg, bool padding)
Convert a pcl::PointCloud<T> object to a PCLPointCloud2 binary data blob.
void write(std::ostream &stream, Type value)
Function for writing data to a stream.
std::vector<::pcl::PCLPointField > fields
std::vector< std::uint8_t > data
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr