VAPOR3 3.9.4
ViewpointParams.h
Go to the documentation of this file.
1//************************************************************************
2// *
3// Copyright (C) 2004 *
4// University Corporation for Atmospheric Research *
5// All Rights Reserved *
6// *
7//************************************************************************/
8//
9// File: ViewpointParams.h
10//
11// Author: Alan Norton
12// National Center for Atmospheric Research
13// PO 3000, Boulder, Colorado
14//
15// Date: August 2004
16//
17// Description: Defines the ViewpointParams class
18// This class contains the parameters associated with viewpoint and lights
19//
20#ifndef VIEWPOINTPARAMS_H
21#define VIEWPOINTPARAMS_H
22
23#include <vapor/ParamsBase.h>
24#include <vapor/Viewpoint.h>
25#include <vapor/Transform.h>
26
27#include <memory>
28#include <fstream>
29
30namespace VAPoR {
31
38
44public:
46
48
50
52
54
57 void rescale(vector<double> scaleFac);
58
63 int getNumLights() const
64 {
65 size_t n = (size_t)GetValueLong(_numLightsTag, _defaultNumLights);
66 if (n > 2) n = 2;
67 return (n);
68 }
69
74 double getExponent() const { return (GetValueDouble(_specularExpTag, _defaultSpecularExp)); }
75
79 void setNumLights(size_t nlights)
80 {
81 if (nlights > 2) nlights = 2;
82 SetValueLong(_numLightsTag, "Set number of lights", nlights);
83 }
84
89 //
90 double getLightDirection(int lightNum, int dir) const;
91
97 void setLightDirection(int lightNum, int dir, double val);
98
102 double getDiffuseCoeff(int lightNum) const;
103
107 double getSpecularCoeff(int lightNum) const;
108
111 double getAmbientCoeff() const { return GetValueDouble(_ambientCoeffTag, _defaultAmbientCoeff); }
112
117 void setDiffuseCoeff(int lightNum, double val);
118
123 void setSpecularCoeff(int lightNum, double val);
124
128 void setExponent(double val) { SetValueDouble(_specularExpTag, "Set specular lighting", val); }
129
133 void setAmbientCoeff(double val) { SetValueDouble(_ambientCoeffTag, "Set ambient lighting", val); }
134
140
146 void SetWindowSize(size_t width, size_t height);
147
153 void GetWindowSize(size_t &width, size_t &height) const;
154
155 void SetFOV(float v);
156 double GetFOV() const;
159
160 enum ProjectionType { Perspective, Orthographic, MapOrthographic };
163
165 vector<double> GetStretchFactors() const;
166
169 void SetStretchFactors(vector<double> factors);
170
175 {
176 Viewpoint *v = (Viewpoint *)m_VPs->GetParams(_currentViewTag);
177 VAssert(v != NULL);
178 return (v);
179 }
180
182 //
183 void GetModelViewMatrix(double m[16]) const { getCurrentViewpoint()->GetModelViewMatrix(m); }
184 std::vector<double> GetModelViewMatrix() const
185 {
186 double m[16];
187 getCurrentViewpoint()->GetModelViewMatrix(m);
188 vector<double> vec(m, m + sizeof(m) / sizeof(m[0]));
189 return (vec);
190 }
191 void SetModelViewMatrix(const double matrix[16]) { getCurrentViewpoint()->SetModelViewMatrix(matrix); }
192 void SetModelViewMatrix(const std::vector<double> mvec)
193 {
194 VAssert(mvec.size() == 16);
195 double m[16];
196 for (int i = 0; i < mvec.size(); i++) m[i] = mvec[i];
197 getCurrentViewpoint()->SetModelViewMatrix(m);
198 }
199
200 void GetProjectionMatrix(double m[16]) const { getCurrentViewpoint()->GetProjectionMatrix(m); }
201 void SetProjectionMatrix(const double m[16]) { getCurrentViewpoint()->SetProjectionMatrix(m); }
202
203 bool ReconstructCamera(const double m[16], double position[3], double upVec[3], double viewDir[3]) const { return (getCurrentViewpoint()->ReconstructCamera(m, position, upVec, viewDir)); }
204
205 std::vector<double> GetRotationCenter() const { return (getCurrentViewpoint()->GetRotationCenter()); }
206
207 void GetRotationCenter(double c[3]) const
208 {
209 vector<double> val = GetRotationCenter();
210 VAssert(val.size() == 3);
211 for (int i = 0; i < val.size(); i++) c[i] = val[i];
212 }
213
214 void SetRotationCenter(vector<double> c) { getCurrentViewpoint()->SetRotationCenter(c); }
215 void SetRotationCenter(const double c[3])
216 {
217 std::vector<double> vec = {c[0], c[1], c[2]};
218 SetRotationCenter(vec);
219 }
220
226 //
227 virtual Transform *GetTransform(string dataSetName);
228
232 //
233 vector<string> GetTransformNames() const { return (_transforms->GetNames()); }
234
237 int SetCameraFromFile(const std::string &path);
238
241 int SaveCameraToFile(const std::string &path);
242
243#ifdef VAPOR3_0_0_ALPHA
247 double GetCurrentViewDiameter(vector<double> stretchFactors) const;
248#endif
249
250#ifndef DOXYGEN_SKIP_THIS
251
252 static const double *getDefaultLightDirection(int lightNum) { return _defaultLightDirection[lightNum]; }
253 static double getDefaultAmbientCoeff() { return _defaultAmbientCoeff; }
254 static double getDefaultSpecularExp() { return _defaultSpecularExp; }
255 static int getDefaultNumLights() { return _defaultNumLights; }
256 static const double *getDefaultDiffuseCoeff() { return _defaultDiffuseCoeff; }
257 static const double *getDefaultSpecularCoeff() { return _defaultSpecularCoeff; }
258 static void setDefaultLightDirection(int lightNum, double val[3])
259 {
260 for (int i = 0; i < 3; i++) _defaultLightDirection[lightNum][i] = val[i];
261 }
262 static void setDefaultSpecularCoeff(double val[3])
263 {
264 for (int i = 0; i < 3; i++) _defaultSpecularCoeff[i] = val[i];
265 }
266 static void setDefaultDiffuseCoeff(double val[3])
267 {
268 for (int i = 0; i < 3; i++) _defaultDiffuseCoeff[i] = val[i];
269 }
270 static void setDefaultAmbientCoeff(double val) { _defaultAmbientCoeff = val; }
271 static void setDefaultSpecularExp(double val) { _defaultSpecularExp = val; }
272 static void setDefaultNumLights(int val) { _defaultNumLights = val; }
273
274 // Get static string identifier for this params class
275 //
276 static string GetClassType() { return ("ViewpointParams"); }
277
278 static const string UseCustomFramebufferTag;
279 static const string CustomFramebufferWidthTag;
280 static const string CustomFramebufferHeightTag;
281
282private:
283 ParamsContainer *m_VPs = nullptr;
284 ParamsContainer *_transforms = nullptr;
285
286 static const string _viewPointsTag;
287 static const string _transformsTag;
288 static const string _currentViewTag;
289 static const string _lightDirectionsTag;
290 static const string _diffuseCoeffTag;
291 static const string _specularCoeffTag;
292 static const string _specularExpTag;
293 static const string _ambientCoeffTag;
294 static const string _numLightsTag;
295 static const string m_windowSizeTag;
296 static const string m_stretchFactorsTag;
297 static const string m_fieldOfView;
298 static const string _orthoProjectionSizeTag;
299 static const string _projectionTypeTag;
300
301 // defaults:
302 static double _defaultLightDirection[3][4];
303 static double _defaultDiffuseCoeff[3];
304 static double _defaultSpecularCoeff[3];
305 static double _defaultAmbientCoeff;
306 static double _defaultSpecularExp;
307 static int _defaultNumLights;
308
309 void _init();
310
311#endif // DOXYGEN_SKIP_THIS
312};
313}; // namespace VAPoR
314#endif // VIEWPOINTPARAMS_H
#define VAssert(expr)
Definition: VAssert.h:9
State capture class.
Definition: ParamsBase.h:62
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:50
class that indicates location and direction of view
Definition: Transform.h:22
A class for describing the viewpoint and lights in a 3D VAPOR scene.
vector< string > GetTransformNames() const
int SaveCameraToFile(const std::string &path)
double getDiffuseCoeff(int lightNum) const
double getAmbientCoeff() const
virtual Viewpoint * getCurrentViewpoint() const
void setNumLights(size_t nlights)
bool ReconstructCamera(const double m[16], double position[3], double upVec[3], double viewDir[3]) const
void SetFOV(float v)
void SetModelViewMatrix(const double matrix[16])
void SetModelViewMatrix(const std::vector< double > mvec)
void GetModelViewMatrix(double m[16]) const
Return the current 4x4 model-view matrix.
void setDiffuseCoeff(int lightNum, double val)
void setLightDirection(int lightNum, int dir, double val)
ViewpointParams & operator=(const ViewpointParams &rhs)
void GetRotationCenter(double c[3]) const
std::vector< double > GetModelViewMatrix() const
double GetFOV() const
double GetOrthoProjectionSize() const
void SetStretchFactors(vector< double > factors)
void SetProjectionType(ProjectionType type)
void SetOrthoProjectionSize(float f)
double getSpecularCoeff(int lightNum) const
int SetCameraFromFile(const std::string &path)
void SetRotationCenter(const double c[3])
void setSpecularCoeff(int lightNum, double val)
double getLightDirection(int lightNum, int dir) const
vector< double > GetStretchFactors() const
Method to get stretch factors.
void setExponent(double val)
ViewpointParams(const ViewpointParams &rhs)
std::vector< double > GetRotationCenter() const
double getExponent() const
void SetRotationCenter(vector< double > c)
ViewpointParams(ParamsBase::StateSave *ssave)
virtual Transform * GetTransform(string dataSetName)
void setAmbientCoeff(double val)
ProjectionType GetProjectionType() const
void rescale(vector< double > scaleFac)
void SetWindowSize(size_t width, size_t height)
ViewpointParams(ParamsBase::StateSave *ssave, XmlNode *node)
void SetProjectionMatrix(const double m[16])
void GetWindowSize(size_t &width, size_t &height) const
void SetCurrentViewpoint(Viewpoint *newVP)
void GetProjectionMatrix(double m[16]) const
class that indicates location and direction of view
Definition: Viewpoint.h:22
An Xml tree.
Definition: XmlNode.h:49
#define PARAMS_API
Definition: common.h:77