OpenWalnut
1.2.5
|
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 #include <boost/lexical_cast.hpp> 00030 00031 #include "../common/exceptions/WOutOfBounds.h" 00032 #include "../common/WStringUtils.h" 00033 #include "WColor.h" 00034 00035 // This function is taken from VTK 5.4.2. Since its BSD licensed the license 00036 // notice follows below. It is not taken from FAnToM since it seems more self 00037 // documenting. 00038 // 00039 // /*========================================================================= 00040 // 00041 // Program: Visualization Toolkit 00042 // Module: $RCSfile: vtkMath.cxx,v $ 00043 // 00044 // Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00045 // All rights reserved. 00046 // See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00047 // 00048 // This software is distributed WITHOUT ANY WARRANTY; without even 00049 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00050 // PURPOSE. See the above copyright notice for more information. 00051 // 00052 // ========================================================================= 00053 // Copyright 2005 Sandia Corporation. 00054 // Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00055 // license for use of this work by or on behalf of the 00056 // U.S. Government. Redistribution and use in source and binary forms, with 00057 // or without modification, are permitted provided that this Notice and any 00058 // statement of authorship are reproduced on all copies. 00059 // 00060 // Contact: pppebay@sandia.gov,dcthomp@sandia.gov, 00061 // 00062 // =========================================================================*/ 00063 WColor convertHSVtoRGBA( double h, double s, double v ) 00064 { 00065 const double onethird = 1.0 / 3.0; 00066 const double onesixth = 1.0 / 6.0; 00067 const double twothird = 2.0 / 3.0; 00068 const double fivesixth = 5.0 / 6.0; 00069 double r = 0.0; 00070 double g = 0.0; 00071 double b = 0.0; 00072 00073 // compute RGB from HSV 00074 if( h > onesixth && h <= onethird ) // green/red 00075 { 00076 g = 1.0; 00077 r = ( onethird - h ) / onesixth; 00078 b = 0.0; 00079 } 00080 else if( h > onethird && h <= 0.5 ) // green/blue 00081 { 00082 g = 1.0; 00083 b = ( h - onethird ) / onesixth; 00084 r = 0.0; 00085 } 00086 else if( h > 0.5 && h <= twothird ) // blue/green 00087 { 00088 b = 1.0; 00089 g = ( twothird - h ) / onesixth; 00090 r = 0.0; 00091 } 00092 else if( h > twothird && h <= fivesixth ) // blue/red 00093 { 00094 b = 1.0; 00095 r = ( h - twothird ) / onesixth; 00096 g = 0.0; 00097 } 00098 else if( h > fivesixth && h <= 1.0) // red/blue 00099 { 00100 r = 1.0; 00101 b = ( 1.0 - h ) / onesixth; 00102 g = 0.0; 00103 } 00104 else // red/green 00105 { 00106 r = 1.0; 00107 g = h / onesixth; 00108 b = 0.0; 00109 } 00110 00111 // add Saturation to the equation. 00112 r = ( s * r + ( 1.0 - s ) ) * v; 00113 g = ( s * g + ( 1.0 - s ) ) * v; 00114 b = ( s * b + ( 1.0 - s ) ) * v; 00115 00116 return WColor( r, g, b, 1.0f ); 00117 } 00118 00119 WColor inverseColor( const WColor& other ) 00120 { 00121 return WColor( std::abs( 1.0f - other[0] ), std::abs( 1.0f - other[1] ), std::abs( 1.0f - other[2] ), other[3] ); 00122 }