OpenWalnut  1.5.0dev
WColor.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <cmath>
26 #include <string>
27 #include <vector>
28 
29 
30 #include "../common/exceptions/WOutOfBounds.h"
31 #include "../common/WStringUtils.h"
32 #include "WColor.h"
33 
34 // initialize static palette
35 namespace defaultColor
36 {
37  /** the default palette colors */
38  const WColor DefaultPalette[ 22 ]= {
39  // The standard colors
40  RED, GREEN, BLUE, YELLOW, ORANGE, PINK, CYAN,
41  // the slightly lighter standard colors
42  LIGHTRED, LIGHTGREEN, LIGHTBLUE, LIGHTYELLOW,
43  // the slighly darker standard colors
44  DARKRED, DARKGREEN, DARKBLUE, DARKYELLOW, VIOLET, TEAL,
45  // black-white
46  BLACK, GRAY25, GRAY50, GRAY75, WHITE
47  };
48 }
49 
50 // This function is taken from VTK 5.4.2. Since its BSD licensed the license
51 // notice follows below. It is not taken from FAnToM since it seems more self
52 // documenting.
53 //
54 // /*=========================================================================
55 //
56 // Program: Visualization Toolkit
57 // Module: $RCSfile: vtkMath.cxx,v $
58 //
59 // Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
60 // All rights reserved.
61 // See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
62 //
63 // This software is distributed WITHOUT ANY WARRANTY; without even
64 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
65 // PURPOSE. See the above copyright notice for more information.
66 //
67 // =========================================================================
68 // Copyright 2005 Sandia Corporation.
69 // Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
70 // license for use of this work by or on behalf of the
71 // U.S. Government. Redistribution and use in source and binary forms, with
72 // or without modification, are permitted provided that this Notice and any
73 // statement of authorship are reproduced on all copies.
74 //
75 // Contact: pppebay@sandia.gov,dcthomp@sandia.gov,
76 //
77 // =========================================================================*/
78 WColor convertHSVtoRGBA( double h, double s, double v )
79 {
80  const double onethird = 1.0 / 3.0;
81  const double onesixth = 1.0 / 6.0;
82  const double twothird = 2.0 / 3.0;
83  const double fivesixth = 5.0 / 6.0;
84  double r = 0.0;
85  double g = 0.0;
86  double b = 0.0;
87 
88  // compute RGB from HSV
89  if( h > onesixth && h <= onethird ) // green/red
90  {
91  g = 1.0;
92  r = ( onethird - h ) / onesixth;
93  b = 0.0;
94  }
95  else if( h > onethird && h <= 0.5 ) // green/blue
96  {
97  g = 1.0;
98  b = ( h - onethird ) / onesixth;
99  r = 0.0;
100  }
101  else if( h > 0.5 && h <= twothird ) // blue/green
102  {
103  b = 1.0;
104  g = ( twothird - h ) / onesixth;
105  r = 0.0;
106  }
107  else if( h > twothird && h <= fivesixth ) // blue/red
108  {
109  b = 1.0;
110  r = ( h - twothird ) / onesixth;
111  g = 0.0;
112  }
113  else if( h > fivesixth && h <= 1.0 ) // red/blue
114  {
115  r = 1.0;
116  b = ( 1.0 - h ) / onesixth;
117  g = 0.0;
118  }
119  else // red/green
120  {
121  r = 1.0;
122  g = h / onesixth;
123  b = 0.0;
124  }
125 
126  // add Saturation to the equation.
127  r = ( s * r + ( 1.0 - s ) ) * v;
128  g = ( s * g + ( 1.0 - s ) ) * v;
129  b = ( s * b + ( 1.0 - s ) ) * v;
130 
131  return WColor( r, g, b, 1.0f );
132 }
133 
134 WColor inverseColor( const WColor& other )
135 {
136  return WColor( std::abs( 1.0f - other[0] ), std::abs( 1.0f - other[1] ), std::abs( 1.0f - other[2] ), other[3] );
137 }
Some default colors.
Definition: WColor.cpp:36
const WColor DefaultPalette[22]
the default palette colors
Definition: WColor.cpp:38