diqtctab.h

00001 /*
00002  *
00003  *  Copyright (C) 2002-2005, OFFIS
00004  *
00005  *  This software and supporting documentation were developed by
00006  *
00007  *    Kuratorium OFFIS e.V.
00008  *    Healthcare Information and Communication Systems
00009  *    Escherweg 2
00010  *    D-26121 Oldenburg, Germany
00011  *
00012  *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
00013  *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
00014  *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
00015  *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
00016  *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
00017  *
00018  *  Module:  dcmimage
00019  *
00020  *  Author:  Marco Eichelberg
00021  *
00022  *  Purpose: class DcmQuantColorTable
00023  *
00024  *  Last Update:      $Author: meichel $
00025  *  Update Date:      $Date: 2005/12/08 16:01:45 $
00026  *  CVS/RCS Revision: $Revision: 1.6 $
00027  *  Status:           $State: Exp $
00028  *
00029  *  CVS/RCS Log at end of file
00030  *
00031  */
00032 
00033 
00034 #ifndef DIQTCTAB_H
00035 #define DIQTCTAB_H
00036 
00037 #include "dcmtk/config/osconfig.h"
00038 #include "dcmtk/ofstd/oftypes.h"   /* for OFBool */
00039 #include "dcmtk/ofstd/ofcond.h"    /* for OFCondition */
00040 #include "dcmtk/dcmimage/diqtpix.h"   /* for DcmQuantPixel */
00041 #include "dcmtk/dcmimage/diqthash.h"  /* for DcmQuantHistogramItem */
00042 #include "dcmtk/ofstd/ofstring.h"  /* for class OFString */
00043 
00044 
00045 class DicomImage;
00046 class DcmItem;
00047 
00048 
00052 class DcmQuantColorTable
00053 {
00054 public:
00055 
00057   DcmQuantColorTable();
00058 
00060   ~DcmQuantColorTable();
00061 
00063   void clear();
00064 
00068   inline unsigned long getColors() const
00069   {
00070     return numColors;
00071   }
00072 
00077   void setDescriptionString(OFString& str) const;
00078 
00088   OFCondition computeHistogram(DicomImage& image, unsigned long maxcolors);
00089 
00094   inline unsigned long getMaxVal() const
00095   {
00096     return maxval;
00097   }
00098 
00103   inline const DcmQuantPixel& getPixel(unsigned long idx) const
00104   {
00105 #ifdef DEBUG
00106     assert(array && idx < numColors);
00107 #endif
00108     return *(array[idx]);
00109   }
00110 
00115   inline DcmQuantComponent getRed(unsigned long idx) const
00116   {
00117 #ifdef DEBUG
00118     assert(array && idx < numColors);
00119 #endif
00120     return array[idx]->getRed();
00121   }
00122 
00127   inline DcmQuantComponent getGreen(unsigned long idx) const
00128   {
00129 #ifdef DEBUG
00130     assert(array && idx < numColors);
00131 #endif
00132     return array[idx]->getGreen();
00133   }
00134 
00139   inline DcmQuantComponent getBlue(unsigned long idx) const
00140   {
00141 #ifdef DEBUG
00142     assert(array && idx < numColors);
00143 #endif
00144     return array[idx]->getBlue();
00145   }
00146 
00162   OFCondition medianCut(
00163     DcmQuantColorTable& histogram,
00164     unsigned long sum,
00165     unsigned long theMaxval,
00166     unsigned long numberOfColors,
00167     DcmLargestDimensionType largeType,
00168     DcmRepresentativeColorType repType);
00169 
00174   inline int computeIndex(const DcmQuantPixel& px) const
00175   {
00176     int result = -1;
00177     register int r2, g2, b2;
00178     register long newdist;
00179     register int r1 = OFstatic_cast(int, px.getRed());
00180     register int g1 = OFstatic_cast(int, px.getGreen());
00181     register int b1 = OFstatic_cast(int, px.getBlue());
00182     register long dist = 2000000000;
00183     for (unsigned long i = 0; i < numColors; ++i)
00184     {
00185         r2 = r1 - OFstatic_cast(int, array[i]->getRed());
00186         g2 = g1 - OFstatic_cast(int, array[i]->getGreen());
00187         b2 = b1 - OFstatic_cast(int, array[i]->getBlue());
00188         newdist = r2*r2 + g2*g2 + b2*b2;
00189         if (newdist < dist)
00190         {
00191             result = OFstatic_cast(int, i);
00192             dist = newdist;
00193             if (dist < array[i]->getValue()) i=numColors; // break out of for loop
00194         }
00195     }
00196     return result;
00197   }
00198 
00208   OFCondition write(
00209     DcmItem& target,
00210     OFBool writeAsOW,
00211     OFBool write16BitEntries);
00212 
00213 
00214 private:
00215 
00222   void computeClusters();
00223 
00225   DcmQuantColorTable(const DcmQuantColorTable& src);
00226 
00228   DcmQuantColorTable& operator=(const DcmQuantColorTable& src);
00229 
00231   DcmQuantHistogramItemPointer *array;
00232 
00234   unsigned long numColors;
00235 
00239   unsigned long maxval;
00240 
00241 };
00242 
00243 #endif
00244 
00245 
00246 /*
00247  * CVS/RCS Log:
00248  * $Log: diqtctab.h,v $
00249  * Revision 1.6  2005/12/08 16:01:45  meichel
00250  * Changed include path schema for all DCMTK header files
00251  *
00252  * Revision 1.5  2003/12/23 12:15:40  joergr
00253  * Adapted type casts to new-style typecast operators defined in ofcast.h.
00254  * Updated copyright header.
00255  *
00256  * Revision 1.4  2003/07/04 13:25:40  meichel
00257  * Replaced forward declarations for OFString with explicit includes,
00258  *   needed when compiling with HAVE_STD_STRING
00259  *
00260  * Revision 1.3  2003/06/12 15:09:41  joergr
00261  * Fixed inconsistent API documentation reported by Doxygen.
00262  *
00263  * Revision 1.2  2002/05/15 09:53:29  meichel
00264  * Minor corrections to avoid warnings on Sun CC 2.0.1
00265  *
00266  * Revision 1.1  2002/01/25 13:32:04  meichel
00267  * Initial release of new color quantization classes and
00268  *   the dcmquant tool in module dcmimage.
00269  *
00270  *
00271  */


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5