Point Cloud Library (PCL)  1.10.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/io/file_io.h>
41 #include <pcl/PCLPointField.h>
42 #include <pcl/common/io.h>
43 
44 
45 namespace pcl
46 {
47  /** \brief Ascii Point Cloud Reader.
48  * Read any ASCII file by setting the separating characters and input point fields.
49  *
50  * \author Adam Stambler (adasta@gmail.com)
51  * \ingroup io
52  */
54  {
55  public:
56  ASCIIReader ();
57  ~ASCIIReader ();
58  using FileReader::read;
59 
60  /* Load only the meta information (number of points, their types, etc),
61  * and not the points themselves, from a given FILE file. Useful for fast
62  * evaluation of the underlying data structure.
63  *
64  * Returns:
65  * * < 0 (-1) on error
66  * * > 0 on success
67  * \param[in] file_name the name of the file to load
68  * \param[out] cloud the resultant point cloud dataset (only the header will be filled)
69  * \param[out] origin the sensor acquisition origin (only for > FILE_V7 - null if not present)
70  * \param[out] orientation the sensor acquisition orientation (only for > FILE_V7 - identity if not present)
71  * \param[out] file_version the FILE version of the file (either FILE_V6 or FILE_V7)
72  * \param[out] data_type the type of data (binary data=1, ascii=0, etc)
73  * \param[out] data_idx the offset of cloud data within the file
74  * \param[in] offset the offset in the file where to expect the true header to begin.
75  * One usage example for setting the offset parameter is for reading
76  * data from a TAR "archive containing multiple files: TAR files always
77  * add a 512 byte header in front of the actual file, so set the offset
78  * to the next byte after the header (e.g., 513).
79  */
80  int
81  readHeader (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
82  Eigen::Vector4f &origin, Eigen::Quaternionf &orientation,
83  int &file_version, int &data_type, unsigned int &data_idx, const int offset = 0) override ;
84 
85 
86  /** \brief Read a point cloud data from a FILE file and store it into a pcl/PCLPointCloud2.
87  * \param[in] file_name the name of the file containing the actual PointCloud data
88  * \param[out] cloud the resultant PointCloud message read from disk
89  * \param[out] origin the sensor acquisition origin (only for > FILE_V7 - null if not present)
90  * \param[out] orientation the sensor acquisition orientation (only for > FILE_V7 - identity if not present)
91  * \param[out] file_version the FILE version of the file (either FILE_V6 or FILE_V7)
92  * \param[in] offset the offset in the file where to expect the true header to begin.
93  * One usage example for setting the offset parameter is for reading
94  * data from a TAR "archive containing multiple files: TAR files always
95  * add a 512 byte header in front of the actual file, so set the offset
96  * to the next byte after the header (e.g., 513).
97  */
98  int
99  read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
100  Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &file_version,
101  const int offset = 0) override;
102 
103  /** \brief Set the ascii file point fields.
104  */
105  template<typename PointT>
106  void setInputFields ();
107 
108  /** \brief Set the ascii file point fields using a list of fields.
109  * \param[in] fields is a list of point fields, in order, in the input ascii file
110  */
111  void
112  setInputFields (const std::vector<pcl::PCLPointField>& fields);
113 
114 
115  /** \brief Set the ascii file point fields using a point type.
116  * \param[in] p a point type
117  */
118  template<typename PointT>
119  [[deprecated("use parameterless setInputFields<PointT>() instead")]]
120  inline void setInputFields (const PointT p)
121  {
122  (void) p;
123  setInputFields<PointT> ();
124  }
125 
126 
127  /** \brief Set the Separating characters for the ascii point fields 2.
128  * \param[in] chars string of separating characters
129  * Sets the separating characters for the point fields. The
130  * default separating characters are " \n\t,"
131  */
132  void
133  setSepChars (const std::string &chars);
134 
135  /** \brief Set the extension of the ascii point file type.
136  * \param[in] ext extension (example : ".txt" or ".xyz" )
137  */
138  void
139  setExtension (const std::string &ext) { extension_ = ext; }
140 
141  protected:
142  std::string sep_chars_;
143  std::string extension_;
144  std::vector<pcl::PCLPointField> fields_;
145  std::string name_;
146 
147 
148  /** \brief Parses token based on field type.
149  * \param[in] token string representation of point fields
150  * \param[in] field token point field type
151  * \param[out] data_target address that the point field data should be assigned to
152  * returns the size of the parsed point field in bytes
153  */
154  int
155  parse (const std::string& token, const pcl::PCLPointField& field, std::uint8_t* data_target);
156 
157  /** \brief Returns the size in bytes of a point field type.
158  * \param[in] type point field type
159  * returns the size of the type in bytes
160  */
162  typeSize (int type);
163  };
164 }
165 
166 #include <pcl/io/impl/ascii_io.hpp>
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::uint32_t
std::uint32_t uint32_t
Definition: pcl_macros.h:96
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:53
pcl::ASCIIReader::setExtension
void setExtension(const std::string &ext)
Set the extension of the ascii point file type.
Definition: ascii_io.h:139
pcl::ASCIIReader::setInputFields
void setInputFields(const PointT p)
Set the ascii file point fields using a point type.
Definition: ascii_io.h:120
pcl::ASCIIReader::extension_
std::string extension_
Definition: ascii_io.h:143
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:623
pcl::read
void read(std::istream &stream, Type &value)
Function for reading data from a stream.
Definition: region_xy.h:46
pcl::ASCIIReader::sep_chars_
std::string sep_chars_
Definition: ascii_io.h:142
pcl::ASCIIReader::name_
std::string name_
Definition: ascii_io.h:145
pcl::FileReader
Point Cloud Data (FILE) file format reader interface.
Definition: file_io.h:55
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:19
pcl::uint8_t
std::uint8_t uint8_t
Definition: pcl_macros.h:92
pcl::PCLPointField
Definition: PCLPointField.h:14
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:253
pcl::ASCIIReader::fields_
std::vector< pcl::PCLPointField > fields_
Definition: ascii_io.h:144