io.cpp
Go to the documentation of this file.
1 #include "io.h"
2 
3 #include "pointmatcher/IO.h"
4 
5 PYBIND11_MAKE_OPAQUE(std::vector<PointMatcherIO<ScalarType>::SupportedLabel>) // SupportedLabels
6 PYBIND11_MAKE_OPAQUE(std::vector<PointMatcherIO<ScalarType>::FileInfo>) // FileInfoVector
7 PYBIND11_MAKE_OPAQUE(std::vector<PointMatcherIO<ScalarType>::PLYProperty>) // PLYProperties
8 
9 namespace python
10 {
11  namespace pointmatcher
12  {
13  void pybindIO(py::module& p_module)
14  {
16  py::class_<PMIO> pyPointMatcherIO(p_module, "PointMatcherIO", "IO Functions and classes that are dependant on scalar type are defined in this templatized class");
17 
18  pyPointMatcherIO.def(py::init<>())
19  .def_static("getColLabel", &PMIO::getColLabel, py::arg("label"), py::arg("row"), "convert a descriptor label to an appropriate sub-label");
20 
21  using PMPropTypes = PMIO::PMPropTypes;
22  py::enum_<PMPropTypes>(pyPointMatcherIO, "PMPropTypes", "Type of information in a DataPoints. Each type is stored in its own dense matrix.")
23  .value("FEATURE", PMPropTypes::FEATURE).value("DESCRIPTOR", PMPropTypes::DESCRIPTOR)
24  .value("TIME", PMPropTypes::TIME).value("UNSUPPORTED", PMPropTypes::UNSUPPORTED);
25 
26  using SupportedLabel = PMIO::SupportedLabel;
27  py::class_<SupportedLabel>(pyPointMatcherIO, "SupportedLabel", "Structure containing all information required to map external information to PointMatcher internal representation")
28  .def_readwrite("internalName", &SupportedLabel::internalName, "name used in PointMatcher")
29  .def_readwrite("externalName", &SupportedLabel::externalName, "name used in external format")
30  .def_readwrite("type", &SupportedLabel::type, "type of information in PointMatcher")
31 
32  .def(py::init<const std::string&, const std::string&, const PMPropTypes&>(), py::arg("internalName"), py::arg("externalName"), py::arg("type"));
33 
34  using SupportedLabels = PMIO::SupportedLabels;
35  py::bind_vector<SupportedLabels>(pyPointMatcherIO, "SupportedLabels", "Vector of supported labels in PointMatcher and their external names");
36 
37  using GenericInputHeader = PMIO::GenericInputHeader;
38  py::class_<GenericInputHeader>(pyPointMatcherIO, "GenericInputHeader", "Helper structure designed to parse file headers")
39  .def_readwrite("name", &GenericInputHeader::name)
40  .def_readwrite("matrixRowId", &GenericInputHeader::matrixRowId)
41  .def_readwrite("matrixType", &GenericInputHeader::matrixType).def(py::init<>())
42  .def(py::init<const std::string&>(), py::arg("name"));
43 
44  pyPointMatcherIO.def_static("getSupportedExternalLabels", &PMIO::getSupportedExternalLabels, R"pbdoc(
45 Vector containing the mapping of all external names to PointMatcher representation.
46 The order is important (i.e., nx before ny). This can also be used to remap 1D descriptor name to a better one.
47 )pbdoc");
48 
49  using LabelGenerator = PMIO::LabelGenerator;
50  py::class_<LabelGenerator>(pyPointMatcherIO, "LabelGenerator").def(py::init<>())
51  .def("add", (void (LabelGenerator::*)(const std::string)) &LabelGenerator::add, py::arg("internalName"), "add a name to the vector of labels. If already there, will increament the dimension.")
52  .def("add", (void (LabelGenerator::*)(const std::string, const unsigned int)) &LabelGenerator::add, py::arg("internalName"), py::arg("dim"), "add a name to the vector of labels with its dimension.")
53  .def("getLabels", &LabelGenerator::getLabels, "Return the vector of labels used to build a DataPoints");
54 
55  pyPointMatcherIO
56  .def_static("loadCSV", (DataPoints (*)(const std::string&)) &PMIO::loadCSV, py::arg("fileName"))
57  .def_static("saveCSV", (void (*)(const DataPoints&, const std::string&, unsigned precision)) &PMIO::saveCSV, py::arg("data"), py::arg("fileName"), py::arg("precision"));
58 
59  using SupportedVTKDataTypes = PMIO::SupportedVTKDataTypes;
60  py::enum_<SupportedVTKDataTypes>(pyPointMatcherIO, "SupportedVTKDataTypes", "Enumeration of legacy VTK data types that can be parsed")
61  .value("POLYDATA", SupportedVTKDataTypes::POLYDATA)
62  .value("UNSTRUCTURED_GRID", SupportedVTKDataTypes::UNSTRUCTURED_GRID);
63 
64  using SplitTime = PMIO::SplitTime;
65  py::class_<SplitTime>(pyPointMatcherIO, "SplitTime", "Storage for time loaded separatly")
66  .def_readwrite("isHigh32Found", &SplitTime::isHigh32Found, "was the high 32bits found in the file")
67  .def_readwrite("isLow32Found", &SplitTime::isLow32Found, "was the low 32bits found in the file")
68  .def_readwrite("high32", &SplitTime::high32, "Matrix containing file data representing the high 32 bits")
69  .def_readwrite("low32", &SplitTime::low32, "Matrix containing file data representing the low 32 bits")
70  .def(py::init<>());
71 
72  pyPointMatcherIO
73  .def_static("loadVTK", (DataPoints (*)(const std::string&)) &PMIO::loadVTK, py::arg("fileName"))
74  .def_static("saveVTK", (void (*)(const DataPoints&, const std::string&, bool, unsigned precision)) &PMIO::saveVTK, py::arg("data"), py::arg("fileName"), py::arg("binary") = false, py::arg("precision") = 7)
75 
76  .def_static("loadPLY", (DataPoints (*)(const std::string&)) &PMIO::loadPLY, py::arg("fileName"))
77  .def_static("savePLY", (void (*)(const DataPoints&, const std::string&, unsigned precision)) &PMIO::savePLY, py::arg("data"), py::arg("fileName"), py::arg("precision"), "save datapoints to PLY point cloud format")
78 
79  .def_static("loadPCD", (DataPoints (*)(const std::string&)) &PMIO::loadPCD, py::arg("fileName"))
80  .def_static("savePCD", (void (*)(const DataPoints&, const std::string&, unsigned precision)) &PMIO::savePCD, py::arg("data"), py::arg("fileName"), py::arg("precision"), "save datapoints to PCD point cloud format");
81 
82  using FileInfo = PMIO::FileInfo;
83  using Vector3 = FileInfo::Vector3;
84  py::class_<FileInfo>(pyPointMatcherIO, "FileInfo", "Information to exploit a reading from a file using this library. Fields might be left blank if unused.")
85  .def_readwrite("readingFileName", &FileInfo::readingFileName, "file name of the reading point cloud")
86  .def_readwrite("referenceFileName", &FileInfo::referenceFileName, "file name of the reference point cloud")
87  .def_readwrite("configFileName", &FileInfo::configFileName, "file name of the yaml configuration")
88  .def_readwrite("initialTransformation", &FileInfo::initialTransformation, "matrix of initial estimate transform")
89  .def_readwrite("groundTruthTransformation", &FileInfo::groundTruthTransformation, "matrix of the ground-truth transform")
90  .def_readwrite("gravity", &FileInfo::gravity, "gravity vector")
91 
92  .def(py::init<const std::string&, const std::string&, const std::string&, const TransformationParameters&, const TransformationParameters&, const Vector&>(), py::arg("readingPath") = "", py::arg(" referencePath") = "", py::arg("configFileName") = "", py::arg("initialTransformation") = TransformationParameters(), py::arg("groundTruthTransformation") = TransformationParameters(), py::arg("gravity") = Vector3::Zero(), "Constructor, leave fields blank if unused");
93 
94  using FileInfoVector = PMIO::FileInfoVector;
95  py::bind_vector<FileInfoVector>(pyPointMatcherIO, "FileInfoVector", "A vector of file info, to be used in batch processing")
96  .def(py::init<>(), "Empty constructor")
97  .def(py::init<const std::string&, std::string, std::string>(), py::arg("fileName"), py::arg("dataPath") = "", py::arg("configPath") = "", R"pbdoc(
98 Load a vector of FileInfo from a CSV file.
99 
100 @param fileName name of the CSV file
101 @param dataPath path relative to which the point cloud CSV or VTK will be resolved
102 @param configPath path relative to which the yaml configuration files will be resolved
103 
104 The first line of the CSV file must contain a header. The supported tags are:
105 - reading: file name of the reading point cloud
106 - reference: file name of the reference point cloud
107 - config: file name of the YAML configuration of the ICP chain
108 - iTxy: initial transformation, coordinate x,y
109 - gTxy: ground-truth transformation, coordinate x,y
110 Note that the header must at least contain "reading".
111 )pbdoc");
112 
113  using CsvDescriptor = PMIO::CsvDescriptor;
114  py::class_<CsvDescriptor>(pyPointMatcherIO, "CsvDescriptor", "A structure to hold information about descriptors contained in a CSV file")
115  .def(py::init<>()).def_readwrite("name", &CsvDescriptor::name, "name of descriptor")
116  .def_readwrite("start_col", &CsvDescriptor::start_col, "column number at which descriptor starts")
117  .def_readwrite("span", &CsvDescriptor::span, "number of columns spanned by descriptor");
118 
119  pyPointMatcherIO
120  .def_static("plyPropTypeValid", &PMIO::plyPropTypeValid, "Check that property defined by type is a valid PLY type note: type must be lowercase");
121 
122  using PLYProperty = PMIO::PLYProperty;
123  py::class_<PLYProperty>(pyPointMatcherIO, "PLYProperty", "Interface for PLY property")
124  .def_readwrite("name", &PLYProperty::name, "name of PLY property")
125  .def_readwrite("type", &PLYProperty::type, "type of PLY property")
126  .def_readwrite("idx_type", &PLYProperty::idx_type, "for list properties, type of number of elements")
127  .def_readwrite("pos", &PLYProperty::pos, "index of the property in element")
128  .def_readwrite("is_list", &PLYProperty::is_list, "member is true of property is a list")
129  .def_readwrite("pmType", &PLYProperty::pmType, "type of information in PointMatcher")
130  .def_readwrite("pmRowID", &PLYProperty::pmRowID, "row id used in a DataPoints")
131 
132  .def(py::init<>(), "Default constructor. If used member values must be filled later.")
133  .def(py::init<const std::string&, const std::string&, const unsigned>(), py::arg("type"), py::arg("name"), py::arg("pos"), "regular property")
134  .def(py::init<const std::string&, const std::string&, const std::string&, const unsigned>(), py::arg("idx_type"), py::arg("type"), py::arg("name"), py::arg("pos"), "list property")
135 
136  .def("__eq__", &PLYProperty::operator==, "compare with other property");
137 
138  using PLYProperties = PMIO::PLYProperties;
139  py::bind_vector<PLYProperties>(pyPointMatcherIO, "PLYProperties", "Vector of properties specific to PLY files");
140 
141  using PLYDescPropMap = PMIO::PLYDescPropMap;
142  py::bind_map<PLYDescPropMap>(pyPointMatcherIO, "PLYDescPropMap", "Map from a descriptor name to a list PLY property\nex: \"normals\" -> nx, ny ,nz");
143 
144  using PLYElement = PMIO::PLYElement;
145  py::class_<PLYElement>(pyPointMatcherIO, "PLYElement", "Interface for all PLY elements.")
146  .def_readwrite("name", &PLYElement::name, "name identifying the PLY element")
147  .def_readwrite("num", &PLYElement::num, "number of occurences of the element")
148  .def_readwrite("total_props", &PLYElement::total_props, "total number of properties in PLY element")
149  .def_readwrite("offset", &PLYElement::offset, "line at which data starts")
150  .def_readwrite("properties", &PLYElement::properties, "all properties found in the header")
151  .def_readwrite("nbFeatures", &PLYElement::nbFeatures, "number of valid features found in the header")
152  .def_readwrite("nbDescriptors", &PLYElement::nbDescriptors, "number of valid descriptors found in the header")
153 
154  .def(py::init<const std::string&, const unsigned, const unsigned>(), py::arg("name"), py::arg("num"), py::arg("offset"), R"pbdoc(
155 PLY Element constructor
156 
157 @param name name of the ply element (case-sensitive)
158 @param num number of times the element appears in the file
159 @param offset if there are several elements, the line offset at which this element begins. Note that, as of writing, only one (vertex) element is supported.
160 
161 This object holds information about a PLY element contained in the file.
162 It is filled out when reading the header and used when parsing the data.
163 )pbdoc").def("__eq__", &PLYElement::operator==, "comparison operator for elements");
164 
165  using PLYVertex = PMIO::PLYVertex;
166  py::class_<PLYVertex, PLYElement>(pyPointMatcherIO, "PLYVertex", "Implementation of PLY vertex element")
167  .def(py::init<const unsigned, const unsigned>(), py::arg("num"), py::arg("offset"), R"pbdoc(
168 Constructor
169 
170 @param num number of times the element appears in the file
171 @param offset if there are several elements, the line offset at which this element begins. Note that, as of writing, only one (vertex) element is supported.
172 
173 Implementation of PLY element interface for the vertex element
174 )pbdoc");
175 
176 // FIXME : Generate undefined symbol error for "elementSupported" or "createElement" method when importing the module
177 // using PLYElementF = PMIO::PLYElementF;
178 // py::class_<PLYElementF>(pyPointMatcherIO, "PLYElementF", "Factory for PLY elements")
179 // .def("elementSupported", &PLYElementF::elementSupported, py::arg("elem_name"), "returns true if element named elem_name is supported by this parser")
180 // .def_static("createElement", &PLYElementF::createElement, py::arg("elem_name"), py::arg("elem_num"), py::arg("offset"), "factory function, build element defined by name with elem_num elements");
181 
182  using PCDproperty = PMIO::PCDproperty;
183  py::class_<PCDproperty>(pyPointMatcherIO, "PCDproperty", "Information for a PCD property")
184  .def_readwrite("field", &PCDproperty::field, "Name of the property")
185  .def_readwrite("size", &PCDproperty::size, "Size of the property in bytes")
186  .def_readwrite("type", &PCDproperty::type, "Type: I: signed, U: unsigned, F: float")
187  .def_readwrite("count", &PCDproperty::count, "number of dimension")
188  .def_readwrite("pmType", &PCDproperty::pmType, "type of information in PointMatcher")
189  .def_readwrite("pmRowID", &PCDproperty::pmRowID, "row id used in a DataPoints")
190 
191  .def(py::init<>());
192 
193  using PCDheader = PMIO::PCDheader;
194  py::class_<PCDheader>(pyPointMatcherIO, "PCDheader", "All information contained in the header of a PCD file")
195  .def_readwrite("version", &PCDheader::version, "Version of the PCD file used")
196  .def_readwrite("properties", &PCDheader::properties, "vector of properties")
197  .def_readwrite("width", &PCDheader::width, "width of sensor matrix")
198  .def_readwrite("height", &PCDheader::height, "height of sensor matrix")
199  .def_readwrite("viewPoint", &PCDheader::viewPoint, "not used")
200  .def_readwrite("nbPoints", &PCDheader::nbPoints, "number of points, same as width*height")
201  .def_readwrite("dataType", &PCDheader::dataType, "ascii or binary")
202 
203  .def(py::init<>());
204  }
205  }
206 }
PointMatcherIO
IO Functions and classes that are dependant on scalar type are defined in this templatized class.
Definition: IO.h:43
PointMatcherIO::PLYDescPropMap
std::map< std::string, std::vector< PLYProperty > > PLYDescPropMap
Definition: IO.h:293
PointMatcherIO::GenericInputHeader
Helper structure designed to parse file headers.
Definition: IO.h:87
PointMatcherIO::PLYVertex
Implementation of PLY vertex element.
Definition: IO.h:334
PointMatcherIO::loadVTK
static DataPoints loadVTK(const std::string &fileName)
Load point cloud from a file as VTK.
Definition: pointmatcher/IO.cpp:911
icp_customized.name
string name
Definition: icp_customized.py:45
PointMatcherIO::PCDheader
All information contained in the header of a PCD file.
Definition: IO.h:388
PointMatcherIO::SplitTime
Storage for time loaded separatly.
Definition: IO.h:198
PointMatcherIO::savePLY
static void savePLY(const DataPoints &data, const std::string &fileName, unsigned precision)
save datapoints to PLY point cloud format
Definition: pointmatcher/IO.cpp:1655
PointMatcherIO::PLYProperty
Interface for PLY property.
Definition: IO.h:267
PointMatcherIO::PLYElement
Interface for all PLY elements.
Definition: IO.h:302
PointMatcher::DataPoints
A point cloud.
Definition: PointMatcher.h:207
PointMatcherIO::SupportedVTKDataTypes
SupportedVTKDataTypes
Enumeration of legacy VTK data types that can be parsed.
Definition: IO.h:191
testing::internal::string
::std::string string
Definition: gtest.h:1979
setup.version
version
Definition: setup.py:15
PointMatcherIO::loadCSV
static DataPoints loadCSV(const std::string &fileName)
Associate an external name to a DataPoints type of information.
Definition: pointmatcher/IO.cpp:408
PointMatcherIO::loadPLY
static DataPoints loadPLY(const std::string &fileName)
Load polygon file format (ply) file.
Definition: pointmatcher/IO.cpp:1289
PointMatcherIO::SupportedLabels
std::vector< SupportedLabel > SupportedLabels
Vector of supported labels in PointMatcher and their external names.
Definition: IO.h:84
python
Definition: add_descriptor.cpp:5
PointMatcherIO::PMPropTypes
PMPropTypes
Type of information in a DataPoints. Each type is stored in its own dense matrix.
Definition: IO.h:64
PointMatcherIO::FileInfoVector
A vector of file info, to be used in batch processing.
Definition: IO.h:245
PointMatcherIO::SupportedLabel
Structure containing all information required to map external information to PointMatcher internal re...
Definition: IO.h:73
PointMatcherIO::saveCSV
static void saveCSV(const DataPoints &data, const std::string &fileName, unsigned precision)
Save point cloud to a file as CSV.
Definition: pointmatcher/IO.cpp:836
PointMatcherIO::PLYProperties
std::vector< PLYProperty > PLYProperties
Vector of properties specific to PLY files.
Definition: IO.h:296
PointMatcherIO::getColLabel
static std::string getColLabel(const Label &label, const int row)
convert a descriptor label to an appropriate sub-label
Definition: pointmatcher/IO.cpp:469
python::pointmatcher::pybindIO
void pybindIO(py::module &p_module)
PointMatcherIO::getSupportedExternalLabels
static const SupportedLabels & getSupportedExternalLabels()
Definition: IO.h:117
PointMatcherIO::CsvDescriptor
A structure to hold information about descriptors contained in a CSV file.
Definition: IO.h:257
std
PointMatcherIO::FileInfo
Information to exploit a reading from a file using this library. Fields might be left blank if unused...
Definition: IO.h:230
TransformationParameters
PM::TransformationParameters TransformationParameters
Definition: pypoint_matcher_helper.h:63
io.h
PointMatcherIO::savePCD
static void savePCD(const DataPoints &data, const std::string &fileName, unsigned precision)
save datapoints to PCD point cloud format
Definition: pointmatcher/IO.cpp:2260
PointMatcherIO::saveVTK
static void saveVTK(const DataPoints &data, const std::string &fileName, bool binary=false, unsigned precision=7)
Save point cloud to a file as VTK.
Definition: pointmatcher/IO.cpp:1262
ScalarType
PM::ScalarType ScalarType
Definition: pypoint_matcher_helper.h:54
PointMatcherIO::PCDproperty
Information for a PCD property.
Definition: IO.h:364
IO.h
PointMatcherIO::plyPropTypeValid
static bool plyPropTypeValid(const std::string &type)
Check that property defined by type is a valid PLY type note: type must be lowercase.
Definition: pointmatcher/IO.cpp:1826
PointMatcherIO::loadPCD
static DataPoints loadPCD(const std::string &fileName)
PointMatcherIO::LabelGenerator
Generate a vector of Labels by checking for collision is the same name is reused.
Definition: IO.h:162


libpointmatcher
Author(s):
autogenerated on Mon Sep 16 2024 02:24:09