]> OCCT Git - occt.git/commitdiff
0022632: Visualization - provide logarithmic scale for Aspect_ColorScale class
authorisz <isz@opencascade.com>
Thu, 8 Oct 2015 09:07:59 +0000 (12:07 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 15 Oct 2015 09:15:06 +0000 (12:15 +0300)
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.

src/AIS/AIS_ColorScale.cxx
src/AIS/AIS_ColorScale.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/bugs/vis/bug22632 [new file with mode: 0644]

index 9b53f63211e3e4ea901aa42d52fcf989bcf58acf..e0edfa6ddb1e438ac9afcf44ec1fe4fff522bbf2 100644 (file)
@@ -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  :
index 86fa9806277c85871a6c46e75733b8f912b10176..91216611e66844b016dd12472d120bcdb16c82ac 100644 (file)
@@ -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;
index f73417ee756fb4178f5738c6589e3fc357a933c5..503f9db58213fa38cc1c6027f3789a66ad2d7c1f 100644 (file)
@@ -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 (file)
index 0000000..8bd5918
--- /dev/null
@@ -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
+