Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 09:15:38

0001 // Author: Ilya Khramov
0002 // Copyright (c) 2019 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _Graphic3d_CubeMapOrder_HeaderFile
0016 #define _Graphic3d_CubeMapOrder_HeaderFile
0017 
0018 #include <Graphic3d_CubeMapSide.hxx>
0019 #include <Standard_Macro.hxx>
0020 
0021 class Graphic3d_ValidatedCubeMapOrder;
0022 
0023 //! Graphic3d_CubeMapOrder maps sides of cubemap on tiles in packed cubemap image
0024 //! to support different tiles order in such images.
0025 //! Also it can be considered as permutation of numbers from 0 to 5.
0026 //! It stores permutation in one integer as convolution.
0027 class Graphic3d_CubeMapOrder
0028 {
0029 
0030 public:
0031   //! Default constructor.
0032   //! Creates empty order with zero convolution.
0033   Standard_EXPORT Graphic3d_CubeMapOrder();
0034 
0035   //! Initializes order with values.
0036   Standard_EXPORT Graphic3d_CubeMapOrder(unsigned char thePosXLocation,
0037                                          unsigned char theNegXLocation,
0038                                          unsigned char thePosYLocation,
0039                                          unsigned char theNegYLocation,
0040                                          unsigned char thePosZLocation,
0041                                          unsigned char theNegZLocation);
0042 
0043   //! Creates Graphic3d_CubeMapOrder using Graphic3d_ValidatedCubeMapOrder.
0044   Standard_EXPORT Graphic3d_CubeMapOrder(const Graphic3d_ValidatedCubeMapOrder& theOrder);
0045 
0046   //! Alias of 'operator='.
0047   Standard_EXPORT Graphic3d_CubeMapOrder& Set(const Graphic3d_CubeMapOrder& theOrder);
0048 
0049   //! Checks whether order is valid and returns object containing it.
0050   //! If order is invalid then exception will be thrown.
0051   //! This method is only way to create Graphic3d_ValidatedCubeMapOrder except copy constructor.
0052   Standard_EXPORT Graphic3d_ValidatedCubeMapOrder Validated() const;
0053 
0054 public:
0055   //! Sets number of tile in packed cubemap image according passed cubemap side.
0056   Standard_EXPORT Graphic3d_CubeMapOrder& Set(Graphic3d_CubeMapSide theCubeMapSide,
0057                                               unsigned char         theValue);
0058 
0059   //! Sets default order (just from 0 to 5)
0060   Standard_EXPORT Graphic3d_CubeMapOrder& SetDefault();
0061 
0062   //! Applies another cubemap order as permutation for the current one.
0063   Standard_EXPORT Graphic3d_CubeMapOrder& Permute(const Graphic3d_ValidatedCubeMapOrder& anOrder);
0064 
0065   //! Returns permuted by other cubemap order copy of current one.
0066   Standard_EXPORT Graphic3d_CubeMapOrder
0067     Permuted(const Graphic3d_ValidatedCubeMapOrder& anOrder) const;
0068 
0069   //! Swaps values of two cubemap sides.
0070   Standard_EXPORT Graphic3d_CubeMapOrder& Swap(Graphic3d_CubeMapSide theFirstSide,
0071                                                Graphic3d_CubeMapSide theSecondSide);
0072 
0073   //! Returns copy of current order with swapped values of two cubemap sides.
0074   Standard_EXPORT Graphic3d_CubeMapOrder Swapped(Graphic3d_CubeMapSide theFirstSide,
0075                                                  Graphic3d_CubeMapSide theSecondSide) const;
0076 
0077   //! Returns value of passed cubemap side.
0078   Standard_EXPORT unsigned char Get(Graphic3d_CubeMapSide theCubeMapSide) const;
0079 
0080   //! Alias of 'Get'.
0081   Standard_EXPORT unsigned char operator[](Graphic3d_CubeMapSide theCubeMapSide) const;
0082 
0083   //! Makes order empty.
0084   Standard_EXPORT Graphic3d_CubeMapOrder& Clear();
0085 
0086   //! Checks whether order is empty.
0087   Standard_EXPORT bool IsEmpty() const;
0088 
0089   //! Checks whether order has repetitions.
0090   Standard_EXPORT bool HasRepetitions() const;
0091 
0092   //! Checks whether attempts to assign index greater than 5 to any side happed.
0093   Standard_EXPORT bool HasOverflows() const;
0094 
0095   //! Checks whether order is valid.
0096   //! Order is valid when it doesn't have repetitions
0097   //! and there were not attempts to assign indexes greater than 5.
0098   Standard_EXPORT bool IsValid() const;
0099 
0100 public:
0101   //! Returns default order in protector container class.
0102   //! It is guaranteed to be valid.
0103   Standard_EXPORT static const Graphic3d_ValidatedCubeMapOrder& Default();
0104 
0105 private:
0106   //! Alias of 'Get' with other parameter's type for more handful iteration.
0107   unsigned char get(unsigned char theCubeMapSide) const;
0108 
0109   //! Alias of 'set' with other parameter's type for more handful iteration and applying
0110   //! permutations.
0111   void set(unsigned char theCubeMapSide, unsigned char theValue);
0112 
0113   //! 'Set' without overflow's checking.
0114   void set(Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue);
0115 
0116 private:
0117   unsigned int myConvolution;  //!< Contains all values of permutation as power convolution
0118   bool         myHasOverflows; //!< Indicates if there are attempts to assign index greater than 5
0119 };
0120 
0121 //! Graphic3d_ValidatedCubeMapOrder contains completely valid order object.
0122 //! The only way to create this class except copy constructor is 'Validated' method of
0123 //! Graphic3d_CubeMapOrder. This class can initialize Graphic3d_CubeMapOrder. It is supposed to be
0124 //! used in case of necessity of completely valid order (in function argument as example). It helps
0125 //! to automate order's valid checks.
0126 class Graphic3d_ValidatedCubeMapOrder
0127 {
0128 
0129 public:
0130   friend class Graphic3d_CubeMapOrder;
0131 
0132   //! Allows skip access to 'Order' field and work directly.
0133   const Graphic3d_CubeMapOrder* operator->() const { return &Order; }
0134 
0135   //! Copy constructor.
0136   Graphic3d_ValidatedCubeMapOrder(const Graphic3d_ValidatedCubeMapOrder& theOther)
0137       : Order(theOther.Order)
0138   {
0139   }
0140 
0141 public:
0142   const Graphic3d_CubeMapOrder Order; //!< Completely valid order
0143 
0144 private:
0145   //! Only Graphic3d_CubeMapOrder can generate Graphic3d_ValidatedCubeMapOrder in 'Validated'
0146   //! method.
0147   Graphic3d_ValidatedCubeMapOrder(const Graphic3d_CubeMapOrder theOrder)
0148       : Order(theOrder)
0149   {
0150   }
0151 
0152   //! Deleted 'operator='
0153   Graphic3d_ValidatedCubeMapOrder& operator=(const Graphic3d_ValidatedCubeMapOrder&);
0154 };
0155 
0156 #endif // _Graphic3d_CubeMapOrder_HeaderFile