Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-02 09:12:28

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 <NCollection_Vec2.hxx>
0018 #include <Standard_TypeDef.hxx>
0019 #include <Standard_Integer.hxx>
0020 #include <Standard_OStream.hxx>
0021 
0022 //! Class defines the area (Tile) inside a view.
0023 class Graphic3d_CameraTile
0024 {
0025 public:
0026   NCollection_Vec2<int> TotalSize; //!< total size of the View area, in pixels
0027   NCollection_Vec2<int> TileSize;  //!< size of the Tile, in pixels
0028   // clang-format off
0029   NCollection_Vec2<int> 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   // clang-format on
0032 
0033 public:
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()
0038       : IsTopDown(false)
0039   {
0040   }
0041 
0042   //! Return true if Tile has been defined.
0043   bool IsValid() const
0044   {
0045     return TotalSize.x() > 0 && TotalSize.y() > 0 && TileSize.x() > 0 && TileSize.y() > 0;
0046   }
0047 
0048   //! Return offset position from lower-left corner.
0049   NCollection_Vec2<int> OffsetLowerLeft() const
0050   {
0051     return NCollection_Vec2<int>(Offset.x(),
0052                                  !IsTopDown ? Offset.y() : 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() = (std::max)(Offset.x(), 0);
0065     aTile.Offset.y() = (std::max)(Offset.y(), 0);
0066 
0067     const int anX      = (std::min)(Offset.x() + TileSize.x(), TotalSize.x());
0068     const int anY      = (std::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 NCollection_Vec2<int> anOffset1 = OffsetLowerLeft();
0078     const NCollection_Vec2<int> anOffset2 = theOther.OffsetLowerLeft();
0079     return TotalSize.x() == theOther.TotalSize.x() && TotalSize.y() == theOther.TotalSize.y()
0080            && TileSize.x() == theOther.TileSize.x() && TileSize.y() == theOther.TileSize.y()
0081            && anOffset1.x() == anOffset2.x() && anOffset1.y() == anOffset2.y();
0082   }
0083 
0084   //! Dumps the content of me into the stream
0085   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0086 };
0087 
0088 #endif // _Graphic3d_CameraTile_HeaderFile