Skip to content

Commit c9c576d

Browse files
Files structure changed
1 parent 7d7bd19 commit c9c576d

File tree

9 files changed

+668
-427
lines changed

9 files changed

+668
-427
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# Build results
1111
[Bb]uild/
1212
.vs/
13+
.vscode/
1314
out/
1415

1516
CMakeSettings.json

README.md

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# **PlotOpenCv C++ library**
77

8-
**v1.1.0**
8+
**v1.2.0**
99

1010

1111

@@ -16,18 +16,20 @@
1616
- [Library files](#library-files)
1717
- [plot class description](#plot-class-description)
1818
- [Class declaration](#class-declaration)
19+
- [getVersion method](#getversion-method)
20+
- [Class constructor](#class-constructor)
1921
- [addPlot (1D) method](#addplot-for-1d-dataset-method)
2022
- [addPlot (2D) method](#addplot-for-2d-dataset-method)
2123
- [clean method](#show-method)
2224
- [show method](#clean-method)
23-
- [Example](#example)
2425
- [Build and connect to your project](#build-and-connect-to-your-project)
26+
- [Example](#example)
2527

2628

2729

2830
# Overview
2931

30-
**PlotOpenCv** C++ library provides the visualization of 2-dimensional line charts. This library is built upon the OpenCV, providing users with a convenient and efficient tool for visualizing data through line charts. With **PlotOpenCv**, users can create multiple line charts within a single window and tune various chart parameters, such as line width, color, and more. It utilizes C++17 standard. The library is licensed under the Apache 2.0 license.
32+
**PlotOpenCv** C++ library provides the visualization of 2-dimensional line charts. This library is built upon the OpenCV, providing users with a convenient and efficient tool for visualizing data through line charts. With **PlotOpenCv**, users can create multiple line charts within a single window and tune various chart parameters, such as line width, color, and more. It utilizes C++17 standard. The library is licensed under the **Apache 2.0** license.
3133

3234

3335

@@ -42,6 +44,7 @@
4244
| 1.0.2 | 16.04.2024 | - Antialiased line drawing implemented.<br/>- Window size issue fixed.<br/>- Documentation updated. |
4345
| 1.0.3 | 17.05.2024 | - Documentation updated. |
4446
| 1.1.0 | 19.07.2024 | - CMake structure updated.<br />- Files renamed. |
47+
| 1.2.0 | 23.07.2024 | - Files structure changed to hide opencv headers.<br />- Library interface changed. |
4548

4649

4750

@@ -57,6 +60,9 @@ src ------------------------- Library source code folder.
5760
PlotOpenCvVersion.h ----- Header file with library version.
5861
PlotOpenCvVersion.h.in -- File for CMake to generate version header.
5962
PlotOpenCv.cpp ---------- C++ implementation file.
63+
Impl -------------------- Folder with plot implementation.
64+
PlotOpenCvImpl.h ---- Plot implementation header file.
65+
PlotOpenCvImpl.cpp -- C++ implementation file.
6066
test ------------------------ Folder for test application.
6167
CMakeLists.txt ---------- CMake file of test application.
6268
main.cpp ---------------- Source code of test application.
@@ -77,7 +83,26 @@ namespace cr
7783
{
7884
namespace utils
7985
{
80-
/// plot class.
86+
87+
/**
88+
* @brief Plot color.
89+
*/
90+
class PlotColor
91+
{
92+
public:
93+
/// Class constructor
94+
PlotColor(int b, int g, int r) : b(b), g(g), r(r) {}
95+
/// Blue color 0-255.
96+
int b{0};
97+
/// Green color 0-255.
98+
int g{0};
99+
/// Red color 0-255.
100+
int r{0};
101+
};
102+
103+
/**
104+
* @brief Plot class.
105+
*/
81106
class Plot
82107
{
83108
public:
@@ -87,21 +112,22 @@ public:
87112

88113
/// Class constructor.
89114
Plot(std::string name, int width = 1280, int height = 720,
90-
cv::Scalar backgroundColor = cv::Scalar(255, 255, 255),
91-
cv::Scalar scaleLineColor = cv::Scalar(0, 128, 128));
115+
PlotColor backgroundColor = PlotColor(255, 255, 255),
116+
PlotColor scaleLineColor = PlotColor(0, 128, 128));
92117

93118
/// Class destructor.
94119
~Plot();
95120

96121
/// Render plots on window.
97122
template <typename T>
98123
void addPlot(std::vector<T>& points, int id, int start = 0, int end = 0,
99-
cv::Scalar color = cv::Scalar(255, 255, 255), int thickness = 1);
124+
PlotColor color = PlotColor(255, 255, 255), int thickness = 1);
125+
100126
/// Method to render plots on window.
101127
template <typename T>
102128
void addPlot(std::vector<std::vector<T>>& points, int id,
103-
int start = 0, int end = 0,
104-
cv::Scalar color = cv::Scalar(255, 255, 255), int thickness = 1);
129+
int start = 0, int end = 0,
130+
PlotColor color = PlotColor(255, 255, 255), int thickness = 1);
105131

106132
/// Method to clean window.
107133
void clean();
@@ -132,7 +158,32 @@ std::cout << "PlotOpenCv class version: " << PlotOpenCv::getVersion();
132158
Console output:
133159

134160
```bash
135-
PlotOpenCv class version: 1.1.0
161+
PlotOpenCv class version: 1.2.0
162+
```
163+
164+
165+
## Class constructor
166+
167+
The **Plot** class constructor requires basic parameters. Constructor declaration:
168+
169+
```cpp
170+
Plot(std::string name, int width = 1280, int height = 720,
171+
PlotColor backgroundColor = PlotColor(255, 255, 255),
172+
PlotColor scaleLineColor = PlotColor(0, 128, 128));
173+
```
174+
175+
| Parameter | Value |
176+
| --------------- | ------------------------------- |
177+
| name | OpenCV window name. |
178+
| width | Window width, pixels. |
179+
| height | Window height, pixels. |
180+
| backgroundColor | Background color, BGR. |
181+
| scaleLineColor | Scale line color, BGR. |
182+
183+
Example of class initialization:
184+
185+
```cpp
186+
Plot graph("Test graph", 1280, 640, PlotColor(50, 50, 50));
136187
```
137188

138189

@@ -148,7 +199,7 @@ void addPlot(std::vector<T> &points, int id, int start = 0, int end = 0,
148199
149200
| Parameter | Value |
150201
| --------- | ------------------------------------------------------------ |
151-
| Points | One dimensional vector which includes vertical points.Vector format : {y1, y2, ... } |
202+
| Points | One dimensional vector which includes vertical points. Vector format : {y1, y2, ... } |
152203
| id | Identifier for chart on a window. Provides user to update a chart or add new one. |
153204
| start | Start index of plot from vector when user wants to plot a specific range from a dataset. Should be 0 for whole dataset.|
154205
| end | End index of plot from vector when user wants to plot a specific range from a dataset. Should be 0 for whole dataset. |
@@ -162,8 +213,10 @@ void addPlot(std::vector<T> &points, int id, int start = 0, int end = 0,
162213
The **addPlot(...)** method serves the purpose of incorporating a new line chart into the existing window. It either introduces a new plot if the provided id is not yet present, or updates an existing plot associated with the given identifier. Method declaration:
163214
164215
```cpp
165-
void addPlot(std::vector<std::vector<T>> &points, int id, int start = 0, int end = 0,
166-
cv::Scalar color = cv::Scalar(255, 255, 255), int thickness = 1);
216+
template <typename T>
217+
void addPlot(std::vector<std::vector<T>>& points, int id,
218+
int start = 0, int end = 0,
219+
PlotColor color = PlotColor(255, 255, 255), int thickness = 1);
167220
```
168221

169222
| Parameter | Value |
@@ -231,7 +284,7 @@ src
231284
yourLib.cpp
232285
```
233286

234-
create folder **3rdparty** in your repository and copy **PlotOpenCv** repository folder there. New structure of your repository:
287+
Create folder **3rdparty** in your repository and copy **PlotOpenCv** repository folder there. New structure of your repository:
235288

236289
```bash
237290
CMakeLists.txt
@@ -321,25 +374,21 @@ The example demonstrates how to use **PlotOpenCv** library.
321374

322375
int main()
323376
{
324-
plot graph("Test graph", 1280, 720,cv::Scalar(0, 128, 128) cv::Scalar(50, 50, 50));
377+
plot graph("Test graph", 1280, 720, PlotColor(0, 128, 128) PlotColor(50, 50, 50));
325378

326379
std::vector<float> linePoints(9000);
327380
std::vector<std::vector<float>> linePoints2(5000, std::vector<float>(2));
328381

329-
graph.addPlot(linePoints,0, 0, 0, cv::Scalar(255,0,0), 5);
330-
graph.addPlot(linePoints2,1, 0, 0, cv::Scalar(0,255,0), 2);
382+
graph.addPlot(linePoints, 0, 0, 0, PlotColor(255,0,0), 5);
383+
graph.addPlot(linePoints2, 1, 0, 0, PlotColor(0,255,0), 2);
331384

332385
graph.show();
333386
cv::waitKey(0);
334387
return 0;
335388
}
336389
```
337390

338-
339-
340-
# Example Charts
341-
342-
Example charts shows what visual effects user should expect depending on input data.
391+
Example charts shows what visual effects user should expect depending on input data:
343392

344393
![plot_opencv_example_1](./static/plot_opencv_example_1.png)
345394
![plot_opencv_example_2](./static/plot_opencv_example_2.png)

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.4 LANGUAGES CXX)
9+
project(PlotOpenCv VERSION 1.2.0 LANGUAGES CXX)
1010

1111

1212

0 commit comments

Comments
 (0)