Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pybind __eq__ methods #578

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions pointmatcher/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,14 @@ typename PointMatcher<T>::DataPoints PointMatcher<T>::DataPoints::load(const std
const boost::filesystem::path path(fileName);
if (path.has_extension())
{
const string& ext(path.extension().string());
if(boost::iequals(ext, ".vtk"))
const string ext(path.extension().string());
if(ext == ".vtk")
return PointMatcherIO<T>::loadVTK(fileName);
else if(boost::iequals(ext, ".csv"))
else if(ext == ".csv")
return PointMatcherIO<T>::loadCSV(fileName);
else if(boost::iequals(ext, ".ply"))
else if(ext == ".ply")
return PointMatcherIO<T>::loadPLY(fileName);
else if(boost::iequals(ext, ".pcd"))
else if(ext == ".pcd")
return PointMatcherIO<T>::loadPCD(fileName);
else
throw runtime_error("loadAnyFormat(): Unknown extension \"" + ext + "\" for file \"" + fileName + "\", extension must be either \".vtk\", \".ply\", \".pcd\" or \".csv\"");
Expand Down Expand Up @@ -818,18 +818,18 @@ void PointMatcher<T>::DataPoints::save(const std::string& fileName, bool binary,
const boost::filesystem::path path(fileName);
if (path.has_extension())
{
const string& ext(path.extension().string());
if (boost::iequals(ext, ".vtk"))
const string ext(path.extension().string());
if (ext == ".vtk")
return PointMatcherIO<T>::saveVTK(*this, fileName, binary, precision);

if (binary)
throw runtime_error("save(): Binary writing is not supported together with extension \"" + ext + "\". Currently binary writing is only supported with \".vtk\".");

if (boost::iequals(ext, ".csv"))
if (ext == ".csv")
return PointMatcherIO<T>::saveCSV(*this, fileName, precision);
else if (boost::iequals(ext, ".ply"))
else if (ext == ".ply")
return PointMatcherIO<T>::savePLY(*this, fileName, precision);
else if (boost::iequals(ext, ".pcd"))
else if (ext == ".pcd")
return PointMatcherIO<T>::savePCD(*this, fileName, precision);
else
throw runtime_error("save(): Unknown extension \"" + ext + "\" for file \"" + fileName + "\", extension must be either \".vtk\", \".ply\", \".pcd\" or \".csv\"");
Expand Down Expand Up @@ -1845,19 +1845,6 @@ bool PointMatcherIO<T>::plyPropTypeValid(const std::string& type) {
}


template <typename T>
bool PointMatcherIO<T>::PLYElement::operator==(const PLYElement& rhs) const
{
return name == rhs.name;
}


template <typename T>
bool PointMatcherIO<T>::PLYProperty::operator==(const PLYProperty& rhs) const
{
return name == rhs.name && type == rhs.type;
}


//! @brief Load Point Cloud Library (pcd) file
//! @param fileName a string containing the path and the file name
Expand Down
19 changes: 17 additions & 2 deletions pointmatcher/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,15 @@ struct PointMatcherIO
// list property
PLYProperty(const std::string& idx_type, const std::string& type, const std::string& name, const unsigned pos); //! list prop ctor

bool operator==(const PLYProperty& other) const; //! compare with other property
bool friend operator==(const PLYProperty& lhs, const PLYProperty& rhs) //! compare with other property
{
return lhs.name == rhs.name && lhs.type == rhs.type;
}

bool friend operator!=(const PLYProperty& lhs, const PLYProperty& rhs) //! compare with other property
{
return lhs.name != rhs.name || lhs.type != rhs.type;
}
};

//! Map from a descriptor name to a list PLY property
Expand Down Expand Up @@ -325,8 +333,15 @@ struct PointMatcherIO

//bool supportsProperty(const PLYProperty& prop) const; //!< Returns true if property pro is supported by element

bool operator==(const PLYElement& other) const; //!< comparison operator for elements
bool friend operator==(const PLYElement& lhs, const PLYElement& rhs) //!< comparison operator for elements
{
return lhs.name == rhs.name;
}

bool friend operator!=(const PLYElement& lhs, const PLYElement& rhs) //!< comparison operator for elements
{
return lhs.name != rhs.name;
}
};


Expand Down
2 changes: 1 addition & 1 deletion python/pointmatcher/data_points_filters.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef PYTHON_MODULES_DATA_POINTS_FILTERS_MODULE_H
#define PYTHON_MODULES_DATAPOINTSFILTERS_MODULE_H
#define PYTHON_MODULES_DATA_POINTS_FILTERS_MODULE_H

#include "pypoint_matcher_helper.h"

Expand Down
17 changes: 9 additions & 8 deletions python/pointmatcher/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ Note that the header must at least contain "reading".
.def(py::init<>(), "Default constructor. If used member values must be filled later.")
.def(py::init<const std::string&, const std::string&, const unsigned>(), py::arg("type"), py::arg("name"), py::arg("pos"), "regular property")
.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")

.def("__eq__", &PLYProperty::operator==, "compare with other property");
.def(py::self == py::self)
.def(py::self != py::self);

using PLYProperties = PMIO::PLYProperties;
py::bind_vector<PLYProperties>(pyPointMatcherIO, "PLYProperties", "Vector of properties specific to PLY files");
Expand All @@ -160,7 +160,9 @@ PLY Element constructor

This object holds information about a PLY element contained in the file.
It is filled out when reading the header and used when parsing the data.
)pbdoc").def("__eq__", &PLYElement::operator==, "comparison operator for elements");
)pbdoc")
.def(py::self == py::self)
.def(py::self != py::self);

using PLYVertex = PMIO::PLYVertex;
py::class_<PLYVertex, PLYElement>(pyPointMatcherIO, "PLYVertex", "Implementation of PLY vertex element")
Expand All @@ -173,11 +175,10 @@ Constructor
Implementation of PLY element interface for the vertex element
)pbdoc");

// FIXME : Generate undefined symbol error for "elementSupported" or "createElement" method when importing the module
// using PLYElementF = PMIO::PLYElementF;
// py::class_<PLYElementF>(pyPointMatcherIO, "PLYElementF", "Factory for PLY elements")
// .def("elementSupported", &PLYElementF::elementSupported, py::arg("elem_name"), "returns true if element named elem_name is supported by this parser")
// .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");
using PLYElementF = PMIO::PLYElementF;
py::class_<PLYElementF>(pyPointMatcherIO, "PLYElementF", "Factory for PLY elements")
.def("elementSupported", &PLYElementF::elementSupported, py::arg("elem_name"), "returns true if element named elem_name is supported by this parser")
.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");

using PCDproperty = PMIO::PCDproperty;
py::class_<PCDproperty>(pyPointMatcherIO, "PCDproperty", "Information for a PCD property")
Expand Down
3 changes: 2 additions & 1 deletion utest/ui/icp/GeneralTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ TEST(icpTest, icpTest)
std::cout << "Testing file " << d->path().string() << std::endl;
// Load config file, and form ICP object
PM::ICP icp;
if (d->path().has_extension() != true) continue;
if (d->path().extension().string() != ".yaml") continue;
std::string config_file = d->path().string();
if (fs::extension(config_file) != ".yaml") continue;
std::ifstream ifs(config_file.c_str());
EXPECT_NO_THROW(icp.loadFromYaml(ifs)) << "This error was caused by the test file:" << endl << " " << config_file;

Expand Down
Loading