00001 #ifndef SAUPEPREDICTOR_HEADER_
00002 #define SAUPEPREDICTOR_HEADER_
00003
00004 #include "../headers.h"
00005 #include "../kdTree.h"
00006
00008
00013 class MSaupePredictor: public IStdEncPredictor {
00014 DECLARE_debugModule;
00015
00016 DECLARE_TypeInfo( MSaupePredictor, "Saupe predictor"
00017 , "Predictor for standard encoder using multi-dimensional nearest neighbour search"
00018 , {
00019 label: "Prediction chunk size",
00020 desc: "The number of predicted domains in a chunk",
00021 type: settingInt(1,16,64)
00022 }, {
00023 label: "Max. predicted part",
00024 desc: "The maximal part of domains predicted for a range block",
00025 type: settingInt(-20,-8,0,IntLog2)
00026 } )
00027
00028 protected:
00030 enum Settings { ChunkSize, MaxPredPart };
00031
00033 Real maxPredCoeff() { return ldexp( Real(1), settingsInt(MaxPredPart) ); }
00034
00035 public:
00036 typedef float KDReal;
00037 typedef KDTree<KDReal> Tree;
00038 protected:
00039
00040 std::vector<Tree*> levelTrees;
00041 #ifndef NDEBUG // the stats about the domain counts predicted
00042 long predicted, maxpred;
00043 #endif
00044
00045 protected:
00046
00047 #ifndef NDEBUG
00048 MSaupePredictor(): predicted(0), maxpred(0) {}
00049 #endif
00050
00051 ~MSaupePredictor() { cleanUp(); }
00052
00053 public:
00056 IOneRangePredictor* newPredictor(const NewPredictorData &data);
00057
00058 void cleanUp() {
00059 clearContainer(levelTrees);
00060 levelTrees.clear();
00061 }
00063
00064 protected:
00066 int getPredLevel(int ) const
00067 { return 2; }
00068
00070 Tree* createTree(const NewPredictorData &data);
00071
00073 static void refineDomain( const SummedPixels &pixMatrix, int x0, int y0
00074 , bool allowInversion, int realLevel, int predLevel, SReal *pixelResult );
00076 static void refineRange
00077 ( const NewPredictorData &data, int predLevel, SReal *pixelResult );
00078
00079
00080 protected:
00082 class OneRangePredictor: public IOneRangePredictor {
00083 friend class MSaupePredictor;
00084
00086 struct HeapInfo {
00087 int index;
00088 float bestError;
00089
00091 HeapInfo(int index_,float bestError_)
00092 : index(index_), bestError(bestError_) {}
00093
00095 bool operator<(const HeapInfo &other) const
00096 { return bestError>other.bestError; }
00097 };
00098
00100 class SEnormalizator {
00101 Real errorAccel;
00102 public:
00104 void initialize(const NewPredictorData &data,int predLevel) {
00105 int shift= 2 * (predLevel - data.rangeBlock->level);
00106 errorAccel= ldexp( data.pixCount/data.rnDev2, shift );
00107
00108 }
00110 Real normSE(Real error) const {
00111 Real result= std::ldexp( 1-sqrt(1-error*errorAccel), 1 );
00112 if ( isNaN(result) )
00113 result= numeric_limits<Real>::infinity();
00114 return result;
00115 }
00116 } errorNorm;
00117
00118 typedef Tree::PointHeap PointHeap;
00119 protected:
00120 std::vector<PointHeap*> heaps;
00121 std::vector<HeapInfo> infoHeap;
00122 KDReal *points;
00123 int chunkSize
00124 , predsRemain
00125 , heapCount;
00126 bool firstChunk
00127 , allowRotations
00128 , isRegular;
00129
00130 DEBUG_ONLY( public: long *predicted; )
00131
00132 protected:
00134 OneRangePredictor( const NewPredictorData &data, int chunkSize_
00135 , const Tree &tree, int maxPredicts );
00136 public:
00139 Predictions& getChunk(float maxPredictedSE,Predictions &store);
00140 ~OneRangePredictor() {
00141 clearContainer(heaps);
00142 delete[] points;
00143 }
00145 };
00146 };
00147
00148 #endif // SAUPEPREDICTOR_HEADER_