From 8abf245a59f4409a7e2589461a6b2d9868360ca9 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 30 Mar 2010 12:27:31 +0000 Subject: [PATCH] /*! + * Returns nodes of given face (counted from zero) for given volumic element. + */ + long_array GetElemFaceNodes(in long elemId, in short faceIndex); + + /*! + * Returns an element based on all given nodes. + */ + long FindElementByNodes(in long_array nodes); --- idl/SMESH_Mesh.idl | 10 +++++ src/SMDS/SMDS_Mesh.cxx | 73 ++++++++++++++++++++++++------------ src/SMDS/SMDS_Mesh.hxx | 3 ++ src/SMESH_I/SMESH_Mesh_i.cxx | 51 +++++++++++++++++++++++++ src/SMESH_I/SMESH_Mesh_i.hxx | 11 +++++- 5 files changed, 123 insertions(+), 25 deletions(-) diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index 14ced70ce..5812506c2 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -774,6 +774,16 @@ module SMESH */ long ElemNbFaces(in long id); + /*! + * Returns nodes of given face (counted from zero) for given volumic element. + */ + long_array GetElemFaceNodes(in long elemId, in short faceIndex); + + /*! + * Returns an element based on all given nodes. + */ + long FindElementByNodes(in long_array nodes); + /*! * Returns true if given element is polygon */ diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index d6235a3b7..0e63864bf 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -941,11 +941,11 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, /// Add a polygon defined by its nodes IDs /////////////////////////////////////////////////////////////////////////////// -SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (std::vector nodes_ids, +SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (vector nodes_ids, const int ID) { int nbNodes = nodes_ids.size(); - std::vector nodes (nbNodes); + vector nodes (nbNodes); for (int i = 0; i < nbNodes; i++) { nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]); if (!nodes[i]) return NULL; @@ -958,7 +958,7 @@ SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (std::vector nodes_ids, /////////////////////////////////////////////////////////////////////////////// SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID - (std::vector nodes, + (vector nodes, const int ID) { SMDS_MeshFace * face; @@ -990,7 +990,7 @@ SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID /// An ID is automatically affected to the created face. /////////////////////////////////////////////////////////////////////////////// -SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (std::vector nodes) +SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (vector nodes) { return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID()); } @@ -1003,12 +1003,12 @@ SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (std::vector no /////////////////////////////////////////////////////////////////////////////// SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID - (std::vector nodes_ids, - std::vector quantities, + (vector nodes_ids, + vector quantities, const int ID) { int nbNodes = nodes_ids.size(); - std::vector nodes (nbNodes); + vector nodes (nbNodes); for (int i = 0; i < nbNodes; i++) { nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]); if (!nodes[i]) return NULL; @@ -1023,8 +1023,8 @@ SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID /////////////////////////////////////////////////////////////////////////////// SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID - (std::vector nodes, - std::vector quantities, + (vector nodes, + vector quantities, const int ID) { SMDS_MeshVolume* volume; @@ -1056,8 +1056,8 @@ SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID /////////////////////////////////////////////////////////////////////////////// SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume - (std::vector nodes, - std::vector quantities) + (vector nodes, + vector quantities) { int ID = myElementIDFactory->GetFreeID(); SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID); @@ -1763,10 +1763,10 @@ const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const //purpose : find polygon //======================================================================= -const SMDS_MeshFace* SMDS_Mesh::FindFace (const std::vector& nodes_ids) const +const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector& nodes_ids) const { int nbnodes = nodes_ids.size(); - std::vector poly_nodes (nbnodes); + vector poly_nodes (nbnodes); for (int inode = 0; inode < nbnodes; inode++) { const SMDS_MeshNode * node = FindNode(nodes_ids[inode]); if (node == NULL) return NULL; @@ -1775,18 +1775,43 @@ const SMDS_MeshFace* SMDS_Mesh::FindFace (const std::vector& nodes_ids) con return FindFace(poly_nodes); } -const SMDS_MeshFace* SMDS_Mesh::FindFace (const std::vector& nodes) +const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector& nodes) { - if ( nodes.size() > 2 && nodes[0] ) { - SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(SMDSAbs_Face); - while (itF->more()) { - const SMDS_MeshElement* f = itF->next(); - if ( f->NbNodes() == nodes.size() ) { - for ( int i = 1; f && i < nodes.size(); ++ i ) - if ( f->GetNodeIndex( nodes[ i ]) < 0 ) - f = 0; - if ( f ) - return static_cast (f); + return (const SMDS_MeshFace*) FindElement( nodes, SMDSAbs_Face ); +} + + +//================================================================================ +/*! + * \brief Return element based on all given nodes + * \param nodes - node of element + * \param type - type of element + * \param noMedium - true if medium nodes of quadratic element are not included in + * \retval const SMDS_MeshElement* - found element or NULL + */ +//================================================================================ + +const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector& nodes, + const SMDSAbs_ElementType type, + const bool noMedium) +{ + if ( nodes.size() > 0 && nodes[0] ) + { + SMDS_ElemIteratorPtr itF = nodes[0]->GetInverseElementIterator(type); + while (itF->more()) + { + const SMDS_MeshElement* e = itF->next(); + int nbNodesToCheck = noMedium ? e->NbCornerNodes() : e->NbNodes(); + if ( nbNodesToCheck == nodes.size() ) + { + for ( int i = 1; e && i < nodes.size(); ++ i ) + { + int nodeIndex = e->GetNodeIndex( nodes[ i ]); + if ( nodeIndex < 0 || nodeIndex >= nbNodesToCheck ) + e = 0; + } + if ( e ) + return static_cast (e); } } } diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index 0da9824c9..2c1b43e2e 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -492,6 +492,9 @@ public: const SMDS_MeshFace *FindFace(const std::vector& nodes_ids) const; static const SMDS_MeshFace* FindFace(const std::vector& nodes); + static const SMDS_MeshElement* FindElement(const std::vector& nodes, + const SMDSAbs_ElementType type=SMDSAbs_All, + const bool noMedium=true); /*! * \brief Raise an exception if free memory (ram+swap) too low diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 41dbdeb0a..385500815 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -3195,6 +3195,57 @@ CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id) return elem->NbFaces(); } +//======================================================================= +//function : GetElemFaceNodes +//purpose : Returns nodes of given face (counted from zero) for given element. +//======================================================================= + +SMESH::long_array* SMESH_Mesh_i::GetElemFaceNodes(CORBA::Long elemId, + CORBA::Short faceIndex) +{ + SMESH::long_array_var aResult = new SMESH::long_array(); + if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() ) + { + if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(elemId) ) + { + SMDS_VolumeTool vtool( elem ); + if ( faceIndex < vtool.NbFaces() ) + { + aResult->length( vtool.NbFaceNodes( faceIndex )); + const SMDS_MeshNode** nn = vtool.GetFaceNodes( faceIndex ); + for ( int i = 0; i < aResult->length(); ++i ) + aResult[ i ] = nn[ i ]->GetID(); + } + } + } + return aResult._retn(); +} + +//======================================================================= +//function : FindElementByNodes +//purpose : Returns an element based on all given nodes. +//======================================================================= + +CORBA::Long SMESH_Mesh_i::FindElementByNodes(const SMESH::long_array& nodes) +{ + CORBA::Long elemID(0); + if ( SMESHDS_Mesh* mesh = _impl->GetMeshDS() ) + { + vector< const SMDS_MeshNode * > nn( nodes.length() ); + for ( int i = 0; i < nodes.length(); ++i ) + if ( !( nn[i] = mesh->FindNode( nodes[i] ))) + return elemID; + + const SMDS_MeshElement* elem = mesh->FindElement( nn ); + if ( !elem && ( _impl->NbEdges( ORDER_QUADRATIC ) || + _impl->NbFaces( ORDER_QUADRATIC ) || + _impl->NbVolumes( ORDER_QUADRATIC ))) + elem = mesh->FindElement( nn, SMDSAbs_All, /*noMedium=*/true ); + + if ( elem ) elemID = CORBA::Long( elem->GetID() ); + } + return elemID; +} //============================================================================= /*! diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index db41226b6..fa261314a 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -455,7 +455,16 @@ public: * Returns number of faces for given element */ CORBA::Long ElemNbFaces(CORBA::Long id); - + /*! + * Returns nodes of given face (counted from zero) for given element. + */ + SMESH::long_array* GetElemFaceNodes(CORBA::Long elemId, CORBA::Short faceIndex); + + /*! + * Returns an element based on all given nodes. + */ + CORBA::Long FindElementByNodes(const SMESH::long_array& nodes); + /*! * Returns true if given element is polygon */ -- 2.39.2