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 #include <Graphic3d_CubeMapOrder.hxx>
17 #include <Standard_Failure.hxx>
21 // =======================================================================
22 // function : Graphic3d_CubeMapOrder
24 // =======================================================================
25 Graphic3d_CubeMapOrder::Graphic3d_CubeMapOrder()
28 myHasOverflows (false)
31 // =======================================================================
32 // function : Graphic3d_CubeMapOrder
34 // =======================================================================
35 Graphic3d_CubeMapOrder::Graphic3d_CubeMapOrder (unsigned char thePosXLocation,
36 unsigned char theNegXLocation,
37 unsigned char thePosYLocation,
38 unsigned char theNegYLocation,
39 unsigned char thePosZLocation,
40 unsigned char theNegZLocation)
43 myHasOverflows (false)
45 Set (Graphic3d_CMS_POS_X, thePosXLocation);
46 Set (Graphic3d_CMS_NEG_X, theNegXLocation);
47 Set (Graphic3d_CMS_POS_Y, thePosYLocation);
48 Set (Graphic3d_CMS_NEG_Y, theNegYLocation);
49 Set (Graphic3d_CMS_POS_Z, thePosZLocation);
50 Set (Graphic3d_CMS_NEG_Z, theNegZLocation);
53 // =======================================================================
54 // function : Graphic3d_CubeMapOrder
56 // =======================================================================
57 Graphic3d_CubeMapOrder::Graphic3d_CubeMapOrder (const Graphic3d_ValidatedCubeMapOrder theOrder)
59 myConvolution (theOrder.Order.myConvolution),
60 myHasOverflows (theOrder.Order.myHasOverflows)
63 // =======================================================================
66 // =======================================================================
67 Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Set (const Graphic3d_CubeMapOrder& theOrder)
69 myConvolution = theOrder.myConvolution;
70 myHasOverflows = theOrder.myHasOverflows;
74 // =======================================================================
75 // function : operator=
77 // =======================================================================
78 Graphic3d_ValidatedCubeMapOrder Graphic3d_CubeMapOrder::Validated() const
82 throw Standard_Failure("Try of Graphic3d_ValidatedCubeMapOrder creation using invalid Graphic3d_CubeMapOrder");
88 // =======================================================================
91 // =======================================================================
92 Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue)
96 myHasOverflows = true;
99 set (theCubeMapSide, theValue);
103 // =======================================================================
106 // =======================================================================
107 unsigned char Graphic3d_CubeMapOrder::Get (Graphic3d_CubeMapSide theCubeMapSide) const
109 return get (static_cast<unsigned char> (theCubeMapSide));
112 // =======================================================================
113 // function : operator[]
115 // =======================================================================
116 unsigned char Graphic3d_CubeMapOrder::operator[] (Graphic3d_CubeMapSide theCubeMapSide) const
118 return Get (theCubeMapSide);
121 // =======================================================================
122 // function : SetDefault
124 // =======================================================================
125 Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::SetDefault()
127 for (unsigned char i = 0; i < 6; ++i)
129 set (Graphic3d_CubeMapSide (i), i);
134 // =======================================================================
135 // function : Permute
137 // =======================================================================
138 Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Permute (Graphic3d_ValidatedCubeMapOrder thePermutation)
140 for (unsigned char i = 0; i < 6; ++i)
142 set (i, thePermutation->get (get (i)));
148 // =======================================================================
149 // function : Permuted
151 // =======================================================================
152 Graphic3d_CubeMapOrder Graphic3d_CubeMapOrder::Permuted (Graphic3d_ValidatedCubeMapOrder thePermutation) const
154 Graphic3d_CubeMapOrder anOrder = *this;
155 anOrder.Permute (thePermutation);
159 // =======================================================================
162 // =======================================================================
163 Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Swap (Graphic3d_CubeMapSide theFirstSide,
164 Graphic3d_CubeMapSide theSecondSide)
166 unsigned char aTmp = Get (theFirstSide);
167 set (theFirstSide, Get(theSecondSide));
168 set (theSecondSide, aTmp);
172 // =======================================================================
173 // function : Swapped
175 // =======================================================================
176 Graphic3d_CubeMapOrder Graphic3d_CubeMapOrder::Swapped (Graphic3d_CubeMapSide theFirstSide,
177 Graphic3d_CubeMapSide theSecondSide) const
179 Graphic3d_CubeMapOrder anOrder = *this;
180 anOrder.Swap (theFirstSide, theSecondSide);
184 // =======================================================================
187 // =======================================================================
188 Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Clear()
191 myHasOverflows = false;
195 // =======================================================================
196 // function : IsEmpty
198 // =======================================================================
199 bool Graphic3d_CubeMapOrder::IsEmpty() const
201 return myConvolution == 0;
204 // =======================================================================
205 // function : HasRepetitions
207 // =======================================================================
208 bool Graphic3d_CubeMapOrder::HasRepetitions() const
210 std::bitset<6> aBitSet;
211 for (unsigned char i = 0; i < 6; ++i)
213 std::bitset<6>::reference aFlag = aBitSet[get (i)];
223 // =======================================================================
224 // function : HasOverflows
226 // =======================================================================
227 bool Graphic3d_CubeMapOrder::HasOverflows() const
229 return myHasOverflows;
232 // =======================================================================
233 // function : IsValid
235 // =======================================================================
236 bool Graphic3d_CubeMapOrder::IsValid() const
238 return !HasRepetitions() && !HasOverflows();
241 // =======================================================================
244 // =======================================================================
245 unsigned char Graphic3d_CubeMapOrder::get (unsigned char theCubeMapSide) const
247 return (myConvolution / (1 << (theCubeMapSide * 3))) % (1 << 3);
250 // =======================================================================
253 // =======================================================================
254 void Graphic3d_CubeMapOrder::set (unsigned char theCubeMapSide, unsigned char theValue)
256 unsigned int aValuePlace = 1 << (theCubeMapSide * 3);
257 myConvolution -= aValuePlace * get (theCubeMapSide);
258 myConvolution += aValuePlace * theValue;
261 // =======================================================================
264 // =======================================================================
265 void Graphic3d_CubeMapOrder::set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue)
267 set (static_cast<unsigned char> (theCubeMapSide), theValue);
270 // =======================================================================
271 // function : Default
273 // =======================================================================
274 const Graphic3d_ValidatedCubeMapOrder& Graphic3d_CubeMapOrder::Default()
276 static const Graphic3d_ValidatedCubeMapOrder aCubeMapOrder = Graphic3d_CubeMapOrder().SetDefault().Validated();
277 return aCubeMapOrder;