1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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 : implementation 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 "SMESHDS_Mesh.hxx"
32 #include "SMESHDS_SubMesh.hxx"
33 #include "SMESH_Block.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_ComputeError.hxx"
36 #include "SMESH_HypoFilter.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MeshAlgos.hxx"
39 #include "SMESH_MesherHelper.hxx"
40 #include "SMESH_subMesh.hxx"
41 #include "StdMeshers_BlockRenumber.hxx"
42 #include "StdMeshers_FaceSide.hxx"
43 #include "StdMeshers_ViscousLayers.hxx"
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRep_Tool.hxx>
47 #include <Standard_ErrorHandler.hxx>
48 #include <Standard_Failure.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <TopTools_MapIteratorOfMapOfShape.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <TopTools_SequenceOfShape.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Face.hxx>
57 #include <TopoDS_Vertex.hxx>
59 #include <gp_Pnt2d.hxx>
66 #include <Bnd_B3d.hxx>
73 // #define DUMP_VERT(msg,V) { TopoDS_Vertex v = V; gp_Pnt p = BRep_Tool::Pnt(v); cout << msg << "( "<< p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl; }
77 #define DUMP_VERT(msg,v)
80 //================================================================================
81 // text for message about an internal error
82 #define ERR_LI(txt) SMESH_Comment(txt) << ":" << __LINE__
84 // order corresponds to right order of edges in CASCADE face
85 enum EQuadSides{ Q_BOTTOM=0, Q_RIGHT, Q_TOP, Q_LEFT, Q_CHILD, Q_PARENT };
87 enum EBoxSides{ B_BOTTOM=0, B_RIGHT, B_TOP, B_LEFT, B_FRONT, B_BACK, B_UNDEFINED };
89 enum EAxes{ COO_X=1, COO_Y, COO_Z };
91 //================================================================================
93 * \brief Converter of a pair of integers to a sole index
98 _Indexer( int xSize, int ySize ): _xSize(xSize), _ySize(ySize) {}
99 int size() const { return _xSize * _ySize; }
100 int operator()(const int x, const int y) const { return y * _xSize + x; }
103 //================================================================================
105 * \brief Wrapper of a composite or an ordinary edge.
110 _FaceSide(const _FaceSide& other);
111 _FaceSide(const TopoDS_Edge& edge=TopoDS_Edge());
112 _FaceSide(const list<TopoDS_Edge>& edges);
113 _FaceSide* GetSide(const int i);
114 const _FaceSide* GetSide(const int i) const;
115 int size() const { return myChildren.size(); }
116 int NbVertices() const;
117 int NbCommonVertices( const TopTools_MapOfShape& VV ) const;
118 TopoDS_Vertex FirstVertex() const;
119 TopoDS_Vertex LastVertex() const;
120 TopoDS_Vertex Vertex(int i) const;
121 TopoDS_Edge Edge(int i) const;
122 bool Contain( const _FaceSide& side, int* which=0 ) const;
123 bool Contain( const TopoDS_Vertex& vertex ) const;
124 void AppendSide( const _FaceSide& side );
125 void SetBottomSide( int i );
126 int GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges=0) const;
127 bool StoreNodes(SMESH_ProxyMesh& mesh, vector<const SMDS_MeshNode*>& myGrid,
128 bool reverse, bool isProxy, const SMESHDS_SubMesh* smToCheckEdges=0 );
129 void SetID(EQuadSides id) { myID = id; }
130 static inline const TopoDS_TShape* ptr(const TopoDS_Shape& theShape)
131 { return theShape.TShape().operator->(); }
138 list< _FaceSide > myChildren;
141 TopTools_MapOfShape myVertices;
143 EQuadSides myID; // debug
145 //================================================================================
147 * \brief Class corresponding to a meshed composite face of a box.
148 * Provides simplified access to it's sub-mesh data.
152 typedef list< _QuadFaceGrid > TChildren;
156 public: //** Methods to find and orient faces of 6 sides of the box **//
159 bool Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh );
161 //!< try to unite self with other face
162 bool AddContinuousFace( const _QuadFaceGrid& f, const TopTools_MapOfShape& internalEdges );
164 //!< Try to set the side as bottom hirizontal side
165 bool SetBottomSide(const _FaceSide& side, int* sideIndex=0);
167 //!< Return face adjacent to zero-based i-th side of this face
168 _QuadFaceGrid* FindAdjacentForSide(int i, list<_QuadFaceGrid>& faces, EBoxSides id) const;
170 //!< Reverse edges in order to have the bottom edge going along axes of the unit box
173 bool IsComplex() const { return !myChildren.empty(); }
175 int NbChildren() const { return myChildren.size(); }
177 typedef SMDS_SetIterator< const _QuadFaceGrid&,
178 TChildren::const_iterator,
179 SMDS::SimpleAccessor<const _QuadFaceGrid&,TChildren::const_iterator>,
180 SMDS::PassAllValueFilter<_QuadFaceGrid> >
183 TChildIterator GetChildren() const
184 { return TChildIterator( myChildren.begin(), myChildren.end()); }
186 bool Contain( const TopoDS_Vertex& vertex ) const { return mySides.Contain( vertex ); }
188 public: //** Loading and access to mesh **//
190 //!< Load nodes of a mesh
191 bool LoadGrid( SMESH_ProxyMesh& mesh );
193 //!< Computes normalized parameters of nodes of myGrid
194 void ComputeIJK( int i1, int i2, double v3 );
196 //!< Return number of segments on the hirizontal sides
197 int GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
199 //!< Return number of segments on the vertical sides
200 int GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
202 //!< Return edge on the hirizontal bottom sides
203 int GetHoriEdges(vector<TopoDS_Edge> & edges) const;
205 //!< Return a node by its position
206 const SMDS_MeshNode* GetNode(int iHori, int iVert) const;
208 //!< Return node coordinates by its position
209 gp_XYZ GetXYZ(int iHori, int iVert) const;
211 //!< Return normalized parameters of nodes within the unitary cube
212 gp_XYZ& GetIJK(int iCol, int iRow) { return myIJK[ myIndexer( iCol, iRow )]; }
214 public: //** Access to member fields **//
216 //!< Return i-th face side (0<i<4)
217 const _FaceSide& GetSide(int i) const;
219 //!< Return it's face, NULL if it is composite
220 TopoDS_Face GetFace() const { return myFace; }
222 //!< Return normal to the face at vertex v
223 bool GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const;
225 SMESH_ComputeErrorPtr GetError() const { return myError; }
227 void SetID(EBoxSides id) { myID = id; }
229 void DumpGrid() const;
231 void DumpVertices() const;
235 bool error(const std::string& text, int code = COMPERR_ALGO_FAILED)
236 { myError = SMESH_ComputeError::New( code, text ); return false; }
238 bool error(const SMESH_ComputeErrorPtr& err)
239 { myError = err; return ( !myError || myError->IsOK() ); }
241 bool loadCompositeGrid(SMESH_ProxyMesh& mesh);
243 bool fillGrid(SMESH_ProxyMesh& theMesh,
244 vector<const SMDS_MeshNode*> & theGrid,
245 const _Indexer& theIndexer,
249 bool locateChildren();
251 void setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers );
257 TChildren myChildren;
259 _QuadFaceGrid* myLeftBottomChild;
260 _QuadFaceGrid* myRightBrother;
261 _QuadFaceGrid* myUpBrother;
264 vector<const SMDS_MeshNode*> myGrid;
265 vector<gp_XYZ> myIJK; // normalized parameters of nodes
267 SMESH_ComputeErrorPtr myError;
269 EBoxSides myID; // debug
272 //================================================================================
276 //================================================================================
278 StdMeshers_CompositeHexa_3D::StdMeshers_CompositeHexa_3D(int hypId, SMESH_Gen* gen)
279 :SMESH_3D_Algo(hypId, gen), _blockRenumberHyp( nullptr )
281 _name = "CompositeHexa_3D";
282 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
285 //================================================================================
287 * \brief always return true
289 //================================================================================
291 bool StdMeshers_CompositeHexa_3D::CheckHypothesis(SMESH_Mesh& aMesh,
292 const TopoDS_Shape& aShape,
293 Hypothesis_Status& aStatus)
295 _blockRenumberHyp = nullptr;
303 //================================================================================
305 * \brief Checks structure of a quadrangular mesh at the common VERTEX of two EDGEs.
306 * Returns true if there are two quadrangles near the VERTEX.
308 //================================================================================
310 bool isContinuousMesh(TopoDS_Edge E1,
312 const TopoDS_Face& F,
313 const SMESH_ProxyMesh& mesh)
315 if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
316 E1.Orientation( TopAbs_FORWARD );
317 if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
318 E2.Orientation( TopAbs_FORWARD );
321 if ( !TopExp::CommonVertex( E1, E2, V )) return false;
323 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
324 if ( !n ) return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
326 n = mesh.GetProxyNode( n );
328 const SMESHDS_SubMesh* sm = mesh.GetSubMesh( F );
329 if ( !sm ) return false;
332 SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
334 return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
335 while ( fIt->more() )
337 const SMDS_MeshElement* f = fIt->next();
338 if ( !sm->Contains( f )) continue;
340 if ( f->NbCornerNodes() == 4 )
348 //================================================================================
350 * \brief Return true if a vertex holds a node and this node is used by some quadrangle
352 //================================================================================
354 // bool isMeshedVertex( TopoDS_Vertex& V,
355 // const SMESH_Mesh& mesh )
357 // const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
358 // if ( !n ) return false;
360 // SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
361 // while ( fIt->more() )
363 // const SMDS_MeshElement* f = fIt->next();
364 // if ( f->NbCornerNodes() == 4 )
370 //================================================================================
372 * \brief Finds VERTEXes located at block corners
374 //================================================================================
376 void getBlockCorners( SMESH_ProxyMesh& mesh,
377 const TopoDS_Shape& shape,
378 TopTools_MapOfShape& cornerVV)
380 std::set<int> faceIDs; // ids of FACEs in the shape
382 for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
383 faceIDs.insert( mesh.GetMeshDS()->ShapeToIndex( exp.Current() ));
385 TopTools_MapOfShape checkedVV;
386 for ( exp.Init( shape, TopAbs_VERTEX ); exp.More(); exp.Next() )
388 TopoDS_Vertex V = TopoDS::Vertex( exp.Current() );
389 if ( !checkedVV.Add( V )) continue;
391 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
394 const SMDS_MeshNode* nProxy = mesh.GetProxyNode( n );
395 bool isProxy = ( nProxy != n );
399 SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
400 while ( fIt->more() )
402 const SMDS_MeshElement* f = fIt->next();
403 if ( !faceIDs.count( f->getshapeId() )) continue;
405 if ( isProxy && !mesh.GetSubMesh( f->getshapeId() )->Contains( f ))
408 if ( f->NbCornerNodes() == 4 )
418 //================================================================================
420 * \brief Return EDGEs dividing one box side
422 //================================================================================
424 bool getInternalEdges( SMESH_Mesh& mesh,
425 const TopoDS_Shape& shape,
426 const TopTools_MapOfShape& cornerVV,
427 TopTools_MapOfShape& internEE)
429 TopTools_IndexedMapOfShape subEE, subFF;
430 TopExp::MapShapes( shape, TopAbs_EDGE, subEE );
431 TopExp::MapShapes( shape, TopAbs_FACE, subFF );
434 TopTools_MapOfShape subChecked, ridgeEE;
435 TopTools_MapIteratorOfMapOfShape vIt( cornerVV );
436 for ( ; vIt.More(); vIt.Next() )
438 TopoDS_Shape V0 = vIt.Key();
439 // walk from one corner VERTEX to another along ridge EDGEs
440 PShapeIteratorPtr riIt = SMESH_MesherHelper::GetAncestors( V0, mesh, TopAbs_EDGE );
441 while ( const TopoDS_Shape* riE = riIt->next() )
443 if ( !subEE.Contains( *riE ) || !subChecked.Add( *riE ))
445 TopoDS_Edge ridgeE = TopoDS::Edge( *riE );
446 while ( !ridgeE.IsNull() )
448 if ( !ridgeEE.Add( ridgeE ))
450 TopExp::Vertices( ridgeE, VV[0], VV[1] );
451 TopoDS_Shape V1 = VV[ V0.IsSame( VV[0] )];
452 if ( cornerVV.Contains( V1 ) )
453 break; // ridgeE reached a corner VERTEX
455 // detect internal EDGEs among those sharing V1. There can be 2, 3 or 4 EDGEs and
456 // number of internal EDGEs is N-2
457 TopoDS_Shape nextRidgeE;
458 PShapeIteratorPtr eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
459 while ( const TopoDS_Shape* E = eIt->next() )
461 if ( E->IsSame( ridgeE ) || !subEE.Contains( *E ) || !subChecked.Add( *E ))
463 // look for FACEs sharing both E and ridgeE
464 PShapeIteratorPtr fIt = SMESH_MesherHelper::GetAncestors( *E, mesh, TopAbs_FACE );
465 while ( const TopoDS_Shape* F = fIt->next() )
467 if ( !SMESH_MesherHelper::IsSubShape( ridgeE, *F ))
469 if ( !subFF.Contains( *F ))
471 if ( isContinuousMesh( ridgeE, TopoDS::Edge( *E ), TopoDS::Face( *F ), mesh ))
482 // look for the next ridge EDGE ending at V1
483 if ( nextRidgeE.IsNull() )
485 eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
486 while ( const TopoDS_Shape* E = eIt->next() )
487 if ( !ridgeE.IsSame( *E ) && !internEE.Contains( *E ) && subEE.Contains( *E ))
493 ridgeE = TopoDS::Edge( nextRidgeE );
496 if ( ridgeE.IsNull() )
498 } // check EDGEs around the last VERTEX of ridgeE
499 } // loop on ridge EDGEs around a corner VERTEX
500 } // loop on on corner VERTEXes
502 if ( subEE.Extent() > ridgeEE.Extent() + internEE.Extent() ) // PAL23269
503 for ( int i = 1; i < subEE.Extent(); ++i )
504 if ( !ridgeEE.Contains( subEE(i) ))
505 internEE.Add( subEE(i) );
508 } // getInternalEdges()
510 //================================================================================
512 * \brief Find a face including two given nodes
514 //================================================================================
516 const SMDS_MeshElement* FindFaceByNodes( const SMDS_MeshNode* n1,
517 const SMDS_MeshNode* n2,
518 TIDSortedElemSet avoidSet,
519 SMESH_ProxyMesh& mesh)
521 SMDS_ElemIteratorPtr faceIt = mesh.GetInverseElementIterator( n1, SMDSAbs_Face );
522 while ( faceIt->more() )
524 const SMDS_MeshElement* f = faceIt->next();
525 if ( !avoidSet.count( f ) && f->GetNodeIndex( n2 ) >= 0 )
531 //================================================================================
533 * \brief Check that a segment bounds a face belonging to smOfFaces
535 //================================================================================
537 bool IsSegmentOnSubMeshBoundary( const SMDS_MeshNode* n1,
538 const SMDS_MeshNode* n2,
539 const SMESHDS_SubMesh* smOfFaces,
540 SMESH_ProxyMesh& mesh)
542 TIDSortedElemSet avoidSet;
543 bool faceFound = false;
545 while ( const SMDS_MeshElement* f = FindFaceByNodes( n1, n2, avoidSet, mesh ))
547 if (( faceFound = smOfFaces->Contains( f )))
549 avoidSet.insert( f );
554 //================================================================================
556 * \brief Rearrange block sides according to StdMeshers_BlockRenumber hypothesis
558 //================================================================================
560 bool arrangeForRenumber( list< _QuadFaceGrid >& blockSides,
561 const TopTools_MapOfShape& cornerVertices,
564 TopoDS_Vertex& v001 )
568 // block CS is not defined;
569 // renumber only if the block has an edge parallel to an axis of global CS
571 v000 = StdMeshers_RenumberHelper::GetVertex000( cornerVertices );
575 for ( auto it = cornerVertices.cbegin(); it != cornerVertices.cend(); ++it )
576 bbox.Add( BRep_Tool::Pnt( TopoDS::Vertex( *it )));
577 double tol = 1e-5 * Sqrt( bbox.SquareExtent() );
579 // get block edges starting at v000
581 std::vector< const _FaceSide* > edgesAtV000;
582 std::vector< gp_Vec > edgeDir;
583 std::vector< int > iParallel; // 0 - none, 1 - X, 2 - Y, 3 - Z
584 TopTools_MapOfShape lastVertices;
585 for ( _QuadFaceGrid & quad: blockSides )
587 for ( int iS = 0; iS < 4 && edgesAtV000.size() < 3; ++iS )
589 const _FaceSide* side = & quad.GetSide( iS );
590 TopoDS_Vertex v1 = side->FirstVertex(), v2 = side->LastVertex();
591 if (( v1.IsSame( v000 ) && !lastVertices.Contains( v2 )) ||
592 ( v2.IsSame( v000 ) && !lastVertices.Contains( v1 )))
594 bool reverse = v2.IsSame( v000 );
597 lastVertices.Add( v2 );
599 edgesAtV000.push_back( side );
601 gp_Pnt pf = BRep_Tool::Pnt( v1 );
602 gp_Pnt pl = BRep_Tool::Pnt( v2 );
603 gp_Vec vec( pf, pl );
604 edgeDir.push_back( vec );
606 iParallel.push_back( 0 );
607 if ( !v001.IsNull() )
609 if ( quad.IsComplex() )
610 for ( _QuadFaceGrid::TChildIterator chIt = quad.GetChildren(); chIt.more(); )
612 const _QuadFaceGrid& child = chIt.next();
613 if ( child.GetSide( iS ).Contain( v001 ))
615 iParallel.back() = 3;
619 else if ( side->Contain( v001 ))
620 iParallel.back() = 3;
624 bool isStraight = true;
625 std::list< TopoDS_Edge > edges;
626 for ( int iE = 0; true; ++iE )
628 TopoDS_Edge edge = side->Edge( iE );
631 edges.push_back( edge );
633 isStraight = SMESH_Algo::IsStraight( edge );
635 // is parallel to a GCS axis?
638 int nbDiff = (( Abs( vec.X() ) > tol ) +
639 ( Abs( vec.Y() ) > tol ) +
640 ( Abs( vec.Z() ) > tol ) );
642 iParallel.back() = ( Abs( vec.X() ) > tol ) ? 1 : ( Abs( vec.Y() ) > tol ) ? 2 : 3;
646 TopoDS_Face nullFace;
647 StdMeshers_FaceSide fSide( nullFace, edges, mesh, true, true );
648 edgeDir.back() = gp_Vec( pf, fSide.Value3d( reverse ? 0.99 : 0.01 ));
654 if ( std::accumulate( iParallel.begin(), iParallel.end(), 0 ) == 0 )
657 // find edge OZ and edge OX
658 const _FaceSide* edgeOZ = nullptr, *edgeOY = nullptr, *edgeOX = nullptr;
659 auto iZIt = std::find( iParallel.begin(), iParallel.end(), 3 );
660 if ( iZIt != iParallel.end() )
662 int i = std::distance( iParallel.begin(), iZIt );
663 edgeOZ = edgesAtV000[ i ];
664 int iE1 = SMESH_MesherHelper::WrapIndex( i + 1, edgesAtV000.size() );
665 int iE2 = SMESH_MesherHelper::WrapIndex( i + 2, edgesAtV000.size() );
666 if (( edgeDir[ iE1 ] ^ edgeDir[ iE2 ] ) * edgeDir[ i ] < 0 )
667 std::swap( iE1, iE2 );
668 edgeOX = edgesAtV000[ iE1 ];
669 edgeOY = edgesAtV000[ iE2 ];
673 for ( size_t i = 0; i < edgesAtV000.size(); ++i )
675 if ( !iParallel[ i ] )
677 int iE1 = SMESH_MesherHelper::WrapIndex( i + 1, edgesAtV000.size() );
678 int iE2 = SMESH_MesherHelper::WrapIndex( i + 2, edgesAtV000.size() );
679 if (( edgeDir[ iE1 ] ^ edgeDir[ iE2 ] ) * edgeDir[ i ] < 0 )
680 std::swap( iE1, iE2 );
681 edgeOZ = edgesAtV000[ iParallel[i] == 1 ? iE2 : iE1 ];
682 edgeOX = edgesAtV000[ iParallel[i] == 1 ? i : iE1 ];
683 edgeOY = edgesAtV000[ iParallel[i] == 1 ? iE1 : i ];
688 if ( !edgeOZ || !edgeOX || !edgeOY )
691 TopoDS_Vertex v100 = edgeOX->LastVertex();
692 if ( v100.IsSame( v000 ))
693 v100 = edgeOX->FirstVertex();
695 // Find the left quad, one including v000 but not v100
697 for ( auto quad = blockSides.begin(); quad != blockSides.end(); ++quad )
699 if ( quad->Contain( v000 ) && !quad->Contain( v100 )) // it's a left quad
701 if ( quad != blockSides.begin() )
702 blockSides.splice( blockSides.begin(), blockSides, quad );
703 blockSides.front().SetBottomSide( *edgeOZ ); // edgeOY
713 //================================================================================
715 * \brief Tries to find 6 sides of a box
717 //================================================================================
719 bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape& shape,
720 list< _QuadFaceGrid >& boxFaces,
722 SMESH_ProxyMesh& proxyMesh,
724 _QuadFaceGrid * & fBottom,
725 _QuadFaceGrid * & fTop,
726 _QuadFaceGrid * & fFront,
727 _QuadFaceGrid * & fBack,
728 _QuadFaceGrid * & fLeft,
729 _QuadFaceGrid * & fRight)
731 TopTools_MapOfShape cornerVertices;
732 getBlockCorners( proxyMesh, shape, cornerVertices );
733 if ( cornerVertices.Extent() != 8 )
734 return error( COMPERR_BAD_INPUT_MESH, "Can't find 8 corners of a block by 2D mesh" );
735 TopTools_MapOfShape internalEdges;
736 if ( !getInternalEdges( mesh, shape, cornerVertices, internalEdges ))
737 return error( COMPERR_BAD_INPUT_MESH, "2D mesh is not suitable for i,j,k hexa meshing" );
739 list< _QuadFaceGrid >::iterator boxFace;
742 for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFaces )
745 if ( !f.Init( TopoDS::Face( exp.Current() ), proxyMesh ))
746 return error (COMPERR_BAD_SHAPE);
748 _QuadFaceGrid* prevContinuous = 0;
749 for ( boxFace = boxFaces.begin(); boxFace != boxFaces.end(); ++boxFace )
751 if ( prevContinuous )
753 if ( prevContinuous->AddContinuousFace( *boxFace, internalEdges ))
754 boxFace = --boxFaces.erase( boxFace );
756 else if ( boxFace->AddContinuousFace( f, internalEdges ))
758 prevContinuous = & (*boxFace);
761 if ( !prevContinuous )
762 boxFaces.push_back( f );
764 // Check what we have
765 if ( boxFaces.size() != 6 && nbFaces != 6)
768 SMESH_Comment("Can't find 6 sides of a box. Number of found sides - ")<<boxFaces.size());
770 if ( boxFaces.size() != 6 && nbFaces == 6 ) { // strange ordinary box with continuous faces
771 boxFaces.resize( 6 );
772 boxFace = boxFaces.begin();
773 for ( exp.Init( shape, TopAbs_FACE); exp.More(); exp.Next(), ++boxFace )
774 boxFace->Init( TopoDS::Face( exp.Current() ), proxyMesh );
777 toRenumber = _blockRenumberHyp;
780 TopoDS_Vertex v000, v001;
781 _blockRenumberHyp->IsSolidIncluded( mesh, shape, v000, v001 );
783 toRenumber = arrangeForRenumber( boxFaces, cornerVertices, &mesh, v000, v001 );
787 mesh.GetMeshDS()->Modified();
788 mesh.GetMeshDS()->CompactMesh(); // remove numbering holes
792 // ----------------------------------------
793 // Find out position of faces within a box
794 // ----------------------------------------
795 // start from a bottom face
796 fBottom = &boxFaces.front();
797 fBottom->SetID( B_BOTTOM );
798 // find vertical faces
799 fFront = fBottom->FindAdjacentForSide( Q_BOTTOM, boxFaces, B_FRONT );
800 fLeft = fBottom->FindAdjacentForSide( Q_RIGHT, boxFaces, B_LEFT );
801 fBack = fBottom->FindAdjacentForSide( Q_TOP, boxFaces, B_BACK );
802 fRight = fBottom->FindAdjacentForSide( Q_LEFT, boxFaces, B_RIGHT );
804 if ( !fFront || !fBack || !fLeft || !fRight )
805 return error(COMPERR_BAD_SHAPE);
808 for ( boxFace = ++boxFaces.begin(); boxFace != boxFaces.end() && !fTop; ++boxFace )
811 fTop->SetID( B_TOP );
812 if ( fTop==fFront || fTop==fLeft || fTop==fBack || fTop==fRight )
815 // set bottom of the top side
816 if ( !fTop->SetBottomSide( fFront->GetSide( Q_TOP ) )) {
817 if ( !fFront->IsComplex() )
818 return error( ERR_LI("Error in StdMeshers_CompositeHexa_3D::Compute()"));
820 _QuadFaceGrid::TChildIterator chIt = fFront->GetChildren();
821 while ( chIt.more() ) {
822 const _QuadFaceGrid& frontChild = chIt.next();
823 if ( fTop->SetBottomSide( frontChild.GetSide( Q_TOP )))
829 return error(COMPERR_BAD_SHAPE);
831 // orient bottom edge of faces along axes of the unit box
832 fBottom->ReverseEdges();
833 fBack ->ReverseEdges();
834 fLeft ->ReverseEdges();
839 //================================================================================
841 * \brief Computes hexahedral mesh on a box with composite sides
842 * \param aMesh - mesh to compute
843 * \param aShape - shape to mesh
844 * \retval bool - success sign
846 //================================================================================
848 bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh& theMesh,
849 const TopoDS_Shape& theShape)
851 SMESH_MesherHelper helper( theMesh );
852 _quadraticMesh = helper.IsQuadraticSubMesh( theShape );
853 helper.SetElementsOnShape( true );
856 SMESH_ProxyMesh::Ptr proxyMesh;
857 SMESH_HypoFilter vlFilter( SMESH_HypoFilter::HasName( StdMeshers_ViscousLayers::GetHypType() ));
858 const SMESH_Hypothesis * hyp = theMesh.GetHypothesis( theShape, vlFilter, true );
859 const StdMeshers_ViscousLayers* vlHyp = static_cast< const StdMeshers_ViscousLayers* >( hyp );
861 proxyMesh = vlHyp->Compute( theMesh, theShape, /*toMakeN2NMap=*/true );
863 proxyMesh.reset( new SMESH_ProxyMesh( theMesh ));
865 // -------------------------
866 // Try to find 6 side faces
867 // -------------------------
868 list< _QuadFaceGrid > boxFaceContainer;
869 bool toRenumber = false;
870 _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
871 if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh, toRenumber,
872 fBottom, fTop, fFront, fBack, fLeft, fRight))
875 // ------------------------------------------
876 // Fill columns of nodes with existing nodes
877 // ------------------------------------------
879 // let faces load their grids
880 if ( !fBottom->LoadGrid( *proxyMesh )) return error( fBottom->GetError() );
881 if ( !fBack ->LoadGrid( *proxyMesh )) return error( fBack ->GetError() );
882 if ( !fLeft ->LoadGrid( *proxyMesh )) return error( fLeft ->GetError() );
883 if ( !fFront ->LoadGrid( *proxyMesh )) return error( fFront ->GetError() );
884 if ( !fRight ->LoadGrid( *proxyMesh )) return error( fRight ->GetError() );
885 if ( !fTop ->LoadGrid( *proxyMesh )) return error( fTop ->GetError() );
887 // compute normalized parameters of nodes on sides (PAL23189)
888 fBottom->ComputeIJK( COO_X, COO_Y, /*z=*/0. );
889 fBack ->ComputeIJK( COO_X, COO_Z, /*y=*/1. );
890 fLeft ->ComputeIJK( COO_Y, COO_Z, /*x=*/0. );
891 fFront ->ComputeIJK( COO_X, COO_Z, /*y=*/0. );
892 fRight ->ComputeIJK( COO_Y, COO_Z, /*x=*/1. );
893 fTop ->ComputeIJK( COO_X, COO_Y, /*z=*/1. );
895 StdMeshers_RenumberHelper renumHelper( theMesh, _blockRenumberHyp );
897 int x, xSize = fBottom->GetNbHoriSegments(*proxyMesh) + 1, X = xSize - 1;
898 int y, ySize = fBottom->GetNbVertSegments(*proxyMesh) + 1, Y = ySize - 1;
899 int z, zSize = fFront ->GetNbVertSegments(*proxyMesh) + 1, Z = zSize - 1;
900 _Indexer colIndex( xSize, ySize );
901 vector< vector< const SMDS_MeshNode* > > columns( colIndex.size() );
903 // fill node columns by front and back box sides
904 for ( x = 0; x < xSize; ++x ) {
905 vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( x, 0 )];
906 vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( x, Y )];
907 column0.resize( zSize );
908 column1.resize( zSize );
909 for ( z = 0; z < zSize; ++z ) {
910 column0[ z ] = fFront->GetNode( x, z );
911 column1[ z ] = fBack ->GetNode( x, z );
914 // fill node columns by left and right box sides
915 for ( y = 1; y < ySize-1; ++y ) {
916 vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( 0, y )];
917 vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( X, y )];
918 column0.resize( zSize );
919 column1.resize( zSize );
920 for ( z = 0; z < zSize; ++z ) {
921 column0[ z ] = fLeft ->GetNode( y, z );
922 column1[ z ] = fRight->GetNode( y, z );
925 // get nodes from top and bottom box sides
926 for ( x = 1; x < xSize-1; ++x ) {
927 for ( y = 1; y < ySize-1; ++y ) {
928 vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
929 column.resize( zSize );
930 column.front() = fBottom->GetNode( x, y );
931 column.back() = fTop ->GetNode( x, y );
935 // ----------------------------
936 // Add internal nodes of a box
937 // ----------------------------
938 // projection points of internal nodes on box sub-shapes by which
939 // coordinates of internal nodes are computed
940 vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
942 // projections on vertices are constant
943 pointsOnShapes[ SMESH_Block::ID_V000 ] = fBottom->GetXYZ( 0, 0 );
944 pointsOnShapes[ SMESH_Block::ID_V100 ] = fBottom->GetXYZ( X, 0 );
945 pointsOnShapes[ SMESH_Block::ID_V010 ] = fBottom->GetXYZ( 0, Y );
946 pointsOnShapes[ SMESH_Block::ID_V110 ] = fBottom->GetXYZ( X, Y );
947 pointsOnShapes[ SMESH_Block::ID_V001 ] = fTop->GetXYZ( 0, 0 );
948 pointsOnShapes[ SMESH_Block::ID_V101 ] = fTop->GetXYZ( X, 0 );
949 pointsOnShapes[ SMESH_Block::ID_V011 ] = fTop->GetXYZ( 0, Y );
950 pointsOnShapes[ SMESH_Block::ID_V111 ] = fTop->GetXYZ( X, Y );
952 gp_XYZ params; // normalized parameters of an internal node within the unit box
955 for ( y = 0; y < ySize; ++y )
957 vector< const SMDS_MeshNode* >& columnXy = columns[ colIndex( X, y )];
958 for ( z = 0; z < zSize; ++z )
959 renumHelper.AddReplacingNode( columnXy[ z ] );
962 for ( x = X-1; x > 0; --x )
966 vector< const SMDS_MeshNode* >& columnX0 = columns[ colIndex( x, 0 )];
967 for ( z = 0; z < zSize; ++z )
968 renumHelper.AddReplacingNode( columnX0[ z ] );
971 const double rX = x / double(X);
972 for ( y = 1; y < ySize-1; ++y )
974 const double rY = y / double(Y);
975 // column to fill during z loop
976 vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
977 // points projections on horizontal edges
978 pointsOnShapes[ SMESH_Block::ID_Ex00 ] = fBottom->GetXYZ( x, 0 );
979 pointsOnShapes[ SMESH_Block::ID_Ex10 ] = fBottom->GetXYZ( x, Y );
980 pointsOnShapes[ SMESH_Block::ID_E0y0 ] = fBottom->GetXYZ( 0, y );
981 pointsOnShapes[ SMESH_Block::ID_E1y0 ] = fBottom->GetXYZ( X, y );
982 pointsOnShapes[ SMESH_Block::ID_Ex01 ] = fTop->GetXYZ( x, 0 );
983 pointsOnShapes[ SMESH_Block::ID_Ex11 ] = fTop->GetXYZ( x, Y );
984 pointsOnShapes[ SMESH_Block::ID_E0y1 ] = fTop->GetXYZ( 0, y );
985 pointsOnShapes[ SMESH_Block::ID_E1y1 ] = fTop->GetXYZ( X, y );
986 // points projections on horizontal faces
987 pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = fBottom->GetXYZ( x, y );
988 pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = fTop ->GetXYZ( x, y );
991 renumHelper.AddReplacingNode( column[ 0 ] );
993 for ( z = 1; z < zSize-1; ++z ) // z loop
995 // compute normalized parameters of an internal node within the unit box
996 const double rZ = z / double(Z);
997 const gp_XYZ& pBo = fBottom->GetIJK( x, y );
998 const gp_XYZ& pTo = fTop ->GetIJK( x, y );
999 const gp_XYZ& pFr = fFront ->GetIJK( x, z );
1000 const gp_XYZ& pBa = fBack ->GetIJK( x, z );
1001 const gp_XYZ& pLe = fLeft ->GetIJK( y, z );
1002 const gp_XYZ& pRi = fRight ->GetIJK( y, z );
1003 params.SetCoord( 1, 0.5 * ( pBo.X() * ( 1. - rZ ) + pTo.X() * rZ +
1004 pFr.X() * ( 1. - rY ) + pBa.X() * rY ));
1005 params.SetCoord( 2, 0.5 * ( pBo.Y() * ( 1. - rZ ) + pTo.Y() * rZ +
1006 pLe.Y() * ( 1. - rX ) + pRi.Y() * rX ));
1007 params.SetCoord( 3, 0.5 * ( pFr.Z() * ( 1. - rY ) + pBa.Z() * rY +
1008 pLe.Z() * ( 1. - rX ) + pRi.Z() * rX ));
1010 // point projections on vertical edges
1011 pointsOnShapes[ SMESH_Block::ID_E00z ] = fFront->GetXYZ( 0, z );
1012 pointsOnShapes[ SMESH_Block::ID_E10z ] = fFront->GetXYZ( X, z );
1013 pointsOnShapes[ SMESH_Block::ID_E01z ] = fBack->GetXYZ( 0, z );
1014 pointsOnShapes[ SMESH_Block::ID_E11z ] = fBack->GetXYZ( X, z );
1015 // point projections on vertical faces
1016 pointsOnShapes[ SMESH_Block::ID_Fx0z ] = fFront->GetXYZ( x, z );
1017 pointsOnShapes[ SMESH_Block::ID_Fx1z ] = fBack ->GetXYZ( x, z );
1018 pointsOnShapes[ SMESH_Block::ID_F0yz ] = fLeft ->GetXYZ( y, z );
1019 pointsOnShapes[ SMESH_Block::ID_F1yz ] = fRight->GetXYZ( y, z );
1021 // compute internal node coordinates
1023 SMESH_Block::ShellPoint( params, pointsOnShapes, coords );
1024 column[ z ] = helper.AddNode( coords.X(), coords.Y(), coords.Z() );
1028 //cout << "----------------------------------------------------------------------"<<endl;
1029 //for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id)
1031 // gp_XYZ p = pointsOnShapes[ id ];
1032 // SMESH_Block::DumpShapeID( id,cout)<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;
1034 //cout << "Params: ( "<< params.X()<<", "<<params.Y()<<", "<<params.Z()<<" )"<<endl;
1035 //cout << "coords: ( "<< coords.X()<<", "<<coords.Y()<<", "<<coords.Z()<<" )"<<endl;
1039 renumHelper.AddReplacingNode( column[ Z ] );
1044 vector< const SMDS_MeshNode* >& columnXY = columns[ colIndex( x, Y )];
1045 for ( z = 0; z < zSize; ++z )
1046 renumHelper.AddReplacingNode( columnXY[ z ] );
1048 } // for ( x = X-1; x > 0; --x )
1051 for ( y = 0; y < ySize; ++y )
1053 vector< const SMDS_MeshNode* >& column0Y = columns[ colIndex( 0, y )];
1054 for ( z = 0; z < zSize; ++z )
1055 renumHelper.AddReplacingNode( column0Y[ z ] );
1059 // faces no more needed, free memory
1060 boxFaceContainer.clear();
1065 for ( x = xSize-2; true; --x ) {
1066 for ( y = 0; y < ySize-1; ++y ) {
1067 vector< const SMDS_MeshNode* >& col00 = columns[ colIndex( x, y )];
1068 vector< const SMDS_MeshNode* >& col10 = columns[ colIndex( x+1, y )];
1069 vector< const SMDS_MeshNode* >& col01 = columns[ colIndex( x, y+1 )];
1070 vector< const SMDS_MeshNode* >& col11 = columns[ colIndex( x+1, y+1 )];
1071 for ( z = 0; z < zSize-1; ++z )
1073 // bottom face normal of a hexa mush point outside the volume
1074 helper.AddVolume(col10[z], col11[z], col11[z+1], col10[z+1],
1075 col00[z], col01[z], col01[z+1], col00[z+1]);
1083 renumHelper.DoReplaceNodes();
1085 if ( _blockRenumberHyp )
1087 return error( _blockRenumberHyp->CheckHypothesis( theMesh, theShape ));
1093 //================================================================================
1097 //================================================================================
1099 bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh& theMesh,
1100 const TopoDS_Shape& theShape,
1101 MapShapeNbElems& aResMap)
1103 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
1105 // -------------------------
1106 // Try to find 6 side faces
1107 // -------------------------
1108 list< _QuadFaceGrid > boxFaceContainer;
1109 _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
1110 bool toRenumber = false;
1111 if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh, toRenumber,
1112 fBottom, fTop, fFront, fBack, fLeft, fRight))
1115 // Find a less complex side
1116 _QuadFaceGrid * lessComplexSide = & boxFaceContainer.front();
1117 list< _QuadFaceGrid >::iterator face = boxFaceContainer.begin();
1118 for ( ++face; face != boxFaceContainer.end() && lessComplexSide->IsComplex(); ++face )
1119 if ( face->NbChildren() < lessComplexSide->NbChildren() )
1120 lessComplexSide = & *face;
1122 // Get an 1D size of lessComplexSide
1124 vector<TopoDS_Edge> edges;
1125 if ( !lessComplexSide->GetHoriEdges(edges) )
1127 for ( size_t i = 0; i < edges.size(); ++i )
1129 const vector<int>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1130 if ( !nbElems.empty() )
1131 nbSeg1 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1134 // Get an 1D size of a box side orthogonal to lessComplexSide
1136 _QuadFaceGrid* ortoSide =
1137 lessComplexSide->FindAdjacentForSide( Q_LEFT, boxFaceContainer, B_UNDEFINED );
1139 if ( !ortoSide || !ortoSide->GetHoriEdges(edges) ) return false;
1140 for ( size_t i = 0; i < edges.size(); ++i )
1142 const vector<int>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1143 if ( !nbElems.empty() )
1144 nbSeg2 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1147 // Get an 2D size of a box side orthogonal to lessComplexSide
1148 int nbFaces = 0, nbQuadFace = 0;
1149 list< TopoDS_Face > sideFaces;
1150 if ( ortoSide->IsComplex() )
1151 for ( _QuadFaceGrid::TChildIterator child = ortoSide->GetChildren(); child.more(); )
1152 sideFaces.push_back( child.next().GetFace() );
1154 sideFaces.push_back( ortoSide->GetFace() );
1156 list< TopoDS_Face >::iterator f = sideFaces.begin();
1157 for ( ; f != sideFaces.end(); ++f )
1159 const vector<int>& nbElems = aResMap[ theMesh.GetSubMesh( *f )];
1160 if ( !nbElems.empty() )
1162 nbFaces = nbElems[ SMDSEntity_Quadrangle ];
1163 nbQuadFace = nbElems[ SMDSEntity_Quad_Quadrangle ];
1167 // Fill nb of elements
1168 vector<int> aResVec(SMDSEntity_Last,0);
1169 int nbSeg3 = ( nbFaces + nbQuadFace ) / nbSeg2;
1170 aResVec[SMDSEntity_Node] = (nbSeg1-1) * (nbSeg2-1) * (nbSeg3-1);
1171 aResVec[SMDSEntity_Hexa] = nbSeg1 * nbFaces;
1172 aResVec[SMDSEntity_Quad_Hexa] = nbSeg1 * nbQuadFace;
1174 aResMap.insert( make_pair( theMesh.GetSubMesh(theShape), aResVec ));
1180 //================================================================================
1182 * \brief constructor of non-initialized _QuadFaceGrid
1184 //================================================================================
1186 _QuadFaceGrid::_QuadFaceGrid():
1187 myReverse(false), myRightBrother(0), myUpBrother(0), myIndexer(0,0), myID(B_UNDEFINED)
1191 //================================================================================
1193 * \brief Initialization
1195 //================================================================================
1197 bool _QuadFaceGrid::Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh)
1200 mySides = _FaceSide();
1202 myLeftBottomChild = myRightBrother = myUpBrother = 0;
1205 //if ( myFace.Orientation() != TopAbs_FORWARD )
1208 list< TopoDS_Edge > edges;
1209 list< int > nbEdgesInWire;
1210 int nbWire = SMESH_Block::GetOrderedEdges (myFace, edges, nbEdgesInWire);
1214 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1215 if ( nbEdgesInWire.front() == 4 ) // exactly 4 edges
1217 for ( ; edgeIt != edges.end(); ++edgeIt )
1218 mySides.AppendSide( _FaceSide( *edgeIt ));
1220 else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
1221 list< TopoDS_Edge > sideEdges;
1222 while ( !edges.empty()) {
1224 sideEdges.splice( sideEdges.end(), edges, edges.begin());// edges.front()->sideEdges.back()
1225 if ( SMESH_Algo::isDegenerated( sideEdges.back() ))
1227 while ( !edges.empty() ) {
1228 if ( isContinuousMesh( sideEdges.back(), edges.front(), f, mesh )) {
1229 sideEdges.splice( sideEdges.end(), edges, edges.begin());
1231 else if ( isContinuousMesh( sideEdges.front(), edges.back(), f, mesh )) {
1232 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
1238 mySides.AppendSide( _FaceSide( sideEdges ));
1241 if (mySides.size() != 4)
1245 mySides.GetSide( Q_BOTTOM )->SetID( Q_BOTTOM );
1246 mySides.GetSide( Q_RIGHT )->SetID( Q_RIGHT );
1247 mySides.GetSide( Q_TOP )->SetID( Q_TOP );
1248 mySides.GetSide( Q_LEFT )->SetID( Q_LEFT );
1254 //================================================================================
1256 * \brief Try to unite self with other ordinary face
1258 //================================================================================
1260 bool _QuadFaceGrid::AddContinuousFace( const _QuadFaceGrid& other,
1261 const TopTools_MapOfShape& internalEdges)
1263 for ( int i = 0; i < 4; ++i )
1265 const _FaceSide& otherSide = other.GetSide( i );
1267 if ( mySides.Contain( otherSide, &iMyCommon ))
1269 if ( internalEdges.Contains( otherSide.Edge( 0 )))
1271 DUMP_VERT("Cont 1", mySides.GetSide(iMyCommon)->FirstVertex());
1272 DUMP_VERT("Cont 2", mySides.GetSide(iMyCommon)->LastVertex());
1273 DUMP_VERT("Cont 3", otherSide.FirstVertex());
1274 DUMP_VERT("Cont 4", otherSide.LastVertex());
1276 if ( myChildren.empty() )
1278 myChildren.push_back( *this );
1281 else // find iMyCommon in myChildren
1283 for ( TChildIterator children = GetChildren(); children.more(); ) {
1284 const _QuadFaceGrid& child = children.next();
1285 if ( child.mySides.Contain( otherSide, &iMyCommon ))
1290 // orient new children equally
1291 int otherBottomIndex = SMESH_MesherHelper::WrapIndex( i - iMyCommon + 2, 4 );
1292 if ( other.IsComplex() )
1293 for ( TChildIterator children = other.GetChildren(); children.more(); ) {
1294 myChildren.push_back( children.next() );
1295 myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1298 myChildren.push_back( other );
1299 myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1302 myLeftBottomChild = 0;
1304 // collect vertices in mySides
1305 if ( other.IsComplex() )
1306 for ( TChildIterator children = other.GetChildren(); children.more(); )
1308 const _QuadFaceGrid& child = children.next();
1309 for ( int i = 0; i < 4; ++i )
1310 mySides.AppendSide( child.GetSide(i) );
1313 for ( int i = 0; i < 4; ++i )
1314 mySides.AppendSide( other.GetSide(i) );
1323 //================================================================================
1325 * \brief Try to set the side as bottom hirizontal side
1327 //================================================================================
1329 bool _QuadFaceGrid::SetBottomSide(const _FaceSide& bottom, int* sideIndex)
1331 myLeftBottomChild = myRightBrother = myUpBrother = 0;
1334 if ( myChildren.empty() )
1336 if ( mySides.Contain( bottom, &myBottomIndex )) {
1337 mySides.SetBottomSide( myBottomIndex );
1339 *sideIndex = myBottomIndex;
1345 TChildren::iterator childFace = myChildren.begin(), childEnd = myChildren.end();
1346 for ( ; childFace != childEnd; ++childFace )
1348 if ( childFace->SetBottomSide( bottom, &myBottomIndex ))
1350 TChildren::iterator orientedChild = childFace;
1351 for ( childFace = myChildren.begin(); childFace != childEnd; ++childFace ) {
1352 if ( childFace != orientedChild )
1353 childFace->SetBottomSide( childFace->GetSide( myBottomIndex ));
1356 *sideIndex = myBottomIndex;
1364 //================================================================================
1366 * \brief Return face adjacent to i-th side of this face, (0<i<4)
1368 //================================================================================
1370 _QuadFaceGrid* _QuadFaceGrid::FindAdjacentForSide(int i,
1371 list<_QuadFaceGrid>& faces,
1374 const _FaceSide & iSide = GetSide( i );
1375 list< _QuadFaceGrid >::iterator boxFace = faces.begin();
1376 for ( ; boxFace != faces.end(); ++boxFace )
1378 _QuadFaceGrid* f = & (*boxFace);
1379 if ( f != this && f->SetBottomSide( iSide ))
1380 return f->SetID( id ), f;
1382 return (_QuadFaceGrid*) 0;
1385 //================================================================================
1387 * \brief Return i-th side
1389 //================================================================================
1391 const _FaceSide& _QuadFaceGrid::GetSide(int i) const
1393 if ( myChildren.empty() )
1394 return *mySides.GetSide(i);
1396 _QuadFaceGrid* me = const_cast<_QuadFaceGrid*>(this);
1397 if ( !me->locateChildren() || !myLeftBottomChild )
1398 return *mySides.GetSide(i);
1400 const _QuadFaceGrid* child = myLeftBottomChild;
1406 while ( child->myRightBrother )
1407 child = child->myRightBrother;
1410 while ( child->myUpBrother )
1411 child = child->myUpBrother;
1415 return child->GetSide( i );
1418 //================================================================================
1420 * \brief Reverse edges in order to have them oriented along axes of the unit box
1422 //================================================================================
1424 void _QuadFaceGrid::ReverseEdges()
1426 myReverse = !myReverse;
1429 // if ( !myFace.IsNull() )
1430 // TopAbs::Print(myFace.Orientation(), cout);
1433 if ( myChildren.empty() )
1440 TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1441 for ( ; child != childEnd; ++child )
1442 child->ReverseEdges();
1446 //================================================================================
1448 * \brief Load nodes of a mesh
1450 //================================================================================
1452 bool _QuadFaceGrid::LoadGrid( SMESH_ProxyMesh& mesh )
1454 if ( !myChildren.empty() )
1456 // Let child faces load their grids
1457 TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1458 for ( ; child != childEnd; ++child ) {
1459 child->SetID( myID );
1460 if ( !child->LoadGrid( mesh ) )
1461 return error( child->GetError() );
1463 // Fill myGrid with nodes of patches
1464 return loadCompositeGrid( mesh );
1467 // ---------------------------------------
1468 // Fill myGrid with nodes bound to myFace
1469 // ---------------------------------------
1471 if ( !myGrid.empty() )
1474 const SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace );
1476 // check that all faces are quadrangular
1477 SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
1478 while ( fIt->more() )
1479 if ( fIt->next()->NbNodes() % 4 > 0 )
1480 return error("Non-quadrangular mesh faces are not allowed on sides of a composite block");
1482 bool isProxy, isTmpElem;
1483 if ( faceSubMesh && faceSubMesh->NbElements() > 0 )
1485 isProxy = dynamic_cast< const SMESH_ProxyMesh::SubMesh* >( faceSubMesh );
1486 isTmpElem = mesh.IsTemporary( faceSubMesh->GetElements()->next() );
1488 const SMESHDS_SubMesh* smToCheckEdges = ( isProxy && !isTmpElem ) ? faceSubMesh : 0;
1490 myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh, smToCheckEdges );
1491 myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT )->GetNbSegments( mesh, smToCheckEdges );
1493 myGrid.resize( myIndexer.size() );
1495 // store nodes bound to the bottom edge
1496 mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse, isProxy, smToCheckEdges );
1498 // store the rest nodes row by row
1500 TIDSortedElemSet avoidSet;
1501 const SMDS_MeshElement* firstQuad = 0; // most left face above the last row of found nodes
1503 size_t nbFoundNodes = myIndexer._xSize;
1504 while ( nbFoundNodes != myGrid.size() )
1506 // first and last nodes of the last filled row of nodes
1507 const SMDS_MeshNode* n1down = myGrid[ nbFoundNodes - myIndexer._xSize ];
1508 const SMDS_MeshNode* n2down = myGrid[ nbFoundNodes - myIndexer._xSize + 1];
1509 const SMDS_MeshNode* n1downLast = myGrid[ nbFoundNodes-1 ];
1511 // find the first face above the row by the first two left nodes
1519 firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh );
1520 while ( firstQuad && !faceSubMesh->Contains( firstQuad )) {
1521 avoidSet.insert( firstQuad );
1522 firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh);
1524 if ( !firstQuad || !faceSubMesh->Contains( firstQuad ))
1525 return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1527 // find the node of quad bound to the left geom edge
1528 int i2down = firstQuad->GetNodeIndex( n2down );
1529 const SMDS_MeshNode* n1up = firstQuad->GetNode(( i2down+2 ) % 4 );
1530 myGrid[ nbFoundNodes++ ] = n1up;
1531 // the 4-the node of the first quad
1532 int i1down = firstQuad->GetNodeIndex( n1down );
1533 const SMDS_MeshNode* n2up = firstQuad->GetNode(( i1down+2 ) % 4 );
1534 myGrid[ nbFoundNodes++ ] = n2up;
1538 const SMDS_MeshElement* quad = firstQuad;
1540 // find the rest nodes by remaining faces above the row
1548 while ( n1down != n1downLast )
1551 avoidSet.clear(); avoidSet.insert( quad );
1552 quad = FindFaceByNodes( n1down, n1up, avoidSet, mesh );
1553 if ( !quad || quad->NbNodes() % 4 > 0)
1554 return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1557 if ( quad->GetNode( i1down ) != n1down ) // check already found index
1558 i1down = quad->GetNodeIndex( n1down );
1559 n2up = quad->GetNode(( i1down+2 ) % 4 );
1560 myGrid[ nbFoundNodes++ ] = n2up;
1562 n1down = myGrid[ nbFoundNodes - myIndexer._xSize - 1 ];
1565 avoidSet.clear(); avoidSet.insert( firstQuad );
1567 DumpGrid(); // debug
1572 //================================================================================
1574 * \brief Fill myIJK with normalized parameters of nodes in myGrid
1575 * \param [in] i1 - coordinate index along rows of myGrid
1576 * \param [in] i2 - coordinate index along columns of myGrid
1577 * \param [in] v3 - value of the constant parameter
1579 //================================================================================
1581 void _QuadFaceGrid::ComputeIJK( int i1, int i2, double v3 )
1583 gp_XYZ ijk( v3, v3, v3 );
1584 myIJK.resize( myIndexer.size(), ijk );
1586 const size_t nbCol = myIndexer._xSize;
1587 const size_t nbRow = myIndexer._ySize;
1589 vector< double > len( nbRow );
1591 for ( size_t i = 0; i < nbCol; ++i )
1593 gp_Pnt pPrev = GetXYZ( i, 0 );
1594 for ( size_t j = 1; j < nbRow; ++j )
1596 gp_Pnt p = GetXYZ( i, j );
1597 len[ j ] = len[ j-1 ] + p.Distance( pPrev );
1600 for ( size_t j = 0; j < nbRow; ++j )
1601 GetIJK( i, j ).SetCoord( i2, len[ j ]/len.back() );
1604 len.resize( nbCol );
1605 for ( size_t j = 0; j < nbRow; ++j )
1607 gp_Pnt pPrev = GetXYZ( 0, j );
1608 for ( size_t i = 1; i < nbCol; ++i )
1610 gp_Pnt p = GetXYZ( i, j );
1611 len[ i ] = len[ i-1 ] + p.Distance( pPrev );
1614 for ( size_t i = 0; i < nbCol; ++i )
1615 GetIJK( i, j ).SetCoord( i1, len[ i ]/len.back() );
1619 //================================================================================
1621 * \brief Find out mutual location of children: find their right and up brothers
1623 //================================================================================
1625 bool _QuadFaceGrid::locateChildren()
1627 if ( myLeftBottomChild )
1630 TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1632 // find a child sharing it's first bottom vertex with no other brother
1633 myLeftBottomChild = 0;
1634 for ( ; !myLeftBottomChild && child != childEnd; ++child )
1636 TopoDS_Vertex leftVertex = child->GetSide( Q_BOTTOM ).FirstVertex();
1637 bool sharedVertex = false;
1638 TChildren::iterator otherChild = myChildren.begin();
1639 for ( ; otherChild != childEnd && !sharedVertex; ++otherChild )
1640 if ( otherChild != child )
1641 sharedVertex = otherChild->mySides.Contain( leftVertex );
1642 if ( !sharedVertex ) {
1643 myLeftBottomChild = & (*child);
1644 DUMP_VERT("0 left bottom Vertex: ",leftVertex );
1647 if (!myLeftBottomChild)
1648 return error(ERR_LI("Error in locateChildren()"));
1650 set< _QuadFaceGrid* > notLocatedChilren;
1651 for (child = myChildren.begin() ; child != childEnd; ++child )
1652 notLocatedChilren.insert( & (*child));
1654 // connect myLeftBottomChild to it's right and upper brothers
1655 notLocatedChilren.erase( myLeftBottomChild );
1656 myLeftBottomChild->setBrothers( notLocatedChilren );
1657 if ( !notLocatedChilren.empty() )
1658 return error(ERR_LI("Error in locateChildren()"));
1663 //================================================================================
1665 * \brief Fill myGrid with nodes of patches
1667 //================================================================================
1669 bool _QuadFaceGrid::loadCompositeGrid(SMESH_ProxyMesh& mesh)
1671 // Find out mutual location of children: find their right and up brothers
1672 if ( !locateChildren() )
1675 // Load nodes according to mutual location of children
1678 myIndexer._xSize = 1 + myLeftBottomChild->GetNbHoriSegments( mesh, /*withBrothers=*/true );
1679 myIndexer._ySize = 1 + myLeftBottomChild->GetNbVertSegments( mesh, /*withBrothers=*/true );
1681 myGrid.resize( myIndexer.size() );
1683 int fromX = myReverse ? myIndexer._xSize : 0;
1684 if ( !myLeftBottomChild->fillGrid( mesh, myGrid, myIndexer, fromX, 0 ))
1685 return error( myLeftBottomChild->GetError() );
1692 //================================================================================
1694 * \brief Find right an upper brothers among notLocatedBrothers
1696 //================================================================================
1698 void _QuadFaceGrid::setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers )
1700 if ( !notLocatedBrothers.empty() )
1702 // find right brother
1703 TopoDS_Vertex rightVertex = GetSide( Q_BOTTOM ).LastVertex();
1704 DUMP_VERT("1 right bottom Vertex: ",rightVertex );
1705 set< _QuadFaceGrid* >::iterator brIt, brEnd = notLocatedBrothers.end();
1706 for ( brIt = notLocatedBrothers.begin(); brIt != brEnd; ++brIt )
1708 _QuadFaceGrid* brother = *brIt;
1709 TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1710 DUMP_VERT( "brother left bottom: ", brotherLeftVertex );
1711 if ( rightVertex.IsSame( brotherLeftVertex )) {
1712 myRightBrother = brother;
1713 notLocatedBrothers.erase( brIt );
1717 // find upper brother
1718 TopoDS_Vertex upVertex = GetSide( Q_LEFT ).FirstVertex();
1719 DUMP_VERT("1 left up Vertex: ",upVertex);
1720 brIt = notLocatedBrothers.begin(), brEnd = notLocatedBrothers.end();
1721 for ( ; brIt != brEnd; ++brIt )
1723 _QuadFaceGrid* brother = *brIt;
1724 TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1725 DUMP_VERT("brother left bottom: ", brotherLeftVertex);
1726 if ( upVertex.IsSame( brotherLeftVertex )) {
1727 myUpBrother = brother;
1728 notLocatedBrothers.erase( myUpBrother );
1733 if ( myRightBrother )
1734 myRightBrother->setBrothers( notLocatedBrothers );
1736 myUpBrother->setBrothers( notLocatedBrothers );
1740 //================================================================================
1742 * \brief Store nodes of a simple face into grid starting from (x,y) position
1744 //================================================================================
1746 bool _QuadFaceGrid::fillGrid(SMESH_ProxyMesh& theMesh,
1747 vector<const SMDS_MeshNode*> & theGrid,
1748 const _Indexer& theIndexer,
1752 if ( myGrid.empty() && !LoadGrid( theMesh ))
1755 // store my own grid in the global grid
1757 int fromX = myReverse ? theX - myIndexer._xSize: theX;
1759 for ( int i = 0, x = fromX; i < myIndexer._xSize; ++i, ++x )
1760 for ( int j = 0, y = theY; j < myIndexer._ySize; ++j, ++y )
1761 theGrid[ theIndexer( x, y )] = myGrid[ myIndexer( i, j )];
1763 // store grids of my right and upper brothers
1765 if ( myRightBrother )
1770 fromX += myIndexer._xSize - 1;
1771 if ( !myRightBrother->fillGrid( theMesh, theGrid, theIndexer, fromX, theY ))
1772 return error( myRightBrother->GetError() );
1776 if ( !myUpBrother->fillGrid( theMesh, theGrid, theIndexer,
1777 theX, theY + myIndexer._ySize - 1))
1778 return error( myUpBrother->GetError() );
1783 //================================================================================
1785 * \brief Return number of segments on the hirizontal sides
1787 //================================================================================
1789 int _QuadFaceGrid::GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1792 if ( myLeftBottomChild )
1794 nbSegs += myLeftBottomChild->GetNbHoriSegments( mesh, true );
1798 nbSegs = mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
1799 if ( withBrothers && myRightBrother )
1800 nbSegs += myRightBrother->GetNbHoriSegments( mesh, withBrothers );
1805 //================================================================================
1807 * \brief Return number of segments on the vertical sides
1809 //================================================================================
1811 int _QuadFaceGrid::GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1814 if ( myLeftBottomChild )
1816 nbSegs += myLeftBottomChild->GetNbVertSegments( mesh, true );
1820 nbSegs = mySides.GetSide( Q_LEFT )->GetNbSegments(mesh,0);
1821 if ( withBrothers && myUpBrother )
1822 nbSegs += myUpBrother->GetNbVertSegments( mesh, withBrothers );
1827 //================================================================================
1829 * \brief Return edge on the hirizontal bottom sides
1831 //================================================================================
1833 int _QuadFaceGrid::GetHoriEdges(vector<TopoDS_Edge> & edges) const
1835 if ( myLeftBottomChild )
1837 return myLeftBottomChild->GetHoriEdges( edges );
1841 const _FaceSide* bottom = mySides.GetSide( Q_BOTTOM );
1844 TopoDS_Edge e = bottom->Edge( i++ );
1848 edges.push_back( e );
1850 if ( myRightBrother )
1851 myRightBrother->GetHoriEdges( edges );
1853 return edges.size();
1856 //================================================================================
1858 * \brief Return a node by its position
1860 //================================================================================
1862 const SMDS_MeshNode* _QuadFaceGrid::GetNode(int iHori, int iVert) const
1864 return myGrid[ myIndexer( iHori, iVert )];
1867 //================================================================================
1869 * \brief Return node coordinates by its position
1871 //================================================================================
1873 gp_XYZ _QuadFaceGrid::GetXYZ(int iHori, int iVert) const
1875 SMESH_TNodeXYZ xyz = myGrid[ myIndexer( iHori, iVert )];
1879 //================================================================================
1881 * \brief Return normal to the face at vertex v
1883 //================================================================================
1885 bool _QuadFaceGrid::GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const
1887 if ( myChildren.empty() )
1889 if ( mySides.Contain( v )) {
1891 gp_Pnt2d uv = BRep_Tool::Parameters( v, myFace );
1892 BRepAdaptor_Surface surface( myFace );
1893 gp_Pnt p; gp_Vec d1u, d1v;
1894 surface.D1( uv.X(), uv.Y(), p, d1u, d1v );
1895 n = d1u.Crossed( d1v );
1898 catch (Standard_Failure) {
1905 TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1906 for ( ; child != childEnd; ++child )
1907 if ( child->GetNormal( v, n ))
1913 //================================================================================
1915 * \brief Dumps coordinates of grid nodes
1917 //================================================================================
1919 void _QuadFaceGrid::DumpGrid() const
1922 const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1923 cout << "****** Face " << names[ myID ] << endl;
1925 if ( myChildren.empty() || !myGrid.empty() )
1927 cout << "x size: " << myIndexer._xSize << "; y size: " << myIndexer._ySize << endl;
1928 for ( int y = 0; y < myIndexer._ySize; ++y ) {
1929 cout << "-- row " << y << endl;
1930 for ( int x = 0; x < myIndexer._xSize; ++x ) {
1931 const SMDS_MeshNode* n = myGrid[ myIndexer( x, y ) ];
1932 cout << x << " ( " << n->X() << ", " << n->Y() << ", " << n->Z() << " )" << endl;
1938 cout << "Nb children: " << myChildren.size() << endl;
1939 TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1940 for ( int i=0; child != childEnd; ++child, ++i ) {
1941 cout << " *** SUBFACE " << i+1 << endl;
1942 ((_QuadFaceGrid&)(*child)).SetID( myID );
1949 //================================================================================
1951 * \brief Dump vertices
1953 //================================================================================
1955 void _QuadFaceGrid::DumpVertices() const
1958 cout << "****** Face ";
1959 const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1960 if ( myID >= B_BOTTOM && myID < B_BACK )
1961 cout << names[ myID ] << endl;
1963 cout << "UNDEFINED" << endl;
1965 if ( myChildren.empty() )
1967 for ( int i = 0; i < 4; ++i )
1969 cout << " Side "; mySides.GetSide( i )->Dump();
1974 cout << "-- Nb children: " << myChildren.size() << endl;
1975 TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1976 for ( int i=0; child != childEnd; ++child, ++i ) {
1977 cout << " *** SUBFACE " << i+1 << endl;
1978 ((_QuadFaceGrid&)(*child)).SetID( myID );
1979 child->DumpVertices();
1985 //=======================================================================
1986 //function : _FaceSide
1987 //purpose : copy constructor
1988 //=======================================================================
1990 _FaceSide::_FaceSide(const _FaceSide& other)
1992 myEdge = other.myEdge;
1993 myChildren = other.myChildren;
1994 myNbChildren = other.myNbChildren;
1995 myVertices.Assign( other.myVertices );
1999 //================================================================================
2001 * \brief Construct a face side of one edge
2003 //================================================================================
2005 _FaceSide::_FaceSide(const TopoDS_Edge& edge):
2006 myEdge( edge ), myNbChildren(0)
2008 if ( !edge.IsNull() )
2009 for ( TopExp_Explorer exp( edge, TopAbs_VERTEX ); exp.More(); exp.Next() )
2010 //myVertices.insert( ptr ( exp.Current() ));
2011 myVertices.Add( exp.Current() );
2014 //================================================================================
2016 * \brief Construct a face side of several edges
2018 //================================================================================
2020 _FaceSide::_FaceSide(const list<TopoDS_Edge>& edges):
2023 list<TopoDS_Edge>::const_iterator edge = edges.begin(), eEnd = edges.end();
2024 for ( ; edge != eEnd; ++edge ) {
2025 myChildren.push_back( _FaceSide( *edge ));
2027 myVertices.Add( myChildren.back().FirstVertex() );
2028 myVertices.Add( myChildren.back().LastVertex() );
2029 myChildren.back().SetID( Q_CHILD ); // not to splice them
2033 //=======================================================================
2034 //function : GetSide
2036 //=======================================================================
2038 _FaceSide* _FaceSide::GetSide(const int i)
2040 if ( i >= myNbChildren )
2043 list< _FaceSide >::iterator side = myChildren.begin();
2045 std::advance( side, i );
2049 //=======================================================================
2050 //function : GetSide
2052 //=======================================================================
2054 const _FaceSide* _FaceSide::GetSide(const int i) const
2056 return const_cast< _FaceSide* >(this)->GetSide(i);
2059 //=======================================================================
2060 //function : NbVertices
2061 //purpose : return nb of vertices in the side
2062 //=======================================================================
2064 int _FaceSide::NbVertices() const
2066 if ( myChildren.empty() )
2067 return myVertices.Extent();
2069 return myNbChildren + 1;
2072 //=======================================================================
2073 //function : NbCommonVertices
2074 //purpose : Returns number of my vertices common with the given ones
2075 //=======================================================================
2077 int _FaceSide::NbCommonVertices( const TopTools_MapOfShape& VV ) const
2080 TopTools_MapIteratorOfMapOfShape vIt ( myVertices );
2081 for ( ; vIt.More(); vIt.Next() )
2082 nbCommon += ( VV.Contains( vIt.Key() ));
2087 //=======================================================================
2088 //function : FirstVertex
2090 //=======================================================================
2092 TopoDS_Vertex _FaceSide::FirstVertex() const
2094 if ( myChildren.empty() )
2095 return TopExp::FirstVertex( myEdge, Standard_True );
2097 return myChildren.front().FirstVertex();
2100 //=======================================================================
2101 //function : LastVertex
2103 //=======================================================================
2105 TopoDS_Vertex _FaceSide::LastVertex() const
2107 if ( myChildren.empty() )
2108 return TopExp::LastVertex( myEdge, Standard_True );
2110 return myChildren.back().LastVertex();
2113 //=======================================================================
2116 //=======================================================================
2118 TopoDS_Vertex _FaceSide::Vertex(int i) const
2120 if ( myChildren.empty() )
2121 return i ? LastVertex() : FirstVertex();
2123 if ( i >= myNbChildren )
2124 return myChildren.back().LastVertex();
2126 return GetSide(i)->FirstVertex();
2129 //================================================================================
2131 * \brief Return i-the zero-based edge of the side
2133 //================================================================================
2135 TopoDS_Edge _FaceSide::Edge(int i) const
2137 if ( i == 0 && !myEdge.IsNull() )
2140 if ( const _FaceSide* iSide = GetSide( i ))
2141 return iSide->myEdge;
2143 return TopoDS_Edge();
2146 //=======================================================================
2147 //function : Contain
2149 //=======================================================================
2151 bool _FaceSide::Contain( const _FaceSide& side, int* which ) const
2153 if ( !which || myChildren.empty() )
2158 TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2159 for ( ; vIt.More(); vIt.Next() )
2160 nbCommon += ( myVertices.Contains( vIt.Key() ));
2161 return (nbCommon > 1);
2163 list< _FaceSide >::const_iterator mySide = myChildren.begin(), sideEnd = myChildren.end();
2164 for ( int i = 0; mySide != sideEnd; ++mySide, ++i ) {
2165 if ( mySide->Contain( side )) {
2173 //=======================================================================
2174 //function : Contain
2176 //=======================================================================
2178 bool _FaceSide::Contain( const TopoDS_Vertex& vertex ) const
2180 return myVertices.Contains( vertex );
2183 //=======================================================================
2184 //function : AppendSide
2186 //=======================================================================
2188 void _FaceSide::AppendSide( const _FaceSide& side )
2190 if ( !myEdge.IsNull() )
2192 myChildren.push_back( *this );
2196 myChildren.push_back( side );
2198 TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2199 for ( ; vIt.More(); vIt.Next() )
2200 myVertices.Add( vIt.Key() );
2203 myChildren.back().SetID( EQuadSides( myNbChildren-1 ));
2206 //=======================================================================
2207 //function : SetBottomSide
2209 //=======================================================================
2211 void _FaceSide::SetBottomSide( int i )
2213 if ( i > 0 && myID == Q_PARENT ) {
2214 list< _FaceSide >::iterator sideEnd, side = myChildren.begin();
2215 std::advance( side, i );
2216 myChildren.splice( myChildren.begin(), myChildren, side, myChildren.end() );
2218 side = myChildren.begin(), sideEnd = myChildren.end();
2219 for ( int i = 0; side != sideEnd; ++side, ++i ) {
2220 side->SetID( EQuadSides(i) );
2221 side->SetBottomSide(i);
2226 //=======================================================================
2227 //function : GetNbSegments
2229 //=======================================================================
2231 int _FaceSide::GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges) const
2234 if ( myChildren.empty() )
2236 nb = mesh.GetSubMesh(myEdge)->NbElements();
2238 if ( smToCheckEdges )
2240 // check that segments bound faces belonging to smToCheckEdges
2241 SMDS_ElemIteratorPtr segIt = mesh.GetSubMesh(myEdge)->GetElements();
2242 while ( segIt->more() )
2244 const SMDS_MeshElement* seg = segIt->next();
2245 if ( !IsSegmentOnSubMeshBoundary( mesh.GetProxyNode( seg->GetNode(0) ),
2246 mesh.GetProxyNode( seg->GetNode(1) ),
2247 smToCheckEdges, mesh ))
2254 list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2255 for ( ; side != sideEnd; ++side )
2256 nb += side->GetNbSegments( mesh, smToCheckEdges );
2261 //=======================================================================
2262 //function : StoreNodes
2264 //=======================================================================
2266 bool _FaceSide::StoreNodes(SMESH_ProxyMesh& mesh,
2267 vector<const SMDS_MeshNode*>& myGrid,
2270 const SMESHDS_SubMesh* smToCheckEdges)
2272 list< TopoDS_Edge > edges;
2273 if ( myChildren.empty() )
2275 edges.push_back( myEdge );
2279 list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2280 for ( ; side != sideEnd; ++side )
2282 edges.push_front( side->myEdge );
2284 edges.push_back ( side->myEdge );
2287 list< TopoDS_Edge >::iterator edge = edges.begin(), eEnd = edges.end();
2288 for ( ; edge != eEnd; ++edge )
2290 typedef map< double, const SMDS_MeshNode* > TParamNodeMap;
2291 TParamNodeMap nodes;
2292 bool ok = SMESH_Algo::GetSortedNodesOnEdge( mesh.GetMeshDS(),
2294 /*ignoreMediumNodes=*/true,
2296 if ( !ok ) return false;
2298 // skip nodes on VERTEXes not included in faces
2299 if ( !nodes.begin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2300 nodes.erase( nodes.begin() );
2301 if ( !nodes.empty() &&
2302 !nodes.rbegin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2303 nodes.erase( --nodes.end() );
2307 TParamNodeMap::iterator u_node, nEnd = nodes.end();
2308 for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2309 u_node->second = mesh.GetProxyNode( u_node->second );
2312 if ( smToCheckEdges ) // erase nodes of segments not bounding faces of smToCheckEdges
2315 TParamNodeMap::iterator u_node1, u_node2 = nodes.begin(), nEnd = nodes.end();
2316 for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2317 if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2318 smToCheckEdges, mesh ))
2321 nodes.erase( u_node1 );
2324 TParamNodeMap::reverse_iterator u_node1, u_node2 = nodes.rbegin(), nEnd = nodes.rend();
2325 for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2326 if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2327 smToCheckEdges, mesh ))
2330 nodes.erase( --(( u_node2 = u_node1 ).base() ));
2334 bool forward = ( edge->Orientation() == TopAbs_FORWARD );
2335 if ( reverse ) forward = !forward;
2338 TParamNodeMap::iterator u_node, nEnd = nodes.end();
2339 for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2340 myGrid[ nbNodes++ ] = u_node->second;
2344 TParamNodeMap::reverse_iterator u_node, nEnd = nodes.rend();
2345 for ( u_node = nodes.rbegin(); u_node != nEnd; ++u_node )
2346 myGrid[ nbNodes++ ] = u_node->second;
2348 nbNodes--; // node on vertex present in two adjacent edges
2353 //=======================================================================
2355 //purpose : dump end vertices
2356 //=======================================================================
2358 void _FaceSide::Dump() const
2360 if ( myChildren.empty() )
2362 const char* sideNames[] = { "Q_BOTTOM", "Q_RIGHT", "Q_TOP", "Q_LEFT", "Q_CHILD", "Q_PARENT" };
2363 if ( myID >= Q_BOTTOM && myID < Q_PARENT )
2364 cout << sideNames[ myID ] << endl;
2366 cout << "<UNDEFINED ID>" << endl;
2367 TopoDS_Vertex f = FirstVertex();
2368 TopoDS_Vertex l = LastVertex();
2369 gp_Pnt pf = BRep_Tool::Pnt(f);
2370 gp_Pnt pl = BRep_Tool::Pnt(l);
2371 cout << "\t ( "<< ptr( f ) << " - " << ptr( l )<< " )"
2372 << "\t ( "<< pf.X()<<", "<<pf.Y()<<", "<<pf.Z()<<" ) - "
2373 << " ( "<< pl.X()<<", "<<pl.Y()<<", "<<pl.Z()<<" )"<<endl;
2377 list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2378 for ( ; side != sideEnd; ++side ) {