glc_viewport.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #ifndef GLC_VIEWPORT_H_
00026 #define GLC_VIEWPORT_H_
00027 #include <QGLWidget>
00028 #include <QPair>
00029 #include <QHash>
00030 #include "glc_camera.h"
00031 #include "glc_imageplane.h"
00032 #include "../glc_boundingbox.h"
00033 #include "glc_frustum.h"
00034 #include "../maths/glc_plane.h"
00035 #include "../sceneGraph/glc_3dviewcollection.h"
00036
00037 #include "../glc_config.h"
00038
00039 class GLC_3DViewInstance;
00040
00043
00052
00053 class GLC_LIB_EXPORT GLC_Viewport
00054 {
00055
00057
00059
00060 public:
00062
00069 GLC_Viewport(QGLWidget *GLWidget);
00070
00072 virtual ~GLC_Viewport();
00073
00075
00077
00079
00080 public:
00082 inline GLC_Camera* cameraHandle() const
00083 {return m_pViewCam;}
00084
00086 inline int viewHSize() const
00087 { return m_WindowHSize;}
00088
00090 inline int viewVSize() const
00091 { return m_WindowVSize;}
00092
00094 inline double aspectRatio() const
00095 { return static_cast<double>(m_WindowHSize) / static_cast<double>(m_WindowVSize);}
00096
00098 GLC_Point2d normalyseMousePosition(int x, int y);
00099
00101 GLC_Point2d mapToOpenGLScreen(int x, int y);
00102
00104 GLC_Point2d mapNormalyzeToOpenGLScreen(double x, double y);
00105
00107 GLC_Vector3d mapPosMouse( GLdouble Posx, GLdouble Posy) const;
00108
00110 GLC_Vector3d mapNormalyzePosMouse(double Posx, double Posy) const;
00111
00113 inline double viewAngle() const
00114 { return m_ViewAngle;}
00115
00117 inline double viewTangent() const
00118 { return m_ViewTangent;}
00119
00120
00122 inline double nearClippingPlaneDist(void) const
00123 { return m_dDistanceMini;}
00124
00126 inline double farClippingPlaneDist(void) const
00127 { return m_DistanceMax;}
00128
00130 inline QColor backgroundColor(void) const
00131 { return m_BackgroundColor;}
00132
00134 inline GLsizei selectionSquareSize() const
00135 {return m_SelectionSquareSize;}
00136
00138 inline GLC_Matrix4x4 projectionMatrix() const
00139 {return m_ProjectionMatrix;}
00140
00142 inline GLC_Matrix4x4 compositionMatrix() const;
00143
00145 inline GLC_3DViewCollection* widget3dCollectionHandle()
00146 {return &m_3DWidgetCollection;}
00147
00149 inline bool useOrtho()const
00150 {return m_UseParallelProjection;}
00151
00153 inline int minimumPixelCullingSize() const
00154 {return m_MinimumStaticPixelSize;}
00155
00157 inline double minimumStaticPixelCullingRatio() const
00158 {return m_MinimumStaticRatioSize;}
00159
00161 inline double minimumDynamicPixelCullingRatio() const
00162 {return m_MinimumDynamicRatioSize;}
00163
00165
00167
00169
00170 public:
00172
00173 void initGl();
00174
00176 void glExecuteCam(void);
00177
00179 void updateProjectionMat(void);
00180
00182 void forceAspectRatio(double);
00183
00185 void updateAspectRatio();
00186
00188 const GLC_Frustum& frustum() const
00189 {return m_Frustum;}
00190
00192 GLC_Frustum selectionFrustum(int, int) const;
00193
00195 GLC_Point3d unProject(int, int) const;
00196
00198
00199 QList<GLC_Point3d> unproject(const QList<int>&)const;
00200
00202 inline QGLWidget* qGLWidgetHandle()
00203 {return m_pQGLWidget;}
00204
00206
00208
00210
00211 private:
00212
00214 void renderImagePlane();
00215
00216 public:
00217
00219 void render3DWidget();
00220
00222
00224
00226
00227 public:
00228
00230 void setWinGLSize(int HSize, int VSize);
00231
00233
00234 GLC_uint renderAndSelect(int x, int y);
00235
00237 GLC_uint selectOnPreviousRender(int x, int y);
00238
00240
00241 GLC_uint selectBody(GLC_3DViewInstance*, int x, int y);
00242
00244
00245 QPair<int, GLC_uint> selectPrimitive(GLC_3DViewInstance*, int x, int y);
00246
00248 QSet<GLC_uint> selectInsideSquare(int x1, int y1, int x2, int y2);
00249
00251 void loadBackGroundImage(const QString& imageFile);
00252
00254 void loadBackGroundImage(const QImage& image);
00255
00257 void deleteBackGroundImage();
00258
00260 inline void setViewAngle(double TargetFov)
00261 {
00262 m_ViewAngle= TargetFov;
00263 m_ViewTangent= tan(glc::toRadian(m_ViewAngle));
00264 updateProjectionMat();
00265 }
00266
00268 bool setDistMin(double DistMin);
00269
00271 bool setDistMax(double DistMax);
00272
00274
00275 void setDistMinAndMax(const GLC_BoundingBox& bBox);
00276
00278 void setBackgroundColor(QColor setColor);
00279
00281 inline void setSelectionSquareSize(GLsizei size)
00282 {m_SelectionSquareSize= size;}
00283
00285
00286 inline bool updateFrustum(GLC_Matrix4x4* pMat= NULL);
00287
00289 void addClipPlane(GLenum planeGlEnum, GLC_Plane* pPlane);
00290
00292 void removeClipPlane(GLenum planeGlEnum);
00293
00295 void removeAllClipPlane();
00296
00298 void useClipPlane(bool flag);
00299
00301 inline void add3DWidget(GLC_3DViewInstance& widget)
00302 {m_3DWidgetCollection.add(widget);}
00303
00305 inline void clearBackground(const QColor& c) const
00306 {m_pQGLWidget->qglClearColor(c);}
00307
00309 void setToOrtho(bool useOrtho);
00310
00312 inline void setMinimumPixelCullingSize(int size)
00313 {
00314 m_MinimumStaticPixelSize= size;
00315 updateMinimumRatioSize();
00316 }
00318
00319
00322
00324
00325 void reframe(const GLC_BoundingBox& box);
00326
00328
00329
00331
00333 private:
00335 GLC_uint meaningfulIdInsideSquare(GLint x, GLint y, GLsizei width, GLsizei height);
00336
00338 QSet<GLC_uint> listOfIdInsideSquare(GLint x, GLint y, GLsizei width, GLsizei height);
00339
00341 void updateMinimumRatioSize();
00342
00343
00345
00347 private:
00348
00350 GLC_Camera *m_pViewCam;
00351
00352 double m_DistanceMax;
00353 double m_dDistanceMini;
00354 double m_ViewAngle;
00355 double m_ViewTangent;
00356
00357
00359 GLC_ImagePlane* m_pImagePlane;
00360
00361
00362 int m_WindowHSize;
00363 int m_WindowVSize;
00364
00366 double m_AspectRatio;
00367
00369 QGLWidget* m_pQGLWidget;
00370
00372 QColor m_BackgroundColor;
00373
00375 GLsizei m_SelectionSquareSize;
00376
00378 GLC_Matrix4x4 m_ProjectionMatrix;
00379
00381 GLC_Frustum m_Frustum;
00382
00384 QHash<GLenum, GLC_Plane*> m_ClipPlanesHash;
00385
00387 bool m_UseClipPlane;
00388
00390 GLC_3DViewCollection m_3DWidgetCollection;
00391
00393 bool m_UseParallelProjection;
00394
00396 int m_MinimumStaticPixelSize;
00397
00399 double m_MinimumStaticRatioSize;
00400
00402 double m_MinimumDynamicRatioSize;
00403 };
00404
00405 GLC_Matrix4x4 GLC_Viewport::compositionMatrix() const
00406 {
00407
00408 GLC_Matrix4x4 projectionMatrix= m_ProjectionMatrix;
00409
00410 GLC_Matrix4x4 modelViewMatrix= m_pViewCam->modelViewMatrix();
00411
00412 GLC_Matrix4x4 compMatrix= projectionMatrix * modelViewMatrix;
00413
00414 return compMatrix;
00415 }
00416
00417 bool GLC_Viewport::updateFrustum(GLC_Matrix4x4* pMat)
00418 {
00419 if (NULL == pMat)
00420 {
00421 return m_Frustum.update(compositionMatrix());
00422 }
00423 else
00424 {
00425 return m_Frustum.update(*pMat);
00426 }
00427 }
00428 #endif //GLC_VIEWPORT_H_