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