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;
46 class PARAMS_API ViewpointParams : public Params {
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  bool getStereoCapture(){ return stereoCapture;}
142  void setStereoMode(int mode) {stereoMode = mode;}
143  void setStereoCapture(int mode) {stereoCapture = mode;}
144  float getStereoSeparation() {return stereoSeparation;}
145  void setStereoSeparation(float angle){stereoSeparation = angle;}
146  float getStereoConvergence() {return stereoConvergence;}
147  void setStereoConvergence(float conv) {stereoConvergence = conv;}
148 
149  void setNumLights(int nlights) {numLights = nlights;}
150  const float* getLightDirection(int lightNum){return lightDirection[lightNum];}
151  void setLightDirection(int lightNum,int dir, float val){
152  lightDirection[lightNum][dir] = val;
153  }
154  float getDiffuseCoeff(int lightNum) {return diffuseCoeff[lightNum];}
155  float getSpecularCoeff(int lightNum) {return specularCoeff[lightNum];}
156 
157  float getAmbientCoeff() {return ambientCoeff;}
158  void setDiffuseCoeff(int lightNum, float val) {diffuseCoeff[lightNum]=val;}
159  void setSpecularCoeff(int lightNum, float val) {specularCoeff[lightNum]=val;}
160  void setExponent(float val) {specularExp=val;}
161  void setAmbientCoeff(float val) {ambientCoeff=val;}
162  Viewpoint* getCurrentViewpoint() { return currentViewpoint;}
163  void setCurrentViewpoint(Viewpoint* newVP){
164  if (currentViewpoint) delete currentViewpoint;
165  currentViewpoint = newVP;
166  }
167  Viewpoint* getHomeViewpoint() { return homeViewpoint;}
168  void setHomeViewpoint(Viewpoint* newVP){
169  if (homeViewpoint) delete homeViewpoint;
170  homeViewpoint = newVP;
171  }
172 
173  //Set to default viewpoint for specified region
174  void centerFullRegion(int timestep);
175 
176  float* getRotCenterLatLon(){return currentViewpoint->getRotCenterLatLon();}
177  float getRotationCenterLocal(int i){ return currentViewpoint->getRotationCenterLocal(i);}
178  float* getCamPosLatLon() {return currentViewpoint->getCamPosLatLon();}
179 
180  void setRotationCenterLocal(float* vec, int timestep){
181  currentViewpoint->setRotationCenterLocal(vec);
182  if (useLatLon) convertLocalToLonLat(timestep);
183  }
184  void setCamPosLatLon(float x, float y) {currentViewpoint->setCamPosLatLon(x,y);}
185  void setRotCenterLatLon(float x, float y) {currentViewpoint->setRotCenterLatLon(x,y);}
186  bool isLatLon() {return useLatLon;}
187  void setLatLon(bool val){useLatLon = val;}
188 
189  void rescale(float scaleFac[3], int timestep);
190 
191  bool convertLocalToLonLat(int timestep);
192  bool convertLocalFromLonLat(int timestep);
193  //determine far and near distance to region based on current viewpoint
194  void getFarNearDist(float* boxFar, float* boxNear);
195 
196  //Reset viewpoint when new session is started:
197  virtual bool reinit(bool doOverride);
198  virtual void restart();
199 
200  static void setDefaultPrefs();
201  //Transformations to convert world coords to (unit)render cube and back
202  //
203 
204  static void localToStretchedCube(const float fromCoords[3], float toCoords[3]);
205 
206  static void localToStretchedCube(const double fromCoords[3], double toCoords[3]);
207 
208 
209  static void localFromStretchedCube(float fromCoords[3], float toCoords[3]);
210  static void setCoordTrans();
211 
212  //Maintain the OpenGL Model Matrices, since they can be shared between visualizers
213 
214  const double* getModelViewMatrix() {return modelViewMatrix;}
215 
216  //Rotate a 3-vector based on current modelview matrix
217  void transform3Vector(const float vec[3], float resvec[3]);
218 
219  void setModelViewMatrix(double* mtx){
220  for (int i = 0; i<16; i++) modelViewMatrix[i] = mtx[i];
221  }
222  bool elementStartHandler(ExpatParseMgr*, int /* depth*/ , std::string& /*tag*/, const char ** /*attribs*/);
223  bool elementEndHandler(ExpatParseMgr*, int /*depth*/ , std::string& /*tag*/);
224  ParamNode* buildNode();
225  static const float* getDefaultViewDir(){return defaultViewDir;}
226  static const float* getDefaultUpVec(){return defaultUpVec;}
227  static const float* getDefaultLightDirection(int lightNum){return defaultLightDirection[lightNum];}
228  static float getDefaultAmbientCoeff(){return defaultAmbientCoeff;}
229  static float getDefaultSpecularExp(){return defaultSpecularExp;}
230  static int getDefaultNumLights(){return defaultNumLights;}
231  static const float* getDefaultDiffuseCoeff() {return defaultDiffuseCoeff;}
232  static const float* getDefaultSpecularCoeff() {return defaultSpecularCoeff;}
233  static void setDefaultLightDirection(int lightNum, float val[3]){
234  for (int i = 0; i<3; i++) defaultLightDirection[lightNum][i] = val[i];
235  }
236  static void setDefaultUpVec(float val[3]){
237  for (int i = 0; i<3; i++) defaultUpVec[i] = val[i];
238  }
239  static void setDefaultViewDir(float val[3]){
240  for (int i = 0; i<3; i++) defaultViewDir[i] = val[i];
241  }
242  static void setDefaultSpecularCoeff(float val[3]){
243  for (int i = 0; i<3; i++) defaultSpecularCoeff[i] = val[i];
244  }
245  static void setDefaultDiffuseCoeff(float val[3]){
246  for (int i = 0; i<3; i++) defaultDiffuseCoeff[i] = val[i];
247  }
248  static void setDefaultAmbientCoeff(float val){ defaultAmbientCoeff = val;}
249  static void setDefaultSpecularExp(float val){ defaultSpecularExp = val;}
250  static void setDefaultNumLights(int val){ defaultNumLights = val;}
251  static const string _stereoUserPrefAttr;
252  static const string _stereoCaptureUserPrefAttr;
253 
254 
255 protected:
256 
257 
258 
259  static const string _shortName;
260  static const string _latLonAttr;
261  static const string _currentViewTag;
262  static const string _homeViewTag;
263  static const string _lightTag;
264  static const string _lightDirectionAttr;
265  static const string _lightNumAttr;
266  static const string _diffuseLightAttr;
267  static const string _ambientLightAttr;
268  static const string _specularLightAttr;
269  static const string _specularExponentAttr;
270  static const string _stereoModeAttr;
271  static const string _stereoCaptureAttr;
272  static const string _stereoSeparationAttr;
273  static const string _stereoConvergenceAttr;
274 
275  Viewpoint* currentViewpoint;
276  Viewpoint* homeViewpoint;
277  static bool _stereoSupported;
278  static bool _stereoUserPref;
279  static bool _stereoCaptureUserPref;
280  float stereoSeparation;
281  float stereoConvergence;
282  int stereoMode;
283  bool stereoCapture;
284  bool useLatLon;
285  int numLights;
286  int parsingLightNum;
287  float lightDirection[3][4];
288  float diffuseCoeff[3];
289  float specularCoeff[3];
290  float specularExp;
291  float ambientCoeff;
292 
293  //Static coeffs for affine coord conversion:
294  //
295  static float minStretchedCubeCoord[3];
296  static float maxStretchedCubeCoord[3];
297 
298  static float maxStretchedCubeSide;
299  //defaults:
300  static float defaultViewDir[3];
301  static float defaultUpVec[3];
302  static float defaultLightDirection[3][3];
303  static float defaultDiffuseCoeff[3];
304  static float defaultSpecularCoeff[3];
305  static float defaultAmbientCoeff;
306  static float defaultSpecularExp;
307  static int defaultNumLights;
308  //Max sides
309 
310  //GL state saved here since it may be shared...
311  //
312  double modelViewMatrix[16];
313 #endif //DOXYGEN_SKIP_THIS
314 };
315 };
316 #endif //VIEWPOINTPARAMS_H
317 
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()