44 #include <pcl/common/io.h>
45 #include <pcl/io/file_io.h>
46 #include <pcl/io/ply/ply_parser.h>
47 #include <pcl/PolygonMesh.h>
90 : origin_ (
Eigen::Vector4f::Zero ())
91 , orientation_ (
Eigen::Matrix3f::Identity ())
95 : origin_ (
Eigen::Vector4f::Zero ())
96 , orientation_ (
Eigen::Matrix3f::Identity ())
105 orientation_ = p.orientation_;
106 range_grid_ = p.range_grid_;
107 polygons_ = p.polygons_;
136 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation,
137 int &ply_version,
int &data_type,
unsigned int &data_idx,
const int offset = 0)
override;
153 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation,
int& ply_version,
const int offset = 0)
override;
168 Eigen::Vector4f origin;
169 Eigen::Quaternionf orientation;
171 return read (file_name, cloud, origin, orientation, ply_version, offset);
183 template<
typename Po
intT>
inline int
189 ply_version, offset);
213 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation,
214 int& ply_version,
const int offset = 0);
233 parse (
const std::string& istream_filename);
241 infoCallback (
const std::string& filename, std::size_t line_number,
const std::string& message)
243 PCL_DEBUG (
"[pcl::PLYReader] %s:%lu: %s\n", filename.c_str (), line_number, message.c_str ());
252 warningCallback (
const std::string& filename, std::size_t line_number,
const std::string& message)
254 PCL_WARN (
"[pcl::PLYReader] %s:%lu: %s\n", filename.c_str (), line_number, message.c_str ());
263 errorCallback (
const std::string& filename, std::size_t line_number,
const std::string& message)
265 PCL_ERROR (
"[pcl::PLYReader] %s:%lu: %s\n", filename.c_str (), line_number, message.c_str ());
272 std::tuple<std::function<void ()>, std::function<void ()> >
273 elementDefinitionCallback (
const std::string& element_name, std::size_t count);
276 endHeaderCallback ();
282 template <
typename ScalarType> std::function<void (ScalarType)>
283 scalarPropertyDefinitionCallback (
const std::string& element_name,
const std::string& property_name);
289 template <
typename SizeType,
typename ScalarType>
290 std::tuple<std::function<void (SizeType)>, std::function<void (ScalarType)>, std::function<void ()> >
291 listPropertyDefinitionCallback (
const std::string& element_name,
const std::string& property_name);
296 template <
typename SizeType>
void
297 vertexListPropertyBeginCallback (
const std::string& property_name, SizeType size);
302 template <
typename ContentType>
void
303 vertexListPropertyContentCallback (ContentType value);
307 vertexListPropertyEndCallback ();
313 template<
typename Scalar>
void
314 vertexScalarPropertyCallback (Scalar value);
343 originXCallback (
const float& value) { origin_[0] = value; }
349 originYCallback (
const float& value) { origin_[1] = value; }
355 originZCallback (
const float& value) { origin_[2] = value; }
361 orientationXaxisXCallback (
const float& value) { orientation_ (0,0) = value; }
367 orientationXaxisYCallback (
const float& value) { orientation_ (0,1) = value; }
373 orientationXaxisZCallback (
const float& value) { orientation_ (0,2) = value; }
379 orientationYaxisXCallback (
const float& value) { orientation_ (1,0) = value; }
385 orientationYaxisYCallback (
const float& value) { orientation_ (1,1) = value; }
391 orientationYaxisZCallback (
const float& value) { orientation_ (1,2) = value; }
397 orientationZaxisXCallback (
const float& value) { orientation_ (2,0) = value; }
403 orientationZaxisYCallback (
const float& value) { orientation_ (2,1) = value; }
409 orientationZaxisZCallback (
const float& value) { orientation_ (2,2) = value; }
415 cloudHeightCallback (
const int &height) { cloud_->height = height; }
421 cloudWidthCallback (
const int &width) { cloud_->width = width; }
428 template<
typename Scalar>
void
429 appendScalarProperty (
const std::string& name,
const std::size_t& count = 1);
440 amendProperty (
const std::string& old_name,
const std::string& new_name, std::uint8_t datatype = 0);
444 vertexBeginCallback ();
448 vertexEndCallback ();
452 rangeGridBeginCallback ();
468 rangeGridVertexIndicesEndCallback ();
472 rangeGridEndCallback ();
476 objInfoCallback (
const std::string& line);
480 faceBeginCallback ();
496 faceVertexIndicesEndCallback ();
503 Eigen::Vector4f origin_;
506 Eigen::Matrix3f orientation_;
510 std::size_t vertex_count_{0};
511 int vertex_offset_before_{0};
513 std::vector<std::vector <int> > *range_grid_{
nullptr};
514 std::size_t rgb_offset_before_{0};
515 bool do_resize_{
false};
517 std::vector<pcl::Vertices> *polygons_{
nullptr};
523 std::int32_t r_{0}, g_{0}, b_{0};
525 std::uint32_t a_{0}, rgba_{0};
552 const Eigen::Vector4f &origin,
553 const Eigen::Quaternionf &orientation,
555 bool use_camera =
true)
557 return (generateHeader (cloud, origin, orientation,
true, use_camera, valid_points));
571 const Eigen::Vector4f &origin,
572 const Eigen::Quaternionf &orientation,
574 bool use_camera =
true)
576 return (generateHeader (cloud, origin, orientation,
false, use_camera, valid_points));
590 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
591 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (),
593 bool use_camera =
true);
604 const Eigen::Vector4f& origin = Eigen::Vector4f::Zero (),
const Eigen::Quaternionf& orientation= Eigen::Quaternionf::Identity (),
605 bool use_camera=
true);
617 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
618 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (),
619 bool use_camera =
true);
631 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
632 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (),
633 const bool binary =
false)
override
636 return (this->writeBinary (file_name, cloud, origin, orientation,
true));
637 return (this->writeASCII (file_name, cloud, origin, orientation, 8,
true));
652 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
653 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (),
655 bool use_camera =
true)
658 return (this->writeBinary (file_name, cloud, origin, orientation, use_camera));
659 return (this->writeASCII (file_name, cloud, origin, orientation, 8, use_camera));
674 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
675 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (),
677 bool use_camera =
true)
679 return (
write (file_name, *cloud, origin, orientation, binary, use_camera));
690 template<
typename Po
intT>
inline int
691 write (
const std::string &file_name,
694 bool use_camera =
true)
703 return (this->
write (file_name, blob, origin, orientation, binary, use_camera));
713 const Eigen::Vector4f &origin,
714 const Eigen::Quaternionf &orientation,
720 writeContentWithCameraASCII (
int nr_points,
722 const Eigen::Vector4f &origin,
723 const Eigen::Quaternionf &orientation,
727 writeContentWithRangeGridASCII (
int nr_points,
729 std::ostringstream& fs,
730 int& nb_valid_points);
748 return (p.
read (file_name, cloud));
761 Eigen::Vector4f &origin, Eigen::Quaternionf &orientation)
765 return (p.
read (file_name, cloud, origin, orientation, ply_version));
773 template<
typename Po
intT>
inline int
777 return (p.
read (file_name, cloud));
793 return (p.
read (file_name, mesh));
807 const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
808 const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity (),
809 bool binary_mode =
false,
bool use_camera =
true)
812 return (w.
write (file_name, cloud, origin, orientation, binary_mode, use_camera));
822 template<
typename Po
intT>
inline int
826 return (w.
write<
PointT> (file_name, cloud, binary_mode));
835 template<
typename Po
intT>
inline int
839 return (w.
write<
PointT> (file_name, cloud,
false));
847 template<
typename Po
intT>
inline int
861 template<
typename Po
intT>
int
870 return (w.
write<
PointT> (file_name, cloud_out, binary_mode));
Point Cloud Data (FILE) file format reader interface.
Point Cloud Data (FILE) file format writer.
Point Cloud Data (PLY) file format reader.
int read(const std::string &file_name, pcl::PCLPointCloud2 &cloud, const int offset=0)
Read a point cloud data from a PLY file and store it into a pcl/PCLPointCloud2.
int read(const std::string &file_name, pcl::PointCloud< PointT > &cloud, const int offset=0)
Read a point cloud data from any PLY file, and convert it to the given template format.
int read(const std::string &file_name, pcl::PolygonMesh &mesh, const int offset=0)
Read a point cloud data from a PLY file and store it into a pcl/PolygonMesh.
int read(const std::string &file_name, pcl::PCLPointCloud2 &cloud, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &ply_version, const int offset=0) override
Read a point cloud data from a PLY file and store it into a pcl/PCLPointCloud2.
PLYReader(const PLYReader &p)
int readHeader(const std::string &file_name, pcl::PCLPointCloud2 &cloud, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &ply_version, int &data_type, unsigned int &data_idx, const int offset=0) override
Read a point cloud data header from a PLY file.
int read(const std::string &file_name, pcl::PolygonMesh &mesh, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &ply_version, const int offset=0)
Read a point cloud data from a PLY file and store it into a pcl/PolygonMesh.
Point Cloud Data (PLY) file format writer.
std::string generateHeaderBinary(const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin, const Eigen::Quaternionf &orientation, int valid_points, bool use_camera=true)
Generate the header of a PLY v.7 file format.
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(), bool binary=false, bool use_camera=true)
Save point cloud data to a PLY file containing n-D points.
int writeBinary(const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), bool use_camera=true)
Save point cloud data to a PLY file containing n-D points, in BINARY format.
~PLYWriter() override=default
Destructor.
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) override
Save point cloud data to a PLY file containing n-D points.
int write(const std::string &file_name, const pcl::PointCloud< PointT > &cloud, bool binary=false, bool use_camera=true)
Save point cloud data to a PLY file containing n-D points.
int writeBinary(std::ostream &os, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), bool use_camera=true)
Save point cloud data to a std::ostream containing n-D points, in BINARY format.
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(), bool binary=false, bool use_camera=true)
Save point cloud data to a PLY file containing n-D points.
std::string generateHeaderASCII(const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin, const Eigen::Quaternionf &orientation, int valid_points, bool use_camera=true)
Generate the header of a PLY v.7 file format.
int writeASCII(const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), int precision=8, bool use_camera=true)
Save point cloud data to a PLY file containing n-D points, in ASCII format.
PLYWriter()=default
Constructor.
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).
Class ply_parser parses a PLY file and generates appropriate atomic parsers for the body.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
void copyPointCloud(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
Copy all the fields from a given point cloud into a new point cloud.
int savePLYFileBinary(const std::string &file_name, const pcl::PointCloud< PointT > &cloud)
Templated version for saving point cloud data to a PLY file containing a specific given cloud format.
int savePLYFileASCII(const std::string &file_name, const pcl::PointCloud< PointT > &cloud)
Templated version for saving point cloud data to a PLY file containing a specific given cloud format.
int loadPLYFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud)
Load a PLY v.6 file into a PCLPointCloud2 type.
int savePLYFile(const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), bool binary_mode=false, bool use_camera=true)
Save point cloud data to a PLY file containing n-D points.
Defines functions, macros and traits for allocating and using memory.
void read(std::istream &stream, Type &value)
Function for reading data from a stream.
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.
IndicesAllocator<> Indices
Type used for indices in PCL.
void write(std::ostream &stream, Type value)
Function for writing data to a stream.
Defines all the PCL and non-PCL macros used.
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.