00001 #ifndef __HISTOGRAM_H__ 00002 #define __HISTOGRAM_H__ 00003 00004 #include <stdio.h> 00005 #include <stdint.h> 00006 #include <math.h> 00007 00008 #include "avltree.h" 00009 00010 namespace bilateral 00011 { 00012 00013 class SubHistogram 00014 { 00015 public: 00016 SubHistogram(); 00017 00018 virtual ~SubHistogram(); 00019 00020 bool AddValue(int64_t val, int64_t square, int64_t cube); 00021 bool RemoveValue(int64_t val); 00022 void Clear(void); 00023 00024 void GetSums(int64_t min, int64_t max, 00025 int64_t &sum, 00026 int64_t &sum_squares, 00027 int64_t &sum_cubes, 00028 uint32_t &count) const; 00029 private: 00030 Node *m_tree; 00031 }; 00032 00033 00034 const uint32_t NUM_LAYERS = 5; 00035 00036 class BoxHistogram 00037 { 00038 public: 00039 BoxHistogram(uint32_t width, uint32_t diameter); 00040 ~BoxHistogram(); 00041 00042 bool AddValue(uint32_t x, float val); 00043 bool RemoveValue(uint32_t x, float val); 00044 void Clear(void); 00045 00046 void GetSums(uint32_t xmin, uint32_t xmax, 00047 float min, float max, 00048 float &sum, 00049 float &sum_squares, 00050 float &sum_cubes, 00051 uint32_t &count) const; 00052 private: 00053 uint32_t GetLayerSize(uint32_t layer) const; 00054 00055 SubHistogram *m_layers[NUM_LAYERS]; 00056 uint32_t m_count[NUM_LAYERS]; 00057 uint32_t m_masks[NUM_LAYERS]; 00058 uint32_t m_width; 00059 uint32_t m_use_layers; 00060 }; 00061 00062 } 00063 #endif 00064