Welcome to mirror list, hosted at ThFree Co, Russian Federation.

traffic_mode.hpp « openlr_assessment_tool « openlr_match_quality « openlr - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d7c88654d3a46e858d95350d88e5cbe99033794 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#pragma once

#include "openlr/openlr_match_quality/openlr_assessment_tool/points_controller_delegate_base.hpp"
#include "openlr/openlr_match_quality/openlr_assessment_tool/segment_correspondence.hpp"
#include "openlr/openlr_match_quality/openlr_assessment_tool/traffic_drawer_delegate_base.hpp"

#include "openlr/decoded_path.hpp"
#include "openlr/openlr_model.hpp"

#include "indexer/data_source.hpp"

#include "base/exception.hpp"

#include "3party/pugixml/src/pugixml.hpp"

#include <cstdint>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>

#include <QAbstractTableModel>
#include <Qt>

class QItemSelection;
class Selection;

DECLARE_EXCEPTION(TrafficModeError, RootException);

namespace impl
{
/// This class denotes a "non-deterministic" feature point.
/// I.e. it is a set of all pairs <FeatureID, point index>
/// located at a specified coordinate.
/// Only one point at a time is considered active.
class RoadPointCandidate
{
public:
  RoadPointCandidate(std::vector<openlr::FeaturePoint> const & points,
                     m2::PointD const & coord);

  void ActivateCommonPoint(RoadPointCandidate const & rpc);
  openlr::FeaturePoint const & GetPoint() const;
  m2::PointD const & GetCoordinate() const;

private:
  static size_t const kInvalidId;

  void SetActivePoint(FeatureID const & fid);

  m2::PointD m_coord = m2::PointD::Zero();
  std::vector<openlr::FeaturePoint> m_points;

  size_t m_activePointIndex = kInvalidId;
};
}  // namespace impl

class BookmarkManager;

namespace openlr
{
/// This class is used to map sample ids to real data
/// and change sample evaluations.
class TrafficMode : public QAbstractTableModel
{
  Q_OBJECT

public:
  // TODO(mgsergio): Check we are on the right mwm. I.e. right mwm version and everything.
  TrafficMode(std::string const & dataFileName, DataSource const & dataSource,
              std::unique_ptr<TrafficDrawerDelegateBase> drawerDelegate,
              std::unique_ptr<PointsControllerDelegateBase> pointsDelegate,
              QObject * parent = Q_NULLPTR);

  bool SaveSampleAs(std::string const & fileName) const;

  int rowCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE;
  int columnCount(const QModelIndex & parent = QModelIndex()) 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;

  bool IsBuildingPath() const { return m_buildingPath; }
  void GoldifyMatchedPath();
  void StartBuildingPath();
  void PushPoint(m2::PointD const & coord,
                 std::vector<FeaturePoint> const & points);
  void PopPoint();
  void CommitPath();
  void RollBackPath();
  void IgnorePath();

  size_t GetPointsCount() const;
  m2::PointD const & GetPoint(size_t const index) const;
  m2::PointD const & GetLastPoint() const;
  std::vector<m2::PointD> GetGoldenPathPoints() const;

public slots:
  void OnItemSelected(QItemSelection const & selected, QItemSelection const &);
  void OnClick(m2::PointD const & clickPoint, Qt::MouseButton const button)
  {
    HandlePoint(clickPoint, button);
  }

signals:
  void EditingStopped();
  void SegmentSelected(int segmentId);

private:
  void HandlePoint(m2::PointD clickPoint, Qt::MouseButton const button);
  bool StartBuildingPathChecks() const;

  DataSource const & m_dataSource;
  std::vector<SegmentCorrespondence> m_segments;
  // Non-owning pointer to an element of m_segments.
  SegmentCorrespondence * m_currentSegment = nullptr;

  std::unique_ptr<TrafficDrawerDelegateBase> m_drawerDelegate;
  std::unique_ptr<PointsControllerDelegateBase> m_pointsDelegate;

  bool m_buildingPath = false;
  std::vector<impl::RoadPointCandidate> m_goldenPath;

  // Clone this document and add things to its clone when saving sample.
  pugi::xml_document m_template;
};
}  // namespace openlr