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   Standard_EXPORT SelectMgr_FrustumBuilder();
34 
35   //! Returns current camera
Handle(Graphic3d_Camera)36   const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
37 
38   //! Stores current camera
39   Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera)& theCamera);
40 
41   //! Stores current window width and height
42   Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth,
43                                       const Standard_Integer theHeight);
44 
45   //! Stores current viewport coordinates
46   Standard_EXPORT void SetViewport (const Standard_Real theX,
47                                     const Standard_Real theY,
48                                     const Standard_Real theWidth,
49                                     const Standard_Real theHeight);
50 
51   Standard_EXPORT void InvalidateViewport();
52 
53   Standard_EXPORT void WindowSize (Standard_Integer& theWidth,
54                                    Standard_Integer& theHeight) const;
55 
56   //! Calculates signed distance between plane with equation
57   //! theEq and point thePnt
58   Standard_EXPORT Standard_Real SignedPlanePntDist (const SelectMgr_Vec3& theEq,
59                                                     const SelectMgr_Vec3& thePnt) const;
60 
61   //! Projects 2d screen point onto view frustum plane:
62   //! theZ = 0 - near plane,
63   //! theZ = 1 - far plane
64   Standard_EXPORT gp_Pnt ProjectPntOnViewPlane (const Standard_Real& theX,
65                                                 const Standard_Real& theY,
66                                                 const Standard_Real& theZ) const;
67 
68   DEFINE_STANDARD_RTTIEXT(SelectMgr_FrustumBuilder,Standard_Transient)
69 
70 private:
71 
72   Handle(Graphic3d_Camera)          myCamera;
73   Standard_Integer                  myWidth;
74   Standard_Integer                  myHeight;
75   NCollection_Vec4<Standard_Real>   myViewport;
76   Standard_Boolean                  myIsViewportSet;
77 };
78 
79 DEFINE_STANDARD_HANDLE(SelectMgr_FrustumBuilder, Standard_Transient)
80 
81 #endif // _SelectMgr_FrustumBuilder_HeaderFile
82