Salome HOME
Copyright update 2021
[modules/smesh.git] / src / StdMeshers / StdMeshers_CompositeHexa_3D.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, 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   int 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   int 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<int>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1131     if ( !nbElems.empty() )
1132       nbSeg1 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1133   }
1134
1135   // Get an 1D size of a box side orthogonal to lessComplexSide
1136   int 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<int>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1144     if ( !nbElems.empty() )
1145       nbSeg2 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1146   }
1147
1148   // Get an 2D size of a box side orthogonal to lessComplexSide
1149   int 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<int>& 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<int> aResVec(SMDSEntity_Last,0);
1170   int 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 #ifdef _DEBUG_
1246   mySides.GetSide( Q_BOTTOM )->SetID( Q_BOTTOM );
1247   mySides.GetSide( Q_RIGHT  )->SetID( Q_RIGHT );
1248   mySides.GetSide( Q_TOP    )->SetID( Q_TOP );
1249   mySides.GetSide( Q_LEFT   )->SetID( Q_LEFT );
1250 #endif
1251
1252   return true;
1253 }
1254
1255 //================================================================================
1256 /*!
1257  * \brief Try to unite self with other ordinary face
1258  */
1259 //================================================================================
1260
1261 bool _QuadFaceGrid::AddContinuousFace( const _QuadFaceGrid&       other,
1262                                        const TopTools_MapOfShape& internalEdges)
1263 {
1264   for ( int i = 0; i < 4; ++i )
1265   {
1266     const _FaceSide& otherSide = other.GetSide( i );
1267     int iMyCommon;
1268     if ( mySides.Contain( otherSide, &iMyCommon ))
1269     {
1270       if ( internalEdges.Contains( otherSide.Edge( 0 )))
1271       {
1272         DUMP_VERT("Cont 1", mySides.GetSide(iMyCommon)->FirstVertex());
1273         DUMP_VERT("Cont 2", mySides.GetSide(iMyCommon)->LastVertex());
1274         DUMP_VERT("Cont 3", otherSide.FirstVertex());
1275         DUMP_VERT("Cont 4", otherSide.LastVertex());
1276
1277         if ( myChildren.empty() )
1278         {
1279           myChildren.push_back( *this );
1280           myFace.Nullify();
1281         }
1282         else // find iMyCommon in myChildren
1283         {
1284           for ( TChildIterator children = GetChildren(); children.more(); ) {
1285             const _QuadFaceGrid& child = children.next();
1286             if ( child.mySides.Contain( otherSide, &iMyCommon ))
1287               break;
1288           }
1289         }
1290
1291         // orient new children equally
1292         int otherBottomIndex = SMESH_MesherHelper::WrapIndex( i - iMyCommon + 2, 4 );
1293         if ( other.IsComplex() )
1294           for ( TChildIterator children = other.GetChildren(); children.more(); ) {
1295             myChildren.push_back( children.next() );
1296             myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1297           }
1298         else {
1299           myChildren.push_back( other );
1300           myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1301         }
1302
1303         myLeftBottomChild = 0;
1304
1305         // collect vertices in mySides
1306         if ( other.IsComplex() )
1307           for ( TChildIterator children = other.GetChildren(); children.more(); )
1308           {
1309             const _QuadFaceGrid& child = children.next();
1310             for ( int i = 0; i < 4; ++i )
1311               mySides.AppendSide( child.GetSide(i) );
1312           }
1313         else
1314           for ( int i = 0; i < 4; ++i )
1315             mySides.AppendSide( other.GetSide(i) );
1316
1317         return true;
1318       }
1319     }
1320   }
1321   return false;
1322 }
1323
1324 //================================================================================
1325 /*!
1326  * \brief Try to set the side as bottom hirizontal side
1327  */
1328 //================================================================================
1329
1330 bool _QuadFaceGrid::SetBottomSide(const _FaceSide& bottom, int* sideIndex)
1331 {
1332   myLeftBottomChild = myRightBrother = myUpBrother = 0;
1333
1334   int myBottomIndex;
1335   if ( myChildren.empty() )
1336   {
1337     if ( mySides.Contain( bottom, &myBottomIndex )) {
1338       mySides.SetBottomSide( myBottomIndex );
1339       if ( sideIndex )
1340         *sideIndex = myBottomIndex;
1341       return true;
1342     }
1343   }
1344   else
1345   {
1346     TChildren::iterator childFace = myChildren.begin(), childEnd = myChildren.end();
1347     for ( ; childFace != childEnd; ++childFace )
1348     {
1349       if ( childFace->SetBottomSide( bottom, &myBottomIndex ))
1350       {
1351         TChildren::iterator orientedChild = childFace;
1352         for ( childFace = myChildren.begin(); childFace != childEnd; ++childFace ) {
1353           if ( childFace != orientedChild )
1354             childFace->SetBottomSide( childFace->GetSide( myBottomIndex ));
1355         }
1356         if ( sideIndex )
1357           *sideIndex = myBottomIndex;
1358         return true;
1359       }
1360     }
1361   }
1362   return false;
1363 }
1364
1365 //================================================================================
1366 /*!
1367  * \brief Return face adjacent to i-th side of this face, (0<i<4)
1368  */
1369 //================================================================================
1370
1371 _QuadFaceGrid* _QuadFaceGrid::FindAdjacentForSide(int                  i,
1372                                                   list<_QuadFaceGrid>& faces,
1373                                                   EBoxSides            id) const
1374 {
1375   const _FaceSide & iSide = GetSide( i );
1376   list< _QuadFaceGrid >::iterator boxFace = faces.begin();
1377   for ( ; boxFace != faces.end(); ++boxFace )
1378   {
1379     _QuadFaceGrid* f  = & (*boxFace);
1380     if ( f != this && f->SetBottomSide( iSide ))
1381       return f->SetID( id ), f;
1382   }
1383   return (_QuadFaceGrid*) 0;
1384 }
1385
1386 //================================================================================
1387 /*!
1388  * \brief Return i-th side
1389  */
1390 //================================================================================
1391
1392 const _FaceSide& _QuadFaceGrid::GetSide(int i) const
1393 {
1394   if ( myChildren.empty() )
1395     return *mySides.GetSide(i);
1396
1397   _QuadFaceGrid* me = const_cast<_QuadFaceGrid*>(this);
1398   if ( !me->locateChildren() || !myLeftBottomChild )
1399     return *mySides.GetSide(i);
1400
1401   const _QuadFaceGrid* child = myLeftBottomChild;
1402   switch ( i ){
1403   case Q_BOTTOM:
1404   case Q_LEFT:
1405     break;
1406   case Q_RIGHT:
1407     while ( child->myRightBrother )
1408       child = child->myRightBrother;
1409     break;
1410   case Q_TOP:
1411     while ( child->myUpBrother )
1412       child = child->myUpBrother;
1413     break;
1414   default: ;
1415   }
1416   return child->GetSide( i );
1417 }
1418
1419 //================================================================================
1420 /*!
1421  * \brief Reverse edges in order to have them oriented along axes of the unit box
1422  */
1423 //================================================================================
1424
1425 void _QuadFaceGrid::ReverseEdges()
1426 {
1427   myReverse = !myReverse;
1428
1429 // #ifdef DEB_FACES
1430 //   if ( !myFace.IsNull() )
1431 //     TopAbs::Print(myFace.Orientation(), cout);
1432 // #endif
1433
1434   if ( myChildren.empty() )
1435   {
1436     DumpVertices();
1437   }
1438   else
1439   {
1440     DumpVertices();
1441     TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1442     for ( ; child != childEnd; ++child )
1443       child->ReverseEdges();
1444   }
1445 }
1446
1447 //================================================================================
1448 /*!
1449  * \brief Load nodes of a mesh
1450  */
1451 //================================================================================
1452
1453 bool _QuadFaceGrid::LoadGrid( SMESH_ProxyMesh& mesh )
1454 {
1455   if ( !myChildren.empty() )
1456   {
1457     // Let child faces load their grids
1458     TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1459     for ( ; child != childEnd; ++child ) {
1460       child->SetID( myID );
1461       if ( !child->LoadGrid( mesh ) )
1462         return error( child->GetError() );
1463     }
1464     // Fill myGrid with nodes of patches
1465     return loadCompositeGrid( mesh );
1466   }
1467
1468   // ---------------------------------------
1469   // Fill myGrid with nodes bound to myFace
1470   // ---------------------------------------
1471
1472   if ( !myGrid.empty() )
1473     return true;
1474
1475   const SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace );
1476
1477   // check that all faces are quadrangular
1478   SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
1479   while ( fIt->more() )
1480     if ( fIt->next()->NbNodes() % 4 > 0 )
1481       return error("Non-quadrangular mesh faces are not allowed on sides of a composite block");
1482
1483   bool isProxy = false, isTmpElem = false;
1484   if ( faceSubMesh && faceSubMesh->NbElements() > 0 )
1485   {
1486     isProxy   = dynamic_cast< const SMESH_ProxyMesh::SubMesh* >( faceSubMesh );
1487     isTmpElem = mesh.IsTemporary( faceSubMesh->GetElements()->next() );
1488   }
1489   const SMESHDS_SubMesh* smToCheckEdges = ( isProxy && !isTmpElem ) ? faceSubMesh : 0;
1490
1491   myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh, smToCheckEdges );
1492   myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT   )->GetNbSegments( mesh, smToCheckEdges );
1493
1494   myGrid.resize( myIndexer.size() );
1495
1496   // store nodes bound to the bottom edge
1497   mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse, isProxy, smToCheckEdges );
1498
1499   // store the rest nodes row by row
1500
1501   TIDSortedElemSet avoidSet;
1502   const SMDS_MeshElement* firstQuad = 0; // most left face above the last row of found nodes
1503
1504   size_t nbFoundNodes = myIndexer._xSize;
1505   while ( nbFoundNodes != myGrid.size() )
1506   {
1507     // first and last nodes of the last filled row of nodes
1508     const SMDS_MeshNode* n1down = myGrid[ nbFoundNodes - myIndexer._xSize ];
1509     const SMDS_MeshNode* n2down = myGrid[ nbFoundNodes - myIndexer._xSize + 1];
1510     const SMDS_MeshNode* n1downLast = myGrid[ nbFoundNodes-1 ];
1511
1512     // find the first face above the row by the first two left nodes
1513     //
1514     // n1up     n2up
1515     //     o---o
1516     //     |   |
1517     //     o---o  o  o  o  o
1518     //n1down    n2down
1519     //
1520     firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh );
1521     while ( firstQuad && !faceSubMesh->Contains( firstQuad )) {
1522       avoidSet.insert( firstQuad );
1523       firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh);
1524     }
1525     if ( !firstQuad || !faceSubMesh->Contains( firstQuad ))
1526       return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1527
1528     // find the node of quad bound to the left geom edge
1529     int i2down = firstQuad->GetNodeIndex( n2down );
1530     const SMDS_MeshNode* n1up = firstQuad->GetNode(( i2down+2 ) % 4 );
1531     myGrid[ nbFoundNodes++ ] = n1up;
1532     // the 4-the node of the first quad
1533     int i1down = firstQuad->GetNodeIndex( n1down );
1534     const SMDS_MeshNode* n2up = firstQuad->GetNode(( i1down+2 ) % 4 );
1535     myGrid[ nbFoundNodes++ ] = n2up;
1536
1537     n1down = n2down;
1538     n1up   = n2up;
1539     const SMDS_MeshElement* quad = firstQuad;
1540
1541     // find the rest nodes by remaining faces above the row
1542     //
1543     //             n1up
1544     //     o---o--o
1545     //     |   |  | ->
1546     //     o---o--o  o  o  o
1547     //                      n1downLast
1548     //
1549     while ( n1down != n1downLast )
1550     {
1551       // next face
1552       avoidSet.clear(); avoidSet.insert( quad );
1553       quad = FindFaceByNodes( n1down, n1up, avoidSet, mesh );
1554       if ( !quad || quad->NbNodes() % 4 > 0)
1555         return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1556
1557       // next node
1558       if ( quad->GetNode( i1down ) != n1down ) // check already found index
1559         i1down = quad->GetNodeIndex( n1down );
1560       n2up = quad->GetNode(( i1down+2 ) % 4 );
1561       myGrid[ nbFoundNodes++ ] = n2up;
1562
1563       n1down = myGrid[ nbFoundNodes - myIndexer._xSize - 1 ];
1564       n1up   = n2up;
1565     }
1566     avoidSet.clear(); avoidSet.insert( firstQuad );
1567   }
1568   DumpGrid(); // debug
1569
1570   return true;
1571 }
1572
1573 //================================================================================
1574 /*!
1575  * \brief Fill myIJK with normalized parameters of nodes in myGrid
1576  *  \param [in] i1 - coordinate index along rows of myGrid
1577  *  \param [in] i2 - coordinate index along columns of myGrid
1578  *  \param [in] v3 - value of the constant parameter
1579  */
1580 //================================================================================
1581
1582 void _QuadFaceGrid::ComputeIJK( int i1, int i2, double v3 )
1583 {
1584   gp_XYZ ijk( v3, v3, v3 );
1585   myIJK.resize( myIndexer.size(), ijk );
1586
1587   const size_t nbCol = myIndexer._xSize;
1588   const size_t nbRow = myIndexer._ySize;
1589
1590   vector< double > len( nbRow );
1591   len[0] = 0;
1592   for ( size_t i = 0; i < nbCol; ++i )
1593   {
1594     gp_Pnt pPrev = GetXYZ( i, 0 );
1595     for ( size_t j = 1; j < nbRow; ++j )
1596     {
1597       gp_Pnt p = GetXYZ( i, j );
1598       len[ j ] = len[ j-1 ] + p.Distance( pPrev );
1599       pPrev = p;
1600     }
1601     for ( size_t j = 0; j < nbRow; ++j )
1602       GetIJK( i, j ).SetCoord( i2, len[ j ]/len.back() );
1603   }
1604
1605   len.resize( nbCol );
1606   for ( size_t j = 0; j < nbRow; ++j )
1607   {
1608     gp_Pnt pPrev = GetXYZ( 0, j );
1609     for ( size_t i = 1; i < nbCol; ++i )
1610     {
1611       gp_Pnt p = GetXYZ( i, j );
1612       len[ i ] = len[ i-1 ] + p.Distance( pPrev );
1613       pPrev = p;
1614     }
1615     for ( size_t i = 0; i < nbCol; ++i )
1616       GetIJK( i, j ).SetCoord( i1, len[ i ]/len.back() );
1617   }
1618 }
1619
1620 //================================================================================
1621 /*!
1622  * \brief Find out mutual location of children: find their right and up brothers
1623  */
1624 //================================================================================
1625
1626 bool _QuadFaceGrid::locateChildren()
1627 {
1628   if ( myLeftBottomChild )
1629     return true;
1630
1631   TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1632
1633   // find a child sharing it's first bottom vertex with no other brother
1634   myLeftBottomChild = 0;
1635   for ( ; !myLeftBottomChild && child != childEnd; ++child )
1636   {
1637     TopoDS_Vertex leftVertex = child->GetSide( Q_BOTTOM ).FirstVertex();
1638     bool sharedVertex = false;
1639     TChildren::iterator otherChild = myChildren.begin();
1640     for ( ; otherChild != childEnd && !sharedVertex; ++otherChild )
1641       if ( otherChild != child )
1642         sharedVertex = otherChild->mySides.Contain( leftVertex );
1643     if ( !sharedVertex ) {
1644       myLeftBottomChild = & (*child);
1645       DUMP_VERT("0 left bottom Vertex: ",leftVertex );
1646     }
1647   }
1648   if (!myLeftBottomChild)
1649     return error(ERR_LI("Error in locateChildren()"));
1650
1651   set< _QuadFaceGrid* > notLocatedChilren;
1652   for (child = myChildren.begin() ; child != childEnd; ++child )
1653     notLocatedChilren.insert( & (*child));
1654
1655   // connect myLeftBottomChild to it's right and upper brothers
1656   notLocatedChilren.erase( myLeftBottomChild );
1657   myLeftBottomChild->setBrothers( notLocatedChilren );
1658   if ( !notLocatedChilren.empty() )
1659     return error(ERR_LI("Error in locateChildren()"));
1660
1661   return true;
1662 }
1663
1664 //================================================================================
1665 /*!
1666  * \brief Fill myGrid with nodes of patches
1667  */
1668 //================================================================================
1669
1670 bool _QuadFaceGrid::loadCompositeGrid(SMESH_ProxyMesh& mesh)
1671 {
1672   // Find out mutual location of children: find their right and up brothers
1673   if ( !locateChildren() )
1674     return false;
1675
1676   // Load nodes according to mutual location of children
1677
1678   // grid size
1679   myIndexer._xSize = 1 + myLeftBottomChild->GetNbHoriSegments( mesh, /*withBrothers=*/true );
1680   myIndexer._ySize = 1 + myLeftBottomChild->GetNbVertSegments( mesh, /*withBrothers=*/true );
1681
1682   myGrid.resize( myIndexer.size() );
1683
1684   int fromX = myReverse ? myIndexer._xSize : 0;
1685   if ( !myLeftBottomChild->fillGrid( mesh, myGrid, myIndexer, fromX, 0 ))
1686     return error( myLeftBottomChild->GetError() );
1687
1688   DumpGrid();
1689
1690   return true;
1691 }
1692
1693 //================================================================================
1694 /*!
1695  * \brief Find right an upper brothers among notLocatedBrothers
1696  */
1697 //================================================================================
1698
1699 void _QuadFaceGrid::setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers )
1700 {
1701   if ( !notLocatedBrothers.empty() )
1702   {
1703     // find right brother
1704     TopoDS_Vertex rightVertex = GetSide( Q_BOTTOM ).LastVertex();
1705     DUMP_VERT("1 right bottom Vertex: ",rightVertex );
1706     set< _QuadFaceGrid* >::iterator brIt, brEnd = notLocatedBrothers.end();
1707     for ( brIt = notLocatedBrothers.begin(); brIt != brEnd; ++brIt )
1708     {
1709       _QuadFaceGrid* brother = *brIt;
1710       TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1711       DUMP_VERT( "brother left bottom: ", brotherLeftVertex );
1712       if ( rightVertex.IsSame( brotherLeftVertex )) {
1713         myRightBrother = brother;
1714         notLocatedBrothers.erase( brIt );
1715         break;
1716       }
1717     }
1718     // find upper brother
1719     TopoDS_Vertex upVertex = GetSide( Q_LEFT ).FirstVertex();
1720     DUMP_VERT("1 left up Vertex: ",upVertex);
1721     brIt = notLocatedBrothers.begin(), brEnd = notLocatedBrothers.end();
1722     for ( ; brIt != brEnd; ++brIt )
1723     {
1724       _QuadFaceGrid* brother = *brIt;
1725       TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1726       DUMP_VERT("brother left bottom: ", brotherLeftVertex);
1727       if ( upVertex.IsSame( brotherLeftVertex )) {
1728         myUpBrother = brother;
1729         notLocatedBrothers.erase( myUpBrother );
1730         break;
1731       }
1732     }
1733     // recursive call
1734     if ( myRightBrother )
1735       myRightBrother->setBrothers( notLocatedBrothers );
1736     if ( myUpBrother )
1737       myUpBrother->setBrothers( notLocatedBrothers );
1738   }
1739 }
1740
1741 //================================================================================
1742 /*!
1743  * \brief Store nodes of a simple face into grid starting from (x,y) position
1744  */
1745 //================================================================================
1746
1747 bool _QuadFaceGrid::fillGrid(SMESH_ProxyMesh&               theMesh,
1748                              vector<const SMDS_MeshNode*> & theGrid,
1749                              const _Indexer&                theIndexer,
1750                              int                            theX,
1751                              int                            theY)
1752 {
1753   if ( myGrid.empty() && !LoadGrid( theMesh ))
1754     return false;
1755
1756   // store my own grid in the global grid
1757
1758   int fromX = myReverse ? theX - myIndexer._xSize: theX;
1759
1760   for ( int i = 0, x = fromX; i < myIndexer._xSize; ++i, ++x )
1761     for ( int j = 0, y = theY; j < myIndexer._ySize; ++j, ++y )
1762       theGrid[ theIndexer( x, y )] = myGrid[ myIndexer( i, j )];
1763
1764   // store grids of my right and upper brothers
1765
1766   if ( myRightBrother )
1767   {
1768     if ( myReverse )
1769       fromX += 1;
1770     else
1771       fromX += myIndexer._xSize - 1;
1772     if ( !myRightBrother->fillGrid( theMesh, theGrid, theIndexer, fromX, theY ))
1773       return error( myRightBrother->GetError() );
1774   }
1775   if ( myUpBrother )
1776   {
1777     if ( !myUpBrother->fillGrid( theMesh, theGrid, theIndexer,
1778                                  theX, theY + myIndexer._ySize - 1))
1779       return error( myUpBrother->GetError() );
1780   }
1781   return true;
1782 }
1783
1784 //================================================================================
1785 /*!
1786  * \brief Return number of segments on the hirizontal sides
1787  */
1788 //================================================================================
1789
1790 int _QuadFaceGrid::GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1791 {
1792   int nbSegs = 0;
1793   if ( myLeftBottomChild )
1794   {
1795     nbSegs += myLeftBottomChild->GetNbHoriSegments( mesh, true );
1796   }
1797   else
1798   {
1799     nbSegs = mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
1800     if ( withBrothers && myRightBrother )
1801       nbSegs += myRightBrother->GetNbHoriSegments( mesh, withBrothers );
1802   }
1803   return nbSegs;
1804 }
1805
1806 //================================================================================
1807 /*!
1808  * \brief Return number of segments on the vertical sides
1809  */
1810 //================================================================================
1811
1812 int _QuadFaceGrid::GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1813 {
1814   int nbSegs = 0;
1815   if ( myLeftBottomChild )
1816   {
1817     nbSegs += myLeftBottomChild->GetNbVertSegments( mesh, true );
1818   }
1819   else
1820   {
1821     nbSegs = mySides.GetSide( Q_LEFT )->GetNbSegments(mesh,0);
1822     if ( withBrothers && myUpBrother )
1823       nbSegs += myUpBrother->GetNbVertSegments( mesh, withBrothers );
1824   }
1825   return nbSegs;
1826 }
1827
1828 //================================================================================
1829 /*!
1830  * \brief Return edge on the hirizontal bottom sides
1831  */
1832 //================================================================================
1833
1834 int _QuadFaceGrid::GetHoriEdges(vector<TopoDS_Edge> & edges) const
1835 {
1836   if ( myLeftBottomChild )
1837   {
1838     return myLeftBottomChild->GetHoriEdges( edges );
1839   }
1840   else
1841   {
1842     const _FaceSide* bottom  = mySides.GetSide( Q_BOTTOM );
1843     int i = 0;
1844     while ( true ) {
1845       TopoDS_Edge e = bottom->Edge( i++ );
1846       if ( e.IsNull() )
1847         break;
1848       else
1849         edges.push_back( e );
1850     }
1851     if ( myRightBrother )
1852       myRightBrother->GetHoriEdges( edges );
1853   }
1854   return edges.size();
1855 }
1856
1857 //================================================================================
1858 /*!
1859  * \brief Return a node by its position
1860  */
1861 //================================================================================
1862
1863 const SMDS_MeshNode* _QuadFaceGrid::GetNode(int iHori, int iVert) const
1864 {
1865   return myGrid[ myIndexer( iHori, iVert )];
1866 }
1867
1868 //================================================================================
1869 /*!
1870  * \brief Return node coordinates by its position
1871  */
1872 //================================================================================
1873
1874 gp_XYZ _QuadFaceGrid::GetXYZ(int iHori, int iVert) const
1875 {
1876   SMESH_TNodeXYZ xyz = myGrid[ myIndexer( iHori, iVert )];
1877   return xyz;
1878 }
1879
1880 //================================================================================
1881 /*!
1882  * \brief Return normal to the face at vertex v
1883  */
1884 //================================================================================
1885
1886 bool _QuadFaceGrid::GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const
1887 {
1888   if ( myChildren.empty() )
1889   {
1890     if ( mySides.Contain( v )) {
1891       try {
1892         gp_Pnt2d uv = BRep_Tool::Parameters( v, myFace );
1893         BRepAdaptor_Surface surface( myFace );
1894         gp_Pnt p; gp_Vec d1u, d1v;
1895         surface.D1( uv.X(), uv.Y(), p, d1u, d1v );
1896         n = d1u.Crossed( d1v );
1897         return true;
1898       }
1899       catch (Standard_Failure&) {
1900         return false;
1901       }
1902     }
1903   }
1904   else
1905   {
1906     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1907     for ( ; child != childEnd; ++child )
1908       if ( child->GetNormal( v, n ))
1909         return true;
1910   }
1911   return false;
1912 }
1913
1914 //================================================================================
1915 /*!
1916  * \brief Dumps coordinates of grid nodes
1917  */
1918 //================================================================================
1919
1920 void _QuadFaceGrid::DumpGrid() const
1921 {
1922 #ifdef DEB_GRID
1923   const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1924   cout << "****** Face " << names[ myID ] << endl;
1925
1926   if ( myChildren.empty() || !myGrid.empty() )
1927   {
1928     cout << "x size: " << myIndexer._xSize << "; y size: " << myIndexer._ySize << endl;
1929     for ( int y = 0; y < myIndexer._ySize; ++y ) {
1930       cout << "-- row " << y << endl;
1931       for ( int x = 0; x < myIndexer._xSize; ++x ) {
1932         const SMDS_MeshNode* n = myGrid[ myIndexer( x, y ) ];
1933         cout << x << " ( " << n->X() << ", " << n->Y() << ", " << n->Z() << " )" << endl;
1934       }
1935     }
1936   }
1937   else
1938   {
1939     cout << "Nb children: " << myChildren.size() << endl;
1940     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1941     for ( int i=0; child != childEnd; ++child, ++i ) {
1942       cout << "   *** SUBFACE " << i+1 << endl;
1943       ((_QuadFaceGrid&)(*child)).SetID( myID );
1944       child->DumpGrid();
1945     }
1946   }
1947 #endif
1948 }
1949
1950 //================================================================================
1951 /*!
1952  * \brief Dump vertices
1953  */
1954 //================================================================================
1955
1956 void _QuadFaceGrid::DumpVertices() const
1957 {
1958 #ifdef DEB_FACES
1959   cout << "****** Face ";
1960   const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1961   if ( myID >= B_BOTTOM && myID < B_BACK )
1962     cout << names[ myID ] << endl;
1963   else
1964     cout << "UNDEFINED" << endl;
1965
1966   if ( myChildren.empty() )
1967   {
1968     for ( int i = 0; i < 4; ++i )
1969     {
1970       cout << "  Side "; mySides.GetSide( i )->Dump();
1971     }
1972   }
1973   else
1974   {
1975     cout << "-- Nb children: " << myChildren.size() << endl;
1976     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1977     for ( int i=0; child != childEnd; ++child, ++i ) {
1978       cout << "   *** SUBFACE " << i+1 << endl;
1979       ((_QuadFaceGrid&)(*child)).SetID( myID );
1980       child->DumpVertices();
1981     }
1982   }
1983 #endif
1984 }
1985
1986 //=======================================================================
1987 //function : _FaceSide
1988 //purpose  : copy constructor
1989 //=======================================================================
1990
1991 _FaceSide::_FaceSide(const _FaceSide& other)
1992 {
1993   myEdge = other.myEdge;
1994   myChildren = other.myChildren;
1995   myNbChildren = other.myNbChildren;
1996   myVertices.Assign( other.myVertices );
1997   myID = other.myID;
1998 }
1999
2000 //================================================================================
2001 /*!
2002  * \brief Construct a face side of one edge
2003  */
2004 //================================================================================
2005
2006 _FaceSide::_FaceSide(const TopoDS_Edge& edge):
2007   myEdge( edge ), myNbChildren(0)
2008 {
2009   if ( !edge.IsNull() )
2010     for ( TopExp_Explorer exp( edge, TopAbs_VERTEX ); exp.More(); exp.Next() )
2011       //myVertices.insert( ptr ( exp.Current() ));
2012       myVertices.Add( exp.Current() );
2013 }
2014
2015 //================================================================================
2016 /*!
2017  * \brief Construct a face side of several edges
2018  */
2019 //================================================================================
2020
2021 _FaceSide::_FaceSide(const list<TopoDS_Edge>& edges):
2022   myNbChildren(0)
2023 {
2024   list<TopoDS_Edge>::const_iterator edge = edges.begin(), eEnd = edges.end();
2025   for ( ; edge != eEnd; ++edge ) {
2026     myChildren.push_back( _FaceSide( *edge ));
2027     myNbChildren++;
2028     myVertices.Add( myChildren.back().FirstVertex() );
2029     myVertices.Add( myChildren.back().LastVertex() );
2030     myChildren.back().SetID( Q_CHILD ); // not to splice them
2031   }
2032 }
2033
2034 //=======================================================================
2035 //function : GetSide
2036 //purpose  :
2037 //=======================================================================
2038
2039 _FaceSide* _FaceSide::GetSide(const int i)
2040 {
2041   if ( i >= myNbChildren )
2042     return 0;
2043
2044   list< _FaceSide >::iterator side = myChildren.begin();
2045   if ( i )
2046     std::advance( side, i );
2047   return & (*side);
2048 }
2049
2050 //=======================================================================
2051 //function : GetSide
2052 //purpose  : 
2053 //=======================================================================
2054
2055 const _FaceSide* _FaceSide::GetSide(const int i) const
2056 {
2057   return const_cast< _FaceSide* >(this)->GetSide(i);
2058 }
2059
2060 //=======================================================================
2061 //function : NbVertices
2062 //purpose  : return nb of vertices in the side
2063 //=======================================================================
2064
2065 int _FaceSide::NbVertices() const
2066 {
2067   if ( myChildren.empty() )
2068     return myVertices.Extent();
2069
2070   return myNbChildren + 1;
2071 }
2072
2073 //=======================================================================
2074 //function : NbCommonVertices
2075 //purpose  : Returns number of my vertices common with the given ones
2076 //=======================================================================
2077
2078 int _FaceSide::NbCommonVertices( const TopTools_MapOfShape& VV ) const
2079 {
2080   int nbCommon = 0;
2081   TopTools_MapIteratorOfMapOfShape vIt ( myVertices );
2082   for ( ; vIt.More(); vIt.Next() )
2083     nbCommon += ( VV.Contains( vIt.Key() ));
2084
2085   return nbCommon;
2086 }
2087
2088 //=======================================================================
2089 //function : FirstVertex
2090 //purpose  :
2091 //=======================================================================
2092
2093 TopoDS_Vertex _FaceSide::FirstVertex() const
2094 {
2095   if ( myChildren.empty() )
2096     return TopExp::FirstVertex( myEdge, Standard_True );
2097
2098   return myChildren.front().FirstVertex();
2099 }
2100
2101 //=======================================================================
2102 //function : LastVertex
2103 //purpose  : 
2104 //=======================================================================
2105
2106 TopoDS_Vertex _FaceSide::LastVertex() const
2107 {
2108   if ( myChildren.empty() )
2109     return TopExp::LastVertex( myEdge, Standard_True );
2110
2111   return myChildren.back().LastVertex();
2112 }
2113
2114 //=======================================================================
2115 //function : Vertex
2116 //purpose  : 
2117 //=======================================================================
2118
2119 TopoDS_Vertex _FaceSide::Vertex(int i) const
2120 {
2121   if ( myChildren.empty() )
2122     return i ? LastVertex() : FirstVertex();
2123       
2124   if ( i >= myNbChildren )
2125     return myChildren.back().LastVertex();
2126   
2127   return GetSide(i)->FirstVertex();
2128 }
2129
2130 //================================================================================
2131 /*!
2132  * \brief Return i-the zero-based edge of the side
2133  */
2134 //================================================================================
2135
2136 TopoDS_Edge _FaceSide::Edge(int i) const
2137 {
2138   if ( i == 0 && !myEdge.IsNull() )
2139     return myEdge;
2140
2141   if ( const _FaceSide* iSide = GetSide( i ))
2142     return iSide->myEdge;
2143
2144   return TopoDS_Edge();
2145 }
2146
2147 //=======================================================================
2148 //function : Contain
2149 //purpose  : 
2150 //=======================================================================
2151
2152 bool _FaceSide::Contain( const _FaceSide& side, int* which ) const
2153 {
2154   if ( !which || myChildren.empty() )
2155   {
2156     if ( which )
2157       *which = 0;
2158     int nbCommon = 0;
2159     TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2160     for ( ; vIt.More(); vIt.Next() )
2161       nbCommon += ( myVertices.Contains( vIt.Key() ));
2162     return (nbCommon > 1);
2163   }
2164   list< _FaceSide >::const_iterator mySide = myChildren.begin(), sideEnd = myChildren.end();
2165   for ( int i = 0; mySide != sideEnd; ++mySide, ++i ) {
2166     if ( mySide->Contain( side )) {
2167       *which = i;
2168       return true;
2169     }
2170   }
2171   return false;
2172 }
2173
2174 //=======================================================================
2175 //function : Contain
2176 //purpose  : 
2177 //=======================================================================
2178
2179 bool _FaceSide::Contain( const TopoDS_Vertex& vertex ) const
2180 {
2181   return myVertices.Contains( vertex );
2182 }
2183
2184 //=======================================================================
2185 //function : AppendSide
2186 //purpose  : 
2187 //=======================================================================
2188
2189 void _FaceSide::AppendSide( const _FaceSide& side )
2190 {
2191   if ( !myEdge.IsNull() )
2192   {
2193     myChildren.push_back( *this );
2194     myNbChildren = 1;
2195     myEdge.Nullify();
2196   }
2197   myChildren.push_back( side );
2198   myNbChildren++;
2199   TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2200   for ( ; vIt.More(); vIt.Next() )
2201     myVertices.Add( vIt.Key() );
2202
2203   myID = Q_PARENT;
2204   myChildren.back().SetID( EQuadSides( myNbChildren-1 ));
2205 }
2206
2207 //=======================================================================
2208 //function : SetBottomSide
2209 //purpose  : 
2210 //=======================================================================
2211
2212 void _FaceSide::SetBottomSide( int i )
2213 {
2214   if ( i > 0 && myID == Q_PARENT ) {
2215     list< _FaceSide >::iterator sideEnd, side = myChildren.begin();
2216     std::advance( side, i );
2217     myChildren.splice( myChildren.begin(), myChildren, side, myChildren.end() );
2218
2219     side = myChildren.begin(), sideEnd = myChildren.end();
2220     for ( int i = 0; side != sideEnd; ++side, ++i ) {
2221       side->SetID( EQuadSides(i) );
2222       side->SetBottomSide(i);
2223     }
2224   }
2225 }
2226
2227 //=======================================================================
2228 //function : GetNbSegments
2229 //purpose  : 
2230 //=======================================================================
2231
2232 int _FaceSide::GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges) const
2233 {
2234   int nb = 0;
2235   if ( myChildren.empty() )
2236   {
2237     nb = mesh.GetSubMesh(myEdge)->NbElements();
2238
2239     if ( smToCheckEdges )
2240     {
2241       // check that segments bound faces belonging to smToCheckEdges
2242       SMDS_ElemIteratorPtr segIt = mesh.GetSubMesh(myEdge)->GetElements();
2243       while ( segIt->more() )
2244       {
2245         const SMDS_MeshElement* seg = segIt->next();
2246         if ( !IsSegmentOnSubMeshBoundary( mesh.GetProxyNode( seg->GetNode(0) ),
2247                                           mesh.GetProxyNode( seg->GetNode(1) ),
2248                                           smToCheckEdges, mesh ))
2249           --nb;
2250       }
2251     }
2252   }
2253   else
2254   {
2255     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2256     for ( ; side != sideEnd; ++side )
2257       nb += side->GetNbSegments( mesh, smToCheckEdges );
2258   }
2259   return nb;
2260 }
2261
2262 //=======================================================================
2263 //function : StoreNodes
2264 //purpose  :
2265 //=======================================================================
2266
2267 bool _FaceSide::StoreNodes(SMESH_ProxyMesh&              mesh,
2268                            vector<const SMDS_MeshNode*>& myGrid,
2269                            bool                          reverse,
2270                            bool                          isProxy,
2271                            const SMESHDS_SubMesh*        smToCheckEdges)
2272 {
2273   list< TopoDS_Edge > edges;
2274   if ( myChildren.empty() )
2275   {
2276     edges.push_back( myEdge );
2277   }
2278   else
2279   {
2280     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2281     for ( ; side != sideEnd; ++side )
2282       if ( reverse )
2283         edges.push_front( side->myEdge );
2284       else
2285         edges.push_back ( side->myEdge );
2286   }
2287   int nbNodes = 0;
2288   list< TopoDS_Edge >::iterator edge = edges.begin(), eEnd = edges.end();
2289   for ( ; edge != eEnd; ++edge )
2290   {
2291     typedef map< double, const SMDS_MeshNode* > TParamNodeMap;
2292     TParamNodeMap nodes;
2293     bool ok = SMESH_Algo::GetSortedNodesOnEdge( mesh.GetMeshDS(),
2294                                                 *edge,
2295                                                 /*ignoreMediumNodes=*/true,
2296                                                 nodes);
2297     if ( !ok ) return false;
2298
2299     // skip nodes on VERTEXes not included in faces
2300     if ( !nodes.begin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2301       nodes.erase( nodes.begin() );
2302     if ( !nodes.empty() &&
2303          !nodes.rbegin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2304       nodes.erase( --nodes.end() );
2305
2306     if ( isProxy )
2307     {
2308       TParamNodeMap::iterator u_node, nEnd = nodes.end();
2309       for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2310         u_node->second = mesh.GetProxyNode( u_node->second );
2311     }
2312
2313     if ( smToCheckEdges ) // erase nodes of segments not bounding faces of smToCheckEdges
2314     {
2315       {
2316         TParamNodeMap::iterator u_node1, u_node2 = nodes.begin(), nEnd = nodes.end();
2317         for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2318           if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2319                                            smToCheckEdges, mesh ))
2320             break;
2321           else
2322             nodes.erase( u_node1 );
2323       }
2324       {
2325         TParamNodeMap::reverse_iterator u_node1, u_node2 = nodes.rbegin(), nEnd = nodes.rend();
2326         for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2327           if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2328                                            smToCheckEdges, mesh ))
2329             break;
2330           else
2331             nodes.erase( --(( u_node2 = u_node1 ).base() ));
2332       }
2333     }
2334
2335     bool forward = ( edge->Orientation() == TopAbs_FORWARD );
2336     if ( reverse ) forward = !forward;
2337     if ( forward )
2338     {
2339       TParamNodeMap::iterator u_node, nEnd = nodes.end();
2340       for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2341         myGrid[ nbNodes++ ] = u_node->second;
2342     }
2343     else
2344     {
2345       TParamNodeMap::reverse_iterator u_node, nEnd = nodes.rend();
2346       for ( u_node = nodes.rbegin(); u_node != nEnd; ++u_node )
2347         myGrid[ nbNodes++ ] = u_node->second;
2348     }
2349     nbNodes--; // node on vertex present in two adjacent edges
2350   }
2351   return nbNodes > 0;
2352 }
2353
2354 //=======================================================================
2355 //function : Dump
2356 //purpose  : dump end vertices
2357 //=======================================================================
2358
2359 void _FaceSide::Dump() const
2360 {
2361   if ( myChildren.empty() )
2362   {
2363     const char* sideNames[] = { "Q_BOTTOM", "Q_RIGHT", "Q_TOP", "Q_LEFT", "Q_CHILD", "Q_PARENT" };
2364     if ( myID >= Q_BOTTOM && myID < Q_PARENT )
2365       cout << sideNames[ myID ] << endl;
2366     else
2367       cout << "<UNDEFINED ID>" << endl;
2368     TopoDS_Vertex f = FirstVertex();
2369     TopoDS_Vertex l = LastVertex();
2370     gp_Pnt pf = BRep_Tool::Pnt(f);
2371     gp_Pnt pl = BRep_Tool::Pnt(l);
2372     cout << "\t ( "<< ptr( f ) << " - " << ptr( l )<< " )"
2373          << "\t ( "<< pf.X()<<", "<<pf.Y()<<", "<<pf.Z()<<" ) - "
2374          << " ( "<< pl.X()<<", "<<pl.Y()<<", "<<pl.Z()<<" )"<<endl;
2375   }
2376   else
2377   {
2378     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2379     for ( ; side != sideEnd; ++side ) {
2380       side->Dump();
2381       cout << "\t";
2382     }
2383   }
2384 }