GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_viewport.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #ifndef GLC_VIEWPORT_H_
26 #define GLC_VIEWPORT_H_
27 #include <QGLWidget>
28 #include <QPair>
29 #include <QHash>
30 #include <QObject>
31 
32 #include "glc_camera.h"
33 #include "glc_imageplane.h"
34 #include "../glc_boundingbox.h"
35 #include "glc_frustum.h"
36 #include "../maths/glc_plane.h"
37 #include "../sceneGraph/glc_3dviewcollection.h"
38 
39 #include "../glc_config.h"
40 
41 class GLC_3DViewInstance;
42 
45 
54 
55 class GLC_LIB_EXPORT GLC_Viewport : public QObject
56 {
57  Q_OBJECT
58 
60 
62 
63 public:
65 
72  GLC_Viewport();
73 
75  virtual ~GLC_Viewport();
76 
78 
80 
82 
83 public:
85  inline GLC_Camera* cameraHandle() const
86  {return m_pViewCam;}
87 
89  QSize size() const;
90 
92  inline int viewHSize() const
93  { return m_Width;}
94 
96  inline int viewVSize() const
97  { return m_Height;}
98 
100  inline double aspectRatio() const
101  { return static_cast<double>(m_Width) / static_cast<double>(m_Height);}
102 
104  GLC_Point2d normalyseMousePosition(int x, int y);
105 
107  GLC_Point2d mapToOpenGLScreen(int x, int y);
108 
110  GLC_Point2d mapNormalyzeToOpenGLScreen(double x, double y);
111 
113  GLC_Vector3d mapPosMouse( GLdouble Posx, GLdouble Posy) const;
114 
116  GLC_Vector3d mapNormalyzePosMouse(double Posx, double Posy) const;
117 
119  inline double viewAngle() const
120  { return m_ViewAngle;}
121 
123  inline double viewTangent() const
124  { return m_ViewTangent;}
125 
126 
128  inline double nearClippingPlaneDist(void) const
129  { return m_dDistanceMini;}
130 
132  inline double farClippingPlaneDist(void) const
133  { return m_DistanceMax;}
134 
136  inline QColor backgroundColor(void) const
137  { return m_BackgroundColor;}
138 
140  inline GLsizei selectionSquareSize() const
141  {return m_SelectionSquareSize;}
142 
144  inline GLC_Matrix4x4 projectionMatrix() const
145  {return m_ProjectionMatrix;}
146 
148  inline GLC_Matrix4x4 compositionMatrix() const;
149 
151  inline GLC_3DViewCollection* widget3dCollectionHandle()
152  {return &m_3DWidgetCollection;}
153 
155  inline bool useOrtho()const
156  {return m_UseParallelProjection;}
157 
159  inline int minimumPixelCullingSize() const
160  {return m_MinimumStaticPixelSize;}
161 
163  inline double minimumStaticPixelCullingRatio() const
164  {return m_MinimumStaticRatioSize;}
165 
167  inline double minimumDynamicPixelCullingRatio() const
168  {return m_MinimumDynamicRatioSize;}
169 
171 
173 
175 
176 public:
178 
179  void initGl();
180 
182  void glExecuteCam(void);
183 
185  void updateProjectionMat(void);
186 
188  void forceAspectRatio(double);
189 
191  void updateAspectRatio();
192 
194  const GLC_Frustum& frustum() const
195  {return m_Frustum;}
196 
198  GLC_Frustum selectionFrustum(int, int) const;
199 
201  GLC_Point3d unProject(int, int, GLenum buffer= GL_FRONT) const;
202 
204 
205  QList<GLC_Point3d> unproject(const QList<int>& list, GLenum buffer= GL_FRONT)const;
206 
208 
210 
212 
213 private:
214 
216  void renderImagePlane();
217 
218 public:
219 
221  void render3DWidget();
222 
224 
226 
228 
229 public:
230 
232  void setWinGLSize(int width, int height, bool updateOGLViewport= true);
233 
235  void setWinGLSize(const QSize& size, bool updateOGLViewport= true);
236 
238 
239  GLC_uint renderAndSelect(int x, int y, GLenum buffer= GL_BACK);
240 
242  GLC_uint selectOnPreviousRender(int x, int y, GLenum buffer= GL_BACK);
243 
245 
246  GLC_uint selectBody(GLC_3DViewInstance*, int x, int y, GLenum buffer= GL_BACK);
247 
249 
250  QPair<int, GLC_uint> selectPrimitive(GLC_3DViewInstance*, int x, int y, GLenum buffer= GL_BACK);
251 
253  QSet<GLC_uint> selectInsideSquare(int x1, int y1, int x2, int y2, GLenum buffer= GL_BACK);
254 
256  void loadBackGroundImage(const QString& imageFile);
257 
259  void loadBackGroundImage(const QImage& image);
260 
262  void deleteBackGroundImage();
263 
265  inline void setViewAngle(double TargetFov)
266  {
267  m_ViewAngle= TargetFov;
268  m_ViewTangent= tan(glc::toRadian(m_ViewAngle));
269  updateProjectionMat();
270  }
271 
273  bool setDistMin(double DistMin);
274 
276  bool setDistMax(double DistMax);
277 
279 
280  void setDistMinAndMax(const GLC_BoundingBox& bBox);
281 
283  void setBackgroundColor(QColor setColor);
284 
286  inline void setSelectionSquareSize(GLsizei size)
287  {m_SelectionSquareSize= size;}
288 
290 
291  inline bool updateFrustum(GLC_Matrix4x4* pMat= NULL);
292 
294  void addClipPlane(GLenum planeGlEnum, GLC_Plane* pPlane);
295 
297  void removeClipPlane(GLenum planeGlEnum);
298 
300  void removeAllClipPlane();
301 
303  void useClipPlane(bool flag);
304 
306  inline void add3DWidget(GLC_3DViewInstance& widget)
307  {m_3DWidgetCollection.add(widget);}
308 
310  void clearBackground(const QColor& color) const;
311 
313  void setToOrtho(bool useOrtho);
314 
316  inline void setMinimumPixelCullingSize(int size)
317  {
318  m_MinimumStaticPixelSize= size;
319  updateMinimumRatioSize();
320  }
322 
323 
326 //{@
328 
329  void reframe(const GLC_BoundingBox& box, double coverFactor = 2.2);
330 
332 
333 
336 //{@
337 signals:
339  void updateOpenGL();
340 
342 
343 
344 
346 // private services functions
348 private:
350  GLC_uint meaningfulIdInsideSquare(GLint x, GLint y, GLsizei width, GLsizei height, GLenum buffer);
351 
353  QSet<GLC_uint> listOfIdInsideSquare(GLint x, GLint y, GLsizei width, GLsizei height, GLenum buffer);
354 
356  void updateMinimumRatioSize();
357 
358 
360 // Private Members
362 private:
363 
366 
367  double m_DistanceMax;
369  double m_ViewAngle;
370  double m_ViewTangent;
371 
372 
375 
376  // OpenGL View Definition
377  int m_Width;
378  int m_Height;
379 
382 
385 
388 
391 
394 
396  QHash<GLenum, GLC_Plane*> m_ClipPlanesHash;
397 
400 
403 
406 
409 
412 
415 };
416 
418 {
419  // Get the viewport projection matrix
421  // Get the camera modelView matrix
422  GLC_Matrix4x4 modelViewMatrix= m_pViewCam->modelViewMatrix();
423  // Composition matrix
424  GLC_Matrix4x4 compMatrix= projectionMatrix * modelViewMatrix;
425 
426  return compMatrix;
427 }
428 
430 {
431  if (NULL == pMat)
432  {
434  }
435  else
436  {
437  return m_Frustum.update(*pMat);
438  }
439 }
440 #endif //GLC_VIEWPORT_H_

©2005-2013 Laurent Ribon