From: El Hadi Moussi Date: Mon, 5 Aug 2024 17:04:00 +0000 (+0200) Subject: Add the normal field and the affine point into the output med file X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8bd204646b6a5d373d74539a9d692d206c63e4a7;p=tools%2Fmedcoupling.git Add the normal field and the affine point into the output med file --- diff --git a/src/ShapeRecogn/ShapeRecognMesh.cxx b/src/ShapeRecogn/ShapeRecognMesh.cxx index 8dc73c44d..27572d9ed 100644 --- a/src/ShapeRecogn/ShapeRecognMesh.cxx +++ b/src/ShapeRecogn/ShapeRecognMesh.cxx @@ -27,6 +27,56 @@ const Nodes *ShapeRecognMesh::getNodes() const return nodes; } +MEDCouplingFieldDouble *ShapeRecognMesh::buildAffinePointField() const +{ + const std::vector &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 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 &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 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(); } diff --git a/src/ShapeRecogn/ShapeRecognMesh.hxx b/src/ShapeRecogn/ShapeRecognMesh.hxx index d4532e752..2d4fcfa90 100644 --- a/src/ShapeRecogn/ShapeRecognMesh.hxx +++ b/src/ShapeRecogn/ShapeRecognMesh.hxx @@ -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); diff --git a/src/ShapeRecogn/Swig/ShapeRecognMesh.i b/src/ShapeRecogn/Swig/ShapeRecognMesh.i index 7522ff83c..699b3264b 100644 --- a/src/ShapeRecogn/Swig/ShapeRecognMesh.i +++ b/src/ShapeRecogn/Swig/ShapeRecognMesh.i @@ -9,5 +9,7 @@ %ignore getAreas() const; %ignore getNodes() const; +%ignore buildNormalField() const; +%ignore buildAffinePointField() const; %ignore recognize(); %include "ShapeRecognMesh.hxx"