#include <Graphic3d_ArrayOfTriangles.hxx>
#include <Graphic3d_Text.hxx>
#include <Prs3d_LineAspect.hxx>
-#include <Prs3d_Root.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_Text.hxx>
#include <Prs3d_TextAspect.hxx>
}
}
+//=======================================================================
+//function : MakeUniformColors
+//purpose :
+//=======================================================================
+Aspect_SequenceOfColor AIS_ColorScale::MakeUniformColors (Standard_Integer theNbColors,
+ Standard_Real theLightness,
+ Standard_Real theHueFrom,
+ Standard_Real theHueTo)
+{
+ Aspect_SequenceOfColor aResult;
+
+ // adjust range to be within (0, 360], with sign according to theHueFrom and theHueTo
+ Standard_Real aHueRange = std::fmod (theHueTo - theHueFrom, 360.);
+ const Standard_Real aHueEps = Precision::Angular() * 180. / M_PI;
+ if (Abs (aHueRange) <= aHueEps)
+ {
+ aHueRange = (aHueRange < 0 ? -360. : 360.);
+ }
+
+ // treat limit cases
+ if (theNbColors < 1)
+ {
+ return aResult;
+ }
+ if (theNbColors == 1)
+ {
+ Standard_Real aHue = std::fmod (theHueFrom, 360.);
+ if (aHue < 0.)
+ {
+ aHue += 360.;
+ }
+ Quantity_Color aColor (theLightness, 130., aHue, Quantity_TOC_CIELch);
+ aResult.Append (aColor);
+ return aResult;
+ }
+
+ // discretize the range with 1 degree step
+ const int NBCOLORS = 2 + (int)Abs (aHueRange / 1.);
+ Standard_Real aHueStep = aHueRange / (NBCOLORS - 1);
+ NCollection_Array1<Quantity_Color> aGrid (0, NBCOLORS - 1);
+ for (Standard_Integer i = 0; i < NBCOLORS; i++)
+ {
+ Standard_Real aHue = std::fmod (theHueFrom + i * aHueStep, 360.);
+ if (aHue < 0.)
+ {
+ aHue += 360.;
+ }
+ aGrid(i).SetValues (theLightness, 130., aHue, Quantity_TOC_CIELch);
+ }
+
+ // and compute distances between each two colors in a grid
+ TColStd_Array1OfReal aMetric (0, NBCOLORS - 1);
+ Standard_Real aLength = 0.;
+ for (Standard_Integer i = 0, j = NBCOLORS - 1; i < NBCOLORS; j = i++)
+ {
+ aLength += (aMetric(i) = aGrid(i).DeltaE2000 (aGrid(j)));
+ }
+
+ // determine desired step by distance;
+ // normally we aim to distribute colors from start to end
+ // of the range, but if distance between first and last points of the range
+ // is less than that step (e.g. range is full 360 deg),
+ // then distribute by the whole 360 deg scope to ensure that first
+ // and last colors are sufficiently distanced
+ Standard_Real aDStep = (aLength - aMetric.First()) / (theNbColors - 1);
+ if (aMetric.First() < aDStep)
+ {
+ aDStep = aLength / theNbColors;
+ }
+
+ // generate sequence
+ aResult.Append(aGrid(0));
+ Standard_Real aParam = 0., aPrev = 0., aTarget = aDStep;
+ for (int i = 1; i < NBCOLORS; i++)
+ {
+ aParam = aPrev + aMetric(i);
+ while (aTarget <= aParam)
+ {
+ float aCoefPrev = float((aParam - aTarget) / (aParam - aPrev));
+ float aCoefCurr = float((aTarget - aPrev) / (aParam - aPrev));
+ Quantity_Color aColor (aGrid(i).Rgb() * aCoefCurr + aGrid(i-1).Rgb() * aCoefPrev);
+ aResult.Append (aColor);
+ aTarget += aDStep;
+ }
+ aPrev = aParam;
+ }
+ if (aResult.Length() < theNbColors)
+ {
+ aResult.Append (aGrid.Last());
+ }
+ Standard_ASSERT_VOID (aResult.Length() == theNbColors, "Failed to generate requested nb of colors");
+ return aResult;
+}
+
//=======================================================================
//function : SizeHint
//purpose :
//function : Compute
//purpose :
//=======================================================================
-void AIS_ColorScale::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
+void AIS_ColorScale::Compute (const Handle(PrsMgr_PresentationManager)& ,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode)
{
//=======================================================================
Standard_Integer AIS_ColorScale::TextWidth (const TCollection_ExtendedString& theText) const
{
- Standard_Integer aWidth, anAscent, aDescent;
+ Standard_Integer aWidth = 0, anAscent = 0, aDescent = 0;
TextSize (theText, myTextHeight, aWidth, anAscent, aDescent);
return aWidth;
}
//=======================================================================
Standard_Integer AIS_ColorScale::TextHeight (const TCollection_ExtendedString& theText) const
{
- Standard_Integer aWidth, anAscent, aDescent;
+ Standard_Integer aWidth = 0, anAscent = 0, aDescent = 0;
TextSize (theText, myTextHeight, aWidth, anAscent, aDescent);
return anAscent + aDescent;
}
Standard_Integer& theAscent,
Standard_Integer& theDescent) const
{
- if (!HasInteractiveContext())
+ Standard_ShortReal aWidth = 10.0f, anAscent = 1.0f, aDescent = 1.0f;
+ if (HasInteractiveContext())
{
- return;
+ const TCollection_AsciiString aText (theText);
+ const Handle(V3d_Viewer)& aViewer = GetContext()->CurrentViewer();
+ const Handle(Graphic3d_CView)& aView = aViewer->ActiveViewIterator().Value()->View();
+ aViewer->Driver()->TextSize (aView, aText.ToCString(), (Standard_ShortReal)theHeight, aWidth, anAscent, aDescent);
}
-
- Standard_ShortReal aWidth = 10.0f;
- Standard_ShortReal anAscent = 1.0f;
- Standard_ShortReal aDescent = 1.0f;
- const TCollection_AsciiString aText (theText);
-
- const Handle(V3d_Viewer)& aViewer = GetContext()->CurrentViewer();
- const Handle(Graphic3d_CView)& aView = aViewer->ActiveViewIterator().Value()->View();
- aViewer->Driver()->TextSize (aView, aText.ToCString(), (Standard_ShortReal)theHeight, aWidth, anAscent, aDescent);
theWidth = (Standard_Integer)aWidth;
theAscent = (Standard_Integer)anAscent;
theDescent = (Standard_Integer)aDescent;