Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / StdMeshers / StdMeshers_QuadToTriaAdaptor.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMESH : implementaion of SMESH idl descriptions
23 // File      : StdMeshers_QuadToTriaAdaptor.cxx
24 // Module    : SMESH
25 // Created   : Wen May 07 16:37:07 2008
26 // Author    : Sergey KUUL (skl)
27 //
28 #include "StdMeshers_QuadToTriaAdaptor.hxx"
29
30 //#include <TColgp_HArray1OfPnt.hxx>
31 //#include <TColgp_HArray1OfVec.hxx>
32 #include <TopExp_Explorer.hxx>
33 #include <TopoDS.hxx>
34 #include <SMESH_Algo.hxx>
35 #include <TColgp_HSequenceOfPnt.hxx>
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TColStd_HSequenceOfInteger.hxx>
38 #include <IntAna_Quadric.hxx>
39 #include <IntAna_IntConicQuad.hxx>
40 #include <gp_Lin.hxx>
41 #include <gp_Pln.hxx>
42 #include <SMDS_FaceOfNodes.hxx>
43
44 #include <NCollection_Array1.hxx>
45 typedef NCollection_Array1<TColStd_SequenceOfInteger> StdMeshers_Array1OfSequenceOfInteger;
46
47
48 //=======================================================================
49 //function : StdMeshers_QuadToTriaAdaptor
50 //purpose  : 
51 //=======================================================================
52
53 StdMeshers_QuadToTriaAdaptor::StdMeshers_QuadToTriaAdaptor()
54 {
55 }
56
57
58 //================================================================================
59 /*!
60  * \brief Destructor
61  */
62 //================================================================================
63
64 StdMeshers_QuadToTriaAdaptor::~StdMeshers_QuadToTriaAdaptor()
65 {}
66
67
68 //=======================================================================
69 //function : FindBestPoint
70 //purpose  : Auxilare for Compute()
71 //           V - normal to (P1,P2,PC)
72 //=======================================================================
73 static gp_Pnt FindBestPoint(const gp_Pnt& P1, const gp_Pnt& P2,
74                             const gp_Pnt& PC, const gp_Vec& V)
75 {
76   double a = P1.Distance(P2);
77   double b = P1.Distance(PC);
78   double c = P2.Distance(PC);
79   if( a < (b+c)/2 )
80     return PC;
81   else {
82     // find shift along V in order to a became equal to (b+c)/2
83     double shift = sqrt( a*a + (b*b-c*c)*(b*b-c*c)/16/a/a - (b*b+c*c)/2 );
84     gp_Dir aDir(V);
85     gp_Pnt Pbest( PC.X() + aDir.X()*shift,  PC.Y() + aDir.Y()*shift,
86                   PC.Z() + aDir.Z()*shift );
87     return Pbest;
88   }
89 }
90
91
92 //=======================================================================
93 //function : HasIntersection3
94 //purpose  : Auxilare for HasIntersection()
95 //           find intersection point between triangle (P1,P2,P3)
96 //           and segment [PC,P]
97 //=======================================================================
98 static bool HasIntersection3(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint,
99                              const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3)
100 {
101   //cout<<"HasIntersection3"<<endl;
102   //cout<<"  PC("<<PC.X()<<","<<PC.Y()<<","<<PC.Z()<<")"<<endl;
103   //cout<<"  P("<<P.X()<<","<<P.Y()<<","<<P.Z()<<")"<<endl;
104   //cout<<"  P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
105   //cout<<"  P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
106   //cout<<"  P3("<<P3.X()<<","<<P3.Y()<<","<<P3.Z()<<")"<<endl;
107   gp_Vec VP1(P1,P2);
108   gp_Vec VP2(P1,P3);
109   IntAna_Quadric IAQ(gp_Pln(P1,VP1.Crossed(VP2)));
110   IntAna_IntConicQuad IAICQ(gp_Lin(PC,gp_Dir(gp_Vec(PC,P))),IAQ);
111   if(IAICQ.IsDone()) {
112     if( IAICQ.IsInQuadric() )
113       return false;
114     if( IAICQ.NbPoints() == 1 ) {
115       gp_Pnt PIn = IAICQ.Point(1);
116       double preci = 1.e-6;
117       // check if this point is internal for segment [PC,P]
118       bool IsExternal =
119         ( (PC.X()-PIn.X())*(P.X()-PIn.X()) > preci ) ||
120         ( (PC.Y()-PIn.Y())*(P.Y()-PIn.Y()) > preci ) ||
121         ( (PC.Z()-PIn.Z())*(P.Z()-PIn.Z()) > preci );
122       if(IsExternal) {
123         return false;
124       }
125       // check if this point is internal for triangle (P1,P2,P3)
126       gp_Vec V1(PIn,P1);
127       gp_Vec V2(PIn,P2);
128       gp_Vec V3(PIn,P3);
129       if( V1.Magnitude()<preci || V2.Magnitude()<preci ||
130           V3.Magnitude()<preci ) {
131         Pint = PIn;
132         return true;
133       }
134       gp_Vec VC1 = V1.Crossed(V2);
135       gp_Vec VC2 = V2.Crossed(V3);
136       gp_Vec VC3 = V3.Crossed(V1);
137       if(VC1.Magnitude()<preci) {
138         if(VC2.IsOpposite(VC3,preci)) {
139           return false;
140         }
141       }
142       else if(VC2.Magnitude()<preci) {
143         if(VC1.IsOpposite(VC3,preci)) {
144           return false;
145         }
146       }
147       else if(VC3.Magnitude()<preci) {
148         if(VC1.IsOpposite(VC2,preci)) {
149           return false;
150         }
151       }
152       else {
153         if( VC1.IsOpposite(VC2,preci) || VC1.IsOpposite(VC3,preci) ||
154             VC2.IsOpposite(VC3,preci) ) {
155           return false;
156         }
157       }
158       Pint = PIn;
159       return true;
160     }
161   }
162
163   return false;
164 }
165
166
167 //=======================================================================
168 //function : HasIntersection
169 //purpose  : Auxilare for CheckIntersection()
170 //=======================================================================
171 static bool HasIntersection(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint,
172                             Handle(TColgp_HSequenceOfPnt)& aContour)
173 {
174   if(aContour->Length()==3) {
175     return HasIntersection3( P, PC, Pint, aContour->Value(1),
176                              aContour->Value(2), aContour->Value(3) );
177   }
178   else {
179     bool check = false;
180     if( (aContour->Value(1).Distance(aContour->Value(2)) > 1.e-6) &&
181         (aContour->Value(1).Distance(aContour->Value(3)) > 1.e-6) &&
182         (aContour->Value(2).Distance(aContour->Value(3)) > 1.e-6) ) {
183       check = HasIntersection3( P, PC, Pint, aContour->Value(1),
184                                 aContour->Value(2), aContour->Value(3) );
185     }
186     if(check) return true;
187     if( (aContour->Value(1).Distance(aContour->Value(4)) > 1.e-6) &&
188         (aContour->Value(1).Distance(aContour->Value(3)) > 1.e-6) &&
189         (aContour->Value(4).Distance(aContour->Value(3)) > 1.e-6) ) {
190       check = HasIntersection3( P, PC, Pint, aContour->Value(1),
191                                 aContour->Value(3), aContour->Value(4) );
192     }
193     if(check) return true;
194   }
195
196   return false;
197 }
198
199
200 //=======================================================================
201 //function : CheckIntersection
202 //purpose  : Auxilare for Compute()
203 //           NotCheckedFace - for optimization
204 //=======================================================================
205 bool StdMeshers_QuadToTriaAdaptor::CheckIntersection
206                        (const gp_Pnt& P, const gp_Pnt& PC,
207                         gp_Pnt& Pint, SMESH_Mesh& aMesh,
208                         const TopoDS_Shape& aShape,
209                         const TopoDS_Shape& NotCheckedFace)
210 {
211   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
212   //cout<<"    CheckIntersection: meshDS->NbFaces() = "<<meshDS->NbFaces()<<endl;
213   bool res = false;
214   double dist = RealLast();
215   gp_Pnt Pres;
216   for (TopExp_Explorer exp(aShape,TopAbs_FACE);exp.More();exp.Next()) {
217     const TopoDS_Shape& aShapeFace = exp.Current();
218     if(aShapeFace==NotCheckedFace)
219       continue;
220     const SMESHDS_SubMesh * aSubMeshDSFace = meshDS->MeshElements(aShapeFace);
221     if ( aSubMeshDSFace ) {
222       SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
223       while ( iteratorElem->more() ) { // loop on elements on a face
224         const SMDS_MeshElement* face = iteratorElem->next();
225         Handle(TColgp_HSequenceOfPnt) aContour = new TColgp_HSequenceOfPnt;
226         SMDS_ElemIteratorPtr nodeIt = face->nodesIterator();
227         if( !face->IsQuadratic() ) {
228           while ( nodeIt->more() ) {
229             const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
230             aContour->Append(gp_Pnt(node->X(), node->Y(), node->Z()));
231           }
232         }
233         else {
234           int nn = 0;
235           while ( nodeIt->more() ) {
236             nn++;
237             const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
238             aContour->Append(gp_Pnt(node->X(), node->Y(), node->Z()));
239             if(nn==face->NbNodes()/2) break;
240           }
241         }
242         if( HasIntersection(P, PC, Pres, aContour) ) {
243           res = true;
244           double tmp = PC.Distance(Pres);
245           if(tmp<dist) {
246             Pint = Pres;
247             dist = tmp;
248           }
249         }
250       }
251     }
252   }
253   return res;
254 }
255
256
257 //=======================================================================
258 //function : CompareTrias
259 //purpose  : Auxilare for Compute()
260 //=======================================================================
261 static bool CompareTrias(const SMDS_MeshElement* F1,const SMDS_MeshElement* F2)
262 {
263   SMDS_ElemIteratorPtr nIt = F1->nodesIterator();
264   const SMDS_MeshNode* Ns1[3];
265   int k = 0;
266   while( nIt->more() ) {
267     Ns1[k] = static_cast<const SMDS_MeshNode*>( nIt->next() );
268     k++;
269   }
270   nIt = F2->nodesIterator();
271   const SMDS_MeshNode* Ns2[3];
272   k = 0;
273   while( nIt->more() ) {
274     Ns2[k] = static_cast<const SMDS_MeshNode*>( nIt->next() );
275     k++;
276   }
277   if( ( Ns1[1]==Ns2[1] && Ns1[2]==Ns2[2] ) ||
278       ( Ns1[1]==Ns2[2] && Ns1[2]==Ns2[1] ) )
279     return true;
280   return false;
281 }
282
283
284 //=======================================================================
285 //function : IsDegenarate
286 //purpose  : Auxilare for Preparation()
287 //=======================================================================
288 static int IsDegenarate(const Handle(TColgp_HArray1OfPnt)& PN)
289 {
290   int i = 1;
291   for(; i<4; i++) {
292     int j = i+1;
293     for(; j<=4; j++) {
294       if( PN->Value(i).Distance(PN->Value(j)) < 1.e-6 )
295         return j;
296     }
297   }
298   return 0;
299 }
300
301
302 //=======================================================================
303 //function : Preparation
304 //purpose  : Auxilare for Compute()
305 //         : Return 0 if given face is not quad,
306 //                  1 if given face is quad,
307 //                  2 if given face is degenerate quad (two nodes are coincided)
308 //=======================================================================
309 int StdMeshers_QuadToTriaAdaptor::Preparation(const SMDS_MeshElement* face,
310                                               Handle(TColgp_HArray1OfPnt) PN,
311                                               Handle(TColgp_HArray1OfVec) VN,
312                                               std::vector<const SMDS_MeshNode*>& FNodes,
313                                               gp_Pnt& PC, gp_Vec& VNorm)
314 {
315   int i = 0;
316   double xc=0., yc=0., zc=0.;
317   SMDS_ElemIteratorPtr nodeIt = face->nodesIterator();
318   if( !face->IsQuadratic() ) {
319     if( face->NbNodes() != 4 )
320       return 0;
321     while ( nodeIt->more() ) {
322       i++;
323       const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
324       FNodes[i-1] = node;
325       PN->SetValue( i, gp_Pnt(node->X(), node->Y(), node->Z()) );
326       xc += node->X();
327       yc += node->Y();
328       zc += node->Z();
329     }
330   }
331   else {
332     if( face->NbNodes() != 8)
333       return 0;
334     while ( nodeIt->more() ) {
335       i++;
336       const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
337       FNodes[i-1] = node;
338       PN->SetValue( i, gp_Pnt(node->X(), node->Y(), node->Z()) );
339       xc += node->X();
340       yc += node->Y();
341       zc += node->Z();
342       if(i==4) break;
343     }
344   }
345
346   int nbp = 4;
347
348   int j = 0;
349   for(i=1; i<4; i++) {
350     j = i+1;
351     for(; j<=4; j++) {
352       if( PN->Value(i).Distance(PN->Value(j)) < 1.e-6 )
353         break;
354     }
355     if(j<=4) break;
356   }
357   //int deg_num = IsDegenarate(PN);
358   //if(deg_num>0) {
359   bool hasdeg = false;
360   if(i<4) {
361     //cout<<"find degeneration"<<endl;
362     hasdeg = true;
363     gp_Pnt Pdeg = PN->Value(i);
364
365     std::list< const SMDS_MeshNode* >::iterator itdg = myDegNodes.begin();
366     const SMDS_MeshNode* DegNode = 0;
367     for(; itdg!=myDegNodes.end(); itdg++) {
368       const SMDS_MeshNode* N = (*itdg);
369       gp_Pnt Ptmp(N->X(),N->Y(),N->Z());
370       if(Pdeg.Distance(Ptmp)<1.e-6) {
371         DegNode = N;
372         //DegNode = const_cast<SMDS_MeshNode*>(N);
373         break;
374       }
375     }
376     if(!DegNode) {
377       DegNode = FNodes[i-1];
378       myDegNodes.push_back(DegNode);
379     }
380     else {
381       FNodes[i-1] = DegNode;
382     }
383     for(i=j; i<4; i++) {
384       PN->SetValue(i,PN->Value(i+1));
385       FNodes[i-1] = FNodes[i];
386     }
387     nbp = 3;
388     //PC = gp_Pnt( PN->Value(1).X() + PN.Value
389   }
390
391   PC = gp_Pnt(xc/4., yc/4., zc/4.);
392   //cout<<"  PC("<<PC.X()<<","<<PC.Y()<<","<<PC.Z()<<")"<<endl;
393
394   //PN->SetValue(5,PN->Value(1));
395   PN->SetValue(nbp+1,PN->Value(1));
396   //FNodes[4] = FNodes[0];
397   FNodes[nbp] = FNodes[0];
398   // find normal direction
399   //gp_Vec V1(PC,PN->Value(4));
400   gp_Vec V1(PC,PN->Value(nbp));
401   gp_Vec V2(PC,PN->Value(1));
402   VNorm = V1.Crossed(V2);
403   //VN->SetValue(4,VNorm);
404   VN->SetValue(nbp,VNorm);
405   //for(i=1; i<4; i++) {
406   for(i=1; i<nbp; i++) {
407     V1 = gp_Vec(PC,PN->Value(i));
408     V2 = gp_Vec(PC,PN->Value(i+1));
409     gp_Vec Vtmp = V1.Crossed(V2);
410     VN->SetValue(i,Vtmp);
411     VNorm += Vtmp;
412   }
413   //cout<<"  VNorm("<<VNorm.X()<<","<<VNorm.Y()<<","<<VNorm.Z()<<")"<<endl;
414   if(hasdeg) return 2;
415   return 1;
416 }
417
418
419 //=======================================================================
420 //function : Compute
421 //purpose  : 
422 //=======================================================================
423
424 bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
425 {
426   myResMap.clear();
427   myMapFPyram.clear();
428
429   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
430
431   for (TopExp_Explorer exp(aShape,TopAbs_FACE);exp.More();exp.Next()) {
432     const TopoDS_Shape& aShapeFace = exp.Current();
433     const SMESHDS_SubMesh * aSubMeshDSFace = meshDS->MeshElements( aShapeFace );
434     if ( aSubMeshDSFace ) {
435       bool isRev = SMESH_Algo::IsReversedSubMesh( TopoDS::Face(aShapeFace), meshDS );
436
437       SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
438       while ( iteratorElem->more() ) { // loop on elements on a face
439         const SMDS_MeshElement* face = iteratorElem->next();
440         //cout<<endl<<"================= face->GetID() = "<<face->GetID()<<endl;
441         // preparation step using face info
442         Handle(TColgp_HArray1OfPnt) PN = new TColgp_HArray1OfPnt(1,5);
443         Handle(TColgp_HArray1OfVec) VN = new TColgp_HArray1OfVec(1,4);
444         std::vector<const SMDS_MeshNode*> FNodes(5);
445         gp_Pnt PC;
446         gp_Vec VNorm;
447         int stat =  Preparation(face, PN, VN, FNodes, PC, VNorm);
448         if(stat==0)
449           continue;
450
451         if(stat==2) {
452           // degenerate face
453           // add triangles to result map
454           std::list<const SMDS_FaceOfNodes*> aList;
455           SMDS_FaceOfNodes* NewFace;
456           if(!isRev)
457             NewFace = new SMDS_FaceOfNodes( FNodes[0], FNodes[1], FNodes[2] );
458           else
459             NewFace = new SMDS_FaceOfNodes( FNodes[0], FNodes[2], FNodes[1] );
460           aList.push_back(NewFace);
461           myResMap.insert(make_pair(face,aList));
462           continue;
463         }
464
465         if(!isRev) VNorm.Reverse();
466         double xc = 0., yc = 0., zc = 0.;
467         int i = 1;
468         for(; i<=4; i++) {
469           gp_Pnt Pbest;
470           if(!isRev)
471             Pbest = FindBestPoint(PN->Value(i), PN->Value(i+1), PC, VN->Value(i).Reversed());
472           else
473             Pbest = FindBestPoint(PN->Value(i), PN->Value(i+1), PC, VN->Value(i));
474           xc += Pbest.X();
475           yc += Pbest.Y();
476           zc += Pbest.Z();
477         }
478         gp_Pnt PCbest(xc/4., yc/4., zc/4.);
479
480         // check PCbest
481         double height = PCbest.Distance(PC);
482         if(height<1.e-6) {
483           // create new PCbest using a bit shift along VNorm
484           PCbest = gp_Pnt( PC.X() + VNorm.X()*0.001,
485                            PC.Y() + VNorm.Y()*0.001,
486                            PC.Z() + VNorm.Z()*0.001);
487         }
488         else {
489           // check possible intersection with other faces
490           gp_Pnt Pint;
491           bool check = CheckIntersection(PCbest, PC, Pint, aMesh, aShape, aShapeFace);
492           if(check) {
493             //cout<<"--PC("<<PC.X()<<","<<PC.Y()<<","<<PC.Z()<<")"<<endl;
494             //cout<<"  PCbest("<<PCbest.X()<<","<<PCbest.Y()<<","<<PCbest.Z()<<")"<<endl;
495             double dist = PC.Distance(Pint)/3.;
496             gp_Dir aDir(gp_Vec(PC,PCbest));
497             PCbest = gp_Pnt( PC.X() + aDir.X()*dist,
498                              PC.Y() + aDir.Y()*dist,
499                              PC.Z() + aDir.Z()*dist );
500           }
501           else {
502             gp_Vec VB(PC,PCbest);
503             gp_Pnt PCbestTmp(PC.X()+VB.X()*3, PC.X()+VB.X()*3, PC.X()+VB.X()*3);
504             bool check = CheckIntersection(PCbestTmp, PC, Pint, aMesh, aShape, aShapeFace);
505             if(check) {
506               double dist = PC.Distance(Pint)/3.;
507               if(dist<height) {
508                 gp_Dir aDir(gp_Vec(PC,PCbest));
509                 PCbest = gp_Pnt( PC.X() + aDir.X()*dist,
510                                  PC.Y() + aDir.Y()*dist,
511                                  PC.Z() + aDir.Z()*dist );
512               }
513             }
514           }
515         }
516         // create node for PCbest
517         SMDS_MeshNode* NewNode = meshDS->AddNode( PCbest.X(), PCbest.Y(), PCbest.Z() );
518         // add triangles to result map
519         std::list<const SMDS_FaceOfNodes*> aList;
520         for(i=0; i<4; i++) {
521           SMDS_FaceOfNodes* NewFace = new SMDS_FaceOfNodes( NewNode, FNodes[i], FNodes[i+1] );
522           aList.push_back(NewFace);
523         }
524         myResMap.insert(make_pair(face,aList));
525         // create pyramid
526         SMDS_MeshVolume* aPyram =
527           meshDS->AddVolume( FNodes[0], FNodes[1], FNodes[2], FNodes[3], NewNode );
528         myMapFPyram.insert(make_pair(face,aPyram));
529       } // end loop on elements on a face
530     }
531   } // end for(TopExp_Explorer exp(aShape,TopAbs_FACE);exp.More();exp.Next()) {
532
533   return Compute2ndPart(aMesh);
534 }
535
536
537 //=======================================================================
538 //function : Compute
539 //purpose  : 
540 //=======================================================================
541
542 bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh)
543 {
544   myResMap.clear();
545   myMapFPyram.clear();
546
547   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
548
549   SMDS_FaceIteratorPtr itFace = meshDS->facesIterator();
550
551   while(itFace->more()) {
552     const SMDS_MeshElement* face = itFace->next();
553     if ( !face ) continue;
554     //cout<<endl<<"================= face->GetID() = "<<face->GetID()<<endl;
555     // preparation step using face info
556     Handle(TColgp_HArray1OfPnt) PN = new TColgp_HArray1OfPnt(1,5);
557     Handle(TColgp_HArray1OfVec) VN = new TColgp_HArray1OfVec(1,4);
558     std::vector<const SMDS_MeshNode*> FNodes(5);
559     gp_Pnt PC;
560     gp_Vec VNorm;
561
562     int stat =  Preparation(face, PN, VN, FNodes, PC, VNorm);
563     if(stat==0)
564       continue;
565
566     if(stat==2) {
567       // degenerate face
568       // add triangles to result map
569       std::list<const SMDS_FaceOfNodes*> aList;
570       SMDS_FaceOfNodes* NewFace;
571       // check orientation
572
573       double tmp = PN->Value(1).Distance(PN->Value(2)) +
574         PN->Value(2).Distance(PN->Value(3));
575       gp_Dir tmpDir(VNorm);
576       gp_Pnt Ptmp1( PC.X() + tmpDir.X()*tmp*1.e6,
577                     PC.Y() + tmpDir.Y()*tmp*1.e6,
578                     PC.Z() + tmpDir.Z()*tmp*1.e6 );
579       gp_Pnt Ptmp2( PC.X() + tmpDir.Reversed().X()*tmp*1.e6,
580                     PC.Y() + tmpDir.Reversed().Y()*tmp*1.e6,
581                     PC.Z() + tmpDir.Reversed().Z()*tmp*1.e6 );
582       // check intersection for Ptmp1 and Ptmp2
583       bool IsRev = false;
584       bool IsOK1 = false;
585       bool IsOK2 = false;
586       double dist1 = RealLast();
587       double dist2 = RealLast();
588       gp_Pnt Pres1,Pres2;
589       SMDS_FaceIteratorPtr itf = meshDS->facesIterator();
590       while(itf->more()) {
591         const SMDS_MeshElement* F = itf->next();
592         if(F==face) continue;
593         Handle(TColgp_HSequenceOfPnt) aContour = new TColgp_HSequenceOfPnt;
594         SMDS_ElemIteratorPtr nodeIt = F->nodesIterator();
595         if( !F->IsQuadratic() ) {
596           while ( nodeIt->more() ) {
597             const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
598             aContour->Append(gp_Pnt(node->X(), node->Y(), node->Z()));
599           }
600         }
601         else {
602           int nn = 0;
603           while ( nodeIt->more() ) {
604             nn++;
605             const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
606             aContour->Append(gp_Pnt(node->X(), node->Y(), node->Z()));
607             if(nn==face->NbNodes()/2) break;
608           }
609         }
610         gp_Pnt PPP;
611         if( HasIntersection(Ptmp1, PC, PPP, aContour) ) {
612           IsOK1 = true;
613           double tmp = PC.Distance(PPP);
614           if(tmp<dist1) {
615             Pres1 = PPP;
616             dist1 = tmp;
617           }
618         }
619         if( HasIntersection(Ptmp2, PC, PPP, aContour) ) {
620           IsOK2 = true;
621           double tmp = PC.Distance(PPP);
622           if(tmp<dist2) {
623             Pres2 = PPP;
624             dist2 = tmp;
625           }
626         }
627       }
628
629       if( IsOK1 && !IsOK2 ) {
630         // using existed direction
631       }
632       else if( !IsOK1 && IsOK2 ) {
633         // using opposite direction
634         IsRev = true;
635       }
636       else { // IsOK1 && IsOK2
637         double tmp1 = PC.Distance(Pres1)/3.;
638         double tmp2 = PC.Distance(Pres2)/3.;
639         if(tmp1<tmp2) {
640           // using existed direction
641         }
642         else {
643           // using opposite direction
644           IsRev = true;
645         }
646       }
647       if(!IsRev)
648         NewFace = new SMDS_FaceOfNodes( FNodes[0], FNodes[1], FNodes[2] );
649       else
650         NewFace = new SMDS_FaceOfNodes( FNodes[0], FNodes[2], FNodes[1] );
651       aList.push_back(NewFace);
652       myResMap.insert(make_pair(face,aList));
653       continue;
654     }
655     
656     double xc = 0., yc = 0., zc = 0.;
657     int i = 1;
658     for(; i<=4; i++) {
659       gp_Pnt Pbest = FindBestPoint(PN->Value(i), PN->Value(i+1), PC, VN->Value(i));
660       xc += Pbest.X();
661       yc += Pbest.Y();
662       zc += Pbest.Z();
663     }
664     gp_Pnt PCbest(xc/4., yc/4., zc/4.);
665     double height = PCbest.Distance(PC);
666     if(height<1.e-6) {
667       // create new PCbest using a bit shift along VNorm
668       PCbest = gp_Pnt( PC.X() + VNorm.X()*0.001,
669                        PC.Y() + VNorm.Y()*0.001,
670                        PC.Z() + VNorm.Z()*0.001);
671       height = PCbest.Distance(PC);
672     }
673     //cout<<"  PCbest("<<PCbest.X()<<","<<PCbest.Y()<<","<<PCbest.Z()<<")"<<endl;
674
675     gp_Vec V1(PC,PCbest);
676     double tmp = PN->Value(1).Distance(PN->Value(3)) +
677       PN->Value(2).Distance(PN->Value(4));
678     gp_Dir tmpDir(V1);
679     gp_Pnt Ptmp1( PC.X() + tmpDir.X()*tmp*1.e6,
680                   PC.Y() + tmpDir.Y()*tmp*1.e6,
681                   PC.Z() + tmpDir.Z()*tmp*1.e6 );
682     gp_Pnt Ptmp2( PC.X() + tmpDir.Reversed().X()*tmp*1.e6,
683                   PC.Y() + tmpDir.Reversed().Y()*tmp*1.e6,
684                   PC.Z() + tmpDir.Reversed().Z()*tmp*1.e6 );
685     // check intersection for Ptmp1 and Ptmp2
686     bool IsRev = false;
687     bool IsOK1 = false;
688     bool IsOK2 = false;
689     double dist1 = RealLast();
690     double dist2 = RealLast();
691     gp_Pnt Pres1,Pres2;
692     SMDS_FaceIteratorPtr itf = meshDS->facesIterator();
693     while(itf->more()) {
694       const SMDS_MeshElement* F = itf->next();
695       if(F==face) continue;
696       Handle(TColgp_HSequenceOfPnt) aContour = new TColgp_HSequenceOfPnt;
697       SMDS_ElemIteratorPtr nodeIt = F->nodesIterator();
698       if( !F->IsQuadratic() ) {
699         while ( nodeIt->more() ) {
700           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
701           aContour->Append(gp_Pnt(node->X(), node->Y(), node->Z()));
702         }
703       }
704       else {
705         int nn = 0;
706         while ( nodeIt->more() ) {
707           nn++;
708           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
709           aContour->Append(gp_Pnt(node->X(), node->Y(), node->Z()));
710           if(nn==face->NbNodes()/2) break;
711         }
712       }
713       gp_Pnt PPP;
714       if( HasIntersection(Ptmp1, PC, PPP, aContour) ) {
715         IsOK1 = true;
716         double tmp = PC.Distance(PPP);
717         if(tmp<dist1) {
718           Pres1 = PPP;
719           dist1 = tmp;
720         }
721       }
722       if( HasIntersection(Ptmp2, PC, PPP, aContour) ) {
723         IsOK2 = true;
724         double tmp = PC.Distance(PPP);
725         if(tmp<dist2) {
726           Pres2 = PPP;
727           dist2 = tmp;
728         }
729       }
730     }
731
732     if( IsOK1 && !IsOK2 ) {
733       // using existed direction
734       double tmp = PC.Distance(Pres1)/3.;
735       if( height > tmp ) {
736         height = tmp;
737         PCbest = gp_Pnt( PC.X() + tmpDir.X()*height,
738                          PC.Y() + tmpDir.Y()*height,
739                          PC.Z() + tmpDir.Z()*height );
740       }
741     }
742     else if( !IsOK1 && IsOK2 ) {
743       // using opposite direction
744       IsRev = true;
745       double tmp = PC.Distance(Pres2)/3.;
746       if( height > tmp ) height = tmp;
747       PCbest = gp_Pnt( PC.X() + tmpDir.Reversed().X()*height,
748                        PC.Y() + tmpDir.Reversed().Y()*height,
749                        PC.Z() + tmpDir.Reversed().Z()*height );
750     }
751     else { // IsOK1 && IsOK2
752       double tmp1 = PC.Distance(Pres1)/3.;
753       double tmp2 = PC.Distance(Pres2)/3.;
754       if(tmp1<tmp2) {
755         // using existed direction
756         if( height > tmp1 ) {
757           height = tmp1;
758           PCbest = gp_Pnt( PC.X() + tmpDir.X()*height,
759                            PC.Y() + tmpDir.Y()*height,
760                            PC.Z() + tmpDir.Z()*height );
761         }
762       }
763       else {
764         // using opposite direction
765         IsRev = true;
766         if( height > tmp2 ) height = tmp2;
767         PCbest = gp_Pnt( PC.X() + tmpDir.Reversed().X()*height,
768                          PC.Y() + tmpDir.Reversed().Y()*height,
769                          PC.Z() + tmpDir.Reversed().Z()*height );
770       }
771     }
772
773     // create node for PCbest
774     SMDS_MeshNode* NewNode = meshDS->AddNode( PCbest.X(), PCbest.Y(), PCbest.Z() );
775     // add triangles to result map
776     std::list<const SMDS_FaceOfNodes*> aList;
777     for(i=0; i<4; i++) {
778       SMDS_FaceOfNodes* NewFace;
779       if(IsRev)
780         NewFace = new SMDS_FaceOfNodes( NewNode, FNodes[i], FNodes[i+1] );
781       else
782         NewFace = new SMDS_FaceOfNodes( NewNode, FNodes[i+1], FNodes[i] );
783       aList.push_back(NewFace);
784     }
785     myResMap.insert(make_pair(face,aList));
786     // create pyramid
787     SMDS_MeshVolume* aPyram;
788     if(IsRev)
789      aPyram = meshDS->AddVolume( FNodes[0], FNodes[1], FNodes[2], FNodes[3], NewNode );
790     else
791      aPyram = meshDS->AddVolume( FNodes[0], FNodes[3], FNodes[2], FNodes[1], NewNode );
792     myMapFPyram.insert(make_pair(face,aPyram));
793   } // end loop on elements on a face
794
795   return Compute2ndPart(aMesh);
796 }
797
798
799 //=======================================================================
800 //function : Compute2ndPart
801 //purpose  : 
802 //=======================================================================
803
804 bool StdMeshers_QuadToTriaAdaptor::Compute2ndPart(SMESH_Mesh& aMesh)
805 {
806   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
807
808   // check intersections between created pyramids
809   int NbPyram = myMapFPyram.size();
810   //cout<<"NbPyram = "<<NbPyram<<endl;
811   if(NbPyram==0)
812     return true;
813
814   std::vector< const SMDS_MeshElement* > Pyrams(NbPyram);
815   std::vector< const SMDS_MeshElement* > Faces(NbPyram);
816   std::map< const SMDS_MeshElement*,
817     const SMDS_MeshElement* >::iterator itp = myMapFPyram.begin();
818   int i = 0;
819   for(; itp!=myMapFPyram.end(); itp++, i++) {
820     Faces[i] = (*itp).first;
821     Pyrams[i] = (*itp).second;
822   }
823   StdMeshers_Array1OfSequenceOfInteger MergesInfo(0,NbPyram-1);
824   for(i=0; i<NbPyram; i++) {
825     TColStd_SequenceOfInteger aMerges;
826     aMerges.Append(i);
827     MergesInfo.SetValue(i,aMerges);
828   }
829   for(i=0; i<NbPyram-1; i++) {
830     const SMDS_MeshElement* Prm1 = Pyrams[i];
831     SMDS_ElemIteratorPtr nIt = Prm1->nodesIterator();
832     std::vector<gp_Pnt> Ps1(5);
833     const SMDS_MeshNode* Ns1[5];
834     int k = 0;
835     while( nIt->more() ) {
836       const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nIt->next() );
837       Ns1[k] = node;
838       Ps1[k] = gp_Pnt(node->X(), node->Y(), node->Z());
839       k++;
840     }
841     bool NeedMove = false;
842     for(int j=i+1; j<NbPyram; j++) {
843       //cout<<"  i="<<i<<" j="<<j<<endl;
844       const TColStd_SequenceOfInteger& aMergesI = MergesInfo.Value(i);
845       int nbI = aMergesI.Length();
846       const TColStd_SequenceOfInteger& aMergesJ = MergesInfo.Value(j);
847       int nbJ = aMergesJ.Length();
848
849       int k = 2;
850       bool NeedCont = false;
851       for(; k<=nbI; k++) {
852         if(aMergesI.Value(k)==j) {
853           NeedCont = true;
854           break;
855         }
856       }
857       if(NeedCont) continue;
858
859       const SMDS_MeshElement* Prm2 = Pyrams[j];
860       nIt = Prm2->nodesIterator();
861       std::vector<gp_Pnt> Ps2(5);
862       const SMDS_MeshNode* Ns2[5];
863       k = 0;
864       while( nIt->more() ) {
865         const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nIt->next() );
866         Ns2[k] = node;
867         Ps2[k] = gp_Pnt(node->X(), node->Y(), node->Z());
868         k++;
869       }
870
871       bool hasInt = false;
872       gp_Pnt Pint;
873       for(k=0; k<4; k++) {
874         gp_Vec Vtmp(Ps1[k],Ps1[4]);
875         gp_Pnt Pshift( Ps1[k].X() + Vtmp.X()*0.01,
876                        Ps1[k].Y() + Vtmp.Y()*0.01,
877                        Ps1[k].Z() + Vtmp.Z()*0.01 );
878         int m=0;
879         for(; m<3; m++) {
880           if( HasIntersection3( Pshift, Ps1[4], Pint, Ps2[m], Ps2[m+1], Ps2[4]) ) {
881             hasInt = true;
882             break;
883           }
884         }
885         if( HasIntersection3( Pshift, Ps1[4], Pint, Ps2[3], Ps2[0], Ps2[4]) ) {
886           hasInt = true;
887         }
888         if(hasInt) break;
889       }
890       if(!hasInt) {
891         for(k=0; k<4; k++) {
892           gp_Vec Vtmp(Ps2[k],Ps2[4]);
893           gp_Pnt Pshift( Ps2[k].X() + Vtmp.X()*0.01,
894                          Ps2[k].Y() + Vtmp.Y()*0.01,
895                          Ps2[k].Z() + Vtmp.Z()*0.01 );
896           int m=0;
897           for(; m<3; m++) {
898             if( HasIntersection3( Pshift, Ps2[4], Pint, Ps1[m], Ps1[m+1], Ps1[4]) ) {
899               hasInt = true;
900               break;
901             }
902           }
903           if( HasIntersection3( Pshift, Ps2[4], Pint, Ps1[3], Ps1[0], Ps1[4]) ) {
904             hasInt = true;
905           }
906           if(hasInt) break;
907         }
908       }
909
910       if(hasInt) {
911         //cout<<"    has intersec for i="<<i<<" j="<<j<<endl;
912         // check if MeshFaces have 2 common node
913         int nbc = 0;
914         for(k=0; k<4; k++) {
915           for(int m=0; m<4; m++) {
916             if( Ns1[k]==Ns2[m] ) nbc++;
917           }
918         }
919         //cout<<"      nbc = "<<nbc<<endl;
920         if(nbc>0) {
921           // create common node
922           SMDS_MeshNode* CommonNode = const_cast<SMDS_MeshNode*>(Ns1[4]);
923           CommonNode->setXYZ( ( nbI*Ps1[4].X() + nbJ*Ps2[4].X() ) / (nbI+nbJ),
924                               ( nbI*Ps1[4].Y() + nbJ*Ps2[4].Y() ) / (nbI+nbJ),
925                               ( nbI*Ps1[4].Z() + nbJ*Ps2[4].Z() ) / (nbI+nbJ) );
926           NeedMove = true;
927           //cout<<"       CommonNode: "<<CommonNode;
928           const SMDS_MeshNode* Nrem = Ns2[4];
929           Ns2[4] = CommonNode;
930           meshDS->ChangeElementNodes(Prm2, Ns2, 5);
931           // update pyramids for J
932           for(k=2; k<=nbJ; k++) {
933             const SMDS_MeshElement* tmpPrm = Pyrams[aMergesJ.Value(k)];
934             SMDS_ElemIteratorPtr tmpIt = tmpPrm->nodesIterator();
935             const SMDS_MeshNode* Ns[5];
936             int m = 0;
937             while( tmpIt->more() ) {
938               Ns[m] = static_cast<const SMDS_MeshNode*>( tmpIt->next() );
939               m++;
940             }
941             Ns[4] = CommonNode;
942             meshDS->ChangeElementNodes(tmpPrm, Ns, 5);
943           }
944
945           // update MergesInfo
946           for(k=1; k<=nbI; k++) {
947             int num = aMergesI.Value(k);
948             const TColStd_SequenceOfInteger& aSeq = MergesInfo.Value(num);
949             TColStd_SequenceOfInteger tmpSeq;
950             int m = 1;
951             for(; m<=aSeq.Length(); m++) {
952               tmpSeq.Append(aSeq.Value(m));
953             }
954             for(m=1; m<=nbJ; m++) {
955               tmpSeq.Append(aMergesJ.Value(m));
956             }
957             MergesInfo.SetValue(num,tmpSeq);
958           }
959           for(k=1; k<=nbJ; k++) {
960             int num = aMergesJ.Value(k);
961             const TColStd_SequenceOfInteger& aSeq = MergesInfo.Value(num);
962             TColStd_SequenceOfInteger tmpSeq;
963             int m = 1;
964             for(; m<=aSeq.Length(); m++) {
965               tmpSeq.Append(aSeq.Value(m));
966             }
967             for(m=1; m<=nbI; m++) {
968               tmpSeq.Append(aMergesI.Value(m));
969             }
970             MergesInfo.SetValue(num,tmpSeq);
971           }
972
973           // update triangles for aMergesJ
974           for(k=1; k<=nbJ; k++) {
975             std::list< std::list< const SMDS_MeshNode* > > aFNodes;
976             std::list< const SMDS_MeshElement* > aFFaces;
977             int num = aMergesJ.Value(k);
978             std::map< const SMDS_MeshElement*,
979               std::list<const SMDS_FaceOfNodes*> >::iterator itrm = myResMap.find(Faces[num]);
980             std::list<const SMDS_FaceOfNodes*> trias = (*itrm).second;
981             std::list<const SMDS_FaceOfNodes*>::iterator itt = trias.begin();
982             for(; itt!=trias.end(); itt++) {
983               int nn = -1;
984               SMDS_ElemIteratorPtr nodeIt = (*itt)->nodesIterator();
985               const SMDS_MeshNode* NF[3];
986               while ( nodeIt->more() ) {
987                 nn++;
988                 NF[nn] = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
989               }
990               NF[0] = CommonNode;
991               SMDS_FaceOfNodes* Ftria = const_cast< SMDS_FaceOfNodes*>( (*itt) );
992               Ftria->ChangeNodes(NF, 3);
993             }
994           }
995
996           // check and remove coincided faces
997           TColStd_SequenceOfInteger IdRemovedTrias;
998           int i1 = 1;
999           for(; i1<=nbI; i1++) {
1000             int numI = aMergesI.Value(i1);
1001             std::map< const SMDS_MeshElement*,
1002               std::list<const SMDS_FaceOfNodes*> >::iterator itrmI = myResMap.find(Faces[numI]);
1003             std::list<const SMDS_FaceOfNodes*> triasI = (*itrmI).second;
1004             std::list<const SMDS_FaceOfNodes*>::iterator ittI = triasI.begin();
1005             int nbfI = triasI.size();
1006             std::vector<const SMDS_FaceOfNodes*> FsI(nbfI);
1007             k = 0;
1008             for(; ittI!=triasI.end(); ittI++) {
1009               FsI[k]  = (*ittI);
1010               k++;
1011             }
1012             int i2 = 0;
1013             for(; i2<nbfI; i2++) {
1014               const SMDS_FaceOfNodes* FI = FsI[i2];
1015               if(FI==0) continue;
1016               int j1 = 1;
1017               for(; j1<=nbJ; j1++) {
1018                 int numJ = aMergesJ.Value(j1);
1019                 std::map< const SMDS_MeshElement*,
1020                   std::list<const SMDS_FaceOfNodes*> >::iterator itrmJ = myResMap.find(Faces[numJ]);
1021                 std::list<const SMDS_FaceOfNodes*> triasJ = (*itrmJ).second;
1022                 std::list<const SMDS_FaceOfNodes*>::iterator ittJ = triasJ.begin();
1023                 int nbfJ = triasJ.size();
1024                 std::vector<const SMDS_FaceOfNodes*> FsJ(nbfJ);
1025                 k = 0;
1026                 for(; ittJ!=triasJ.end(); ittJ++) {
1027                   FsJ[k]  = (*ittJ);
1028                   k++;
1029                 }
1030                 int j2 = 0;
1031                 for(; j2<nbfJ; j2++) {
1032                   const SMDS_FaceOfNodes* FJ = FsJ[j2];
1033                   // compare triangles
1034                   if( CompareTrias(FI,FJ) ) {
1035                     IdRemovedTrias.Append( FI->GetID() );
1036                     IdRemovedTrias.Append( FJ->GetID() );
1037                     FsI[i2] = 0;
1038                     FsJ[j2] = 0;
1039                     std::list<const SMDS_FaceOfNodes*> new_triasI;
1040                     for(k=0; k<nbfI; k++) {
1041                       if( FsI[k]==0 ) continue;
1042                       new_triasI.push_back( FsI[k] );
1043                     }
1044                     (*itrmI).second = new_triasI;
1045                     triasI = new_triasI;
1046                     std::list<const SMDS_FaceOfNodes*> new_triasJ;
1047                     for(k=0; k<nbfJ; k++) {
1048                       if( FsJ[k]==0 ) continue;
1049                       new_triasJ.push_back( FsJ[k] );
1050                     }
1051                     (*itrmJ).second = new_triasJ;
1052                     triasJ = new_triasJ;
1053                     // remove faces
1054                     delete FI;
1055                     delete FJ;
1056                     // close for j2 and j1
1057                     j1 = nbJ;
1058                     break;
1059                   }
1060                 } // j2
1061               } // j1
1062             } // i2
1063           } // i1
1064           // removing node
1065           meshDS->RemoveNode(Nrem);
1066         }
1067         else { // nbc==0
1068           //cout<<"decrease height of pyramids"<<endl;
1069           // decrease height of pyramids
1070           double xc1 = 0., yc1 = 0., zc1 = 0.;
1071           double xc2 = 0., yc2 = 0., zc2 = 0.;
1072           for(k=0; k<4; k++) {
1073             xc1 += Ps1[k].X();
1074             yc1 += Ps1[k].Y();
1075             zc1 += Ps1[k].Z();
1076             xc2 += Ps2[k].X();
1077             yc2 += Ps2[k].Y();
1078             zc2 += Ps2[k].Z();
1079           }
1080           gp_Pnt PC1(xc1/4.,yc1/4.,zc1/4.);
1081           gp_Pnt PC2(xc2/4.,yc2/4.,zc2/4.);
1082           gp_Vec VN1(PC1,Ps1[4]);
1083           gp_Vec VI1(PC1,Pint);
1084           gp_Vec VN2(PC2,Ps2[4]);
1085           gp_Vec VI2(PC2,Pint);
1086           double ang1 = fabs(VN1.Angle(VI1));
1087           double ang2 = fabs(VN2.Angle(VI2));
1088           double h1,h2;
1089           if(ang1>PI/3.)
1090             h1 = VI1.Magnitude()/2;
1091           else
1092             h1 = VI1.Magnitude()*cos(ang1);
1093           if(ang2>PI/3.)
1094             h2 = VI2.Magnitude()/2;
1095           else
1096             h2 = VI2.Magnitude()*cos(ang2);
1097           double coef1 = 0.5;
1098           if(ang1<PI/3)
1099             coef1 -= cos(ang1)*0.25;
1100           double coef2 = 0.5;
1101           if(ang2<PI/3)
1102             coef2 -= cos(ang1)*0.25;
1103
1104           SMDS_MeshNode* aNode1 = const_cast<SMDS_MeshNode*>(Ns1[4]);
1105           VN1.Scale(coef1);
1106           aNode1->setXYZ( PC1.X()+VN1.X(), PC1.Y()+VN1.Y(), PC1.Z()+VN1.Z() );
1107           SMDS_MeshNode* aNode2 = const_cast<SMDS_MeshNode*>(Ns2[4]);
1108           VN2.Scale(coef2);
1109           aNode2->setXYZ( PC2.X()+VN2.X(), PC2.Y()+VN2.Y(), PC2.Z()+VN2.Z() );
1110           NeedMove = true;
1111         }
1112       } // end if(hasInt)
1113       else {
1114         //cout<<"    no intersec for i="<<i<<" j="<<j<<endl;
1115       }
1116
1117     }
1118     if( NeedMove && !meshDS->IsEmbeddedMode() ) {
1119       meshDS->MoveNode( Ns1[4], Ns1[4]->X(), Ns1[4]->Y(), Ns1[4]->Z() );
1120     }
1121   }
1122
1123   return true;
1124 }
1125
1126
1127 //================================================================================
1128 /*!
1129  * \brief Return list of created triangles for given face
1130  */
1131 //================================================================================
1132 std::list<const SMDS_FaceOfNodes*> StdMeshers_QuadToTriaAdaptor::GetTriangles
1133                                                    (const SMDS_MeshElement* aFace)
1134 {
1135   std::list<const SMDS_FaceOfNodes*> aRes;
1136   std::map< const SMDS_MeshElement*,
1137     std::list<const SMDS_FaceOfNodes*> >::iterator it = myResMap.find(aFace);
1138   if( it != myResMap.end() ) {
1139     aRes = (*it).second;
1140   }
1141   return aRes;
1142 }
1143
1144
1145 //================================================================================
1146 /*!
1147  * \brief Remove all create auxilary faces
1148  */
1149 //================================================================================
1150 //void StdMeshers_QuadToTriaAdaptor::RemoveFaces(SMESH_Mesh& aMesh)
1151 //{
1152 //  SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
1153 //  std::map< const SMDS_MeshElement*,
1154 //    std::list<const SMDS_MeshElement*> >::iterator it = myResMap.begin();
1155 //  for(; it != myResMap.end(); it++ ) {
1156 //    std::list<const SMDS_MeshElement*> aFaces = (*it).second;
1157 //    std::list<const SMDS_MeshElement*>::iterator itf = aFaces.begin();
1158 //    for(; itf!=aFaces.end(); itf++ ) {
1159 //      meshDS->RemoveElement( (*itf) );
1160 //    }
1161 //  }
1162 //}