diff --git a/src/AIS/AIS_ColorScale.cxx b/src/AIS/AIS_ColorScale.cxx index 9b53f63211..e0edfa6ddb 100644 --- a/src/AIS/AIS_ColorScale.cxx +++ b/src/AIS/AIS_ColorScale.cxx @@ -53,6 +53,7 @@ myColorType (Aspect_TOCSD_AUTO), myLabelType (Aspect_TOCSD_AUTO), myAtBorder (Standard_True), myReversed (Standard_False), +myIsLogarithmic (Standard_False), myLabelPos (Aspect_TOCSP_RIGHT), myTitlePos (Aspect_TOCSP_CENTER), myXPos (0), @@ -90,8 +91,7 @@ TCollection_ExtendedString AIS_ColorScale::GetLabel (const Standard_Integer theI return myLabels.Value (theIndex + 1); } - - const Standard_Real aVal = GetNumber (theIndex); + Standard_Real aVal = IsLogarithmic() ? GetLogNumber(theIndex) : GetNumber (theIndex); const TCollection_AsciiString aFormat = Format(); Standard_Character aBuf[1024]; sprintf (aBuf, aFormat.ToCString(), aVal); @@ -484,6 +484,21 @@ Standard_Real AIS_ColorScale::GetNumber (const Standard_Integer theIndex) const return aNum; } +//======================================================================= +//function : GetLogNumber +//purpose : +//======================================================================= +Standard_Real AIS_ColorScale::GetLogNumber (const Standard_Integer theIndex) const +{ + if (GetNumberOfIntervals() > 0) + { + Standard_Real aMin = myMin > 0 ? myMin : 1.0; + Standard_Real aDivisor = std::pow (myMax/aMin, 1.0/myInterval); + return aMin*std::pow (aDivisor,theIndex); + } + return 0; +} + //======================================================================= //function : HueFromValue //purpose : diff --git a/src/AIS/AIS_ColorScale.hxx b/src/AIS/AIS_ColorScale.hxx index 86fa980627..91216611e6 100644 --- a/src/AIS/AIS_ColorScale.hxx +++ b/src/AIS/AIS_ColorScale.hxx @@ -94,6 +94,9 @@ public: //! Returns true if the labels placed at border of color filled rectangles. Standard_EXPORT Standard_Boolean IsLabelAtBorder() const { return myAtBorder; } + //! Returns true if the color scale has logarithmic intervals + Standard_Boolean IsLogarithmic() const { return myIsLogarithmic; } + //! Sets the minimal value of color scale. Standard_EXPORT void SetMin (const Standard_Real theMin); @@ -146,6 +149,9 @@ public: //! Sets true if the labels placed at border of color filled rectangles. Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn); + //! Sets true if the color scale has logarithmic intervals. + void SetLogarithmic (const Standard_Boolean isLogarithmic) { myIsLogarithmic = isLogarithmic; }; + //! Returns the size of color scale. Standard_EXPORT void GetSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const; @@ -248,13 +254,16 @@ private: TCollection_AsciiString Format() const; //! Returns the value of given interval. - Standard_Real GetNumber (const Standard_Integer anIndex) const; + Standard_Real GetNumber (const Standard_Integer theIndex) const; + + //! Returns the value of given logarithmic interval. + Standard_Real GetLogNumber (const Standard_Integer theIndex) const; //! Returns the color's hue for the given value in the given interval. //! @param theValue [in] the current value of interval. //! @param theMin [in] the min value of interval. //! @param theMax [in] the max value of interval. - static Standard_Integer HueFromValue (const Standard_Integer aValue, const Standard_Integer aMin, const Standard_Integer aMax); + static Standard_Integer HueFromValue (const Standard_Integer theValue, const Standard_Integer theMin, const Standard_Integer theMax); private: @@ -267,6 +276,7 @@ private: Aspect_TypeOfColorScaleData myLabelType; Standard_Boolean myAtBorder; Standard_Boolean myReversed; + Standard_Boolean myIsLogarithmic; Aspect_SequenceOfColor myColors; TColStd_SequenceOfExtendedString myLabels; Aspect_TypeOfColorScalePosition myLabelPos; diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index f73417ee75..503f9db582 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -3448,6 +3448,11 @@ static int VColorScale (Draw_Interpretor& theDI, std::cout << "Error: no active view!\n"; return 1; } + if (theArgNb <= 1) + { + std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n"; + return 1; + } Handle(AIS_ColorScale) aCS; // find object @@ -3488,11 +3493,6 @@ static int VColorScale (Draw_Interpretor& theDI, ViewerTest_AutoUpdater anUpdateTool (aContext, aView); - if (theArgNb <= 1) - { - std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n"; - return 1; - } if (theArgNb <= 2) { theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n" @@ -3609,6 +3609,22 @@ static int VColorScale (Draw_Interpretor& theDI, return 1; } } + else if (aFlag == "-logarithmic" + || aFlag == "-log") + { + if (anArgIter + 1 >= theArgNb) + { + std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; + return 1; + } + Standard_Boolean IsLog; + if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog)) + { + std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; + return 1; + } + aCS->SetLogarithmic (IsLog); + } else if (aFlag == "-xy") { if (anArgIter + 2 >= theArgNb) diff --git a/tests/bugs/vis/bug22632 b/tests/bugs/vis/bug22632 new file mode 100644 index 0000000000..8bd5918029 --- /dev/null +++ b/tests/bugs/vis/bug22632 @@ -0,0 +1,31 @@ +puts "============" +puts "OCC25632" +puts "Display logarithmic colorscale." +puts "============" +puts "" + +vinit View1 +vclear +vaxo + +# create non-logarithmic color scale with range 0-1000 and 3 intervals +vcolorscale cs -range 0 1000 3 +vdump ${imagedir}/${casename}_1.png + +# create logarithmic color scale with range 1-1000 and 3 intervals +vcolorscale cs -range 0 1000 3 -log 1 +vdump ${imagedir}/${casename}_2.png + +# create logarithmic color scales with different ranges and intervals +vcolorscale cs -range 5 200 4 +vdump ${imagedir}/${casename}_3.png + +vcolorscale cs -range 1 1568 8 +vdump ${imagedir}/${casename}_4.png + +vcolorscale cs -range 3 500 5 +vdump ${imagedir}/${casename}_5.png + +vcolorscale cs -range 1 1000 6 +vdump ${imagedir}/${casename}_6.png +