TBTK
Plotter.h
Go to the documentation of this file.
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 
23 #ifndef COM_DAFER45_TBTK_PLOTTER
24 #define COM_DAFER45_TBTK_PLOTTER
25 
26 #include "TBTK/Array.h"
27 #include "TBTK/PlotCanvas.h"
28 #include "TBTK/Decoration.h"
29 #include "TBTK/Path.h"
30 #include "TBTK/Point.h"
31 #include "TBTK/Property/DOS.h"
32 #include "TBTK/Streams.h"
33 #include "TBTK/TBTKMacros.h"
34 
35 #include <string>
36 #include <tuple>
37 #include <vector>
38 
39 #include <opencv2/core/core.hpp>
40 #include <opencv2/highgui/highgui.hpp>
41 
42 namespace TBTK{
43 namespace Plot{
44 
45 class Plotter{
46 public:
48  Plotter();
49 
51  ~Plotter();
52 
54  void setWidth(unsigned int width);
55 
57  void setHeight(unsigned int height);
58 
60  void setPadding(
61  double paddingLeft,
62  double paddingRight,
63  double paddingBottom,
64  double paddingTop
65  );
66 
68  void setBoundsX(double minX, double maxX);
69 
71  void setBoundsY(double minY, double maxY);
72 
74  void setBounds(double minX, double maxX, double minY, double maxY);
75 
77  void setAutoScaleX(bool autoScaleX);
78 
80  void setAutoScaleY(bool autoScaleY);
81 
83  void setAutoScale(bool autoScale);
84 
86  void setLabelX(const std::string &labelX);
87 
89  void setLabelY(const std::string &labelY);
90 
92  void setCanvas(cv::Mat &canvas);
93 
95  const cv::Mat& getCanvas();
96 
98  void plot(
99  double x,
100  double y,
101  const Decoration &decoration = Decoration(
102  {0, 0, 0}, Decoration::LineStyle::Point
103  )
104  );
105 
107  void plot(
108  const std::vector<double> &axis,
109  const std::vector<double> &data,
110  const Decoration &decoration = Decoration(
111  {0, 0, 0}, Decoration::LineStyle::Line
112  )
113  );
114 
116  void plot(
117  const std::vector<double> &data,
118  const Decoration &decoration = Decoration(
119  {0, 0, 0}, Decoration::LineStyle::Line
120  )
121  );
122 
124  void plot(
125  const Property::DOS &dos,
126  double sigma = 0,
127  unsigned int windowSize = 51
128  );
129 
131  void plot(
132  const std::vector<std::vector<double>> &data
133  );
134 
136  void plot(
137  const Array<double> &data,
138  const Decoration &decoration = Decoration(
139  {0, 0, 0}, Decoration::LineStyle::Line
140  )
141  );
142 
144  void plot(
145  const std::vector<std::vector<double>> &data,
146  const std::vector<std::vector<double>> &intensity,
147  const Decoration &decoration = Decoration(
148  {0, 0, 0}, Decoration::LineStyle::Point
149  )
150  );
151 
153  void plot(
154  const Array<double> &data,
155  const Array<double> &intensity,
156  const Decoration &decoration = Decoration(
157  {0, 0, 0}, Decoration::LineStyle::Point
158  )
159  );
160 
162  void setHold(bool hold);
163 
165  void clear();
166 
168  void save(std::string filename);
169 private:
171  PlotCanvas canvas;
172 
174  bool autoScaleX, autoScaleY;
175 
178  bool hold;
179 
181  std::vector<Drawable*> dataStorage;
182 
184  void drawDataStorage();
185 
187  void clearDataStorage();
188 };
189 
190 inline void Plotter::setWidth(unsigned int width){
191  canvas.setWidth(width);
192 }
193 
194 inline void Plotter::setHeight(unsigned int height){
195  canvas.setHeight(height);
196 }
197 
199  double paddingLeft,
200  double paddingRight,
201  double paddingBottom,
202  double paddingTop
203 ){
204  canvas.setPadding(
205  paddingLeft,
206  paddingRight,
207  paddingBottom,
208  paddingTop
209  );
210 }
211 
213  double minX,
214  double maxX
215 ){
216  TBTKAssert(
217  minX < maxX,
218  "Plotter::setBoundsX()",
219  "minX has to be smaller than maxX",
220  ""
221  );
222  this->autoScaleX = false;
223  canvas.setBoundsX(minX, maxX);
224 }
225 
227  double minY,
228  double maxY
229 ){
230  TBTKAssert(
231  minY < maxY,
232  "Plotter::setBoundsY()",
233  "minY has to be smaller than maxY",
234  ""
235  );
236  this->autoScaleY = false;
237  canvas.setBoundsY(minY, maxY);
238 }
239 
240 inline void Plotter::setBounds(
241  double minX,
242  double maxX,
243  double minY,
244  double maxY
245 ){
246  setBoundsX(minX, maxX);
247  setBoundsY(minY, maxY);
248 }
249 
250 inline void Plotter::setAutoScaleX(bool autoScaleX){
251  this->autoScaleX = autoScaleX;
252 }
253 
254 inline void Plotter::setAutoScaleY(bool autoScaleY){
255  this->autoScaleY = autoScaleY;
256 }
257 
258 inline void Plotter::setAutoScale(bool autoScale){
259  setAutoScaleX(autoScale);
260  setAutoScaleY(autoScale);
261 }
262 
263 inline void Plotter::setLabelX(const std::string &labelX){
264  canvas.setLabelX(labelX);
265 }
266 
267 inline void Plotter::setLabelY(const std::string &labelY){
268  canvas.setLabelY(labelY);
269 }
270 
271 inline void Plotter::setCanvas(cv::Mat &canvas){
272  this->canvas.setCanvas(canvas);
273 }
274 
275 inline const cv::Mat& Plotter::getCanvas(){
276  if(dataStorage.size() != 0){
277  drawDataStorage();
278  canvas.drawAxes();
279  }
280 
281  return canvas.getCanvas();
282 }
283 
284 inline void Plotter::setHold(bool hold){
285  this->hold = hold;
286 }
287 
288 inline void Plotter::clear(){
289  clearDataStorage();
290  canvas.clear();
291 }
292 
293 inline void Plotter::save(std::string filename){
294  if(dataStorage.size() != 0){
295  drawDataStorage();
296  canvas.drawAxes();
297  }
298 
299  canvas.save(filename);
300 }
301 
302 inline void Plotter::clearDataStorage(){
303  for(unsigned int n = 0; n < dataStorage.size(); n++)
304  delete dataStorage[n];
305  dataStorage.clear();
306 }
307 
308 }; //End namespace Plot
309 }; //End namespace TBTK
310 
311 #endif
void setLabelY(const std::string &labelY)
Definition: PlotCanvas.h:260
void clear()
Definition: PlotCanvas.h:294
const cv::Mat & getCanvas() const
Definition: PlotCanvas.h:281
void plot(double x, double y, const Decoration &decoration=Decoration({0, 0, 0}, Decoration::LineStyle::Point))
Precompiler macros.
void save(std::string filename)
Definition: Plotter.h:293
Decoration.
void setPadding(double paddingLeft, double paddingRight, double paddingBottom, double paddingTop)
Definition: PlotCanvas.h:176
void setBoundsX(double minX, double maxX)
Definition: PlotCanvas.h:188
void setBoundsX(double minX, double maxX)
Definition: Plotter.h:212
void setBoundsY(double minY, double maxY)
Definition: PlotCanvas.h:209
Definition: PlotCanvas.h:36
Multi-dimensional array.
void setAutoScaleY(bool autoScaleY)
Definition: Plotter.h:254
void setWidth(unsigned int width)
Definition: PlotCanvas.h:168
Definition: Decoration.h:31
Definition: Array.h:34
void setWidth(unsigned int width)
Definition: Plotter.h:190
void setBoundsY(double minY, double maxY)
Definition: Plotter.h:226
void setHeight(unsigned int height)
Definition: PlotCanvas.h:172
void setLabelX(const std::string &labelX)
Definition: PlotCanvas.h:256
const cv::Mat & getCanvas()
Definition: Plotter.h:275
Definition: ModelFactory.h:35
Property container for density of states (DOS).
void setAutoScale(bool autoScale)
Definition: Plotter.h:258
void setPadding(double paddingLeft, double paddingRight, double paddingBottom, double paddingTop)
Definition: Plotter.h:198
void setLabelX(const std::string &labelX)
Definition: Plotter.h:263
Path.
void setLabelY(const std::string &labelY)
Definition: Plotter.h:267
Property container for density of states (DOS).
Definition: DOS.h:32
void setHeight(unsigned int height)
Definition: Plotter.h:194
void setHold(bool hold)
Definition: Plotter.h:284
void clear()
Definition: Plotter.h:288
void setAutoScaleX(bool autoScaleX)
Definition: Plotter.h:250
void setBounds(double minX, double maxX, double minY, double maxY)
Definition: Plotter.h:240
Streams for TBTK output.
void setCanvas(cv::Mat &canvas)
Definition: Plotter.h:271
Definition: Plotter.h:45
void save(std::string filename) const
Definition: PlotCanvas.h:403