data_points.cpp
Go to the documentation of this file.
1 #include "data_points.h"
2 
3 namespace python
4 {
5  namespace pointmatcher
6  {
7  void pybindDataPoints(py::class_<PM>& p_class)
8  {
9  using View = DataPoints::View;
10  using TimeView = DataPoints::TimeView;
11  using ConstView = DataPoints::ConstView;
12  using TimeConstView = DataPoints::TimeConstView;
13 
14  py::class_<DataPoints> pyDataPoints(p_class, "DataPoints");
15 
16  pyDataPoints.doc() = R"pbdoc(
17 A point cloud
18 
19 For every point, it has features and, optionally, descriptors.
20 Features are typically the coordinates of the point in the space.
21 Descriptors contain information attached to the point, such as its color, its normal vector, etc.
22 In both features and descriptors, every point can have multiple channels.
23 Every channel has a dimension and a name.
24 For instance, a typical 3D cloud might have the channels \c x, \c y, \c z, \c w of dimension 1 as features (using homogeneous coordinates), and the channel \c normal of size 3 as descriptor.
25 There are no sub-channels, such as \c normal.x, for the sake of simplicity.
26 Moreover, the position of the points is in homogeneous coordinates because they need both translation and rotation, while the normals need only rotation.
27 All channels contain scalar values of type ScalarType.)pbdoc";
28 
29  py::class_<Label>(pyDataPoints, "Label").def_readwrite("text", &Label::text, "name of the label")
30  .def_readwrite("span", &Label::span, "number of data dimensions the label spans")
31 
32  .def(py::init<const std::string&, const size_t>(), py::arg("text") = "", py::arg("span") = 0)
33  .def("__eq__", &Label::operator==, py::arg("that"));
34 
35  py::bind_vector<Labels>(pyDataPoints, "Labels", "A vector of Label")
36  .def(py::init<>(), "Construct empty Labels")
37  .def(py::init<const Label&>(), py::arg("label"), "Construct Labels with a single Label in it")
38 
39  .def("contains", &Labels::contains, py::arg("text"), "Return whether there is a label named text")
40  .def("totalDim", &Labels::totalDim, "Return the sum of the spans of each label")
41  .def("__str__", [](const Labels& self)
42  {
43  std::ostringstream oss;
44  oss << self;
45  return oss.str();
46  });
47 
48  using InvalidField = DataPoints::InvalidField;
49  py::register_exception<InvalidField>(pyDataPoints, "InvalidField");
50 
51  pyDataPoints
52  // Constructors from descriptions (reserve memory)
53  .def(py::init<>())
54 
55  .def(py::init<const Labels&, const Labels&, const size_t>(), py::arg("featureLabels"), py::arg("descriptorLabels"), py::arg("pointCount"))
56 
57  .def(py::init<const Labels&, const Labels&, const Labels&, const size_t>(), py::arg("featureLabels"), py::arg("descriptorLabels"), py::arg("timeLabels"), py::arg("pointCount"))
58 
59  // Copy constructor
60  .def(py::init<const DataPoints&>())
61 
62  // Copy constructors from partial data
63  .def(py::init<const Matrix&, const Labels&>(), py::arg("features"), py::arg("featureLabels"))
64 
65  .def(py::init<const Matrix&, const Labels&, const Matrix&, const Labels&>(), py::arg("features"), py::arg("featureLabels"), py::arg("descriptors"), py::arg("descriptorLabels"))
66 
67  .def(py::init<const Matrix&, const Labels&, const Matrix&, const Labels&, const PM::Int64Matrix&, const Labels&>(), py::arg("features"), py::arg("featureLabels"), py::arg("descriptors"), py::arg("descriptorLabels"), py::arg("times"), py::arg("timeLabels"))
68 
69  .def("__eq__", &DataPoints::operator==, py::arg("that"))
70 
71  .def("getNbPoints", &DataPoints::getNbPoints).def("getEuclideanDim", &DataPoints::getEuclideanDim)
72  .def("getHomogeneousDim", &DataPoints::getHomogeneousDim)
73  .def("getNbGroupedDescriptors", &DataPoints::getNbGroupedDescriptors)
74  .def("getDescriptorDim", &DataPoints::getDescriptorDim).def("getTimeDim", &DataPoints::getTimeDim)
75 
76  .def("save", &DataPoints::save, py::arg("fileName"), py::arg("binary") = false, py::arg("precision") = 6)
77  .def_static("load", &DataPoints::load, py::arg("filename"))
78 
79  .def("concatenate", &DataPoints::concatenate, py::arg("dp"))
80  .def("conservativeResize", &DataPoints::conservativeResize, py::arg("pointCount"))
81  .def("createSimilarEmpty", (DataPoints (DataPoints::*)() const) &DataPoints::createSimilarEmpty)
82  .def("createSimilarEmpty", (DataPoints (DataPoints::*)(DataPoints::Index) const) &DataPoints::createSimilarEmpty, py::arg("pointCount"))
83  .def("setColFrom", &DataPoints::setColFrom, py::arg("thisCol"), py::arg("that"), py::arg("thatCol"))
84  .def("swapCols", &DataPoints::swapCols, py::arg("iCol"), py::arg("jCol"))
85 
86  .def("allocateFeature", &DataPoints::allocateFeature, py::arg("name"), py::arg("dim"))
87  .def("allocateFeatures", &DataPoints::allocateFeatures, py::arg("newLabels"))
88  .def("addFeature", &DataPoints::addFeature, py::arg("name"), py::arg("newFeature"))
89  .def("removeFeature", &DataPoints::removeFeature, py::arg("name"))
90  .def("getFeatureCopyByName", &DataPoints::getFeatureCopyByName, py::arg("name"))
91  .def("getFeatureViewByName_const", (ConstView (DataPoints::*)(const std::string&) const) &DataPoints::getFeatureViewByName, py::arg("name"))
92  .def("getFeatureViewByName", (View (DataPoints::*)(const std::string&)) &DataPoints::getFeatureViewByName, py::arg("name"))
93  .def("getFeatureRowViewByName_const", (ConstView (DataPoints::*)(const std::string&, const unsigned) const) &DataPoints::getFeatureRowViewByName, py::arg("name"), py::arg("row"))
94  .def("getFeatureRowViewByName", (View (DataPoints::*)(const std::string&, const unsigned)) &DataPoints::getFeatureRowViewByName, py::arg("name"), py::arg("row"))
95  .def("featureExists", (bool (DataPoints::*)(const std::string&) const) &DataPoints::featureExists, py::arg("name"))
96  .def("featureExists", (bool (DataPoints::*)(const std::string&, const unsigned) const) &DataPoints::featureExists, py::arg("name"), py::arg("dim"))
97  .def("getFeatureDimension", &DataPoints::getFeatureDimension, py::arg("name"))
98  .def("getFeatureStartingRow", &DataPoints::getFeatureStartingRow, py::arg("name"))
99 
100  .def("allocateDescriptor", &DataPoints::allocateDescriptor, py::arg("name"), py::arg("dim"))
101  .def("allocateDescriptors", &DataPoints::allocateDescriptors, py::arg("newLabels"))
102  .def("addDescriptor", &DataPoints::addDescriptor, py::arg("name"), py::arg("newDescriptor"))
103  .def("removeDescriptor", &DataPoints::removeDescriptor, py::arg("name"))
104  .def("getDescriptorCopyByName", &DataPoints::getDescriptorCopyByName, py::arg("name"))
105  .def("getDescriptorViewByName_const", (ConstView (DataPoints::*)(const std::string&) const) &DataPoints::getDescriptorViewByName, py::arg("name"))
106  .def("getDescriptorViewByName", (View (DataPoints::*)(const std::string&)) &DataPoints::getDescriptorViewByName, py::arg("name"))
107  .def("getDescriptorRowViewByName_const", (ConstView (DataPoints::*)(const std::string&, const unsigned) const) &DataPoints::getDescriptorRowViewByName, py::arg("name"), py::arg("row"))
108  .def("getDescriptorRowViewByName", (View (DataPoints::*)(const std::string&, const unsigned)) &DataPoints::getDescriptorRowViewByName, py::arg("name"), py::arg("row"))
109  .def("descriptorExists", (bool (DataPoints::*)(const std::string&) const) &DataPoints::descriptorExists)
110  .def("descriptorExists", (bool (DataPoints::*)(const std::string&, const unsigned) const) &DataPoints::descriptorExists)
111  .def("getDescriptorDimension", &DataPoints::getDescriptorDimension, py::arg("name"))
112  .def("getDescriptorStartingRow", &DataPoints::getDescriptorStartingRow, py::arg("name"))
113  .def("assertDescriptorConsistency", &DataPoints::assertDescriptorConsistency)
114 
115  .def("allocateTime", &DataPoints::allocateTime, py::arg("name"), py::arg("dim"))
116  .def("allocateTimes", &DataPoints::allocateTimes, py::arg("newLabels"))
117  .def("addTime", &DataPoints::addTime, py::arg("name"), py::arg("newTime"))
118  .def("removeTime", &DataPoints::removeTime, py::arg("name"))
119  .def("getTimeCopyByName", &DataPoints::getTimeCopyByName, py::arg("name"))
120  .def("getTimeViewByName_const", (TimeConstView (DataPoints::*)(const std::string&) const) &DataPoints::getTimeViewByName, py::arg("name"))
121  .def("getTimeViewByName", (TimeView (DataPoints::*)(const std::string&)) &DataPoints::getTimeViewByName, py::arg("name"))
122  .def("getTimeRowViewByName_const", (TimeConstView (DataPoints::*)(const std::string&, const unsigned) const) &DataPoints::getTimeRowViewByName, py::arg("name"), py::arg("row"))
123  .def("getTimeRowViewByName", (TimeView (DataPoints::*)(const std::string&, const unsigned)) &DataPoints::getTimeRowViewByName, py::arg("name"), py::arg("row"))
124  .def("timeExists", (bool (DataPoints::*)(const std::string&) const) &DataPoints::timeExists, py::arg("name"))
125  .def("timeExists", (bool (DataPoints::*)(const std::string&, const unsigned) const) &DataPoints::timeExists, py::arg("name"), py::arg("dim"))
126  .def("getTimeDimension", &DataPoints::getTimeDimension, py::arg("name"))
127  .def("getTimeStartingRow", &DataPoints::getTimeStartingRow, py::arg("name"))
128  .def("assertTimesConsistency", &DataPoints::assertTimesConsistency)
129 // .def("__str__)", [](const DataPoints& self)
130 // {
131 // std::ostringstream oss;
132 //
133 // oss << self.features << '\n';
134 //
135 // for(const Label& l : self.featureLabels)
136 // {
137 // oss << "featureLabels : ";
138 // oss << "text : " << l.text;
139 // oss << " span : " << l.span << '\n';
140 // }
141 //
142 // oss << self.descriptors << '\n';
143 //
144 // for(const Label& l : self.descriptorLabels)
145 // {
146 // oss << "descriptorLabels : ";
147 // oss << "text : " << l.text;
148 // oss << " span : " << l.span << '\n';
149 // }
150 //
151 // oss << self.times;
152 //
153 // for(const Label& l : self.timeLabels)
154 // {
155 // oss << "timeLabels : ";
156 // oss << "text : " << l.text;
157 // oss << " span : " << l.span << '\n';
158 // }
159 //
160 // py::print(oss.str());
161 // })
162 
163  .def_readwrite("features", &DataPoints::features, "features of points in the cloud")
164  .def_readwrite("featureLabels", &DataPoints::featureLabels, "labels of features")
165  .def_readwrite("descriptors", &DataPoints::descriptors, "descriptors of points in the cloud, might be empty")
166  .def_readwrite("descriptorLabels", &DataPoints::descriptorLabels, "labels of descriptors")
167  .def_readwrite("times", &DataPoints::times, "time associated to each points, might be empty")
168  .def_readwrite("timeLabels", &DataPoints::timeLabels, "labels of times");
169  }
170  }
171 }
PointMatcher::DataPoints::timeExists
bool timeExists(const std::string &name) const
Look if a time with a given name exist.
Definition: pointmatcher/DataPoints.cpp:688
PointMatcher::DataPoints::getNbGroupedDescriptors
unsigned getNbGroupedDescriptors() const
Return the number of grouped descriptors (e.g., normals can have 3 components but would count as only...
Definition: pointmatcher/DataPoints.cpp:180
PointMatcher::DataPoints::descriptorLabels
Labels descriptorLabels
labels of descriptors
Definition: PointMatcher.h:334
PointMatcher::DataPoints::swapCols
void swapCols(Index iCol, Index jCol)
Swap column i and j in the point cloud, swap also features and descriptors if any....
Definition: pointmatcher/DataPoints.cpp:406
PointMatcher::DataPoints::Label::text
std::string text
name of the label
Definition: PointMatcher.h:223
PointMatcher::DataPoints::getEuclideanDim
unsigned getEuclideanDim() const
Return the dimension of the point cloud.
Definition: pointmatcher/DataPoints.cpp:165
PointMatcher::DataPoints::addTime
void addTime(const std::string &name, const Int64Matrix &newTime)
Add a time by name, remove first if already exists.
Definition: pointmatcher/DataPoints.cpp:637
PointMatcher::DataPoints::assertDescriptorConsistency
void assertDescriptorConsistency() const
Assert if descriptors are not consistent with features.
Definition: pointmatcher/DataPoints.cpp:611
PointMatcher::DataPoints::Labels
A vector of Label.
Definition: PointMatcher.h:229
PointMatcher::DataPoints::removeFeature
void removeFeature(const std::string &name)
Remove a feature by name, the whole matrix will be copied.
Definition: pointmatcher/DataPoints.cpp:445
PointMatcher::DataPoints::concatenate
void concatenate(const DataPoints &dp)
Add another point cloud after the current one. Faster merge will be achieved if all descriptor and ti...
Definition: pointmatcher/DataPoints.cpp:226
PointMatcher::DataPoints::addFeature
void addFeature(const std::string &name, const Matrix &newFeature)
Add a feature by name, remove first if already exists. The 'pad' field will stay at the end for homog...
Definition: pointmatcher/DataPoints.cpp:436
PointMatcher::DataPoints::allocateDescriptor
void allocateDescriptor(const std::string &name, const unsigned dim)
Makes sure a descriptor of a given name exists, if present, check its dimensions.
Definition: pointmatcher/DataPoints.cpp:519
PointMatcher::DataPoints::descriptorExists
bool descriptorExists(const std::string &name) const
Look if a descriptor with a given name exist.
Definition: pointmatcher/DataPoints.cpp:583
PointMatcher::DataPoints::addDescriptor
void addDescriptor(const std::string &name, const Matrix &newDescriptor)
Add a descriptor by name, remove first if already exists.
Definition: pointmatcher/DataPoints.cpp:533
PointMatcher::DataPoints::getDescriptorCopyByName
Matrix getDescriptorCopyByName(const std::string &name) const
Get descriptor by name, return a matrix containing a copy of the requested descriptor.
Definition: pointmatcher/DataPoints.cpp:548
PointMatcher::DataPoints::getTimeDim
unsigned getTimeDim() const
Return the total number of times.
Definition: pointmatcher/DataPoints.cpp:194
PointMatcher::DataPoints::getTimeCopyByName
Int64Matrix getTimeCopyByName(const std::string &name) const
Get time by name, return a matrix containing a copy of the requested time.
Definition: pointmatcher/DataPoints.cpp:651
PointMatcher::DataPoints
A point cloud.
Definition: PointMatcher.h:207
PointMatcher::DataPoints::allocateFeatures
void allocateFeatures(const Labels &newLabels)
Make sure a vector of features of given names exist.
Definition: pointmatcher/DataPoints.cpp:429
PointMatcher::DataPoints::getDescriptorStartingRow
unsigned getDescriptorStartingRow(const std::string &name) const
Return the starting row of a descriptor with a given name. Return 0 if the name is not found.
Definition: pointmatcher/DataPoints.cpp:604
PointMatcher::DataPoints::getHomogeneousDim
unsigned getHomogeneousDim() const
Return the dimension of the point cloud in homogeneous coordinates (one more than Euclidean dimension...
Definition: pointmatcher/DataPoints.cpp:173
testing::internal::string
::std::string string
Definition: gtest.h:1979
PointMatcher::DataPoints::timeLabels
Labels timeLabels
labels of times.
Definition: PointMatcher.h:336
PointMatcher::DataPoints::getTimeDimension
unsigned getTimeDimension(const std::string &name) const
Return the dimension of a time with a given name. Return 0 if the name is not found.
Definition: pointmatcher/DataPoints.cpp:702
PointMatcher::DataPoints::getFeatureDimension
unsigned getFeatureDimension(const std::string &name) const
Return the dimension of a feature with a given name. Return 0 if the name is not found.
Definition: pointmatcher/DataPoints.cpp:501
PointMatcher::DataPoints::TimeConstView
const typedef Eigen::Block< const Int64Matrix > TimeConstView
a view on a const time
Definition: PointMatcher.h:216
PointMatcher::DataPoints::InvalidField
An exception thrown when one tries to access features or descriptors unexisting or of wrong dimension...
Definition: PointMatcher.h:250
PointMatcher::DataPoints::getFeatureViewByName
ConstView getFeatureViewByName(const std::string &name) const
Get a const view on a feature by name, throw an exception if it does not exist.
Definition: pointmatcher/DataPoints.cpp:459
PointMatcher::DataPoints::featureExists
bool featureExists(const std::string &name) const
Look if a feature with a given name exist.
Definition: pointmatcher/DataPoints.cpp:487
PointMatcher::DataPoints::allocateTime
void allocateTime(const std::string &name, const unsigned dim)
Makes sure a time of a given name exists, if present, check its dimensions.
Definition: pointmatcher/DataPoints.cpp:622
python
Definition: add_descriptor.cpp:5
PointMatcher::DataPoints::allocateFeature
void allocateFeature(const std::string &name, const unsigned dim)
Makes sure a feature of a given name exists, if present, check its dimensions.
Definition: pointmatcher/DataPoints.cpp:422
PointMatcher::DataPoints::featureLabels
Labels featureLabels
labels of features
Definition: PointMatcher.h:332
PointMatcher::DataPoints::setColFrom
void setColFrom(Index thisCol, const DataPoints &that, Index thatCol)
Set column thisCol equal to column thatCol of that, copy features and descriptors if any....
Definition: pointmatcher/DataPoints.cpp:393
PointMatcher::DataPoints::createSimilarEmpty
DataPoints createSimilarEmpty() const
Create an empty DataPoints of similar dimensions and labels for features, descriptors and times.
Definition: pointmatcher/DataPoints.cpp:340
PointMatcher::DataPoints::descriptors
Matrix descriptors
descriptors of points in the cloud, might be empty
Definition: PointMatcher.h:333
PointMatcher::DataPoints::TimeView
Eigen::Block< Int64Matrix > TimeView
A view on a time.
Definition: PointMatcher.h:212
PointMatcher::DataPoints::getFeatureRowViewByName
ConstView getFeatureRowViewByName(const std::string &name, const unsigned row) const
Get a const view on a feature row by name and number, throw an exception if it does not exist.
Definition: pointmatcher/DataPoints.cpp:473
PointMatcher::DataPoints::getTimeViewByName
TimeConstView getTimeViewByName(const std::string &name) const
Get a const view on a time by name, throw an exception if it does not exist.
Definition: pointmatcher/DataPoints.cpp:659
PointMatcher::DataPoints::assertTimesConsistency
void assertTimesConsistency() const
Assert if times are not consistent with features.
Definition: pointmatcher/DataPoints.cpp:716
PointMatcher::DataPoints::getNbPoints
unsigned getNbPoints() const
Return the number of points contained in the point cloud.
Definition: pointmatcher/DataPoints.cpp:158
PointMatcher::DataPoints::features
Matrix features
features of points in the cloud
Definition: PointMatcher.h:331
PointMatcher::DataPoints::ConstView
const typedef Eigen::Block< const Matrix > ConstView
A view on a const feature or const descriptor.
Definition: PointMatcher.h:214
PointMatcher::DataPoints::Index
Matrix::Index Index
An index to a row or a column.
Definition: PointMatcher.h:218
python::pointmatcher::pybindDataPoints
void pybindDataPoints(py::class_< PM > &p_class)
Definition: data_points.cpp:7
PointMatcher::DataPoints::Labels::contains
bool contains(const std::string &text) const
Return whether there is a label named text.
Definition: pointmatcher/DataPoints.cpp:75
PointMatcher::DataPoints::times
Int64Matrix times
time associated to each points, might be empty
Definition: PointMatcher.h:335
PointMatcher::DataPoints::allocateTimes
void allocateTimes(const Labels &newLabels)
Make sure a vector of time of given names exist.
Definition: pointmatcher/DataPoints.cpp:629
PointMatcher::DataPoints::removeTime
void removeTime(const std::string &name)
Remove a descriptor by name, the whole matrix will be copied.
Definition: pointmatcher/DataPoints.cpp:644
PointMatcher::DataPoints::removeDescriptor
void removeDescriptor(const std::string &name)
Remove a descriptor by name, the whole matrix will be copied.
Definition: pointmatcher/DataPoints.cpp:540
PointMatcher::DataPoints::save
void save(const std::string &fileName, bool binary=false, unsigned precision=7) const
Save a point cloud to a file, determine format from extension.
Definition: pointmatcher/IO.cpp:809
PointMatcher::DataPoints::getTimeStartingRow
unsigned getTimeStartingRow(const std::string &name) const
Return the starting row of a time with a given name. Return 0 if the name is not found.
Definition: pointmatcher/DataPoints.cpp:709
PointMatcher::DataPoints::Label::span
size_t span
number of data dimensions the label spans
Definition: PointMatcher.h:224
PointMatcher::DataPoints::getDescriptorDimension
unsigned getDescriptorDimension(const std::string &name) const
Return the dimension of a descriptor with a given name. Return 0 if the name is not found.
Definition: pointmatcher/DataPoints.cpp:597
PointMatcher::DataPoints::getDescriptorDim
unsigned getDescriptorDim() const
Return the total number of descriptors.
Definition: pointmatcher/DataPoints.cpp:187
data_points.h
PointMatcher::DataPoints::View
Eigen::Block< Matrix > View
A view on a feature or descriptor.
Definition: PointMatcher.h:210
PointMatcher::DataPoints::conservativeResize
void conservativeResize(Index pointCount)
Resize the cloud to pointCount points, conserving existing ones.
Definition: pointmatcher/DataPoints.cpp:328
PointMatcher::DataPoints::getDescriptorRowViewByName
ConstView getDescriptorRowViewByName(const std::string &name, const unsigned row) const
Get a const view on a descriptor row by name and number, throw an exception if it does not exist.
Definition: pointmatcher/DataPoints.cpp:569
PointMatcher::DataPoints::Labels::totalDim
size_t totalDim() const
Return the sum of the spans of each label.
Definition: pointmatcher/DataPoints.cpp:87
PointMatcher::DataPoints::getTimeRowViewByName
TimeConstView getTimeRowViewByName(const std::string &name, const unsigned row) const
Get a const view on a time row by name and number, throw an exception if it does not exist.
Definition: pointmatcher/DataPoints.cpp:673
PointMatcher::DataPoints::load
static DataPoints load(const std::string &fileName)
Load a point cloud from a file, determine format from extension.
Definition: pointmatcher/IO.cpp:375
PointMatcher::DataPoints::getDescriptorViewByName
ConstView getDescriptorViewByName(const std::string &name) const
Get a const view on a descriptor by name, throw an exception if it does not exist.
Definition: pointmatcher/DataPoints.cpp:555
PointMatcher::DataPoints::getFeatureStartingRow
unsigned getFeatureStartingRow(const std::string &name) const
Return the starting row of a feature with a given name. Return 0 if the name is not found.
Definition: pointmatcher/DataPoints.cpp:508
PointMatcher::DataPoints::getFeatureCopyByName
Matrix getFeatureCopyByName(const std::string &name) const
Get feature by name, return a matrix containing a copy of the requested feature.
Definition: pointmatcher/DataPoints.cpp:452
PointMatcher::DataPoints::allocateDescriptors
void allocateDescriptors(const Labels &newLabels)
Make sure a vector of descriptors of given names exist.
Definition: pointmatcher/DataPoints.cpp:526


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