Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0032   //! Default constructor.
0033   //! Creates empty order with zero convolution.
0034   Standard_EXPORT Graphic3d_CubeMapOrder();
0035 
0036   //! Initializes order with values.
0037   Standard_EXPORT Graphic3d_CubeMapOrder (unsigned char thePosXLocation,
0038                                           unsigned char theNegXLocation,
0039                                           unsigned char thePosYLocation,
0040                                           unsigned char theNegYLocation,
0041                                           unsigned char thePosZLocation,
0042                                           unsigned char theNegZLocation);
0043 
0044   //! Creates Graphic3d_CubeMapOrder using Graphic3d_ValidatedCubeMapOrder.
0045   Standard_EXPORT Graphic3d_CubeMapOrder (const Graphic3d_ValidatedCubeMapOrder& theOrder);
0046 
0047   //! Alias of 'operator='.
0048   Standard_EXPORT Graphic3d_CubeMapOrder& Set (const Graphic3d_CubeMapOrder& theOrder);
0049 
0050   //! Checks whether order is valid and returns object containing it.
0051   //! If order is invalid then exception will be thrown.
0052   //! This method is only way to create Graphic3d_ValidatedCubeMapOrder except copy constructor.
0053   Standard_EXPORT Graphic3d_ValidatedCubeMapOrder Validated() const;
0054 
0055 public:
0056 
0057   //! Sets number of tile in packed cubemap image according passed cubemap side.
0058   Standard_EXPORT Graphic3d_CubeMapOrder& Set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue);
0059 
0060   //! Sets default order (just from 0 to 5)
0061   Standard_EXPORT Graphic3d_CubeMapOrder& SetDefault();
0062 
0063   //! Applies another cubemap order as permutation for the current one.
0064   Standard_EXPORT Graphic3d_CubeMapOrder& Permute (const Graphic3d_ValidatedCubeMapOrder& anOrder);
0065 
0066   //! Returns permuted by other cubemap order copy of current one. 
0067   Standard_EXPORT Graphic3d_CubeMapOrder 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 
0102   //! Returns default order in protector container class.
0103   //! It is guaranteed to be valid.
0104   Standard_EXPORT static const Graphic3d_ValidatedCubeMapOrder& Default();
0105 
0106 private:
0107 
0108   //! Alias of 'Get' with other parameter's type for more handful iteration.
0109   unsigned char get (unsigned char theCubeMapSide) const;
0110 
0111   //! Alias of 'set' with other parameter's type for more handful iteration and applying permutations.
0112   void set (unsigned char theCubeMapSide, unsigned char theValue);
0113 
0114   //! 'Set' without overflow's checking.
0115   void set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue);
0116 
0117 private:
0118 
0119   unsigned int myConvolution;  //!< Contains all values of permutation as power convolution
0120   bool         myHasOverflows; //!< Indicates if there are attempts to assign index greater than 5
0121 };
0122 
0123 //! Graphic3d_ValidatedCubeMapOrder contains completely valid order object.
0124 //! The only way to create this class except copy constructor is 'Validated' method of Graphic3d_CubeMapOrder.
0125 //! This class can initialize Graphic3d_CubeMapOrder.
0126 //! It is supposed to be used in case of necessity of completely valid order (in function argument as example).
0127 //! It helps to automate order's valid checks.
0128 class Graphic3d_ValidatedCubeMapOrder
0129 {
0130 
0131 public:
0132 
0133   friend class Graphic3d_CubeMapOrder;
0134 
0135   //! Allows skip access to 'Order' field and work directly.
0136   const Graphic3d_CubeMapOrder* operator->() const
0137   {
0138     return &Order;
0139   }
0140 
0141   //! Copy constructor.
0142   Graphic3d_ValidatedCubeMapOrder (const Graphic3d_ValidatedCubeMapOrder& theOther)
0143   : Order (theOther.Order) {}
0144 
0145 public:
0146 
0147   const Graphic3d_CubeMapOrder Order; //!< Completely valid order
0148 
0149 private:
0150 
0151   //! Only Graphic3d_CubeMapOrder can generate Graphic3d_ValidatedCubeMapOrder in 'Validated' method.
0152   Graphic3d_ValidatedCubeMapOrder(const Graphic3d_CubeMapOrder theOrder)
0153   : Order(theOrder) {}
0154 
0155   //! Deleted 'operator='
0156   Graphic3d_ValidatedCubeMapOrder& operator= (const Graphic3d_ValidatedCubeMapOrder&);
0157 
0158 };
0159 
0160 #endif // _Graphic3d_CubeMapOrder_HeaderFile