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