From: El Hadi Moussi Date: Wed, 7 Aug 2024 09:36:27 +0000 (+0200) Subject: Simplification of the constants X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=53888ff6ae825c90664d35b748f9c767aa47467d;p=tools%2Fmedcoupling.git Simplification of the constants --- diff --git a/src/ShapeRecogn/AreasBuilder.cxx b/src/ShapeRecogn/AreasBuilder.cxx index ef5d6ea20..fee223961 100644 --- a/src/ShapeRecogn/AreasBuilder.cxx +++ b/src/ShapeRecogn/AreasBuilder.cxx @@ -269,7 +269,7 @@ bool AreasBuilder::doesItMatch(mcIdType areaId, mcIdType nodeId) const break; case PrimitiveType::Cylinder: isMatching = fabs(areas->getAdimKdiff0(areaId) - - nodes->getAdimKdiff0(nodeId)) < EPSILON_PROP; + nodes->getAdimKdiff0(nodeId)) < TOL_MATCH_CYLINDER; break; case PrimitiveType::Cone: case PrimitiveType::Unknown: @@ -301,7 +301,8 @@ bool AreasBuilder::doesItBelong(mcIdType areaId, mcIdType nodeId) const double distanceToCenter = distanceToSphere( nodes->getCoordinates(nodeId), areas->getCenter(areaId)); - isClose = fabs(distanceToCenter - areas->getRadius(areaId)) < DELTA_SPHERE; + double radius = areas->getRadius(areaId); + isClose = fabs((distanceToCenter - radius) / radius) < DELTA_SPHERE; } break; case PrimitiveType::Cylinder: @@ -316,12 +317,14 @@ bool AreasBuilder::doesItBelong(mcIdType areaId, mcIdType nodeId) const break; case PrimitiveType::Cone: { + double radius = areas->getRadius(areaId); isClose = distanceToCone( nodes->getCoordinates(nodeId), areas->getAxis(areaId), areas->getApex(areaId), - areas->getAngle(areaId), - areas->getRadius(areaId)) < DELTA_CONE; + areas->getAngle(areaId)) / + fabs(radius) < + DELTA_CONE; } break; case PrimitiveType::Torus: @@ -391,8 +394,7 @@ double AreasBuilder::distanceToCone( const std::array &nodeCoords, const std::array &axis, const std::array &apex, - double angle, - double radius) + double angle) { std::array ps{ apex[0] - nodeCoords[0], @@ -407,5 +409,5 @@ double AreasBuilder::distanceToCone( double a = MathOps::computeNorm( MathOps::cross(ps, v)); double b = MathOps::dot(ps, v); - return fabs(a * cos(angle) - b * sin(angle)) / fabs(radius); + return fabs(a * cos(angle) - b * sin(angle)); } diff --git a/src/ShapeRecogn/AreasBuilder.hxx b/src/ShapeRecogn/AreasBuilder.hxx index eb97c5714..470a6baa2 100644 --- a/src/ShapeRecogn/AreasBuilder.hxx +++ b/src/ShapeRecogn/AreasBuilder.hxx @@ -61,8 +61,7 @@ namespace MEDCoupling const std::array &nodeCoords, const std::array &axis, const std::array &apex, - double angle, - double radius); + double angle); const Nodes *nodes; Areas *areas; diff --git a/src/ShapeRecogn/NodeCurvatureCalculator.cxx b/src/ShapeRecogn/NodeCurvatureCalculator.cxx index 6a2f6528a..1b40ea8d2 100644 --- a/src/ShapeRecogn/NodeCurvatureCalculator.cxx +++ b/src/ShapeRecogn/NodeCurvatureCalculator.cxx @@ -161,13 +161,13 @@ void NodeCurvatureCalculator::computeCurvatures(mcIdType nodeId, double tol) PrimitiveType NodeCurvatureCalculator::findPrimitiveType(double k1, double k2, double kdiff0, double kis0) const { - if ((fabs(k1 - k2) < EPSILON_SC) && (fabs((k1 + k2) / 2) < EPSILON_PL)) + if ((fabs(k1 - k2) < EPSILON_PRIMITIVE) && (fabs((k1 + k2) / 2) < EPSILON_PRIMITIVE)) return PrimitiveType::Plane; - else if ((fabs(k1 - k2) < EPSILON_SC) && (fabs((k1 + k2) / 2) > EPSILON_PL)) + else if ((fabs(k1 - k2) < EPSILON_PRIMITIVE) && (fabs((k1 + k2) / 2) > EPSILON_PRIMITIVE)) return PrimitiveType::Sphere; - else if ((fabs(kdiff0) > EPSILON_CY) && (fabs(kis0) < EPSILON_CY)) + else if ((fabs(kdiff0) > EPSILON_PRIMITIVE) && (fabs(kis0) < EPSILON_PRIMITIVE)) return PrimitiveType::Cylinder; - else if ((fabs(k1) > EPSILON_CY) && (fabs(k2) > EPSILON_CY)) + else if ((fabs(k1) > EPSILON_PRIMITIVE) && (fabs(k2) > EPSILON_PRIMITIVE)) return PrimitiveType::Torus; else return PrimitiveType::Unknown; diff --git a/src/ShapeRecogn/ShapeRecongConstants.hxx b/src/ShapeRecogn/ShapeRecongConstants.hxx index 2c36f19fb..d2a4628eb 100644 --- a/src/ShapeRecogn/ShapeRecongConstants.hxx +++ b/src/ShapeRecogn/ShapeRecongConstants.hxx @@ -23,17 +23,19 @@ namespace MEDCoupling { // Nodes - constexpr double EPSILON_SC = 0.005; // For |k1 - k2| - constexpr double EPSILON_PL = 0.001; // For |k1 + k2| / 2 = 1 / R - constexpr double EPSILON_CY = 0.005; // For k1 or k2 + constexpr double EPSILON_PRIMITIVE = 0.05; // Areas - constexpr double EPSILON_PROP = 0.05; - constexpr double DELTA_PLANE = 0.01; - constexpr double DELTA_SPHERE = 0.1; - constexpr double DELTA_CYLINDER = 0.02; + // - Match + constexpr double TOL_MATCH_CYLINDER = 0.05; + constexpr double TOL_MATCH_SPHERE = 0.05; + // - Relative distance + constexpr double DELTA_PLANE = 0.05; + constexpr double DELTA_SPHERE = 0.05; + constexpr double DELTA_CYLINDER = 0.05; constexpr double DELTA_CONE = 0.05; + // - Invalid Zones constexpr double THETA_MAX_CYLINDER = 0.05; - constexpr double TOL_MATCH_SPHERE = 0.1; + // - Thresholds constexpr int THRESHOLD_MIN_NB_NODES = 5; constexpr int THRESHOLD_MAX_NB_AREAS = 500; };