1 // Copyright (C) 2007-2024 CEA, EDF, 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 <Bnd_B3d.hxx>
48 #include <Standard_ErrorHandler.hxx>
49 #include <Standard_Failure.hxx>
50 #include <TopExp_Explorer.hxx>
51 #include <TopTools_IndexedMapOfShape.hxx>
52 #include <TopTools_MapIteratorOfMapOfShape.hxx>
53 #include <TopTools_MapOfShape.hxx>
54 #include <TopTools_SequenceOfShape.hxx>
56 #include <TopoDS_Edge.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Vertex.hxx>
60 #include <gp_Pnt2d.hxx>
74 // #define DUMP_VERT(msg,V) { TopoDS_Vertex v = V; gp_Pnt p = BRep_Tool::Pnt(v); cout << msg << "( "<< p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl; }
78 #define DUMP_VERT(msg,v)
81 //================================================================================
82 // text for message about an internal error
83 #define ERR_LI(txt) SMESH_Comment(txt) << ":" << __LINE__
85 // order corresponds to right order of edges in CASCADE face
86 enum EQuadSides{ Q_BOTTOM=0, Q_RIGHT, Q_TOP, Q_LEFT, Q_CHILD, Q_PARENT };
88 enum EBoxSides{ B_BOTTOM=0, B_RIGHT, B_TOP, B_LEFT, B_FRONT, B_BACK, B_UNDEFINED };
90 enum EAxes{ COO_X=1, COO_Y, COO_Z };
92 //================================================================================
94 * \brief Converter of a pair of integers to a sole index
99 _Indexer( int xSize, int ySize ): _xSize(xSize), _ySize(ySize) {}
100 int size() const { return _xSize * _ySize; }
101 int operator()(const int x, const int y) const { return y * _xSize + x; }
104 //================================================================================
106 * \brief Wrapper of a composite or an ordinary edge.
111 _FaceSide(const _FaceSide& other);
112 _FaceSide(const TopoDS_Edge& edge=TopoDS_Edge());
113 _FaceSide(const list<TopoDS_Edge>& edges);
114 _FaceSide* GetSide(const int i);
115 const _FaceSide* GetSide(const int i) const;
116 int size() const { return myChildren.size(); }
117 int NbVertices() const;
118 int NbCommonVertices( const TopTools_MapOfShape& VV ) const;
119 TopoDS_Vertex FirstVertex() const;
120 TopoDS_Vertex LastVertex() const;
121 TopoDS_Vertex Vertex(int i) const;
122 TopoDS_Edge Edge(int i) const;
123 bool Contain( const _FaceSide& side, int* which=0 ) const;
124 bool Contain( const TopoDS_Vertex& vertex ) const;
125 void AppendSide( const _FaceSide& side );
126 void SetBottomSide( int i );
127 smIdType GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges=0) const;
128 bool StoreNodes(SMESH_ProxyMesh& mesh, vector<const SMDS_MeshNode*>& myGrid,
129 bool reverse, bool isProxy, const SMESHDS_SubMesh* smToCheckEdges=0 );
130 void SetID(EQuadSides id) { myID = id; }
131 static inline const TopoDS_TShape* ptr(const TopoDS_Shape& theShape)
132 { return theShape.TShape().operator->(); }
139 list< _FaceSide > myChildren;
142 TopTools_MapOfShape myVertices;
144 EQuadSides myID; // debug
146 //================================================================================
148 * \brief Class corresponding to a meshed composite face of a box.
149 * Provides simplified access to it's sub-mesh data.
153 typedef list< _QuadFaceGrid > TChildren;
157 public: //** Methods to find and orient faces of 6 sides of the box **//
160 bool Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh );
162 //!< try to unite self with other face
163 bool AddContinuousFace( const _QuadFaceGrid& f, const TopTools_MapOfShape& internalEdges );
165 //!< Try to set the side as bottom hirizontal side
166 bool SetBottomSide(const _FaceSide& side, int* sideIndex=0);
168 //!< Return face adjacent to zero-based i-th side of this face
169 _QuadFaceGrid* FindAdjacentForSide(int i, list<_QuadFaceGrid>& faces, EBoxSides id) const;
171 //!< Reverse edges in order to have the bottom edge going along axes of the unit box
174 bool IsComplex() const { return !myChildren.empty(); }
176 int NbChildren() const { return myChildren.size(); }
178 typedef SMDS_SetIterator< const _QuadFaceGrid&,
179 TChildren::const_iterator,
180 SMDS::SimpleAccessor<const _QuadFaceGrid&,TChildren::const_iterator>,
181 SMDS::PassAllValueFilter<_QuadFaceGrid> >
184 TChildIterator GetChildren() const
185 { return TChildIterator( myChildren.begin(), myChildren.end()); }
187 bool Contain( const TopoDS_Vertex& vertex ) const { return mySides.Contain( vertex ); }
189 public: //** Loading and access to mesh **//
191 //!< Load nodes of a mesh
192 bool LoadGrid( SMESH_ProxyMesh& mesh );
194 //!< Computes normalized parameters of nodes of myGrid
195 void ComputeIJK( int i1, int i2, double v3 );
197 //!< Return number of segments on the hirizontal sides
198 int GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
200 //!< Return number of segments on the vertical sides
201 int GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
203 //!< Return edge on the hirizontal bottom sides
204 int GetHoriEdges(vector<TopoDS_Edge> & edges) const;
206 //!< Return a node by its position
207 const SMDS_MeshNode* GetNode(int iHori, int iVert) const;
209 //!< Return node coordinates by its position
210 gp_XYZ GetXYZ(int iHori, int iVert) const;
212 //!< Return normalized parameters of nodes within the unitary cube
213 gp_XYZ& GetIJK(int iCol, int iRow) { return myIJK[ myIndexer( iCol, iRow )]; }
215 public: //** Access to member fields **//
217 //!< Return i-th face side (0<i<4)
218 const _FaceSide& GetSide(int i) const;
220 //!< Return it's face, NULL if it is composite
221 TopoDS_Face GetFace() const { return myFace; }
223 //!< Return normal to the face at vertex v
224 bool GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const;
226 SMESH_ComputeErrorPtr GetError() const { return myError; }
228 void SetID(EBoxSides id) { myID = id; }
230 void DumpGrid() const;
232 void DumpVertices() const;
236 bool error(const std::string& text, int code = COMPERR_ALGO_FAILED)
237 { myError = SMESH_ComputeError::New( code, text ); return false; }
239 bool error(const SMESH_ComputeErrorPtr& err)
240 { myError = err; return ( !myError || myError->IsOK() ); }
242 bool loadCompositeGrid(SMESH_ProxyMesh& mesh);
244 bool fillGrid(SMESH_ProxyMesh& theMesh,
245 vector<const SMDS_MeshNode*> & theGrid,
246 const _Indexer& theIndexer,
250 bool locateChildren();
252 void setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers );
258 TChildren myChildren;
260 _QuadFaceGrid* myLeftBottomChild;
261 _QuadFaceGrid* myRightBrother;
262 _QuadFaceGrid* myUpBrother;
265 vector<const SMDS_MeshNode*> myGrid;
266 vector<gp_XYZ> myIJK; // normalized parameters of nodes
268 SMESH_ComputeErrorPtr myError;
270 EBoxSides myID; // debug
273 //================================================================================
277 //================================================================================
279 StdMeshers_CompositeHexa_3D::StdMeshers_CompositeHexa_3D(int hypId, SMESH_Gen* gen)
280 :SMESH_3D_Algo(hypId, gen), _blockRenumberHyp( nullptr )
282 _name = "CompositeHexa_3D";
283 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID); // 1 bit /shape type
286 //================================================================================
288 * \brief always return true
290 //================================================================================
292 bool StdMeshers_CompositeHexa_3D::CheckHypothesis(SMESH_Mesh& /*aMesh*/,
293 const TopoDS_Shape& /*aShape*/,
294 Hypothesis_Status& aStatus)
296 _blockRenumberHyp = nullptr;
304 //================================================================================
306 * \brief Checks structure of a quadrangular mesh at the common VERTEX of two EDGEs.
307 * Returns true if there are two quadrangles near the VERTEX.
309 //================================================================================
311 bool isContinuousMesh(TopoDS_Edge E1,
313 const TopoDS_Face& F,
314 const SMESH_ProxyMesh& mesh)
316 if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
317 E1.Orientation( TopAbs_FORWARD );
318 if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
319 E2.Orientation( TopAbs_FORWARD );
322 if ( !TopExp::CommonVertex( E1, E2, V )) return false;
324 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
325 if ( !n ) return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
327 n = mesh.GetProxyNode( n );
329 const SMESHDS_SubMesh* sm = mesh.GetSubMesh( F );
330 if ( !sm ) return false;
333 SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
335 return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
336 while ( fIt->more() )
338 const SMDS_MeshElement* f = fIt->next();
339 if ( !sm->Contains( f )) continue;
341 if ( f->NbCornerNodes() == 4 )
349 //================================================================================
351 * \brief Return true if a vertex holds a node and this node is used by some quadrangle
353 //================================================================================
355 // bool isMeshedVertex( TopoDS_Vertex& V,
356 // const SMESH_Mesh& mesh )
358 // const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
359 // if ( !n ) return false;
361 // SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
362 // while ( fIt->more() )
364 // const SMDS_MeshElement* f = fIt->next();
365 // if ( f->NbCornerNodes() == 4 )
371 //================================================================================
373 * \brief Finds VERTEXes located at block corners
375 //================================================================================
377 void getBlockCorners( SMESH_ProxyMesh& mesh,
378 const TopoDS_Shape& shape,
379 TopTools_MapOfShape& cornerVV)
381 std::set<int> faceIDs; // ids of FACEs in the shape
383 for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
384 faceIDs.insert( mesh.GetMeshDS()->ShapeToIndex( exp.Current() ));
386 TopTools_MapOfShape checkedVV;
387 for ( exp.Init( shape, TopAbs_VERTEX ); exp.More(); exp.Next() )
389 TopoDS_Vertex V = TopoDS::Vertex( exp.Current() );
390 if ( !checkedVV.Add( V )) continue;
392 const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
395 const SMDS_MeshNode* nProxy = mesh.GetProxyNode( n );
396 bool isProxy = ( nProxy != n );
400 SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
401 while ( fIt->more() )
403 const SMDS_MeshElement* f = fIt->next();
404 if ( !faceIDs.count( f->getshapeId() )) continue;
406 if ( isProxy && !mesh.GetSubMesh( f->getshapeId() )->Contains( f ))
409 if ( f->NbCornerNodes() == 4 )
419 //================================================================================
421 * \brief Return EDGEs dividing one box side
423 //================================================================================
425 bool getInternalEdges( SMESH_Mesh& mesh,
426 const TopoDS_Shape& shape,
427 const TopTools_MapOfShape& cornerVV,
428 TopTools_MapOfShape& internEE)
430 TopTools_IndexedMapOfShape subEE, subFF;
431 TopExp::MapShapes( shape, TopAbs_EDGE, subEE );
432 TopExp::MapShapes( shape, TopAbs_FACE, subFF );
435 TopTools_MapOfShape subChecked, ridgeEE;
436 TopTools_MapIteratorOfMapOfShape vIt( cornerVV );
437 for ( ; vIt.More(); vIt.Next() )
439 TopoDS_Shape V0 = vIt.Key();
440 // walk from one corner VERTEX to another along ridge EDGEs
441 PShapeIteratorPtr riIt = SMESH_MesherHelper::GetAncestors( V0, mesh, TopAbs_EDGE );
442 while ( const TopoDS_Shape* riE = riIt->next() )
444 if ( !subEE.Contains( *riE ) || !subChecked.Add( *riE ))
446 TopoDS_Edge ridgeE = TopoDS::Edge( *riE );
447 while ( !ridgeE.IsNull() )
449 if ( !ridgeEE.Add( ridgeE ))
451 TopExp::Vertices( ridgeE, VV[0], VV[1] );
452 TopoDS_Shape V1 = VV[ V0.IsSame( VV[0] )];
453 if ( cornerVV.Contains( V1 ) )
454 break; // ridgeE reached a corner VERTEX
456 // detect internal EDGEs among those sharing V1. There can be 2, 3 or 4 EDGEs and
457 // number of internal EDGEs is N-2
458 TopoDS_Shape nextRidgeE;
459 PShapeIteratorPtr eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
460 while ( const TopoDS_Shape* E = eIt->next() )
462 if ( E->IsSame( ridgeE ) || !subEE.Contains( *E ) || !subChecked.Add( *E ))
464 // look for FACEs sharing both E and ridgeE
465 PShapeIteratorPtr fIt = SMESH_MesherHelper::GetAncestors( *E, mesh, TopAbs_FACE );
466 while ( const TopoDS_Shape* F = fIt->next() )
468 if ( !SMESH_MesherHelper::IsSubShape( ridgeE, *F ))
470 if ( !subFF.Contains( *F ))
472 if ( isContinuousMesh( ridgeE, TopoDS::Edge( *E ), TopoDS::Face( *F ), mesh ))
483 // look for the next ridge EDGE ending at V1
484 if ( nextRidgeE.IsNull() )
486 eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
487 while ( const TopoDS_Shape* E = eIt->next() )
488 if ( !ridgeE.IsSame( *E ) && !internEE.Contains( *E ) && subEE.Contains( *E ))
494 ridgeE = TopoDS::Edge( nextRidgeE );
497 if ( ridgeE.IsNull() )
499 } // check EDGEs around the last VERTEX of ridgeE
500 } // loop on ridge EDGEs around a corner VERTEX
501 } // loop on on corner VERTEXes
503 if ( subEE.Extent() > ridgeEE.Extent() + internEE.Extent() ) // PAL23269
504 for ( int i = 1; i < subEE.Extent(); ++i )
505 if ( !ridgeEE.Contains( subEE(i) ))
506 internEE.Add( subEE(i) );
509 } // getInternalEdges()
511 //================================================================================
513 * \brief Find a face including two given nodes
515 //================================================================================
517 const SMDS_MeshElement* FindFaceByNodes( const SMDS_MeshNode* n1,
518 const SMDS_MeshNode* n2,
519 TIDSortedElemSet avoidSet,
520 SMESH_ProxyMesh& mesh)
522 SMDS_ElemIteratorPtr faceIt = mesh.GetInverseElementIterator( n1, SMDSAbs_Face );
523 while ( faceIt->more() )
525 const SMDS_MeshElement* f = faceIt->next();
526 if ( !avoidSet.count( f ) && f->GetNodeIndex( n2 ) >= 0 )
532 //================================================================================
534 * \brief Check that a segment bounds a face belonging to smOfFaces
536 //================================================================================
538 bool IsSegmentOnSubMeshBoundary( const SMDS_MeshNode* n1,
539 const SMDS_MeshNode* n2,
540 const SMESHDS_SubMesh* smOfFaces,
541 SMESH_ProxyMesh& mesh)
543 TIDSortedElemSet avoidSet;
544 bool faceFound = false;
546 while ( const SMDS_MeshElement* f = FindFaceByNodes( n1, n2, avoidSet, mesh ))
548 if (( faceFound = smOfFaces->Contains( f )))
550 avoidSet.insert( f );
555 //================================================================================
557 * \brief Rearrange block sides according to StdMeshers_BlockRenumber hypothesis
559 //================================================================================
561 bool arrangeForRenumber( list< _QuadFaceGrid >& blockSides,
562 const TopTools_MapOfShape& cornerVertices,
565 TopoDS_Vertex& v001 )
569 // block CS is not defined;
570 // renumber only if the block has an edge parallel to an axis of global CS
572 v000 = StdMeshers_RenumberHelper::GetVertex000( cornerVertices );
576 for ( auto it = cornerVertices.cbegin(); it != cornerVertices.cend(); ++it )
577 bbox.Add( BRep_Tool::Pnt( TopoDS::Vertex( *it )));
578 double tol = 1e-5 * Sqrt( bbox.SquareExtent() );
580 // get block edges starting at v000
582 std::vector< const _FaceSide* > edgesAtV000;
583 std::vector< gp_Vec > edgeDir;
584 std::vector< int > iParallel; // 0 - none, 1 - X, 2 - Y, 3 - Z
585 TopTools_MapOfShape lastVertices;
586 for ( _QuadFaceGrid & quad: blockSides )
588 for ( int iS = 0; iS < 4 && edgesAtV000.size() < 3; ++iS )
590 const _FaceSide* side = & quad.GetSide( iS );
591 TopoDS_Vertex v1 = side->FirstVertex(), v2 = side->LastVertex();
592 if (( v1.IsSame( v000 ) && !lastVertices.Contains( v2 )) ||
593 ( v2.IsSame( v000 ) && !lastVertices.Contains( v1 )))
595 bool reverse = v2.IsSame( v000 );
598 lastVertices.Add( v2 );
600 edgesAtV000.push_back( side );
602 gp_Pnt pf = BRep_Tool::Pnt( v1 );
603 gp_Pnt pl = BRep_Tool::Pnt( v2 );
604 gp_Vec vec( pf, pl );
605 edgeDir.push_back( vec );
607 iParallel.push_back( 0 );
608 if ( !v001.IsNull() )
610 if ( quad.IsComplex() )
611 for ( _QuadFaceGrid::TChildIterator chIt = quad.GetChildren(); chIt.more(); )
613 const _QuadFaceGrid& child = chIt.next();
614 if ( child.GetSide( iS ).Contain( v001 ))
616 iParallel.back() = 3;
620 else if ( side->Contain( v001 ))
621 iParallel.back() = 3;
625 bool isStraight = true;
626 std::list< TopoDS_Edge > edges;
627 for ( int iE = 0; true; ++iE )
629 TopoDS_Edge edge = side->Edge( iE );
632 edges.push_back( edge );
634 isStraight = SMESH_Algo::IsStraight( edge );
636 // is parallel to a GCS axis?
639 int nbDiff = (( Abs( vec.X() ) > tol ) +
640 ( Abs( vec.Y() ) > tol ) +
641 ( Abs( vec.Z() ) > tol ) );
643 iParallel.back() = ( Abs( vec.X() ) > tol ) ? 1 : ( Abs( vec.Y() ) > tol ) ? 2 : 3;
647 TopoDS_Face nullFace;
648 StdMeshers_FaceSide fSide( nullFace, edges, mesh, true, true );
649 edgeDir.back() = gp_Vec( pf, fSide.Value3d( reverse ? 0.99 : 0.01 ));
655 if ( std::accumulate( iParallel.begin(), iParallel.end(), 0 ) == 0 )
658 // find edge OZ and edge OX
659 const _FaceSide* edgeOZ = nullptr, *edgeOY = nullptr, *edgeOX = nullptr;
660 auto iZIt = std::find( iParallel.begin(), iParallel.end(), 3 );
661 if ( iZIt != iParallel.end() )
663 int i = std::distance( iParallel.begin(), iZIt );
664 edgeOZ = edgesAtV000[ i ];
665 int iE1 = SMESH_MesherHelper::WrapIndex( i + 1, edgesAtV000.size() );
666 int iE2 = SMESH_MesherHelper::WrapIndex( i + 2, edgesAtV000.size() );
667 if (( edgeDir[ iE1 ] ^ edgeDir[ iE2 ] ) * edgeDir[ i ] < 0 )
668 std::swap( iE1, iE2 );
669 edgeOX = edgesAtV000[ iE1 ];
670 edgeOY = edgesAtV000[ iE2 ];
674 for ( size_t i = 0; i < edgesAtV000.size(); ++i )
676 if ( !iParallel[ i ] )
678 int iE1 = SMESH_MesherHelper::WrapIndex( i + 1, edgesAtV000.size() );
679 int iE2 = SMESH_MesherHelper::WrapIndex( i + 2, edgesAtV000.size() );
680 if (( edgeDir[ iE1 ] ^ edgeDir[ iE2 ] ) * edgeDir[ i ] < 0 )
681 std::swap( iE1, iE2 );
682 edgeOZ = edgesAtV000[ iParallel[i] == 1 ? iE2 : iE1 ];
683 edgeOX = edgesAtV000[ iParallel[i] == 1 ? i : iE1 ];
684 edgeOY = edgesAtV000[ iParallel[i] == 1 ? iE1 : i ];
689 if ( !edgeOZ || !edgeOX || !edgeOY )
692 TopoDS_Vertex v100 = edgeOX->LastVertex();
693 if ( v100.IsSame( v000 ))
694 v100 = edgeOX->FirstVertex();
696 // Find the left quad, one including v000 but not v100
698 for ( auto quad = blockSides.begin(); quad != blockSides.end(); ++quad )
700 if ( quad->Contain( v000 ) && !quad->Contain( v100 )) // it's a left quad
702 if ( quad != blockSides.begin() )
703 blockSides.splice( blockSides.begin(), blockSides, quad );
704 blockSides.front().SetBottomSide( *edgeOZ ); // edgeOY
714 //================================================================================
716 * \brief Tries to find 6 sides of a box
718 //================================================================================
720 bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape& shape,
721 list< _QuadFaceGrid >& boxFaces,
723 SMESH_ProxyMesh& proxyMesh,
725 _QuadFaceGrid * & fBottom,
726 _QuadFaceGrid * & fTop,
727 _QuadFaceGrid * & fFront,
728 _QuadFaceGrid * & fBack,
729 _QuadFaceGrid * & fLeft,
730 _QuadFaceGrid * & fRight)
732 TopTools_MapOfShape cornerVertices;
733 getBlockCorners( proxyMesh, shape, cornerVertices );
734 if ( cornerVertices.Extent() != 8 )
735 return error( COMPERR_BAD_INPUT_MESH, "Can't find 8 corners of a block by 2D mesh" );
736 TopTools_MapOfShape internalEdges;
737 if ( !getInternalEdges( mesh, shape, cornerVertices, internalEdges ))
738 return error( COMPERR_BAD_INPUT_MESH, "2D mesh is not suitable for i,j,k hexa meshing" );
740 list< _QuadFaceGrid >::iterator boxFace;
743 for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFaces )
746 if ( !f.Init( TopoDS::Face( exp.Current() ), proxyMesh ))
747 return error (COMPERR_BAD_SHAPE);
749 _QuadFaceGrid* prevContinuous = 0;
750 for ( boxFace = boxFaces.begin(); boxFace != boxFaces.end(); ++boxFace )
752 if ( prevContinuous )
754 if ( prevContinuous->AddContinuousFace( *boxFace, internalEdges ))
755 boxFace = --boxFaces.erase( boxFace );
757 else if ( boxFace->AddContinuousFace( f, internalEdges ))
759 prevContinuous = & (*boxFace);
762 if ( !prevContinuous )
763 boxFaces.push_back( f );
765 // Check what we have
766 if ( boxFaces.size() != 6 && nbFaces != 6)
769 SMESH_Comment("Can't find 6 sides of a box. Number of found sides - ")<<boxFaces.size());
771 if ( boxFaces.size() != 6 && nbFaces == 6 ) { // strange ordinary box with continuous faces
772 boxFaces.resize( 6 );
773 boxFace = boxFaces.begin();
774 for ( exp.Init( shape, TopAbs_FACE); exp.More(); exp.Next(), ++boxFace )
775 boxFace->Init( TopoDS::Face( exp.Current() ), proxyMesh );
778 toRenumber = _blockRenumberHyp;
781 TopoDS_Vertex v000, v001;
782 _blockRenumberHyp->IsSolidIncluded( mesh, shape, v000, v001 );
784 toRenumber = arrangeForRenumber( boxFaces, cornerVertices, &mesh, v000, v001 );
788 mesh.GetMeshDS()->Modified();
789 mesh.GetMeshDS()->CompactMesh(); // remove numbering holes
793 // ----------------------------------------
794 // Find out position of faces within a box
795 // ----------------------------------------
796 // start from a bottom face
797 fBottom = &boxFaces.front();
798 fBottom->SetID( B_BOTTOM );
799 // find vertical faces
800 fFront = fBottom->FindAdjacentForSide( Q_BOTTOM, boxFaces, B_FRONT );
801 fLeft = fBottom->FindAdjacentForSide( Q_RIGHT, boxFaces, B_LEFT );
802 fBack = fBottom->FindAdjacentForSide( Q_TOP, boxFaces, B_BACK );
803 fRight = fBottom->FindAdjacentForSide( Q_LEFT, boxFaces, B_RIGHT );
805 if ( !fFront || !fBack || !fLeft || !fRight )
806 return error(COMPERR_BAD_SHAPE);
809 for ( boxFace = ++boxFaces.begin(); boxFace != boxFaces.end() && !fTop; ++boxFace )
812 fTop->SetID( B_TOP );
813 if ( fTop==fFront || fTop==fLeft || fTop==fBack || fTop==fRight )
816 // set bottom of the top side
817 if ( !fTop->SetBottomSide( fFront->GetSide( Q_TOP ) )) {
818 if ( !fFront->IsComplex() )
819 return error( ERR_LI("Error in StdMeshers_CompositeHexa_3D::Compute()"));
821 _QuadFaceGrid::TChildIterator chIt = fFront->GetChildren();
822 while ( chIt.more() ) {
823 const _QuadFaceGrid& frontChild = chIt.next();
824 if ( fTop->SetBottomSide( frontChild.GetSide( Q_TOP )))
830 return error(COMPERR_BAD_SHAPE);
832 // orient bottom edge of faces along axes of the unit box
833 fBottom->ReverseEdges();
834 fBack ->ReverseEdges();
835 fLeft ->ReverseEdges();
840 //================================================================================
842 * \brief Computes hexahedral mesh on a box with composite sides
843 * \param aMesh - mesh to compute
844 * \param aShape - shape to mesh
845 * \retval bool - success sign
847 //================================================================================
849 bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh& theMesh,
850 const TopoDS_Shape& theShape)
852 SMESH_MesherHelper helper( theMesh );
853 _quadraticMesh = helper.IsQuadraticSubMesh( theShape );
854 helper.SetElementsOnShape( true );
857 SMESH_ProxyMesh::Ptr proxyMesh;
858 SMESH_HypoFilter vlFilter( SMESH_HypoFilter::HasName( StdMeshers_ViscousLayers::GetHypType() ));
859 const SMESH_Hypothesis * hyp = theMesh.GetHypothesis( theShape, vlFilter, true );
860 const StdMeshers_ViscousLayers* vlHyp = static_cast< const StdMeshers_ViscousLayers* >( hyp );
862 proxyMesh = vlHyp->Compute( theMesh, theShape, /*toMakeN2NMap=*/true );
864 proxyMesh.reset( new SMESH_ProxyMesh( theMesh ));
866 // -------------------------
867 // Try to find 6 side faces
868 // -------------------------
869 list< _QuadFaceGrid > boxFaceContainer;
870 bool toRenumber = false;
871 _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
872 if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh, toRenumber,
873 fBottom, fTop, fFront, fBack, fLeft, fRight))
876 // ------------------------------------------
877 // Fill columns of nodes with existing nodes
878 // ------------------------------------------
880 // let faces load their grids
881 if ( !fBottom->LoadGrid( *proxyMesh )) return error( fBottom->GetError() );
882 if ( !fBack ->LoadGrid( *proxyMesh )) return error( fBack ->GetError() );
883 if ( !fLeft ->LoadGrid( *proxyMesh )) return error( fLeft ->GetError() );
884 if ( !fFront ->LoadGrid( *proxyMesh )) return error( fFront ->GetError() );
885 if ( !fRight ->LoadGrid( *proxyMesh )) return error( fRight ->GetError() );
886 if ( !fTop ->LoadGrid( *proxyMesh )) return error( fTop ->GetError() );
888 // compute normalized parameters of nodes on sides (PAL23189)
889 fBottom->ComputeIJK( COO_X, COO_Y, /*z=*/0. );
890 fBack ->ComputeIJK( COO_X, COO_Z, /*y=*/1. );
891 fLeft ->ComputeIJK( COO_Y, COO_Z, /*x=*/0. );
892 fFront ->ComputeIJK( COO_X, COO_Z, /*y=*/0. );
893 fRight ->ComputeIJK( COO_Y, COO_Z, /*x=*/1. );
894 fTop ->ComputeIJK( COO_X, COO_Y, /*z=*/1. );
896 StdMeshers_RenumberHelper renumHelper( theMesh, _blockRenumberHyp );
898 int x, xSize = fBottom->GetNbHoriSegments(*proxyMesh) + 1, X = xSize - 1;
899 int y, ySize = fBottom->GetNbVertSegments(*proxyMesh) + 1, Y = ySize - 1;
900 int z, zSize = fFront ->GetNbVertSegments(*proxyMesh) + 1, Z = zSize - 1;
901 _Indexer colIndex( xSize, ySize );
902 vector< vector< const SMDS_MeshNode* > > columns( colIndex.size() );
904 // fill node columns by front and back box sides
905 for ( x = 0; x < xSize; ++x ) {
906 vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( x, 0 )];
907 vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( x, Y )];
908 column0.resize( zSize );
909 column1.resize( zSize );
910 for ( z = 0; z < zSize; ++z ) {
911 column0[ z ] = fFront->GetNode( x, z );
912 column1[ z ] = fBack ->GetNode( x, z );
915 // fill node columns by left and right box sides
916 for ( y = 1; y < ySize-1; ++y ) {
917 vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( 0, y )];
918 vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( X, y )];
919 column0.resize( zSize );
920 column1.resize( zSize );
921 for ( z = 0; z < zSize; ++z ) {
922 column0[ z ] = fLeft ->GetNode( y, z );
923 column1[ z ] = fRight->GetNode( y, z );
926 // get nodes from top and bottom box sides
927 for ( x = 1; x < xSize-1; ++x ) {
928 for ( y = 1; y < ySize-1; ++y ) {
929 vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
930 column.resize( zSize );
931 column.front() = fBottom->GetNode( x, y );
932 column.back() = fTop ->GetNode( x, y );
936 // ----------------------------
937 // Add internal nodes of a box
938 // ----------------------------
939 // projection points of internal nodes on box sub-shapes by which
940 // coordinates of internal nodes are computed
941 vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
943 // projections on vertices are constant
944 pointsOnShapes[ SMESH_Block::ID_V000 ] = fBottom->GetXYZ( 0, 0 );
945 pointsOnShapes[ SMESH_Block::ID_V100 ] = fBottom->GetXYZ( X, 0 );
946 pointsOnShapes[ SMESH_Block::ID_V010 ] = fBottom->GetXYZ( 0, Y );
947 pointsOnShapes[ SMESH_Block::ID_V110 ] = fBottom->GetXYZ( X, Y );
948 pointsOnShapes[ SMESH_Block::ID_V001 ] = fTop->GetXYZ( 0, 0 );
949 pointsOnShapes[ SMESH_Block::ID_V101 ] = fTop->GetXYZ( X, 0 );
950 pointsOnShapes[ SMESH_Block::ID_V011 ] = fTop->GetXYZ( 0, Y );
951 pointsOnShapes[ SMESH_Block::ID_V111 ] = fTop->GetXYZ( X, Y );
953 gp_XYZ params; // normalized parameters of an internal node within the unit box
956 for ( y = 0; y < ySize; ++y )
958 vector< const SMDS_MeshNode* >& columnXy = columns[ colIndex( X, y )];
959 for ( z = 0; z < zSize; ++z )
960 renumHelper.AddReplacingNode( columnXy[ z ] );
963 for ( x = X-1; x > 0; --x )
967 vector< const SMDS_MeshNode* >& columnX0 = columns[ colIndex( x, 0 )];
968 for ( z = 0; z < zSize; ++z )
969 renumHelper.AddReplacingNode( columnX0[ z ] );
972 const double rX = x / double(X);
973 for ( y = 1; y < ySize-1; ++y )
975 const double rY = y / double(Y);
976 // column to fill during z loop
977 vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
978 // points projections on horizontal edges
979 pointsOnShapes[ SMESH_Block::ID_Ex00 ] = fBottom->GetXYZ( x, 0 );
980 pointsOnShapes[ SMESH_Block::ID_Ex10 ] = fBottom->GetXYZ( x, Y );
981 pointsOnShapes[ SMESH_Block::ID_E0y0 ] = fBottom->GetXYZ( 0, y );
982 pointsOnShapes[ SMESH_Block::ID_E1y0 ] = fBottom->GetXYZ( X, y );
983 pointsOnShapes[ SMESH_Block::ID_Ex01 ] = fTop->GetXYZ( x, 0 );
984 pointsOnShapes[ SMESH_Block::ID_Ex11 ] = fTop->GetXYZ( x, Y );
985 pointsOnShapes[ SMESH_Block::ID_E0y1 ] = fTop->GetXYZ( 0, y );
986 pointsOnShapes[ SMESH_Block::ID_E1y1 ] = fTop->GetXYZ( X, y );
987 // points projections on horizontal faces
988 pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = fBottom->GetXYZ( x, y );
989 pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = fTop ->GetXYZ( x, y );
992 renumHelper.AddReplacingNode( column[ 0 ] );
994 for ( z = 1; z < zSize-1; ++z ) // z loop
996 // compute normalized parameters of an internal node within the unit box
997 const double rZ = z / double(Z);
998 const gp_XYZ& pBo = fBottom->GetIJK( x, y );
999 const gp_XYZ& pTo = fTop ->GetIJK( x, y );
1000 const gp_XYZ& pFr = fFront ->GetIJK( x, z );
1001 const gp_XYZ& pBa = fBack ->GetIJK( x, z );
1002 const gp_XYZ& pLe = fLeft ->GetIJK( y, z );
1003 const gp_XYZ& pRi = fRight ->GetIJK( y, z );
1004 params.SetCoord( 1, 0.5 * ( pBo.X() * ( 1. - rZ ) + pTo.X() * rZ +
1005 pFr.X() * ( 1. - rY ) + pBa.X() * rY ));
1006 params.SetCoord( 2, 0.5 * ( pBo.Y() * ( 1. - rZ ) + pTo.Y() * rZ +
1007 pLe.Y() * ( 1. - rX ) + pRi.Y() * rX ));
1008 params.SetCoord( 3, 0.5 * ( pFr.Z() * ( 1. - rY ) + pBa.Z() * rY +
1009 pLe.Z() * ( 1. - rX ) + pRi.Z() * rX ));
1011 // point projections on vertical edges
1012 pointsOnShapes[ SMESH_Block::ID_E00z ] = fFront->GetXYZ( 0, z );
1013 pointsOnShapes[ SMESH_Block::ID_E10z ] = fFront->GetXYZ( X, z );
1014 pointsOnShapes[ SMESH_Block::ID_E01z ] = fBack->GetXYZ( 0, z );
1015 pointsOnShapes[ SMESH_Block::ID_E11z ] = fBack->GetXYZ( X, z );
1016 // point projections on vertical faces
1017 pointsOnShapes[ SMESH_Block::ID_Fx0z ] = fFront->GetXYZ( x, z );
1018 pointsOnShapes[ SMESH_Block::ID_Fx1z ] = fBack ->GetXYZ( x, z );
1019 pointsOnShapes[ SMESH_Block::ID_F0yz ] = fLeft ->GetXYZ( y, z );
1020 pointsOnShapes[ SMESH_Block::ID_F1yz ] = fRight->GetXYZ( y, z );
1022 // compute internal node coordinates
1024 SMESH_Block::ShellPoint( params, pointsOnShapes, coords );
1025 column[ z ] = helper.AddNode( coords.X(), coords.Y(), coords.Z() );
1029 //cout << "----------------------------------------------------------------------"<<endl;
1030 //for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id)
1032 // gp_XYZ p = pointsOnShapes[ id ];
1033 // SMESH_Block::DumpShapeID( id,cout)<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;
1035 //cout << "Params: ( "<< params.X()<<", "<<params.Y()<<", "<<params.Z()<<" )"<<endl;
1036 //cout << "coords: ( "<< coords.X()<<", "<<coords.Y()<<", "<<coords.Z()<<" )"<<endl;
1040 renumHelper.AddReplacingNode( column[ Z ] );
1045 vector< const SMDS_MeshNode* >& columnXY = columns[ colIndex( x, Y )];
1046 for ( z = 0; z < zSize; ++z )
1047 renumHelper.AddReplacingNode( columnXY[ z ] );
1049 } // for ( x = X-1; x > 0; --x )
1052 for ( y = 0; y < ySize; ++y )
1054 vector< const SMDS_MeshNode* >& column0Y = columns[ colIndex( 0, y )];
1055 for ( z = 0; z < zSize; ++z )
1056 renumHelper.AddReplacingNode( column0Y[ z ] );
1060 // faces no more needed, free memory
1061 boxFaceContainer.clear();
1066 for ( x = xSize-2; true; --x ) {
1067 for ( y = 0; y < ySize-1; ++y ) {
1068 vector< const SMDS_MeshNode* >& col00 = columns[ colIndex( x, y )];
1069 vector< const SMDS_MeshNode* >& col10 = columns[ colIndex( x+1, y )];
1070 vector< const SMDS_MeshNode* >& col01 = columns[ colIndex( x, y+1 )];
1071 vector< const SMDS_MeshNode* >& col11 = columns[ colIndex( x+1, y+1 )];
1072 for ( z = 0; z < zSize-1; ++z )
1074 // bottom face normal of a hexa mush point outside the volume
1075 helper.AddVolume(col10[z], col11[z], col11[z+1], col10[z+1],
1076 col00[z], col01[z], col01[z+1], col00[z+1]);
1084 renumHelper.DoReplaceNodes();
1086 if ( _blockRenumberHyp )
1088 return error( _blockRenumberHyp->CheckHypothesis( theMesh, theShape ));
1094 //================================================================================
1098 //================================================================================
1100 bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh& theMesh,
1101 const TopoDS_Shape& theShape,
1102 MapShapeNbElems& aResMap)
1104 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
1106 // -------------------------
1107 // Try to find 6 side faces
1108 // -------------------------
1109 list< _QuadFaceGrid > boxFaceContainer;
1110 _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
1111 bool toRenumber = false;
1112 if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh, toRenumber,
1113 fBottom, fTop, fFront, fBack, fLeft, fRight))
1116 // Find a less complex side
1117 _QuadFaceGrid * lessComplexSide = & boxFaceContainer.front();
1118 list< _QuadFaceGrid >::iterator face = boxFaceContainer.begin();
1119 for ( ++face; face != boxFaceContainer.end() && lessComplexSide->IsComplex(); ++face )
1120 if ( face->NbChildren() < lessComplexSide->NbChildren() )
1121 lessComplexSide = & *face;
1123 // Get an 1D size of lessComplexSide
1124 smIdType nbSeg1 = 0;
1125 vector<TopoDS_Edge> edges;
1126 if ( !lessComplexSide->GetHoriEdges(edges) )
1128 for ( size_t i = 0; i < edges.size(); ++i )
1130 const vector<smIdType>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1131 if ( !nbElems.empty() )
1132 nbSeg1 += std::max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1135 // Get an 1D size of a box side orthogonal to lessComplexSide
1136 smIdType nbSeg2 = 0;
1137 _QuadFaceGrid* ortoSide =
1138 lessComplexSide->FindAdjacentForSide( Q_LEFT, boxFaceContainer, B_UNDEFINED );
1140 if ( !ortoSide || !ortoSide->GetHoriEdges(edges) ) return false;
1141 for ( size_t i = 0; i < edges.size(); ++i )
1143 const vector<smIdType>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1144 if ( !nbElems.empty() )
1145 nbSeg2 += std::max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1148 // Get an 2D size of a box side orthogonal to lessComplexSide
1149 smIdType nbFaces = 0, nbQuadFace = 0;
1150 list< TopoDS_Face > sideFaces;
1151 if ( ortoSide->IsComplex() )
1152 for ( _QuadFaceGrid::TChildIterator child = ortoSide->GetChildren(); child.more(); )
1153 sideFaces.push_back( child.next().GetFace() );
1155 sideFaces.push_back( ortoSide->GetFace() );
1157 list< TopoDS_Face >::iterator f = sideFaces.begin();
1158 for ( ; f != sideFaces.end(); ++f )
1160 const vector<smIdType>& nbElems = aResMap[ theMesh.GetSubMesh( *f )];
1161 if ( !nbElems.empty() )
1163 nbFaces = nbElems[ SMDSEntity_Quadrangle ];
1164 nbQuadFace = nbElems[ SMDSEntity_Quad_Quadrangle ];
1168 // Fill nb of elements
1169 vector<smIdType> aResVec(SMDSEntity_Last,0);
1170 smIdType nbSeg3 = ( nbFaces + nbQuadFace ) / nbSeg2;
1171 aResVec[SMDSEntity_Node] = (nbSeg1-1) * (nbSeg2-1) * (nbSeg3-1);
1172 aResVec[SMDSEntity_Hexa] = nbSeg1 * nbFaces;
1173 aResVec[SMDSEntity_Quad_Hexa] = nbSeg1 * nbQuadFace;
1175 aResMap.insert( make_pair( theMesh.GetSubMesh(theShape), aResVec ));
1181 //================================================================================
1183 * \brief constructor of non-initialized _QuadFaceGrid
1185 //================================================================================
1187 _QuadFaceGrid::_QuadFaceGrid():
1188 myReverse(false), myRightBrother(0), myUpBrother(0), myIndexer(0,0), myID(B_UNDEFINED)
1192 //================================================================================
1194 * \brief Initialization
1196 //================================================================================
1198 bool _QuadFaceGrid::Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh)
1201 mySides = _FaceSide();
1203 myLeftBottomChild = myRightBrother = myUpBrother = 0;
1206 //if ( myFace.Orientation() != TopAbs_FORWARD )
1209 list< TopoDS_Edge > edges;
1210 list< int > nbEdgesInWire;
1211 int nbWire = SMESH_Block::GetOrderedEdges (myFace, edges, nbEdgesInWire);
1215 list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1216 if ( nbEdgesInWire.front() == 4 ) // exactly 4 edges
1218 for ( ; edgeIt != edges.end(); ++edgeIt )
1219 mySides.AppendSide( _FaceSide( *edgeIt ));
1221 else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
1222 list< TopoDS_Edge > sideEdges;
1223 while ( !edges.empty()) {
1225 sideEdges.splice( sideEdges.end(), edges, edges.begin());// edges.front()->sideEdges.back()
1226 if ( SMESH_Algo::isDegenerated( sideEdges.back() ))
1228 while ( !edges.empty() ) {
1229 if ( isContinuousMesh( sideEdges.back(), edges.front(), f, mesh )) {
1230 sideEdges.splice( sideEdges.end(), edges, edges.begin());
1232 else if ( isContinuousMesh( sideEdges.front(), edges.back(), f, mesh )) {
1233 sideEdges.splice( sideEdges.begin(), edges, --edges.end());
1239 mySides.AppendSide( _FaceSide( sideEdges ));
1242 if (mySides.size() != 4)
1245 if (SALOME::VerbosityActivated())
1247 mySides.GetSide( Q_BOTTOM )->SetID( Q_BOTTOM );
1248 mySides.GetSide( Q_RIGHT )->SetID( Q_RIGHT );
1249 mySides.GetSide( Q_TOP )->SetID( Q_TOP );
1250 mySides.GetSide( Q_LEFT )->SetID( Q_LEFT );
1256 //================================================================================
1258 * \brief Try to unite self with other ordinary face
1260 //================================================================================
1262 bool _QuadFaceGrid::AddContinuousFace( const _QuadFaceGrid& other,
1263 const TopTools_MapOfShape& internalEdges)
1265 for ( int i = 0; i < 4; ++i )
1267 const _FaceSide& otherSide = other.GetSide( i );
1269 if ( mySides.Contain( otherSide, &iMyCommon ))
1271 if ( internalEdges.Contains( otherSide.Edge( 0 )))
1273 DUMP_VERT("Cont 1", mySides.GetSide(iMyCommon)->FirstVertex());
1274 DUMP_VERT("Cont 2", mySides.GetSide(iMyCommon)->LastVertex());
1275 DUMP_VERT("Cont 3", otherSide.FirstVertex());
1276 DUMP_VERT("Cont 4", otherSide.LastVertex());
1278 if ( myChildren.empty() )
1280 myChildren.push_back( *this );
1283 else // find iMyCommon in myChildren
1285 for ( TChildIterator children = GetChildren(); children.more(); ) {
1286 const _QuadFaceGrid& child = children.next();
1287 if ( child.mySides.Contain( otherSide, &iMyCommon ))
1292 // orient new children equally
1293 int otherBottomIndex = SMESH_MesherHelper::WrapIndex( i - iMyCommon + 2, 4 );
1294 if ( other.IsComplex() )
1295 for ( TChildIterator children = other.GetChildren(); children.more(); ) {
1296 myChildren.push_back( children.next() );
1297 myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1300 myChildren.push_back( other );
1301 myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1304 myLeftBottomChild = 0;
1306 // collect vertices in mySides
1307 if ( other.IsComplex() )
1308 for ( TChildIterator children = other.GetChildren(); children.more(); )
1310 const _QuadFaceGrid& child = children.next();
1311 for ( int i = 0; i < 4; ++i )
1312 mySides.AppendSide( child.GetSide(i) );
1315 for ( int i = 0; i < 4; ++i )
1316 mySides.AppendSide( other.GetSide(i) );
1325 //================================================================================
1327 * \brief Try to set the side as bottom hirizontal side
1329 //================================================================================
1331 bool _QuadFaceGrid::SetBottomSide(const _FaceSide& bottom, int* sideIndex)
1333 myLeftBottomChild = myRightBrother = myUpBrother = 0;
1336 if ( myChildren.empty() )
1338 if ( mySides.Contain( bottom, &myBottomIndex )) {
1339 mySides.SetBottomSide( myBottomIndex );
1341 *sideIndex = myBottomIndex;
1347 TChildren::iterator childFace = myChildren.begin(), childEnd = myChildren.end();
1348 for ( ; childFace != childEnd; ++childFace )
1350 if ( childFace->SetBottomSide( bottom, &myBottomIndex ))
1352 TChildren::iterator orientedChild = childFace;
1353 for ( childFace = myChildren.begin(); childFace != childEnd; ++childFace ) {
1354 if ( childFace != orientedChild )
1355 childFace->SetBottomSide( childFace->GetSide( myBottomIndex ));
1358 *sideIndex = myBottomIndex;
1366 //================================================================================
1368 * \brief Return face adjacent to i-th side of this face, (0<i<4)
1370 //================================================================================
1372 _QuadFaceGrid* _QuadFaceGrid::FindAdjacentForSide(int i,
1373 list<_QuadFaceGrid>& faces,
1376 const _FaceSide & iSide = GetSide( i );
1377 list< _QuadFaceGrid >::iterator boxFace = faces.begin();
1378 for ( ; boxFace != faces.end(); ++boxFace )
1380 _QuadFaceGrid* f = & (*boxFace);
1381 if ( f != this && f->SetBottomSide( iSide ))
1382 return f->SetID( id ), f;
1384 return (_QuadFaceGrid*) 0;
1387 //================================================================================
1389 * \brief Return i-th side
1391 //================================================================================
1393 const _FaceSide& _QuadFaceGrid::GetSide(int i) const
1395 if ( myChildren.empty() )
1396 return *mySides.GetSide(i);
1398 _QuadFaceGrid* me = const_cast<_QuadFaceGrid*>(this);
1399 if ( !me->locateChildren() || !myLeftBottomChild )
1400 return *mySides.GetSide(i);
1402 const _QuadFaceGrid* child = myLeftBottomChild;
1408 while ( child->myRightBrother )
1409 child = child->myRightBrother;
1412 while ( child->myUpBrother )
1413 child = child->myUpBrother;
1417 return child->GetSide( i );
1420 //================================================================================
1422 * \brief Reverse edges in order to have them oriented along axes of the unit box
1424 //================================================================================
1426 void _QuadFaceGrid::ReverseEdges()
1428 myReverse = !myReverse;
1431 // if ( !myFace.IsNull() )
1432 // TopAbs::Print(myFace.Orientation(), cout);
1435 if ( myChildren.empty() )
1442 TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1443 for ( ; child != childEnd; ++child )
1444 child->ReverseEdges();
1448 //================================================================================
1450 * \brief Load nodes of a mesh
1452 //================================================================================
1454 bool _QuadFaceGrid::LoadGrid( SMESH_ProxyMesh& mesh )
1456 if ( !myChildren.empty() )
1458 // Let child faces load their grids
1459 TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1460 for ( ; child != childEnd; ++child ) {
1461 child->SetID( myID );
1462 if ( !child->LoadGrid( mesh ) )
1463 return error( child->GetError() );
1465 // Fill myGrid with nodes of patches
1466 return loadCompositeGrid( mesh );
1469 // ---------------------------------------
1470 // Fill myGrid with nodes bound to myFace
1471 // ---------------------------------------
1473 if ( !myGrid.empty() )
1476 const SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace );
1478 // check that all faces are quadrangular
1479 SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
1480 while ( fIt->more() )
1481 if ( fIt->next()->NbNodes() % 4 > 0 )
1482 return error("Non-quadrangular mesh faces are not allowed on sides of a composite block");
1484 bool isProxy = false, isTmpElem = false;
1485 if ( faceSubMesh && faceSubMesh->NbElements() > 0 )
1487 isProxy = dynamic_cast< const SMESH_ProxyMesh::SubMesh* >( faceSubMesh );
1488 isTmpElem = mesh.IsTemporary( faceSubMesh->GetElements()->next() );
1490 const SMESHDS_SubMesh* smToCheckEdges = ( isProxy && !isTmpElem ) ? faceSubMesh : 0;
1492 myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh, smToCheckEdges );
1493 myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT )->GetNbSegments( mesh, smToCheckEdges );
1495 myGrid.resize( myIndexer.size() );
1497 // store nodes bound to the bottom edge
1498 mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse, isProxy, smToCheckEdges );
1500 // store the rest nodes row by row
1502 TIDSortedElemSet avoidSet;
1503 const SMDS_MeshElement* firstQuad = 0; // most left face above the last row of found nodes
1505 size_t nbFoundNodes = myIndexer._xSize;
1506 while ( nbFoundNodes != myGrid.size() )
1508 // first and last nodes of the last filled row of nodes
1509 const SMDS_MeshNode* n1down = myGrid[ nbFoundNodes - myIndexer._xSize ];
1510 const SMDS_MeshNode* n2down = myGrid[ nbFoundNodes - myIndexer._xSize + 1];
1511 const SMDS_MeshNode* n1downLast = myGrid[ nbFoundNodes-1 ];
1513 // find the first face above the row by the first two left nodes
1521 firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh );
1522 while ( firstQuad && !faceSubMesh->Contains( firstQuad )) {
1523 avoidSet.insert( firstQuad );
1524 firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh);
1526 if ( !firstQuad || !faceSubMesh->Contains( firstQuad ))
1527 return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1529 // find the node of quad bound to the left geom edge
1530 int i2down = firstQuad->GetNodeIndex( n2down );
1531 const SMDS_MeshNode* n1up = firstQuad->GetNode(( i2down+2 ) % 4 );
1532 myGrid[ nbFoundNodes++ ] = n1up;
1533 // the 4-the node of the first quad
1534 int i1down = firstQuad->GetNodeIndex( n1down );
1535 const SMDS_MeshNode* n2up = firstQuad->GetNode(( i1down+2 ) % 4 );
1536 myGrid[ nbFoundNodes++ ] = n2up;
1540 const SMDS_MeshElement* quad = firstQuad;
1542 // find the rest nodes by remaining faces above the row
1550 while ( n1down != n1downLast )
1553 avoidSet.clear(); avoidSet.insert( quad );
1554 quad = FindFaceByNodes( n1down, n1up, avoidSet, mesh );
1555 if ( !quad || quad->NbNodes() % 4 > 0)
1556 return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1559 if ( quad->GetNode( i1down ) != n1down ) // check already found index
1560 i1down = quad->GetNodeIndex( n1down );
1561 n2up = quad->GetNode(( i1down+2 ) % 4 );
1562 myGrid[ nbFoundNodes++ ] = n2up;
1564 n1down = myGrid[ nbFoundNodes - myIndexer._xSize - 1 ];
1567 avoidSet.clear(); avoidSet.insert( firstQuad );
1569 DumpGrid(); // debug
1574 //================================================================================
1576 * \brief Fill myIJK with normalized parameters of nodes in myGrid
1577 * \param [in] i1 - coordinate index along rows of myGrid
1578 * \param [in] i2 - coordinate index along columns of myGrid
1579 * \param [in] v3 - value of the constant parameter
1581 //================================================================================
1583 void _QuadFaceGrid::ComputeIJK( int i1, int i2, double v3 )
1585 gp_XYZ ijk( v3, v3, v3 );
1586 myIJK.resize( myIndexer.size(), ijk );
1588 const size_t nbCol = myIndexer._xSize;
1589 const size_t nbRow = myIndexer._ySize;
1591 vector< double > len( nbRow );
1593 for ( size_t i = 0; i < nbCol; ++i )
1595 gp_Pnt pPrev = GetXYZ( i, 0 );
1596 for ( size_t j = 1; j < nbRow; ++j )
1598 gp_Pnt p = GetXYZ( i, j );
1599 len[ j ] = len[ j-1 ] + p.Distance( pPrev );
1602 for ( size_t j = 0; j < nbRow; ++j )
1603 GetIJK( i, j ).SetCoord( i2, len[ j ]/len.back() );
1606 len.resize( nbCol );
1607 for ( size_t j = 0; j < nbRow; ++j )
1609 gp_Pnt pPrev = GetXYZ( 0, j );
1610 for ( size_t i = 1; i < nbCol; ++i )
1612 gp_Pnt p = GetXYZ( i, j );
1613 len[ i ] = len[ i-1 ] + p.Distance( pPrev );
1616 for ( size_t i = 0; i < nbCol; ++i )
1617 GetIJK( i, j ).SetCoord( i1, len[ i ]/len.back() );
1621 //================================================================================
1623 * \brief Find out mutual location of children: find their right and up brothers
1625 //================================================================================
1627 bool _QuadFaceGrid::locateChildren()
1629 if ( myLeftBottomChild )
1632 TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1634 // find a child sharing it's first bottom vertex with no other brother
1635 myLeftBottomChild = 0;
1636 for ( ; !myLeftBottomChild && child != childEnd; ++child )
1638 TopoDS_Vertex leftVertex = child->GetSide( Q_BOTTOM ).FirstVertex();
1639 bool sharedVertex = false;
1640 TChildren::iterator otherChild = myChildren.begin();
1641 for ( ; otherChild != childEnd && !sharedVertex; ++otherChild )
1642 if ( otherChild != child )
1643 sharedVertex = otherChild->mySides.Contain( leftVertex );
1644 if ( !sharedVertex ) {
1645 myLeftBottomChild = & (*child);
1646 DUMP_VERT("0 left bottom Vertex: ",leftVertex );
1649 if (!myLeftBottomChild)
1650 return error(ERR_LI("Error in locateChildren()"));
1652 set< _QuadFaceGrid* > notLocatedChilren;
1653 for (child = myChildren.begin() ; child != childEnd; ++child )
1654 notLocatedChilren.insert( & (*child));
1656 // connect myLeftBottomChild to it's right and upper brothers
1657 notLocatedChilren.erase( myLeftBottomChild );
1658 myLeftBottomChild->setBrothers( notLocatedChilren );
1659 if ( !notLocatedChilren.empty() )
1660 return error(ERR_LI("Error in locateChildren()"));
1665 //================================================================================
1667 * \brief Fill myGrid with nodes of patches
1669 //================================================================================
1671 bool _QuadFaceGrid::loadCompositeGrid(SMESH_ProxyMesh& mesh)
1673 // Find out mutual location of children: find their right and up brothers
1674 if ( !locateChildren() )
1677 // Load nodes according to mutual location of children
1680 myIndexer._xSize = 1 + myLeftBottomChild->GetNbHoriSegments( mesh, /*withBrothers=*/true );
1681 myIndexer._ySize = 1 + myLeftBottomChild->GetNbVertSegments( mesh, /*withBrothers=*/true );
1683 myGrid.resize( myIndexer.size() );
1685 int fromX = myReverse ? myIndexer._xSize : 0;
1686 if ( !myLeftBottomChild->fillGrid( mesh, myGrid, myIndexer, fromX, 0 ))
1687 return error( myLeftBottomChild->GetError() );
1694 //================================================================================
1696 * \brief Find right an upper brothers among notLocatedBrothers
1698 //================================================================================
1700 void _QuadFaceGrid::setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers )
1702 if ( !notLocatedBrothers.empty() )
1704 // find right brother
1705 TopoDS_Vertex rightVertex = GetSide( Q_BOTTOM ).LastVertex();
1706 DUMP_VERT("1 right bottom Vertex: ",rightVertex );
1707 set< _QuadFaceGrid* >::iterator brIt, brEnd = notLocatedBrothers.end();
1708 for ( brIt = notLocatedBrothers.begin(); brIt != brEnd; ++brIt )
1710 _QuadFaceGrid* brother = *brIt;
1711 TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1712 DUMP_VERT( "brother left bottom: ", brotherLeftVertex );
1713 if ( rightVertex.IsSame( brotherLeftVertex )) {
1714 myRightBrother = brother;
1715 notLocatedBrothers.erase( brIt );
1719 // find upper brother
1720 TopoDS_Vertex upVertex = GetSide( Q_LEFT ).FirstVertex();
1721 DUMP_VERT("1 left up Vertex: ",upVertex);
1722 brIt = notLocatedBrothers.begin(), brEnd = notLocatedBrothers.end();
1723 for ( ; brIt != brEnd; ++brIt )
1725 _QuadFaceGrid* brother = *brIt;
1726 TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1727 DUMP_VERT("brother left bottom: ", brotherLeftVertex);
1728 if ( upVertex.IsSame( brotherLeftVertex )) {
1729 myUpBrother = brother;
1730 notLocatedBrothers.erase( myUpBrother );
1735 if ( myRightBrother )
1736 myRightBrother->setBrothers( notLocatedBrothers );
1738 myUpBrother->setBrothers( notLocatedBrothers );
1742 //================================================================================
1744 * \brief Store nodes of a simple face into grid starting from (x,y) position
1746 //================================================================================
1748 bool _QuadFaceGrid::fillGrid(SMESH_ProxyMesh& theMesh,
1749 vector<const SMDS_MeshNode*> & theGrid,
1750 const _Indexer& theIndexer,
1754 if ( myGrid.empty() && !LoadGrid( theMesh ))
1757 // store my own grid in the global grid
1759 int fromX = myReverse ? theX - myIndexer._xSize: theX;
1761 for ( int i = 0, x = fromX; i < myIndexer._xSize; ++i, ++x )
1762 for ( int j = 0, y = theY; j < myIndexer._ySize; ++j, ++y )
1763 theGrid[ theIndexer( x, y )] = myGrid[ myIndexer( i, j )];
1765 // store grids of my right and upper brothers
1767 if ( myRightBrother )
1772 fromX += myIndexer._xSize - 1;
1773 if ( !myRightBrother->fillGrid( theMesh, theGrid, theIndexer, fromX, theY ))
1774 return error( myRightBrother->GetError() );
1778 if ( !myUpBrother->fillGrid( theMesh, theGrid, theIndexer,
1779 theX, theY + myIndexer._ySize - 1))
1780 return error( myUpBrother->GetError() );
1785 //================================================================================
1787 * \brief Return number of segments on the hirizontal sides
1789 //================================================================================
1791 int _QuadFaceGrid::GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1794 if ( myLeftBottomChild )
1796 nbSegs += myLeftBottomChild->GetNbHoriSegments( mesh, true );
1800 nbSegs = mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
1801 if ( withBrothers && myRightBrother )
1802 nbSegs += myRightBrother->GetNbHoriSegments( mesh, withBrothers );
1807 //================================================================================
1809 * \brief Return number of segments on the vertical sides
1811 //================================================================================
1813 int _QuadFaceGrid::GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1816 if ( myLeftBottomChild )
1818 nbSegs += myLeftBottomChild->GetNbVertSegments( mesh, true );
1822 nbSegs = mySides.GetSide( Q_LEFT )->GetNbSegments(mesh,0);
1823 if ( withBrothers && myUpBrother )
1824 nbSegs += myUpBrother->GetNbVertSegments( mesh, withBrothers );
1829 //================================================================================
1831 * \brief Return edge on the hirizontal bottom sides
1833 //================================================================================
1835 int _QuadFaceGrid::GetHoriEdges(vector<TopoDS_Edge> & edges) const
1837 if ( myLeftBottomChild )
1839 return myLeftBottomChild->GetHoriEdges( edges );
1843 const _FaceSide* bottom = mySides.GetSide( Q_BOTTOM );
1846 TopoDS_Edge e = bottom->Edge( i++ );
1850 edges.push_back( e );
1852 if ( myRightBrother )
1853 myRightBrother->GetHoriEdges( edges );
1855 return edges.size();
1858 //================================================================================
1860 * \brief Return a node by its position
1862 //================================================================================
1864 const SMDS_MeshNode* _QuadFaceGrid::GetNode(int iHori, int iVert) const
1866 return myGrid[ myIndexer( iHori, iVert )];
1869 //================================================================================
1871 * \brief Return node coordinates by its position
1873 //================================================================================
1875 gp_XYZ _QuadFaceGrid::GetXYZ(int iHori, int iVert) const
1877 SMESH_TNodeXYZ xyz = myGrid[ myIndexer( iHori, iVert )];
1881 //================================================================================
1883 * \brief Return normal to the face at vertex v
1885 //================================================================================
1887 bool _QuadFaceGrid::GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const
1889 if ( myChildren.empty() )
1891 if ( mySides.Contain( v )) {
1893 gp_Pnt2d uv = BRep_Tool::Parameters( v, myFace );
1894 BRepAdaptor_Surface surface( myFace );
1895 gp_Pnt p; gp_Vec d1u, d1v;
1896 surface.D1( uv.X(), uv.Y(), p, d1u, d1v );
1897 n = d1u.Crossed( d1v );
1900 catch (Standard_Failure&) {
1907 TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1908 for ( ; child != childEnd; ++child )
1909 if ( child->GetNormal( v, n ))
1915 //================================================================================
1917 * \brief Dumps coordinates of grid nodes
1919 //================================================================================
1921 void _QuadFaceGrid::DumpGrid() const
1924 const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1925 cout << "****** Face " << names[ myID ] << endl;
1927 if ( myChildren.empty() || !myGrid.empty() )
1929 cout << "x size: " << myIndexer._xSize << "; y size: " << myIndexer._ySize << endl;
1930 for ( int y = 0; y < myIndexer._ySize; ++y ) {
1931 cout << "-- row " << y << endl;
1932 for ( int x = 0; x < myIndexer._xSize; ++x ) {
1933 const SMDS_MeshNode* n = myGrid[ myIndexer( x, y ) ];
1934 cout << x << " ( " << n->X() << ", " << n->Y() << ", " << n->Z() << " )" << endl;
1940 cout << "Nb children: " << myChildren.size() << endl;
1941 TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1942 for ( int i=0; child != childEnd; ++child, ++i ) {
1943 cout << " *** SUBFACE " << i+1 << endl;
1944 ((_QuadFaceGrid&)(*child)).SetID( myID );
1951 //================================================================================
1953 * \brief Dump vertices
1955 //================================================================================
1957 void _QuadFaceGrid::DumpVertices() const
1960 cout << "****** Face ";
1961 const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1962 if ( myID >= B_BOTTOM && myID < B_BACK )
1963 cout << names[ myID ] << endl;
1965 cout << "UNDEFINED" << endl;
1967 if ( myChildren.empty() )
1969 for ( int i = 0; i < 4; ++i )
1971 cout << " Side "; mySides.GetSide( i )->Dump();
1976 cout << "-- Nb children: " << myChildren.size() << endl;
1977 TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1978 for ( int i=0; child != childEnd; ++child, ++i ) {
1979 cout << " *** SUBFACE " << i+1 << endl;
1980 ((_QuadFaceGrid&)(*child)).SetID( myID );
1981 child->DumpVertices();
1987 //=======================================================================
1988 //function : _FaceSide
1989 //purpose : copy constructor
1990 //=======================================================================
1992 _FaceSide::_FaceSide(const _FaceSide& other)
1994 myEdge = other.myEdge;
1995 myChildren = other.myChildren;
1996 myNbChildren = other.myNbChildren;
1997 myVertices.Assign( other.myVertices );
2001 //================================================================================
2003 * \brief Construct a face side of one edge
2005 //================================================================================
2007 _FaceSide::_FaceSide(const TopoDS_Edge& edge):
2008 myEdge( edge ), myNbChildren(0)
2010 if ( !edge.IsNull() )
2011 for ( TopExp_Explorer exp( edge, TopAbs_VERTEX ); exp.More(); exp.Next() )
2012 //myVertices.insert( ptr ( exp.Current() ));
2013 myVertices.Add( exp.Current() );
2016 //================================================================================
2018 * \brief Construct a face side of several edges
2020 //================================================================================
2022 _FaceSide::_FaceSide(const list<TopoDS_Edge>& edges):
2025 list<TopoDS_Edge>::const_iterator edge = edges.begin(), eEnd = edges.end();
2026 for ( ; edge != eEnd; ++edge ) {
2027 myChildren.push_back( _FaceSide( *edge ));
2029 myVertices.Add( myChildren.back().FirstVertex() );
2030 myVertices.Add( myChildren.back().LastVertex() );
2031 myChildren.back().SetID( Q_CHILD ); // not to splice them
2035 //=======================================================================
2036 //function : GetSide
2038 //=======================================================================
2040 _FaceSide* _FaceSide::GetSide(const int i)
2042 if ( i >= myNbChildren )
2045 list< _FaceSide >::iterator side = myChildren.begin();
2047 std::advance( side, i );
2051 //=======================================================================
2052 //function : GetSide
2054 //=======================================================================
2056 const _FaceSide* _FaceSide::GetSide(const int i) const
2058 return const_cast< _FaceSide* >(this)->GetSide(i);
2061 //=======================================================================
2062 //function : NbVertices
2063 //purpose : return nb of vertices in the side
2064 //=======================================================================
2066 int _FaceSide::NbVertices() const
2068 if ( myChildren.empty() )
2069 return myVertices.Extent();
2071 return myNbChildren + 1;
2074 //=======================================================================
2075 //function : NbCommonVertices
2076 //purpose : Returns number of my vertices common with the given ones
2077 //=======================================================================
2079 int _FaceSide::NbCommonVertices( const TopTools_MapOfShape& VV ) const
2082 TopTools_MapIteratorOfMapOfShape vIt ( myVertices );
2083 for ( ; vIt.More(); vIt.Next() )
2084 nbCommon += ( VV.Contains( vIt.Key() ));
2089 //=======================================================================
2090 //function : FirstVertex
2092 //=======================================================================
2094 TopoDS_Vertex _FaceSide::FirstVertex() const
2096 if ( myChildren.empty() )
2097 return TopExp::FirstVertex( myEdge, Standard_True );
2099 return myChildren.front().FirstVertex();
2102 //=======================================================================
2103 //function : LastVertex
2105 //=======================================================================
2107 TopoDS_Vertex _FaceSide::LastVertex() const
2109 if ( myChildren.empty() )
2110 return TopExp::LastVertex( myEdge, Standard_True );
2112 return myChildren.back().LastVertex();
2115 //=======================================================================
2118 //=======================================================================
2120 TopoDS_Vertex _FaceSide::Vertex(int i) const
2122 if ( myChildren.empty() )
2123 return i ? LastVertex() : FirstVertex();
2125 if ( i >= myNbChildren )
2126 return myChildren.back().LastVertex();
2128 return GetSide(i)->FirstVertex();
2131 //================================================================================
2133 * \brief Return i-the zero-based edge of the side
2135 //================================================================================
2137 TopoDS_Edge _FaceSide::Edge(int i) const
2139 if ( i == 0 && !myEdge.IsNull() )
2142 if ( const _FaceSide* iSide = GetSide( i ))
2143 return iSide->myEdge;
2145 return TopoDS_Edge();
2148 //=======================================================================
2149 //function : Contain
2151 //=======================================================================
2153 bool _FaceSide::Contain( const _FaceSide& side, int* which ) const
2155 if ( !which || myChildren.empty() )
2160 TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2161 for ( ; vIt.More(); vIt.Next() )
2162 nbCommon += ( myVertices.Contains( vIt.Key() ));
2163 return (nbCommon > 1);
2165 list< _FaceSide >::const_iterator mySide = myChildren.begin(), sideEnd = myChildren.end();
2166 for ( int i = 0; mySide != sideEnd; ++mySide, ++i ) {
2167 if ( mySide->Contain( side )) {
2175 //=======================================================================
2176 //function : Contain
2178 //=======================================================================
2180 bool _FaceSide::Contain( const TopoDS_Vertex& vertex ) const
2182 return myVertices.Contains( vertex );
2185 //=======================================================================
2186 //function : AppendSide
2188 //=======================================================================
2190 void _FaceSide::AppendSide( const _FaceSide& side )
2192 if ( !myEdge.IsNull() )
2194 myChildren.push_back( *this );
2198 myChildren.push_back( side );
2200 TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2201 for ( ; vIt.More(); vIt.Next() )
2202 myVertices.Add( vIt.Key() );
2205 myChildren.back().SetID( EQuadSides( myNbChildren-1 ));
2208 //=======================================================================
2209 //function : SetBottomSide
2211 //=======================================================================
2213 void _FaceSide::SetBottomSide( int i )
2215 if ( i > 0 && myID == Q_PARENT ) {
2216 list< _FaceSide >::iterator sideEnd, side = myChildren.begin();
2217 std::advance( side, i );
2218 myChildren.splice( myChildren.begin(), myChildren, side, myChildren.end() );
2220 side = myChildren.begin(), sideEnd = myChildren.end();
2221 for ( int i = 0; side != sideEnd; ++side, ++i ) {
2222 side->SetID( EQuadSides(i) );
2223 side->SetBottomSide(i);
2228 //=======================================================================
2229 //function : GetNbSegments
2231 //=======================================================================
2233 smIdType _FaceSide::GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges) const
2236 if ( myChildren.empty() )
2238 nb = mesh.GetSubMesh(myEdge)->NbElements();
2240 if ( smToCheckEdges )
2242 // check that segments bound faces belonging to smToCheckEdges
2243 SMDS_ElemIteratorPtr segIt = mesh.GetSubMesh(myEdge)->GetElements();
2244 while ( segIt->more() )
2246 const SMDS_MeshElement* seg = segIt->next();
2247 if ( !IsSegmentOnSubMeshBoundary( mesh.GetProxyNode( seg->GetNode(0) ),
2248 mesh.GetProxyNode( seg->GetNode(1) ),
2249 smToCheckEdges, mesh ))
2256 list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2257 for ( ; side != sideEnd; ++side )
2258 nb += side->GetNbSegments( mesh, smToCheckEdges );
2263 //=======================================================================
2264 //function : StoreNodes
2266 //=======================================================================
2268 bool _FaceSide::StoreNodes(SMESH_ProxyMesh& mesh,
2269 vector<const SMDS_MeshNode*>& myGrid,
2272 const SMESHDS_SubMesh* smToCheckEdges)
2274 list< TopoDS_Edge > edges;
2275 if ( myChildren.empty() )
2277 edges.push_back( myEdge );
2281 list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2282 for ( ; side != sideEnd; ++side )
2284 edges.push_front( side->myEdge );
2286 edges.push_back ( side->myEdge );
2289 list< TopoDS_Edge >::iterator edge = edges.begin(), eEnd = edges.end();
2290 for ( ; edge != eEnd; ++edge )
2292 typedef map< double, const SMDS_MeshNode* > TParamNodeMap;
2293 TParamNodeMap nodes;
2294 bool ok = SMESH_Algo::GetSortedNodesOnEdge( mesh.GetMeshDS(),
2296 /*ignoreMediumNodes=*/true,
2298 if ( !ok ) return false;
2300 // skip nodes on VERTEXes not included in faces
2301 if ( !nodes.begin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2302 nodes.erase( nodes.begin() );
2303 if ( !nodes.empty() &&
2304 !nodes.rbegin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2305 nodes.erase( --nodes.end() );
2309 TParamNodeMap::iterator u_node, nEnd = nodes.end();
2310 for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2311 u_node->second = mesh.GetProxyNode( u_node->second );
2314 if ( smToCheckEdges ) // erase nodes of segments not bounding faces of smToCheckEdges
2317 TParamNodeMap::iterator u_node1, u_node2 = nodes.begin(), nEnd = nodes.end();
2318 for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2319 if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2320 smToCheckEdges, mesh ))
2323 nodes.erase( u_node1 );
2326 TParamNodeMap::reverse_iterator u_node1, u_node2 = nodes.rbegin(), nEnd = nodes.rend();
2327 for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2328 if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2329 smToCheckEdges, mesh ))
2332 nodes.erase( --(( u_node2 = u_node1 ).base() ));
2336 bool forward = ( edge->Orientation() == TopAbs_FORWARD );
2337 if ( reverse ) forward = !forward;
2340 TParamNodeMap::iterator u_node, nEnd = nodes.end();
2341 for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2342 myGrid[ nbNodes++ ] = u_node->second;
2346 TParamNodeMap::reverse_iterator u_node, nEnd = nodes.rend();
2347 for ( u_node = nodes.rbegin(); u_node != nEnd; ++u_node )
2348 myGrid[ nbNodes++ ] = u_node->second;
2350 nbNodes--; // node on vertex present in two adjacent edges
2355 //=======================================================================
2357 //purpose : dump end vertices
2358 //=======================================================================
2360 void _FaceSide::Dump() const
2362 if ( myChildren.empty() )
2364 const char* sideNames[] = { "Q_BOTTOM", "Q_RIGHT", "Q_TOP", "Q_LEFT", "Q_CHILD", "Q_PARENT" };
2365 if ( myID >= Q_BOTTOM && myID < Q_PARENT )
2366 cout << sideNames[ myID ] << endl;
2368 cout << "<UNDEFINED ID>" << endl;
2369 TopoDS_Vertex f = FirstVertex();
2370 TopoDS_Vertex l = LastVertex();
2371 gp_Pnt pf = BRep_Tool::Pnt(f);
2372 gp_Pnt pl = BRep_Tool::Pnt(l);
2373 cout << "\t ( "<< ptr( f ) << " - " << ptr( l )<< " )"
2374 << "\t ( "<< pf.X()<<", "<<pf.Y()<<", "<<pf.Z()<<" ) - "
2375 << " ( "<< pl.X()<<", "<<pl.Y()<<", "<<pl.Z()<<" )"<<endl;
2379 list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2380 for ( ; side != sideEnd; ++side ) {