1 // Created on: 2003-10-08
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2003-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <MeshVS_TwoColors.hxx>
19 //================================================================
20 // Function : HashCode
22 //================================================================
23 Standard_Integer HashCode ( const MeshVS_TwoColors& theKey,
24 const Standard_Integer theUpper)
26 #define MESHPRS_HASH_BYTE(val) { \
28 aHash += (aHash << 10); \
29 aHash ^= (aHash >> 6); \
31 Standard_Integer aHash = 0;
32 MESHPRS_HASH_BYTE (theKey.r1)
33 MESHPRS_HASH_BYTE (theKey.g1)
34 MESHPRS_HASH_BYTE (theKey.b1)
35 MESHPRS_HASH_BYTE (theKey.r2)
36 MESHPRS_HASH_BYTE (theKey.g2)
37 MESHPRS_HASH_BYTE (theKey.b2)
38 aHash += (aHash << 3);
39 aHash ^= (aHash >> 11);
40 aHash += (aHash << 15);
41 return (( aHash & 0x7fffffff ) % theUpper) + 1;
42 #undef MESHPRS_HASH_BYTE
45 //================================================================
48 //================================================================
49 Standard_Boolean IsEqual (const MeshVS_TwoColors& K1,
50 const MeshVS_TwoColors& K2)
52 return (((K1.r1 * 256 + K1.g1) * 256 + K1.b1) ==
53 ((K2.r1 * 256 + K2.g1) * 256 + K2.b1) &&
54 ((K1.r2 * 256 + K1.g2) * 256 + K1.b2) ==
55 ((K2.r2 * 256 + K2.g2) * 256 + K2.b2));
58 //================================================================
59 // Function : operator ==
61 //================================================================
62 Standard_Boolean operator== ( const MeshVS_TwoColors& K1,
63 const MeshVS_TwoColors& K2 )
65 return IsEqual ( K1, K2 );
68 //================================================================
69 // Function : BindTwoColors
71 //================================================================
72 MeshVS_TwoColors BindTwoColors ( const Quantity_Color& theCol1, const Quantity_Color& theCol2 )
74 MeshVS_TwoColors aRes;
76 aRes.r1 = unsigned ( theCol1.Red() * 255.0 );
77 aRes.g1 = unsigned ( theCol1.Green() * 255.0 );
78 aRes.b1 = unsigned ( theCol1.Blue() * 255.0 );
79 aRes.r2 = unsigned ( theCol2.Red() * 255.0 );
80 aRes.g2 = unsigned ( theCol2.Green() * 255.0 );
81 aRes.b2 = unsigned ( theCol2.Blue() * 255.0 );
86 //================================================================
87 // Function : ExtractColor
89 //================================================================
90 Quantity_Color ExtractColor ( MeshVS_TwoColors& theTwoColors, const Standard_Integer Index )
93 Standard_Real max = 255.0;
96 aRes.SetValues ( Standard_Real (theTwoColors.r1) / max,
97 Standard_Real (theTwoColors.g1) / max,
98 Standard_Real (theTwoColors.b1) / max, Quantity_TOC_RGB );
100 aRes.SetValues ( Standard_Real (theTwoColors.r2) / max,
101 Standard_Real (theTwoColors.g2) / max,
102 Standard_Real (theTwoColors.b2) / max, Quantity_TOC_RGB );
107 //================================================================
108 // Function : ExtractColors
110 //================================================================
111 void ExtractColors ( MeshVS_TwoColors& theTwoColors, Quantity_Color& theCol1, Quantity_Color& theCol2 )
113 Standard_Real max = 255.0;
114 theCol1.SetValues ( Standard_Real (theTwoColors.r1) / max,
115 Standard_Real (theTwoColors.g1) / max,
116 Standard_Real (theTwoColors.b1) / max, Quantity_TOC_RGB );
117 theCol2.SetValues ( Standard_Real (theTwoColors.r2) / max,
118 Standard_Real (theTwoColors.g2) / max,
119 Standard_Real (theTwoColors.b2) / max, Quantity_TOC_RGB );