Overture  Version 25
GenericGraphicsInterface.h
Go to the documentation of this file.
1 #ifndef GENERIC_GRAPHICS_INTERFACE_H
2 #define GENERIC_GRAPHICS_INTERFACE_H
3 
4 //============================================================================================
5 // -----------------------------------------
6 // ------Generic Graphics Interface---------
7 // -----------------------------------------
8 //
9 // This is the generic graphics interface. It supports menus, command files and
10 // some generic plotting. This Class does not know how to do any plotting. The
11 // derived Class GL_GraphicsInterface does know how to plot.
12 //
13 //===========================================================================================
14 
15 #ifndef NO_APP
16 #include "GenericDataBase.h"
17 #endif
18 
19 #include "GUITypes.h"
20 
21 #include "wdhdefs.h"
22 
23 #include "mathutil.h" // define max, min, etc
24 
25 #ifndef NO_APP
26 #include "OvertureInit.h"
27 #else
28 #include "GUIInit.h"
29 #endif
30 
31 #include "GraphicsParameters.h"
32 
33 #include <assert.h>
34 
35 #ifndef NO_APP
36 #ifndef OV_USE_OLD_STL_HEADERS
37 #include <stack>
38 #include <queue>
40 #else
41 #include <stack.h>
42 #include <queue.h>
43 #endif
44 #else
45 #include <stack>
46 #include <queue>
47 #endif
48 
49 // extern GraphicsParameters Overture::defaultGraphicsParameters(); // use these as a default argument
50 extern const aString nullString;
51 
52 // forward declarations
53 class CompositeSurface;
55 class AdvancingFront;
56 
57 class MappedGrid;
60 
61 class GridCollection;
64 
66 
67 #ifdef OV_USE_DOUBLE
70 #else
73 #endif
74 
75 #include "GUIState.h"
76 // class SelectionInfo;
77 // class PickInfo3D;
78 // class GUIState;
79 
81 {
82 public:
83 // data member are public for now...
87 };
88 
90 {
91 public:
92 
94 {
95  offScreenRender, // better but may not be supported when OpenGl does direct rendering to the hardware
96  frameBuffer // grab the frame buffer, resolution is determined by the window size
97 };
98 
99 
100 enum
101 {
102  defaultOrigin=-(INT_MAX/2)
103 };
104 
106 {
110 };
111 
112 enum
113 {
115 };
116 
117 // Set some view parameters
119 {
120  xAxisAngle, // angle to rotate about x-axis (absolute value, not incremental)
127 };
128 
129 enum displayListProperty{ // bitwise flags for handling display lists.
130  lightDL = 1, // if this bit is set, the display list should be plotted with lighting, otherwise not.
131  plotDL = 2, // if this bit is set, the display list should be plotted, otherwise not
132  hideableDL = 4, // if this bit is set, the display list can be hidden (i.e., not plotted) instead of
133 // getting erased.
134  interactiveDL = 8 // if set, this display list will be drawn during interactive rotations
135 };
136 
137 //
138 // Default constructor
139 //
141 //
142 // Constructor that takes argc and argv from main program and strips away GLUT parameters
143 //
144 GenericGraphicsInterface(int & argc, char *argv[]);
145 
146 virtual
148 
149 // abort the program if we stop reading a command file.
150 void
151 abortIfCommandFileEnds(bool trueOrFalse=true);
152 
153 virtual void
154 appendCommandHistory(const aString &answer)=0;
155 
156 // make a new default prompt by appending to the current, and push onto the stack
157 int
158 appendToTheDefaultPrompt(const aString & appendage );
159 
160 virtual int
161 beginRecordDisplayLists( IntegerArray & displayLists)=0;
162 
163 
164 // add cascading entries to a long menu.
165 int
167  int startCascade,
168  int endCascade ) const ;
169 // choose a colour
170 virtual aString
171 chooseAColour()=0;
172 
173 virtual void
175 
176 // Open the window (but only if one is not already open)
177 virtual int
178 createWindow(const aString & windowTitle = nullString,
179  int argc=0,
180  char *argv[] = NULL )=0;
181 
182 virtual void
183 deleteList(int dList)=0;
184 
185 // destroy the window
186 virtual int
187 destroyWindow(int win_number)=0;
188 
189 virtual void
190 displayColourBar(const int & numberOfContourLevels,
191  RealArray & contourLevels,
192  GUITypes::real uMin,
193  GUITypes::real uMax,
194  GraphicsParameters & parameters)=0;
195 
196 // display help on a topic in the help pull-down menu
197 virtual bool
198 displayHelp( const aString & topic )=0;
199 
200 // Draw coloured squares with a number inside them to label colours on the plot
201 virtual void
202 drawColouredSquares(const IntegerArray & numberList,
204  const int & numberOfColourNames = -1 , // use default colours by default
205  aString *colourNames = NULL)=0;
206 
207 
208 virtual void
209 drawColourBar(const int & numberOfContourLevels,
210  RealArray & contourLevels,
211  GUITypes::real uMin=0.,
212  GUITypes::real uMax=1.,
214  GUITypes::real xLeft=.775, // .8
215  GUITypes::real xRight=.825, // .85
216  GUITypes::real yBottom=-.75,
217  GUITypes::real yTop=.75)=0;
218 
219 
220 virtual int
221 endRecordDisplayLists( IntegerArray & displayLists)=0;
222 
223 // Erase all graphics display lists
224 virtual void
225 erase()=0;
226 
227 // erases all display lists in window win_number.
228 virtual void
229 erase(const int win_number, bool forceDelete = false)=0;
230 
231 // erase a list of display lists
232 virtual void
233 erase(const IntegerArray & displayList)=0;
234 
235 virtual void
236 eraseColourBar()=0;
237 
238 virtual void
239 eraseLabels(GraphicsParameters & parameters, int win_number = -1)=0;
240 
241 virtual int
242 generateNewDisplayList(bool lit = false, bool plotIt = true, bool erasable = false,
243  bool interactive = true)=0;
244 
245 virtual int
246 getMenuItem(const aString *menu, aString & answer, const aString & prompt=nullString)=0;
247 
248 virtual int
249 getAnswer(aString & answer, const aString & prompt)=0;
250 
251 virtual int
252 getAnswer(aString & answer, const aString & prompt,
253  SelectionInfo &selection)=0;
254 
255 virtual int
256 getAnswerNoBlock(aString & answer, const aString & prompt)=0;
257 
258 // return the aspect ratio of a window
259 virtual GUITypes::real
260 getAspectRatio(const int win=0)=0;
261 
262 virtual void
264 
265 // Set the info level which determines the level of information that is output.
266 // 0=expert, 1=intermediate, 2=novice
267 int
268 getInfoLevel() const;
269 
270 // access functions for display lists
271 virtual int
272 getFirstDL(const int win)=0;
273 
274 virtual int
275 getFirstFixedDL(const int win)=0;
276 
277 virtual int
278 getTopLabelDL(const int win)=0;
279 
280 virtual int
281 getTopLabel1DL(const int win)=0;
282 
283 virtual int
284 getTopLabel2DL(const int win)=0;
285 
286 virtual int
287 getTopLabel3DL(const int win)=0;
288 
289 virtual int
290 getBottomLabelDL(const int win)=0;
291 
292 virtual int
293 getBottomLabel1DL(const int win)=0;
294 
295 virtual int
296 getBottomLabel2DL(const int win)=0;
297 
298 virtual int
299 getBottomLabel3DL(const int win)=0;
300 
301 virtual int
302 getCurrentWindow()=0;
303 
304 // get the name of the colour for backGroundColour, textColour, ...
305 virtual aString
306 getColour( ItemColourEnum item )=0;
307 
308 // return the name of a colour for i=0,1,2,...
309 virtual aString
310 getColourName( int i ) const=0;
311 
312 virtual int
313 getColouredSquaresDL(const int win)=0;
314 
315 virtual int
316 getColourBarDL(const int win)=0;
317 
318 const aString &
320 
321 virtual RealArray
322 getGlobalBound() const=0;
323 
324 virtual bool
326 
327 virtual bool
328 getPlotTheAxes(int win_number=-1)=0;
329 
330 virtual bool
331 getPlotTheColourBar(int win_number = -1)=0;
332 
333 virtual bool
334 getPlotTheColouredSquares(int win_number = -1)=0;
335 
336 virtual bool
337 getPlotTheLabels(int win_number = -1)=0;
338 
339 virtual int
340 getFirstUserLabelDL(const int win)=0;
341 
342 virtual int
343 getLastUserLabelDL(const int win)=0;
344 
345 virtual int
346 getLastFixedDL(const int win)=0;
347 
348 virtual int
349 getFirstRotableDL(const int win)=0;
350 
351 virtual int
352 getAxesDL(const int win)=0;
353 
354 virtual int
355 getFirstUserRotableDL(const int win)=0;
356 
357 virtual int
358 getLastUserRotableDL(const int win)=0;
359 
360 virtual int
361 getLastRotableDL(const int win)=0;
362 
363 virtual int
364 getLastDL(const int win)=0;
365 
366 virtual GUITypes::real
367 getLineWidthScaleFactor(int window = -1 )=0;
368 
369 virtual int
370 getMaxNOfDL(const int win)=0;
371 
372 int
373 getMatch(const aString *menu, aString & answer);
374 
375 virtual int
376 getNewLabelList(int win = -1 )=0;
377 
378 int
380 
381 // return a file pointer to the current command file we are reading
382 FILE*
383 getReadCommandFile() const;
384 
385 // return a file pointer to the current command file we are saving
386 FILE*
387 getSaveCommandFile() const;
388 
389 int
390 getValues(const aString & prompt,
391  IntegerArray & values,
392  const int minimunValue= INT_MIN,
393  const int maximumValue= INT_MAX,
394  const int sort = 0 );
395 
396 int
397 getValues(const aString & prompt,
398  RealArray & values,
399  const GUITypes::real minimunValue= -REAL_MAX,
400  const GUITypes::real maximumValue= REAL_MAX,
401  const int sort = 0 );
402 
403 virtual void
404 getView(ViewLocation & loc, int win_number = -1)=0;
405 
406 virtual aString
407 getXAxisLabel()=0;
408 
409 virtual aString
410 getYAxisLabel()=0;
411 
412 virtual aString
413 getZAxisLabel()=0;
414 
415 virtual bool
416 getPlotTheRotationPoint(int win_number = -1)=0;
417 
418 virtual bool
419 getPlotTheBackgroundGrid(int win_number = -1)=0;
420 
421 // return true if graphics plotting turned on (Note: this routine is non-virtual).
422 bool
423 graphicsIsOn();
424 
425 // Save the graphics window in hard-copy form
426 virtual int
427 hardCopy(const aString & fileName=nullString,
429  int win_number=-1)=0;
430 
431 int
432 indexInCascadingMenu( int & index,
433  const int startCascade,
434  const int endCascade ) const;
435 
436 virtual void
437 initView(int win_number=-1)=0;
438 
439 // input a filename
440 virtual void
441 inputFileName(aString &answer, const aString & prompt=nullString, const aString & extension=nullString)=0;
442 
443 
444 
445 // Input a string after displaying an optional prompt
446 virtual void
447 inputString(aString &answer, const aString & prompt=nullString);
448 
449 // return true if the graphics windows are open (on this processor)
450 bool
452 
453 // return true if the graphics windows are open
454 bool
456 
457 virtual void
458 label(const aString & string,
459  GUITypes::real xPosition,
460  GUITypes::real yPosition,
461  GUITypes::real size=.1,
462  int centering=0,
463  GUITypes::real angle=0.,
465  const aString & colour = nullString,
466  GUITypes::real zOffset =.99 )=0;
467 
468 // convert normalized coordinates [-1,+1] to world (globalBound) coordinates
469 virtual int
470 normalizedToWorldCoordinates(const RealArray & r, RealArray & x ) const=0;
471 
472 // Output a string
473 virtual void
474 outputString(const aString & message, int messageLevel =2 );
475 
476 // output a line to the command file if there is one open.
477 void
478 outputToCommandFile( const aString & line );
479 
480 virtual int
481 pause()=0;
482 
483 virtual int
484 pickPoints( RealArray & x,
485  bool plotPoints = TRUE,
486  int win_number = -1 )=0;
487 
488 // plot and erase title labels
489 virtual void
490 plotLabels(GraphicsParameters & parameters,
491  const GUITypes::real & labelSize=-1., // <0 means use default in parameters
492  const GUITypes::real & topLabelHeight=.925,
493  const GUITypes::real & bottomLabelHeight=-.925,
494  int win_number = -1)=0;
495 
496 // plot points
497 virtual void
498 plotPoints(const realArray & points,
500  int dList = 0)=0;
501 
502 #ifdef USE_PPP
503 // Version to use in parallel that takes serial arrays as input and forms the aggregate
504 virtual void
505 plotPoints(const RealArray & points,
507  int dList = 0)=0;
508 #endif
509 
510 // plot points with different colour
511 virtual void
512 plotPoints(const realArray & points,
513  const realArray & value,
515  int dList = 0 )=0;
516 
517 #ifdef USE_PPP
518 // Version to use in parallel that takes serial arrays as input and forms the aggregate
519 virtual void
520 plotPoints(const RealArray & points,
521  const RealArray & value,
523  int dList = 0)=0;
524 #endif
525 
526 virtual void
527 plotLines(const realArray & arrows,
529  int dList = 0 )=0;
530 
531 
532 // pop a default prompt off the stack and make the next prompt the new default
533 int
535 
536 virtual void
537 pollEvents()=0;
538 
539 virtual void
540 pushGUI( GUIState &newState )=0;
541 
542 virtual void
543 popGUI()=0;
544 
545 virtual int
546 psToRaster(const aString & fileName,
547  const aString & ppmFileName)=0;
548 
549 // push a default prompt onto a stack and make the current prompt
550 int
551 pushDefaultPrompt(const aString & prompt );
552 
553 
554 // Start reading a command file (if no file name is given, prompt for one)
555 FILE*
556 readCommandFile(const aString & commandFileName=nullString);
557 
558 // Start reading commands from an array of Strings, commands terminated by the aString=""
559 int
560 readCommandsFromStrings(const aString *commands);
561 
562 // return true of we are reading from a command file.
563 bool
564 readingFromCommandFile() const;
565 
566 // Redraw all graphics display lists
567 virtual void
568 redraw( bool immediate=FALSE)=0;
569 
570 virtual void
571 resetGlobalBound(const int win_number)=0;
572 
573 virtual void
574 resetView(int win_number=-1)=0;
575 
576 // Start saving a command file (if no file name is given, prompt for one)
577 FILE*
578 saveCommandFile(const aString & commandFileName=nullString);
579 
580 int
581 savePickCommands(bool trueOrFalse=TRUE );
582 
583 virtual void
584 setCurrentWindow(const int & w)=0;
585 
586 // set the deafult prompt and clear the stack of deafult prompts
587 int
588 setDefaultPrompt(const aString & prompt);
589 
590 // Start saving an echo file (if no file name is given, prompt for one)
591 FILE*
592 saveEchoFile(const aString & fileName=nullString);
593 
594 virtual int
595 setAxesLabels( const aString & xAxisLabel=blankString,
596  const aString & yAxisLabel=blankString,
597  const aString & zAxisLabel=blankString )=0;
598 
599 virtual int
601 
602 // set the colour for subsequent objects that are plotted
603 virtual int
604 setColour( const aString & colourName )=0;
605 
606 // set colour to default for a given type of item
607 virtual int
608 setColour( ItemColourEnum item )=0;
609 
610 virtual void
612 
613 // assign a name for colour i
614 virtual void
615 setColourName( int i, aString newColourName ) const=0;
616 
617 // Functions for setting the bounding box and the rotation center
618 virtual void
619 setGlobalBound(const RealArray &xBound)=0;
620 
621 virtual int
622 setKeepAspectRatio( bool trueOrFalse=true )=0;
623 
624 void
625 setInfoLevel(int value);
626 
627 // Set scale factor for line widths (this can be used to increase the line widths for
628 // high-res off screen rendering.
629 virtual void
630 setLineWidthScaleFactor(const GUITypes::real & lineWidthScaleFactor = 1, int win_number = -1 )=0;
631 
632 // if true, ignore the "pause" statement
633 void
634 setIgnorePause( bool trueOrFalse=true );
635 
636 virtual void
637 setInteractiveDL(int list, bool interactive)=0;
638 
639 virtual void
640 setLighting(int list, bool lit)=0;
641 
642 // toggle whether a display list should be plotted or not
643 virtual void
644 setPlotDL(int list, bool lit)=0;
645 
646 // Access functions for plotTheAxes.
647 virtual void
648 setPlotTheAxes(bool newState, int win_number=-1)=0;
649 
650 void
652 
653 virtual void
654 setXAxisLabel(const aString & xAxisLabel_=blankString)=0;
655 
656 virtual void
657 setYAxisLabel(const aString & yAxisLabel_=blankString)=0;
658 
659 virtual void
660 setZAxisLabel(const aString & zAxisLabel_=blankString)=0;
661 
662 virtual void
663 setAxesDimension(int dim, int win_number=-1)=0;
664 
665 // Access functions for plotTheLabels
666 virtual void
667 setPlotTheLabels(bool newState, int win_number = -1)=0;
668 
669 virtual void
670 setPlotTheRotationPoint(bool newState, int win_number = -1)=0;
671 
672 virtual void
673 setPlotTheColourBar(bool newState, int win_number = -1)=0;
674 
675 virtual void
676 setPlotTheColouredSquares(bool newState, int win_number = -1)=0;
677 
678 virtual void
679 setPlotTheBackgroundGrid(bool newState, int win_number = -1)=0;
680 
681 virtual void
682 setUserButtonSensitive( int btn, int trueOrFalse )=0;
683 
684 virtual void
685 setView(ViewLocation & loc, int win_number = -1)=0;
686 
687 virtual void
688 setView(const ViewParameters & viewParameter, const GUITypes::real & value)=0;
689 
690 // Stop reading the command file (and close the file)
691 virtual void
693 
694 // Stop saving the command file (and close the file)
695 void
697 
698 // Stop saving the echo file (and close the file)
699 void
701 
702 // turn on graphics (grid, contour, streamline... plots)
703 void
705 
706 // turn off graphics (grid, contour, streamline... plots)
707 void
709 
710 // remove the last thing appended to the default prompt (just pop's the stack)
711 int
713 
714 // update the colour bar.
715 virtual void
716 updateColourBar(GraphicsParameters & parameters, int window=0)=0;
717 
718 // convert world to normalized coordinates [-1,+1]
719 virtual int
720 worldToNormalizedCoordinates(const RealArray & x, RealArray & r ) const=0;
721 
722 // Plot a label in 2D world coordinates
723 // This label DOES rotate and scale with the plot
724 virtual void
725 xLabel(const aString & string,
726  const GUITypes::real xPosition,
727  const GUITypes::real yPosition,
728  const GUITypes::real size=.1,
729  const int centering=0, // -1=left justify, 0=center, 1=right justify
730  const GUITypes::real angle=0.,
732  int win_number = -1)=0;
733 
734 // Plot a label in 3D world coordinates
735 // This label DOES rotate and scale with the plot
736 virtual void
737 xLabel(const aString & string,
738  const RealArray & x, // supply 3 position coordinates
739  const GUITypes::real size=.1,
740  const int centering=0,
741  const GUITypes::real angle=0.,
743  int win_number = -1)=0;
744 
745 virtual void
746 xLabel(const aString & string,
747  const GUITypes::real x[3],
748  const GUITypes::real size =.1,
749  const int centering = 0,
750  const GUITypes::real angle = 0.,
752  int win_number = -1 )=0;
753 
754 // Plot a label with position and size in World coordinates,
755 // This label DOES rotate and scale with the plot. This version of xLabel
756 // plots the string in the plane formed by the vectors {\ff rightVector}
757 // and {\ff upVector}.
758 virtual void
759 xLabel(const aString & string,
760  const RealArray & x, // supply 3 position coordinates
761  const GUITypes::real size, // size in world coordinates
762  const int centering,
763  const RealArray & rightVector, // string lies parallel to this vector
764  const RealArray & upVector, // in the plane of these two vectors
766  int win_number = -1)=0;
767 
768 virtual void
769 xLabel(const aString & string,
770  const GUITypes::real x[3],
771  const GUITypes::real size,
772  const int centering,
773  const GUITypes::real rightVector[3],
774  const GUITypes::real upVector[3],
776  int win_number = -1)=0;
777 
778 
779 
780 protected:
781 // These must be the same as in GraphicsParameters, put here for convenience
782 enum Sizes
783 {
801  numberOfSizes // counts number of entries in this list
802 };
803 
805 FILE *readFile, *saveFile, *echoFile; // command files
806 std::stack<FILE*> readFileStack;
807 std::queue<aString> stringCommands; // this is a FIFO queue, first in, first out
808 
809 bool getInteractiveResponse; // if true, do not get next command from a command file
810 
812 bool savePick; // if false, do not save pick related stuff in the command file.
813 
814 OvertureParser *parser; // for parsing commands (with perl for e.g.)
815 bool useParser; // if true, parse commands
816 
817 bool singleProcessorGraphicsMode; // true if we are only plotting on one processor
818 int processorForGraphics; // use this processor for plotting graphics on
819 bool graphicsPlottingIsOn; // set to false to skip graphics (for batch runs for e.g.)
820 
821 GUIState *currentGUI; // the GUIState needs to be here so it is available from fileAnswer
822 
824 aString *defaultPromptStack; // stack of default prompts
826 int saveFileCount; // counts lines written to log file -- for flushing the file
827 bool graphicsWindowIsOpen; // true if the graphics window is open on this processor.
828 bool interactiveGraphicsIsOn; // true if the graphics window is open
829 bool ignorePause; // if true, ignore the "pause" statement
830 
831 bool preferDirectRendering; // if true, prefer direct rendering of OpenGL to the graphics card
833 
836 
837 int simplifyPlotWhenRotating; // if true then draw a wire frame when rotating (if implemented)
838 
839 public:
840 // make this public for now
841 int gridCoarseningFactor; // coarsen contour/grid plots by this factor (usually for very fine grids) (if implemented)
842 // kkc moved this into the public interface so we can add perl commands in the main program to execute before the graphics interface goes to work
843 int
844 parseAnswer(aString & answer );
845 
846 
847 protected:
848 
851 
852 void
853 constructor(int & argc, char *argv[]);
854 
855 int
857 
858 virtual int
860 
861 int
862 fileAnswer(aString & answer,
863  const aString & prompt,
864  SelectionInfo * selection_);
865 
866 int
868  const aString & prompt,
869  SelectionInfo * selection_);
870 
871 int
872 promptAnswer(aString & answer,
873  const aString & prompt = nullString);
874 
875 };
876 
877 
878 
879 #endif