22010: [CEA 731] "CreateDimGroup" creates some faces not belonging to volumes's skin

Re-implenent CreateDimGroup()
This commit is contained in:
eap 2012-12-17 14:12:40 +00:00
parent b70f27b542
commit 6cafe5cc9f

View File

@ -31,10 +31,12 @@
#include "SMDS_ElemIterator.hxx" #include "SMDS_ElemIterator.hxx"
#include "SMDS_FacePosition.hxx" #include "SMDS_FacePosition.hxx"
#include "SMDS_IteratorOnIterators.hxx" #include "SMDS_IteratorOnIterators.hxx"
#include "SMDS_MeshGroup.hxx"
#include "SMDS_SetIterator.hxx" #include "SMDS_SetIterator.hxx"
#include "SMDS_VolumeTool.hxx" #include "SMDS_VolumeTool.hxx"
#include "SMESHDS_Command.hxx" #include "SMESHDS_Command.hxx"
#include "SMESHDS_CommandType.hxx" #include "SMESHDS_CommandType.hxx"
#include "SMESHDS_Group.hxx"
#include "SMESHDS_GroupOnGeom.hxx" #include "SMESHDS_GroupOnGeom.hxx"
#include "SMESH_Filter_i.hxx" #include "SMESH_Filter_i.hxx"
#include "SMESH_Gen_i.hxx" #include "SMESH_Gen_i.hxx"
@ -1575,8 +1577,11 @@ SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups,
\param theElemType dimension of elements \param theElemType dimension of elements
\param theName name of new group \param theName name of new group
\return pointer on new group \return pointer on new group
*
IMP 19939
*/ */
//============================================================================= //=============================================================================
SMESH::SMESH_Group_ptr SMESH::SMESH_Group_ptr
SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups, SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups,
SMESH::ElementType theElemType, SMESH::ElementType theElemType,
@ -1593,127 +1598,68 @@ SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups,
SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType; SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
// Create a group
TPythonDump pyDump;
SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName );
if ( aResGrp->_is_nil() )
return SMESH::SMESH_Group::_nil();
SMESHDS_GroupBase* groupBaseDS =
SMESH::DownCast<SMESH_GroupBase_i*>( aResGrp )->GetGroupDS();
SMDS_MeshGroup& resGroupCore = static_cast< SMESHDS_Group* >( groupBaseDS )->SMDSGroup();
try try
{ {
// Create map of nodes from all groups for ( int g = 0, n = theGroups.length(); g < n; g++ ) // loop on theGroups
set< int > aNodeMap;
for ( int g = 0, n = theGroups.length(); g < n; g++ )
{ {
SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ]; SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
if ( CORBA::is_nil( aGrp ) ) if ( CORBA::is_nil( aGrp ) )
continue; continue;
SMESH::ElementType aType = aGrp->GetType(); groupBaseDS = SMESH::DownCast<SMESH_GroupBase_i*>( aGrp )->GetGroupDS();
if ( aType == SMESH::ALL ) SMDS_ElemIteratorPtr elIt = groupBaseDS->GetElements();
continue;
else if ( aType == SMESH::NODE ) if ( theElemType == SMESH::NODE ) // get all nodes of elements
{ {
SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); while ( elIt->more() ) {
for ( int i = 0, n = aCurrIds->length(); i < n; i++ ) const SMDS_MeshElement* el = elIt->next();
{ SMDS_ElemIteratorPtr nIt = el->nodesIterator();
int aCurrId = aCurrIds[ i ]; while ( nIt->more() )
const SMDS_MeshNode* aNode = aMeshDS->FindNode( aCurrId ); resGroupCore.Add( nIt->next() );
if ( aNode )
aNodeMap.insert( aNode->GetID() );
} }
} }
else else // get elements of theElemType based on nodes of every element of group
{ {
SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); while ( elIt->more() )
for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
{ {
int aCurrId = aCurrIds[ i ]; const SMDS_MeshElement* el = elIt->next(); // an element of group
const SMDS_MeshElement* anElem = aMeshDS->FindElement( aCurrId ); TIDSortedElemSet elNodes( el->begin_nodes(), el->end_nodes() );
if ( !anElem ) TIDSortedElemSet checkedElems;
continue; SMDS_ElemIteratorPtr nIt = el->nodesIterator();
SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator(); while ( nIt->more() )
while( aNodeIter->more() )
{ {
const SMDS_MeshNode* aNode = const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>( nIt->next() );
dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() ); SMDS_ElemIteratorPtr elOfTypeIt = n->GetInverseElementIterator( anElemType );
if ( aNode ) // check nodes of elements of theElemType around el
aNodeMap.insert( aNode->GetID() ); while ( elOfTypeIt->more() )
{
const SMDS_MeshElement* elOfType = elOfTypeIt->next();
if ( !checkedElems.insert( elOfType ).second ) continue;
SMDS_ElemIteratorPtr nIt2 = elOfType->nodesIterator();
bool allNodesOK = true;
while ( nIt2->more() && allNodesOK )
allNodesOK = elNodes.count( nIt2->next() );
if ( allNodesOK )
resGroupCore.Add( elOfType );
}
} }
} }
} }
} }
// Get result identifiers
vector< int > aResultIds;
if ( theElemType == SMESH::NODE )
{
//NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
set<int>::iterator iter = aNodeMap.begin();
for ( ; iter != aNodeMap.end(); iter++ )
aResultIds.push_back( *iter);
}
else
{
// Create list of elements of given dimension constructed on the nodes
vector< int > anElemList;
//NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
//for ( ; aNodeIter.More(); aNodeIter.Next() )
set<int>::iterator iter = aNodeMap.begin();
for ( ; iter != aNodeMap.end(); iter++ )
{
const SMDS_MeshElement* aNode =
dynamic_cast<const SMDS_MeshElement*>( aMeshDS->FindNode( *iter ) );
if ( !aNode )
continue;
SMDS_ElemIteratorPtr anElemIter = aNode->elementsIterator( anElemType );
while( anElemIter->more() )
{
const SMDS_MeshElement* anElem =
dynamic_cast<const SMDS_MeshElement*>( anElemIter->next() );
if ( anElem && anElem->GetType() == anElemType )
anElemList.push_back( anElem->GetID() );
}
}
// check whether all nodes of elements are present in nodes map
for (int i=0; i< anElemList.size(); i++)
{
const SMDS_MeshElement* anElem = aMeshDS->FindElement( anElemList[i] );
if ( !anElem )
continue;
bool isOk = true;
SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
while( aNodeIter->more() )
{
const SMDS_MeshNode* aNode =
dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
if ( !aNode || !aNodeMap.count( aNode->GetID() ) )
{
isOk = false;
break;
}
}
if ( isOk )
aResultIds.push_back( anElem->GetID() );
}
}
// Create group
TPythonDump pyDump;
SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName );
if ( aResGrp->_is_nil() )
return SMESH::SMESH_Group::_nil();
// Create array of identifiers
SMESH::long_array_var aResIds = new SMESH::long_array;
aResIds->length( aResultIds.size() );
for (int i=0; i< aResultIds.size(); i++)
aResIds[ i ] = aResultIds[i];
aResGrp->Add( aResIds );
// Update Python script // Update Python script
pyDump << aResGrp << " = " << _this() << ".CreateDimGroup( " pyDump << aResGrp << " = " << _this() << ".CreateDimGroup( "
<< &theGroups << ", " << theElemType << ", '" << theName << "' )"; << &theGroups << ", " << theElemType << ", '" << theName << "' )";