From: eap Date: Wed, 17 Nov 2021 14:45:29 +0000 (+0300) Subject: bos #26452 [EDF] (2021) SMESH: orientation of faces X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cc635c4bde0c5d500001ad00b46db48a9c8da010;p=tools%2Fmedcoupling.git bos #26452 [EDF] (2021) SMESH: orientation of faces Add examples and fix the function --- diff --git a/doc/developer/doxygen/doxfiles/examples/medcouplingexamplesmeshes.doxy b/doc/developer/doxygen/doxfiles/examples/medcouplingexamplesmeshes.doxy index ffa1d4112..491e4f01d 100644 --- a/doc/developer/doxygen/doxfiles/examples/medcouplingexamplesmeshes.doxy +++ b/doc/developer/doxygen/doxfiles/examples/medcouplingexamplesmeshes.doxy @@ -171,7 +171,10 @@ finds one reversed face. After that we fix the incorrectly oriented cell using \ref MEDCoupling::MEDCouplingUMesh::orientCorrectly2DCells "orientCorrectly2DCells()" and re-check the orientation of cells. \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2 - +Alternatively you can orient all 2D cells equally using the first cell as a reference: +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_3 +Also it is possible to orient some selected 2D cells by using another group of cells as the reference: +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_4 \subsubsection cpp_mcumesh_renumberNodesInConn Renumbering nodes in the connectivity array diff --git a/doc/developer/doxygen/fakesources/MEDCouplingUMesh.C b/doc/developer/doxygen/fakesources/MEDCouplingUMesh.C index b9e0ac718..6a4fa25d9 100644 --- a/doc/developer/doxygen/fakesources/MEDCouplingUMesh.C +++ b/doc/developer/doxygen/fakesources/MEDCouplingUMesh.C @@ -132,6 +132,7 @@ MEDCouplingUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, dou //MEDCouplingUMesh::mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes); //MEDCouplingUMesh::mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes); MEDCouplingUMesh::orientCorrectly2DCells(const double *vec, bool polyOnly); +MEDCouplingUMesh::orientCorrectly2DCells(const MEDCouplingUMesh* refFaces = nullptr); MEDCouplingUMesh::orientCorrectlyPolyhedrons(); //MEDCouplingUMesh::renumberNodes(const int *newNodeNumbers, int newNbOfNodes); //MEDCouplingUMesh::renumberNodes2(const int *newNodeNumbers, int newNbOfNodes); diff --git a/doc/user/input/data_analysis.rst b/doc/user/input/data_analysis.rst index ed6753fae..1ac5b2b66 100644 --- a/doc/user/input/data_analysis.rst +++ b/doc/user/input/data_analysis.rst @@ -491,6 +491,18 @@ The last argument if True, only polygons are checked, else, all cells are checke A mesh before applying orientCorrectly2DCells (to the left) and after (to the right) +Alternatively you can orient all 2D cells equally using the first cell as a reference: + +.. literalinclude:: ../../../src/MEDCoupling_Swig/UsersGuideExamplesTest.py + :start-after: UG_CommonHandlingMesh_11_1 + :end-before: UG_CommonHandlingMesh_11_1 + +Also it is possible to orient some selected 2D cells by using another group of cells as the reference: + +.. literalinclude:: ../../../src/MEDCoupling_Swig/UsersGuideExamplesTest.py + :start-after: UG_CommonHandlingMesh_11_2 + :end-before: UG_CommonHandlingMesh_11_2 + If your mesh includes incorrectly oriented polyhedra, the following method can help to fix your mesh: .. literalinclude:: ../../../src/MEDCoupling_Swig/UsersGuideExamplesTest.py diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 292f75ed8..a9181f3e7 100755 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -8800,6 +8800,11 @@ namespace MEDCouplingImpl * \throw If \a this mesh and \refFaces do not share nodes. * \throw If \a refFaces are not equally oriented. * \throw If \a this mesh plus \a refFaces together form a non-manifold mesh. + * + * \if ENABLE_EXAMPLES + * \ref cpp_mcumesh_are2DCellsNotCorrectlyOriented "Here is a C++ example".
+ * \ref py_mcumesh_are2DCellsNotCorrectlyOriented "Here is a Python example". + * \endif */ //================================================================================ @@ -8842,14 +8847,9 @@ void MEDCouplingUMesh::orientCorrectly2DCells(const MEDCouplingUMesh* refFaces) mesh[_OBJ]->getReverseNodalConnectivity( revNodal[_OBJ], revNodalIndx[_OBJ] ); mesh[_REF]->getReverseNodalConnectivity( revNodal[_REF], revNodalIndx[_REF] ); - std::vector< mcIdType > faceQueue; // starting faces with IDs counted from 1; negative ID mean a face in ref mesh - if ( refFaces ) - faceQueue.push_back( MEDCouplingImpl::encodeID( 0, _REF )); - else - faceQueue.push_back( MEDCouplingImpl::encodeID( 0, _OBJ )); - std::vector< mcIdType > faceNodes(4); std::vector< mcIdType > facesByEdge(4), equalFaces; + std::vector< mcIdType > faceQueue; // starting faces with IDs counted from 1; negative ID mean a face in ref mesh while ( nbFacesToCheck[_OBJ] + nbFacesToCheck[_REF] > 0 ) // until all faces checked { @@ -8861,6 +8861,7 @@ void MEDCouplingUMesh::orientCorrectly2DCells(const MEDCouplingUMesh* refFaces) if ( !isFaceQueued[iMesh][f] ) { faceQueue.push_back( MEDCouplingImpl::encodeID( f, iMesh )); + isFaceQueued[ iMesh ][ f ] = true; iMesh = 0; break; } diff --git a/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx b/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx index 37f145cff..7976969be 100644 --- a/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx +++ b/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx @@ -919,6 +919,17 @@ void CppExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented() mesh->are2DCellsNotCorrectlyOriented( vec, false, badCellIds ); CPPUNIT_ASSERT( badCellIds.size() == 0 ); // the orientation is OK //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2] + //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_3] + mesh->orientCorrectly2DCells(); + //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_3] + //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_4] + const mcIdType refCells[] = { 0,2 }; + const mcIdType objCells[] = { 1,3 }; + MCAuto refGroup = mesh->buildPartOfMySelf( refCells, refCells + 2 ); + MCAuto objGroup = mesh->buildPartOfMySelf( objCells, objCells + 2 ); + objGroup->orientCorrectly2DCells( refGroup ); + mesh->setPartOfMySelf( objCells, objCells + 2, *objGroup ); + //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_4] } void CppExample_MEDCouplingUMesh_getCellsContainingPoints() diff --git a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py index bda6078a2..625472e53 100644 --- a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py @@ -706,6 +706,17 @@ class MEDCouplingBasicsTest(unittest.TestCase): badCellIds=mesh.are2DCellsNotCorrectlyOriented( vec, False ) assert len( badCellIds ) == 0 # the orientation is OK #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2] + #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_3] + mesh.orientCorrectly2DCells( None ) + #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_3] + #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_4] + refCells = [ 0,2 ] + objCells = [ 1,3 ] + refGroup = mesh.buildPartOfMySelf( refCells ) + objGroup = mesh.buildPartOfMySelf( objCells ) + objGroup.orientCorrectly2DCells( refGroup ) + mesh.setPartOfMySelf( objCells, objGroup ) + #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_4] return def testExample_MEDCouplingUMesh_getCellsContainingPoints(self): diff --git a/src/MEDCoupling_Swig/UsersGuideExamplesTest.py b/src/MEDCoupling_Swig/UsersGuideExamplesTest.py index 6a4673459..2b7557f34 100755 --- a/src/MEDCoupling_Swig/UsersGuideExamplesTest.py +++ b/src/MEDCoupling_Swig/UsersGuideExamplesTest.py @@ -475,6 +475,19 @@ vec=[0,0,-1] skin.orientCorrectly2DCells(vec,False) #! [UG_CommonHandlingMesh_11] +#! [UG_CommonHandlingMesh_11_1] +skin.orientCorrectly2DCells( None ) +#! [UG_CommonHandlingMesh_11_1] + +#! [UG_CommonHandlingMesh_11_2] +refCells = [ 0,2,4 ] +objCells = [ 1,3,5,6,7,8, 20 ] +refGroup = skin.buildPartOfMySelf( refCells ) +objGroup = skin.buildPartOfMySelf( objCells ) +objGroup.orientCorrectly2DCells( refGroup ) +skin.setPartOfMySelf( objCells, objGroup ) +#! [UG_CommonHandlingMesh_11_2] + #! [UG_CommonHandlingMesh_12] m3.orientCorrectlyPolyhedrons() #! [UG_CommonHandlingMesh_12]