0021840: [CEA 655] Scalar bar: using a logarithmic scale

This commit is contained in:
jfa 2013-02-08 12:40:16 +00:00
parent 86a9f36ce4
commit aea880cf9e
13 changed files with 238 additions and 180 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -7,8 +7,12 @@ In this dialog you can specify the properties of the scalar bar
\image html scalar_bar_dlg.png
<ul>
<li><b>Scalar Range</b> in this menu you can specify
<b>Min value</b> and <b>Max value</b> of the <b>Scalar Bar</b> </li>
<li><b>Scalar Range</b> - in this menu you can specify
<b>Min value</b> and <b>Max value</b> of the <b>Scalar Bar</b>, and
also you can turn on/off <b>Logarithmic</b> scaling of the scalar bar.</li>
\note <b>Logarithmic scale</b> is not applicable in case of
negative and zero values in the range. In such cases it is disabled.
<li><b>Font</b> - in this menu you can set type, face and color for
the font of <b>Title</b> and <b>Labels</b> of the <b>Scalar
@ -29,7 +33,7 @@ location (<b>X</b> and <b>Y</b>) and size (<b>Width</b> and
side)</li>
<li><b>Y</b>: ordinate of the origin (from the bottom)</li>
</ul>
<li><b>Distribution</b> in this menu you can Show/Hide distribution histogram of the values of the <b>Scalar Bar</b> and specify histogram properties</li>
<li><b>Distribution</b> - in this menu you can Show/Hide distribution histogram of the values of the <b>Scalar Bar</b> and specify histogram properties</li>
<ul>
<li><b>Multicolor</b> the histogram is colored as <b>Scalar Bar</b></li>
<li><b>Monocolor</b> the histogram is colored as selected with <b>Distribution color</b> selector</li>

View File

@ -115,7 +115,7 @@ module SMESH
{
double GetValue( in long theElementId );
Histogram GetHistogram( in short nbIntervals );
Histogram GetHistogram( in short nbIntervals, in boolean isLogarithmic );
/*!
* Set precision for calculation. It is a position after point which is

View File

@ -18,7 +18,6 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "SMESH_ControlsDef.hxx"
@ -322,12 +321,12 @@ double NumericalFunctor::Round( const double & aVal )
* \param minmax - boundaries of diapason of values to divide into intervals
*/
//================================================================================
void NumericalFunctor::GetHistogram(int nbIntervals,
std::vector<int>& nbEvents,
std::vector<double>& funValues,
const vector<int>& elements,
const double* minmax)
const double* minmax,
const bool isLogarithmic)
{
if ( nbIntervals < 1 ||
!myMesh ||
@ -381,7 +380,14 @@ void NumericalFunctor::GetHistogram(int nbIntervals,
{
// find end value of i-th interval
double r = (i+1) / double(nbIntervals);
if (isLogarithmic && funValues.front() > 1e-07 && funValues.back() > 1e-07) {
double logmin = log10(funValues.front());
double lval = logmin + r * (log10(funValues.back()) - logmin);
funValues[i+1] = pow(10.0, lval);
}
else {
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] )

View File

@ -125,7 +125,8 @@ namespace SMESH{
std::vector<int>& nbEvents,
std::vector<double>& funValues,
const std::vector<int>& elements,
const double* minmax=0);
const double* minmax=0,
const bool isLogarithmic = false);
virtual SMDSAbs_ElementType GetType() const = 0;
virtual double GetBadRate( double Value, int nbNodes ) const = 0;
long GetPrecision() const;

View File

@ -18,13 +18,12 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH OBJECT : interactive object for SMESH visualization
// File : SMESH_Actor.cxx
// Author : Nicolas REJNERI
// Module : SMESH
//
#include "SMESH_ActorDef.h"
#include "SMESH_ActorUtils.h"
#include "SMESH_DeviceActor.h"
@ -814,6 +813,10 @@ SMESH_ActorDef::
SetControlMode(eControl theMode,
bool theCheckEntityMode)
{
vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
lookupTable->SetScale(VTK_SCALE_LINEAR);
SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
if( !mgr )
return;
@ -1080,6 +1083,13 @@ SetControlMode(eControl theMode,
myTimeStamp->Modified();
Modified();
lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
double * range = lookupTable->GetRange();
if (isLogarithmic && range[0] > 1e-07 && range[1] > 1e-07)
lookupTable->SetScale(VTK_SCALE_LOG10);
Update();
}
@ -2340,7 +2350,8 @@ void SMESH_ActorDef::UpdateDistribution()
elemIds.push_back( (*e)->GetID());
vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
double * range = lookupTable->GetRange();
fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range, isLogarithmic);
myScalarBarActor->SetDistribution(nbEvents);
}
}
@ -2418,7 +2429,8 @@ SPlot2d_Histogram* SMESH_ActorDef::UpdatePlot2Histogram() {
vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
double * range = lookupTable->GetRange();
fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range, isLogarithmic);
for ( int i = 0; i < std::min( nbEvents.size(), funValues.size() -1 ); i++ )
my2dHistogram->addPoint(funValues[i] + (funValues[i+1] - funValues[i])/2.0, static_cast<double>(nbEvents[i]));

View File

@ -1108,9 +1108,10 @@
vtkLookupTable* lookupTable =
static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
double * minmax = lookupTable->GetRange();
bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
std::vector<int> nbEvents;
std::vector<double> funValues;
aNumFun->GetHistogram( nbIntervals, nbEvents, funValues, elements, minmax );
aNumFun->GetHistogram( nbIntervals, nbEvents, funValues, elements, minmax, isLogarithmic );
QString anInitialPath = "";
if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
anInitialPath = QDir::currentPath();

View File

@ -18,13 +18,12 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH SMESHGUI : GUI for SMESH component
// File : SMESHGUI_Preferences_ScalarBarDlg.cxx
// Author : Nicolas REJNERI, Open CASCADE S.A.S.
// SMESH includes
//
#include "SMESHGUI_Preferences_ScalarBarDlg.h"
#include "SMESHGUI.h"
@ -130,7 +129,8 @@ SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI*
/******************************************************************************/
// Scalar range
myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this );
QHBoxLayout* myRangeGrpLayout = new QHBoxLayout( myRangeGrp );
//QHBoxLayout* myRangeGrpLayout = new QHBoxLayout( myRangeGrp );
QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp );
myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
myMinEdit = new QLineEdit( myRangeGrp );
@ -141,10 +141,15 @@ SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI*
myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
myMaxEdit->setValidator( new QDoubleValidator( this ) );
myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp ) );
myRangeGrpLayout->addWidget( myMinEdit );
myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp ) );
myRangeGrpLayout->addWidget( myMaxEdit );
myLogarithmicCheck = new QCheckBox (myRangeGrp);
myLogarithmicCheck->setText(tr("SMESH_LOGARITHMIC_SCALARBAR"));
myLogarithmicCheck->setChecked(false);
myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp ), 0, 0, 1, 1 );
myRangeGrpLayout->addWidget( myMinEdit, 0, 1, 1, 1 );
myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp ), 0, 2, 1, 1 );
myRangeGrpLayout->addWidget( myMaxEdit, 0, 3, 1, 1 );
myRangeGrpLayout->addWidget( myLogarithmicCheck, 1, 0, 1, 4 );
aTopLayout->addWidget( myRangeGrp );
@ -423,8 +428,6 @@ SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI*
QColor(255, 255, 255));
myMonoColorBtn->setColor(distributionColor);
// --> then init from selection if necessary
onSelectionChanged();
@ -434,6 +437,8 @@ SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI*
connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
connect( myHelpBtn, SIGNAL(clicked()), this, SLOT( onHelp() ) );
connect( myMinEdit, SIGNAL( textChanged(const QString &) ), this, SLOT( onMinMaxChanged() ) );
connect( myMaxEdit, SIGNAL( textChanged(const QString &) ), this, SLOT( onMinMaxChanged() ) );
connect( myXSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
connect( myYSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
connect( aOrientationGrp, SIGNAL( buttonClicked( int ) ), this, SLOT( onOrientationChanged() ) );
@ -556,12 +561,16 @@ bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
if(nbColorsChanged)
myScalarBarActor->SetMaximumNumberOfColors(myColorsSpin->value());
myLookupTable->SetRange( aMin, aMax );
myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
bool scaleChanged = (myLogarithmicCheck->isChecked() != (myLookupTable->GetScale() == VTK_SCALE_LOG10));
if (scaleChanged)
myLookupTable->SetScale(myLogarithmicCheck->isChecked() ? VTK_SCALE_LOG10 : VTK_SCALE_LINEAR);
myLookupTable->Build();
if( nbColorsChanged || rangeChanges)
if (nbColorsChanged || rangeChanges || scaleChanged)
myActor->UpdateDistribution();
#ifndef DISABLE_PLOT2DVIEWER
@ -573,8 +582,6 @@ bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
SMESH::ProcessIn2DViewers(myActor);
#endif
SMESH::RepaintCurrentView();
return true;
}
@ -639,9 +646,13 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
if ( myScalarBarActor->GetLookupTable() ) {
vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
vtkLookupTable* aLookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
vtkFloatingPointType *range = aLookupTable->GetRange();
myMinEdit->setText( QString::number( range[0],'g',12 ) );
myMaxEdit->setText( QString::number( range[1],'g',12 ) );
myLogarithmicCheck->setChecked(aLookupTable->GetScale() == VTK_SCALE_LOG10);
myLogarithmicCheck->setEnabled(range[0] > 1e-07 && range[1] > 1e-07);
}
vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
@ -690,7 +701,6 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
myDistributionGrp->setChecked((bool)myScalarBarActor->GetDistributionVisibility());
onDistributionActivated(myScalarBarActor->GetDistributionVisibility());
myRangeGrp->setEnabled( true );
myFontGrp->setEnabled( true );
myLabColorGrp->setEnabled( true );
@ -727,6 +737,22 @@ void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
QDialog::closeEvent( e );
}
//=================================================================================================
/*!
* SMESHGUI_Preferences_ScalarBarDlg::onMinMaxChanged
*
* Called when Scalar Range values are changed
*/
//=================================================================================================
void SMESHGUI_Preferences_ScalarBarDlg::onMinMaxChanged()
{
double aMin = myMinEdit->text().toDouble();
double aMax = myMaxEdit->text().toDouble();
bool isLogarithmicEnabled = (aMin > 1e-07 && aMax > 1e-07);
myLogarithmicCheck->setChecked(isLogarithmicEnabled);
myLogarithmicCheck->setEnabled(isLogarithmicEnabled);
}
//=================================================================================================
/*!
* SMESHGUI_Preferences_ScalarBarDlg::onXYChanged

View File

@ -23,7 +23,7 @@
// SMESH SMESHGUI : GUI for SMESH component
// File : SMESHGUI_Preferences_ScalarBarDlg.h
// Author : Nicolas REJNERI, Open CASCADE S.A.S.
//
#ifndef SMESHGUI_PREFERENCES_SCALARBARDLG_H
#define SMESHGUI_PREFERENCES_SCALARBARDLG_H
@ -78,6 +78,7 @@ protected slots:
void onHelp();
void onSelectionChanged();
void onXYChanged();
void onMinMaxChanged();
void onOrientationChanged();
void onDistributionChanged( int );
void onDistributionActivated( bool );
@ -94,6 +95,7 @@ private:
QGroupBox* myRangeGrp;
QLineEdit* myMinEdit;
QLineEdit* myMaxEdit;
QCheckBox* myLogarithmicCheck;
QGroupBox* myFontGrp;
QtxColorButton* myTitleColorBtn;

View File

@ -1828,6 +1828,10 @@ Check algorithm documentation for supported geometry</translation>
<source>SMESH_LENGTH</source>
<translation>Length</translation>
</message>
<message>
<source>SMESH_LOGARITHMIC_SCALARBAR</source>
<translation>Logarithmic</translation>
</message>
<message>
<source>SMESH_MAKE_GROUPS</source>
<translation>Generate groups</translation>

View File

@ -1800,6 +1800,10 @@ Référez-vous à la documentation sur l&apos;algorithme et la géométrie suppo
<source>SMESH_LENGTH</source>
<translation>Longueur</translation>
</message>
<message>
<source>SMESH_LOGARITHMIC_SCALARBAR</source>
<translation type="unfinished">Logarithmic</translation>
</message>
<message>
<source>SMESH_MAKE_GROUPS</source>
<translation>Générer les groupes</translation>

View File

@ -18,13 +18,12 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
// File : SMESH_Filter_i.cxx
// Author : Alexey Petrov, OCC
// Module : SMESH
//
#include "SMESH_Filter_i.hxx"
#include "SMDS_ElemIterator.hxx"
@ -580,12 +579,12 @@ CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
return myNumericalFunctorPtr->GetValue( theId );
}
SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals)
SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals, CORBA::Boolean isLogarithmic)
{
std::vector<int> nbEvents;
std::vector<double> funValues;
std::vector<int> elements;
myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements);
myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
#ifdef WIN32
nbIntervals = CORBA::Short( min( nbEvents.size(), funValues.size() - 1));

View File

@ -18,13 +18,12 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
// File : SMESH_Filter_i.hxx
// Author : Alexey Petrov, OCC
// Module : SMESH
//
#ifndef _SMESH_FILTER_I_HXX_
#define _SMESH_FILTER_I_HXX_
@ -162,7 +161,7 @@ namespace SMESH
{
public:
CORBA::Double GetValue( CORBA::Long theElementId );
SMESH::Histogram* GetHistogram(CORBA::Short nbIntervals);
SMESH::Histogram* GetHistogram(CORBA::Short nbIntervals, CORBA::Boolean isLogarithmic);
void SetPrecision( CORBA::Long thePrecision );
CORBA::Long GetPrecision();
Controls::NumericalFunctorPtr GetNumericalFunctor();