]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #736: axis size correct computation basing on bounding box of cylindrical face
authormpv <mpv@opencascade.com>
Wed, 19 Aug 2015 11:48:39 +0000 (14:48 +0300)
committermpv <mpv@opencascade.com>
Wed, 19 Aug 2015 11:48:39 +0000 (14:48 +0300)
src/GeomAPI/GeomAPI_Face.cpp
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp

index 4b300475928fe493a2d309c1eb00efe7e030e57c..826b8477ae7a5ebb95545ea5dc3040489a29ac0a 100644 (file)
@@ -18,6 +18,7 @@
 #include <Geom_Plane.hxx>
 #include <Geom_CylindricalSurface.hxx>
 #include <GeomLib_IsPlanarSurface.hxx>
+#include <Geom_RectangularTrimmedSurface.hxx>
 
 GeomAPI_Face::GeomAPI_Face()
   : GeomAPI_Shape()
@@ -66,6 +67,10 @@ bool GeomAPI_Face::isPlanar() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
+  Handle(Geom_RectangularTrimmedSurface) aTrimmed = 
+    Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
+  if (!aTrimmed.IsNull())
+    aSurf = aTrimmed->BasisSurface();
   GeomLib_IsPlanarSurface isPlanar(aSurf);
   return isPlanar.IsPlanar() == Standard_True;
 }
@@ -74,6 +79,10 @@ bool GeomAPI_Face::isCylindrical() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
+  Handle(Geom_RectangularTrimmedSurface) aTrimmed = 
+    Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
+  if (!aTrimmed.IsNull())
+    aSurf = aTrimmed->BasisSurface();
   return aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) == Standard_True;
 }
 
index fdf2fc434a4760f5f8ff3e5d1f9c86ce692818ec..3c177a1787e65cce0425633c6ba3540bf2cf2c2e 100644 (file)
 #include <BRep_Tool.hxx>
 #include <Geom_Plane.hxx>
 #include <Geom_CylindricalSurface.hxx>
+#include <Geom_RectangularTrimmedSurface.hxx>
 
 #include <gp_Ax2.hxx>
 #include <gp_Circ.hxx>
+#include <Bnd_Box.hxx>
+#include <BRepBndLib.hxx>
 
 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
     std::shared_ptr<GeomAPI_Pnt> theStart, std::shared_ptr<GeomAPI_Pnt> theEnd)
@@ -48,14 +51,55 @@ std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::cylinderAxis(
   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
   if (aSurf.IsNull())
     return aResult;
+  Handle(Geom_RectangularTrimmedSurface) aTrimmed = 
+    Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
+  if (!aTrimmed.IsNull())
+    aSurf = aTrimmed->BasisSurface();
   Handle(Geom_CylindricalSurface) aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf);
   if (aCyl.IsNull())
     return aResult;
   gp_Ax1 anAxis = aCyl->Axis();
+  // compute the start and the end points of the resulting edge by the bounding box of the face
+  // (vertices projected to the axis) plus 10%
+  Bnd_Box aFaceBnd;
+  BRepBndLib::Add(aFace, aFaceBnd);
+  gp_Pnt aBoxMin(aFaceBnd.CornerMin()), aBoxMax(aFaceBnd.CornerMax());
+  bool isFirst = true;
+  double aParamMin = 0, aParamMax = 0;
+  for(int aX = 0; aX < 2; aX++) {
+    for(int aY = 0; aY < 2; aY++) {
+      for(int aZ = 0; aZ < 2; aZ++) {
+        gp_XYZ aBoxVertex(aX == 0 ? aBoxMin.X() : aBoxMax.X(), 
+          aY == 0 ? aBoxMin.Y() : aBoxMax.Y(), aZ == 0 ? aBoxMin.Z() : aBoxMax.Z());
+        gp_XYZ aVec(aBoxVertex - anAxis.Location().XYZ());
+        double aProjParam = aVec.Dot(anAxis.Direction().XYZ());
+        if (isFirst) {
+          isFirst = false;
+          aParamMin = aProjParam;
+          aParamMax = aProjParam;
+        } else {
+          if (aParamMin > aProjParam)
+            aParamMin = aProjParam;
+          else if (aParamMax < aProjParam)
+            aParamMax = aProjParam;
+        }
+      }
+    }
+  }
+  // add 10%
+  double aDelta = aParamMax - aParamMin;
+  if (aDelta < 1.e-4) aDelta = 1.e-4;
+  aParamMin -= aDelta * 0.1;
+  aParamMax += aDelta * 0.1;
+
+  gp_Pnt aStart(aParamMin * anAxis.Direction().XYZ() + anAxis.Location().XYZ());
+  gp_Pnt anEnd(aParamMax * anAxis.Direction().XYZ() + anAxis.Location().XYZ());
+  /*
   gp_Pnt aStart(anAxis.Location().Transformed(aLoc.Transformation()));
   // edge length is 100, "-" because cylinder of extrusion has negative direction with the cylinder
   gp_Pnt anEnd(anAxis.Location().XYZ() - anAxis.Direction().XYZ() * 100.);
   anEnd.Transform(aLoc.Transformation());
+  */
   
   BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
   std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);