]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Add the normal field and the affine point into the output med file
authorEl Hadi Moussi <moussi@phimeca.com>
Mon, 5 Aug 2024 17:04:00 +0000 (19:04 +0200)
committerEl Hadi Moussi <moussi@phimeca.com>
Mon, 5 Aug 2024 17:04:00 +0000 (19:04 +0200)
src/ShapeRecogn/ShapeRecognMesh.cxx
src/ShapeRecogn/ShapeRecognMesh.hxx
src/ShapeRecogn/Swig/ShapeRecognMesh.i

index 8dc73c44dfc6b8723b1f7cc8f590f8d1cb2fc659..27572d9eda8fa49f676fd8a18e79db3370ed50cd 100644 (file)
@@ -27,6 +27,56 @@ const Nodes *ShapeRecognMesh::getNodes() const
     return nodes;
 }
 
+MEDCouplingFieldDouble *ShapeRecognMesh::buildAffinePointField() const
+{
+    const std::vector<mcIdType> &areaIdByNodes = areas->getAreaIdByNodes();
+    MEDCouplingFieldDouble *field = MEDCouplingFieldDouble::New(
+        ON_NODES);
+    field->setName("area_affine_point");
+    field->setMesh(mesh);
+    DataArrayDouble *values = DataArrayDouble::New();
+    values->setName("area_affine_point");
+    values->alloc(nodes->getNbNodes(), 3);
+    values->setInfoOnComponent(0, "X");
+    values->setInfoOnComponent(1, "Y");
+    values->setInfoOnComponent(2, "Z");
+    for (mcIdType nodeId = 0; nodeId < (mcIdType)areaIdByNodes.size(); ++nodeId)
+    {
+        std::array<double, 3> affinePoint = areas->getAffinePoint(areaIdByNodes[nodeId]);
+        values->setIJ(nodeId, 0, affinePoint[0]);
+        values->setIJ(nodeId, 1, affinePoint[1]);
+        values->setIJ(nodeId, 2, affinePoint[2]);
+    }
+    field->setArray(values);
+    values->decrRef();
+    return field;
+}
+
+MEDCouplingFieldDouble *ShapeRecognMesh::buildNormalField() const
+{
+    const std::vector<mcIdType> &areaIdByNodes = areas->getAreaIdByNodes();
+    MEDCouplingFieldDouble *field = MEDCouplingFieldDouble::New(
+        ON_NODES);
+    field->setName("area_normal");
+    field->setMesh(mesh);
+    DataArrayDouble *values = DataArrayDouble::New();
+    values->setName("area_normal");
+    values->alloc(nodes->getNbNodes(), 3);
+    values->setInfoOnComponent(0, "X");
+    values->setInfoOnComponent(1, "Y");
+    values->setInfoOnComponent(2, "Z");
+    for (mcIdType nodeId = 0; nodeId < (mcIdType)areaIdByNodes.size(); ++nodeId)
+    {
+        std::array<double, 3> normal = areas->getNormal(areaIdByNodes[nodeId]);
+        values->setIJ(nodeId, 0, normal[0]);
+        values->setIJ(nodeId, 1, normal[1]);
+        values->setIJ(nodeId, 2, normal[2]);
+    }
+    field->setArray(values);
+    values->decrRef();
+    return field;
+}
+
 const Areas *ShapeRecognMesh::getAreas() const
 {
     return areas;
@@ -114,7 +164,7 @@ void ShapeRecognMesh::recognize(const std::string &outputFile)
     DataArrayDouble *areaIds = DataArrayDouble::New();
     areaIds->setName("area_ids");
     areaIds->alloc(nodes->getNbNodes(), 1);
-    for (mcIdType nodeId = 0; nodeId < areaIdByNodes.size(); ++nodeId)
+    for (mcIdType nodeId = 0; nodeId < (mcIdType)areaIdByNodes.size(); ++nodeId)
         areaIds->setIJ(nodeId, 0, (double)areaIdByNodes[nodeId]);
     fieldAreaIds->setArray(areaIds);
     areaIds->decrRef();
@@ -128,10 +178,18 @@ void ShapeRecognMesh::recognize(const std::string &outputFile)
     DataArrayDouble *areaPrimitiveTypes = DataArrayDouble::New();
     areaPrimitiveTypes->setName("area_primitive_types");
     areaPrimitiveTypes->alloc(nodes->getNbNodes(), 1);
-    for (mcIdType nodeId = 0; nodeId < areaIdByNodes.size(); ++nodeId)
+    for (mcIdType nodeId = 0; nodeId < (mcIdType)areaIdByNodes.size(); ++nodeId)
         areaPrimitiveTypes->setIJ(nodeId, 0, (double)areas->getPrimitiveTypeInt(areaIdByNodes[nodeId]));
     fieldAreaPrimitiveTypes->setArray(areaPrimitiveTypes);
     areaPrimitiveTypes->decrRef();
     WriteField(outputFile, fieldAreaPrimitiveTypes, false);
     fieldAreaPrimitiveTypes->decrRef();
+    // - normal
+    auto fieldNormal = buildNormalField();
+    WriteField(outputFile, fieldNormal, false);
+    fieldNormal->decrRef();
+    // - affine point
+    auto fieldAffinePoint = buildAffinePointField();
+    WriteField(outputFile, fieldAffinePoint, false);
+    fieldAffinePoint->decrRef();
 }
index d4532e75251f96e68a7944da0a7d68fe2217cc27..2d4fcfa90ed1d69b43eae4cad1f3346813528a38 100644 (file)
@@ -37,6 +37,8 @@ namespace MEDCoupling
 
         const Areas *getAreas() const;
         const Nodes *getNodes() const;
+        MEDCouplingFieldDouble *buildAffinePointField() const;
+        MEDCouplingFieldDouble *buildNormalField() const;
 
         void recognize();
         void recognize(const std::string &outputFile);
index 7522ff83cab6e42ea66e6e58d071913b146308c9..699b3264be5db74432d2de68d959a912829e2a36 100644 (file)
@@ -9,5 +9,7 @@
 
 %ignore getAreas() const; 
 %ignore getNodes() const; 
+%ignore buildNormalField() const; 
+%ignore buildAffinePointField() const; 
 %ignore recognize(); 
 %include "ShapeRecognMesh.hxx"