PAL13504 (Mesh from an imported mesh)

some optimization
This commit is contained in:
eap 2007-02-19 16:22:37 +00:00
parent b4888f2b96
commit 9e4f893366
2 changed files with 75 additions and 84 deletions

View File

@ -225,12 +225,10 @@ bool SMESH_MeshEditor::IsMedium(const SMDS_MeshNode* node,
const SMDSAbs_ElementType typeToCheck) const SMDSAbs_ElementType typeToCheck)
{ {
bool isMedium = false; bool isMedium = false;
SMDS_ElemIteratorPtr it = node->GetInverseElementIterator(); SMDS_ElemIteratorPtr it = node->GetInverseElementIterator(typeToCheck);
while (it->more()) { while (it->more()) {
const SMDS_MeshElement* elem = it->next(); const SMDS_MeshElement* elem = it->next();
isMedium = elem->IsMediumNode(node); isMedium = elem->IsMediumNode(node);
if ( typeToCheck == SMDSAbs_All || elem->GetType() == typeToCheck )
break;
} }
return isMedium; return isMedium;
} }
@ -6057,9 +6055,9 @@ void SMESH_MeshEditor::UpdateVolumes (const SMDS_MeshNode* theBetweenNode
//function : ConvertElemToQuadratic //function : ConvertElemToQuadratic
//purpose : //purpose :
//======================================================================= //=======================================================================
void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh *theSm, void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh * theSm,
SMESH_MesherHelper* theHelper, SMESH_MesherHelper& theHelper,
const bool theForce3d) const bool theForce3d)
{ {
if( !theSm ) return; if( !theSm ) return;
SMESHDS_Mesh* meshDS = GetMeshDS(); SMESHDS_Mesh* meshDS = GetMeshDS();
@ -6067,7 +6065,7 @@ void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh *theSm,
while(ElemItr->more()) while(ElemItr->more())
{ {
const SMDS_MeshElement* elem = ElemItr->next(); const SMDS_MeshElement* elem = ElemItr->next();
if( !elem ) continue; if( !elem || elem->IsQuadratic() ) continue;
int id = elem->GetID(); int id = elem->GetID();
int nbNodes = elem->NbNodes(); int nbNodes = elem->NbNodes();
@ -6077,30 +6075,29 @@ void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh *theSm,
{ {
aNds[i] = elem->GetNode(i); aNds[i] = elem->GetNode(i);
} }
SMDSAbs_ElementType aType = elem->GetType(); SMDSAbs_ElementType aType = elem->GetType();
theSm->RemoveElement(elem);
meshDS->SMDS_Mesh::RemoveFreeElement(elem);
const SMDS_MeshElement* NewElem = 0; const SMDS_MeshElement* NewElem = 0;
switch( aType ) switch( aType )
{ {
case SMDSAbs_Edge : case SMDSAbs_Edge :
{ {
meshDS->RemoveFreeElement(elem, theSm); NewElem = theHelper.AddEdge(aNds[0], aNds[1], id, theForce3d);
NewElem = theHelper->AddQuadraticEdge(aNds[0], aNds[1], id, theForce3d);
break; break;
} }
case SMDSAbs_Face : case SMDSAbs_Face :
{ {
if(elem->IsQuadratic()) continue;
meshDS->RemoveFreeElement(elem, theSm);
switch(nbNodes) switch(nbNodes)
{ {
case 3: case 3:
NewElem = theHelper->AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d); NewElem = theHelper.AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d);
break; break;
case 4: case 4:
NewElem = theHelper->AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d); NewElem = theHelper.AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d);
break; break;
default: default:
continue; continue;
@ -6109,20 +6106,17 @@ void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh *theSm,
} }
case SMDSAbs_Volume : case SMDSAbs_Volume :
{ {
if( elem->IsQuadratic() ) continue;
meshDS->RemoveFreeElement(elem, theSm);
switch(nbNodes) switch(nbNodes)
{ {
case 4: case 4:
NewElem = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], id, true); NewElem = theHelper.AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], id, true);
break; break;
case 6: case 6:
NewElem = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], aNds[4], aNds[5], id, true); NewElem = theHelper.AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], aNds[4], aNds[5], id, true);
break; break;
case 8: case 8:
NewElem = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], NewElem = theHelper.AddVolume(aNds[0], aNds[1], aNds[2], aNds[3],
aNds[4], aNds[5], aNds[6], aNds[7], id, true); aNds[4], aNds[5], aNds[6], aNds[7], id, true);
break; break;
default: default:
continue; continue;
@ -6137,6 +6131,8 @@ void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh *theSm,
AddToSameGroups( NewElem, elem, meshDS); AddToSameGroups( NewElem, elem, meshDS);
theSm->AddElement( NewElem ); theSm->AddElement( NewElem );
} }
if ( NewElem != elem )
RemoveElemFromGroups (elem, meshDS);
} }
} }
@ -6148,8 +6144,8 @@ void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d)
{ {
SMESHDS_Mesh* meshDS = GetMeshDS(); SMESHDS_Mesh* meshDS = GetMeshDS();
SMESH_MesherHelper* aHelper = new SMESH_MesherHelper(*myMesh); SMESH_MesherHelper aHelper(*myMesh);
aHelper->SetKeyIsQuadratic( true ); aHelper.SetIsQuadratic( true );
const TopoDS_Shape& aShape = meshDS->ShapeToMesh(); const TopoDS_Shape& aShape = meshDS->ShapeToMesh();
if ( !aShape.IsNull() && GetMesh()->GetSubMeshContaining(aShape) ) if ( !aShape.IsNull() && GetMesh()->GetSubMeshContaining(aShape) )
@ -6161,10 +6157,10 @@ void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d)
for (itsub = aMapSM.begin(); itsub != aMapSM.end(); itsub++) for (itsub = aMapSM.begin(); itsub != aMapSM.end(); itsub++)
{ {
SMESHDS_SubMesh *sm = ((*itsub).second)->GetSubMeshDS(); SMESHDS_SubMesh *sm = ((*itsub).second)->GetSubMeshDS();
aHelper->SetSubShape( (*itsub).second->GetSubShape() ); aHelper.SetSubShape( (*itsub).second->GetSubShape() );
ConvertElemToQuadratic(sm, aHelper, theForce3d); ConvertElemToQuadratic(sm, aHelper, theForce3d);
} }
aHelper->SetSubShape( aSubMesh->GetSubShape() ); aHelper.SetSubShape( aSubMesh->GetSubShape() );
ConvertElemToQuadratic(aSubMesh->GetSubMeshDS(), aHelper, theForce3d); ConvertElemToQuadratic(aSubMesh->GetSubMeshDS(), aHelper, theForce3d);
} }
else else
@ -6173,17 +6169,19 @@ void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d)
while(aEdgeItr->more()) while(aEdgeItr->more())
{ {
const SMDS_MeshEdge* edge = aEdgeItr->next(); const SMDS_MeshEdge* edge = aEdgeItr->next();
if(edge) if(edge && !edge->IsQuadratic())
{ {
int id = edge->GetID(); int id = edge->GetID();
const SMDS_MeshNode* n1 = edge->GetNode(0); const SMDS_MeshNode* n1 = edge->GetNode(0);
const SMDS_MeshNode* n2 = edge->GetNode(1); const SMDS_MeshNode* n2 = edge->GetNode(1);
RemoveElemFromGroups (edge, meshDS);
meshDS->SMDS_Mesh::RemoveFreeElement(edge); meshDS->SMDS_Mesh::RemoveFreeElement(edge);
const SMDS_QuadraticEdge* NewEdge = aHelper->AddQuadraticEdge(n1, n2, id, theForce3d); const SMDS_MeshEdge* NewEdge = aHelper.AddEdge(n1, n2, id, theForce3d);
AddToSameGroups(NewEdge, edge, meshDS); if ( NewEdge )
AddToSameGroups(NewEdge, edge, meshDS);
if ( NewEdge != edge )
RemoveElemFromGroups (edge, meshDS);
} }
} }
SMDS_FaceIteratorPtr aFaceItr = meshDS->facesIterator(); SMDS_FaceIteratorPtr aFaceItr = meshDS->facesIterator();
@ -6201,22 +6199,24 @@ void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d)
aNds[i] = face->GetNode(i); aNds[i] = face->GetNode(i);
} }
RemoveElemFromGroups (face, meshDS);
meshDS->SMDS_Mesh::RemoveFreeElement(face); meshDS->SMDS_Mesh::RemoveFreeElement(face);
SMDS_MeshFace * NewFace = 0; SMDS_MeshFace * NewFace = 0;
switch(nbNodes) switch(nbNodes)
{ {
case 3: case 3:
NewFace = aHelper->AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d); NewFace = aHelper.AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d);
break; break;
case 4: case 4:
NewFace = aHelper->AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d); NewFace = aHelper.AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d);
break; break;
default: default:
continue; continue;
} }
AddToSameGroups(NewFace, face, meshDS); if ( NewFace )
AddToSameGroups(NewFace, face, meshDS);
if ( NewFace != face )
RemoveElemFromGroups (face, meshDS);
} }
SMDS_VolumeIteratorPtr aVolumeItr = meshDS->volumesIterator(); SMDS_VolumeIteratorPtr aVolumeItr = meshDS->volumesIterator();
while(aVolumeItr->more()) while(aVolumeItr->more())
@ -6233,54 +6233,52 @@ void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d)
aNds[i] = volume->GetNode(i); aNds[i] = volume->GetNode(i);
} }
RemoveElemFromGroups (volume, meshDS);
meshDS->SMDS_Mesh::RemoveFreeElement(volume); meshDS->SMDS_Mesh::RemoveFreeElement(volume);
SMDS_MeshVolume * NewVolume = 0; SMDS_MeshVolume * NewVolume = 0;
switch(nbNodes) switch(nbNodes)
{ {
case 4: case 4:
NewVolume = aHelper->AddVolume(aNds[0], aNds[1], aNds[2], NewVolume = aHelper.AddVolume(aNds[0], aNds[1], aNds[2],
aNds[3], id, true ); aNds[3], id, true );
break; break;
case 6: case 6:
NewVolume = aHelper->AddVolume(aNds[0], aNds[1], aNds[2], NewVolume = aHelper.AddVolume(aNds[0], aNds[1], aNds[2],
aNds[3], aNds[4], aNds[5], id, true); aNds[3], aNds[4], aNds[5], id, true);
break; break;
case 8: case 8:
NewVolume = aHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], NewVolume = aHelper.AddVolume(aNds[0], aNds[1], aNds[2], aNds[3],
aNds[4], aNds[5], aNds[6], aNds[7], id, true); aNds[4], aNds[5], aNds[6], aNds[7], id, true);
break; break;
default: default:
continue; continue;
} }
AddToSameGroups(NewVolume, volume, meshDS); if ( NewVolume )
AddToSameGroups(NewVolume, volume, meshDS);
if ( NewVolume != volume )
RemoveElemFromGroups (volume, meshDS);
} }
} }
delete aHelper;
} }
//======================================================================= //=======================================================================
//function : RemoveQuadElem //function : RemoveQuadElem
//purpose : //purpose :
//======================================================================= //=======================================================================
void SMESH_MeshEditor::RemoveQuadElem(SMESHDS_SubMesh *theSm, void SMESH_MeshEditor::RemoveQuadElem(SMESHDS_SubMesh * theSm,
SMDS_ElemIteratorPtr theItr, SMDS_ElemIteratorPtr theItr,
RemoveQuadNodeMap& theRemoveNodeMap) const int theShapeID)
{ {
SMESHDS_Mesh* meshDS = GetMeshDS(); SMESHDS_Mesh* meshDS = GetMeshDS();
while( theItr->more() ) while( theItr->more() )
{ {
const SMDS_MeshElement* elem = theItr->next(); const SMDS_MeshElement* elem = theItr->next();
if( elem ) if( elem && elem->IsQuadratic())
{ {
if( !elem->IsQuadratic() )
continue;
int id = elem->GetID(); int id = elem->GetID();
int nbNodes = elem->NbNodes(), idx = 0; int nbNodes = elem->NbNodes(), idx = 0;
vector<const SMDS_MeshNode *> aNds; vector<const SMDS_MeshNode *> aNds;
aNds.reserve( nbNodes );
for(int i = 0; i < nbNodes; i++) for(int i = 0; i < nbNodes; i++)
{ {
@ -6288,11 +6286,11 @@ void SMESH_MeshEditor::RemoveQuadElem(SMESHDS_SubMesh *theSm,
if( elem->IsMediumNode( n ) ) if( elem->IsMediumNode( n ) )
{ {
ItRemoveQuadNodeMap itRNM = theRemoveNodeMap.find( n ); if ( n->GetPosition()->GetShapeId() != theShapeID )
if( itRNM == theRemoveNodeMap.end() ) meshDS->RemoveFreeNode( n, meshDS->MeshElements
{ ( n->GetPosition()->GetShapeId() ));
theRemoveNodeMap.insert(RemoveQuadNodeMap::value_type( n,theSm )); else
} meshDS->RemoveFreeNode( n, theSm );
} }
else else
aNds.push_back( n ); aNds.push_back( n );
@ -6303,7 +6301,9 @@ void SMESH_MeshEditor::RemoveQuadElem(SMESHDS_SubMesh *theSm,
SMDSAbs_ElementType aType = elem->GetType(); SMDSAbs_ElementType aType = elem->GetType();
//remove old quadratic elements //remove old quadratic elements
meshDS->RemoveFreeElement( elem, theSm ); meshDS->SMDS_Mesh::RemoveFreeElement( elem );
if ( theSm )
theSm->RemoveElement( elem );
SMDS_MeshElement * NewElem = 0; SMDS_MeshElement * NewElem = 0;
switch(aType) switch(aType)
@ -6332,8 +6332,11 @@ void SMESH_MeshEditor::RemoveQuadElem(SMESHDS_SubMesh *theSm,
break; break;
} }
AddToSameGroups(NewElem, elem, meshDS); if ( NewElem )
if( theSm ) AddToSameGroups(NewElem, elem, meshDS);
if ( NewElem != elem )
RemoveElemFromGroups (elem, meshDS);
if( theSm && NewElem )
theSm->AddElement( NewElem ); theSm->AddElement( NewElem );
} }
} }
@ -6345,8 +6348,6 @@ void SMESH_MeshEditor::RemoveQuadElem(SMESHDS_SubMesh *theSm,
bool SMESH_MeshEditor::ConvertFromQuadratic() bool SMESH_MeshEditor::ConvertFromQuadratic()
{ {
SMESHDS_Mesh* meshDS = GetMeshDS(); SMESHDS_Mesh* meshDS = GetMeshDS();
RemoveQuadNodeMap aRemoveNodeMap;
const TopoDS_Shape& aShape = meshDS->ShapeToMesh(); const TopoDS_Shape& aShape = meshDS->ShapeToMesh();
if ( !aShape.IsNull() && GetMesh()->GetSubMeshContaining(aShape) ) if ( !aShape.IsNull() && GetMesh()->GetSubMeshContaining(aShape) )
@ -6359,23 +6360,16 @@ bool SMESH_MeshEditor::ConvertFromQuadratic()
{ {
SMESHDS_SubMesh *sm = ((*itsub).second)->GetSubMeshDS(); SMESHDS_SubMesh *sm = ((*itsub).second)->GetSubMeshDS();
if( sm ) if( sm )
RemoveQuadElem( sm, sm->GetElements(), aRemoveNodeMap ); RemoveQuadElem( sm, sm->GetElements(), itsub->second->GetId() );
} }
SMESHDS_SubMesh *Sm = aSubMesh->GetSubMeshDS(); SMESHDS_SubMesh *Sm = aSubMesh->GetSubMeshDS();
if( Sm ) if( Sm )
RemoveQuadElem( Sm, Sm->GetElements(), aRemoveNodeMap ); RemoveQuadElem( Sm, Sm->GetElements(), aSubMesh->GetId() );
} }
else else
{ {
SMESHDS_SubMesh *aSM = 0; SMESHDS_SubMesh *aSM = 0;
RemoveQuadElem( aSM, meshDS->elementsIterator(), aRemoveNodeMap ); RemoveQuadElem( aSM, meshDS->elementsIterator(), 0 );
}
//remove all quadratic nodes
ItRemoveQuadNodeMap itRNM = aRemoveNodeMap.begin();
for ( ; itRNM != aRemoveNodeMap.end(); itRNM++ )
{
meshDS->RemoveFreeNode( (*itRNM).first, (*itRNM).second );
} }
return true; return true;

View File

@ -43,12 +43,9 @@
#include <list> #include <list>
#include <map> #include <map>
typedef map<const SMDS_MeshElement*, typedef std::map<const SMDS_MeshElement*,
list<const SMDS_MeshElement*> > TElemOfElemListMap; std::list<const SMDS_MeshElement*> > TElemOfElemListMap;
typedef map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap; typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
typedef map<const SMDS_MeshNode*, SMESHDS_SubMesh*> RemoveQuadNodeMap;
typedef map<const SMDS_MeshNode*, SMESHDS_SubMesh*>::iterator ItRemoveQuadNodeMap;
class SMDS_MeshFace; class SMDS_MeshFace;
class SMDS_MeshNode; class SMDS_MeshNode;
@ -63,7 +60,7 @@ class gp_Pnt;
*/ */
// ============================================================ // ============================================================
template < class TMeshElem > template < class TMeshElem = SMDS_MeshElement>
struct TIDCompare { struct TIDCompare {
bool operator () (const TMeshElem* e1, const TMeshElem* e2) const bool operator () (const TMeshElem* e1, const TMeshElem* e2) const
{ return e1->GetID() < e2->GetID(); } { return e1->GetID() < e2->GetID(); }
@ -449,21 +446,21 @@ public:
SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); } SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
SMESH_SequenceOfElemPtr GetLastCreatedNodes() { return myLastCreatedNodes; } const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
SMESH_SequenceOfElemPtr GetLastCreatedElems() { return myLastCreatedElems; } const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
private: private:
void ConvertElemToQuadratic(SMESHDS_SubMesh *theSm, void ConvertElemToQuadratic(SMESHDS_SubMesh * theSm,
SMESH_MesherHelper* theHelper, SMESH_MesherHelper& theHelper,
const bool theForce3d); const bool theForce3d);
//Auxiliary function for "ConvertToQuadratic" is intended to convert //Auxiliary function for "ConvertToQuadratic" is intended to convert
//elements contained in submesh to quadratic //elements contained in submesh to quadratic
void RemoveQuadElem( SMESHDS_SubMesh *theSm, void RemoveQuadElem( SMESHDS_SubMesh * theSm,
SMDS_ElemIteratorPtr theItr, SMDS_ElemIteratorPtr theItr,
RemoveQuadNodeMap& theRemoveNodeMap); const int theShapeID);
//Auxiliary function for "ConvertFromQuadratic" is intended to convert quadratic //Auxiliary function for "ConvertFromQuadratic" is intended to convert quadratic
//element to ordinary and for removing quadratic nodes //element to ordinary and for removing quadratic nodes