From 8a950e9b2eac347d6fd1af351d9f714140d325cd Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 12 Oct 2010 11:18:31 +0000 Subject: [PATCH] 0020948: EDF 1468 SMESH: Histogram of the quality controls + Histogram GetHistogram() --- idl/SMESH_Filter.idl | 13 +++++++ src/Controls/SMESH_Controls.cxx | 56 ++++++++++++++++++++++++++++++ src/Controls/SMESH_ControlsDef.hxx | 3 ++ src/SMESH_I/SMESH_Filter_i.cxx | 22 ++++++++++++ src/SMESH_I/SMESH_Filter_i.hxx | 1 + 5 files changed, 95 insertions(+) diff --git a/idl/SMESH_Filter.idl b/idl/SMESH_Filter.idl index 56f2cdce2..d65ed3b46 100644 --- a/idl/SMESH_Filter.idl +++ b/idl/SMESH_Filter.idl @@ -74,6 +74,17 @@ module SMESH FT_Undefined }; + /*! + * Parameters of a reclangle of histogram + */ + struct HistogramRectangle + { + long nbEvents; + double min; + double max; + }; + typedef sequence Histogram; + /*! * Base interface for all functors ( i.e. numerical functors and predicates ) */ @@ -93,6 +104,8 @@ module SMESH { double GetValue( in long theElementId ); + Histogram GetHistogram( in short nbIntervals ); + /*! * Set precision for calculation. It is a position after point which is * used to functor value after calculation. diff --git a/src/Controls/SMESH_Controls.cxx b/src/Controls/SMESH_Controls.cxx index d8a5528dc..8e943469c 100644 --- a/src/Controls/SMESH_Controls.cxx +++ b/src/Controls/SMESH_Controls.cxx @@ -277,6 +277,62 @@ double NumericalFunctor::GetValue( long theId ) return 0.; } +//================================================================================ +/*! + * \brief Return histogram of functor values + * \param nbIntervals - number of intervals + * \param nbEvents - number of mesh elements having values within i-th interval + * \param funValues - boundaries of intervals + */ +//================================================================================ + +void NumericalFunctor::GetHistogram(int nbIntervals, + std::vector& nbEvents, + std::vector& funValues) +{ + if ( nbIntervals < 1 || + !myMesh || + !myMesh->GetMeshInfo().NbElements( GetType() )) + return; + nbEvents.resize( nbIntervals, 0 ); + funValues.resize( nbIntervals+1 ); + + // get all values sorted + std::multiset< double > values; + SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator(GetType()); + while ( elemIt->more() ) + values.insert( GetValue( elemIt->next()->GetID() )); + + // case nbIntervals == 1 + funValues[0] = *values.begin(); + funValues[nbIntervals] = *values.rbegin(); + if ( nbIntervals == 1 ) + { + nbEvents[0] = values.size(); + return; + } + // case of 1 value + if (funValues.front() == funValues.back()) + { + nbIntervals = 1; + nbEvents.resize( nbIntervals, values.size() ); + funValues.resize( nbIntervals+1); + } + // generic case + std::multiset< double >::iterator min = values.begin(), max; + for ( int i = 0; i < nbIntervals; ++i ) + { + double r = (i+1) / double( nbIntervals ); + funValues[i+1] = funValues.front() * (1-r) + funValues.back() * r; + if ( min != values.end() && *min <= funValues[i+1] ) + { + max = values.upper_bound( funValues[i+1] ); // greater than funValues[i+1], or end() + nbEvents[i] = std::distance( min, max ); + min = max; + } + } +} + //======================================================================= //function : GetValue //purpose : diff --git a/src/Controls/SMESH_ControlsDef.hxx b/src/Controls/SMESH_ControlsDef.hxx index 5849c1f83..2b7bffeba 100644 --- a/src/Controls/SMESH_ControlsDef.hxx +++ b/src/Controls/SMESH_ControlsDef.hxx @@ -127,6 +127,9 @@ 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); virtual SMDSAbs_ElementType GetType() const = 0; virtual double GetBadRate( double Value, int nbNodes ) const = 0; long GetPrecision() const; diff --git a/src/SMESH_I/SMESH_Filter_i.cxx b/src/SMESH_I/SMESH_Filter_i.cxx index 67c0addd1..c878c2db0 100644 --- a/src/SMESH_I/SMESH_Filter_i.cxx +++ b/src/SMESH_I/SMESH_Filter_i.cxx @@ -596,6 +596,28 @@ CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId ) return myNumericalFunctorPtr->GetValue( theId ); } +SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals) +{ + std::vector nbEvents; + std::vector funValues; + myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues); + + nbIntervals = CORBA::Short( std::min( nbEvents.size(), funValues.size() - 1)); + SMESH::Histogram_var histogram = new SMESH::Histogram; + if ( nbIntervals > 0 ) + { + histogram->length( nbIntervals ); + for ( int i = 0; i < nbIntervals; ++i ) + { + HistogramRectangle& rect = histogram[i]; + rect.nbEvents = nbEvents[i]; + rect.min = funValues[i]; + rect.max = funValues[i+1]; + } + } + return histogram._retn(); +} + void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision ) { myNumericalFunctorPtr->SetPrecision( thePrecision ); diff --git a/src/SMESH_I/SMESH_Filter_i.hxx b/src/SMESH_I/SMESH_Filter_i.hxx index 5451f821f..91fa638b7 100644 --- a/src/SMESH_I/SMESH_Filter_i.hxx +++ b/src/SMESH_I/SMESH_Filter_i.hxx @@ -157,6 +157,7 @@ namespace SMESH { public: CORBA::Double GetValue( CORBA::Long theElementId ); + SMESH::Histogram* GetHistogram(CORBA::Short nbIntervals); void SetPrecision( CORBA::Long thePrecision ); CORBA::Long GetPrecision(); Controls::NumericalFunctorPtr GetNumericalFunctor(); -- 2.39.2