summaryrefslogtreecommitdiff
path: root/src/MeshVS/MeshVS_TwoColors.cxx
blob: 5ab897f75ec1acea250e5b3d9e8b37c95e384b71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// File:	MeshVS_TwoColors.hxx
// Created:	Wed Oct 08 2003
// Author:	Alexander SOLOVYOV
// Copyright:	 Open CASCADE 2003

#include <MeshVS_TwoColors.hxx>


//================================================================
// Function : HashCode
// Purpose  :
//================================================================
Standard_Integer HashCode ( const MeshVS_TwoColors&       theKey,
                            const Standard_Integer theUpper)
{
#define MESHPRS_HASH_BYTE(val) { \
    aHash += (val);              \
    aHash += (aHash << 10);      \
    aHash ^= (aHash >> 6);       \
  }
  Standard_Integer aHash = 0;
  MESHPRS_HASH_BYTE (theKey.r1)
  MESHPRS_HASH_BYTE (theKey.g1)
  MESHPRS_HASH_BYTE (theKey.b1)
  MESHPRS_HASH_BYTE (theKey.r2)
  MESHPRS_HASH_BYTE (theKey.g2)
  MESHPRS_HASH_BYTE (theKey.b2)
  aHash += (aHash << 3);
  aHash ^= (aHash >> 11);
  aHash += (aHash << 15);
  return (( aHash & 0x7fffffff ) % theUpper) + 1;
#undef MESHPRS_HASH_BYTE
}

//================================================================
// Function : IsEqual
// Purpose  :
//================================================================
Standard_Boolean IsEqual (const MeshVS_TwoColors& K1,
                          const MeshVS_TwoColors& K2)
{
  return (((K1.r1 * 256 + K1.g1) * 256 + K1.b1) ==
          ((K2.r1 * 256 + K2.g1) * 256 + K2.b1) &&
          ((K1.r2 * 256 + K1.g2) * 256 + K1.b2) ==
          ((K2.r2 * 256 + K2.g2) * 256 + K2.b2));
}

//================================================================
// Function : operator ==
// Purpose  :
//================================================================
Standard_Boolean operator== ( const MeshVS_TwoColors& K1,
                              const MeshVS_TwoColors& K2  )
{
  return IsEqual ( K1, K2 );
}

//================================================================
// Function : BindTwoColors
// Purpose  :
//================================================================
MeshVS_TwoColors BindTwoColors ( const Quantity_Color& theCol1, const Quantity_Color& theCol2 )
{
  MeshVS_TwoColors aRes;

  aRes.r1 = unsigned ( theCol1.Red()   * 255.0 );
  aRes.g1 = unsigned ( theCol1.Green() * 255.0 );
  aRes.b1 = unsigned ( theCol1.Blue()  * 255.0 );
  aRes.r2 = unsigned ( theCol2.Red()   * 255.0 );
  aRes.g2 = unsigned ( theCol2.Green() * 255.0 );
  aRes.b2 = unsigned ( theCol2.Blue()  * 255.0 );

  return aRes;
}

//================================================================
// Function : ExtractColor
// Purpose  :
//================================================================
Quantity_Color ExtractColor ( MeshVS_TwoColors& theTwoColors, const Standard_Integer Index )
{
  Quantity_Color aRes;
  Standard_Real max = 255.0;

  if ( Index == 1 )
    aRes.SetValues ( Standard_Real (theTwoColors.r1) / max,
                     Standard_Real (theTwoColors.g1) / max,
                     Standard_Real (theTwoColors.b1) / max, Quantity_TOC_RGB );
  else if (Index == 2)
    aRes.SetValues ( Standard_Real (theTwoColors.r2) / max,
                     Standard_Real (theTwoColors.g2) / max,
                     Standard_Real (theTwoColors.b2) / max, Quantity_TOC_RGB );

  return aRes;
}

//================================================================
// Function : ExtractColors
// Purpose  :
//================================================================
void ExtractColors ( MeshVS_TwoColors& theTwoColors, Quantity_Color& theCol1, Quantity_Color& theCol2 )
{
  Standard_Real max = 255.0;
  theCol1.SetValues ( Standard_Real (theTwoColors.r1) / max,
                      Standard_Real (theTwoColors.g1) / max,
                      Standard_Real (theTwoColors.b1) / max, Quantity_TOC_RGB );
  theCol2.SetValues ( Standard_Real (theTwoColors.r2) / max,
                      Standard_Real (theTwoColors.g2) / max,
                      Standard_Real (theTwoColors.b2) / max, Quantity_TOC_RGB );
}