00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #include <mitkColorSequenceCycleH.h> 00018 #include <mitkColorConversions.h> 00019 00020 namespace mitk 00021 { 00022 00023 ColorSequenceCycleH::ColorSequenceCycleH() 00024 { 00025 color_h = -60.0; // after the first increase this will yield red 00026 color_s = 1.0; // full saturation 00027 color_v = 1.0; // full value 00028 color_cycle = 0; 00029 } 00030 00031 ColorSequenceCycleH::~ColorSequenceCycleH() 00032 { 00033 // nothing to do 00034 } 00035 00036 Color ColorSequenceCycleH::GetNextColor() 00037 { 00038 color_h += 60.0; 00039 if ( color_h < 0.0 ) color_h = 0.0; 00040 00041 if (color_h >= 360.0) 00042 { 00043 if ( color_cycle == 0 ) 00044 { 00045 color_h = 30.0; 00046 color_s = 1.0; 00047 color_v = 1.0; 00048 color_cycle = 1; 00049 } 00050 else if (color_cycle == 1) 00051 { 00052 color_h = 0.0; 00053 color_s = 0.5; 00054 color_v = 1.0; 00055 color_cycle = 2; 00056 } 00057 else if (color_cycle == 2) 00058 { 00059 color_h = 30.0; 00060 color_s = 0.5; 00061 color_v = 1.0; 00062 color_cycle = 3; 00063 } 00064 else if (color_cycle == 3) 00065 { 00066 color_h = 0.0; 00067 color_s = 1.0; 00068 color_v = 0.5; 00069 color_cycle = 4; 00070 } 00071 else if (color_cycle == 4) 00072 { 00073 color_h = 30.0; 00074 color_s = 1.0; 00075 color_v = 0.5; 00076 color_cycle = 5; 00077 } 00078 else if (color_cycle == 5) 00079 { 00080 color_h = 0.0; 00081 color_s = 1.0; 00082 color_v = 1.0; 00083 color_cycle = 0; 00084 } 00085 } 00086 00087 // convert to rgb 00088 float r, g, b; 00089 ColorConversions::Hsv2Rgb(color_h, color_s, color_v, r, g, b); 00090 00091 Color returnColor; 00092 returnColor.Set(r, g, b); 00093 00094 return returnColor; 00095 } 00096 00097 void ColorSequenceCycleH::GoToBegin() 00098 { 00099 color_h = -60.0; // after the first increase this will yield red 00100 color_s = 1.0; // full saturation 00101 color_v = 1.0; // full value 00102 color_cycle = 0; 00103 } 00104 00105 void ColorSequenceCycleH::ChangeHueValueByCycleSteps( int steps ) 00106 { 00107 color_h += (float)(steps*60.0); 00108 } 00109 00110 void ColorSequenceCycleH::ChangeHueValueByAbsoluteNumber( float number ) 00111 { 00112 color_h += number; 00113 } 00114 00115 void ColorSequenceCycleH::SetColorCycle( unsigned short cycle ) 00116 { 00117 if ( cycle > 5 ) cycle = 5; 00118 color_cycle = cycle; 00119 color_h = 360.0; 00120 this->GetNextColor(); 00121 00122 } 00123 00124 } // mitk 00125