0028417: Using PRECOMPILED HEADER to speed up compilation time
[occt.git] / src / SelectMgr / SelectMgr_FrustumBuilder.hxx
1 // Created on: 2014-11-24
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _SelectMgr_FrustumBuilder_HeaderFile
17 #define _SelectMgr_FrustumBuilder_HeaderFile
18
19 #include <Standard_Type.hxx>
20
21 #include <Graphic3d_Camera.hxx>
22 #include <Graphic3d_WorldViewProjState.hxx>
23 #include <Precision.hxx>
24 #include <SelectMgr_VectorTypes.hxx>
25
26 //! The purpose of this class is to provide unified interface for building
27 //! selecting frustum depending on current camera projection and orientation
28 //! matrices, window size and viewport parameters.
29 class SelectMgr_FrustumBuilder : public Standard_Transient
30 {
31 public:
32   //! Creates new frustum builder with empty matrices
33   SelectMgr_FrustumBuilder();
34
35   //! Stores current world view transformation matrix
36   Standard_EXPORT void SetWorldViewMatrix (const Graphic3d_Mat4d& theWorldViewMatrix);
37
38   //! @return current world view transformation matrix
39   Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const;
40
41   //! Stores current projection matrix
42   Standard_EXPORT void SetProjectionMatrix (const Graphic3d_Mat4d& theProjection);
43
44   //! @return current projection matrix
45   Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
46
47   //! Stores current world view projection matrix state for the orientation and projection matrices
48   Standard_EXPORT void SetWorldViewProjState (const Graphic3d_WorldViewProjState& theState);
49
50   //! @return current world view projection state
51   Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;
52
53   //! Stores current window width and height
54   Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth,
55                                       const Standard_Integer theHeight);
56
57   //! Stores current viewport coordinates
58   Standard_EXPORT void SetViewport (const Standard_Real theX,
59                                     const Standard_Real theY,
60                                     const Standard_Real theWidth,
61                                     const Standard_Real theHeight);
62
63   Standard_EXPORT void InvalidateViewport();
64
65   Standard_EXPORT void WindowSize (Standard_Integer& theWidth,
66                                    Standard_Integer& theHeight) const;
67
68   //! Calculates signed distance between plane with equation
69   //! theEq and point thePnt
70   Standard_EXPORT Standard_Real SignedPlanePntDist (const SelectMgr_Vec3& theEq,
71                                                     const SelectMgr_Vec3& thePnt) const;
72
73   //! Projects 2d screen point onto view frustum plane:
74   //! theZ = 0 - near plane,
75   //! theZ = 1 - far plane
76   Standard_EXPORT gp_Pnt ProjectPntOnViewPlane (const Standard_Real& theX,
77                                                 const Standard_Real& theY,
78                                                 const Standard_Real& theZ) const;
79
80   DEFINE_STANDARD_RTTIEXT(SelectMgr_FrustumBuilder,Standard_Transient)
81
82 private:
83
84   //! Unprojects point from NDC coords to 3d world space
85   gp_Pnt unProject (const gp_Pnt& thePnt) const;
86
87 private:
88
89   Graphic3d_Mat4d                   myWorldView;
90   Graphic3d_Mat4d                   myProjection;
91   Graphic3d_WorldViewProjState      myWorldViewProjState;
92   Standard_Integer                  myWidth;
93   Standard_Integer                  myHeight;
94   NCollection_Vec4<Standard_Real>   myViewport;
95   Standard_Boolean                  myIsViewportSet;
96 };
97
98 DEFINE_STANDARD_HANDLE(SelectMgr_FrustumBuilder, Standard_Transient)
99
100 #endif // _SelectMgr_FrustumBuilder_HeaderFile