Locus No Pilotus
Project of four first grade MIPT DAFE/RSE students (for engineering practical work in the second semester) in Qt C++
Loading...
Searching...
No Matches
data_tools::PlotArea Class Reference

Класс, упрощающий управление классами gui на QCustomPlot. More...

#include <plot_area.h>

Collaboration diagram for data_tools::PlotArea:

Public Member Functions

 PlotArea ()=default
 
 PlotArea (QCustomPlot *plot)
 
void ClearTrajectory ()
 
gui::FlyingRobotGetRobot ()
 
gui::TrajectoryGetTrajectory ()
 
void ReDraw ()
 Перерисовывает на полотне все объекты и обновляет данные
 
void ReDrawTrajectory ()
 Перерисовывает на полотне траекторию
 
void SetAmountOfRobots (unsigned short amount)
 
void SetPlot (QCustomPlot *plot)
 Устанавливает значение plot.
 
void Setup (DataManager *manager)
 
size_t TrajectorySize () const
 

Private Member Functions

void CalculateTrajectory_ ()
 Расчет вектора сегментов по заданным объектам на полотне
 
void CheckHills_ ()
 
void CheckIntersectionsBetweenHills_ ()
 
void CheckIntersectionsBetweenTrappyCircles_ ()
 
void CheckTargets_ ()
 
void CheckTrappyCircles_ ()
 
void CheckTrappyLines_ ()
 

Private Attributes

unsigned short amount_of_robots_ = 1
 
std::unique_ptr< DataManagermanager_
 
std::unique_ptr< QCustomPlot > plot_
 
std::unique_ptr< gui::FlyingRobotrobot_ {new gui::FlyingRobot()}
 
std::unique_ptr< gui::Trajectorytrajectory_ {new gui::Trajectory()}
 

Detailed Description

Класс, упрощающий управление классами gui на QCustomPlot.

Constructor & Destructor Documentation

◆ PlotArea() [1/2]

data_tools::PlotArea::PlotArea ( )
default

◆ PlotArea() [2/2]

data_tools::PlotArea::PlotArea ( QCustomPlot * plot)
inline
13: plot_{plot} {}
std::unique_ptr< QCustomPlot > plot_
Definition plot_area.h:44

Member Function Documentation

◆ CalculateTrajectory_()

void data_tools::PlotArea::CalculateTrajectory_ ( )
private

Расчет вектора сегментов по заданным объектам на полотне

44 {
45 auto lib_targets = std::vector<lib::Target>(manager_->GetTargets().size());
46 for (size_t i = 0; i < lib_targets.size(); i++)
47 lib_targets[i] = manager_->GetTargets()[i].GetData();
48
49 auto lib_hills = std::vector<lib::Hill>(manager_->GetHills().size());
50 for (size_t i = 0; i < lib_hills.size(); i++)
51 lib_hills[i] = manager_->GetHills()[i].GetData();
52
53 auto lib_tr_lines =
54 std::vector<lib::TrappyLine>(manager_->GetTrappyLines().size());
55 for (size_t i = 0; i < lib_tr_lines.size(); i++)
56 lib_tr_lines[i] = manager_->GetTrappyLines()[i].GetData();
57
58 auto lib_tr_circles =
59 std::vector<lib::TrappyCircle>(manager_->GetTrappyCircles().size());
60 for (size_t i = 0; i < lib_tr_circles.size(); i++)
61 lib_tr_circles[i] = manager_->GetTrappyCircles()[i].GetData();
62
63 trajectory_->Calculate(lib_targets, lib_hills, lib_tr_circles, lib_tr_lines,
65 if (lib_targets.size() > 1) robot_->SetTrajectory(trajectory_.get());
66}
std::unique_ptr< gui::FlyingRobot > robot_
Definition plot_area.h:48
unsigned short amount_of_robots_
Definition plot_area.h:50
std::unique_ptr< DataManager > manager_
Definition plot_area.h:45
std::unique_ptr< gui::Trajectory > trajectory_
Definition plot_area.h:47
void SetTrajectory(gui::Trajectory *trj)
Definition flying_robot.cpp:6
void Calculate(const std::vector< lib::Target > &targets, const std::vector< lib::Hill > &hills, const std::vector< lib::TrappyCircle > &tr_circles, const std::vector< lib::TrappyLine > &tr_lines, unsigned short amount_of_robots)
Расчет вектора сегментов по заданным объектам на полотне
Definition trajectory.cpp:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckHills_()

void data_tools::PlotArea::CheckHills_ ( )
private
141 {
142 for (const auto& hill : manager_->GetHills()) {
143 // Проверка на пересечения с другими Hill
145
146 // Проверка на выпуклость многоугольника
147 // Определяем знак векторного произведения
148 QVector2D v1 = QVector2D(hill.GetVertices()[1].x - hill.GetVertices()[0].x,
149 hill.GetVertices()[1].y - hill.GetVertices()[0].y);
150 QVector2D v2 = QVector2D(hill.GetVertices()[2].x - hill.GetVertices()[1].x,
151 hill.GetVertices()[2].y - hill.GetVertices()[1].y);
152 short sign = (v1.x() * v2.y() - v1.y() * v2.x()) /
153 abs(v1.x() * v2.y() - v1.y() * v2.x());
154
155 size_t sz = hill.GetVertices().size();
156 for (size_t i = 1; i < sz; i++) {
157 QVector2D vec1 = QVector2D(
158 hill.GetVertices()[(i + 1) % sz].x - hill.GetVertices()[i % sz].x,
159 hill.GetVertices()[(i + 1) % sz].y - hill.GetVertices()[i % sz].y);
160 QVector2D vec2 = QVector2D(hill.GetVertices()[(i + 2) % sz].x -
161 hill.GetVertices()[(i + 1) % sz].x,
162 hill.GetVertices()[(i + 2) % sz].y -
163 hill.GetVertices()[(i + 1) % sz].y);
164
165 double product = vec1.x() * vec2.y() - vec1.y() * vec2.x();
166
167 if (product == 0 || product / abs(product) != sign) {
168 std::string text = "There is non-convex polygon! Id: ";
169 text += std::to_string(hill.GetData().GetId());
170 throw std::invalid_argument(text);
171 }
172 }
173
174 // Проверка на то, что какой-то Target находится внутри или на Hill
175 for (const auto& target : manager_->GetTargets())
176 if (IsPointInsideHill(target.GetPoint(), hill.GetVertices())) {
177 std::string text = "There is Target in Hill! Id's: ";
178 text += std::to_string(target.GetData().GetId());
179 text += " and ";
180 text += std::to_string(hill.GetData().GetId());
181 throw std::invalid_argument(text);
182 }
183 }
184}
void CheckIntersectionsBetweenHills_()
Definition check_errors.cpp:47
bool IsPointInsideHill(lib::Point point, std::vector< lib::Point > vertices)
Definition check_errors.cpp:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckIntersectionsBetweenHills_()

void data_tools::PlotArea::CheckIntersectionsBetweenHills_ ( )
private
47 {
48 if (manager_->GetHillsPtrs().empty()) return;
49
50 for (size_t i = 0; i < manager_->GetHills().size() - 1; i++) {
51 std::vector<math::Point> vec;
52 for (const auto& v : manager_->GetHillsPtrs()[i]->GetVertices())
53 vec.push_back(math::Point(v));
54
55 for (size_t j = i + 1; j < manager_->GetHillsPtrs().size(); j++) {
56 std::vector<math::Point> vec2;
57 for (const auto& v : manager_->GetHillsPtrs()[j]->GetVertices())
58 vec2.push_back(math::Point(v));
59
60 for (size_t k = 0; k < vec2.size(); k++) {
62 vec2[(k + 1) % vec2.size()]) ||
63 IsPointInsideHill(manager_->GetHillsPtrs()[j]->GetVertices()[k],
64 manager_->GetHillsPtrs()[i]->GetVertices())) {
65 std::string text = "There are intersections between Hills! Id's: ";
66 text +=
67 std::to_string(manager_->GetHillsPtrs()[i]->GetData().GetId());
68 text += " and ";
69 text +=
70 std::to_string(manager_->GetHillsPtrs()[j]->GetData().GetId());
71 throw std::invalid_argument(text);
72 }
73 }
74 }
75 }
76}
Многоугольное препятствие
Definition obstacles.h:100
Definition adjacency_matrix.cpp:7
bool AreThereIntersections(const CircleObstacle &cr_obst, const Point &point1, const Point &point2)
Проверяет, пересекает ли отрезок, проведенный через две точки, окружность
Definition helpers_functions.cpp:226
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckIntersectionsBetweenTrappyCircles_()

void data_tools::PlotArea::CheckIntersectionsBetweenTrappyCircles_ ( )
private
25 {
26 if (manager_->GetTrappyCircles().empty()) return;
27
28 for (size_t i = 0; i < manager_->GetTrappyCircles().size() - 1; i++) {
29 const auto trc = manager_->GetTrappyCircles()[i];
30
31 for (size_t j = i + 1; j < manager_->GetTrappyCircles().size(); j++) {
32 const auto trc2 = manager_->GetTrappyCircles()[j];
33
34 if (lib::DistanceBetweenPoints(trc2.GetCenter(), trc.GetCenter()) <
35 trc2.GetRadius() + trc.GetRadius()) {
36 std::string text =
37 "There are intersections between TrappyCircles! Id's: ";
38 text += std::to_string(trc.GetData().GetId());
39 text += " and ";
40 text += std::to_string(trc2.GetData().GetId());
41 throw std::invalid_argument(text);
42 }
43 }
44 }
45}
double DistanceBetweenPoints(const Point &first_point, const Point &second_point)
Находит расстояние между двумя мат. точками
Definition point.cpp:27
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckTargets_()

void data_tools::PlotArea::CheckTargets_ ( )
private
131 {
132 if (manager_->GetTargetsPtrs().size() > 30) {
133 std::string text = "There are too many Targets: ";
134 text += std::to_string(manager_->GetTargetsPtrs().size());
135 text += " > 30 \n";
136 text += "(sorry, but our algo is now to slow for more)";
137 throw std::invalid_argument(text);
138 }
139}
Here is the caller graph for this function:

◆ CheckTrappyCircles_()

void data_tools::PlotArea::CheckTrappyCircles_ ( )
private
78 {
79 // Проверка на пересечения с другими TrappyCircle
81
82 if (manager_->GetTrappyCircles().empty()) return;
83
84 for (const auto& trc : manager_->GetTrappyCircles()) {
85 // Проверка на то, что какой-то Target находится внутри TrappyCircle
86 for (const auto& target : manager_->GetTargets()) {
87 if (lib::DistanceBetweenPoints(target.GetPoint(), trc.GetCenter()) <=
88 trc.GetRadius()) {
89 std::string text = "There is Target in TrappyCircle! Id's: ";
90 text += std::to_string(target.GetData().GetId());
91 text += " and ";
92 text += std::to_string(trc.GetData().GetId());
93 throw std::invalid_argument(text);
94 }
95 }
96
97 // Проверка на пересечения с Hill
98 for (const auto& hill : manager_->GetHillsPtrs()) {
99 std::vector<math::Point> vec;
100 for (const auto& v : hill->GetVertices()) vec.push_back(math::Point(v));
101
102 for (size_t k = 0; k < vec.size(); k++) {
104 math::CircleObstacle(trc.GetCenter(), trc.GetRadius()), vec[k],
105 vec[(k + 1) % vec.size()]) ||
106 IsPointInsideHill(trc.GetCenter(), hill->GetVertices()) ||
108 trc.GetCenter(), hill->GetVertices()[k]) < trc.GetRadius()) {
109 std::string text =
110 "There are intersections between TrappyCircle and Hill! Id's: ";
111 text += std::to_string(trc.GetData().GetId());
112 text += " and ";
113 text += std::to_string(hill->GetData().GetId());
114 throw std::invalid_argument(text);
115 }
116 }
117 }
118 }
119}
void CheckIntersectionsBetweenTrappyCircles_()
Definition check_errors.cpp:25
Круговое препятствие
Definition obstacles.h:58
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckTrappyLines_()

void data_tools::PlotArea::CheckTrappyLines_ ( )
private
121 {
122 auto l = manager_->GetTrappyLinesPtrs().size();
123 auto n = manager_->GetTargetsPtrs().size() + amount_of_robots_ - 1;
124 if (l == 0) return;
125
126 // прекрасная формула
127 if ((pow(n, 2) - n) / 2 - l < n)
128 throw std::invalid_argument("There are too many TrappyLines here!");
129}
Here is the caller graph for this function:

◆ ClearTrajectory()

void data_tools::PlotArea::ClearTrajectory ( )
inline
33{ trajectory_->Clear(); }
void Clear()
Definition trajectory.h:56
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetRobot()

gui::FlyingRobot * data_tools::PlotArea::GetRobot ( )
inline
26{ return robot_.get(); }
Here is the caller graph for this function:

◆ GetTrajectory()

gui::Trajectory * data_tools::PlotArea::GetTrajectory ( )
inline
28{ return trajectory_.get(); }
Here is the caller graph for this function:

◆ ReDraw()

void data_tools::PlotArea::ReDraw ( )

Перерисовывает на полотне все объекты и обновляет данные

8 {
9 plot_->clearPlottables();
10 plot_->clearItems();
11
12 for (auto& target : manager_->GetTargetsPtrs()) target->Draw(plot_.get());
13
14 for (auto& hill : manager_->GetHillsPtrs()) hill->Draw(plot_.get());
15
16 for (auto& tr_circle : manager_->GetTrappyCirclesPtrs())
17 tr_circle->Draw(plot_.get());
18
19 for (auto& tr_line : manager_->GetTrappyLinesPtrs())
20 tr_line->Draw(plot_.get());
21
23
24 plot_->replot();
25}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReDrawTrajectory()

void data_tools::PlotArea::ReDrawTrajectory ( )

Перерисовывает на полотне траекторию

27 {
28 ReDraw();
29
30 try {
35
37 trajectory_->Draw(plot_.get());
38 plot_->replot();
39 } catch (const std::exception& e) {
40 QMessageBox::warning(plot_.get(), "Cannot calculate trajectory!", e.what());
41 }
42}
void CheckHills_()
Definition check_errors.cpp:141
void CheckTargets_()
Definition check_errors.cpp:131
void CalculateTrajectory_()
Расчет вектора сегментов по заданным объектам на полотне
Definition plot_area.cpp:44
void CheckTrappyCircles_()
Definition check_errors.cpp:78
void CheckTrappyLines_()
Definition check_errors.cpp:121
void ReDraw()
Перерисовывает на полотне все объекты и обновляет данные
Definition plot_area.cpp:8
void Draw(QCustomPlot *plot) override
Отрисовывает фигуру на полотне
Definition trajectory.cpp:6
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAmountOfRobots()

void data_tools::PlotArea::SetAmountOfRobots ( unsigned short amount)
inline
37{ amount_of_robots_ = amount; }
Here is the caller graph for this function:

◆ SetPlot()

void data_tools::PlotArea::SetPlot ( QCustomPlot * plot)
inline

Устанавливает значение plot.

Parameters
plotуказатель на полотно
21{ plot_.reset(plot); }
Here is the caller graph for this function:

◆ Setup()

void data_tools::PlotArea::Setup ( DataManager * manager)
6{ manager_.reset(manager); }
Here is the caller graph for this function:

◆ TrajectorySize()

size_t data_tools::PlotArea::TrajectorySize ( ) const
inline
35{ return trajectory_->Segments().size(); }
std::vector< gui::Segment > & Segments()
Возвращает вектор сегментов
Definition trajectory.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ amount_of_robots_

unsigned short data_tools::PlotArea::amount_of_robots_ = 1
private

◆ manager_

std::unique_ptr<DataManager> data_tools::PlotArea::manager_
private

◆ plot_

std::unique_ptr<QCustomPlot> data_tools::PlotArea::plot_
private

◆ robot_

std::unique_ptr<gui::FlyingRobot> data_tools::PlotArea::robot_ {new gui::FlyingRobot()}
private
48{new gui::FlyingRobot()};
Класс, который позволяет анимировать движение робота
Definition flying_robot.h:13

◆ trajectory_

std::unique_ptr<gui::Trajectory> data_tools::PlotArea::trajectory_ {new gui::Trajectory()}
private
47{new gui::Trajectory()};
Фигура траектории облёта объектов на полотне
Definition trajectory.h:14

The documentation for this class was generated from the following files: