1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : StdMeshers_QuadToTriaAdaptor.cxx
22 // Created : Wen May 07 16:37:07 2008
23 // Author : Sergey KUUL (skl)
25 #include "StdMeshers_QuadToTriaAdaptor.hxx"
27 #include "SMDS_SetIterator.hxx"
29 #include "SMESHDS_GroupBase.hxx"
30 #include "SMESH_Algo.hxx"
31 #include "SMESH_Group.hxx"
32 #include "SMESH_MeshAlgos.hxx"
33 #include "SMESH_MesherHelper.hxx"
35 #include <IntAna_IntConicQuad.hxx>
36 #include <IntAna_Quadric.hxx>
37 #include <TColgp_HArray1OfPnt.hxx>
38 #include <TColgp_HArray1OfVec.hxx>
39 #include <TColgp_HSequenceOfPnt.hxx>
40 #include <TopExp_Explorer.hxx>
44 #include "utilities.h"
52 enum EQuadNature { NOT_QUAD, QUAD, DEGEN_QUAD, PYRAM_APEX = 4, TRIA_APEX = 0 };
54 // std-like iterator used to get coordinates of nodes of mesh element
55 typedef SMDS_StdIterator< SMESH_TNodeXYZ, SMDS_ElemIteratorPtr > TXyzIterator;
59 //================================================================================
61 * \brief Return true if two nodes of triangles are equal
63 //================================================================================
65 bool EqualTriangles(const SMDS_MeshElement* F1,const SMDS_MeshElement* F2)
68 ( F1->GetNode(1)==F2->GetNode(2) && F1->GetNode(2)==F2->GetNode(1) ) ||
69 ( F1->GetNode(1)==F2->GetNode(1) && F1->GetNode(2)==F2->GetNode(2) );
71 //================================================================================
73 * \brief Return true if two adjacent pyramids are too close one to another
74 * so that a tetrahedron to built between them would have too poor quality
76 //================================================================================
78 bool TooCloseAdjacent( const SMDS_MeshElement* PrmI,
79 const SMDS_MeshElement* PrmJ,
82 const SMDS_MeshNode* nApexI = PrmI->GetNode(4);
83 const SMDS_MeshNode* nApexJ = PrmJ->GetNode(4);
84 if ( nApexI == nApexJ ||
85 nApexI->getshapeId() != nApexJ->getshapeId() )
88 // Find two common base nodes and their indices within PrmI and PrmJ
89 const SMDS_MeshNode* baseNodes[2] = { 0,0 };
90 int baseNodesIndI[2], baseNodesIndJ[2];
91 for ( int i = 0; i < 4 ; ++i )
93 int j = PrmJ->GetNodeIndex( PrmI->GetNode(i));
96 int ind = baseNodes[0] ? 1:0;
97 if ( baseNodes[ ind ])
98 return false; // pyramids with a common base face
99 baseNodes [ ind ] = PrmI->GetNode(i);
100 baseNodesIndI[ ind ] = i;
101 baseNodesIndJ[ ind ] = j;
104 if ( !baseNodes[1] ) return false; // not adjacent
106 // Get normals of triangles sharing baseNodes
107 gp_XYZ apexI = SMESH_TNodeXYZ( nApexI );
108 gp_XYZ apexJ = SMESH_TNodeXYZ( nApexJ );
109 gp_XYZ base1 = SMESH_TNodeXYZ( baseNodes[0]);
110 gp_XYZ base2 = SMESH_TNodeXYZ( baseNodes[1]);
111 gp_Vec baseVec( base1, base2 );
112 gp_Vec baI( base1, apexI );
113 gp_Vec baJ( base1, apexJ );
114 gp_Vec nI = baseVec.Crossed( baI );
115 gp_Vec nJ = baseVec.Crossed( baJ );
117 // Check angle between normals
118 double angle = nI.Angle( nJ );
119 bool tooClose = ( angle < 15. * M_PI / 180. );
121 // Check if pyramids collide
122 if ( !tooClose && baI * baJ > 0 )
124 // find out if nI points outside of PrmI or inside
125 int dInd = baseNodesIndI[1] - baseNodesIndI[0];
126 bool isOutI = ( abs(dInd)==1 ) ? dInd < 0 : dInd > 0;
128 // find out sign of projection of nJ to baI
129 double proj = baI * nJ;
131 tooClose = isOutI ? proj > 0 : proj < 0;
134 // Check if PrmI and PrmJ are in same domain
135 if ( tooClose && !hasShape )
137 // check order of baseNodes within pyramids, it must be opposite
139 dInd = baseNodesIndI[1] - baseNodesIndI[0];
140 bool isOutI = ( abs(dInd)==1 ) ? dInd < 0 : dInd > 0;
141 dInd = baseNodesIndJ[1] - baseNodesIndJ[0];
142 bool isOutJ = ( abs(dInd)==1 ) ? dInd < 0 : dInd > 0;
143 if ( isOutJ == isOutI )
144 return false; // other domain
146 // direct both normals outside pyramid
147 ( isOutI ? nJ : nI ).Reverse();
149 // check absence of a face separating domains between pyramids
150 TIDSortedElemSet emptySet, avoidSet;
152 while ( const SMDS_MeshElement* f =
153 SMESH_MeshAlgos::FindFaceInSet( baseNodes[0], baseNodes[1],
154 emptySet, avoidSet, &i1, &i2 ))
156 avoidSet.insert( f );
158 // face node other than baseNodes
159 int otherNodeInd = 0;
160 while ( otherNodeInd == i1 || otherNodeInd == i2 ) otherNodeInd++;
161 const SMDS_MeshNode* otherFaceNode = f->GetNode( otherNodeInd );
163 if ( otherFaceNode == nApexI || otherFaceNode == nApexJ )
164 continue; // f is a temporary triangle
166 // check if f is a base face of either of pyramids
167 if ( f->NbCornerNodes() == 4 &&
168 ( PrmI->GetNodeIndex( otherFaceNode ) >= 0 ||
169 PrmJ->GetNodeIndex( otherFaceNode ) >= 0 ))
170 continue; // f is a base quadrangle
172 // check projections of face direction (baOFN) to triange normals (nI and nJ)
173 gp_Vec baOFN( base1, SMESH_TNodeXYZ( otherFaceNode ));
174 if ( nI * baOFN > 0 && nJ * baOFN > 0 )
176 tooClose = false; // f is between pyramids
185 //================================================================================
187 * \brief Move medium nodes of merged quadratic pyramids
189 //================================================================================
191 void UpdateQuadraticPyramids(const set<const SMDS_MeshNode*>& commonApex,
192 SMESHDS_Mesh* meshDS)
194 typedef SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > TStdElemIterator;
195 TStdElemIterator itEnd;
197 // shift of node index to get medium nodes between the 4 base nodes and the apex
198 const int base2MediumShift = 9;
200 set<const SMDS_MeshNode*>::const_iterator nIt = commonApex.begin();
201 for ( ; nIt != commonApex.end(); ++nIt )
203 SMESH_TNodeXYZ apex( *nIt );
205 vector< const SMDS_MeshElement* > pyrams // pyramids sharing the apex node
206 ( TStdElemIterator( apex._node->GetInverseElementIterator( SMDSAbs_Volume )), itEnd );
208 // Select medium nodes to keep and medium nodes to remove
210 typedef map < const SMDS_MeshNode*, const SMDS_MeshNode*, TIDCompare > TN2NMap;
211 TN2NMap base2medium; // to keep
212 vector< const SMDS_MeshNode* > nodesToRemove;
214 for ( unsigned i = 0; i < pyrams.size(); ++i )
215 for ( int baseIndex = 0; baseIndex < PYRAM_APEX; ++baseIndex )
217 SMESH_TNodeXYZ base = pyrams[i]->GetNode( baseIndex );
218 const SMDS_MeshNode* medium = pyrams[i]->GetNode( baseIndex + base2MediumShift );
219 TN2NMap::iterator b2m = base2medium.insert( make_pair( base._node, medium )).first;
220 if ( b2m->second != medium )
222 nodesToRemove.push_back( medium );
226 // move the kept medium node
227 gp_XYZ newXYZ = 0.5 * ( apex + base );
228 meshDS->MoveNode( medium, newXYZ.X(), newXYZ.Y(), newXYZ.Z() );
232 // Within pyramids, replace nodes to remove by nodes to keep
234 for ( unsigned i = 0; i < pyrams.size(); ++i )
236 vector< const SMDS_MeshNode* > nodes( pyrams[i]->begin_nodes(),
237 pyrams[i]->end_nodes() );
238 for ( int baseIndex = 0; baseIndex < PYRAM_APEX; ++baseIndex )
240 const SMDS_MeshNode* base = pyrams[i]->GetNode( baseIndex );
241 nodes[ baseIndex + base2MediumShift ] = base2medium[ base ];
243 meshDS->ChangeElementNodes( pyrams[i], &nodes[0], nodes.size());
246 // Remove the replaced nodes
248 if ( !nodesToRemove.empty() )
250 SMESHDS_SubMesh * sm = meshDS->MeshElements( nodesToRemove[0]->getshapeId() );
251 for ( unsigned i = 0; i < nodesToRemove.size(); ++i )
252 meshDS->RemoveFreeNode( nodesToRemove[i], sm, /*fromGroups=*/false);
259 //================================================================================
261 * \brief Merge the two pyramids (i.e. fuse their apex) and others already merged with them
263 //================================================================================
265 void StdMeshers_QuadToTriaAdaptor::MergePiramids( const SMDS_MeshElement* PrmI,
266 const SMDS_MeshElement* PrmJ,
267 set<const SMDS_MeshNode*> & nodesToMove)
269 const SMDS_MeshNode* Nrem = PrmJ->GetNode(4); // node to remove
270 //int nbJ = Nrem->NbInverseElements( SMDSAbs_Volume );
271 SMESH_TNodeXYZ Pj( Nrem );
273 // an apex node to make common to all merged pyramids
274 SMDS_MeshNode* CommonNode = const_cast<SMDS_MeshNode*>(PrmI->GetNode(4));
275 if ( CommonNode == Nrem ) return; // already merged
276 //int nbI = CommonNode->NbInverseElements( SMDSAbs_Volume );
277 SMESH_TNodeXYZ Pi( CommonNode );
278 gp_XYZ Pnew = /*( nbI*Pi + nbJ*Pj ) / (nbI+nbJ);*/ 0.5 * ( Pi + Pj );
279 CommonNode->setXYZ( Pnew.X(), Pnew.Y(), Pnew.Z() );
281 nodesToMove.insert( CommonNode );
282 nodesToMove.erase ( Nrem );
284 typedef SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > TStdElemIterator;
285 TStdElemIterator itEnd;
287 // find and remove coincided faces of merged pyramids
288 vector< const SMDS_MeshElement* > inverseElems
289 // copy inverse elements to avoid iteration on changing container
290 ( TStdElemIterator( CommonNode->GetInverseElementIterator(SMDSAbs_Face)), itEnd);
291 for ( unsigned i = 0; i < inverseElems.size(); ++i )
293 const SMDS_MeshElement* FI = inverseElems[i];
294 const SMDS_MeshElement* FJEqual = 0;
295 SMDS_ElemIteratorPtr triItJ = Nrem->GetInverseElementIterator(SMDSAbs_Face);
296 while ( !FJEqual && triItJ->more() )
298 const SMDS_MeshElement* FJ = triItJ->next();
299 if ( EqualTriangles( FJ, FI ))
304 removeTmpElement( FI );
305 removeTmpElement( FJEqual );
306 myRemovedTrias.insert( FI );
307 myRemovedTrias.insert( FJEqual );
311 // set the common apex node to pyramids and triangles merged with J
312 inverseElems.assign( TStdElemIterator( Nrem->GetInverseElementIterator()), itEnd );
313 for ( unsigned i = 0; i < inverseElems.size(); ++i )
315 const SMDS_MeshElement* elem = inverseElems[i];
316 vector< const SMDS_MeshNode* > nodes( elem->begin_nodes(), elem->end_nodes() );
317 nodes[ elem->GetType() == SMDSAbs_Volume ? PYRAM_APEX : TRIA_APEX ] = CommonNode;
318 GetMeshDS()->ChangeElementNodes( elem, &nodes[0], nodes.size());
320 ASSERT( Nrem->NbInverseElements() == 0 );
321 GetMeshDS()->RemoveFreeNode( Nrem,
322 GetMeshDS()->MeshElements( Nrem->getshapeId()),
323 /*fromGroups=*/false);
326 //================================================================================
328 * \brief Merges adjacent pyramids
330 //================================================================================
332 void StdMeshers_QuadToTriaAdaptor::MergeAdjacent(const SMDS_MeshElement* PrmI,
333 set<const SMDS_MeshNode*>& nodesToMove)
335 TIDSortedElemSet adjacentPyrams;
336 bool mergedPyrams = false;
337 for(int k=0; k<4; k++) // loop on 4 base nodes of PrmI
339 const SMDS_MeshNode* n = PrmI->GetNode(k);
340 SMDS_ElemIteratorPtr vIt = n->GetInverseElementIterator( SMDSAbs_Volume );
341 while ( vIt->more() )
343 const SMDS_MeshElement* PrmJ = vIt->next();
344 if ( PrmJ->NbCornerNodes() != 5 || !adjacentPyrams.insert( PrmJ ).second )
346 if ( PrmI != PrmJ && TooCloseAdjacent( PrmI, PrmJ, GetMesh()->HasShapeToMesh() ))
348 MergePiramids( PrmI, PrmJ, nodesToMove );
350 // container of inverse elements can change
351 vIt = n->GetInverseElementIterator( SMDSAbs_Volume );
357 TIDSortedElemSet::iterator prm;
358 for (prm = adjacentPyrams.begin(); prm != adjacentPyrams.end(); ++prm)
359 MergeAdjacent( *prm, nodesToMove );
363 //================================================================================
367 //================================================================================
369 StdMeshers_QuadToTriaAdaptor::StdMeshers_QuadToTriaAdaptor():
374 //================================================================================
378 //================================================================================
380 StdMeshers_QuadToTriaAdaptor::~StdMeshers_QuadToTriaAdaptor()
382 // temporary faces are deleted by ~SMESH_ProxyMesh()
383 if ( myElemSearcher ) delete myElemSearcher;
387 //=======================================================================
388 //function : FindBestPoint
389 //purpose : Return a point P laying on the line (PC,V) so that triangle
390 // (P, P1, P2) to be equilateral as much as possible
391 // V - normal to (P1,P2,PC)
392 //=======================================================================
394 static gp_Pnt FindBestPoint(const gp_Pnt& P1, const gp_Pnt& P2,
395 const gp_Pnt& PC, const gp_Vec& V)
398 const double a = P1.Distance(P2);
399 const double b = P1.Distance(PC);
400 const double c = P2.Distance(PC);
404 // find shift along V in order a to became equal to (b+c)/2
405 const double Vsize = V.Magnitude();
406 if ( fabs( Vsize ) > std::numeric_limits<double>::min() )
408 const double shift = sqrt( a*a + (b*b-c*c)*(b*b-c*c)/16/a/a - (b*b+c*c)/2 );
409 Pbest.ChangeCoord() += shift * V.XYZ() / Vsize;
415 //=======================================================================
416 //function : HasIntersection3
417 //purpose : Auxilare for HasIntersection()
418 // find intersection point between triangle (P1,P2,P3)
419 // and segment [PC,P]
420 //=======================================================================
422 static bool HasIntersection3(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint,
423 const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3)
425 //cout<<"HasIntersection3"<<endl;
426 //cout<<" PC("<<PC.X()<<","<<PC.Y()<<","<<PC.Z()<<")"<<endl;
427 //cout<<" P("<<P.X()<<","<<P.Y()<<","<<P.Z()<<")"<<endl;
428 //cout<<" P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
429 //cout<<" P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
430 //cout<<" P3("<<P3.X()<<","<<P3.Y()<<","<<P3.Z()<<")"<<endl;
433 IntAna_Quadric IAQ(gp_Pln(P1,VP1.Crossed(VP2)));
434 IntAna_IntConicQuad IAICQ(gp_Lin(PC,gp_Dir(gp_Vec(PC,P))),IAQ);
436 if( IAICQ.IsInQuadric() )
438 if( IAICQ.NbPoints() == 1 ) {
439 gp_Pnt PIn = IAICQ.Point(1);
440 const double preci = 1.e-10 * P.Distance(PC);
441 // check if this point is internal for segment [PC,P]
443 ( (PC.X()-PIn.X())*(P.X()-PIn.X()) > preci ) ||
444 ( (PC.Y()-PIn.Y())*(P.Y()-PIn.Y()) > preci ) ||
445 ( (PC.Z()-PIn.Z())*(P.Z()-PIn.Z()) > preci );
449 // check if this point is internal for triangle (P1,P2,P3)
453 if( V1.Magnitude()<preci ||
454 V2.Magnitude()<preci ||
455 V3.Magnitude()<preci ) {
459 const double angularTol = 1e-6;
460 gp_Vec VC1 = V1.Crossed(V2);
461 gp_Vec VC2 = V2.Crossed(V3);
462 gp_Vec VC3 = V3.Crossed(V1);
463 if(VC1.Magnitude()<gp::Resolution()) {
464 if(VC2.IsOpposite(VC3,angularTol)) {
468 else if(VC2.Magnitude()<gp::Resolution()) {
469 if(VC1.IsOpposite(VC3,angularTol)) {
473 else if(VC3.Magnitude()<gp::Resolution()) {
474 if(VC1.IsOpposite(VC2,angularTol)) {
479 if( VC1.IsOpposite(VC2,angularTol) || VC1.IsOpposite(VC3,angularTol) ||
480 VC2.IsOpposite(VC3,angularTol) ) {
492 //=======================================================================
493 //function : HasIntersection
494 //purpose : Auxilare for CheckIntersection()
495 //=======================================================================
497 static bool HasIntersection(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint,
498 Handle(TColgp_HSequenceOfPnt)& aContour)
500 if(aContour->Length()==3) {
501 return HasIntersection3( P, PC, Pint, aContour->Value(1),
502 aContour->Value(2), aContour->Value(3) );
506 if( (aContour->Value(1).Distance(aContour->Value(2)) > 1.e-6) &&
507 (aContour->Value(1).Distance(aContour->Value(3)) > 1.e-6) &&
508 (aContour->Value(2).Distance(aContour->Value(3)) > 1.e-6) ) {
509 check = HasIntersection3( P, PC, Pint, aContour->Value(1),
510 aContour->Value(2), aContour->Value(3) );
512 if(check) return true;
513 if( (aContour->Value(1).Distance(aContour->Value(4)) > 1.e-6) &&
514 (aContour->Value(1).Distance(aContour->Value(3)) > 1.e-6) &&
515 (aContour->Value(4).Distance(aContour->Value(3)) > 1.e-6) ) {
516 check = HasIntersection3( P, PC, Pint, aContour->Value(1),
517 aContour->Value(3), aContour->Value(4) );
519 if(check) return true;
525 //================================================================================
527 * \brief Checks if a line segment (P,PC) intersects any mesh face.
528 * \param P - first segment end
529 * \param PC - second segment end (it is a gravity center of quadrangle)
530 * \param Pint - (out) intersection point
531 * \param aMesh - mesh
532 * \param aShape - shape to check faces on
533 * \param NotCheckedFace - mesh face not to check
534 * \retval bool - true if there is an intersection
536 //================================================================================
538 bool StdMeshers_QuadToTriaAdaptor::CheckIntersection (const gp_Pnt& P,
542 const TopoDS_Shape& aShape,
543 const SMDS_MeshElement* NotCheckedFace)
545 if ( !myElemSearcher )
546 myElemSearcher = SMESH_MeshAlgos::GetElementSearcher( *aMesh.GetMeshDS() );
547 SMESH_ElementSearcher* searcher = const_cast<SMESH_ElementSearcher*>(myElemSearcher);
549 //SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
550 //cout<<" CheckIntersection: meshDS->NbFaces() = "<<meshDS->NbFaces()<<endl;
552 double dist = RealLast(); // find intersection closest to the segment
555 gp_Ax1 line( P, gp_Vec(P,PC));
556 vector< const SMDS_MeshElement* > suspectElems;
557 searcher->GetElementsNearLine( line, SMDSAbs_Face, suspectElems);
559 for ( int i = 0; i < suspectElems.size(); ++i )
561 const SMDS_MeshElement* face = suspectElems[i];
562 if ( face == NotCheckedFace ) continue;
563 Handle(TColgp_HSequenceOfPnt) aContour = new TColgp_HSequenceOfPnt;
564 for ( int i = 0; i < face->NbCornerNodes(); ++i )
565 aContour->Append( SMESH_TNodeXYZ( face->GetNode(i) ));
566 if( HasIntersection(P, PC, Pres, aContour) ) {
568 double tmp = PC.Distance(Pres);
578 //================================================================================
580 * \brief Prepare data for the given face
581 * \param PN - coordinates of face nodes
582 * \param VN - cross products of vectors (PC-PN(i)) ^ (PC-PN(i+1))
583 * \param FNodes - face nodes
584 * \param PC - gravity center of nodes
585 * \param VNorm - face normal (sum of VN)
586 * \param volumes - two volumes sharing the given face, the first is in VNorm direction
587 * \retval int - 0 if given face is not quad,
588 * 1 if given face is quad,
589 * 2 if given face is degenerate quad (two nodes are coincided)
591 //================================================================================
593 int StdMeshers_QuadToTriaAdaptor::Preparation(const SMDS_MeshElement* face,
594 Handle(TColgp_HArray1OfPnt)& PN,
595 Handle(TColgp_HArray1OfVec)& VN,
596 vector<const SMDS_MeshNode*>& FNodes,
599 const SMDS_MeshElement** volumes)
601 if( face->NbCornerNodes() != 4 )
607 gp_XYZ xyzC(0., 0., 0.);
608 for ( i = 0; i < 4; ++i )
610 gp_XYZ p = SMESH_TNodeXYZ( FNodes[i] = face->GetNode(i) );
611 PN->SetValue( i+1, p );
622 if( PN->Value(i).Distance(PN->Value(j)) < 1.e-6 )
627 //int deg_num = IsDegenarate(PN);
631 //cout<<"find degeneration"<<endl;
633 gp_Pnt Pdeg = PN->Value(i);
635 list< const SMDS_MeshNode* >::iterator itdg = myDegNodes.begin();
636 const SMDS_MeshNode* DegNode = 0;
637 for(; itdg!=myDegNodes.end(); itdg++) {
638 const SMDS_MeshNode* N = (*itdg);
639 gp_Pnt Ptmp(N->X(),N->Y(),N->Z());
640 if(Pdeg.Distance(Ptmp)<1.e-6) {
642 //DegNode = const_cast<SMDS_MeshNode*>(N);
647 DegNode = FNodes[i-1];
648 myDegNodes.push_back(DegNode);
651 FNodes[i-1] = DegNode;
654 PN->SetValue(i,PN->Value(i+1));
655 FNodes[i-1] = FNodes[i];
660 PN->SetValue(nbp+1,PN->Value(1));
661 FNodes[nbp] = FNodes[0];
662 // find normal direction
663 gp_Vec V1(PC,PN->Value(nbp));
664 gp_Vec V2(PC,PN->Value(1));
665 VNorm = V1.Crossed(V2);
666 VN->SetValue(nbp,VNorm);
667 for(i=1; i<nbp; i++) {
668 V1 = gp_Vec(PC,PN->Value(i));
669 V2 = gp_Vec(PC,PN->Value(i+1));
670 gp_Vec Vtmp = V1.Crossed(V2);
671 VN->SetValue(i,Vtmp);
675 // find volumes sharing the face
678 volumes[0] = volumes[1] = 0;
679 SMDS_ElemIteratorPtr vIt = FNodes[0]->GetInverseElementIterator( SMDSAbs_Volume );
680 while ( vIt->more() )
682 const SMDS_MeshElement* vol = vIt->next();
683 bool volSharesAllNodes = true;
684 for ( int i = 1; i < face->NbNodes() && volSharesAllNodes; ++i )
685 volSharesAllNodes = ( vol->GetNodeIndex( FNodes[i] ) >= 0 );
686 if ( volSharesAllNodes )
687 volumes[ volumes[0] ? 1 : 0 ] = vol;
688 // we could additionally check that vol has all FNodes in its one face using SMDS_VolumeTool
690 // define volume position relating to the face normal
694 SMDS_ElemIteratorPtr nodeIt = volumes[0]->nodesIterator();
696 volGC = accumulate( TXyzIterator(nodeIt), TXyzIterator(), volGC ) / volumes[0]->NbNodes();
698 if ( VNorm * gp_Vec( PC, volGC ) < 0 )
699 swap( volumes[0], volumes[1] );
703 //cout<<" VNorm("<<VNorm.X()<<","<<VNorm.Y()<<","<<VNorm.Z()<<")"<<endl;
704 return hasdeg ? DEGEN_QUAD : QUAD;
708 //=======================================================================
711 //=======================================================================
713 bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh,
714 const TopoDS_Shape& aShape,
715 SMESH_ProxyMesh* aProxyMesh)
717 SMESH_ProxyMesh::setMesh( aMesh );
719 if ( aShape.ShapeType() != TopAbs_SOLID &&
720 aShape.ShapeType() != TopAbs_SHELL )
725 vector<const SMDS_MeshElement*> myPyramids;
727 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
728 SMESH_MesherHelper helper(aMesh);
729 helper.IsQuadraticSubMesh(aShape);
730 helper.SetElementsOnShape( true );
732 if ( myElemSearcher ) delete myElemSearcher;
734 myElemSearcher = SMESH_MeshAlgos::GetElementSearcher( *meshDS, aProxyMesh->GetFaces(aShape));
736 myElemSearcher = SMESH_MeshAlgos::GetElementSearcher( *meshDS );
738 const SMESHDS_SubMesh * aSubMeshDSFace;
739 Handle(TColgp_HArray1OfPnt) PN = new TColgp_HArray1OfPnt(1,5);
740 Handle(TColgp_HArray1OfVec) VN = new TColgp_HArray1OfVec(1,4);
741 vector<const SMDS_MeshNode*> FNodes(5);
745 for (TopExp_Explorer exp(aShape,TopAbs_FACE);exp.More();exp.Next())
747 const TopoDS_Shape& aShapeFace = exp.Current();
749 aSubMeshDSFace = aProxyMesh->GetSubMesh( aShapeFace );
751 aSubMeshDSFace = meshDS->MeshElements( aShapeFace );
753 vector<const SMDS_MeshElement*> trias, quads;
754 bool hasNewTrias = false;
756 if ( aSubMeshDSFace )
759 if ( helper.NbAncestors( aShapeFace, aMesh, aShape.ShapeType() ) > 1 )
760 isRev = helper.IsReversedSubMesh( TopoDS::Face(aShapeFace) );
762 SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
763 while ( iteratorElem->more() ) // loop on elements on a geometrical face
765 const SMDS_MeshElement* face = iteratorElem->next();
766 // preparation step to get face info
767 int stat = Preparation(face, PN, VN, FNodes, PC, VNorm);
772 trias.push_back( face );
778 // add triangles to result map
779 SMDS_MeshFace* NewFace;
781 NewFace = meshDS->AddFace( FNodes[0], FNodes[1], FNodes[2] );
783 NewFace = meshDS->AddFace( FNodes[0], FNodes[2], FNodes[1] );
784 storeTmpElement( NewFace );
785 trias.push_back ( NewFace );
786 quads.push_back( face );
793 if(!isRev) VNorm.Reverse();
794 double xc = 0., yc = 0., zc = 0.;
799 Pbest = FindBestPoint(PN->Value(i), PN->Value(i+1), PC, VN->Value(i).Reversed());
801 Pbest = FindBestPoint(PN->Value(i), PN->Value(i+1), PC, VN->Value(i));
806 gp_Pnt PCbest(xc/4., yc/4., zc/4.);
809 double height = PCbest.Distance(PC);
811 // create new PCbest using a bit shift along VNorm
812 PCbest = PC.XYZ() + VNorm.XYZ() * 0.001;
815 // check possible intersection with other faces
817 bool check = CheckIntersection(PCbest, PC, Pint, aMesh, aShape, face);
819 //cout<<"--PC("<<PC.X()<<","<<PC.Y()<<","<<PC.Z()<<")"<<endl;
820 //cout<<" PCbest("<<PCbest.X()<<","<<PCbest.Y()<<","<<PCbest.Z()<<")"<<endl;
821 double dist = PC.Distance(Pint)/3.;
822 gp_Dir aDir(gp_Vec(PC,PCbest));
823 PCbest = PC.XYZ() + aDir.XYZ() * dist;
826 gp_Vec VB(PC,PCbest);
827 gp_Pnt PCbestTmp = PC.XYZ() + VB.XYZ() * 3.0;
828 check = CheckIntersection(PCbestTmp, PC, Pint, aMesh, aShape, face);
830 double dist = PC.Distance(Pint)/3.;
832 gp_Dir aDir(gp_Vec(PC,PCbest));
833 PCbest = PC.XYZ() + aDir.XYZ() * dist;
838 // create node for PCbest
839 SMDS_MeshNode* NewNode = helper.AddNode( PCbest.X(), PCbest.Y(), PCbest.Z() );
841 // add triangles to result map
844 trias.push_back ( meshDS->AddFace( NewNode, FNodes[i], FNodes[i+1] ));
845 storeTmpElement( trias.back() );
848 if ( isRev ) swap( FNodes[1], FNodes[3]);
849 SMDS_MeshVolume* aPyram =
850 helper.AddVolume( FNodes[0], FNodes[1], FNodes[2], FNodes[3], NewNode );
851 myPyramids.push_back(aPyram);
853 quads.push_back( face );
860 } // end loop on elements on a face submesh
862 bool sourceSubMeshIsProxy = false;
865 // move proxy sub-mesh from other proxy mesh to this
866 sourceSubMeshIsProxy = takeProxySubMesh( aShapeFace, aProxyMesh );
867 // move also tmp elements added in mesh
868 takeTmpElemsInMesh( aProxyMesh );
872 SMESH_ProxyMesh::SubMesh* prxSubMesh = getProxySubMesh( aShapeFace );
873 prxSubMesh->ChangeElements( trias.begin(), trias.end() );
875 // delete tmp quadrangles removed from aProxyMesh
876 if ( sourceSubMeshIsProxy )
878 for ( unsigned i = 0; i < quads.size(); ++i )
879 removeTmpElement( quads[i] );
881 delete myElemSearcher;
883 SMESH_MeshAlgos::GetElementSearcher( *meshDS, aProxyMesh->GetFaces(aShape));
887 } // end for(TopExp_Explorer exp(aShape,TopAbs_FACE);exp.More();exp.Next()) {
889 return Compute2ndPart(aMesh, myPyramids);
892 //================================================================================
894 * \brief Computes pyramids in mesh with no shape
896 //================================================================================
898 bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh)
900 SMESH_ProxyMesh::setMesh( aMesh );
901 SMESH_ProxyMesh::_allowedTypes.push_back( SMDSEntity_Triangle );
902 SMESH_ProxyMesh::_allowedTypes.push_back( SMDSEntity_Quad_Triangle );
903 if ( aMesh.NbQuadrangles() < 1 )
906 // find if there is a group of faces identified as skin faces, with normal going outside the volume
907 std::string groupName = "skinFaces";
908 SMESHDS_GroupBase* groupDS = 0;
909 SMESH_Mesh::GroupIteratorPtr groupIt = aMesh.GetGroups();
910 while ( groupIt->more() )
913 SMESH_Group * group = groupIt->next();
914 if ( !group ) continue;
915 groupDS = group->GetGroupDS();
916 if ( !groupDS || groupDS->IsEmpty() )
921 if (groupDS->GetType() != SMDSAbs_Face)
926 std::string grpName = group->GetName();
927 if (grpName == groupName)
929 MESSAGE("group skinFaces provided");
936 vector<const SMDS_MeshElement*> myPyramids;
937 SMESH_MesherHelper helper(aMesh);
938 helper.IsQuadraticSubMesh(aMesh.GetShapeToMesh());
939 helper.SetElementsOnShape( true );
941 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
942 SMESH_ProxyMesh::SubMesh* prxSubMesh = getProxySubMesh();
944 if ( !myElemSearcher )
945 myElemSearcher = SMESH_MeshAlgos::GetElementSearcher( *meshDS );
946 SMESH_ElementSearcher* searcher = const_cast<SMESH_ElementSearcher*>(myElemSearcher);
948 SMDS_FaceIteratorPtr fIt = meshDS->facesIterator(/*idInceasingOrder=*/true);
951 const SMDS_MeshElement* face = fIt->next();
952 if ( !face ) continue;
953 // retrieve needed information about a face
954 Handle(TColgp_HArray1OfPnt) PN = new TColgp_HArray1OfPnt(1,5);
955 Handle(TColgp_HArray1OfVec) VN = new TColgp_HArray1OfVec(1,4);
956 vector<const SMDS_MeshNode*> FNodes(5);
959 const SMDS_MeshElement* volumes[2];
960 int what = Preparation(face, PN, VN, FNodes, PC, VNorm, volumes);
961 if ( what == NOT_QUAD )
963 if ( volumes[0] && volumes[1] )
964 continue; // face is shared by two volumes - no space for a pyramid
966 if ( what == DEGEN_QUAD )
969 // add a triangle to the proxy mesh
970 SMDS_MeshFace* NewFace;
973 double tmp = PN->Value(1).Distance(PN->Value(2)) + PN->Value(2).Distance(PN->Value(3));
974 // far points in VNorm direction
975 gp_Pnt Ptmp1 = PC.XYZ() + VNorm.XYZ() * tmp * 1.e6;
976 gp_Pnt Ptmp2 = PC.XYZ() - VNorm.XYZ() * tmp * 1.e6;
977 // check intersection for Ptmp1 and Ptmp2
981 double dist1 = RealLast();
982 double dist2 = RealLast();
985 gp_Ax1 line( PC, VNorm );
986 vector< const SMDS_MeshElement* > suspectElems;
987 searcher->GetElementsNearLine( line, SMDSAbs_Face, suspectElems);
989 for ( int iF = 0; iF < suspectElems.size(); ++iF ) {
990 const SMDS_MeshElement* F = suspectElems[iF];
991 if(F==face) continue;
992 Handle(TColgp_HSequenceOfPnt) aContour = new TColgp_HSequenceOfPnt;
993 for ( int i = 0; i < 4; ++i )
994 aContour->Append( SMESH_TNodeXYZ( F->GetNode(i) ));
996 if( !volumes[0] && HasIntersection(Ptmp1, PC, PPP, aContour) ) {
998 double tmp = PC.Distance(PPP);
1004 if( !volumes[1] && HasIntersection(Ptmp2, PC, PPP, aContour) ) {
1006 double tmp = PC.Distance(PPP);
1014 if( IsOK1 && !IsOK2 ) {
1015 // using existed direction
1017 else if( !IsOK1 && IsOK2 ) {
1018 // using opposite direction
1021 else { // IsOK1 && IsOK2
1022 double tmp1 = PC.Distance(Pres1);
1023 double tmp2 = PC.Distance(Pres2);
1025 // using existed direction
1028 // using opposite direction
1033 NewFace = meshDS->AddFace( FNodes[0], FNodes[1], FNodes[2] );
1035 NewFace = meshDS->AddFace( FNodes[0], FNodes[2], FNodes[1] );
1036 storeTmpElement( NewFace );
1037 prxSubMesh->AddElement( NewFace );
1041 // Case of non-degenerated quadrangle
1043 // Find pyramid peak
1045 gp_XYZ PCbest(0., 0., 0.); // pyramid peak
1048 gp_Pnt Pbest = FindBestPoint(PN->Value(i), PN->Value(i+1), PC, VN->Value(i));
1049 PCbest += Pbest.XYZ();
1053 double height = PC.Distance(PCbest); // pyramid height to precise
1054 if ( height < 1.e-6 ) {
1055 // create new PCbest using a bit shift along VNorm
1056 PCbest = PC.XYZ() + VNorm.XYZ() * 0.001;
1057 height = PC.Distance(PCbest);
1058 if ( height < std::numeric_limits<double>::min() )
1059 return false; // batterfly element
1062 // Restrict pyramid height by intersection with other faces
1063 gp_Vec tmpDir(PC,PCbest); tmpDir.Normalize();
1064 double tmp = PN->Value(1).Distance(PN->Value(3)) + PN->Value(2).Distance(PN->Value(4));
1065 // far points: in (PC, PCbest) direction and vice-versa
1066 gp_Pnt farPnt[2] = { PC.XYZ() + tmpDir.XYZ() * tmp * 1.e6,
1067 PC.XYZ() - tmpDir.XYZ() * tmp * 1.e6 };
1068 // check intersection for farPnt1 and farPnt2
1069 bool intersected[2] = { false, false };
1070 double dist [2] = { RealLast(), RealLast() };
1073 gp_Ax1 line( PC, tmpDir );
1074 vector< const SMDS_MeshElement* > suspectElems;
1075 searcher->GetElementsNearLine( line, SMDSAbs_Face, suspectElems);
1077 for ( int iF = 0; iF < suspectElems.size(); ++iF )
1079 const SMDS_MeshElement* F = suspectElems[iF];
1080 if(F==face) continue;
1081 Handle(TColgp_HSequenceOfPnt) aContour = new TColgp_HSequenceOfPnt;
1082 int nbN = F->NbNodes() / ( F->IsQuadratic() ? 2 : 1 );
1083 for ( i = 0; i < nbN; ++i )
1084 aContour->Append( SMESH_TNodeXYZ( F->GetNode(i) ));
1086 for ( int isRev = 0; isRev < 2; ++isRev )
1088 if( !volumes[isRev] && HasIntersection(farPnt[isRev], PC, intP, aContour) ) {
1089 intersected[isRev] = true;
1090 double d = PC.Distance( intP );
1091 if( d < dist[isRev] )
1093 intPnt[isRev] = intP;
1100 // if the face belong to the group of skinFaces, do not build a pyramid outside
1101 if (groupDS && groupDS->Contains(face))
1103 intersected[0] = false;
1105 else if ( intersected[0] && intersected[1] ) // check if one of pyramids is in a hole
1107 gp_Pnt P ( PC.XYZ() + tmpDir.XYZ() * 0.5 * PC.Distance( intPnt[0] ));
1108 if ( searcher->GetPointState( P ) == TopAbs_OUT )
1109 intersected[0] = false;
1112 P = ( PC.XYZ() - tmpDir.XYZ() * 0.5 * PC.Distance( intPnt[1] ));
1113 if ( searcher->GetPointState( P ) == TopAbs_OUT )
1114 intersected[1] = false;
1118 // Create one or two pyramids
1120 for ( int isRev = 0; isRev < 2; ++isRev )
1122 if( !intersected[isRev] ) continue;
1123 double pyramidH = Min( height, PC.Distance(intPnt[isRev])/3.);
1124 PCbest = PC.XYZ() + tmpDir.XYZ() * (isRev ? -pyramidH : pyramidH);
1126 // create node for PCbest
1127 SMDS_MeshNode* NewNode = helper.AddNode( PCbest.X(), PCbest.Y(), PCbest.Z() );
1129 // add triangles to result map
1130 for(i=0; i<4; i++) {
1131 SMDS_MeshFace* NewFace;
1133 NewFace = meshDS->AddFace( NewNode, FNodes[i], FNodes[i+1] );
1135 NewFace = meshDS->AddFace( NewNode, FNodes[i+1], FNodes[i] );
1136 storeTmpElement( NewFace );
1137 prxSubMesh->AddElement( NewFace );
1140 SMDS_MeshVolume* aPyram;
1142 aPyram = helper.AddVolume( FNodes[0], FNodes[1], FNodes[2], FNodes[3], NewNode );
1144 aPyram = helper.AddVolume( FNodes[0], FNodes[3], FNodes[2], FNodes[1], NewNode );
1145 myPyramids.push_back(aPyram);
1147 } // end loop on all faces
1149 return Compute2ndPart(aMesh, myPyramids);
1152 //================================================================================
1154 * \brief Update created pyramids and faces to avoid their intersection
1156 //================================================================================
1158 bool StdMeshers_QuadToTriaAdaptor::Compute2ndPart(SMESH_Mesh& aMesh,
1159 const vector<const SMDS_MeshElement*>& myPyramids)
1161 if(myPyramids.empty())
1164 SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1165 int i, j, k, myShapeID = myPyramids[0]->GetNode(4)->getshapeId();
1167 if ( myElemSearcher ) delete myElemSearcher;
1168 myElemSearcher = SMESH_MeshAlgos::GetElementSearcher( *meshDS );
1169 SMESH_ElementSearcher* searcher = const_cast<SMESH_ElementSearcher*>(myElemSearcher);
1171 set<const SMDS_MeshNode*> nodesToMove;
1173 // check adjacent pyramids
1175 for ( i = 0; i < myPyramids.size(); ++i )
1177 const SMDS_MeshElement* PrmI = myPyramids[i];
1178 MergeAdjacent( PrmI, nodesToMove );
1181 // iterate on all pyramids
1182 for ( i = 0; i < myPyramids.size(); ++i )
1184 const SMDS_MeshElement* PrmI = myPyramids[i];
1186 // compare PrmI with all the rest pyramids
1188 // collect adjacent pyramids and nodes coordinates of PrmI
1189 set<const SMDS_MeshElement*> checkedPyrams;
1190 vector<gp_Pnt> PsI(5);
1191 for(k=0; k<5; k++) // loop on 4 base nodes of PrmI
1193 const SMDS_MeshNode* n = PrmI->GetNode(k);
1194 PsI[k] = SMESH_TNodeXYZ( n );
1195 SMDS_ElemIteratorPtr vIt = n->GetInverseElementIterator( SMDSAbs_Volume );
1196 while ( vIt->more() )
1198 const SMDS_MeshElement* PrmJ = vIt->next();
1199 if ( SMESH_MeshAlgos::GetCommonNodes( PrmI, PrmJ ).size() > 1 )
1200 checkedPyrams.insert( PrmJ );
1204 // check intersection with distant pyramids
1205 for(k=0; k<4; k++) // loop on 4 base nodes of PrmI
1207 gp_Vec Vtmp(PsI[k],PsI[4]);
1208 gp_Ax1 line( PsI[k], Vtmp );
1209 vector< const SMDS_MeshElement* > suspectPyrams;
1210 searcher->GetElementsNearLine( line, SMDSAbs_Volume, suspectPyrams);
1212 for ( j = 0; j < suspectPyrams.size(); ++j )
1214 const SMDS_MeshElement* PrmJ = suspectPyrams[j];
1215 if ( PrmJ == PrmI || PrmJ->NbCornerNodes() != 5 )
1217 if ( myShapeID != PrmJ->GetNode(4)->getshapeId())
1218 continue; // pyramid from other SOLID
1219 if ( PrmI->GetNode(4) == PrmJ->GetNode(4) )
1220 continue; // pyramids PrmI and PrmJ already merged
1221 if ( !checkedPyrams.insert( PrmJ ).second )
1222 continue; // already checked
1224 TXyzIterator xyzIt( PrmJ->nodesIterator() );
1225 vector<gp_Pnt> PsJ( xyzIt, TXyzIterator() );
1229 for(k=0; k<4 && !hasInt; k++) {
1230 gp_Vec Vtmp(PsI[k],PsI[4]);
1231 gp_Pnt Pshift = PsI[k].XYZ() + Vtmp.XYZ() * 0.01; // base node moved a bit to apex
1233 ( HasIntersection3( Pshift, PsI[4], Pint, PsJ[0], PsJ[1], PsJ[4]) ||
1234 HasIntersection3( Pshift, PsI[4], Pint, PsJ[1], PsJ[2], PsJ[4]) ||
1235 HasIntersection3( Pshift, PsI[4], Pint, PsJ[2], PsJ[3], PsJ[4]) ||
1236 HasIntersection3( Pshift, PsI[4], Pint, PsJ[3], PsJ[0], PsJ[4]) );
1238 for(k=0; k<4 && !hasInt; k++) {
1239 gp_Vec Vtmp(PsJ[k],PsJ[4]);
1240 gp_Pnt Pshift = PsJ[k].XYZ() + Vtmp.XYZ() * 0.01;
1242 ( HasIntersection3( Pshift, PsJ[4], Pint, PsI[0], PsI[1], PsI[4]) ||
1243 HasIntersection3( Pshift, PsJ[4], Pint, PsI[1], PsI[2], PsI[4]) ||
1244 HasIntersection3( Pshift, PsJ[4], Pint, PsI[2], PsI[3], PsI[4]) ||
1245 HasIntersection3( Pshift, PsJ[4], Pint, PsI[3], PsI[0], PsI[4]) );
1250 // count common nodes of base faces of two pyramids
1253 nbc += int ( PrmI->GetNodeIndex( PrmJ->GetNode(k) ) >= 0 );
1256 continue; // pyrams have a common base face
1260 // Merge the two pyramids and others already merged with them
1261 MergePiramids( PrmI, PrmJ, nodesToMove );
1265 // decrease height of pyramids
1266 gp_XYZ PCi(0,0,0), PCj(0,0,0);
1267 for(k=0; k<4; k++) {
1268 PCi += PsI[k].XYZ();
1269 PCj += PsJ[k].XYZ();
1272 gp_Vec VN1(PCi,PsI[4]);
1273 gp_Vec VN2(PCj,PsJ[4]);
1274 gp_Vec VI1(PCi,Pint);
1275 gp_Vec VI2(PCj,Pint);
1276 double ang1 = fabs(VN1.Angle(VI1));
1277 double ang2 = fabs(VN2.Angle(VI2));
1278 double coef1 = 0.5 - (( ang1 < M_PI/3. ) ? cos(ang1)*0.25 : 0 );
1279 double coef2 = 0.5 - (( ang2 < M_PI/3. ) ? cos(ang2)*0.25 : 0 ); // cos(ang2) ?
1280 // double coef2 = 0.5;
1282 // coef2 -= cos(ang1)*0.25;
1286 SMDS_MeshNode* aNode1 = const_cast<SMDS_MeshNode*>(PrmI->GetNode(4));
1287 aNode1->setXYZ( PCi.X()+VN1.X(), PCi.Y()+VN1.Y(), PCi.Z()+VN1.Z() );
1288 SMDS_MeshNode* aNode2 = const_cast<SMDS_MeshNode*>(PrmJ->GetNode(4));
1289 aNode2->setXYZ( PCj.X()+VN2.X(), PCj.Y()+VN2.Y(), PCj.Z()+VN2.Z() );
1290 nodesToMove.insert( aNode1 );
1291 nodesToMove.insert( aNode2 );
1293 // fix intersections that could appear after apex movement
1294 MergeAdjacent( PrmI, nodesToMove );
1295 MergeAdjacent( PrmJ, nodesToMove );
1298 } // loop on suspectPyrams
1299 } // loop on 4 base nodes of PrmI
1301 } // loop on all pyramids
1303 if( !nodesToMove.empty() && !meshDS->IsEmbeddedMode() )
1305 set<const SMDS_MeshNode*>::iterator n = nodesToMove.begin();
1306 for ( ; n != nodesToMove.end(); ++n )
1307 meshDS->MoveNode( *n, (*n)->X(), (*n)->Y(), (*n)->Z() );
1310 // move medium nodes of merged quadratic pyramids
1311 if ( myPyramids[0]->IsQuadratic() )
1312 UpdateQuadraticPyramids( nodesToMove, GetMeshDS() );
1314 // erase removed triangles from the proxy mesh
1315 if ( !myRemovedTrias.empty() )
1317 for ( int i = 0; i <= meshDS->MaxShapeIndex(); ++i )
1318 if ( SMESH_ProxyMesh::SubMesh* sm = findProxySubMesh(i))
1320 vector<const SMDS_MeshElement *> faces;
1321 faces.reserve( sm->NbElements() );
1322 SMDS_ElemIteratorPtr fIt = sm->GetElements();
1323 while ( fIt->more() )
1325 const SMDS_MeshElement* tria = fIt->next();
1326 set<const SMDS_MeshElement*>::iterator rmTria = myRemovedTrias.find( tria );
1327 if ( rmTria != myRemovedTrias.end() )
1328 myRemovedTrias.erase( rmTria );
1330 faces.push_back( tria );
1332 sm->ChangeElements( faces.begin(), faces.end() );
1338 delete myElemSearcher;