IO.h
Go to the documentation of this file.
1 // kate: replace-tabs off; indent-width 4; indent-mode normal
2 // vim: ts=4:sw=4:noexpandtab
3 /*
4 
5 Copyright (c) 2010--2012,
6 François Pomerleau and Stephane Magnenat, ASL, ETHZ, Switzerland
7 You can contact the authors at <f dot pomerleau at gmail dot com> and
8 <stephane at magnenat dot net>
9 
10 All rights reserved.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright
17  notice, this list of conditions and the following disclaimer in the
18  documentation and/or other materials provided with the distribution.
19  * Neither the name of the <organization> nor the
20  names of its contributors may be used to endorse or promote products
21  derived from this software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
27 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34  */
35 
36 #ifndef __POINTMATCHER_IO_H
37 #define __POINTMATCHER_IO_H
38 
39 #include "PointMatcher.h"
40 
42 template<typename T>
44 {
45  typedef typename PointMatcher<T>::Vector Vector;
46  typedef typename PointMatcher<T>::Matrix Matrix;
53 
55  typedef std::pair<int, std::string >LabelAssociationPair;
56 
59  typedef std::map<std::string, LabelAssociationPair > SublabelAssociationMap;
60 
61  static std::string getColLabel(const Label& label, const int row);
62 
65  {
70  };
71 
74  {
78 
80  SupportedLabel(const std::string& internalName, const std::string& externalName, const PMPropTypes& type);
81  };
82 
84  typedef std::vector<SupportedLabel> SupportedLabels;
85 
88  {
90  unsigned int matrixRowId;
92 
94  //TODO: move that to .cpp
96  {
97  init(name);
98  };
99 
101  {
102  init("");
103  };
104 
105  private:
106  void init(std::string name)
107  {
108  this->name = name;
109  this->matrixRowId = 0;
110  this->matrixType = UNSUPPORTED;
111  };
112  };
113 
117  static const SupportedLabels & getSupportedExternalLabels()
118  {
119  // This table can be read as:
120  // (internalName, externalName, type)
121  const static SupportedLabels labels = {
122  {"x", "x", FEATURE},
123  {"y", "y", FEATURE},
124  {"z", "z", FEATURE},
125  {"pad", "pad", FEATURE},
126  //{"internalName", "externalName", FEATURE},
127  {"normals", "nx", DESCRIPTOR},
128  {"normals", "ny", DESCRIPTOR},
129  {"normals", "nz", DESCRIPTOR},
130  {"normals", "normal_x", DESCRIPTOR},
131  {"normals", "normal_y", DESCRIPTOR},
132  {"normals", "normal_z", DESCRIPTOR},
133  {"observationDirections", "observationDirections0", DESCRIPTOR},
134  {"observationDirections", "observationDirections1", DESCRIPTOR},
135  {"observationDirections", "observationDirections2", DESCRIPTOR},
136  {"color", "red", DESCRIPTOR},
137  {"color", "green", DESCRIPTOR},
138  {"color", "blue", DESCRIPTOR},
139  {"color", "alpha", DESCRIPTOR},
140  {"eigValues", "eigValues0", DESCRIPTOR},
141  {"eigValues", "eigValues1", DESCRIPTOR},
142  {"eigValues", "eigValues2", DESCRIPTOR},
143  {"eigVectors", "eigVectors0X", DESCRIPTOR},
144  {"eigVectors", "eigVectors0Y", DESCRIPTOR},
145  {"eigVectors", "eigVectors0Z", DESCRIPTOR},
146  {"eigVectors", "eigVectors1X", DESCRIPTOR},
147  {"eigVectors", "eigVectors1Y", DESCRIPTOR},
148  {"eigVectors", "eigVectors1Z", DESCRIPTOR},
149  {"eigVectors", "eigVectors2X", DESCRIPTOR},
150  {"eigVectors", "eigVectors2Y", DESCRIPTOR},
151  {"eigVectors", "eigVectors2Z", DESCRIPTOR},
152  {"intensity", "intensity", DESCRIPTOR},
153  //{"internalName", "externalName", DESCRIPTOR},
154  {"time", "time", TIME}
155  //{"internalName", "externalName", TIME}
156  };
157 
158  return labels;
159  }
160 
163  {
164  Labels labels;
165 
166  public:
168  void add(const std::string internalName);
169 
171  void add(const std::string internalName, const unsigned int dim);
172 
173 
175  Labels getLabels() const;
176  };
177 
178 
180  //static PMPropTypes getPMType(const std::string& externalName); //! Return the type of information specific to a DataPoints based on a sulabel name
181 
182  // CSV
183  static DataPoints loadCSV(const std::string& fileName);
184  static DataPoints loadCSV(std::istream& is);
185 
186  static void saveCSV(const DataPoints& data, const std::string& fileName);
187  static void saveCSV(const DataPoints& data, std::ostream& os);
188 
189  // VTK
192  {
195  };
196 
198  struct SplitTime
199  {
202  Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic> high32;
205  Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic> low32;
206 
208  SplitTime(): isHigh32Found(false), isLow32Found(false){};
209 
210  };
211 
212  static DataPoints loadVTK(const std::string& fileName);
213  static DataPoints loadVTK(std::istream& is);
214 
215  static void saveVTK(const DataPoints& data, const std::string& fileName, bool binary = false);
216 
217  // PLY
218  static DataPoints loadPLY(const std::string& fileName);
219  static DataPoints loadPLY(std::istream& is);
220 
221  static void savePLY(const DataPoints& data, const std::string& fileName);
222 
223  // PCD
224  static DataPoints loadPCD(const std::string& fileName);
225  static DataPoints loadPCD(std::istream& is);
226 
227  static void savePCD(const DataPoints& data, const std::string& fileName);
228 
230  struct FileInfo
231  {
232  typedef Eigen::Matrix<T, 3, 1> Vector3;
233 
237  TransformationParameters initialTransformation;
238  TransformationParameters groundTruthTransformation;
239  Vector3 gravity;
240 
241  FileInfo(const std::string& readingPath="", const std::string& referencePath="", const std::string& configFileName="", const TransformationParameters& initialTransformation=TransformationParameters(), const TransformationParameters& groundTruthTransformation=TransformationParameters(), const Vector& gravity=Vector3::Zero());
242  };
243 
245  struct FileInfoVector: public std::vector<FileInfo>
246  {
247  FileInfoVector();
248  FileInfoVector(const std::string& fileName, std::string dataPath = "", std::string configPath = "");
249 
250  protected:
251  std::string localToGlobalFileName(const std::string& path, const std::string& fileName);
252  bool findTransform(const PointMatcherSupport::CsvElements& data, const std::string& prefix, unsigned dim);
253  TransformationParameters getTransform(const PointMatcherSupport::CsvElements& data, const std::string& prefix, unsigned dim, unsigned line);
254  };
255 
257  struct CsvDescriptor {
259  unsigned start_col;
260  unsigned span;
261  };
262 
264  static bool plyPropTypeValid (const std::string& type);
265 
267  struct PLYProperty
268  {
269  //PLY information:
273  unsigned pos;
274  bool is_list;
275 
276  //PointMatcher information:
278  int pmRowID;
279 
280  PLYProperty() { }
281 
282  // regular property
283  PLYProperty(const std::string& type, const std::string& name, const unsigned pos);
284 
285  // list property
286  PLYProperty(const std::string& idx_type, const std::string& type, const std::string& name, const unsigned pos);
287 
288  bool operator==(const PLYProperty& other) const;
289  };
290 
293  typedef std::map<std::string, std::vector<PLYProperty> > PLYDescPropMap;
294 
296  typedef std::vector<PLYProperty> PLYProperties;
297 
299  typedef typename PLYProperties::iterator it_PLYProp;
300 
303  {
304  public:
306  unsigned num;
307  unsigned total_props;
308  unsigned offset;
309  PLYProperties properties;
310  unsigned nbFeatures;
311  unsigned nbDescriptors;
312 
313 
315 
323  PLYElement(const std::string& name, const unsigned num, const unsigned offset) :
324  name(name), num(num), total_props(0), offset(offset), nbFeatures(0), nbDescriptors(0) {}
325 
326  //bool supportsProperty(const PLYProperty& prop) const; //!< Returns true if property pro is supported by element
327 
328  bool operator==(const PLYElement& other) const;
329 
330  };
331 
332 
334  class PLYVertex : public PLYElement
335  {
336  public:
338 
344  PLYVertex(const unsigned num, const unsigned offset) : PLYElement("vertex", num, offset) {}
345 
346  };
347 
350  {
352  {
355  };
356 
357  static ElementTypes getElementType(const std::string& elem_name);
358  public:
359  bool elementSupported(const std::string& elem_name);
360  static PLYElement* createElement(const std::string& elem_name, const int elem_num, const unsigned offset);
361  };
362 
364  struct PCDproperty
365  {
367  unsigned int size;
368  char type;
369  unsigned int count;
370 
371  //PointMatcher information:
373  int pmRowID;
374 
377  {
378  field = "";
379  size = 0;
380  type = '-';
381  count = 1;
382  pmType = UNSUPPORTED;
383  pmRowID = -1;
384  };
385  };
386 
388  struct PCDheader
389  {
391  std::vector<PCDproperty> properties;
392  unsigned int width;
393  unsigned int height;
394  Eigen::Matrix<T, 7, 1> viewPoint;
395  unsigned int nbPoints;
397 
399  {
400  version = "-";
401  width = 0;
402  height = 0;
403  viewPoint = Eigen::Matrix<T, 7, 1>::Zero();
404  nbPoints = 0;
405  dataType = "-";
406  };
407  };
408 };
409 
410 
411 #endif // __POINTMATCHER_IO_H
int pmRowID
row id used in a DataPoints
Definition: IO.h:278
TransformationParameters initialTransformation
matrix of initial estimate transform
Definition: IO.h:237
bool is_list
member is true of property is a list
Definition: IO.h:274
public interface
unsigned int size
Size of the property in bytes.
Definition: IO.h:367
GenericInputHeader(const std::string name)
Constructor.
Definition: IO.h:95
IO Functions and classes that are dependant on scalar type are defined in this templatized class...
Definition: IO.h:43
unsigned int count
number of dimension
Definition: IO.h:369
static DataPoints loadPCD(const std::string &fileName)
unsigned pos
index of the property in element
Definition: IO.h:273
unsigned span
number of columns spanned by descriptor
Definition: IO.h:260
std::string referenceFileName
file name of the reference point cloud
Definition: IO.h:235
std::string readingFileName
file name of the reading point cloud
Definition: IO.h:234
std::string dataPath
Definition: utest.cpp:43
std::string name
name of descriptor
Definition: IO.h:258
::std::string string
Definition: gtest.h:1979
std::vector< SupportedLabel > SupportedLabels
Vector of supported labels in PointMatcher and their external names.
Definition: IO.h:84
Eigen::Matrix< T, 7, 1 > viewPoint
not used
Definition: IO.h:394
data
Definition: icp.py:50
PointMatcher< T >::DataPoints::Labels Labels
alias
Definition: IO.h:52
std::string configFileName
file name of the yaml configuration
Definition: IO.h:236
std::string type
type of PLY property
Definition: IO.h:271
Factory for PLY elements.
Definition: IO.h:349
PLYElement(const std::string &name, const unsigned num, const unsigned offset)
PLY Element constructor.
Definition: IO.h:323
static bool plyPropTypeValid(const std::string &type)
Check that property defined by type is a valid PLY type note: type must be lowercase.
static void savePLY(const DataPoints &data, const std::string &fileName)
save datapoints to PLY point cloud format
static void saveVTK(const DataPoints &data, const std::string &fileName, bool binary=false)
Save point cloud to a file as VTK.
std::string name
name identifying the PLY element
Definition: IO.h:305
std::string name
name of PLY property
Definition: IO.h:270
bool isHigh32Found
was the high 32bits found in the file
Definition: IO.h:200
SplitTime()
Constructor.
Definition: IO.h:208
Helper structure designed to parse file headers.
Definition: IO.h:87
The name for a certain number of dim.
Definition: PointMatcher.h:221
std::string field
Name of the property.
Definition: IO.h:366
All information contained in the header of a PCD file.
Definition: IO.h:388
static DataPoints loadCSV(const std::string &fileName)
Associate an external name to a DataPoints type of information.
PointMatcher< T >::TransformationParameters TransformationParameters
alias
Definition: IO.h:49
std::map< std::string, std::vector< std::string > > CsvElements
Data from a CSV file.
Definition: PointMatcher.h:125
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dense matrix over ScalarType.
Definition: PointMatcher.h:169
PointMatcher< T >::Vector Vector
alias
Definition: IO.h:45
PLYProperty()
Default constructor. If used member values must be filled later.
Definition: IO.h:280
static DataPoints loadPLY(const std::string &fileName)
Load polygon file format (ply) file.
static const SupportedLabels & getSupportedExternalLabels()
Definition: IO.h:117
std::string dataType
ascii or binary
Definition: IO.h:396
PMPropTypes pmType
type of information in PointMatcher
Definition: IO.h:277
PointMatcher< T >::DataPoints::Label Label
alias
Definition: IO.h:51
unsigned num
number of occurences of the element
Definition: IO.h:306
PLYVertex(const unsigned num, const unsigned offset)
Constructor.
Definition: IO.h:344
PLYProperties properties
all properties found in the header
Definition: IO.h:309
Eigen::Matrix< T, 3, 1 > Vector3
alias
Definition: IO.h:232
static void saveCSV(const DataPoints &data, const std::string &fileName)
Save point cloud to a file as CSV.
Information for a PCD property.
Definition: IO.h:364
PMPropTypes type
type of information in PointMatcher
Definition: IO.h:77
PMPropTypes pmType
type of information in PointMatcher
Definition: IO.h:372
unsigned int nbPoints
number of points, same as width*height
Definition: IO.h:395
PointMatcher< T >::Matrix Matrix
alias
Definition: IO.h:46
PMPropTypes matrixType
in which matrix the information will be loaded
Definition: IO.h:91
Labels labels
vector of labels used to cumulat information
Definition: IO.h:164
Eigen::Matrix< unsigned int, Eigen::Dynamic, Eigen::Dynamic > low32
Matrix containing file data representing the low 32 bits.
Definition: IO.h:205
std::string idx_type
for list properties, type of number of elements
Definition: IO.h:272
bool operator==(const GTEST_10_TUPLE_(T)&t, const GTEST_10_TUPLE_(U)&u)
Definition: gtest.h:1607
static void savePCD(const DataPoints &data, const std::string &fileName)
save datapoints to PCD point cloud format
unsigned start_col
column number at which descriptor starts
Definition: IO.h:259
PointMatcher< T >::Int64Matrix Int64Matrix
alias
Definition: IO.h:47
A structure to hold information about descriptors contained in a CSV file.
Definition: IO.h:257
Eigen::Matrix< std::int64_t, Eigen::Dynamic, Eigen::Dynamic > Int64Matrix
A dense signed 64-bits matrix.
Definition: PointMatcher.h:173
Information to exploit a reading from a file using this library. Fields might be left blank if unused...
Definition: IO.h:230
std::string version
Version of the PCD file used.
Definition: IO.h:390
PointMatcher< T >::Matrix Parameters
alias
Definition: IO.h:50
unsigned int height
height of sensor matrix
Definition: IO.h:393
unsigned total_props
total number of properties in PLY element
Definition: IO.h:307
SupportedVTKDataTypes
Enumeration of legacy VTK data types that can be parsed.
Definition: IO.h:191
std::vector< PCDproperty > properties
vector of properties
Definition: IO.h:391
unsigned nbDescriptors
number of valid descriptors found in the header
Definition: IO.h:311
Storage for time loaded separatly.
Definition: IO.h:198
unsigned nbFeatures
number of valid features found in the header
Definition: IO.h:310
TransformationParameters groundTruthTransformation
matrix of the ground-truth transform
Definition: IO.h:238
char type
Type: I: signed, U: unsigned, F: float.
Definition: IO.h:368
std::pair< int, std::string > LabelAssociationPair
Pair feature column, feature name.
Definition: IO.h:55
std::map< std::string, LabelAssociationPair > SublabelAssociationMap
Definition: IO.h:59
std::string name
name found in the file
Definition: IO.h:89
static std::string getColLabel(const Label &label, const int row)
convert a descriptor label to an appropriate sub-label
Structure containing all information required to map external information to PointMatcher internal re...
Definition: IO.h:73
A vector of file info, to be used in batch processing.
Definition: IO.h:245
Generate a vector of Labels by checking for collision is the same name is reused. ...
Definition: IO.h:162
Interface for PLY property.
Definition: IO.h:267
unsigned int width
width of sensor matrix
Definition: IO.h:392
PLYProperties::iterator it_PLYProp
Iterator for a vector of PLY properties.
Definition: IO.h:299
PointMatcher< T >::DataPoints DataPoints
alias
Definition: IO.h:48
int pmRowID
row id used in a DataPoints
Definition: IO.h:373
PMPropTypes
Type of information in a DataPoints. Each type is stored in its own dense matrix. ...
Definition: IO.h:64
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector over ScalarType.
Definition: PointMatcher.h:161
void init(std::string name)
Definition: IO.h:106
PCDproperty()
Empty constructor.
Definition: IO.h:376
std::string internalName
name used in PointMatcher
Definition: IO.h:75
Vector3 gravity
gravity vector
Definition: IO.h:239
std::map< std::string, std::vector< PLYProperty > > PLYDescPropMap
Definition: IO.h:293
Implementation of PLY vertex element.
Definition: IO.h:334
unsigned int matrixRowId
on which row the information will be loaded
Definition: IO.h:90
Interface for all PLY elements.
Definition: IO.h:302
std::string externalName
name used in external format
Definition: IO.h:76
Matrix TransformationParameters
A matrix holding the parameters a transformation.
Definition: PointMatcher.h:182
std::vector< PLYProperty > PLYProperties
Vector of properties specific to PLY files.
Definition: IO.h:296
unsigned offset
line at which data starts
Definition: IO.h:308
static DataPoints loadVTK(const std::string &fileName)
Load point cloud from a file as VTK.
SupportedLabel(const std::string &internalName, const std::string &externalName, const PMPropTypes &type)
Constructor.


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:38:02