Orfeo Toolbox  3.16
otbGlWidget.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #include "otbGlWidget.h"
19 
20 namespace otb
21 {
22 
24 ::GlWidget() : Fl_Gl_Window(0, 0, 0, 0), m_Identifier(), m_UseGlAcceleration(false),
25  m_BackgroundColor()
26 {
27  m_Identifier = "Default";
28 
29 #if 0
30  // OTB_GL_USE_ACCEL
31  m_UseGlAcceleration = true;
32 #endif
33 
34  // Default background color
35  m_BackgroundColor.Fill(0);
36 }
37 
39 {
40  // Clear registered controller
42 }
43 
44 void GlWidget::PrintSelf(std::ostream& os, itk::Indent indent) const
45 {
46  // Call the superclass implementation
47  Superclass::PrintSelf(os, indent);
48  // Display information about the widget
49  os << indent << "Widget " << m_Identifier << ": " << std::endl;
50 
51 #if 0
52  #ifndef OTB_GL_USE_ACCEL
53  os << indent << indent << "OpenGl acceleration is not allowed." << std::endl;
54  #else
56  {
57  os << indent << indent << "OpenGl acceleration is allowed and enabled." << std::endl;
58  }
59  else
60  {
61  os << indent << indent << "OpenGl acceleration is allowed but disabled." << std::endl;
62  }
63  #endif
64 #endif
65 }
66 
68 {
69 #if 0
70  // Check if Gl acceleration mode is correct
71  #ifndef OTB_GL_USE_ACCEL
73  {
74  itkWarningMacro(
75  <<
76  "Gl acceleration enabled but not allowed. Consider rebuilding with OTB_USE_GL_ACCEL to ON. For now, disabling Gl acceleration.");
77  m_UseGlAcceleration = false;
78  }
79  #endif
80 #endif
81 
82  // Set up Gl environement
83  if (!this->valid())
84  {
85  valid(1);
86  glLoadIdentity();
87  glViewport(0, 0, w(), h());
89  glShadeModel(GL_FLAT);
90  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
91  }
92  glClear(GL_COLOR_BUFFER_BIT); //this clears and paints to black
93  glMatrixMode(GL_MODELVIEW); //clear previous 3D draw params
94  glLoadIdentity();
95  glMatrixMode(GL_PROJECTION);
96  this->ortho();
97  glDisable(GL_BLEND);
98 }
99 
100 void GlWidget::resize(int x, int y, int w, int h)
101 {
102  // Distinguish between resize, move and not changed events
103  // (The system window manager may generate multiple resizing events,
104  // so we'd rather avoid event flooding here)
105  bool reportMove = false;
106  bool reportResize = false;
107  if (this->x() != x || this->y() != y)
108  {
109  reportMove = true;
110  }
111 
112  if (this->w() != w || this->h() != h)
113  {
114  reportResize = true;
115  }
116 
117  // First call the superclass implementation
118  Fl_Gl_Window::resize(x, y, w, h);
119  // If There is a controller
120  if (m_Controller.IsNotNull())
121  {
122  if (reportMove)
123  {
124  m_Controller->HandleWidgetMove(m_Identifier, x, y);
125  }
126  if (reportResize)
127  {
128  m_Controller->HandleWidgetResize(m_Identifier, w, h);
129  }
130  }
131 }
132 
133 int GlWidget::handle(int event)
134 {
135  // Call superclass implementation
136  int resp = Fl_Widget::handle(event);
137 
138  // Check if there is a controller
139  // Avoid processing hide events, since it causes segfault (the
140  // destructor of the Fl class generates hide events).
141  if (m_Controller.IsNotNull() && event != FL_HIDE)
142  {
143  resp = m_Controller->HandleWidgetEvent(m_Identifier, event);
144  }
145  return resp;
146 }
147 
149 {
150  // Get the cursor position
151  PointType index;
152  index[0] = Fl::event_x();
153  index[1] = Fl::event_y();
154  // Flip the y axis
155  index[1] = this->h() - index[1];
156  return index;
157 }
158 }

Generated at Sun Feb 3 2013 00:25:08 for Orfeo Toolbox with doxygen 1.8.1.1