]> OCCT Git - occt.git/commitdiff
0032995: Modeling algorithms - Interface for checking canonical geometry CR32995-SALOME
authorvsv <vsv@opencascade.com>
Thu, 7 Jul 2022 13:39:51 +0000 (16:39 +0300)
committervsv <vsv@opencascade.com>
Thu, 7 Jul 2022 13:39:51 +0000 (16:39 +0300)
GeomConvert_CurveToAnaCurve, GeomConvert_SurfToAnaSurf - geometrical algorithms
for converting geometrical curve and surfaces in canonical geometry with given tolerance.

ShapeAnalysis_CanonicalRecognition - interface for checking canonical geometry.

# Conflicts:
# src/GeomConvert/FILES
# src/GeomConvert/GeomConvert_CurveToAnaCurve.cxx
# src/GeomConvert/GeomConvert_CurveToAnaCurve.hxx
# src/GeomConvert/GeomConvert_SurfToAnaSurf.cxx
# src/GeomConvert/GeomConvert_SurfToAnaSurf.hxx
# src/SWDRAW/SWDRAW_ShapeAnalysis.cxx
# src/ShapeAnalysis/FILES
# src/ShapeAnalysis/ShapeAnalysis_CanonicalRecognition.cxx
# src/ShapeAnalysis/ShapeAnalysis_CanonicalRecognition.hxx
# tests/cr/base/A1
# tests/cr/base/A2
# tests/cr/base/A3
# tests/cr/base/A4
# tests/cr/base/A5
# tests/cr/base/A6
# tests/cr/base/B1
# tests/cr/base/B2
# tests/cr/base/B3
# tests/cr/base/B4
# tests/cr/base/B5
# tests/cr/base/B6
# tests/cr/base/B7
# tests/cr/base/B8
# tests/cr/base/B9
# tests/cr/grids.list

37 files changed:
dox/user_guides/shape_healing/shape_healing.md
src/GeomConvert/GeomConvert_CurveToAnaCurve.cxx
src/GeomConvert/GeomConvert_CurveToAnaCurve.hxx
src/GeomConvert/GeomConvert_SurfToAnaSurf.cxx
src/GeomConvert/GeomConvert_SurfToAnaSurf.hxx
src/Image/Image_AlienPixMap.cxx
src/SWDRAW/SWDRAW_ShapeAnalysis.cxx
src/ShapeAnalysis/FILES
src/ShapeAnalysis/ShapeAnalysis_CanonicalRecognition.cxx
src/ShapeAnalysis/ShapeAnalysis_CanonicalRecognition.hxx
src/ShapeAnalysis/ShapeAnalysis_FuncConeLSDist.cxx [new file with mode: 0644]
src/ShapeAnalysis/ShapeAnalysis_FuncConeLSDist.hxx [new file with mode: 0644]
src/ShapeAnalysis/ShapeAnalysis_FuncCylinderLSDist.cxx [new file with mode: 0644]
src/ShapeAnalysis/ShapeAnalysis_FuncCylinderLSDist.hxx [new file with mode: 0644]
src/ShapeAnalysis/ShapeAnalysis_FuncSphereLSDist.cxx [new file with mode: 0644]
src/ShapeAnalysis/ShapeAnalysis_FuncSphereLSDist.hxx [new file with mode: 0644]
src/gce/gce_MakeCirc.cxx
tests/cr/approx/A1 [new file with mode: 0644]
tests/cr/approx/A2 [new file with mode: 0644]
tests/cr/approx/A3 [new file with mode: 0644]
tests/cr/approx/A4 [new file with mode: 0644]
tests/cr/base/A1
tests/cr/base/A2
tests/cr/base/A3
tests/cr/base/A4
tests/cr/base/A5
tests/cr/base/A6
tests/cr/base/B1
tests/cr/base/B2
tests/cr/base/B3
tests/cr/base/B4
tests/cr/base/B5
tests/cr/base/B6
tests/cr/base/B7
tests/cr/base/B8
tests/cr/base/B9
tests/cr/grids.list

index abf476b53662f05c502893481b2c93a2c0c332d6..89e53c171f2dfb86423291051bbe0d811bbdd500 100644 (file)
@@ -896,6 +896,25 @@ Analysis of surfaces is allowed for following shapes:
   * wire - the same as for edge, but algorithm checks all edges of wire in order to find analytical surface, which most close to the input sample surface.
 
 
+@subsubsection occt_shg_3_2_4 Analysis of shape underlined geometry
+
+Class *ShapeAnalysis_CanonicalRecognition* provides tools that analyze geometry of shape and explore the possibility of converting geometry into a canonical form.
+Canonical forms for curves are lines, circles and ellipses.
+Canonical forms for surfaces are planar, cylindrical, conical and spherical surfaces.
+
+Recognition and converting into canonical form is performed according to maximal deviation criterium: maximal distance between initial and canonical geometrical objects must be less, than given value.
+
+Analysis of curves is allowed for following shapes:
+  * edge - algorithm checks 3d curve of edge
+  * wire - algorithm checks 3d curves of all edges in order to convert them in the same analytical curve
+
+Analysis of surfaces is allowed for following shapes:
+  * face - algorithm checks surface of face
+  * shell - algorithm checks surfaces of all faces in order to convert them in the same analytical surface
+  * edge - algorithm checks all surfaces that are shared by given edge in order convert one of them in analytical surface, which most close to the input sample surface.
+  * wire - the same as for edge, but algorithm checks all edges of wire in order to find analytical surface, which most close to the input sample surface.
+
+
 @section occt_shg_4 Upgrading
 
 Upgrading tools are intended for adaptation of shapes for better use by Open CASCADE Technology or for customization to particular needs, i.e. for export to another system. This means that not only it corrects and upgrades but also changes the definition of a shape with regard to its geometry, size and other aspects. Convenient API allows you to create your own tools to perform specific upgrading. Additional tools for particular cases provide an ability to divide shapes and surfaces according to certain criteria. 
index f6e40f117aae445570aa7c2da118502c0a2b7b30..8e135e1edb2bfb76d7e2068da62ff3a6fc5568a1 100644 (file)
 #include <TColStd_Array1OfReal.hxx>
 #include <TColStd_Array2OfReal.hxx>
 #include <GeomAbs_CurveType.hxx>
+#include <math_Vector.hxx>
+#include <math_Matrix.hxx>
+#include <math_Gauss.hxx>
 
-//=======================================================================
-//function : AdjustByPeriod
-//purpose  : 
-//=======================================================================
-static Standard_Real AdjustByPeriod(const Standard_Real Val,
-  const Standard_Real ToVal,
-  const Standard_Real Period)
-{
-  Standard_Real diff = Val - ToVal;
-  Standard_Real D = Abs(diff);
-  Standard_Real P = Abs(Period);
-  if (D <= 0.5 * P) return 0.;
-  if (P < 1e-100) return diff;
-  return (diff >0 ? -P : P) * floor(D / P + 0.5);
-}
-
-//=======================================================================
-//function : AdjustToPeriod
-//purpose  : 
-//=======================================================================
-
-static Standard_Real AdjustToPeriod(const Standard_Real Val,
-  const Standard_Real ValMin,
-  const Standard_Real ValMax)
-{
-  return AdjustByPeriod(Val, 0.5 * (ValMin + ValMax), ValMax - ValMin);
-}
 
 GeomConvert_CurveToAnaCurve::GeomConvert_CurveToAnaCurve():
   myGap(Precision::Infinite()),
@@ -141,8 +117,7 @@ Standard_Boolean GeomConvert_CurveToAnaCurve::IsLinear(const TColgp_Array1OfPnt&
       }
     }
   
-  Standard_Real dPreci = Precision::Confusion()*Precision::Confusion();
-  if(dMax < dPreci)
+  if (dMax < Precision::SquareConfusion())
     return Standard_False;
   
   Standard_Real tol2 = tolerance*tolerance;
@@ -197,8 +172,7 @@ Handle(Geom_Line) GeomConvert_CurveToAnaCurve::ComputeLine (const Handle(Geom_Cu
 
   gp_Pnt P1 = curve->Value (c1);
   gp_Pnt P2 = curve->Value (c2);
-  Standard_Real dPreci = Precision::Confusion()*Precision::Confusion();
-  if(P1.SquareDistance(P2) < dPreci)
+  if(P1.SquareDistance(P2) < Precision::SquareConfusion())
     return line;
   cf = c1;  cl = c2;
   
@@ -244,11 +218,9 @@ Handle(Geom_Line) GeomConvert_CurveToAnaCurve::ComputeLine (const Handle(Geom_Cu
 //=======================================================================
 
 Standard_Boolean GeomConvert_CurveToAnaCurve::GetCircle (gp_Circ& crc,   
-                                                const gp_Pnt& P0,const gp_Pnt& P1, const gp_Pnt& P2,
-                                                const Standard_Real d0, const Standard_Real d1, const Standard_Real epsang)
+                                                const gp_Pnt& P0,const gp_Pnt& P1, const gp_Pnt& P2) 
 {
-//  Control if points are not aligned (should be done by MakeCirc ?)
-//  d0 and d1 are distances (p0 p1) and (p0 p2)
+//  Control if points are not aligned (should be done by MakeCirc 
   Standard_Real aMaxCoord = Sqrt(Precision::Infinite());
   if (Abs(P0.X()) > aMaxCoord || Abs(P0.Y()) > aMaxCoord || Abs(P0.Z()) > aMaxCoord)
     return Standard_False;
@@ -256,15 +228,12 @@ Standard_Boolean GeomConvert_CurveToAnaCurve::GetCircle (gp_Circ& crc,
     return Standard_False;
   if (Abs(P2.X()) > aMaxCoord || Abs(P2.Y()) > aMaxCoord || Abs(P2.Z()) > aMaxCoord)
     return Standard_False;
-  gp_Vec p0p1 (P0,P1);
-  gp_Vec p0p2 (P0,P2);
-  Standard_Real ang = p0p1.CrossSquareMagnitude (p0p2);
-  if (ang < d0*d1*epsang) return Standard_False;
 
 //  Building the circle
   gce_MakeCirc mkc (P0,P1,P2);
   if (!mkc.IsDone()) return Standard_False;
   crc = mkc.Value();
+  if (crc.Radius() < gp::Resolution()) return Standard_False;
   //  Recalage sur P0
   gp_Pnt PC = crc.Location();
   gp_Ax2 axe = crc.Position();
@@ -299,22 +268,9 @@ Handle(Geom_Curve) GeomConvert_CurveToAnaCurve::ComputeCircle (const Handle(Geom
   P0 = c3d->Value(c1);
   P1 = c3d->Value(ca);
   P2 = c3d->Value(cb);
-
-//  For Control if points are not aligned (should be done by MakeCirc ?),
-//  d0 and d1 are distances (p0 p1) and (p0 p2)
-//  return result here means : void result (no circle)
-  Standard_Real eps = Precision::Angular();  // angular resolution
-  Standard_Real d0 = P0.Distance(P1);  Standard_Real d1 = P0.Distance(P2);
-  if (d0 < Precision::Confusion() || d1 < Precision::Confusion()) return circ;
   
   gp_Circ crc;
-  if (!GetCircle (crc,P0,P1,P2,d0,d1,eps)) return circ;
-  
-  cf = 0;
-//   Standard_Real cm = ElCLib::Parameter (crc,c3d->Value ((c1+c2)/2) );
-//   cl = ElCLib::Parameter (crc,c3d->Value (c2));
-//   if (cl > 2 * M_PI) cl = 2 * M_PI;
-//   if (cl < cm && cm > 0.99 * M_PI) cl = 2 * M_PI;
+  if (!GetCircle (crc,P0,P1,P2)) return circ;
   
   //  Reste a controler que c est bien un cercle : prendre 20 points
   Standard_Real du = (c2-c1)/20;
@@ -334,17 +290,19 @@ Handle(Geom_Curve) GeomConvert_CurveToAnaCurve::ComputeCircle (const Handle(Geom
   Standard_Real PI2 = 2 * M_PI;
   
   cf = ElCLib::Parameter (crc,c3d->Value (c1));
-  cf+= AdjustToPeriod(cf,0.,PI2);
+  cf = ElCLib::InPeriod(cf, 0., PI2);
+
   //first parameter should be closed to zero
   
   if(Abs(cf) < Precision::PConfusion() || Abs(PI2-cf) < Precision::PConfusion())
     cf = 0.;
-    
+
   Standard_Real cm = ElCLib::Parameter (crc,c3d->Value ((c1+c2)/2.));
-  cm+= AdjustToPeriod(cm,cf,cf+PI2);
+  cm = ElCLib::InPeriod(cm, cf, cf + PI2);
+
   cl = ElCLib::Parameter (crc,c3d->Value (c2));
-  cl+= AdjustToPeriod(cl,cm,cm+PI2);
-  
+  cl = ElCLib::InPeriod(cl, cm, cm + PI2);
+
   circ = new Geom_Circle (crc);
   return circ;
 }
@@ -404,117 +362,6 @@ static Standard_Boolean IsArrayPntPlanar(const Handle(TColgp_HArray1OfPnt)& HAP,
   return Standard_True;
 }
 
-
-//=======================================================================
-//function : Determ3
-//purpose  : 
-//=======================================================================
-
-static Standard_Real Determ3(const TColStd_Array2OfReal& A)
-{
-  Standard_Real det = A.Value(1,1)*A.Value(2,2)*A.Value(3,3) +
-                      A.Value(1,2)*A.Value(2,3)*A.Value(3,1) +
-                      A.Value(1,3)*A.Value(2,1)*A.Value(3,2) -
-                      A.Value(1,3)*A.Value(2,2)*A.Value(3,1) -
-                      A.Value(1,1)*A.Value(2,3)*A.Value(3,2) -
-                      A.Value(1,2)*A.Value(2,1)*A.Value(3,3);
-  return det;
-}
-
-//=======================================================================
-//function : Determ4
-//purpose  : 
-//=======================================================================
-
-static Standard_Real Determ4(const TColStd_Array2OfReal& A)
-{
-  Standard_Real det=0;
-  Standard_Integer i,j,k;
-  TColStd_Array2OfReal C(1,3,1,3);
-
-  for(j=1; j<=4; j++) {
-    for(i=2; i<=4; i++) {
-      for(k=1; k<=4; k++) {
-        if(k<j)
-          C.SetValue(i-1,k,A.Value(i,k));
-        if(k>j)
-          C.SetValue(i-1,k-1,A.Value(i,k));
-      }
-    }
-    if(j==1 || j==3)
-      det = det + A.Value(1,j)*Determ3(C);
-    else
-      det = det - A.Value(1,j)*Determ3(C);
-  }
-  return det;
-}
-
-//=======================================================================
-//function : Determ5
-//purpose  : 
-//=======================================================================
-
-static Standard_Real Determ5(const TColStd_Array2OfReal& A)
-{
-  Standard_Real det=0;
-  Standard_Integer i,j,k;
-  TColStd_Array2OfReal C(1,4,1,4);
-
-  for(j=1; j<=5; j++) {
-    for(i=2; i<=5; i++) {
-      for(k=1; k<=5; k++) {
-        if(k<j)
-          C.SetValue(i-1,k,A.Value(i,k));
-        if(k>j)
-          C.SetValue(i-1,k-1,A.Value(i,k));
-      }
-    }
-    if(j==1 || j==3 || j==5)
-      det = det + A.Value(1,j)*Determ4(C);
-    else
-      det = det - A.Value(1,j)*Determ4(C);
-  }
-  return det;
-}
-
-//=======================================================================
-//function : SolveLinSys5
-//purpose  : 
-//=======================================================================
-
-static Standard_Boolean SolveLinSys5(const TColStd_Array2OfReal& A,
-                                     const TColStd_Array1OfReal& B,
-                                           TColStd_Array1OfReal& X )
-{
-  Standard_Integer i,j;
-  Standard_Real D0,DN;
-  TColStd_Array2OfReal A1(1,5,1,5);
-  TColStd_Array1OfReal Tmp(1,5);
-  for(j=1; j<=5; j++) {
-    for(i=1; i<=5; i++) {
-      A1.SetValue(i,j,A.Value(i,j));
-    }
-  }
-
-  D0 = Determ5(A1);
-  if(D0==0)
-    return Standard_False;
-
-  for(j=1; j<=5; j++) {
-    for(i=1; i<=5; i++) {
-      Tmp.SetValue(i,A1.Value(i,j));
-      A1.SetValue(i,j,B.Value(i));
-    }
-    DN = Determ5(A1);
-    X.SetValue(j,DN/D0);
-    for(i=1; i<=5; i++) {
-      A1.SetValue(i,j,Tmp.Value(i));
-    }
-  }
-  return Standard_True;
-}
-
-
 //=======================================================================
 //function : ConicdDefinition
 //purpose  : 
@@ -675,30 +522,33 @@ Handle(Geom_Curve) GeomConvert_CurveToAnaCurve::ComputeEllipse(const Handle(Geom
   Tr.SetTransformation(AX);
   gp_Trsf Tr2 = Tr.Inverted();
   
-  TColStd_Array2OfReal Dt(1,5,1,5);
-  TColStd_Array1OfReal F(1,5), Sl(1,5);
+  math_Matrix Dt(1, 5, 1, 5);
+  math_Vector F(1, 5), Sl(1, 5);
 
   Standard_Real XN,YN,ZN = 0.;
   gp_Pnt PT,PP;
   for(i=1; i<=5; i++) {
     PT = AP->Value(i).Transformed(Tr);
     PT.Coord(XN,YN,ZN);
-    Dt.SetValue(i, 1, XN*XN);
-    Dt.SetValue(i,2,XN*YN);
-    Dt.SetValue(i,3,YN*YN);
-    Dt.SetValue(i,4,XN);
-    Dt.SetValue(i,5,YN);
-    F.SetValue(i,-1);
+    Dt(i, 1) = XN*XN;
+    Dt(i, 2) = XN*YN;
+    Dt(i, 3) = YN*YN;
+    Dt(i, 4) = XN;
+    Dt(i, 5) = YN;
+    F(i) = -1.;
   }
-  //
-  if(!SolveLinSys5(Dt,F,Sl))
+
+  math_Gauss aSolver(Dt);
+  if (!aSolver.IsDone())
     return res;
+
+  aSolver.Solve(F, Sl);
   
-  AF=Sl.Value(1);
-  BF=Sl.Value(2);
-  CF=Sl.Value(3);
-  DF=Sl.Value(4);
-  EF=Sl.Value(5);
+  AF=Sl(1);
+  BF=Sl(2);
+  CF=Sl(3);
+  DF=Sl(4);
+  EF=Sl(5);
 
   Q1=AF*CF+BF*EF*DF/4-CF*DF*DF/4-BF*BF/4-AF*EF*EF/4;
   Q2=AF*CF-BF*BF/4;
@@ -752,21 +602,23 @@ if (Q2 > 0 && Q1*Q3 < 0) {
 
     Standard_Real PI2 = 2 * M_PI;
     cf = ElCLib::Parameter(anEllipse, c3d->Value(c1));
-    cf += AdjustToPeriod(cf, 0., PI2);
+    cf = ElCLib::InPeriod(cf, 0., PI2);
+
     //first parameter should be closed to zero
 
     if (Abs(cf) < Precision::PConfusion() || Abs(PI2 - cf) < Precision::PConfusion())
       cf = 0.;
 
     Standard_Real cm = ElCLib::Parameter(anEllipse, c3d->Value((c1 + c2) / 2.));
-    cm += AdjustToPeriod(cm, cf, cf + PI2);
+    cm = ElCLib::InPeriod(cm, cf, cf + PI2);
+
     cl = ElCLib::Parameter(anEllipse, c3d->Value(c2));
-    cl += AdjustToPeriod(cl, cm, cm + PI2);
+    cl = ElCLib::InPeriod(cl, cm, cm + PI2);
 
     res = gell;
   }
 }
-
+/*
 if (Q2 < 0 && Q1 != 0) {
   // hyberbola
 }
@@ -774,7 +626,7 @@ if (Q2 < 0 && Q1 != 0) {
 if (Q2 == 0 && Q1 != 0) {
   // parabola
 }
-
+*/
 return res;
 }
 
index fe75c63b7c1d8cc14f3f653e0f20b7b393aa4edb..5bffa86d57e6cadf986b2da582e4c217cdd2b2cd 100644 (file)
@@ -79,7 +79,7 @@ public:
   Standard_EXPORT static gp_Lin GetLine(const gp_Pnt& P1, const gp_Pnt& P2, Standard_Real& cf, Standard_Real& cl);
 
   //! Creates circle on points. Returns true if OK.
-  Standard_EXPORT static Standard_Boolean GetCircle (gp_Circ& Circ, const gp_Pnt& P0, const gp_Pnt& P1, const gp_Pnt& P2, const Standard_Real d0, const Standard_Real d1, const Standard_Real eps);
+  Standard_EXPORT static Standard_Boolean GetCircle(gp_Circ& Circ, const gp_Pnt& P0, const gp_Pnt& P1, const gp_Pnt& P2); 
 
   //! Returns maximal deviation of converted surface from the original
   //! one computed by last call to ConvertToAnalytical
index fdb39148646b5022ad18466f6d9328fffbea0a9c..23fee697e2cd6dfb42b33d585e1e2fb3dbc22706 100644 (file)
 #include <Geom_Plane.hxx>
 #include <Geom_SphericalSurface.hxx>
 #include <Geom_Surface.hxx>
+#include <Geom_SurfaceOfRevolution.hxx>
 #include <Geom_ToroidalSurface.hxx>
 #include <Geom_TrimmedCurve.hxx>
-#include <GeomAdaptor_HSurface.hxx>
+#include <GeomAdaptor_Surface.hxx>
 #include <GeomAdaptor_Surface.hxx>
 #include <GeomLib_IsPlanarSurface.hxx>
 #include <gp_Ax3.hxx>
 #include <GeomConvert_SurfToAnaSurf.hxx>
 #include <TColgp_Array1OfPnt.hxx>
 #include <TColStd_Array1OfReal.hxx>
+#include <Extrema_ExtElC.hxx>
+
+//static method for checking surface of revolution
+//To avoid two-parts cone-like surface
+static void CheckVTrimForRevSurf(const Handle(Geom_SurfaceOfRevolution)& aRevSurf,
+  Standard_Real& V1, Standard_Real& V2)
+{
+  const Handle(Geom_Curve)& aBC = aRevSurf->BasisCurve();
+  Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aBC);
+  if (aLine.IsNull())
+    return;
+  const gp_Ax1& anAxis = aRevSurf->Axis();
+
+  gp_Lin anALin(anAxis);
+  Extrema_ExtElC anExtLL(aLine->Lin(), anALin, Precision::Angular());
+  if (!anExtLL.IsDone() || anExtLL.IsParallel())
+    return;
+  Standard_Integer aNbExt = anExtLL.NbExt();
+  if (aNbExt == 0)
+    return;
+
+  Standard_Integer i;
+  Standard_Integer imin = 0;
+  for (i = 1; i <= aNbExt; ++i)
+  {
+    if (anExtLL.SquareDistance(i) < Precision::SquareConfusion())
+    {
+      imin = i;
+      break;
+    }
+  }
+  if (imin == 0)
+    return;
+
+  Extrema_POnCurv aP1, aP2;
+  anExtLL.Points(imin, aP1, aP2);
+  Standard_Real aVExt = aP1.Parameter();
+  if (aVExt <= V1 || aVExt >= V2)
+    return;
+
+  if (aVExt - V1 > V2 - aVExt)
+  {
+    V2 = aVExt;
+  }
+  else
+  {
+    V1 = aVExt;
+  }
 
+}
 
 // static method to try create toroidal surface.
 // In case <isTryUMajor> = Standard_True try to use V isoline radius as minor radaius.
@@ -71,12 +121,12 @@ static Handle(Geom_Surface) TryTorusSphere(const Handle(Geom_Surface)& theSurf,
   if (isTryUMajor)
   {
     IsoCrv1 = theSurf->VIso(Param1 + ((Param2 - Param1) / 3.));
-    IsoCrv2 = theSurf->VIso(Param1 + ((Param2 - Param1)*2. / 3));
+    IsoCrv2 = theSurf->VIso(Param1 + ((Param2 - Param1) * 2. / 3));
   }
   else
   {
     IsoCrv1 = theSurf->UIso(Param1 + ((Param2 - Param1) / 3.));
-    IsoCrv2 = theSurf->UIso(Param1 + ((Param2 - Param1)*2. / 3));
+    IsoCrv2 = theSurf->UIso(Param1 + ((Param2 - Param1) * 2. / 3));
   }
 
   Handle(Geom_Curve) Crv1 = GeomConvert_CurveToAnaCurve::ComputeCurve(IsoCrv1, toler, aParam1ToCrv, aParam2ToCrv, cf, cl,
@@ -103,7 +153,7 @@ static Handle(Geom_Surface) TryTorusSphere(const Handle(Geom_Surface)& theSurf,
   aPnt2 = aCircle1->Circ().Location();
   aPnt3 = aCircle2->Circ().Location();
 
-  Standard_Real eps = 1.e-09;  // angular resolution
+  //Standard_Real eps = 1.e-09;  // angular resolution
   Standard_Real d0 = aPnt1.Distance(aPnt2);  Standard_Real d1 = aPnt1.Distance(aPnt3);
   gp_Circ circ;
 
@@ -120,7 +170,7 @@ static Handle(Geom_Surface) TryTorusSphere(const Handle(Geom_Surface)& theSurf,
     return newSurface;
   }
 
-  if (!GeomConvert_CurveToAnaCurve::GetCircle(circ, aPnt1, aPnt2, aPnt3, d0, d1, eps))
+  if (!GeomConvert_CurveToAnaCurve::GetCircle(circ, aPnt1, aPnt2, aPnt3) /*, d0, d1, eps)*/)
     return newSurface;
 
   Standard_Real aMajorR = circ.Radius();
@@ -131,7 +181,7 @@ static Handle(Geom_Surface) TryTorusSphere(const Handle(Geom_Surface)& theSurf,
   return newSurface;
 }
 
-static Standard_Real ComputeGap(const Handle(Geom_Surface)& theSurf, 
+static Standard_Real ComputeGap(const Handle(Geom_Surface)& theSurf,
   const Standard_Real theU1, const Standard_Real theU2, const Standard_Real theV1, const Standard_Real theV2,
   const Handle(Geom_Surface) theNewSurf, const Standard_Real theTol = RealLast())
 {
@@ -142,26 +192,26 @@ static Standard_Real ComputeGap(const Handle(Geom_Surface)& theSurf,
   gp_Cone aCon;
   gp_Sphere aSphere;
   gp_Torus aTor;
-  switch (aSType) 
+  switch (aSType)
   {
-    case GeomAbs_Plane:
-      aPln = aGAS.Plane();
-      break;
-    case GeomAbs_Cylinder:
-      aCyl = aGAS.Cylinder();
-      break;
-    case GeomAbs_Cone:
-      aCon = aGAS.Cone();
-      break;
-    case GeomAbs_Sphere:
-      aSphere = aGAS.Sphere();
-      break;
-    case GeomAbs_Torus:
-      aTor = aGAS.Torus();
-      break;
-    default:
-      return Precision::Infinite();
-      break;
+  case GeomAbs_Plane:
+    aPln = aGAS.Plane();
+    break;
+  case GeomAbs_Cylinder:
+    aCyl = aGAS.Cylinder();
+    break;
+  case GeomAbs_Cone:
+    aCon = aGAS.Cone();
+    break;
+  case GeomAbs_Sphere:
+    aSphere = aGAS.Sphere();
+    break;
+  case GeomAbs_Torus:
+    aTor = aGAS.Torus();
+    break;
+  default:
+    return Precision::Infinite();
+    break;
   }
 
   Standard_Real aGap = 0.;
@@ -177,9 +227,9 @@ static Standard_Real ComputeGap(const Handle(Geom_Surface)& theSurf,
   DV = (theV2 - theV1) / (NP - 1);
   Standard_Real DU2 = DU / 2., DV2 = DV / 2.;
   for (j = 1; (j < NP) && onSurface; j++) {
-    Standard_Real V = theV1 + DV*(j - 1) + DV2;
+    Standard_Real V = theV1 + DV * (j - 1) + DV2;
     for (i = 1; i <= NP; i++) {
-      Standard_Real U = theU1 + DU*(i - 1) + DU2;
+      Standard_Real U = theU1 + DU * (i - 1) + DU2;
       theSurf->D0(U, V, P3d);
 
       switch (aSType) {
@@ -236,9 +286,9 @@ static Standard_Real ComputeGap(const Handle(Geom_Surface)& theSurf,
 //purpose  : 
 //=======================================================================
 GeomConvert_SurfToAnaSurf::GeomConvert_SurfToAnaSurf() :
-       myGap (-1.), 
-       myConvType (GeomConvert_Simplest),
-       myTarget (GeomAbs_Plane)
+  myGap(-1.),
+  myConvType(GeomConvert_Simplest),
+  myTarget(GeomAbs_Plane)
 {
 }
 
@@ -247,12 +297,12 @@ GeomConvert_SurfToAnaSurf::GeomConvert_SurfToAnaSurf() :
 //purpose  : 
 //=======================================================================
 
-GeomConvert_SurfToAnaSurf::GeomConvert_SurfToAnaSurf (const Handle(Geom_Surface)& S) :
+GeomConvert_SurfToAnaSurf::GeomConvert_SurfToAnaSurf(const Handle(Geom_Surface)& S) :
   myGap(-1.),
   myConvType(GeomConvert_Simplest),
   myTarget(GeomAbs_Plane)
 {
-  Init ( S );
+  Init(S);
 }
 
 //=======================================================================
@@ -260,7 +310,7 @@ GeomConvert_SurfToAnaSurf::GeomConvert_SurfToAnaSurf (const Handle(Geom_Surface)
 //purpose  : 
 //=======================================================================
 
-void GeomConvert_SurfToAnaSurf::Init (const Handle(Geom_Surface)& S) 
+void GeomConvert_SurfToAnaSurf::Init(const Handle(Geom_Surface)& S)
 {
   mySurf = S;
 }
@@ -270,19 +320,24 @@ void GeomConvert_SurfToAnaSurf::Init (const Handle(Geom_Surface)& S)
 //purpose  : 
 //=======================================================================
 
-Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical (const Standard_Real InitialToler) 
+Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical(const Standard_Real InitialToler)
 {
   Standard_Real U1, U2, V1, V2;
   mySurf->Bounds(U1, U2, V1, V2);
-  if(Precision::IsInfinite(U1) && Precision::IsInfinite(U2) ) {
+  if (Precision::IsInfinite(U1) && Precision::IsInfinite(U2)) {
     U1 = -1.;
     U2 = 1.;
   }
-  if(Precision::IsInfinite(V1) && Precision::IsInfinite(V2) ) {
+  if (Precision::IsInfinite(V1) && Precision::IsInfinite(V2)) {
     V1 = -1.;
     V2 = 1.;
+    Handle(Geom_SurfaceOfRevolution) aRevSurf = Handle(Geom_SurfaceOfRevolution)::DownCast(mySurf);
+    if (!aRevSurf.IsNull())
+    {
+      CheckVTrimForRevSurf(aRevSurf, V1, V2);
+    }
   }
-  return ConvertToAnalytical(InitialToler, U1, U2, V1, V2); 
+  return ConvertToAnalytical(InitialToler, U1, U2, V1, V2);
 }
 
 //=======================================================================
@@ -298,33 +353,33 @@ Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical(const Standa
   GeomAbs_SurfaceType aSType = aGAS.GetType();
   switch (aSType)
   {
-    case GeomAbs_Plane:
-    {
-      myGap = 0.;
-      return new Geom_Plane(aGAS.Plane());
-    }
-    case GeomAbs_Cylinder:
-    {
-      myGap = 0.;
-      return new Geom_CylindricalSurface(aGAS.Cylinder());
-    }
-    case GeomAbs_Cone:
-    {
-      myGap = 0.;
-      return new Geom_ConicalSurface(aGAS.Cone());
-    }
-    case GeomAbs_Sphere:
-    {
-      myGap = 0.;
-      return new Geom_SphericalSurface(aGAS.Sphere());
-    }
-    case GeomAbs_Torus:
-    {
-      myGap = 0.;
-      return new Geom_ToroidalSurface(aGAS.Torus());
-    }
-    default:
-      break;
+  case GeomAbs_Plane:
+  {
+    myGap = 0.;
+    return new Geom_Plane(aGAS.Plane());
+  }
+  case GeomAbs_Cylinder:
+  {
+    myGap = 0.;
+    return new Geom_CylindricalSurface(aGAS.Cylinder());
+  }
+  case GeomAbs_Cone:
+  {
+    myGap = 0.;
+    return new Geom_ConicalSurface(aGAS.Cone());
+  }
+  case GeomAbs_Sphere:
+  {
+    myGap = 0.;
+    return new Geom_SphericalSurface(aGAS.Sphere());
+  }
+  case GeomAbs_Torus:
+  {
+    myGap = 0.;
+    return new Geom_ToroidalSurface(aGAS.Torus());
+  }
+  default:
+    break;
   }
   //
   Standard_Real toler = InitialToler;
@@ -341,7 +396,7 @@ Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical(const Standa
   {
     return newSurf[isurf];
   }
-  else 
+  else
   {
     if (Umin - U1 > aTolBnd)
     {
@@ -363,7 +418,7 @@ Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical(const Standa
       V2 = Vmax;
       aDoSegment = Standard_True;
     }
-     
+
   }
 
   Standard_Boolean IsBz = aSType == GeomAbs_BezierSurface;
@@ -399,8 +454,8 @@ Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical(const Standa
     gp_Pln newPln = GeomIsPlanar.Plan();
     newSurf[isurf] = new Geom_Plane(newPln);
     dd[isurf] = ComputeGap(aTempS, U1, U2, V1, V2, newSurf[isurf]);
-    if ( myConvType == GeomConvert_Simplest || 
-        (myConvType == GeomConvert_Target && myTarget == GeomAbs_Plane))
+    if (myConvType == GeomConvert_Simplest ||
+      (myConvType == GeomConvert_Target && myTarget == GeomAbs_Plane))
     {
       myGap = dd[isurf];
       return newSurf[isurf];
@@ -424,10 +479,10 @@ Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical(const Standa
   Standard_Boolean aToroidSphere = Standard_False;
 
   //convert middle uiso and viso to canonical representation
-  Standard_Real VMid = 0.5*(V1 + V2);
-  Standard_Real UMid = 0.5*(U1 + U2);
+  Standard_Real VMid = 0.5 * (V1 + V2);
+  Standard_Real UMid = 0.5 * (U1 + U2);
   Handle(Geom_Surface) TrSurf = aTempS;
-  if(!aDoSegment)
+  if (!aDoSegment)
     TrSurf = new Geom_RectangularTrimmedSurface(aTempS, U1, U2, V1, V2);
 
   Handle(Geom_Curve) UIso = TrSurf->UIso(UMid);
@@ -566,7 +621,7 @@ Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical(const Standa
         gp_Ax3 Axes;
         Standard_Real semiangle =
           gp_Vec(isoline).Angle(gp_Vec(P3, P1));
-        if (semiangle>M_PI / 2)  semiangle = M_PI - semiangle;
+        if (semiangle > M_PI / 2)  semiangle = M_PI - semiangle;
         if (R1 > R3) {
           radius = R3;
           Axes = gp_Ax3(P3, gp_Dir(gp_Vec(P3, P1)));
@@ -626,7 +681,7 @@ Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical(const Standa
     myGap = dd[imin];
     return newSurf[imin];
   }
-  
+
   return newSurf[0];
 }
 
@@ -636,19 +691,19 @@ Handle(Geom_Surface) GeomConvert_SurfToAnaSurf::ConvertToAnalytical(const Standa
 //=======================================================================
 
 Standard_Boolean GeomConvert_SurfToAnaSurf::IsSame(const Handle(Geom_Surface)& S1,
-                                             const Handle(Geom_Surface)& S2,
-                                             const Standard_Real tol)
+  const Handle(Geom_Surface)& S2,
+  const Standard_Real tol)
 {
   // only elementary surfaces are processed
-  if(!S1->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) ||
-     !S2->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
+  if (!S1->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) ||
+    !S2->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
     return Standard_False;
-  
-  Handle(GeomAdaptor_HSurface) anAdaptor1 = new GeomAdaptor_HSurface(S1);
-  Handle(GeomAdaptor_HSurface) anAdaptor2 = new GeomAdaptor_HSurface(S2);
 
-  GeomAbs_SurfaceType aST1 = anAdaptor1->GetType();
-  GeomAbs_SurfaceType aST2 = anAdaptor2->GetType();
+  GeomAdaptor_Surface anAdaptor1(S1);
+  GeomAdaptor_Surface anAdaptor2(S2);
+
+  GeomAbs_SurfaceType aST1 = anAdaptor1.GetType();
+  GeomAbs_SurfaceType aST2 = anAdaptor2.GetType();
 
   if (aST1 != aST2)
   {
@@ -658,28 +713,28 @@ Standard_Boolean GeomConvert_SurfToAnaSurf::IsSame(const Handle(Geom_Surface)& S
   IntAna_QuadQuadGeo interii;
   if (aST1 == GeomAbs_Plane)
   {
-    interii.Perform(anAdaptor1->Plane(), anAdaptor2->Plane(), tol, tol);
+    interii.Perform(anAdaptor1.Plane(), anAdaptor2.Plane(), tol, tol);
   }
   else if (aST1 == GeomAbs_Cylinder)
   {
-    interii.Perform(anAdaptor1->Cylinder(), anAdaptor2->Cylinder(), tol);
+    interii.Perform(anAdaptor1.Cylinder(), anAdaptor2.Cylinder(), tol);
   }
   else if (aST1 == GeomAbs_Cone)
   {
-    interii.Perform(anAdaptor1->Cone(), anAdaptor2->Cone(), tol);
+    interii.Perform(anAdaptor1.Cone(), anAdaptor2.Cone(), tol);
   }
   else if (aST1 == GeomAbs_Sphere)
   {
-    interii.Perform(anAdaptor1->Sphere(), anAdaptor2->Sphere(), tol);
+    interii.Perform(anAdaptor1.Sphere(), anAdaptor2.Sphere(), tol);
   }
   else if (aST1 == GeomAbs_Torus)
   {
-    interii.Perform(anAdaptor1->Torus(), anAdaptor2->Torus(), tol);
+    interii.Perform(anAdaptor1.Torus(), anAdaptor2.Torus(), tol);
   }
 
   if (!interii.IsDone())
     return Standard_False;
-  
+
   IntAna_ResultType aTypeRes = interii.TypeInter();
 
   return aTypeRes == IntAna_Same;
@@ -694,16 +749,16 @@ Standard_Boolean GeomConvert_SurfToAnaSurf::IsSame(const Handle(Geom_Surface)& S
 
 Standard_Boolean GeomConvert_SurfToAnaSurf::IsCanonical(const Handle(Geom_Surface)& S)
 {
-  if(S.IsNull())
+  if (S.IsNull())
     return Standard_False;
-  
-  if (   S->IsKind(STANDARD_TYPE(Geom_Plane))
-      || S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))
-      || S->IsKind(STANDARD_TYPE(Geom_ConicalSurface))
-      || S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) 
-      || S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)))
+
+  if (S->IsKind(STANDARD_TYPE(Geom_Plane))
+    || S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))
+    || S->IsKind(STANDARD_TYPE(Geom_ConicalSurface))
+    || S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))
+    || S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)))
     return Standard_True;
-  
+
   return Standard_False;
 }
 
index a5bdf593dfa5d6936f85b0a35061d13ad3c63ab5..016956590e16b3526ab1913ddb6fdfb346d7e734 100644 (file)
@@ -62,14 +62,8 @@ public:
   
   //! Tries to convert the Surface to an Analytic form
   //! Returns the result
-  //! Works only if the Surface is BSpline or Bezier.
-  //! Else, or in case of failure, returns a Null Handle
+  //! In case of failure, returns a Null Handle
   //!
-  //! If <substitute> is True, the new surface replaces the actual
-  //! one in <me>
-  //!
-  //! It works by analysing the case which can apply, creating the
-  //! corresponding analytic surface, then checking coincidence
   Standard_EXPORT Handle(Geom_Surface) ConvertToAnalytical (const Standard_Real InitialToler);
   Standard_EXPORT Handle(Geom_Surface) ConvertToAnalytical (const Standard_Real InitialToler,
                                                             const Standard_Real Umin, const Standard_Real Umax,
index 291938dc02dd6e8e57c3adf6f9f88ef4ab48d23c..cd7336b7df4560e712877cd106d574f43aa2e246 100644 (file)
 // commercial license or contractual agreement.
 
 #if !defined(HAVE_FREEIMAGE) && defined(_WIN32)
-  #define HAVE_WINCODEC
+#define HAVE_WINCODEC
 #endif
 
 #ifdef HAVE_FREEIMAGE
-  #include <FreeImage.h>
+#include <FreeImage.h>
 
-  #ifdef _MSC_VER
-    #pragma comment( lib, "FreeImage.lib" )
-  #endif
+#ifdef _MSC_VER
+//  #pragma comment( lib, "FreeImage.lib" )
+#endif
 #elif defined(HAVE_WINCODEC)
-  #include <wincodec.h>
-  // prevent warnings on MSVC10
-  #include <Standard_WarningsDisable.hxx>
-  #include <Standard_TypeDef.hxx>
-  #include <Standard_WarningsRestore.hxx>
-  #undef min
-  #undef max
-
-  #ifdef _MSC_VER
-    #pragma comment(lib, "Ole32.lib")
-  #endif
+#include <wincodec.h>
+// prevent warnings on MSVC10
+#include <Standard_WarningsDisable.hxx>
+#include <Standard_TypeDef.hxx>
+#include <Standard_WarningsRestore.hxx>
+#undef min
+#undef max
+
+#ifdef _MSC_VER
+#pragma comment(lib, "Ole32.lib")
+#endif
 #endif
 
 #include <Image_AlienPixMap.hxx>
 #include <fstream>
 #include <algorithm>
 
-IMPLEMENT_STANDARD_RTTIEXT(Image_AlienPixMap,Image_PixMap)
+IMPLEMENT_STANDARD_RTTIEXT(Image_AlienPixMap, Image_PixMap)
 
 namespace
 {
 #ifdef HAVE_FREEIMAGE
-  static Image_Format convertFromFreeFormat (FREE_IMAGE_TYPE       theFormatFI,
-                                             FREE_IMAGE_COLOR_TYPE theColorTypeFI,
-                                             unsigned              theBitsPerPixel)
+  static Image_Format convertFromFreeFormat(FREE_IMAGE_TYPE       theFormatFI,
+    FREE_IMAGE_COLOR_TYPE theColorTypeFI,
+    unsigned              theBitsPerPixel)
   {
     switch (theFormatFI)
     {
-      case FIT_RGBF:   return Image_Format_RGBF;
-      case FIT_RGBAF:  return Image_Format_RGBAF;
-      case FIT_FLOAT:  return Image_Format_GrayF;
-      case FIT_BITMAP:
+    case FIT_RGBF:   return Image_Format_RGBF;
+    case FIT_RGBAF:  return Image_Format_RGBAF;
+    case FIT_FLOAT:  return Image_Format_GrayF;
+    case FIT_BITMAP:
+    {
+      switch (theColorTypeFI)
+      {
+      case FIC_MINISBLACK:
+      {
+        return Image_Format_Gray;
+      }
+      case FIC_RGB:
       {
-        switch (theColorTypeFI)
+        if (Image_PixMap::IsBigEndianHost())
         {
-          case FIC_MINISBLACK:
-          {
-            return Image_Format_Gray;
-          }
-          case FIC_RGB:
-          {
-            if (Image_PixMap::IsBigEndianHost())
-            {
-              return (theBitsPerPixel == 32) ? Image_Format_RGB32 : Image_Format_RGB;
-            }
-            else
-            {
-              return (theBitsPerPixel == 32) ? Image_Format_BGR32 : Image_Format_BGR;
-            }
-          }
-          case FIC_RGBALPHA:
-          {
-            return Image_PixMap::IsBigEndianHost() ? Image_Format_RGBA : Image_Format_BGRA;
-          }
-          default:
-            return Image_Format_UNKNOWN;
+          return (theBitsPerPixel == 32) ? Image_Format_RGB32 : Image_Format_RGB;
+        }
+        else
+        {
+          return (theBitsPerPixel == 32) ? Image_Format_BGR32 : Image_Format_BGR;
         }
       }
+      case FIC_RGBALPHA:
+      {
+        return Image_PixMap::IsBigEndianHost() ? Image_Format_RGBA : Image_Format_BGRA;
+      }
       default:
         return Image_Format_UNKNOWN;
+      }
+    }
+    default:
+      return Image_Format_UNKNOWN;
     }
   }
 
-  static FREE_IMAGE_TYPE convertToFreeFormat (Image_Format theFormat)
+  static FREE_IMAGE_TYPE convertToFreeFormat(Image_Format theFormat)
   {
     switch (theFormat)
     {
-      case Image_Format_GrayF:
-      case Image_Format_AlphaF:
-        return FIT_FLOAT;
-      case Image_Format_RGBAF:
-        return FIT_RGBAF;
-      case Image_Format_RGBF:
-        return FIT_RGBF;
-      case Image_Format_RGBA:
-      case Image_Format_BGRA:
-      case Image_Format_RGB32:
-      case Image_Format_BGR32:
-      case Image_Format_RGB:
-      case Image_Format_BGR:
-      case Image_Format_Gray:
-      case Image_Format_Alpha:
-        return FIT_BITMAP;
-      default:
-        return FIT_UNKNOWN;
+    case Image_Format_GrayF:
+    case Image_Format_AlphaF:
+      return FIT_FLOAT;
+    case Image_Format_RGBAF:
+      return FIT_RGBAF;
+    case Image_Format_RGBF:
+      return FIT_RGBF;
+    case Image_Format_RGBA:
+    case Image_Format_BGRA:
+    case Image_Format_RGB32:
+    case Image_Format_BGR32:
+    case Image_Format_RGB:
+    case Image_Format_BGR:
+    case Image_Format_Gray:
+    case Image_Format_Alpha:
+      return FIT_BITMAP;
+    default:
+      return FIT_UNKNOWN;
     }
   }
 
@@ -126,14 +126,14 @@ namespace
   {
   public:
     //! Construct wrapper over input stream.
-    Image_FreeImageStream (std::istream& theStream)
-    : myIStream (&theStream), myOStream (NULL), myInitPos (theStream.tellg()) {}
+    Image_FreeImageStream(std::istream& theStream)
+      : myIStream(&theStream), myOStream(NULL), myInitPos(theStream.tellg()) {}
 
     //! Get io object.
     FreeImageIO GetFiIO() const
     {
       FreeImageIO anIo;
-      memset (&anIo, 0, sizeof(anIo));
+      memset(&anIo, 0, sizeof(anIo));
       if (myIStream != NULL)
       {
         anIo.read_proc = readProc;
@@ -148,28 +148,28 @@ namespace
     }
   public:
     //! Simulate fread().
-    static unsigned int DLL_CALLCONV readProc (void* theBuffer, unsigned int theSize, unsigned int theCount, fi_handle theHandle)
+    static unsigned int DLL_CALLCONV readProc(void* theBuffer, unsigned int theSize, unsigned int theCount, fi_handle theHandle)
     {
-      Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
+      Image_FreeImageStream* aThis = (Image_FreeImageStream*)theHandle;
       if (aThis->myIStream == NULL)
       {
         return 0;
       }
 
-      if (!aThis->myIStream->read ((char* )theBuffer, std::streamsize(theSize) * std::streamsize(theCount)))
+      if (!aThis->myIStream->read((char*)theBuffer, std::streamsize(theSize) * std::streamsize(theCount)))
       {
         //aThis->myIStream->clear();
       }
       const std::streamsize aNbRead = aThis->myIStream->gcount();
-      return (unsigned int )(aNbRead / theSize);
+      return (unsigned int)(aNbRead / theSize);
     }
 
     //! Simulate fwrite().
-    static unsigned int DLL_CALLCONV writeProc (void* theBuffer, unsigned int theSize, unsigned int theCount, fi_handle theHandle)
+    static unsigned int DLL_CALLCONV writeProc(void* theBuffer, unsigned int theSize, unsigned int theCount, fi_handle theHandle)
     {
-      Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
+      Image_FreeImageStream* aThis = (Image_FreeImageStream*)theHandle;
       if (aThis->myOStream != NULL
-       && aThis->myOStream->write ((const char* )theBuffer, std::streamsize(theSize) * std::streamsize(theCount)))
+        && aThis->myOStream->write((const char*)theBuffer, std::streamsize(theSize) * std::streamsize(theCount)))
       {
         return theCount;
       }
@@ -177,9 +177,9 @@ namespace
     }
 
     //! Simulate fseek().
-    static int DLL_CALLCONV seekProc (fi_handle theHandle, long theOffset, int theOrigin)
+    static int DLL_CALLCONV seekProc(fi_handle theHandle, long theOffset, int theOrigin)
     {
-      Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
+      Image_FreeImageStream* aThis = (Image_FreeImageStream*)theHandle;
       if (aThis->myIStream == NULL)
       {
         return -1;
@@ -188,38 +188,38 @@ namespace
       bool isSeekDone = false;
       switch (theOrigin)
       {
-        case SEEK_SET:
-          if (aThis->myIStream->seekg ((std::streamoff )aThis->myInitPos + theOffset, std::ios::beg))
-          {
-            isSeekDone = true;
-          }
-          break;
-        case SEEK_CUR:
-          if (aThis->myIStream->seekg (theOffset, std::ios::cur))
-          {
-            isSeekDone = true;
-          }
-          break;
-        case SEEK_END:
-          if (aThis->myIStream->seekg (theOffset, std::ios::end))
-          {
-            isSeekDone = true;
-          }
-          break;
+      case SEEK_SET:
+        if (aThis->myIStream->seekg((std::streamoff)aThis->myInitPos + theOffset, std::ios::beg))
+        {
+          isSeekDone = true;
+        }
+        break;
+      case SEEK_CUR:
+        if (aThis->myIStream->seekg(theOffset, std::ios::cur))
+        {
+          isSeekDone = true;
+        }
+        break;
+      case SEEK_END:
+        if (aThis->myIStream->seekg(theOffset, std::ios::end))
+        {
+          isSeekDone = true;
+        }
+        break;
       }
       return isSeekDone ? 0 : -1;
     }
 
     //! Simulate ftell().
-    static long DLL_CALLCONV tellProc (fi_handle theHandle)
+    static long DLL_CALLCONV tellProc(fi_handle theHandle)
     {
-      Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
-      const long aPos = aThis->myIStream != NULL ? (long )(aThis->myIStream->tellg() - aThis->myInitPos) : 0;
+      Image_FreeImageStream* aThis = (Image_FreeImageStream*)theHandle;
+      const long aPos = aThis->myIStream != NULL ? (long)(aThis->myIStream->tellg() - aThis->myInitPos) : 0;
       return aPos;
     }
   private:
-    std::istream*  myIStream;
-    std::ostream*  myOStream;
+    std::istream* myIStream;
+    std::ostream* myOStream;
     std::streampos myInitPos;
   };
 
@@ -238,7 +238,7 @@ namespace
   public:
     //! Empty constructor.
     Image_ComPtr()
-    : myPtr (NULL) {}
+      : myPtr(NULL) {}
 
     //! Destructor.
     ~Image_ComPtr()
@@ -262,7 +262,7 @@ namespace
     //! Return pointer for initialization.
     T*& ChangePtr()
     {
-      Standard_ASSERT_RAISE (myPtr == NULL, "Pointer cannot be initialized twice!");
+      Standard_ASSERT_RAISE(myPtr == NULL, "Pointer cannot be initialized twice!");
       return myPtr;
     }
 
@@ -280,7 +280,7 @@ namespace
   };
 
   //! Convert WIC GUID to Image_Format.
-  static Image_Format convertFromWicFormat (const WICPixelFormatGUID& theFormat)
+  static Image_Format convertFromWicFormat(const WICPixelFormatGUID& theFormat)
   {
     if (theFormat == GUID_WICPixelFormat32bppBGRA)
     {
@@ -306,24 +306,24 @@ namespace
   }
 
   //! Convert Image_Format to WIC GUID.
-  static WICPixelFormatGUID convertToWicFormat (Image_Format theFormat)
+  static WICPixelFormatGUID convertToWicFormat(Image_Format theFormat)
   {
     switch (theFormat)
     {
-      case Image_Format_BGRA:   return GUID_WICPixelFormat32bppBGRA;
-      case Image_Format_BGR32:  return GUID_WICPixelFormat32bppBGR;
-      case Image_Format_RGB:    return GUID_WICPixelFormat24bppRGB;
-      case Image_Format_BGR:    return GUID_WICPixelFormat24bppBGR;
-      case Image_Format_Gray:   return GUID_WICPixelFormat8bppGray;
-      case Image_Format_Alpha:  return GUID_WICPixelFormat8bppGray; // GUID_WICPixelFormat8bppAlpha
-      case Image_Format_GrayF:  // GUID_WICPixelFormat32bppGrayFloat
-      case Image_Format_AlphaF:
-      case Image_Format_RGBAF:  // GUID_WICPixelFormat128bppRGBAFloat
-      case Image_Format_RGBF:   // GUID_WICPixelFormat96bppRGBFloat
-      case Image_Format_RGBA:   // GUID_WICPixelFormat32bppRGBA
-      case Image_Format_RGB32:  // GUID_WICPixelFormat32bppRGB
-      default:
-        return getNullGuid();
+    case Image_Format_BGRA:   return GUID_WICPixelFormat32bppBGRA;
+    case Image_Format_BGR32:  return GUID_WICPixelFormat32bppBGR;
+    case Image_Format_RGB:    return GUID_WICPixelFormat24bppRGB;
+    case Image_Format_BGR:    return GUID_WICPixelFormat24bppBGR;
+    case Image_Format_Gray:   return GUID_WICPixelFormat8bppGray;
+    case Image_Format_Alpha:  return GUID_WICPixelFormat8bppGray; // GUID_WICPixelFormat8bppAlpha
+    case Image_Format_GrayF:  // GUID_WICPixelFormat32bppGrayFloat
+    case Image_Format_AlphaF:
+    case Image_Format_RGBAF:  // GUID_WICPixelFormat128bppRGBAFloat
+    case Image_Format_RGBF:   // GUID_WICPixelFormat96bppRGBFloat
+    case Image_Format_RGBA:   // GUID_WICPixelFormat32bppRGBA
+    case Image_Format_RGB32:  // GUID_WICPixelFormat32bppRGB
+    default:
+      return getNullGuid();
     }
   }
 
@@ -335,9 +335,9 @@ namespace
 // purpose  :
 // =======================================================================
 Image_AlienPixMap::Image_AlienPixMap()
-: myLibImage (NULL)
+  : myLibImage(NULL)
 {
-  SetTopDown (false);
+  SetTopDown(false);
 }
 
 // =======================================================================
@@ -353,11 +353,11 @@ Image_AlienPixMap::~Image_AlienPixMap()
 // function : InitWrapper
 // purpose  :
 // =======================================================================
-bool Image_AlienPixMap::InitWrapper (Image_Format,
-                                     Standard_Byte*,
-                                     const Standard_Size,
-                                     const Standard_Size,
-                                     const Standard_Size)
+bool Image_AlienPixMap::InitWrapper(Image_Format,
+  Standard_Byte*,
+  const Standard_Size,
+  const Standard_Size,
+  const Standard_Size)
 {
   Clear();
   return false;
@@ -368,76 +368,76 @@ bool Image_AlienPixMap::InitWrapper (Image_Format,
 // purpose  :
 // =======================================================================
 #ifdef HAVE_FREEIMAGE
-bool Image_AlienPixMap::InitTrash (Image_Format        thePixelFormat,
-                                   const Standard_Size theSizeX,
-                                   const Standard_Size theSizeY,
-                                   const Standard_Size /*theSizeRowBytes*/)
+bool Image_AlienPixMap::InitTrash(Image_Format        thePixelFormat,
+  const Standard_Size theSizeX,
+  const Standard_Size theSizeY,
+  const Standard_Size /*theSizeRowBytes*/)
 {
   Clear();
-  FREE_IMAGE_TYPE aFormatFI = convertToFreeFormat (thePixelFormat);
-  int aBitsPerPixel = (int )Image_PixMap::SizePixelBytes (thePixelFormat) * 8;
+  FREE_IMAGE_TYPE aFormatFI = convertToFreeFormat(thePixelFormat);
+  int aBitsPerPixel = (int)Image_PixMap::SizePixelBytes(thePixelFormat) * 8;
   if (aFormatFI == FIT_UNKNOWN)
   {
-    aFormatFI     = FIT_BITMAP;
+    aFormatFI = FIT_BITMAP;
     aBitsPerPixel = 24;
   }
 
-  FIBITMAP* anImage = FreeImage_AllocateT (aFormatFI, (int )theSizeX, (int )theSizeY, aBitsPerPixel);
-  Image_Format aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage),
-                                                FreeImage_GetColorType(anImage),
-                                                FreeImage_GetBPP      (anImage));
+  FIBITMAP* anImage = FreeImage_AllocateT(aFormatFI, (int)theSizeX, (int)theSizeY, aBitsPerPixel);
+  Image_Format aFormat = convertFromFreeFormat(FreeImage_GetImageType(anImage),
+    FreeImage_GetColorType(anImage),
+    FreeImage_GetBPP(anImage));
   if (thePixelFormat == Image_Format_BGR32
-   || thePixelFormat == Image_Format_RGB32)
+    || thePixelFormat == Image_Format_RGB32)
   {
     //FreeImage_SetTransparent (anImage, FALSE);
     aFormat = (aFormat == Image_Format_BGRA) ? Image_Format_BGR32 : Image_Format_RGB32;
   }
 
-  Image_PixMap::InitWrapper (aFormat, FreeImage_GetBits (anImage),
-                             FreeImage_GetWidth (anImage), FreeImage_GetHeight (anImage), FreeImage_GetPitch (anImage));
-  SetTopDown (false);
+  Image_PixMap::InitWrapper(aFormat, FreeImage_GetBits(anImage),
+    FreeImage_GetWidth(anImage), FreeImage_GetHeight(anImage), FreeImage_GetPitch(anImage));
+  SetTopDown(false);
 
   // assign image after wrapper initialization (virtual Clear() called inside)
   myLibImage = anImage;
   return true;
 }
 #elif defined(HAVE_WINCODEC)
-bool Image_AlienPixMap::InitTrash (Image_Format        thePixelFormat,
-                                   const Standard_Size theSizeX,
-                                   const Standard_Size theSizeY,
-                                   const Standard_Size theSizeRowBytes)
+bool Image_AlienPixMap::InitTrash(Image_Format        thePixelFormat,
+  const Standard_Size theSizeX,
+  const Standard_Size theSizeY,
+  const Standard_Size theSizeRowBytes)
 {
   Clear();
   Image_Format aFormat = thePixelFormat;
   switch (aFormat)
   {
-    case Image_Format_RGB:
-      aFormat = Image_Format_BGR;
-      break;
-    case Image_Format_RGB32:
-      aFormat = Image_Format_BGR32;
-      break;
-    case Image_Format_RGBA:
-      aFormat = Image_Format_BGRA;
-      break;
-    default:
-      break;
+  case Image_Format_RGB:
+    aFormat = Image_Format_BGR;
+    break;
+  case Image_Format_RGB32:
+    aFormat = Image_Format_BGR32;
+    break;
+  case Image_Format_RGBA:
+    aFormat = Image_Format_BGRA;
+    break;
+  default:
+    break;
   }
 
-  if (!Image_PixMap::InitTrash (aFormat, theSizeX, theSizeY, theSizeRowBytes))
+  if (!Image_PixMap::InitTrash(aFormat, theSizeX, theSizeY, theSizeRowBytes))
   {
     return false;
   }
-  SetTopDown (true);
+  SetTopDown(true);
   return true;
 }
 #else
-bool Image_AlienPixMap::InitTrash (Image_Format        thePixelFormat,
-                                   const Standard_Size theSizeX,
-                                   const Standard_Size theSizeY,
-                                   const Standard_Size theSizeRowBytes)
+bool Image_AlienPixMap::InitTrash(Image_Format        thePixelFormat,
+  const Standard_Size theSizeX,
+  const Standard_Size theSizeY,
+  const Standard_Size theSizeRowBytes)
 {
-  return Image_PixMap::InitTrash (thePixelFormat, theSizeX, theSizeY, theSizeRowBytes);
+  return Image_PixMap::InitTrash(thePixelFormat, theSizeX, theSizeY, theSizeRowBytes);
 }
 #endif
 
@@ -445,14 +445,14 @@ bool Image_AlienPixMap::InitTrash (Image_Format        thePixelFormat,
 // function : InitCopy
 // purpose  :
 // =======================================================================
-bool Image_AlienPixMap::InitCopy (const Image_PixMap& theCopy)
+bool Image_AlienPixMap::InitCopy(const Image_PixMap& theCopy)
 {
   if (&theCopy == this)
   {
     // self-copying disallowed
     return false;
   }
-  if (!InitTrash (theCopy.Format(), theCopy.SizeX(), theCopy.SizeY(), theCopy.SizeRowBytes()))
+  if (!InitTrash(theCopy.Format(), theCopy.SizeX(), theCopy.SizeY(), theCopy.SizeRowBytes()))
   {
     return false;
   }
@@ -460,18 +460,18 @@ bool Image_AlienPixMap::InitCopy (const Image_PixMap& theCopy)
   if (myImgFormat == theCopy.Format())
   {
     if (SizeRowBytes() == theCopy.SizeRowBytes()
-     && TopDownInc()   == theCopy.TopDownInc())
+      && TopDownInc() == theCopy.TopDownInc())
     {
       // copy with one call
-      memcpy (ChangeData(), theCopy.Data(), std::min (SizeBytes(), theCopy.SizeBytes()));
+      memcpy(ChangeData(), theCopy.Data(), std::min(SizeBytes(), theCopy.SizeBytes()));
       return true;
     }
 
     // copy row-by-row
-    const Standard_Size aRowSizeBytes = std::min (SizeRowBytes(), theCopy.SizeRowBytes());
+    const Standard_Size aRowSizeBytes = std::min(SizeRowBytes(), theCopy.SizeRowBytes());
     for (Standard_Size aRow = 0; aRow < myData.SizeY; ++aRow)
     {
-      memcpy (ChangeRow (aRow), theCopy.Row (aRow), aRowSizeBytes);
+      memcpy(ChangeRow(aRow), theCopy.Row(aRow), aRowSizeBytes);
     }
     return true;
   }
@@ -491,7 +491,7 @@ void Image_AlienPixMap::Clear()
 #ifdef HAVE_FREEIMAGE
   if (myLibImage != NULL)
   {
-    FreeImage_Unload (myLibImage);
+    FreeImage_Unload(myLibImage);
     myLibImage = NULL;
   }
 #endif
@@ -517,41 +517,41 @@ bool Image_AlienPixMap::IsTopDownDefault()
 // purpose  :
 // =======================================================================
 #ifdef HAVE_FREEIMAGE
-bool Image_AlienPixMap::Load (const Standard_Byte* theData,
-                              Standard_Size theLength,
-                              const TCollection_AsciiString& theImagePath)
+bool Image_AlienPixMap::Load(const Standard_Byte* theData,
+  Standard_Size theLength,
+  const TCollection_AsciiString& theImagePath)
 {
   Clear();
 
 #ifdef _WIN32
-  const TCollection_ExtendedString aFileNameW (theImagePath);
+  const TCollection_ExtendedString aFileNameW(theImagePath);
 #endif
   FREE_IMAGE_FORMAT aFIF = FIF_UNKNOWN;
   FIMEMORY* aFiMem = NULL;
   if (theData != NULL)
   {
-    aFiMem = FreeImage_OpenMemory ((BYTE* )theData, (DWORD )theLength);
-    aFIF = FreeImage_GetFileTypeFromMemory (aFiMem, 0);
+    aFiMem = FreeImage_OpenMemory((BYTE*)theData, (DWORD)theLength);
+    aFIF = FreeImage_GetFileTypeFromMemory(aFiMem, 0);
   }
   else
   {
-  #ifdef _WIN32
-    aFIF = FreeImage_GetFileTypeU (aFileNameW.ToWideString(), 0);
-  #else
-    aFIF = FreeImage_GetFileType (theImagePath.ToCString(), 0);
-  #endif
+#ifdef _WIN32
+    aFIF = FreeImage_GetFileTypeU(aFileNameW.ToWideString(), 0);
+#else
+    aFIF = FreeImage_GetFileType(theImagePath.ToCString(), 0);
+#endif
   }
   if (aFIF == FIF_UNKNOWN)
   {
     // no signature? try to guess the file format from the file extension
-    aFIF = FreeImage_GetFIFFromFilename (theImagePath.ToCString());
+    aFIF = FreeImage_GetFIFFromFilename(theImagePath.ToCString());
   }
-  if ((aFIF == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading (aFIF))
+  if ((aFIF == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading(aFIF))
   {
-    ::Message::SendFail (TCollection_AsciiString ("Error: image '") + theImagePath + "' has unsupported file format");
+    ::Message::SendFail(TCollection_AsciiString("Error: image '") + theImagePath + "' has unsupported file format");
     if (aFiMem != NULL)
     {
-      FreeImage_CloseMemory (aFiMem);
+      FreeImage_CloseMemory(aFiMem);
     }
     return false;
   }
@@ -571,81 +571,81 @@ bool Image_AlienPixMap::Load (const Standard_Byte* theData,
   FIBITMAP* anImage = NULL;
   if (theData != NULL)
   {
-    anImage = FreeImage_LoadFromMemory (aFIF, aFiMem, aLoadFlags);
-    FreeImage_CloseMemory (aFiMem);
+    anImage = FreeImage_LoadFromMemory(aFIF, aFiMem, aLoadFlags);
+    FreeImage_CloseMemory(aFiMem);
     aFiMem = NULL;
   }
   else
   {
-  #ifdef _WIN32
-    anImage = FreeImage_LoadU (aFIF, aFileNameW.ToWideString(), aLoadFlags);
-  #else
-    anImage = FreeImage_Load  (aFIF, theImagePath.ToCString(), aLoadFlags);
-  #endif
+#ifdef _WIN32
+    anImage = FreeImage_LoadU(aFIF, aFileNameW.ToWideString(), aLoadFlags);
+#else
+    anImage = FreeImage_Load(aFIF, theImagePath.ToCString(), aLoadFlags);
+#endif
   }
   if (anImage == NULL)
   {
-    ::Message::SendFail (TCollection_AsciiString ("Error: image file '") + theImagePath  + "' is missing or invalid");
+    ::Message::SendFail(TCollection_AsciiString("Error: image file '") + theImagePath + "' is missing or invalid");
     return false;
   }
 
   Image_Format aFormat = Image_Format_UNKNOWN;
-  if (FreeImage_GetBPP (anImage) == 1)
+  if (FreeImage_GetBPP(anImage) == 1)
   {
-    FIBITMAP* aTmpImage = FreeImage_ConvertTo8Bits (anImage);
-    FreeImage_Unload (anImage);
+    FIBITMAP* aTmpImage = FreeImage_ConvertTo8Bits(anImage);
+    FreeImage_Unload(anImage);
     anImage = aTmpImage;
   }
   if (anImage != NULL)
   {
-    aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage),
-                                     FreeImage_GetColorType(anImage),
-                                     FreeImage_GetBPP      (anImage));
+    aFormat = convertFromFreeFormat(FreeImage_GetImageType(anImage),
+      FreeImage_GetColorType(anImage),
+      FreeImage_GetBPP(anImage));
     if (aFormat == Image_Format_UNKNOWN)
     {
-      FIBITMAP* aTmpImage = FreeImage_ConvertTo24Bits (anImage);
-      FreeImage_Unload (anImage);
+      FIBITMAP* aTmpImage = FreeImage_ConvertTo24Bits(anImage);
+      FreeImage_Unload(anImage);
       anImage = aTmpImage;
       if (anImage != NULL)
       {
-        aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage),
-                                         FreeImage_GetColorType(anImage),
-                                         FreeImage_GetBPP      (anImage));
+        aFormat = convertFromFreeFormat(FreeImage_GetImageType(anImage),
+          FreeImage_GetColorType(anImage),
+          FreeImage_GetBPP(anImage));
       }
     }
   }
   if (aFormat == Image_Format_UNKNOWN)
   {
-    ::Message::SendFail (TCollection_AsciiString ("Error: image '") + theImagePath + "' has unsupported pixel format");
+    ::Message::SendFail(TCollection_AsciiString("Error: image '") + theImagePath + "' has unsupported pixel format");
     return false;
   }
 
-  Image_PixMap::InitWrapper (aFormat, FreeImage_GetBits (anImage),
-                             FreeImage_GetWidth (anImage), FreeImage_GetHeight (anImage), FreeImage_GetPitch (anImage));
-  SetTopDown (false);
+  Image_PixMap::InitWrapper(aFormat, FreeImage_GetBits(anImage),
+    FreeImage_GetWidth(anImage), FreeImage_GetHeight(anImage), FreeImage_GetPitch(anImage));
+  SetTopDown(false);
 
   // assign image after wrapper initialization (virtual Clear() called inside)
   myLibImage = anImage;
   return true;
 }
 
-bool Image_AlienPixMap::Load (std::istream& theStream,
-                              const TCollection_AsciiString& theFileName)
+bool Image_AlienPixMap::Load(std::istream& theStream,
+  const TCollection_AsciiString& theFileName)
 {
   Clear();
 
-  Image_FreeImageStream aStream (theStream);
+  Image_FreeImageStream aStream(theStream);
   FreeImageIO aFiIO = aStream.GetFiIO();
 
-  FREE_IMAGE_FORMAT aFIF = FreeImage_GetFileTypeFromHandle (&aFiIO, &aStream, 0);
+  FREE_IMAGE_FORMAT aFIF = FreeImage_GetFileTypeFromHandle(&aFiIO, &aStream, 0);
   if (aFIF == FIF_UNKNOWN)
   {
     // no signature? try to guess the file format from the file extension
-    aFIF = FreeImage_GetFIFFromFilename (theFileName.ToCString());
+    aFIF = FreeImage_GetFIFFromFilename(theFileName.ToCString());
   }
-  if ((aFIF == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading (aFIF))
+  if ((aFIF == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading(aFIF))
   {
-    ::Message::SendFail (TCollection_AsciiString ("Error: image stream '") + theFileName + "' has unsupported file format");
+    ::Message::SendFail(TCollection_AsciiString("Error: image stream '") + theFileName + "' has unsupported file format");
     return false;
   }
 
@@ -661,25 +661,25 @@ bool Image_AlienPixMap::Load (std::istream& theStream,
     aLoadFlags = ICO_MAKEALPHA;
   }
 
-  FIBITMAP* anImage = FreeImage_LoadFromHandle (aFIF, &aFiIO, &aStream, aLoadFlags);
+  FIBITMAP* anImage = FreeImage_LoadFromHandle(aFIF, &aFiIO, &aStream, aLoadFlags);
   if (anImage == NULL)
   {
-    ::Message::SendFail (TCollection_AsciiString ("Error: image stream '") + theFileName + "' is missing or invalid");
+    ::Message::SendFail(TCollection_AsciiString("Error: image stream '") + theFileName + "' is missing or invalid");
     return false;
   }
 
-  Image_Format aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage),
-                                                FreeImage_GetColorType(anImage),
-                                                FreeImage_GetBPP      (anImage));
+  Image_Format aFormat = convertFromFreeFormat(FreeImage_GetImageType(anImage),
+    FreeImage_GetColorType(anImage),
+    FreeImage_GetBPP(anImage));
   if (aFormat == Image_Format_UNKNOWN)
   {
-    ::Message::SendFail (TCollection_AsciiString ("Error: image stream '") + theFileName + "' has unsupported pixel format");
+    ::Message::SendFail(TCollection_AsciiString("Error: image stream '") + theFileName + "' has unsupported pixel format");
     return false;
   }
 
-  Image_PixMap::InitWrapper (aFormat, FreeImage_GetBits (anImage),
-                             FreeImage_GetWidth (anImage), FreeImage_GetHeight (anImage), FreeImage_GetPitch (anImage));
-  SetTopDown (false);
+  Image_PixMap::InitWrapper(aFormat, FreeImage_GetBits(anImage),
+    FreeImage_GetWidth(anImage), FreeImage_GetHeight(anImage), FreeImage_GetPitch(anImage));
+  SetTopDown(false);
 
   // assign image after wrapper initialization (virtual Clear() called inside)
   myLibImage = anImage;
@@ -687,17 +687,17 @@ bool Image_AlienPixMap::Load (std::istream& theStream,
 }
 
 #elif defined(HAVE_WINCODEC)
-bool Image_AlienPixMap::Load (const Standard_Byte* theData,
-                              Standard_Size theLength,
-                              const TCollection_AsciiString& theFileName)
+bool Image_AlienPixMap::Load(const Standard_Byte* theData,
+  Standard_Size theLength,
+  const TCollection_AsciiString& theFileName)
 {
   Clear();
 
   Image_ComPtr<IWICImagingFactory> aWicImgFactory;
-  CoInitializeEx (NULL, COINIT_MULTITHREADED);
-  if (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory.ChangePtr())) != S_OK)
+  CoInitializeEx(NULL, COINIT_MULTITHREADED);
+  if (CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory.ChangePtr())) != S_OK)
   {
-    Message::SendFail ("Error: cannot initialize WIC Imaging Factory");
+    Message::SendFail("Error: cannot initialize WIC Imaging Factory");
     return false;
   }
 
@@ -705,24 +705,24 @@ bool Image_AlienPixMap::Load (const Standard_Byte* theData,
   Image_ComPtr<IWICStream> aWicStream;
   if (theData != NULL)
   {
-    if (aWicImgFactory->CreateStream (&aWicStream.ChangePtr()) != S_OK
-     || aWicStream->InitializeFromMemory ((BYTE* )theData, (DWORD )theLength) != S_OK)
+    if (aWicImgFactory->CreateStream(&aWicStream.ChangePtr()) != S_OK
+      || aWicStream->InitializeFromMemory((BYTE*)theData, (DWORD)theLength) != S_OK)
     {
-      Message::SendFail ("Error: cannot initialize WIC Stream");
+      Message::SendFail("Error: cannot initialize WIC Stream");
       return false;
     }
-    if (aWicImgFactory->CreateDecoderFromStream (aWicStream.get(), NULL, WICDecodeMetadataCacheOnDemand, &aWicDecoder.ChangePtr()) != S_OK)
+    if (aWicImgFactory->CreateDecoderFromStream(aWicStream.get(), NULL, WICDecodeMetadataCacheOnDemand, &aWicDecoder.ChangePtr()) != S_OK)
     {
-      Message::SendFail ("Error: cannot create WIC Image Decoder");
+      Message::SendFail("Error: cannot create WIC Image Decoder");
       return false;
     }
   }
   else
   {
-    const TCollection_ExtendedString aFileNameW (theFileName);
-    if (aWicImgFactory->CreateDecoderFromFilename (aFileNameW.ToWideString(), NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &aWicDecoder.ChangePtr()) != S_OK)
+    const TCollection_ExtendedString aFileNameW(theFileName);
+    if (aWicImgFactory->CreateDecoderFromFilename(aFileNameW.ToWideString(), NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &aWicDecoder.ChangePtr()) != S_OK)
     {
-      Message::SendFail ("Error: cannot create WIC Image Decoder");
+      Message::SendFail("Error: cannot create WIC Image Decoder");
       return false;
     }
   }
@@ -730,88 +730,88 @@ bool Image_AlienPixMap::Load (const Standard_Byte* theData,
   UINT aFrameCount = 0, aFrameSizeX = 0, aFrameSizeY = 0;
   WICPixelFormatGUID aWicPixelFormat = getNullGuid();
   Image_ComPtr<IWICBitmapFrameDecode> aWicFrameDecode;
-  if (aWicDecoder->GetFrameCount (&aFrameCount) != S_OK
-   || aFrameCount < 1
-   || aWicDecoder->GetFrame (0, &aWicFrameDecode.ChangePtr()) != S_OK
-   || aWicFrameDecode->GetSize (&aFrameSizeX, &aFrameSizeY) != S_OK
-   || aWicFrameDecode->GetPixelFormat (&aWicPixelFormat))
+  if (aWicDecoder->GetFrameCount(&aFrameCount) != S_OK
+    || aFrameCount < 1
+    || aWicDecoder->GetFrame(0, &aWicFrameDecode.ChangePtr()) != S_OK
+    || aWicFrameDecode->GetSize(&aFrameSizeX, &aFrameSizeY) != S_OK
+    || aWicFrameDecode->GetPixelFormat(&aWicPixelFormat))
   {
-    Message::SendFail ("Error: cannot get WIC Image Frame");
+    Message::SendFail("Error: cannot get WIC Image Frame");
     return false;
   }
 
   Image_ComPtr<IWICFormatConverter> aWicConvertedFrame;
-  Image_Format aPixelFormat = convertFromWicFormat (aWicPixelFormat);
+  Image_Format aPixelFormat = convertFromWicFormat(aWicPixelFormat);
   if (aPixelFormat == Image_Format_UNKNOWN)
   {
     aPixelFormat = Image_Format_RGB;
-    if (aWicImgFactory->CreateFormatConverter (&aWicConvertedFrame.ChangePtr()) != S_OK
-     || aWicConvertedFrame->Initialize (aWicFrameDecode.get(), convertToWicFormat (aPixelFormat), WICBitmapDitherTypeNone, NULL, 0.0f, WICBitmapPaletteTypeCustom) != S_OK)
+    if (aWicImgFactory->CreateFormatConverter(&aWicConvertedFrame.ChangePtr()) != S_OK
+      || aWicConvertedFrame->Initialize(aWicFrameDecode.get(), convertToWicFormat(aPixelFormat), WICBitmapDitherTypeNone, NULL, 0.0f, WICBitmapPaletteTypeCustom) != S_OK)
     {
-      Message::SendFail ("Error: cannot convert WIC Image Frame to RGB format");
+      Message::SendFail("Error: cannot convert WIC Image Frame to RGB format");
       return false;
     }
     aWicFrameDecode.Nullify();
   }
 
-  if (!Image_PixMap::InitTrash (aPixelFormat, aFrameSizeX, aFrameSizeY))
+  if (!Image_PixMap::InitTrash(aPixelFormat, aFrameSizeX, aFrameSizeY))
   {
-    Message::SendFail ("Error: cannot initialize memory for image");
+    Message::SendFail("Error: cannot initialize memory for image");
     return false;
   }
 
   IWICBitmapSource* aWicSrc = aWicFrameDecode.get();
-  if(!aWicConvertedFrame.IsNull())
+  if (!aWicConvertedFrame.IsNull())
   {
     aWicSrc = aWicConvertedFrame.get();
   }
-  if (aWicSrc->CopyPixels (NULL, (UINT )SizeRowBytes(), (UINT )SizeBytes(), ChangeData()) != S_OK)
+  if (aWicSrc->CopyPixels(NULL, (UINT)SizeRowBytes(), (UINT)SizeBytes(), ChangeData()) != S_OK)
   {
-    Message::SendFail ("Error: cannot copy pixels from WIC Image");
+    Message::SendFail("Error: cannot copy pixels from WIC Image");
     return false;
   }
-  SetTopDown (true);
+  SetTopDown(true);
   return true;
 }
-bool Image_AlienPixMap::Load (std::istream& theStream,
-                              const TCollection_AsciiString& theFilePath)
+bool Image_AlienPixMap::Load(std::istream& theStream,
+  const TCollection_AsciiString& theFilePath)
 {
   Clear();
 
   // fallback copying stream data into transient buffer
   const std::streamoff aStart = theStream.tellg();
-  theStream.seekg (0, std::ios::end);
+  theStream.seekg(0, std::ios::end);
   const Standard_Integer aLen = Standard_Integer(theStream.tellg() - aStart);
-  theStream.seekg (aStart);
+  theStream.seekg(aStart);
   if (aLen <= 0)
   {
-    Message::SendFail ("Error: empty stream");
+    Message::SendFail("Error: empty stream");
     return false;
   }
 
-  NCollection_Array1<Standard_Byte> aBuff (1, aLen);
-  if (!theStream.read ((char* )&aBuff.ChangeFirst(), aBuff.Size()))
+  NCollection_Array1<Standard_Byte> aBuff(1, aLen);
+  if (!theStream.read((char*)&aBuff.ChangeFirst(), aBuff.Size()))
   {
-    Message::SendFail ("Error: unable to read stream");
+    Message::SendFail("Error: unable to read stream");
     return false;
   }
 
-  return Load (&aBuff.ChangeFirst(), aBuff.Size(), theFilePath);
+  return Load(&aBuff.ChangeFirst(), aBuff.Size(), theFilePath);
 }
 #else
-bool Image_AlienPixMap::Load (std::istream& ,
-                              const TCollection_AsciiString& )
+bool Image_AlienPixMap::Load(std::istream&,
+  const TCollection_AsciiString&)
 {
   Clear();
-  Message::SendFail ("Error: no image library available");
+  Message::SendFail("Error: no image library available");
   return false;
 }
-bool Image_AlienPixMap::Load (const Standard_Byte* ,
-                              Standard_Size ,
-                              const TCollection_AsciiString& )
+bool Image_AlienPixMap::Load(const Standard_Byte*,
+  Standard_Size,
+  const TCollection_AsciiString&)
 {
   Clear();
-  Message::SendFail ("Error: no image library available");
+  Message::SendFail("Error: no image library available");
   return false;
 }
 #endif
@@ -820,7 +820,7 @@ bool Image_AlienPixMap::Load (const Standard_Byte* ,
 // function : savePPM
 // purpose  :
 // =======================================================================
-bool Image_AlienPixMap::savePPM (const TCollection_AsciiString& theFileName) const
+bool Image_AlienPixMap::savePPM(const TCollection_AsciiString& theFileName) const
 {
   if (IsEmpty())
   {
@@ -828,15 +828,15 @@ bool Image_AlienPixMap::savePPM (const TCollection_AsciiString& theFileName) con
   }
 
   // Open file
-  FILE* aFile = OSD_OpenFile (theFileName.ToCString(), "wb");
+  FILE* aFile = OSD_OpenFile(theFileName.ToCString(), "wb");
   if (aFile == NULL)
   {
     return false;
   }
 
   // Write header
-  fprintf (aFile, "P6\n%d %d\n255\n", (int )SizeX(), (int )SizeY());
-  fprintf (aFile, "# Image stored by OpenCASCADE framework in linear RGB colorspace\n");
+  fprintf(aFile, "P6\n%d %d\n255\n", (int)SizeX(), (int)SizeY());
+  fprintf(aFile, "# Image stored by OpenCASCADE framework in linear RGB colorspace\n");
 
   // Write pixel data
   Standard_Byte aByte;
@@ -845,15 +845,15 @@ bool Image_AlienPixMap::savePPM (const TCollection_AsciiString& theFileName) con
     for (Standard_Size aCol = 0; aCol < SizeX(); ++aCol)
     {
       // extremely SLOW but universal (implemented for all supported pixel formats)
-      const Quantity_ColorRGBA aColor = PixelColor ((Standard_Integer )aCol, (Standard_Integer )aRow);
-      aByte = Standard_Byte(aColor.GetRGB().Red()   * 255.0); fwrite (&aByte, 1, 1, aFile);
-      aByte = Standard_Byte(aColor.GetRGB().Green() * 255.0); fwrite (&aByte, 1, 1, aFile);
-      aByte = Standard_Byte(aColor.GetRGB().Blue()  * 255.0); fwrite (&aByte, 1, 1, aFile);
+      const Quantity_ColorRGBA aColor = PixelColor((Standard_Integer)aCol, (Standard_Integer)aRow);
+      aByte = Standard_Byte(aColor.GetRGB().Red() * 255.0); fwrite(&aByte, 1, 1, aFile);
+      aByte = Standard_Byte(aColor.GetRGB().Green() * 255.0); fwrite(&aByte, 1, 1, aFile);
+      aByte = Standard_Byte(aColor.GetRGB().Blue() * 255.0); fwrite(&aByte, 1, 1, aFile);
     }
   }
 
   // Close file
-  fclose (aFile);
+  fclose(aFile);
   return true;
 }
 
@@ -861,7 +861,7 @@ bool Image_AlienPixMap::savePPM (const TCollection_AsciiString& theFileName) con
 // function : Save
 // purpose  :
 // =======================================================================
-bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
+bool Image_AlienPixMap::Save(const TCollection_AsciiString& theFileName)
 {
 #ifdef HAVE_FREEIMAGE
   if (myLibImage == NULL)
@@ -870,10 +870,10 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
   }
 
 #ifdef _WIN32
-  const TCollection_ExtendedString aFileNameW (theFileName.ToCString(), Standard_True);
-  FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilenameU (aFileNameW.ToWideString());
+  const TCollection_ExtendedString aFileNameW(theFileName.ToCString(), Standard_True);
+  FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilenameU(aFileNameW.ToWideString());
 #else
-  FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilename (theFileName.ToCString());
+  FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilename(theFileName.ToCString());
 #endif
   if (anImageFormat == FIF_UNKNOWN)
   {
@@ -885,8 +885,8 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
 
   if (IsTopDown())
   {
-    FreeImage_FlipVertical (myLibImage);
-    SetTopDown (false);
+    FreeImage_FlipVertical(myLibImage);
+    SetTopDown(false);
   }
 
   // FreeImage doesn't provide flexible format conversion API
@@ -894,112 +894,112 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
   FIBITMAP* anImageToDump = myLibImage;
   switch (anImageFormat)
   {
-    case FIF_PNG:
-    case FIF_BMP:
+  case FIF_PNG:
+  case FIF_BMP:
+  {
+    if (Format() == Image_Format_BGR32
+      || Format() == Image_Format_RGB32)
     {
-      if (Format() == Image_Format_BGR32
-       || Format() == Image_Format_RGB32)
+      // stupid FreeImage treats reserved byte as alpha if some bytes not set to 0xFF
+      for (Standard_Size aRow = 0; aRow < SizeY(); ++aRow)
       {
-        // stupid FreeImage treats reserved byte as alpha if some bytes not set to 0xFF
-        for (Standard_Size aRow = 0; aRow < SizeY(); ++aRow)
+        for (Standard_Size aCol = 0; aCol < SizeX(); ++aCol)
         {
-          for (Standard_Size aCol = 0; aCol < SizeX(); ++aCol)
-          {
-            myData.ChangeValue (aRow, aCol)[3] = 0xFF;
-          }
+          myData.ChangeValue(aRow, aCol)[3] = 0xFF;
         }
       }
-      else if (FreeImage_GetImageType (myLibImage) != FIT_BITMAP)
-      {
-        anImageToDump = FreeImage_ConvertToType (myLibImage, FIT_BITMAP);
-      }
-      break;
     }
-    case FIF_GIF:
+    else if (FreeImage_GetImageType(myLibImage) != FIT_BITMAP)
+    {
+      anImageToDump = FreeImage_ConvertToType(myLibImage, FIT_BITMAP);
+    }
+    break;
+  }
+  case FIF_GIF:
+  {
+    FIBITMAP* aTmpBitmap = myLibImage;
+    if (FreeImage_GetImageType(myLibImage) != FIT_BITMAP)
     {
-      FIBITMAP* aTmpBitmap = myLibImage;
-      if (FreeImage_GetImageType (myLibImage) != FIT_BITMAP)
+      aTmpBitmap = FreeImage_ConvertToType(myLibImage, FIT_BITMAP);
+      if (aTmpBitmap == NULL)
       {
-        aTmpBitmap = FreeImage_ConvertToType (myLibImage, FIT_BITMAP);
-        if (aTmpBitmap == NULL)
-        {
-          return false;
-        }
+        return false;
       }
+    }
 
-      if (FreeImage_GetBPP (aTmpBitmap) != 24)
+    if (FreeImage_GetBPP(aTmpBitmap) != 24)
+    {
+      FIBITMAP* aTmpBitmap24 = FreeImage_ConvertTo24Bits(aTmpBitmap);
+      if (aTmpBitmap != myLibImage)
       {
-        FIBITMAP* aTmpBitmap24 = FreeImage_ConvertTo24Bits (aTmpBitmap);
-        if (aTmpBitmap != myLibImage)
-        {
-          FreeImage_Unload (aTmpBitmap);
-        }
-        if (aTmpBitmap24 == NULL)
-        {
-          return false;
-        }
-        aTmpBitmap = aTmpBitmap24;
+        FreeImage_Unload(aTmpBitmap);
       }
-
-      // need conversion to image with palette (requires 24bit bitmap)
-      anImageToDump = FreeImage_ColorQuantize (aTmpBitmap, FIQ_NNQUANT);
-      if (aTmpBitmap != myLibImage)
+      if (aTmpBitmap24 == NULL)
       {
-        FreeImage_Unload (aTmpBitmap);
+        return false;
       }
-      break;
+      aTmpBitmap = aTmpBitmap24;
     }
-    case FIF_HDR:
-    case FIF_EXR:
+
+    // need conversion to image with palette (requires 24bit bitmap)
+    anImageToDump = FreeImage_ColorQuantize(aTmpBitmap, FIQ_NNQUANT);
+    if (aTmpBitmap != myLibImage)
     {
-      if (Format() == Image_Format_Gray
-       || Format() == Image_Format_Alpha)
-      {
-        anImageToDump = FreeImage_ConvertToType (myLibImage, FIT_FLOAT);
-      }
-      else if (Format() == Image_Format_RGBA
-            || Format() == Image_Format_BGRA)
+      FreeImage_Unload(aTmpBitmap);
+    }
+    break;
+  }
+  case FIF_HDR:
+  case FIF_EXR:
+  {
+    if (Format() == Image_Format_Gray
+      || Format() == Image_Format_Alpha)
+    {
+      anImageToDump = FreeImage_ConvertToType(myLibImage, FIT_FLOAT);
+    }
+    else if (Format() == Image_Format_RGBA
+      || Format() == Image_Format_BGRA)
+    {
+      anImageToDump = FreeImage_ConvertToType(myLibImage, FIT_RGBAF);
+    }
+    else
+    {
+      FREE_IMAGE_TYPE aImgTypeFI = FreeImage_GetImageType(myLibImage);
+      if (aImgTypeFI != FIT_RGBF
+        && aImgTypeFI != FIT_RGBAF
+        && aImgTypeFI != FIT_FLOAT)
       {
-        anImageToDump = FreeImage_ConvertToType (myLibImage, FIT_RGBAF);
+        anImageToDump = FreeImage_ConvertToType(myLibImage, FIT_RGBF);
       }
-      else
+    }
+    break;
+  }
+  default:
+  {
+    if (FreeImage_GetImageType(myLibImage) != FIT_BITMAP)
+    {
+      anImageToDump = FreeImage_ConvertToType(myLibImage, FIT_BITMAP);
+      if (anImageToDump == NULL)
       {
-        FREE_IMAGE_TYPE aImgTypeFI = FreeImage_GetImageType (myLibImage);
-        if (aImgTypeFI != FIT_RGBF
-         && aImgTypeFI != FIT_RGBAF
-         && aImgTypeFI != FIT_FLOAT)
-        {
-          anImageToDump = FreeImage_ConvertToType (myLibImage, FIT_RGBF);
-        }
+        return false;
       }
-      break;
     }
-    default:
+
+    if (FreeImage_GetBPP(anImageToDump) != 24)
     {
-      if (FreeImage_GetImageType (myLibImage) != FIT_BITMAP)
+      FIBITMAP* aTmpBitmap24 = FreeImage_ConvertTo24Bits(anImageToDump);
+      if (anImageToDump != myLibImage)
       {
-        anImageToDump = FreeImage_ConvertToType (myLibImage, FIT_BITMAP);
-        if (anImageToDump == NULL)
-        {
-          return false;
-        }
+        FreeImage_Unload(anImageToDump);
       }
-
-      if (FreeImage_GetBPP (anImageToDump) != 24)
+      if (aTmpBitmap24 == NULL)
       {
-        FIBITMAP* aTmpBitmap24 = FreeImage_ConvertTo24Bits (anImageToDump);
-        if (anImageToDump != myLibImage)
-        {
-          FreeImage_Unload (anImageToDump);
-        }
-        if (aTmpBitmap24 == NULL)
-        {
-          return false;
-        }
-        anImageToDump = aTmpBitmap24;
+        return false;
       }
-      break;
+      anImageToDump = aTmpBitmap24;
     }
+    break;
+  }
   }
 
   if (anImageToDump == NULL)
@@ -1008,13 +1008,13 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
   }
 
 #ifdef _WIN32
-  bool isSaved = (FreeImage_SaveU (anImageFormat, anImageToDump, aFileNameW.ToWideString()) != FALSE);
+  bool isSaved = (FreeImage_SaveU(anImageFormat, anImageToDump, aFileNameW.ToWideString()) != FALSE);
 #else
-  bool isSaved = (FreeImage_Save  (anImageFormat, anImageToDump, theFileName.ToCString()) != FALSE);
+  bool isSaved = (FreeImage_Save(anImageFormat, anImageToDump, theFileName.ToCString()) != FALSE);
 #endif
   if (anImageToDump != myLibImage)
   {
-    FreeImage_Unload (anImageToDump);
+    FreeImage_Unload(anImageToDump);
   }
   return isSaved;
 
@@ -1023,91 +1023,91 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
   TCollection_AsciiString aFileNameLower = theFileName;
   aFileNameLower.LowerCase();
   GUID aFileFormat = getNullGuid();
-  if (aFileNameLower.EndsWith (".ppm"))
+  if (aFileNameLower.EndsWith(".ppm"))
   {
-    return savePPM (theFileName);
+    return savePPM(theFileName);
   }
-  else if (aFileNameLower.EndsWith (".bmp"))
+  else if (aFileNameLower.EndsWith(".bmp"))
   {
     aFileFormat = GUID_ContainerFormatBmp;
   }
-  else if (aFileNameLower.EndsWith (".png"))
+  else if (aFileNameLower.EndsWith(".png"))
   {
     aFileFormat = GUID_ContainerFormatPng;
   }
-  else if (aFileNameLower.EndsWith (".jpg")
-        || aFileNameLower.EndsWith (".jpeg"))
+  else if (aFileNameLower.EndsWith(".jpg")
+    || aFileNameLower.EndsWith(".jpeg"))
   {
     aFileFormat = GUID_ContainerFormatJpeg;
   }
-  else if (aFileNameLower.EndsWith (".tiff"))
+  else if (aFileNameLower.EndsWith(".tiff"))
   {
     aFileFormat = GUID_ContainerFormatTiff;
   }
-  else if (aFileNameLower.EndsWith (".gif"))
+  else if (aFileNameLower.EndsWith(".gif"))
   {
     aFileFormat = GUID_ContainerFormatGif;
   }
 
   if (aFileFormat == getNullGuid())
   {
-    Message::SendFail ("Error: unsupported image format");
+    Message::SendFail("Error: unsupported image format");
     return false;
   }
 
   Image_ComPtr<IWICImagingFactory> aWicImgFactory;
-  CoInitializeEx (NULL, COINIT_MULTITHREADED);
-  if (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory.ChangePtr())) != S_OK)
+  CoInitializeEx(NULL, COINIT_MULTITHREADED);
+  if (CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory.ChangePtr())) != S_OK)
   {
-    Message::SendFail ("Error: cannot initialize WIC Imaging Factory");
+    Message::SendFail("Error: cannot initialize WIC Imaging Factory");
     return false;
   }
 
   Image_ComPtr<IWICStream> aWicFileStream;
   Image_ComPtr<IWICBitmapEncoder> aWicEncoder;
-  const TCollection_ExtendedString aFileNameW (theFileName);
-  if (aWicImgFactory->CreateStream (&aWicFileStream.ChangePtr()) != S_OK
-   || aWicFileStream->InitializeFromFilename (aFileNameW.ToWideString(), GENERIC_WRITE) != S_OK)
+  const TCollection_ExtendedString aFileNameW(theFileName);
+  if (aWicImgFactory->CreateStream(&aWicFileStream.ChangePtr()) != S_OK
+    || aWicFileStream->InitializeFromFilename(aFileNameW.ToWideString(), GENERIC_WRITE) != S_OK)
   {
-    Message::SendFail ("Error: cannot create WIC File Stream");
+    Message::SendFail("Error: cannot create WIC File Stream");
     return false;
   }
-  if (aWicImgFactory->CreateEncoder (aFileFormat, NULL, &aWicEncoder.ChangePtr()) != S_OK
-   || aWicEncoder->Initialize (aWicFileStream.get(), WICBitmapEncoderNoCache) != S_OK)
+  if (aWicImgFactory->CreateEncoder(aFileFormat, NULL, &aWicEncoder.ChangePtr()) != S_OK
+    || aWicEncoder->Initialize(aWicFileStream.get(), WICBitmapEncoderNoCache) != S_OK)
   {
-    Message::SendFail ("Error: cannot create WIC Encoder");
+    Message::SendFail("Error: cannot create WIC Encoder");
     return false;
   }
 
-  const WICPixelFormatGUID aWicPixelFormat = convertToWicFormat (myImgFormat);
+  const WICPixelFormatGUID aWicPixelFormat = convertToWicFormat(myImgFormat);
   if (aWicPixelFormat == getNullGuid())
   {
-    Message::SendFail ("Error: unsupported pixel format");
+    Message::SendFail("Error: unsupported pixel format");
     return false;
   }
 
   WICPixelFormatGUID aWicPixelFormatRes = aWicPixelFormat;
   Image_ComPtr<IWICBitmapFrameEncode> aWicFrameEncode;
-  if (aWicEncoder->CreateNewFrame (&aWicFrameEncode.ChangePtr(), NULL) != S_OK
-   || aWicFrameEncode->Initialize (NULL) != S_OK
-   || aWicFrameEncode->SetSize ((UINT )SizeX(), (UINT )SizeY()) != S_OK
-   || aWicFrameEncode->SetPixelFormat (&aWicPixelFormatRes) != S_OK)
+  if (aWicEncoder->CreateNewFrame(&aWicFrameEncode.ChangePtr(), NULL) != S_OK
+    || aWicFrameEncode->Initialize(NULL) != S_OK
+    || aWicFrameEncode->SetSize((UINT)SizeX(), (UINT)SizeY()) != S_OK
+    || aWicFrameEncode->SetPixelFormat(&aWicPixelFormatRes) != S_OK)
   {
-    Message::SendFail ("Error: cannot create WIC Frame");
+    Message::SendFail("Error: cannot create WIC Frame");
     return false;
   }
 
   if (aWicPixelFormatRes != aWicPixelFormat)
   {
-    Message::SendFail ("Error: pixel format is unsupported by image format");
+    Message::SendFail("Error: pixel format is unsupported by image format");
     return false;
   }
 
   if (IsTopDown())
   {
-    if (aWicFrameEncode->WritePixels ((UINT )SizeY(), (UINT )SizeRowBytes(), (UINT )SizeBytes(), (BYTE* )Data()) != S_OK)
+    if (aWicFrameEncode->WritePixels((UINT)SizeY(), (UINT)SizeRowBytes(), (UINT)SizeBytes(), (BYTE*)Data()) != S_OK)
     {
-      Message::SendFail ("Error: cannot write pixels to WIC Frame");
+      Message::SendFail("Error: cannot write pixels to WIC Frame");
       return false;
     }
   }
@@ -1115,21 +1115,21 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
   {
     for (Standard_Size aRow = 0; aRow < SizeY(); ++aRow)
     {
-      if (aWicFrameEncode->WritePixels (1, (UINT )SizeRowBytes(), (UINT )SizeRowBytes(), (BYTE* )Row (aRow)) != S_OK)
+      if (aWicFrameEncode->WritePixels(1, (UINT)SizeRowBytes(), (UINT)SizeRowBytes(), (BYTE*)Row(aRow)) != S_OK)
       {
-        Message::SendFail ("Error: cannot write pixels to WIC Frame");
+        Message::SendFail("Error: cannot write pixels to WIC Frame");
         return false;
       }
     }
   }
 
   if (aWicFrameEncode->Commit() != S_OK
-   || aWicEncoder->Commit() != S_OK)
+    || aWicEncoder->Commit() != S_OK)
   {
-    Message::SendFail ("Error: cannot commit data to WIC Frame");
+    Message::SendFail("Error: cannot commit data to WIC Frame");
     return false;
   }
-  if (aWicFileStream->Commit (STGC_DEFAULT) != S_OK)
+  if (aWicFileStream->Commit(STGC_DEFAULT) != S_OK)
   {
     //Message::Send ("Error: cannot commit data to WIC File Stream", Message_Fail);
     //return false;
@@ -1137,13 +1137,13 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
   return true;
 #else
   const Standard_Integer aLen = theFileName.Length();
-  if ((aLen >= 4) && (theFileName.Value (aLen - 3) == '.')
-      && strcasecmp( theFileName.ToCString() + aLen - 3, "ppm") == 0 )
+  if ((aLen >= 4) && (theFileName.Value(aLen - 3) == '.')
+    && strcasecmp(theFileName.ToCString() + aLen - 3, "ppm") == 0)
   {
-    return savePPM (theFileName);
+    return savePPM(theFileName);
   }
-  Message::SendTrace ("Image_PixMap, no image library available! Image saved in PPM format");
-  return savePPM (theFileName);
+  Message::SendTrace("Image_PixMap, no image library available! Image saved in PPM format");
+  return savePPM(theFileName);
 #endif
 }
 
@@ -1151,12 +1151,12 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
 // function : AdjustGamma
 // purpose  :
 // =======================================================================
-bool Image_AlienPixMap::AdjustGamma (const Standard_Real theGammaCorr)
+bool Image_AlienPixMap::AdjustGamma(const Standard_Real theGammaCorr)
 {
 #ifdef HAVE_FREEIMAGE
-  return FreeImage_AdjustGamma (myLibImage, theGammaCorr) != FALSE;
+  return FreeImage_AdjustGamma(myLibImage, theGammaCorr) != FALSE;
 #else
-  (void )theGammaCorr;
+  (void)theGammaCorr;
   return false;
 #endif
 }
index 4dd5e0a921550253ab3d99b46d3c47463c78bfc6..4e7177a00b8eafd0c6f45c7c11202ae4b06b26b5 100644 (file)
@@ -994,7 +994,15 @@ static Standard_Integer getanasurf(Draw_Interpretor& di,
   Standard_Integer n, const char** a)
 
 {
-  if (n < 3) return 1;
+  if (n < 3) {
+    di << "Usage: \n";
+    di << "getanasurf res shape [target [tol [sample]]] \n";
+    di << "target is reqired type of surface and can be: pln, cyl, con sph \n";
+    di << "sample is surface of required type, which parameters are used as starting \n";
+    di << "point for seaching parametrs of surface by Least Square method when input shape \n";
+    di << "is edge or wire \n";
+      return 1;
+  }
   TopoDS_Shape sh = DBRep::Get(a[2]);
   if (sh.IsNull()) return 1;
   TopAbs_ShapeEnum aShType = sh.ShapeType();
@@ -1007,8 +1015,17 @@ static Standard_Integer getanasurf(Draw_Interpretor& di,
   GeomAbs_SurfaceType aTargets[] = { GeomAbs_Plane, GeomAbs_Cylinder, GeomAbs_Cone, GeomAbs_Sphere };
   Standard_Integer isurf = 0;
   if (n > 3)
-    isurf = Draw::Atoi(a[3]);
-  isurf = Min(isurf, 3);
+  {
+    if (strcmp(a[3], "pln") == 0)
+      isurf = 0;
+    else if (strcmp(a[3], "cyl") == 0)
+      isurf = 1;
+    else if (strcmp(a[3], "con") == 0)
+      isurf = 2;
+    else if (strcmp(a[3], "sph") == 0)
+      isurf = 3;
+  }
+
   Standard_Real tol = 1.e-7;
   if (n > 4)
     tol = Draw::Atof(a[4]);
@@ -1079,6 +1096,7 @@ static Standard_Integer getanasurf(Draw_Interpretor& di,
   if (!aRes.IsNull())
   {
     DrawTrSurf::Set(a[1], aRes);
+    di << "Gap = " << aCanonRec.GetGap() << "\n";
   }
   else
   {
@@ -1094,6 +1112,12 @@ static Standard_Integer getanasurf(Draw_Interpretor& di,
 Standard_Integer getanacurve(Draw_Interpretor& di,
   Standard_Integer n, const char** a)
 {
+  if (n < 3) {
+    di << "Usage: \n";
+    di << "getanacurve res shape [target [tol]] \n";
+    di << "target is reqired type of curve and can be: lin, cir, ell  \n";
+    return 1;
+  }
   TopoDS_Shape sh = DBRep::Get(a[2]);
   if (sh.IsNull()) return 1;
   TopAbs_ShapeEnum aShType = sh.ShapeType();
@@ -1106,11 +1130,18 @@ Standard_Integer getanacurve(Draw_Interpretor& di,
   GeomAbs_CurveType aTargets[] = { GeomAbs_Line, GeomAbs_Circle, GeomAbs_Ellipse };
   Standard_Integer icurv = 0;
   if (n > 3)
-    icurv = Draw::Atoi(a[3]);
-  icurv = Min(icurv, 2);
-  Standard_Real tol = 1.e-7;
+  {
+    if (strcmp(a[3],"lin") == 0)
+      icurv = 0;
+    else if (strcmp(a[3], "cir") == 0)
+      icurv = 1;
+    else if (strcmp(a[3], "ell") == 0)
+      icurv = 2;
+  }
+
+  Standard_Real tol = Precision::Confusion();
   if (n > 4)
-    tol = Draw::Atof(a[4]);
+      tol = Draw::Atof(a[4]);
 
   ShapeAnalysis_CanonicalRecognition aCanonRec(sh);
   Handle(Geom_Curve) aRes;
@@ -1144,6 +1175,7 @@ Standard_Integer getanacurve(Draw_Interpretor& di,
   if (!aRes.IsNull())
   {
     DrawTrSurf::Set(a[1], aRes);
+    di << "Gap = " << aCanonRec.GetGap() << "\n";
   }
   else
   {
@@ -1194,7 +1226,7 @@ Standard_Integer getanacurve(Draw_Interpretor& di,
   theCommands.Add("getareacontour","wire ",__FILE__, getareacontour, groupold);
   theCommands.Add ("checkselfintersection","wire [face]", __FILE__,checkselfintersection,g);
   theCommands.Add ("checkedge","edge [face]", __FILE__,checkedge,g);
-  theCommands.Add("getanasurf", "getanasurf res shape [target [tol [sample]]]", __FILE__, getanasurf, g);
+  theCommands.Add("getanasurf", "getanasurf res shape [target [tol [sample]]] ", __FILE__, getanasurf, g);
   theCommands.Add("getanacurve", "getanacurve res shape [target [tol]]", __FILE__, getanacurve, g);
 
 
index e98e01ad998a65e98716744ad1112499b5d07171..aa551c28885f069b76f646cde566a580050485bf 100755 (executable)
@@ -47,3 +47,9 @@ ShapeAnalysis_WireVertex.cxx
 ShapeAnalysis_WireVertex.hxx
 ShapeAnalysis_CanonicalRecognition.cxx
 ShapeAnalysis_CanonicalRecognition.hxx
+ShapeAnalysis_FuncSphereLSDist.cxx
+ShapeAnalysis_FuncSphereLSDist.hxx
+ShapeAnalysis_FuncCylinderLSDist.cxx
+ShapeAnalysis_FuncCylinderLSDist.hxx
+ShapeAnalysis_FuncConeLSDist.cxx
+ShapeAnalysis_FuncConeLSDist.hxx
index 49689c071e591df7c800b6f2d2ba6647097312e2..3abf8c12b503aaeeb87e25a3e2bd312199718a41 100644 (file)
 #include <GeomAbs_SurfaceType.hxx>
 #include <GeomAbs_CurveType.hxx>
 #include <NCollection_Vector.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <GeomAdaptor_Surface.hxx>
+#include <BRepLib_FindSurface.hxx>
+#include <TColgp_HArray1OfXYZ.hxx>
+#include <math_Vector.hxx>
+#include <ShapeAnalysis_FuncSphereLSDist.hxx>
+#include <ShapeAnalysis_FuncCylinderLSDist.hxx>
+#include <ShapeAnalysis_FuncConeLSDist.hxx>
+#include <BRepAdaptor_Curve.hxx>
+#include <GCPnts_AbscissaPoint.hxx>
+#include <GCPnts_QuasiUniformAbscissa.hxx>
+#include <math_PSO.hxx>
+#include <math_Powell.hxx>
+#include <ElSLib.hxx>
 
 
 //Declaration of static functions
@@ -64,6 +78,17 @@ static Standard_Boolean CompareSurfParams(const GeomAbs_SurfaceType theTarget, c
 static Standard_Real DeviationSurfParams(const GeomAbs_SurfaceType theTarget,
   const gp_Ax3& theRefPos, const TColStd_Array1OfReal& theRefParams,
   const gp_Ax3& thePos, const TColStd_Array1OfReal& theParams);
+static Standard_Boolean GetSamplePoints(const TopoDS_Wire& theWire, 
+  const Standard_Real theTol, const Standard_Integer theMaxNbInt,
+  Handle(TColgp_HArray1OfXYZ)& thePoints);
+static Standard_Real GetLSGap(const Handle(TColgp_HArray1OfXYZ)& thePoints, const GeomAbs_SurfaceType theTarget,
+  const gp_Ax3& thePos, const TColStd_Array1OfReal& theParams);
+static void FillSolverData(const GeomAbs_SurfaceType theTarget,
+  const gp_Ax3& thePos, const TColStd_Array1OfReal& theParams,
+  math_Vector& theStartPoint,
+  math_Vector& theFBnd, math_Vector& theLBnd, const Standard_Real theRelDev = 0.2);
+static void SetCanonicParameters(const GeomAbs_SurfaceType theTarget, 
+  const math_Vector& theSol, gp_Ax3& thePos, TColStd_Array1OfReal& theParams);
 
 
 //=======================================================================
@@ -201,11 +226,27 @@ Standard_Boolean ShapeAnalysis_CanonicalRecognition::IsPlane(const Standard_Real
   TColStd_Array1OfReal aParams(1, 1);
   //
   GeomAbs_SurfaceType aTarget = GeomAbs_Plane;
-  Standard_Boolean isOK = IsElementarySurf(aTarget, theTol, aPos, aParams);
-  if (!isOK)
-    return isOK;
-  thePln.SetPosition(aPos);
-  return Standard_True;
+  if (IsElementarySurf(aTarget, theTol, aPos, aParams))
+  {
+    thePln.SetPosition(aPos);
+    return Standard_True;
+  }
+  //Try to build plane for wire or edge
+  if (mySType == TopAbs_EDGE || mySType == TopAbs_WIRE)
+  {
+    BRepLib_FindSurface aFndSurf(myShape, theTol, Standard_True, Standard_False);
+    if (aFndSurf.Found())
+    {
+      Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aFndSurf.Surface());
+      thePln = aPlane->Pln();
+      myGap = aFndSurf.ToleranceReached();
+      myStatus = 0;
+      return Standard_True;
+    }
+    else
+      myStatus = 1;
+  }
+  return Standard_False;
 }
 
 //=======================================================================
@@ -220,12 +261,41 @@ Standard_Boolean ShapeAnalysis_CanonicalRecognition::IsCylinder(const Standard_R
   aParams(1) = theCyl.Radius();
   //
   GeomAbs_SurfaceType aTarget = GeomAbs_Cylinder;
-  Standard_Boolean isOK = IsElementarySurf(aTarget, theTol, aPos, aParams);
-  if (!isOK)
-    return isOK;
-  theCyl.SetPosition(aPos);
-  theCyl.SetRadius(aParams(1));
-  return Standard_True;
+  if (IsElementarySurf(aTarget, theTol, aPos, aParams))
+  {
+    theCyl.SetPosition(aPos);
+    theCyl.SetRadius(aParams(1));
+    return Standard_True;
+  }
+
+  if (aParams(1) > Precision::Infinite())
+  {
+    //Sample cylinder does not seem to be set, least square method is not applicable.
+    return Standard_False;
+  }
+  if (myShape.ShapeType() == TopAbs_EDGE || myShape.ShapeType() == TopAbs_WIRE)
+  {
+    //Try to build surface by least square method;
+    TopoDS_Wire aWire;
+    if (myShape.ShapeType() == TopAbs_EDGE)
+    {
+      BRep_Builder aBB;
+      aBB.MakeWire(aWire);
+      aBB.Add(aWire, myShape);
+    }
+    else
+    {
+      aWire = TopoDS::Wire(myShape);
+    }
+    Standard_Boolean isDone = GetSurfaceByLS(aWire, theTol, aTarget, aPos, aParams, myGap, myStatus);
+    if (isDone)
+    {
+      theCyl.SetPosition(aPos);
+      theCyl.SetRadius(aParams(1));
+      return Standard_True;
+    }
+  }
+  return Standard_False;
 }
 
 //=======================================================================
@@ -241,13 +311,44 @@ Standard_Boolean ShapeAnalysis_CanonicalRecognition::IsCone(const Standard_Real
   aParams(2) = theCone.RefRadius();
   //
   GeomAbs_SurfaceType aTarget = GeomAbs_Cone;
-  Standard_Boolean isOK = IsElementarySurf(aTarget, theTol, aPos, aParams);
-  if (!isOK)
-    return isOK;
-  theCone.SetPosition(aPos);
-  theCone.SetSemiAngle(aParams(1));
-  theCone.SetRadius(aParams(2));
-  return Standard_True;
+  if (IsElementarySurf(aTarget, theTol, aPos, aParams))
+  {
+    theCone.SetPosition(aPos);
+    theCone.SetSemiAngle(aParams(1));
+    theCone.SetRadius(aParams(2));
+    return Standard_True;
+  }
+
+
+  if (aParams(2) > Precision::Infinite())
+  {
+    //Sample cone does not seem to be set, least square method is not applicable.
+    return Standard_False;
+  }
+  if (myShape.ShapeType() == TopAbs_EDGE || myShape.ShapeType() == TopAbs_WIRE)
+  {
+    //Try to build surface by least square method;
+    TopoDS_Wire aWire;
+    if (myShape.ShapeType() == TopAbs_EDGE)
+    {
+      BRep_Builder aBB;
+      aBB.MakeWire(aWire);
+      aBB.Add(aWire, myShape);
+    }
+    else
+    {
+      aWire = TopoDS::Wire(myShape);
+    }
+    Standard_Boolean isDone = GetSurfaceByLS(aWire, theTol, aTarget, aPos, aParams, myGap, myStatus);
+    if (isDone)
+    {
+      theCone.SetPosition(aPos);
+      theCone.SetSemiAngle(aParams(1));
+      theCone.SetRadius(aParams(2));
+      return Standard_True;
+    }
+  }
+  return Standard_False;
 }
 
 //=======================================================================
@@ -262,12 +363,41 @@ Standard_Boolean ShapeAnalysis_CanonicalRecognition::IsSphere(const Standard_Rea
   aParams(1) = theSphere.Radius();
   //
   GeomAbs_SurfaceType aTarget = GeomAbs_Sphere;
-  Standard_Boolean isOK = IsElementarySurf(aTarget, theTol, aPos, aParams);
-  if (!isOK)
-    return isOK;
-  theSphere.SetPosition(aPos);
-  theSphere.SetRadius(aParams(1));
-  return Standard_True;
+  if (IsElementarySurf(aTarget, theTol, aPos, aParams))
+  {
+    theSphere.SetPosition(aPos);
+    theSphere.SetRadius(aParams(1));
+    return Standard_True;
+  }
+  //
+  if (aParams(1) > Precision::Infinite())
+  {
+    //Sample sphere does not seem to be set, least square method is not applicable.
+    return Standard_False;
+  }
+  if (myShape.ShapeType() == TopAbs_EDGE || myShape.ShapeType() == TopAbs_WIRE)
+  {
+    //Try to build surface by least square method;
+    TopoDS_Wire aWire;
+    if (myShape.ShapeType() == TopAbs_EDGE)
+    {
+      BRep_Builder aBB;
+      aBB.MakeWire(aWire);
+      aBB.Add(aWire, myShape);
+    }
+    else
+    {
+      aWire = TopoDS::Wire(myShape);
+    }
+    Standard_Boolean isDone = GetSurfaceByLS(aWire, theTol, aTarget, aPos, aParams, myGap, myStatus);
+    if (isDone)
+    {
+      theSphere.SetPosition(aPos);
+      theSphere.SetRadius(aParams(1));
+      return Standard_True;
+    }
+  }
+  return Standard_False;
 }
 
 //=======================================================================
@@ -557,14 +687,21 @@ Handle(Geom_Surface) ShapeAnalysis_CanonicalRecognition::GetSurface(const TopoDS
 
   Standard_Integer ifit = -1, i;
   Standard_Real aMinDev = RealLast();
-  for (i = 0; i < aSurfs.Size(); ++i)
+  if (aSurfs.Size() == 1)
   {
-    SetSurfParams(theTarget, aSurfs(i), aPos, aParams);
-    Standard_Real aDev = DeviationSurfParams(theTarget, thePos, theParams, aPos, aParams);
-    if (aDev < aMinDev)
+    ifit = 0;
+  }
+  else
+  {
+    for (i = 0; i < aSurfs.Size(); ++i)
     {
-      aMinDev = aDev;
-      ifit = i;
+      SetSurfParams(theTarget, aSurfs(i), aPos, aParams);
+      Standard_Real aDev = DeviationSurfParams(theTarget, thePos, theParams, aPos, aParams);
+      if (aDev < aMinDev)
+      {
+        aMinDev = aDev;
+        ifit = i;
+      }
     }
   }
   if (ifit >= 0)
@@ -649,6 +786,130 @@ Handle(Geom_Surface) ShapeAnalysis_CanonicalRecognition::GetSurface(const TopoDS
   theGap = aGap1;
   return anElemSurf1;
 
+}
+//=======================================================================
+//function : GetSurfaceByLS
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean ShapeAnalysis_CanonicalRecognition::GetSurfaceByLS(const TopoDS_Wire& theWire,
+  const Standard_Real theTol,
+  const GeomAbs_SurfaceType theTarget,
+  gp_Ax3& thePos, TColStd_Array1OfReal& theParams,
+  Standard_Real& theGap, Standard_Integer& theStatus)
+{
+  Handle(TColgp_HArray1OfXYZ) aPoints;
+  Standard_Integer aNbMaxInt = 100;
+  if (!GetSamplePoints(theWire, theTol, aNbMaxInt, aPoints))
+    return Standard_False;
+
+  theGap = GetLSGap(aPoints, theTarget, thePos, theParams);
+  if (theGap <= theTol)
+  {
+    theStatus = 0;
+    return Standard_True;
+  }
+
+  Standard_Integer aNbVar = 0;
+  if (theTarget == GeomAbs_Sphere)
+    aNbVar = 4;
+  else if (theTarget == GeomAbs_Cylinder)
+    aNbVar = 4;
+  else if (theTarget == GeomAbs_Cone)
+    aNbVar = 5;
+  else
+    return Standard_False;
+
+  math_Vector aFBnd(1, aNbVar), aLBnd(1, aNbVar), aStartPoint(1, aNbVar);
+
+  Standard_Real aRelDev = 0.2; //Customer can set parameters of sample surface
+                               // with relative precision about aRelDev.
+                               // For example, if radius of sample surface is R,
+                               // it means, that "exact" vaue is in interav 
+                               //[R - aRelDev*R, R + aRelDev*R]. This intrrval is set
+                               // for R as boundary values for dptimization algo.
+  FillSolverData(theTarget, thePos, theParams,
+                 aStartPoint, aFBnd, aLBnd, aRelDev);
+
+  //
+  Standard_Real aTol = Precision::Confusion();
+  math_MultipleVarFunction* aPFunc; 
+  ShapeAnalysis_FuncSphereLSDist aFuncSph(aPoints);
+  ShapeAnalysis_FuncCylinderLSDist aFuncCyl(aPoints, thePos.Direction());
+  ShapeAnalysis_FuncConeLSDist aFuncCon(aPoints, thePos.Direction());
+  if (theTarget == GeomAbs_Sphere)
+  {
+    aPFunc = (math_MultipleVarFunction*)&aFuncSph;
+  }
+  else if (theTarget == GeomAbs_Cylinder)
+  {
+    aPFunc = (math_MultipleVarFunction*)&aFuncCyl;
+  }
+  else if (theTarget == GeomAbs_Cone)
+  {
+    aPFunc = (math_MultipleVarFunction*)&aFuncCon;
+  }
+  else
+    aPFunc = NULL;
+  //
+  math_Vector aSteps(1, aNbVar);
+  Standard_Integer aNbInt = 10;
+  Standard_Integer i;
+  for (i = 1; i <= aNbVar; ++i)
+  {
+    aSteps(i) = (aLBnd(i) - aFBnd(i)) / aNbInt;
+  }
+  math_PSO aGlobSolver(aPFunc, aFBnd, aLBnd, aSteps);
+  Standard_Real aLSDist;
+  aGlobSolver.Perform(aSteps, aLSDist, aStartPoint);
+  SetCanonicParameters(theTarget, aStartPoint, thePos, theParams);
+
+  theGap = GetLSGap(aPoints, theTarget, thePos, theParams);
+  if (theGap <= theTol)
+  {
+    theStatus = 0;
+    return Standard_True;
+  }
+    //
+  math_Matrix aDirMatrix(1, aNbVar, 1, aNbVar, 0.0);
+  for (i = 1; i <= aNbVar; i++)
+    aDirMatrix(i, i) = 1.0;
+
+  if (theTarget == GeomAbs_Cylinder || theTarget == GeomAbs_Cone)
+  {
+    //Set search direction for location to be perpendicular to axis to avoid
+    //seaching along axis
+    const gp_Dir aDir = thePos.Direction();
+    gp_Pln aPln(thePos.Location(), aDir);
+    gp_Dir aUDir = aPln.Position().XDirection();
+    gp_Dir aVDir = aPln.Position().YDirection();
+    for (i = 1; i <= 3; ++i)
+    {
+      aDirMatrix(i, 1) = aUDir.Coord(i);
+      aDirMatrix(i, 2) = aVDir.Coord(i);
+      gp_Dir aUVDir(aUDir.XYZ() + aVDir.XYZ());
+      aDirMatrix(i, 3) = aUVDir.Coord(i);
+    }
+  }
+
+  math_Powell aSolver(*aPFunc, aTol);
+  aSolver.Perform(*aPFunc, aStartPoint, aDirMatrix);
+
+  if (aSolver.IsDone())
+  {
+    aSolver.Location(aStartPoint);
+    theStatus = 0;
+    SetCanonicParameters(theTarget, aStartPoint, thePos, theParams);
+    theGap = GetLSGap(aPoints, theTarget, thePos, theParams);
+    theStatus = 0;
+    if(theGap <= theTol)
+      return Standard_True;
+  }
+  else
+    theStatus = 1;
+
+  return Standard_False;
+
 }
 
 //=======================================================================
@@ -749,37 +1010,32 @@ Standard_Integer GetNbPars(const GeomAbs_SurfaceType theTarget)
 Standard_Boolean SetConicParameters(const GeomAbs_CurveType theTarget, const Handle(Geom_Curve)& theConic,
   gp_Ax2& thePos, TColStd_Array1OfReal& theParams)
 {
+  if (theConic.IsNull())
+    return Standard_False;
+  GeomAdaptor_Curve aGAC(theConic);
+  if(aGAC.GetType() != theTarget)
+    return Standard_False;
+
   if (theTarget == GeomAbs_Line)
   {
-    Handle(Geom_Line) aConic = Handle(Geom_Line)::DownCast(theConic);
-    if (aConic.IsNull())
-      return Standard_False;
-    gp_Lin aLin = aConic->Lin();
+    gp_Lin aLin = aGAC.Line();
     thePos.SetAxis(aLin.Position());
   }
   else if (theTarget == GeomAbs_Circle)
   {
-    Handle(Geom_Circle) aConic = Handle(Geom_Circle)::DownCast(theConic);
-    if (aConic.IsNull())
-      return Standard_False;
-    gp_Circ aCirc = aConic->Circ();
+    gp_Circ aCirc = aGAC.Circle();
     thePos = aCirc.Position();
     theParams(1) = aCirc.Radius();
   }
   else if (theTarget == GeomAbs_Ellipse)
   {
-    Handle(Geom_Ellipse) aConic = Handle(Geom_Ellipse)::DownCast(theConic);
-    if (aConic.IsNull())
-      return Standard_False;
-    gp_Elips anElips = aConic->Elips();
+    gp_Elips anElips = aGAC.Ellipse();
     thePos = anElips.Position();
     theParams(1) = anElips.MajorRadius();
     theParams(2) = anElips.MinorRadius();
   }
   else
-  {
     return Standard_False;
-  }
   return Standard_True;
 
 }
@@ -826,43 +1082,37 @@ Standard_Boolean SetSurfParams(const GeomAbs_SurfaceType theTarget, const Handle
   gp_Ax3& thePos, TColStd_Array1OfReal& theParams)
 {
   //
+  if (theElemSurf.IsNull())
+    return Standard_False;
+  GeomAdaptor_Surface aGAS(theElemSurf);
+  if (aGAS.GetType() != theTarget)
+    return Standard_False;
+
   Standard_Real aNbPars = GetNbPars(theTarget);
   if (theParams.Length() < aNbPars)
     return Standard_False;
 
   if (theTarget == GeomAbs_Plane)
   {
-    Handle(Geom_Plane) aSurf = Handle(Geom_Plane)::DownCast(theElemSurf);
-    if (aSurf.IsNull())
-      return Standard_False;
-    gp_Pln aPln = aSurf->Pln();
+    gp_Pln aPln = aGAS.Plane();
     thePos = aPln.Position();
   }
   else if (theTarget == GeomAbs_Cylinder)
   {
-    Handle(Geom_CylindricalSurface) aSurf = Handle(Geom_CylindricalSurface)::DownCast(theElemSurf);
-    if (aSurf.IsNull())
-      return Standard_False;
-    gp_Cylinder aCyl = aSurf->Cylinder();
+    gp_Cylinder aCyl = aGAS.Cylinder();
     thePos = aCyl.Position();
     theParams(1) = aCyl.Radius();
   }
   else if (theTarget == GeomAbs_Cone)
   {
-    Handle(Geom_ConicalSurface) aSurf = Handle(Geom_ConicalSurface)::DownCast(theElemSurf);
-    if (aSurf.IsNull())
-      return Standard_False;
-    gp_Cone aCon = aSurf->Cone();
+    gp_Cone aCon = aGAS.Cone();
     thePos = aCon.Position();
     theParams(1) = aCon.SemiAngle();
     theParams(2) = aCon.RefRadius();
   }
   else if (theTarget == GeomAbs_Sphere)
   {
-    Handle(Geom_SphericalSurface) aSurf = Handle(Geom_SphericalSurface)::DownCast(theElemSurf);
-    if (aSurf.IsNull())
-      return Standard_False;
-    gp_Sphere aSph = aSurf->Sphere();
+    gp_Sphere aSph = aGAS.Sphere();
     thePos = aSph.Position();
     theParams(1) = aSph.Radius();
   }
@@ -962,3 +1212,204 @@ Standard_Real DeviationSurfParams(const GeomAbs_SurfaceType theTarget,
   return aDevPars;
 }
 
+//=======================================================================
+//function : GetSamplePoints
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean GetSamplePoints(const TopoDS_Wire& theWire, 
+                                 const Standard_Real theTol,
+                                 const Standard_Integer theMaxNbInt,                               
+                                 Handle(TColgp_HArray1OfXYZ)& thePoints)
+{
+  NCollection_Vector<Standard_Real> aLengths;
+  NCollection_Vector<BRepAdaptor_Curve> aCurves;
+  NCollection_Vector<gp_XYZ> aPoints;
+  Standard_Real aTol = Max(1.e-3, theTol/10.);
+  Standard_Real aTotalLength = 0.;
+  TopoDS_Iterator anEIter(theWire);
+  for (; anEIter.More(); anEIter.Next())
+  {
+    const TopoDS_Edge& anE = TopoDS::Edge(anEIter.Value());
+    if (BRep_Tool::Degenerated(anE))
+      continue;
+    BRepAdaptor_Curve aBAC(anE);
+    Standard_Real aClength = GCPnts_AbscissaPoint::Length(aBAC, aTol);
+    aTotalLength += aClength;
+    aCurves.Append(aBAC);
+    aLengths.Append(aClength);
+  }
+
+  if(aTotalLength < theTol)
+    return Standard_False;
+
+  Standard_Integer i, aNb = aLengths.Length();
+  for (i = 0; i < aNb; ++i)
+  {
+    const BRepAdaptor_Curve& aC = aCurves(i);
+    Standard_Real aClength = GCPnts_AbscissaPoint::Length(aC, aTol);
+    Standard_Integer aNbPoints = RealToInt(aClength / aTotalLength * theMaxNbInt + 1);
+    aNbPoints = Max(2, aNbPoints);
+    GCPnts_QuasiUniformAbscissa aPointGen(aC, aNbPoints);
+    if (!aPointGen.IsDone())
+      continue;
+    aNbPoints = aPointGen.NbPoints();
+    Standard_Integer j;
+    for (j = 1; j <= aNbPoints; ++j)
+    {
+      Standard_Real t = aPointGen.Parameter(j);
+      gp_Pnt aP = aC.Value(t);
+      aPoints.Append(aP.XYZ());
+    }
+  }
+
+  if (aPoints.Length() < 1)
+    return Standard_False;
+
+  thePoints = new TColgp_HArray1OfXYZ(1, aPoints.Length());
+  for (i = 0; i < aPoints.Length(); ++i)
+  {
+    thePoints->SetValue(i + 1, aPoints(i));
+  }
+
+  return Standard_True;
+
+}
+
+//=======================================================================
+//function : GetLSGap
+//purpose  : 
+//=======================================================================
+
+static Standard_Real GetLSGap(const Handle(TColgp_HArray1OfXYZ)& thePoints, const GeomAbs_SurfaceType theTarget,
+  const gp_Ax3& thePos, const TColStd_Array1OfReal& theParams)
+{
+
+  Standard_Real aGap = 0.;
+  gp_XYZ aLoc = thePos.Location().XYZ();
+  gp_Vec aDir(thePos.Direction());
+
+
+  Standard_Integer i;
+  if (theTarget == GeomAbs_Sphere)
+  {
+    Standard_Real anR = theParams(1);
+    for (i = thePoints->Lower(); i <= thePoints->Upper(); ++i)
+    {
+      gp_XYZ aD = thePoints->Value(i) - aLoc;
+      aGap = Max(aGap, Abs((aD.Modulus() - anR)));
+    }
+  }
+  else if (theTarget == GeomAbs_Cylinder)
+  {
+    Standard_Real anR = theParams(1);
+    for (i = thePoints->Lower(); i <= thePoints->Upper(); ++i)
+    {
+      gp_Vec aD(thePoints->Value(i) - aLoc);
+      aD.Cross(aDir);
+      aGap = Max(aGap, Abs((aD.Magnitude() - anR)));
+    }
+  }
+  else if (theTarget == GeomAbs_Cone)
+  {  
+    Standard_Real anAng = theParams(1);
+    Standard_Real anR = theParams(2);
+    for (i = thePoints->Lower(); i <= thePoints->Upper(); ++i)
+    {
+      Standard_Real u, v;
+      gp_Pnt aPi(thePoints->Value(i));
+      ElSLib::ConeParameters(thePos, anR, anAng, aPi, u, v);
+      gp_Pnt aPp;
+      ElSLib::ConeD0(u, v, thePos, anR, anAng, aPp);
+      aGap = Max(aGap, aPi.SquareDistance(aPp));
+    }
+    aGap = Sqrt(aGap);
+  }
+
+  return aGap;
+}
+
+//=======================================================================
+//function : FillSolverData
+//purpose  : 
+//=======================================================================
+
+void FillSolverData(const GeomAbs_SurfaceType theTarget, 
+  const gp_Ax3& thePos, const TColStd_Array1OfReal& theParams,
+  math_Vector& theStartPoint,
+  math_Vector& theFBnd, math_Vector& theLBnd, const Standard_Real theRelDev)
+{
+  if (theTarget == GeomAbs_Sphere || theTarget == GeomAbs_Cylinder)
+  {
+    theStartPoint(1) = thePos.Location().X();
+    theStartPoint(2) = thePos.Location().Y();
+    theStartPoint(3) = thePos.Location().Z();
+    theStartPoint(4) = theParams(1);
+    Standard_Real aDR = theRelDev * theParams(1);
+    Standard_Real aDXYZ = aDR;
+    Standard_Integer i;
+    for (i = 1; i <= 3; ++i)
+    {
+      theFBnd(i) = theStartPoint(i) - aDXYZ;
+      theLBnd(i) = theStartPoint(i) + aDXYZ;
+    }
+    theFBnd(4) = theStartPoint(4) - aDR;
+    theLBnd(4) = theStartPoint(4) + aDR;
+  }
+  if (theTarget == GeomAbs_Cone)
+  {
+    theStartPoint(1) = thePos.Location().X();
+    theStartPoint(2) = thePos.Location().Y();
+    theStartPoint(3) = thePos.Location().Z();
+    theStartPoint(4) = theParams(1); //SemiAngle
+    theStartPoint(5) = theParams(2); //Radius
+    Standard_Real aDR = theRelDev * theParams(2);
+    if (aDR < Precision::Confusion())
+    {
+      aDR = 0.1;
+    }
+    Standard_Real aDXYZ = aDR;
+    Standard_Real aDAng = theRelDev * Abs(theParams(1));
+    Standard_Integer i;
+    for (i = 1; i <= 3; ++i)
+    {
+      theFBnd(i) = theStartPoint(i) - aDXYZ;
+      theLBnd(i) = theStartPoint(i) + aDXYZ;
+    }
+    if (theParams(1) >= 0.)
+    {
+      theFBnd(4) = theStartPoint(4) - aDAng;
+      theLBnd(4) = Min(M_PI_2, theStartPoint(4) + aDR);
+    }
+    else
+    {
+      theFBnd(4) = Max(-M_PI_2, theStartPoint(4) - aDAng);
+      theLBnd(4) = theStartPoint(4) + aDAng;
+    }
+    theFBnd(5) = theStartPoint(5) - aDR;
+    theLBnd(5) = theStartPoint(5) + aDR;
+  }
+
+}
+
+//=======================================================================
+//function : SetCanonicParameters
+//purpose  : 
+//=======================================================================
+
+void SetCanonicParameters(const GeomAbs_SurfaceType theTarget,
+  const math_Vector& theSol, gp_Ax3& thePos, TColStd_Array1OfReal& theParams)
+{
+  gp_Pnt aLoc(theSol(1), theSol(2), theSol(3));
+  thePos.SetLocation(aLoc);
+  if (theTarget == GeomAbs_Sphere || theTarget == GeomAbs_Cylinder)
+  {
+    theParams(1) = theSol(4);//radius
+  }
+  else if (theTarget == GeomAbs_Cone)
+  {
+    theParams(1) = theSol(4);//semiangle
+    theParams(2) = theSol(5);//radius
+  }
+
+}
\ No newline at end of file
index 7a9906f456a96cab133c695e6db9a13ad3bb9d2d..7fa079b82c446e7feb66e1f776a4a0589af1d3b9 100644 (file)
@@ -150,6 +150,11 @@ private:
     const GeomConvert_ConvType theType, const GeomAbs_CurveType theTarget,
     Standard_Real& theGap, Standard_Integer& theStatus);
 
+  static Standard_Boolean GetSurfaceByLS(const TopoDS_Wire& theWire, const Standard_Real theTol,
+    const GeomAbs_SurfaceType theTarget,
+    gp_Ax3& thePos, TColStd_Array1OfReal& theParams,
+    Standard_Real& theGap, Standard_Integer& theStatus);
+
   void Init(const TopoDS_Shape& theShape);
 
 private:
diff --git a/src/ShapeAnalysis/ShapeAnalysis_FuncConeLSDist.cxx b/src/ShapeAnalysis/ShapeAnalysis_FuncConeLSDist.cxx
new file mode 100644 (file)
index 0000000..865d9e8
--- /dev/null
@@ -0,0 +1,68 @@
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2022 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <ShapeAnalysis_FuncConeLSDist.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Vec.hxx>
+#include <gp_Ax3.hxx>
+#include <math_Vector.hxx>
+#include <ElSLib.hxx>
+
+//=======================================================================
+//function : ShapeAnalysis_FuncConeLSDist
+//purpose  : 
+//=======================================================================
+ShapeAnalysis_FuncConeLSDist::ShapeAnalysis_FuncConeLSDist(
+                                  const Handle(TColgp_HArray1OfXYZ)& thePoints,
+                                  const gp_Dir& theDir):
+  myPoints(thePoints), myDir(theDir)
+{
+}
+
+//=======================================================================
+//function : NbVariables
+//purpose  : 
+//=======================================================================
+Standard_Integer ShapeAnalysis_FuncConeLSDist::NbVariables () const
+{
+  return 5;
+}
+
+//=======================================================================
+//function : Value
+//purpose  : 
+//=======================================================================
+Standard_Boolean ShapeAnalysis_FuncConeLSDist::Value(const math_Vector& X, Standard_Real& F)
+{
+  gp_Pnt aLoc(X(1), X(2), X(3));
+  Standard_Real aSemiAngle = X(4), anR = X(5);
+  gp_Ax3 aPos(aLoc, myDir);
+
+  F = 0.;
+  Standard_Integer i;
+  for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
+  {
+    Standard_Real u, v;
+    gp_Pnt aPi(myPoints->Value(i));
+    ElSLib::ConeParameters(aPos, anR, aSemiAngle, aPi, u, v);
+    gp_Pnt aPp;
+    ElSLib::ConeD0(u, v, aPos, anR, aSemiAngle, aPp);
+    F += aPi.SquareDistance(aPp);
+  }
+
+  return Standard_True;
+}
+
+
diff --git a/src/ShapeAnalysis/ShapeAnalysis_FuncConeLSDist.hxx b/src/ShapeAnalysis/ShapeAnalysis_FuncConeLSDist.hxx
new file mode 100644 (file)
index 0000000..381b86c
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright (c) 1991-1999 Matra Datavision
+// Copyright (c) 1999-2022 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _ShapeAnalysis_FuncConeLSDist_HeaderFile
+#define _ShapeAnalysis_FuncConeLSDist_HeaderFile
+
+#include <Standard.hxx>
+#include <Standard_DefineAlloc.hxx>
+
+#include <math_MultipleVarFunction.hxx>
+#include <TColgp_HArray1OfXYZ.hxx>
+#include <math_Vector.hxx>
+#include <gp_Dir.hxx>
+
+//! Function for search of Cone canonic parameters: coordinates of center local coordinate system, 
+//! direction of axis, radius and semi-angle from set of points
+//! by least square method.
+//! 
+//!
+class ShapeAnalysis_FuncConeLSDist : public math_MultipleVarFunction
+{
+public:
+
+  DEFINE_STANDARD_ALLOC
+
+  //! Constructor.
+  Standard_EXPORT ShapeAnalysis_FuncConeLSDist() {};
+  
+  Standard_EXPORT ShapeAnalysis_FuncConeLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints,
+                                                   const gp_Dir& theDir);
+
+  void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints)
+  {
+    myPoints = thePoints;
+  }
+
+  void SetDir(const gp_Dir& theDir)
+  {
+    myDir = theDir;
+  }
+
+  //! Number of variables.
+  Standard_EXPORT Standard_Integer NbVariables() const Standard_OVERRIDE;
+
+  //! Value.
+  Standard_EXPORT Standard_Boolean Value(const math_Vector& X,Standard_Real& F) Standard_OVERRIDE;
+
+
+private:
+
+  Handle(TColgp_HArray1OfXYZ) myPoints;
+  gp_Dir myDir;
+  
+};
+#endif // _ShapeAnalysis_FuncConeLSDist_HeaderFile
diff --git a/src/ShapeAnalysis/ShapeAnalysis_FuncCylinderLSDist.cxx b/src/ShapeAnalysis/ShapeAnalysis_FuncCylinderLSDist.cxx
new file mode 100644 (file)
index 0000000..681bef1
--- /dev/null
@@ -0,0 +1,140 @@
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2022 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <ShapeAnalysis_FuncCylinderLSDist.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Vec.hxx>
+#include <math_Vector.hxx>
+
+//=======================================================================
+//function : ShapeAnalysis_FuncCylinderLSDist
+//purpose  : 
+//=======================================================================
+ShapeAnalysis_FuncCylinderLSDist::ShapeAnalysis_FuncCylinderLSDist(
+                                  const Handle(TColgp_HArray1OfXYZ)& thePoints,
+                                  const gp_Dir& theDir):
+  myPoints(thePoints), myDir(theDir)
+{
+}
+
+//=======================================================================
+//function : NbVariables
+//purpose  : 
+//=======================================================================
+Standard_Integer ShapeAnalysis_FuncCylinderLSDist::NbVariables () const
+{
+  return 4;
+}
+
+//=======================================================================
+//function : Value
+//purpose  : 
+//=======================================================================
+Standard_Boolean ShapeAnalysis_FuncCylinderLSDist::Value(const math_Vector& X,Standard_Real& F)
+{
+  gp_XYZ aLoc(X(1), X(2), X(3));
+  Standard_Real anR2 = X(4)*X(4);
+
+  F = 0.;
+  Standard_Integer i;
+  for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
+  {
+    gp_Vec aV(myPoints->Value(i) - aLoc);
+    Standard_Real aD2 = aV.CrossSquareMagnitude(myDir);
+    Standard_Real d = aD2 - anR2;
+    F += d * d;
+  }
+
+  return Standard_True;
+}
+
+//=======================================================================
+//function : Gradient
+//purpose  : 
+//=======================================================================
+Standard_Boolean ShapeAnalysis_FuncCylinderLSDist::Gradient(const math_Vector& X,math_Vector& G)
+
+{
+  gp_XYZ aLoc(X(1), X(2), X(3));
+  Standard_Real anR = X(4), anR2 = anR * anR;
+  Standard_Real x = myDir.X(), y = myDir.Y(), z = myDir.Z();
+  G.Init(0.);
+
+  Standard_Integer i;
+  for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
+  {
+    gp_Vec aV(myPoints->Value(i) - aLoc);
+    Standard_Real aD2 = aV.CrossSquareMagnitude(myDir);
+    Standard_Real d = aD2 - anR2;
+    Standard_Real Dx0 =  2.*(aV.Z()*x - aV.X()*z)*z
+                        -2.*(aV.X()*y - aV.Y()*x)*y;
+    Standard_Real Dy0 = -2.*(aV.Y()*z - aV.Z()*y)*z
+                        +2.*(aV.X()*y - aV.Y()*x)*x;
+    Standard_Real Dz0 =  2.*(aV.Y()*z - aV.Z()*y)*y
+                        -2.*(aV.Z()*x - aV.X()*z)*x;
+
+    G(1) += d * Dx0;
+    G(2) += d * Dy0;
+    G(3) += d * Dz0;
+    //
+    G(4) += d;
+  }
+
+  G *= 2;
+  G(6) *= -2.*anR;
+
+  return Standard_True;
+}
+
+//=======================================================================
+//function : Values
+//purpose  : 
+//=======================================================================
+Standard_Boolean ShapeAnalysis_FuncCylinderLSDist::Values(const math_Vector& X,Standard_Real& F,math_Vector& G)
+{
+  gp_XYZ aLoc(X(1), X(2), X(3));
+  Standard_Real anR = X(4), anR2 = anR * anR;
+  Standard_Real x = myDir.X(), y = myDir.Y(), z = myDir.Z();
+
+  F = 0.;
+  G.Init(0.);
+  Standard_Integer i;
+  for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
+  {
+    gp_Vec aV(myPoints->Value(i) - aLoc);
+    Standard_Real aD2 = aV.CrossSquareMagnitude(myDir);
+    Standard_Real d = aD2 - anR2;
+    Standard_Real Dx0 = 2.*(aV.Z()*x - aV.X()*z)*z
+      - 2.*(aV.X()*y - aV.Y()*x)*y;
+    Standard_Real Dy0 = -2.*(aV.Y()*z - aV.Z()*y)*z
+      + 2.*(aV.X()*y - aV.Y()*x)*x;
+    Standard_Real Dz0 = 2.*(aV.Y()*z - aV.Z()*y)*y
+      - 2.*(aV.Z()*x - aV.X()*z)*x;
+
+    G(1) += d * Dx0;
+    G(2) += d * Dy0;
+    G(3) += d * Dz0;
+    //
+    G(4) += d;
+    //
+    F += d * d;
+  }
+
+  G *= 2;
+  G(4) *= -2.*anR;
+
+  return true;
+}
+
diff --git a/src/ShapeAnalysis/ShapeAnalysis_FuncCylinderLSDist.hxx b/src/ShapeAnalysis/ShapeAnalysis_FuncCylinderLSDist.hxx
new file mode 100644 (file)
index 0000000..3375e52
--- /dev/null
@@ -0,0 +1,100 @@
+// Copyright (c) 1991-1999 Matra Datavision
+// Copyright (c) 1999-2022 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _ShapeAnalysis_FuncCylinderLSDist_HeaderFile
+#define _ShapeAnalysis_FuncCylinderLSDist_HeaderFile
+
+#include <Standard.hxx>
+#include <Standard_DefineAlloc.hxx>
+
+#include <math_MultipleVarFunctionWithGradient.hxx>
+#include <TColgp_HArray1OfXYZ.hxx>
+#include <math_Vector.hxx>
+#include <gp_Dir.hxx>
+
+//! Function for search of cylinder canonic parameters: coordinates of center local coordinate system, 
+//! direction of axis and radius from set of points
+//! by least square method.
+//! 
+//! The class inherits math_MultipleVarFunctionWithGradient and thus is intended
+//! for use in math_BFGS algorithm.
+//!
+//! Parametrisation:
+//! Cylinder is defined by its axis and radius. Axis is defined by 3 cartesian coordinats it location x0, y0, z0 
+//! and direction, which is constant and set by user: 
+//! dir.x, dir.y, dir.z
+//! The criteria is:
+//! F(x0, y0, z0, theta, phi, R) = Sum[|(P(i) - Loc)^dir|^2 - R^2]^2 => min
+//! P(i) is i-th sample point, Loc, dir - axis location and direction, R - radius
+//!
+//! The square vector product |(P(i) - Loc)^dir|^2 is:
+//!
+//! [(y - y0)*dir.z - (z - z0)*dir.y]^2 +
+//! [(z - z0)*dir.x - (x - x0)*dir.z]^2 +
+//! [(x - x0)*dir.y - (y - y0)*dir.x]^2
+//!
+//! First derivative of square vector product are:
+//! Dx0 =  2*[(z - z0)*dir.x - (x - x0)*dir.z]*dir.z 
+//!       -2*[(x - x0)*dir.y - (y - y0)*dir.x]*dir.y
+//! Dy0 = -2*[(y - y0)*dir.z - (z - z0)*dir.y]*dir.z
+//!       +2*[(x - x0)*dir.y - (y - y0)*dir.x]*dir.x
+//! Dz0 =  2*[(y - y0)*dir.z - (z - z0)*dir.y]*dir.y
+//!       -2*[(z - z0)*dir.x - (x - x0)*dir.z]*dir.x
+//!
+//! dF/dx0 : G1(...) = 2*Sum{[...]*Dx0}
+//! dF/dy0 : G2(...) = 2*Sum{[...]*Dy0}
+//! dF/dz0 : G3(...) = 2*Sum{[...]*Dz0}
+//! dF/dR : G4(...) = -4*R*Sum[...]
+//! [...] = [|(P(i) - Loc)^dir|^2 - R^2]
+class ShapeAnalysis_FuncCylinderLSDist : public math_MultipleVarFunctionWithGradient
+{
+public:
+
+  DEFINE_STANDARD_ALLOC
+
+  //! Constructor.
+  Standard_EXPORT ShapeAnalysis_FuncCylinderLSDist() {};
+  
+  Standard_EXPORT ShapeAnalysis_FuncCylinderLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints,
+                                                   const gp_Dir& theDir);
+
+  void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints)
+  {
+    myPoints = thePoints;
+  }
+
+  void SetDir(const gp_Dir& theDir)
+  {
+    myDir = theDir;
+  }
+
+  //! Number of variables.
+  Standard_EXPORT Standard_Integer NbVariables() const Standard_OVERRIDE;
+
+  //! Value.
+  Standard_EXPORT Standard_Boolean Value(const math_Vector& X,Standard_Real& F) Standard_OVERRIDE;
+
+  //! Gradient.
+  Standard_EXPORT Standard_Boolean Gradient(const math_Vector& X,math_Vector& G) Standard_OVERRIDE;
+
+  //! Value and gradient.
+  Standard_EXPORT Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G) Standard_OVERRIDE;
+
+private:
+
+  Handle(TColgp_HArray1OfXYZ) myPoints;
+  gp_Dir myDir;
+  
+};
+#endif // _ShapeAnalysis_FuncCylinderLSDist_HeaderFile
diff --git a/src/ShapeAnalysis/ShapeAnalysis_FuncSphereLSDist.cxx b/src/ShapeAnalysis/ShapeAnalysis_FuncSphereLSDist.cxx
new file mode 100644 (file)
index 0000000..7bf64af
--- /dev/null
@@ -0,0 +1,115 @@
+// Created on: 2016-05-10
+// Created by: Alexander MALYSHEV
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2016 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <ShapeAnalysis_FuncSphereLSDist.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Vec.hxx>
+#include <math_Vector.hxx>
+
+//=======================================================================
+//function : ShapeAnalysis_FuncSphereLSDist
+//purpose  : 
+//=======================================================================
+ShapeAnalysis_FuncSphereLSDist::ShapeAnalysis_FuncSphereLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints):
+  myPoints(thePoints)
+{
+}
+
+//=======================================================================
+//function : NbVariables
+//purpose  : 
+//=======================================================================
+Standard_Integer ShapeAnalysis_FuncSphereLSDist::NbVariables () const
+{
+  return 4;
+}
+
+//=======================================================================
+//function : Value
+//purpose  : 
+//=======================================================================
+Standard_Boolean ShapeAnalysis_FuncSphereLSDist::Value(const math_Vector& X,Standard_Real& F)
+{
+  gp_XYZ aLoc(X(1), X(2), X(3));
+  Standard_Real anR2 = X(4)*X(4);
+
+  F = 0.;
+  Standard_Integer i;
+  for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
+  {
+    Standard_Real d = (myPoints->Value(i) - aLoc).SquareModulus() - anR2;
+    F += d * d;
+  }
+
+  return Standard_True;
+}
+
+//=======================================================================
+//function : Gradient
+//purpose  : 
+//=======================================================================
+Standard_Boolean ShapeAnalysis_FuncSphereLSDist::Gradient(const math_Vector& X,math_Vector& G)
+
+{
+  gp_XYZ aLoc(X(1), X(2), X(3));
+  Standard_Real anR = X(4), anR2 = anR * anR;
+
+  G.Init(0.);
+  Standard_Integer i;
+  for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
+  {
+    gp_XYZ dLoc = myPoints->Value(i) - aLoc;
+    Standard_Real d = dLoc.SquareModulus() - anR2;
+    G(1) += d * dLoc.X();
+    G(2) += d * dLoc.Y();
+    G(3) += d * dLoc.Z();
+    G(4) += d;
+  }
+  G *= -4;
+  G(4) *= anR;
+
+  return Standard_True;
+}
+
+//=======================================================================
+//function : Values
+//purpose  : 
+//=======================================================================
+Standard_Boolean ShapeAnalysis_FuncSphereLSDist::Values(const math_Vector& X,Standard_Real& F,math_Vector& G)
+{
+  gp_XYZ aLoc(X(1), X(2), X(3));
+  Standard_Real anR = X(4), anR2 = anR * anR;
+
+  G.Init(0.);
+  F = 0.;
+  Standard_Integer i;
+  for (i = myPoints->Lower(); i <= myPoints->Upper(); ++i)
+  {
+    gp_XYZ dLoc = myPoints->Value(i) - aLoc;
+    Standard_Real d = dLoc.SquareModulus() - anR2;
+    G(1) += d * dLoc.X();
+    G(2) += d * dLoc.Y();
+    G(3) += d * dLoc.Z();
+    G(4) += d;
+    F += d * d;
+  }
+  G *= -4;
+  G(4) *= anR;
+
+  return true;
+}
+
diff --git a/src/ShapeAnalysis/ShapeAnalysis_FuncSphereLSDist.hxx b/src/ShapeAnalysis/ShapeAnalysis_FuncSphereLSDist.hxx
new file mode 100644 (file)
index 0000000..fae0ffa
--- /dev/null
@@ -0,0 +1,77 @@
+
+// Copyright (c) 1991-1999 Matra Datavision
+// Copyright (c) 1999-2022 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _ShapeAnalysis_FuncSphereLSDist_HeaderFile
+#define _ShapeAnalysis_FuncSphereLSDist_HeaderFile
+
+#include <Standard.hxx>
+#include <Standard_DefineAlloc.hxx>
+
+#include <math_MultipleVarFunctionWithGradient.hxx>
+#include <TColgp_HArray1OfXYZ.hxx>
+#include <math_Vector.hxx>
+
+//! Function for search of sphere canonic parameters: coordinates of center and radius from set of moints
+//! by least square method.
+//! //!
+//! The class inherits math_MultipleVarFunctionWithGradient and thus is intended
+//! for use in math_BFGS algorithm.
+//!
+//! The criteria is:
+//! F(x0, y0, z0, R) = Sum[(x(i) - x0)^2 + (y(i) - y0)^2 + (z(i) - z0)^2 - R^2]^2 => min,
+//! x(i), y(i), z(i) - coordinates of sample points, x0, y0, z0, R - coordinates of center and radius of sphere,
+//! which must be defined
+//!
+//! The first derivative are:
+//! dF/dx0 : G1(x0, y0, z0, R) = -4*Sum{[...]*(x(i) - x0)} 
+//! dF/dy0 : G2(x0, y0, z0, R) = -4*Sum{[...]*(y(i) - y0)}
+//! dF/dz0 : G3(x0, y0, z0, R) = -4*Sum{[...]*(z(i) - z0)}
+//! dF/dR : G4(x0, y0, z0, R) = -4*R*Sum[...]
+//! [...] = [(x(i) - x0)^2 + (y(i) - y0)^2 + (z(i) - z0)^2 - R^2]
+//!
+class ShapeAnalysis_FuncSphereLSDist : public math_MultipleVarFunctionWithGradient
+{
+public:
+
+  DEFINE_STANDARD_ALLOC
+
+  //! Constructor.
+  Standard_EXPORT ShapeAnalysis_FuncSphereLSDist() {};
+  
+  Standard_EXPORT ShapeAnalysis_FuncSphereLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints);
+
+  void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints)
+  {
+    myPoints = thePoints;
+  }
+
+  //! Number of variables.
+  Standard_EXPORT Standard_Integer NbVariables() const Standard_OVERRIDE;
+
+  //! Value.
+  Standard_EXPORT Standard_Boolean Value(const math_Vector& X,Standard_Real& F) Standard_OVERRIDE;
+
+  //! Gradient.
+  Standard_EXPORT Standard_Boolean Gradient(const math_Vector& X,math_Vector& G) Standard_OVERRIDE;
+
+  //! Value and gradient.
+  Standard_EXPORT Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G) Standard_OVERRIDE;
+
+private:
+
+  Handle(TColgp_HArray1OfXYZ) myPoints;
+  
+};
+#endif // _ShapeAnalysis_FuncSphereLSDist_HeaderFile
index 99e32446b72109aa97e17b6d924fd0cacf446ab0..f4794eff8ea2a7505a8bd036fd3bc1fcc1a43c1f 100644 (file)
@@ -54,7 +54,7 @@ gce_MakeCirc::gce_MakeCirc(const gp_Pnt&  P1 ,
 //=========================================================================
   Standard_Real dist1, dist2, dist3, aResolution;
   //
-  aResolution=gp::Resolution();
+  aResolution = gp::Resolution();
   //
   dist1 = P1.Distance(P2);
   dist2 = P1.Distance(P3);
@@ -77,7 +77,7 @@ gce_MakeCirc::gce_MakeCirc(const gp_Pnt&  P1 ,
   P2.Coord(x2,y2,z2);
   P3.Coord(x3,y3,z3);
   gp_Dir Dir1(x2-x1,y2-y1,z2-z1);
-  gp_Dir Dir2(x3-x2,y3-y2,z3-z2);
+  gp_Vec VDir2(x3-x2,y3-y2,z3-z2);
   //
   gp_Ax1 anAx1(P1, Dir1);
   gp_Lin aL12 (anAx1);
@@ -86,14 +86,21 @@ gce_MakeCirc::gce_MakeCirc(const gp_Pnt&  P1 ,
     return;
   }
   //
-  gp_Dir Dir3 = Dir1.Crossed(Dir2);
+  gp_Vec VDir1(Dir1);
+  gp_Vec VDir3 = VDir1.Crossed(VDir2);
+  if(VDir3.SquareMagnitude() < aResolution)
+  {
+    TheError = gce_ColinearPoints;
+    return;
+  }
   //
+  gp_Dir Dir3(VDir3);
   gp_Dir dir = Dir1.Crossed(Dir3);
   gp_Lin L1(gp_Pnt((P1.XYZ()+P2.XYZ())/2.),dir);
-  dir = Dir2.Crossed(Dir3);
+  dir = VDir2.Crossed(Dir3);
   gp_Lin L2(gp_Pnt((P3.XYZ()+P2.XYZ())/2.),dir);
 
-  Standard_Real Tol = 0.000000001;
+  Standard_Real Tol = Precision::PConfusion();
   Extrema_ExtElC distmin(L1,L2,Tol);
   
   if (!distmin.IsDone()) { 
@@ -140,7 +147,7 @@ gce_MakeCirc::gce_MakeCirc(const gp_Pnt&  P1 ,
       //Dir2 = gp_Dir(x2-x3,y2-y3,z2-z3);
       //modified by NIZNHY-PKV Thu Mar  3 11:31:13 2005t
       //
-      TheCirc = gp_Circ(gp_Ax2(pInt, Dir3, Dir1),(dist1+dist2+dist3)/3.);
+      TheCirc = gp_Circ(gp_Ax2(pInt, gp_Dir(VDir3), Dir1),(dist1+dist2+dist3)/3.);
       TheError = gce_Done;
     }
   }
diff --git a/tests/cr/approx/A1 b/tests/cr/approx/A1
new file mode 100644 (file)
index 0000000..f449daf
--- /dev/null
@@ -0,0 +1,12 @@
+polyline w 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0
+getanasurf res w pln  1.e-3
+if {[isdraw res]} {
+  set log [dump res]
+  if { [regexp {Plane} $log ] != 1 } {
+     puts "Error: surface is not a plane"
+  }
+} else {
+  puts "Error: required surface is not got"
+}
+
+
diff --git a/tests/cr/approx/A2 b/tests/cr/approx/A2
new file mode 100644 (file)
index 0000000..5ac2f8f
--- /dev/null
@@ -0,0 +1,15 @@
+cylinder cyl 0 0 0 1 1 1 1
+mkface f cyl 0 2 0 1
+explode f w
+nurbsconvert w f_1
+cylinder cyl 0.1 0.1 0.1 1 1 1 .9
+getanasurf res w cyl 1.e-3 cyl
+if {[isdraw res]} {
+  set log [dump res]
+  if { [regexp {CylindricalSurface} $log ] != 1 } {
+     puts "Error: surface is not a cylindrical surface"
+  }
+} else {
+  puts "Error: required surface is not got"
+}
+
diff --git a/tests/cr/approx/A3 b/tests/cr/approx/A3
new file mode 100644 (file)
index 0000000..f59b3c6
--- /dev/null
@@ -0,0 +1,15 @@
+plane pl 0 0 0 1 1 1
+pcone con pl 2 1 3 60
+explode con w
+nurbsconvert w con_1
+cone con 0.1 .1 .1 1 1 1 -17 1.9
+getanasurf res w con 1.e-3 con
+if {[isdraw res]} {
+  set log [dump res]
+  if { [regexp {ConicalSurface} $log ] != 1 } {
+     puts "Error: surface is not a conical surface"
+  }
+} else {
+  puts "Error: required surface is not got"
+}
+
diff --git a/tests/cr/approx/A4 b/tests/cr/approx/A4
new file mode 100644 (file)
index 0000000..d1c3384
--- /dev/null
@@ -0,0 +1,16 @@
+sphere sph 1
+mkface f sph 0 2 0 pi/2
+explode f w
+nurbsconvert w f_1
+sphere sph 0.1 0.1 0.1 1
+getanasurf res w sph 1.e-3 sph
+if {[isdraw res]} {
+  set log [dump res]
+  if { [regexp {SphericalSurface} $log ] != 1 } {
+     puts "Error: surface is not a spherical surface"
+  }
+} else {
+  puts "Error: required surface is not got"
+}
+
+
index 409bc58e503475366dab71b2bc866720835a1e15..4de2c8d7bb6ae4e90c586bab9f05b0a768125631 100644 (file)
@@ -1,6 +1,6 @@
 beziercurve bz 3 0 0 0 .5 .5e-3 0 1 0 0
 mkedge e bz
-getanacurve c e 0  1.e-3
+getanacurve c e lin  1.e-3
 if {[isdraw c]} {
   set log [dump c]
   if { [regexp {Line} $log ] != 1 } {
index f1e19524c8e8d714b42fc5810881aab208b9b381..5f66a23ee48c0381b6a44b7dc8221f6f8bfe0d70 100644 (file)
@@ -1,6 +1,6 @@
 beziercurve bz 3 0 0 0 .5 .5e-3 0 1 0 0
 mkedge e bz
-getanacurve c e 1 1.e-3
+getanacurve c e cir 1.e-3
 if {[isdraw c]} {
   set log [dump c]
   if { [regexp {Circle} $log ] != 1 } {
index 3a3af119dcb71838c58983b10123fe98affd6a11..97d6e1ec5d6039fdedb718f3584249735fa9a2b7 100644 (file)
@@ -1,7 +1,7 @@
 ellipse bz 0 0 0 0 0 1 1 .5
 convert bz bz
 mkedge e bz
-getanacurve c e 2 1.e-7
+getanacurve c e ell 1.e-7
 if {[isdraw c]} {
   set log [dump c]
   if { [regexp {Ellipse} $log ] != 1 } {
index b193d05ef18856208c2dbeb724e1447e6a4e406c..76c26f34b4638be4804ce7ea6e163e02ff12541a 100644 (file)
@@ -3,7 +3,7 @@ mkedge e1 bz 0 .3
 mkedge e2 bz .3 0.7
 mkedge e3 bz .7 1.
 wire w e1 e2 e3
-getanacurve c w 0 1.e-3
+getanacurve c w lin 1.e-3
 if {[isdraw c]} {
   set log [dump c]
   if { [regexp {Line} $log ] != 1 } {
index 4d3ccdce8be8ee8efac73145acb4a6139a54d85f..7323a6221abc90ff79c8da6b32a2d998c8d38a23 100644 (file)
@@ -4,7 +4,7 @@ mkedge e1 bz 0 1
 mkedge e2 bz 1 2.5
 mkedge e3 bz 2.5 6
 wire w e1 e2 e3
-getanacurve c w 1 1.e-7
+getanacurve c w cir 1.e-7
 if {[isdraw c]} {
   set log [dump c]
   if { [regexp {Circle} $log ] != 1 } {
index 2799654e37de8b0f67ad8e3dda2cc059b04720f2..dabfd08c3e14f5bd9ee1a481d2d9f247910ff750 100644 (file)
@@ -4,7 +4,7 @@ mkedge e1 bz 0 1
 mkedge e2 bz 1 2.5
 mkedge e3 bz 2.5 6
 wire w e1 e2 e3
-getanacurve c w 2 1.e-7
+getanacurve c w ell 1.e-7
 if {[isdraw c]} {
   set log [dump c]
   if { [regexp {Ellipse} $log ] != 1 } {
index 2bd53e9e4042044de46095a28f73c8cc2cb4cb3c..87498c880928ef95bcd41cd37a88a5129eb90029 100644 (file)
@@ -2,7 +2,7 @@ plane surf
 trim surf surf -1 1 -1 1
 convert surf surf
 mkface f surf
-getanasurf asurf f 0  1.e-7
+getanasurf asurf f pln  1.e-7
 if {[isdraw asurf]} {
   set log [dump asurf]
   if { [regexp {Plane} $log ] != 1 } {
index e63fb099a70c42c426285f4ca8f0cd8da9658e24..312e25ab4b63f8e25a968f37bf50d4bf16be7d4d 100644 (file)
@@ -2,7 +2,7 @@ cylinder surf 1
 trimv surf surf -1 1 
 convert surf surf
 mkface f surf
-getanasurf asurf f 1  1.e-7
+getanasurf asurf f cyl  1.e-7
 if {[isdraw asurf]} {
   set log [dump asurf]
   if { [regexp {CylindricalSurface} $log ] != 1 } {
index a53779e51df0153c7dae592c9079fda782b4925c..ce1e30b4b1bac4554cc5d61a0306bcfce4e8085b 100644 (file)
@@ -2,7 +2,7 @@ cone surf 30 0
 trimv surf surf -1 0
 convert surf surf
 mkface f surf
-getanasurf asurf f 2  1.e-7
+getanasurf asurf f con  1.e-7
 if {[isdraw asurf]} {
   set log [dump asurf]
   if { [regexp {ConicalSurface} $log ] != 1 } {
index 3028fc9ecdf999a685019b0b418f1e2a9ce5bc26..7259721402286f694a02e7fafe7a60ff7830d5e0 100644 (file)
@@ -1,7 +1,7 @@
 sphere surf 1
 convert surf surf
 mkface f surf
-getanasurf asurf f 3  1.e-7
+getanasurf asurf f sph  1.e-7
 if {[isdraw asurf]} {
   set log [dump asurf]
   if { [regexp {SphericalSurface} $log ] != 1 } {
index 1f8f5be3bfe5a21eaf2f677a58f49fb81b8f94c7..58c4d5b223d86de5750803964099c3a7b7f9eedf 100644 (file)
@@ -12,7 +12,7 @@ trim surf4 surf 0 1 -1 0
 convert surf4 surf4
 mkface f4 surf4
 sewing sh f1 f2 f3 f4
-getanasurf asurf sh 0  1.e-7
+getanasurf asurf sh pln  1.e-7
 if {[isdraw asurf]} {
   set log [dump asurf]
   if { [regexp {Plane} $log ] != 1 } {
index b2b80bfa25c2d2b453cbb50ae397784bb3701fb4..db670f3a5dcd3a5b591b5d2b9261597e58450267 100644 (file)
@@ -12,7 +12,7 @@ trim surf4 surf 3 6 -1 0
 convert surf4 surf4
 mkface f4 surf4
 sewing sh f1 f2 f3 f4
-getanasurf asurf sh  1  1.e-7
+getanasurf asurf sh  cyl  1.e-7
 if {[isdraw asurf]} {
   set log [dump asurf]
   if { [regexp {CylindricalSurface} $log ] != 1 } {
index 29766bab8027d7a8c564a6016bdcdc9a21c08314..2c2d5f2fc41a4aee1604c7e30172623bad4cadf7 100644 (file)
@@ -12,7 +12,7 @@ trim surf4 surf 3 6 0 1
 convert surf4 surf4
 mkface f4 surf4
 sewing sh f1 f2 f3 f4
-getanasurf asurf sh  2  1.e-7
+getanasurf asurf sh con  1.e-7
 if {[isdraw asurf]} {
   set log [dump asurf]
   if { [regexp {ConicalSurface} $log ] != 1 } {
index 7bf2927aa4fd1ef06e6caafd26f9c2140ba38728..64e69c99594c60437cd26d2ab43eca3a628dbc5e 100644 (file)
@@ -12,7 +12,7 @@ trim surf4 surf 3 6 -1.5 0
 convert surf4 surf4
 mkface f4 surf4
 sewing sh f1 f2 f3 f4
-getanasurf asurf sh  3  1.e-7
+getanasurf asurf sh sph 1.e-7
 if {[isdraw asurf]} {
   set log [dump asurf]
   if { [regexp {SphericalSurface} $log ] != 1 } {
index d4e72cce505c4df349b9081791039a19d2a1f801..195c30074a1ea85b453ad6ffe1953744d9ea50ca 100644 (file)
@@ -24,7 +24,7 @@ add ss_2 w
 add ss_3 w
 add ss_4 w
 add ss_5 w
-getanasurf asurf w  1.e-7 cyl
+getanasurf asurf w cyl 1.e-7 cyl
 if {[isdraw asurf]} {
   set log [dump asurf]
   if { [regexp {CylindricalSurface} $log ] != 1 } {
index b2bf4e12dd1efc71da7396fd8b5e4d90af482573..8eb5c913e5ce19822c3a38ccc37e24bccc5486a7 100644 (file)
@@ -1 +1,2 @@
 001 base
+002 approx