Skip to content

Commit

Permalink
Use strJoin from stuff library
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerKuemmerle committed Aug 13, 2024
1 parent 3de3d5c commit 5e58d32
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
28 changes: 2 additions & 26 deletions g2o/apps/g2o_viewer/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,19 @@
#include "g2o/core/sparse_optimizer.h"
#include "g2o/stuff/filesys_tools.h"
#include "g2o/stuff/logger.h"
#include "g2o/stuff/string_tools.h"
#include "properties_widget.h"
#include "viewer_properties_widget.h"

namespace {
/**
* @brief Join into a string using a delimeter
*
* @tparam Iterator
* @tparam std::iterator_traits<Iterator>::value_type
* @param b begin of the range for output
* @param e end of the range for output
* @param delimiter will be inserted in between elements
* @return std::string joined string
*/
template <typename Iterator,
typename Value = typename std::iterator_traits<Iterator>::value_type>
std::string strJoin(Iterator b, Iterator e, const std::string& delimiter) {
std::ostringstream os;
if (b != e) {
std::copy(b, std::prev(e),
std::ostream_iterator<Value>(os, delimiter.c_str()));
b = std::prev(e);
}
if (b != e) {
os << *b;
}
return os.str();
}

QString prepareFilter(const std::vector<g2o::io::FileFilter>& filters) {
std::vector<std::string> filter_patterns;
filter_patterns.reserve(filters.size());
std::transform(filters.begin(), filters.end(),
std::back_inserter(filter_patterns),
[](const g2o::io::FileFilter& f) { return f.filter; });
return QString::fromStdString(
strJoin(filter_patterns.begin(), filter_patterns.end(), ";;"));
g2o::strJoin(filter_patterns.begin(), filter_patterns.end(), ";;"));
}

g2o::io::Format extractFileFormat(
Expand Down
7 changes: 4 additions & 3 deletions g2o/core/io/io_g2o.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ std::optional<AbstractGraph> IoG2O::load(std::istream& input) {
}
result.vertices().emplace_back(vertex);
G2O_TRACE("Read vertex {} with estimate [{}]", vertex.tag,
fmt::join(vertex.estimate, ","));
strJoin(vertex.estimate.begin(), vertex.estimate.end(), ", "));
last_data_container = &result.vertices().back();
} else if (type_info.elementTypeBit == HyperGraph::kHgetEdge) {
AbstractGraph::AbstractEdge edge;
Expand Down Expand Up @@ -169,8 +169,9 @@ std::optional<AbstractGraph> IoG2O::load(std::istream& input) {
G2O_TRACE(
"Read edge {} connecting [{}] with measurement [{}] and information "
"[{}]",
edge.tag, fmt::join(edge.ids, ","), fmt::join(edge.measurement, ","),
fmt::join(edge.information, ","));
edge.tag, strJoin(edge.ids.begin(), edge.ids.end(), ", "),
strJoin(edge.measurement.begin(), edge.measurement.end(), ", "),
strJoin(edge.information.begin(), edge.information.end(), ", "));
last_data_container = &result.edges().back();
} else if (type_info.elementTypeBit == HyperGraph::kHgetData) {
if (!last_data_container) {
Expand Down
14 changes: 8 additions & 6 deletions g2o/core/optimizable_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,9 @@ bool OptimizableGraph::load(std::istream& is, io::Format format) {
}
}
if (!vertsOkay) {
G2O_ERROR("Unable to find vertices for edge {} IDs: {}",
abstract_edge.tag, fmt::join(abstract_edge.ids, " "));
G2O_ERROR(
"Unable to find vertices for edge {} IDs: {}", abstract_edge.tag,
strJoin(abstract_edge.ids.begin(), abstract_edge.ids.end(), " "));
continue;
}
for (size_t i = 0; i < abstract_edge.param_ids.size(); ++i) {
Expand All @@ -451,8 +452,9 @@ bool OptimizableGraph::load(std::istream& is, io::Format format) {
if (r != c) information(c, r) = information(r, c);
}
if (!addEdge(edge)) {
G2O_ERROR("Failure adding Edge {} IDs {}", abstract_edge.tag,
fmt::join(abstract_edge.ids, " "));
G2O_ERROR(
"Failure adding Edge {} IDs {}", abstract_edge.tag,
strJoin(abstract_edge.ids.begin(), abstract_edge.ids.end(), " "));
}
if (!abstract_edge.data.empty())
addDataToGraphElement(*edge, abstract_edge.data);
Expand Down Expand Up @@ -755,10 +757,10 @@ bool OptimizableGraph::verifyInformationMatrices(bool verbose) const {
for (const auto& v : e->vertices()) ids.push_back(v->id());
if (!isSymmetric)
G2O_WARN("Information Matrix for an edge is not symmetric: {}",
fmt::join(ids, " "));
strJoin(ids.begin(), ids.end(), " "));
else
G2O_WARN("Information Matrix for an edge is not SPD: {}",
fmt::join(ids, " "));
strJoin(ids.begin(), ids.end(), " "));
if (isSymmetric)
G2O_WARN("eigenvalues: {}", eigenSolver.eigenvalues().transpose());
}
Expand Down

0 comments on commit 5e58d32

Please sign in to comment.