-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use marker association in globalBA/localBA
- Loading branch information
1 parent
c0181b0
commit 0aeba4a
Showing
4 changed files
with
344 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef OPENVSLAM_OPTIMIZER_G2O_DISTANCE_EDGE_H | ||
#define OPENVSLAM_OPTIMIZER_G2O_DISTANCE_EDGE_H | ||
|
||
#include "openvslam/type.h" | ||
#include "openvslam/optimize/internal/landmark_vertex.h" | ||
|
||
#include <g2o/core/base_binary_edge.h> | ||
|
||
namespace openvslam { | ||
namespace optimize { | ||
namespace internal { | ||
|
||
class distance_edge final : public g2o::BaseBinaryEdge<1, double, landmark_vertex, landmark_vertex> { | ||
public: | ||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
|
||
distance_edge(); | ||
|
||
bool read(std::istream& is) override; | ||
|
||
bool write(std::ostream& os) const override; | ||
|
||
void computeError() override; | ||
}; | ||
|
||
inline distance_edge::distance_edge() | ||
: g2o::BaseBinaryEdge<1, double, landmark_vertex, landmark_vertex>() {} | ||
|
||
inline bool distance_edge::read(std::istream& is) { | ||
is >> _measurement; | ||
is >> information()(0, 0); | ||
return true; | ||
} | ||
|
||
inline bool distance_edge::write(std::ostream& os) const { | ||
os << measurement() << " "; | ||
os << " " << information()(0, 0); | ||
return os.good(); | ||
} | ||
|
||
inline void distance_edge::computeError() { | ||
const auto v1 = static_cast<const landmark_vertex*>(_vertices.at(0)); | ||
const auto v2 = static_cast<const landmark_vertex*>(_vertices.at(1)); | ||
_error[0] = _measurement - (v2->estimate() - v1->estimate()).norm(); | ||
} | ||
|
||
} // namespace internal | ||
} // namespace optimize | ||
} // namespace openvslam | ||
|
||
#endif // OPENVSLAM_OPTIMIZER_G2O_DISTANCE_EDGE_H |
100 changes: 100 additions & 0 deletions
100
src/openvslam/optimize/internal/marker_vertex_container.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#ifndef OPENVSLAM_OPTIMIZE_G2O_MARKER_VERTEX_CONTAINER_H | ||
#define OPENVSLAM_OPTIMIZE_G2O_MARKER_VERTEX_CONTAINER_H | ||
|
||
#include "openvslam/type.h" | ||
#include "openvslam/data/marker.h" | ||
#include "openvslam/optimize/internal/landmark_vertex.h" | ||
|
||
#include <unordered_map> | ||
#include <memory> | ||
|
||
namespace openvslam { | ||
|
||
namespace data { | ||
class marker; | ||
} // namespace data | ||
|
||
namespace optimize { | ||
namespace internal { | ||
|
||
class marker_vertex_container { | ||
public: | ||
//! Constructor | ||
explicit marker_vertex_container(const std::shared_ptr<unsigned int> offset, const unsigned int num_reserve = 200); | ||
|
||
//! Destructor | ||
virtual ~marker_vertex_container() = default; | ||
|
||
//! Create and return the g2o vertex created from the specified marker | ||
std::vector<landmark_vertex*> create_vertices(const std::shared_ptr<data::marker>& mkr, const bool is_constant); | ||
|
||
//! Get vertex corresponding with the specified marker | ||
landmark_vertex* get_vertex(const std::shared_ptr<data::marker>& mkr, const unsigned int corner_id) const; | ||
|
||
//! Get vertex corresponding with the specified marker ID | ||
landmark_vertex* get_vertex(const unsigned int marker_id, const unsigned int corner_id) const; | ||
|
||
private: | ||
landmark_vertex* create_vertex(const unsigned int marker_id, const unsigned int corner_id, | ||
const Vec3_t& pos_w, const bool is_constant); | ||
|
||
//! vertex ID = offset + marker ID * 4 + corner ID | ||
const std::shared_ptr<unsigned int> offset_ = nullptr; | ||
|
||
//! key: marker ID, value: vertexs | ||
std::unordered_map<unsigned int, std::vector<landmark_vertex*>> vtx_container_; | ||
|
||
//! key: marker ID, value: vertex IDs | ||
std::unordered_map<unsigned int, std::vector<unsigned int>> vtx_id_container_; | ||
|
||
//! key: vertex ID, value: marker ID and corner ID | ||
std::unordered_map<unsigned int, std::pair<unsigned int, unsigned int>> id_container_; | ||
}; | ||
|
||
inline marker_vertex_container::marker_vertex_container(const std::shared_ptr<unsigned int> offset, const unsigned int num_reserve) | ||
: offset_(offset) { | ||
vtx_container_.reserve(num_reserve); | ||
vtx_id_container_.reserve(num_reserve); | ||
id_container_.reserve(num_reserve); | ||
} | ||
|
||
inline std::vector<landmark_vertex*> marker_vertex_container::create_vertices(const std::shared_ptr<data::marker>& mkr, const bool is_constant) { | ||
std::vector<landmark_vertex*> vertices; | ||
std::vector<unsigned int> vtx_ids; | ||
for (unsigned int i = 0; i < mkr->corners_pos_w_.size(); ++i) { | ||
vtx_ids.push_back(*offset_); | ||
vertices.push_back(create_vertex(mkr->id_, i, mkr->corners_pos_w_[i], is_constant)); | ||
} | ||
vtx_id_container_[mkr->id_] = vtx_ids; | ||
vtx_container_[mkr->id_] = vertices; | ||
return vertices; | ||
} | ||
|
||
inline landmark_vertex* marker_vertex_container::create_vertex(const unsigned int marker_id, const unsigned int corner_id, | ||
const Vec3_t& pos_w, const bool is_constant) { | ||
// Create vertex | ||
const auto vtx_id = *offset_; | ||
(*offset_)++; | ||
auto vtx = new landmark_vertex(); | ||
vtx->setId(vtx_id); | ||
vtx->setEstimate(pos_w); | ||
vtx->setFixed(is_constant); | ||
vtx->setMarginalized(false); | ||
// Set to id database | ||
id_container_[vtx_id] = std::make_pair(marker_id, corner_id); | ||
return vtx; | ||
} | ||
|
||
inline landmark_vertex* marker_vertex_container::get_vertex(const std::shared_ptr<data::marker>& mkr, const unsigned int corner_id) const { | ||
return get_vertex(mkr->id_, corner_id); | ||
} | ||
|
||
inline landmark_vertex* marker_vertex_container::get_vertex(const unsigned int marker_id, const unsigned int corner_id) const { | ||
return vtx_container_.at(marker_id)[corner_id]; | ||
} | ||
|
||
} // namespace internal | ||
} // namespace optimize | ||
} // namespace openvslam | ||
|
||
#endif // OPENVSLAM_OPTIMIZE_G2O_MARKER_VERTEX_CONTAINER_H |
Oops, something went wrong.