TBTK
Need a break? Support the development by playing Polarity Puzzles
Plotter.h
1 /* Copyright 2017 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
17 
24 #ifndef COM_DAFER45_TBTK_PLOT_PLOTTER
25 #define COM_DAFER45_TBTK_PLOT_PLOTTER
26 
27 #include "TBTK/Array.h"
28 #include "TBTK/Plot/PlotCanvas.h"
29 #include "TBTK/Plot/Decoration.h"
30 #include "TBTK/Plot/Path.h"
31 #include "TBTK/Plot/Point.h"
32 #include "TBTK/Property/DOS.h"
34 #include "TBTK/Streams.h"
35 #include "TBTK/TBTKMacros.h"
36 
37 #include <string>
38 #include <tuple>
39 #include <vector>
40 
41 #include <opencv2/core/core.hpp>
42 #include <opencv2/highgui/highgui.hpp>
43 
44 namespace TBTK{
45 namespace Plot{
46 
47 class Plotter{
48 public:
50  Plotter();
51 
53  ~Plotter();
54 
56  void setWidth(unsigned int width);
57 
59  void setHeight(unsigned int height);
60 
62  void setPadding(
63  double paddingLeft,
64  double paddingRight,
65  double paddingBottom,
66  double paddingTop
67  );
68 
70  void setBoundsX(double minX, double maxX);
71 
73  void setBoundsY(double minY, double maxY);
74 
76  void setBounds(double minX, double maxX, double minY, double maxY);
77 
79  void setAutoScaleX(bool autoScaleX);
80 
82  void setAutoScaleY(bool autoScaleY);
83 
85  void setAutoScale(bool autoScale);
86 
88  void setLabelX(const std::string &labelX);
89 
91  void setLabelY(const std::string &labelY);
92 
94  void setCanvas(cv::Mat &canvas);
95 
97  const cv::Mat& getCanvas();
98 
100  void plot(
101  double x,
102  double y,
103  const Decoration &decoration = Decoration(
104  {0, 0, 0}, Decoration::LineStyle::Point
105  )
106  );
107 
109  void plot(
110  const std::vector<double> &axis,
111  const std::vector<double> &data,
112  const Decoration &decoration = Decoration(
113  {0, 0, 0}, Decoration::LineStyle::Line
114  )
115  );
116 
118  void plot(
119  const std::vector<double> &data,
120  const Decoration &decoration = Decoration(
121  {0, 0, 0}, Decoration::LineStyle::Line
122  )
123  );
124 
126  void plot(
127  const Property::DOS &dos,
128  double sigma = 0,
129  unsigned int windowSize = 51
130  );
131 
133  void plot(const Property::EigenValues &eigenValues);
134 
136  void plot(
137  const std::vector<std::vector<double>> &data
138  );
139 
141  void plot(
142  const Array<double> &data,
143  const Decoration &decoration = Decoration(
144  {0, 0, 0}, Decoration::LineStyle::Line
145  )
146  );
147 
149  void plot(
150  const std::vector<std::vector<double>> &data,
151  const std::vector<std::vector<double>> &intensity,
152  const Decoration &decoration = Decoration(
153  {0, 0, 0}, Decoration::LineStyle::Point
154  )
155  );
156 
158  void plot(
159  const Array<double> &data,
160  const Array<double> &intensity,
161  const Decoration &decoration = Decoration(
162  {0, 0, 0}, Decoration::LineStyle::Point
163  )
164  );
165 
167  void setHold(bool hold);
168 
170  void clear();
171 
173  void save(std::string filename);
174 private:
176  PlotCanvas canvas;
177 
179  bool autoScaleX, autoScaleY;
180 
183  bool hold;
184 
186  std::vector<Drawable*> dataStorage;
187 
189  void drawDataStorage();
190 
192  void clearDataStorage();
193 };
194 
195 inline void Plotter::setWidth(unsigned int width){
196  canvas.setWidth(width);
197 }
198 
199 inline void Plotter::setHeight(unsigned int height){
200  canvas.setHeight(height);
201 }
202 
203 inline void Plotter::setPadding(
204  double paddingLeft,
205  double paddingRight,
206  double paddingBottom,
207  double paddingTop
208 ){
209  canvas.setPadding(
210  paddingLeft,
211  paddingRight,
212  paddingBottom,
213  paddingTop
214  );
215 }
216 
217 inline void Plotter::setBoundsX(
218  double minX,
219  double maxX
220 ){
221  TBTKAssert(
222  minX < maxX,
223  "Plotter::setBoundsX()",
224  "minX has to be smaller than maxX",
225  ""
226  );
227  this->autoScaleX = false;
228  canvas.setBoundsX(minX, maxX);
229 }
230 
231 inline void Plotter::setBoundsY(
232  double minY,
233  double maxY
234 ){
235  TBTKAssert(
236  minY < maxY,
237  "Plotter::setBoundsY()",
238  "minY has to be smaller than maxY",
239  ""
240  );
241  this->autoScaleY = false;
242  canvas.setBoundsY(minY, maxY);
243 }
244 
245 inline void Plotter::setBounds(
246  double minX,
247  double maxX,
248  double minY,
249  double maxY
250 ){
251  setBoundsX(minX, maxX);
252  setBoundsY(minY, maxY);
253 }
254 
255 inline void Plotter::setAutoScaleX(bool autoScaleX){
256  this->autoScaleX = autoScaleX;
257 }
258 
259 inline void Plotter::setAutoScaleY(bool autoScaleY){
260  this->autoScaleY = autoScaleY;
261 }
262 
263 inline void Plotter::setAutoScale(bool autoScale){
264  setAutoScaleX(autoScale);
265  setAutoScaleY(autoScale);
266 }
267 
268 inline void Plotter::setLabelX(const std::string &labelX){
269  canvas.setLabelX(labelX);
270 }
271 
272 inline void Plotter::setLabelY(const std::string &labelY){
273  canvas.setLabelY(labelY);
274 }
275 
276 inline void Plotter::setCanvas(cv::Mat &canvas){
277  this->canvas.setCanvas(canvas);
278 }
279 
280 inline const cv::Mat& Plotter::getCanvas(){
281  if(dataStorage.size() != 0){
282  drawDataStorage();
283  canvas.drawAxes();
284  }
285 
286  return canvas.getCanvas();
287 }
288 
289 inline void Plotter::setHold(bool hold){
290  this->hold = hold;
291 }
292 
293 inline void Plotter::clear(){
294  clearDataStorage();
295  canvas.clear();
296 }
297 
298 inline void Plotter::save(std::string filename){
299  if(dataStorage.size() != 0){
300  drawDataStorage();
301  canvas.drawAxes();
302  }
303 
304  canvas.save(filename);
305 }
306 
307 inline void Plotter::clearDataStorage(){
308  for(unsigned int n = 0; n < dataStorage.size(); n++)
309  delete dataStorage[n];
310  dataStorage.clear();
311 }
312 
313 }; //End namespace Plot
314 }; //End namespace TBTK
315 
316 #endif
317 
Precompiler macros.
Property container for eigen values.
Multi-dimensional array.
Definition: Boolean.h:32
Property container for density of states (DOS).
Streams for TBTK output.