Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:47

0001 // Copyright (c) 2016 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Graphic3d_CameraTile_HeaderFile
0015 #define _Graphic3d_CameraTile_HeaderFile
0016 
0017 #include <Graphic3d_Vec2.hxx>
0018 #include <Standard_Integer.hxx>
0019 #include <Standard_OStream.hxx>
0020 #include <Standard_TypeDef.hxx>
0021 
0022 //! Class defines the area (Tile) inside a view.
0023 class Graphic3d_CameraTile
0024 {
0025 public:
0026 
0027   Graphic3d_Vec2i TotalSize; //!< total size of the View area, in pixels
0028   Graphic3d_Vec2i TileSize;  //!< size of the Tile, in pixels
0029   Graphic3d_Vec2i Offset;    //!< the lower-left corner of the Tile relative to the View area (or upper-left if IsTopDown is true), in pixels
0030   bool            IsTopDown; //!< indicate the offset coordinate system - lower-left (default) or top-down
0031 
0032 public:
0033 
0034   //! Default constructor.
0035   //! Initializes the empty Tile of zero size and lower-left offset orientation.
0036   //! Such Tile is considered uninitialized (invalid).
0037   Graphic3d_CameraTile() : IsTopDown (false) {}
0038 
0039   //! Return true if Tile has been defined.
0040   bool IsValid() const
0041   {
0042     return TotalSize.x() > 0 && TotalSize.y() > 0
0043         && TileSize.x()  > 0 && TileSize.y()  > 0;
0044   }
0045 
0046   //! Return offset position from lower-left corner.
0047   Graphic3d_Vec2i OffsetLowerLeft() const
0048   {
0049     return Graphic3d_Vec2i (Offset.x(),
0050                            !IsTopDown
0051                            ? Offset.y()
0052                            : TotalSize.y() - Offset.y() - 1);
0053   }
0054 
0055   //! Return the copy cropped by total size
0056   Graphic3d_CameraTile Cropped() const
0057   {
0058     Graphic3d_CameraTile aTile = *this;
0059     if (!IsValid())
0060     {
0061       return aTile;
0062     }
0063 
0064     aTile.Offset.x() = Max (Offset.x(), 0);
0065     aTile.Offset.y() = Max (Offset.y(), 0);
0066 
0067     const Standard_Integer anX = Min (Offset.x() + TileSize.x(), TotalSize.x());
0068     const Standard_Integer anY = Min (Offset.y() + TileSize.y(), TotalSize.y());
0069     aTile.TileSize.x() = anX - Offset.x();
0070     aTile.TileSize.y() = anY - Offset.y();
0071     return aTile;
0072   }
0073 
0074   //! Equality check.
0075   bool operator== (const Graphic3d_CameraTile& theOther) const
0076   {
0077     const Graphic3d_Vec2i anOffset1 = OffsetLowerLeft();
0078     const Graphic3d_Vec2i anOffset2 = theOther.OffsetLowerLeft();
0079     return TotalSize.x() == theOther.TotalSize.x()
0080         && TotalSize.y() == theOther.TotalSize.y()
0081         && TileSize.x()  == theOther.TileSize.x()
0082         && TileSize.y()  == theOther.TileSize.y()
0083         && anOffset1.x() == anOffset2.x()
0084         && anOffset1.y() == anOffset2.y();
0085   }
0086   
0087   //! Dumps the content of me into the stream
0088   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0089 
0090 };
0091 
0092 #endif // _Graphic3d_CameraTile_HeaderFile