Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Math/Histogram.h

Go to the documentation of this file.
00001 /**
00002  * @file Histogram.h
00003  *
00004  * The file defines a struct to represent histograms.
00005  * 
00006  * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a>
00007 */
00008 
00009 #ifndef __Histogram_h__
00010 #define __Histogram_h__
00011 
00012 #include "Tools/Streams/InOut.h"
00013 #include <string.h>
00014 #include "Tools/Debugging/Debugging.h"
00015 #include "Platform/GTAssert.h"
00016 
00017 /**
00018  * A struct to represent histograms
00019  */
00020 class Histogram
00021 {
00022 public:
00023   enum HistogramID
00024   {
00025     noID,
00026     imageIntensityY,
00027     imageIntensityU,
00028     imageIntensityV,
00029     scanLineIntensityY,
00030     scanLineIntensityU,
00031     scanLineIntensityV,
00032     colorFrequency,
00033     lengthOfSegments,
00034     numberOfHistogramIDs
00035   };
00036 
00037   static const char* getName(HistogramID histogramID)
00038   {
00039     switch(histogramID)
00040     {
00041     case noID: return "no histogram";
00042     case imageIntensityY: return "image intensity y";
00043     case imageIntensityU: return "image intensity u";
00044     case imageIntensityV: return "image intensity v";
00045     case scanLineIntensityY: return "scan line intensity y";
00046     case scanLineIntensityU: return "scan line intensity u";
00047     case scanLineIntensityV: return "scan line intensity v";
00048     case colorFrequency: return "color frequency";
00049     case lengthOfSegments: return "length of segments";
00050     default: return "Please edit Histogram::getName() !";
00051     }
00052   }
00053   
00054   static DebugKeyTable::debugKeyID getDebugKeyID(HistogramID histogramID)
00055   {
00056     switch(histogramID)
00057     {
00058     case imageIntensityY: return DebugKeyTable::sendHistogram_imageIntensityY;
00059     case imageIntensityU: return DebugKeyTable::sendHistogram_imageIntensityU;
00060     case imageIntensityV: return DebugKeyTable::sendHistogram_imageIntensityV;
00061     case scanLineIntensityY: return DebugKeyTable::sendHistogram_scanLineIntensityY;
00062     case scanLineIntensityU: return DebugKeyTable::sendHistogram_scanLineIntensityU;
00063     case scanLineIntensityV: return DebugKeyTable::sendHistogram_scanLineIntensityV;
00064     case colorFrequency: return DebugKeyTable::sendHistogram_colorFrequency;
00065     case lengthOfSegments: return DebugKeyTable::sendHistogram_lengthOfSegments;
00066     default: 
00067       {
00068         ASSERT(false);
00069         return (DebugKeyTable::debugKeyID)0;
00070       }
00071     }
00072   }
00073 
00074 
00075   Histogram() { histogramID = noID; init(); }
00076   Histogram(HistogramID id) { histogramID = id; init(); }
00077 
00078   void init();
00079   void init(int numberOfEntries);
00080   void add(int index);
00081   void setID(HistogramID id) { histogramID = id; }
00082 
00083   int getValue(int index);
00084   int getNumberOfEntries();
00085 
00086   HistogramID getHistogramID();
00087 
00088   Histogram& operator=(const Histogram& other)
00089   {
00090     memcpy(value, other.value, sizeof(value));
00091     numberOfEntries = other.numberOfEntries;
00092     histogramID = other.histogramID;
00093     sum = other.sum;
00094     numberOfAddedEntries = other.numberOfAddedEntries;
00095     return *this;
00096   }
00097 
00098   double getAverage();
00099   double getAverageFrequencyOverAllEntries();
00100   double getAverageFrequencyOverUsedEntries();
00101 
00102   void analyseClusters();
00103   int getNumberOfClusters();
00104   int getBeginOfCluster(int index);
00105   int getEndOfCluster(int index);
00106 
00107 private:
00108   enum{maxNumberOfEntries = 256};
00109   int value[maxNumberOfEntries];
00110   int numberOfEntries;
00111   HistogramID histogramID;
00112 
00113   int numberOfAddedEntries;
00114   int sum;
00115 
00116   int numberOfClusters;
00117   int beginOfCluster[maxNumberOfEntries];
00118   int endOfCluster[maxNumberOfEntries];
00119 };
00120 
00121 /**
00122  * Streaming operator that reads a Histogram from a stream.
00123  * @param stream The stream from which is read.
00124  * @param histogram The Histogram object.
00125  * @return The stream.
00126  */ 
00127 In& operator>>(In& stream, Histogram& histogram);
00128  
00129 /**
00130  * Streaming operator that writes a Histogram to a stream.
00131  * @param stream The stream to write on.
00132  * @param histogram The Histogram object.
00133  * @return The stream.
00134  */ 
00135 Out& operator<<(Out& stream, Histogram& histogram);
00136 
00137 
00138 #endif // __Histogram_h__
00139 
00140 /*
00141  * Change log:
00142  * 
00143  * $Log: Histogram.h,v $
00144  * Revision 1.1.1.1  2004/05/22 17:37:11  cvsadm
00145  * created new repository GT2004_WM
00146  *
00147  * Revision 1.2  2003/10/29 13:15:02  juengel
00148  * "colorFrequency" added.
00149  *
00150  * Revision 1.1  2003/10/07 10:13:24  cvsadm
00151  * Created GT2004 (M.J.)
00152  *
00153  * Revision 1.3  2003/09/28 09:28:48  juengel
00154  * Comments corrected.
00155  *
00156  * Revision 1.2  2003/09/26 15:28:10  juengel
00157  * Renamed DataTypes to representations.
00158  *
00159  * Revision 1.1  2003/09/26 11:40:40  juengel
00160  * - sorted tools
00161  * - clean-up in DataTypes
00162  *
00163  * Revision 1.2  2003/09/02 11:15:35  dueffert
00164  * doxygen docu corrected
00165  *
00166  * Revision 1.1  2003/08/25 17:19:39  juengel
00167  * Added Histogram
00168  *
00169 */

Generated on Thu Sep 23 19:57:39 2004 for GT2004 by doxygen 1.3.6