// SPDX-FileCopyrightText: Copyright 2024 Kenji Koide // SPDX-License-Identifier: MIT #include #include #include #include #include #include #include #include #include #include #include #include namespace py = pybind11; using namespace small_gicp; void define_factors(py::module& m) { // DistanceRejector py::class_(m, "DistanceRejector", "Correspondence rejection based on the distance between points.") .def(py::init<>()) .def("set_max_distance", [](DistanceRejector& rejector, double dist) { rejector.max_dist_sq = dist * dist; }, py::arg("dist"), "Set the maximum distance."); // ICPFactor py::class_(m, "ICPFactor", "ICP per-point factor") .def(py::init<>()) .def( "linearize", []( ICPFactor& factor, const PointCloud& target, const PointCloud& source, const KdTree& kdtree, const Eigen::Matrix4d& T, size_t source_index, const DistanceRejector& rejector) -> std::tuple, Eigen::Matrix, double> { Eigen::Matrix H = Eigen::Matrix::Zero(); Eigen::Matrix b = Eigen::Matrix::Zero(); double e = 0.0; bool succ = factor.linearize(target, source, kdtree, Eigen::Isometry3d(T), source_index, rejector, &H, &b, &e); return std::make_tuple(succ, H, b, e); }, py::arg("target"), py::arg("source"), py::arg("kdtree"), py::arg("T"), py::arg("source_index"), py::arg("rejector"), "Linearize the factor. Returns a tuple of success, Hessian, gradient, and error."); // PointToPlaneICPFactor py::class_(m, "PointToPlaneICPFactor", "Point-to-plane ICP per-point factor") .def(py::init<>()) .def( "linearize", []( PointToPlaneICPFactor& factor, const PointCloud& target, const PointCloud& source, const KdTree& kdtree, const Eigen::Matrix4d& T, size_t source_index, const DistanceRejector& rejector) -> std::tuple, Eigen::Matrix, double> { Eigen::Matrix H = Eigen::Matrix::Zero(); Eigen::Matrix b = Eigen::Matrix::Zero(); double e = 0.0; bool succ = factor.linearize(target, source, kdtree, Eigen::Isometry3d(T), source_index, rejector, &H, &b, &e); return std::make_tuple(succ, H, b, e); }, py::arg("target"), py::arg("source"), py::arg("kdtree"), py::arg("T"), py::arg("source_index"), py::arg("rejector"), "Linearize the factor. Returns a tuple of success, Hessian, gradient, and error."); // GICPFactor py::class_(m, "GICPFactor", "Generalized ICP per-point factor") // .def(py::init<>()) .def( "linearize", []( GICPFactor& factor, const PointCloud& target, const PointCloud& source, const KdTree& kdtree, const Eigen::Matrix4d& T, size_t source_index, const DistanceRejector& rejector) -> std::tuple, Eigen::Matrix, double> { Eigen::Matrix H = Eigen::Matrix::Zero(); Eigen::Matrix b = Eigen::Matrix::Zero(); double e = 0.0; bool succ = factor.linearize(target, source, kdtree, Eigen::Isometry3d(T), source_index, rejector, &H, &b, &e); return std::make_tuple(succ, H, b, e); }, py::arg("target"), py::arg("source"), py::arg("kdtree"), py::arg("T"), py::arg("source_index"), py::arg("rejector"), "Linearize the factor. Returns a tuple of success, Hessian, gradient, and error."); }