From ed06327034f485b9c0ef5c09b3e42231f4584786 Mon Sep 17 00:00:00 2001 From: osa Date: Tue, 14 Oct 2014 18:27:57 +0400 Subject: [PATCH] 0025332: Visualization - rewrite MinMaxValues methods to using of Bnd_Box --- src/Bnd/Bnd_Box.cdl | 27 +++- src/Bnd/Bnd_Box.cxx | 85 ++++++++--- src/Graphic3d/Graphic3d.cdl | 3 +- src/Graphic3d/Graphic3d_Camera.cxx | 82 +++++------ src/Graphic3d/Graphic3d_Structure.cdl | 14 +- src/Graphic3d/Graphic3d_Structure.cxx | 45 +++--- src/NIS/NIS_View.cxx | 21 +-- src/V3d/V3d.cdl | 3 +- src/V3d/V3d_View.cdl | 9 +- src/V3d/V3d_View.cxx | 61 ++++---- src/ViewerTest/ViewerTest.cxx | 10 +- src/Visual3d/Visual3d.cdl | 3 +- src/Visual3d/Visual3d_View.cdl | 34 +---- src/Visual3d/Visual3d_View.cxx | 204 +++++--------------------- 14 files changed, 250 insertions(+), 351 deletions(-) diff --git a/src/Bnd/Bnd_Box.cdl b/src/Bnd/Bnd_Box.cdl index 677290abbd..5552cd44b8 100644 --- a/src/Bnd/Bnd_Box.cdl +++ b/src/Bnd/Bnd_Box.cdl @@ -111,13 +111,30 @@ is -- increased by the same amount. is static; - Get(me; aXmin, aYmin, aZmin, aXmax, aYmax, aZmax : out Real) - ---Purpose: Returns the bounds of this bounding box. The gap is included. - -- If this bounding box is infinite (i.e. "open"), returned values - -- may be equal to +/- Precision::Infinite(). + Get (me; theXmin, theYmin, theZmin, theXmax, theYmax, theZmax : out Real) + ---Purpose: Returns the bounds of this bounding box. The gap is included. + -- If this bounding box is infinite (i.e. "open"), returned values + -- may be equal to +/- Precision::Infinite(). + -- Standard_ConstructionError exception will be thrown if the box is void. raises ConstructionError -- if IsVoid() is static; - + + CornerMin(me) returns Pnt from gp + ---Purpose: Returns the lower corner of this bounding box. The gap is included. + -- If this bounding box is infinite (i.e. "open"), returned values + -- may be equal to +/- Precision::Infinite(). + -- Standard_ConstructionError exception will be thrown if the box is void. + raises ConstructionError -- if IsVoid() + is static; + + CornerMax(me) returns Pnt from gp + ---Purpose: Returns the upper corner of this bounding box. The gap is included. + -- If this bounding box is infinite (i.e. "open"), returned values + -- may be equal to +/- Precision::Infinite(). + -- Standard_ConstructionError exception will be thrown if the box is void. + raises ConstructionError -- if IsVoid() + is static; + OpenXmin(me : in out) ---Purpose: The Box will be infinitely long in the Xmin -- direction. diff --git a/src/Bnd/Bnd_Box.cxx b/src/Bnd/Bnd_Box.cxx index 940ad79a61..99ebaeb526 100644 --- a/src/Bnd/Bnd_Box.cxx +++ b/src/Bnd/Bnd_Box.cxx @@ -201,27 +201,74 @@ void Bnd_Box::Enlarge (const Standard_Real Tol) //purpose : //======================================================================= -void Bnd_Box::Get (Standard_Real& x, - Standard_Real& y, - Standard_Real& z, - Standard_Real& X, - Standard_Real& Y, - Standard_Real& Z) const +void Bnd_Box::Get (Standard_Real& theXmin, + Standard_Real& theYmin, + Standard_Real& theZmin, + Standard_Real& theXmax, + Standard_Real& theYmax, + Standard_Real& theZmax) const { + if (VoidFlag()) + { + Standard_ConstructionError::Raise ("Bnd_Box is void"); + } + + if (XminFlag()) theXmin = -Bnd_Precision_Infinite; + else theXmin = Xmin - Gap; + if (XmaxFlag()) theXmax = Bnd_Precision_Infinite; + else theXmax = Xmax + Gap; + if (YminFlag()) theYmin = -Bnd_Precision_Infinite; + else theYmin = Ymin - Gap; + if (YmaxFlag()) theYmax = Bnd_Precision_Infinite; + else theYmax = Ymax + Gap; + if (ZminFlag()) theZmin = -Bnd_Precision_Infinite; + else theZmin = Zmin - Gap; + if (ZmaxFlag()) theZmax = Bnd_Precision_Infinite; + else theZmax = Zmax + Gap; +} + +//======================================================================= +//function : CornerMin +//purpose : +//======================================================================= + +gp_Pnt Bnd_Box::CornerMin() const +{ + gp_Pnt aCornerMin; + if (VoidFlag()) + { + Standard_ConstructionError::Raise ("Bnd_Box is void"); + return aCornerMin; + } + if (XminFlag()) aCornerMin.SetX (-Bnd_Precision_Infinite); + else aCornerMin.SetX (Xmin - Gap); + if (YminFlag()) aCornerMin.SetY (-Bnd_Precision_Infinite); + else aCornerMin.SetY (Ymin - Gap); + if (ZminFlag()) aCornerMin.SetZ (-Bnd_Precision_Infinite); + else aCornerMin.SetZ (Zmin - Gap); + return aCornerMin; +} + +//======================================================================= +//function : CornerMax +//purpose : +//======================================================================= + +gp_Pnt Bnd_Box::CornerMax() const +{ + gp_Pnt aCornerMax; if(VoidFlag()) - Standard_ConstructionError::Raise("Bnd_Box is void"); - if (XminFlag()) x = -Bnd_Precision_Infinite; - else x = Xmin-Gap; - if (XmaxFlag()) X = Bnd_Precision_Infinite; - else X = Xmax+Gap; - if (YminFlag()) y = -Bnd_Precision_Infinite; - else y = Ymin-Gap; - if (YmaxFlag()) Y = Bnd_Precision_Infinite; - else Y = Ymax+Gap; - if (ZminFlag()) z = -Bnd_Precision_Infinite; - else z = Zmin-Gap; - if (ZmaxFlag()) Z = Bnd_Precision_Infinite; - else Z = Zmax+Gap; + { + Standard_ConstructionError::Raise ("Bnd_Box is void"); + return aCornerMax; + } + if (XmaxFlag()) aCornerMax.SetX (Bnd_Precision_Infinite); + else aCornerMax.SetX (Xmax + Gap); + if (YminFlag()) aCornerMax.SetY (Bnd_Precision_Infinite); + else aCornerMax.SetY (Ymax + Gap); + if (ZminFlag()) aCornerMax.SetZ (Bnd_Precision_Infinite); + else aCornerMax.SetZ (Zmax + Gap); + return aCornerMax; } //======================================================================= diff --git a/src/Graphic3d/Graphic3d.cdl b/src/Graphic3d/Graphic3d.cdl index aaf3e03ad9..64ffa52639 100644 --- a/src/Graphic3d/Graphic3d.cdl +++ b/src/Graphic3d/Graphic3d.cdl @@ -72,7 +72,8 @@ uses WNT, Image, gp, - Font + Font, + Bnd is ----------------------- diff --git a/src/Graphic3d/Graphic3d_Camera.cxx b/src/Graphic3d/Graphic3d_Camera.cxx index 838ae2ab11..edf72cdaf1 100644 --- a/src/Graphic3d/Graphic3d_Camera.cxx +++ b/src/Graphic3d/Graphic3d_Camera.cxx @@ -22,6 +22,8 @@ #include #include +#include + IMPLEMENT_STANDARD_HANDLE(Graphic3d_Camera, Standard_Transient) IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Camera, Standard_Transient) @@ -983,17 +985,7 @@ void Graphic3d_Camera::ZFitAll (const Standard_Real theScaleFactor, const Bnd_Bo // should be computed using information on boundaries of primary application actors, // (e.g. representing the displayed model) - to ensure that they are not unreasonably clipped. - - Standard_Real aMinMax[6]; // applicative min max boundaries - theMinMax.Get (aMinMax[0], aMinMax[1], aMinMax[2], aMinMax[3], aMinMax[4], aMinMax[5]); - - Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag). - theGraphicBB.Get (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2], aGraphicBB[3], aGraphicBB[4], aGraphicBB[5]); - - // Check if anything can be adjusted - Standard_Real aLim = (ShortRealLast() - 1.0); - if (Abs (aGraphicBB[0]) > aLim || Abs (aGraphicBB[1]) > aLim || Abs (aGraphicBB[2]) > aLim || - Abs (aGraphicBB[3]) > aLim || Abs (aGraphicBB[4]) > aLim || Abs (aGraphicBB[5]) > aLim) + if (theGraphicBB.IsVoid()) { // ShortReal precision factor used to add meaningful tolerance to // ZNear, ZFar values in order to avoid equality after type conversion @@ -1023,26 +1015,34 @@ void Graphic3d_Camera::ZFitAll (const Standard_Real theScaleFactor, const Bnd_Bo } // Measure depth of boundary points from camera eye - gp_Pnt aPntsToMeasure[16] = + NCollection_Sequence aPntsToMeasure; + + Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag). + theGraphicBB.Get (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2], aGraphicBB[3], aGraphicBB[4], aGraphicBB[5]); + + aPntsToMeasure.Append (gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2])); + aPntsToMeasure.Append (gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[5])); + aPntsToMeasure.Append (gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[2])); + aPntsToMeasure.Append (gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[5])); + aPntsToMeasure.Append (gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[2])); + aPntsToMeasure.Append (gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[5])); + aPntsToMeasure.Append (gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[2])); + aPntsToMeasure.Append (gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[5])); + + if (!theMinMax.IsVoid() && !theMinMax.IsWhole()) { - gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[2]), - gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[5]), - gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[2]), - gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[5]), - gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[2]), - gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[5]), - gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[2]), - gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[5]), - - gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2]), - gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[5]), - gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[2]), - gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[5]), - gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[2]), - gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[5]), - gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[2]), - gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[5]) - }; + Standard_Real aMinMax[6]; // applicative min max boundaries + theMinMax.Get (aMinMax[0], aMinMax[1], aMinMax[2], aMinMax[3], aMinMax[4], aMinMax[5]); + + aPntsToMeasure.Append (gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[2])); + aPntsToMeasure.Append (gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[5])); + aPntsToMeasure.Append (gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[2])); + aPntsToMeasure.Append (gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[5])); + aPntsToMeasure.Append (gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[2])); + aPntsToMeasure.Append (gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[5])); + aPntsToMeasure.Append (gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[2])); + aPntsToMeasure.Append (gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[5])); + } // Camera eye plane gp_Dir aCamDir = Direction(); @@ -1057,18 +1057,15 @@ void Graphic3d_Camera::ZFitAll (const Standard_Real theScaleFactor, const Bnd_Bo const gp_XYZ& anAxialScale = myAxialScale; // Get minimum and maximum distances to the eye plane - for (Standard_Integer aPntIt = 0; aPntIt < 16; ++aPntIt) + Standard_Integer aCounter = 0; + NCollection_Sequence::Iterator aPntIt(aPntsToMeasure); + for (; aPntIt.More(); aPntIt.Next()) { - gp_Pnt aMeasurePnt = aPntsToMeasure[aPntIt]; - - if (Abs (aMeasurePnt.X()) > aLim || Abs (aMeasurePnt.Y()) > aLim || Abs (aMeasurePnt.Z()) > aLim) - { - continue; - } + gp_Pnt aMeasurePnt = aPntIt.Value(); aMeasurePnt = gp_Pnt (aMeasurePnt.X() * anAxialScale.X(), - aMeasurePnt.Y() * anAxialScale.Y(), - aMeasurePnt.Z() * anAxialScale.Z()); + aMeasurePnt.Y() * anAxialScale.Y(), + aMeasurePnt.Z() * anAxialScale.Z()); Standard_Real aDistance = aCamPln.Distance (aMeasurePnt); @@ -1078,10 +1075,13 @@ void Graphic3d_Camera::ZFitAll (const Standard_Real theScaleFactor, const Bnd_Bo aDistance *= -1; } - Standard_Real& aChangeMinDist = aPntIt >= 8 ? aGraphicMinDist : aModelMinDist; - Standard_Real& aChangeMaxDist = aPntIt >= 8 ? aGraphicMaxDist : aModelMaxDist; + // the first eight points are from theGraphicBB, the last eight points are from theMinMax + // (they can be absent). + Standard_Real& aChangeMinDist = aCounter >= 8 ? aModelMinDist : aGraphicMinDist; + Standard_Real& aChangeMaxDist = aCounter >= 8 ? aModelMaxDist : aGraphicMaxDist; aChangeMinDist = Min (aDistance, aChangeMinDist); aChangeMaxDist = Max (aDistance, aChangeMaxDist); + aCounter++; } // Compute depth of bounding box center diff --git a/src/Graphic3d/Graphic3d_Structure.cdl b/src/Graphic3d/Graphic3d_Structure.cdl index 7c5d470b49..46e1f86142 100644 --- a/src/Graphic3d/Graphic3d_Structure.cdl +++ b/src/Graphic3d/Graphic3d_Structure.cdl @@ -73,7 +73,8 @@ uses Pnt from gp, SequenceOfHClipPlane from Graphic3d, BndBox4f from Graphic3d, - BndBox4d from Graphic3d + BndBox4d from Graphic3d, + Box from Bnd raises @@ -574,10 +575,8 @@ is ---Purpose: Returns the current group of graphic attributes used -- for 3d marker primitives. - MinMaxValues (me; - theXMin, theYMin, theZMin : out Real from Standard; - theXMax, theYMax, theZMax : out Real from Standard; - theToIgnoreInfiniteFlag : Boolean from Standard = Standard_False) + MinMaxValues (me; theToIgnoreInfiniteFlag : Boolean from Standard = Standard_False) + returns Box from Bnd is static; ---Level: Public ---Purpose: Returns the coordinates of the boundary box of the structure . @@ -587,9 +586,8 @@ is -- of the structure. This approach generally used for application -- specific fit operation (e.g. fitting the model into screen, -- not taking into accout infinite helper elements). - -- Warning: If the structure is empty or infinite then : - -- theXMin = theYMin = theZMin = RealFirst (). - -- theXMax = theYMax = theZMax = RealLast (). + -- Warning: If the structure is empty then the empty box is returned, + -- If the structure is infinite then the whole box is returned. ---Category: Inquire methods PrimitivesAspect ( me; diff --git a/src/Graphic3d/Graphic3d_Structure.cxx b/src/Graphic3d/Graphic3d_Structure.cxx index 3ec6316e17..92a42502f9 100644 --- a/src/Graphic3d/Graphic3d_Structure.cxx +++ b/src/Graphic3d/Graphic3d_Structure.cxx @@ -1651,33 +1651,32 @@ void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const //function : MinMaxValues //purpose : //============================================================================= -void Graphic3d_Structure::MinMaxValues (Standard_Real& theXMin, - Standard_Real& theYMin, - Standard_Real& theZMin, - Standard_Real& theXMax, - Standard_Real& theYMax, - Standard_Real& theZMax, - const Standard_Boolean theToIgnoreInfiniteFlag) const +Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const { Graphic3d_BndBox4d aBox; + Bnd_Box aResult; addTransformed (aBox, theToIgnoreInfiniteFlag); - if (!aBox.IsValid()) - { - theXMin = RealFirst(); - theYMin = RealFirst(); - theZMin = RealFirst(); - theXMax = RealLast(); - theYMax = RealLast(); - theZMax = RealLast(); - return; + if (aBox.IsValid()) + { + aResult.Add (gp_Pnt (aBox.CornerMin().x(), + aBox.CornerMin().y(), + aBox.CornerMin().z())); + aResult.Add (gp_Pnt (aBox.CornerMax().x(), + aBox.CornerMax().y(), + aBox.CornerMax().z())); + + Standard_Real aLimMin = ShortRealFirst() + 1.0; + Standard_Real aLimMax = ShortRealLast() - 1.0; + gp_Pnt aMin = aResult.CornerMin(); + gp_Pnt aMax = aResult.CornerMax(); + if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin && + aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax) + { + //For structure which infinite in all three dimensions the Whole bounding box will be returned + aResult.SetWhole(); + } } - - theXMin = aBox.CornerMin().x(); - theYMin = aBox.CornerMin().y(); - theZMin = aBox.CornerMin().z(); - theXMax = aBox.CornerMax().x(); - theYMax = aBox.CornerMax().y(); - theZMax = aBox.CornerMax().z(); + return aResult; } //============================================================================= diff --git a/src/NIS/NIS_View.cxx b/src/NIS/NIS_View.cxx index bd4c3ba1c0..ee24237aaa 100644 --- a/src/NIS/NIS_View.cxx +++ b/src/NIS/NIS_View.cxx @@ -106,17 +106,18 @@ void NIS_View::RemoveContext (NIS_InteractiveContext * theCtx) Standard_Boolean NIS_View::FitAll3d (const Quantity_Coefficient theCoef) { - Bnd_B3f aBox = GetBndBox(); + Bnd_B3f aB3fBox = GetBndBox(); - if (aBox.IsVoid() || MyView->IsDefined() == Standard_False) + if (aB3fBox.IsVoid() || MyView->IsDefined() == Standard_False) { return Standard_False; } - gp_XYZ aMin = aBox.CornerMin(); - gp_XYZ aMax = aBox.CornerMax(); + Bnd_Box aBox; + aBox.Add (gp_Pnt (aB3fBox.CornerMin())); + aBox.Add (gp_Pnt (aB3fBox.CornerMax())); - if (!FitMinMax (myCamera, aMin, aMax, theCoef, 0.0, Standard_False)) + if (!FitMinMax (myCamera, aBox, theCoef, 0.0, Standard_False)) { return Standard_False; } @@ -150,11 +151,11 @@ Bnd_B3f NIS_View::GetBndBox() const } // Take the bounding box of AIS objects displayed in the view - Standard_Real aVal[6]; - View()->MinMaxValues(aVal[0], aVal[1], aVal[2], aVal[3], aVal[4], aVal[5]); - if (aVal[3] < 0.5 * RealLast()) { - aBox.Add (gp_XYZ (aVal[0], aVal[1], aVal[2])); - aBox.Add (gp_XYZ (aVal[3], aVal[4], aVal[5])); + Bnd_Box aVal = View()->MinMaxValues(); + if (!aVal.IsVoid()) + { + aBox.Add (aVal.CornerMin()); + aBox.Add (aVal.CornerMax()); } return aBox; diff --git a/src/V3d/V3d.cdl b/src/V3d/V3d.cdl index 8016462440..2346113ea0 100644 --- a/src/V3d/V3d.cdl +++ b/src/V3d/V3d.cdl @@ -42,7 +42,8 @@ uses Image, gp, OSD, - Font + Font, + Bnd is diff --git a/src/V3d/V3d_View.cdl b/src/V3d/V3d_View.cdl index 8aecd67bf2..bdb30dd514 100644 --- a/src/V3d/V3d_View.cdl +++ b/src/V3d/V3d_View.cdl @@ -136,7 +136,8 @@ uses SequenceOfHClipPlane from Graphic3d, RenderingMode from Graphic3d, RenderingParams from Graphic3d, - XYZ from gp + XYZ from gp, + Box from Bnd raises BadValue from V3d, TypeMismatch from Standard, @@ -1531,8 +1532,7 @@ is FitMinMax (me; theCamera : Camera_Handle from Graphic3d; - theMinCorner : XYZ from gp; - theMaxCorner : XYZ from gp; + theBox : Box from Bnd; theMargin : Real from Standard; theResolution : Real from Standard = 0.0; theToEnlargeIfLine : Boolean from Standard = Standard_True) @@ -1541,8 +1541,7 @@ is ---Purpose: Transform camera eye, center and scale to fit in the -- passed bounding box specified in WCS. -- @param theCamera [in] the camera. - -- @param theMinCorner [in] the minimal corner of bounding box. - -- @param theMaxCorner [in] the maximal corner of bounding box. + -- @param theBox [in] the bounding box. -- @param theMargin [in] the margin coefficient for view borders. -- @param theResolution [in] the minimum size of projection of -- bounding box in Xv or Yv direction when it considered to diff --git a/src/V3d/V3d_View.cxx b/src/V3d/V3d_View.cxx index 5427bc81f0..189a6e10a7 100644 --- a/src/V3d/V3d_View.cxx +++ b/src/V3d/V3d_View.cxx @@ -1509,12 +1509,7 @@ void V3d_View::FitAll (const Standard_Real theMargin, const Standard_Boolean the return; } - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - MyView->MinMaxValues (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - gp_XYZ aMin (aXmin, aYmin, aZmin); - gp_XYZ aMax (aXmax, aYmax, aZmax); - - if (!FitMinMax (myCamera, aMin, aMax, theMargin, 10.0 * Precision::Confusion())) + if (!FitMinMax (myCamera, MyView->MinMaxValues(), theMargin, 10.0 * Precision::Confusion())) { return; } @@ -1545,19 +1540,13 @@ void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect, return ; } - MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ; - - Standard_Real LIM = ShortRealLast() -1.; - if (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM - || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) { - ImmediateUpdate(); - return ; - } - - if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) { - ImmediateUpdate(); - return ; - } + Bnd_Box aBox = MyView->MinMaxValues(); + if (aBox.IsVoid()) + { + ImmediateUpdate(); + return ; + } + aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ; MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ; Umin = Min(U,U1) ; Umax = Max(U,U1) ; @@ -2060,7 +2049,8 @@ Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; if( Nstruct ) { - MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ; + Bnd_Box aBox = MyView->MinMaxValues(); + aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ; MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ; MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; @@ -2107,7 +2097,8 @@ Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; if( Nstruct ) { - MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ; + Bnd_Box aBox = MyView->MinMaxValues(); + aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); } return Nstruct ; } @@ -2133,17 +2124,16 @@ Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_ const Handle(Graphic3d_Structure)& aStruct = MyIterator.Key(); if (!aStruct->IsEmpty()) { - aStruct->MinMaxValues (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); + Bnd_Box aBox = aStruct->MinMaxValues(); // Check bounding box for validness - Standard_Real aLim = (ShortRealLast() - 1.0); - if (Abs (Xmin) > aLim || Abs (Ymin) > aLim || Abs (Zmin) > aLim || - Abs (Xmax) > aLim || Abs (Ymax) > aLim || Abs (Zmax) > aLim) + if (aBox.IsVoid()) { continue; } // use camera projection to find gravity point + aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); gp_Pnt aPnts[8] = { gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax), gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax), @@ -3019,16 +3009,13 @@ const Handle(Graphic3d_Camera)& V3d_View::Camera() const // purpose : Internal // ======================================================================= Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera, - const gp_XYZ& theMinCorner, - const gp_XYZ& theMaxCorner, + const Bnd_Box& theBox, const Standard_Real theMargin, const Standard_Real theResolution, const Standard_Boolean theToEnlargeIfLine) const { // Check bounding box for validness - Standard_Real aLim = (ShortRealLast() - 1.0); - if (Abs (theMinCorner.X()) > aLim || Abs (theMinCorner.Y()) > aLim || Abs (theMinCorner.Z()) > aLim || - Abs (theMaxCorner.X()) > aLim || Abs (theMaxCorner.Y()) > aLim || Abs (theMaxCorner.Z()) > aLim) + if (theBox.IsVoid()) { return Standard_False; // bounding box is out of bounds... } @@ -3039,12 +3026,14 @@ Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera, // option is to perform frustum plane adjustment algorithm in view camera space, // which will lead to a number of additional world-view space conversions and // loosing precision as well. - Standard_Real aXmin = theMinCorner.X() * theCamera->AxialScale().X(); - Standard_Real aXmax = theMaxCorner.X() * theCamera->AxialScale().X(); - Standard_Real aYmin = theMinCorner.Y() * theCamera->AxialScale().Y(); - Standard_Real aYmax = theMaxCorner.Y() * theCamera->AxialScale().Y(); - Standard_Real aZmin = theMinCorner.Z() * theCamera->AxialScale().Z(); - Standard_Real aZmax = theMaxCorner.Z() * theCamera->AxialScale().Z(); + gp_Pnt aMinCorner = theBox.CornerMin(); + gp_Pnt aMaxCorner = theBox.CornerMax(); + Standard_Real aXmin = aMinCorner.X() * theCamera->AxialScale().X(); + Standard_Real aXmax = aMaxCorner.X() * theCamera->AxialScale().X(); + Standard_Real aYmin = aMinCorner.Y() * theCamera->AxialScale().Y(); + Standard_Real aYmax = aMaxCorner.Y() * theCamera->AxialScale().Y(); + Standard_Real aZmin = aMinCorner.Z() * theCamera->AxialScale().Z(); + Standard_Real aZmax = aMaxCorner.Z() * theCamera->AxialScale().Z(); Bnd_Box aBBox; aBBox.Update (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 8093cb334a..8a7a9838b1 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -2478,12 +2478,12 @@ inline void bndPresentation (Draw_Interpretor& theDI, } case BndAction_Print: { - Graphic3d_Vec3d aMin, aMax; - thePrs->Presentation()->MinMaxValues (aMin.x(), aMin.y(), aMin.z(), - aMax.x(), aMax.y(), aMax.z()); + Bnd_Box aBox = thePrs->Presentation()->MinMaxValues(); + gp_Pnt aMin = aBox.CornerMin(); + gp_Pnt aMax = aBox.CornerMax(); theDI << theName << "\n" - << aMin.x() << " " << aMin.y() << " " << aMin.z() << " " - << aMax.x() << " " << aMax.y() << " " << aMax.z() << "\n"; + << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " " + << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n"; break; } } diff --git a/src/Visual3d/Visual3d.cdl b/src/Visual3d/Visual3d.cdl index 6c6758e697..5d617986b9 100644 --- a/src/Visual3d/Visual3d.cdl +++ b/src/Visual3d/Visual3d.cdl @@ -54,7 +54,8 @@ uses MMgt, WNT, OSD, - Font + Font, + Bnd is diff --git a/src/Visual3d/Visual3d_View.cdl b/src/Visual3d/Visual3d_View.cdl index a6c098e175..919d791e62 100644 --- a/src/Visual3d/Visual3d_View.cdl +++ b/src/Visual3d/Visual3d_View.cdl @@ -108,7 +108,8 @@ uses ExtendedString from TCollection, CGraduatedTrihedron from Graphic3d, - PixMap from Image + PixMap from Image, + Box from Bnd raises TransformError from Visual3d, @@ -670,9 +671,8 @@ is ---Category: Inquire methods MinMaxValues (me; - theXMin, theYMin, theZMin : out Real from Standard; - theXMax, theYMax, theZMax : out Real from Standard; theToIgnoreInfiniteFlag : Boolean from Standard = Standard_False) + returns Box from Bnd is static; ---Level: Public ---Purpose: Returns the coordinates of the boundary box of all @@ -683,40 +683,14 @@ is MinMaxValues (me; theSet : MapOfStructure from Graphic3d; - theXMin, theYMin, theZMin : out Real from Standard; - theXMax, theYMax, theZMax : out Real from Standard; theToIgnoreInfiniteFlag : Boolean from Standard = Standard_False) + returns Box from Bnd is static; ---Level: Public ---Purpose: Returns the coordinates of the boundary box of all -- structures in the set . -- If is TRUE, then the boundary box -- also includes minimum and maximum limits of graphical elements - -- forming parts of infinite structures. - - MinMaxValues (me; - theXMin, theYMin : out Real from Standard; - theXMax, theYMax : out Real from Standard; - theToIgnoreInfiniteFlag : Boolean from Standard = Standard_False) - is static; - ---Level: Public - ---Purpose: Returns the coordinates of the projection of the - -- boundary box of all structures displayed in the view . - -- If is TRUE, then the boundary box - -- also includes minimum and maximum limits of graphical elements - -- forming parts of infinite structures. - - MinMaxValues (me; - theSet : MapOfStructure from Graphic3d; - theXMin, theYMin : out Real from Standard; - theXMax, theYMax : out Real from Standard; - theToIgnoreInfiniteFlag : Boolean from Standard = Standard_False) - is static; - ---Level: Public - ---Purpose: Returns the coordinates of the projection of the - -- boundary box of all structures in the set . - -- If is TRUE, then the boundary box - -- also includes minimum and maximum limits of graphical elements -- forming parts of infinite structures. NumberOfDisplayedStructures ( me ) diff --git a/src/Visual3d/Visual3d_View.cxx b/src/Visual3d/Visual3d_View.cxx index 35c4a9a2e1..8d2717d9ca 100644 --- a/src/Visual3d/Visual3d_View.cxx +++ b/src/Visual3d/Visual3d_View.cxx @@ -1124,24 +1124,8 @@ void Visual3d_View::AutoZFit() // ======================================================================== void Visual3d_View::ZFitAll (const Standard_Real theScaleFactor) { - Standard_Real aMinMax[6]; // applicative min max boundaries - MinMaxValues (aMinMax[0], aMinMax[1], aMinMax[2], - aMinMax[3], aMinMax[4], aMinMax[5], - Standard_False); - - Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag). - MinMaxValues (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2], - aGraphicBB[3], aGraphicBB[4], aGraphicBB[5], - Standard_True); - - Bnd_Box aMinMaxBox; - Bnd_Box aGraphicBox; - - aMinMaxBox.Update (aMinMax[0], aMinMax[1], aMinMax[2], - aMinMax[3], aMinMax[4], aMinMax[5]); - - aGraphicBox.Update (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2], - aGraphicBB[3], aGraphicBB[4], aGraphicBB[5]); + Bnd_Box aMinMaxBox = MinMaxValues (Standard_False); // applicative min max boundaries + Bnd_Box aGraphicBox = MinMaxValues (Standard_True); // real graphical boundaries (not accounting infinite flag). const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera; aCamera->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox); @@ -1697,163 +1681,58 @@ Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& t // function : MinMaxValues // purpose : // ======================================================================== -void Visual3d_View::MinMaxValues (Standard_Real& theXMin, - Standard_Real& theYMin, - Standard_Real& theZMin, - Standard_Real& theXMax, - Standard_Real& theYMax, - Standard_Real& theZMax, - const Standard_Boolean theToIgnoreInfiniteFlag) const +Bnd_Box Visual3d_View::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const { - MinMaxValues (myStructsDisplayed, - theXMin, theYMin, theZMin, - theXMax, theYMax, theZMax, - theToIgnoreInfiniteFlag); + return MinMaxValues (myStructsDisplayed, + theToIgnoreInfiniteFlag); } // ======================================================================== // function : MinMaxValues // purpose : // ======================================================================== -void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet, - Standard_Real& theXMin, - Standard_Real& theYMin, - Standard_Real& theZMin, - Standard_Real& theXMax, - Standard_Real& theYMax, - Standard_Real& theZMax, - const Standard_Boolean theToIgnoreInfiniteFlag) const +Bnd_Box Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet, + const Standard_Boolean theToIgnoreInfiniteFlag) const { + Bnd_Box aResult; if (theSet.IsEmpty ()) { - theXMin = RealFirst(); - theYMin = RealFirst(); - theZMin = RealFirst(); - - theXMax = RealLast(); - theYMax = RealLast(); - theZMax = RealLast(); + // Return an empty box. + return aResult; } - else + Graphic3d_MapIteratorOfMapOfStructure anIterator (theSet); + for (anIterator.Initialize (theSet); anIterator.More(); anIterator.Next()) { - Standard_Real aXm, aYm, aZm, aXM, aYM, aZM; - Graphic3d_MapIteratorOfMapOfStructure anIterator (theSet); - - theXMin = RealLast(); - theYMin = RealLast(); - theZMin = RealLast(); + const Handle(Graphic3d_Structure)& aStructure = anIterator.Key(); - theXMax = RealFirst (); - theYMax = RealFirst (); - theZMax = RealFirst (); + if (!aStructure->IsVisible()) + continue; - for (anIterator.Initialize (theSet); anIterator.More(); anIterator.Next()) + if (aStructure->IsInfinite() && !theToIgnoreInfiniteFlag) { - const Handle(Graphic3d_Structure)& aStructure = anIterator.Key(); - - if (!aStructure->IsVisible()) - continue; - - if (aStructure->IsInfinite() && !theToIgnoreInfiniteFlag) + //XMin, YMin .... ZMax are initialized by means of infinite line data + Bnd_Box aBox = aStructure->MinMaxValues (Standard_False); + if (!aBox.IsWhole() && !aBox.IsVoid()) { - //XMin, YMin .... ZMax are initialized by means of infinite line data - aStructure->MinMaxValues (aXm, aYm, aZm, aXM, aYM, aZM, Standard_False); - if (aXm != RealFirst() && aXm < theXMin) - { - theXMin = aXm; - } - if (aYm != RealFirst() && aYm < theYMin) - { - theYMin = aYm; - } - if (aZm != RealFirst() && aZm < theZMin) - { - theZMin = aZm; - } - if (aXM != RealLast() && aXM > theXMax) - { - theXMax = aXM; - } - if (aYM != RealLast() && aYM > theYMax) - { - theYMax = aYM; - } - if (aZM != RealLast() && aZM > theZMax) - { - theZMax = aZM; - } + aResult.Add (aBox); } + } - // Only non-empty and non-infinite structures - // are taken into account for calculation of MinMax - if ((!aStructure->IsInfinite() || theToIgnoreInfiniteFlag) && !aStructure->IsEmpty()) - { - aStructure->MinMaxValues (aXm, aYm, aZm, aXM, aYM, aZM, theToIgnoreInfiniteFlag); + // Only non-empty and non-infinite structures + // are taken into account for calculation of MinMax + if ((!aStructure->IsInfinite() || theToIgnoreInfiniteFlag) && !aStructure->IsEmpty()) + { + Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag); - /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */ - //"FitAll" operation ignores object with transform persitence parameter - if(aStructure->TransformPersistenceMode() == Graphic3d_TMF_None ) - { - theXMin = Min (aXm, theXMin); - theYMin = Min (aYm, theYMin); - theZMin = Min (aZm, theZMin); - theXMax = Max (aXM, theXMax); - theYMax = Max (aYM, theYMax); - theZMax = Max (aZM, theZMax); - } + /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */ + //"FitAll" operation ignores object with transform persitence parameter + if(aStructure->TransformPersistenceMode() == Graphic3d_TMF_None ) + { + aResult.Add (aBox); } } - - // The following cases are relevant - // For exemple if all structures are empty or infinite - if (theXMax < theXMin) { aXm = theXMin; theXMin = theXMax; theXMax = aXm; } - if (theYMax < theYMin) { aYm = theYMin; theYMin = theYMax; theYMax = aYm; } - if (theZMax < theZMin) { aZm = theZMin; theZMin = theZMax; theZMax = aZm; } } -} - -// ======================================================================== -// function : MinMaxValues -// purpose : -// ======================================================================== -void Visual3d_View::MinMaxValues (Standard_Real& theXMin, - Standard_Real& theYMin, - Standard_Real& theXMax, - Standard_Real& theYMax, - const Standard_Boolean theToIgnoreInfiniteFlag) const -{ - MinMaxValues (myStructsDisplayed, - theXMin, theYMin, - theXMax, theYMax, - theToIgnoreInfiniteFlag); -} - -// ======================================================================== -// function : MinMaxValues -// purpose : -// ======================================================================== -void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet, - Standard_Real& theXMin, - Standard_Real& theYMin, - Standard_Real& theXMax, - Standard_Real& theYMax, - const Standard_Boolean theToIgnoreInfiniteFlag) const -{ - Standard_Real aXm, aYm, aZm, aXM, aYM, aZM; - Standard_Real aXp, aYp, aZp; - - MinMaxValues (theSet, aXm, aYm, aZm, aXM, aYM, aZM, theToIgnoreInfiniteFlag); - - Projects (aXm, aYm, aZm, aXp, aYp, aZp); - theXMin = aXp; - theYMin = aYp; - - Projects (aXM, aYM, aZM, aXp, aYp, aZp); - theXMax = aXp; - theYMax = aYp; - - if (theXMax < theXMin) { aXp = theXMax; theXMax = theXMin; theXMin = aXp; } - if (theYMax < theYMin) { aYp = theYMax; theYMax = theYMin; theYMin = aYp; } + return aResult; } // ======================================================================= @@ -2199,23 +2078,16 @@ void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType) myGraphicDriver->TriedronEcho (MyCView, theType); } -static Standard_Boolean checkFloat (const Standard_Real theValue) -{ - return theValue > -FLT_MAX - && theValue < FLT_MAX; -} - static void SetMinMaxValuesCallback (Visual3d_View* theView) { - Graphic3d_Vec3d aMin, aMax; - theView->MinMaxValues (aMin.x(), aMin.y(), aMin.z(), - aMax.x(), aMax.y(), aMax.z()); - if (checkFloat (aMin.x()) && checkFloat (aMin.y()) && checkFloat (aMin.z()) - && checkFloat (aMax.x()) && checkFloat (aMax.y()) && checkFloat (aMax.z())) + Bnd_Box aBox = theView->MinMaxValues(); + if (!aBox.IsVoid()) { + gp_Pnt aMin = aBox.CornerMin(); + gp_Pnt aMax = aBox.CornerMax(); const Handle(Graphic3d_GraphicDriver)& aDriver = theView->GraphicDriver(); - aDriver->GraduatedTrihedronMinMaxValues ((Standard_ShortReal )aMin.x(), (Standard_ShortReal )aMin.y(), (Standard_ShortReal )aMin.z(), - (Standard_ShortReal )aMax.x(), (Standard_ShortReal )aMax.y(), (Standard_ShortReal )aMax.z()); + aDriver->GraduatedTrihedronMinMaxValues ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z(), + (Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z()); } } -- 2.20.1