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
00023
00024
00026
00027 #ifndef GLC_VIEWPORT_H_
00028 #define GLC_VIEWPORT_H_
00029 #include <QGLWidget>
00030 #include <QPair>
00031 #include <QHash>
00032 #include "glc_camera.h"
00033 #include "glc_imageplane.h"
00034 #include "../glc_boundingbox.h"
00035 #include "glc_frustum.h"
00036 #include "../maths/glc_plane.h"
00037 #include "../sceneGraph/glc_3dviewcollection.h"
00038
00039 #include "../glc_config.h"
00040
00041 class GLC_3DViewInstance;
00042
00045
00054
00055 class GLC_LIB_EXPORT GLC_Viewport
00056 {
00057
00059
00061
00062 public:
00064
00071 GLC_Viewport(QGLWidget *GLWidget);
00072
00074 virtual ~GLC_Viewport();
00075
00077
00079
00081
00082 public:
00084 inline GLC_Camera* cameraHandle() const
00085 {return m_pViewCam;}
00086
00088 inline int viewHSize() const
00089 { return m_WindowHSize;}
00090
00092 inline int viewVSize() const
00093 { return m_WindowVSize;}
00094
00096 inline double aspectRatio() const
00097 { return static_cast<double>(m_WindowHSize) / static_cast<double>(m_WindowVSize);}
00098
00100 GLC_Vector3d mapPosMouse( GLdouble Posx, GLdouble Posy) const;
00101
00103 inline double viewAngle() const
00104 { return m_ViewAngle;}
00105
00107 inline double viewTangent() const
00108 { return m_ViewTangent;}
00109
00110
00112 inline double nearClippingPlaneDist(void) const
00113 { return m_dDistanceMini;}
00114
00116 inline double farClippingPlaneDist(void) const
00117 { return m_DistanceMax;}
00118
00120 inline QColor backgroundColor(void) const
00121 { return m_BackgroundColor;}
00122
00124 inline GLsizei selectionSquareSize() const
00125 {return m_SelectionSquareSize;}
00126
00128 inline GLC_Matrix4x4 projectionMatrix() const
00129 {return m_ProjectionMatrix;}
00130
00132 inline GLC_Matrix4x4 compositionMatrix() const;
00133
00135 inline GLC_3DViewCollection* widget3dCollectionHandle()
00136 {return &m_3DWidgetCollection;}
00137
00139 inline bool useOrtho()const
00140 {return m_UseParallelProjection;}
00141
00143 inline int minimumPixelCullingSize() const
00144 {return m_MinimumStaticPixelSize;}
00145
00147 inline double minimumStaticPixelCullingRatio() const
00148 {return m_MinimumStaticRatioSize;}
00149
00151 inline double minimumDynamicPixelCullingRatio() const
00152 {return m_MinimumDynamicRatioSize;}
00153
00155
00157
00159
00160 public:
00162
00163 void initGl();
00164
00166 void glExecuteCam(void);
00167
00169 void updateProjectionMat(void);
00170
00172 void forceAspectRatio(double);
00173
00175 void updateAspectRatio();
00176
00178 const GLC_Frustum& frustum() const
00179 {return m_Frustum;}
00180
00182 GLC_Frustum selectionFrustum(int, int) const;
00183
00185 GLC_Point3d unProject(int, int) const;
00186
00188
00189 QList<GLC_Point3d> unproject(const QList<int>&)const;
00190
00192 inline QGLWidget* qGLWidgetHandle()
00193 {return m_pQGLWidget;}
00194
00196
00198
00200
00201 private:
00202
00204 void renderImagePlane();
00205
00206 public:
00207
00209 void render3DWidget();
00210
00212
00214
00216
00217 public:
00218
00220 void setWinGLSize(int HSize, int VSize);
00221
00223
00224 GLC_uint renderAndSelect(int x, int y);
00225
00227 GLC_uint selectOnPreviousRender(int x, int y);
00228
00230
00231 GLC_uint selectBody(GLC_3DViewInstance*, int x, int y);
00232
00234
00235 QPair<int, GLC_uint> selectPrimitive(GLC_3DViewInstance*, int x, int y);
00236
00238 QSet<GLC_uint> selectInsideSquare(int x1, int y1, int x2, int y2);
00239
00241 void loadBackGroundImage(const QString& imageFile);
00242
00244 void loadBackGroundImage(const QImage& image);
00245
00247 void deleteBackGroundImage();
00248
00250 inline void setViewAngle(double TargetFov)
00251 {
00252 m_ViewAngle= TargetFov;
00253 m_ViewTangent= tan(glc::toRadian(m_ViewAngle));
00254 updateProjectionMat();
00255 }
00256
00258 bool setDistMin(double DistMin);
00259
00261 bool setDistMax(double DistMax);
00262
00264
00265 void setDistMinAndMax(const GLC_BoundingBox& bBox);
00266
00268 void setBackgroundColor(QColor setColor);
00269
00271 inline void setSelectionSquareSize(GLsizei size)
00272 {m_SelectionSquareSize= size;}
00273
00275
00276 inline bool updateFrustum(GLC_Matrix4x4* pMat= NULL);
00277
00279 void addClipPlane(GLenum planeGlEnum, GLC_Plane* pPlane);
00280
00282 void removeClipPlane(GLenum planeGlEnum);
00283
00285 void removeAllClipPlane();
00286
00288 void useClipPlane(bool flag);
00289
00291 inline void add3DWidget(GLC_3DViewInstance& widget)
00292 {m_3DWidgetCollection.add(widget);}
00293
00295 inline void clearBackground(const QColor& c) const
00296 {m_pQGLWidget->qglClearColor(c);}
00297
00299 void setToOrtho(bool useOrtho);
00300
00302 inline void setMinimumPixelCullingSize(int size)
00303 {
00304 m_MinimumStaticPixelSize= size;
00305 updateMinimumRatioSize();
00306 }
00308
00309
00312
00314
00315 void reframe(const GLC_BoundingBox& box);
00316
00318
00319
00321
00323 private:
00325 GLC_uint meaningfulIdInsideSquare(GLint x, GLint y, GLsizei width, GLsizei height);
00326
00328 QSet<GLC_uint> listOfIdInsideSquare(GLint x, GLint y, GLsizei width, GLsizei height);
00329
00331 void updateMinimumRatioSize();
00332
00333
00335
00337 private:
00338
00340 GLC_Camera *m_pViewCam;
00341
00342 double m_DistanceMax;
00343 double m_dDistanceMini;
00344 double m_ViewAngle;
00345 double m_ViewTangent;
00346
00347
00349 GLC_ImagePlane* m_pImagePlane;
00350
00351
00352 int m_WindowHSize;
00353 int m_WindowVSize;
00354
00356 double m_AspectRatio;
00357
00359 QGLWidget* m_pQGLWidget;
00360
00362 QColor m_BackgroundColor;
00363
00365 GLsizei m_SelectionSquareSize;
00366
00368 GLC_Matrix4x4 m_ProjectionMatrix;
00369
00371 GLC_Frustum m_Frustum;
00372
00374 QHash<GLenum, GLC_Plane*> m_ClipPlanesHash;
00375
00377 bool m_UseClipPlane;
00378
00380 GLC_3DViewCollection m_3DWidgetCollection;
00381
00383 bool m_UseParallelProjection;
00384
00386 int m_MinimumStaticPixelSize;
00387
00389 double m_MinimumStaticRatioSize;
00390
00392 double m_MinimumDynamicRatioSize;
00393 };
00394
00395 GLC_Matrix4x4 GLC_Viewport::compositionMatrix() const
00396 {
00397
00398 GLC_Matrix4x4 projectionMatrix= m_ProjectionMatrix;
00399
00400 GLC_Matrix4x4 modelViewMatrix= m_pViewCam->modelViewMatrix();
00401
00402 GLC_Matrix4x4 compMatrix= projectionMatrix * modelViewMatrix;
00403
00404 return compMatrix;
00405 }
00406
00407 bool GLC_Viewport::updateFrustum(GLC_Matrix4x4* pMat)
00408 {
00409 if (NULL == pMat)
00410 {
00411 return m_Frustum.update(compositionMatrix());
00412 }
00413 else
00414 {
00415 return m_Frustum.update(*pMat);
00416 }
00417 }
00418 #endif //GLC_VIEWPORT_H_