55
66#include " ct_icp/odometry.hpp"
77#include " ct_icp/types.hpp"
8+ #include " evalio/convert/base.h"
9+ #include " evalio/convert/eigen.h"
810#include " evalio/pipeline.h"
911#include " evalio/types.h"
1012
13+ namespace ev = evalio;
14+
15+ // ------------------------- Handle all conversions ------------------------- //
16+ namespace evalio {
17+ template <>
18+ inline evalio::Point convert (const ct_icp::Point3D& from) {
19+ return ev::Point {
20+ .x = from.raw_pt .x (),
21+ .y = from.raw_pt .y (),
22+ .z = from.raw_pt .z (),
23+ .intensity = 0.0 ,
24+ .t = ev::Duration::from_nsec (0 ),
25+ .row = 0 ,
26+ .col = 0 ,
27+ };
28+ }
29+
30+ template <>
31+ inline ct_icp::Point3D convert (const evalio::Point& from) {
32+ ct_icp::Point3D to;
33+ to.raw_pt = Eigen::Vector3d (from.x , from.y , from.z );
34+ to.pt = to.raw_pt ;
35+ to.alpha_timestamp = from.t .to_sec ();
36+ to.index_frame = 0 ;
37+ return to;
38+ }
39+
40+ template <>
41+ inline evalio::SE3 convert (const ct_icp::TrajectoryFrame& in) {
42+ return ev::SE3 (ev::SO3::fromMat (in.begin_R ), in.begin_t );
43+ }
44+ } // namespace evalio
45+
46+ // ------------------------- Actual Wrapper ------------------------- //
1147// Simple enum wrapper to parse all strings -> enum options
1248struct CTICPEnumParams {
1349 std::string motion_compensation;
@@ -91,44 +127,16 @@ struct CTICPEnumParams {
91127 }
92128};
93129
94- class CTICP : public evalio ::Pipeline {
130+ class CTICP : public ev ::Pipeline {
95131private:
96132 std::unique_ptr<ct_icp::Odometry> ct_icp_;
97133 ct_icp::OdometryOptions config_ =
98134 ct_icp::OdometryOptions::DefaultDrivingProfile ();
99135 CTICPEnumParams enum_params_;
100136
101- evalio ::SE3 lidar_T_imu_ = evalio ::SE3::identity();
137+ ev ::SE3 lidar_T_imu_ = ev ::SE3::identity();
102138 size_t scan_idx_ = 0 ;
103139
104- inline evalio::SE3 to_evalio_pose (const ct_icp::TrajectoryFrame& pose) const {
105- return evalio::SE3 (evalio::SO3::fromMat (pose.begin_R ), pose.begin_t );
106- }
107-
108- inline evalio::Point to_evalio_point (const ct_icp::Point3D& point) const {
109- return evalio::Point {
110- .x = point.raw_pt .x (),
111- .y = point.raw_pt .y (),
112- .z = point.raw_pt .z (),
113- .intensity = 0.0 ,
114- .t = evalio::Duration::from_nsec (0 ),
115- .row = 0 ,
116- .col = 0 ,
117- };
118- }
119-
120- inline evalio::Point to_evalio_point (const Eigen::Vector3d& point) const {
121- return evalio::Point {
122- .x = point.x (),
123- .y = point.y (),
124- .z = point.z (),
125- .intensity = 0.0 ,
126- .t = evalio::Duration::from_nsec (0 ),
127- .row = 0 ,
128- .col = 0 ,
129- };
130- }
131-
132140public:
133141 CTICP () {
134142 config_.debug_print = false ;
@@ -196,29 +204,24 @@ class CTICP: public evalio::Pipeline {
196204 // clang-format on
197205
198206 // Getters
199- const evalio ::SE3 pose() override {
207+ const ev ::SE3 pose() override {
200208 const auto pose = ct_icp_->Trajectory ().back ();
201- return to_evalio_pose (pose) * lidar_T_imu_;
209+ return ev::convert<ev::SE3> (pose) * lidar_T_imu_;
202210 }
203211
204- const std::map<std::string, std::vector<evalio::Point>> map () override {
205- const auto map = ct_icp_->GetLocalMap ();
206- std::vector<evalio::Point> ev_points;
207- ev_points.reserve (map.size ());
208- for (const auto & point : map) {
209- ev_points.push_back (to_evalio_point (point));
210- }
211- return {{" planar" , std::move (ev_points)}};
212+ const std::map<std::string, std::vector<ev::Point>> map () override {
213+ auto map = ct_icp_->GetLocalMap ();
214+ return ev::convert_map<decltype (map)>({{" planar" , map}});
212215 }
213216
214217 // Setters
215- void set_imu_params (evalio ::ImuParams params) override {}
218+ void set_imu_params (ev ::ImuParams params) override {}
216219
217- void set_lidar_params (evalio ::LidarParams params) override {
220+ void set_lidar_params (ev ::LidarParams params) override {
218221 config_.max_distance = params.max_range ;
219222 }
220223
221- void set_imu_T_lidar (evalio ::SE3 T) override {
224+ void set_imu_T_lidar (ev ::SE3 T) override {
222225 lidar_T_imu_ = T.inverse ();
223226 }
224227
@@ -228,49 +231,40 @@ class CTICP: public evalio::Pipeline {
228231 ct_icp_ = std::make_unique<ct_icp::Odometry>(config_);
229232 }
230233
231- void add_imu (evalio ::ImuMeasurement mm) override {}
234+ void add_imu (ev ::ImuMeasurement mm) override {}
232235
233- std::map<std::string, std::vector<evalio::Point>>
234- add_lidar (evalio::LidarMeasurement mm) override {
235- // Set everything up
236- std::vector<ct_icp::Point3D> pc;
237- pc.reserve (mm.points .size ());
236+ std::map<std::string, std::vector<ev::Point>>
237+ add_lidar (ev::LidarMeasurement mm) override {
238+ // Convert
239+ auto pc = ev::convert_iter<std::vector<ct_icp::Point3D>>(mm.points );
238240
239- // Figure out min/max timesteps
241+ // Normalize timestamps to [0, 1]
240242 const auto & [min, max] = std::minmax_element (
241- mm.points .cbegin (),
242- mm.points .cend (),
243- [](const evalio::Point& a, const evalio::Point& b) { return a.t < b.t ; }
243+ pc.cbegin (),
244+ pc.cend (),
245+ [](const ct_icp::Point3D& a, const ct_icp::Point3D& b) {
246+ return a.alpha_timestamp < b.alpha_timestamp ;
247+ }
244248 );
245249
246- const auto min_t = min->t . to_sec () ;
247- const auto max_t = max->t . to_sec () ;
248- const auto normalize = [min_t , max_t ](evalio::Duration t) {
249- return (t. to_sec () - min_t ) / (max_t - min_t );
250+ const auto min_t = min->alpha_timestamp ;
251+ const auto max_t = max->alpha_timestamp ;
252+ const auto normalize = [min_t , max_t ](double t) {
253+ return (t - min_t ) / (max_t - min_t );
250254 };
251255
252256 // Copy
253- for (const auto & point : mm.points ) {
254- ct_icp::Point3D p;
255- p.raw_pt = Eigen::Vector3d (point.x , point.y , point.z );
256- p.pt = p.raw_pt ;
257- p.alpha_timestamp = normalize (point.t );
258- p.index_frame = scan_idx_;
259- pc.push_back (p);
257+ for (auto & p : pc) {
258+ p.alpha_timestamp = normalize (p.alpha_timestamp );
260259 }
261260
262261 // Run through pipeline
263262 const auto summary = ct_icp_->RegisterFrame (pc);
264-
265- // Return the used points
266- std::vector<evalio::Point> ev_planar_points;
267- ev_planar_points.reserve (summary.keypoints .size ());
268- for (const auto & point : summary.keypoints ) {
269- ev_planar_points.push_back (to_evalio_point (point));
270- }
271-
272263 scan_idx_++;
273264
274- return {{" planar" , ev_planar_points}};
265+ // Return the used points
266+ return ev::convert_map<std::vector<ct_icp::Point3D>>(
267+ {{" planar" , summary.keypoints }}
268+ );
275269 }
276270};
0 commit comments