Skip to content

Commit 96fcda0

Browse files
Merge pull request #2 from ConstantRobotics-Ltd/dev
Dev
2 parents a5bfaed + 16e2cb5 commit 96fcda0

File tree

5 files changed

+28
-36
lines changed

5 files changed

+28
-36
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# **plotOpenCv C++ library**
55

6-
**v1.0.0**
6+
**v1.0.1**
77

88
------
99

@@ -34,6 +34,7 @@
3434
| Version | Release date | What's new |
3535
| ------- | ------------ | ------------------------------------------------------------ |
3636
| 1.0.0 | 08.09.2023 | First version. |
37+
| 1.0.1 | 18.09.2023 | Update used container for plots. |
3738

3839

3940
# plot class description
@@ -131,7 +132,7 @@ std::cout << "plotOpenCv class version: " << plotOpenCv::getVersion() << std::en
131132
Console output:
132133

133134
```bash
134-
plotOpenCv class version: 1.0.0
135+
plotOpenCv class version: 1.0.1
135136
```
136137

137138
## addPlot (for 1D dataset) method

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.13)
66
## LIBRARY-PROJECT
77
## name and version
88
###############################################################################
9-
project(plotOpenCv VERSION 1.0.0 LANGUAGES CXX)
9+
project(plotOpenCv VERSION 1.0.1 LANGUAGES CXX)
1010

1111
###############################################################################
1212
## SETTINGS

src/plotOpenCv.cpp

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void cr::utils::Plot::renderPlot(Plot2D plot)
9393
plot.m_inMax, plot.m_outMax, plot.m_outMin) + plot.m_offsetY);
9494

9595
cv::line(*m_image, previousPoint, currentPoint, plot.m_color,
96-
plot.m_tickness, cv::LINE_8);
96+
plot.m_tickness, cv::LINE_8);
9797
}
9898
}
9999
// 2D vector drawing.
@@ -117,30 +117,26 @@ void cr::utils::Plot::renderPlot(Plot2D plot)
117117
cv::Scalar color, int thickness)
118118
{
119119
// Check if id is already contained.
120-
for (const int& i : m_ids)
120+
for (const auto& pair : m_plots)
121121
{
122+
const int& i = pair.first;
122123
if (i == id)
123124
{
124125
// Remove plot from list.
125-
std::list<Plot2D>::iterator it = m_plots.begin();
126-
std::advance(it, id);
127-
m_plots.erase(it);
128-
129-
// Remove id from list.
130-
auto removeIndex = std::remove(m_ids.begin(), m_ids.end(), id);
131-
m_ids.erase(removeIndex, m_ids.end());
126+
auto it = m_plots.find(i);
127+
if (it != m_plots.end())
128+
m_plots.erase(it);
132129
}
133130
}
134-
135-
m_ids.push_back(id);
136-
131+
137132
// Add ploting object to list.
138133
std::vector<double> doubles;
139134
for (int i =0;i<points.size(); i++)
140135
{
141136
doubles.push_back(static_cast<double>(points[i]));
142137
}
143-
m_plots.emplace_back(Plot2D(doubles, id, start, end, color, thickness));
138+
139+
m_plots.insert(std::make_pair(id, Plot2D(doubles, id, start, end, color, thickness)));
144140

145141
}
146142

@@ -149,23 +145,18 @@ void cr::utils::Plot::renderPlot(Plot2D plot)
149145
cv::Scalar color, int thickness)
150146
{
151147
// Check if id is already contained.
152-
for (const int& i : m_ids)
148+
for (const auto& pair : m_plots)
153149
{
150+
const int& i = pair.first;
154151
if (i == id)
155152
{
156153
// Remove plot from list.
157-
std::list<Plot2D>::iterator it = m_plots.begin();
158-
std::advance(it, id);
159-
m_plots.erase(it);
160-
161-
// Remove id from list.
162-
auto removeIndex = std::remove(m_ids.begin(), m_ids.end(), id);
163-
m_ids.erase(removeIndex, m_ids.end());
154+
auto it = m_plots.find(i);
155+
if (it != m_plots.end())
156+
m_plots.erase(it);
164157
}
165158
}
166159

167-
m_ids.push_back(id);
168-
169160
// Convert points vector to double.
170161
std::vector<std::vector<double>> doubles;
171162
std::vector<double> temp(2);
@@ -178,7 +169,7 @@ void cr::utils::Plot::renderPlot(Plot2D plot)
178169
}
179170

180171
// Add ploting object to list.
181-
m_plots.emplace_back(Plot2D(doubles, id, start, end, color, thickness));
172+
m_plots.insert(std::make_pair(id, Plot2D(doubles, id, start, end, color, thickness)));
182173

183174
}
184175

@@ -200,8 +191,8 @@ void cr::utils::Plot::clean()
200191
cv::line(*m_image, cv::Point(i, 0),
201192
cv::Point(i, m_height), cv::Scalar(0, 0, 0));
202193

194+
// Clear all instances from container.
203195
m_plots.clear();
204-
m_ids.clear();
205196
}
206197

207198
void cr::utils::Plot::show()
@@ -225,9 +216,10 @@ void cr::utils::Plot::show()
225216
cv::Point(i, m_height), cv::Scalar(0, 0, 0));
226217
}
227218

228-
// Draw plot objects on window.
229-
for (const Plot2D& plot : m_plots)
219+
// Iterate over the values (Plot2D instances) in the map
220+
for (const auto& pair : m_plots)
230221
{
222+
const Plot2D& plot = pair.second;
231223
renderPlot(plot);
232224
}
233225

src/plotOpenCv.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include <vector>
33
#include <string>
4+
#include <map>
45
#include <opencv2/opencv.hpp>
56
#include <opencv2/highgui/highgui.hpp>
67

@@ -146,10 +147,8 @@ class Plot {
146147
cv::Scalar m_horizontalScaleLineColor;
147148
/// Window name
148149
std::string m_name;
149-
/// List of plots
150-
std::list<Plot2D> m_plots;
151-
/// List of ids
152-
std::vector<int> m_ids;
150+
// Create a std::map to store Plot2D instances with integer IDs
151+
std::map<int, Plot2D> m_plots;
153152

154153
/**
155154
* @brief Method to render a plot on window.

src/plotOpenCvVersion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
#define PLOT_OPENCV_MAJOR_VERSION 1
44
#define PLOT_OPENCV_MINOR_VERSION 0
5-
#define PLOT_OPENCV_PATCH_VERSION 0
5+
#define PLOT_OPENCV_PATCH_VERSION 1
66

7-
#define PLOT_OPENCV_VERSION "1.0.0"
7+
#define PLOT_OPENCV_VERSION "1.0.1"

0 commit comments

Comments
 (0)