0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / MeshVS / MeshVS_TwoColors.cxx
1 // Created on: 2003-10-08
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2003-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <MeshVS_TwoColors.hxx>
17
18
19 //================================================================
20 // function : HashCode
21 // purpose  :
22 //================================================================
23 Standard_Integer HashCode (const MeshVS_TwoColors& theKey, const Standard_Integer theUpperBound)
24 {
25 #define MESHPRS_HASH_BYTE(val) { \
26     aHash += (val);              \
27     aHash += (aHash << 10);      \
28     aHash ^= (aHash >> 6);       \
29   }
30   unsigned int aHash = 0;
31   MESHPRS_HASH_BYTE (theKey.r1)
32   MESHPRS_HASH_BYTE (theKey.g1)
33   MESHPRS_HASH_BYTE (theKey.b1)
34   MESHPRS_HASH_BYTE (theKey.r2)
35   MESHPRS_HASH_BYTE (theKey.g2)
36   MESHPRS_HASH_BYTE (theKey.b2)
37   aHash += (aHash << 3);
38   aHash ^= (aHash >> 11);
39   aHash += (aHash << 15);
40   return HashCode(aHash, theUpperBound);
41 #undef MESHPRS_HASH_BYTE
42 }
43
44 //================================================================
45 // Function : IsEqual
46 // Purpose  :
47 //================================================================
48 Standard_Boolean IsEqual (const MeshVS_TwoColors& K1,
49                           const MeshVS_TwoColors& K2)
50 {
51   return (((K1.r1 * 256 + K1.g1) * 256 + K1.b1) ==
52           ((K2.r1 * 256 + K2.g1) * 256 + K2.b1) &&
53           ((K1.r2 * 256 + K1.g2) * 256 + K1.b2) ==
54           ((K2.r2 * 256 + K2.g2) * 256 + K2.b2));
55 }
56
57 //================================================================
58 // Function : operator ==
59 // Purpose  :
60 //================================================================
61 Standard_Boolean operator== ( const MeshVS_TwoColors& K1,
62                               const MeshVS_TwoColors& K2  )
63 {
64   return IsEqual ( K1, K2 );
65 }
66
67 //================================================================
68 // Function : BindTwoColors
69 // Purpose  :
70 //================================================================
71 MeshVS_TwoColors BindTwoColors ( const Quantity_Color& theCol1, const Quantity_Color& theCol2 )
72 {
73   MeshVS_TwoColors aRes;
74
75   aRes.r1 = unsigned ( theCol1.Red()   * 255.0 );
76   aRes.g1 = unsigned ( theCol1.Green() * 255.0 );
77   aRes.b1 = unsigned ( theCol1.Blue()  * 255.0 );
78   aRes.r2 = unsigned ( theCol2.Red()   * 255.0 );
79   aRes.g2 = unsigned ( theCol2.Green() * 255.0 );
80   aRes.b2 = unsigned ( theCol2.Blue()  * 255.0 );
81
82   return aRes;
83 }
84
85 //================================================================
86 // Function : ExtractColor
87 // Purpose  :
88 //================================================================
89 Quantity_Color ExtractColor ( MeshVS_TwoColors& theTwoColors, const Standard_Integer Index )
90 {
91   Quantity_Color aRes;
92   Standard_Real max = 255.0;
93
94   if ( Index == 1 )
95     aRes.SetValues ( Standard_Real (theTwoColors.r1) / max,
96                      Standard_Real (theTwoColors.g1) / max,
97                      Standard_Real (theTwoColors.b1) / max, Quantity_TOC_RGB );
98   else if (Index == 2)
99     aRes.SetValues ( Standard_Real (theTwoColors.r2) / max,
100                      Standard_Real (theTwoColors.g2) / max,
101                      Standard_Real (theTwoColors.b2) / max, Quantity_TOC_RGB );
102
103   return aRes;
104 }
105
106 //================================================================
107 // Function : ExtractColors
108 // Purpose  :
109 //================================================================
110 void ExtractColors ( MeshVS_TwoColors& theTwoColors, Quantity_Color& theCol1, Quantity_Color& theCol2 )
111 {
112   Standard_Real max = 255.0;
113   theCol1.SetValues ( Standard_Real (theTwoColors.r1) / max,
114                       Standard_Real (theTwoColors.g1) / max,
115                       Standard_Real (theTwoColors.b1) / max, Quantity_TOC_RGB );
116   theCol2.SetValues ( Standard_Real (theTwoColors.r2) / max,
117                       Standard_Real (theTwoColors.g2) / max,
118                       Standard_Real (theTwoColors.b2) / max, Quantity_TOC_RGB );
119 }