mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-02-06 00:54:17 +05:00
PAL13190 (EDF159 SMESH: in Merge Nodes and Merge Elements, visualisze nodes or meshes twice):
add FindEqualElements(); modify MergeEqualElements().
This commit is contained in:
parent
2670bc54ec
commit
f899a9e718
@ -335,7 +335,10 @@ module SMESH
|
|||||||
|
|
||||||
void MergeNodes (in array_of_long_array GroupsOfNodes);
|
void MergeNodes (in array_of_long_array GroupsOfNodes);
|
||||||
|
|
||||||
void MergeEqualElements();
|
void FindEqualElements (in SMESH_IDSource MeshOrSubMeshOrGroup,
|
||||||
|
out array_of_long_array GroupsOfElementsID);
|
||||||
|
|
||||||
|
void MergeEqualElements(in array_of_long_array GroupsOfElementsID);
|
||||||
/*!
|
/*!
|
||||||
* If the given ID is a valid node ID (nodeID > 0), just move this node, else
|
* If the given ID is a valid node ID (nodeID > 0), just move this node, else
|
||||||
* move the node closest to the point to point's location and return ID of the node
|
* move the node closest to the point to point's location and return ID of the node
|
||||||
|
@ -5069,60 +5069,96 @@ class SortableElement : public set <const SMDS_MeshElement*>
|
|||||||
mutable const SMDS_MeshElement* myElem;
|
mutable const SMDS_MeshElement* myElem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : FindEqualElements
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
void SMESH_MeshEditor::FindEqualElements(set<const SMDS_MeshElement*> & theElements,
|
||||||
|
TListOfListOfElementsID & theGroupsOfElementsID)
|
||||||
|
{
|
||||||
|
myLastCreatedElems.Clear();
|
||||||
|
myLastCreatedNodes.Clear();
|
||||||
|
|
||||||
|
typedef set<const SMDS_MeshElement*> TElemsSet;
|
||||||
|
typedef map< SortableElement, int > TMapOfNodeSet;
|
||||||
|
typedef list<int> TGroupOfElems;
|
||||||
|
|
||||||
|
TElemsSet elems;
|
||||||
|
if ( theElements.empty() )
|
||||||
|
{ // get all elements in the mesh
|
||||||
|
SMDS_ElemIteratorPtr eIt = GetMeshDS()->elementsIterator();
|
||||||
|
while ( eIt->more() )
|
||||||
|
elems.insert( elems.end(), eIt->next());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
elems = theElements;
|
||||||
|
|
||||||
|
vector< TGroupOfElems > arrayOfGroups;
|
||||||
|
TGroupOfElems groupOfElems;
|
||||||
|
TMapOfNodeSet mapOfNodeSet;
|
||||||
|
|
||||||
|
TElemsSet::iterator elemIt = elems.begin();
|
||||||
|
for ( int i = 0, j=0; elemIt != elems.end(); ++elemIt, ++j ) {
|
||||||
|
const SMDS_MeshElement* curElem = *elemIt;
|
||||||
|
SortableElement SE(curElem);
|
||||||
|
int ind = -1;
|
||||||
|
// check uniqueness
|
||||||
|
pair< TMapOfNodeSet::iterator, bool> pp = mapOfNodeSet.insert(make_pair(SE, i));
|
||||||
|
if( !(pp.second) ) {
|
||||||
|
TMapOfNodeSet::iterator& itSE = pp.first;
|
||||||
|
ind = (*itSE).second;
|
||||||
|
arrayOfGroups[ind].push_back(curElem->GetID());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
groupOfElems.clear();
|
||||||
|
groupOfElems.push_back(curElem->GetID());
|
||||||
|
arrayOfGroups.push_back(groupOfElems);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector< TGroupOfElems >::iterator groupIt = arrayOfGroups.begin();
|
||||||
|
for ( ; groupIt != arrayOfGroups.end(); ++groupIt ) {
|
||||||
|
groupOfElems = *groupIt;
|
||||||
|
if ( groupOfElems.size() > 1 ) {
|
||||||
|
groupOfElems.sort();
|
||||||
|
theGroupsOfElementsID.push_back(groupOfElems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : MergeEqualElements
|
//function : MergeEqualElements
|
||||||
//purpose : Remove all but one of elements built on the same nodes.
|
//purpose : Remove all but one of elements built on the same nodes.
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
void SMESH_MeshEditor::MergeEqualElements()
|
void SMESH_MeshEditor::MergeEqualElements(TListOfListOfElementsID & theGroupsOfElementsID)
|
||||||
{
|
{
|
||||||
myLastCreatedElems.Clear();
|
myLastCreatedElems.Clear();
|
||||||
myLastCreatedNodes.Clear();
|
myLastCreatedNodes.Clear();
|
||||||
|
|
||||||
|
typedef list<int> TListOfIDs;
|
||||||
|
TListOfIDs rmElemIds; // IDs of elems to remove
|
||||||
|
|
||||||
SMESHDS_Mesh* aMesh = GetMeshDS();
|
SMESHDS_Mesh* aMesh = GetMeshDS();
|
||||||
|
|
||||||
SMDS_EdgeIteratorPtr eIt = aMesh->edgesIterator();
|
TListOfListOfElementsID::iterator groupsIt = theGroupsOfElementsID.begin();
|
||||||
SMDS_FaceIteratorPtr fIt = aMesh->facesIterator();
|
while ( groupsIt != theGroupsOfElementsID.end() ) {
|
||||||
SMDS_VolumeIteratorPtr vIt = aMesh->volumesIterator();
|
TListOfIDs& aGroupOfElemID = *groupsIt;
|
||||||
|
aGroupOfElemID.sort();
|
||||||
list< int > rmElemIds; // IDs of elems to remove
|
int elemIDToKeep = aGroupOfElemID.front();
|
||||||
|
const SMDS_MeshElement* elemToKeep = aMesh->FindElement(elemIDToKeep);
|
||||||
for ( int iDim = 1; iDim <= 3; iDim++ ) {
|
aGroupOfElemID.pop_front();
|
||||||
|
TListOfIDs::iterator idIt = aGroupOfElemID.begin();
|
||||||
set< SortableElement > setOfNodeSet;
|
while ( idIt != aGroupOfElemID.end() ) {
|
||||||
while ( 1 ) {
|
int elemIDToRemove = *idIt;
|
||||||
// get next element
|
const SMDS_MeshElement* elemToRemove = aMesh->FindElement(elemIDToRemove);
|
||||||
const SMDS_MeshElement* elem = 0;
|
// add the kept element in groups of removed one (PAL15188)
|
||||||
if ( iDim == 1 ) {
|
AddToSameGroups( elemToKeep, elemToRemove, aMesh );
|
||||||
if ( eIt->more() ) elem = eIt->next();
|
rmElemIds.push_back( elemIDToRemove );
|
||||||
} else if ( iDim == 2 ) {
|
++idIt;
|
||||||
if ( fIt->more() ) elem = fIt->next();
|
|
||||||
} else {
|
|
||||||
if ( vIt->more() ) elem = vIt->next();
|
|
||||||
}
|
|
||||||
if ( !elem ) break;
|
|
||||||
|
|
||||||
SortableElement SE(elem);
|
|
||||||
|
|
||||||
// check uniqueness
|
|
||||||
pair< set<SortableElement>::iterator, bool> pp = setOfNodeSet.insert(SE);
|
|
||||||
if( !(pp.second) ) {
|
|
||||||
set<SortableElement>::iterator & itSE = pp.first;
|
|
||||||
const SortableElement & SEold = *itSE;
|
|
||||||
if( SEold.Get()->GetID() > elem->GetID() ) {
|
|
||||||
// keep elem, remove old
|
|
||||||
rmElemIds.push_back( SEold.Get()->GetID() );
|
|
||||||
// add kept elem in groups of removed one (PAL15188)
|
|
||||||
AddToSameGroups( elem, SEold.Get(), GetMeshDS() );
|
|
||||||
SEold.Set( elem );
|
|
||||||
}
|
|
||||||
else { // remove elem
|
|
||||||
rmElemIds.push_back( elem->GetID() );
|
|
||||||
AddToSameGroups( SEold.Get(), elem, GetMeshDS() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
++groupsIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
Remove( rmElemIds, false );
|
Remove( rmElemIds, false );
|
||||||
|
@ -315,7 +315,14 @@ public:
|
|||||||
// In each group, the cdr of nodes are substituted by the first one
|
// In each group, the cdr of nodes are substituted by the first one
|
||||||
// in all elements.
|
// in all elements.
|
||||||
|
|
||||||
void MergeEqualElements();
|
typedef std::list< std::list< int > > TListOfListOfElementsID;
|
||||||
|
|
||||||
|
void FindEqualElements(std::set<const SMDS_MeshElement*> & theElements,
|
||||||
|
TListOfListOfElementsID & theGroupsOfElementsID);
|
||||||
|
// Return list of group of elements build on the same nodes.
|
||||||
|
// Search among theElements or in the whole mesh if theElements is empty.
|
||||||
|
|
||||||
|
void MergeEqualElements(TListOfListOfElementsID & theGroupsOfElementsID);
|
||||||
// Remove all but one of elements built on the same nodes.
|
// Remove all but one of elements built on the same nodes.
|
||||||
// Return nb of successfully merged groups.
|
// Return nb of successfully merged groups.
|
||||||
|
|
||||||
|
@ -1884,20 +1884,86 @@ void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfN
|
|||||||
aTPythonDump << "])";
|
aTPythonDump << "])";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : FindEqualElements
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
|
||||||
|
SMESH::array_of_long_array_out GroupsOfElementsID)
|
||||||
|
{
|
||||||
|
initData();
|
||||||
|
if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
|
||||||
|
SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
|
||||||
|
typedef list<int> TListOfIDs;
|
||||||
|
set<const SMDS_MeshElement*> elems;
|
||||||
|
SMESH::long_array_var aElementsId = theObject->GetIDs();
|
||||||
|
SMESHDS_Mesh* aMesh = GetMeshDS();
|
||||||
|
|
||||||
|
for(int i = 0; i < aElementsId->length(); i++) {
|
||||||
|
CORBA::Long anID = aElementsId[i];
|
||||||
|
const SMDS_MeshElement * elem = aMesh->FindElement(anID);
|
||||||
|
if (elem) {
|
||||||
|
elems.insert(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
|
||||||
|
::SMESH_MeshEditor anEditor( myMesh );
|
||||||
|
anEditor.FindEqualElements( elems, aListOfListOfElementsID );
|
||||||
|
|
||||||
|
GroupsOfElementsID = new SMESH::array_of_long_array;
|
||||||
|
GroupsOfElementsID->length( aListOfListOfElementsID.size() );
|
||||||
|
|
||||||
|
::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
|
||||||
|
for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
|
||||||
|
SMESH::long_array& aGroup = GroupsOfElementsID[ j ];
|
||||||
|
TListOfIDs& listOfIDs = *arraysIt;
|
||||||
|
aGroup.length( listOfIDs.size() );
|
||||||
|
TListOfIDs::iterator idIt = listOfIDs.begin();
|
||||||
|
for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
|
||||||
|
aGroup[ k ] = *idIt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Python script
|
||||||
|
TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
|
||||||
|
<<theObject<<" )";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : MergeEqualElements
|
//function : MergeEqualElements
|
||||||
//purpose :
|
//purpose :
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
void SMESH_MeshEditor_i::MergeEqualElements()
|
void SMESH_MeshEditor_i::MergeEqualElements(const SMESH::array_of_long_array& GroupsOfElementsID)
|
||||||
{
|
{
|
||||||
initData();
|
initData();
|
||||||
|
|
||||||
|
TPythonDump aTPythonDump;
|
||||||
|
aTPythonDump << this << ".MergeEqualElements( [";
|
||||||
|
|
||||||
|
::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
|
||||||
|
|
||||||
|
for (int i = 0; i < GroupsOfElementsID.length(); i++) {
|
||||||
|
const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
|
||||||
|
aListOfListOfElementsID.push_back( list< int >() );
|
||||||
|
list< int >& aListOfElemsID = aListOfListOfElementsID.back();
|
||||||
|
for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
|
||||||
|
CORBA::Long id = anElemsIDGroup[ j ];
|
||||||
|
aListOfElemsID.push_back( id );
|
||||||
|
}
|
||||||
|
if ( aListOfElemsID.size() < 2 )
|
||||||
|
aListOfListOfElementsID.pop_back();
|
||||||
|
if ( i > 0 ) aTPythonDump << ", ";
|
||||||
|
aTPythonDump << anElemsIDGroup;
|
||||||
|
}
|
||||||
|
|
||||||
::SMESH_MeshEditor anEditor( myMesh );
|
::SMESH_MeshEditor anEditor( myMesh );
|
||||||
anEditor.MergeEqualElements();
|
anEditor.MergeEqualElements(aListOfListOfElementsID);
|
||||||
|
|
||||||
// Update Python script
|
// Update Python script
|
||||||
TPythonDump() << this << ".MergeEqualElements()";
|
aTPythonDump << "] )";
|
||||||
}
|
}
|
||||||
|
|
||||||
//================================================================================
|
//================================================================================
|
||||||
|
@ -208,7 +208,9 @@ class SMESH_MeshEditor_i: public POA_SMESH::SMESH_MeshEditor
|
|||||||
CORBA::Double Tolerance,
|
CORBA::Double Tolerance,
|
||||||
SMESH::array_of_long_array_out GroupsOfNodes);
|
SMESH::array_of_long_array_out GroupsOfNodes);
|
||||||
void MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes);
|
void MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes);
|
||||||
void MergeEqualElements();
|
void FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
|
||||||
|
SMESH::array_of_long_array_out GroupsOfElementsID);
|
||||||
|
void MergeEqualElements(const SMESH::array_of_long_array& GroupsOfElementsID);
|
||||||
CORBA::Long MoveClosestNodeToPoint(CORBA::Double x,
|
CORBA::Long MoveClosestNodeToPoint(CORBA::Double x,
|
||||||
CORBA::Double y,
|
CORBA::Double y,
|
||||||
CORBA::Double z,
|
CORBA::Double z,
|
||||||
|
Loading…
Reference in New Issue
Block a user