From 938bc72f7a29fe9b9c18b4876e670c88aa88c2bf Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 22 Nov 2010 17:48:38 +0000 Subject: [PATCH] 0020948]: EDF 1468 SMESH: Histogram of the quality controls Add arg to limit range of values void GetHistogram(int nbIntervals, std::vector& nbEvents, std::vector& funValues, const std::vector& elements, + const double* minmax=0); --- src/Controls/SMESH_Controls.cxx | 24 ++++++++++++++++++++---- src/Controls/SMESH_ControlsDef.hxx | 9 +++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Controls/SMESH_Controls.cxx b/src/Controls/SMESH_Controls.cxx index b13588de6..ff91ae732 100644 --- a/src/Controls/SMESH_Controls.cxx +++ b/src/Controls/SMESH_Controls.cxx @@ -284,13 +284,15 @@ double NumericalFunctor::GetValue( long theId ) * \param nbEvents - number of mesh elements having values within i-th interval * \param funValues - boundaries of intervals * \param elements - elements to check vulue of; empty list means "of all" + * \param minmax - boundaries of diapason of values to divide into intervals */ //================================================================================ void NumericalFunctor::GetHistogram(int nbIntervals, std::vector& nbEvents, std::vector& funValues, - const vector& elements) + const vector& elements, + const double* minmax) { if ( nbIntervals < 1 || !myMesh || @@ -314,9 +316,17 @@ void NumericalFunctor::GetHistogram(int nbIntervals, values.insert( GetValue( *id )); } + if ( minmax ) + { + funValues[0] = minmax[0]; + funValues[nbIntervals] = minmax[1]; + } + else + { + funValues[0] = *values.begin(); + funValues[nbIntervals] = *values.rbegin(); + } // case nbIntervals == 1 - funValues[0] = *values.begin(); - funValues[nbIntervals] = *values.rbegin(); if ( nbIntervals == 1 ) { nbEvents[0] = values.size(); @@ -334,15 +344,21 @@ void NumericalFunctor::GetHistogram(int nbIntervals, std::multiset< double >::iterator min = values.begin(), max; for ( int i = 0; i < nbIntervals; ++i ) { + // find end value of i-th interval double r = (i+1) / double( nbIntervals ); funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r; + + // count values in the i-th interval if there are any if ( min != values.end() && *min <= funValues[i+1] ) { - max = values.upper_bound( funValues[i+1] ); // greater than funValues[i+1], or end() + // find the first value out of the interval + max = values.upper_bound( funValues[i+1] ); // max is greater than funValues[i+1], or end() nbEvents[i] = std::distance( min, max ); min = max; } } + // add values larger than minmax[1] + nbEvents.back() += std::distance( min, values.end() ); } //======================================================================= diff --git a/src/Controls/SMESH_ControlsDef.hxx b/src/Controls/SMESH_ControlsDef.hxx index 46255a26a..8a183d5b5 100644 --- a/src/Controls/SMESH_ControlsDef.hxx +++ b/src/Controls/SMESH_ControlsDef.hxx @@ -127,10 +127,11 @@ namespace SMESH{ virtual void SetMesh( const SMDS_Mesh* theMesh ); virtual double GetValue( long theElementId ); virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;}; - void GetHistogram(int nbIntervals, - std::vector& nbEvents, - std::vector& funValues, - const std::vector& elements); + void GetHistogram(int nbIntervals, + std::vector& nbEvents, + std::vector& funValues, + const std::vector& elements, + const double* minmax=0); virtual SMDSAbs_ElementType GetType() const = 0; virtual double GetBadRate( double Value, int nbNodes ) const = 0; long GetPrecision() const;