]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Add a method to compute the average distance with the neighbors of a node
authorEl Hadi Moussi <moussi@phimeca.com>
Wed, 7 Aug 2024 07:52:34 +0000 (09:52 +0200)
committerEl Hadi Moussi <moussi@phimeca.com>
Wed, 7 Aug 2024 07:52:34 +0000 (09:52 +0200)
src/ShapeRecogn/NodeCurvatureCalculator.cxx
src/ShapeRecogn/NodeCurvatureCalculator.hxx

index ae42386298d88cc367893f3df906fb3cc77233db..7b796aa541224c0462fc221f209e46a89a3273b1 100644 (file)
@@ -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<mcIdType> &neighborIds) const
+{
+    double distance = 0.0;
+    std::array<double, 3>
+        nodeCoords = nodes->getCoordinates(nodeId);
+    for (size_t i = 0; i < neighborIds.size(); ++i)
+    {
+        std::array<double, 3> 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<double> NodeCurvatureCalculator::computeDiscreteCurvatures(
     mcIdType nodeId,
     const std::vector<mcIdType> &neighborIds) const
index 8b3a58515d02ae5f0409aa6b6b85d95765476cb9..ab15e2f877d2f4d0e733a5abf2e7e9495c3fc34e 100644 (file)
@@ -48,6 +48,7 @@ namespace MEDCoupling
             const std::array<double, 3> &normal,
             const std::array<double, 3> &e1) const;
         void computeCellNormal(const std::vector<mcIdType> &nodeIds, std::array<double, 3> &cellNormal) const;
+        double computeAverageDistance(mcIdType nodeId, const std::vector<mcIdType> &neighborIds) const;
         std::vector<double> computeDiscreteCurvatures(mcIdType nodeId, const std::vector<mcIdType> &neighborIds) const;
         double computeDiscreteCurvature(mcIdType nodeId, mcIdType neighborId) const;
         std::vector<double> computeTangentDirections(mcIdType nodeId, const std::vector<mcIdType> &neighborIds) const;