Salome HOME
Update of CheckDone
[modules/smesh.git] / src / StdMeshers / StdMeshers_CompositeHexa_3D.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SMESH SMESH : implementation of SMESH idl descriptions
21 // File      : StdMeshers_CompositeHexa_3D.cxx
22 // Module    : SMESH
23 // Created   : Tue Nov 25 11:04:59 2008
24 // Author    : Edward AGAPOV (eap)
25
26 #include "StdMeshers_CompositeHexa_3D.hxx"
27
28 #include "SMDS_Mesh.hxx"
29 #include "SMDS_MeshNode.hxx"
30 #include "SMDS_SetIterator.hxx"
31 #include "SMESHDS_Mesh.hxx"
32 #include "SMESHDS_SubMesh.hxx"
33 #include "SMESH_Block.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_ComputeError.hxx"
36 #include "SMESH_HypoFilter.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MeshAlgos.hxx"
39 #include "SMESH_MesherHelper.hxx"
40 #include "SMESH_subMesh.hxx"
41 #include "StdMeshers_BlockRenumber.hxx"
42 #include "StdMeshers_FaceSide.hxx"
43 #include "StdMeshers_ViscousLayers.hxx"
44
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRep_Tool.hxx>
47 #include <Bnd_B3d.hxx>
48 #include <Standard_ErrorHandler.hxx>
49 #include <Standard_Failure.hxx>
50 #include <TopExp_Explorer.hxx>
51 #include <TopTools_IndexedMapOfShape.hxx>
52 #include <TopTools_MapIteratorOfMapOfShape.hxx>
53 #include <TopTools_MapOfShape.hxx>
54 #include <TopTools_SequenceOfShape.hxx>
55 #include <TopoDS.hxx>
56 #include <TopoDS_Edge.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Vertex.hxx>
59 #include <gp_Pnt.hxx>
60 #include <gp_Pnt2d.hxx>
61 #include <gp_Vec.hxx>
62 #include <gp_XYZ.hxx>
63
64 #include <list>
65 #include <numeric>
66 #include <set>
67 #include <vector>
68
69 using namespace std;
70
71 #ifdef _DEBUG_
72 // #define DEB_FACES
73 // #define DEB_GRID
74 // #define DUMP_VERT(msg,V) { TopoDS_Vertex v = V; gp_Pnt p = BRep_Tool::Pnt(v); cout << msg << "( "<< p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl; }
75 #endif
76
77 #ifndef DUMP_VERT
78 #define DUMP_VERT(msg,v)
79 #endif
80
81 //================================================================================
82 // text for message about an internal error
83 #define ERR_LI(txt) SMESH_Comment(txt) << ":" << __LINE__
84
85 // order corresponds to right order of edges in CASCADE face
86 enum EQuadSides{ Q_BOTTOM=0, Q_RIGHT, Q_TOP, Q_LEFT,   Q_CHILD, Q_PARENT };
87
88 enum EBoxSides{ B_BOTTOM=0, B_RIGHT, B_TOP, B_LEFT, B_FRONT, B_BACK, B_UNDEFINED };
89
90 enum EAxes{ COO_X=1, COO_Y, COO_Z };
91
92 //================================================================================
93 /*!
94  * \brief Converter of a pair of integers to a sole index
95  */
96 struct _Indexer
97 {
98   int _xSize, _ySize;
99   _Indexer( int xSize, int ySize ): _xSize(xSize), _ySize(ySize) {}
100   int size() const { return _xSize * _ySize; }
101   int operator()(const int x, const int y) const { return y * _xSize + x; }
102 };
103
104 //================================================================================
105 /*!
106  * \brief Wrapper of a composite or an ordinary edge.
107  */
108 class _FaceSide
109 {
110 public:
111   _FaceSide(const _FaceSide& other);
112   _FaceSide(const TopoDS_Edge& edge=TopoDS_Edge());
113   _FaceSide(const list<TopoDS_Edge>& edges);
114   _FaceSide* GetSide(const int i);
115   const _FaceSide* GetSide(const int i) const;
116   int size() const { return myChildren.size(); }
117   int NbVertices() const;
118   int NbCommonVertices( const TopTools_MapOfShape& VV ) const;
119   TopoDS_Vertex FirstVertex() const;
120   TopoDS_Vertex LastVertex() const;
121   TopoDS_Vertex Vertex(int i) const;
122   TopoDS_Edge   Edge(int i) const;
123   bool Contain( const _FaceSide& side, int* which=0 ) const;
124   bool Contain( const TopoDS_Vertex& vertex ) const;
125   void AppendSide( const _FaceSide& side );
126   void SetBottomSide( int i );
127   smIdType GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges=0) const;
128   bool StoreNodes(SMESH_ProxyMesh& mesh, vector<const SMDS_MeshNode*>& myGrid,
129                   bool reverse, bool isProxy, const SMESHDS_SubMesh* smToCheckEdges=0 );
130   void SetID(EQuadSides id) { myID = id; }
131   static inline const TopoDS_TShape* ptr(const TopoDS_Shape& theShape)
132   { return theShape.TShape().operator->(); }
133   void Dump() const;
134
135 private:
136
137
138   TopoDS_Edge       myEdge;
139   list< _FaceSide > myChildren;
140   int               myNbChildren;
141
142   TopTools_MapOfShape myVertices;
143
144   EQuadSides        myID; // debug
145 };
146 //================================================================================
147 /*!
148  * \brief Class corresponding to a meshed composite face of a box.
149  *        Provides simplified access to it's sub-mesh data.
150  */
151 class _QuadFaceGrid
152 {
153   typedef list< _QuadFaceGrid > TChildren;
154 public:
155   _QuadFaceGrid();
156
157 public: //** Methods to find and orient faces of 6 sides of the box **//
158   
159   //!< initialization
160   bool Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh );
161
162   //!< try to unite self with other face
163   bool AddContinuousFace( const _QuadFaceGrid& f, const TopTools_MapOfShape& internalEdges );
164
165   //!< Try to set the side as bottom hirizontal side
166   bool SetBottomSide(const _FaceSide& side, int* sideIndex=0);
167
168   //!< Return face adjacent to zero-based i-th side of this face
169   _QuadFaceGrid* FindAdjacentForSide(int i, list<_QuadFaceGrid>& faces, EBoxSides id) const;
170
171   //!< Reverse edges in order to have the bottom edge going along axes of the unit box
172   void ReverseEdges();
173
174   bool IsComplex() const { return !myChildren.empty(); }
175
176   int NbChildren() const { return myChildren.size(); }
177
178   typedef SMDS_SetIterator< const _QuadFaceGrid&,
179                             TChildren::const_iterator,
180                             SMDS::SimpleAccessor<const _QuadFaceGrid&,TChildren::const_iterator>,
181                             SMDS::PassAllValueFilter<_QuadFaceGrid> >
182     TChildIterator;
183
184   TChildIterator GetChildren() const
185   { return TChildIterator( myChildren.begin(), myChildren.end()); }
186
187   bool Contain( const TopoDS_Vertex& vertex ) const { return mySides.Contain( vertex ); }
188
189 public: //** Loading and access to mesh **//
190
191   //!< Load nodes of a mesh
192   bool LoadGrid( SMESH_ProxyMesh& mesh );
193
194   //!< Computes normalized parameters of nodes of myGrid
195   void ComputeIJK( int i1, int i2, double v3 );
196
197   //!< Return number of segments on the hirizontal sides
198   int GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
199
200   //!< Return number of segments on the vertical sides
201   int GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
202
203   //!< Return edge on the hirizontal bottom sides
204   int GetHoriEdges(vector<TopoDS_Edge> & edges) const;
205
206   //!< Return a node by its position
207   const SMDS_MeshNode* GetNode(int iHori, int iVert) const;
208
209   //!< Return node coordinates by its position
210   gp_XYZ GetXYZ(int iHori, int iVert) const;
211
212   //!< Return normalized parameters of nodes within the unitary cube
213   gp_XYZ& GetIJK(int iCol, int iRow) { return myIJK[ myIndexer( iCol, iRow )]; }
214
215 public: //** Access to member fields **//
216
217   //!< Return i-th face side (0<i<4)
218   const _FaceSide& GetSide(int i) const;
219
220   //!< Return it's face, NULL if it is composite
221   TopoDS_Face GetFace() const { return myFace; }
222
223   //!< Return normal to the face at vertex v
224   bool GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const;
225
226   SMESH_ComputeErrorPtr GetError() const { return myError; }
227
228   void SetID(EBoxSides id) { myID = id; }
229
230   void DumpGrid() const;
231
232   void DumpVertices() const;
233
234 private:
235
236   bool error(const std::string& text, int code = COMPERR_ALGO_FAILED)
237   { myError = SMESH_ComputeError::New( code, text ); return false; }
238
239   bool error(const SMESH_ComputeErrorPtr& err)
240   { myError = err; return ( !myError || myError->IsOK() ); }
241
242   bool loadCompositeGrid(SMESH_ProxyMesh& mesh);
243
244   bool fillGrid(SMESH_ProxyMesh&               theMesh,
245                 vector<const SMDS_MeshNode*> & theGrid,
246                 const _Indexer&                theIndexer,
247                 int                            theX,
248                 int                            theY);
249
250   bool locateChildren();
251
252   void setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers );
253
254   TopoDS_Face myFace;
255   _FaceSide   mySides;
256   bool        myReverse;
257
258   TChildren   myChildren;
259
260   _QuadFaceGrid* myLeftBottomChild;
261   _QuadFaceGrid* myRightBrother;
262   _QuadFaceGrid* myUpBrother;
263
264   _Indexer                      myIndexer;
265   vector<const SMDS_MeshNode*>  myGrid;
266   vector<gp_XYZ>                myIJK; // normalized parameters of nodes
267
268   SMESH_ComputeErrorPtr         myError;
269
270   EBoxSides   myID; // debug
271 };
272
273 //================================================================================
274 /*!
275  * \brief Constructor
276  */
277 //================================================================================
278
279 StdMeshers_CompositeHexa_3D::StdMeshers_CompositeHexa_3D(int hypId, SMESH_Gen* gen)
280   :SMESH_3D_Algo(hypId, gen), _blockRenumberHyp( nullptr )
281 {
282   _name = "CompositeHexa_3D";
283   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);       // 1 bit /shape type
284 }
285
286 //================================================================================
287 /*!
288  * \brief always return true
289  */
290 //================================================================================
291
292 bool StdMeshers_CompositeHexa_3D::CheckHypothesis(SMESH_Mesh&         /*aMesh*/,
293                                                   const TopoDS_Shape& /*aShape*/,
294                                                   Hypothesis_Status&  aStatus)
295 {
296   _blockRenumberHyp = nullptr;
297   aStatus = HYP_OK;
298   return true;
299 }
300
301 namespace
302 {
303
304   //================================================================================
305   /*!
306    * \brief Checks structure of a quadrangular mesh at the common VERTEX of two EDGEs.
307    *        Returns true if there are two quadrangles near the VERTEX.
308    */
309   //================================================================================
310
311   bool isContinuousMesh(TopoDS_Edge            E1,
312                         TopoDS_Edge            E2,
313                         const TopoDS_Face&     F,
314                         const SMESH_ProxyMesh& mesh)
315   {
316     if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
317       E1.Orientation( TopAbs_FORWARD );
318     if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
319       E2.Orientation( TopAbs_FORWARD );
320
321     TopoDS_Vertex V;
322     if ( !TopExp::CommonVertex( E1, E2, V )) return false;
323
324     const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
325     if ( !n ) return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
326
327     n = mesh.GetProxyNode( n );
328
329     const SMESHDS_SubMesh* sm = mesh.GetSubMesh( F );
330     if ( !sm ) return false;
331
332     int nbQuads = 0;
333     SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
334     if ( !fIt->more() )
335       return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
336     while ( fIt->more() )
337     {
338       const SMDS_MeshElement* f = fIt->next();
339       if ( !sm->Contains( f )) continue;
340
341       if ( f->NbCornerNodes() == 4 )
342         ++nbQuads;
343       else
344         return false;
345     }
346     return nbQuads == 2;
347   }
348
349   //================================================================================
350   /*!
351    * \brief Return true if a vertex holds a node and this node is used by some quadrangle
352    */
353   //================================================================================
354
355   // bool isMeshedVertex( TopoDS_Vertex&     V,
356   //                      const SMESH_Mesh&  mesh )
357   // {
358   //   const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
359   //   if ( !n ) return false;
360     
361   //   SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
362   //   while ( fIt->more() )
363   //   {
364   //     const SMDS_MeshElement* f = fIt->next();
365   //     if ( f->NbCornerNodes() == 4 )
366   //       return true;
367   //   }
368   //   return false;
369   // }
370
371   //================================================================================
372   /*!
373    * \brief Finds VERTEXes located at block corners
374    */
375   //================================================================================
376
377   void getBlockCorners( SMESH_ProxyMesh&     mesh,
378                         const TopoDS_Shape&  shape,
379                         TopTools_MapOfShape& cornerVV)
380   {
381     std::set<int> faceIDs; // ids of FACEs in the shape
382     TopExp_Explorer exp;
383     for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
384       faceIDs.insert( mesh.GetMeshDS()->ShapeToIndex( exp.Current() ));
385
386     TopTools_MapOfShape checkedVV;
387     for ( exp.Init( shape, TopAbs_VERTEX ); exp.More(); exp.Next() )
388     {
389       TopoDS_Vertex V = TopoDS::Vertex( exp.Current() );
390       if ( !checkedVV.Add( V )) continue;
391
392       const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
393       if ( !n ) continue;
394
395       const SMDS_MeshNode* nProxy = mesh.GetProxyNode( n );
396       bool isProxy = ( nProxy != n );
397       n = nProxy;
398
399       int nbQuads = 0;
400       SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
401       while ( fIt->more() )
402       {
403         const SMDS_MeshElement* f = fIt->next();
404         if ( !faceIDs.count( f->getshapeId() )) continue;
405
406         if ( isProxy && !mesh.GetSubMesh( f->getshapeId() )->Contains( f ))
407           continue;
408
409         if ( f->NbCornerNodes() == 4 )
410           ++nbQuads;
411         else
412           nbQuads = 100;
413       }
414       if ( nbQuads == 3 )
415         cornerVV.Add( V );
416     }
417   }
418
419   //================================================================================
420   /*!
421    * \brief Return EDGEs dividing one box side
422    */
423   //================================================================================
424
425   bool getInternalEdges( SMESH_Mesh&                mesh,
426                          const TopoDS_Shape&        shape,
427                          const TopTools_MapOfShape& cornerVV,
428                          TopTools_MapOfShape&       internEE)
429   {
430     TopTools_IndexedMapOfShape subEE, subFF;
431     TopExp::MapShapes( shape, TopAbs_EDGE, subEE );
432     TopExp::MapShapes( shape, TopAbs_FACE, subFF );
433
434     TopoDS_Vertex VV[2];
435     TopTools_MapOfShape subChecked, ridgeEE;
436     TopTools_MapIteratorOfMapOfShape vIt( cornerVV );
437     for ( ; vIt.More(); vIt.Next() )
438     {
439       TopoDS_Shape V0 = vIt.Key();
440       // walk from one corner VERTEX to another along ridge EDGEs
441       PShapeIteratorPtr riIt = SMESH_MesherHelper::GetAncestors( V0, mesh, TopAbs_EDGE );
442       while ( const TopoDS_Shape* riE = riIt->next() )
443       {
444         if ( !subEE.Contains( *riE ) || !subChecked.Add( *riE ))
445           continue;
446         TopoDS_Edge ridgeE = TopoDS::Edge( *riE );
447         while ( !ridgeE.IsNull() )
448         {
449           if ( !ridgeEE.Add( ridgeE ))
450             break;
451           TopExp::Vertices( ridgeE, VV[0], VV[1] );
452           TopoDS_Shape V1 = VV[ V0.IsSame( VV[0] )];
453           if ( cornerVV.Contains( V1 ) )
454             break; // ridgeE reached a corner VERTEX
455
456           // detect internal EDGEs among those sharing V1. There can be 2, 3 or 4 EDGEs and
457           // number of internal EDGEs is N-2
458           TopoDS_Shape nextRidgeE;
459           PShapeIteratorPtr eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
460           while ( const TopoDS_Shape* E = eIt->next() )
461           {
462             if ( E->IsSame( ridgeE ) || !subEE.Contains( *E ) || !subChecked.Add( *E ))
463               continue;
464             // look for FACEs sharing both E and ridgeE
465             PShapeIteratorPtr fIt = SMESH_MesherHelper::GetAncestors( *E, mesh, TopAbs_FACE );
466             while ( const TopoDS_Shape* F = fIt->next() )
467             {
468               if ( !SMESH_MesherHelper::IsSubShape( ridgeE, *F ))
469                 continue;
470               if ( !subFF.Contains( *F ))
471                 continue;
472               if ( isContinuousMesh( ridgeE, TopoDS::Edge( *E ), TopoDS::Face( *F ), mesh ))
473               {
474                 nextRidgeE = *E;
475               }
476               else
477               {
478                 internEE.Add( *E );
479               }
480               break;
481             }
482           }
483           // look for the next ridge EDGE ending at V1
484           if ( nextRidgeE.IsNull() )
485           {
486             eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
487             while ( const TopoDS_Shape* E = eIt->next() )
488               if ( !ridgeE.IsSame( *E ) && !internEE.Contains( *E ) && subEE.Contains( *E ))
489               {
490                 nextRidgeE = *E;
491                 break;
492               }
493           }
494           ridgeE = TopoDS::Edge( nextRidgeE );
495           V0 = V1;
496
497           if ( ridgeE.IsNull() )
498             return false;
499         } // check EDGEs around the last VERTEX of ridgeE 
500       } // loop on ridge EDGEs around a corner VERTEX
501     } // loop on on corner VERTEXes
502
503     if ( subEE.Extent() > ridgeEE.Extent() + internEE.Extent() ) // PAL23269
504       for ( int i = 1; i < subEE.Extent(); ++i )
505         if ( !ridgeEE.Contains( subEE(i) ))
506           internEE.Add( subEE(i) );
507
508     return true;
509   } // getInternalEdges()
510
511   //================================================================================
512   /*!
513    * \brief Find a face including two given nodes
514    */
515   //================================================================================
516
517   const SMDS_MeshElement* FindFaceByNodes( const SMDS_MeshNode* n1,
518                                            const SMDS_MeshNode* n2,
519                                            TIDSortedElemSet     avoidSet,
520                                            SMESH_ProxyMesh&     mesh)
521   {
522     SMDS_ElemIteratorPtr faceIt = mesh.GetInverseElementIterator( n1, SMDSAbs_Face );
523     while ( faceIt->more() )
524     {
525       const SMDS_MeshElement* f = faceIt->next();
526       if ( !avoidSet.count( f ) && f->GetNodeIndex( n2 ) >= 0 )
527         return f;
528     }
529     return 0;
530   }
531
532   //================================================================================
533   /*!
534    * \brief Check that a segment bounds a face belonging to smOfFaces
535    */
536   //================================================================================
537
538   bool IsSegmentOnSubMeshBoundary( const SMDS_MeshNode*   n1,
539                                    const SMDS_MeshNode*   n2,
540                                    const SMESHDS_SubMesh* smOfFaces,
541                                    SMESH_ProxyMesh&       mesh)
542   {
543     TIDSortedElemSet avoidSet;
544     bool faceFound = false;
545
546     while ( const SMDS_MeshElement* f = FindFaceByNodes( n1, n2, avoidSet, mesh ))
547     {
548       if (( faceFound = smOfFaces->Contains( f )))
549         break;
550       avoidSet.insert( f );
551     }
552     return faceFound;
553   }
554
555     //================================================================================
556   /*!
557    * \brief Rearrange block sides according to StdMeshers_BlockRenumber hypothesis
558    */
559   //================================================================================
560
561   bool arrangeForRenumber( list< _QuadFaceGrid >&     blockSides,
562                            const TopTools_MapOfShape& cornerVertices,
563                            SMESH_Mesh*                mesh,
564                            TopoDS_Vertex&             v000,
565                            TopoDS_Vertex&             v001 )
566   {
567     if ( v000.IsNull() )
568     {
569       // block CS is not defined;
570       // renumber only if the block has an edge parallel to an axis of global CS
571
572       v000 = StdMeshers_RenumberHelper::GetVertex000( cornerVertices );
573     }
574
575     Bnd_B3d bbox;
576     for ( auto it = cornerVertices.cbegin(); it != cornerVertices.cend(); ++it )
577       bbox.Add( BRep_Tool::Pnt( TopoDS::Vertex( *it )));
578     double tol = 1e-5 * Sqrt( bbox.SquareExtent() );
579
580     // get block edges starting at v000
581
582     std::vector< const _FaceSide* > edgesAtV000;
583     std::vector< gp_Vec >           edgeDir;
584     std::vector< int >              iParallel; // 0 - none, 1 - X, 2 - Y, 3 - Z
585     TopTools_MapOfShape             lastVertices;
586     for ( _QuadFaceGrid & quad: blockSides )
587     {
588       for ( int iS = 0; iS < 4 &&  edgesAtV000.size() < 3; ++iS )
589       {
590         const _FaceSide* side = & quad.GetSide( iS );
591         TopoDS_Vertex v1 = side->FirstVertex(), v2 = side->LastVertex();
592         if (( v1.IsSame( v000 ) && !lastVertices.Contains( v2 )) ||
593             ( v2.IsSame( v000 ) && !lastVertices.Contains( v1 )))
594         {
595           bool reverse = v2.IsSame( v000 );
596           if ( reverse )
597             std::swap( v1, v2 );
598           lastVertices.Add( v2 );
599
600           edgesAtV000.push_back( side );
601
602           gp_Pnt pf = BRep_Tool::Pnt( v1 );
603           gp_Pnt pl = BRep_Tool::Pnt( v2 );
604           gp_Vec vec( pf, pl );
605           edgeDir.push_back( vec );
606
607           iParallel.push_back( 0 );
608           if ( !v001.IsNull() )
609           {
610             if ( quad.IsComplex() )
611               for ( _QuadFaceGrid::TChildIterator chIt = quad.GetChildren(); chIt.more(); )
612               {
613                 const _QuadFaceGrid& child = chIt.next();
614                 if ( child.GetSide( iS ).Contain( v001 ))
615                 {
616                   iParallel.back() = 3;
617                   break;
618                 }
619               }
620             else if ( side->Contain( v001 ))
621               iParallel.back() = 3;
622           }
623           else
624           {
625             bool isStraight = true;
626             std::list< TopoDS_Edge > edges;
627             for ( int iE = 0; true; ++iE )
628             {
629               TopoDS_Edge edge = side->Edge( iE );
630               if ( edge.IsNull() )
631                 break;
632               edges.push_back( edge );
633               if ( isStraight )
634                 isStraight = SMESH_Algo::IsStraight( edge );
635             }
636             // is parallel to a GCS axis?
637             if ( isStraight )
638             {
639               int nbDiff = (( Abs( vec.X() ) > tol ) +
640                             ( Abs( vec.Y() ) > tol ) +
641                             ( Abs( vec.Z() ) > tol ) );
642               if ( nbDiff == 1 )
643                 iParallel.back() = ( Abs( vec.X() ) > tol ) ? 1 : ( Abs( vec.Y() ) > tol ) ? 2 : 3;
644             }
645             else
646             {
647               TopoDS_Face nullFace;
648               StdMeshers_FaceSide fSide( nullFace, edges, mesh, true, true );
649               edgeDir.back() = gp_Vec( pf, fSide.Value3d( reverse ? 0.99 : 0.01 ));
650             }
651           }
652         }
653       }
654     }
655     if ( std::accumulate( iParallel.begin(), iParallel.end(), 0 ) == 0 )
656       return false;
657
658     // find edge OZ and edge OX
659     const _FaceSide* edgeOZ = nullptr, *edgeOY = nullptr, *edgeOX = nullptr;
660     auto iZIt = std::find( iParallel.begin(), iParallel.end(), 3 );
661     if ( iZIt != iParallel.end() )
662     {
663       int i = std::distance( iParallel.begin(), iZIt );
664       edgeOZ = edgesAtV000[ i ];
665       int iE1 = SMESH_MesherHelper::WrapIndex( i + 1, edgesAtV000.size() );
666       int iE2 = SMESH_MesherHelper::WrapIndex( i + 2, edgesAtV000.size() );
667       if (( edgeDir[ iE1 ] ^ edgeDir[ iE2 ] ) * edgeDir[ i ] < 0 )
668         std::swap( iE1, iE2 );
669       edgeOX = edgesAtV000[ iE1 ];
670       edgeOY = edgesAtV000[ iE2 ];
671     }
672     else
673     {
674       for ( size_t i = 0; i < edgesAtV000.size(); ++i )
675       {
676         if ( !iParallel[ i ] )
677           continue;
678         int iE1 = SMESH_MesherHelper::WrapIndex( i + 1, edgesAtV000.size() );
679         int iE2 = SMESH_MesherHelper::WrapIndex( i + 2, edgesAtV000.size() );
680         if (( edgeDir[ iE1 ] ^ edgeDir[ iE2 ] ) * edgeDir[ i ] < 0 )
681           std::swap( iE1, iE2 );
682         edgeOZ = edgesAtV000[ iParallel[i] == 1 ? iE2 : iE1 ];
683         edgeOX = edgesAtV000[ iParallel[i] == 1 ? i : iE1 ];
684         edgeOY = edgesAtV000[ iParallel[i] == 1 ? iE1 : i ];
685         break;
686       }
687     }
688
689     if ( !edgeOZ || !edgeOX || !edgeOY )
690       return false;
691
692     TopoDS_Vertex v100 = edgeOX->LastVertex();
693     if ( v100.IsSame( v000 ))
694       v100 = edgeOX->FirstVertex();
695
696     // Find the left quad, one including v000 but not v100
697
698     for ( auto quad = blockSides.begin(); quad != blockSides.end(); ++quad )
699     {
700       if ( quad->Contain( v000 ) && !quad->Contain( v100 )) // it's a left quad
701       {
702         if ( quad != blockSides.begin() )
703           blockSides.splice( blockSides.begin(), blockSides, quad );
704         blockSides.front().SetBottomSide( *edgeOZ ); // edgeOY
705
706         return true;
707       }
708     }
709     return false;
710   }
711
712 } // namespace
713
714 //================================================================================
715 /*!
716  * \brief Tries to find 6 sides of a box
717  */
718 //================================================================================
719
720 bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape&    shape,
721                                                 list< _QuadFaceGrid >& boxFaces,
722                                                 SMESH_Mesh&            mesh,
723                                                 SMESH_ProxyMesh&       proxyMesh,
724                                                 bool&                  toRenumber,
725                                                 _QuadFaceGrid * &      fBottom,
726                                                 _QuadFaceGrid * &      fTop,
727                                                 _QuadFaceGrid * &      fFront,
728                                                 _QuadFaceGrid * &      fBack,
729                                                 _QuadFaceGrid * &      fLeft,
730                                                 _QuadFaceGrid * &      fRight)
731 {
732   TopTools_MapOfShape cornerVertices;
733   getBlockCorners( proxyMesh, shape, cornerVertices );
734   if ( cornerVertices.Extent() != 8 )
735     return error( COMPERR_BAD_INPUT_MESH, "Can't find 8 corners of a block by 2D mesh" );
736   TopTools_MapOfShape internalEdges;
737   if ( !getInternalEdges( mesh, shape, cornerVertices, internalEdges ))
738     return error( COMPERR_BAD_INPUT_MESH, "2D mesh is not suitable for i,j,k hexa meshing" );
739
740   list< _QuadFaceGrid >::iterator boxFace;
741   TopExp_Explorer exp;
742   int nbFaces = 0;
743   for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFaces )
744   {
745     _QuadFaceGrid f;
746     if ( !f.Init( TopoDS::Face( exp.Current() ), proxyMesh ))
747       return error (COMPERR_BAD_SHAPE);
748
749     _QuadFaceGrid* prevContinuous = 0;
750     for ( boxFace = boxFaces.begin(); boxFace != boxFaces.end(); ++boxFace )
751     {
752       if ( prevContinuous )
753       {
754         if ( prevContinuous->AddContinuousFace( *boxFace, internalEdges ))
755           boxFace = --boxFaces.erase( boxFace );
756       }
757       else if ( boxFace->AddContinuousFace( f, internalEdges ))
758       {
759         prevContinuous = & (*boxFace);
760       }
761     }
762     if ( !prevContinuous )
763       boxFaces.push_back( f );
764   }
765   // Check what we have
766   if ( boxFaces.size() != 6 && nbFaces != 6)
767     return error
768       (COMPERR_BAD_SHAPE,
769        SMESH_Comment("Can't find 6 sides of a box. Number of found sides - ")<<boxFaces.size());
770
771   if ( boxFaces.size() != 6 && nbFaces == 6 ) { // strange ordinary box with continuous faces
772     boxFaces.resize( 6 );
773     boxFace = boxFaces.begin();
774     for ( exp.Init( shape, TopAbs_FACE); exp.More(); exp.Next(), ++boxFace )
775       boxFace->Init( TopoDS::Face( exp.Current() ), proxyMesh );
776   }
777
778   toRenumber = _blockRenumberHyp;
779   if ( toRenumber )
780   {
781     TopoDS_Vertex v000, v001;
782     _blockRenumberHyp->IsSolidIncluded( mesh, shape, v000, v001 );
783
784     toRenumber = arrangeForRenumber( boxFaces, cornerVertices, &mesh, v000, v001 );
785
786     if ( toRenumber )
787     {
788       mesh.GetMeshDS()->Modified();
789       mesh.GetMeshDS()->CompactMesh(); // remove numbering holes
790     }
791   }
792   
793   // ----------------------------------------
794   // Find out position of faces within a box
795   // ----------------------------------------
796   // start from a bottom face
797   fBottom = &boxFaces.front();
798   fBottom->SetID( B_BOTTOM );
799   // find vertical faces
800   fFront = fBottom->FindAdjacentForSide( Q_BOTTOM, boxFaces, B_FRONT );
801   fLeft  = fBottom->FindAdjacentForSide( Q_RIGHT,  boxFaces, B_LEFT  );
802   fBack  = fBottom->FindAdjacentForSide( Q_TOP,    boxFaces, B_BACK  );
803   fRight = fBottom->FindAdjacentForSide( Q_LEFT,   boxFaces, B_RIGHT );
804   // check the found
805   if ( !fFront || !fBack || !fLeft || !fRight )
806     return error(COMPERR_BAD_SHAPE);
807   // find a top face
808   fTop = 0;
809   for ( boxFace = ++boxFaces.begin(); boxFace != boxFaces.end() && !fTop; ++boxFace )
810   {
811     fTop = & (*boxFace);
812     fTop->SetID( B_TOP );
813     if ( fTop==fFront || fTop==fLeft || fTop==fBack || fTop==fRight )
814       fTop = 0;
815   }
816   // set bottom of the top side
817   if ( !fTop->SetBottomSide( fFront->GetSide( Q_TOP ) )) {
818     if ( !fFront->IsComplex() )
819       return error( ERR_LI("Error in StdMeshers_CompositeHexa_3D::Compute()"));
820     else {
821       _QuadFaceGrid::TChildIterator chIt = fFront->GetChildren();
822       while ( chIt.more() ) {
823         const _QuadFaceGrid& frontChild = chIt.next();
824         if ( fTop->SetBottomSide( frontChild.GetSide( Q_TOP )))
825           break;
826       }
827     }
828   }
829   if ( !fTop )
830     return error(COMPERR_BAD_SHAPE);
831
832   // orient bottom edge of faces along axes of the unit box
833   fBottom->ReverseEdges();
834   fBack  ->ReverseEdges();
835   fLeft  ->ReverseEdges();
836
837   return true;
838 }
839
840 //================================================================================
841 /*!
842  * \brief Computes hexahedral mesh on a box with composite sides
843  *  \param aMesh - mesh to compute
844  *  \param aShape - shape to mesh
845  *  \retval bool - success sign
846  */
847 //================================================================================
848
849 bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh&         theMesh,
850                                           const TopoDS_Shape& theShape)
851 {
852   SMESH_MesherHelper helper( theMesh );
853   _quadraticMesh = helper.IsQuadraticSubMesh( theShape );
854   helper.SetElementsOnShape( true );
855
856   // get Viscous Mesh
857   SMESH_ProxyMesh::Ptr proxyMesh;
858   SMESH_HypoFilter vlFilter( SMESH_HypoFilter::HasName( StdMeshers_ViscousLayers::GetHypType() ));
859   const SMESH_Hypothesis *          hyp = theMesh.GetHypothesis( theShape, vlFilter, true );
860   const StdMeshers_ViscousLayers* vlHyp = static_cast< const StdMeshers_ViscousLayers* >( hyp );
861   if ( vlHyp )
862     proxyMesh = vlHyp->Compute( theMesh, theShape, /*toMakeN2NMap=*/true );
863   else
864     proxyMesh.reset( new SMESH_ProxyMesh( theMesh ));
865
866   // -------------------------
867   // Try to find 6 side faces
868   // -------------------------
869   list< _QuadFaceGrid > boxFaceContainer;
870   bool toRenumber = false;
871   _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
872   if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh, toRenumber,
873                        fBottom, fTop, fFront, fBack, fLeft, fRight))
874     return false;
875
876   // ------------------------------------------
877   // Fill columns of nodes with existing nodes
878   // ------------------------------------------
879
880   // let faces load their grids
881   if ( !fBottom->LoadGrid( *proxyMesh )) return error( fBottom->GetError() );
882   if ( !fBack  ->LoadGrid( *proxyMesh )) return error( fBack  ->GetError() );
883   if ( !fLeft  ->LoadGrid( *proxyMesh )) return error( fLeft  ->GetError() );
884   if ( !fFront ->LoadGrid( *proxyMesh )) return error( fFront ->GetError() );
885   if ( !fRight ->LoadGrid( *proxyMesh )) return error( fRight ->GetError() );
886   if ( !fTop   ->LoadGrid( *proxyMesh )) return error( fTop   ->GetError() );
887
888   // compute normalized parameters of nodes on sides (PAL23189)
889   fBottom->ComputeIJK( COO_X, COO_Y, /*z=*/0. );
890   fBack  ->ComputeIJK( COO_X, COO_Z, /*y=*/1. );
891   fLeft  ->ComputeIJK( COO_Y, COO_Z, /*x=*/0. );
892   fFront ->ComputeIJK( COO_X, COO_Z, /*y=*/0. );
893   fRight ->ComputeIJK( COO_Y, COO_Z, /*x=*/1. );
894   fTop   ->ComputeIJK( COO_X, COO_Y, /*z=*/1. );
895
896   StdMeshers_RenumberHelper renumHelper( theMesh, _blockRenumberHyp );
897
898   int x, xSize = fBottom->GetNbHoriSegments(*proxyMesh) + 1, X = xSize - 1;
899   int y, ySize = fBottom->GetNbVertSegments(*proxyMesh) + 1, Y = ySize - 1;
900   int z, zSize = fFront ->GetNbVertSegments(*proxyMesh) + 1, Z = zSize - 1;
901   _Indexer colIndex( xSize, ySize );
902   vector< vector< const SMDS_MeshNode* > > columns( colIndex.size() );
903
904   // fill node columns by front and back box sides
905   for ( x = 0; x < xSize; ++x ) {
906     vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( x, 0 )];
907     vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( x, Y )];
908     column0.resize( zSize );
909     column1.resize( zSize );
910     for ( z = 0; z < zSize; ++z ) {
911       column0[ z ] = fFront->GetNode( x, z );
912       column1[ z ] = fBack ->GetNode( x, z );
913     }
914   }
915   // fill node columns by left and right box sides
916   for ( y = 1; y < ySize-1; ++y ) {
917     vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( 0, y )];
918     vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( X, y )];
919     column0.resize( zSize );
920     column1.resize( zSize );
921     for ( z = 0; z < zSize; ++z ) {
922       column0[ z ] = fLeft ->GetNode( y, z );
923       column1[ z ] = fRight->GetNode( y, z );
924     }
925   }
926   // get nodes from top and bottom box sides
927   for ( x = 1; x < xSize-1; ++x ) {
928     for ( y = 1; y < ySize-1; ++y ) {
929       vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
930       column.resize( zSize );
931       column.front() = fBottom->GetNode( x, y );
932       column.back()  = fTop   ->GetNode( x, y );
933     }
934   }
935
936   // ----------------------------
937   // Add internal nodes of a box
938   // ----------------------------
939   // projection points of internal nodes on box sub-shapes by which
940   // coordinates of internal nodes are computed
941   vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
942
943   // projections on vertices are constant
944   pointsOnShapes[ SMESH_Block::ID_V000 ] = fBottom->GetXYZ( 0, 0 );
945   pointsOnShapes[ SMESH_Block::ID_V100 ] = fBottom->GetXYZ( X, 0 );
946   pointsOnShapes[ SMESH_Block::ID_V010 ] = fBottom->GetXYZ( 0, Y );
947   pointsOnShapes[ SMESH_Block::ID_V110 ] = fBottom->GetXYZ( X, Y );
948   pointsOnShapes[ SMESH_Block::ID_V001 ] = fTop->GetXYZ( 0, 0 );
949   pointsOnShapes[ SMESH_Block::ID_V101 ] = fTop->GetXYZ( X, 0 );
950   pointsOnShapes[ SMESH_Block::ID_V011 ] = fTop->GetXYZ( 0, Y );
951   pointsOnShapes[ SMESH_Block::ID_V111 ] = fTop->GetXYZ( X, Y );
952
953   gp_XYZ params; // normalized parameters of an internal node within the unit box
954
955   if ( toRenumber )
956     for ( y = 0; y < ySize; ++y )
957     {
958       vector< const SMDS_MeshNode* >& columnXy = columns[ colIndex( X, y )];
959       for ( z = 0; z < zSize; ++z )
960         renumHelper.AddReplacingNode( columnXy[ z ] );
961     }
962
963   for ( x = X-1; x > 0; --x )
964   {
965     if ( toRenumber )
966     {
967       vector< const SMDS_MeshNode* >& columnX0 = columns[ colIndex( x, 0 )];
968       for ( z = 0; z < zSize; ++z )
969         renumHelper.AddReplacingNode( columnX0[ z ] );
970     }
971
972     const double rX = x / double(X);
973     for ( y = 1; y < ySize-1; ++y )
974     {
975       const double rY = y / double(Y);
976       // column to fill during z loop
977       vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
978       // points projections on horizontal edges
979       pointsOnShapes[ SMESH_Block::ID_Ex00 ] = fBottom->GetXYZ( x, 0 );
980       pointsOnShapes[ SMESH_Block::ID_Ex10 ] = fBottom->GetXYZ( x, Y );
981       pointsOnShapes[ SMESH_Block::ID_E0y0 ] = fBottom->GetXYZ( 0, y );
982       pointsOnShapes[ SMESH_Block::ID_E1y0 ] = fBottom->GetXYZ( X, y );
983       pointsOnShapes[ SMESH_Block::ID_Ex01 ] = fTop->GetXYZ( x, 0 );
984       pointsOnShapes[ SMESH_Block::ID_Ex11 ] = fTop->GetXYZ( x, Y );
985       pointsOnShapes[ SMESH_Block::ID_E0y1 ] = fTop->GetXYZ( 0, y );
986       pointsOnShapes[ SMESH_Block::ID_E1y1 ] = fTop->GetXYZ( X, y );
987       // points projections on horizontal faces
988       pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = fBottom->GetXYZ( x, y );
989       pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = fTop   ->GetXYZ( x, y );
990
991       if ( toRenumber )
992         renumHelper.AddReplacingNode( column[ 0 ] );
993
994       for ( z = 1; z < zSize-1; ++z ) // z loop
995       {
996         // compute normalized parameters of an internal node within the unit box
997         const double   rZ = z / double(Z);
998         const gp_XYZ& pBo = fBottom->GetIJK( x, y );
999         const gp_XYZ& pTo = fTop   ->GetIJK( x, y );
1000         const gp_XYZ& pFr = fFront ->GetIJK( x, z );
1001         const gp_XYZ& pBa = fBack  ->GetIJK( x, z );
1002         const gp_XYZ& pLe = fLeft  ->GetIJK( y, z );
1003         const gp_XYZ& pRi = fRight ->GetIJK( y, z );
1004         params.SetCoord( 1, 0.5 * ( pBo.X() * ( 1. - rZ ) + pTo.X() * rZ  +
1005                                     pFr.X() * ( 1. - rY ) + pBa.X() * rY ));
1006         params.SetCoord( 2, 0.5 * ( pBo.Y() * ( 1. - rZ ) + pTo.Y() * rZ  +
1007                                     pLe.Y() * ( 1. - rX ) + pRi.Y() * rX ));
1008         params.SetCoord( 3, 0.5 * ( pFr.Z() * ( 1. - rY ) + pBa.Z() * rY  +
1009                                     pLe.Z() * ( 1. - rX ) + pRi.Z() * rX ));
1010
1011         // point projections on vertical edges
1012         pointsOnShapes[ SMESH_Block::ID_E00z ] = fFront->GetXYZ( 0, z );
1013         pointsOnShapes[ SMESH_Block::ID_E10z ] = fFront->GetXYZ( X, z );
1014         pointsOnShapes[ SMESH_Block::ID_E01z ] = fBack->GetXYZ( 0, z );
1015         pointsOnShapes[ SMESH_Block::ID_E11z ] = fBack->GetXYZ( X, z );
1016         // point projections on vertical faces
1017         pointsOnShapes[ SMESH_Block::ID_Fx0z ] = fFront->GetXYZ( x, z );
1018         pointsOnShapes[ SMESH_Block::ID_Fx1z ] = fBack ->GetXYZ( x, z );    
1019         pointsOnShapes[ SMESH_Block::ID_F0yz ] = fLeft ->GetXYZ( y, z );    
1020         pointsOnShapes[ SMESH_Block::ID_F1yz ] = fRight->GetXYZ( y, z );
1021
1022         // compute internal node coordinates
1023         gp_XYZ coords;
1024         SMESH_Block::ShellPoint( params, pointsOnShapes, coords );
1025         column[ z ] = helper.AddNode( coords.X(), coords.Y(), coords.Z() );
1026
1027 #ifdef DEB_GRID
1028         // debug
1029         //cout << "----------------------------------------------------------------------"<<endl;
1030         //for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id)
1031         //{
1032         //  gp_XYZ p = pointsOnShapes[ id ];
1033         //  SMESH_Block::DumpShapeID( id,cout)<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;
1034         //}
1035         //cout << "Params: ( "<< params.X()<<", "<<params.Y()<<", "<<params.Z()<<" )"<<endl;
1036         //cout << "coords: ( "<< coords.X()<<", "<<coords.Y()<<", "<<coords.Z()<<" )"<<endl;
1037 #endif
1038       } // z loop
1039       if ( toRenumber )
1040         renumHelper.AddReplacingNode( column[ Z ] );
1041
1042     } // y loop
1043     if ( toRenumber )
1044     {
1045       vector< const SMDS_MeshNode* >& columnXY = columns[ colIndex( x, Y )];
1046       for ( z = 0; z < zSize; ++z )
1047         renumHelper.AddReplacingNode( columnXY[ z ] );
1048     }
1049   } // for ( x = X-1; x > 0; --x )
1050
1051   if ( toRenumber )
1052     for ( y = 0; y < ySize; ++y )
1053     {
1054       vector< const SMDS_MeshNode* >& column0Y = columns[ colIndex( 0, y )];
1055       for ( z = 0; z < zSize; ++z )
1056         renumHelper.AddReplacingNode( column0Y[ z ] );
1057     }
1058
1059
1060   // faces no more needed, free memory
1061   boxFaceContainer.clear();
1062
1063   // ----------------
1064   // Add hexahedrons
1065   // ----------------
1066   for ( x = xSize-2; true; --x ) {
1067     for ( y = 0; y < ySize-1; ++y ) {
1068       vector< const SMDS_MeshNode* >& col00 = columns[ colIndex( x, y )];
1069       vector< const SMDS_MeshNode* >& col10 = columns[ colIndex( x+1, y )];
1070       vector< const SMDS_MeshNode* >& col01 = columns[ colIndex( x, y+1 )];
1071       vector< const SMDS_MeshNode* >& col11 = columns[ colIndex( x+1, y+1 )];
1072       for ( z = 0; z < zSize-1; ++z )
1073       {
1074         // bottom face normal of a hexa mush point outside the volume
1075         helper.AddVolume(col10[z], col11[z], col11[z+1], col10[z+1],
1076                          col00[z], col01[z], col01[z+1], col00[z+1]);
1077       }
1078     }
1079     if ( x == 0)
1080       break;
1081
1082   }
1083   if ( toRenumber )
1084     renumHelper.DoReplaceNodes();
1085
1086   if ( _blockRenumberHyp )
1087   {
1088     return error( _blockRenumberHyp->CheckHypothesis( theMesh, theShape ));
1089   }
1090
1091   return true;
1092 }
1093
1094 //================================================================================
1095 /*!
1096  *  Evaluate
1097  */
1098 //================================================================================
1099
1100 bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh&         theMesh,
1101                                            const TopoDS_Shape& theShape,
1102                                            MapShapeNbElems&    aResMap)
1103 {
1104   SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
1105
1106   // -------------------------
1107   // Try to find 6 side faces
1108   // -------------------------
1109   list< _QuadFaceGrid > boxFaceContainer;
1110   _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
1111   bool toRenumber = false;
1112   if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh, toRenumber,
1113                        fBottom, fTop, fFront, fBack, fLeft, fRight))
1114     return false;
1115
1116   // Find a less complex side
1117   _QuadFaceGrid * lessComplexSide = & boxFaceContainer.front();
1118   list< _QuadFaceGrid >::iterator face = boxFaceContainer.begin();
1119   for ( ++face; face != boxFaceContainer.end() && lessComplexSide->IsComplex(); ++face )
1120     if ( face->NbChildren() < lessComplexSide->NbChildren() )
1121       lessComplexSide = & *face;
1122
1123   // Get an 1D size of lessComplexSide
1124   smIdType nbSeg1 = 0;
1125   vector<TopoDS_Edge> edges;
1126   if ( !lessComplexSide->GetHoriEdges(edges) )
1127     return false;
1128   for ( size_t i = 0; i < edges.size(); ++i )
1129   {
1130     const vector<smIdType>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1131     if ( !nbElems.empty() )
1132       nbSeg1 += std::max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1133   }
1134
1135   // Get an 1D size of a box side orthogonal to lessComplexSide
1136   smIdType nbSeg2 = 0;
1137   _QuadFaceGrid* ortoSide =
1138     lessComplexSide->FindAdjacentForSide( Q_LEFT, boxFaceContainer, B_UNDEFINED );
1139   edges.clear();
1140   if ( !ortoSide || !ortoSide->GetHoriEdges(edges) ) return false;
1141   for ( size_t i = 0; i < edges.size(); ++i )
1142   {
1143     const vector<smIdType>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1144     if ( !nbElems.empty() )
1145       nbSeg2 += std::max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1146   }
1147
1148   // Get an 2D size of a box side orthogonal to lessComplexSide
1149   smIdType nbFaces = 0, nbQuadFace = 0;
1150   list< TopoDS_Face > sideFaces;
1151   if ( ortoSide->IsComplex() )
1152     for ( _QuadFaceGrid::TChildIterator child = ortoSide->GetChildren(); child.more(); )
1153       sideFaces.push_back( child.next().GetFace() );
1154   else
1155     sideFaces.push_back( ortoSide->GetFace() );
1156   //
1157   list< TopoDS_Face >::iterator f = sideFaces.begin();
1158   for ( ; f != sideFaces.end(); ++f )
1159   {
1160     const vector<smIdType>& nbElems = aResMap[ theMesh.GetSubMesh( *f )];
1161     if ( !nbElems.empty() )
1162     {
1163       nbFaces    = nbElems[ SMDSEntity_Quadrangle ];
1164       nbQuadFace = nbElems[ SMDSEntity_Quad_Quadrangle ];
1165     }
1166   }
1167
1168   // Fill nb of elements
1169   vector<smIdType> aResVec(SMDSEntity_Last,0);
1170   smIdType nbSeg3 = ( nbFaces + nbQuadFace ) / nbSeg2;
1171   aResVec[SMDSEntity_Node]       = (nbSeg1-1) * (nbSeg2-1) * (nbSeg3-1);
1172   aResVec[SMDSEntity_Hexa]       = nbSeg1 * nbFaces;
1173   aResVec[SMDSEntity_Quad_Hexa]  = nbSeg1 * nbQuadFace;
1174
1175   aResMap.insert( make_pair( theMesh.GetSubMesh(theShape), aResVec ));
1176
1177   return true;
1178 }
1179
1180
1181 //================================================================================
1182 /*!
1183  * \brief constructor of non-initialized _QuadFaceGrid
1184  */
1185 //================================================================================
1186
1187 _QuadFaceGrid::_QuadFaceGrid():
1188   myReverse(false), myRightBrother(0), myUpBrother(0), myIndexer(0,0), myID(B_UNDEFINED)
1189 {
1190 }
1191
1192 //================================================================================
1193 /*!
1194  * \brief Initialization
1195  */
1196 //================================================================================
1197
1198 bool _QuadFaceGrid::Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh)
1199 {
1200   myFace         = f;
1201   mySides        = _FaceSide();
1202   myReverse      = false;
1203   myLeftBottomChild = myRightBrother = myUpBrother = 0;
1204   myChildren.clear();
1205   myGrid.clear();
1206   //if ( myFace.Orientation() != TopAbs_FORWARD )
1207     //myFace.Reverse();
1208
1209   list< TopoDS_Edge > edges;
1210   list< int > nbEdgesInWire;
1211   int nbWire = SMESH_Block::GetOrderedEdges (myFace, edges, nbEdgesInWire);
1212   if ( nbWire != 1 )
1213     return false;
1214
1215   list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1216   if ( nbEdgesInWire.front() == 4 ) // exactly 4 edges
1217   {
1218     for ( ; edgeIt != edges.end(); ++edgeIt )
1219       mySides.AppendSide( _FaceSide( *edgeIt ));
1220   }
1221   else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
1222     list< TopoDS_Edge > sideEdges;
1223     while ( !edges.empty()) {
1224       sideEdges.clear();
1225       sideEdges.splice( sideEdges.end(), edges, edges.begin());// edges.front()->sideEdges.back()
1226       if ( SMESH_Algo::isDegenerated( sideEdges.back() ))
1227         continue;
1228       while ( !edges.empty() ) {
1229         if ( isContinuousMesh( sideEdges.back(), edges.front(), f, mesh )) {
1230           sideEdges.splice( sideEdges.end(), edges, edges.begin());
1231         }
1232         else if ( isContinuousMesh( sideEdges.front(), edges.back(), f, mesh )) {
1233           sideEdges.splice( sideEdges.begin(), edges, --edges.end());
1234         }
1235         else {
1236           break;
1237         }
1238       }
1239       mySides.AppendSide( _FaceSide( sideEdges ));
1240     }
1241   }
1242   if (mySides.size() != 4)
1243     return false;
1244
1245 if (SALOME::VerbosityActivated())
1246 {
1247   mySides.GetSide( Q_BOTTOM )->SetID( Q_BOTTOM );
1248   mySides.GetSide( Q_RIGHT  )->SetID( Q_RIGHT );
1249   mySides.GetSide( Q_TOP    )->SetID( Q_TOP );
1250   mySides.GetSide( Q_LEFT   )->SetID( Q_LEFT );
1251 }
1252
1253   return true;
1254 }
1255
1256 //================================================================================
1257 /*!
1258  * \brief Try to unite self with other ordinary face
1259  */
1260 //================================================================================
1261
1262 bool _QuadFaceGrid::AddContinuousFace( const _QuadFaceGrid&       other,
1263                                        const TopTools_MapOfShape& internalEdges)
1264 {
1265   for ( int i = 0; i < 4; ++i )
1266   {
1267     const _FaceSide& otherSide = other.GetSide( i );
1268     int iMyCommon;
1269     if ( mySides.Contain( otherSide, &iMyCommon ))
1270     {
1271       if ( internalEdges.Contains( otherSide.Edge( 0 )))
1272       {
1273         DUMP_VERT("Cont 1", mySides.GetSide(iMyCommon)->FirstVertex());
1274         DUMP_VERT("Cont 2", mySides.GetSide(iMyCommon)->LastVertex());
1275         DUMP_VERT("Cont 3", otherSide.FirstVertex());
1276         DUMP_VERT("Cont 4", otherSide.LastVertex());
1277
1278         if ( myChildren.empty() )
1279         {
1280           myChildren.push_back( *this );
1281           myFace.Nullify();
1282         }
1283         else // find iMyCommon in myChildren
1284         {
1285           for ( TChildIterator children = GetChildren(); children.more(); ) {
1286             const _QuadFaceGrid& child = children.next();
1287             if ( child.mySides.Contain( otherSide, &iMyCommon ))
1288               break;
1289           }
1290         }
1291
1292         // orient new children equally
1293         int otherBottomIndex = SMESH_MesherHelper::WrapIndex( i - iMyCommon + 2, 4 );
1294         if ( other.IsComplex() )
1295           for ( TChildIterator children = other.GetChildren(); children.more(); ) {
1296             myChildren.push_back( children.next() );
1297             myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1298           }
1299         else {
1300           myChildren.push_back( other );
1301           myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1302         }
1303
1304         myLeftBottomChild = 0;
1305
1306         // collect vertices in mySides
1307         if ( other.IsComplex() )
1308           for ( TChildIterator children = other.GetChildren(); children.more(); )
1309           {
1310             const _QuadFaceGrid& child = children.next();
1311             for ( int i = 0; i < 4; ++i )
1312               mySides.AppendSide( child.GetSide(i) );
1313           }
1314         else
1315           for ( int i = 0; i < 4; ++i )
1316             mySides.AppendSide( other.GetSide(i) );
1317
1318         return true;
1319       }
1320     }
1321   }
1322   return false;
1323 }
1324
1325 //================================================================================
1326 /*!
1327  * \brief Try to set the side as bottom hirizontal side
1328  */
1329 //================================================================================
1330
1331 bool _QuadFaceGrid::SetBottomSide(const _FaceSide& bottom, int* sideIndex)
1332 {
1333   myLeftBottomChild = myRightBrother = myUpBrother = 0;
1334
1335   int myBottomIndex;
1336   if ( myChildren.empty() )
1337   {
1338     if ( mySides.Contain( bottom, &myBottomIndex )) {
1339       mySides.SetBottomSide( myBottomIndex );
1340       if ( sideIndex )
1341         *sideIndex = myBottomIndex;
1342       return true;
1343     }
1344   }
1345   else
1346   {
1347     TChildren::iterator childFace = myChildren.begin(), childEnd = myChildren.end();
1348     for ( ; childFace != childEnd; ++childFace )
1349     {
1350       if ( childFace->SetBottomSide( bottom, &myBottomIndex ))
1351       {
1352         TChildren::iterator orientedChild = childFace;
1353         for ( childFace = myChildren.begin(); childFace != childEnd; ++childFace ) {
1354           if ( childFace != orientedChild )
1355             childFace->SetBottomSide( childFace->GetSide( myBottomIndex ));
1356         }
1357         if ( sideIndex )
1358           *sideIndex = myBottomIndex;
1359         return true;
1360       }
1361     }
1362   }
1363   return false;
1364 }
1365
1366 //================================================================================
1367 /*!
1368  * \brief Return face adjacent to i-th side of this face, (0<i<4)
1369  */
1370 //================================================================================
1371
1372 _QuadFaceGrid* _QuadFaceGrid::FindAdjacentForSide(int                  i,
1373                                                   list<_QuadFaceGrid>& faces,
1374                                                   EBoxSides            id) const
1375 {
1376   const _FaceSide & iSide = GetSide( i );
1377   list< _QuadFaceGrid >::iterator boxFace = faces.begin();
1378   for ( ; boxFace != faces.end(); ++boxFace )
1379   {
1380     _QuadFaceGrid* f  = & (*boxFace);
1381     if ( f != this && f->SetBottomSide( iSide ))
1382       return f->SetID( id ), f;
1383   }
1384   return (_QuadFaceGrid*) 0;
1385 }
1386
1387 //================================================================================
1388 /*!
1389  * \brief Return i-th side
1390  */
1391 //================================================================================
1392
1393 const _FaceSide& _QuadFaceGrid::GetSide(int i) const
1394 {
1395   if ( myChildren.empty() )
1396     return *mySides.GetSide(i);
1397
1398   _QuadFaceGrid* me = const_cast<_QuadFaceGrid*>(this);
1399   if ( !me->locateChildren() || !myLeftBottomChild )
1400     return *mySides.GetSide(i);
1401
1402   const _QuadFaceGrid* child = myLeftBottomChild;
1403   switch ( i ){
1404   case Q_BOTTOM:
1405   case Q_LEFT:
1406     break;
1407   case Q_RIGHT:
1408     while ( child->myRightBrother )
1409       child = child->myRightBrother;
1410     break;
1411   case Q_TOP:
1412     while ( child->myUpBrother )
1413       child = child->myUpBrother;
1414     break;
1415   default: ;
1416   }
1417   return child->GetSide( i );
1418 }
1419
1420 //================================================================================
1421 /*!
1422  * \brief Reverse edges in order to have them oriented along axes of the unit box
1423  */
1424 //================================================================================
1425
1426 void _QuadFaceGrid::ReverseEdges()
1427 {
1428   myReverse = !myReverse;
1429
1430 // #ifdef DEB_FACES
1431 //   if ( !myFace.IsNull() )
1432 //     TopAbs::Print(myFace.Orientation(), cout);
1433 // #endif
1434
1435   if ( myChildren.empty() )
1436   {
1437     DumpVertices();
1438   }
1439   else
1440   {
1441     DumpVertices();
1442     TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1443     for ( ; child != childEnd; ++child )
1444       child->ReverseEdges();
1445   }
1446 }
1447
1448 //================================================================================
1449 /*!
1450  * \brief Load nodes of a mesh
1451  */
1452 //================================================================================
1453
1454 bool _QuadFaceGrid::LoadGrid( SMESH_ProxyMesh& mesh )
1455 {
1456   if ( !myChildren.empty() )
1457   {
1458     // Let child faces load their grids
1459     TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1460     for ( ; child != childEnd; ++child ) {
1461       child->SetID( myID );
1462       if ( !child->LoadGrid( mesh ) )
1463         return error( child->GetError() );
1464     }
1465     // Fill myGrid with nodes of patches
1466     return loadCompositeGrid( mesh );
1467   }
1468
1469   // ---------------------------------------
1470   // Fill myGrid with nodes bound to myFace
1471   // ---------------------------------------
1472
1473   if ( !myGrid.empty() )
1474     return true;
1475
1476   const SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace );
1477
1478   // check that all faces are quadrangular
1479   SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
1480   while ( fIt->more() )
1481     if ( fIt->next()->NbNodes() % 4 > 0 )
1482       return error("Non-quadrangular mesh faces are not allowed on sides of a composite block");
1483
1484   bool isProxy = false, isTmpElem = false;
1485   if ( faceSubMesh && faceSubMesh->NbElements() > 0 )
1486   {
1487     isProxy   = dynamic_cast< const SMESH_ProxyMesh::SubMesh* >( faceSubMesh );
1488     isTmpElem = mesh.IsTemporary( faceSubMesh->GetElements()->next() );
1489   }
1490   const SMESHDS_SubMesh* smToCheckEdges = ( isProxy && !isTmpElem ) ? faceSubMesh : 0;
1491
1492   myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh, smToCheckEdges );
1493   myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT   )->GetNbSegments( mesh, smToCheckEdges );
1494
1495   myGrid.resize( myIndexer.size() );
1496
1497   // store nodes bound to the bottom edge
1498   mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse, isProxy, smToCheckEdges );
1499
1500   // store the rest nodes row by row
1501
1502   TIDSortedElemSet avoidSet;
1503   const SMDS_MeshElement* firstQuad = 0; // most left face above the last row of found nodes
1504
1505   size_t nbFoundNodes = myIndexer._xSize;
1506   while ( nbFoundNodes != myGrid.size() )
1507   {
1508     // first and last nodes of the last filled row of nodes
1509     const SMDS_MeshNode* n1down = myGrid[ nbFoundNodes - myIndexer._xSize ];
1510     const SMDS_MeshNode* n2down = myGrid[ nbFoundNodes - myIndexer._xSize + 1];
1511     const SMDS_MeshNode* n1downLast = myGrid[ nbFoundNodes-1 ];
1512
1513     // find the first face above the row by the first two left nodes
1514     //
1515     // n1up     n2up
1516     //     o---o
1517     //     |   |
1518     //     o---o  o  o  o  o
1519     //n1down    n2down
1520     //
1521     firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh );
1522     while ( firstQuad && !faceSubMesh->Contains( firstQuad )) {
1523       avoidSet.insert( firstQuad );
1524       firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh);
1525     }
1526     if ( !firstQuad || !faceSubMesh->Contains( firstQuad ))
1527       return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1528
1529     // find the node of quad bound to the left geom edge
1530     int i2down = firstQuad->GetNodeIndex( n2down );
1531     const SMDS_MeshNode* n1up = firstQuad->GetNode(( i2down+2 ) % 4 );
1532     myGrid[ nbFoundNodes++ ] = n1up;
1533     // the 4-the node of the first quad
1534     int i1down = firstQuad->GetNodeIndex( n1down );
1535     const SMDS_MeshNode* n2up = firstQuad->GetNode(( i1down+2 ) % 4 );
1536     myGrid[ nbFoundNodes++ ] = n2up;
1537
1538     n1down = n2down;
1539     n1up   = n2up;
1540     const SMDS_MeshElement* quad = firstQuad;
1541
1542     // find the rest nodes by remaining faces above the row
1543     //
1544     //             n1up
1545     //     o---o--o
1546     //     |   |  | ->
1547     //     o---o--o  o  o  o
1548     //                      n1downLast
1549     //
1550     while ( n1down != n1downLast )
1551     {
1552       // next face
1553       avoidSet.clear(); avoidSet.insert( quad );
1554       quad = FindFaceByNodes( n1down, n1up, avoidSet, mesh );
1555       if ( !quad || quad->NbNodes() % 4 > 0)
1556         return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1557
1558       // next node
1559       if ( quad->GetNode( i1down ) != n1down ) // check already found index
1560         i1down = quad->GetNodeIndex( n1down );
1561       n2up = quad->GetNode(( i1down+2 ) % 4 );
1562       myGrid[ nbFoundNodes++ ] = n2up;
1563
1564       n1down = myGrid[ nbFoundNodes - myIndexer._xSize - 1 ];
1565       n1up   = n2up;
1566     }
1567     avoidSet.clear(); avoidSet.insert( firstQuad );
1568   }
1569   DumpGrid(); // debug
1570
1571   return true;
1572 }
1573
1574 //================================================================================
1575 /*!
1576  * \brief Fill myIJK with normalized parameters of nodes in myGrid
1577  *  \param [in] i1 - coordinate index along rows of myGrid
1578  *  \param [in] i2 - coordinate index along columns of myGrid
1579  *  \param [in] v3 - value of the constant parameter
1580  */
1581 //================================================================================
1582
1583 void _QuadFaceGrid::ComputeIJK( int i1, int i2, double v3 )
1584 {
1585   gp_XYZ ijk( v3, v3, v3 );
1586   myIJK.resize( myIndexer.size(), ijk );
1587
1588   const size_t nbCol = myIndexer._xSize;
1589   const size_t nbRow = myIndexer._ySize;
1590
1591   vector< double > len( nbRow );
1592   len[0] = 0;
1593   for ( size_t i = 0; i < nbCol; ++i )
1594   {
1595     gp_Pnt pPrev = GetXYZ( i, 0 );
1596     for ( size_t j = 1; j < nbRow; ++j )
1597     {
1598       gp_Pnt p = GetXYZ( i, j );
1599       len[ j ] = len[ j-1 ] + p.Distance( pPrev );
1600       pPrev = p;
1601     }
1602     for ( size_t j = 0; j < nbRow; ++j )
1603       GetIJK( i, j ).SetCoord( i2, len[ j ]/len.back() );
1604   }
1605
1606   len.resize( nbCol );
1607   for ( size_t j = 0; j < nbRow; ++j )
1608   {
1609     gp_Pnt pPrev = GetXYZ( 0, j );
1610     for ( size_t i = 1; i < nbCol; ++i )
1611     {
1612       gp_Pnt p = GetXYZ( i, j );
1613       len[ i ] = len[ i-1 ] + p.Distance( pPrev );
1614       pPrev = p;
1615     }
1616     for ( size_t i = 0; i < nbCol; ++i )
1617       GetIJK( i, j ).SetCoord( i1, len[ i ]/len.back() );
1618   }
1619 }
1620
1621 //================================================================================
1622 /*!
1623  * \brief Find out mutual location of children: find their right and up brothers
1624  */
1625 //================================================================================
1626
1627 bool _QuadFaceGrid::locateChildren()
1628 {
1629   if ( myLeftBottomChild )
1630     return true;
1631
1632   TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1633
1634   // find a child sharing it's first bottom vertex with no other brother
1635   myLeftBottomChild = 0;
1636   for ( ; !myLeftBottomChild && child != childEnd; ++child )
1637   {
1638     TopoDS_Vertex leftVertex = child->GetSide( Q_BOTTOM ).FirstVertex();
1639     bool sharedVertex = false;
1640     TChildren::iterator otherChild = myChildren.begin();
1641     for ( ; otherChild != childEnd && !sharedVertex; ++otherChild )
1642       if ( otherChild != child )
1643         sharedVertex = otherChild->mySides.Contain( leftVertex );
1644     if ( !sharedVertex ) {
1645       myLeftBottomChild = & (*child);
1646       DUMP_VERT("0 left bottom Vertex: ",leftVertex );
1647     }
1648   }
1649   if (!myLeftBottomChild)
1650     return error(ERR_LI("Error in locateChildren()"));
1651
1652   set< _QuadFaceGrid* > notLocatedChilren;
1653   for (child = myChildren.begin() ; child != childEnd; ++child )
1654     notLocatedChilren.insert( & (*child));
1655
1656   // connect myLeftBottomChild to it's right and upper brothers
1657   notLocatedChilren.erase( myLeftBottomChild );
1658   myLeftBottomChild->setBrothers( notLocatedChilren );
1659   if ( !notLocatedChilren.empty() )
1660     return error(ERR_LI("Error in locateChildren()"));
1661
1662   return true;
1663 }
1664
1665 //================================================================================
1666 /*!
1667  * \brief Fill myGrid with nodes of patches
1668  */
1669 //================================================================================
1670
1671 bool _QuadFaceGrid::loadCompositeGrid(SMESH_ProxyMesh& mesh)
1672 {
1673   // Find out mutual location of children: find their right and up brothers
1674   if ( !locateChildren() )
1675     return false;
1676
1677   // Load nodes according to mutual location of children
1678
1679   // grid size
1680   myIndexer._xSize = 1 + myLeftBottomChild->GetNbHoriSegments( mesh, /*withBrothers=*/true );
1681   myIndexer._ySize = 1 + myLeftBottomChild->GetNbVertSegments( mesh, /*withBrothers=*/true );
1682
1683   myGrid.resize( myIndexer.size() );
1684
1685   int fromX = myReverse ? myIndexer._xSize : 0;
1686   if ( !myLeftBottomChild->fillGrid( mesh, myGrid, myIndexer, fromX, 0 ))
1687     return error( myLeftBottomChild->GetError() );
1688
1689   DumpGrid();
1690
1691   return true;
1692 }
1693
1694 //================================================================================
1695 /*!
1696  * \brief Find right an upper brothers among notLocatedBrothers
1697  */
1698 //================================================================================
1699
1700 void _QuadFaceGrid::setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers )
1701 {
1702   if ( !notLocatedBrothers.empty() )
1703   {
1704     // find right brother
1705     TopoDS_Vertex rightVertex = GetSide( Q_BOTTOM ).LastVertex();
1706     DUMP_VERT("1 right bottom Vertex: ",rightVertex );
1707     set< _QuadFaceGrid* >::iterator brIt, brEnd = notLocatedBrothers.end();
1708     for ( brIt = notLocatedBrothers.begin(); brIt != brEnd; ++brIt )
1709     {
1710       _QuadFaceGrid* brother = *brIt;
1711       TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1712       DUMP_VERT( "brother left bottom: ", brotherLeftVertex );
1713       if ( rightVertex.IsSame( brotherLeftVertex )) {
1714         myRightBrother = brother;
1715         notLocatedBrothers.erase( brIt );
1716         break;
1717       }
1718     }
1719     // find upper brother
1720     TopoDS_Vertex upVertex = GetSide( Q_LEFT ).FirstVertex();
1721     DUMP_VERT("1 left up Vertex: ",upVertex);
1722     brIt = notLocatedBrothers.begin(), brEnd = notLocatedBrothers.end();
1723     for ( ; brIt != brEnd; ++brIt )
1724     {
1725       _QuadFaceGrid* brother = *brIt;
1726       TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1727       DUMP_VERT("brother left bottom: ", brotherLeftVertex);
1728       if ( upVertex.IsSame( brotherLeftVertex )) {
1729         myUpBrother = brother;
1730         notLocatedBrothers.erase( myUpBrother );
1731         break;
1732       }
1733     }
1734     // recursive call
1735     if ( myRightBrother )
1736       myRightBrother->setBrothers( notLocatedBrothers );
1737     if ( myUpBrother )
1738       myUpBrother->setBrothers( notLocatedBrothers );
1739   }
1740 }
1741
1742 //================================================================================
1743 /*!
1744  * \brief Store nodes of a simple face into grid starting from (x,y) position
1745  */
1746 //================================================================================
1747
1748 bool _QuadFaceGrid::fillGrid(SMESH_ProxyMesh&               theMesh,
1749                              vector<const SMDS_MeshNode*> & theGrid,
1750                              const _Indexer&                theIndexer,
1751                              int                            theX,
1752                              int                            theY)
1753 {
1754   if ( myGrid.empty() && !LoadGrid( theMesh ))
1755     return false;
1756
1757   // store my own grid in the global grid
1758
1759   int fromX = myReverse ? theX - myIndexer._xSize: theX;
1760
1761   for ( int i = 0, x = fromX; i < myIndexer._xSize; ++i, ++x )
1762     for ( int j = 0, y = theY; j < myIndexer._ySize; ++j, ++y )
1763       theGrid[ theIndexer( x, y )] = myGrid[ myIndexer( i, j )];
1764
1765   // store grids of my right and upper brothers
1766
1767   if ( myRightBrother )
1768   {
1769     if ( myReverse )
1770       fromX += 1;
1771     else
1772       fromX += myIndexer._xSize - 1;
1773     if ( !myRightBrother->fillGrid( theMesh, theGrid, theIndexer, fromX, theY ))
1774       return error( myRightBrother->GetError() );
1775   }
1776   if ( myUpBrother )
1777   {
1778     if ( !myUpBrother->fillGrid( theMesh, theGrid, theIndexer,
1779                                  theX, theY + myIndexer._ySize - 1))
1780       return error( myUpBrother->GetError() );
1781   }
1782   return true;
1783 }
1784
1785 //================================================================================
1786 /*!
1787  * \brief Return number of segments on the hirizontal sides
1788  */
1789 //================================================================================
1790
1791 int _QuadFaceGrid::GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1792 {
1793   int nbSegs = 0;
1794   if ( myLeftBottomChild )
1795   {
1796     nbSegs += myLeftBottomChild->GetNbHoriSegments( mesh, true );
1797   }
1798   else
1799   {
1800     nbSegs = mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
1801     if ( withBrothers && myRightBrother )
1802       nbSegs += myRightBrother->GetNbHoriSegments( mesh, withBrothers );
1803   }
1804   return nbSegs;
1805 }
1806
1807 //================================================================================
1808 /*!
1809  * \brief Return number of segments on the vertical sides
1810  */
1811 //================================================================================
1812
1813 int _QuadFaceGrid::GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1814 {
1815   int nbSegs = 0;
1816   if ( myLeftBottomChild )
1817   {
1818     nbSegs += myLeftBottomChild->GetNbVertSegments( mesh, true );
1819   }
1820   else
1821   {
1822     nbSegs = mySides.GetSide( Q_LEFT )->GetNbSegments(mesh,0);
1823     if ( withBrothers && myUpBrother )
1824       nbSegs += myUpBrother->GetNbVertSegments( mesh, withBrothers );
1825   }
1826   return nbSegs;
1827 }
1828
1829 //================================================================================
1830 /*!
1831  * \brief Return edge on the hirizontal bottom sides
1832  */
1833 //================================================================================
1834
1835 int _QuadFaceGrid::GetHoriEdges(vector<TopoDS_Edge> & edges) const
1836 {
1837   if ( myLeftBottomChild )
1838   {
1839     return myLeftBottomChild->GetHoriEdges( edges );
1840   }
1841   else
1842   {
1843     const _FaceSide* bottom  = mySides.GetSide( Q_BOTTOM );
1844     int i = 0;
1845     while ( true ) {
1846       TopoDS_Edge e = bottom->Edge( i++ );
1847       if ( e.IsNull() )
1848         break;
1849       else
1850         edges.push_back( e );
1851     }
1852     if ( myRightBrother )
1853       myRightBrother->GetHoriEdges( edges );
1854   }
1855   return edges.size();
1856 }
1857
1858 //================================================================================
1859 /*!
1860  * \brief Return a node by its position
1861  */
1862 //================================================================================
1863
1864 const SMDS_MeshNode* _QuadFaceGrid::GetNode(int iHori, int iVert) const
1865 {
1866   return myGrid[ myIndexer( iHori, iVert )];
1867 }
1868
1869 //================================================================================
1870 /*!
1871  * \brief Return node coordinates by its position
1872  */
1873 //================================================================================
1874
1875 gp_XYZ _QuadFaceGrid::GetXYZ(int iHori, int iVert) const
1876 {
1877   SMESH_TNodeXYZ xyz = myGrid[ myIndexer( iHori, iVert )];
1878   return xyz;
1879 }
1880
1881 //================================================================================
1882 /*!
1883  * \brief Return normal to the face at vertex v
1884  */
1885 //================================================================================
1886
1887 bool _QuadFaceGrid::GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const
1888 {
1889   if ( myChildren.empty() )
1890   {
1891     if ( mySides.Contain( v )) {
1892       try {
1893         gp_Pnt2d uv = BRep_Tool::Parameters( v, myFace );
1894         BRepAdaptor_Surface surface( myFace );
1895         gp_Pnt p; gp_Vec d1u, d1v;
1896         surface.D1( uv.X(), uv.Y(), p, d1u, d1v );
1897         n = d1u.Crossed( d1v );
1898         return true;
1899       }
1900       catch (Standard_Failure&) {
1901         return false;
1902       }
1903     }
1904   }
1905   else
1906   {
1907     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1908     for ( ; child != childEnd; ++child )
1909       if ( child->GetNormal( v, n ))
1910         return true;
1911   }
1912   return false;
1913 }
1914
1915 //================================================================================
1916 /*!
1917  * \brief Dumps coordinates of grid nodes
1918  */
1919 //================================================================================
1920
1921 void _QuadFaceGrid::DumpGrid() const
1922 {
1923 #ifdef DEB_GRID
1924   const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1925   cout << "****** Face " << names[ myID ] << endl;
1926
1927   if ( myChildren.empty() || !myGrid.empty() )
1928   {
1929     cout << "x size: " << myIndexer._xSize << "; y size: " << myIndexer._ySize << endl;
1930     for ( int y = 0; y < myIndexer._ySize; ++y ) {
1931       cout << "-- row " << y << endl;
1932       for ( int x = 0; x < myIndexer._xSize; ++x ) {
1933         const SMDS_MeshNode* n = myGrid[ myIndexer( x, y ) ];
1934         cout << x << " ( " << n->X() << ", " << n->Y() << ", " << n->Z() << " )" << endl;
1935       }
1936     }
1937   }
1938   else
1939   {
1940     cout << "Nb children: " << myChildren.size() << endl;
1941     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1942     for ( int i=0; child != childEnd; ++child, ++i ) {
1943       cout << "   *** SUBFACE " << i+1 << endl;
1944       ((_QuadFaceGrid&)(*child)).SetID( myID );
1945       child->DumpGrid();
1946     }
1947   }
1948 #endif
1949 }
1950
1951 //================================================================================
1952 /*!
1953  * \brief Dump vertices
1954  */
1955 //================================================================================
1956
1957 void _QuadFaceGrid::DumpVertices() const
1958 {
1959 #ifdef DEB_FACES
1960   cout << "****** Face ";
1961   const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1962   if ( myID >= B_BOTTOM && myID < B_BACK )
1963     cout << names[ myID ] << endl;
1964   else
1965     cout << "UNDEFINED" << endl;
1966
1967   if ( myChildren.empty() )
1968   {
1969     for ( int i = 0; i < 4; ++i )
1970     {
1971       cout << "  Side "; mySides.GetSide( i )->Dump();
1972     }
1973   }
1974   else
1975   {
1976     cout << "-- Nb children: " << myChildren.size() << endl;
1977     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1978     for ( int i=0; child != childEnd; ++child, ++i ) {
1979       cout << "   *** SUBFACE " << i+1 << endl;
1980       ((_QuadFaceGrid&)(*child)).SetID( myID );
1981       child->DumpVertices();
1982     }
1983   }
1984 #endif
1985 }
1986
1987 //=======================================================================
1988 //function : _FaceSide
1989 //purpose  : copy constructor
1990 //=======================================================================
1991
1992 _FaceSide::_FaceSide(const _FaceSide& other)
1993 {
1994   myEdge = other.myEdge;
1995   myChildren = other.myChildren;
1996   myNbChildren = other.myNbChildren;
1997   myVertices.Assign( other.myVertices );
1998   myID = other.myID;
1999 }
2000
2001 //================================================================================
2002 /*!
2003  * \brief Construct a face side of one edge
2004  */
2005 //================================================================================
2006
2007 _FaceSide::_FaceSide(const TopoDS_Edge& edge):
2008   myEdge( edge ), myNbChildren(0)
2009 {
2010   if ( !edge.IsNull() )
2011     for ( TopExp_Explorer exp( edge, TopAbs_VERTEX ); exp.More(); exp.Next() )
2012       //myVertices.insert( ptr ( exp.Current() ));
2013       myVertices.Add( exp.Current() );
2014 }
2015
2016 //================================================================================
2017 /*!
2018  * \brief Construct a face side of several edges
2019  */
2020 //================================================================================
2021
2022 _FaceSide::_FaceSide(const list<TopoDS_Edge>& edges):
2023   myNbChildren(0)
2024 {
2025   list<TopoDS_Edge>::const_iterator edge = edges.begin(), eEnd = edges.end();
2026   for ( ; edge != eEnd; ++edge ) {
2027     myChildren.push_back( _FaceSide( *edge ));
2028     myNbChildren++;
2029     myVertices.Add( myChildren.back().FirstVertex() );
2030     myVertices.Add( myChildren.back().LastVertex() );
2031     myChildren.back().SetID( Q_CHILD ); // not to splice them
2032   }
2033 }
2034
2035 //=======================================================================
2036 //function : GetSide
2037 //purpose  :
2038 //=======================================================================
2039
2040 _FaceSide* _FaceSide::GetSide(const int i)
2041 {
2042   if ( i >= myNbChildren )
2043     return 0;
2044
2045   list< _FaceSide >::iterator side = myChildren.begin();
2046   if ( i )
2047     std::advance( side, i );
2048   return & (*side);
2049 }
2050
2051 //=======================================================================
2052 //function : GetSide
2053 //purpose  : 
2054 //=======================================================================
2055
2056 const _FaceSide* _FaceSide::GetSide(const int i) const
2057 {
2058   return const_cast< _FaceSide* >(this)->GetSide(i);
2059 }
2060
2061 //=======================================================================
2062 //function : NbVertices
2063 //purpose  : return nb of vertices in the side
2064 //=======================================================================
2065
2066 int _FaceSide::NbVertices() const
2067 {
2068   if ( myChildren.empty() )
2069     return myVertices.Extent();
2070
2071   return myNbChildren + 1;
2072 }
2073
2074 //=======================================================================
2075 //function : NbCommonVertices
2076 //purpose  : Returns number of my vertices common with the given ones
2077 //=======================================================================
2078
2079 int _FaceSide::NbCommonVertices( const TopTools_MapOfShape& VV ) const
2080 {
2081   int nbCommon = 0;
2082   TopTools_MapIteratorOfMapOfShape vIt ( myVertices );
2083   for ( ; vIt.More(); vIt.Next() )
2084     nbCommon += ( VV.Contains( vIt.Key() ));
2085
2086   return nbCommon;
2087 }
2088
2089 //=======================================================================
2090 //function : FirstVertex
2091 //purpose  :
2092 //=======================================================================
2093
2094 TopoDS_Vertex _FaceSide::FirstVertex() const
2095 {
2096   if ( myChildren.empty() )
2097     return TopExp::FirstVertex( myEdge, Standard_True );
2098
2099   return myChildren.front().FirstVertex();
2100 }
2101
2102 //=======================================================================
2103 //function : LastVertex
2104 //purpose  : 
2105 //=======================================================================
2106
2107 TopoDS_Vertex _FaceSide::LastVertex() const
2108 {
2109   if ( myChildren.empty() )
2110     return TopExp::LastVertex( myEdge, Standard_True );
2111
2112   return myChildren.back().LastVertex();
2113 }
2114
2115 //=======================================================================
2116 //function : Vertex
2117 //purpose  : 
2118 //=======================================================================
2119
2120 TopoDS_Vertex _FaceSide::Vertex(int i) const
2121 {
2122   if ( myChildren.empty() )
2123     return i ? LastVertex() : FirstVertex();
2124       
2125   if ( i >= myNbChildren )
2126     return myChildren.back().LastVertex();
2127   
2128   return GetSide(i)->FirstVertex();
2129 }
2130
2131 //================================================================================
2132 /*!
2133  * \brief Return i-the zero-based edge of the side
2134  */
2135 //================================================================================
2136
2137 TopoDS_Edge _FaceSide::Edge(int i) const
2138 {
2139   if ( i == 0 && !myEdge.IsNull() )
2140     return myEdge;
2141
2142   if ( const _FaceSide* iSide = GetSide( i ))
2143     return iSide->myEdge;
2144
2145   return TopoDS_Edge();
2146 }
2147
2148 //=======================================================================
2149 //function : Contain
2150 //purpose  : 
2151 //=======================================================================
2152
2153 bool _FaceSide::Contain( const _FaceSide& side, int* which ) const
2154 {
2155   if ( !which || myChildren.empty() )
2156   {
2157     if ( which )
2158       *which = 0;
2159     int nbCommon = 0;
2160     TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2161     for ( ; vIt.More(); vIt.Next() )
2162       nbCommon += ( myVertices.Contains( vIt.Key() ));
2163     return (nbCommon > 1);
2164   }
2165   list< _FaceSide >::const_iterator mySide = myChildren.begin(), sideEnd = myChildren.end();
2166   for ( int i = 0; mySide != sideEnd; ++mySide, ++i ) {
2167     if ( mySide->Contain( side )) {
2168       *which = i;
2169       return true;
2170     }
2171   }
2172   return false;
2173 }
2174
2175 //=======================================================================
2176 //function : Contain
2177 //purpose  : 
2178 //=======================================================================
2179
2180 bool _FaceSide::Contain( const TopoDS_Vertex& vertex ) const
2181 {
2182   return myVertices.Contains( vertex );
2183 }
2184
2185 //=======================================================================
2186 //function : AppendSide
2187 //purpose  : 
2188 //=======================================================================
2189
2190 void _FaceSide::AppendSide( const _FaceSide& side )
2191 {
2192   if ( !myEdge.IsNull() )
2193   {
2194     myChildren.push_back( *this );
2195     myNbChildren = 1;
2196     myEdge.Nullify();
2197   }
2198   myChildren.push_back( side );
2199   myNbChildren++;
2200   TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2201   for ( ; vIt.More(); vIt.Next() )
2202     myVertices.Add( vIt.Key() );
2203
2204   myID = Q_PARENT;
2205   myChildren.back().SetID( EQuadSides( myNbChildren-1 ));
2206 }
2207
2208 //=======================================================================
2209 //function : SetBottomSide
2210 //purpose  : 
2211 //=======================================================================
2212
2213 void _FaceSide::SetBottomSide( int i )
2214 {
2215   if ( i > 0 && myID == Q_PARENT ) {
2216     list< _FaceSide >::iterator sideEnd, side = myChildren.begin();
2217     std::advance( side, i );
2218     myChildren.splice( myChildren.begin(), myChildren, side, myChildren.end() );
2219
2220     side = myChildren.begin(), sideEnd = myChildren.end();
2221     for ( int i = 0; side != sideEnd; ++side, ++i ) {
2222       side->SetID( EQuadSides(i) );
2223       side->SetBottomSide(i);
2224     }
2225   }
2226 }
2227
2228 //=======================================================================
2229 //function : GetNbSegments
2230 //purpose  : 
2231 //=======================================================================
2232
2233 smIdType _FaceSide::GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges) const
2234 {
2235   smIdType nb = 0;
2236   if ( myChildren.empty() )
2237   {
2238     nb = mesh.GetSubMesh(myEdge)->NbElements();
2239
2240     if ( smToCheckEdges )
2241     {
2242       // check that segments bound faces belonging to smToCheckEdges
2243       SMDS_ElemIteratorPtr segIt = mesh.GetSubMesh(myEdge)->GetElements();
2244       while ( segIt->more() )
2245       {
2246         const SMDS_MeshElement* seg = segIt->next();
2247         if ( !IsSegmentOnSubMeshBoundary( mesh.GetProxyNode( seg->GetNode(0) ),
2248                                           mesh.GetProxyNode( seg->GetNode(1) ),
2249                                           smToCheckEdges, mesh ))
2250           --nb;
2251       }
2252     }
2253   }
2254   else
2255   {
2256     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2257     for ( ; side != sideEnd; ++side )
2258       nb += side->GetNbSegments( mesh, smToCheckEdges );
2259   }
2260   return nb;
2261 }
2262
2263 //=======================================================================
2264 //function : StoreNodes
2265 //purpose  :
2266 //=======================================================================
2267
2268 bool _FaceSide::StoreNodes(SMESH_ProxyMesh&              mesh,
2269                            vector<const SMDS_MeshNode*>& myGrid,
2270                            bool                          reverse,
2271                            bool                          isProxy,
2272                            const SMESHDS_SubMesh*        smToCheckEdges)
2273 {
2274   list< TopoDS_Edge > edges;
2275   if ( myChildren.empty() )
2276   {
2277     edges.push_back( myEdge );
2278   }
2279   else
2280   {
2281     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2282     for ( ; side != sideEnd; ++side )
2283       if ( reverse )
2284         edges.push_front( side->myEdge );
2285       else
2286         edges.push_back ( side->myEdge );
2287   }
2288   int nbNodes = 0;
2289   list< TopoDS_Edge >::iterator edge = edges.begin(), eEnd = edges.end();
2290   for ( ; edge != eEnd; ++edge )
2291   {
2292     typedef map< double, const SMDS_MeshNode* > TParamNodeMap;
2293     TParamNodeMap nodes;
2294     bool ok = SMESH_Algo::GetSortedNodesOnEdge( mesh.GetMeshDS(),
2295                                                 *edge,
2296                                                 /*ignoreMediumNodes=*/true,
2297                                                 nodes);
2298     if ( !ok ) return false;
2299
2300     // skip nodes on VERTEXes not included in faces
2301     if ( !nodes.begin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2302       nodes.erase( nodes.begin() );
2303     if ( !nodes.empty() &&
2304          !nodes.rbegin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2305       nodes.erase( --nodes.end() );
2306
2307     if ( isProxy )
2308     {
2309       TParamNodeMap::iterator u_node, nEnd = nodes.end();
2310       for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2311         u_node->second = mesh.GetProxyNode( u_node->second );
2312     }
2313
2314     if ( smToCheckEdges ) // erase nodes of segments not bounding faces of smToCheckEdges
2315     {
2316       {
2317         TParamNodeMap::iterator u_node1, u_node2 = nodes.begin(), nEnd = nodes.end();
2318         for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2319           if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2320                                            smToCheckEdges, mesh ))
2321             break;
2322           else
2323             nodes.erase( u_node1 );
2324       }
2325       {
2326         TParamNodeMap::reverse_iterator u_node1, u_node2 = nodes.rbegin(), nEnd = nodes.rend();
2327         for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2328           if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2329                                            smToCheckEdges, mesh ))
2330             break;
2331           else
2332             nodes.erase( --(( u_node2 = u_node1 ).base() ));
2333       }
2334     }
2335
2336     bool forward = ( edge->Orientation() == TopAbs_FORWARD );
2337     if ( reverse ) forward = !forward;
2338     if ( forward )
2339     {
2340       TParamNodeMap::iterator u_node, nEnd = nodes.end();
2341       for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2342         myGrid[ nbNodes++ ] = u_node->second;
2343     }
2344     else
2345     {
2346       TParamNodeMap::reverse_iterator u_node, nEnd = nodes.rend();
2347       for ( u_node = nodes.rbegin(); u_node != nEnd; ++u_node )
2348         myGrid[ nbNodes++ ] = u_node->second;
2349     }
2350     nbNodes--; // node on vertex present in two adjacent edges
2351   }
2352   return nbNodes > 0;
2353 }
2354
2355 //=======================================================================
2356 //function : Dump
2357 //purpose  : dump end vertices
2358 //=======================================================================
2359
2360 void _FaceSide::Dump() const
2361 {
2362   if ( myChildren.empty() )
2363   {
2364     const char* sideNames[] = { "Q_BOTTOM", "Q_RIGHT", "Q_TOP", "Q_LEFT", "Q_CHILD", "Q_PARENT" };
2365     if ( myID >= Q_BOTTOM && myID < Q_PARENT )
2366       cout << sideNames[ myID ] << endl;
2367     else
2368       cout << "<UNDEFINED ID>" << endl;
2369     TopoDS_Vertex f = FirstVertex();
2370     TopoDS_Vertex l = LastVertex();
2371     gp_Pnt pf = BRep_Tool::Pnt(f);
2372     gp_Pnt pl = BRep_Tool::Pnt(l);
2373     cout << "\t ( "<< ptr( f ) << " - " << ptr( l )<< " )"
2374          << "\t ( "<< pf.X()<<", "<<pf.Y()<<", "<<pf.Z()<<" ) - "
2375          << " ( "<< pl.X()<<", "<<pl.Y()<<", "<<pl.Z()<<" )"<<endl;
2376   }
2377   else
2378   {
2379     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2380     for ( ; side != sideEnd; ++side ) {
2381       side->Dump();
2382       cout << "\t";
2383     }
2384   }
2385 }