NAPISD
PAHdb website C++ backend
Loading...
Searching...
No Matches
Canvas.h
1#ifndef _CANVAS_H_
2#define _CANVAS_H_
3
4#define PL_DOUBLE
5
6#include <plplot/plstream.h>
7
8#include "Exception.h"
9
10#include "CanvasItem.h"
11
12#include "Point.h"
13
14#include "Line.h"
15
16#include "Curve.h"
17
18#include "Plot.h"
19
20#include "Text.h"
21
22#include "Panels.h"
23
24#include <cmath>
25
26#include <algorithm>
27#include <array>
28#include <iterator>
29#include <memory>
30#include <sstream>
31#include <string>
32#include <string_view>
33#include <vector>
34
35class Canvas {
36
37public:
38 typedef std::vector<std::unique_ptr<CanvasItem>>::iterator iterator;
39
40 Canvas();
41
42 CanvasItem &operator[](std::size_t idx);
43
44 iterator begin() noexcept { return (_items.begin()); }
45
46 iterator end() noexcept { return (_items.end()); }
47
48 void add(CanvasItem &item);
49
50 void add(std::vector<Plot> &plots);
51
52 void erase();
53
54 void erase(std::vector<std::unique_ptr<CanvasItem>>::iterator begin,
55 std::vector<std::unique_ptr<CanvasItem>>::iterator end);
56
57 void setSize(const std::array<int, 2> size);
58
59 void setColor(const std::string_view color);
60
61 void setDefaultCharacterHeight(double height);
62
63 std::array<int, 2> const &getSize() const;
64
65 float getAspectRatio() const;
66
67 std::string_view getColor() const;
68
69 const double &getDefaultCharacterHeight() const;
70
71 void paintOnScreen();
72
73 void paintOnPostscript(std::string_view filename);
74
75 void paintOnPNG(std::string_view filename);
76
77 void paintOnJPEG(std::string_view filename);
78
79private:
80 std::unique_ptr<plstream> _plstream;
81
82 std::string _color;
83
84 std::vector<std::string> _colormap;
85
86 std::vector<std::unique_ptr<CanvasItem>> _items;
87
88 std::array<int, 2> _size;
89
90 double _defaultcharacterheight;
91
92 double _defaultticklength;
93
94 int lookUpColor(std::string_view hex);
95
96 void paint();
97
98 void draw(Plot *plot);
99};
100
101inline CanvasItem &Canvas::operator[](std::size_t idx) {
102 return (*_items[idx]);
103}
104
105inline void Canvas::erase() { _items.erase(_items.begin(), _items.end()); }
106
107inline void
108Canvas::erase(std::vector<std::unique_ptr<CanvasItem>>::iterator begin,
109 std::vector<std::unique_ptr<CanvasItem>>::iterator end) {
110 _items.erase(begin, end);
111}
112
113inline void Canvas::setSize(const std::array<int, 2> size) { _size = size; }
114
115inline void Canvas::setColor(const std::string_view color) { _color = color; }
116
117inline void Canvas::setDefaultCharacterHeight(double height) {
118 _defaultcharacterheight = height;
119}
120
121inline std::array<int, 2> const &Canvas::getSize() const { return (_size); }
122
123inline float Canvas::getAspectRatio() const {
124 return static_cast<float>(_size[0]) / _size[1];
125}
126
127inline std::string_view Canvas::getColor() const { return (_color); }
128
129inline const double &Canvas::getDefaultCharacterHeight() const {
130 return (_defaultcharacterheight);
131}
132
133#endif /* _CANVAS_H_ */
Definition Plot.h:20

Since FY2019 the NASA Ames PAH IR Spectroscopic Database is being supported through a directed Work Package at NASA Ames titled: "Laboratory Astrophysics - The NASA Ames PAH IR Spectroscopic Database".
Since FY2023 the NASA Ames PAH IR Spectroscopic Database is being supported through the Laboratory Astrophysics Rd 2 directed Work Package at NASA Ames.
© Copyright 2021-2025, Christiaan Boersma