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, const Standard_Integer theUpperBound)
25 #define MESHPRS_HASH_BYTE(val) { \
27 aHash += (aHash << 10); \
28 aHash ^= (aHash >> 6); \
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
44 //================================================================
47 //================================================================
48 Standard_Boolean IsEqual (const MeshVS_TwoColors& K1,
49 const MeshVS_TwoColors& K2)
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));
57 //================================================================
58 // Function : operator ==
60 //================================================================
61 Standard_Boolean operator== ( const MeshVS_TwoColors& K1,
62 const MeshVS_TwoColors& K2 )
64 return IsEqual ( K1, K2 );
67 //================================================================
68 // Function : BindTwoColors
70 //================================================================
71 MeshVS_TwoColors BindTwoColors ( const Quantity_Color& theCol1, const Quantity_Color& theCol2 )
73 MeshVS_TwoColors aRes;
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 );
85 //================================================================
86 // Function : ExtractColor
88 //================================================================
89 Quantity_Color ExtractColor ( MeshVS_TwoColors& theTwoColors, const Standard_Integer Index )
92 Standard_Real max = 255.0;
95 aRes.SetValues ( Standard_Real (theTwoColors.r1) / max,
96 Standard_Real (theTwoColors.g1) / max,
97 Standard_Real (theTwoColors.b1) / max, Quantity_TOC_RGB );
99 aRes.SetValues ( Standard_Real (theTwoColors.r2) / max,
100 Standard_Real (theTwoColors.g2) / max,
101 Standard_Real (theTwoColors.b2) / max, Quantity_TOC_RGB );
106 //================================================================
107 // Function : ExtractColors
109 //================================================================
110 void ExtractColors ( MeshVS_TwoColors& theTwoColors, Quantity_Color& theCol1, Quantity_Color& theCol2 )
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 );