From fe54beb840d7355eeeea2ede2eb84a38c4b1da94 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 13 Feb 2019 13:48:04 +0300 Subject: [PATCH] Displaying positive and genative offsets for edges in openlr assessment tool. --- openlr/decoded_path.cpp | 23 ++++--- openlr/decoded_path.hpp | 3 + .../openlr_assessment_tool/mainwindow.cpp | 1 + .../segment_correspondence.cpp | 6 ++ .../segment_correspondence.hpp | 7 +++ .../openlr_assessment_tool/traffic_mode.cpp | 62 +++++++++++++++++-- .../openlr_assessment_tool/traffic_mode.hpp | 4 +- .../openlr_assessment_tool/traffic_panel.cpp | 2 +- openlr/paths_connector.cpp | 1 - 9 files changed, 92 insertions(+), 17 deletions(-) diff --git a/openlr/decoded_path.cpp b/openlr/decoded_path.cpp index 34bfc8191d..6ed600ce1a 100644 --- a/openlr/decoded_path.cpp +++ b/openlr/decoded_path.cpp @@ -19,18 +19,18 @@ namespace { +uint32_t UintFromXML(pugi::xml_node const & node) +{ + THROW_IF_NODE_IS_EMPTY(node, openlr::DecodedPathLoadError, ("Can't parse uint")); + return node.text().as_uint(); +} + bool IsForwardFromXML(pugi::xml_node const & node) { THROW_IF_NODE_IS_EMPTY(node, openlr::DecodedPathLoadError, ("Can't parse IsForward")); return node.text().as_bool(); } -uint32_t SegmentIdFromXML(pugi::xml_node const & node) -{ - THROW_IF_NODE_IS_EMPTY(node, openlr::DecodedPathLoadError, ("Can't parse SegmentId")); - return node.text().as_uint(); -} - void LatLonToXML(ms::LatLon const & latLon, pugi::xml_node & node) { auto const kDigitsAfterComma = 5; @@ -63,6 +63,15 @@ void FeatureIdToXML(FeatureID const & fid, pugi::xml_node & node) namespace openlr { +uint32_t UintValueFromXML(pugi::xml_node const & node) +{ + auto const value = node.child("olr:value"); + if (!value) + return 0; + + return UintFromXML(value); +} + void WriteAsMappingForSpark(std::string const & fileName, std::vector const & paths) { std::ofstream ofs(fileName); @@ -120,7 +129,7 @@ void PathFromXML(pugi::xml_node const & node, DataSource const & dataSource, Pat FeatureIdFromXML(e.child("FeatureID"), dataSource, fid); auto const isForward = IsForwardFromXML(e.child("IsForward")); - auto const segmentId = SegmentIdFromXML(e.child("SegmentId")); + auto const segmentId = UintFromXML(e.child("SegmentId")); ms::LatLon start, end; LatLonFromXML(e.child("StartJunction"), start); diff --git a/openlr/decoded_path.hpp b/openlr/decoded_path.hpp index 19a66a1409..d41c80852e 100644 --- a/openlr/decoded_path.hpp +++ b/openlr/decoded_path.hpp @@ -5,6 +5,7 @@ #include "base/exception.hpp" #include "base/newtype.hpp" +#include #include #include #include @@ -30,6 +31,8 @@ struct DecodedPath Path m_path; }; +uint32_t UintValueFromXML(pugi::xml_node const & node); + void WriteAsMappingForSpark(std::string const & fileName, std::vector const & paths); void WriteAsMappingForSpark(std::ostream & ost, std::vector const & paths); diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp index 824980eb35..0968973acf 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/mainwindow.cpp @@ -326,6 +326,7 @@ void MainWindow::CreateTrafficPanel(string const & dataFilePath) m_docWidget->setWidget(new TrafficPanel(m_trafficMode, m_docWidget)); m_docWidget->adjustSize(); + m_docWidget->setMinimumWidth(400); m_docWidget->show(); } diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.cpp index 24f0c54bef..17bf153d60 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.cpp @@ -6,6 +6,9 @@ SegmentCorrespondence::SegmentCorrespondence(SegmentCorrespondence const & sc) { m_partnerSegment = sc.m_partnerSegment; + m_positiveOffset = sc.m_positiveOffset; + m_negativeOffset = sc.m_negativeOffset; + m_matchedPath = sc.m_matchedPath; m_fakePath = sc.m_fakePath; m_goldenPath = sc.m_goldenPath; @@ -17,11 +20,14 @@ SegmentCorrespondence::SegmentCorrespondence(SegmentCorrespondence const & sc) } SegmentCorrespondence::SegmentCorrespondence(openlr::LinearSegment const & segment, + uint32_t positiveOffset, uint32_t negativeOffset, openlr::Path const & matchedPath, openlr::Path const & fakePath, openlr::Path const & goldenPath, pugi::xml_node const & partnerSegmentXML) : m_partnerSegment(segment) + , m_positiveOffset(positiveOffset) + , m_negativeOffset(negativeOffset) , m_matchedPath(matchedPath) , m_fakePath(fakePath) { diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.hpp b/openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.hpp index 091f023f6b..ae6119dd4c 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.hpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.hpp @@ -19,6 +19,7 @@ public: SegmentCorrespondence(SegmentCorrespondence const & sc); SegmentCorrespondence(openlr::LinearSegment const & segment, + uint32_t positiveOffset, uint32_t negativeOffset, openlr::Path const & matchedPath, openlr::Path const & fakePath, openlr::Path const & goldenPath, @@ -27,6 +28,9 @@ public: openlr::Path const & GetMatchedPath() const { return m_matchedPath; } bool HasMatchedPath() const { return !m_matchedPath.empty(); } + uint32_t GetPositiveOffset() const { return m_positiveOffset; } + uint32_t GetNegativeOffset() const { return m_negativeOffset; } + openlr::Path const & GetFakePath() const { return m_fakePath; } bool HasFakePath() const { return !m_fakePath.empty(); } @@ -48,6 +52,9 @@ public: private: openlr::LinearSegment m_partnerSegment; + uint32_t m_positiveOffset = 0; + uint32_t m_negativeOffset = 0; + openlr::Path m_matchedPath; openlr::Path m_fakePath; openlr::Path m_goldenPath; diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp index 81c6dc7c10..bfed2d2351 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.cpp @@ -5,6 +5,7 @@ #include "indexer/data_source.hpp" #include "indexer/scales.hpp" +#include "base/assert.hpp" #include "base/scope_guard.hpp" #include "3party/pugixml/src/utils.hpp" @@ -142,7 +143,7 @@ TrafficMode::TrafficMode(std::string const & dataFileName, DataSource const & da // TODO(mgsergio): Unify error handling interface of openlr_xml_mode and decoded_path parsers. auto const partnerSegmentXML = xmlSegment.child("reportSegments"); if (!openlr::SegmentFromXML(partnerSegmentXML, segment)) - MYTHROW(TrafficModeError, ("An error occured while parsing: can't parse segment")); + MYTHROW(TrafficModeError, ("An error occurred while parsing: can't parse segment")); if (auto const route = xmlSegment.child("Route")) openlr::PathFromXML(route, m_dataSource, matchedPath); @@ -151,7 +152,29 @@ TrafficMode::TrafficMode(std::string const & dataFileName, DataSource const & da if (auto const route = xmlSegment.child("GoldenRoute")) openlr::PathFromXML(route, m_dataSource, goldenPath); - m_segments.emplace_back(segment, matchedPath, fakePath, goldenPath, partnerSegmentXML); + uint32_t positiveOffsetM = 0; + uint32_t negativeOffsetM = 0; + if (auto const reportSegmentLRC = partnerSegmentXML.child("ReportSegmentLRC")) + { + if (auto const method = reportSegmentLRC.child("method")) + { + if (auto const locationReference = method.child("olr:locationReference")) + { + if (auto const optionLinearLocationReference = locationReference + .child("olr:optionLinearLocationReference")) + { + if (auto const positiveOffset = optionLinearLocationReference.child("olr:positiveOffset")) + positiveOffsetM = UintValueFromXML(positiveOffset); + + if (auto const negativeOffset = optionLinearLocationReference.child("olr:negativeOffset")) + negativeOffsetM = UintValueFromXML(negativeOffset); + } + } + } + } + + m_segments.emplace_back(segment, positiveOffsetM, negativeOffsetM, matchedPath, fakePath, + goldenPath, partnerSegmentXML); if (auto const status = xmlSegment.child("Ignored")) { if (status.text().as_bool()) @@ -161,13 +184,13 @@ TrafficMode::TrafficMode(std::string const & dataFileName, DataSource const & da } catch (openlr::DecodedPathLoadError const & e) { - MYTHROW(TrafficModeError, ("An exception occured while parsing", dataFileName, e.Msg())); + MYTHROW(TrafficModeError, ("An exception occurred while parsing", dataFileName, e.Msg())); } - // TODO(mgsergio): LOG(LINFO, (xxx, "segments are loaded")); + LOG(LINFO, (segments.size(), "segments are loaded.")); } -// TODO(mgsergio): Check if a path was commited, or commit it. +// TODO(mgsergio): Check if a path was committed, or commit it. bool TrafficMode::SaveSampleAs(std::string const & fileName) const { CHECK(!fileName.empty(), ("Can't save to an empty file.")); @@ -211,7 +234,7 @@ int TrafficMode::rowCount(const QModelIndex & parent) const return static_cast(m_segments.size()); } -int TrafficMode::columnCount(const QModelIndex & parent) const { return 2; } +int TrafficMode::columnCount(const QModelIndex & parent) const { return 4; } QVariant TrafficMode::data(const QModelIndex & index, int role) const { @@ -230,6 +253,33 @@ QVariant TrafficMode::data(const QModelIndex & index, int role) const if (index.column() == 1) return static_cast(m_segments[index.row()].GetStatus()); + if (index.column() == 2) + return m_segments[index.row()].GetPositiveOffset(); + + if (index.column() == 3) + return m_segments[index.row()].GetNegativeOffset(); + + return QVariant(); +} + +QVariant TrafficMode::headerData(int section, Qt::Orientation orientation, + int role /* = Qt::DisplayRole */) const +{ + if (orientation == Qt::Horizontal) + { + if (role == Qt::DisplayRole) + { + switch (section) + { + case 0: return "Segment id"; break; + case 1: return "Status code"; break; + case 2: return "Positive offset (Meters)"; break; + case 3: return "Negative offset (Meters)"; break; + } + UNREACHABLE(); + } + } + return QVariant(); } diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp index 4d7c88654d..af6af998bd 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_mode.hpp @@ -76,10 +76,10 @@ public: int rowCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex & index, int role) const Q_DECL_OVERRIDE; - // QVariant headerData(int section, Qt::Orientation orientation, - // int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; Qt::ItemFlags flags(QModelIndex const & index) const Q_DECL_OVERRIDE; diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_panel.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_panel.cpp index 0cd112f632..a10d714376 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/traffic_panel.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/traffic_panel.cpp @@ -69,7 +69,7 @@ void TrafficPanel::CreateTable(QAbstractItemModel * trafficModel) m_table->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows); m_table->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection); m_table->verticalHeader()->setVisible(false); - m_table->horizontalHeader()->setVisible(false); + m_table->horizontalHeader()->setVisible(true); m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); m_table->setModel(trafficModel); diff --git a/openlr/paths_connector.cpp b/openlr/paths_connector.cpp index 95fe768b26..8a02f3ddfd 100644 --- a/openlr/paths_connector.cpp +++ b/openlr/paths_connector.cpp @@ -142,7 +142,6 @@ bool PathsConnector::FindShortestPath(Graph::Edge const & from, Graph::Edge cons Graph::EdgeVector & path) { // TODO(mgsergio): Turn Dijkstra to A*. - uint32_t const kLengthToleranceM = 10; struct State