0024712: Extend DRAW commands "vertex" and "extrema". Create test to check all points...
authorabk <abk@opencascade.com>
Thu, 3 Apr 2014 12:34:22 +0000 (16:34 +0400)
committerapn <apn@opencascade.com>
Fri, 4 Apr 2014 08:57:32 +0000 (12:57 +0400)
DRAW command "vertex" was extended to create vertex from point.
DRAW command "extrema" was extended and unified: both extrema points are outputted to DRAW in case of too close points;
parameters of extremal points are outputted.
35 shapes were added for anti-regression tests.
Second DRAW test was created for bug CR23830.

Move shapes to shape-repository

src/BRepTest/BRepTest_CurveCommands.cxx
src/GeometryTest/GeometryTest_APICommands.cxx
tests/bugs/moddata_3/bug23830_2 [new file with mode: 0644]

index 857b653..c924a58 100644 (file)
@@ -57,6 +57,7 @@
 #include <Draw_Appli.hxx>
 #include <DrawTrSurf.hxx>
 #include <DrawTrSurf_BSplineCurve2d.hxx>
+#include <DrawTrSurf_Point.hxx>
 
 #include <gp.hxx>
 #include <Precision.hxx>
@@ -78,12 +79,13 @@ Standard_IMPORT Draw_Viewer dout;
 
 static Standard_Integer vertex(Draw_Interpretor& , Standard_Integer n, const char** a)
 {
-  if (n < 4) return 1;
+  if (n < 3) return 1;
   if (n >= 5) {
     DBRep::Set(a[1],
       BRepBuilderAPI_MakeVertex(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]))));
   }
-  else {
+  else if (n == 4)
+  {
     TopoDS_Shape S = DBRep::Get(a[3]);
     if (S.IsNull()) return 0;
     if (S.ShapeType() != TopAbs_EDGE) return 0;
@@ -92,6 +94,12 @@ static Standard_Integer vertex(Draw_Interpretor& , Standard_Integer n, const cha
     C.D0(Draw::Atof(a[2]),P);
     DBRep::Set(a[1], BRepBuilderAPI_MakeVertex(P));
   }
+  else
+  {
+    Handle(DrawTrSurf_Point) aP =
+      Handle(DrawTrSurf_Point)::DownCast(Draw::Get(a[2]));
+    DBRep::Set(a[1], BRepBuilderAPI_MakeVertex(aP->Point()));
+  }
   return 0;
 }
 
@@ -1772,7 +1780,7 @@ void  BRepTest::CurveCommands(Draw_Interpretor& theCommands)
   const char* g = "TOPOLOGY Curve topology commands";
 
   theCommands.Add("vertex",
-    "vertex name [x y z / p edge]",__FILE__,
+    "vertex name [x y z | p edge | poin]",__FILE__,
     vertex,g);
 
   theCommands.Add("etrim",
index 5e58fca..b19c685 100644 (file)
@@ -320,7 +320,10 @@ static Standard_Integer surfapp(Draw_Interpretor& di, Standard_Integer n, const
 
 static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a)
 {
-  if ( n<3) return 1;
+  if (n < 3)
+  {
+    return 1;
+  }
 
   Handle(Geom_Curve)   GC1, GC2;
   Handle(Geom_Surface) GS1, GS2;
@@ -330,7 +333,7 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
   Standard_Boolean S1 = Standard_False;
   Standard_Boolean S2 = Standard_False;
 
-  Standard_Real U1f,U1l,U2f,U2l,V1f = 0.,V1l = 0.,V2f = 0.,V2l = 0.;
+  Standard_Real U1f, U1l, U2f, U2l, V1f = 0., V1l = 0., V2f = 0., V2l = 0.;
 
   GC1 = DrawTrSurf::GetCurve(a[1]);
   if ( GC1.IsNull()) {
@@ -360,134 +363,143 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
     U2l = GC2->LastParameter();
   }
 
-  char name[100];
-  if ( C1 && C2)
+  NCollection_Vector<gp_Pnt> aPnts1, aPnts2;
+  NCollection_Vector<Standard_Real> aPrms[4];
+  if (C1 && C2)
+  {
+    GeomAPI_ExtremaCurveCurve Ex(GC1, GC2, U1f, U1l, U2f, U2l);
+    if (!Ex.Extrema().IsParallel())
     {
-    GeomAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
-
-    if(!Ex.Extrema().IsParallel())
+      for (Standard_Integer aJ = 1; aJ <= Ex.NbExtrema(); ++aJ)
       {
-      const Standard_Integer aNExtr = Ex.NbExtrema();
-      if(aNExtr == 0)
-        {
-        di << "No solutions!\n";
-        }
-      else
-        {
-        for ( Standard_Integer i = 1; i <= aNExtr; i++)
-          {
-          gp_Pnt P1,P2;
-          Ex.Points(i,P1,P2);
-          Standard_Real U1,V1;
-          Ex.Parameters(i,U1,V1);
-          if (P1.Distance(P2) < 1.e-16)
-            {
-            di << "Extrema " << i << " is point : " << P1.X() << " " << P1.Y() << " " << P1.Z() << "\n";
-            continue;
-            }
-
-          Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
-          Handle(Geom_TrimmedCurve) CT = 
-            new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
-          Sprintf(name,"%s%d","ext_",i);
-          char* temp = name; // portage WNT
-          DrawTrSurf::Set(temp, CT);
-#ifdef DEB          
-          di << name << "(U=" << U1 << ";V=" << V1 << ")" << "\n";
-#else
-          di << name << " ";
-#endif
-          }
-        }
+        gp_Pnt aP1, aP2;
+        Ex.Points(aJ, aP1, aP2);
+        aPnts1.Append(aP1);
+        aPnts2.Append(aP2);
+
+        Standard_Real aU1, aU2;
+        Ex.Parameters(aJ, aU1, aU2);
+        aPrms[0].Append(aU1);
+        aPrms[2].Append(aU2);
       }
+    }
     else
-      {
+    {
       di << "Infinite number of extremas, distance = " << Ex.LowerDistance() << "\n";
-      }
     }
-  else if ( C1 & S2)
+  }
+  else if (C1 && S2)
+  {
+    GeomAPI_ExtremaCurveSurface Ex(GC1, GS2, U1f, U1l, U2f, U2l, V2f, V2l);
+    for (Standard_Integer aJ = 1; aJ <= Ex.NbExtrema(); ++aJ)
+    {
+      gp_Pnt aP1, aP2;
+      Ex.Points(aJ, aP1, aP2);
+      aPnts1.Append(aP1);
+      aPnts2.Append(aP2);
+
+      Standard_Real aU1, aU2, aV2;
+      Ex.Parameters(aJ, aU1, aU2, aV2);
+      aPrms[0].Append(aU1);
+      aPrms[2].Append(aU2);
+      aPrms[3].Append(aV2);
+    }
+  }
+  else if (S1 && C2)
+  {
+    GeomAPI_ExtremaCurveSurface Ex(GC2, GS1, U2f, U2l, U1f, U1l, V1f, V1l);
+    for (Standard_Integer aJ = 1; aJ <= Ex.NbExtrema(); ++aJ)
     {
-    GeomAPI_ExtremaCurveSurface Ex(GC1,GS2,U1f,U1l,U2f,U2l,V2f,V2l);
-
-    const Standard_Integer aNExtr = Ex.NbExtrema();
-    if(aNExtr == 0)
-      {
-      di << "No solutions!\n";
-      }
-    else
-      {
-      for ( Standard_Integer i = 1; i <= aNExtr; i++)
-        {
-        gp_Pnt P1,P2;
-        Ex.Points(i,P1,P2);
-        if (P1.Distance(P2) < 1.e-16) continue;
-        Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
-        Handle(Geom_TrimmedCurve) CT = 
-          new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
-        Sprintf(name,"%s%d","ext_",i);
-        char* temp = name; // portage WNT
-        DrawTrSurf::Set(temp, CT);
-        di << name << " ";
-        }
-      }
+      gp_Pnt aP2, aP1;
+      Ex.Points(aJ, aP2, aP1);
+      aPnts1.Append(aP1);
+      aPnts2.Append(aP2);
+
+      Standard_Real aU1, aV1, aU2;
+      Ex.Parameters(aJ, aU2, aU1, aV1);
+      aPrms[0].Append(aU1);
+      aPrms[1].Append(aV1);
+      aPrms[2].Append(aU2);
     }
-  else if ( S1 & C2)
+  }
+  else if (S1 && S2)
+  {
+    GeomAPI_ExtremaSurfaceSurface Ex(
+      GS1, GS2, U1f, U1l, V1f, V1l, U2f, U2l, V2f, V2l);
+    for (Standard_Integer aJ = 1; aJ <= Ex.NbExtrema(); ++aJ)
     {
-    GeomAPI_ExtremaCurveSurface Ex(GC2,GS1,U2f,U2l,U1f,U1l,V1f,V1l);
+      gp_Pnt aP1, aP2;
+      Ex.Points(aJ, aP1, aP2);
+      aPnts1.Append(aP1);
+      aPnts2.Append(aP2);
+
+      Standard_Real aU1, aV1, aU2, aV2;
+      Ex.Parameters(aJ, aU1, aV1, aU2, aV2);
+      aPrms[0].Append(aU1);
+      aPrms[1].Append(aV1);
+      aPrms[2].Append(aU2);
+      aPrms[3].Append(aV2);
+    }
+  }
 
-    const Standard_Integer aNExtr = Ex.NbExtrema();
-    if(aNExtr == 0)
-      {
-      di << "No solutions!\n";
-      }
-    else
-      {
-      for ( Standard_Integer i = 1; i <= aNExtr; i++)
-        {
-        gp_Pnt P1,P2;
-        Ex.Points(i,P1,P2);
-        if (P1.Distance(P2) < 1.e-16) continue;
-        Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
-        Handle(Geom_TrimmedCurve) CT = 
-          new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
-        Sprintf(name,"%s%d","ext_",i);
-        char* temp = name; // portage WNT
-        DrawTrSurf::Set(temp, CT);
-        di << name << " ";
-        }
-      }
+  char aName[100];
+  char* aName2 = aName; // portage WNT
+
+  // Output points.
+  const Standard_Integer aPntCount = aPnts1.Size();
+  if (aPntCount == 0)
+  {
+    di << "No solutions!\n";
+  }
+  for (Standard_Integer aJ = 1; aJ <= aPntCount; aJ++)
+  {
+    gp_Pnt aP1 = aPnts1(aJ - 1), aP2 = aPnts2(aJ - 1);
+
+    if (aP1.Distance(aP2) < 1.e-16)
+    {
+      di << "Extrema " << aJ << " is point : " <<
+        aP1.X() << " " << aP1.Y() << " " << aP1.Z() << "\n";
+      continue;
     }
-  else if ( S1 & S2)
+
+    Handle(Geom_Line) aL = new Geom_Line(aP1, gp_Vec(aP1, aP2));
+    Handle(Geom_TrimmedCurve) aCT = 
+      new Geom_TrimmedCurve(aL, 0., aP1.Distance(aP2));
+    Sprintf(aName, "%s%d", "ext_", aJ);
+    DrawTrSurf::Set(aName2, aCT);
+    di << aName << " ";
+  }
+
+  if (n >= 4)
+  {
+    // Output points.
+    for (Standard_Integer aJ = 1; aJ <= aPntCount; aJ++)
     {
-    GeomAPI_ExtremaSurfaceSurface Ex(GS1,GS2,U1f,U1l,V1f,V1l,U2f,U2l,V2f,V2l);
+      gp_Pnt aP1 = aPnts1(aJ - 1), aP2 = aPnts2(aJ - 1);
+      Sprintf(aName, "%s%d%s", "ext_", aJ, "_2");
+      DrawTrSurf::Set(aName2, aP1);
+      di << aName << " ";
+      Sprintf(aName, "%s%d%s", "ext_", aJ, "_3");
+      DrawTrSurf::Set(aName2, aP2);
+      di << aName << " ";
+    }
 
-    const Standard_Integer aNExtr = Ex.NbExtrema();
-    if(aNExtr == 0)
+    // Output parameters.
+    for (Standard_Integer aJ = 0; aJ < 4; ++aJ)
+    {
+      for (Standard_Integer aPrmCount = aPrms[aJ].Size(), aK = 0;
+        aK < aPrmCount; ++aK)
       {
-      di << "No solutions!\n";
-      }
-    else
-      {
-      for ( Standard_Integer i = 1; i <= aNExtr; i++)
-        {
-        gp_Pnt P1,P2;
-        Ex.Points(i,P1,P2);
-        if (P1.Distance(P2) < 1.e-16)
-          continue;
-
-        Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
-        Handle(Geom_TrimmedCurve) CT = 
-          new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
-        Sprintf(name,"%s%d","ext_",i);
-        char* temp = name; // portage WNT
-        DrawTrSurf::Set(temp, CT);
-        di << name << " ";
-        }
+        Standard_Real aP = aPrms[aJ](aK);
+        Sprintf(aName, "%s%d%s%d", "prm_", aJ + 1, "_", aK + 1);
+        Draw::Set(aName2, aP);
+        di << aName << " ";
       }
     }
+  }
 
   return 0;
-  }
+}
 
 //=======================================================================
 //function : totalextcc
@@ -573,6 +585,6 @@ void GeometryTest::APICommands(Draw_Interpretor& theCommands)
        "grilapp result nbupoint nbvpoint X0 dX Y0 dY z11 z12 .. z1nu ....  ",
         __FILE__,grilapp);
 
-  theCommands.Add("extrema", "extrema curve/surface curve/surface",__FILE__,extrema);
+  theCommands.Add("extrema", "extrema curve/surface curve/surface [extended_output = 0|1]",__FILE__,extrema);
   theCommands.Add("totalextcc", "totalextcc curve curve",__FILE__,totalextcc);
 }
diff --git a/tests/bugs/moddata_3/bug23830_2 b/tests/bugs/moddata_3/bug23830_2
new file mode 100644 (file)
index 0000000..683f12d
--- /dev/null
@@ -0,0 +1,66 @@
+puts "================"
+puts "OCC23830_2"
+puts "================"
+puts ""
+#######################################################################
+# BRepExtrema_DistShapeShape does not find intersection of face with edge
+#######################################################################
+
+restore [locate_data_file bug23830_face.brep] f
+mksurface s f
+
+for {set i 1} {$i <= 45} {incr i} {
+  restore [locate_data_file bug23830_circle$i.brep] c_$i
+  mkcurve c_$i c_$i
+  extrema s c_$i 1
+  if {![isdraw ext_1_2] || ![isdraw ext_1_3]} {
+    puts "Error: invalid result"
+  }
+  vertex v${i}_1 ext_1_2
+  vertex v${i}_2 ext_1_3
+  unset ext_1_2
+  unset ext_1_3
+}
+
+for {set i 1} {$i <= 45} {incr i} {
+  regexp {Point\s3D\s:\s([-0-9+.e, ]+)} [dump v${i}_1] aDummy aP1
+  regexp {Point\s3D\s:\s([-0-9+.e, ]+)} [dump v${i}_2] aDummy aP2
+  regexp {(^[-0-9+.e]+)} $aP1 aDummy aX1
+  regexp {,\s([-0-9+.e]+),\s} $aP1 aDummy aY1
+  regexp {\s([-0-9+.e]+)$} $aP2 aDummy aZ1
+  regexp {(^[-0-9+.e]+)} $aP2 aDummy aX2
+  regexp {,\s([-0-9+.e]+),\s} $aP2 aDummy aY2
+  regexp {\s([-0-9+.e]+)$} $aP2 aDummy aZ2
+  set aC${i}_1 [concat "$aX1 $aY1 $aZ1"]
+  set aC${i}_2 [concat "$aX2 $aY2 $aZ2"]
+  set aD$i [expr sqrt(($aX2 - $aX1) * ($aX2 - $aX1) + ($aY2 - $aY1) * ($aY2 - $aY1) + ($aZ2 - $aZ1) * ($aZ2 - $aZ1))]
+  if {[set aD$i] > 1e-11} {
+    puts "Error: invalid result ($i)"
+  }
+}
+
+for {set i 1} {$i <= 45} {incr i} {
+  puts ""
+  puts "$i"
+  puts [set aC${i}_1]
+  puts [set aC${i}_2]
+  puts [set aD$i]
+}
+
+smallview
+l
+l
+l
+l
+l
+l
+l
+l
+erase
+display f
+for {set i 1} {$i <= 45} {incr i} {
+  display v${i}_1
+  display v${i}_2
+}
+fit
+set only_screen_axo 1