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_OStream.hxx>
20 #include <Standard_TypeDef.hxx>
21 
22 //! Class defines the area (Tile) inside a view.
23 class Graphic3d_CameraTile
24 {
25 public:
26 
27   Graphic3d_Vec2i TotalSize; //!< total size of the View area, in pixels
28   Graphic3d_Vec2i TileSize;  //!< size of the Tile, in pixels
29   Graphic3d_Vec2i Offset;    //!< the lower-left corner of the Tile relative to the View area (or upper-left if IsTopDown is true), in pixels
30   bool            IsTopDown; //!< indicate the offset coordinate system - lower-left (default) or top-down
31 
32 public:
33 
34   //! Default constructor.
35   //! Initializes the empty Tile of zero size and lower-left offset orientation.
36   //! Such Tile is considered uninitialized (invalid).
Graphic3d_CameraTile()37   Graphic3d_CameraTile() : IsTopDown (false) {}
38 
39   //! Return true if Tile has been defined.
IsValid() const40   bool IsValid() const
41   {
42     return TotalSize.x() > 0 && TotalSize.y() > 0
43         && TileSize.x()  > 0 && TileSize.y()  > 0;
44   }
45 
46   //! Return offset position from lower-left corner.
OffsetLowerLeft() const47   Graphic3d_Vec2i OffsetLowerLeft() const
48   {
49     return Graphic3d_Vec2i (Offset.x(),
50                            !IsTopDown
51                            ? Offset.y()
52                            : TotalSize.y() - Offset.y() - 1);
53   }
54 
55   //! Return the copy cropped by total size
Cropped() const56   Graphic3d_CameraTile Cropped() const
57   {
58     Graphic3d_CameraTile aTile = *this;
59     if (!IsValid())
60     {
61       return aTile;
62     }
63 
64     aTile.Offset.x() = Max (Offset.x(), 0);
65     aTile.Offset.y() = Max (Offset.y(), 0);
66 
67     const Standard_Integer anX = Min (Offset.x() + TileSize.x(), TotalSize.x());
68     const Standard_Integer anY = Min (Offset.y() + TileSize.y(), TotalSize.y());
69     aTile.TileSize.x() = anX - Offset.x();
70     aTile.TileSize.y() = anY - Offset.y();
71     return aTile;
72   }
73 
74   //! Equality check.
operator ==(const Graphic3d_CameraTile & theOther) const75   bool operator== (const Graphic3d_CameraTile& theOther) const
76   {
77     const Graphic3d_Vec2i anOffset1 = OffsetLowerLeft();
78     const Graphic3d_Vec2i anOffset2 = theOther.OffsetLowerLeft();
79     return TotalSize.x() == theOther.TotalSize.x()
80         && TotalSize.y() == theOther.TotalSize.y()
81         && TileSize.x()  == theOther.TileSize.x()
82         && TileSize.y()  == theOther.TileSize.y()
83         && anOffset1.x() == anOffset2.x()
84         && anOffset1.y() == anOffset2.y();
85   }
86 
87   //! Dumps the content of me into the stream
88   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
89 
90 };
91 
92 #endif // _Graphic3d_CameraTile_HeaderFile
93