/// Add a polygon defined by its nodes IDs
///////////////////////////////////////////////////////////////////////////////
-SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (std::vector<int> nodes_ids,
+SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (vector<int> nodes_ids,
const int ID)
{
int nbNodes = nodes_ids.size();
- std::vector<const SMDS_MeshNode*> nodes (nbNodes);
+ vector<const SMDS_MeshNode*> nodes (nbNodes);
for (int i = 0; i < nbNodes; i++) {
nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
if (!nodes[i]) return NULL;
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID
- (std::vector<const SMDS_MeshNode*> nodes,
+ (vector<const SMDS_MeshNode*> nodes,
const int ID)
{
SMDS_MeshFace * face;
/// An ID is automatically affected to the created face.
///////////////////////////////////////////////////////////////////////////////
-SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (std::vector<const SMDS_MeshNode*> nodes)
+SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (vector<const SMDS_MeshNode*> nodes)
{
return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID());
}
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID
- (std::vector<int> nodes_ids,
- std::vector<int> quantities,
+ (vector<int> nodes_ids,
+ vector<int> quantities,
const int ID)
{
int nbNodes = nodes_ids.size();
- std::vector<const SMDS_MeshNode*> nodes (nbNodes);
+ vector<const SMDS_MeshNode*> nodes (nbNodes);
for (int i = 0; i < nbNodes; i++) {
nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]);
if (!nodes[i]) return NULL;
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID
- (std::vector<const SMDS_MeshNode*> nodes,
- std::vector<int> quantities,
+ (vector<const SMDS_MeshNode*> nodes,
+ vector<int> quantities,
const int ID)
{
SMDS_MeshVolume* volume;
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
- (std::vector<const SMDS_MeshNode*> nodes,
- std::vector<int> quantities)
+ (vector<const SMDS_MeshNode*> nodes,
+ vector<int> quantities)
{
int ID = myElementIDFactory->GetFreeID();
SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
//purpose : find polygon
//=======================================================================
-const SMDS_MeshFace* SMDS_Mesh::FindFace (const std::vector<int>& nodes_ids) const
+const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<int>& nodes_ids) const
{
int nbnodes = nodes_ids.size();
- std::vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
+ vector<const SMDS_MeshNode *> poly_nodes (nbnodes);
for (int inode = 0; inode < nbnodes; inode++) {
const SMDS_MeshNode * node = FindNode(nodes_ids[inode]);
if (node == NULL) return NULL;
return FindFace(poly_nodes);
}
-const SMDS_MeshFace* SMDS_Mesh::FindFace (const std::vector<const SMDS_MeshNode *>& nodes)
+const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector<const SMDS_MeshNode *>& 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<const SMDS_MeshFace *> (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 <nodes>
+ * \retval const SMDS_MeshElement* - found element or NULL
+ */
+//================================================================================
+
+const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector<const SMDS_MeshNode *>& 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<const SMDS_MeshFace *> (e);
}
}
}
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;
+}
//=============================================================================
/*!