0020948: EDF 1468 SMESH: Histogram of the quality controls

+    Histogram GetHistogram()
This commit is contained in:
eap 2010-10-12 11:18:31 +00:00
parent 52603030d5
commit 8a950e9b2e
5 changed files with 95 additions and 0 deletions

View File

@ -74,6 +74,17 @@ module SMESH
FT_Undefined FT_Undefined
}; };
/*!
* Parameters of a reclangle of histogram
*/
struct HistogramRectangle
{
long nbEvents;
double min;
double max;
};
typedef sequence<HistogramRectangle> Histogram;
/*! /*!
* Base interface for all functors ( i.e. numerical functors and predicates ) * Base interface for all functors ( i.e. numerical functors and predicates )
*/ */
@ -93,6 +104,8 @@ module SMESH
{ {
double GetValue( in long theElementId ); double GetValue( in long theElementId );
Histogram GetHistogram( in short nbIntervals );
/*! /*!
* Set precision for calculation. It is a position after point which is * Set precision for calculation. It is a position after point which is
* used to functor value after calculation. * used to functor value after calculation.

View File

@ -277,6 +277,62 @@ double NumericalFunctor::GetValue( long theId )
return 0.; 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<int>& nbEvents,
std::vector<double>& 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 //function : GetValue
//purpose : //purpose :

View File

@ -127,6 +127,9 @@ namespace SMESH{
virtual void SetMesh( const SMDS_Mesh* theMesh ); virtual void SetMesh( const SMDS_Mesh* theMesh );
virtual double GetValue( long theElementId ); virtual double GetValue( long theElementId );
virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;}; virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
void GetHistogram(int nbIntervals,
std::vector<int>& nbEvents,
std::vector<double>& funValues);
virtual SMDSAbs_ElementType GetType() const = 0; virtual SMDSAbs_ElementType GetType() const = 0;
virtual double GetBadRate( double Value, int nbNodes ) const = 0; virtual double GetBadRate( double Value, int nbNodes ) const = 0;
long GetPrecision() const; long GetPrecision() const;

View File

@ -596,6 +596,28 @@ CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
return myNumericalFunctorPtr->GetValue( theId ); return myNumericalFunctorPtr->GetValue( theId );
} }
SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals)
{
std::vector<int> nbEvents;
std::vector<double> 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 ) void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
{ {
myNumericalFunctorPtr->SetPrecision( thePrecision ); myNumericalFunctorPtr->SetPrecision( thePrecision );

View File

@ -157,6 +157,7 @@ namespace SMESH
{ {
public: public:
CORBA::Double GetValue( CORBA::Long theElementId ); CORBA::Double GetValue( CORBA::Long theElementId );
SMESH::Histogram* GetHistogram(CORBA::Short nbIntervals);
void SetPrecision( CORBA::Long thePrecision ); void SetPrecision( CORBA::Long thePrecision );
CORBA::Long GetPrecision(); CORBA::Long GetPrecision();
Controls::NumericalFunctorPtr GetNumericalFunctor(); Controls::NumericalFunctorPtr GetNumericalFunctor();