TBTK
Need a break? Support the development by playing Polarity Puzzles
Plotter2.h
1 /* Copyright 2019 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_PLOTTER_2
25 #define COM_DAFER45_TBTK_PLOTTER_2
26 
27 #include "TBTK/Array.h"
28 #include "TBTK/Canvas2D.h"
29 #include "TBTK/Canvas3D.h"
30 #include "TBTK/PNGCanvas2D.h"
31 #include "TBTK/PNGCanvas3D.h"
32 #include "TBTK/Property/DOS.h"
34 #include "TBTK/Property/LDOS.h"
35 #include "TBTK/Streams.h"
36 #include "TBTK/TBTKMacros.h"
37 
38 #include <sstream>
39 
40 namespace TBTK{
41 
42 class Plotter2{
43 public:
45  Plotter2();
46 
48  ~Plotter2();
49 
51  void setWidth(unsigned int width);
52 
54  void setHeight(unsigned int height);
55 
57  void setBoundsX(double minX, double maxX);
58 
60  void setBoundsY(double minY, double maxY);
61 
63  void setBounds(double minX, double maxX, double minY, double maxY);
64 
66  void setAutoScaleX(bool autoScaleX);
67 
69  void setAutoScaleY(bool autoScaleY);
70 
72  void setAutoScale(bool autoScale);
73 
75  void setTitle(const std::string &title);
76 
78  void setLabelX(const std::string &labelX);
79 
81  void setLabelY(const std::string &labelY);
82 
84  void setLabelZ(const std::string &labelZ);
85 
87  void plot(
88  const std::vector<double> &x,
89  const std::vector<double> &y,
90  const std::string &title = "",
91  const std::vector<unsigned char> &color = {0, 0, 0},
92  unsigned int size = 1
93  );
94 
96  void plot(
97  const std::vector<double> &data,
98  const std::string &title = "",
99  const std::vector<unsigned char> &color = {0, 0, 0},
100  unsigned int size = 1
101  );
102 
104  void plot(
105  const Property::DOS &dos,
106  double sigma = 0,
107  unsigned int windowSize = 51
108  );
109 
112  void plot(
113  const Property::LDOS &ldos,
114  double sigma = 0,
115  unsigned int windowSize = 51
116  );
117 
119  void plot(const Property::EigenValues &eigenValues);
120 
122  void plot(
123  const std::vector<std::vector<double>> &data,
124  const std::string &title = ""
125  );
126 
128  void plot(
129  const Array<double> &data,
130  const std::string &title = "",
131  const std::vector<unsigned char> &color = {0, 0, 0},
132  unsigned int size = 1
133  );
134 
136 /* void plot(
137  const std::vector<std::vector<double>> &data,
138  const std::vector<std::vector<double>> &intensity
139  );*/
140 
142 /* void plot(
143  const Array<double> &data,
144  const Array<double> &intensity
145  );*/
146 
148  void setHold(bool hold);
149 
152  void setTopView(bool topView);
153 
155  void clear();
156 
158  void save(std::string filename);
159 private:
161  Canvas2D canvas2D;
162 
164  Canvas3D canvas3D;
165 
167  Canvas *currentCanvas;
168 
170  bool autoScaleX, autoScaleY;
171 
173  void setCurrentCanvas(Canvas &canvas);
174 };
175 
176 inline void Plotter2::setWidth(unsigned int width){
177  canvas2D.setWidth(width);
178  canvas3D.setWidth(width);
179 }
180 
181 inline void Plotter2::setHeight(unsigned int height){
182  canvas2D.setHeight(height);
183  canvas3D.setHeight(height);
184 }
185 
186 inline void Plotter2::setBoundsX(double minX, double maxX){
187  TBTKAssert(
188  minX < maxX,
189  "Plotter2::setBoundsX()",
190  "minX has to be smaller than maxX",
191  ""
192  );
193  this->autoScaleX = false;
194  canvas2D.setBoundsX(minX, maxX);
195 }
196 
197 inline void Plotter2::setBoundsY(double minY, double maxY){
198  TBTKAssert(
199  minY < maxY,
200  "Plotter2::setBoundsY()",
201  "minY has to be smaller than maxY",
202  ""
203  );
204  this->autoScaleY = false;
205  canvas2D.setBoundsY(minY, maxY);
206 }
207 
208 inline void Plotter2::setBounds(
209  double minX,
210  double maxX,
211  double minY,
212  double maxY
213 ){
214  setBoundsX(minX, maxX);
215  setBoundsY(minY, maxY);
216 }
217 
218 inline void Plotter2::setAutoScaleX(bool autoScaleX){
219  this->autoScaleX = autoScaleX;
220 }
221 
222 inline void Plotter2::setAutoScaleY(bool autoScaleY){
223  this->autoScaleY = autoScaleY;
224 }
225 
226 inline void Plotter2::setAutoScale(bool autoScale){
227  setAutoScaleX(autoScale);
228  setAutoScaleY(autoScale);
229 }
230 
231 inline void Plotter2::setTitle(const std::string &title){
232  canvas2D.setTitle(title);
233  canvas3D.setTitle(title);
234 }
235 
236 inline void Plotter2::setLabelX(const std::string &labelX){
237  canvas2D.setLabelX(labelX);
238  canvas3D.setLabelX(labelX);
239 }
240 
241 inline void Plotter2::setLabelY(const std::string &labelY){
242  canvas2D.setLabelY(labelY);
243  canvas3D.setLabelY(labelY);
244 }
245 
246 inline void Plotter2::setLabelZ(const std::string &labelZ){
247  canvas3D.setLabelZ(labelZ);
248 }
249 
250 inline void Plotter2::setHold(bool hold){
251  canvas2D.setHold(hold);
252  canvas3D.setHold(hold);
253 }
254 
255 inline void Plotter2::setTopView(bool topView){
256  setCurrentCanvas(canvas3D);
257  canvas3D.setTopView(topView);
258 }
259 
260 inline void Plotter2::clear(){
261  canvas2D.clear();
262 }
263 
264 inline void Plotter2::save(std::string filename){
265  std::vector<std::string> tokens;
266  std::stringstream ss(filename);
267  std::string token;
268  while(std::getline(ss, token, '.'))
269  tokens.push_back(token);
270 
271  TBTKAssert(
272  tokens.size() != 0,
273  "Plotter2::save()",
274  "Invalid filename '" << filename << "'.",
275  ""
276  );
277  if(
278  tokens.back().compare("png") == 0
279  || tokens.back().compare("PNG") == 0
280  ){
281  if(currentCanvas == &canvas2D){
282  PNGCanvas2D canvas(canvas2D);
283  canvas.flush(filename);
284  }
285  else if(currentCanvas == &canvas3D){
286  PNGCanvas3D canvas(canvas3D);
287  canvas.flush(filename);
288  }
289  }
290  else{
291  TBTKExit(
292  "Plotter2::save()",
293  "Unknown file type '" << tokens.back() << "'.",
294  ""
295  );
296  }
297 }
298 
299 }; //End namespace TBTK
300 
301 #endif
302 
Precompiler macros.
Property container for eigen values.
Property container for local density of states (LDOS).
Multi-dimensional array.
Definition: Boolean.h:32
Property container for density of states (DOS).
Streams for TBTK output.