OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #include <cmath> 00026 #include <string> 00027 #include <vector> 00028 00029 00030 #include "../common/exceptions/WOutOfBounds.h" 00031 #include "../common/WStringUtils.h" 00032 #include "WColor.h" 00033 00034 // initialize static palette 00035 namespace defaultColor 00036 { 00037 /** the default palette colors */ 00038 const WColor DefaultPalette[ 22 ]= { 00039 // The standard colors 00040 RED, GREEN, BLUE, YELLOW, ORANGE, PINK, CYAN, 00041 // the slightly lighter standard colors 00042 LIGHTRED, LIGHTGREEN, LIGHTBLUE, LIGHTYELLOW, 00043 // the slighly darker standard colors 00044 DARKRED, DARKGREEN, DARKBLUE, DARKYELLOW, VIOLET, TEAL, 00045 // black-white 00046 BLACK, GRAY25, GRAY50, GRAY75, WHITE 00047 }; 00048 } 00049 00050 // This function is taken from VTK 5.4.2. Since its BSD licensed the license 00051 // notice follows below. It is not taken from FAnToM since it seems more self 00052 // documenting. 00053 // 00054 // /*========================================================================= 00055 // 00056 // Program: Visualization Toolkit 00057 // Module: $RCSfile: vtkMath.cxx,v $ 00058 // 00059 // Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00060 // All rights reserved. 00061 // See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00062 // 00063 // This software is distributed WITHOUT ANY WARRANTY; without even 00064 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00065 // PURPOSE. See the above copyright notice for more information. 00066 // 00067 // ========================================================================= 00068 // Copyright 2005 Sandia Corporation. 00069 // Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00070 // license for use of this work by or on behalf of the 00071 // U.S. Government. Redistribution and use in source and binary forms, with 00072 // or without modification, are permitted provided that this Notice and any 00073 // statement of authorship are reproduced on all copies. 00074 // 00075 // Contact: pppebay@sandia.gov,dcthomp@sandia.gov, 00076 // 00077 // =========================================================================*/ 00078 WColor convertHSVtoRGBA( double h, double s, double v ) 00079 { 00080 const double onethird = 1.0 / 3.0; 00081 const double onesixth = 1.0 / 6.0; 00082 const double twothird = 2.0 / 3.0; 00083 const double fivesixth = 5.0 / 6.0; 00084 double r = 0.0; 00085 double g = 0.0; 00086 double b = 0.0; 00087 00088 // compute RGB from HSV 00089 if( h > onesixth && h <= onethird ) // green/red 00090 { 00091 g = 1.0; 00092 r = ( onethird - h ) / onesixth; 00093 b = 0.0; 00094 } 00095 else if( h > onethird && h <= 0.5 ) // green/blue 00096 { 00097 g = 1.0; 00098 b = ( h - onethird ) / onesixth; 00099 r = 0.0; 00100 } 00101 else if( h > 0.5 && h <= twothird ) // blue/green 00102 { 00103 b = 1.0; 00104 g = ( twothird - h ) / onesixth; 00105 r = 0.0; 00106 } 00107 else if( h > twothird && h <= fivesixth ) // blue/red 00108 { 00109 b = 1.0; 00110 r = ( h - twothird ) / onesixth; 00111 g = 0.0; 00112 } 00113 else if( h > fivesixth && h <= 1.0) // red/blue 00114 { 00115 r = 1.0; 00116 b = ( 1.0 - h ) / onesixth; 00117 g = 0.0; 00118 } 00119 else // red/green 00120 { 00121 r = 1.0; 00122 g = h / onesixth; 00123 b = 0.0; 00124 } 00125 00126 // add Saturation to the equation. 00127 r = ( s * r + ( 1.0 - s ) ) * v; 00128 g = ( s * g + ( 1.0 - s ) ) * v; 00129 b = ( s * b + ( 1.0 - s ) ) * v; 00130 00131 return WColor( r, g, b, 1.0f ); 00132 } 00133 00134 WColor inverseColor( const WColor& other ) 00135 { 00136 return WColor( std::abs( 1.0f - other[0] ), std::abs( 1.0f - other[1] ), std::abs( 1.0f - other[2] ), other[3] ); 00137 }