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)
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 }
Matrix getFeatureCopyByName(const std::string &name) const
Get feature by name, return a matrix containing a copy of the requested feature.
void allocateDescriptor(const std::string &name, const unsigned dim)
Makes sure a descriptor of a given name exists, if present, check its dimensions. ...
void allocateTime(const std::string &name, const unsigned dim)
Makes sure a time of a given name exists, if present, check its dimensions.
void allocateTimes(const Labels &newLabels)
Make sure a vector of time of given names exist.
const Eigen::Block< const Int64Matrix > TimeConstView
a view on a const time
Definition: PointMatcher.h:216
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.
unsigned getTimeDim() const
Return the total number of times.
Matrix descriptors
descriptors of points in the cloud, might be empty
Definition: PointMatcher.h:333
void removeTime(const std::string &name)
Remove a descriptor by name, the whole matrix will be copied.
bool timeExists(const std::string &name) const
Look if a time with a given name exist.
Eigen::Block< Int64Matrix > TimeView
A view on a time.
Definition: PointMatcher.h:212
void setColFrom(Index thisCol, const DataPoints &that, Index thatCol)
Set column thisCol equal to column thatCol of that, copy features and descriptors if any...
void assertDescriptorConsistency() const
Assert if descriptors are not consistent with features.
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...
Matrix::Index Index
An index to a row or a column.
Definition: PointMatcher.h:218
ConstView getDescriptorViewByName(const std::string &name) const
Get a const view on a descriptor by name, throw an exception if it does not exist.
::std::string string
Definition: gtest.h:1979
unsigned getNbPoints() const
Return the number of points contained in the point cloud.
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...
unsigned getNbGroupedDescriptors() const
Return the number of grouped descriptors (e.g., normals can have 3 components but would count as only...
Labels featureLabels
labels of features
Definition: PointMatcher.h:332
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...
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...
Labels timeLabels
labels of times.
Definition: PointMatcher.h:336
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...
TimeConstView getTimeViewByName(const std::string &name) const
Get a const view on a time by name, throw an exception if it does not exist.
void pybindDataPoints(py::class_< PM > &p_class)
Definition: data_points.cpp:7
Matrix getDescriptorCopyByName(const std::string &name) const
Get descriptor by name, return a matrix containing a copy of the requested descriptor.
unsigned getHomogeneousDim() const
Return the dimension of the point cloud in homogeneous coordinates (one more than Euclidean dimension...
void removeDescriptor(const std::string &name)
Remove a descriptor by name, the whole matrix will be copied.
const Eigen::Block< const Matrix > ConstView
A view on a const feature or const descriptor.
Definition: PointMatcher.h:214
void concatenate(const DataPoints &dp)
Add another point cloud after the current one. Faster merge will be achieved if all descriptor and ti...
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.
bool featureExists(const std::string &name) const
Look if a feature with a given name exist.
bool descriptorExists(const std::string &name) const
Look if a descriptor with a given name exist.
bool contains(const std::string &text) const
Return whether there is a label named text.
void swapCols(Index iCol, Index jCol)
Swap column i and j in the point cloud, swap also features and descriptors if any. Assumes sizes are similar.
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...
void allocateFeatures(const Labels &newLabels)
Make sure a vector of features of given names exist.
void conservativeResize(Index pointCount)
Resize the cloud to pointCount points, conserving existing ones.
void addFeature(const std::string &name, const Matrix &newFeature)
Add a feature by name, remove first if already exists. The &#39;pad&#39; field will stay at the end for homog...
size_t span
number of data dimensions the label spans
Definition: PointMatcher.h:224
void assertTimesConsistency() const
Assert if times are not consistent with features.
Eigen::Block< Matrix > View
A view on a feature or descriptor.
Definition: PointMatcher.h:210
void save(const std::string &fileName, bool binary=false) const
Save a point cloud to a file, determine format from extension.
An exception thrown when one tries to access features or descriptors unexisting or of wrong dimension...
Definition: PointMatcher.h:250
void allocateFeature(const std::string &name, const unsigned dim)
Makes sure a feature of a given name exists, if present, check its dimensions.
Int64Matrix times
time associated to each points, might be empty
Definition: PointMatcher.h:335
void addTime(const std::string &name, const Int64Matrix &newTime)
Add a time by name, remove first if already exists.
size_t totalDim() const
Return the sum of the spans of each label.
Matrix features
features of points in the cloud
Definition: PointMatcher.h:331
DataPoints createSimilarEmpty() const
Create an empty DataPoints of similar dimensions and labels for features, descriptors and times...
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.
unsigned getDescriptorDim() const
Return the total number of descriptors.
static DataPoints load(const std::string &fileName)
Load a point cloud from a file, determine format from extension.
void addDescriptor(const std::string &name, const Matrix &newDescriptor)
Add a descriptor by name, remove first if already exists.
void allocateDescriptors(const Labels &newLabels)
Make sure a vector of descriptors of given names exist.
unsigned getEuclideanDim() const
Return the dimension of the point cloud.
std::string text
name of the label
Definition: PointMatcher.h:223
Int64Matrix getTimeCopyByName(const std::string &name) const
Get time by name, return a matrix containing a copy of the requested time.
void removeFeature(const std::string &name)
Remove a feature by name, the whole matrix will be copied.
Labels descriptorLabels
labels of descriptors
Definition: PointMatcher.h:334
ConstView getFeatureViewByName(const std::string &name) const
Get a const view on a feature by name, throw an exception if it does not exist.


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