Option "-logarithmic" is provided for draw command vcolorscale.
It changes color scale's labels to logarithmic values due to the min and max range and the number of intervals of the color scale.
New test case added. Fixed error when command vcolorscale was called without arguments.
myLabelType (Aspect_TOCSD_AUTO),
myAtBorder (Standard_True),
myReversed (Standard_False),
+myIsLogarithmic (Standard_False),
myLabelPos (Aspect_TOCSP_RIGHT),
myTitlePos (Aspect_TOCSP_CENTER),
myXPos (0),
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);
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 :
//! 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);
//! 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;
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:
Aspect_TypeOfColorScaleData myLabelType;
Standard_Boolean myAtBorder;
Standard_Boolean myReversed;
+ Standard_Boolean myIsLogarithmic;
Aspect_SequenceOfColor myColors;
TColStd_SequenceOfExtendedString myLabels;
Aspect_TypeOfColorScalePosition myLabelPos;
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
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"
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)
--- /dev/null
+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
+