3bffef55 |
1 | // Copyright (c) 2016 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _Graphic3d_CameraTile_HeaderFile |
15 | #define _Graphic3d_CameraTile_HeaderFile |
16 | |
17 | #include <Graphic3d_Vec2.hxx> |
18 | #include <Standard_Integer.hxx> |
19 | #include <Standard_TypeDef.hxx> |
20 | |
21 | //! Class defines the area (Tile) inside a view. |
22 | class Graphic3d_CameraTile |
23 | { |
24 | public: |
25 | |
26 | Graphic3d_Vec2i TotalSize; //!< total size of the View area, in pixels |
27 | Graphic3d_Vec2i TileSize; //!< size of the Tile, in pixels |
28 | Graphic3d_Vec2i Offset; //!< the lower-left corner of the Tile relative to the View area (or upper-left if IsTopDown is true), in pixels |
29 | bool IsTopDown; //!< indicate the offset coordinate system - lower-left (default) or top-down |
30 | |
31 | public: |
32 | |
33 | //! Default constructor. |
34 | //! Initializes the empty Tile of zero size and lower-left offset orientation. |
35 | //! Such Tile is considered uninitialized (invalid). |
36 | Graphic3d_CameraTile() : IsTopDown (false) {} |
37 | |
38 | //! Return true if Tile has been defined. |
39 | bool IsValid() const |
40 | { |
41 | return TotalSize.x() > 0 && TotalSize.y() > 0 |
42 | && TileSize.x() > 0 && TileSize.y() > 0; |
43 | } |
44 | |
45 | //! Return offset position from lower-left corner. |
46 | Graphic3d_Vec2i OffsetLowerLeft() const |
47 | { |
48 | return Graphic3d_Vec2i (Offset.x(), |
49 | !IsTopDown |
50 | ? Offset.y() |
51 | : TotalSize.y() - Offset.y() - 1); |
52 | } |
53 | |
54 | //! Return the copy cropped by total size |
55 | Graphic3d_CameraTile Cropped() const |
56 | { |
57 | Graphic3d_CameraTile aTile = *this; |
58 | if (!IsValid()) |
59 | { |
60 | return aTile; |
61 | } |
62 | |
63 | aTile.Offset.x() = Max (Offset.x(), 0); |
64 | aTile.Offset.y() = Max (Offset.y(), 0); |
65 | |
66 | const Standard_Integer anX = Min (Offset.x() + TileSize.x(), TotalSize.x()); |
67 | const Standard_Integer anY = Min (Offset.y() + TileSize.y(), TotalSize.y()); |
68 | aTile.TileSize.x() = anX - Offset.x(); |
69 | aTile.TileSize.y() = anY - Offset.y(); |
70 | return aTile; |
71 | } |
72 | |
73 | //! Equality check. |
74 | bool operator== (const Graphic3d_CameraTile& theOther) const |
75 | { |
76 | const Graphic3d_Vec2i anOffset1 = OffsetLowerLeft(); |
77 | const Graphic3d_Vec2i anOffset2 = theOther.OffsetLowerLeft(); |
78 | return TotalSize.x() == theOther.TotalSize.x() |
79 | && TotalSize.y() == theOther.TotalSize.y() |
80 | && TileSize.x() == theOther.TileSize.x() |
81 | && TileSize.y() == theOther.TileSize.y() |
82 | && anOffset1.x() == anOffset2.x() |
83 | && anOffset1.y() == anOffset2.y(); |
84 | } |
85 | |
86 | }; |
87 | |
88 | #endif // _Graphic3d_CameraTile_HeaderFile |