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