</property>
</widget>
</item>
- <item row="4" column="0" colspan="3">
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Average</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1" colspan="2">
+ <widget class="QLineEdit" name="avgvalue">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
pass
def helpMessage(self):
- QMessageBox.about(None, "About Min/Max value of control",
+ QMessageBox.about(None, "About Min/Max and Average value of control",
"""
- Displays the min/max value of a control
- ---------------------------------
+ Displays the min/max and average value of a control
+ ---------------------------------------------------
-This plugin displays the min and max value of a control
+ This plugin displays the min, max and average value of a control
on a mesh.
Inputs:
- The mesh to analyse
if self.mm and control:
fun = smesh.GetFunctor(controls_dict[str(control)])
fun.SetMesh(self.mm)
- hist = fun.GetHistogram(1,False)
- maxVal = hist[0].max
+ nbRectangles = int(max(100, self.mm.NbElements() / 100 ))
+ hist = fun.GetHistogram(nbRectangles,False)
+ maxVal = hist[-1].max
minVal = hist[0].min
+ avgVal = 0
+ nbElems = 0
+ for rect in hist:
+ avgVal += 0.5 * ( hist[0].max + hist[0].min ) * rect.nbEvents
+ nbElems += rect.nbEvents
+ if nbElems > 0:
+ avgVal /= nbElems
self.ui.maxvalue.setText("%f"%(maxVal))
self.ui.minvalue.setText("%f"%(minVal))
+ self.ui.avgvalue.setText("%f"%(avgVal))
else:
pass
pass
# register the function in the plugin manager
if DEMO_IS_ACTIVATED:
- salome_pluginsmanager.AddFunction('Get min or max value of control',
- 'Get min or max value of control',
+ salome_pluginsmanager.AddFunction('Get min, max and average value of control',
+ 'Get min, max and average value of control',
minmax)