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