Skip to content

Commit

Permalink
Expose map transformation method
Browse files Browse the repository at this point in the history
  • Loading branch information
victorreijgwart committed Dec 12, 2024
1 parent 43003a4 commit ba9ae88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions examples/python/edit/transform_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
import numpy as np
import pywavemap as wave

# Load the map
user_home = os.path.expanduser('~')
input_map_path = os.path.join(user_home, "your_map.wvmp")
your_map = wave.Map.load(input_map_path)

# Define a transformation that flips the map upside down, for illustration
translation = np.array([0.0, 0.0, 0.0])
rotation = wave.Rotation(w=0.0, x=1.0, y=0.0, z=0.0)
transformation = wave.Pose(rotation, translation)

# Transform the map
your_map = wave.edit.transform(your_map, transformation)

# Save the map
output_map_path = os.path.join(user_home, "your_map_transformed.wvmp")
your_map.store(output_map_path)
16 changes: 16 additions & 0 deletions library/python/src/edit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <memory>

#include <nanobind/eigen/dense.h>
#include <nanobind/stl/unique_ptr.h>
#include <wavemap/core/map/hashed_chunked_wavelet_octree.h>
#include <wavemap/core/map/hashed_wavelet_octree.h>
#include <wavemap/core/utils/edit/crop.h>
#include <wavemap/core/utils/edit/multiply.h>
#include <wavemap/core/utils/edit/transform.h>

using namespace nb::literals; // NOLINT

Expand Down Expand Up @@ -45,5 +47,19 @@ void add_edit_module(nb::module_& m_edit) {
edit::multiply(map, multiplier, std::make_shared<ThreadPool>());
},
"map"_a, "multiplier"_a);

// Map transformation methods
m_edit.def(
"transform",
[](HashedWaveletOctree& B_map, const Transformation3D& T_AB) {
return edit::transform(B_map, T_AB, std::make_shared<ThreadPool>());
},
"map"_a, "transformation"_a);
m_edit.def(
"transform",
[](HashedChunkedWaveletOctree& B_map, const Transformation3D& T_AB) {
return edit::transform(B_map, T_AB, std::make_shared<ThreadPool>());
},
"map"_a, "transformation"_a);
}
} // namespace wavemap
3 changes: 3 additions & 0 deletions library/python/src/measurements.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ void add_measurement_bindings(nb::module_& m) {
nb::class_<Rotation3D>(m, "Rotation",
"A class representing rotations in 3D space.")
.def(nb::init<Rotation3D::RotationMatrix>(), "rotation_matrix"_a)
.def(nb::init<FloatingPoint, FloatingPoint, FloatingPoint,
FloatingPoint>(),
"w"_a, "x"_a, "y"_a, "z"_a)
.def("inverse", &Rotation3D::inverse, "Compute the rotation's inverse.");
nb::class_<Transformation3D>(m, "Pose",
"A class representing poses in 3D space.")
Expand Down

0 comments on commit ba9ae88

Please sign in to comment.