From 239363f61c66c77120826c2385ca8bdf269d84af Mon Sep 17 00:00:00 2001 From: El Hadi Moussi Date: Wed, 7 Aug 2024 09:52:34 +0200 Subject: [PATCH] Add a method to compute the average distance with the neighbors of a node --- src/ShapeRecogn/NodeCurvatureCalculator.cxx | 16 ++++++++++++++++ src/ShapeRecogn/NodeCurvatureCalculator.hxx | 1 + 2 files changed, 17 insertions(+) diff --git a/src/ShapeRecogn/NodeCurvatureCalculator.cxx b/src/ShapeRecogn/NodeCurvatureCalculator.cxx index ae4238629..7b796aa54 100644 --- a/src/ShapeRecogn/NodeCurvatureCalculator.cxx +++ b/src/ShapeRecogn/NodeCurvatureCalculator.cxx @@ -219,6 +219,22 @@ void NodeCurvatureCalculator::computeCellNormal( cellNormal[2] = a[0] * b[1] - a[1] * b[0]; } +double NodeCurvatureCalculator::computeAverageDistance(mcIdType nodeId, const std::vector &neighborIds) const +{ + double distance = 0.0; + std::array + nodeCoords = nodes->getCoordinates(nodeId); + for (size_t i = 0; i < neighborIds.size(); ++i) + { + std::array neighborCoords = nodes->getCoordinates(neighborIds[i]); + double distanceToNeighbor = 0.0; + for (size_t j = 0; j < 3; ++j) + distanceToNeighbor += pow(neighborCoords[j] - nodeCoords[j], 2); + distance += sqrt(distanceToNeighbor); + } + return distance / (double)neighborIds.size(); +} + std::vector NodeCurvatureCalculator::computeDiscreteCurvatures( mcIdType nodeId, const std::vector &neighborIds) const diff --git a/src/ShapeRecogn/NodeCurvatureCalculator.hxx b/src/ShapeRecogn/NodeCurvatureCalculator.hxx index 8b3a58515..ab15e2f87 100644 --- a/src/ShapeRecogn/NodeCurvatureCalculator.hxx +++ b/src/ShapeRecogn/NodeCurvatureCalculator.hxx @@ -48,6 +48,7 @@ namespace MEDCoupling const std::array &normal, const std::array &e1) const; void computeCellNormal(const std::vector &nodeIds, std::array &cellNormal) const; + double computeAverageDistance(mcIdType nodeId, const std::vector &neighborIds) const; std::vector computeDiscreteCurvatures(mcIdType nodeId, const std::vector &neighborIds) const; double computeDiscreteCurvature(mcIdType nodeId, mcIdType neighborId) const; std::vector computeTangentDirections(mcIdType nodeId, const std::vector &neighborIds) const; -- 2.39.2