From e29480edf1d6ff4f4cd18b2b9e7dabf3520c70ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Thu, 25 Jun 2009 18:50:37 +0200 Subject: [PATCH] Fixed cstring include in kdTree.h, some infinity and comment stuff. --- kdTree.h | 4 ++++ modules/quadTree.cpp | 2 +- modules/saupePredictor.cpp | 25 ++++++++++++------------- modules/saupePredictor.h | 36 ++++++++++++++++++++---------------- modules/stdEncoder.cpp | 4 ++-- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/kdTree.h b/kdTree.h index da239d2..eea417e 100644 --- a/kdTree.h +++ b/kdTree.h @@ -1,6 +1,10 @@ #ifndef KDTREE_HEADER_ #define KDTREE_HEADER_ +#ifdef NDEBUG + #include // memcpy +#endif + namespace NOSPACE { using namespace std; } diff --git a/modules/quadTree.cpp b/modules/quadTree.cpp index c1b2de8..2733483 100644 --- a/modules/quadTree.cpp +++ b/modules/quadTree.cpp @@ -9,7 +9,7 @@ struct MQuadTree::NodeExtremes { int min, max; NodeExtremes() - : min( numeric_limits::max() ), max( numeric_limits::min() ) {} + : min( numeric_limits::infinity() ), max( -numeric_limits::infinity() ) {} void operator()(const MQuadTree::RangeNode *node) { int now= node->level; if (nowcount); if (maxPredicts<=0) maxPredicts= 1; - OneRangePredictor *result= - new OneRangePredictor(data,settingsInt(ChunkSize),*tree,maxPredicts); - - - #ifndef NDEBUG - maxpred+= tree->count*(data.allowRotations?8:1)*(data.allowInversion?2:1); - result->predicted= &predicted; + new OneRangePredictor( data, settingsInt(ChunkSize), *tree, maxPredicts ); + + #ifndef NDEBUG // collecting debugging stats + maxpred+= tree->count*(data.allowRotations?8:1)*(data.allowInversion?2:1); + result->predicted= &predicted; #endif return result; @@ -56,14 +54,14 @@ MSaupePredictor::Tree* MSaupePredictor::createTree(const NewPredictorData &data) // compute the average and standard deviation (data needed for normalization) Real sum, sum2; pool.getSums(x0,y0,x0+sideLength,y0+sideLength).unpack(sum,sum2); + Real avg= ldexp(sum,-2*level); // the same as = 1 / sqrt( sum2 - sqr(sum)/pixelCount ) ); Real multiply= 1 / sqrt( sum2 - sqr(ldexp(sum,-level)) ); if ( !finite(multiply) ) multiply= 1; // it would be better not to add the domains into the tree - // if inversion is allowed and the first pixel is below zero then invert the block - //if ( data.allowInversion && *domPixNow < 0 ) - // multiply= -multiply; - Real avg= ldexp(sum,-2*level); + // if inversion is allowed and the first pixel is below average, then invert the block + if ( data.allowInversion && *domPixNow < avg ) + multiply= -multiply; MatrixWalkers::AddMulCopy oper( -avg, multiply ); // copy every column of the domain's pixels (and normalize them on the way) using namespace FieldMath; @@ -85,6 +83,7 @@ MSaupePredictor::Tree* MSaupePredictor::createTree(const NewPredictorData &data) } namespace NOSPACE { + /** Transformer performing an affine function */ template struct AddMulCopyTo2nd { T toAdd, toMul; @@ -95,7 +94,7 @@ namespace NOSPACE { { res= (f+toAdd)*toMul; } void innerEnd() const {} }; - + /** Transformer performing sign change */ struct SignChanger { template void operator()(R1 in,R2 &out) const { out= -in; } diff --git a/modules/saupePredictor.h b/modules/saupePredictor.h index 9ba6d1b..96dbc3f 100644 --- a/modules/saupePredictor.h +++ b/modules/saupePredictor.h @@ -20,7 +20,7 @@ class MSaupePredictor: public IStdEncPredictor { type: settingFloat(0,5,100) } ) -private: +protected: /** Indices for settings */ enum Settings { ChunkSize, MaxPredPercent }; @@ -30,7 +30,7 @@ private: public: typedef float KDReal; ///< The floating point type used in the KD-tree typedef KDTree Tree;///< The version of KDTree in use -private: +protected: // Module's data std::vector levelTrees; ///< The predicting Tree for every level (can be missing) #ifndef NDEBUG @@ -48,19 +48,23 @@ public: /** \name IStdEncPredictor interface * @{ */ IOneRangePredictor* newPredictor(const NewPredictorData &data); + void cleanUp() { clearContainer(levelTrees); levelTrees.clear(); } /// @} -private: +protected: /** Builds a new tree for one level of range blocks using passed domain blocks */ Tree* createTree(const NewPredictorData &data); -private: + +protected: /** Implementation of the one-range-predictor from IStdEncPredictor interface */ class OneRangePredictor: public IOneRangePredictor { + friend class MSaupePredictor; + /** Struct representing one node of the KD-tree and its distance form the range block */ struct HeapInfo { int index; ///< The index of the node in the tree @@ -70,46 +74,46 @@ private: HeapInfo(int index_,float bestError_) : index(index_), bestError(bestError_) {} - /** Reverse comparison operator according to the #bestError (lowest first) */ + /** Reverse comparison operator according to the ::bestError (lowest first) */ bool operator<(const HeapInfo &other) const { return bestError>other.bestError; } }; class SEnormalizator { - Real errorAccel; /// Accelerator for conversion of SEs to the real values + Real errorAccel; ///< Accelerator for conversion of SEs to the real values public: - /** Initializes the normalizator for a range block, needed to call #normSE */ + /** Initializes the normalizator for a range block, needed to call ::normSE */ void initialize(const NewPredictorData &data) { errorAccel= data.pixCount / data.rnDev2; } - /** Computes normalized-tree-error from real SE (#initialize has been called) */ + /** Computes normalized-tree-error from real SE (::initialize has been called) */ Real normSE(Real error) const { Real result= std::ldexp( 1-sqrt(1-error*errorAccel), 1 ); if ( isNaN(result) ) - result= numeric_limits::max(); + result= numeric_limits::infinity(); return result; } - } errorNorm; + } errorNorm; ///< used to compute SE in the normalized space (from normal SE) typedef Tree::PointHeap PointHeap; - + protected: std::vector heaps; ///< Pointers to the heaps for every rotation and inversion - std::vector infoHeap; ///< Heap built from #heaps according to their best SEs + std::vector infoHeap; ///< Heap built from ::heaps according to their best SEs KDReal *points; ///< Normalized range rotations and inversions used by the heaps (owned) int chunkSize /// The suggested count for predicted ranges returned at once - , predsRemain /// Max. remaining count of predictions to be returned + , predsRemain /// Max.\ remaining count of predictions to be returned , heapCount; ///< The number of heaps bool firstChunk /// True if nothing has been predicted yet, false otherwise - , allowRotations/// NewPredictorData::allowRotations + , allowRotations/// Like NewPredictorData::allowRotations , isRegular; ///< Indicates regularity of the range block (see RangeNode::isRegular) DEBUG_ONLY( public: long *predicted; ) - public: + protected: /** Creates a new predictor for a range block (prepares tree-heaps, etc.) */ OneRangePredictor( const NewPredictorData &data, int chunkSize_ , const Tree &tree, int maxPredicts ); - + public: /** \name IOneRangePredictor interface * @{ */ Predictions& getChunk(float maxPredictedSE,Predictions &store); diff --git a/modules/stdEncoder.cpp b/modules/stdEncoder.cpp index 0b28143..720e011 100644 --- a/modules/stdEncoder.cpp +++ b/modules/stdEncoder.cpp @@ -176,7 +176,7 @@ namespace NOSPACE { /** Only initializes ::error to the maximum float value */ BestInfo() - : Prediction(), error( numeric_limits::max() ) {} + : Prediction(), error( numeric_limits::infinity() ) {} /** Only returns reference to *this typed as IStdEncPredictor::Prediciton */ IStdEncPredictor::Prediction& prediction() { return *this; } @@ -389,7 +389,7 @@ float MStdEncoder::findBestSE(const RangeNode &range,bool allowHigherSE) { : plSet->moduleQ2SE->rangeSE( plSet->quality, range.size() ); ASSERT(info.targetSE>=0); if (allowHigherSE) - info.best.error= numeric_limits::max(); + info.best.error= numeric_limits::infinity(); info.selectExactCompareProc(); { // a goto-skippable block -- 2.11.4.GIT