1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0032940: Canonical Recognition: Some surfaces are not recognized as cylindrical surfaces

New method for recognizing cylindrical surfaces based on analysis Gaussian field of initial surface is added  in
class GeomConvert_SurfToAnaSurf
This commit is contained in:
ifv
2022-07-11 11:09:33 +03:00
committed by smoskvin
parent 411ad1a819
commit b315a85dd7
12 changed files with 598 additions and 207 deletions

View File

@@ -46,9 +46,3 @@ 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

View File

@@ -51,9 +51,9 @@
#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 <GeomConvert_FuncSphereLSDist.hxx>
#include <GeomConvert_FuncCylinderLSDist.hxx>
#include <GeomConvert_FuncConeLSDist.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <GCPnts_AbscissaPoint.hxx>
#include <GCPnts_QuasiUniformAbscissa.hxx>
@@ -834,9 +834,9 @@ Standard_Boolean ShapeAnalysis_CanonicalRecognition::GetSurfaceByLS(const TopoDS
//
Standard_Real aTol = Precision::Confusion();
math_MultipleVarFunction* aPFunc;
ShapeAnalysis_FuncSphereLSDist aFuncSph(aPoints);
ShapeAnalysis_FuncCylinderLSDist aFuncCyl(aPoints, thePos.Direction());
ShapeAnalysis_FuncConeLSDist aFuncCon(aPoints, thePos.Direction());
GeomConvert_FuncSphereLSDist aFuncSph(aPoints);
GeomConvert_FuncCylinderLSDist aFuncCyl(aPoints, thePos.Direction());
GeomConvert_FuncConeLSDist aFuncCon(aPoints, thePos.Direction());
if (theTarget == GeomAbs_Sphere)
{
aPFunc = (math_MultipleVarFunction*)&aFuncSph;

View File

@@ -1,68 +0,0 @@
// 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;
}

View File

@@ -1,66 +0,0 @@
// 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

View File

@@ -1,140 +0,0 @@
// 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;
}

View File

@@ -1,100 +0,0 @@
// 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

View File

@@ -1,115 +0,0 @@
// 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;
}

View File

@@ -1,77 +0,0 @@
// 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