0025768: Visualization, Graphic3d_Structure - do not use invalid bounding boxes of...
authorkgv <kgv@opencascade.com>
Thu, 5 Feb 2015 15:05:31 +0000 (18:05 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 5 Feb 2015 15:06:21 +0000 (18:06 +0300)
Prs3d_WFShape::Add() - do not create empty group

Graphic3d_Structure::minMaxCoord() - do not use uninitialized bounding box

Added test case bugs/vis/bug25768

src/Graphic3d/Graphic3d_Structure.cdl
src/Graphic3d/Graphic3d_Structure.cxx
src/Prs3d/Prs3d_WFShape.cxx
src/StdPrs/StdPrs_DeflectionCurve.cxx
tests/bugs/vis/bug25768 [new file with mode: 0644]

index 194e568..c4e94ec 100644 (file)
@@ -853,8 +853,7 @@ is
        ---Purpose: Returns the identification number of the structure <me>.
        ---Category: Private methods
 
-  minMaxCoord (me;
-               theToIgnoreInfiniteFlag : Boolean from Standard = Standard_False)
+  minMaxCoord (me)
     returns BndBox4f from Graphic3d
   is static private;
   ---Purpose: Returns the extreme coordinates found in the structure <me> without transformation applied.
index 1929d1b..053d0af 100644 (file)
@@ -1749,21 +1749,12 @@ Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
 //function : minMaxCoord
 //purpose  :
 //=============================================================================
-Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord (const Standard_Boolean theToIgnoreInfiniteFlag) const
+Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
 {
   Graphic3d_BndBox4f aBnd;
   for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
   {
-    if (!theToIgnoreInfiniteFlag)
-    {
-      aBnd.Combine (aGroupIter.Value()->BoundingBox());
-    }
-    else
-    {
-      Graphic3d_BndBox4f aValidBnd (aGroupIter.Value()->BoundingBox().CornerMin(),
-                                    aGroupIter.Value()->BoundingBox().CornerMax());
-      aBnd.Combine (aValidBnd);
-    }
+    aBnd.Combine (aGroupIter.Value()->BoundingBox());
   }
   return aBnd;
 }
@@ -1775,7 +1766,7 @@ Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord (const Standard_Boolean theT
 void Graphic3d_Structure::getBox (Graphic3d_BndBox4d&    theBox,
                                   const Standard_Boolean theToIgnoreInfiniteFlag) const
 {
-  Graphic3d_BndBox4f aBoxF = minMaxCoord (theToIgnoreInfiniteFlag);
+  Graphic3d_BndBox4f aBoxF = minMaxCoord();
   if (aBoxF.IsValid())
   {
     theBox = Graphic3d_BndBox4d (Graphic3d_Vec4d ((Standard_Real )aBoxF.CornerMin().x(),
index 34d4425..de6a9e0 100755 (executable)
@@ -157,8 +157,6 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
 
   Standard_Real aDeflection = Prs3d::GetDeflection(theShape, theDrawer);
 
-  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
-
   Prs3d_NListOfSequenceOfPnt anUIsoCurves;
   Prs3d_NListOfSequenceOfPnt aVIsoCurves;
   Prs3d_NListOfSequenceOfPnt aWireCurves;
@@ -424,7 +422,6 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
   if (theDrawer->WireDraw())
   {
     // Wire (without any neighbour)
-    aGroup->SetPrimitivesAspect (theDrawer->WireAspect()->Aspect());
     for (anIt.Initialize(aLWire); anIt.More(); anIt.Next())
     {
       const TopoDS_Edge& anEdge = TopoDS::Edge (anIt.Value());
index 1d5d289..57a3a33 100644 (file)
@@ -127,17 +127,16 @@ static Standard_Boolean FindLimits(const Adaptor3d_Curve& aCurve,
 
 
 //==================================================================
-// function: DrawCurve
+// function: drawCurve
 // purpose:
 //==================================================================
-static void DrawCurve (Adaptor3d_Curve&              aCurve,
-                       const Handle(Graphic3d_Group) aGroup,
+static void drawCurve (Adaptor3d_Curve&              aCurve,
+                       const Handle(Graphic3d_Group)& aGroup,
                        const Quantity_Length         TheDeflection,
                        const Standard_Real           anAngle,
                        const Standard_Real           U1,
                        const Standard_Real           U2,
-                       TColgp_SequenceOfPnt&         Points,
-                       const Standard_Boolean drawCurve)
+                       TColgp_SequenceOfPnt&         Points)
 {
   switch (aCurve.GetType())
   {
@@ -147,7 +146,7 @@ static void DrawCurve (Adaptor3d_Curve&              aCurve,
       gp_Pnt p2 = aCurve.Value(U2);
       Points.Append(p1);
       Points.Append(p2);
-      if(drawCurve)
+      if (!aGroup.IsNull())
       {
         Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
         aPrims->AddVertex(p1);
@@ -187,17 +186,21 @@ static void DrawCurve (Adaptor3d_Curve&              aCurve,
       }
 
       Handle(Graphic3d_ArrayOfPolylines) aPrims;
-      if(drawCurve)
+      if (!aGroup.IsNull())
         aPrims = new Graphic3d_ArrayOfPolylines(SeqP.Length());
       
       for (i = 1; i <= SeqP.Length(); i++) { 
         const gp_Pnt& p = SeqP.Value(i);
         Points.Append(p);
-        if(drawCurve)
+        if (!aGroup.IsNull())
+        {
           aPrims->AddVertex(p);
+        }
+      }
+      if (!aGroup.IsNull())
+      {
+        aGroup->AddPrimitiveArray (aPrims);
       }
-      if(drawCurve)
-        aGroup->AddPrimitiveArray(aPrims);
     }
   }
 }
@@ -285,7 +288,7 @@ static Standard_Boolean MatchCurve (
 void StdPrs_DeflectionCurve::Add (const Handle (Prs3d_Presentation)& aPresentation,
                                   Adaptor3d_Curve&                   aCurve,
                                   const Handle (Prs3d_Drawer)&       aDrawer,
-                                  const Standard_Boolean drawCurve)
+                                  const Standard_Boolean theToDrawCurve)
 {
   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(aDrawer->LineAspect()->Aspect());
 
@@ -293,11 +296,17 @@ void StdPrs_DeflectionCurve::Add (const Handle (Prs3d_Presentation)& aPresentati
   if (FindLimits(aCurve, aDrawer->MaximalParameterValue(), V1, V2))
   {
     TColgp_SequenceOfPnt Points;
-    DrawCurve(aCurve,
-              Prs3d_Root::CurrentGroup(aPresentation),
+    Handle(Graphic3d_Group) aGroup;
+    if (theToDrawCurve)
+    {
+      aGroup = Prs3d_Root::CurrentGroup (aPresentation);
+    }
+
+    drawCurve(aCurve,
+              aGroup,
               GetDeflection(aCurve, V1, V2, aDrawer),
               aDrawer->DeviationAngle(),
-              V1, V2, Points, drawCurve);
+              V1, V2, Points);
 
     if (aDrawer->LineArrowDraw()) {
       gp_Pnt Location;
@@ -322,9 +331,14 @@ void StdPrs_DeflectionCurve::Add (const Handle (Prs3d_Presentation)& aPresentati
                                   const Standard_Real                U1,
                                   const Standard_Real                U2,
                                   const Handle (Prs3d_Drawer)&       aDrawer,
-                                  const Standard_Boolean drawCurve)
+                                  const Standard_Boolean theToDrawCurve)
 {
-  Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(aDrawer->LineAspect()->Aspect());
+  Handle(Graphic3d_Group) aGroup;
+  if (theToDrawCurve)
+  {
+    aGroup = Prs3d_Root::CurrentGroup (aPresentation);
+    aGroup->SetPrimitivesAspect(aDrawer->LineAspect()->Aspect());
+  }
 
   Standard_Real V1 = U1;
   Standard_Real V2 = U2;  
@@ -333,11 +347,11 @@ void StdPrs_DeflectionCurve::Add (const Handle (Prs3d_Presentation)& aPresentati
   if (Precision::IsPositiveInfinite(V2)) V2 = aDrawer->MaximalParameterValue();
 
   TColgp_SequenceOfPnt Points;
-  DrawCurve(aCurve,
-            Prs3d_Root::CurrentGroup(aPresentation),
+  drawCurve(aCurve,
+            aGroup,
             GetDeflection(aCurve, V1, V2, aDrawer),
             aDrawer->DeviationAngle(),
-            V1 , V2, Points, drawCurve);
+            V1 , V2, Points);
 
   if (aDrawer->LineArrowDraw()) {
     gp_Pnt Location;
@@ -362,10 +376,15 @@ void StdPrs_DeflectionCurve::Add (const Handle (Prs3d_Presentation)& aPresentati
                                   const Standard_Real                aDeflection,
                                   TColgp_SequenceOfPnt&              Points,
                                   const Standard_Real                anAngle,
-                                  const Standard_Boolean drawCurve)
+                                  const Standard_Boolean theToDrawCurve)
 {
-  DrawCurve(aCurve, Prs3d_Root::CurrentGroup(aPresentation),
-            aDeflection, anAngle, U1, U2, Points, drawCurve);
+  Handle(Graphic3d_Group) aGroup;
+  if (theToDrawCurve)
+  {
+    aGroup = Prs3d_Root::CurrentGroup (aPresentation);
+  }
+
+  drawCurve (aCurve, aGroup, aDeflection, anAngle, U1, U2, Points);
 }
 
 //==================================================================
@@ -377,15 +396,22 @@ void StdPrs_DeflectionCurve::Add (const Handle (Prs3d_Presentation)& aPresentati
                                   const Standard_Real                aDeflection,
                                   const Standard_Real                aLimit,
                                   const Standard_Real                anAngle,
-                                  const Standard_Boolean drawCurve) 
+                                  const Standard_Boolean theToDrawCurve)
 {
   Standard_Real V1, V2;
-  if (FindLimits(aCurve, aLimit, V1, V2))
+  if (!FindLimits(aCurve, aLimit, V1, V2))
   {
-    TColgp_SequenceOfPnt Points;
-    DrawCurve(aCurve, Prs3d_Root::CurrentGroup(aPresentation),
-              aDeflection, anAngle, V1, V2, Points, drawCurve);
+    return;
   }
+
+  Handle(Graphic3d_Group) aGroup;
+  if (theToDrawCurve)
+  {
+    aGroup = Prs3d_Root::CurrentGroup (aPresentation);
+  }
+
+  TColgp_SequenceOfPnt Points;
+  drawCurve (aCurve, aGroup, aDeflection, anAngle, V1, V2, Points);
 }
 
 
@@ -398,12 +424,20 @@ void StdPrs_DeflectionCurve::Add (const Handle (Prs3d_Presentation)& aPresentati
                                   const Standard_Real                aDeflection,
                                   const Handle(Prs3d_Drawer)&        aDrawer,
                                   TColgp_SequenceOfPnt&              Points,
-                                  const Standard_Boolean drawCurve) 
+                                  const Standard_Boolean theToDrawCurve)
 {
   Standard_Real V1, V2;
-  if (FindLimits(aCurve, aDrawer->MaximalParameterValue(), V1, V2))
-    DrawCurve(aCurve, Prs3d_Root::CurrentGroup(aPresentation),
-              aDeflection, aDrawer->DeviationAngle(), V1, V2, Points, drawCurve);
+  if (!FindLimits(aCurve, aDrawer->MaximalParameterValue(), V1, V2))
+  {
+    return;
+  }
+
+  Handle(Graphic3d_Group) aGroup;
+  if (theToDrawCurve)
+  {
+    aGroup = Prs3d_Root::CurrentGroup (aPresentation);
+  }
+  drawCurve (aCurve, aGroup, aDeflection, aDrawer->DeviationAngle(), V1, V2, Points);
 }
 
 
diff --git a/tests/bugs/vis/bug25768 b/tests/bugs/vis/bug25768
new file mode 100644 (file)
index 0000000..2ef35eb
--- /dev/null
@@ -0,0 +1,28 @@
+puts "========="
+puts "CR25768"
+puts "========="
+puts ""
+###########################################################################################
+# Visualization, Graphic3d_Structure - do not use invalid bounding boxes of empty groups
+###########################################################################################
+box b 100 0 0 2 1 1
+vinit View1
+vclear
+vaxo
+vsetdispmode 0
+vdisplay b
+vfit
+vzoom 0.1
+vbounding b
+
+set x_coord 115
+set y_coord 153
+checkcolor $x_coord $y_coord 0 0 0
+
+if { $stat != 1 } {
+  puts "Error: invalid broken bounding boxes"
+} else {
+  puts "OK: valid boundong box"
+}
+
+set only_screen 1