VAPoR  0.1
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 <qwidget.h>
24 #include "params.h"
25 
26 #include "viewpoint.h"
27 
28 class VizTab;
29 
30 namespace VAPoR {
31 class ExpatParseMgr;
32 class MainForm;
33 class RegionParams;
34 class PanelCommand;
35 class XmlNode;
36 class ParamNode;
47 
48 public:
51  ViewpointParams(int winnum);
53  virtual ~ViewpointParams();
54 
55 
60  static float getMaxStretchedCubeSide() {return maxStretchedCubeSide;}
61 
66  static float* getMinStretchedCubeCoords() {return minStretchedCubeCoord;}
67 
72  int getNumLights() { return numLights;}
73 
78  float getExponent() {return specularExp;}
79 
82  float* getCameraPosLocal() {return currentViewpoint->getCameraPosLocal();}
83 
86  float* getViewDir() {return currentViewpoint->getViewDir();}
87 
90  float* getUpVec() {return currentViewpoint->getUpVec();}
91 
96  float* getRotationCenterLocal(){return currentViewpoint->getRotationCenterLocal();}
97 
98 #ifndef DOXYGEN_SKIP_THIS
99  static ParamsBase* CreateDefaultInstance() {return new ViewpointParams(-1);}
100  const std::string& getShortName() {return _shortName;}
101  virtual Params* deepCopy(ParamNode* n = 0);
102  //Note that all calls to get camera pos and get rot center return values
103  //in local coordinates, not in lat/lon. When the viewpoint params is in
104  //latlon mode, it is necessary to perform convertLocalFromLonLat and convertLocalToLonLat
105  //to keep the local coords current with latlons. This conversion must occur whenever
106  //the coordinates change (from the gui or the manip),
107  //and when the time step changes, whenever
108  //there is a change between latlon and local mode, and whenever a new
109  //data set is loaded
110  //When setCameraPos or setRotCenter is called in latlon mode, the new local values
111  //must be converted to latlon values.
112 
113  float getCameraPosLocal(int coord) {return currentViewpoint->getCameraPosLocal()[coord];}
114 
115  void setCameraPosLocal(float* val,int timestep ) {
116  currentViewpoint->setCameraPosLocal(val);
117  if (useLatLon) convertLocalToLonLat(timestep);
118  }
119 
120  void setViewDir(int i, float val) { currentViewpoint->setViewDir(i,val);}
121  void setViewDir(float* val) {currentViewpoint->setViewDir(val);}
122 
123  void setUpVec(int i, float val) { currentViewpoint->setUpVec(i,val);}
124  void setUpVec(float* val) {currentViewpoint->setUpVec(val);}
125  bool hasPerspective(){return currentViewpoint->hasPerspective();}
126  void setPerspective(bool on) {currentViewpoint->setPerspective(on);}
127  int getStereoMode(){ return stereoMode;}
128  void setStereoMode(int mode) {stereoMode = mode;}
129  float getStereoSeparation() {return stereoSeparation;}
130  void setStereoSeparation(float angle){stereoSeparation = angle;}
131 
132  void setNumLights(int nlights) {numLights = nlights;}
133  const float* getLightDirection(int lightNum){return lightDirection[lightNum];}
134  void setLightDirection(int lightNum,int dir, float val){
135  lightDirection[lightNum][dir] = val;
136  }
137  float getDiffuseCoeff(int lightNum) {return diffuseCoeff[lightNum];}
138  float getSpecularCoeff(int lightNum) {return specularCoeff[lightNum];}
139 
140  float getAmbientCoeff() {return ambientCoeff;}
141  void setDiffuseCoeff(int lightNum, float val) {diffuseCoeff[lightNum]=val;}
142  void setSpecularCoeff(int lightNum, float val) {specularCoeff[lightNum]=val;}
143  void setExponent(float val) {specularExp=val;}
144  void setAmbientCoeff(float val) {ambientCoeff=val;}
145  Viewpoint* getCurrentViewpoint() { return currentViewpoint;}
146  void setCurrentViewpoint(Viewpoint* newVP){
147  if (currentViewpoint) delete currentViewpoint;
148  currentViewpoint = newVP;
149  }
150  Viewpoint* getHomeViewpoint() { return homeViewpoint;}
151  void setHomeViewpoint(Viewpoint* newVP){
152  if (homeViewpoint) delete homeViewpoint;
153  homeViewpoint = newVP;
154  }
155 
156  //Set to default viewpoint for specified region
157  void centerFullRegion(int timestep);
158 
159  float* getRotCenterLatLon(){return currentViewpoint->getRotCenterLatLon();}
160  float getRotationCenterLocal(int i){ return currentViewpoint->getRotationCenterLocal(i);}
161  float* getCamPosLatLon() {return currentViewpoint->getCamPosLatLon();}
162 
163  void setRotationCenterLocal(float* vec, int timestep){
164  currentViewpoint->setRotationCenterLocal(vec);
165  if (useLatLon) convertLocalToLonLat(timestep);
166  }
167  void setCamPosLatLon(float x, float y) {currentViewpoint->setCamPosLatLon(x,y);}
168  void setRotCenterLatLon(float x, float y) {currentViewpoint->setRotCenterLatLon(x,y);}
169  bool isLatLon() {return useLatLon;}
170  void setLatLon(bool val){useLatLon = val;}
171 
172  void rescale(float scaleFac[3], int timestep);
173 
174  bool convertLocalToLonLat(int timestep);
175  bool convertLocalFromLonLat(int timestep);
176  //determine far and near distance to region based on current viewpoint
177  void getFarNearDist(float* boxFar, float* boxNear);
178 
179  //Reset viewpoint when new session is started:
180  virtual bool reinit(bool doOverride);
181  virtual void restart();
182 
183  static void setDefaultPrefs();
184  //Transformations to convert world coords to (unit)render cube and back
185  //
186 
187  static void localToStretchedCube(const float fromCoords[3], float toCoords[3]);
188 
189  static void localToStretchedCube(const double fromCoords[3], double toCoords[3]);
190 
191 
192  static void localFromStretchedCube(float fromCoords[3], float toCoords[3]);
193  static void setCoordTrans();
194 
195  //Maintain the OpenGL Model Matrices, since they can be shared between visualizers
196 
197  const double* getModelViewMatrix() {return modelViewMatrix;}
198 
199  //Rotate a 3-vector based on current modelview matrix
200  void transform3Vector(const float vec[3], float resvec[3]);
201 
202  void setModelViewMatrix(double* mtx){
203  for (int i = 0; i<16; i++) modelViewMatrix[i] = mtx[i];
204  }
205  bool elementStartHandler(ExpatParseMgr*, int /* depth*/ , std::string& /*tag*/, const char ** /*attribs*/);
206  bool elementEndHandler(ExpatParseMgr*, int /*depth*/ , std::string& /*tag*/);
207  ParamNode* buildNode();
208  static const float* getDefaultViewDir(){return defaultViewDir;}
209  static const float* getDefaultUpVec(){return defaultUpVec;}
210  static const float* getDefaultLightDirection(int lightNum){return defaultLightDirection[lightNum];}
211  static float getDefaultAmbientCoeff(){return defaultAmbientCoeff;}
212  static float getDefaultSpecularExp(){return defaultSpecularExp;}
213  static int getDefaultNumLights(){return defaultNumLights;}
214  static const float* getDefaultDiffuseCoeff() {return defaultDiffuseCoeff;}
215  static const float* getDefaultSpecularCoeff() {return defaultSpecularCoeff;}
216  static void setDefaultLightDirection(int lightNum, float val[3]){
217  for (int i = 0; i<3; i++) defaultLightDirection[lightNum][i] = val[i];
218  }
219  static void setDefaultUpVec(float val[3]){
220  for (int i = 0; i<3; i++) defaultUpVec[i] = val[i];
221  }
222  static void setDefaultViewDir(float val[3]){
223  for (int i = 0; i<3; i++) defaultViewDir[i] = val[i];
224  }
225  static void setDefaultSpecularCoeff(float val[3]){
226  for (int i = 0; i<3; i++) defaultSpecularCoeff[i] = val[i];
227  }
228  static void setDefaultDiffuseCoeff(float val[3]){
229  for (int i = 0; i<3; i++) defaultDiffuseCoeff[i] = val[i];
230  }
231  static void setDefaultAmbientCoeff(float val){ defaultAmbientCoeff = val;}
232  static void setDefaultSpecularExp(float val){ defaultSpecularExp = val;}
233  static void setDefaultNumLights(int val){ defaultNumLights = val;}
234 
235 
236 protected:
237 
238 
239 
240  static const string _shortName;
241  static const string _latLonAttr;
242  static const string _currentViewTag;
243  static const string _homeViewTag;
244  static const string _lightTag;
245  static const string _lightDirectionAttr;
246  static const string _lightNumAttr;
247  static const string _diffuseLightAttr;
248  static const string _ambientLightAttr;
249  static const string _specularLightAttr;
250  static const string _specularExponentAttr;
251  static const string _stereoModeAttr;
252  static const string _stereoSeparationAttr;
253 
254 
255  Viewpoint* currentViewpoint;
256  Viewpoint* homeViewpoint;
257  float stereoSeparation;
258  int stereoMode; //0 for center, 1 for left, 2 for right
259  bool useLatLon;
260  int numLights;
261  int parsingLightNum;
262  float lightDirection[3][4];
263  float diffuseCoeff[3];
264  float specularCoeff[3];
265  float specularExp;
266  float ambientCoeff;
267 
268  //Static coeffs for affine coord conversion:
269  //
270  static float minStretchedCubeCoord[3];
271  static float maxStretchedCubeCoord[3];
272 
273  static float maxStretchedCubeSide;
274  //defaults:
275  static float defaultViewDir[3];
276  static float defaultUpVec[3];
277  static float defaultLightDirection[3][3];
278  static float defaultDiffuseCoeff[3];
279  static float defaultSpecularCoeff[3];
280  static float defaultAmbientCoeff;
281  static float defaultSpecularExp;
282  static int defaultNumLights;
283  //Max sides
284 
285  //GL state saved here since it may be shared...
286  //
287  double modelViewMatrix[16];
288 #endif //DOXYGEN_SKIP_THIS
289 };
290 };
291 #endif //VIEWPOINTPARAMS_H
292 
#define PARAMS_API
Definition: common.h:63
A pure virtual class for managing parameters used in visualization.
Definition: params.h:75
static float getMaxStretchedCubeSide()
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:57
A class for describing the viewpoint and lights.
float * getRotationCenterLocal()
static float * getMinStretchedCubeCoords()