25 #include "trackball.h" 33 #include <vapor/MyBase.h> 34 #include <vapor/common.h> 36 #include "ShaderMgr.h" 40 #define MAXNUMRENDERERS 20 56 class TwoDImageParams;
58 class TranslateStretchManip;
59 class TranslateRotateManip;
77 class RENDER_API
GLWindow :
public MyBase,
public QGLWidget
106 void TransformToUnitBox();
114 return manipFromMode[modeIndex];
120 return paramsFromMode[modeIndex];
132 static const string&
getModeName(
int index) {
return modeName[index];}
139 static int AddMouseMode(
const std::string paramsTag,
int manipType,
const char* name);
153 static void ConvertAxes(
bool toLatLon,
const int ticDirs[3],
const double fromMinTic[3],
const double fromMaxTic[3],
const double fromOrigin[3],
const double fromTicLength[3],
154 double toMinTic[3],
double toMaxTic[3],
double toOrigin[3],
double toTicLength[3]);
158 int addTextObject(
Renderer*,
int timestep,
const char* fontPath,
int textSize,
float textColor[4],
float bgColor[4],
int type,
string text);
159 void changeTextObjectType(
int type);
161 void addText(
Renderer*,
int timestep,
int objectNum,
float posn[3]);
163 void clearTextObjects(
Renderer*,
int timestep);
165 #ifndef DOXYGEN_SKIP_THIS 166 GLWindow( QGLFormat& fmt, QWidget* parent,
int winnum);
170 Trackball* getTBall() {
return myTBall;}
171 void setPerspective(
bool isPersp) {perspective = isPersp;}
172 bool getPerspective() {
return perspective;}
192 void setMaxSize(
float wsize) {maxDim = wsize;}
193 void setCenter(
float cntr[3]) { wCenter[0] = cntr[0]; wCenter[1] = cntr[1]; wCenter[2] = cntr[2];}
198 bool pointIsOnQuad(
float cor1[3],
float cor2[3],
float cor3[3],
float cor4[3],
float pickPt[2]);
205 int pointIsOnBox(
float corners[8][3],
float pickPt[2]);
210 bool projectPointToWin(
float cubeCoords[3],
float winCoords[2]){
211 double cCoords[3], wCoords[2];
212 for (
int i = 0; i<3; i++) cCoords[i] = cubeCoords[i];
213 bool rc = projectPointToWin(cCoords,wCoords);
214 winCoords[0]=wCoords[0];winCoords[1]=wCoords[1];
217 bool projectPointToWin(
double cubeCoords[3],
double winCoords[2]);
224 bool projectPointToLine(
float mouseCoords[2],
float projCoords[2]);
227 bool startHandleSlide(
float mouseCoords[2],
int handleNum,
Params* p);
232 bool pixelToVector(
float winCoords[2],
const float cameraPos[3],
float dirVec[3]);
235 bool getPixelData(
unsigned char* data,
string frame=
"");
237 void setRenderNew() {renderNew =
true;}
238 void draw3DCursor(
const float position[3]);
240 void renderTimeStamp(
bool rebuild);
241 void buildTimeStampImage();
244 bool useLatLonAnnotation() {
return latLonAnnot;}
245 void setLatLonAnnotation(
bool val){ latLonAnnot = val;}
249 QColor& getColorbarBackgroundColor() {
return colorbarBackgroundColor;}
250 bool axisArrowsAreEnabled() {
return axisArrowsEnabled;}
251 bool axisAnnotationIsEnabled() {
return axisAnnotationEnabled;}
253 const vector<bool> getColorbarEnabled() {
return colorbarEnabled;}
254 void setColorbarEnabled(
const vector<bool> vb) {colorbarEnabled = vb;}
255 void setColorbarTitles(
const vector<string> vs) {colorbarTitles = vs;}
256 const vector<string> getColorbarTitles() {
return colorbarTitles;}
260 float getAxisArrowCoord(
int i){
return axisArrowCoord[i];}
261 double getAxisOriginCoord(
int i){
return axisOriginCoord[i];}
262 double getMinTic(
int i){
return minTic[i];}
263 double getMaxTic(
int i){
return maxTic[i];}
264 double getTicLength(
int i){
return ticLength[i];}
265 int getNumTics(
int i){
return numTics[i];}
266 int getTicDir(
int i){
return ticDir[i];}
267 int getLabelHeight() {
return labelHeight;}
268 int getLabelDigits() {
return labelDigits;}
269 float getTicWidth(){
return ticWidth;}
270 QColor& getAxisColor() {
return axisColor;}
271 const vector<float> getColorbarLLX() {
return colorbarLLX;}
272 const vector<float> getColorbarLLY() {
return colorbarLLY;}
273 float getColorbarSize(
int i) {
return colorbarSize[i];}
274 int getColorbarNumTics() {
return numColorbarTics;}
275 int getColorbarDigits() {
return colorbarDigits;}
276 int getColorbarFontsize() {
return colorbarFontsize;}
279 int getTimeAnnotType() {
return timeAnnotType;}
280 int getTimeAnnotTextSize() {
return timeAnnotTextSize;}
281 float getTimeAnnotCoord(
int j){
return timeAnnotCoords[j];}
282 QColor getTimeAnnotColor(){
return timeAnnotColor;}
283 void setTimeAnnotTextSize(
int size){timeAnnotTextSize = size;}
284 void setTimeAnnotColor(QColor c) {timeAnnotColor = c;}
285 void setTimeAnnotType(
int t) {timeAnnotType = t;}
286 void setTimeAnnotCoords(
float crds[2]){
287 timeAnnotCoords[0] = crds[0];
288 timeAnnotCoords[1] = crds[1];
292 void setColorbarBackgroundColor(QColor& c) {colorbarBackgroundColor = c;}
295 void enableAxisArrows(
bool enable) {axisArrowsEnabled = enable;}
296 void enableAxisAnnotation(
bool enable) {axisAnnotationEnabled = enable;}
301 void setAxisArrowCoord(
int i,
float val){axisArrowCoord[i] = val;}
302 void setAxisOriginCoord(
int i,
double val){axisOriginCoord[i] = val;}
303 void setNumTics(
int i,
int val) {numTics[i] = val;}
304 void setTicDir(
int i,
int val) {ticDir[i] = val;}
305 void setMinTic(
int i,
double val) {minTic[i] = val;}
306 void setMaxTic(
int i,
double val) {maxTic[i] = val;}
307 void setTicLength(
int i,
double val) {ticLength[i] = val;}
308 void setLabelHeight(
int h){labelHeight = h;}
309 void setLabelDigits(
int d) {labelDigits = d;}
310 void setTicWidth(
float w) {ticWidth = w;}
311 void setAxisColor(QColor& c) {axisColor = c;}
312 void setDisplacement(
float val){displacement = val;}
313 float getDisplacement() {
return displacement;}
314 void setColorbarAutoTitles(
bool i) {colorbarAutoTitles = i;}
315 bool getColorbarAutoTitles() {
return colorbarAutoTitles;}
316 void setColorbarLLX(
const vector<float> crds) {colorbarLLX = crds;}
317 void setColorbarLLY(
const vector<float> crds) {colorbarLLY = crds;}
318 void setColorbarSize(
int i,
float crd) {colorbarSize[i] = crd;}
319 void setColorbarNumTics(
int i) {numColorbarTics = i;}
320 bool colorbarIsDirty() {
return colorbarDirty;}
321 bool timeAnnotIsDirty() {
return timeAnnotDirty;}
322 void setColorbarDirty(
bool val){colorbarDirty = val;}
323 void setTimeAnnotDirty(
bool val){timeAnnotDirty = val;}
324 void setColorbarDigits(
int ndigs) {colorbarDigits = ndigs;}
325 void setColorbarFontsize(
int fsize) {colorbarFontsize = fsize;}
326 void setAxisLabelsDirty(
bool val){axisLabelsDirty = val;}
327 void setTextRenderersDirty(
bool val){textRenderersDirty = val;}
328 bool textRenderersAreDirty() {
return textRenderersDirty;}
329 bool axisLabelsAreDirty(){
return axisLabelsDirty;}
332 bool mouseIsDown() {
return mouseDownHere;}
333 void setMouseDown(
bool downUp) {mouseDownHere = downUp;}
335 void setNumRenderers(
int num) {numRenderers = num;}
336 int getNumRenderers() {
return numRenderers;}
339 Renderer* getRenderer(
int i) {
return renderer[i];}
351 void removeAllRenderers();
352 void sortRenderers(
int timestep);
354 void removeDisabledRenderers();
358 static int getCurrentMouseMode() {
return currentMouseMode;}
359 static void setCurrentMouseMode(
int t){currentMouseMode = t;}
368 void setActiveViewpointParams(
Params* p) {setActiveParams(p,Params::_viewpointParamsTag);}
369 void setActiveRegionParams(
Params* p) {
370 setActiveParams(p,Params::_regionParamsTag);
371 getManip(Params::_regionParamsTag)->setParams(p);
373 void setActiveAnimationParams(
Params* p) {setActiveParams(p,Params::_animationParamsTag);}
376 FlowParams* getActiveFlowParams() {
return (FlowParams*)getActiveParams(Params::_flowParamsTag);}
377 ProbeParams* getActiveProbeParams() {
return (ProbeParams*)getActiveParams(Params::_probeParamsTag);}
378 TwoDDataParams* getActiveTwoDDataParams() {
return (TwoDDataParams*)getActiveParams(Params::_twoDDataParamsTag);}
379 TwoDImageParams* getActiveTwoDImageParams() {
return (TwoDImageParams*)getActiveParams(Params::_twoDImageParamsTag);}
381 vector<Params*> currentParams;
385 currentParams[pType] = p;
387 void setActiveParams(
Params* p,
const std::string& tag){
398 float getPixelSize();
399 bool viewerCoordsChanged() {
return newViewerCoords;}
400 void setViewerCoordsChanged(
bool isNew) {newViewerCoords = isNew;}
401 bool isCapturingImage() {
return (capturingImage != 0);}
402 bool isCapturingFlow() {
return (capturingFlow);}
403 bool isSingleCapturingImage() {
return (capturingImage == 1);}
404 void startImageCapture(QString& name,
int startNum,
bool isTif) {
406 captureNumImage = startNum;
407 captureNameImage = name;
408 newCaptureImage =
true;
409 capturingTif = isTif;
410 previousFrameNum = -1;
411 previousTimeStep = -1;
414 void startFlowCapture(QString& name) {
415 capturingFlow =
true;
416 captureNameFlow = name;
419 void singleCaptureImage(QString& name){
421 captureNameImage = name;
422 newCaptureImage =
true;
425 bool captureIsNewImage() {
return newCaptureImage;}
427 void setCaptureNewImage(
bool isNew){ newCaptureImage = isNew;}
429 void stopImageCapture() {capturingImage = 0;}
430 void stopFlowCapture() {capturingFlow =
false;}
434 void doFrameCapture(
string frame=
"");
435 QString& getFlowFilename(){
return captureNameFlow;}
438 TranslateStretchManip* getManip(
const std::string& paramTag){
440 return manipHolder[mode];
443 ColorbarManip* getColorbarManip() {
return _cbManip;}
446 void setPreRenderCB(
renderCBFcn f){preRenderCB = f;}
447 void setPostRenderCB(
renderCBFcn f){postRenderCB = f;}
448 static int getJpegQuality();
449 static void setJpegQuality(
int qual);
450 static bool depthPeelEnabled() {
return depthPeeling;}
451 static void enableDepthPeeling(
bool val) {depthPeeling = val;}
452 static bool getDefaultAxisArrowsEnabled(){
return defaultAxisArrowsEnabled;}
453 static void setDefaultAxisArrows(
bool val){defaultAxisArrowsEnabled = val;}
454 static bool getDefaultTerrainEnabled(){
return defaultTerrainEnabled;}
455 static bool getDefaultSpinAnimateEnabled(){
return defaultSpinAnimateEnabled;}
456 static void setDefaultShowTerrain(
bool val){defaultTerrainEnabled = val;}
457 static void setDefaultSpinAnimate(
bool val){defaultSpinAnimateEnabled = val;}
458 static void setDefaultPrefs();
459 int getWindowNum() {
return winNum;}
463 static int getActiveWinNum() {
return activeWindowNum;}
464 static void setActiveWinNum(
int winnum) {activeWindowNum = winnum;}
465 bool windowIsActive(){
return (winNum == activeWindowNum);}
466 static bool activeWinSharesRegion() {
return regionShareFlag;}
467 static void setRegionShareFlag(
bool regionIsShared){regionShareFlag = regionIsShared;}
470 const GLdouble* getProjectionMatrix() {
return projectionMatrix;}
472 void getNearFarClippingPlanes(GLfloat *nearplane, GLfloat *farplane) {
473 *nearplane = nearDist; *farplane = farDist;
477 const GLint* getViewport() {
return viewport;}
486 static OGLVendorType GetVendor();
488 void startSpin(
int renderMS);
491 bool spinning(){
return isSpinning;}
497 static bool isRendering(){
return nowPainting;}
499 static void setSpinAnimation(
bool on){spinAnimate = on;}
500 static bool spinAnimationEnabled(){
return spinAnimate;}
508 GLuint currentBuffer;
511 GLuint depthA, depthB;
513 int depthWidth, depthHeight, depthTexUnit;
514 ShaderMgr* getShaderMgr() {
return manager;}
515 void depthPeelPaintEvent();
516 void renderScene(
float extents[6],
float minFull[3],
float maxFull[3],
int timeStep);
517 void setUpPaintEvent();
518 bool checkForStereo();
519 void regPaintEvent(
float *extents,
float *minFull,
float *maxFull);
520 int adjustTo3D(
string eye);
521 bool peelInitialized;
522 bool isDepthPeeling(){
return depthPeeling;}
524 for (
int i = 0; i< rendererTypeLookup.size(); i++){
525 if (rendererTypeLookup[i] == t)
return i;
529 int getNumTFs() {
return rendererTypeLookup.size();}
532 QImage glTimeStampImage;
533 SpinTimer *mySpinTimer;
536 static vector<ParamsBase::ParamsBaseType> paramsFromMode;
537 static vector<int> manipFromMode;
538 static vector<string> modeName;
539 static map<ParamsBase::ParamsBaseType, int> modeFromParams;
541 vector<TranslateStretchManip*> manipHolder;
542 ColorbarManip* _cbManip;
548 class RenderListElt {
554 static bool renderPriority(RenderListElt* ren1, RenderListElt* ren2){
555 return (ren1->camDist > ren2->camDist);
561 for (
int i = 0; i< rendererTypeLookup.size(); i++){
563 if (colorbarEnabled[i])
return i;
570 static void flatConvertFromLonLat(
double x[2],
double minLon,
double maxLon,
double minX,
double maxX);
571 std::vector<QImage> axisLabels[3];
573 bool axisLabelsDirty;
574 bool textRenderersDirty;
575 static bool depthPeeling;
577 int previousTimeStep;
578 int previousFrameNum;
579 static int jpegQuality;
583 bool newViewerCoords;
584 static int currentMouseMode;
585 std::map<DirtyBitType,bool> vizDirtyBit;
592 std::map<RenderParams*,Renderer*> rendererMapping;
600 GLdouble* getModelMatrix();
604 GLfloat* setTexCrd(
int i,
int j);
611 void resizeGL(
int w,
int h );
623 void paintEvent(QPaintEvent* event);
625 bool event ( QEvent * e );
628 void perspectiveGL( GLdouble fovY, GLdouble aspect, GLdouble zNear, GLdouble zFar );
629 void setUpViewport(
int width,
int height);
632 void setSubregionFrameColorFlt(
const QColor& c);
633 void setRegionFrameColorFlt(
const QColor& c);
636 void renderDomainFrame(
float* extents,
float* minFull,
float* maxFull);
638 void drawSubregionBounds(
float* extents);
639 void drawAxisArrows(
float* extents);
640 void drawAxisTics(
int tstep);
641 void drawAxisLabels(
int tstep);
642 void buildAxisLabels(
int tstep);
647 static float* cornerPoint(
float* extents,
int faceNum);
650 static bool faceIsVisible(
float* extents,
float* viewerCoords,
int faceNum);
654 void renderText(
int timestep);
655 float regionFrameColorFlt[3];
656 float subregionFrameColorFlt[3];
671 bool newCaptureImage;
672 QString captureNameImage;
673 QString captureNameFlow;
677 float farDist, nearDist;
680 GLdouble projectionMatrix[16];
681 static bool nowPainting;
684 QColor colorbarBackgroundColor;
688 int timeAnnotTextSize;
689 float timeAnnotCoords[2];
690 QColor timeAnnotColor;
692 bool axisArrowsEnabled;
693 bool axisAnnotationEnabled;
695 int colorbarFontsize;
697 float axisArrowCoord[3];
698 double axisOriginCoord[3];
704 int labelHeight, labelDigits;
709 bool colorbarAutoTitles;
710 vector<float> colorbarLLX;
711 vector<float> colorbarLLY;
712 vector<bool> colorbarEnabled;
713 vector<string>colorbarTitles;
714 float colorbarSize[2];
725 static int activeWindowNum;
729 static bool regionShareFlag;
730 static bool defaultTerrainEnabled;
731 static bool defaultSpinAnimateEnabled;
732 static bool spinAnimate;
733 static bool defaultAxisArrowsEnabled;
736 int axisLabelNums[3];
740 float mouseDownPoint[2];
742 float handleProjVec[2];
744 GLuint _timeStampTexid;
750 map<int, map<Renderer*,vector<TextObject*> > >textObjectMap;
752 map< int, map< pair<Renderer*, int> , vector<float*>* > >textCoordMap;
753 std::vector<int> rendererTypeLookup;
756 #endif //DOXYGEN_SKIP_THIS A class for performing OpenGL rendering in a VAPOR Visualizer.
A pure virtual class for managing parameters used in visualization.
A Params subclass for managing parameters used by Renderers.
virtual bool UsesMapperFunction()
static Params * GetCurrentParamsInstance(int pType, int winnum)
ViewpointParams * getActiveViewpointParams()
A class for describing a 3D axis-aligned region in user space.
ParamsBaseType GetParamsBaseTypeId()
AnimationParams * getActiveAnimationParams()
A class for describing the viewpoint and lights.
bool(* renderCBFcn)(int winnum, bool newCoords)
static ParamsBaseType GetTypeFromTag(const string &tag)
static DataStatus * getInstance()
RegionParams * getActiveRegionParams()
static int getModeManipType(int modeIndex)
A class that specifies parameters used in animation.
static const string & getModeName(int index)
static int getModeFromParams(ParamsBase::ParamsBaseType t)
static ParamsBase::ParamsBaseType getModeParamType(int modeIndex)
A class that performs rendering in the GLWindow.