[bos #35094] [EDF] (2023-T1) X,Y,Z to U,V. Consider face tolerance.

This commit is contained in:
jfa 2023-06-26 17:56:13 +01:00
parent 9473f01eac
commit e8fc8b6907
3 changed files with 35 additions and 26 deletions

View File

@ -3032,8 +3032,8 @@ Handle(TColStd_HArray1OfReal) GEOMImpl_IMeasureOperations::XYZtoUV
} }
// Face tolerance // Face tolerance
Standard_Real squareTolerance = BRep_Tool::Tolerance(F); Standard_Real aTol = BRep_Tool::Tolerance(F);
squareTolerance = squareTolerance * squareTolerance; Standard_Real squareTolerance = aTol * aTol;
// Compute parameters // Compute parameters
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F); Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
@ -3049,19 +3049,25 @@ Handle(TColStd_HArray1OfReal) GEOMImpl_IMeasureOperations::XYZtoUV
gp_Pnt aP (theXYZlist->Value(iCLower + iP * 3), gp_Pnt aP (theXYZlist->Value(iCLower + iP * 3),
theXYZlist->Value(iCLower + iP * 3 + 1), theXYZlist->Value(iCLower + iP * 3 + 1),
theXYZlist->Value(iCLower + iP * 3 + 2)); theXYZlist->Value(iCLower + iP * 3 + 2));
Standard_Real U, V; try { // as GEOMUtils::ProjectPointOnFace can throw exceptions
gp_Pnt aPonF = GEOMUtils::ProjectPointOnFace(aP, F, U, V); Standard_Real U, V;
if (aP.SquareDistance(aPonF) < squareTolerance) { gp_Pnt aPonF = GEOMUtils::ProjectPointOnFace(aP, F, U, V, aTol);
if (isNormalized) { if (aP.SquareDistance(aPonF) < squareTolerance) {
// Normalize parameters to be in [0, 1] if (isNormalized) {
U = (U - U1) / dU; // Normalize parameters to be in [0, 1]
V = (V - V1) / dV; U = (U - U1) / dU;
V = (V - V1) / dV;
}
aRet->SetValue(iP * 2 , U);
aRet->SetValue(iP * 2 + 1, V);
}
else {
SetErrorCode("Point too far from face");
return aRet;
} }
aRet->SetValue(iP * 2 , U);
aRet->SetValue(iP * 2 + 1, V);
} }
else { catch (Standard_Failure& aFail) {
SetErrorCode("Point too far from face"); SetErrorCode(aFail.GetMessageString());
return aRet; return aRet;
} }
} }

View File

@ -1032,7 +1032,8 @@ Standard_Real GEOMUtils::GetMinDistance
//======================================================================= //=======================================================================
gp_Pnt GEOMUtils::ProjectPointOnFace(const gp_Pnt& thePoint, gp_Pnt GEOMUtils::ProjectPointOnFace(const gp_Pnt& thePoint,
const TopoDS_Shape& theFace, const TopoDS_Shape& theFace,
double& theU, double& theV) double& theU, double& theV,
const double theTol)
{ {
if (theFace.IsNull() || theFace.ShapeType() != TopAbs_FACE) if (theFace.IsNull() || theFace.ShapeType() != TopAbs_FACE)
Standard_TypeMismatch::Raise Standard_TypeMismatch::Raise
@ -1044,7 +1045,7 @@ gp_Pnt GEOMUtils::ProjectPointOnFace(const gp_Pnt& thePoint,
BRepTools::UVBounds(aFace, U1, U2, V1, V2); BRepTools::UVBounds(aFace, U1, U2, V1, V2);
// projector // projector
Standard_Real tol = 1.e-4; Standard_Real tol = Max(theTol, 1.e-4);
GeomAPI_ProjectPointOnSurf proj; GeomAPI_ProjectPointOnSurf proj;
proj.Init(surface, U1, U2, V1, V2, tol); proj.Init(surface, U1, U2, V1, V2, tol);
proj.Perform(thePoint); proj.Perform(thePoint);

View File

@ -74,13 +74,13 @@ namespace GEOMUtils
* \brief Compute numerical functor for the shape. * \brief Compute numerical functor for the shape.
* *
* Resulting value can be used to sort out shapes according to some parameter. * Resulting value can be used to sort out shapes according to some parameter.
* *
* Returns a pair of two values (dist, functor) where * Returns a pair of two values (dist, functor) where
* - \a dist is a some value that is computed according to the center of mass of given shape; * - \a dist is a some value that is computed according to the center of mass of given shape;
* - \a functor is a numerical functor value * - \a functor is a numerical functor value
* *
* The numerical functor is computed according to the shape's topological properties as follows: * The numerical functor is computed according to the shape's topological properties as follows:
* - orientation for vertices * - orientation for vertices
* - length for edges and wires * - length for edges and wires
* - area for faces and shells * - area for faces and shells
* - volume for solids, compounds, compsolids * - volume for solids, compounds, compsolids
@ -161,7 +161,7 @@ namespace GEOMUtils
* \retval bool Returns false if the shape has no faces, i.e. impossible to build triangulation. * \retval bool Returns false if the shape has no faces, i.e. impossible to build triangulation.
*/ */
Standard_EXPORT bool CheckTriangulation (const TopoDS_Shape& theShape); Standard_EXPORT bool CheckTriangulation (const TopoDS_Shape& theShape);
/*! /*!
* \brief Return type of shape for explode. In case of compound it will be a type of its first sub shape. * \brief Return type of shape for explode. In case of compound it will be a type of its first sub shape.
* \param theShape The shape to get type of. * \param theShape The shape to get type of.
@ -201,7 +201,7 @@ namespace GEOMUtils
Standard_EXPORT Standard_Real GetMinDistanceSingular(const TopoDS_Shape& aSh1, Standard_EXPORT Standard_Real GetMinDistanceSingular(const TopoDS_Shape& aSh1,
const TopoDS_Shape& aSh2, const TopoDS_Shape& aSh2,
gp_Pnt& Ptmp1, gp_Pnt& Ptmp2); gp_Pnt& Ptmp1, gp_Pnt& Ptmp2);
/*! /*!
* \brief Computes minumal distance between two shapes. * \brief Computes minumal distance between two shapes.
* *
@ -214,7 +214,7 @@ namespace GEOMUtils
Standard_EXPORT Standard_Real GetMinDistance(const TopoDS_Shape& theShape1, Standard_EXPORT Standard_Real GetMinDistance(const TopoDS_Shape& theShape1,
const TopoDS_Shape& theShape2, const TopoDS_Shape& theShape2,
gp_Pnt& thePnt1, gp_Pnt& thePnt2); gp_Pnt& thePnt1, gp_Pnt& thePnt2);
/*! /*!
* \brief Computes normal projection of \a thePoint to \a theFace. * \brief Computes normal projection of \a thePoint to \a theFace.
* *
@ -222,12 +222,14 @@ namespace GEOMUtils
* \param theFace the face shape * \param theFace the face shape
* \param theU the output U parameter of the point on the face * \param theU the output U parameter of the point on the face
* \param theV the output V parameter of the point on the face * \param theV the output V parameter of the point on the face
* \param theTol the tolerance value. Maximum of theTol and 1e-04 will be used for calculation.
* \retval the projection (3d point) if found, throws an exception otherwise * \retval the projection (3d point) if found, throws an exception otherwise
*/ */
Standard_EXPORT gp_Pnt ProjectPointOnFace(const gp_Pnt& thePoint, Standard_EXPORT gp_Pnt ProjectPointOnFace(const gp_Pnt& thePoint,
const TopoDS_Shape& theFace, const TopoDS_Shape& theFace,
double& theU, double& theV); double& theU, double& theV,
const double theTol = 1e-04);
/*! /*!
* \brief Returns the point clicked in 3D view. * \brief Returns the point clicked in 3D view.
* *
@ -274,7 +276,7 @@ namespace GEOMUtils
* operation or \c false otherwise * operation or \c false otherwise
*/ */
Standard_EXPORT bool CheckBOPArguments(const TopoDS_Shape &theShape); Standard_EXPORT bool CheckBOPArguments(const TopoDS_Shape &theShape);
/*! /*!
* \brief Limit shape tolerance to the given value * \brief Limit shape tolerance to the given value
* *
@ -312,13 +314,13 @@ namespace GEOMUtils
/*! /*!
* \brief Fix curves of the given shape * \brief Fix curves of the given shape
* *
* The function checks each curve of the input shape in the following way: * The function checks each curve of the input shape in the following way:
* - compute deviation of the curve from the underlying surface in a set of points * - compute deviation of the curve from the underlying surface in a set of points
* computed with the certain discretization step value * computed with the certain discretization step value
* - find maximum tolerance between computed deviation values * - find maximum tolerance between computed deviation values
* - limit tolerance of the curve with the computed maximum value * - limit tolerance of the curve with the computed maximum value
* *
* \param shape shape being fixed * \param shape shape being fixed
* \return \c true if resulting shape is valid * \return \c true if resulting shape is valid
*/ */
@ -332,7 +334,7 @@ namespace GEOMUtils
*/ */
Standard_EXPORT bool Write( const TopoDS_Shape& shape, Standard_EXPORT bool Write( const TopoDS_Shape& shape,
const char* fileName ); const char* fileName );
/*! /*!
* \brief Extract single SOLID from COMPSOLID or COMPOUND. * \brief Extract single SOLID from COMPSOLID or COMPOUND.
* *