Salome HOME
[bos #23982] EDF 22984 - aspect ratio of hexa
[modules/smesh.git] / src / DriverMED / DriverMED_W_SMESHDS_Mesh.cxx
index 63c69c992ee921e3a18351a076439b76abd0d968..326409fff66298171f642ee58c6ccfa9d1be30f7 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -34,6 +34,7 @@
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_SetIterator.hxx"
 #include "SMESHDS_Mesh.hxx"
+#include "MED_Common.hxx"
 
 #include <med.h>
 
@@ -62,7 +63,8 @@ DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
   myAutoDimension(false),
   myAddODOnVertices(false),
   myDoAllInGroups(false),
-  myVersion(-1)
+  myVersion(-1),
+  myZTolerance(-1.)
 {}
 
 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theVersion)
@@ -110,7 +112,7 @@ void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
   myAllSubMeshes = true;
 }
 
-void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
+void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int /*theID*/)
 {
   mySubMeshes.push_back( theSubMesh );
 }
@@ -377,7 +379,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
       if ( myAutoDimension && aMeshDimension < 3 )
       {
         SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
-        double aBounds[6];
+        double aBounds[6] = {0.,0.,0.,0.,0.,0.};
         if(aNodesIter->more()){
           const SMDS_MeshNode* aNode = aNodesIter->next();
           aBounds[0] = aBounds[1] = aNode->X();
@@ -417,6 +419,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
         anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
         anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
         anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
+        if ( myZTolerance > 0 && anIsZDimension )
+          anIsZDimension = (aBounds[5] > myZTolerance || aBounds[4] < -myZTolerance );
         aSpaceDimension = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
         if ( !aSpaceDimension )
           aSpaceDimension = 3;
@@ -550,6 +554,10 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
       for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
         aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
       }
+      if ( aSpaceDimension == 3 &&
+           -myZTolerance < aTCoordSlice[2] && aTCoordSlice[2] < myZTolerance )
+        aTCoordSlice[2] = 0.;
+
       // node number
       int aNodeID = aCoordHelperPtr->GetID();
       aNodeInfo->SetElemNum( iNode, aNodeID );