VAPoR  3.0.0
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 "params.h"
24 #include "viewpoint.h"
25 #include "command.h"
26 
27 class VizTab;
28 
29 namespace VAPoR {
30 class ExpatParseMgr;
31 class RegionParams;
32 class XmlNode;
33 class ParamNode;
46 
47 public:
53  ViewpointParams(XmlNode* parent, int winnum);
55  virtual ~ViewpointParams();
58  static ParamsBase* CreateDefaultInstance() {return new ViewpointParams(0,-1);}
61  const std::string getShortName() {return _shortName;}
62 
65  void rescale(vector<double> scaleFac);
66 
70  void getFarNearDist(float* boxFar, float* boxNear);
71 
74  virtual void Validate(int type);
75 
77  virtual void restart();
78 
82  const double* getModelViewMatrix() {return _modelViewMatrix;}
86  const double* getProjectionMatrix() {return _projectionMatrix;}
90  void setProjectionMatrix(const double* mtx){
91  for (int i = 0; i<16; i++) _projectionMatrix[i] = mtx[i];
92  }
96  void setModelViewMatrix(const double* mtx){
97  for (int i = 0; i<16; i++) _modelViewMatrix[i] = mtx[i];
98  }
99 
101 
106  int getNumLights() {
107  vector<long> defNumLights(_defaultNumLights,1);
108  return (GetValueLong(_numLightsTag,defNumLights));
109  }
110 
115  double getExponent() {
116  vector<double> defSpecExp(_defaultSpecularExp,1);
117  return (GetValueDouble(_specularExpTag,defSpecExp));
118  }
119 
122  const vector<double> getCameraPosLocal() {return getCurrentViewpoint()->getCameraPosLocal();}
123 
126  void getStretchedCamPosLocal(double* vec){
127  getCurrentViewpoint()->getStretchedCamPosLocal(vec);
128  }
132  int setStretchedCamPosLocal(const double* vec){
133  return getCurrentViewpoint()->setStretchedCamPosLocal(vec,this);
134  }
137  void getStretchedRotCtrLocal(double* vec){
138  getCurrentViewpoint()->getStretchedRotCtrLocal(vec);
139  }
143  int setStretchedRotCtrLocal(const double* vec){
144  return getCurrentViewpoint()->setStretchedRotCtrLocal(vec,this);
145  }
148  const vector<double> getViewDir() {return getCurrentViewpoint()->getViewDir();}
149 
152  const vector<double> getUpVec() {return getCurrentViewpoint()->getUpVec();}
153 
158  const vector<double> getRotationCenterLocal(){return getCurrentViewpoint()->getRotationCenterLocal();}
159 
162  Viewpoint* currentViewpoint = getCurrentViewpoint();
163  setHomeViewpoint((Viewpoint*)currentViewpoint->deepCopy());
164  }
165 
169  double getCameraPosLocal(int coord) {
170  return getCurrentViewpoint()->getCameraPosLocal()[coord];
171  }
172 
177  int setCameraPosLocal(const vector<double>& val,int ) {
178  VPSetChanged(true);
179  return getCurrentViewpoint()->setCameraPosLocal(val, this);
180  }
185  int setViewDir(int coord, double val) {
186  VPSetChanged(true);
187  return getCurrentViewpoint()->setViewDir(coord,val, this);
188  }
192  int setViewDir(const vector<double>& val) {
193  VPSetChanged(true);
194  return getCurrentViewpoint()->setViewDir(val, this);
195  }
200  int setUpVec(int i, double val) {
201  VPSetChanged(true);
202  return getCurrentViewpoint()->setUpVec(i,val,this);
203  }
207  int setUpVec(const vector<double>& val) {
208  VPSetChanged(true);
209  return getCurrentViewpoint()->setUpVec(val,this);
210  }
214  double getRotationCenterLocal(int coord){ return getCurrentViewpoint()->getRotationCenterLocal(coord);}
215 
219  int setRotationCenterLocal(const vector<double>& vec){
220  VPSetChanged(true);
221  return getCurrentViewpoint()->setRotationCenterLocal(vec,this);
222  }
226  int setNumLights(int nlights) {
227  return SetValueLong(_numLightsTag,"Set number of lights", nlights);
228  }
233  double getLightDirection(int lightNum, int dir){
234  return GetValueDoubleVec(_lightDirectionsTag)[dir+3*lightNum];
235  }
241  int setLightDirection(int lightNum, int dir, double val){
242 
243  vector<double> ldirs = GetValueDoubleVec(_lightDirectionsTag);
244  ldirs[dir+3*lightNum] = val;
245  return SetValueDouble(_lightDirectionsTag,"Set light direction",ldirs);
246  }
250  double getDiffuseCoeff(int lightNum) {
251  vector<double> _defaultDiffCoeff;
252  for (int i = 0; i<3; i++) _defaultDiffCoeff.push_back(_defaultDiffuseCoeff[i]);
253  return GetValueDoubleVec(_diffuseCoeffTag,_defaultDiffCoeff)[lightNum];
254  }
258  double getSpecularCoeff(int lightNum) {
259  vector<double> _defaultSpecCoeff;
260  for (int i = 0; i<3; i++) _defaultSpecCoeff.push_back(_defaultSpecularCoeff[i]);
261  return GetValueDoubleVec(_specularCoeffTag,_defaultSpecCoeff)[lightNum];
262  }
265  double getAmbientCoeff() {
266  vector<double> _defaultAmbient(_defaultAmbientCoeff,1);
267  return GetValueDouble(_ambientCoeffTag,_defaultAmbient);
268  }
273  int setDiffuseCoeff(int lightNum, double val) {
274 
275  vector<double>diffCoeff = GetValueDoubleVec(_diffuseCoeffTag);
276  diffCoeff[lightNum]=val;
277  return SetValueDouble(_diffuseCoeffTag,"Set diffuse coefficient",diffCoeff);
278  }
283  int setSpecularCoeff(int lightNum, double val) {
284 
285  vector<double>specCoeff= GetValueDoubleVec(_specularCoeffTag);
286  specCoeff[lightNum]=val;
287  return SetValueDouble(_specularCoeffTag,"Set specular coefficient",specCoeff);
288  }
292  int setExponent(double val) {
293  return SetValueDouble(_specularExpTag, "Set specular lighting",val);
294  }
298  int setAmbientCoeff(double val) {
299  return SetValueDouble(_ambientCoeffTag,"Set ambient lighting",val);
300  }
306  Command* cmd = Command::CaptureStart(this,"set current viewpoint");
307  vector<string> path;
308  path.push_back(_currentViewTag);
309  path.push_back(Viewpoint::_viewpointTag);
310  int rc = SetParamsBase(path,newVP);
311  Command::CaptureEnd(cmd,this);
312  VPSetChanged(true);
313  return rc;
314 
315  }
321  Command* cmd = Command::CaptureStart(this, "set home viewpoint");
322  vector<string> path;
323  path.push_back(_homeViewTag);
324  path.push_back(Viewpoint::_viewpointTag);
325  int rc = SetParamsBase(path,newVP);
326  Command::CaptureEnd(cmd,this);
327  VPSetChanged(true);
328  return rc;
329  }
334  void centerFullDomain(int timestep);
335 
336 
341  vector<string> path;
342  path.push_back(_homeViewTag);
343  path.push_back(Viewpoint::_viewpointTag);
344  return (Viewpoint*) GetParamsBase(path);
345  }
351  void VPSetChanged(bool val);
352 
357  bool VPHasChanged(int viz = -1);
358 
359 #ifndef DOXYGEN_SKIP_THIS
360 
361  static const double* getDefaultViewDir(){return _defaultViewDir;}
362  static const double* getDefaultUpVec(){return _defaultUpVec;}
363  static const double* getDefaultLightDirection(int lightNum){return _defaultLightDirection[lightNum];}
364  static double getDefaultAmbientCoeff(){return _defaultAmbientCoeff;}
365  static double getDefaultSpecularExp(){return _defaultSpecularExp;}
366  static int getDefaultNumLights(){return _defaultNumLights;}
367  static const double* getDefaultDiffuseCoeff() {return _defaultDiffuseCoeff;}
368  static const double* getDefaultSpecularCoeff() {return _defaultSpecularCoeff;}
369  static void setDefaultLightDirection(int lightNum, double val[3]){
370  for (int i = 0; i<3; i++) _defaultLightDirection[lightNum][i] = val[i];
371  }
372  static void setDefaultUpVec(double val[3]){
373  for (int i = 0; i<3; i++) _defaultUpVec[i] = val[i];
374  }
375  static void setDefaultViewDir(double val[3]){
376  for (int i = 0; i<3; i++) _defaultViewDir[i] = val[i];
377  }
378  static void setDefaultSpecularCoeff(double val[3]){
379  for (int i = 0; i<3; i++) _defaultSpecularCoeff[i] = val[i];
380  }
381  static void setDefaultDiffuseCoeff(double val[3]){
382  for (int i = 0; i<3; i++) _defaultDiffuseCoeff[i] = val[i];
383  }
384  static void setDefaultAmbientCoeff(double val){ _defaultAmbientCoeff = val;}
385  static void setDefaultSpecularExp(double val){ _defaultSpecularExp = val;}
386  static void setDefaultNumLights(int val){ _defaultNumLights = val;}
387 
388 private:
389  bool _vpChangeBit; //accessed via VPHasChanged() and VPSetChanged();
390  static const string _shortName;
391  static const string _currentViewTag;
392  static const string _homeViewTag;
393  static const string _lightDirectionsTag;
394  static const string _diffuseCoeffTag;
395  static const string _specularCoeffTag;
396  static const string _specularExpTag;
397  static const string _ambientCoeffTag;
398  static const string _numLightsTag;
399 
400  //Following is protected
401  virtual Viewpoint* getCurrentViewpoint() {
402  vector<string> path;
403  path.push_back(_currentViewTag);
404  path.push_back(Viewpoint::_viewpointTag);
405  return (Viewpoint*)GetParamsBase(path);
406  }
407  //defaults:
408  static double _defaultViewDir[3];
409  static double _defaultUpVec[3];
410  static double _defaultLightDirection[3][3];
411  static double _defaultDiffuseCoeff[3];
412  static double _defaultSpecularCoeff[3];
413  static double _defaultAmbientCoeff;
414  static double _defaultSpecularExp;
415  static int _defaultNumLights;
416  double _modelViewMatrix[16];
417  double _projectionMatrix[16];
418 #endif //DOXYGEN_SKIP_THIS
419 };
420 };
421 #endif //VIEWPOINTPARAMS_H
422 
void getStretchedCamPosLocal(double *vec)
int setViewDir(int coord, double val)
int setUpVec(int i, double val)
double getRotationCenterLocal(int coord)
void setModelViewMatrix(const double *mtx)
A pure virtual class for managing parameters used in visualization.
Definition: params.h:129
int setHomeViewpoint(Viewpoint *newVP)
double getLightDirection(int lightNum, int dir)
int setDiffuseCoeff(int lightNum, double val)
int setExponent(double val)
void getStretchedRotCtrLocal(double *vec)
int setCurrentViewpoint(Viewpoint *newVP)
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:90
static Command * CaptureStart(Params *prevParams, const char *desc, UndoRedoHelpCB_T helper=0, Params *prevAuxParams=0)
Definition: command.h:115
double getDiffuseCoeff(int lightNum)
void setProjectionMatrix(const double *mtx)
const vector< double > getUpVec()
A class for describing the viewpoint and lights in a 3D VAPOR scene.
class that indicates location and direction of view
Definition: viewpoint.h:22
int setNumLights(int nlights)
int setAmbientCoeff(double val)
static ParamsBase * CreateDefaultInstance()
int setStretchedCamPosLocal(const double *vec)
const double * getProjectionMatrix()
int setCameraPosLocal(const vector< double > &val, int)
const std::string getShortName()
const double * getModelViewMatrix()
double getSpecularCoeff(int lightNum)
double getCameraPosLocal(int coord)
const vector< double > getCameraPosLocal()
void setCurrentVPToHome()
Set the current viewpoint to be the home viewpoint.
const vector< double > getViewDir()
int setStretchedRotCtrLocal(const double *vec)
const vector< double > getRotationCenterLocal()
#define PARAMS_API
virtual Viewpoint * getHomeViewpoint()
Definition: DC.h:10
Provides support for maintaining a queue of recently issued commands, performing UnDo, ReDo, etc. The parent Command class supports a queue of Params changes; each entry has a clone of the previous and next Params instance associated with a change.
Definition: command.h:50
int setViewDir(const vector< double > &val)
int setRotationCenterLocal(const vector< double > &vec)
int setLightDirection(int lightNum, int dir, double val)
int setSpecularCoeff(int lightNum, double val)
static void CaptureEnd(Command *pCom, Params *nextParams, Params *nextAuxParams=0)
Definition: command.h:127
int setUpVec(const vector< double > &val)