freHueToRGBPixelAccessor.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freHueToRGBPixelAccessor.cxx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #ifndef _freHueToRGBPixelAccessor_cxx
00023 #define _freHueToRGBPixelAccessor_cxx
00024 
00025 #include "freHueToRGBPixelAccessor.h"
00026 
00027 namespace FREE
00028 {
00029 namespace Accessor
00030 {
00031 
00032   template <class T>
00033   typename HueToRGBPixelAccessor<T>::ExternalType
00034   HueToRGBPixelAccessor<T>::
00035   Get( const InternalType & input ) const
00036   {
00037     InternalType inputMod = input%360;
00038     unsigned int iColorCircleSeg = floor(input/60);
00039     
00040     float rgbProp = inputMod-360;
00041 
00042     if (inputMod<60) rgbProp = inputMod;
00043     else if (inputMod<60) rgbProp = inputMod-120;
00044     else if (inputMod<180) rgbProp = inputMod-240;
00045     else if (inputMod<300) rgbProp = inputMod-360;
00046     
00047     rgbProp = abs(rgbProp/60)*255;
00048 
00049     ExternalType rgbPixel;
00050 
00051     switch (iColorCircleSeg)
00052     {
00053     case 0:
00054       {
00055         rgbPixel[0] = 255;
00056         rgbPixel[1] = rgbProp;
00057         rgbPixel[2] = 0;
00058         break;
00059       }
00060     case 1:
00061       {
00062         rgbPixel[0] = rgbProp;
00063         rgbPixel[1] = 255;
00064         rgbPixel[2] = 0;
00065         break;
00066       }
00067     case 2:
00068       {
00069         rgbPixel[0] = 0;
00070         rgbPixel[1] = 255;
00071         rgbPixel[2] = rgbProp;
00072         break;
00073       }
00074     case 3:
00075       {
00076         rgbPixel[0] = 0;
00077         rgbPixel[1] = rgbProp;
00078         rgbPixel[2] = 255;
00079         break;
00080       }
00081     case 4:
00082       {
00083         rgbPixel[0] = rgbProp;
00084         rgbPixel[1] = 0;
00085         rgbPixel[2] = 255;
00086         break;
00087       }
00088     case 5:
00089       {
00090         rgbPixel[0] = 255;
00091         rgbPixel[1] = 0;
00092         rgbPixel[2] = rgbProp;
00093         break;
00094       }
00095     }
00096 
00097     return rgbPixel;
00098   }
00099 
00100   template <class T>
00101   void
00102   HueToRGBPixelAccessor<T>::
00103   Set( InternalType & output, const ExternalType & input ) const
00104         {
00105    double minRGB = min(min(input[0],input[1]),input[2]);
00106    double maxRGB = max(max(input[0],input[1]),input[2]);
00107    
00108    double delta = maxRGB - minRGB;
00109 
00110    double s = 0.0;
00111    double h = 0.0;
00112 
00113    if (maxRGB != 0.0) s = 255.0 * delta / maxRGB;
00114 
00115    if (s != 0.0)
00116    {
00117      if (input[0] == maxRGB)
00118      {
00119        h = (input[1] - input[2]) / delta;
00120      }
00121      else if (input[1] == maxRGB)
00122      {
00123        h = 2.0 + ((input[2] - input[0]) / delta);
00124      }
00125      else
00126      {
00127        h = 4.0 + (input[0] - input[1]) / delta;
00128      }
00129    }
00130    else
00131    {
00132      h = -1.0;
00133    }
00134 
00135    h *= 60 ;
00136 
00137    if (h < 0.0) h = h + 360.0;
00138 
00139    output = h;
00140         };
00141 
00142 } // namespace Accessor
00143 } // namespace free
00144 
00145 #endif

Generated at Sat Oct 13 16:02:18 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000