1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SMESH SMESH : implementaion of SMESH idl descriptions
21 // File : StdMeshers_CompositeHexa_3D.cxx
23 // Created : Tue Nov 25 11:04:59 2008
24 // Author : Edward AGAPOV (eap)
26 #include "StdMeshers_CompositeHexa_3D.hxx"
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_MesherHelper.hxx"
36 #include "SMESH_subMesh.hxx"
38 #include <BRepAdaptor_Surface.hxx>
39 #include <BRep_Tool.hxx>
40 #include <Standard_ErrorHandler.hxx>
41 #include <Standard_Failure.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <TopTools_MapIteratorOfMapOfShape.hxx>
44 #include <TopTools_MapOfShape.hxx>
45 #include <TopTools_SequenceOfShape.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Vertex.hxx>
51 #include <gp_Pnt2d.hxx>
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;}
70 #define DUMP_VERT(msg,v)
74 //================================================================================
75 // text for message about an internal error
76 #define ERR_LI(txt) SMESH_Comment(txt) << ":" << __LINE__
78 // order corresponds to right order of edges in CASCADE face
79 enum EQuadSides{ Q_BOTTOM=0, Q_RIGHT, Q_TOP, Q_LEFT, Q_CHILD, Q_PARENT };
81 enum EBoxSides{ B_BOTTOM=0, B_RIGHT, B_TOP, B_LEFT, B_FRONT, B_BACK, B_UNDEFINED };
83 //================================================================================
85 * \brief Convertor of a pair of integers to a sole index
90 _Indexer( int xSize, int ySize ): _xSize(xSize), _ySize(ySize) {}
91 int size() const { return _xSize * _ySize; }
92 int operator()(const int x, const int y) const { return y * _xSize + x; }
95 //================================================================================
97 * \brief Wrapper of a composite or an ordinary edge.
102 _FaceSide(const _FaceSide& other);
103 _FaceSide(const TopoDS_Edge& edge=TopoDS_Edge());
104 _FaceSide(const list<TopoDS_Edge>& edges);
105 _FaceSide* GetSide(const int i);
106 const _FaceSide* GetSide(const int i) const;
107 int size() { return myChildren.size(); }
108 int NbVertices() const;
109 TopoDS_Vertex FirstVertex() const;
110 TopoDS_Vertex LastVertex() const;
111 TopoDS_Vertex Vertex(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->(); }
127 list< _FaceSide > myChildren;
130 //set<const TopoDS_TShape*> myVertices;
131 TopTools_MapOfShape myVertices;
133 EQuadSides myID; // debug
135 //================================================================================
137 * \brief Class corresponding to a meshed composite face of a box.
138 * Provides simplified access to it's sub-mesh data.
142 typedef list< _QuadFaceGrid > TChildren;
146 public: //** Methods to find and orient faces of 6 sides of the box **//
149 bool Init(const TopoDS_Face& f);
151 //!< try to unite self with other face
152 bool AddContinuousFace( const _QuadFaceGrid& f );
154 //!< Try to set the side as bottom hirizontal side
155 bool SetBottomSide(const _FaceSide& side, int* sideIndex=0);
157 //!< Return face adjacent to i-th side of this face
158 _QuadFaceGrid* FindAdjacentForSide(int i, vector<_QuadFaceGrid>& faces) const; // (0<i<4)
160 //!< Reverse edges in order to have the bottom edge going along axes of the unit box
161 void ReverseEdges(/*int e1, int e2*/);
163 bool IsComplex() const { return !myChildren.empty(); }
165 typedef SMDS_SetIterator< const _QuadFaceGrid&, TChildren::const_iterator > TChildIterator;
167 TChildIterator GetChildren() const
168 { return TChildIterator( myChildren.begin(), myChildren.end()); }
170 public: //** Loading and access to mesh **//
172 //!< Load nodes of a mesh
173 bool LoadGrid( SMESH_Mesh& mesh );
175 //!< Return number of segments on the hirizontal sides
176 int GetNbHoriSegments(SMESH_Mesh& mesh, bool withBrothers=false) const;
178 //!< Return number of segments on the vertical sides
179 int GetNbVertSegments(SMESH_Mesh& mesh, bool withBrothers=false) const;
181 //!< Return a node by its position
182 const SMDS_MeshNode* GetNode(int iHori, int iVert) const;
184 //!< Return node coordinates by its position
185 gp_XYZ GetXYZ(int iHori, int iVert) const;
187 public: //** Access to member fields **//
189 //!< Return i-th face side (0<i<4)
190 const _FaceSide& GetSide(int i) const;
192 //!< Return it's face, NULL if it is composite
193 TopoDS_Face GetFace() const { return myFace; }
195 //!< Return normal to the face at vertex v
196 bool GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const;
198 SMESH_ComputeErrorPtr GetError() const { return myError; }
200 void SetID(EBoxSides id) { myID = id; }
202 void DumpGrid() const;
204 void DumpVertices() const;
208 bool error(const std::string& text, int code = COMPERR_ALGO_FAILED)
209 { myError = SMESH_ComputeError::New( code, text ); return false; }
211 bool error(const SMESH_ComputeErrorPtr& err)
212 { myError = err; return ( !myError || myError->IsOK() ); }
214 bool loadCompositeGrid(SMESH_Mesh& mesh);
216 bool fillGrid(SMESH_Mesh& theMesh,
217 vector<const SMDS_MeshNode*> & theGrid,
218 const _Indexer& theIndexer,
222 bool locateChildren();
224 void setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers );
230 TChildren myChildren;
232 _QuadFaceGrid* myLeftBottomChild;
233 _QuadFaceGrid* myRightBrother;
234 _QuadFaceGrid* myUpBrother;
237 vector<const SMDS_MeshNode*> myGrid;
239 SMESH_ComputeErrorPtr myError;
241 EBoxSides myID; // debug
244 //================================================================================
248 //================================================================================
250 StdMeshers_CompositeHexa_3D::StdMeshers_CompositeHexa_3D(int hypId, int studyId, SMESH_Gen* gen)
251 :SMESH_3D_Algo(hypId, studyId, gen)
253 _name = "CompositeHexa_3D";
254 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
257 //================================================================================
259 * \brief always return true
261 //================================================================================
263 bool StdMeshers_CompositeHexa_3D::CheckHypothesis(SMESH_Mesh& aMesh,
264 const TopoDS_Shape& aShape,
265 Hypothesis_Status& aStatus)
271 //================================================================================
273 * \brief Computes hexahedral mesh on a box with composite sides
274 * \param aMesh - mesh to compute
275 * \param aShape - shape to mesh
276 * \retval bool - succes sign
278 //================================================================================
280 bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh& theMesh,
281 const TopoDS_Shape& theShape)
283 SMESH_MesherHelper helper( theMesh );
284 _quadraticMesh = helper.IsQuadraticSubMesh( theShape );
285 helper.SetElementsOnShape( true );
287 // -------------------------
288 // Try to find 6 side faces
289 // -------------------------
290 vector< _QuadFaceGrid > boxFaces; boxFaces.reserve( 6 );
292 int iFace, nbFaces = 0;
293 for ( exp.Init(theShape, TopAbs_FACE); exp.More(); exp.Next(), ++nbFaces )
296 if ( !f.Init( TopoDS::Face( exp.Current() )))
297 return error (COMPERR_BAD_SHAPE);
298 bool isContinuous = false;
299 for ( int i=0; i < boxFaces.size() && !isContinuous; ++i )
300 isContinuous = boxFaces[ i ].AddContinuousFace( f );
302 boxFaces.push_back( f );
304 // Check what we have
305 if ( boxFaces.size() != 6 && nbFaces != 6)
308 SMESH_Comment("Can't find 6 sides of a box. Number of found sides - ")<<boxFaces.size());
310 if ( boxFaces.size() != 6 && nbFaces == 6 ) { // strange ordinary box with continuous faces
311 boxFaces.resize( 6 );
313 for ( exp.Init(theShape, TopAbs_FACE); exp.More(); exp.Next(), ++iFace )
314 boxFaces[ iFace ].Init( TopoDS::Face( exp.Current() ) );
316 // ----------------------------------------
317 // Find out position of faces within a box
318 // ----------------------------------------
320 _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
321 // start from a bottom face
322 fBottom = &boxFaces[0];
323 // find vertical faces
324 fFront = fBottom->FindAdjacentForSide( Q_BOTTOM, boxFaces );
325 fLeft = fBottom->FindAdjacentForSide( Q_RIGHT, boxFaces );
326 fBack = fBottom->FindAdjacentForSide( Q_TOP, boxFaces );
327 fRight = fBottom->FindAdjacentForSide( Q_LEFT, boxFaces );
329 if ( !fFront || !fBack || !fLeft || !fRight )
330 return error(COMPERR_BAD_SHAPE);
333 for ( int i=1; i < boxFaces.size() && !fTop; ++i ) {
334 fTop = & boxFaces[ i ];
335 if ( fTop==fFront || fTop==fLeft || fTop==fBack || fTop==fRight )
338 // set bottom of the top side
339 if ( !fTop->SetBottomSide( fFront->GetSide( Q_TOP ) )) {
340 if ( !fFront->IsComplex() )
341 return error( ERR_LI("Error in StdMeshers_CompositeHexa_3D::Compute()"));
343 _QuadFaceGrid::TChildIterator chIt = fFront->GetChildren();
344 while ( chIt.more() ) {
345 const _QuadFaceGrid& frontChild = chIt.next();
346 if ( fTop->SetBottomSide( frontChild.GetSide( Q_TOP )))
352 return error(COMPERR_BAD_SHAPE);
354 fBottom->SetID( B_BOTTOM );
355 fBack ->SetID( B_BACK );
356 fLeft ->SetID( B_LEFT );
357 fFront ->SetID( B_FRONT );
358 fRight ->SetID( B_RIGHT );
359 fTop ->SetID( B_TOP );
361 // orient bottom egde of faces along axes of the unit box
362 fBottom->ReverseEdges();
363 fBack ->ReverseEdges();
364 fLeft ->ReverseEdges();
366 // ------------------------------------------
367 // Fill columns of nodes with existing nodes
368 // ------------------------------------------
370 // let faces load their grids
371 if ( !fBottom->LoadGrid( theMesh )) return error( fBottom->GetError() );
372 if ( !fBack ->LoadGrid( theMesh )) return error( fBack ->GetError() );
373 if ( !fLeft ->LoadGrid( theMesh )) return error( fLeft ->GetError() );
374 if ( !fFront ->LoadGrid( theMesh )) return error( fFront ->GetError() );
375 if ( !fRight ->LoadGrid( theMesh )) return error( fRight ->GetError() );
376 if ( !fTop ->LoadGrid( theMesh )) return error( fTop ->GetError() );
378 int x, xSize = fBottom->GetNbHoriSegments(theMesh) + 1, X = xSize - 1;
379 int y, ySize = fBottom->GetNbVertSegments(theMesh) + 1, Y = ySize - 1;
380 int z, zSize = fFront ->GetNbVertSegments(theMesh) + 1, Z = zSize - 1;
381 _Indexer colIndex( xSize, ySize );
382 vector< vector< const SMDS_MeshNode* > > columns( colIndex.size() );
384 // fill node columns by front and back box sides
385 for ( x = 0; x < xSize; ++x ) {
386 vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( x, 0 )];
387 vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( x, Y )];
388 column0.resize( zSize );
389 column1.resize( zSize );
390 for ( z = 0; z < zSize; ++z ) {
391 column0[ z ] = fFront->GetNode( x, z );
392 column1[ z ] = fBack ->GetNode( x, z );
395 // fill node columns by left and right box sides
396 for ( y = 1; y < ySize-1; ++y ) {
397 vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( 0, y )];
398 vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( X, y )];
399 column0.resize( zSize );
400 column1.resize( zSize );
401 for ( z = 0; z < zSize; ++z ) {
402 column0[ z ] = fLeft ->GetNode( y, z );
403 column1[ z ] = fRight->GetNode( y, z );
406 // get nodes from top and bottom box sides
407 for ( x = 1; x < xSize-1; ++x ) {
408 for ( y = 1; y < ySize-1; ++y ) {
409 vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
410 column.resize( zSize );
411 column.front() = fBottom->GetNode( x, y );
412 column.back() = fTop ->GetNode( x, y );
416 // ----------------------------
417 // Add internal nodes of a box
418 // ----------------------------
419 // projection points of internal nodes on box subshapes by which
420 // coordinates of internal nodes are computed
421 vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
423 // projections on vertices are constant
424 pointsOnShapes[ SMESH_Block::ID_V000 ] = fBottom->GetXYZ( 0, 0 );
425 pointsOnShapes[ SMESH_Block::ID_V100 ] = fBottom->GetXYZ( X, 0 );
426 pointsOnShapes[ SMESH_Block::ID_V010 ] = fBottom->GetXYZ( 0, Y );
427 pointsOnShapes[ SMESH_Block::ID_V110 ] = fBottom->GetXYZ( X, Y );
428 pointsOnShapes[ SMESH_Block::ID_V001 ] = fTop->GetXYZ( 0, 0 );
429 pointsOnShapes[ SMESH_Block::ID_V101 ] = fTop->GetXYZ( X, 0 );
430 pointsOnShapes[ SMESH_Block::ID_V011 ] = fTop->GetXYZ( 0, Y );
431 pointsOnShapes[ SMESH_Block::ID_V111 ] = fTop->GetXYZ( X, Y );
433 for ( x = 1; x < xSize-1; ++x )
435 gp_XYZ params; // normalized parameters of internal node within a unit box
436 params.SetCoord( 1, x / double(X) );
437 for ( y = 1; y < ySize-1; ++y )
439 params.SetCoord( 2, y / double(Y) );
440 // column to fill during z loop
441 vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
442 // points projections on horizontal edges
443 pointsOnShapes[ SMESH_Block::ID_Ex00 ] = fBottom->GetXYZ( x, 0 );
444 pointsOnShapes[ SMESH_Block::ID_Ex10 ] = fBottom->GetXYZ( x, Y );
445 pointsOnShapes[ SMESH_Block::ID_E0y0 ] = fBottom->GetXYZ( 0, y );
446 pointsOnShapes[ SMESH_Block::ID_E1y0 ] = fBottom->GetXYZ( X, y );
447 pointsOnShapes[ SMESH_Block::ID_Ex01 ] = fTop->GetXYZ( x, 0 );
448 pointsOnShapes[ SMESH_Block::ID_Ex11 ] = fTop->GetXYZ( x, Y );
449 pointsOnShapes[ SMESH_Block::ID_E0y1 ] = fTop->GetXYZ( 0, y );
450 pointsOnShapes[ SMESH_Block::ID_E1y1 ] = fTop->GetXYZ( X, y );
451 // points projections on horizontal faces
452 pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = fBottom->GetXYZ( x, y );
453 pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = fTop ->GetXYZ( x, y );
454 for ( z = 1; z < zSize-1; ++z ) // z loop
456 params.SetCoord( 3, z / double(Z) );
457 // point projections on vertical edges
458 pointsOnShapes[ SMESH_Block::ID_E00z ] = fFront->GetXYZ( 0, z );
459 pointsOnShapes[ SMESH_Block::ID_E10z ] = fFront->GetXYZ( X, z );
460 pointsOnShapes[ SMESH_Block::ID_E01z ] = fBack->GetXYZ( 0, z );
461 pointsOnShapes[ SMESH_Block::ID_E11z ] = fBack->GetXYZ( X, z );
462 // point projections on vertical faces
463 pointsOnShapes[ SMESH_Block::ID_Fx0z ] = fFront->GetXYZ( x, z );
464 pointsOnShapes[ SMESH_Block::ID_Fx1z ] = fBack ->GetXYZ( x, z );
465 pointsOnShapes[ SMESH_Block::ID_F0yz ] = fLeft ->GetXYZ( y, z );
466 pointsOnShapes[ SMESH_Block::ID_F1yz ] = fRight->GetXYZ( y, z );
468 // compute internal node coordinates
470 SMESH_Block::ShellPoint( params, pointsOnShapes, coords );
471 column[ z ] = helper.AddNode( coords.X(), coords.Y(), coords.Z() );
475 //cout << "----------------------------------------------------------------------"<<endl;
476 //for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id)
478 // gp_XYZ p = pointsOnShapes[ id ];
479 // SMESH_Block::DumpShapeID( id,cout)<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;
481 //cout << "Params: ( "<< params.X()<<", "<<params.Y()<<", "<<params.Z()<<" )"<<endl;
482 //cout << "coords: ( "<< coords.X()<<", "<<coords.Y()<<", "<<coords.Z()<<" )"<<endl;
487 // faces no more needed, free memory
493 for ( x = 0; x < xSize-1; ++x ) {
494 for ( y = 0; y < ySize-1; ++y ) {
495 vector< const SMDS_MeshNode* >& col00 = columns[ colIndex( x, y )];
496 vector< const SMDS_MeshNode* >& col10 = columns[ colIndex( x+1, y )];
497 vector< const SMDS_MeshNode* >& col01 = columns[ colIndex( x, y+1 )];
498 vector< const SMDS_MeshNode* >& col11 = columns[ colIndex( x+1, y+1 )];
499 for ( z = 0; z < zSize-1; ++z )
501 // bottom face normal of a hexa mush point outside the volume
502 helper.AddVolume(col00[z], col01[z], col11[z], col10[z],
503 col00[z+1], col01[z+1], col11[z+1], col10[z+1]);
511 //=======================================================================
513 //purpose : auxilary for Evaluate
514 //=======================================================================
515 int GetNb2d(_QuadFaceGrid* QFG, SMESH_Mesh& theMesh,
516 MapShapeNbElems& aResMap)
519 _QuadFaceGrid::TChildIterator aCI = QFG->GetChildren();
520 while( aCI.more() ) {
521 const _QuadFaceGrid& currChild = aCI.next();
522 SMESH_subMesh *sm = theMesh.GetSubMesh(currChild.GetFace());
524 MapShapeNbElemsItr anIt = aResMap.find(sm);
525 if( anIt == aResMap.end() ) continue;
526 std::vector<int> aVec = (*anIt).second;
527 nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
534 //================================================================================
538 //================================================================================
540 bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh& theMesh,
541 const TopoDS_Shape& theShape,
542 MapShapeNbElems& aResMap)
544 SMESH_MesherHelper aTool(theMesh);
545 bool _quadraticMesh = aTool.IsQuadraticSubMesh(theShape);
548 // -------------------------
549 // Try to find 6 side faces
550 // -------------------------
551 vector< _QuadFaceGrid > boxFaces; boxFaces.reserve( 6 );
553 int iFace, nbFaces = 0;
554 for ( exp.Init(theShape, TopAbs_FACE); exp.More(); exp.Next(), ++nbFaces )
557 if ( !f.Init( TopoDS::Face( exp.Current() )))
558 //return error (COMPERR_BAD_SHAPE);
560 bool isContinuous = false;
561 for ( int i=0; i < boxFaces.size() && !isContinuous; ++i )
562 isContinuous = boxFaces[ i ].AddContinuousFace( f );
564 boxFaces.push_back( f );
566 // Check what we have
567 if ( boxFaces.size() != 6 && nbFaces != 6)
569 // (COMPERR_BAD_SHAPE,
570 // SMESH_Comment("Can't find 6 sides of a box. Number of found sides - ")<<boxFaces.size());
573 if ( boxFaces.size() != 6 && nbFaces == 6 ) { // strange ordinary box with continuous faces
574 boxFaces.resize( 6 );
576 for ( exp.Init(theShape, TopAbs_FACE); exp.More(); exp.Next(), ++iFace )
577 boxFaces[ iFace ].Init( TopoDS::Face( exp.Current() ) );
580 // ----------------------------------------
581 // Find out position of faces within a box
582 // ----------------------------------------
584 _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
585 // start from a bottom face
586 fBottom = &boxFaces[0];
587 // find vertical faces
588 fFront = fBottom->FindAdjacentForSide( Q_BOTTOM, boxFaces );
589 fLeft = fBottom->FindAdjacentForSide( Q_RIGHT, boxFaces );
590 fBack = fBottom->FindAdjacentForSide( Q_TOP, boxFaces );
591 fRight = fBottom->FindAdjacentForSide( Q_LEFT, boxFaces );
593 if ( !fFront || !fBack || !fLeft || !fRight )
594 //return error(COMPERR_BAD_SHAPE);
599 for(; i < boxFaces.size() && !fTop; ++i ) {
600 fTop = & boxFaces[ i ];
601 if ( fTop==fFront || fTop==fLeft || fTop==fBack || fTop==fRight )
604 // set bottom of the top side
605 if ( !fTop->SetBottomSide( fFront->GetSide( Q_TOP ) )) {
606 if ( !fFront->IsComplex() )
607 //return error( ERR_LI("Error in StdMeshers_CompositeHexa_3D::Compute()"));
610 _QuadFaceGrid::TChildIterator chIt = fFront->GetChildren();
611 while ( chIt.more() ) {
612 const _QuadFaceGrid& frontChild = chIt.next();
613 if ( fTop->SetBottomSide( frontChild.GetSide( Q_TOP )))
619 //return error(COMPERR_BAD_SHAPE);
623 TopTools_SequenceOfShape BottomFaces;
624 _QuadFaceGrid::TChildIterator aCI = fBottom->GetChildren();
625 while( aCI.more() ) {
626 const _QuadFaceGrid& currChild = aCI.next();
627 BottomFaces.Append(currChild.GetFace());
629 // find boundary edges and internal nodes for bottom face
630 TopTools_SequenceOfShape BndEdges;
632 //TopTools_MapOfShape BndEdges;
633 for(i=1; i<=BottomFaces.Length(); i++) {
634 for (TopExp_Explorer exp(BottomFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
636 SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
638 MapShapeNbElemsItr anIt = aResMap.find(sm);
639 if( anIt == aResMap.end() ) continue;
640 std::vector<int> aVec = (*anIt).second;
641 nb0 = aVec[SMDSEntity_Node];
644 for(; j<=BndEdges.Length(); j++) {
645 if( BndEdges.Value(j) == exp.Current() ) {
646 // internal edge => remove it
652 if( j > BndEdges.Length() ) {
653 BndEdges.Append(exp.Current());
655 //if( BndEdges.Contains(exp.Current()) ) {
656 //BndEdges.Remove( exp.Current() );
659 //BndEdges.Add( exp.Current() );
664 // find number of 1d elems for bottom face
666 for(i=1; i<=BndEdges.Length(); i++) {
667 SMESH_subMesh *sm = theMesh.GetSubMesh(BndEdges.Value(i));
669 MapShapeNbElemsItr anIt = aResMap.find(sm);
670 if( anIt == aResMap.end() ) continue;
671 std::vector<int> aVec = (*anIt).second;
672 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
676 // find number of 2d elems on side faces
678 nb2d += GetNb2d(fFront, theMesh, aResMap);
679 nb2d += GetNb2d(fRight, theMesh, aResMap);
680 nb2d += GetNb2d(fBack, theMesh, aResMap);
681 nb2d += GetNb2d(fLeft, theMesh, aResMap);
683 // find number of 2d elems and nodes on bottom faces
684 int nb0d=0, nb2d_3=0, nb2d_4=0;
685 for(i=1; i<=BottomFaces.Length(); i++) {
686 SMESH_subMesh *sm = theMesh.GetSubMesh(BottomFaces.Value(i));
688 MapShapeNbElemsItr anIt = aResMap.find(sm);
689 if( anIt == aResMap.end() ) continue;
690 std::vector<int> aVec = (*anIt).second;
691 nb0d += aVec[SMDSEntity_Node];
692 nb2d_3 += Max(aVec[SMDSEntity_Triangle], aVec[SMDSEntity_Quad_Triangle]);
693 nb2d_4 += Max(aVec[SMDSEntity_Quadrangle], aVec[SMDSEntity_Quad_Quadrangle]);
698 std::vector<int> aResVec(SMDSEntity_Last);
699 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
701 aResVec[SMDSEntity_Quad_Penta] = nb2d_3 * ( nb2d/nb1d );
702 aResVec[SMDSEntity_Quad_Hexa] = nb2d_4 * ( nb2d/nb1d );
703 aResVec[SMDSEntity_Node] = nb0d * ( 2*nb2d/nb1d - 1 );
706 aResVec[SMDSEntity_Node] = nb0d * ( nb2d/nb1d - 1 );
707 aResVec[SMDSEntity_Penta] = nb2d_3 * ( nb2d/nb1d );
708 aResVec[SMDSEntity_Hexa] = nb2d_4 * ( nb2d/nb1d );
710 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
711 aResMap.insert(std::make_pair(sm,aResVec));
717 //================================================================================
719 * \brief constructor of non-initialized _QuadFaceGrid
721 //================================================================================
723 _QuadFaceGrid::_QuadFaceGrid():
724 myReverse(false), myRightBrother(0), myUpBrother(0), myIndexer(0,0), myID(B_UNDEFINED)
728 //================================================================================
730 * \brief Initialization
732 //================================================================================
734 bool _QuadFaceGrid::Init(const TopoDS_Face& f)
737 mySides = _FaceSide();
739 myLeftBottomChild = myRightBrother = myUpBrother = 0;
742 //if ( myFace.Orientation() != TopAbs_FORWARD )
746 list< TopoDS_Edge > edges;
747 list< int > nbEdgesInWire;
748 int nbWire = SMESH_Block::GetOrderedEdges (myFace, V, edges, nbEdgesInWire);
752 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
753 if ( nbEdgesInWire.front() == 4 ) // exactly 4 edges
755 for ( ; edgeIt != edges.end(); ++edgeIt )
756 mySides.AppendSide( _FaceSide( *edgeIt ));
758 else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
759 list< TopoDS_Edge > sideEdges;
760 while ( !edges.empty()) {
762 sideEdges.splice( sideEdges.end(), edges, edges.begin());// edges.front()->sideEdges.back()
763 while ( !edges.empty() ) {
764 if ( SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() )) {
765 sideEdges.splice( sideEdges.end(), edges, edges.begin());
767 else if ( SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() )) {
768 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
774 mySides.AppendSide( _FaceSide( sideEdges ));
777 if (mySides.size() != 4)
781 mySides.GetSide( Q_BOTTOM )->SetID( Q_BOTTOM );
782 mySides.GetSide( Q_RIGHT )->SetID( Q_RIGHT );
783 mySides.GetSide( Q_TOP )->SetID( Q_TOP );
784 mySides.GetSide( Q_LEFT )->SetID( Q_LEFT );
790 //================================================================================
792 * \brief Try to unite self with other ordinary face
794 //================================================================================
796 bool _QuadFaceGrid::AddContinuousFace( const _QuadFaceGrid& other )
798 for ( int i = 0; i < 4; ++i ) {
799 const _FaceSide& otherSide = other.GetSide( i );
801 if ( mySides.Contain( otherSide, &iMyCommon ) ) {
802 // check if normals of two faces are collinear at all vertices of a otherSide
803 const double angleTol = PI / 180 / 2;
804 int iV, nbV = otherSide.NbVertices(), nbCollinear = 0;
805 for ( iV = 0; iV < nbV; ++iV )
807 TopoDS_Vertex v = otherSide.Vertex( iV );
809 if ( !GetNormal( v, n1 ) || !other.GetNormal( v, n2 ))
813 if ( n1.Angle(n2) < angleTol )
818 if ( nbCollinear > 1 ) { // this face becomes composite if not yet is
819 DUMP_VERT("Cont 1", mySides.GetSide(iMyCommon)->FirstVertex());
820 DUMP_VERT("Cont 2", mySides.GetSide(iMyCommon)->LastVertex());
821 DUMP_VERT("Cont 3", otherSide.FirstVertex());
822 DUMP_VERT("Cont 4", otherSide.LastVertex());
823 if ( myChildren.empty() ) {
824 myChildren.push_back( *this );
827 myChildren.push_back( other );
828 int otherBottomIndex = ( 4 + i - iMyCommon + 2 ) % 4;
829 myChildren.back().SetBottomSide( other.GetSide( otherBottomIndex ));
830 // collect vertices in mySides
831 mySides.AppendSide( other.GetSide(0) );
832 mySides.AppendSide( other.GetSide(1) );
833 mySides.AppendSide( other.GetSide(2) );
834 mySides.AppendSide( other.GetSide(3) );
842 //================================================================================
844 * \brief Try to set the side as bottom hirizontal side
846 //================================================================================
848 bool _QuadFaceGrid::SetBottomSide(const _FaceSide& bottom, int* sideIndex)
850 myLeftBottomChild = myRightBrother = myUpBrother = 0;
853 if ( myChildren.empty() )
855 if ( mySides.Contain( bottom, &myBottomIndex )) {
856 mySides.SetBottomSide( myBottomIndex );
858 *sideIndex = myBottomIndex;
864 TChildren::iterator childFace = myChildren.begin(), childEnd = myChildren.end();
865 for ( ; childFace != childEnd; ++childFace )
867 if ( childFace->SetBottomSide( bottom, &myBottomIndex ))
869 TChildren::iterator orientedCild = childFace;
870 for ( childFace = myChildren.begin(); childFace != childEnd; ++childFace ) {
871 if ( childFace != orientedCild )
872 childFace->SetBottomSide( childFace->GetSide( myBottomIndex ));
875 *sideIndex = myBottomIndex;
883 //================================================================================
885 * \brief Return face adjacent to i-th side of this face, (0<i<4)
887 //================================================================================
889 _QuadFaceGrid* _QuadFaceGrid::FindAdjacentForSide(int i, vector<_QuadFaceGrid>& faces) const
891 for ( int iF = 0; iF < faces.size(); ++iF ) {
892 _QuadFaceGrid* f = &faces[ iF ];
893 if ( f != this && f->SetBottomSide( GetSide( i )))
896 return (_QuadFaceGrid*) 0;
899 //================================================================================
901 * \brief Return i-th side
903 //================================================================================
905 const _FaceSide& _QuadFaceGrid::GetSide(int i) const
907 if ( myChildren.empty() )
908 return *mySides.GetSide(i);
910 _QuadFaceGrid* me = const_cast<_QuadFaceGrid*>(this);
911 if ( !me->locateChildren() || !myLeftBottomChild )
912 return *mySides.GetSide(i);
914 const _QuadFaceGrid* child = myLeftBottomChild;
920 while ( child->myRightBrother )
921 child = child->myRightBrother;
924 while ( child->myUpBrother )
925 child = child->myUpBrother;
929 return child->GetSide( i );
932 //================================================================================
934 * \brief Reverse edges in order to have them oriented along axes of the unit box
936 //================================================================================
938 void _QuadFaceGrid::ReverseEdges(/*int e1, int e2*/)
940 myReverse = !myReverse;
943 // if ( !myFace.IsNull() )
944 // TopAbs::Print(myFace.Orientation(), cout);
947 if ( myChildren.empty() )
949 // mySides.GetSide( e1 )->Reverse();
950 // mySides.GetSide( e2 )->Reverse();
956 TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
957 for ( ; child != childEnd; ++child )
958 child->ReverseEdges( /*e1, e2*/ );
962 //================================================================================
964 * \brief Load nodes of a mesh
966 //================================================================================
968 bool _QuadFaceGrid::LoadGrid( SMESH_Mesh& mesh )
970 if ( !myChildren.empty() )
972 // Let child faces load their grids
973 TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
974 for ( ; child != childEnd; ++child ) {
975 child->SetID( myID );
976 if ( !child->LoadGrid( mesh ) )
977 return error( child->GetError() );
979 // Fill myGrid with nodes of patches
980 return loadCompositeGrid( mesh );
983 // ---------------------------------------
984 // Fill myGrid with nodes bound to myFace
985 // ---------------------------------------
987 if ( !myGrid.empty() )
990 SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace )->GetSubMeshDS();
991 // check that all faces are quadrangular
992 SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
993 while ( fIt->more() )
994 if ( fIt->next()->NbNodes() % 4 > 0 )
995 return error("Non-quadrangular mesh faces are not allowed on sides of a composite block");
997 myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
998 myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT )->GetNbSegments( mesh );
1000 myGrid.resize( myIndexer.size() );
1002 // strore nodes bound to the bottom edge
1003 mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse );
1005 // store the rest nodes row by row
1007 const SMDS_MeshNode* dummy = mesh.GetMeshDS()->AddNode(0,0,0);
1008 const SMDS_MeshElement* firstQuad = dummy; // most left face above the last row of found nodes
1010 int nbFoundNodes = myIndexer._xSize;
1011 while ( nbFoundNodes != myGrid.size() )
1013 // first and last nodes of the last filled row of nodes
1014 const SMDS_MeshNode* n1down = myGrid[ nbFoundNodes - myIndexer._xSize ];
1015 const SMDS_MeshNode* n2down = myGrid[ nbFoundNodes - myIndexer._xSize + 1];
1016 const SMDS_MeshNode* n1downLast = myGrid[ nbFoundNodes-1 ];
1018 // find the first face above the row by the first two left nodes
1026 TIDSortedElemSet emptySet, avoidSet;
1027 avoidSet.insert( firstQuad );
1028 firstQuad = SMESH_MeshEditor::FindFaceInSet( n1down, n2down, emptySet, avoidSet);
1029 while ( firstQuad && !faceSubMesh->Contains( firstQuad )) {
1030 avoidSet.insert( firstQuad );
1031 firstQuad = SMESH_MeshEditor::FindFaceInSet( n1down, n2down, emptySet, avoidSet);
1033 if ( !firstQuad || !faceSubMesh->Contains( firstQuad ))
1034 return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1036 // find the node of quad bound to the left geom edge
1037 int i2down = firstQuad->GetNodeIndex( n2down );
1038 const SMDS_MeshNode* n1up = firstQuad->GetNode(( i2down+2 ) % 4 );
1039 myGrid[ nbFoundNodes++ ] = n1up;
1040 // the 4-the node of the first quad
1041 int i1down = firstQuad->GetNodeIndex( n1down );
1042 const SMDS_MeshNode* n2up = firstQuad->GetNode(( i1down+2 ) % 4 );
1043 myGrid[ nbFoundNodes++ ] = n2up;
1047 const SMDS_MeshElement* quad = firstQuad;
1049 // find the rest nodes by remaining faces above the row
1057 while ( n1down != n1downLast )
1060 avoidSet.clear(); avoidSet.insert( quad );
1061 quad = SMESH_MeshEditor::FindFaceInSet( n1down, n1up, emptySet, avoidSet );
1062 if ( !quad || quad->NbNodes() % 4 > 0)
1063 return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1066 if ( quad->GetNode( i1down ) != n1down ) // check already found index
1067 i1down = quad->GetNodeIndex( n1down );
1068 n2up = quad->GetNode(( i1down+2 ) % 4 );
1069 myGrid[ nbFoundNodes++ ] = n2up;
1071 n1down = myGrid[ nbFoundNodes - myIndexer._xSize - 1 ];
1075 mesh.GetMeshDS()->RemoveNode(dummy);
1076 DumpGrid(); // debug
1081 //================================================================================
1083 * \brief Find out mutual location of children: find their right and up brothers
1085 //================================================================================
1087 bool _QuadFaceGrid::locateChildren()
1089 if ( myLeftBottomChild )
1092 TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1094 // find a child sharing it's first bottom vertex with no other brother
1095 myLeftBottomChild = 0;
1096 for ( ; !myLeftBottomChild && child != childEnd; ++child )
1098 TopoDS_Vertex leftVertex = child->GetSide( Q_BOTTOM ).FirstVertex();
1099 bool sharedVertex = false;
1100 TChildren::iterator otherChild = myChildren.begin();
1101 for ( ; otherChild != childEnd && !sharedVertex; ++otherChild )
1102 if ( otherChild != child )
1103 sharedVertex = otherChild->mySides.Contain( leftVertex );
1104 if ( !sharedVertex ) {
1105 myLeftBottomChild = & (*child);
1106 DUMP_VERT("0 left bottom Vertex: ",leftVertex );
1109 if (!myLeftBottomChild)
1110 return error(ERR_LI("Error in locateChildren()"));
1112 set< _QuadFaceGrid* > notLocatedChilren;
1113 for (child = myChildren.begin() ; child != childEnd; ++child )
1114 notLocatedChilren.insert( & (*child));
1116 // connect myLeftBottomChild to it's right and upper brothers
1117 notLocatedChilren.erase( myLeftBottomChild );
1118 myLeftBottomChild->setBrothers( notLocatedChilren );
1119 if ( !notLocatedChilren.empty() )
1120 return error(ERR_LI("Error in locateChildren()"));
1125 //================================================================================
1127 * \brief Fill myGrid with nodes of patches
1129 //================================================================================
1131 bool _QuadFaceGrid::loadCompositeGrid(SMESH_Mesh& mesh)
1133 // Find out mutual location of children: find their right and up brothers
1134 if ( !locateChildren() )
1137 // Load nodes according to mutual location of children
1140 myIndexer._xSize = 1 + myLeftBottomChild->GetNbHoriSegments(mesh, /*withBrothers=*/true);
1141 myIndexer._ySize = 1 + myLeftBottomChild->GetNbVertSegments(mesh, /*withBrothers=*/true);
1143 myGrid.resize( myIndexer.size() );
1145 int fromX = myReverse ? myIndexer._xSize : 0;
1146 if (!myLeftBottomChild->fillGrid( mesh, myGrid, myIndexer, fromX, 0 ))
1147 return error( myLeftBottomChild->GetError() );
1154 //================================================================================
1156 * \brief Find right an upper brothers among notLocatedBrothers
1158 //================================================================================
1160 void _QuadFaceGrid::setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers )
1162 if ( !notLocatedBrothers.empty() )
1164 // find right brother
1165 TopoDS_Vertex rightVertex = GetSide( Q_BOTTOM ).LastVertex();
1166 DUMP_VERT("1 right bottom Vertex: ",rightVertex );
1167 set< _QuadFaceGrid* >::iterator brIt, brEnd = notLocatedBrothers.end();
1168 for ( brIt = notLocatedBrothers.begin(); !myRightBrother && brIt != brEnd; ++brIt )
1170 _QuadFaceGrid* brother = *brIt;
1171 TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1172 DUMP_VERT( "brother left bottom: ", brotherLeftVertex );
1173 if ( rightVertex.IsSame( brotherLeftVertex )) {
1174 myRightBrother = brother;
1175 notLocatedBrothers.erase( myRightBrother );
1178 // find upper brother
1179 TopoDS_Vertex upVertex = GetSide( Q_LEFT ).FirstVertex();
1180 DUMP_VERT("1 left up Vertex: ",upVertex);
1181 brIt = notLocatedBrothers.begin(), brEnd = notLocatedBrothers.end();
1182 for ( ; !myUpBrother && brIt != brEnd; ++brIt )
1184 _QuadFaceGrid* brother = *brIt;
1185 TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1186 DUMP_VERT("brother left bottom: ", brotherLeftVertex);
1187 if ( upVertex.IsSame( brotherLeftVertex )) {
1188 myUpBrother = brother;
1189 notLocatedBrothers.erase( myUpBrother );
1193 if ( myRightBrother )
1194 myRightBrother->setBrothers( notLocatedBrothers );
1196 myUpBrother->setBrothers( notLocatedBrothers );
1200 //================================================================================
1202 * \brief Store nodes of a simple face into grid starting from (x,y) position
1204 //================================================================================
1206 bool _QuadFaceGrid::fillGrid(SMESH_Mesh& theMesh,
1207 vector<const SMDS_MeshNode*> & theGrid,
1208 const _Indexer& theIndexer,
1212 if ( myGrid.empty() && !LoadGrid( theMesh ))
1215 // store my own grid in the global grid
1217 int fromX = myReverse ? theX - myIndexer._xSize: theX;
1219 for ( int i = 0, x = fromX; i < myIndexer._xSize; ++i, ++x )
1220 for ( int j = 0, y = theY; j < myIndexer._ySize; ++j, ++y )
1221 theGrid[ theIndexer( x, y )] = myGrid[ myIndexer( i, j )];
1223 // store grids of my right and upper brothers
1225 if ( myRightBrother )
1230 fromX += myIndexer._xSize - 1;
1231 if ( !myRightBrother->fillGrid( theMesh, theGrid, theIndexer, fromX, theY ))
1232 return error( myRightBrother->GetError() );
1236 if ( !myUpBrother->fillGrid( theMesh, theGrid, theIndexer,
1237 theX, theY + myIndexer._ySize - 1))
1238 return error( myUpBrother->GetError() );
1243 //================================================================================
1245 * \brief Return number of segments on the hirizontal sides
1247 //================================================================================
1249 int _QuadFaceGrid::GetNbHoriSegments(SMESH_Mesh& mesh, bool withBrothers) const
1252 if ( myLeftBottomChild )
1254 nbSegs += myLeftBottomChild->GetNbHoriSegments( mesh, true );
1258 nbSegs = mySides.GetSide( Q_BOTTOM )->GetNbSegments(mesh);
1259 if ( withBrothers && myRightBrother )
1260 nbSegs += myRightBrother->GetNbHoriSegments( mesh, withBrothers );
1265 //================================================================================
1267 * \brief Return number of segments on the vertical sides
1269 //================================================================================
1271 int _QuadFaceGrid::GetNbVertSegments(SMESH_Mesh& mesh, bool withBrothers) const
1274 if ( myLeftBottomChild )
1276 nbSegs += myLeftBottomChild->GetNbVertSegments( mesh, true );
1280 nbSegs = mySides.GetSide( Q_LEFT )->GetNbSegments(mesh);
1281 if ( withBrothers && myUpBrother )
1282 nbSegs += myUpBrother->GetNbVertSegments( mesh, withBrothers );
1287 //================================================================================
1289 * \brief Return a node by its position
1291 //================================================================================
1293 const SMDS_MeshNode* _QuadFaceGrid::GetNode(int iHori, int iVert) const
1295 return myGrid[ myIndexer( iHori, iVert )];
1298 //================================================================================
1300 * \brief Return node coordinates by its position
1302 //================================================================================
1304 gp_XYZ _QuadFaceGrid::GetXYZ(int iHori, int iVert) const
1306 const SMDS_MeshNode* n = myGrid[ myIndexer( iHori, iVert )];
1307 return gp_XYZ( n->X(), n->Y(), n->Z() );
1310 //================================================================================
1312 * \brief Return normal to the face at vertex v
1314 //================================================================================
1316 bool _QuadFaceGrid::GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const
1318 if ( myChildren.empty() )
1320 if ( mySides.Contain( v )) {
1322 gp_Pnt2d uv = BRep_Tool::Parameters( v, myFace );
1323 BRepAdaptor_Surface surface( myFace );
1324 gp_Pnt p; gp_Vec d1u, d1v;
1325 surface.D1( uv.X(), uv.Y(), p, d1u, d1v );
1326 n = d1u.Crossed( d1v );
1329 catch (Standard_Failure) {
1336 TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1337 for ( ; child != childEnd; ++child )
1338 if ( child->GetNormal( v, n ))
1344 //================================================================================
1346 * \brief Dumps coordinates of grid nodes
1348 //================================================================================
1350 void _QuadFaceGrid::DumpGrid() const
1353 const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1354 cout << "****** Face " << names[ myID ] << endl;
1356 if ( myChildren.empty() || !myGrid.empty() )
1358 cout << "x size: " << myIndexer._xSize << "; y size: " << myIndexer._ySize << endl;
1359 for ( int y = 0; y < myIndexer._ySize; ++y ) {
1360 cout << "-- row " << y << endl;
1361 for ( int x = 0; x < myIndexer._xSize; ++x ) {
1362 const SMDS_MeshNode* n = myGrid[ myIndexer( x, y ) ];
1363 cout << x << " ( " << n->X() << ", " << n->Y() << ", " << n->Z() << " )" << endl;
1369 cout << "Nb children: " << myChildren.size() << endl;
1370 TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1371 for ( int i=0; child != childEnd; ++child, ++i ) {
1372 cout << " *** SUBFACE " << i+1 << endl;
1373 ((_QuadFaceGrid&)(*child)).SetID( myID );
1380 //================================================================================
1382 * \brief Dump vertices
1384 //================================================================================
1386 void _QuadFaceGrid::DumpVertices() const
1389 cout << "****** Face ";
1390 const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1391 if ( myID >= B_BOTTOM && myID < B_BACK )
1392 cout << names[ myID ] << endl;
1394 cout << "UNDEFINED" << endl;
1396 if ( myChildren.empty() )
1398 for ( int i = 0; i < 4; ++i )
1400 cout << " Side "; mySides.GetSide( i )->Dump();
1405 cout << "-- Nb children: " << myChildren.size() << endl;
1406 TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1407 for ( int i=0; child != childEnd; ++child, ++i ) {
1408 cout << " *** SUBFACE " << i+1 << endl;
1409 ((_QuadFaceGrid&)(*child)).SetID( myID );
1410 child->DumpVertices();
1416 //=======================================================================
1417 //function : _FaceSide
1418 //purpose : copy constructor
1419 //=======================================================================
1421 _FaceSide::_FaceSide(const _FaceSide& other)
1423 myEdge = other.myEdge;
1424 myChildren = other.myChildren;
1425 myNbChildren = other.myNbChildren;
1426 myVertices.Assign( other.myVertices );
1430 //================================================================================
1432 * \brief Construct a face side of one edge
1434 //================================================================================
1436 _FaceSide::_FaceSide(const TopoDS_Edge& edge):
1437 myEdge( edge ), myNbChildren(0)
1439 if ( !edge.IsNull() )
1440 for ( TopExp_Explorer exp( edge, TopAbs_VERTEX ); exp.More(); exp.Next() )
1441 //myVertices.insert( ptr ( exp.Current() ));
1442 myVertices.Add( exp.Current() );
1445 //================================================================================
1447 * \brief Construct a face side of several edges
1449 //================================================================================
1451 _FaceSide::_FaceSide(const list<TopoDS_Edge>& edges):
1454 list<TopoDS_Edge>::const_iterator edge = edges.begin(), eEnd = edges.end();
1455 for ( ; edge != eEnd; ++edge ) {
1456 myChildren.push_back( _FaceSide( *edge ));
1458 // myVertices.insert( myChildren.back().myVertices.begin(),
1459 // myChildren.back().myVertices.end() );
1460 myVertices.Add( myChildren.back().FirstVertex() );
1461 myVertices.Add( myChildren.back().LastVertex() );
1462 myChildren.back().SetID( Q_CHILD ); // not to splice them
1466 //=======================================================================
1467 //function : GetSide
1469 //=======================================================================
1471 _FaceSide* _FaceSide::GetSide(const int i)
1473 if ( i >= myNbChildren )
1476 list< _FaceSide >::iterator side = myChildren.begin();
1478 std::advance( side, i );
1482 //=======================================================================
1483 //function : GetSide
1485 //=======================================================================
1487 const _FaceSide* _FaceSide::GetSide(const int i) const
1489 return const_cast< _FaceSide* >(this)->GetSide(i);
1492 //=======================================================================
1493 //function : NbVertices
1494 //purpose : return nb of vertices in the side
1495 //=======================================================================
1497 int _FaceSide::NbVertices() const
1499 if ( myChildren.empty() )
1500 return myVertices.Extent();
1501 // return myVertices.size();
1503 return myNbChildren + 1;
1506 //=======================================================================
1507 //function : FirstVertex
1509 //=======================================================================
1511 TopoDS_Vertex _FaceSide::FirstVertex() const
1513 if ( myChildren.empty() )
1514 return TopExp::FirstVertex( myEdge, Standard_True );
1516 return myChildren.front().FirstVertex();
1519 //=======================================================================
1520 //function : LastVertex
1522 //=======================================================================
1524 TopoDS_Vertex _FaceSide::LastVertex() const
1526 if ( myChildren.empty() )
1527 return TopExp::LastVertex( myEdge, Standard_True );
1529 return myChildren.back().LastVertex();
1532 //=======================================================================
1535 //=======================================================================
1537 TopoDS_Vertex _FaceSide::Vertex(int i) const
1539 if ( myChildren.empty() )
1540 return i ? LastVertex() : FirstVertex();
1542 if ( i >= myNbChildren )
1543 return myChildren.back().LastVertex();
1545 return GetSide(i)->FirstVertex();
1548 //=======================================================================
1549 //function : Contain
1551 //=======================================================================
1553 bool _FaceSide::Contain( const _FaceSide& side, int* which ) const
1555 if ( !which || myChildren.empty() )
1560 // set<const TopoDS_TShape*>::iterator v, vEnd = side.myVertices.end();
1561 // for ( v = side.myVertices.begin(); v != vEnd; ++v )
1562 // nbCommon += ( myVertices.find( *v ) != myVertices.end() );
1563 TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
1564 for ( ; vIt.More(); vIt.Next() )
1565 nbCommon += ( myVertices.Contains( vIt.Key() ));
1566 return (nbCommon > 1);
1568 list< _FaceSide >::const_iterator mySide = myChildren.begin(), sideEnd = myChildren.end();
1569 for ( int i = 0; mySide != sideEnd; ++mySide, ++i ) {
1570 if ( mySide->Contain( side )) {
1578 //=======================================================================
1579 //function : Contain
1581 //=======================================================================
1583 bool _FaceSide::Contain( const TopoDS_Vertex& vertex ) const
1585 return myVertices.Contains( vertex );
1586 // return myVertices.find( ptr( vertex )) != myVertices.end();
1589 //=======================================================================
1590 //function : AppendSide
1592 //=======================================================================
1594 void _FaceSide::AppendSide( const _FaceSide& side )
1596 if ( !myEdge.IsNull() )
1598 myChildren.push_back( *this );
1602 myChildren.push_back( side );
1604 //myVertices.insert( side.myVertices.begin(), side.myVertices.end() );
1605 TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
1606 for ( ; vIt.More(); vIt.Next() )
1607 myVertices.Add( vIt.Key() );
1610 myChildren.back().SetID( EQuadSides( myNbChildren-1 ));
1613 //=======================================================================
1614 //function : SetBottomSide
1616 //=======================================================================
1618 void _FaceSide::SetBottomSide( int i )
1620 if ( i > 0 && myID == Q_PARENT ) {
1621 list< _FaceSide >::iterator sideEnd, side = myChildren.begin();
1622 std::advance( side, i );
1623 myChildren.splice( myChildren.begin(), myChildren, side, myChildren.end() );
1625 side = myChildren.begin(), sideEnd = myChildren.end();
1626 for ( int i = 0; side != sideEnd; ++side, ++i ) {
1627 side->SetID( EQuadSides(i) );
1628 side->SetBottomSide(i);
1633 //=======================================================================
1634 //function : GetNbSegments
1636 //=======================================================================
1638 int _FaceSide::GetNbSegments(SMESH_Mesh& mesh) const
1641 if ( myChildren.empty() )
1643 nb = mesh.GetSubMesh(myEdge)->GetSubMeshDS()->NbElements();
1647 list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
1648 for ( ; side != sideEnd; ++side )
1649 nb += side->GetNbSegments(mesh);
1654 //=======================================================================
1655 //function : StoreNodes
1657 //=======================================================================
1659 bool _FaceSide::StoreNodes(SMESH_Mesh& mesh,
1660 vector<const SMDS_MeshNode*>& myGrid,
1663 list< TopoDS_Edge > edges;
1664 if ( myChildren.empty() )
1666 edges.push_back( myEdge );
1670 list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
1671 for ( ; side != sideEnd; ++side )
1673 edges.push_front( side->myEdge );
1675 edges.push_back ( side->myEdge );
1678 list< TopoDS_Edge >::iterator edge = edges.begin(), eEnd = edges.end();
1679 for ( ; edge != eEnd; ++edge )
1681 map< double, const SMDS_MeshNode* > nodes;
1682 bool ok = SMESH_Algo::GetSortedNodesOnEdge( mesh.GetMeshDS(),
1684 /*ignoreMediumNodes=*/true,
1686 if ( !ok ) return false;
1688 bool forward = ( edge->Orientation() == TopAbs_FORWARD );
1689 if ( reverse ) forward = !forward;
1692 map< double, const SMDS_MeshNode* >::iterator u_node, nEnd = nodes.end();
1693 for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
1694 myGrid[ nbNodes++ ] = u_node->second;
1698 map< double, const SMDS_MeshNode* >::reverse_iterator u_node, nEnd = nodes.rend();
1699 for ( u_node = nodes.rbegin(); u_node != nEnd; ++u_node )
1700 myGrid[ nbNodes++ ] = u_node->second;
1702 nbNodes--; // node on vertex present in two adjacent edges
1707 //=======================================================================
1709 //purpose : dump end vertices
1710 //=======================================================================
1712 void _FaceSide::Dump() const
1714 if ( myChildren.empty() )
1716 const char* sideNames[] = { "Q_BOTTOM", "Q_RIGHT", "Q_TOP", "Q_LEFT", "Q_CHILD", "Q_PARENT" };
1717 if ( myID >= Q_BOTTOM && myID < Q_PARENT )
1718 cout << sideNames[ myID ] << endl;
1720 cout << "<UNDEFINED ID>" << endl;
1721 TopoDS_Vertex f = FirstVertex();
1722 TopoDS_Vertex l = LastVertex();
1723 gp_Pnt pf = BRep_Tool::Pnt(f);
1724 gp_Pnt pl = BRep_Tool::Pnt(l);
1725 cout << "\t ( "<< ptr( f ) << " - " << ptr( l )<< " )"
1726 << "\t ( "<< pf.X()<<", "<<pf.Y()<<", "<<pf.Z()<<" ) - "
1727 << " ( "<< pl.X()<<", "<<pl.Y()<<", "<<pl.Z()<<" )"<<endl;
1731 list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
1732 for ( ; side != sideEnd; ++side ) {