Point Cloud Library (PCL)  1.11.0
ascii_io.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012-, Open Perception, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #pragma once
39 
40 #include <pcl/pcl_macros.h>
41 #include <pcl/io/file_io.h>
42 #include <pcl/PCLPointField.h>
43 #include <pcl/common/io.h>
44 
45 
46 namespace pcl
47 {
48  /** \brief Ascii Point Cloud Reader.
49  * Read any ASCII file by setting the separating characters and input point fields.
50  *
51  * \author Adam Stambler (adasta@gmail.com)
52  * \ingroup io
53  */
55  {
56  public:
59  using FileReader::read;
60 
61  /* Load only the meta information (number of points, their types, etc),
62  * and not the points themselves, from a given FILE file. Useful for fast
63  * evaluation of the underlying data structure.
64  *
65  * Returns:
66  * * < 0 (-1) on error
67  * * > 0 on success
68  * \param[in] file_name the name of the file to load
69  * \param[out] cloud the resultant point cloud dataset (only the header will be filled)
70  * \param[out] origin the sensor acquisition origin (only for > FILE_V7 - null if not present)
71  * \param[out] orientation the sensor acquisition orientation (only for > FILE_V7 - identity if not present)
72  * \param[out] file_version the FILE version of the file (either FILE_V6 or FILE_V7)
73  * \param[out] data_type the type of data (binary data=1, ascii=0, etc)
74  * \param[out] data_idx the offset of cloud data within the file
75  * \param[in] offset the offset in the file where to expect the true header to begin.
76  * One usage example for setting the offset parameter is for reading
77  * data from a TAR "archive containing multiple files: TAR files always
78  * add a 512 byte header in front of the actual file, so set the offset
79  * to the next byte after the header (e.g., 513).
80  */
81  int
82  readHeader (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
83  Eigen::Vector4f &origin, Eigen::Quaternionf &orientation,
84  int &file_version, int &data_type, unsigned int &data_idx, const int offset = 0) override ;
85 
86 
87  /** \brief Read a point cloud data from a FILE file and store it into a pcl/PCLPointCloud2.
88  * \param[in] file_name the name of the file containing the actual PointCloud data
89  * \param[out] cloud the resultant PointCloud message read from disk
90  * \param[out] origin the sensor acquisition origin (only for > FILE_V7 - null if not present)
91  * \param[out] orientation the sensor acquisition orientation (only for > FILE_V7 - identity if not present)
92  * \param[out] file_version the FILE version of the file (either FILE_V6 or FILE_V7)
93  * \param[in] offset the offset in the file where to expect the true header to begin.
94  * One usage example for setting the offset parameter is for reading
95  * data from a TAR "archive containing multiple files: TAR files always
96  * add a 512 byte header in front of the actual file, so set the offset
97  * to the next byte after the header (e.g., 513).
98  */
99  int
100  read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
101  Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &file_version,
102  const int offset = 0) override;
103 
104  /** \brief Set the ascii file point fields.
105  */
106  template<typename PointT>
107  void setInputFields ();
108 
109  /** \brief Set the ascii file point fields using a list of fields.
110  * \param[in] fields is a list of point fields, in order, in the input ascii file
111  */
112  void
113  setInputFields (const std::vector<pcl::PCLPointField>& fields);
114 
115 
116  /** \brief Set the ascii file point fields using a point type.
117  * \param[in] p a point type
118  */
119  template<typename PointT>
120  PCL_DEPRECATED(1, 12, "use parameterless setInputFields<PointT>() instead")
121  inline void setInputFields (const PointT p)
122  {
123  (void) p;
124  setInputFields<PointT> ();
125  }
126 
127 
128  /** \brief Set the Separating characters for the ascii point fields 2.
129  * \param[in] chars string of separating characters
130  * Sets the separating characters for the point fields. The
131  * default separating characters are " \n\t,"
132  */
133  void
134  setSepChars (const std::string &chars);
135 
136  /** \brief Set the extension of the ascii point file type.
137  * \param[in] ext extension (example : ".txt" or ".xyz" )
138  */
139  void
140  setExtension (const std::string &ext) { extension_ = ext; }
141 
142  protected:
143  std::string sep_chars_;
144  std::string extension_;
145  std::vector<pcl::PCLPointField> fields_;
146  std::string name_;
147 
148 
149  /** \brief Parses token based on field type.
150  * \param[in] token string representation of point fields
151  * \param[in] field token point field type
152  * \param[out] data_target address that the point field data should be assigned to
153  * returns the size of the parsed point field in bytes
154  */
155  int
156  parse (const std::string& token, const pcl::PCLPointField& field, std::uint8_t* data_target);
157 
158  /** \brief Returns the size in bytes of a point field type.
159  * \param[in] type point field type
160  * returns the size of the type in bytes
161  */
163  typeSize (int type);
164  };
165 }
166 
167 #include <pcl/io/impl/ascii_io.hpp>
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl
Definition: convolution.h:46
pcl::uint32_t
std::uint32_t uint32_t
Definition: types.h:58
pcl::FileReader::read
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.
pcl::ASCIIReader
Ascii Point Cloud Reader.
Definition: ascii_io.h:55
pcl::ASCIIReader::setExtension
void setExtension(const std::string &ext)
Set the extension of the ascii point file type.
Definition: ascii_io.h:140
pcl::ASCIIReader::extension_
std::string extension_
Definition: ascii_io.h:144
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:629
PCL_DEPRECATED
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major....
Definition: pcl_macros.h:150
pcl::ASCIIReader::sep_chars_
std::string sep_chars_
Definition: ascii_io.h:143
pcl::ASCIIReader::setSepChars
void setSepChars(const std::string &chars)
Set the Separating characters for the ascii point fields 2.
pcl::ASCIIReader::ASCIIReader
ASCIIReader()
pcl::ASCIIReader::setInputFields
void setInputFields(const std::vector< pcl::PCLPointField > &fields)
Set the ascii file point fields using a list of fields.
pcl::ASCIIReader::name_
std::string name_
Definition: ascii_io.h:146
pcl::ASCIIReader::parse
int parse(const std::string &token, const pcl::PCLPointField &field, std::uint8_t *data_target)
Parses token based on field type.
pcl::FileReader
Point Cloud Data (FILE) file format reader interface.
Definition: file_io.h:56
pcl::ASCIIReader::~ASCIIReader
~ASCIIReader()
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:16
pcl::uint8_t
std::uint8_t uint8_t
Definition: types.h:54
pcl::ASCIIReader::readHeader
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) override
Read a point cloud data header from a FILE file.
pcl::PCLPointField
Definition: PCLPointField.h:12
pcl::ASCIIReader::typeSize
std::uint32_t typeSize(int type)
Returns the size in bytes of a point field type.
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:331
pcl::ASCIIReader::fields_
std::vector< pcl::PCLPointField > fields_
Definition: ascii_io.h:145
pcl::ASCIIReader::read
int read(const std::string &file_name, pcl::PCLPointCloud2 &cloud, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &file_version, const int offset=0) override
Read a point cloud data from a FILE file and store it into a pcl/PCLPointCloud2.