1 // Author: Ilya Khramov
2 // Copyright (c) 2019 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Graphic3d_CubeMapOrder_HeaderFile
16 #define _Graphic3d_CubeMapOrder_HeaderFile
18 #include <Graphic3d_CubeMapSide.hxx>
19 #include <Standard_Macro.hxx>
21 class Graphic3d_ValidatedCubeMapOrder;
23 //! Graphic3d_CubeMapOrder maps sides of cubemap on tiles in packed cubemap image
24 //! to support different tiles order in such images.
25 //! Also it can be considered as permutation of numbers from 0 to 5.
26 //! It stores permutation in one integer as convolution.
27 class Graphic3d_CubeMapOrder
32 //! Default constructor.
33 //! Creates empty order with zero convolution.
34 Standard_EXPORT Graphic3d_CubeMapOrder();
36 //! Initializes order with values.
37 Standard_EXPORT Graphic3d_CubeMapOrder (unsigned char thePosXLocation,
38 unsigned char theNegXLocation,
39 unsigned char thePosYLocation,
40 unsigned char theNegYLocation,
41 unsigned char thePosZLocation,
42 unsigned char theNegZLocation);
44 //! Creates Graphic3d_CubeMapOrder using Graphic3d_ValidatedCubeMapOrder.
45 Standard_EXPORT Graphic3d_CubeMapOrder (const Graphic3d_ValidatedCubeMapOrder theOrder);
47 //! Alias of 'operator='.
48 Standard_EXPORT Graphic3d_CubeMapOrder& Set (const Graphic3d_CubeMapOrder& theOrder);
50 //! Checks whether order is valid and returns object containing it.
51 //! If order is invalid then exception will be thrown.
52 //! This method is only way to create Graphic3d_ValidatedCubeMapOrder except copy constructor.
53 Standard_EXPORT Graphic3d_ValidatedCubeMapOrder Validated() const;
57 //! Sets number of tile in packed cubemap image according passed cubemap side.
58 Standard_EXPORT Graphic3d_CubeMapOrder& Set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue);
60 //! Sets default order (just from 0 to 5)
61 Standard_EXPORT Graphic3d_CubeMapOrder& SetDefault();
63 //! Applies another cubemap order as permutation for the current one.
64 Standard_EXPORT Graphic3d_CubeMapOrder& Permute (Graphic3d_ValidatedCubeMapOrder anOrder);
66 //! Returns permuted by other cubemap order copy of current one.
67 Standard_EXPORT Graphic3d_CubeMapOrder Permuted (Graphic3d_ValidatedCubeMapOrder anOrder) const;
69 //! Swaps values of two cubemap sides.
70 Standard_EXPORT Graphic3d_CubeMapOrder& Swap (Graphic3d_CubeMapSide theFirstSide,
71 Graphic3d_CubeMapSide theSecondSide);
73 //! Returns copy of current order with swapped values of two cubemap sides.
74 Standard_EXPORT Graphic3d_CubeMapOrder Swapped (Graphic3d_CubeMapSide theFirstSide,
75 Graphic3d_CubeMapSide theSecondSide) const;
77 //! Returns value of passed cubemap side.
78 Standard_EXPORT unsigned char Get (Graphic3d_CubeMapSide theCubeMapSide) const;
81 Standard_EXPORT unsigned char operator[] (Graphic3d_CubeMapSide theCubeMapSide) const;
83 //! Makes order empty.
84 Standard_EXPORT Graphic3d_CubeMapOrder& Clear();
86 //! Checks whether order is empty.
87 Standard_EXPORT bool IsEmpty() const;
89 //! Checks whether order has repetitions.
90 Standard_EXPORT bool HasRepetitions() const;
92 //! Checks whether attempts to assign index greater than 5 to any side happed.
93 Standard_EXPORT bool HasOverflows() const;
95 //! Checks whether order is valid.
96 //! Order is valid when it doesn't have repetitions
97 //! and there were not attempts to assign indexes greater than 5.
98 Standard_EXPORT bool IsValid() const;
102 //! Returns default order in protector container class.
103 //! It is guaranteed to be valid.
104 Standard_EXPORT static const Graphic3d_ValidatedCubeMapOrder& Default();
108 //! Alias of 'Get' with other parameter's type for more handful iteration.
109 unsigned char get (unsigned char theCubeMapSide) const;
111 //! Alias of 'set' with other parameter's type for more handful iteration and applying permutations.
112 void set (unsigned char theCubeMapSide, unsigned char theValue);
114 //! 'Set' without overflow's checking.
115 void set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue);
119 unsigned int myConvolution; //!< Contains all values of permutation as power convolution
120 bool myHasOverflows; //!< Indicates if there are attempts to assign index greater than 5
123 //! Graphic3d_ValidatedCubeMapOrder contains completely valid order object.
124 //! The only way to create this class except copy constructor is 'Validated' method of Graphic3d_CubeMapOrder.
125 //! This class can initialize Graphic3d_CubeMapOrder.
126 //! It is supposed to be used in case of necessity of completely valid order (in function argument as example).
127 //! It helps to automate order's valid checks.
128 class Graphic3d_ValidatedCubeMapOrder
133 friend class Graphic3d_CubeMapOrder;
135 //! Allows skip access to 'Order' field and work directly.
136 const Graphic3d_CubeMapOrder* operator->() const
141 //! Copy constructor.
142 Graphic3d_ValidatedCubeMapOrder (const Graphic3d_ValidatedCubeMapOrder& theOther)
143 : Order (theOther.Order) {}
147 const Graphic3d_CubeMapOrder Order; //!< Completely valid order
151 //! Only Graphic3d_CubeMapOrder can generate Graphic3d_ValidatedCubeMapOrder in 'Validated' method.
152 Graphic3d_ValidatedCubeMapOrder(const Graphic3d_CubeMapOrder theOrder)
155 //! Deleted 'operator='
156 Graphic3d_ValidatedCubeMapOrder& operator= (const Graphic3d_ValidatedCubeMapOrder&);
160 #endif // _Graphic3d_CubeMapOrder_HeaderFile