Point Cloud Library (PCL)  1.9.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
ifs_io.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2013, 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 #ifndef PCL_IO_IFS_IO_H_
39 #define PCL_IO_IFS_IO_H_
40 
41 #include <pcl/point_cloud.h>
42 #include <pcl/PCLPointCloud2.h>
43 #include <pcl/conversions.h>
44 #include <pcl/io/boost.h>
45 #include <pcl/PolygonMesh.h>
46 
47 namespace pcl
48 {
49  /** \brief Indexed Face set (IFS) file format reader. This file format is used for
50  * the Brown Mesh Set for instance.
51  * \author Nizar Sallem
52  * \ingroup io
53  */
54  class PCL_EXPORTS IFSReader
55  {
56  public:
57  /** Empty constructor */
58  IFSReader () {}
59  /** Empty destructor */
60  ~IFSReader () {}
61 
62  /** \brief we support two versions
63  * 1.0 classic
64  * 1.1 with texture coordinates addon
65  */
66  enum
67  {
68  IFS_V1_0 = 0,
69  IFS_V1_1 = 1
70  };
71 
72  /** \brief Read a point cloud data header from an IFS file.
73  *
74  * Load only the meta information (number of points, their types, etc),
75  * and not the points themselves, from a given IFS file. Useful for fast
76  * evaluation of the underlying data structure.
77  *
78  * \param[in] file_name the name of the file to load
79  * \param[out] cloud the resultant point cloud dataset (only header will be filled)
80  * \param[out] ifs_version the IFS version of the file (IFS_V1_0 or IFS_V1_1)
81  * \param[out] data_idx the offset of cloud data within the file
82  *
83  * \return
84  * * < 0 (-1) on error
85  * * == 0 on success
86  */
87  int
88  readHeader (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
89  int &ifs_version, unsigned int &data_idx);
90 
91  /** \brief Read a point cloud data from an IFS file and store it into a pcl/PCLPointCloud2.
92  * \param[in] file_name the name of the file containing the actual PointCloud data
93  * \param[out] cloud the resultant PCLPointCloud2 blob read from disk
94  * \param[out] ifs_version the IFS version of the file (either IFS_V1_0 or IFS_V1_1)
95  *
96  * \return
97  * * < 0 (-1) on error
98  * * == 0 on success
99  */
100  int
101  read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, int &ifs_version);
102 
103  /** \brief Read a point cloud data from an IFS file and store it into a PolygonMesh.
104  * \param[in] file_name the name of the file containing the mesh data
105  * \param[out] mesh the resultant PolygonMesh
106  * \param[out] ifs_version the IFS version of the file (either IFS_V1_0 or IFS_V1_1)
107  *
108  * \return
109  * * < 0 (-1) on error
110  * * == 0 on success
111  */
112  int
113  read (const std::string &file_name, pcl::PolygonMesh &mesh, int &ifs_version);
114 
115  /** \brief Read a point cloud data from an IFS file, and convert it to the
116  * given template pcl::PointCloud format.
117  * \param[in] file_name the name of the file containing the actual PointCloud data
118  * \param[out] cloud the resultant PointCloud message read from disk
119  *
120  * \return
121  * * < 0 (-1) on error
122  * * == 0 on success
123  */
124  template<typename PointT> int
125  read (const std::string &file_name, pcl::PointCloud<PointT> &cloud)
126  {
127  pcl::PCLPointCloud2 blob;
128  int ifs_version;
129  cloud.sensor_origin_ = Eigen::Vector4f::Zero ();
130  cloud.sensor_orientation_ = Eigen::Quaternionf::Identity ();
131  int res = read (file_name, blob, ifs_version);
132 
133  // If no error, convert the data
134  if (res == 0)
135  pcl::fromPCLPointCloud2 (blob, cloud);
136  return (res);
137  }
138  };
139 
140  /** \brief Point Cloud Data (IFS) file format writer.
141  * \author Nizar Sallem
142  * \ingroup io
143  */
144  class PCL_EXPORTS IFSWriter
145  {
146  public:
149 
150  /** \brief Save point cloud data to an IFS file containing 3D points.
151  * \param[in] file_name the output file name
152  * \param[in] cloud the point cloud data
153  * \param[in] cloud_name the point cloud name to be stored inside the IFS file.
154  *
155  * \return
156  * * 0 on success
157  * * < 0 on error
158  */
159  int
160  write (const std::string &file_name, const pcl::PCLPointCloud2 &cloud,
161  const std::string &cloud_name = "cloud");
162 
163  /** \brief Save point cloud data to an IFS file containing 3D points.
164  * \param[in] file_name the output file name
165  * \param[in] cloud the point cloud
166  * \param[in] cloud_name the point cloud name to be stored inside the IFS file.
167  *
168  * \return
169  * * 0 on success
170  * * < 0 on error
171  */
172  template<typename PointT> int
173  write (const std::string &file_name, const pcl::PointCloud<PointT> &cloud,
174  const std::string &cloud_name = "cloud")
175  {
176  pcl::PCLPointCloud2 blob;
177  pcl::toPCLPointCloud2<PointT> (cloud, blob);
178  return (write (file_name, blob, cloud_name));
179  }
180  };
181 
182  namespace io
183  {
184  /** \brief Load an IFS file into a PCLPointCloud2 blob type.
185  * \param[in] file_name the name of the file to load
186  * \param[out] cloud the resultant templated point cloud
187  * \return 0 on success < 0 on error
188  *
189  * \ingroup io
190  */
191  inline int
192  loadIFSFile (const std::string &file_name, pcl::PCLPointCloud2 &cloud)
193  {
194  pcl::IFSReader p;
195  int ifs_version;
196  return (p.read (file_name, cloud, ifs_version));
197  }
198 
199  /** \brief Load any IFS file into a templated PointCloud type.
200  * \param[in] file_name the name of the file to load
201  * \param[out] cloud the resultant templated point cloud
202  * \return 0 on success < 0 on error
203  *
204  * \ingroup io
205  */
206  template<typename PointT> inline int
207  loadIFSFile (const std::string &file_name, pcl::PointCloud<PointT> &cloud)
208  {
209  pcl::IFSReader p;
210  return (p.read<PointT> (file_name, cloud));
211  }
212 
213  /** \brief Load any IFS file into a PolygonMesh type.
214  * \param[in] file_name the name of the file to load
215  * \param[out] mesh the resultant mesh
216  * \return 0 on success < 0 on error
217  *
218  * \ingroup io
219  */
220  inline int
221  loadIFSFile (const std::string &file_name, pcl::PolygonMesh &mesh)
222  {
223  pcl::IFSReader p;
224  int ifs_version;
225  return (p.read (file_name, mesh, ifs_version));
226  }
227 
228  /** \brief Save point cloud data to an IFS file containing 3D points
229  * \param[in] file_name the output file name
230  * \param[in] cloud the point cloud data message
231  * \return 0 on success < 0 on error
232  *
233  * \ingroup io
234  */
235  inline int
236  saveIFSFile (const std::string &file_name, const pcl::PCLPointCloud2 &cloud)
237  {
238  pcl::IFSWriter w;
239  return (w.write (file_name, cloud));
240  }
241 
242  /** \brief Save point cloud data to an IFS file containing 3D points
243  * \param[in] file_name the output file name
244  * \param[in] cloud the point cloud
245  * \return 0 on success < 0 on error
246  *
247  * \ingroup io
248  */
249  template<typename PointT> int
250  saveIFSFile (const std::string &file_name, const pcl::PointCloud<PointT> &cloud)
251  {
252  pcl::IFSWriter w;
253  return (w.write<PointT> (file_name, cloud));
254  }
255  }
256 }
257 
258 #endif //#ifndef PCL_IO_IFS_IO_H_
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud object using a field_map...
Definition: conversions.h:169
int loadIFSFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud)
Load an IFS file into a PCLPointCloud2 blob type.
Definition: ifs_io.h:192
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void read(std::istream &stream, Type &value)
Function for reading data from a stream.
Definition: region_xy.h:47
IFSReader()
Empty constructor.
Definition: ifs_io.h:58
Indexed Face set (IFS) file format reader.
Definition: ifs_io.h:54
int read(const std::string &file_name, pcl::PointCloud< PointT > &cloud)
Read a point cloud data from an IFS file, and convert it to the given template pcl::PointCloud format...
Definition: ifs_io.h:125
int read(const std::string &file_name, pcl::PCLPointCloud2 &cloud, int &ifs_version)
Read a point cloud data from an IFS file and store it into a pcl/PCLPointCloud2.
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
Definition: point_cloud.h:423
~IFSReader()
Empty destructor.
Definition: ifs_io.h:60
Point Cloud Data (IFS) file format writer.
Definition: ifs_io.h:144
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
Definition: point_cloud.h:421
int saveIFSFile(const std::string &file_name, const pcl::PCLPointCloud2 &cloud)
Save point cloud data to an IFS file containing 3D points.
Definition: ifs_io.h:236
void write(std::ostream &stream, Type value)
Function for writing data to a stream.
Definition: region_xy.h:64
int write(const std::string &file_name, const pcl::PointCloud< PointT > &cloud, const std::string &cloud_name="cloud")
Save point cloud data to an IFS file containing 3D points.
Definition: ifs_io.h:173
A point structure representing Euclidean xyz coordinates, and the RGB color.
int write(const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const std::string &cloud_name="cloud")
Save point cloud data to an IFS file containing 3D points.