TBTK
Need a break? Support the development by playing Polarity Puzzles
PlotSurfaceParameters.h
Go to the documentation of this file.
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 
24 #ifndef COM_DAFER45_TBTK_VISUALIZATION_MAT_PLOT_LIB_PLOT_SURFACE_PARAMETERS
25 #define COM_DAFER45_TBTK_VISUALIZATION_MAT_PLOT_LIB_PLOT_SURFACE_PARAMETERS
26 
27 #include "TBTK/Visualization/MatPlotLib/matplotlibcpp.h"
28 
29 #include <string>
30 #include <utility>
31 
32 namespace TBTK{
33 namespace Visualization{
34 namespace MatPlotLib{
35 
37 public:
40 
42  void setTitle(const std::string &title, bool overwrite = true);
43 
45  void setLabelX(const std::string &labelX, bool overwrite = true);
46 
48  void setLabelY(const std::string &labelY, bool overwrite = true);
49 
51  void setLabelZ(const std::string &labelZ, bool overwrite = true);
52 
54  void setBoundsX(double minX, double maxX, bool overwrite = true);
55 
57  void setBoundsY(double minY, double maxY, bool overwrite = true);
58 
60  void setRotation(int elevation, int azimuthal, bool overwrite = true);
61 
63  void flush() const;
64 
66  void clear();
67 private:
68  std::pair<bool, std::string> title;
69  std::pair<bool, std::string> labelX;
70  std::pair<bool, std::string> labelY;
71  std::pair<bool, std::string> labelZ;
72  std::pair<bool, std::string> elevation;
73  std::pair<bool, std::string> azimuthal;
74  std::pair<bool, double> minX;
75  std::pair<bool, double> maxX;
76  std::pair<bool, double> minY;
77  std::pair<bool, double> maxY;
78 };
79 
81 ) :
82  title(false, ""),
83  labelX(false, ""),
84  labelY(false, ""),
85  labelZ(false, ""),
86  elevation(false, "30"),
87  azimuthal(false, "-60"),
88  minX(false, 0),
89  maxX(false, 1),
90  minY(false, 0),
91  maxY(false, 1)
92 {
93 }
94 
96  const std::string &title,
97  bool overwrite
98 ){
99  if(overwrite || !this->title.first)
100  this->title = {true, title};
101 }
102 
104  const std::string &labelX,
105  bool overwrite
106 ){
107  if(overwrite || !this->labelX.first)
108  this->labelX = {true, labelX};
109 }
110 
112  const std::string &labelY,
113  bool overwrite
114 ){
115  if(overwrite || !this->labelY.first)
116  this->labelY = {true, labelY};
117 }
118 
120  const std::string &labelZ,
121  bool overwrite
122 ){
123  if(overwrite || !this->labelZ.first)
124  this->labelZ = {true, labelZ};
125 }
126 
128  int elevation,
129  int azimuthal,
130  bool overwrite
131 ){
132  if(overwrite || !this->elevation.first){
133  this->elevation = {true, std::to_string(elevation)};
134  this->azimuthal = {true, std::to_string(azimuthal)};
135  }
136 }
137 
139  double minX,
140  double maxX,
141  bool overwrite
142 ){
143  if(overwrite || !this->minX.first)
144  this->minX = {true, minX};
145  if(overwrite || !this->maxX.first)
146  this->maxX = {true, maxX};
147 }
148 
150  double minY,
151  double maxY,
152  bool overwrite
153 ){
154  if(overwrite || !this->minY.first)
155  this->minY = {true, minY};
156  if(overwrite || !this->maxY.first)
157  this->maxY = {true, maxY};
158 }
159 
160 inline void PlotSurfaceParameters::flush() const{
161  if(title.first)
162  matplotlibcpp::title(title.second);
163  if(labelX.first)
164  matplotlibcpp::xlabel(labelX.second);
165  if(labelY.first)
166  matplotlibcpp::ylabel(labelY.second);
167  if(elevation.first){
168  matplotlibcpp::view_init({
169  {"elev", elevation.second},
170  {"azim", azimuthal.second}
171  });
172  }
173  if(minX.first)
174  matplotlibcpp::xlim(minX.second, maxX.second);
175  if(minY.first)
176  matplotlibcpp::ylim(minY.second, maxY.second);
177 }
178 
180  title = {false, ""};
181  labelX = {false, ""};
182  labelY = {false, ""};
183  labelZ = {false, ""};
184  elevation = {false, ""};
185  azimuthal = {false, ""};
186 }
187 
188 }; //End namespace MatPlotLib
189 }; //End namespace Visualization
190 }; //End namespace TBTK
191 
192 #endif
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::setLabelY
void setLabelY(const std::string &labelY, bool overwrite=true)
Definition: PlotSurfaceParameters.h:111
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::setLabelZ
void setLabelZ(const std::string &labelZ, bool overwrite=true)
Definition: PlotSurfaceParameters.h:119
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::setTitle
void setTitle(const std::string &title, bool overwrite=true)
Definition: PlotSurfaceParameters.h:95
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::setLabelX
void setLabelX(const std::string &labelX, bool overwrite=true)
Definition: PlotSurfaceParameters.h:103
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::clear
void clear()
Definition: PlotSurfaceParameters.h:179
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::setBoundsX
void setBoundsX(double minX, double maxX, bool overwrite=true)
Definition: PlotSurfaceParameters.h:138
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::setBoundsY
void setBoundsY(double minY, double maxY, bool overwrite=true)
Definition: PlotSurfaceParameters.h:149
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::flush
void flush() const
Definition: PlotSurfaceParameters.h:160
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::PlotSurfaceParameters
PlotSurfaceParameters()
Definition: PlotSurfaceParameters.h:80
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters
Definition: PlotSurfaceParameters.h:36
TBTK::Visualization::MatPlotLib::PlotSurfaceParameters::setRotation
void setRotation(int elevation, int azimuthal, bool overwrite=true)
Definition: PlotSurfaceParameters.h:127