From: eap Date: Wed, 26 Apr 2006 12:10:22 +0000 (+0000) Subject: add SMESH_MeshEditor::ConvertToQuadratic() method X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=eeafadb4cabde24e945b9a7e88172629ff671ce5;p=modules%2Fsmesh.git add SMESH_MeshEditor::ConvertToQuadratic() method --- diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index c90867192..172c4517d 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -680,6 +680,8 @@ module SMESH in double MaxAspectRatio, in Smooth_Method Method); + void ConvertToQuadratic(in boolean theForce3d); + void RenumberNodes(); void RenumberElements(); diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index dbc144929..8ac703787 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -954,6 +954,7 @@ int SMESH_MeshEditor::BestSplit (const SMDS_MeshElement* theQuad, return -1; } + //======================================================================= //function : AddToSameGroups //purpose : add elemToAdd to the groups the elemInGroups belongs to @@ -972,6 +973,25 @@ void SMESH_MeshEditor::AddToSameGroups (const SMDS_MeshElement* elemToAdd, } } +//======================================================================= +//function : RemoveElemFromGroups +//purpose : Remove removeelem to the groups the elemInGroups belongs to +//======================================================================= +void SMESH_MeshEditor::RemoveElemFromGroups (const SMDS_MeshElement* removeelem, + SMESHDS_Mesh * aMesh) +{ + const set& groups = aMesh->GetGroups(); + if (!groups.empty()) + { + set::const_iterator GrIt = groups.begin(); + for (; GrIt != groups.end(); GrIt++) + { + SMESHDS_Group* grp = dynamic_cast(*GrIt); + if (!grp || grp->IsEmpty()) continue; + grp->SMDSGroup().Remove(removeelem); + } + } +} //======================================================================= //function : QuadToTri //purpose : Cut quadrangles into triangles. @@ -5798,6 +5818,211 @@ void SMESH_MeshEditor::UpdateVolumes (const SMDS_MeshNode* theBetweenNode } } +//======================================================================= +//function : ConvertElemToQuadratic +//purpose : +//======================================================================= +void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh *theSm, + SMESH_MesherHelper* theHelper, + const bool theForce3d) +{ + if( !theSm ) return; + SMESHDS_Mesh* meshDS = GetMeshDS(); + SMDS_ElemIteratorPtr ElemItr = theSm->GetElements(); + while(ElemItr->more()) + { + const SMDS_MeshElement* elem = ElemItr->next(); + if( !elem ) continue; + + int id = elem->GetID(); + int nbNodes = elem->NbNodes(); + vector aNds (nbNodes); + + for(int i = 0; i < nbNodes; i++) + { + aNds[i] = elem->GetNode(i); + } + + SMDSAbs_ElementType aType = elem->GetType(); + + switch( aType ) + { + case SMDSAbs_Edge : + { + meshDS->RemoveFreeElement(elem, theSm); + const SMDS_QuadraticEdge* NewEdge = theHelper->AddQuadraticEdge(aNds[0], aNds[1], id, theForce3d); + AddToSameGroups(NewEdge, elem, meshDS); + break; + } + case SMDSAbs_Face : + { + if(elem->IsQuadratic()) continue; + + meshDS->RemoveFreeElement(elem, theSm); + SMDS_MeshFace * NewFace = 0; + switch(nbNodes) + { + case 3: + NewFace = theHelper->AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d); + break; + case 4: + NewFace = theHelper->AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d); + break; + default: + continue; + } + AddToSameGroups(NewFace, elem, meshDS); + break; + } + case SMDSAbs_Volume : + { + if( elem->IsQuadratic() ) continue; + + meshDS->RemoveFreeElement(elem, theSm); + SMDS_MeshVolume * NewVolume = 0; + switch(nbNodes) + { + case 4: + NewVolume = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], id, true); + break; + case 6: + NewVolume = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], aNds[4], aNds[5], id, true); + break; + case 8: + NewVolume = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], + aNds[4], aNds[5], aNds[6], aNds[7], id, true); + break; + default: + continue; + } + AddToSameGroups(NewVolume, elem, meshDS); + break; + } + default : + continue; + } + } +} + +//======================================================================= +//function : ConvertToQuadratic +//purpose : +//======================================================================= +void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d) +{ + SMESHDS_Mesh* meshDS = GetMeshDS(); + + SMESH_MesherHelper* aHelper = new SMESH_MesherHelper(*myMesh); + const TopoDS_Shape& aShape = meshDS->ShapeToMesh(); + + if ( !aShape.IsNull() && GetMesh()->GetSubMeshContaining(aShape) ) + { + SMESH_subMesh *aSubMesh = GetMesh()->GetSubMeshContaining(aShape); + + const map < int, SMESH_subMesh * >& aMapSM = aSubMesh->DependsOn(); + map < int, SMESH_subMesh * >::const_iterator itsub; + for (itsub = aMapSM.begin(); itsub != aMapSM.end(); itsub++) + { + SMESHDS_SubMesh *sm = ((*itsub).second)->GetSubMeshDS(); + aHelper->SetSubShape( (*itsub).second->GetSubShape() ); + ConvertElemToQuadratic(sm, aHelper, theForce3d); + } + aHelper->SetSubShape( aSubMesh->GetSubShape() ); + ConvertElemToQuadratic(aSubMesh->GetSubMeshDS(), aHelper, theForce3d); + } + else + { + SMDS_EdgeIteratorPtr aEdgeItr = meshDS->edgesIterator(); + while(aEdgeItr->more()) + { + const SMDS_MeshEdge* edge = aEdgeItr->next(); + if(edge) + { + int id = edge->GetID(); + const SMDS_MeshNode* n1 = edge->GetNode(0); + const SMDS_MeshNode* n2 = edge->GetNode(1); + + RemoveElemFromGroups (edge, meshDS); + meshDS->SMDS_Mesh::RemoveFreeElement(edge); + + const SMDS_QuadraticEdge* NewEdge = aHelper->AddQuadraticEdge(n1, n2, id, theForce3d); + AddToSameGroups(NewEdge, edge, meshDS); + } + } + SMDS_FaceIteratorPtr aFaceItr = meshDS->facesIterator(); + while(aFaceItr->more()) + { + const SMDS_MeshFace* face = aFaceItr->next(); + if(!face || face->IsQuadratic() ) continue; + + int id = face->GetID(); + int nbNodes = face->NbNodes(); + vector aNds (nbNodes); + + for(int i = 0; i < nbNodes; i++) + { + aNds[i] = face->GetNode(i); + } + + RemoveElemFromGroups (face, meshDS); + meshDS->SMDS_Mesh::RemoveFreeElement(face); + + SMDS_MeshFace * NewFace = 0; + switch(nbNodes) + { + case 3: + NewFace = aHelper->AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d); + break; + case 4: + NewFace = aHelper->AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d); + break; + default: + continue; + } + AddToSameGroups(NewFace, face, meshDS); + } + SMDS_VolumeIteratorPtr aVolumeItr = meshDS->volumesIterator(); + while(aVolumeItr->more()) + { + const SMDS_MeshVolume* volume = aVolumeItr->next(); + if(!volume || volume->IsQuadratic() ) continue; + + int id = volume->GetID(); + int nbNodes = volume->NbNodes(); + vector aNds (nbNodes); + + for(int i = 0; i < nbNodes; i++) + { + aNds[i] = volume->GetNode(i); + } + + RemoveElemFromGroups (volume, meshDS); + meshDS->SMDS_Mesh::RemoveFreeElement(volume); + + SMDS_MeshVolume * NewVolume = 0; + switch(nbNodes) + { + case 4: + NewVolume = aHelper->AddVolume(aNds[0], aNds[1], aNds[2], + aNds[3], id, true ); + break; + case 6: + NewVolume = aHelper->AddVolume(aNds[0], aNds[1], aNds[2], + aNds[3], aNds[4], aNds[5], id, true); + break; + case 8: + NewVolume = aHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], + aNds[4], aNds[5], aNds[6], aNds[7], id, true); + break; + default: + continue; + } + AddToSameGroups(NewVolume, volume, meshDS); + } + } + delete aHelper; +} + //======================================================================= //function : SewSideElements //purpose : diff --git a/src/SMESH/SMESH_MeshEditor.hxx b/src/SMESH/SMESH_MeshEditor.hxx index 3805bfd84..3c41fe01a 100644 --- a/src/SMESH/SMESH_MeshEditor.hxx +++ b/src/SMESH/SMESH_MeshEditor.hxx @@ -35,6 +35,7 @@ #include "SMESH_SequenceOfNode.hxx" #include "gp_Dir.hxx" #include "TColStd_HSequenceOfReal.hxx" +#include "SMESH_MesherHelper.hxx" #include #include @@ -339,6 +340,10 @@ class SMESH_MeshEditor { // insert theNodesToInsert into all volumes, containing link // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2. + void ConvertToQuadratic(const bool theForce3d); + //converts all mesh to quadratic one, deletes old elements, replacing + //them with quadratic ones with the same id. + // static int SortQuadNodes (const SMDS_Mesh * theMesh, // int theNodeIds[] ); // // Set 4 nodes of a quadrangle face in a good order. @@ -355,6 +360,10 @@ class SMESH_MeshEditor { SMESHDS_Mesh * aMesh); // Add elemToAdd to the groups the elemInGroups belongs to + static void RemoveElemFromGroups (const SMDS_MeshElement* removeelem, + SMESHDS_Mesh * aMesh); + // remove elemToAdd from the groups + static const SMDS_MeshElement* FindFaceInSet(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2, @@ -377,10 +386,16 @@ class SMESH_MeshEditor { // Return an index of the shape theElem is on // or zero if a shape not found - SMESH_Mesh * GetMesh() { return myMesh; } SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); } +private: + + void ConvertElemToQuadratic(SMESHDS_SubMesh *theSm, + SMESH_MesherHelper* theHelper, + const bool theForce3d); + //Auxiliary function for "ConvertToQuadratic" is intended to convert + //elements contained in submesh to quadratic private: diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index b6371d716..d85ee6295 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -1731,3 +1731,17 @@ SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements, aSecondNode1ToMerge, aSecondNode2ToMerge)); } + +//======================================================================= +//function : ConvertToQuadratic +//purpose : +//======================================================================= + +void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d) +{ + ::SMESH_MeshEditor anEditor( _myMesh ); + anEditor.ConvertToQuadratic(theForce3d); + // Update Python script + TPythonDump() << this << ".ConvertToQuadratic( " + << theForce3d << ") "; +} diff --git a/src/SMESH_I/SMESH_MeshEditor_i.hxx b/src/SMESH_I/SMESH_MeshEditor_i.hxx index 143ad199f..f5f12943c 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.hxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.hxx @@ -116,6 +116,9 @@ class SMESH_MeshEditor_i: public POA_SMESH::SMESH_MeshEditor SMESH::SMESH_MeshEditor::Smooth_Method Method, bool IsParametric); + + void ConvertToQuadratic(CORBA::Boolean Force3d); + void RenumberNodes(); void RenumberElements();