Salome HOME
23118: EDF 11115 SMESH: Hexahedric mesh produces degenerate elements in quadratic...
[modules/smesh.git] / src / StdMeshers / StdMeshers_CompositeHexa_3D.cxx
1 // Copyright (C) 2007-2015  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 : implementaion 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 "SMESH_Block.hxx"
32 #include "SMESH_Comment.hxx"
33 #include "SMESH_ComputeError.hxx"
34 #include "SMESH_Mesh.hxx"
35 #include "SMESH_MeshAlgos.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "SMESH_subMesh.hxx"
38
39 #include <BRepAdaptor_Surface.hxx>
40 #include <BRep_Tool.hxx>
41 #include <Standard_ErrorHandler.hxx>
42 #include <Standard_Failure.hxx>
43 #include <TopExp_Explorer.hxx>
44 #include <TopTools_MapIteratorOfMapOfShape.hxx>
45 #include <TopTools_MapOfShape.hxx>
46 #include <TopTools_SequenceOfShape.hxx>
47 #include <TopoDS.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <TopoDS_Vertex.hxx>
51 #include <gp_Pnt.hxx>
52 #include <gp_Pnt2d.hxx>
53 #include <gp_Vec.hxx>
54 #include <gp_XYZ.hxx>
55
56 #include <list>
57 #include <set>
58 #include <vector>
59
60
61 #ifdef _DEBUG_
62 // #define DEB_FACES
63 // #define DEB_GRID
64 // #define DUMP_VERT(msg,V) \
65 //   { TopoDS_Vertex v = V; gp_Pnt p = BRep_Tool::Pnt(v);                  \
66 //     cout << msg << "( "<< p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;}
67 #endif
68
69 #ifndef DUMP_VERT
70 #define DUMP_VERT(msg,v)
71 #endif
72
73 //================================================================================
74 // text for message about an internal error
75 #define ERR_LI(txt) SMESH_Comment(txt) << ":" << __LINE__
76
77 // order corresponds to right order of edges in CASCADE face
78 enum EQuadSides{ Q_BOTTOM=0, Q_RIGHT, Q_TOP, Q_LEFT,   Q_CHILD, Q_PARENT };
79
80 enum EBoxSides{ B_BOTTOM=0, B_RIGHT, B_TOP, B_LEFT, B_FRONT, B_BACK, B_UNDEFINED };
81
82 //================================================================================
83 /*!
84  * \brief Convertor of a pair of integers to a sole index
85  */
86 struct _Indexer
87 {
88   int _xSize, _ySize;
89   _Indexer( int xSize, int ySize ): _xSize(xSize), _ySize(ySize) {}
90   int size() const { return _xSize * _ySize; }
91   int operator()(const int x, const int y) const { return y * _xSize + x; }
92 };
93
94 //================================================================================
95 /*!
96  * \brief Wrapper of a composite or an ordinary edge.
97  */
98 class _FaceSide
99 {
100 public:
101   _FaceSide(const _FaceSide& other);
102   _FaceSide(const TopoDS_Edge& edge=TopoDS_Edge());
103   _FaceSide(const list<TopoDS_Edge>& edges);
104   _FaceSide* GetSide(const int i);
105   const _FaceSide* GetSide(const int i) const;
106   int size() const { return myChildren.size(); }
107   int NbVertices() const;
108   int NbCommonVertices( const TopTools_MapOfShape& VV ) const;
109   TopoDS_Vertex FirstVertex() const;
110   TopoDS_Vertex LastVertex() const;
111   TopoDS_Vertex Vertex(int i) const;
112   TopoDS_Edge   Edge(int i) const;
113   bool Contain( const _FaceSide& side, int* which=0 ) const;
114   bool Contain( const TopoDS_Vertex& vertex ) const;
115   void AppendSide( const _FaceSide& side );
116   void SetBottomSide( int i );
117   int GetNbSegments(SMESH_Mesh& mesh) const;
118   bool StoreNodes(SMESH_Mesh& mesh, vector<const SMDS_MeshNode*>& myGrid, bool reverse );
119   void SetID(EQuadSides id) { myID = id; }
120   static inline const TopoDS_TShape* ptr(const TopoDS_Shape& theShape)
121   { return theShape.TShape().operator->(); }
122   void Dump() const;
123
124 private:
125
126
127   TopoDS_Edge       myEdge;
128   list< _FaceSide > myChildren;
129   int               myNbChildren;
130
131   TopTools_MapOfShape myVertices;
132
133   EQuadSides        myID; // debug
134 };
135 //================================================================================
136 /*!
137  * \brief Class corresponding to a meshed composite face of a box.
138  *        Provides simplified access to it's sub-mesh data.
139  */
140 class _QuadFaceGrid
141 {
142   typedef list< _QuadFaceGrid > TChildren;
143 public:
144   _QuadFaceGrid();
145
146 public: //** Methods to find and orient faces of 6 sides of the box **//
147   
148   //!< initialization
149   bool Init(const TopoDS_Face& f, SMESH_Mesh& mesh );
150
151   //!< try to unite self with other face
152   bool AddContinuousFace( const _QuadFaceGrid& f, const TopTools_MapOfShape& cornerVertices );
153
154   //!< Try to set the side as bottom hirizontal side
155   bool SetBottomSide(const _FaceSide& side, int* sideIndex=0);
156
157   //!< Return face adjacent to zero-based i-th side of this face
158   _QuadFaceGrid* FindAdjacentForSide(int i, list<_QuadFaceGrid>& faces, EBoxSides id) const;
159
160   //!< Reverse edges in order to have the bottom edge going along axes of the unit box
161   void ReverseEdges(/*int e1, int e2*/);
162
163   bool IsComplex() const { return !myChildren.empty(); }
164
165   int NbChildren() const { return myChildren.size(); }
166
167   typedef SMDS_SetIterator< const _QuadFaceGrid&,
168                             TChildren::const_iterator,
169                             SMDS::SimpleAccessor<const _QuadFaceGrid&,TChildren::const_iterator>,
170                             SMDS::PassAllValueFilter<_QuadFaceGrid> >
171     TChildIterator;
172
173   TChildIterator GetChildren() const
174   { return TChildIterator( myChildren.begin(), myChildren.end()); }
175
176 public: //** Loading and access to mesh **//
177
178   //!< Load nodes of a mesh
179   bool LoadGrid( SMESH_Mesh& mesh );
180
181   //!< Return number of segments on the hirizontal sides
182   int GetNbHoriSegments(SMESH_Mesh& mesh, bool withBrothers=false) const;
183
184   //!< Return number of segments on the vertical sides
185   int GetNbVertSegments(SMESH_Mesh& mesh, bool withBrothers=false) const;
186
187   //!< Return edge on the hirizontal bottom sides
188   int GetHoriEdges(vector<TopoDS_Edge> & edges) const;
189
190   //!< Return a node by its position
191   const SMDS_MeshNode* GetNode(int iHori, int iVert) const;
192
193   //!< Return node coordinates by its position
194   gp_XYZ GetXYZ(int iHori, int iVert) const;
195
196 public: //** Access to member fields **//
197
198   //!< Return i-th face side (0<i<4)
199   const _FaceSide& GetSide(int i) const;
200
201   //!< Return it's face, NULL if it is composite
202   TopoDS_Face GetFace() const { return myFace; }
203
204   //!< Return normal to the face at vertex v
205   bool GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const;
206
207   SMESH_ComputeErrorPtr GetError() const { return myError; }
208
209   void SetID(EBoxSides id) { myID = id; }
210
211   void DumpGrid() const;
212
213   void DumpVertices() const;
214
215 private:
216
217   bool error(const std::string& text, int code = COMPERR_ALGO_FAILED)
218   { myError = SMESH_ComputeError::New( code, text ); return false; }
219
220   bool error(const SMESH_ComputeErrorPtr& err)
221   { myError = err; return ( !myError || myError->IsOK() ); }
222
223   bool isContinuousMesh(TopoDS_Edge E1, TopoDS_Edge E2, SMESH_Mesh& mesh) const;
224
225   bool needContinuationAtSide( int iSide, const TopTools_MapOfShape& cornerVertices ) const;
226
227   bool loadCompositeGrid(SMESH_Mesh& mesh);
228
229   bool fillGrid(SMESH_Mesh&                    theMesh,
230                 vector<const SMDS_MeshNode*> & theGrid,
231                 const _Indexer&                theIndexer,
232                 int                            theX,
233                 int                            theY);
234
235   bool locateChildren();
236
237   void setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers );
238
239   TopoDS_Face myFace;
240   _FaceSide   mySides;
241   bool        myReverse;
242
243   TChildren   myChildren;
244
245   _QuadFaceGrid* myLeftBottomChild;
246   _QuadFaceGrid* myRightBrother;
247   _QuadFaceGrid* myUpBrother;
248
249   _Indexer    myIndexer;
250   vector<const SMDS_MeshNode*>  myGrid;
251
252   SMESH_ComputeErrorPtr         myError;
253
254   EBoxSides   myID; // debug
255 };
256
257 //================================================================================
258 /*!
259  * \brief Constructor
260  */
261 //================================================================================
262
263 StdMeshers_CompositeHexa_3D::StdMeshers_CompositeHexa_3D(int hypId, int studyId, SMESH_Gen* gen)
264   :SMESH_3D_Algo(hypId, studyId, gen)
265 {
266   _name = "CompositeHexa_3D";
267   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);       // 1 bit /shape type
268 }
269
270 //================================================================================
271 /*!
272  * \brief always return true
273  */
274 //================================================================================
275
276 bool StdMeshers_CompositeHexa_3D::CheckHypothesis(SMESH_Mesh&         aMesh,
277                                                   const TopoDS_Shape& aShape,
278                                                   Hypothesis_Status&  aStatus)
279 {
280   aStatus = HYP_OK;
281   return true;
282 }
283
284 namespace
285 {
286   //================================================================================
287   /*!
288    * \brief Finds VERTEXes located and block corners
289    */
290   //================================================================================
291
292   void getBlockCorners( SMESH_Mesh&          mesh,
293                         const TopoDS_Shape&  shape,
294                         TopTools_MapOfShape& cornerVV)
295   {
296     set<int> faceIDs; // ids of FACEs in the shape
297     TopExp_Explorer exp;
298     for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
299       faceIDs.insert( mesh.GetMeshDS()->ShapeToIndex( exp.Current() ));
300
301     TopTools_MapOfShape checkedVV;
302     for ( exp.Init( shape, TopAbs_VERTEX ); exp.More(); exp.Next() )
303     {
304       TopoDS_Vertex V = TopoDS::Vertex( exp.Current() );
305       if ( !checkedVV.Add( V )) continue;
306
307       const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
308       if ( !n ) continue;
309
310       int nbQuads = 0;
311       SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
312       while ( fIt->more() )
313       {
314         const SMDS_MeshElement* f = fIt->next();
315         if ( !faceIDs.count( f->getshapeId() )) continue;
316
317         if ( f->NbCornerNodes() == 4 )
318           ++nbQuads;
319         else
320           nbQuads = 100;
321       }
322       if ( nbQuads == 3 )
323         cornerVV.Add( V );
324     }
325   }
326 }
327
328 //================================================================================
329 /*!
330  * \brief Tries to find 6 sides of a box
331  */
332 //================================================================================
333
334 bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape&    shape,
335                                                 list< _QuadFaceGrid >& boxFaces,
336                                                 SMESH_Mesh&            mesh,
337                                                 _QuadFaceGrid * &      fBottom,
338                                                 _QuadFaceGrid * &      fTop,
339                                                 _QuadFaceGrid * &      fFront,
340                                                 _QuadFaceGrid * &      fBack,
341                                                 _QuadFaceGrid * &      fLeft,
342                                                 _QuadFaceGrid * &      fRight)
343 {
344   TopTools_MapOfShape cornerVertices;
345   getBlockCorners( mesh, shape, cornerVertices );
346   if ( cornerVertices.Extent() != 8 )
347     return false;
348
349   list< _QuadFaceGrid >::iterator boxFace;
350   TopExp_Explorer exp;
351   int nbFaces = 0;
352   for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFaces )
353   {
354     _QuadFaceGrid f;
355     if ( !f.Init( TopoDS::Face( exp.Current() ), mesh ))
356       return error (COMPERR_BAD_SHAPE);
357
358     _QuadFaceGrid* prevContinuous = 0;
359     for ( boxFace = boxFaces.begin(); boxFace != boxFaces.end(); ++boxFace )
360     {
361       if ( prevContinuous )
362       {
363         if ( prevContinuous->AddContinuousFace( *boxFace, cornerVertices ))
364           boxFace = --boxFaces.erase( boxFace );
365       }
366       else if ( boxFace->AddContinuousFace( f, cornerVertices ))
367       {
368         prevContinuous = & (*boxFace);
369       }
370     }
371     if ( !prevContinuous )
372       boxFaces.push_back( f );
373   }
374   // Check what we have
375   if ( boxFaces.size() != 6 && nbFaces != 6)
376     return error
377       (COMPERR_BAD_SHAPE,
378        SMESH_Comment("Can't find 6 sides of a box. Number of found sides - ")<<boxFaces.size());
379
380   if ( boxFaces.size() != 6 && nbFaces == 6 ) { // strange ordinary box with continuous faces
381     boxFaces.resize( 6 );
382     boxFace = boxFaces.begin();
383     for ( exp.Init( shape, TopAbs_FACE); exp.More(); exp.Next(), ++boxFace )
384       boxFace->Init( TopoDS::Face( exp.Current() ), mesh );
385   }
386   // ----------------------------------------
387   // Find out position of faces within a box
388   // ----------------------------------------
389   // start from a bottom face
390   fBottom = &boxFaces.front();
391   fBottom->SetID( B_BOTTOM );
392   // find vertical faces
393   fFront = fBottom->FindAdjacentForSide( Q_BOTTOM, boxFaces, B_FRONT );
394   fLeft  = fBottom->FindAdjacentForSide( Q_RIGHT,  boxFaces, B_LEFT  );
395   fBack  = fBottom->FindAdjacentForSide( Q_TOP,    boxFaces, B_BACK  );
396   fRight = fBottom->FindAdjacentForSide( Q_LEFT,   boxFaces, B_RIGHT );
397   // check the found
398   if ( !fFront || !fBack || !fLeft || !fRight )
399     return error(COMPERR_BAD_SHAPE);
400   // find a top face
401   fTop = 0;
402   for ( boxFace = ++boxFaces.begin(); boxFace != boxFaces.end() && !fTop; ++boxFace )
403   {
404     fTop = & (*boxFace);
405     fTop->SetID( B_TOP );
406     if ( fTop==fFront || fTop==fLeft || fTop==fBack || fTop==fRight )
407       fTop = 0;
408   }
409   // set bottom of the top side
410   if ( !fTop->SetBottomSide( fFront->GetSide( Q_TOP ) )) {
411     if ( !fFront->IsComplex() )
412       return error( ERR_LI("Error in StdMeshers_CompositeHexa_3D::Compute()"));
413     else {
414       _QuadFaceGrid::TChildIterator chIt = fFront->GetChildren();
415       while ( chIt.more() ) {
416         const _QuadFaceGrid& frontChild = chIt.next();
417         if ( fTop->SetBottomSide( frontChild.GetSide( Q_TOP )))
418           break;
419       }
420     }
421   }
422   if ( !fTop )
423     return error(COMPERR_BAD_SHAPE);
424
425   // orient bottom egde of faces along axes of the unit box
426   fBottom->ReverseEdges();
427   fBack  ->ReverseEdges();
428   fLeft  ->ReverseEdges();
429
430   return true;
431 }
432
433 //================================================================================
434 /*!
435  * \brief Computes hexahedral mesh on a box with composite sides
436  *  \param aMesh - mesh to compute
437  *  \param aShape - shape to mesh
438  *  \retval bool - succes sign
439  */
440 //================================================================================
441
442 bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh&         theMesh,
443                                           const TopoDS_Shape& theShape)
444 {
445   SMESH_MesherHelper helper( theMesh );
446   _quadraticMesh = helper.IsQuadraticSubMesh( theShape );
447   helper.SetElementsOnShape( true );
448
449   // -------------------------
450   // Try to find 6 side faces
451   // -------------------------
452   list< _QuadFaceGrid > boxFaceContainer;
453   _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
454   if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh,
455                        fBottom, fTop, fFront, fBack, fLeft, fRight))
456     return false;
457
458   // ------------------------------------------
459   // Fill columns of nodes with existing nodes
460   // ------------------------------------------
461
462   // let faces load their grids
463   if ( !fBottom->LoadGrid( theMesh )) return error( fBottom->GetError() );
464   if ( !fBack  ->LoadGrid( theMesh )) return error( fBack  ->GetError() );
465   if ( !fLeft  ->LoadGrid( theMesh )) return error( fLeft  ->GetError() );
466   if ( !fFront ->LoadGrid( theMesh )) return error( fFront ->GetError() );
467   if ( !fRight ->LoadGrid( theMesh )) return error( fRight ->GetError() );
468   if ( !fTop   ->LoadGrid( theMesh )) return error( fTop   ->GetError() );
469
470   int x, xSize = fBottom->GetNbHoriSegments(theMesh) + 1, X = xSize - 1;
471   int y, ySize = fBottom->GetNbVertSegments(theMesh) + 1, Y = ySize - 1;
472   int z, zSize = fFront ->GetNbVertSegments(theMesh) + 1, Z = zSize - 1;
473   _Indexer colIndex( xSize, ySize );
474   vector< vector< const SMDS_MeshNode* > > columns( colIndex.size() );
475
476   // fill node columns by front and back box sides
477   for ( x = 0; x < xSize; ++x ) {
478     vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( x, 0 )];
479     vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( x, Y )];
480     column0.resize( zSize );
481     column1.resize( zSize );
482     for ( z = 0; z < zSize; ++z ) {
483       column0[ z ] = fFront->GetNode( x, z );
484       column1[ z ] = fBack ->GetNode( x, z );
485     }
486   }
487   // fill node columns by left and right box sides
488   for ( y = 1; y < ySize-1; ++y ) {
489     vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( 0, y )];
490     vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( X, y )];
491     column0.resize( zSize );
492     column1.resize( zSize );
493     for ( z = 0; z < zSize; ++z ) {
494       column0[ z ] = fLeft ->GetNode( y, z );
495       column1[ z ] = fRight->GetNode( y, z );
496     }
497   }
498   // get nodes from top and bottom box sides
499   for ( x = 1; x < xSize-1; ++x ) {
500     for ( y = 1; y < ySize-1; ++y ) {
501       vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
502       column.resize( zSize );
503       column.front() = fBottom->GetNode( x, y );
504       column.back()  = fTop   ->GetNode( x, y );
505     }
506   }
507
508   // ----------------------------
509   // Add internal nodes of a box
510   // ----------------------------
511   // projection points of internal nodes on box sub-shapes by which
512   // coordinates of internal nodes are computed
513   vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
514
515   // projections on vertices are constant
516   pointsOnShapes[ SMESH_Block::ID_V000 ] = fBottom->GetXYZ( 0, 0 );
517   pointsOnShapes[ SMESH_Block::ID_V100 ] = fBottom->GetXYZ( X, 0 );
518   pointsOnShapes[ SMESH_Block::ID_V010 ] = fBottom->GetXYZ( 0, Y );
519   pointsOnShapes[ SMESH_Block::ID_V110 ] = fBottom->GetXYZ( X, Y );
520   pointsOnShapes[ SMESH_Block::ID_V001 ] = fTop->GetXYZ( 0, 0 );
521   pointsOnShapes[ SMESH_Block::ID_V101 ] = fTop->GetXYZ( X, 0 );
522   pointsOnShapes[ SMESH_Block::ID_V011 ] = fTop->GetXYZ( 0, Y );
523   pointsOnShapes[ SMESH_Block::ID_V111 ] = fTop->GetXYZ( X, Y );
524
525   for ( x = 1; x < xSize-1; ++x )
526   {
527     gp_XYZ params; // normalized parameters of internal node within a unit box
528     params.SetCoord( 1, x / double(X) );
529     for ( y = 1; y < ySize-1; ++y )
530     {
531       params.SetCoord( 2, y / double(Y) );
532       // column to fill during z loop
533       vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
534       // points projections on horizontal edges
535       pointsOnShapes[ SMESH_Block::ID_Ex00 ] = fBottom->GetXYZ( x, 0 );
536       pointsOnShapes[ SMESH_Block::ID_Ex10 ] = fBottom->GetXYZ( x, Y );
537       pointsOnShapes[ SMESH_Block::ID_E0y0 ] = fBottom->GetXYZ( 0, y );
538       pointsOnShapes[ SMESH_Block::ID_E1y0 ] = fBottom->GetXYZ( X, y );
539       pointsOnShapes[ SMESH_Block::ID_Ex01 ] = fTop->GetXYZ( x, 0 );
540       pointsOnShapes[ SMESH_Block::ID_Ex11 ] = fTop->GetXYZ( x, Y );
541       pointsOnShapes[ SMESH_Block::ID_E0y1 ] = fTop->GetXYZ( 0, y );
542       pointsOnShapes[ SMESH_Block::ID_E1y1 ] = fTop->GetXYZ( X, y );
543       // points projections on horizontal faces
544       pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = fBottom->GetXYZ( x, y );
545       pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = fTop   ->GetXYZ( x, y );
546       for ( z = 1; z < zSize-1; ++z ) // z loop
547       {
548         params.SetCoord( 3, z / double(Z) );
549         // point projections on vertical edges
550         pointsOnShapes[ SMESH_Block::ID_E00z ] = fFront->GetXYZ( 0, z );    
551         pointsOnShapes[ SMESH_Block::ID_E10z ] = fFront->GetXYZ( X, z );    
552         pointsOnShapes[ SMESH_Block::ID_E01z ] = fBack->GetXYZ( 0, z );    
553         pointsOnShapes[ SMESH_Block::ID_E11z ] = fBack->GetXYZ( X, z );
554         // point projections on vertical faces
555         pointsOnShapes[ SMESH_Block::ID_Fx0z ] = fFront->GetXYZ( x, z );    
556         pointsOnShapes[ SMESH_Block::ID_Fx1z ] = fBack ->GetXYZ( x, z );    
557         pointsOnShapes[ SMESH_Block::ID_F0yz ] = fLeft ->GetXYZ( y, z );    
558         pointsOnShapes[ SMESH_Block::ID_F1yz ] = fRight->GetXYZ( y, z );
559
560         // compute internal node coordinates
561         gp_XYZ coords;
562         SMESH_Block::ShellPoint( params, pointsOnShapes, coords );
563         column[ z ] = helper.AddNode( coords.X(), coords.Y(), coords.Z() );
564
565 #ifdef DEB_GRID
566         // debug
567         //cout << "----------------------------------------------------------------------"<<endl;
568         //for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id)
569         //{
570         //  gp_XYZ p = pointsOnShapes[ id ];
571         //  SMESH_Block::DumpShapeID( id,cout)<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;
572         //}
573         //cout << "Params: ( "<< params.X()<<", "<<params.Y()<<", "<<params.Z()<<" )"<<endl;
574         //cout << "coords: ( "<< coords.X()<<", "<<coords.Y()<<", "<<coords.Z()<<" )"<<endl;
575 #endif
576       }
577     }
578   }
579   // faces no more needed, free memory
580   boxFaceContainer.clear();
581
582   // ----------------
583   // Add hexahedrons
584   // ----------------
585   for ( x = 0; x < xSize-1; ++x ) {
586     for ( y = 0; y < ySize-1; ++y ) {
587       vector< const SMDS_MeshNode* >& col00 = columns[ colIndex( x, y )];
588       vector< const SMDS_MeshNode* >& col10 = columns[ colIndex( x+1, y )];
589       vector< const SMDS_MeshNode* >& col01 = columns[ colIndex( x, y+1 )];
590       vector< const SMDS_MeshNode* >& col11 = columns[ colIndex( x+1, y+1 )];
591       for ( z = 0; z < zSize-1; ++z )
592       {
593         // bottom face normal of a hexa mush point outside the volume
594         helper.AddVolume(col00[z],   col01[z],   col11[z],   col10[z],
595                          col00[z+1], col01[z+1], col11[z+1], col10[z+1]);
596       }
597     }
598   }
599   return true;
600 }
601
602 //================================================================================
603 /*!
604  *  Evaluate
605  */
606 //================================================================================
607
608 bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh&         theMesh,
609                                            const TopoDS_Shape& theShape,
610                                            MapShapeNbElems&    aResMap)
611 {
612   // -------------------------
613   // Try to find 6 side faces
614   // -------------------------
615   list< _QuadFaceGrid > boxFaceContainer;
616   _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
617   if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh,
618                        fBottom, fTop, fFront, fBack, fLeft, fRight))
619     return false;
620
621   // Find a less complex side
622   _QuadFaceGrid * lessComplexSide = & boxFaceContainer.front();
623   list< _QuadFaceGrid >::iterator face = boxFaceContainer.begin();
624   for ( ++face; face != boxFaceContainer.end() && lessComplexSide->IsComplex(); ++face )
625     if ( face->NbChildren() < lessComplexSide->NbChildren() )
626       lessComplexSide = & *face;
627
628   // Get an 1D size of lessComplexSide
629   int nbSeg1 = 0;
630   vector<TopoDS_Edge> edges;
631   if ( !lessComplexSide->GetHoriEdges(edges) )
632     return false;
633   for ( size_t i = 0; i < edges.size(); ++i )
634   {
635     const vector<int>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
636     if ( !nbElems.empty() )
637       nbSeg1 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
638   }
639
640   // Get an 1D size of a box side ortogonal to lessComplexSide
641   int nbSeg2 = 0;
642   _QuadFaceGrid* ortoSide =
643     lessComplexSide->FindAdjacentForSide( Q_LEFT, boxFaceContainer, B_UNDEFINED );
644   edges.clear();
645   if ( !ortoSide || !ortoSide->GetHoriEdges(edges) ) return false;
646   for ( size_t i = 0; i < edges.size(); ++i )
647   {
648     const vector<int>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
649     if ( !nbElems.empty() )
650       nbSeg2 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
651   }
652
653   // Get an 2D size of a box side ortogonal to lessComplexSide
654   int nbFaces = 0, nbQuadFace = 0;
655   list< TopoDS_Face > sideFaces;
656   if ( ortoSide->IsComplex() )
657     for ( _QuadFaceGrid::TChildIterator child = ortoSide->GetChildren(); child.more(); )
658       sideFaces.push_back( child.next().GetFace() );
659   else
660     sideFaces.push_back( ortoSide->GetFace() );
661   //
662   list< TopoDS_Face >::iterator f = sideFaces.begin();
663   for ( ; f != sideFaces.end(); ++f )
664   {
665     const vector<int>& nbElems = aResMap[ theMesh.GetSubMesh( *f )];
666     if ( !nbElems.empty() )
667     {
668       nbFaces    = nbElems[ SMDSEntity_Quadrangle ];
669       nbQuadFace = nbElems[ SMDSEntity_Quad_Quadrangle ];
670     }
671   }
672
673   // Fill nb of elements
674   vector<int> aResVec(SMDSEntity_Last,0);
675   int nbSeg3 = ( nbFaces + nbQuadFace ) / nbSeg2;
676   aResVec[SMDSEntity_Node]       = (nbSeg1-1) * (nbSeg2-1) * (nbSeg3-1);
677   aResVec[SMDSEntity_Hexa]       = nbSeg1 * nbFaces;
678   aResVec[SMDSEntity_Quad_Hexa]  = nbSeg1 * nbQuadFace;
679
680   aResMap.insert( make_pair( theMesh.GetSubMesh(theShape), aResVec ));
681
682   return true;
683 }
684
685
686 //================================================================================
687 /*!
688  * \brief constructor of non-initialized _QuadFaceGrid
689  */
690 //================================================================================
691
692 _QuadFaceGrid::_QuadFaceGrid():
693   myReverse(false), myRightBrother(0), myUpBrother(0), myIndexer(0,0), myID(B_UNDEFINED)
694 {
695 }
696
697 //================================================================================
698 /*!
699  * \brief Initialization
700  */
701 //================================================================================
702
703 bool _QuadFaceGrid::Init(const TopoDS_Face& f, SMESH_Mesh& mesh)
704 {
705   myFace         = f;
706   mySides        = _FaceSide();
707   myReverse      = false;
708   myLeftBottomChild = myRightBrother = myUpBrother = 0;
709   myChildren.clear();
710   myGrid.clear();
711   //if ( myFace.Orientation() != TopAbs_FORWARD )
712     //myFace.Reverse();
713
714   list< TopoDS_Edge > edges;
715   list< int > nbEdgesInWire;
716   int nbWire = SMESH_Block::GetOrderedEdges (myFace, edges, nbEdgesInWire);
717   if ( nbWire != 1 )
718     return false;
719
720   list< TopoDS_Edge >::iterator edgeIt = edges.begin();
721   if ( nbEdgesInWire.front() == 4 ) // exactly 4 edges
722   {
723     for ( ; edgeIt != edges.end(); ++edgeIt )
724       mySides.AppendSide( _FaceSide( *edgeIt ));
725   }
726   else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
727     list< TopoDS_Edge > sideEdges;
728     while ( !edges.empty()) {
729       sideEdges.clear();
730       sideEdges.splice( sideEdges.end(), edges, edges.begin());// edges.front()->sideEdges.back()
731       while ( !edges.empty() ) {
732         if ( SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() )) {
733           sideEdges.splice( sideEdges.end(), edges, edges.begin());
734         }
735         else if ( SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() )) {
736           sideEdges.splice( sideEdges.begin(), edges, --edges.end());
737         }
738         else if ( isContinuousMesh( sideEdges.back(), edges.front(), mesh )) {
739           sideEdges.splice( sideEdges.end(), edges, edges.begin());
740         }
741         else if ( isContinuousMesh( sideEdges.front(), edges.back(), mesh )) {
742           sideEdges.splice( sideEdges.begin(), edges, --edges.end());
743         }
744         else {
745           break;
746         }
747       }
748       mySides.AppendSide( _FaceSide( sideEdges ));
749     }
750   }
751   if (mySides.size() != 4)
752     return false;
753
754 #ifdef _DEBUG_
755   mySides.GetSide( Q_BOTTOM )->SetID( Q_BOTTOM );
756   mySides.GetSide( Q_RIGHT  )->SetID( Q_RIGHT );
757   mySides.GetSide( Q_TOP    )->SetID( Q_TOP );
758   mySides.GetSide( Q_LEFT   )->SetID( Q_LEFT );
759 #endif
760
761   return true;
762 }
763
764 //================================================================================
765 /*!
766  * \brief Try to unite self with other ordinary face
767  */
768 //================================================================================
769
770 bool _QuadFaceGrid::AddContinuousFace( const _QuadFaceGrid&       other,
771                                        const TopTools_MapOfShape& cornerVertices)
772 {
773   for ( int i = 0; i < 4; ++i )
774   {
775     const _FaceSide& otherSide = other.GetSide( i );
776     int iMyCommon;
777     if ( mySides.Contain( otherSide, &iMyCommon ) ) {
778       // check if normals of two faces are collinear at all vertices of an otherSide
779       const double angleTol = M_PI / 180. / 2.;
780       int iV, nbV = otherSide.NbVertices(), nbCollinear = 0;
781       for ( iV = 0; iV < nbV; ++iV )
782       {
783         TopoDS_Vertex v = otherSide.Vertex( iV );
784         gp_Vec n1, n2;
785         if ( !GetNormal( v, n1 ) || !other.GetNormal( v, n2 ))
786           continue;
787         if ( n1 * n2 < 0 )
788           n1.Reverse();
789         if ( n1.Angle(n2) < angleTol )
790           nbCollinear++;
791         else
792           break;
793       }
794       if ( nbCollinear > 1 || // this face becomes composite if not yet is
795            needContinuationAtSide( iMyCommon, cornerVertices) ||
796            other.needContinuationAtSide( i, cornerVertices ))
797       {
798         DUMP_VERT("Cont 1", mySides.GetSide(iMyCommon)->FirstVertex());
799         DUMP_VERT("Cont 2", mySides.GetSide(iMyCommon)->LastVertex());
800         DUMP_VERT("Cont 3", otherSide.FirstVertex());
801         DUMP_VERT("Cont 4", otherSide.LastVertex());
802         if ( myChildren.empty() ) {
803           myChildren.push_back( *this );
804           myFace.Nullify();
805         }
806
807         // orient new children equally
808         int otherBottomIndex = ( 4 + i - iMyCommon + 2 ) % 4;
809         if ( other.IsComplex() )
810           for ( TChildIterator children = other.GetChildren(); children.more(); ) {
811             myChildren.push_back( children.next() );
812             myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
813           }
814         else {
815           myChildren.push_back( other );
816           myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
817         }
818
819         myLeftBottomChild = 0;
820
821         // collect vertices in mySides
822         if ( other.IsComplex() )
823           for ( TChildIterator children = other.GetChildren(); children.more(); )
824           {
825             const _QuadFaceGrid& child =  children.next();
826             for ( int i = 0; i < 4; ++i )
827               mySides.AppendSide( child.GetSide(i) );
828           }
829         else
830           for ( int i = 0; i < 4; ++i )
831             mySides.AppendSide( other.GetSide(i) );
832
833         return true;
834       }
835     }
836   }
837   return false;
838 }
839
840 //================================================================================
841 /*!
842  * \brief Try to set the side as bottom hirizontal side
843  */
844 //================================================================================
845
846 bool _QuadFaceGrid::SetBottomSide(const _FaceSide& bottom, int* sideIndex)
847 {
848   myLeftBottomChild = myRightBrother = myUpBrother = 0;
849
850   int myBottomIndex;
851   if ( myChildren.empty() )
852   {
853     if ( mySides.Contain( bottom, &myBottomIndex )) {
854       mySides.SetBottomSide( myBottomIndex );
855       if ( sideIndex )
856         *sideIndex = myBottomIndex;
857       return true;
858     }
859   }
860   else
861   {
862     TChildren::iterator childFace = myChildren.begin(), childEnd = myChildren.end();
863     for ( ; childFace != childEnd; ++childFace )
864     {
865       if ( childFace->SetBottomSide( bottom, &myBottomIndex ))
866       {
867         TChildren::iterator orientedCild = childFace;
868         for ( childFace = myChildren.begin(); childFace != childEnd; ++childFace ) {
869           if ( childFace != orientedCild )
870             childFace->SetBottomSide( childFace->GetSide( myBottomIndex ));
871         }
872         if ( sideIndex )
873           *sideIndex = myBottomIndex;
874         return true;
875       }
876     }
877   }
878   return false;
879 }
880
881 //================================================================================
882 /*!
883  * \brief Return face adjacent to i-th side of this face, (0<i<4)
884  */
885 //================================================================================
886
887 _QuadFaceGrid* _QuadFaceGrid::FindAdjacentForSide(int                  i,
888                                                   list<_QuadFaceGrid>& faces,
889                                                   EBoxSides            id) const
890 {
891   const _FaceSide & iSide = GetSide( i );
892   list< _QuadFaceGrid >::iterator boxFace = faces.begin();
893   for ( ; boxFace != faces.end(); ++boxFace )
894   {
895     _QuadFaceGrid* f  = & (*boxFace);
896     if ( f != this && f->SetBottomSide( iSide ))
897       return f->SetID( id ), f;
898   }
899   return (_QuadFaceGrid*) 0;
900 }
901
902 //================================================================================
903 /*!
904  * \brief Return i-th side
905  */
906 //================================================================================
907
908 const _FaceSide& _QuadFaceGrid::GetSide(int i) const
909 {
910   if ( myChildren.empty() )
911     return *mySides.GetSide(i);
912
913   _QuadFaceGrid* me = const_cast<_QuadFaceGrid*>(this);
914   if ( !me->locateChildren() || !myLeftBottomChild )
915     return *mySides.GetSide(i);
916
917   const _QuadFaceGrid* child = myLeftBottomChild;
918   switch ( i ){
919   case Q_BOTTOM:
920   case Q_LEFT:
921     break;
922   case Q_RIGHT:
923     while ( child->myRightBrother )
924       child = child->myRightBrother;
925     break;
926   case Q_TOP:
927     while ( child->myUpBrother )
928       child = child->myUpBrother;
929     break;
930   default: ;
931   }
932   return child->GetSide( i );
933 }
934
935 //================================================================================
936 /*!
937  * \brief Reverse edges in order to have them oriented along axes of the unit box
938  */
939 //================================================================================
940
941 void _QuadFaceGrid::ReverseEdges(/*int e1, int e2*/)
942 {
943   myReverse = !myReverse;
944
945 // #ifdef DEB_FACES
946 //   if ( !myFace.IsNull() )
947 //     TopAbs::Print(myFace.Orientation(), cout);
948 // #endif
949
950   if ( myChildren.empty() )
951   {
952 //     mySides.GetSide( e1 )->Reverse();
953 //     mySides.GetSide( e2 )->Reverse();
954     DumpVertices();
955   }
956   else
957   {
958     DumpVertices();
959     TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
960     for ( ; child != childEnd; ++child )
961       child->ReverseEdges( /*e1, e2*/ );
962   }
963 }
964
965 //================================================================================
966 /*!
967  * \brief Load nodes of a mesh
968  */
969 //================================================================================
970
971 bool _QuadFaceGrid::LoadGrid( SMESH_Mesh& mesh )
972 {
973   if ( !myChildren.empty() )
974   {
975     // Let child faces load their grids
976     TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
977     for ( ; child != childEnd; ++child ) {
978       child->SetID( myID );
979       if ( !child->LoadGrid( mesh ) )
980         return error( child->GetError() );
981     }
982     // Fill myGrid with nodes of patches
983     return loadCompositeGrid( mesh );
984   }
985
986   // ---------------------------------------
987   // Fill myGrid with nodes bound to myFace
988   // ---------------------------------------
989
990   if ( !myGrid.empty() )
991     return true;
992
993   SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace )->GetSubMeshDS();
994   // check that all faces are quadrangular
995   SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
996   while ( fIt->more() )
997     if ( fIt->next()->NbNodes() % 4 > 0 )
998       return error("Non-quadrangular mesh faces are not allowed on sides of a composite block");
999   
1000   myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
1001   myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT   )->GetNbSegments( mesh );
1002
1003   myGrid.resize( myIndexer.size() );
1004
1005   // strore nodes bound to the bottom edge
1006   mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse );
1007
1008   // store the rest nodes row by row
1009
1010   const SMDS_MeshNode* dummy = mesh.GetMeshDS()->AddNode(0,0,0);
1011   const SMDS_MeshElement* firstQuad = dummy; // most left face above the last row of found nodes
1012   
1013   int nbFoundNodes = myIndexer._xSize;
1014   while ( nbFoundNodes != myGrid.size() )
1015   {
1016     // first and last nodes of the last filled row of nodes
1017     const SMDS_MeshNode* n1down = myGrid[ nbFoundNodes - myIndexer._xSize ];
1018     const SMDS_MeshNode* n2down = myGrid[ nbFoundNodes - myIndexer._xSize + 1];
1019     const SMDS_MeshNode* n1downLast = myGrid[ nbFoundNodes-1 ];
1020
1021     // find the first face above the row by the first two left nodes
1022     //
1023     // n1up     n2up
1024     //     o---o
1025     //     |   |
1026     //     o---o  o  o  o  o
1027     //n1down    n2down
1028     //
1029     TIDSortedElemSet emptySet, avoidSet;
1030     avoidSet.insert( firstQuad );
1031     firstQuad = SMESH_MeshAlgos::FindFaceInSet( n1down, n2down, emptySet, avoidSet);
1032     while ( firstQuad && !faceSubMesh->Contains( firstQuad )) {
1033       avoidSet.insert( firstQuad );
1034       firstQuad = SMESH_MeshAlgos::FindFaceInSet( n1down, n2down, emptySet, avoidSet);
1035     }
1036     if ( !firstQuad || !faceSubMesh->Contains( firstQuad ))
1037       return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1038
1039     // find the node of quad bound to the left geom edge
1040     int i2down = firstQuad->GetNodeIndex( n2down );
1041     const SMDS_MeshNode* n1up = firstQuad->GetNode(( i2down+2 ) % 4 );
1042     myGrid[ nbFoundNodes++ ] = n1up;
1043     // the 4-the node of the first quad
1044     int i1down = firstQuad->GetNodeIndex( n1down );
1045     const SMDS_MeshNode* n2up = firstQuad->GetNode(( i1down+2 ) % 4 );
1046     myGrid[ nbFoundNodes++ ] = n2up;
1047
1048     n1down = n2down;
1049     n1up   = n2up;
1050     const SMDS_MeshElement* quad = firstQuad;
1051
1052     // find the rest nodes by remaining faces above the row
1053     //
1054     //             n1up
1055     //     o---o--o
1056     //     |   |  | ->
1057     //     o---o--o  o  o  o
1058     //                      n1downLast
1059     //
1060     while ( n1down != n1downLast )
1061     {
1062       // next face
1063       avoidSet.clear(); avoidSet.insert( quad );
1064       quad = SMESH_MeshAlgos::FindFaceInSet( n1down, n1up, emptySet, avoidSet );
1065       if ( !quad || quad->NbNodes() % 4 > 0)
1066         return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1067
1068       // next node
1069       if ( quad->GetNode( i1down ) != n1down ) // check already found index
1070         i1down = quad->GetNodeIndex( n1down );
1071       n2up = quad->GetNode(( i1down+2 ) % 4 );
1072       myGrid[ nbFoundNodes++ ] = n2up;
1073
1074       n1down = myGrid[ nbFoundNodes - myIndexer._xSize - 1 ];
1075       n1up   = n2up;
1076     }
1077   }
1078   mesh.GetMeshDS()->RemoveNode(dummy);
1079   DumpGrid(); // debug
1080
1081   return true;
1082 }
1083
1084 //================================================================================
1085 /*!
1086  * \brief Find out mutual location of children: find their right and up brothers
1087  */
1088 //================================================================================
1089
1090 bool _QuadFaceGrid::locateChildren()
1091 {
1092   if ( myLeftBottomChild )
1093     return true;
1094
1095   TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1096
1097   // find a child sharing it's first bottom vertex with no other brother
1098   myLeftBottomChild = 0;
1099   for ( ; !myLeftBottomChild && child != childEnd; ++child )
1100   {
1101     TopoDS_Vertex leftVertex = child->GetSide( Q_BOTTOM ).FirstVertex();
1102     bool sharedVertex = false;
1103     TChildren::iterator otherChild = myChildren.begin();
1104     for ( ; otherChild != childEnd && !sharedVertex; ++otherChild )
1105       if ( otherChild != child )
1106         sharedVertex = otherChild->mySides.Contain( leftVertex );
1107     if ( !sharedVertex ) {
1108       myLeftBottomChild = & (*child);
1109       DUMP_VERT("0 left bottom Vertex: ",leftVertex );
1110     }
1111   }
1112   if (!myLeftBottomChild)
1113     return error(ERR_LI("Error in locateChildren()"));
1114
1115   set< _QuadFaceGrid* > notLocatedChilren;
1116   for (child = myChildren.begin() ; child != childEnd; ++child )
1117     notLocatedChilren.insert( & (*child));
1118
1119   // connect myLeftBottomChild to it's right and upper brothers
1120   notLocatedChilren.erase( myLeftBottomChild );
1121   myLeftBottomChild->setBrothers( notLocatedChilren );
1122   if ( !notLocatedChilren.empty() )
1123     return error(ERR_LI("Error in locateChildren()"));
1124
1125   return true;
1126 }
1127
1128 //================================================================================
1129 /*!
1130  * \brief Checks structure of a quadrangular mesh at the common VERTEX of two EDGEs.
1131  *        Returns true if there are two quadrangles near the VERTEX.
1132  */
1133 //================================================================================
1134
1135 bool _QuadFaceGrid::isContinuousMesh(TopoDS_Edge E1, TopoDS_Edge E2, SMESH_Mesh& mesh) const
1136 {
1137   if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
1138     E1.Orientation( TopAbs_FORWARD );
1139   if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
1140     E2.Orientation( TopAbs_FORWARD );
1141
1142   TopoDS_Vertex V;
1143   if ( !TopExp::CommonVertex( E1, E2, V )) return false;
1144
1145   const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
1146   if ( !n ) return false;
1147
1148   SMESHDS_SubMesh* sm = mesh.GetSubMesh( myFace )->GetSubMeshDS();
1149   if ( !sm ) return false;
1150
1151   int nbQuads = 0;
1152   SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
1153   while ( fIt->more() )
1154   {
1155     const SMDS_MeshElement* f = fIt->next();
1156     if ( !sm->Contains( f )) continue; 
1157
1158     if ( f->NbCornerNodes() == 4 )
1159       ++nbQuads;
1160     else
1161       return false;
1162   }
1163   return nbQuads == 2;
1164 }
1165
1166 //================================================================================
1167 /*!
1168  * \brief Checks if a continuation FACE is needed at a given side according to
1169  *        presence of corner VERTEXes
1170  */
1171 //================================================================================
1172
1173 bool _QuadFaceGrid::needContinuationAtSide( int                        iSide,
1174                                             const TopTools_MapOfShape& cornerVertices ) const
1175 {
1176   if ( cornerVertices.IsEmpty() )
1177     return false;
1178
1179   // current solution is rough. Take more care of composite sides!
1180
1181   // check presence of corners at iSide
1182   const _FaceSide* side = mySides.GetSide( iSide );
1183   if ( !side ) return false;
1184   int nbCorners = side->NbCommonVertices( cornerVertices );
1185   if ( nbCorners > 0 )
1186     return false;
1187
1188   // check presence of corners at other sides
1189   nbCorners = mySides.NbCommonVertices( cornerVertices );
1190
1191   return ( 0 < nbCorners && nbCorners <= 2 ); // if nbCorners == 2 additional check is needed!!!
1192 }
1193
1194 //================================================================================
1195 /*!
1196  * \brief Fill myGrid with nodes of patches
1197  */
1198 //================================================================================
1199
1200 bool _QuadFaceGrid::loadCompositeGrid(SMESH_Mesh& mesh)
1201 {
1202   // Find out mutual location of children: find their right and up brothers
1203   if ( !locateChildren() )
1204     return false;
1205
1206   // Load nodes according to mutual location of children
1207
1208   // grid size
1209   myIndexer._xSize = 1 + myLeftBottomChild->GetNbHoriSegments(mesh, /*withBrothers=*/true);
1210   myIndexer._ySize = 1 + myLeftBottomChild->GetNbVertSegments(mesh, /*withBrothers=*/true);
1211
1212   myGrid.resize( myIndexer.size() );
1213
1214   int fromX = myReverse ? myIndexer._xSize : 0;
1215   if (!myLeftBottomChild->fillGrid( mesh, myGrid, myIndexer, fromX, 0 ))
1216     return error( myLeftBottomChild->GetError() );
1217
1218   DumpGrid();
1219
1220   return true;
1221 }
1222
1223 //================================================================================
1224 /*!
1225  * \brief Find right an upper brothers among notLocatedBrothers
1226  */
1227 //================================================================================
1228
1229 void _QuadFaceGrid::setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers )
1230 {
1231   if ( !notLocatedBrothers.empty() )
1232   {
1233     // find right brother
1234     TopoDS_Vertex rightVertex = GetSide( Q_BOTTOM ).LastVertex();
1235     DUMP_VERT("1 right bottom Vertex: ",rightVertex );
1236     set< _QuadFaceGrid* >::iterator brIt, brEnd = notLocatedBrothers.end();
1237     for ( brIt = notLocatedBrothers.begin(); brIt != brEnd; ++brIt )
1238     {
1239       _QuadFaceGrid* brother = *brIt;
1240       TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1241       DUMP_VERT( "brother left bottom: ", brotherLeftVertex );
1242       if ( rightVertex.IsSame( brotherLeftVertex )) {
1243         myRightBrother = brother;
1244         notLocatedBrothers.erase( brIt );
1245         break;
1246       }
1247     }
1248     // find upper brother
1249     TopoDS_Vertex upVertex = GetSide( Q_LEFT ).FirstVertex();
1250     DUMP_VERT("1 left up Vertex: ",upVertex);
1251     brIt = notLocatedBrothers.begin(), brEnd = notLocatedBrothers.end();
1252     for ( ; brIt != brEnd; ++brIt )
1253     {
1254       _QuadFaceGrid* brother = *brIt;
1255       TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1256       DUMP_VERT("brother left bottom: ", brotherLeftVertex);
1257       if ( upVertex.IsSame( brotherLeftVertex )) {
1258         myUpBrother = brother;
1259         notLocatedBrothers.erase( myUpBrother );
1260         break;
1261       }
1262     }
1263     // recursive call
1264     if ( myRightBrother )
1265       myRightBrother->setBrothers( notLocatedBrothers );
1266     if ( myUpBrother )
1267       myUpBrother->setBrothers( notLocatedBrothers );
1268   }
1269 }
1270
1271 //================================================================================
1272 /*!
1273  * \brief Store nodes of a simple face into grid starting from (x,y) position
1274  */
1275 //================================================================================
1276
1277 bool _QuadFaceGrid::fillGrid(SMESH_Mesh&                    theMesh,
1278                              vector<const SMDS_MeshNode*> & theGrid,
1279                              const _Indexer&                theIndexer,
1280                              int                            theX,
1281                              int                            theY)
1282 {
1283   if ( myGrid.empty() && !LoadGrid( theMesh ))
1284     return false;
1285
1286   // store my own grid in the global grid
1287
1288   int fromX = myReverse ? theX - myIndexer._xSize: theX;
1289
1290   for ( int i = 0, x = fromX; i < myIndexer._xSize; ++i, ++x )
1291     for ( int j = 0, y = theY; j < myIndexer._ySize; ++j, ++y )
1292       theGrid[ theIndexer( x, y )] = myGrid[ myIndexer( i, j )];
1293
1294   // store grids of my right and upper brothers
1295
1296   if ( myRightBrother )
1297   {
1298     if ( myReverse )
1299       fromX += 1;
1300     else
1301       fromX += myIndexer._xSize - 1;
1302     if ( !myRightBrother->fillGrid( theMesh, theGrid, theIndexer, fromX, theY ))
1303       return error( myRightBrother->GetError() );
1304   }
1305   if ( myUpBrother )
1306   {
1307     if ( !myUpBrother->fillGrid( theMesh, theGrid, theIndexer,
1308                                  theX, theY + myIndexer._ySize - 1))
1309       return error( myUpBrother->GetError() );
1310   }
1311   return true;
1312 }
1313
1314 //================================================================================
1315 /*!
1316  * \brief Return number of segments on the hirizontal sides
1317  */
1318 //================================================================================
1319
1320 int _QuadFaceGrid::GetNbHoriSegments(SMESH_Mesh& mesh, bool withBrothers) const
1321 {
1322   int nbSegs = 0;
1323   if ( myLeftBottomChild )
1324   {
1325     nbSegs += myLeftBottomChild->GetNbHoriSegments( mesh, true );
1326   }
1327   else
1328   {
1329     nbSegs = mySides.GetSide( Q_BOTTOM )->GetNbSegments(mesh);
1330     if ( withBrothers && myRightBrother )
1331       nbSegs += myRightBrother->GetNbHoriSegments( mesh, withBrothers );
1332   }
1333   return nbSegs;
1334 }
1335
1336 //================================================================================
1337 /*!
1338  * \brief Return number of segments on the vertical sides
1339  */
1340 //================================================================================
1341
1342 int _QuadFaceGrid::GetNbVertSegments(SMESH_Mesh& mesh, bool withBrothers) const
1343 {
1344   int nbSegs = 0;
1345   if ( myLeftBottomChild )
1346   {
1347     nbSegs += myLeftBottomChild->GetNbVertSegments( mesh, true );
1348   }
1349   else
1350   {
1351     nbSegs = mySides.GetSide( Q_LEFT )->GetNbSegments(mesh);
1352     if ( withBrothers && myUpBrother )
1353       nbSegs += myUpBrother->GetNbVertSegments( mesh, withBrothers );
1354   }
1355   return nbSegs;
1356 }
1357
1358 //================================================================================
1359 /*!
1360  * \brief Return edge on the hirizontal bottom sides
1361  */
1362 //================================================================================
1363
1364 int _QuadFaceGrid::GetHoriEdges(vector<TopoDS_Edge> & edges) const
1365 {
1366   if ( myLeftBottomChild )
1367   {
1368     return myLeftBottomChild->GetHoriEdges( edges );
1369   }
1370   else
1371   {
1372     const _FaceSide* bottom  = mySides.GetSide( Q_BOTTOM );
1373     int i = 0;
1374     while ( true ) {
1375       TopoDS_Edge e = bottom->Edge( i++ );
1376       if ( e.IsNull() )
1377         break;
1378       else
1379         edges.push_back( e );
1380     }
1381     if ( myRightBrother )
1382       myRightBrother->GetHoriEdges( edges );
1383   }
1384   return edges.size();
1385 }
1386
1387 //================================================================================
1388 /*!
1389  * \brief Return a node by its position
1390  */
1391 //================================================================================
1392
1393 const SMDS_MeshNode* _QuadFaceGrid::GetNode(int iHori, int iVert) const
1394 {
1395   return myGrid[ myIndexer( iHori, iVert )];
1396 }
1397
1398 //================================================================================
1399 /*!
1400  * \brief Return node coordinates by its position
1401  */
1402 //================================================================================
1403
1404 gp_XYZ _QuadFaceGrid::GetXYZ(int iHori, int iVert) const
1405 {
1406   const SMDS_MeshNode* n = myGrid[ myIndexer( iHori, iVert )];
1407   return gp_XYZ( n->X(), n->Y(), n->Z() );
1408 }
1409
1410 //================================================================================
1411 /*!
1412  * \brief Return normal to the face at vertex v
1413  */
1414 //================================================================================
1415
1416 bool _QuadFaceGrid::GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const
1417 {
1418   if ( myChildren.empty() )
1419   {
1420     if ( mySides.Contain( v )) {
1421       try {
1422         gp_Pnt2d uv = BRep_Tool::Parameters( v, myFace );
1423         BRepAdaptor_Surface surface( myFace );
1424         gp_Pnt p; gp_Vec d1u, d1v;
1425         surface.D1( uv.X(), uv.Y(), p, d1u, d1v );
1426         n = d1u.Crossed( d1v );
1427         return true;
1428       }
1429       catch (Standard_Failure) {
1430         return false;
1431       }
1432     }
1433   }
1434   else
1435   {
1436     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1437     for ( ; child != childEnd; ++child )
1438       if ( child->GetNormal( v, n ))
1439         return true;
1440   }
1441   return false;
1442 }
1443
1444 //================================================================================
1445 /*!
1446  * \brief Dumps coordinates of grid nodes
1447  */
1448 //================================================================================
1449
1450 void _QuadFaceGrid::DumpGrid() const
1451 {
1452 #ifdef DEB_GRID
1453   const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1454   cout << "****** Face " << names[ myID ] << endl;
1455
1456   if ( myChildren.empty() || !myGrid.empty() )
1457   {
1458     cout << "x size: " << myIndexer._xSize << "; y size: " << myIndexer._ySize << endl;
1459     for ( int y = 0; y < myIndexer._ySize; ++y ) {
1460       cout << "-- row " << y << endl;
1461       for ( int x = 0; x < myIndexer._xSize; ++x ) {
1462         const SMDS_MeshNode* n = myGrid[ myIndexer( x, y ) ];
1463         cout << x << " ( " << n->X() << ", " << n->Y() << ", " << n->Z() << " )" << endl;
1464       }
1465     }
1466   }
1467   else
1468   {
1469     cout << "Nb children: " << myChildren.size() << endl;
1470     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1471     for ( int i=0; child != childEnd; ++child, ++i ) {
1472       cout << "   *** SUBFACE " << i+1 << endl;
1473       ((_QuadFaceGrid&)(*child)).SetID( myID );
1474       child->DumpGrid();
1475     }
1476   }
1477 #endif
1478 }
1479
1480 //================================================================================
1481 /*!
1482  * \brief Dump vertices
1483  */
1484 //================================================================================
1485
1486 void _QuadFaceGrid::DumpVertices() const
1487 {
1488 #ifdef DEB_FACES
1489   cout << "****** Face ";
1490   const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1491   if ( myID >= B_BOTTOM && myID < B_BACK )
1492     cout << names[ myID ] << endl;
1493   else
1494     cout << "UNDEFINED" << endl;
1495
1496   if ( myChildren.empty() )
1497   {
1498     for ( int i = 0; i < 4; ++i )
1499     {
1500       cout << "  Side "; mySides.GetSide( i )->Dump();
1501     }
1502   }
1503   else
1504   {
1505     cout << "-- Nb children: " << myChildren.size() << endl;
1506     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1507     for ( int i=0; child != childEnd; ++child, ++i ) {
1508       cout << "   *** SUBFACE " << i+1 << endl;
1509       ((_QuadFaceGrid&)(*child)).SetID( myID );
1510       child->DumpVertices();
1511     }
1512   }
1513 #endif
1514 }
1515
1516 //=======================================================================
1517 //function : _FaceSide
1518 //purpose  : copy constructor
1519 //=======================================================================
1520
1521 _FaceSide::_FaceSide(const _FaceSide& other)
1522 {
1523   myEdge = other.myEdge;
1524   myChildren = other.myChildren;
1525   myNbChildren = other.myNbChildren;
1526   myVertices.Assign( other.myVertices );
1527   myID = other.myID;
1528 }
1529
1530 //================================================================================
1531 /*!
1532  * \brief Construct a face side of one edge
1533  */
1534 //================================================================================
1535
1536 _FaceSide::_FaceSide(const TopoDS_Edge& edge):
1537   myEdge( edge ), myNbChildren(0)
1538 {
1539   if ( !edge.IsNull() )
1540     for ( TopExp_Explorer exp( edge, TopAbs_VERTEX ); exp.More(); exp.Next() )
1541       //myVertices.insert( ptr ( exp.Current() ));
1542       myVertices.Add( exp.Current() );
1543 }
1544
1545 //================================================================================
1546 /*!
1547  * \brief Construct a face side of several edges
1548  */
1549 //================================================================================
1550
1551 _FaceSide::_FaceSide(const list<TopoDS_Edge>& edges):
1552   myNbChildren(0)
1553 {
1554   list<TopoDS_Edge>::const_iterator edge = edges.begin(), eEnd = edges.end();
1555   for ( ; edge != eEnd; ++edge ) {
1556     myChildren.push_back( _FaceSide( *edge ));
1557     myNbChildren++;
1558 //     myVertices.insert( myChildren.back().myVertices.begin(),
1559 //                        myChildren.back().myVertices.end() );
1560     myVertices.Add( myChildren.back().FirstVertex() );
1561     myVertices.Add( myChildren.back().LastVertex() );
1562     myChildren.back().SetID( Q_CHILD ); // not to splice them
1563   }
1564 }
1565
1566 //=======================================================================
1567 //function : GetSide
1568 //purpose  : 
1569 //=======================================================================
1570
1571 _FaceSide* _FaceSide::GetSide(const int i)
1572 {
1573   if ( i >= myNbChildren )
1574     return 0;
1575
1576   list< _FaceSide >::iterator side = myChildren.begin();
1577   if ( i )
1578     std::advance( side, i );
1579   return & (*side);
1580 }
1581
1582 //=======================================================================
1583 //function : GetSide
1584 //purpose  : 
1585 //=======================================================================
1586
1587 const _FaceSide* _FaceSide::GetSide(const int i) const
1588 {
1589   return const_cast< _FaceSide* >(this)->GetSide(i);
1590 }
1591
1592 //=======================================================================
1593 //function : NbVertices
1594 //purpose  : return nb of vertices in the side
1595 //=======================================================================
1596
1597 int _FaceSide::NbVertices() const
1598 {
1599   if ( myChildren.empty() )
1600     return myVertices.Extent();
1601
1602   return myNbChildren + 1;
1603 }
1604
1605 //=======================================================================
1606 //function : NbCommonVertices
1607 //purpose  : Returns number of my vertices common with the given ones
1608 //=======================================================================
1609
1610 int _FaceSide::NbCommonVertices( const TopTools_MapOfShape& VV ) const
1611 {
1612   int nbCommon = 0;
1613   TopTools_MapIteratorOfMapOfShape vIt ( myVertices );
1614   for ( ; vIt.More(); vIt.Next() )
1615     nbCommon += ( VV.Contains( vIt.Key() ));
1616
1617   return nbCommon;
1618 }
1619
1620 //=======================================================================
1621 //function : FirstVertex
1622 //purpose  :
1623 //=======================================================================
1624
1625 TopoDS_Vertex _FaceSide::FirstVertex() const
1626 {
1627   if ( myChildren.empty() )
1628     return TopExp::FirstVertex( myEdge, Standard_True );
1629
1630   return myChildren.front().FirstVertex();
1631 }
1632
1633 //=======================================================================
1634 //function : LastVertex
1635 //purpose  : 
1636 //=======================================================================
1637
1638 TopoDS_Vertex _FaceSide::LastVertex() const
1639 {
1640   if ( myChildren.empty() )
1641     return TopExp::LastVertex( myEdge, Standard_True );
1642
1643   return myChildren.back().LastVertex();
1644 }
1645
1646 //=======================================================================
1647 //function : Vertex
1648 //purpose  : 
1649 //=======================================================================
1650
1651 TopoDS_Vertex _FaceSide::Vertex(int i) const
1652 {
1653   if ( myChildren.empty() )
1654     return i ? LastVertex() : FirstVertex();
1655       
1656   if ( i >= myNbChildren )
1657     return myChildren.back().LastVertex();
1658   
1659   return GetSide(i)->FirstVertex();
1660 }
1661
1662 //================================================================================
1663 /*!
1664  * \brief Return i-the zero-based edge of the side
1665  */
1666 //================================================================================
1667
1668 TopoDS_Edge _FaceSide::Edge(int i) const
1669 {
1670   if ( i == 0 && !myEdge.IsNull() )
1671     return myEdge;
1672
1673   if ( const _FaceSide* iSide = GetSide( i ))
1674     return iSide->myEdge;
1675
1676   return TopoDS_Edge();
1677 }
1678
1679 //=======================================================================
1680 //function : Contain
1681 //purpose  : 
1682 //=======================================================================
1683
1684 bool _FaceSide::Contain( const _FaceSide& side, int* which ) const
1685 {
1686   if ( !which || myChildren.empty() )
1687   {
1688     if ( which )
1689       *which = 0;
1690     int nbCommon = 0;
1691     TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
1692     for ( ; vIt.More(); vIt.Next() )
1693       nbCommon += ( myVertices.Contains( vIt.Key() ));
1694     return (nbCommon > 1);
1695   }
1696   list< _FaceSide >::const_iterator mySide = myChildren.begin(), sideEnd = myChildren.end();
1697   for ( int i = 0; mySide != sideEnd; ++mySide, ++i ) {
1698     if ( mySide->Contain( side )) {
1699       *which = i;
1700       return true;
1701     }
1702   }
1703   return false;
1704 }
1705
1706 //=======================================================================
1707 //function : Contain
1708 //purpose  : 
1709 //=======================================================================
1710
1711 bool _FaceSide::Contain( const TopoDS_Vertex& vertex ) const
1712 {
1713   return myVertices.Contains( vertex );
1714 }
1715
1716 //=======================================================================
1717 //function : AppendSide
1718 //purpose  : 
1719 //=======================================================================
1720
1721 void _FaceSide::AppendSide( const _FaceSide& side )
1722 {
1723   if ( !myEdge.IsNull() )
1724   {
1725     myChildren.push_back( *this );
1726     myNbChildren = 1;
1727     myEdge.Nullify();
1728   }
1729   myChildren.push_back( side );
1730   myNbChildren++;
1731   TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
1732   for ( ; vIt.More(); vIt.Next() )
1733     myVertices.Add( vIt.Key() );
1734
1735   myID = Q_PARENT;
1736   myChildren.back().SetID( EQuadSides( myNbChildren-1 ));
1737 }
1738
1739 //=======================================================================
1740 //function : SetBottomSide
1741 //purpose  : 
1742 //=======================================================================
1743
1744 void _FaceSide::SetBottomSide( int i )
1745 {
1746   if ( i > 0 && myID == Q_PARENT ) {
1747     list< _FaceSide >::iterator sideEnd, side = myChildren.begin();
1748     std::advance( side, i );
1749     myChildren.splice( myChildren.begin(), myChildren, side, myChildren.end() );
1750
1751     side = myChildren.begin(), sideEnd = myChildren.end();
1752     for ( int i = 0; side != sideEnd; ++side, ++i ) {
1753       side->SetID( EQuadSides(i) );
1754       side->SetBottomSide(i);
1755     }
1756   }
1757 }
1758
1759 //=======================================================================
1760 //function : GetNbSegments
1761 //purpose  : 
1762 //=======================================================================
1763
1764 int _FaceSide::GetNbSegments(SMESH_Mesh& mesh) const
1765 {
1766   int nb = 0;
1767   if ( myChildren.empty() )
1768   {
1769     nb = mesh.GetSubMesh(myEdge)->GetSubMeshDS()->NbElements();
1770   }
1771   else
1772   {
1773     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
1774     for ( ; side != sideEnd; ++side )
1775       nb += side->GetNbSegments(mesh);
1776   }
1777   return nb;
1778 }
1779
1780 //=======================================================================
1781 //function : StoreNodes
1782 //purpose  : 
1783 //=======================================================================
1784
1785 bool _FaceSide::StoreNodes(SMESH_Mesh&                   mesh,
1786                            vector<const SMDS_MeshNode*>& myGrid,
1787                            bool                          reverse )
1788 {
1789   list< TopoDS_Edge > edges;
1790   if ( myChildren.empty() )
1791   {
1792     edges.push_back( myEdge );
1793   }
1794   else
1795   {
1796     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
1797     for ( ; side != sideEnd; ++side )
1798       if ( reverse )
1799         edges.push_front( side->myEdge );
1800       else
1801         edges.push_back ( side->myEdge );
1802   }
1803   int nbNodes = 0;
1804   list< TopoDS_Edge >::iterator edge = edges.begin(), eEnd = edges.end();
1805   for ( ; edge != eEnd; ++edge )
1806   {
1807     map< double, const SMDS_MeshNode* > nodes;
1808     bool ok = SMESH_Algo::GetSortedNodesOnEdge( mesh.GetMeshDS(),
1809                                                 *edge,
1810                                                 /*ignoreMediumNodes=*/true,
1811                                                 nodes);
1812     if ( !ok ) return false;
1813
1814     bool forward = ( edge->Orientation() == TopAbs_FORWARD );
1815     if ( reverse ) forward = !forward;
1816     if ( forward )
1817     {
1818       map< double, const SMDS_MeshNode* >::iterator u_node, nEnd = nodes.end();
1819       for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
1820         myGrid[ nbNodes++ ] = u_node->second;
1821     }
1822     else 
1823     {
1824       map< double, const SMDS_MeshNode* >::reverse_iterator u_node, nEnd = nodes.rend();
1825       for ( u_node = nodes.rbegin(); u_node != nEnd; ++u_node )
1826         myGrid[ nbNodes++ ] = u_node->second;
1827     }
1828     nbNodes--; // node on vertex present in two adjacent edges
1829   }
1830   return nbNodes > 0;
1831 }
1832
1833 //=======================================================================
1834 //function : Dump
1835 //purpose  : dump end vertices
1836 //=======================================================================
1837
1838 void _FaceSide::Dump() const
1839 {
1840   if ( myChildren.empty() )
1841   {
1842     const char* sideNames[] = { "Q_BOTTOM", "Q_RIGHT", "Q_TOP", "Q_LEFT", "Q_CHILD", "Q_PARENT" };
1843     if ( myID >= Q_BOTTOM && myID < Q_PARENT )
1844       cout << sideNames[ myID ] << endl;
1845     else
1846       cout << "<UNDEFINED ID>" << endl;
1847     TopoDS_Vertex f = FirstVertex();
1848     TopoDS_Vertex l = LastVertex();
1849     gp_Pnt pf = BRep_Tool::Pnt(f);
1850     gp_Pnt pl = BRep_Tool::Pnt(l);
1851     cout << "\t ( "<< ptr( f ) << " - " << ptr( l )<< " )"
1852          << "\t ( "<< pf.X()<<", "<<pf.Y()<<", "<<pf.Z()<<" ) - "
1853          << " ( "<< pl.X()<<", "<<pl.Y()<<", "<<pl.Z()<<" )"<<endl;
1854   }
1855   else
1856   {
1857     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
1858     for ( ; side != sideEnd; ++side ) {
1859       side->Dump();
1860       cout << "\t";
1861     }
1862   }
1863 }