diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index 1298bd9c5c..a4160070a0 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -614,12 +614,27 @@ void ViewProviderFemPostObject::WritePointData(vtkPoints* points, } } -void ViewProviderFemPostObject::setRangeOfColorBar(double min, double max) +void ViewProviderFemPostObject::setRangeOfColorBar(float min, float max) { try { + // setRange expects max value greater than min value. + // A typical case is max equal to min, so machine epsilon + // is used to overwrite and differentiate both values if (min >= max) { - min = max - 10 * std::numeric_limits::epsilon(); - max = max + 10 * std::numeric_limits::epsilon(); + static constexpr float eps = std::numeric_limits::epsilon(); + if (max > 0) { + min = max * (1 - eps); + max = max * (1 + eps); + } + else if (max < 0) { + min = max * (1 + eps); + max = max * (1 - eps); + } + else { + static constexpr float minF = std::numeric_limits::min(); + min = -1 * minF; + max = minF; + } } m_colorBar->setRange(min, max); } @@ -669,7 +684,7 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange) if (ResetColorBarRange) { double range[2]; data->GetRange(range, component); - setRangeOfColorBar(range[0], range[1]); + setRangeOfColorBar(static_cast(range[0]), static_cast(range[1])); } vtkIdType numPts = pd->GetNumberOfPoints(); diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h index d86373ec79..3909502d9e 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h @@ -133,7 +133,7 @@ protected: virtual void setupTaskDialog(TaskDlgPost* dlg); bool setupPipeline(); void updateVtk(); - void setRangeOfColorBar(double min, double max); + void setRangeOfColorBar(float min, float max); SoCoordinate3* m_coordinates; SoIndexedPointSet* m_markers;