1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: SMESH_MesherHelper.cxx
24 // Created: 15.02.06 15:22:41
25 // Author: Sergey KUUL
27 #include "SMESH_MesherHelper.hxx"
29 #include "SMDS_EdgePosition.hxx"
30 #include "SMDS_FaceOfNodes.hxx"
31 #include "SMDS_FacePosition.hxx"
32 #include "SMDS_IteratorOnIterators.hxx"
33 #include "SMDS_VolumeTool.hxx"
34 #include "SMESHDS_Mesh.hxx"
35 #include "SMESH_Block.hxx"
36 #include "SMESH_HypoFilter.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MeshAlgos.hxx"
39 #include "SMESH_MeshEditor.hxx"
40 #include "SMESH_ProxyMesh.hxx"
41 #include "SMESH_subMesh.hxx"
43 #include <BRepAdaptor_Curve.hxx>
44 #include <BRepAdaptor_Surface.hxx>
45 #include <BRepTools.hxx>
46 #include <BRep_Tool.hxx>
47 #include <Geom2d_Curve.hxx>
48 #include <GeomAPI_ProjectPointOnCurve.hxx>
49 #include <GeomAPI_ProjectPointOnSurf.hxx>
50 #include <Geom_Curve.hxx>
51 #include <Geom_RectangularTrimmedSurface.hxx>
52 #include <Geom_Surface.hxx>
53 #include <ShapeAnalysis.hxx>
55 #include <TopExp_Explorer.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TopTools_MapIteratorOfMapOfShape.hxx>
58 #include <TopTools_MapOfShape.hxx>
61 #include <gp_Pnt2d.hxx>
62 #include <gp_Trsf.hxx>
64 #include <Standard_Failure.hxx>
65 #include <Standard_ErrorHandler.hxx>
67 #include <utilities.h>
73 #define RETURN_BAD_RESULT(msg) { MESSAGE(msg); return false; }
77 inline SMESH_NodeXYZ XYZ(const SMDS_MeshNode* n) { return SMESH_NodeXYZ(n); }
79 enum { U_periodic = 1, V_periodic = 2 };
82 //================================================================================
86 //================================================================================
88 SMESH_MesherHelper::SMESH_MesherHelper(SMESH_Mesh& theMesh)
92 myCreateQuadratic(false),
93 myCreateBiQuadratic(false),
94 myFixNodeParameters(false)
96 myPar1[0] = myPar2[0] = myPar1[1] = myPar2[1] = 0;
97 mySetElemOnShape = ( ! myMesh->HasShapeToMesh() );
100 //=======================================================================
101 //function : ~SMESH_MesherHelper
103 //=======================================================================
105 SMESH_MesherHelper::~SMESH_MesherHelper()
108 TID2ProjectorOnSurf::iterator i_proj = myFace2Projector.begin();
109 for ( ; i_proj != myFace2Projector.end(); ++i_proj )
110 delete i_proj->second;
113 TID2ProjectorOnCurve::iterator i_proj = myEdge2Projector.begin();
114 for ( ; i_proj != myEdge2Projector.end(); ++i_proj )
115 delete i_proj->second;
119 //================================================================================
121 * \brief Return SMESH_Gen
123 //================================================================================
125 SMESH_Gen* SMESH_MesherHelper::GetGen() const
127 return GetMesh()->GetGen();
130 //================================================================================
132 * \brief Return mesh DS
134 //================================================================================
136 SMESHDS_Mesh* SMESH_MesherHelper::GetMeshDS() const
138 return GetMesh()->GetMeshDS();
141 //=======================================================================
142 //function : IsQuadraticSubMesh
143 //purpose : Check sub-meshes of a given shape: if all elements on sub-shapes
144 // are quadratic, quadratic elements will be created.
145 // Fill myTLinkNodeMap
146 //=======================================================================
148 bool SMESH_MesherHelper::IsQuadraticSubMesh(const TopoDS_Shape& aSh)
150 SMESHDS_Mesh* meshDS = GetMeshDS();
151 // we can create quadratic elements only if all elements
152 // created on sub-shapes of given shape are quadratic
153 myCreateQuadratic = true;
154 mySeamShapeIds.clear();
155 myDegenShapeIds.clear();
156 TopAbs_ShapeEnum subType( aSh.ShapeType()==TopAbs_FACE ? TopAbs_EDGE : TopAbs_FACE );
157 if ( aSh.ShapeType()==TopAbs_COMPOUND )
159 TopoDS_Iterator subIt( aSh );
161 subType = ( subIt.Value().ShapeType()==TopAbs_FACE ) ? TopAbs_EDGE : TopAbs_FACE;
163 SMDSAbs_ElementType elemType( subType==TopAbs_FACE ? SMDSAbs_Face : SMDSAbs_Edge );
165 if ( !myMesh->HasShapeToMesh() )
167 if (( myCreateQuadratic = myMesh->NbFaces( ORDER_QUADRATIC )))
169 SMDS_FaceIteratorPtr fIt = meshDS->facesIterator();
170 while ( fIt->more() )
171 AddTLinks( static_cast< const SMDS_MeshFace* >( fIt->next() ));
176 TopExp_Explorer exp( aSh, subType );
177 TopTools_MapOfShape checkedSubShapes;
178 for (; exp.More() && myCreateQuadratic; exp.Next()) {
179 if ( !checkedSubShapes.Add( exp.Current() ))
180 continue; // needed if aSh is compound of solids
181 if ( SMESHDS_SubMesh * subMesh = meshDS->MeshElements( exp.Current() )) {
182 if ( SMDS_ElemIteratorPtr it = subMesh->GetElements() ) {
184 const SMDS_MeshElement* e = it->next();
185 if ( e->GetType() != elemType || !e->IsQuadratic() ) {
186 myCreateQuadratic = false;
191 switch ( e->NbCornerNodes() ) {
193 AddTLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(2)); break;
195 AddTLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(3));
196 AddTLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(4));
197 AddTLinkNode(e->GetNode(2),e->GetNode(0),e->GetNode(5)); break;
199 AddTLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(4));
200 AddTLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(5));
201 AddTLinkNode(e->GetNode(2),e->GetNode(3),e->GetNode(6));
202 AddTLinkNode(e->GetNode(3),e->GetNode(0),e->GetNode(7));
205 myCreateQuadratic = false;
215 // if ( nbOldLinks == myTLinkNodeMap.size() ) -- 0023068
216 if ( myTLinkNodeMap.empty() )
217 myCreateQuadratic = false;
219 if ( !myCreateQuadratic )
220 myTLinkNodeMap.clear();
224 return myCreateQuadratic;
227 //=======================================================================
228 //function : SetSubShape
229 //purpose : Set geometry to make elements on
230 //=======================================================================
232 void SMESH_MesherHelper::SetSubShape(const int aShID)
234 if ( aShID == myShapeID )
237 SetSubShape( GetMeshDS()->IndexToShape( aShID ));
239 SetSubShape( TopoDS_Shape() );
242 //=======================================================================
243 //function : SetSubShape
244 //purpose : Set geometry to create elements on
245 //=======================================================================
247 void SMESH_MesherHelper::SetSubShape(const TopoDS_Shape& aSh)
249 if ( myShape.IsSame( aSh ))
253 mySeamShapeIds.clear();
254 myDegenShapeIds.clear();
256 if ( myShape.IsNull() ) {
260 SMESHDS_Mesh* meshDS = GetMeshDS();
261 myShapeID = meshDS->ShapeToIndex(aSh);
264 // treatment of periodic faces
265 for ( TopExp_Explorer eF( aSh, TopAbs_FACE ); eF.More(); eF.Next() )
267 const TopoDS_Face& face = TopoDS::Face( eF.Current() );
268 BRepAdaptor_Surface surf( face, false );
269 if ( surf.IsUPeriodic() || surf.IsUClosed() ) {
270 myParIndex |= U_periodic;
271 myPar1[0] = surf.FirstUParameter();
272 myPar2[0] = surf.LastUParameter();
274 if ( surf.IsVPeriodic() || surf.IsVClosed() ) {
275 myParIndex |= V_periodic;
276 myPar1[1] = surf.FirstVParameter();
277 myPar2[1] = surf.LastVParameter();
281 for (TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next())
283 // look for a "seam" edge, a real seam or an edge on period boundary
284 TopoDS_Edge edge = TopoDS::Edge( exp.Current() );
285 const int edgeID = meshDS->ShapeToIndex( edge );
288 BRep_Tool::UVPoints( edge, face, uv1, uv2 );
289 const double du = Abs( uv1.Coord(1) - uv2.Coord(1) );
290 const double dv = Abs( uv1.Coord(2) - uv2.Coord(2) );
292 bool isSeam = BRep_Tool::IsClosed( edge, face );
293 if ( isSeam ) // real seam - having two pcurves on face
295 // pcurve can lie not on pediod boundary (22582, mesh_Quadratic_01/C9)
298 double u1 = uv1.Coord(1);
300 BRep_Tool::UVPoints( edge, face, uv1, uv2 );
301 double u2 = uv1.Coord(1);
302 myPar1[0] = Min( u1, u2 );
303 myPar2[0] = Max( u1, u2 );
304 myParIndex |= U_periodic;
308 double v1 = uv1.Coord(2);
310 BRep_Tool::UVPoints( edge, face, uv1, uv2 );
311 double v2 = uv1.Coord(2);
312 myPar1[1] = Min( v1, v2 );
313 myPar2[1] = Max( v1, v2 );
314 myParIndex |= V_periodic;
317 else //if ( !isSeam )
319 // one pcurve but on period boundary (22772, mesh_Quadratic_01/D1)
320 if (( myParIndex & U_periodic ) && du < Precision::PConfusion() )
322 isSeam = ( Abs( uv1.Coord(1) - myPar1[0] ) < Precision::PConfusion() ||
323 Abs( uv1.Coord(1) - myPar2[0] ) < Precision::PConfusion() );
325 else if (( myParIndex & V_periodic ) && dv < Precision::PConfusion() )
327 isSeam = ( Abs( uv1.Coord(2) - myPar1[1] ) < Precision::PConfusion() ||
328 Abs( uv1.Coord(2) - myPar2[1] ) < Precision::PConfusion() );
330 if ( isSeam ) // vertices are on period boundary, check a middle point (23032)
332 double f,l, r = 0.2345;
333 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface( edge, face, f, l );
340 uv2 = C2d->Value( f * r + l * ( 1.-r ));
341 if ( du < Precision::PConfusion() )
342 isSeam = ( Abs( uv1.Coord(1) - uv2.Coord(1) ) < Precision::PConfusion() );
344 isSeam = ( Abs( uv1.Coord(2) - uv2.Coord(2) ) < Precision::PConfusion() );
350 // store seam shape indices, negative if shape encounters twice ('real seam')
351 mySeamShapeIds.insert( IsSeamShape( edgeID ) ? -edgeID : edgeID );
352 for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() ) {
353 int vertexID = meshDS->ShapeToIndex( v.Current() );
354 mySeamShapeIds.insert( IsSeamShape( vertexID ) ? -vertexID : vertexID );
358 // look for a degenerated edge
359 if ( SMESH_Algo::isDegenerated( edge )) {
360 myDegenShapeIds.insert( edgeID );
361 for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() )
362 myDegenShapeIds.insert( meshDS->ShapeToIndex( v.Current() ));
364 if ( !BRep_Tool::SameParameter( edge ) ||
365 !BRep_Tool::SameRange( edge ))
367 setPosOnShapeValidity( edgeID, false );
373 //=======================================================================
375 * \brief Copy shape information from another helper. Used to improve performance
376 * since SetSubShape() can be time consuming if there are many edges
378 //=======================================================================
380 void SMESH_MesherHelper::CopySubShapeInfo(const SMESH_MesherHelper& other)
382 this->myShape = other.myShape;
383 this->myShapeID = other.myShapeID;
384 this->myDegenShapeIds = other.myDegenShapeIds;
385 this->mySeamShapeIds = other.mySeamShapeIds;
386 this->myPar1[0] = other.myPar1[0];
387 this->myPar1[1] = other.myPar1[1];
388 this->myPar2[0] = other.myPar2[0];
389 this->myPar2[1] = other.myPar2[1];
390 this->myParIndex = other.myParIndex;
391 this->myFace2Surface = other.myFace2Surface;
394 //=======================================================================
395 //function : ShapeToIndex
396 //purpose : Convert a shape to its index in the SMESHDS_Mesh
397 //=======================================================================
399 int SMESH_MesherHelper::ShapeToIndex( const TopoDS_Shape& S ) const
401 return GetMeshDS()->ShapeToIndex( S );
404 //=======================================================================
405 //function : GetNodeUVneedInFaceNode
406 //purpose : Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
407 // Return true if the face is periodic.
408 // If F is Null, answer about sub-shape set through IsQuadraticSubMesh() or
410 //=======================================================================
412 bool SMESH_MesherHelper::GetNodeUVneedInFaceNode(const TopoDS_Face& F) const
414 if ( F.IsNull() ) return !mySeamShapeIds.empty();
416 if ( !F.IsNull() && !myShape.IsNull() && myShape.IsSame( F ))
417 return !mySeamShapeIds.empty();
420 Handle(Geom_Surface) aSurface = BRep_Tool::Surface( F,loc );
421 if ( !aSurface.IsNull() )
422 return ( aSurface->IsUPeriodic() || aSurface->IsVPeriodic() );
427 //=======================================================================
428 //function : IsMedium
430 //=======================================================================
432 bool SMESH_MesherHelper::IsMedium(const SMDS_MeshNode* node,
433 const SMDSAbs_ElementType typeToCheck)
435 return SMESH_MeshEditor::IsMedium( node, typeToCheck );
438 //=======================================================================
439 //function : GetSubShapeByNode
440 //purpose : Return support shape of a node
441 //=======================================================================
443 TopoDS_Shape SMESH_MesherHelper::GetSubShapeByNode(const SMDS_MeshNode* node,
444 const SMESHDS_Mesh* meshDS)
446 int shapeID = node ? node->getshapeId() : 0;
447 if ( 0 < shapeID && shapeID <= meshDS->MaxShapeIndex() )
448 return meshDS->IndexToShape( shapeID );
450 return TopoDS_Shape();
454 //=======================================================================
455 //function : AddTLinkNode
456 //purpose : add a link in my data structure
457 //=======================================================================
459 void SMESH_MesherHelper::AddTLinkNode(const SMDS_MeshNode* n1,
460 const SMDS_MeshNode* n2,
461 const SMDS_MeshNode* n12)
463 // add new record to map
464 SMESH_TLink link( n1, n2 );
465 myTLinkNodeMap.insert( make_pair(link,n12));
468 //================================================================================
470 * \brief Add quadratic links of edge to own data structure
472 //================================================================================
474 bool SMESH_MesherHelper::AddTLinks(const SMDS_MeshEdge* edge)
476 if ( edge && edge->IsQuadratic() )
477 AddTLinkNode(edge->GetNode(0), edge->GetNode(1), edge->GetNode(2));
483 //================================================================================
485 * \brief Add quadratic links of face to own data structure
487 //================================================================================
489 bool SMESH_MesherHelper::AddTLinks(const SMDS_MeshFace* f)
493 switch ( f->NbNodes() ) {
495 // myMapWithCentralNode.insert
496 // ( make_pair( TBiQuad( f->GetNode(0),f->GetNode(1),f->GetNode(2) ),
498 // break; -- add medium nodes as well
500 AddTLinkNode(f->GetNode(0),f->GetNode(1),f->GetNode(3));
501 AddTLinkNode(f->GetNode(1),f->GetNode(2),f->GetNode(4));
502 AddTLinkNode(f->GetNode(2),f->GetNode(0),f->GetNode(5)); break;
505 // myMapWithCentralNode.insert
506 // ( make_pair( TBiQuad( f->GetNode(0),f->GetNode(1),f->GetNode(2),f->GetNode(3) ),
508 // break; -- add medium nodes as well
510 AddTLinkNode(f->GetNode(0),f->GetNode(1),f->GetNode(4));
511 AddTLinkNode(f->GetNode(1),f->GetNode(2),f->GetNode(5));
512 AddTLinkNode(f->GetNode(2),f->GetNode(3),f->GetNode(6));
513 AddTLinkNode(f->GetNode(3),f->GetNode(0),f->GetNode(7)); break;
520 //================================================================================
522 * \brief Add quadratic links of volume to own data structure
524 //================================================================================
526 bool SMESH_MesherHelper::AddTLinks(const SMDS_MeshVolume* volume)
528 if ( volume->IsQuadratic() )
530 SMDS_VolumeTool vTool( volume );
531 const SMDS_MeshNode** nodes = vTool.GetNodes();
533 for ( int iF = 1; iF < vTool.NbFaces(); ++iF )
535 const int nbN = vTool.NbFaceNodes( iF );
536 const int* iNodes = vTool.GetFaceNodesIndices( iF );
537 for ( int i = 0; i < nbN; )
539 int iN1 = iNodes[i++];
540 int iN12 = iNodes[i++];
542 if ( iN1 > iN2 ) std::swap( iN1, iN2 );
543 int linkID = iN1 * vTool.NbNodes() + iN2;
544 pair< set<int>::iterator, bool > it_isNew = addedLinks.insert( linkID );
545 if ( it_isNew.second )
546 AddTLinkNode( nodes[iN1], nodes[iN2], nodes[iN12] );
548 addedLinks.erase( it_isNew.first ); // each link encounters only twice
550 if ( vTool.NbNodes() == 27 )
552 const SMDS_MeshNode* nFCenter = nodes[ vTool.GetCenterNodeIndex( iF )];
553 if ( nFCenter->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE )
554 myMapWithCentralNode.insert
555 ( make_pair( TBiQuad( nodes[ iNodes[0]], nodes[ iNodes[1]],
556 nodes[ iNodes[2]], nodes[ iNodes[3]] ),
565 //================================================================================
567 * \brief Return true if position of nodes on the shape hasn't yet been checked or
568 * the positions proved to be invalid
570 //================================================================================
572 bool SMESH_MesherHelper::toCheckPosOnShape(int shapeID ) const
574 map< int,bool >::const_iterator id_ok = myNodePosShapesValidity.find( shapeID );
575 return ( id_ok == myNodePosShapesValidity.end() || !id_ok->second );
578 //================================================================================
580 * \brief Set validity of positions of nodes on the shape.
581 * Once set, validity is not changed
583 //================================================================================
585 void SMESH_MesherHelper::setPosOnShapeValidity(int shapeID, bool ok ) const
587 std::map< int,bool >::iterator sh_ok =
588 ((SMESH_MesherHelper*)this)->myNodePosShapesValidity.insert( make_pair( shapeID, ok)).first;
593 //=======================================================================
594 //function : ToFixNodeParameters
595 //purpose : Enables fixing node parameters on EDGEs and FACEs in
596 // GetNodeU(...,check=true), GetNodeUV(...,check=true), CheckNodeUV() and
597 // CheckNodeU() in case if a node lies on a shape set via SetSubShape().
599 //=======================================================================
601 void SMESH_MesherHelper::ToFixNodeParameters(bool toFix)
603 myFixNodeParameters = toFix;
607 //=======================================================================
608 //function : getUVOnSeam
609 //purpose : Select UV on either of 2 pcurves of a seam edge, closest to the given UV
610 //=======================================================================
612 gp_Pnt2d SMESH_MesherHelper::getUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const
614 gp_Pnt2d result = uv1;
615 for ( int i = U_periodic; i <= V_periodic ; ++i )
617 if ( myParIndex & i )
619 double p1 = uv1.Coord( i );
620 double dp1 = Abs( p1-myPar1[i-1]), dp2 = Abs( p1-myPar2[i-1]);
621 if ( myParIndex == i ||
622 dp1 < ( myPar2[i-1] - myPar1[i-1] ) / 100. ||
623 dp2 < ( myPar2[i-1] - myPar1[i-1] ) / 100. )
625 double p2 = uv2.Coord( i );
626 double p1Alt = ( dp1 < dp2 ) ? myPar2[i-1] : myPar1[i-1];
627 if ( Abs( p2 - p1 ) > Abs( p2 - p1Alt ))
628 result.SetCoord( i, p1Alt );
635 //=======================================================================
636 //function : GetNodeUV
637 //purpose : Return node UV on face
638 //=======================================================================
640 gp_XY SMESH_MesherHelper::GetNodeUV(const TopoDS_Face& F,
641 const SMDS_MeshNode* n,
642 const SMDS_MeshNode* n2,
645 gp_Pnt2d uv( Precision::Infinite(), Precision::Infinite() );
647 SMDS_PositionPtr pos = n->GetPosition();
649 if ( pos->GetTypeOfPosition() == SMDS_TOP_FACE )
651 // node has position on face
652 SMDS_FacePositionPtr fpos = pos;
653 uv.SetCoord( fpos->GetUParameter(), fpos->GetVParameter() );
655 uvOK = CheckNodeUV( F, n, uv.ChangeCoord(), 2.*getFaceMaxTol( F )); // 2. from 22830
657 else if ( pos->GetTypeOfPosition() == SMDS_TOP_EDGE )
659 // node has position on EDGE => it is needed to find
660 // corresponding EDGE from FACE, get pcurve for this
661 // EDGE and retrieve value from this pcurve
662 SMDS_EdgePositionPtr epos = pos;
663 const int edgeID = n->getshapeId();
664 const TopoDS_Edge& E = TopoDS::Edge( GetMeshDS()->IndexToShape( edgeID ));
665 double f, l, u = epos->GetUParameter();
666 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface( E, F, f, l );
667 bool validU = ( !C2d.IsNull() && ( f < u ) && ( u < l ));
668 if ( validU ) uv = C2d->Value( u );
669 else uv.SetCoord( Precision::Infinite(),0.);
670 if ( check || !validU )
671 uvOK = CheckNodeUV( F, n, uv.ChangeCoord(), 2.*getFaceMaxTol( F ),/*force=*/ !validU );
673 // for a node on a seam EDGE select one of UVs on 2 pcurves
674 if ( n2 && IsSeamShape( edgeID ))
676 uv = getUVOnSeam( uv, GetNodeUV( F, n2, 0, check ));
679 { // adjust uv to period
681 Handle(Geom_Surface) S = BRep_Tool::Surface(F,loc);
682 Standard_Boolean isUPeriodic = S->IsUPeriodic();
683 Standard_Boolean isVPeriodic = S->IsVPeriodic();
685 if ( isUPeriodic || isVPeriodic ) {
686 Standard_Real UF,UL,VF,VL;
687 S->Bounds(UF,UL,VF,VL);
688 if ( isUPeriodic ) newUV.SetX( uv.X() + ShapeAnalysis::AdjustToPeriod(uv.X(),UF,UL));
689 if ( isVPeriodic ) newUV.SetY( uv.Y() + ShapeAnalysis::AdjustToPeriod(uv.Y(),VF,VL));
693 gp_Pnt2d uv2 = GetNodeUV( F, n2, 0, check );
694 if ( isUPeriodic && Abs( uv.X()-uv2.X() ) < Abs( newUV.X()-uv2.X() ))
695 newUV.SetX( uv.X() );
696 if ( isVPeriodic && Abs( uv.Y()-uv2.Y() ) < Abs( newUV.Y()-uv2.Y() ))
697 newUV.SetY( uv.Y() );
703 else if ( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX )
705 if ( int vertexID = n->getshapeId() ) {
706 const TopoDS_Vertex& V = TopoDS::Vertex(GetMeshDS()->IndexToShape(vertexID));
708 uv = BRep_Tool::Parameters( V, F );
711 catch (Standard_Failure& exc) {
715 if ( !IsSubShape( V, F ))
717 MESSAGE("GetNodeUV() Vertex "<< vertexID <<" not in face "<< GetMeshDS()->ShapeToIndex(F));
718 // get UV of a vertex closest to the node
720 gp_Pnt pn = XYZ( n );
721 for ( TopExp_Explorer vert( F,TopAbs_VERTEX ); !uvOK && vert.More(); vert.Next() ) {
722 TopoDS_Vertex curV = TopoDS::Vertex( vert.Current() );
723 gp_Pnt p = BRep_Tool::Pnt( curV );
724 double curDist = p.SquareDistance( pn );
725 if ( curDist < dist ) {
727 uv = BRep_Tool::Parameters( curV, F );
728 uvOK = ( dist < DBL_MIN );
735 TopTools_ListIteratorOfListOfShape it( myMesh->GetAncestors( V ));
736 for ( ; it.More(); it.Next() ) {
737 if ( it.Value().ShapeType() == TopAbs_EDGE ) {
738 const TopoDS_Edge & edge = TopoDS::Edge( it.Value() );
740 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(edge, F, f, l);
741 if ( !C2d.IsNull() ) {
742 double u = ( V == IthVertex( 0, edge )) ? f : l;
743 uv = C2d->Value( u );
749 if ( !uvOK && V.Orientation() == TopAbs_INTERNAL )
751 Handle(ShapeAnalysis_Surface) projector = GetSurface( F );
752 if ( n2 ) uv = GetNodeUV( F, n2 );
753 if ( Precision::IsInfinite( uv.X() ))
754 uv = projector->NextValueOfUV( uv, BRep_Tool::Pnt( V ), BRep_Tool::Tolerance( F ));
756 uv = projector->ValueOfUV( BRep_Tool::Pnt( V ), BRep_Tool::Tolerance( F ));
757 uvOK = ( projector->Gap() < getFaceMaxTol( F ));
761 if ( n2 && IsSeamShape( vertexID ))
763 bool isSeam = ( myShape.IsSame( F ));
765 SMESH_MesherHelper h( *myMesh );
767 isSeam = IsSeamShape( vertexID );
771 uv = getUVOnSeam( uv, GetNodeUV( F, n2, 0 ));
777 uvOK = CheckNodeUV( F, n, uv.ChangeCoord(), 2.*getFaceMaxTol( F ));
780 if ( check && !uvOK )
786 //=======================================================================
787 //function : CheckNodeUV
788 //purpose : Check and fix node UV on a face
789 //=======================================================================
791 bool SMESH_MesherHelper::CheckNodeUV(const TopoDS_Face& F,
792 const SMDS_MeshNode* n,
796 double distXYZ[4]) const
798 int shapeID = n->getshapeId();
800 if (( infinit = ( Precision::IsInfinite( uv.X() ) || Precision::IsInfinite( uv.Y() ))) ||
802 ( uv.X() == 0. && uv.Y() == 0. ) ||
803 ( toCheckPosOnShape( shapeID )))
805 // check that uv is correct
807 Handle(Geom_Surface) surface = BRep_Tool::Surface( F,loc );
808 SMESH_NodeXYZ nXYZ( n );
809 gp_Pnt nodePnt = nXYZ, surfPnt(0,0,0);
811 if ( !loc.IsIdentity() ) nodePnt.Transform( loc.Transformation().Inverted() );
813 (dist = nodePnt.Distance( surfPnt = surface->Value( uv.X(), uv.Y() ))) > tol )
815 setPosOnShapeValidity( shapeID, false );
816 // uv incorrect, project the node to surface
817 Handle(ShapeAnalysis_Surface) sprojector = GetSurface( F );
818 uv = sprojector->ValueOfUV( nXYZ, tol ).XY();
819 surfPnt = sprojector->Value( uv );
820 dist = surfPnt.Distance( nXYZ );
823 distXYZ[1] = surfPnt.X(); distXYZ[2] = surfPnt.Y(); distXYZ[3]=surfPnt.Z();
827 MESSAGE( "SMESH_MesherHelper::CheckNodeUV(), invalid projection" );
830 // store the fixed UV on the face
831 if ( myShape.IsSame(F) && shapeID == myShapeID && myFixNodeParameters )
832 const_cast<SMDS_MeshNode*>(n)->SetPosition
833 ( SMDS_PositionPtr( new SMDS_FacePosition( uv.X(), uv.Y() )));
835 else if ( myShape.IsSame(F) && uv.Modulus() > numeric_limits<double>::min() )
837 setPosOnShapeValidity( shapeID, true );
843 //=======================================================================
844 //function : GetProjector
845 //purpose : Return projector initialized by given face without location, which is returned
846 //=======================================================================
848 GeomAPI_ProjectPointOnSurf& SMESH_MesherHelper::GetProjector(const TopoDS_Face& F,
849 TopLoc_Location& loc,
852 Handle(Geom_Surface) surface = BRep_Tool::Surface( F,loc );
853 int faceID = GetMeshDS()->ShapeToIndex( F );
854 TID2ProjectorOnSurf& i2proj = const_cast< TID2ProjectorOnSurf&>( myFace2Projector );
855 TID2ProjectorOnSurf::iterator i_proj = i2proj.find( faceID );
856 if ( i_proj == i2proj.end() )
858 if ( tol == 0 ) tol = BRep_Tool::Tolerance( F );
859 double U1, U2, V1, V2;
860 surface->Bounds(U1, U2, V1, V2);
861 GeomAPI_ProjectPointOnSurf* proj = new GeomAPI_ProjectPointOnSurf();
862 proj->Init( surface, U1, U2, V1, V2, tol );
863 i_proj = i2proj.insert( make_pair( faceID, proj )).first;
865 return *( i_proj->second );
868 //=======================================================================
869 //function : GetSurface
870 //purpose : Return a cached ShapeAnalysis_Surface of a FACE
871 //=======================================================================
873 Handle(ShapeAnalysis_Surface) SMESH_MesherHelper::GetSurface(const TopoDS_Face& F ) const
875 Handle(Geom_Surface) surface = BRep_Tool::Surface( F );
876 int faceID = GetMeshDS()->ShapeToIndex( F );
877 TID2Surface::iterator i_surf = myFace2Surface.find( faceID );
878 if ( i_surf == myFace2Surface.end() && faceID )
880 Handle(ShapeAnalysis_Surface) surf( new ShapeAnalysis_Surface( surface ));
881 i_surf = myFace2Surface.insert( make_pair( faceID, surf )).first;
883 return i_surf->second;
888 gp_XY AverageUV(const gp_XY& uv1, const gp_XY& uv2) { return ( uv1 + uv2 ) / 2.; }
889 gp_XY_FunPtr(Added); // define gp_XY_Added pointer to function calling gp_XY::Added(gp_XY)
890 gp_XY_FunPtr(Subtracted);
893 //=======================================================================
894 //function : ApplyIn2D
895 //purpose : Perform given operation on two 2d points in parameric space of given surface.
896 // It takes into account period of the surface. Use gp_XY_FunPtr macro
897 // to easily define pointer to function of gp_XY class.
898 //=======================================================================
900 gp_XY SMESH_MesherHelper::ApplyIn2D(Handle(Geom_Surface) surface,
904 const bool resultInPeriod)
906 if ( surface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface )))
907 surface = Handle(Geom_RectangularTrimmedSurface)::DownCast( surface )->BasisSurface();
908 Standard_Boolean isUPeriodic = surface.IsNull() ? false : surface->IsUPeriodic();
909 Standard_Boolean isVPeriodic = surface.IsNull() ? false : surface->IsVPeriodic();
910 if ( !isUPeriodic && !isVPeriodic )
913 // move uv2 not far than half-period from uv1
915 uv2.X()+(isUPeriodic ? ShapeAnalysis::AdjustByPeriod(uv2.X(),uv1.X(),surface->UPeriod()) :0);
917 uv2.Y()+(isVPeriodic ? ShapeAnalysis::AdjustByPeriod(uv2.Y(),uv1.Y(),surface->VPeriod()) :0);
920 gp_XY res = fun( uv1, gp_XY(u2,v2) );
922 // move result within period
923 if ( resultInPeriod )
925 Standard_Real UF,UL,VF,VL;
926 surface->Bounds(UF,UL,VF,VL);
928 res.SetX( res.X() + ShapeAnalysis::AdjustToPeriod(res.X(),UF,UL));
930 res.SetY( res.Y() + ShapeAnalysis::AdjustToPeriod(res.Y(),VF,VL));
936 //=======================================================================
937 //function : AdjustByPeriod
938 //purpose : Move node positions on a FACE within surface period
939 //=======================================================================
941 void SMESH_MesherHelper::AdjustByPeriod( const TopoDS_Face& face, gp_XY uv[], const int nbUV )
943 SMESH_MesherHelper h( *myMesh ), *ph = face.IsSame( myShape ) ? this : &h;
944 ph->SetSubShape( face );
946 for ( int iCoo = U_periodic; iCoo <= V_periodic; ++iCoo )
947 if ( ph->GetPeriodicIndex() & iCoo )
949 const double period = ( ph->myPar2[iCoo-1] - ph->myPar1[iCoo-1] );
950 const double xRef = uv[0].Coord( iCoo );
951 for ( int i = 1; i < nbUV; ++i )
953 double x = uv[i].Coord( iCoo );
954 double dx = ShapeAnalysis::AdjustByPeriod( x, xRef, period );
955 uv[i].SetCoord( iCoo, x + dx );
960 //=======================================================================
961 //function : GetMiddleUV
962 //purpose : Return middle UV taking in account surface period
963 //=======================================================================
965 gp_XY SMESH_MesherHelper::GetMiddleUV(const Handle(Geom_Surface)& surface,
970 // the proper place of getting basic surface seems to be in ApplyIn2D()
971 // but we put it here to decrease a risk of regressions just before releasing a version
972 // Handle(Geom_Surface) surf = surface;
973 // while ( !surf.IsNull() && surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface )))
974 // surf = Handle(Geom_RectangularTrimmedSurface)::DownCast( surf )->BasisSurface();
976 return ApplyIn2D( surface, p1, p2, & AverageUV );
979 //=======================================================================
980 //function : GetCenterUV
981 //purpose : Return UV for the central node of a biquadratic triangle
982 //=======================================================================
984 gp_XY SMESH_MesherHelper::GetCenterUV(const gp_XY& uv1,
990 bool * isBadTria/*=0*/)
993 gp_XY uvAvg = ( uv12 + uv23 + uv31 ) / 3.;
995 if (( badTria = (( uvAvg - uv1 ) * ( uvAvg - uv23 ) > 0 )))
996 uvAvg = ( uv1 + uv23 ) / 2.;
997 else if (( badTria = (( uvAvg - uv2 ) * ( uvAvg - uv31 ) > 0 )))
998 uvAvg = ( uv2 + uv31 ) / 2.;
999 else if (( badTria = (( uvAvg - uv3 ) * ( uvAvg - uv12 ) > 0 )))
1000 uvAvg = ( uv3 + uv12 ) / 2.;
1003 *isBadTria = badTria;
1007 //=======================================================================
1008 //function : GetNodeU
1009 //purpose : Return node U on edge
1010 //=======================================================================
1012 double SMESH_MesherHelper::GetNodeU(const TopoDS_Edge& E,
1013 const SMDS_MeshNode* n,
1014 const SMDS_MeshNode* inEdgeNode,
1017 double param = Precision::Infinite();
1019 const SMDS_PositionPtr pos = n->GetPosition();
1020 if ( pos->GetTypeOfPosition()==SMDS_TOP_EDGE )
1022 param = pos->GetParameters()[0];
1024 else if( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX )
1026 if ( inEdgeNode && TopExp::FirstVertex( E ).IsSame( TopExp::LastVertex( E ))) // issue 0020128
1029 BRep_Tool::Range( E, f,l );
1030 double uInEdge = GetNodeU( E, inEdgeNode );
1031 param = ( fabs( uInEdge - f ) < fabs( l - uInEdge )) ? f : l;
1035 SMESHDS_Mesh * meshDS = GetMeshDS();
1036 int vertexID = n->getshapeId();
1037 const TopoDS_Vertex& V = TopoDS::Vertex(meshDS->IndexToShape(vertexID));
1038 param = BRep_Tool::Parameter( V, E );
1042 BRepAdaptor_Curve curve( E );
1043 if ( curve.IsPeriodic() )
1045 double uInEdge = GetNodeU( E, inEdgeNode );
1046 param += ShapeAnalysis::AdjustByPeriod( param, uInEdge, curve.Period() );
1053 double tol = BRep_Tool::Tolerance( E );
1054 double f,l; BRep_Tool::Range( E, f,l );
1055 bool force = ( param < f-tol || param > l+tol );
1056 if ( !force && pos->GetTypeOfPosition()==SMDS_TOP_EDGE )
1057 force = ( GetMeshDS()->ShapeToIndex( E ) != n->getshapeId() );
1059 *check = CheckNodeU( E, n, param, 2*tol, force );
1064 //=======================================================================
1065 //function : CheckNodeU
1066 //purpose : Check and fix node U on an edge
1067 // Return false if U is bad and could not be fixed
1068 //=======================================================================
1070 bool SMESH_MesherHelper::CheckNodeU(const TopoDS_Edge& E,
1071 const SMDS_MeshNode* n,
1075 double distXYZ[4]) const
1077 int shapeID = n->getshapeId();
1079 if (( infinit = Precision::IsInfinite( u )) ||
1082 ( toCheckPosOnShape( shapeID )))
1084 TopLoc_Location loc; double f,l;
1085 Handle(Geom_Curve) curve = BRep_Tool::Curve( E,loc,f,l );
1086 if ( curve.IsNull() ) // degenerated edge
1088 if ( u+tol < f || u-tol > l )
1090 double r = Max( 0.5, 1 - tol*n->GetID()); // to get a unique u on edge
1096 gp_Pnt nodePnt = SMESH_TNodeXYZ( n );
1097 if ( !loc.IsIdentity() ) nodePnt.Transform( loc.Transformation().Inverted() );
1099 double dist = 2*tol;
1102 curvPnt = curve->Value( u );
1103 dist = nodePnt.Distance( curvPnt );
1105 curvPnt.Transform( loc );
1107 distXYZ[1] = curvPnt.X(); distXYZ[2] = curvPnt.Y(); distXYZ[3]=curvPnt.Z();
1112 setPosOnShapeValidity( shapeID, false );
1113 // u incorrect, project the node to the curve
1114 int edgeID = GetMeshDS()->ShapeToIndex( E );
1115 TID2ProjectorOnCurve& i2proj = const_cast< TID2ProjectorOnCurve&>( myEdge2Projector );
1116 TID2ProjectorOnCurve::iterator i_proj =
1117 i2proj.insert( make_pair( edgeID, (GeomAPI_ProjectPointOnCurve*) 0 )).first;
1118 if ( !i_proj->second )
1120 i_proj->second = new GeomAPI_ProjectPointOnCurve();
1121 i_proj->second->Init( curve, f, l );
1123 GeomAPI_ProjectPointOnCurve* projector = i_proj->second;
1124 projector->Perform( nodePnt );
1125 if ( projector->NbPoints() < 1 )
1127 MESSAGE( "SMESH_MesherHelper::CheckNodeU() failed to project" );
1130 Standard_Real U = projector->LowerDistanceParameter();
1132 curvPnt = curve->Value( u );
1133 dist = nodePnt.Distance( curvPnt );
1135 curvPnt.Transform( loc );
1137 distXYZ[1] = curvPnt.X(); distXYZ[2] = curvPnt.Y(); distXYZ[3]=curvPnt.Z();
1141 MESSAGE( "CheckNodeU(), invalid projection; distance " << dist << "; tol " << tol );
1144 // store the fixed U on the edge
1145 if ( myShape.IsSame(E) && shapeID == myShapeID && myFixNodeParameters )
1146 const_cast<SMDS_MeshNode*>(n)->SetPosition
1147 ( SMDS_PositionPtr( new SMDS_EdgePosition( U )));
1149 else if ( fabs( u ) > numeric_limits<double>::min() )
1151 setPosOnShapeValidity( shapeID, true );
1153 if (( u < f-tol || u > l+tol ) && force )
1155 MESSAGE("u < f-tol || u > l+tol ; u " << u << " f " << f << " l " << l);
1156 // node is on vertex but is set on periodic but trimmed edge (issue 0020890)
1159 // do not use IsPeriodic() as Geom_TrimmedCurve::IsPeriodic () returns false
1160 double period = curve->Period();
1161 u = ( u < f ) ? u + period : u - period;
1163 catch (Standard_Failure& exc)
1173 //=======================================================================
1174 //function : GetMediumPos
1175 //purpose : Return index and type of the shape (EDGE or FACE only) to
1176 // set a medium node on
1177 //param : useCurSubShape - if true, returns the shape set via SetSubShape()
1179 //param : expectedSupport - shape type corresponding to element being created,
1180 // e.g TopAbs_EDGE if SMDSAbs_Edge is created
1181 // basing on \a n1 and \a n2
1182 // Calling GetMediumPos() with useCurSubShape=true is OK only for the
1183 // case where the lower dim mesh is already constructed and converted to quadratic,
1184 // else, nodes on EDGEs are assigned to FACE, for example.
1185 //=======================================================================
1187 std::pair<int, TopAbs_ShapeEnum>
1188 SMESH_MesherHelper::GetMediumPos(const SMDS_MeshNode* n1,
1189 const SMDS_MeshNode* n2,
1190 const bool useCurSubShape,
1191 TopAbs_ShapeEnum expectedSupport)
1193 if ( useCurSubShape && !myShape.IsNull() )
1194 return std::make_pair( myShapeID, myShape.ShapeType() );
1196 TopAbs_ShapeEnum shapeType = TopAbs_SHAPE;
1200 if (( myShapeID == n1->getshapeId() || myShapeID == n2->getshapeId() ) && myShapeID > 0 )
1202 shapeType = myShape.ShapeType();
1203 shapeID = myShapeID;
1205 else if ( n1->getshapeId() == n2->getshapeId() )
1207 shapeID = n2->getshapeId();
1208 shape = GetSubShapeByNode( n1, GetMeshDS() );
1210 else // 2 different shapes
1212 const SMDS_TypeOfPosition Pos1 = n1->GetPosition()->GetTypeOfPosition();
1213 const SMDS_TypeOfPosition Pos2 = n2->GetPosition()->GetTypeOfPosition();
1215 if ( Pos1 == SMDS_TOP_3DSPACE || Pos2 == SMDS_TOP_3DSPACE )
1219 else if ( Pos1 == SMDS_TOP_FACE || Pos2 == SMDS_TOP_FACE )
1222 if ( Pos1 != SMDS_TOP_FACE || Pos2 != SMDS_TOP_FACE ) // not 2 FACEs
1224 if ( Pos1 != SMDS_TOP_FACE ) std::swap( n1,n2 );
1225 TopoDS_Shape F = GetSubShapeByNode( n1, GetMeshDS() );
1226 TopoDS_Shape S = GetSubShapeByNode( n2, GetMeshDS() );
1227 if ( IsSubShape( S, F ))
1229 shapeType = TopAbs_FACE;
1230 shapeID = n1->getshapeId();
1234 else if ( Pos1 == SMDS_TOP_EDGE && Pos2 == SMDS_TOP_EDGE )
1236 TopoDS_Shape E1 = GetSubShapeByNode( n1, GetMeshDS() );
1237 TopoDS_Shape E2 = GetSubShapeByNode( n2, GetMeshDS() );
1238 shape = GetCommonAncestor( E1, E2, *myMesh, TopAbs_FACE );
1240 else if ( Pos1 == SMDS_TOP_VERTEX && Pos2 == SMDS_TOP_VERTEX )
1242 TopoDS_Shape V1 = GetSubShapeByNode( n1, GetMeshDS() );
1243 TopoDS_Shape V2 = GetSubShapeByNode( n2, GetMeshDS() );
1244 shape = GetCommonAncestor( V1, V2, *myMesh, TopAbs_EDGE );
1245 if ( shape.IsNull() ) shape = GetCommonAncestor( V1, V2, *myMesh, TopAbs_FACE );
1247 else // on VERTEX and EDGE
1249 if ( Pos1 != SMDS_TOP_VERTEX ) std::swap( n1,n2 );
1250 TopoDS_Shape V = GetSubShapeByNode( n1, GetMeshDS() );
1251 TopoDS_Shape E = GetSubShapeByNode( n2, GetMeshDS() );
1252 if ( IsSubShape( V, E ))
1255 shape = GetCommonAncestor( V, E, *myMesh, TopAbs_FACE );
1259 if ( !shape.IsNull() )
1262 shapeID = GetMeshDS()->ShapeToIndex( shape );
1263 shapeType = shape.ShapeType(); // EDGE or FACE
1265 if ( expectedSupport < shapeType &&
1266 expectedSupport != TopAbs_SHAPE &&
1267 !myShape.IsNull() &&
1268 myShape.ShapeType() == expectedSupport )
1270 // e.g. a side of triangle connects nodes on the same EDGE but does not
1271 // lie on this EDGE (an arc with a coarse mesh)
1272 // => shapeType == TopAbs_EDGE, expectedSupport == TopAbs_FACE;
1273 // hope that myShape is a right shape, return it if the found shape
1274 // has converted elements of corresponding dim (segments in our example)
1275 int nbConvertedElems = 0;
1276 SMDSAbs_ElementType type = ( shapeType == TopAbs_FACE ? SMDSAbs_Face : SMDSAbs_Edge );
1277 for ( int iN = 0; iN < 2; ++iN )
1279 const SMDS_MeshNode* n = iN ? n2 : n1;
1280 SMDS_ElemIteratorPtr it = n->GetInverseElementIterator( type );
1281 while ( it->more() )
1283 const SMDS_MeshElement* elem = it->next();
1284 if ( elem->getshapeId() == shapeID &&
1285 elem->IsQuadratic() )
1292 if ( nbConvertedElems == 2 )
1294 shapeType = myShape.ShapeType();
1295 shapeID = myShapeID;
1299 return make_pair( shapeID, shapeType );
1302 //=======================================================================
1303 //function : GetCentralNode
1304 //purpose : Return existing or create a new central node for a quardilateral
1305 // quadratic face given its 8 nodes.
1306 //@param : force3d - true means node creation in between the given nodes,
1307 // else node position is found on a geometrical face if any.
1308 //=======================================================================
1310 const SMDS_MeshNode* SMESH_MesherHelper::GetCentralNode(const SMDS_MeshNode* n1,
1311 const SMDS_MeshNode* n2,
1312 const SMDS_MeshNode* n3,
1313 const SMDS_MeshNode* n4,
1314 const SMDS_MeshNode* n12,
1315 const SMDS_MeshNode* n23,
1316 const SMDS_MeshNode* n34,
1317 const SMDS_MeshNode* n41,
1320 SMDS_MeshNode *centralNode = 0; // central node to return
1322 // Find an existing central node
1324 TBiQuad keyOfMap(n1,n2,n3,n4);
1325 std::map<TBiQuad, const SMDS_MeshNode* >::iterator itMapCentralNode;
1326 itMapCentralNode = myMapWithCentralNode.find( keyOfMap );
1327 if ( itMapCentralNode != myMapWithCentralNode.end() )
1329 return (*itMapCentralNode).second;
1332 // Get type of shape for the new central node
1334 TopAbs_ShapeEnum shapeType = TopAbs_SHAPE;
1338 TopTools_ListIteratorOfListOfShape it;
1340 std::map< int, int > faceId2nbNodes;
1341 std::map< int, int > ::iterator itMapWithIdFace;
1343 SMESHDS_Mesh* meshDS = GetMeshDS();
1345 // check if a face lies on a FACE, i.e. its all corner nodes lie either on the FACE or
1346 // on sub-shapes of the FACE
1347 if ( GetMesh()->HasShapeToMesh() )
1349 const SMDS_MeshNode* nodes[] = { n1, n2, n3, n4 };
1350 for(int i = 0; i < 4; i++)
1352 shape = GetSubShapeByNode( nodes[i], meshDS );
1353 if ( shape.IsNull() ) break;
1354 if ( shape.ShapeType() == TopAbs_SOLID )
1356 solidID = nodes[i]->getshapeId();
1357 shapeType = TopAbs_SOLID;
1360 if ( shape.ShapeType() == TopAbs_FACE )
1362 faceID = nodes[i]->getshapeId();
1363 itMapWithIdFace = faceId2nbNodes.insert( std::make_pair( faceID, 0 ) ).first;
1364 itMapWithIdFace->second++;
1368 PShapeIteratorPtr it = GetAncestors( shape, *GetMesh(), TopAbs_FACE );
1369 while ( const TopoDS_Shape* face = it->next() )
1371 faceID = meshDS->ShapeToIndex( *face );
1372 itMapWithIdFace = faceId2nbNodes.insert( std::make_pair( faceID, 0 )).first;
1373 itMapWithIdFace->second++;
1378 if ( solidID < 1 && !faceId2nbNodes.empty() ) // SOLID not found
1380 // find ID of the FACE the four corner nodes belong to
1381 itMapWithIdFace = faceId2nbNodes.find( myShapeID ); // IPAL52698
1382 if ( itMapWithIdFace != faceId2nbNodes.end() &&
1383 itMapWithIdFace->second == 4 )
1385 shapeType = TopAbs_FACE;
1390 itMapWithIdFace = faceId2nbNodes.begin();
1391 for ( ; itMapWithIdFace != faceId2nbNodes.end(); ++itMapWithIdFace)
1393 if ( itMapWithIdFace->second == 4 )
1395 shapeType = TopAbs_FACE;
1396 faceID = (*itMapWithIdFace).first;
1404 if ( shapeType == TopAbs_FACE )
1406 F = TopoDS::Face( meshDS->IndexToShape( faceID ));
1413 bool toCheck = true;
1414 if ( !F.IsNull() && !force3d )
1416 Handle(ShapeAnalysis_Surface) surface = GetSurface( F );
1417 if ( HasDegeneratedEdges() || surface->HasSingularities( 1e-7 ))
1419 gp_Pnt center = calcTFI (0.5, 0.5, // IPAL0052863
1420 SMESH_TNodeXYZ(n1), SMESH_TNodeXYZ(n2),
1421 SMESH_TNodeXYZ(n3), SMESH_TNodeXYZ(n4),
1422 SMESH_TNodeXYZ(n12), SMESH_TNodeXYZ(n23),
1423 SMESH_TNodeXYZ(n34), SMESH_TNodeXYZ(n41));
1424 gp_Pnt2d uv12 = GetNodeUV( F, n12, n3, &toCheck );
1425 uvAvg = surface->NextValueOfUV( uv12, center, BRep_Tool::Tolerance( F )).XY();
1430 GetNodeUV( F,n1, n3, &toCheck ),
1431 GetNodeUV( F,n2, n4, &toCheck ),
1432 GetNodeUV( F,n3, n1, &toCheck ),
1433 GetNodeUV( F,n4, n2, &toCheck ),
1434 GetNodeUV( F,n12, n3 ),
1435 GetNodeUV( F,n23, n4 ),
1436 GetNodeUV( F,n34, n2 ),
1437 GetNodeUV( F,n41, n2 )
1439 AdjustByPeriod( F, uv, 8 ); // put uv[] within a period (IPAL52698)
1441 uvAvg = calcTFI (0.5, 0.5, uv[0],uv[1],uv[2],uv[3], uv[4],uv[5],uv[6],uv[7] );
1443 P = surface->Value( uvAvg );
1444 centralNode = meshDS->AddNode( P.X(), P.Y(), P.Z() );
1445 // if ( mySetElemOnShape ) node is not elem!
1446 meshDS->SetNodeOnFace( centralNode, faceID, uvAvg.X(), uvAvg.Y() );
1448 else // ( force3d || F.IsNull() )
1450 P = calcTFI (0.5, 0.5,
1451 SMESH_TNodeXYZ(n1), SMESH_TNodeXYZ(n2),
1452 SMESH_TNodeXYZ(n3), SMESH_TNodeXYZ(n4),
1453 SMESH_TNodeXYZ(n12), SMESH_TNodeXYZ(n23),
1454 SMESH_TNodeXYZ(n34), SMESH_TNodeXYZ(n41));
1455 centralNode = meshDS->AddNode( P.X(), P.Y(), P.Z() );
1457 if ( !F.IsNull() ) // force3d
1459 uvAvg = (GetNodeUV(F,n1,n3,&toCheck) +
1460 GetNodeUV(F,n2,n4,&toCheck) +
1461 GetNodeUV(F,n3,n1,&toCheck) +
1462 GetNodeUV(F,n4,n2,&toCheck)) / 4;
1463 //CheckNodeUV( F, centralNode, uvAvg, 2*BRep_Tool::Tolerance( F ), /*force=*/true);
1464 meshDS->SetNodeOnFace( centralNode, faceID, uvAvg.X(), uvAvg.Y() );
1466 else if ( solidID > 0 )
1468 meshDS->SetNodeInVolume( centralNode, solidID );
1470 else if ( myShapeID > 0 && mySetElemOnShape )
1472 meshDS->SetMeshElementOnShape( centralNode, myShapeID );
1475 myMapWithCentralNode.insert( std::make_pair( keyOfMap, centralNode ) );
1479 //=======================================================================
1480 //function : GetCentralNode
1481 //purpose : Return existing or create a new central node for a
1482 // quadratic triangle given its 6 nodes.
1483 //@param : force3d - true means node creation in between the given nodes,
1484 // else node position is found on a geometrical face if any.
1485 //=======================================================================
1487 const SMDS_MeshNode* SMESH_MesherHelper::GetCentralNode(const SMDS_MeshNode* n1,
1488 const SMDS_MeshNode* n2,
1489 const SMDS_MeshNode* n3,
1490 const SMDS_MeshNode* n12,
1491 const SMDS_MeshNode* n23,
1492 const SMDS_MeshNode* n31,
1495 SMDS_MeshNode *centralNode = 0; // central node to return
1497 // Find an existing central node
1499 TBiQuad keyOfMap(n1,n2,n3);
1500 std::map<TBiQuad, const SMDS_MeshNode* >::iterator itMapCentralNode;
1501 itMapCentralNode = myMapWithCentralNode.find( keyOfMap );
1502 if ( itMapCentralNode != myMapWithCentralNode.end() )
1504 return (*itMapCentralNode).second;
1507 // Get type of shape for the new central node
1509 TopAbs_ShapeEnum shapeType = TopAbs_SHAPE;
1513 TopTools_ListIteratorOfListOfShape it;
1515 std::map< int, int > faceId2nbNodes;
1516 std::map< int, int > ::iterator itMapWithIdFace;
1518 SMESHDS_Mesh* meshDS = GetMeshDS();
1520 // check if a face lies on a FACE, i.e. its all corner nodes lie either on the FACE or
1521 // on sub-shapes of the FACE
1522 if ( GetMesh()->HasShapeToMesh() )
1524 const SMDS_MeshNode* nodes[] = { n1, n2, n3 };
1525 for(int i = 0; i < 3; i++)
1527 shape = GetSubShapeByNode( nodes[i], meshDS );
1528 if ( shape.IsNull() ) break;
1529 if ( shape.ShapeType() == TopAbs_SOLID )
1531 solidID = nodes[i]->getshapeId();
1532 shapeType = TopAbs_SOLID;
1535 if ( shape.ShapeType() == TopAbs_FACE )
1537 faceID = nodes[i]->getshapeId();
1538 itMapWithIdFace = faceId2nbNodes.insert( std::make_pair( faceID, 0 ) ).first;
1539 itMapWithIdFace->second++;
1543 PShapeIteratorPtr it = GetAncestors(shape, *GetMesh(), TopAbs_FACE );
1544 while ( const TopoDS_Shape* face = it->next() )
1546 faceID = meshDS->ShapeToIndex( *face );
1547 itMapWithIdFace = faceId2nbNodes.insert( std::make_pair( faceID, 0 ) ).first;
1548 itMapWithIdFace->second++;
1553 if ( solidID < 1 && !faceId2nbNodes.empty() ) // SOLID not found
1555 // find ID of the FACE the four corner nodes belong to
1556 itMapWithIdFace = faceId2nbNodes.find( myShapeID ); // IPAL52698
1557 if ( itMapWithIdFace != faceId2nbNodes.end() &&
1558 itMapWithIdFace->second == 4 )
1560 shapeType = TopAbs_FACE;
1565 itMapWithIdFace = faceId2nbNodes.begin();
1566 for ( ; itMapWithIdFace != faceId2nbNodes.end(); ++itMapWithIdFace)
1568 if ( itMapWithIdFace->second == 3 )
1570 shapeType = TopAbs_FACE;
1571 faceID = (*itMapWithIdFace).first;
1581 if ( shapeType == TopAbs_FACE )
1583 F = TopoDS::Face( meshDS->IndexToShape( faceID ));
1584 bool checkOK = true, badTria = false;
1586 GetNodeUV( F, n1, n23, &checkOK ),
1587 GetNodeUV( F, n2, n31, &checkOK ),
1588 GetNodeUV( F, n3, n12, &checkOK ),
1589 GetNodeUV( F, n12, n3, &checkOK ),
1590 GetNodeUV( F, n23, n1, &checkOK ),
1591 GetNodeUV( F, n31, n2, &checkOK )
1593 AdjustByPeriod( F, uv, 6 ); // put uv[] within a period (IPAL52698)
1595 uvAvg = GetCenterUV( uv[0],uv[1],uv[2], uv[3],uv[4],uv[5], &badTria );
1597 if ( badTria || !checkOK )
1601 // Create a central node
1604 if ( !F.IsNull() && !force3d )
1606 TopLoc_Location loc;
1607 Handle( Geom_Surface ) S = BRep_Tool::Surface( F, loc );
1608 P = S->Value( uvAvg.X(), uvAvg.Y() ).Transformed( loc );
1609 centralNode = meshDS->AddNode( P.X(), P.Y(), P.Z() );
1610 // if ( mySetElemOnShape ) node is not elem!
1611 meshDS->SetNodeOnFace( centralNode, faceID, uvAvg.X(), uvAvg.Y() );
1613 else // ( force3d || F.IsNull() )
1615 P = ( SMESH_TNodeXYZ( n12 ) +
1616 SMESH_TNodeXYZ( n23 ) +
1617 SMESH_TNodeXYZ( n31 ) ) / 3;
1618 centralNode = meshDS->AddNode( P.X(), P.Y(), P.Z() );
1620 if ( !F.IsNull() ) // force3d
1622 meshDS->SetNodeOnFace( centralNode, faceID, uvAvg.X(), uvAvg.Y() );
1624 else if ( solidID > 0 )
1626 meshDS->SetNodeInVolume( centralNode, solidID );
1628 else if ( myShapeID > 0 && mySetElemOnShape )
1630 meshDS->SetMeshElementOnShape( centralNode, myShapeID );
1633 myMapWithCentralNode.insert( std::make_pair( keyOfMap, centralNode ) );
1637 //=======================================================================
1638 //function : GetMediumNode
1639 //purpose : Return existing or create a new medium node between given ones
1640 //=======================================================================
1642 const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1,
1643 const SMDS_MeshNode* n2,
1645 TopAbs_ShapeEnum expectedSupport)
1647 // Find existing node
1649 SMESH_TLink link(n1,n2);
1650 ItTLinkNode itLN = myTLinkNodeMap.find( link );
1651 if ( itLN != myTLinkNodeMap.end() ) {
1652 return (*itLN).second;
1655 // Create medium node
1658 SMESHDS_Mesh* meshDS = GetMeshDS();
1660 if ( IsSeamShape( n1->getshapeId() ))
1661 // to get a correct UV of a node on seam, the second node must have checked UV
1662 std::swap( n1, n2 );
1664 // get type of shape for the new medium node
1665 int faceID = -1, edgeID = -1;
1666 TopoDS_Edge E; double u [2] = {0.,0.};
1667 TopoDS_Face F; gp_XY uv[2];
1668 bool uvOK[2] = { true, true };
1669 const bool useCurSubShape = ( !myShape.IsNull() && myShape.ShapeType() == TopAbs_EDGE );
1671 pair<int, TopAbs_ShapeEnum> pos = GetMediumPos( n1, n2, useCurSubShape, expectedSupport );
1673 // get positions of the given nodes on shapes
1674 if ( pos.second == TopAbs_FACE )
1676 F = TopoDS::Face(meshDS->IndexToShape( faceID = pos.first ));
1677 uv[0] = GetNodeUV(F,n1,n2, force3d ? 0 : &uvOK[0]);
1679 ( HasDegeneratedEdges() || GetSurface( F )->HasSingularities( 1e-7 )))
1681 // IPAL52850 (degen VERTEX not at singularity)
1682 // project middle point to a surface
1683 SMESH_TNodeXYZ p1( n1 ), p2( n2 );
1684 gp_Pnt pMid = 0.5 * ( p1 + p2 );
1685 Handle(ShapeAnalysis_Surface) projector = GetSurface( F );
1688 uvMid = projector->NextValueOfUV( uv[0], pMid, BRep_Tool::Tolerance( F ));
1690 uvMid = projector->ValueOfUV( pMid, getFaceMaxTol( F ));
1691 if ( projector->Gap() * projector->Gap() < ( p1 - p2 ).SquareModulus() / 4 )
1693 gp_Pnt pProj = projector->Value( uvMid );
1694 n12 = meshDS->AddNode( pProj.X(), pProj.Y(), pProj.Z() );
1695 meshDS->SetNodeOnFace( n12, faceID, uvMid.X(), uvMid.Y() );
1696 myTLinkNodeMap.insert( make_pair ( link, n12 ));
1700 uv[1] = GetNodeUV(F,n2,n1, force3d ? 0 : &uvOK[1]);
1702 else if ( pos.second == TopAbs_EDGE )
1704 const SMDS_PositionPtr Pos1 = n1->GetPosition();
1705 const SMDS_PositionPtr Pos2 = n2->GetPosition();
1706 if ( Pos1->GetTypeOfPosition()==SMDS_TOP_EDGE &&
1707 Pos2->GetTypeOfPosition()==SMDS_TOP_EDGE &&
1708 n1->getshapeId() != n2->getshapeId() )
1711 return getMediumNodeOnComposedWire(n1,n2,force3d);
1713 E = TopoDS::Edge(meshDS->IndexToShape( edgeID = pos.first ));
1715 u[0] = GetNodeU(E,n1,n2, force3d ? 0 : &uvOK[0]);
1716 u[1] = GetNodeU(E,n2,n1, force3d ? 0 : &uvOK[1]);
1718 catch ( Standard_Failure& f )
1720 // issue 22502 / a node is on VERTEX not belonging to E
1721 // issue 22568 / both nodes are on non-connected VERTEXes
1722 return getMediumNodeOnComposedWire(n1,n2,force3d);
1726 if ( !force3d & uvOK[0] && uvOK[1] )
1728 // we try to create medium node using UV parameters of
1729 // nodes, else - medium between corresponding 3d points
1732 //if ( uvOK[0] && uvOK[1] )
1734 if ( IsDegenShape( n1->getshapeId() )) {
1735 if ( myParIndex & U_periodic ) uv[0].SetCoord( 1, uv[1].Coord( 1 ));
1736 else uv[0].SetCoord( 2, uv[1].Coord( 2 ));
1738 else if ( IsDegenShape( n2->getshapeId() )) {
1739 if ( myParIndex & U_periodic ) uv[1].SetCoord( 1, uv[0].Coord( 1 ));
1740 else uv[1].SetCoord( 2, uv[0].Coord( 2 ));
1742 TopLoc_Location loc;
1743 Handle(Geom_Surface) S = BRep_Tool::Surface(F,loc);
1744 gp_XY UV = GetMiddleUV( S, uv[0], uv[1] );
1745 gp_Pnt P = S->Value( UV.X(), UV.Y() ).Transformed(loc);
1746 n12 = meshDS->AddNode(P.X(), P.Y(), P.Z());
1747 // if ( mySetElemOnShape ) node is not elem!
1748 meshDS->SetNodeOnFace(n12, faceID, UV.X(), UV.Y());
1749 myTLinkNodeMap.insert(make_pair(link,n12));
1753 else if ( !E.IsNull() )
1756 Handle(Geom_Curve) C = BRep_Tool::Curve(E, f, l);
1759 Standard_Boolean isPeriodic = C->IsPeriodic();
1762 Standard_Real Period = C->Period();
1763 Standard_Real p = u[1]+ShapeAnalysis::AdjustByPeriod(u[1],u[0],Period);
1764 Standard_Real pmid = (u[0]+p)/2.;
1765 U = pmid+ShapeAnalysis::AdjustToPeriod(pmid,C->FirstParameter(),C->LastParameter());
1770 gp_Pnt P = C->Value( U );
1771 n12 = meshDS->AddNode(P.X(), P.Y(), P.Z());
1772 //if ( mySetElemOnShape ) node is not elem!
1773 meshDS->SetNodeOnEdge(n12, edgeID, U);
1774 myTLinkNodeMap.insert(make_pair(link,n12));
1781 double x = ( n1->X() + n2->X() )/2.;
1782 double y = ( n1->Y() + n2->Y() )/2.;
1783 double z = ( n1->Z() + n2->Z() )/2.;
1784 n12 = meshDS->AddNode(x,y,z);
1786 //if ( mySetElemOnShape ) node is not elem!
1790 gp_XY UV = ( uv[0] + uv[1] ) / 2.;
1791 CheckNodeUV( F, n12, UV, 2 * BRep_Tool::Tolerance( F ), /*force=*/true);
1792 meshDS->SetNodeOnFace(n12, faceID, UV.X(), UV.Y() );
1794 else if ( !E.IsNull() )
1796 double U = ( u[0] + u[1] ) / 2.;
1797 CheckNodeU( E, n12, U, 2 * BRep_Tool::Tolerance( E ), /*force=*/true);
1798 meshDS->SetNodeOnEdge(n12, edgeID, U);
1800 else if ( myShapeID > 0 && mySetElemOnShape )
1802 meshDS->SetMeshElementOnShape(n12, myShapeID);
1806 myTLinkNodeMap.insert( make_pair( link, n12 ));
1810 //================================================================================
1812 * \brief Makes a medium node if nodes reside different edges
1814 //================================================================================
1816 const SMDS_MeshNode* SMESH_MesherHelper::getMediumNodeOnComposedWire(const SMDS_MeshNode* n1,
1817 const SMDS_MeshNode* n2,
1820 SMESH_TNodeXYZ p1( n1 ), p2( n2 );
1821 gp_Pnt middle = 0.5 * p1 + 0.5 * p2;
1822 SMDS_MeshNode* n12 = AddNode( middle.X(), middle.Y(), middle.Z() );
1824 // To find position on edge and 3D position for n12,
1825 // project <middle> to 2 edges and select projection most close to <middle>
1827 TopoDS_Edge bestEdge;
1828 double u = 0, distMiddleProj = Precision::Infinite(), distXYZ[4], f,l;
1830 // get shapes under the nodes
1831 TopoDS_Shape shape[2];
1833 for ( int is2nd = 0; is2nd < 2; ++is2nd )
1835 const SMDS_MeshNode* n = is2nd ? n2 : n1;
1836 TopoDS_Shape S = GetSubShapeByNode( n, GetMeshDS() );
1838 shape[ nbShapes++ ] = S;
1841 vector< TopoDS_Shape > edges;
1842 for ( int iS = 0; iS < nbShapes; ++iS )
1844 switch ( shape[iS].ShapeType() ) {
1847 edges.push_back( shape[iS] );
1853 if ( nbShapes == 2 && iS==0 && shape[1-iS].ShapeType() == TopAbs_VERTEX )
1854 edge = GetCommonAncestor( shape[iS], shape[1-iS], *myMesh, TopAbs_EDGE );
1856 if ( edge.IsNull() )
1858 PShapeIteratorPtr eIt = GetAncestors( shape[iS], *myMesh, TopAbs_EDGE );
1859 while( const TopoDS_Shape* e = eIt->next() )
1860 edges.push_back( *e );
1866 if ( nbShapes == 1 || shape[1-iS].ShapeType() < TopAbs_EDGE )
1867 for ( TopExp_Explorer e( shape[iS], TopAbs_EDGE ); e.More(); e.Next() )
1868 edges.push_back( e.Current() );
1875 // project to get U of projection and distance from middle to projection
1876 for ( size_t iE = 0; iE < edges.size(); ++iE )
1878 const TopoDS_Edge& edge = TopoDS::Edge( edges[ iE ]);
1879 distXYZ[0] = distMiddleProj;
1881 CheckNodeU( edge, n12, testU, 2 * BRep_Tool::Tolerance(edge), /*force=*/true, distXYZ );
1882 if ( distXYZ[0] < distMiddleProj )
1884 distMiddleProj = distXYZ[0];
1890 // // both projections failed; set n12 on the edge of n1 with U of a common vertex
1891 // TopoDS_Vertex vCommon;
1892 // if ( TopExp::CommonVertex( edges[0], edges[1], vCommon ))
1893 // u = BRep_Tool::Parameter( vCommon, edges[0] );
1896 // double f,l, u0 = GetNodeU( edges[0], n1 );
1897 // BRep_Tool::Range( edges[0],f,l );
1898 // u = ( fabs(u0-f) < fabs(u0-l) ) ? f : l;
1901 // distMiddleProj = 0;
1904 if ( !bestEdge.IsNull() )
1906 // move n12 to position of a successful projection
1907 //double tol = BRep_Tool::Tolerance(edges[ iOkEdge ]);
1908 if ( !force3d /*&& distMiddleProj > 2*tol*/ )
1910 TopLoc_Location loc;
1911 Handle(Geom_Curve) curve = BRep_Tool::Curve( bestEdge,loc,f,l );
1912 gp_Pnt p = curve->Value( u ).Transformed( loc );
1913 GetMeshDS()->MoveNode( n12, p.X(), p.Y(), p.Z() );
1915 //if ( mySetElemOnShape ) node is not elem!
1917 int edgeID = GetMeshDS()->ShapeToIndex( bestEdge );
1918 if ( edgeID != n12->getshapeId() )
1919 GetMeshDS()->UnSetNodeOnShape( n12 );
1920 GetMeshDS()->SetNodeOnEdge(n12, edgeID, u);
1923 myTLinkNodeMap.insert( make_pair( SMESH_TLink(n1,n2), n12 ));
1928 //=======================================================================
1929 //function : AddNode
1930 //purpose : Creates a node
1931 //=======================================================================
1933 SMDS_MeshNode* SMESH_MesherHelper::AddNode(double x, double y, double z, int ID,
1936 SMESHDS_Mesh * meshDS = GetMeshDS();
1937 SMDS_MeshNode* node = 0;
1939 node = meshDS->AddNodeWithID( x, y, z, ID );
1941 node = meshDS->AddNode( x, y, z );
1942 if ( mySetElemOnShape && myShapeID > 0 ) { // node is not elem ?
1943 switch ( myShape.ShapeType() ) {
1944 case TopAbs_SOLID: meshDS->SetNodeInVolume( node, myShapeID); break;
1945 case TopAbs_SHELL: meshDS->SetNodeInVolume( node, myShapeID); break;
1946 case TopAbs_FACE: meshDS->SetNodeOnFace( node, myShapeID, u, v); break;
1947 case TopAbs_EDGE: meshDS->SetNodeOnEdge( node, myShapeID, u); break;
1948 case TopAbs_VERTEX: meshDS->SetNodeOnVertex( node, myShapeID); break;
1955 //=======================================================================
1956 //function : AddEdge
1957 //purpose : Creates quadratic or linear edge
1958 //=======================================================================
1960 SMDS_MeshEdge* SMESH_MesherHelper::AddEdge(const SMDS_MeshNode* n1,
1961 const SMDS_MeshNode* n2,
1965 SMESHDS_Mesh * meshDS = GetMeshDS();
1967 SMDS_MeshEdge* edge = 0;
1968 if (myCreateQuadratic) {
1969 const SMDS_MeshNode* n12 = GetMediumNode(n1,n2,force3d);
1971 edge = meshDS->AddEdgeWithID(n1, n2, n12, id);
1973 edge = meshDS->AddEdge(n1, n2, n12);
1977 edge = meshDS->AddEdgeWithID(n1, n2, id);
1979 edge = meshDS->AddEdge(n1, n2);
1982 if ( mySetElemOnShape && myShapeID > 0 )
1983 meshDS->SetMeshElementOnShape( edge, myShapeID );
1988 //=======================================================================
1989 //function : AddFace
1990 //purpose : Creates quadratic or linear triangle
1991 //=======================================================================
1993 SMDS_MeshFace* SMESH_MesherHelper::AddFace(const SMDS_MeshNode* n1,
1994 const SMDS_MeshNode* n2,
1995 const SMDS_MeshNode* n3,
1999 SMESHDS_Mesh * meshDS = GetMeshDS();
2000 SMDS_MeshFace* elem = 0;
2002 if( n1==n2 || n2==n3 || n3==n1 )
2005 if(!myCreateQuadratic) {
2007 elem = meshDS->AddFaceWithID(n1, n2, n3, id);
2009 elem = meshDS->AddFace(n1, n2, n3);
2012 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_FACE );
2013 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_FACE );
2014 const SMDS_MeshNode* n31 = GetMediumNode( n3, n1, force3d, TopAbs_FACE );
2015 if(myCreateBiQuadratic)
2017 const SMDS_MeshNode* nCenter = GetCentralNode(n1, n2, n3, n12, n23, n31, force3d);
2019 elem = meshDS->AddFaceWithID(n1, n2, n3, n12, n23, n31, nCenter, id);
2021 elem = meshDS->AddFace(n1, n2, n3, n12, n23, n31, nCenter);
2026 elem = meshDS->AddFaceWithID(n1, n2, n3, n12, n23, n31, id);
2028 elem = meshDS->AddFace(n1, n2, n3, n12, n23, n31);
2031 if ( mySetElemOnShape && myShapeID > 0 )
2032 meshDS->SetMeshElementOnShape( elem, myShapeID );
2037 //=======================================================================
2038 //function : AddFace
2039 //purpose : Creates bi-quadratic, quadratic or linear quadrangle
2040 //=======================================================================
2042 SMDS_MeshFace* SMESH_MesherHelper::AddFace(const SMDS_MeshNode* n1,
2043 const SMDS_MeshNode* n2,
2044 const SMDS_MeshNode* n3,
2045 const SMDS_MeshNode* n4,
2049 SMESHDS_Mesh * meshDS = GetMeshDS();
2050 SMDS_MeshFace* elem = 0;
2053 return AddFace(n1,n3,n4,id,force3d);
2056 return AddFace(n1,n2,n4,id,force3d);
2059 return AddFace(n1,n2,n3,id,force3d);
2062 return AddFace(n1,n2,n4,id,force3d);
2065 return AddFace(n1,n2,n3,id,force3d);
2068 return AddFace(n1,n2,n3,id,force3d);
2071 if(!myCreateQuadratic) {
2073 elem = meshDS->AddFaceWithID(n1, n2, n3, n4, id);
2075 elem = meshDS->AddFace(n1, n2, n3, n4);
2078 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_FACE );
2079 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_FACE );
2080 const SMDS_MeshNode* n34 = GetMediumNode( n3, n4, force3d, TopAbs_FACE );
2081 const SMDS_MeshNode* n41 = GetMediumNode( n4, n1, force3d, TopAbs_FACE );
2082 if(myCreateBiQuadratic)
2084 const SMDS_MeshNode* nCenter = GetCentralNode(n1, n2, n3, n4, n12, n23, n34, n41, force3d);
2086 elem = meshDS->AddFaceWithID(n1, n2, n3, n4, n12, n23, n34, n41, nCenter, id);
2088 elem = meshDS->AddFace(n1, n2, n3, n4, n12, n23, n34, n41, nCenter);
2093 elem = meshDS->AddFaceWithID(n1, n2, n3, n4, n12, n23, n34, n41, id);
2095 elem = meshDS->AddFace(n1, n2, n3, n4, n12, n23, n34, n41);
2098 if ( mySetElemOnShape && myShapeID > 0 )
2099 meshDS->SetMeshElementOnShape( elem, myShapeID );
2104 //=======================================================================
2105 //function : AddPolygonalFace
2106 //purpose : Creates polygon, with additional nodes in quadratic mesh
2107 //=======================================================================
2109 SMDS_MeshFace* SMESH_MesherHelper::AddPolygonalFace (const vector<const SMDS_MeshNode*>& nodes,
2113 SMESHDS_Mesh * meshDS = GetMeshDS();
2114 SMDS_MeshFace* elem = 0;
2116 if(!myCreateQuadratic)
2119 elem = meshDS->AddPolygonalFaceWithID(nodes, id);
2121 elem = meshDS->AddPolygonalFace(nodes);
2125 vector<const SMDS_MeshNode*> newNodes( nodes.size() * 2 );
2127 for ( size_t i = 0; i < nodes.size(); ++i )
2129 const SMDS_MeshNode* n1 = nodes[i];
2130 const SMDS_MeshNode* n2 = nodes[(i+1)%nodes.size()];
2131 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_FACE );
2132 newNodes.push_back( n12 );
2135 elem = meshDS->AddQuadPolygonalFaceWithID(newNodes, id);
2137 elem = meshDS->AddQuadPolygonalFace(newNodes);
2139 if ( mySetElemOnShape && myShapeID > 0 )
2140 meshDS->SetMeshElementOnShape( elem, myShapeID );
2145 //=======================================================================
2146 //function : AddVolume
2147 //purpose : Creates quadratic or linear prism
2148 //=======================================================================
2150 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2151 const SMDS_MeshNode* n2,
2152 const SMDS_MeshNode* n3,
2153 const SMDS_MeshNode* n4,
2154 const SMDS_MeshNode* n5,
2155 const SMDS_MeshNode* n6,
2159 SMESHDS_Mesh * meshDS = GetMeshDS();
2160 SMDS_MeshVolume* elem = 0;
2161 if(!myCreateQuadratic) {
2163 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, id);
2165 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6);
2168 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2169 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_SOLID );
2170 const SMDS_MeshNode* n31 = GetMediumNode( n3, n1, force3d, TopAbs_SOLID );
2172 const SMDS_MeshNode* n45 = GetMediumNode( n4, n5, force3d, TopAbs_SOLID );
2173 const SMDS_MeshNode* n56 = GetMediumNode( n5, n6, force3d, TopAbs_SOLID );
2174 const SMDS_MeshNode* n64 = GetMediumNode( n6, n4, force3d, TopAbs_SOLID );
2176 const SMDS_MeshNode* n14 = GetMediumNode( n1, n4, force3d, TopAbs_SOLID );
2177 const SMDS_MeshNode* n25 = GetMediumNode( n2, n5, force3d, TopAbs_SOLID );
2178 const SMDS_MeshNode* n36 = GetMediumNode( n3, n6, force3d, TopAbs_SOLID );
2179 if ( myCreateBiQuadratic )
2181 const SMDS_MeshNode* n1245 = GetCentralNode( n1,n2,n4,n5,n12,n25,n45,n14,force3d );
2182 const SMDS_MeshNode* n1346 = GetCentralNode( n1,n3,n4,n6,n31,n36,n64,n14,force3d );
2183 const SMDS_MeshNode* n2356 = GetCentralNode( n2,n3,n6,n5,n23,n36,n56,n25,force3d );
2186 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6,
2187 n12, n23, n31, n45, n56, n64, n14, n25, n36,
2188 n1245, n2356, n1346, id);
2190 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6,
2191 n12, n23, n31, n45, n56, n64, n14, n25, n36,
2192 n1245, n2356, n1346);
2197 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6,
2198 n12, n23, n31, n45, n56, n64, n14, n25, n36, id);
2200 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6,
2201 n12, n23, n31, n45, n56, n64, n14, n25, n36);
2204 if ( mySetElemOnShape && myShapeID > 0 )
2205 meshDS->SetMeshElementOnShape( elem, myShapeID );
2210 //=======================================================================
2211 //function : AddVolume
2212 //purpose : Creates quadratic or linear tetrahedron
2213 //=======================================================================
2215 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2216 const SMDS_MeshNode* n2,
2217 const SMDS_MeshNode* n3,
2218 const SMDS_MeshNode* n4,
2222 SMESHDS_Mesh * meshDS = GetMeshDS();
2223 SMDS_MeshVolume* elem = 0;
2224 if(!myCreateQuadratic) {
2226 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, id);
2228 elem = meshDS->AddVolume(n1, n2, n3, n4);
2231 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2232 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_SOLID );
2233 const SMDS_MeshNode* n31 = GetMediumNode( n3, n1, force3d, TopAbs_SOLID );
2235 const SMDS_MeshNode* n14 = GetMediumNode( n1, n4, force3d, TopAbs_SOLID );
2236 const SMDS_MeshNode* n24 = GetMediumNode( n2, n4, force3d, TopAbs_SOLID );
2237 const SMDS_MeshNode* n34 = GetMediumNode( n3, n4, force3d, TopAbs_SOLID );
2240 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n12, n23, n31, n14, n24, n34, id);
2242 elem = meshDS->AddVolume(n1, n2, n3, n4, n12, n23, n31, n14, n24, n34);
2244 if ( mySetElemOnShape && myShapeID > 0 )
2245 meshDS->SetMeshElementOnShape( elem, myShapeID );
2250 //=======================================================================
2251 //function : AddVolume
2252 //purpose : Creates quadratic or linear pyramid
2253 //=======================================================================
2255 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2256 const SMDS_MeshNode* n2,
2257 const SMDS_MeshNode* n3,
2258 const SMDS_MeshNode* n4,
2259 const SMDS_MeshNode* n5,
2263 SMDS_MeshVolume* elem = 0;
2264 if(!myCreateQuadratic) {
2266 elem = GetMeshDS()->AddVolumeWithID(n1, n2, n3, n4, n5, id);
2268 elem = GetMeshDS()->AddVolume(n1, n2, n3, n4, n5);
2271 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2272 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_SOLID );
2273 const SMDS_MeshNode* n34 = GetMediumNode( n3, n4, force3d, TopAbs_SOLID );
2274 const SMDS_MeshNode* n41 = GetMediumNode( n4, n1, force3d, TopAbs_SOLID );
2276 const SMDS_MeshNode* n15 = GetMediumNode( n1, n5, force3d, TopAbs_SOLID );
2277 const SMDS_MeshNode* n25 = GetMediumNode( n2, n5, force3d, TopAbs_SOLID );
2278 const SMDS_MeshNode* n35 = GetMediumNode( n3, n5, force3d, TopAbs_SOLID );
2279 const SMDS_MeshNode* n45 = GetMediumNode( n4, n5, force3d, TopAbs_SOLID );
2282 elem = GetMeshDS()->AddVolumeWithID ( n1, n2, n3, n4, n5,
2287 elem = GetMeshDS()->AddVolume( n1, n2, n3, n4, n5,
2289 n15, n25, n35, n45);
2291 if ( mySetElemOnShape && myShapeID > 0 )
2292 GetMeshDS()->SetMeshElementOnShape( elem, myShapeID );
2297 //=======================================================================
2298 //function : AddVolume
2299 //purpose : Creates tri-quadratic, quadratic or linear hexahedron
2300 //=======================================================================
2302 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2303 const SMDS_MeshNode* n2,
2304 const SMDS_MeshNode* n3,
2305 const SMDS_MeshNode* n4,
2306 const SMDS_MeshNode* n5,
2307 const SMDS_MeshNode* n6,
2308 const SMDS_MeshNode* n7,
2309 const SMDS_MeshNode* n8,
2313 SMESHDS_Mesh * meshDS = GetMeshDS();
2314 SMDS_MeshVolume* elem = 0;
2315 if(!myCreateQuadratic) {
2317 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, id);
2319 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
2322 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2323 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_SOLID );
2324 const SMDS_MeshNode* n34 = GetMediumNode( n3, n4, force3d, TopAbs_SOLID );
2325 const SMDS_MeshNode* n41 = GetMediumNode( n4, n1, force3d, TopAbs_SOLID );
2327 const SMDS_MeshNode* n56 = GetMediumNode( n5, n6, force3d, TopAbs_SOLID );
2328 const SMDS_MeshNode* n67 = GetMediumNode( n6, n7, force3d, TopAbs_SOLID );
2329 const SMDS_MeshNode* n78 = GetMediumNode( n7, n8, force3d, TopAbs_SOLID );
2330 const SMDS_MeshNode* n85 = GetMediumNode( n8, n5, force3d, TopAbs_SOLID );
2332 const SMDS_MeshNode* n15 = GetMediumNode( n1, n5, force3d, TopAbs_SOLID );
2333 const SMDS_MeshNode* n26 = GetMediumNode( n2, n6, force3d, TopAbs_SOLID );
2334 const SMDS_MeshNode* n37 = GetMediumNode( n3, n7, force3d, TopAbs_SOLID );
2335 const SMDS_MeshNode* n48 = GetMediumNode( n4, n8, force3d, TopAbs_SOLID );
2336 if ( myCreateBiQuadratic )
2338 const SMDS_MeshNode* n1234 = GetCentralNode( n1,n2,n3,n4,n12,n23,n34,n41,force3d );
2339 const SMDS_MeshNode* n1256 = GetCentralNode( n1,n2,n5,n6,n12,n26,n56,n15,force3d );
2340 const SMDS_MeshNode* n2367 = GetCentralNode( n2,n3,n6,n7,n23,n37,n67,n26,force3d );
2341 const SMDS_MeshNode* n3478 = GetCentralNode( n3,n4,n7,n8,n34,n48,n78,n37,force3d );
2342 const SMDS_MeshNode* n1458 = GetCentralNode( n1,n4,n5,n8,n41,n48,n15,n85,force3d );
2343 const SMDS_MeshNode* n5678 = GetCentralNode( n5,n6,n7,n8,n56,n67,n78,n85,force3d );
2345 vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
2347 pointsOnShapes[ SMESH_Block::ID_V000 ] = SMESH_TNodeXYZ( n4 );
2348 pointsOnShapes[ SMESH_Block::ID_V100 ] = SMESH_TNodeXYZ( n8 );
2349 pointsOnShapes[ SMESH_Block::ID_V010 ] = SMESH_TNodeXYZ( n3 );
2350 pointsOnShapes[ SMESH_Block::ID_V110 ] = SMESH_TNodeXYZ( n7 );
2351 pointsOnShapes[ SMESH_Block::ID_V001 ] = SMESH_TNodeXYZ( n1 );
2352 pointsOnShapes[ SMESH_Block::ID_V101 ] = SMESH_TNodeXYZ( n5 );
2353 pointsOnShapes[ SMESH_Block::ID_V011 ] = SMESH_TNodeXYZ( n2 );
2354 pointsOnShapes[ SMESH_Block::ID_V111 ] = SMESH_TNodeXYZ( n6 );
2356 pointsOnShapes[ SMESH_Block::ID_Ex00 ] = SMESH_TNodeXYZ( n48 );
2357 pointsOnShapes[ SMESH_Block::ID_Ex10 ] = SMESH_TNodeXYZ( n37 );
2358 pointsOnShapes[ SMESH_Block::ID_E0y0 ] = SMESH_TNodeXYZ( n15 );
2359 pointsOnShapes[ SMESH_Block::ID_E1y0 ] = SMESH_TNodeXYZ( n26 );
2360 pointsOnShapes[ SMESH_Block::ID_Ex01 ] = SMESH_TNodeXYZ( n34 );
2361 pointsOnShapes[ SMESH_Block::ID_Ex11 ] = SMESH_TNodeXYZ( n78 );
2362 pointsOnShapes[ SMESH_Block::ID_E0y1 ] = SMESH_TNodeXYZ( n12 );
2363 pointsOnShapes[ SMESH_Block::ID_E1y1 ] = SMESH_TNodeXYZ( n56 );
2364 pointsOnShapes[ SMESH_Block::ID_E00z ] = SMESH_TNodeXYZ( n41 );
2365 pointsOnShapes[ SMESH_Block::ID_E10z ] = SMESH_TNodeXYZ( n85 );
2366 pointsOnShapes[ SMESH_Block::ID_E01z ] = SMESH_TNodeXYZ( n23 );
2367 pointsOnShapes[ SMESH_Block::ID_E11z ] = SMESH_TNodeXYZ( n67 );
2369 pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = SMESH_TNodeXYZ( n3478 );
2370 pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = SMESH_TNodeXYZ( n1256 );
2371 pointsOnShapes[ SMESH_Block::ID_Fx0z ] = SMESH_TNodeXYZ( n1458 );
2372 pointsOnShapes[ SMESH_Block::ID_Fx1z ] = SMESH_TNodeXYZ( n2367 );
2373 pointsOnShapes[ SMESH_Block::ID_F0yz ] = SMESH_TNodeXYZ( n1234 );
2374 pointsOnShapes[ SMESH_Block::ID_F1yz ] = SMESH_TNodeXYZ( n5678 );
2376 gp_XYZ centerCube(0.5, 0.5, 0.5);
2378 SMESH_Block::ShellPoint( centerCube, pointsOnShapes, nCenterElem );
2379 const SMDS_MeshNode* nCenter =
2380 meshDS->AddNode( nCenterElem.X(), nCenterElem.Y(), nCenterElem.Z() );
2381 meshDS->SetNodeInVolume( nCenter, myShapeID );
2384 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8,
2385 n12, n23, n34, n41, n56, n67,
2386 n78, n85, n15, n26, n37, n48,
2387 n1234, n1256, n2367, n3478, n1458, n5678, nCenter, id);
2389 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6, n7, n8,
2390 n12, n23, n34, n41, n56, n67,
2391 n78, n85, n15, n26, n37, n48,
2392 n1234, n1256, n2367, n3478, n1458, n5678, nCenter);
2397 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8,
2398 n12, n23, n34, n41, n56, n67,
2399 n78, n85, n15, n26, n37, n48, id);
2401 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6, n7, n8,
2402 n12, n23, n34, n41, n56, n67,
2403 n78, n85, n15, n26, n37, n48);
2406 if ( mySetElemOnShape && myShapeID > 0 )
2407 meshDS->SetMeshElementOnShape( elem, myShapeID );
2412 //=======================================================================
2413 //function : AddVolume
2414 //purpose : Creates LINEAR!!!!!!!!! octahedron
2415 //=======================================================================
2417 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2418 const SMDS_MeshNode* n2,
2419 const SMDS_MeshNode* n3,
2420 const SMDS_MeshNode* n4,
2421 const SMDS_MeshNode* n5,
2422 const SMDS_MeshNode* n6,
2423 const SMDS_MeshNode* n7,
2424 const SMDS_MeshNode* n8,
2425 const SMDS_MeshNode* n9,
2426 const SMDS_MeshNode* n10,
2427 const SMDS_MeshNode* n11,
2428 const SMDS_MeshNode* n12,
2432 SMESHDS_Mesh * meshDS = GetMeshDS();
2433 SMDS_MeshVolume* elem = 0;
2435 elem = meshDS->AddVolumeWithID(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,id);
2437 elem = meshDS->AddVolume(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12);
2438 if ( mySetElemOnShape && myShapeID > 0 )
2439 meshDS->SetMeshElementOnShape( elem, myShapeID );
2443 //=======================================================================
2444 //function : AddPolyhedralVolume
2445 //purpose : Creates polyhedron. In quadratic mesh, adds medium nodes
2446 //=======================================================================
2449 SMESH_MesherHelper::AddPolyhedralVolume (const std::vector<const SMDS_MeshNode*>& nodes,
2450 const std::vector<int>& quantities,
2454 SMESHDS_Mesh * meshDS = GetMeshDS();
2455 SMDS_MeshVolume* elem = 0;
2456 if(!myCreateQuadratic)
2459 elem = meshDS->AddPolyhedralVolumeWithID(nodes, quantities, id);
2461 elem = meshDS->AddPolyhedralVolume(nodes, quantities);
2465 vector<const SMDS_MeshNode*> newNodes;
2466 vector<int> newQuantities;
2467 for ( size_t iFace = 0, iN = 0; iFace < quantities.size(); ++iFace )
2469 int nbNodesInFace = quantities[iFace];
2470 newQuantities.push_back(0);
2471 for ( int i = 0; i < nbNodesInFace; ++i )
2473 const SMDS_MeshNode* n1 = nodes[ iN + i ];
2474 newNodes.push_back( n1 );
2475 newQuantities.back()++;
2477 const SMDS_MeshNode* n2 = nodes[ iN + ( i+1==nbNodesInFace ? 0 : i+1 )];
2478 // if ( n1->GetPosition()->GetTypeOfPosition() != SMDS_TOP_3DSPACE &&
2479 // n2->GetPosition()->GetTypeOfPosition() != SMDS_TOP_3DSPACE )
2481 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2482 newNodes.push_back( n12 );
2483 newQuantities.back()++;
2486 iN += nbNodesInFace;
2489 elem = meshDS->AddPolyhedralVolumeWithID( newNodes, newQuantities, id );
2491 elem = meshDS->AddPolyhedralVolume( newNodes, newQuantities );
2493 if ( mySetElemOnShape && myShapeID > 0 )
2494 meshDS->SetMeshElementOnShape( elem, myShapeID );
2501 //================================================================================
2503 * \brief Check if a node belongs to any face of sub-mesh
2505 //================================================================================
2507 bool isNodeInSubMesh( const SMDS_MeshNode* n, const SMESHDS_SubMesh* sm )
2509 SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator( SMDSAbs_Face );
2510 while ( fIt->more() )
2511 if ( sm->Contains( fIt->next() ))
2517 //=======================================================================
2518 //function : IsSameElemGeometry
2519 //purpose : Returns true if all elements of a sub-mesh are of same shape
2520 //=======================================================================
2522 bool SMESH_MesherHelper::IsSameElemGeometry(const SMESHDS_SubMesh* smDS,
2523 SMDSAbs_GeometryType shape,
2524 const bool nullSubMeshRes)
2526 if ( !smDS ) return nullSubMeshRes;
2528 SMDS_ElemIteratorPtr elemIt = smDS->GetElements();
2529 while ( elemIt->more() ) {
2530 const SMDS_MeshElement* e = elemIt->next();
2531 if ( e->GetGeomType() != shape )
2537 //=======================================================================
2538 //function : LoadNodeColumns
2539 //purpose : Load nodes bound to face into a map of node columns
2540 //=======================================================================
2542 bool SMESH_MesherHelper::LoadNodeColumns(TParam2ColumnMap & theParam2ColumnMap,
2543 const TopoDS_Face& theFace,
2544 const TopoDS_Edge& theBaseEdge,
2545 SMESHDS_Mesh* theMesh,
2546 SMESH_ProxyMesh* theProxyMesh)
2548 return LoadNodeColumns(theParam2ColumnMap,
2550 std::list<TopoDS_Edge>(1,theBaseEdge),
2555 //=======================================================================
2556 //function : LoadNodeColumns
2557 //purpose : Load nodes bound to face into a map of node columns
2558 //=======================================================================
2560 bool SMESH_MesherHelper::LoadNodeColumns(TParam2ColumnMap & theParam2ColumnMap,
2561 const TopoDS_Face& theFace,
2562 const std::list<TopoDS_Edge>& theBaseSide,
2563 SMESHDS_Mesh* theMesh,
2564 SMESH_ProxyMesh* theProxyMesh)
2566 // get a right sub-mesh of theFace
2568 const SMESHDS_SubMesh* faceSubMesh = 0;
2571 faceSubMesh = theProxyMesh->GetSubMesh( theFace );
2572 if ( !faceSubMesh ||
2573 faceSubMesh->NbElements() == 0 ||
2574 theProxyMesh->IsTemporary( faceSubMesh->GetElements()->next() ))
2576 // can use a proxy sub-mesh with not temporary elements only
2582 faceSubMesh = theMesh->MeshElements( theFace );
2583 if ( !faceSubMesh || faceSubMesh->NbElements() == 0 )
2586 if ( theParam2ColumnMap.empty() )
2588 // get data of edges for normalization of params
2589 vector< double > length;
2591 list<TopoDS_Edge>::const_iterator edge;
2593 for ( edge = theBaseSide.begin(); edge != theBaseSide.end(); ++edge )
2595 double len = std::max( 1e-10, SMESH_Algo::EdgeLength( *edge ));
2597 length.push_back( len );
2601 // get nodes on theBaseEdge sorted by param on edge and initialize theParam2ColumnMap with them
2602 const SMDS_MeshNode* prevEndNodes[2] = { 0, 0 };
2603 edge = theBaseSide.begin();
2604 for ( int iE = 0; edge != theBaseSide.end(); ++edge, ++iE )
2606 map< double, const SMDS_MeshNode*> sortedBaseNN;
2607 SMESH_Algo::GetSortedNodesOnEdge( theMesh, *edge,/*noMedium=*/true, sortedBaseNN );
2609 map< double, const SMDS_MeshNode*>::iterator u_n;
2610 // pb with mesh_Projection_2D_00/A1 fixed by adding expectedSupport arg to GetMediumPos()
2611 // so the following solution is commented (hope forever :)
2613 // SMESH_Algo::GetSortedNodesOnEdge( theMesh, *edge,/*noMedium=*/true, sortedBaseNN,
2614 // // SMDSAbs_Edge here is needed to be coherent with
2615 // // StdMeshers_FaceSide used by Quadrangle to get nodes
2616 // // on EDGE; else pb in mesh_Projection_2D_00/A1 where a
2617 // // medium node on EDGE is medium in a triangle but not
2620 // if ( faceSubMesh->GetElements()->next()->IsQuadratic() )
2621 // // filter off nodes medium in faces on theFace (same pb with mesh_Projection_2D_00/A1)
2622 // for ( u_n = sortedBaseNN.begin(); u_n != sortedBaseNN.end() ; )
2624 // const SMDS_MeshNode* node = u_n->second;
2625 // SMDS_ElemIteratorPtr faceIt = node->GetInverseElementIterator( SMDSAbs_Face );
2626 // if ( faceIt->more() && node ) {
2627 // const SMDS_MeshElement* face = faceIt->next();
2628 // if ( faceSubMesh->Contains( face ) && face->IsMediumNode( node ))
2632 // sortedBaseNN.erase( u_n++ );
2636 if ( sortedBaseNN.empty() ) continue;
2638 u_n = sortedBaseNN.begin();
2639 if ( theProxyMesh ) // from sortedBaseNN remove nodes not shared by faces of faceSubMesh
2641 const SMDS_MeshNode* n1 = (++sortedBaseNN.begin())->second;
2642 const SMDS_MeshNode* n2 = (++sortedBaseNN.rbegin())->second;
2643 bool allNodesAreProxy = ( n1 != theProxyMesh->GetProxyNode( n1 ) &&
2644 n2 != theProxyMesh->GetProxyNode( n2 ));
2645 if ( allNodesAreProxy )
2646 for ( u_n = sortedBaseNN.begin(); u_n != sortedBaseNN.end(); u_n++ )
2647 u_n->second = theProxyMesh->GetProxyNode( u_n->second );
2649 if ( u_n = sortedBaseNN.begin(), !isNodeInSubMesh( u_n->second, faceSubMesh ))
2651 while ( ++u_n != sortedBaseNN.end() && !isNodeInSubMesh( u_n->second, faceSubMesh ));
2652 sortedBaseNN.erase( sortedBaseNN.begin(), u_n );
2654 if ( !sortedBaseNN.empty() )
2655 if ( u_n = --sortedBaseNN.end(), !isNodeInSubMesh( u_n->second, faceSubMesh ))
2657 while ( u_n != sortedBaseNN.begin() && !isNodeInSubMesh( (--u_n)->second, faceSubMesh ));
2658 sortedBaseNN.erase( ++u_n, sortedBaseNN.end() );
2660 if ( sortedBaseNN.empty() ) continue;
2664 BRep_Tool::Range( *edge, f, l );
2665 if ( edge->Orientation() == TopAbs_REVERSED ) std::swap( f, l );
2666 const double coeff = 1. / ( l - f ) * length[iE] / fullLen;
2667 const double prevPar = theParam2ColumnMap.empty() ? 0 : theParam2ColumnMap.rbegin()->first;
2668 for ( u_n = sortedBaseNN.begin(); u_n != sortedBaseNN.end(); u_n++ )
2670 if ( u_n->second == prevEndNodes[0] ||
2671 u_n->second == prevEndNodes[1] )
2673 double par = prevPar + coeff * ( u_n->first - f );
2674 TParam2ColumnMap::iterator u2nn =
2675 theParam2ColumnMap.insert( theParam2ColumnMap.end(), make_pair( par, TNodeColumn()));
2676 u2nn->second.push_back( u_n->second );
2678 prevEndNodes[0] = sortedBaseNN.begin()->second;
2679 prevEndNodes[1] = sortedBaseNN.rbegin()->second;
2681 if ( theParam2ColumnMap.size() < 2 )
2686 size_t prevNbRows = theParam2ColumnMap.begin()->second.size(); // current, at least 1 here
2687 size_t expectNbRows = faceSubMesh->NbElements() / ( theParam2ColumnMap.size()-1 ); // to be added
2689 // fill theParam2ColumnMap column by column by passing from nodes on
2690 // theBaseEdge up via mesh faces on theFace
2692 TParam2ColumnMap::iterator par_nVec_1, par_nVec_2;
2693 par_nVec_2 = theParam2ColumnMap.begin();
2694 par_nVec_1 = par_nVec_2++;
2695 TIDSortedElemSet emptySet, avoidSet;
2696 for ( ; par_nVec_2 != theParam2ColumnMap.end(); ++par_nVec_1, ++par_nVec_2 )
2698 vector<const SMDS_MeshNode*>& nCol1 = par_nVec_1->second;
2699 vector<const SMDS_MeshNode*>& nCol2 = par_nVec_2->second;
2700 nCol1.resize( prevNbRows + expectNbRows );
2701 nCol2.resize( prevNbRows + expectNbRows );
2703 int i1, i2; size_t foundNbRows = 0;
2704 const SMDS_MeshNode *n1 = nCol1[ prevNbRows-1 ];
2705 const SMDS_MeshNode *n2 = nCol2[ prevNbRows-1 ];
2706 // find face sharing node n1 and n2 and belonging to faceSubMesh
2707 while ( const SMDS_MeshElement* face =
2708 SMESH_MeshAlgos::FindFaceInSet( n1, n2, emptySet, avoidSet, &i1, &i2))
2710 if ( faceSubMesh->Contains( face ))
2712 int nbNodes = face->NbCornerNodes();
2715 if ( foundNbRows + 1 > expectNbRows )
2717 n1 = face->GetNode( (i2+2) % 4 ); // opposite corner of quadrangle face
2718 n2 = face->GetNode( (i1+2) % 4 );
2719 nCol1[ prevNbRows + foundNbRows] = n1;
2720 nCol2[ prevNbRows + foundNbRows] = n2;
2723 avoidSet.insert( face );
2725 if ((size_t) foundNbRows != expectNbRows )
2729 return ( theParam2ColumnMap.size() > 1 &&
2730 theParam2ColumnMap.begin()->second.size() == prevNbRows + expectNbRows );
2735 //================================================================================
2737 * \brief Return true if a node is at a corner of a 2D structured mesh of FACE
2739 //================================================================================
2741 bool isCornerOfStructure( const SMDS_MeshNode* n,
2742 const SMESHDS_SubMesh* faceSM,
2743 SMESH_MesherHelper& faceAnalyser )
2745 int nbFacesInSM = 0;
2747 SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator( SMDSAbs_Face );
2748 while ( fIt->more() )
2749 nbFacesInSM += faceSM->Contains( fIt->next() );
2751 if ( nbFacesInSM == 1 )
2754 if ( nbFacesInSM == 2 && n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
2756 return faceAnalyser.IsRealSeam( n->getshapeId() );
2762 //=======================================================================
2763 //function : IsStructured
2764 //purpose : Return true if 2D mesh on FACE is a structured rectangle
2765 //=======================================================================
2767 bool SMESH_MesherHelper::IsStructured( SMESH_subMesh* faceSM )
2769 SMESHDS_SubMesh* fSM = faceSM->GetSubMeshDS();
2770 if ( !fSM || fSM->NbElements() == 0 )
2773 list< TopoDS_Edge > edges;
2774 list< int > nbEdgesInWires;
2775 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( faceSM->GetSubShape() ),
2776 edges, nbEdgesInWires );
2777 if ( nbWires != 1 /*|| nbEdgesInWires.front() != 4*/ ) // allow composite sides
2780 // algo: find corners of a structure and then analyze nb of faces and
2781 // length of structure sides
2783 SMESHDS_Mesh* meshDS = faceSM->GetFather()->GetMeshDS();
2784 SMESH_MesherHelper faceAnalyser( *faceSM->GetFather() );
2785 faceAnalyser.SetSubShape( faceSM->GetSubShape() );
2787 // rotate edges to get the first node being at corner
2788 // (in principle it's not necessary because so far none SALOME algo can make
2789 // such a structured mesh that all corner nodes are not on VERTEXes)
2790 bool isCorner = false;
2791 int nbRemainEdges = nbEdgesInWires.front();
2793 TopoDS_Vertex V = IthVertex( 0, edges.front() );
2794 isCorner = isCornerOfStructure( SMESH_Algo::VertexNode( V, meshDS ),
2797 edges.splice( edges.end(), edges, edges.begin() );
2801 while ( !isCorner && nbRemainEdges > 0 );
2806 // get all nodes from EDGEs
2807 list< const SMDS_MeshNode* > nodes;
2808 list< TopoDS_Edge >::iterator edge = edges.begin();
2809 for ( ; edge != edges.end(); ++edge )
2811 map< double, const SMDS_MeshNode* > u2Nodes;
2812 if ( !SMESH_Algo::GetSortedNodesOnEdge( meshDS, *edge,
2813 /*skipMedium=*/true, u2Nodes ))
2816 list< const SMDS_MeshNode* > edgeNodes;
2817 map< double, const SMDS_MeshNode* >::iterator u2n = u2Nodes.begin();
2818 for ( ; u2n != u2Nodes.end(); ++u2n )
2819 edgeNodes.push_back( u2n->second );
2820 if ( edge->Orientation() == TopAbs_REVERSED )
2821 edgeNodes.reverse();
2823 if ( !nodes.empty() && nodes.back() == edgeNodes.front() )
2824 edgeNodes.pop_front();
2825 nodes.splice( nodes.end(), edgeNodes, edgeNodes.begin(), edgeNodes.end() );
2828 // get length of structured sides
2829 vector<int> nbEdgesInSide;
2831 list< const SMDS_MeshNode* >::iterator n = ++nodes.begin();
2832 for ( ; n != nodes.end(); ++n )
2835 if ( isCornerOfStructure( *n, fSM, faceAnalyser )) {
2836 nbEdgesInSide.push_back( nbEdges );
2842 if ( nbEdgesInSide.size() != 4 )
2844 if ( nbEdgesInSide[0] != nbEdgesInSide[2] )
2846 if ( nbEdgesInSide[1] != nbEdgesInSide[3] )
2848 if ( nbEdgesInSide[0] * nbEdgesInSide[1] != fSM->NbElements() )
2854 //=======================================================================
2855 //function : IsDistorted2D
2856 //purpose : Return true if 2D mesh on FACE is ditorted
2857 //=======================================================================
2859 bool SMESH_MesherHelper::IsDistorted2D( SMESH_subMesh* faceSM,
2861 SMESH_MesherHelper* faceHelper)
2863 if ( !faceSM || faceSM->GetSubShape().ShapeType() != TopAbs_FACE )
2866 bool haveBadFaces = false;
2868 SMESH_MesherHelper helper( *faceSM->GetFather() );
2870 helper.CopySubShapeInfo( *faceHelper );
2871 helper.SetSubShape( faceSM->GetSubShape() );
2873 const TopoDS_Face& F = TopoDS::Face( faceSM->GetSubShape() );
2874 SMESHDS_SubMesh* smDS = helper.GetMeshDS()->MeshElements( F );
2875 if ( !smDS || smDS->NbElements() == 0 ) return false;
2877 bool subIdsValid = true; // shape ID of nodes is OK
2878 if ( helper.HasSeam() )
2880 // check if nodes are bound to seam edges
2881 SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(/*includeSelf=*/false);
2882 while ( smIt->more() && subIdsValid )
2884 SMESH_subMesh* sm = smIt->next();
2885 if ( helper.IsSeamShape( sm->GetId() ) && sm->IsEmpty() )
2886 subIdsValid = false;
2889 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
2890 double prevArea = 0;
2891 vector< const SMDS_MeshNode* > nodes;
2893 bool* toCheckUV = checkUV ? & checkUV : 0;
2894 while ( faceIt->more() && !haveBadFaces )
2896 const SMDS_MeshElement* face = faceIt->next();
2899 nodes.resize( face->NbCornerNodes() );
2900 SMDS_MeshElement::iterator n = face->begin_nodes();
2901 for ( size_t i = 0; i < nodes.size(); ++n, ++i )
2904 // avoid elems on degenerate shapes as UV on them can be wrong
2905 if ( helper.HasDegeneratedEdges() )
2907 bool isOnDegen = false;
2908 for ( size_t i = 0; ( i < nodes.size() && !isOnDegen ); ++i )
2909 isOnDegen = helper.IsDegenShape( nodes[ i ]->getshapeId() );
2913 // prepare for getting UVs
2914 const SMDS_MeshNode* inFaceNode = 0;
2915 if ( helper.HasSeam() ) {
2916 for ( size_t i = 0; ( i < nodes.size() && !inFaceNode ); ++i )
2917 if ( !helper.IsSeamShape( nodes[ i ]->getshapeId() ))
2919 inFaceNode = nodes[ i ];
2922 gp_XY uv = helper.GetNodeUV( F, inFaceNode );
2923 if ( helper.IsOnSeam( uv ))
2931 uv.resize( nodes.size() );
2932 for ( size_t i = 0; i < nodes.size(); ++i )
2933 uv[ i ] = helper.GetNodeUV( F, nodes[ i ], inFaceNode, toCheckUV );
2935 if ( !subIdsValid ) // fix uv on seam
2937 gp_XY uvInFace = helper.GetNodeUV( F, inFaceNode );
2938 for ( size_t i = 0; i < uv.size(); ++i )
2939 if ( helper.IsOnSeam( uv[i] ))
2940 uv[i] = helper.getUVOnSeam( uv[i], uvInFace ).XY();
2943 // compare orientation of triangles
2944 double faceArea = 0;
2945 for ( int iT = 0, nbT = nodes.size()-2; iT < nbT; ++iT )
2947 gp_XY v1 = uv[ iT+1 ] - uv[ 0 ];
2948 gp_XY v2 = uv[ iT+2 ] - uv[ 0 ];
2949 faceArea += v2 ^ v1;
2951 haveBadFaces = ( faceArea * prevArea < 0 );
2952 prevArea = faceArea;
2955 return haveBadFaces;
2958 //================================================================================
2960 * \brief Find out elements orientation on a geometrical face
2961 * \param theFace - The face correctly oriented in the shape being meshed
2962 * \retval bool - true if the face normal and the normal of first element
2963 * in the corresponding submesh point in different directions
2965 //================================================================================
2967 bool SMESH_MesherHelper::IsReversedSubMesh (const TopoDS_Face& theFace)
2969 if ( theFace.IsNull() )
2972 // find out orientation of a meshed face
2973 int faceID = GetMeshDS()->ShapeToIndex( theFace );
2974 TopoDS_Shape aMeshedFace = GetMeshDS()->IndexToShape( faceID );
2975 bool isReversed = ( theFace.Orientation() != aMeshedFace.Orientation() );
2977 const SMESHDS_SubMesh * aSubMeshDSFace = GetMeshDS()->MeshElements( faceID );
2978 if ( !aSubMeshDSFace )
2981 // find an element on a bounday of theFace
2982 SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
2983 const SMDS_MeshNode* nn[2];
2984 while ( iteratorElem->more() ) // loop on elements on theFace
2986 const SMDS_MeshElement* elem = iteratorElem->next();
2987 if ( ! elem ) continue;
2989 // look for 2 nodes on EDGE
2990 int nbNodes = elem->NbCornerNodes();
2991 nn[0] = elem->GetNode( nbNodes-1 );
2992 for ( int iN = 0; iN < nbNodes; ++iN )
2994 nn[1] = elem->GetNode( iN );
2995 if ( nn[0]->GetPosition()->GetDim() < 2 &&
2996 nn[1]->GetPosition()->GetDim() < 2 )
2998 TopoDS_Shape s0 = GetSubShapeByNode( nn[0], GetMeshDS() );
2999 TopoDS_Shape s1 = GetSubShapeByNode( nn[1], GetMeshDS() );
3000 TopoDS_Shape E = GetCommonAncestor( s0, s1, *myMesh, TopAbs_EDGE );
3001 if ( !E.IsNull() && !s0.IsSame( s1 ) && E.Orientation() != TopAbs_INTERNAL )
3005 for ( TopExp_Explorer exp( theFace, TopAbs_EDGE ); exp.More(); exp.Next() )
3006 if ( E.IsSame( exp.Current() )) {
3008 E = exp.Current(); // to know orientation
3013 double u0 = GetNodeU( TopoDS::Edge( E ), nn[0], nn[1], &ok );
3014 double u1 = GetNodeU( TopoDS::Edge( E ), nn[1], nn[0], &ok );
3017 // check that the 2 nodes are connected with a segment (IPAL53055)
3019 const SMDS_MeshElement* seg;
3020 if ( SMESHDS_SubMesh* sm = GetMeshDS()->MeshElements( E ))
3021 if (( sm->NbElements() > 0 ) &&
3022 ( seg = GetMeshDS()->FindEdge( nn[0], nn[1] )))
3023 ok = sm->Contains( seg );
3027 isReversed = ( u0 > u1 );
3028 if ( E.Orientation() == TopAbs_REVERSED )
3029 isReversed = !isReversed;
3039 // find an element with a good normal
3041 bool normalOK = false;
3043 iteratorElem = aSubMeshDSFace->GetElements();
3044 while ( !normalOK && iteratorElem->more() ) // loop on elements on theFace
3046 const SMDS_MeshElement* elem = iteratorElem->next();
3047 if ( ! SMESH_MeshAlgos::FaceNormal( elem, const_cast<gp_XYZ&>( Ne.XYZ() ), /*normalized=*/0 ))
3051 // get UV of a node inside theFACE
3052 SMDS_ElemIteratorPtr nodesIt = elem->nodesIterator();
3053 const SMDS_MeshNode* nInFace = 0;
3054 int iPosDim = SMDS_TOP_VERTEX;
3055 while ( nodesIt->more() ) // loop on nodes
3057 const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>( nodesIt->next() );
3058 if ( n->GetPosition()->GetTypeOfPosition() >= iPosDim )
3061 iPosDim = n->GetPosition()->GetTypeOfPosition();
3064 uv = GetNodeUV( theFace, nInFace, 0, &normalOK );
3069 // face normal at node position
3070 TopLoc_Location loc;
3071 Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc );
3072 // if ( surf.IsNull() || surf->Continuity() < GeomAbs_C1 )
3073 // some surfaces not detected as GeomAbs_C1 are nevertheless correct for meshing
3074 if ( surf.IsNull() || surf->Continuity() < GeomAbs_C0 )
3077 gp_Vec d1u, d1v; gp_Pnt p;
3078 surf->D1( uv.X(), uv.Y(), p, d1u, d1v );
3079 gp_Vec Nf = (d1u ^ d1v).Transformed( loc );
3081 if ( theFace.Orientation() == TopAbs_REVERSED )
3084 return Ne * Nf < 0.;
3087 //=======================================================================
3089 //purpose : Count nb of sub-shapes
3090 //=======================================================================
3092 int SMESH_MesherHelper::Count(const TopoDS_Shape& shape,
3093 const TopAbs_ShapeEnum type,
3094 const bool ignoreSame)
3097 TopTools_IndexedMapOfShape map;
3098 TopExp::MapShapes( shape, type, map );
3099 return map.Extent();
3103 for ( TopExp_Explorer exp( shape, type ); exp.More(); exp.Next() )
3109 //=======================================================================
3110 //function : NbAncestors
3111 //purpose : Return number of unique ancestors of the shape
3112 //=======================================================================
3114 int SMESH_MesherHelper::NbAncestors(const TopoDS_Shape& shape,
3115 const SMESH_Mesh& mesh,
3116 TopAbs_ShapeEnum ancestorType/*=TopAbs_SHAPE*/)
3118 TopTools_MapOfShape ancestors;
3119 TopTools_ListIteratorOfListOfShape ansIt( mesh.GetAncestors(shape) );
3120 for ( ; ansIt.More(); ansIt.Next() ) {
3121 if ( ancestorType == TopAbs_SHAPE || ansIt.Value().ShapeType() == ancestorType )
3122 ancestors.Add( ansIt.Value() );
3124 return ancestors.Extent();
3127 //=======================================================================
3128 //function : GetSubShapeOri
3129 //purpose : Return orientation of sub-shape in the main shape
3130 //=======================================================================
3132 TopAbs_Orientation SMESH_MesherHelper::GetSubShapeOri(const TopoDS_Shape& shape,
3133 const TopoDS_Shape& subShape)
3135 TopAbs_Orientation ori = TopAbs_Orientation(-1);
3136 if ( !shape.IsNull() && !subShape.IsNull() )
3138 TopExp_Explorer e( shape, subShape.ShapeType() );
3139 if ( shape.Orientation() >= TopAbs_INTERNAL ) // TopAbs_INTERNAL or TopAbs_EXTERNAL
3140 e.Init( shape.Oriented(TopAbs_FORWARD), subShape.ShapeType() );
3141 for ( ; e.More(); e.Next())
3142 if ( subShape.IsSame( e.Current() ))
3145 ori = e.Current().Orientation();
3150 //=======================================================================
3151 //function : IsSubShape
3153 //=======================================================================
3155 bool SMESH_MesherHelper::IsSubShape( const TopoDS_Shape& shape,
3156 const TopoDS_Shape& mainShape )
3158 if ( !shape.IsNull() && !mainShape.IsNull() )
3160 for ( TopExp_Explorer exp( mainShape, shape.ShapeType());
3163 if ( shape.IsSame( exp.Current() ))
3169 //=======================================================================
3170 //function : IsSubShape
3172 //=======================================================================
3174 bool SMESH_MesherHelper::IsSubShape( const TopoDS_Shape& shape, SMESH_Mesh* aMesh )
3176 if ( shape.IsNull() || !aMesh )
3179 aMesh->GetMeshDS()->ShapeToIndex( shape ) ||
3181 (shape.ShapeType() == TopAbs_COMPOUND && aMesh->GetMeshDS()->IsGroupOfSubShapes( shape ));
3184 //=======================================================================
3185 //function : IsBlock
3187 //=======================================================================
3189 bool SMESH_MesherHelper::IsBlock( const TopoDS_Shape& shape )
3191 if ( shape.IsNull() )
3195 TopExp_Explorer exp( shape, TopAbs_SHELL );
3196 if ( !exp.More() ) return false;
3197 shell = TopoDS::Shell( exp.Current() );
3198 if ( exp.Next(), exp.More() ) return false;
3201 TopTools_IndexedMapOfOrientedShape map;
3202 return SMESH_Block::FindBlockShapes( shell, v, v, map );
3206 //================================================================================
3208 * \brief Return maximal tolerance of shape
3210 //================================================================================
3212 double SMESH_MesherHelper::MaxTolerance( const TopoDS_Shape& shape )
3214 double tol = Precision::Confusion();
3215 TopExp_Explorer exp;
3216 for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
3217 tol = Max( tol, BRep_Tool::Tolerance( TopoDS::Face( exp.Current())));
3218 for ( exp.Init( shape, TopAbs_EDGE ); exp.More(); exp.Next() )
3219 tol = Max( tol, BRep_Tool::Tolerance( TopoDS::Edge( exp.Current())));
3220 for ( exp.Init( shape, TopAbs_VERTEX ); exp.More(); exp.Next() )
3221 tol = Max( tol, BRep_Tool::Tolerance( TopoDS::Vertex( exp.Current())));
3226 //================================================================================
3228 * \brief Return MaxTolerance( face ), probably cached
3230 //================================================================================
3232 double SMESH_MesherHelper::getFaceMaxTol( const TopoDS_Shape& face ) const
3234 int faceID = GetMeshDS()->ShapeToIndex( face );
3236 SMESH_MesherHelper* me = const_cast< SMESH_MesherHelper* >( this );
3237 double & tol = me->myFaceMaxTol.insert( make_pair( faceID, -1. )).first->second;
3239 tol = MaxTolerance( face );
3244 //================================================================================
3246 * \brief Return an angle between two EDGEs sharing a common VERTEX with reference
3247 * of the FACE normal
3248 * \return double - the angle (between -Pi and Pi), negative if the angle is concave,
3249 * 1e100 in case of failure
3250 * \warning Care about order of the EDGEs and their orientation to be as they are
3251 * within the FACE! Don't pass degenerated EDGEs neither!
3253 //================================================================================
3255 double SMESH_MesherHelper::GetAngle( const TopoDS_Edge & theE1,
3256 const TopoDS_Edge & theE2,
3257 const TopoDS_Face & theFace,
3258 const TopoDS_Vertex & theCommonV,
3259 gp_Vec* theFaceNormal)
3261 double angle = 1e100;
3265 Handle(Geom_Curve) c1 = BRep_Tool::Curve( theE1, f,l );
3266 Handle(Geom_Curve) c2 = BRep_Tool::Curve( theE2, f,l );
3267 Handle(Geom2d_Curve) c2d1 = BRep_Tool::CurveOnSurface( theE1, theFace, f,l );
3268 Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace );
3269 double p1 = BRep_Tool::Parameter( theCommonV, theE1 );
3270 double p2 = BRep_Tool::Parameter( theCommonV, theE2 );
3271 if ( c1.IsNull() || c2.IsNull() )
3273 gp_XY uv = c2d1->Value( p1 ).XY();
3274 gp_Vec du, dv; gp_Pnt p;
3275 surf->D1( uv.X(), uv.Y(), p, du, dv );
3276 gp_Vec vec1, vec2, vecRef = du ^ dv;
3279 while ( vecRef.SquareMagnitude() < 1e-25 )
3281 double dp = ( l - f ) / 1000.;
3282 p1tmp += dp * (( Abs( p1 - f ) > Abs( p1 - l )) ? -1. : +1.);
3283 uv = c2d1->Value( p1tmp ).XY();
3284 surf->D1( uv.X(), uv.Y(), p, du, dv );
3286 if ( ++nbLoops > 10 )
3289 cout << "SMESH_MesherHelper::GetAngle(): Captured in a sigularity" << endl;
3294 if ( theFace.Orientation() == TopAbs_REVERSED )
3296 if ( theFaceNormal ) *theFaceNormal = vecRef;
3298 c1->D1( p1, p, vec1 );
3299 c2->D1( p2, p, vec2 );
3300 // TopoDS_Face F = theFace;
3301 // if ( F.Orientation() == TopAbs_INTERNAL )
3302 // F.Orientation( TopAbs_FORWARD );
3303 if ( theE1.Orientation() /*GetSubShapeOri( F, theE1 )*/ == TopAbs_REVERSED )
3305 if ( theE2.Orientation() /*GetSubShapeOri( F, theE2 )*/ == TopAbs_REVERSED )
3307 angle = vec1.AngleWithRef( vec2, vecRef );
3309 if ( Abs ( angle ) >= 0.99 * M_PI )
3311 BRep_Tool::Range( theE1, f, l );
3312 p1 += 1e-7 * ( p1-f < l-p1 ? +1. : -1. );
3313 c1->D1( p1, p, vec1 );
3314 if ( theE1.Orientation() == TopAbs_REVERSED )
3316 BRep_Tool::Range( theE2, f, l );
3317 p2 += 1e-7 * ( p2-f < l-p2 ? +1. : -1. );
3318 c2->D1( p2, p, vec2 );
3319 if ( theE2.Orientation() == TopAbs_REVERSED )
3321 angle = vec1.AngleWithRef( vec2, vecRef );
3330 //================================================================================
3332 * \brief Check if the first and last vertices of an edge are the same
3333 * \param anEdge - the edge to check
3334 * \retval bool - true if same
3336 //================================================================================
3338 bool SMESH_MesherHelper::IsClosedEdge( const TopoDS_Edge& anEdge )
3340 if ( anEdge.Orientation() >= TopAbs_INTERNAL )
3341 return IsClosedEdge( TopoDS::Edge( anEdge.Oriented( TopAbs_FORWARD )));
3342 return TopExp::FirstVertex( anEdge ).IsSame( TopExp::LastVertex( anEdge ));
3345 //================================================================================
3347 * \brief Wrapper over TopExp::FirstVertex() and TopExp::LastVertex() fixing them
3348 * in the case of INTERNAL edge
3350 //================================================================================
3352 TopoDS_Vertex SMESH_MesherHelper::IthVertex( const bool is2nd,
3356 if ( anEdge.Orientation() >= TopAbs_INTERNAL )
3357 anEdge.Orientation( TopAbs_FORWARD );
3359 const TopAbs_Orientation tgtOri = is2nd ? TopAbs_REVERSED : TopAbs_FORWARD;
3360 TopoDS_Iterator vIt( anEdge, CumOri );
3361 while ( vIt.More() && vIt.Value().Orientation() != tgtOri )
3364 return ( vIt.More() ? TopoDS::Vertex(vIt.Value()) : TopoDS_Vertex() );
3367 //================================================================================
3369 * \brief Return type of shape contained in a group
3370 * \param group - a shape of type TopAbs_COMPOUND
3371 * \param avoidCompound - not to return TopAbs_COMPOUND
3373 //================================================================================
3375 TopAbs_ShapeEnum SMESH_MesherHelper::GetGroupType(const TopoDS_Shape& group,
3376 const bool avoidCompound)
3378 if ( !group.IsNull() )
3380 if ( group.ShapeType() != TopAbs_COMPOUND )
3381 return group.ShapeType();
3383 // iterate on a compound
3384 TopoDS_Iterator it( group );
3386 return avoidCompound ? GetGroupType( it.Value() ) : it.Value().ShapeType();
3388 return TopAbs_SHAPE;
3391 //================================================================================
3393 * \brief Returns a shape, to which a hypothesis used to mesh a given shape is assigned
3394 * \param [in] hyp - the hypothesis
3395 * \param [in] shape - the shape, for meshing which the \a hyp is used
3396 * \param [in] mesh - the mesh
3397 * \return TopoDS_Shape - the shape the \a hyp is assigned to
3399 //================================================================================
3401 TopoDS_Shape SMESH_MesherHelper::GetShapeOfHypothesis( const SMESHDS_Hypothesis * hyp,
3402 const TopoDS_Shape& shape,
3405 const SMESH_Hypothesis* h = static_cast<const SMESH_Hypothesis*>( hyp );
3406 SMESH_HypoFilter hypFilter( SMESH_HypoFilter::Is( h ));
3408 TopoDS_Shape shapeOfHyp;
3409 mesh->GetHypothesis( shape, hypFilter, /*checkAncestors=*/true, &shapeOfHyp );
3413 //=======================================================================
3414 //function : IsQuadraticMesh
3415 //purpose : Check mesh without geometry for: if all elements on this shape are quadratic,
3416 // quadratic elements will be created.
3417 // Used then generated 3D mesh without geometry.
3418 //=======================================================================
3420 SMESH_MesherHelper:: MType SMESH_MesherHelper::IsQuadraticMesh()
3422 int NbAllEdgsAndFaces=0;
3423 int NbQuadFacesAndEdgs=0;
3424 int NbFacesAndEdges=0;
3425 //All faces and edges
3426 NbAllEdgsAndFaces = myMesh->NbEdges() + myMesh->NbFaces();
3427 if ( NbAllEdgsAndFaces == 0 )
3428 return SMESH_MesherHelper::LINEAR;
3430 //Quadratic faces and edges
3431 NbQuadFacesAndEdgs = myMesh->NbEdges(ORDER_QUADRATIC) + myMesh->NbFaces(ORDER_QUADRATIC);
3433 //Linear faces and edges
3434 NbFacesAndEdges = myMesh->NbEdges(ORDER_LINEAR) + myMesh->NbFaces(ORDER_LINEAR);
3436 if (NbAllEdgsAndFaces == NbQuadFacesAndEdgs) {
3438 return SMESH_MesherHelper::QUADRATIC;
3440 else if (NbAllEdgsAndFaces == NbFacesAndEdges) {
3442 return SMESH_MesherHelper::LINEAR;
3445 //Mesh with both type of elements
3446 return SMESH_MesherHelper::COMP;
3449 //=======================================================================
3450 //function : GetOtherParam
3451 //purpose : Return an alternative parameter for a node on seam
3452 //=======================================================================
3454 double SMESH_MesherHelper::GetOtherParam(const double param) const
3456 int i = myParIndex & U_periodic ? 0 : 1;
3457 return fabs(param-myPar1[i]) < fabs(param-myPar2[i]) ? myPar2[i] : myPar1[i];
3460 //=======================================================================
3461 //function : NbRealSeam
3462 //purpose : Return a number of real seam edges in the shape set through
3463 // IsQuadraticSubMesh() or SetSubShape(). A real seam edge encounters twice in a wire
3464 //=======================================================================
3466 size_t SMESH_MesherHelper::NbRealSeam() const
3470 std::set< int >::const_iterator id = mySeamShapeIds.begin();
3471 for ( ; id != mySeamShapeIds.end(); ++id )
3472 if ( *id < 0 ) ++nb;
3478 //=======================================================================
3479 //function : IsOnSeam
3480 //purpose : Check if UV is on seam. Return 0 if not, 1 for U seam, 2 for V seam
3481 //=======================================================================
3483 int SMESH_MesherHelper::IsOnSeam(const gp_XY& uv) const
3485 for ( int i = U_periodic; i <= V_periodic ; ++i )
3486 if ( myParIndex & i )
3488 double p = uv.Coord( i );
3489 double tol = ( myPar2[i-1] - myPar1[i-1] ) / 100.;
3490 if ( Abs( p - myPar1[i-1] ) < tol ||
3491 Abs( p - myPar2[i-1] ) < tol )
3499 //=======================================================================
3501 * \brief Iterator on ancestors of the given type
3503 //=======================================================================
3505 struct TAncestorsIterator : public SMDS_Iterator<const TopoDS_Shape*>
3507 TopTools_ListIteratorOfListOfShape _ancIter;
3508 TopAbs_ShapeEnum _type;
3509 TopTools_MapOfShape _encountered;
3510 TopTools_IndexedMapOfShape _allowed;
3511 TAncestorsIterator( const TopTools_ListOfShape& ancestors,
3512 TopAbs_ShapeEnum type,
3513 const TopoDS_Shape* container/* = 0*/)
3514 : _ancIter( ancestors ), _type( type )
3516 if ( container && !container->IsNull() )
3517 TopExp::MapShapes( *container, type, _allowed);
3518 if ( _ancIter.More() ) {
3519 if ( !isCurrentAllowed() ) next();
3520 else _encountered.Add( _ancIter.Value() );
3525 return _ancIter.More();
3527 virtual const TopoDS_Shape* next()
3529 const TopoDS_Shape* s = _ancIter.More() ? & _ancIter.Value() : 0;
3530 if ( _ancIter.More() )
3531 for ( _ancIter.Next(); _ancIter.More(); _ancIter.Next())
3532 if ( isCurrentAllowed() && _encountered.Add( _ancIter.Value() ))
3536 bool isCurrentAllowed()
3538 return (( _ancIter.Value().ShapeType() == _type ) &&
3539 ( _allowed.IsEmpty() || _allowed.Contains( _ancIter.Value() )));
3545 //=======================================================================
3547 * \brief Return iterator on ancestors of the given type, included into a container shape
3549 //=======================================================================
3551 PShapeIteratorPtr SMESH_MesherHelper::GetAncestors(const TopoDS_Shape& shape,
3552 const SMESH_Mesh& mesh,
3553 TopAbs_ShapeEnum ancestorType,
3554 const TopoDS_Shape* container)
3556 return PShapeIteratorPtr
3557 ( new TAncestorsIterator( mesh.GetAncestors(shape), ancestorType, container));
3560 //=======================================================================
3561 //function : GetCommonAncestor
3562 //purpose : Find a common ancestors of two shapes of the given type
3563 //=======================================================================
3565 TopoDS_Shape SMESH_MesherHelper::GetCommonAncestor(const TopoDS_Shape& shape1,
3566 const TopoDS_Shape& shape2,
3567 const SMESH_Mesh& mesh,
3568 TopAbs_ShapeEnum ancestorType)
3570 TopoDS_Shape commonAnc;
3571 if ( !shape1.IsNull() && !shape2.IsNull() )
3573 if ( shape1.ShapeType() == ancestorType && IsSubShape( shape2, shape1 ))
3575 if ( shape2.ShapeType() == ancestorType && IsSubShape( shape1, shape2 ))
3578 PShapeIteratorPtr ancIt = GetAncestors( shape1, mesh, ancestorType );
3579 while ( const TopoDS_Shape* anc = ancIt->next() )
3580 if ( IsSubShape( shape2, *anc ))
3589 //#include <Perf_Meter.hxx>
3591 //=======================================================================
3592 namespace { // Structures used by FixQuadraticElements()
3593 //=======================================================================
3595 #define __DMP__(txt) \
3597 #define MSG(txt) __DMP__(txt<<endl)
3598 #define MSGBEG(txt) __DMP__(txt)
3600 //const double straightTol2 = 1e-33; // to detect straing links
3601 bool isStraightLink(double linkLen2, double middleNodeMove2)
3603 // straight if <node move> < 1/15 * <link length>
3604 return middleNodeMove2 < 1/15./15. * linkLen2;
3608 // ---------------------------------------
3610 * \brief Quadratic link knowing its faces
3612 struct QLink: public SMESH_TLink
3614 const SMDS_MeshNode* _mediumNode;
3615 mutable vector<const QFace* > _faces;
3616 mutable gp_Vec _nodeMove;
3617 mutable int _nbMoves;
3618 mutable bool _is2dFixed; // is moved along surface or in 3D
3620 QLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2, const SMDS_MeshNode* nm):
3621 SMESH_TLink( n1,n2 ), _mediumNode(nm), _nodeMove(0,0,0), _nbMoves(0) {
3623 _nodeMove = MediumPnt() - MiddlePnt();
3624 _is2dFixed = ( MediumPos() != SMDS_TOP_FACE );
3626 void SetContinuesFaces() const;
3627 const QFace* GetContinuesFace( const QFace* face ) const;
3628 bool OnBoundary() const;
3629 gp_XYZ MiddlePnt() const { return ( XYZ( node1() ) + XYZ( node2() )) / 2.; }
3630 gp_XYZ MediumPnt() const { return XYZ( _mediumNode ); }
3632 SMDS_TypeOfPosition MediumPos() const
3633 { return _mediumNode->GetPosition()->GetTypeOfPosition(); }
3634 SMDS_TypeOfPosition EndPos(bool isSecond) const
3635 { return (isSecond ? node2() : node1())->GetPosition()->GetTypeOfPosition(); }
3636 const SMDS_MeshNode* EndPosNode(SMDS_TypeOfPosition pos) const
3637 { return EndPos(0) == pos ? node1() : EndPos(1) == pos ? node2() : 0; }
3639 void Move(const gp_Vec& move, bool sum=false, bool is2dFixed=false) const
3640 { _nodeMove += move; _nbMoves += sum ? (_nbMoves==0) : 1; _is2dFixed |= is2dFixed; }
3641 gp_XYZ Move() const { return _nodeMove.XYZ() / _nbMoves; }
3642 bool IsMoved() const { return (_nbMoves > 0 /*&& !IsStraight()*/); }
3643 bool IsFixedOnSurface() const { return _is2dFixed; }
3644 bool IsStraight() const
3645 { return isStraightLink( (XYZ(node1())-XYZ(node2())).SquareModulus(),
3646 _nodeMove.SquareMagnitude());
3648 bool operator<(const QLink& other) const {
3649 return (node1()->GetID() == other.node1()->GetID() ?
3650 node2()->GetID() < other.node2()->GetID() :
3651 node1()->GetID() < other.node1()->GetID());
3653 // struct PtrComparator {
3654 // bool operator() (const QLink* l1, const QLink* l2 ) const { return *l1 < *l2; }
3657 // ---------------------------------------------------------
3659 * \brief Link in the chain of links; it connects two faces
3663 const QLink* _qlink;
3664 mutable const QFace* _qfaces[2];
3666 TChainLink(const QLink* qlink=0):_qlink(qlink) {
3667 _qfaces[0] = _qfaces[1] = 0;
3669 void SetFace(const QFace* face) const { int iF = _qfaces[0] ? 1 : 0; _qfaces[iF]=face; }
3671 bool IsBoundary() const { return !_qfaces[1]; }
3673 void RemoveFace( const QFace* face ) const
3674 { _qfaces[(face == _qfaces[1])] = 0; if (!_qfaces[0]) std::swap(_qfaces[0],_qfaces[1]); }
3676 const QFace* NextFace( const QFace* f ) const
3677 { return _qfaces[0]==f ? _qfaces[1] : _qfaces[0]; }
3679 const SMDS_MeshNode* NextNode( const SMDS_MeshNode* n ) const
3680 { return n == _qlink->node1() ? _qlink->node2() : _qlink->node1(); }
3682 bool operator<(const TChainLink& other) const { return *_qlink < *other._qlink; }
3684 operator bool() const { return (_qlink); }
3686 const QLink* operator->() const { return _qlink; }
3688 gp_Vec Normal() const;
3690 bool IsStraight() const;
3692 // --------------------------------------------------------------------
3693 typedef list< TChainLink > TChain;
3694 typedef set < TChainLink > TLinkSet;
3695 typedef TLinkSet::const_iterator TLinkInSet;
3697 const int theFirstStep = 5;
3699 enum { ERR_OK, ERR_TRI, ERR_PRISM, ERR_UNKNOWN }; // errors of QFace::GetLinkChain()
3700 // --------------------------------------------------------------------
3702 * \brief Quadratic face shared by two volumes and bound by QLinks
3704 struct QFace: public TIDSortedNodeSet
3706 mutable const SMDS_MeshElement* _volumes[2];
3707 mutable vector< const QLink* > _sides;
3708 mutable bool _sideIsAdded[4]; // added in chain of links
3711 mutable const SMDS_MeshElement* _face;
3714 QFace( const vector< const QLink*>& links, const SMDS_MeshElement* face=0 );
3716 void SetVolume(const SMDS_MeshElement* v) const { _volumes[ _volumes[0] ? 1 : 0 ] = v; }
3718 int NbVolumes() const { return !_volumes[0] ? 0 : !_volumes[1] ? 1 : 2; }
3720 void AddSelfToLinks() const {
3721 for ( size_t i = 0; i < _sides.size(); ++i )
3722 _sides[i]->_faces.push_back( this );
3724 int LinkIndex( const QLink* side ) const {
3725 for (size_t i = 0; i<_sides.size(); ++i ) if ( _sides[i] == side ) return i;
3728 bool GetLinkChain( int iSide, TChain& chain, SMDS_TypeOfPosition pos, int& err) const;
3730 bool GetLinkChain( TChainLink& link, TChain& chain, SMDS_TypeOfPosition pos, int& err) const
3732 int i = LinkIndex( link._qlink );
3733 if ( i < 0 ) return true;
3734 _sideIsAdded[i] = true;
3735 link.SetFace( this );
3736 // continue from opposite link
3737 return GetLinkChain( (i+2)%_sides.size(), chain, pos, err );
3739 bool IsBoundary() const { return !_volumes[1]; }
3741 bool Contains( const SMDS_MeshNode* node ) const { return count(node); }
3743 bool IsSpoiled(const QLink* bentLink ) const;
3745 TLinkInSet GetBoundaryLink( const TLinkSet& links,
3746 const TChainLink& avoidLink,
3747 TLinkInSet * notBoundaryLink = 0,
3748 const SMDS_MeshNode* nodeToContain = 0,
3749 bool * isAdjacentUsed = 0,
3750 int nbRecursionsLeft = -1) const;
3752 TLinkInSet GetLinkByNode( const TLinkSet& links,
3753 const TChainLink& avoidLink,
3754 const SMDS_MeshNode* nodeToContain) const;
3756 const SMDS_MeshNode* GetNodeInFace() const {
3757 for ( size_t iL = 0; iL < _sides.size(); ++iL )
3758 if ( _sides[iL]->MediumPos() == SMDS_TOP_FACE ) return _sides[iL]->_mediumNode;
3762 gp_Vec LinkNorm(const int i, SMESH_MesherHelper* theFaceHelper=0) const;
3764 double MoveByBoundary( const TChainLink& theLink,
3765 const gp_Vec& theRefVec,
3766 const TLinkSet& theLinks,
3767 SMESH_MesherHelper* theFaceHelper=0,
3768 const double thePrevLen=0,
3769 const int theStep=theFirstStep,
3770 gp_Vec* theLinkNorm=0,
3771 double theSign=1.0) const;
3774 //================================================================================
3776 * \brief Dump QLink and QFace
3778 ostream& operator << (ostream& out, const QLink& l)
3780 out <<"QLink nodes: "
3781 << l.node1()->GetID() << " - "
3782 << l._mediumNode->GetID() << " - "
3783 << l.node2()->GetID() << endl;
3786 ostream& operator << (ostream& out, const QFace& f)
3788 out <<"QFace nodes: "/*<< &f << " "*/;
3789 for ( TIDSortedNodeSet::const_iterator n = f.begin(); n != f.end(); ++n )
3790 out << (*n)->GetID() << " ";
3791 out << " \tvolumes: "
3792 << (f._volumes[0] ? f._volumes[0]->GetID() : 0) << " "
3793 << (f._volumes[1] ? f._volumes[1]->GetID() : 0);
3794 out << " \tNormal: "<< f._normal.X() <<", "<<f._normal.Y() <<", "<<f._normal.Z() << endl;
3798 //================================================================================
3800 * \brief Construct QFace from QLinks
3802 //================================================================================
3804 QFace::QFace( const vector< const QLink*>& links, const SMDS_MeshElement* face )
3806 _volumes[0] = _volumes[1] = 0;
3808 _sideIsAdded[0]=_sideIsAdded[1]=_sideIsAdded[2]=_sideIsAdded[3]=false;
3809 _normal.SetCoord(0,0,0);
3810 for ( size_t i = 1; i < _sides.size(); ++i ) {
3811 const QLink *l1 = _sides[i-1], *l2 = _sides[i];
3812 insert( l1->node1() ); insert( l1->node2() );
3814 gp_Vec v1( XYZ( l1->node2()), XYZ( l1->node1()));
3815 gp_Vec v2( XYZ( l2->node1()), XYZ( l2->node2()));
3816 if ( l1->node1() != l2->node1() && l1->node2() != l2->node2() )
3820 double normSqSize = _normal.SquareMagnitude();
3821 if ( normSqSize > numeric_limits<double>::min() )
3822 _normal /= sqrt( normSqSize );
3824 _normal.SetCoord(1e-33,0,0);
3830 //================================================================================
3832 * \brief Make up a chain of links
3833 * \param iSide - link to add first
3834 * \param chain - chain to fill in
3835 * \param pos - position of medium nodes the links should have
3836 * \param error - out, specifies what is wrong
3837 * \retval bool - false if valid chain can't be built; "valid" means that links
3838 * of the chain belongs to rectangles bounding hexahedrons
3840 //================================================================================
3842 bool QFace::GetLinkChain( int iSide, TChain& chain, SMDS_TypeOfPosition pos, int& error) const
3844 if ( iSide >= (int)_sides.size() ) // wrong argument iSide
3846 if ( _sideIsAdded[ iSide ]) // already in chain
3849 if ( _sides.size() != 4 ) { // triangle - visit all my continuous faces
3852 list< const QFace* > faces( 1, this );
3853 while ( !faces.empty() ) {
3854 const QFace* face = faces.front();
3855 for ( size_t i = 0; i < face->_sides.size(); ++i ) {
3856 if ( !face->_sideIsAdded[i] && face->_sides[i] ) {
3857 face->_sideIsAdded[i] = true;
3858 // find a face side in the chain
3859 TLinkInSet chLink = links.insert( TChainLink(face->_sides[i])).first;
3860 // TChain::iterator chLink = chain.begin();
3861 // for ( ; chLink != chain.end(); ++chLink )
3862 // if ( chLink->_qlink == face->_sides[i] )
3864 // if ( chLink == chain.end() )
3865 // chLink = chain.insert( chain.begin(), TChainLink(face->_sides[i]));
3866 // add a face to a chained link and put a continues face in the queue
3867 chLink->SetFace( face );
3868 if ( face->_sides[i]->MediumPos() == pos )
3869 if ( const QFace* contFace = face->_sides[i]->GetContinuesFace( face ))
3870 if ( contFace->_sides.size() == 3 )
3871 faces.push_back( contFace );
3876 if ( error < ERR_TRI )
3878 chain.insert( chain.end(), links.begin(),links.end() );
3881 _sideIsAdded[iSide] = true; // not to add this link to chain again
3882 const QLink* link = _sides[iSide];
3886 // add link into chain
3887 TChain::iterator chLink = chain.insert( chain.begin(), TChainLink(link));
3888 chLink->SetFace( this );
3891 // propagate from a quadrangle to neighbour faces
3892 if ( link->MediumPos() >= pos ) {
3893 int nbLinkFaces = link->_faces.size();
3894 if ( nbLinkFaces == 4 || (/*nbLinkFaces < 4 && */link->OnBoundary())) {
3895 // hexahedral mesh or boundary quadrangles - goto a continuous face
3896 if ( const QFace* f = link->GetContinuesFace( this ))
3897 if ( f->_sides.size() == 4 )
3898 return f->GetLinkChain( *chLink, chain, pos, error );
3901 TChainLink chLink(link); // side face of prismatic mesh - visit all faces of iSide
3902 for ( int i = 0; i < nbLinkFaces; ++i )
3903 if ( link->_faces[i] )
3904 link->_faces[i]->GetLinkChain( chLink, chain, pos, error );
3905 if ( error < ERR_PRISM )
3913 //================================================================================
3915 * \brief Return a boundary link of the triangle face
3916 * \param links - set of all links
3917 * \param avoidLink - link not to return
3918 * \param notBoundaryLink - out, neither the returned link nor avoidLink
3919 * \param nodeToContain - node the returned link must contain; if provided, search
3920 * also performed on adjacent faces
3921 * \param isAdjacentUsed - returns true if link is found in adjacent faces
3922 * \param nbRecursionsLeft - to limit recursion
3924 //================================================================================
3926 TLinkInSet QFace::GetBoundaryLink( const TLinkSet& links,
3927 const TChainLink& avoidLink,
3928 TLinkInSet * notBoundaryLink,
3929 const SMDS_MeshNode* nodeToContain,
3930 bool * isAdjacentUsed,
3931 int nbRecursionsLeft) const
3933 TLinkInSet linksEnd = links.end(), boundaryLink = linksEnd;
3935 typedef list< pair< const QFace*, TLinkInSet > > TFaceLinkList;
3936 TFaceLinkList adjacentFaces;
3938 for ( size_t iL = 0; iL < _sides.size(); ++iL )
3940 if ( avoidLink._qlink == _sides[iL] )
3942 TLinkInSet link = links.find( _sides[iL] );
3943 if ( link == linksEnd ) continue;
3944 if ( (*link)->MediumPos() > SMDS_TOP_FACE )
3945 continue; // We work on faces here, don't go inside a solid
3948 if ( link->IsBoundary() ) {
3949 if ( !nodeToContain ||
3950 (*link)->node1() == nodeToContain ||
3951 (*link)->node2() == nodeToContain )
3953 boundaryLink = link;
3954 if ( !notBoundaryLink ) break;
3957 else if ( notBoundaryLink ) {
3958 *notBoundaryLink = link;
3959 if ( boundaryLink != linksEnd ) break;
3962 if ( boundaryLink == linksEnd && nodeToContain ) // collect adjacent faces
3963 if ( const QFace* adj = link->NextFace( this ))
3964 if ( adj->Contains( nodeToContain ))
3965 adjacentFaces.push_back( make_pair( adj, link ));
3968 if ( isAdjacentUsed ) *isAdjacentUsed = false;
3969 if ( boundaryLink == linksEnd && nodeToContain && nbRecursionsLeft) // check adjacent faces
3971 if ( nbRecursionsLeft < 0 )
3972 nbRecursionsLeft = nodeToContain->NbInverseElements();
3973 TFaceLinkList::iterator adj = adjacentFaces.begin();
3974 for ( ; boundaryLink == linksEnd && adj != adjacentFaces.end(); ++adj )
3975 boundaryLink = adj->first->GetBoundaryLink( links, *(adj->second), 0, nodeToContain,
3976 isAdjacentUsed, nbRecursionsLeft-1);
3977 if ( isAdjacentUsed ) *isAdjacentUsed = true;
3979 return boundaryLink;
3981 //================================================================================
3983 * \brief Return a link ending at the given node but not avoidLink
3985 //================================================================================
3987 TLinkInSet QFace::GetLinkByNode( const TLinkSet& links,
3988 const TChainLink& avoidLink,
3989 const SMDS_MeshNode* nodeToContain) const
3991 for ( size_t i = 0; i < _sides.size(); ++i )
3992 if ( avoidLink._qlink != _sides[i] &&
3993 (_sides[i]->node1() == nodeToContain || _sides[i]->node2() == nodeToContain ))
3994 return links.find( _sides[i] );
3998 //================================================================================
4000 * \brief Return normal to the i-th side pointing outside the face
4002 //================================================================================
4004 gp_Vec QFace::LinkNorm(const int i, SMESH_MesherHelper* /*uvHelper*/) const
4006 gp_Vec norm = _normal ^ gp_Vec( XYZ(_sides[i]->node1()), XYZ(_sides[i]->node2()));
4007 gp_XYZ pIn = ( _sides[ (i+1)%3 ]->MiddlePnt() +
4008 _sides[ (i+2)%3 ]->MiddlePnt() ) / 2.;
4009 gp_Vec vecOut = ( _sides[i]->MiddlePnt() - pIn );
4011 if ( norm * vecOut < 0 )
4013 double mag2 = norm.SquareMagnitude();
4014 if ( mag2 > numeric_limits<double>::min() )
4015 norm /= sqrt( mag2 );
4018 //================================================================================
4020 * \brief Move medium node of theLink according to its distance from boundary
4021 * \param theLink - link to fix
4022 * \param theRefVec - movement of boundary
4023 * \param theLinks - all adjacent links of continuous triangles
4024 * \param theFaceHelper - helper is not used so far
4025 * \param thePrevLen - distance from the boundary
4026 * \param theStep - number of steps till movement propagation limit
4027 * \param theLinkNorm - out normal to theLink
4028 * \param theSign - 1 or -1 depending on movement of boundary
4029 * \retval double - distance from boundary to propagation limit or other boundary
4031 //================================================================================
4033 double QFace::MoveByBoundary( const TChainLink& theLink,
4034 const gp_Vec& theRefVec,
4035 const TLinkSet& theLinks,
4036 SMESH_MesherHelper* theFaceHelper,
4037 const double thePrevLen,
4039 gp_Vec* theLinkNorm,
4040 double theSign) const
4043 return thePrevLen; // propagation limit reached
4045 size_t iL; // index of theLink
4046 for ( iL = 0; iL < _sides.size(); ++iL )
4047 if ( theLink._qlink == _sides[ iL ])
4050 MSG(string(theStep,'.')<<" Ref( "<<theRefVec.X()<<","<<theRefVec.Y()<<","<<theRefVec.Z()<<" )"
4051 <<" thePrevLen " << thePrevLen);
4052 MSG(string(theStep,'.')<<" "<<*theLink._qlink);
4054 gp_Vec linkNorm = -LinkNorm( iL/*, theFaceHelper*/ ); // normal to theLink
4055 double refProj = theRefVec * linkNorm; // project movement vector to normal of theLink
4056 if ( theStep == theFirstStep )
4057 theSign = refProj < 0. ? -1. : 1.;
4058 else if ( theSign * refProj < 0.4 * theRefVec.Magnitude())
4059 return thePrevLen; // to propagate movement forward only, not in side dir or backward
4061 int iL1 = (iL + 1) % 3, iL2 = (iL + 2) % 3; // indices of the two other links of triangle
4062 TLinkInSet link1 = theLinks.find( _sides[iL1] );
4063 TLinkInSet link2 = theLinks.find( _sides[iL2] );
4065 const QFace *f1 = 0, *f2 = 0; // adjacent faces
4066 bool isBndLink1 = true, isBndLink2 = true;
4067 if ( link1 != theLinks.end() && link2 != theLinks.end() )
4069 f1 = link1->NextFace( this );
4070 f2 = link2->NextFace( this );
4072 isBndLink1 = ( theLink->MediumPos() > (*link1)->MediumPos() );
4073 isBndLink2 = ( theLink->MediumPos() > (*link2)->MediumPos() );
4074 if ( theStep == theFirstStep ) // (issue 22541) quad-dominant mesh
4076 if ( !isBndLink1 && !f1 )
4077 f1 = (*link1)->GetContinuesFace( this ); // get a quadrangle face
4078 if ( !isBndLink2 && !f2 )
4079 f2 = (*link2)->GetContinuesFace( this );
4082 else if ( _sides.size() < 4 )
4085 // propagate to adjacent faces till limit step or boundary
4086 double len1 = thePrevLen + (theLink->MiddlePnt() - _sides[iL1]->MiddlePnt()).Modulus();
4087 double len2 = thePrevLen + (theLink->MiddlePnt() - _sides[iL2]->MiddlePnt()).Modulus();
4088 gp_Vec linkDir1(0,0,0); // initialize to avoid valgrind error ("Conditional jump...")
4089 gp_Vec linkDir2(0,0,0);
4092 if ( f1 && !isBndLink1 )
4093 len1 = f1->MoveByBoundary
4094 ( *link1, theRefVec, theLinks, theFaceHelper, len1, theStep-1, &linkDir1, theSign);
4096 linkDir1 = LinkNorm( iL1/*, theFaceHelper*/ );
4098 MSG( " --------------- EXCEPTION");
4103 if ( f2 && !isBndLink2 )
4104 len2 = f2->MoveByBoundary
4105 ( *link2, theRefVec, theLinks, theFaceHelper, len2, theStep-1, &linkDir2, theSign);
4107 linkDir2 = LinkNorm( iL2/*, theFaceHelper*/ );
4109 MSG( " --------------- EXCEPTION");
4114 if ( theStep != theFirstStep )
4116 // choose chain length by direction of propagation most codirected with theRefVec
4117 bool choose1 = ( theRefVec * linkDir1 * theSign > theRefVec * linkDir2 * theSign );
4118 fullLen = choose1 ? len1 : len2;
4119 double r = thePrevLen / fullLen;
4121 gp_Vec move = linkNorm * refProj * ( 1 - r );
4122 theLink->Move( move, /*sum=*/true );
4124 MSG(string(theStep,'.')<<" Move "<< theLink->_mediumNode->GetID()<<
4125 " by " << refProj * ( 1 - r ) << " following " <<
4126 (choose1 ? *link1->_qlink : *link2->_qlink)); // warning: link1 can be invalid
4128 if ( theLinkNorm ) *theLinkNorm = linkNorm;
4133 //================================================================================
4135 * \brief Checks if the face is distorted due to bentLink
4137 //================================================================================
4139 bool QFace::IsSpoiled(const QLink* bentLink ) const
4141 // code is valid for convex faces only
4143 for ( TIDSortedNodeSet::const_iterator n = begin(); n != end(); ++n )
4144 gc += XYZ( *n ) / double( size() );
4145 for ( size_t i = 0; i < _sides.size(); ++i )
4147 if ( _sides[i] == bentLink ) continue;
4148 gp_Vec linkNorm = _normal ^ gp_Vec( XYZ(_sides[i]->node1()), XYZ(_sides[i]->node2()));
4149 gp_Vec vecOut( gc, _sides[i]->MiddlePnt() );
4150 if ( linkNorm * vecOut < 0 )
4152 double mag2 = linkNorm.SquareMagnitude();
4153 if ( mag2 > numeric_limits<double>::min() )
4154 linkNorm /= sqrt( mag2 );
4155 gp_Vec vecBent ( _sides[i]->MiddlePnt(), bentLink->MediumPnt());
4156 gp_Vec vecStraight( _sides[i]->MiddlePnt(), bentLink->MiddlePnt());
4157 if ( vecBent * linkNorm > -0.1*vecStraight.Magnitude() )
4164 //================================================================================
4166 * \brief Find pairs of continues faces
4168 //================================================================================
4170 void QLink::SetContinuesFaces() const
4172 // x0 x - QLink, [-|] - QFace, v - volume
4174 // | Between _faces of link x2 two vertical faces are continues
4175 // x1----x2-----x3 and two horizontal faces are continues. We set vertical faces
4176 // | to _faces[0] and _faces[1] and horizontal faces to
4177 // v2 | v3 _faces[2] and _faces[3] (or vice versa).
4180 if ( _faces.empty() )
4182 int iFaceCont = -1, nbBoundary = 0, iBoundary[2]={-1,-1};
4183 if ( _faces[0]->IsBoundary() )
4184 iBoundary[ nbBoundary++ ] = 0;
4185 for ( size_t iF = 1; iFaceCont < 0 && iF < _faces.size(); ++iF )
4187 // look for a face bounding none of volumes bound by _faces[0]
4188 bool sameVol = false;
4189 int nbVol = _faces[iF]->NbVolumes();
4190 for ( int iV = 0; !sameVol && iV < nbVol; ++iV )
4191 sameVol = ( _faces[iF]->_volumes[iV] == _faces[0]->_volumes[0] ||
4192 _faces[iF]->_volumes[iV] == _faces[0]->_volumes[1]);
4195 if ( _faces[iF]->IsBoundary() )
4196 iBoundary[ nbBoundary++ ] = iF;
4198 // Set continues faces: arrange _faces to have
4199 // _faces[0] continues to _faces[1]
4200 // _faces[2] continues to _faces[3]
4201 if ( nbBoundary == 2 ) // bnd faces are continues
4203 if (( iBoundary[0] < 2 ) != ( iBoundary[1] < 2 ))
4205 int iNear0 = iBoundary[0] < 2 ? 1-iBoundary[0] : 5-iBoundary[0];
4206 std::swap( _faces[ iBoundary[1] ], _faces[iNear0] );
4209 else if ( iFaceCont > 0 ) // continues faces found
4211 if ( iFaceCont != 1 )
4212 std::swap( _faces[1], _faces[iFaceCont] );
4214 else if ( _faces.size() > 1 ) // not found, set NULL by the first face
4216 _faces.insert( ++_faces.begin(), (QFace*) 0 );
4219 //================================================================================
4221 * \brief Return a face continues to the given one
4223 //================================================================================
4225 const QFace* QLink::GetContinuesFace( const QFace* face ) const
4227 if ( _faces.size() <= 4 )
4228 for ( size_t i = 0; i < _faces.size(); ++i ) {
4229 if ( _faces[i] == face ) {
4230 int iF = i < 2 ? 1-i : 5-i;
4231 return iF < (int)_faces.size() ? _faces[iF] : 0;
4236 //================================================================================
4238 * \brief True if link is on mesh boundary
4240 //================================================================================
4242 bool QLink::OnBoundary() const
4244 for ( size_t i = 0; i < _faces.size(); ++i )
4245 if (_faces[i] && _faces[i]->IsBoundary()) return true;
4248 //================================================================================
4250 * \brief Return normal of link of the chain
4252 //================================================================================
4254 gp_Vec TChainLink::Normal() const {
4256 if (_qfaces[0]) norm = _qfaces[0]->_normal;
4257 if (_qfaces[1]) norm += _qfaces[1]->_normal;
4260 //================================================================================
4262 * \brief Test link curvature taking into account size of faces
4264 //================================================================================
4266 bool TChainLink::IsStraight() const
4268 bool isStraight = _qlink->IsStraight();
4269 if ( isStraight && _qfaces[0] && !_qfaces[1] )
4271 int i = _qfaces[0]->LinkIndex( _qlink );
4272 int iOpp = ( i + 2 ) % _qfaces[0]->_sides.size();
4273 gp_XYZ mid1 = _qlink->MiddlePnt();
4274 gp_XYZ mid2 = _qfaces[0]->_sides[ iOpp ]->MiddlePnt();
4275 double faceSize2 = (mid1-mid2).SquareModulus();
4276 isStraight = _qlink->_nodeMove.SquareMagnitude() < 1/10./10. * faceSize2;
4281 //================================================================================
4283 * \brief Move medium nodes of vertical links of pentahedrons adjacent by side faces
4285 //================================================================================
4287 void fixPrism( TChain& allLinks )
4289 // separate boundary links from internal ones
4290 typedef set<const QLink*/*, QLink::PtrComparator*/> QLinkSet;
4291 QLinkSet interLinks, bndLinks1, bndLink2;
4293 bool isCurved = false;
4294 for ( TChain::iterator lnk = allLinks.begin(); lnk != allLinks.end(); ++lnk ) {
4295 if ( (*lnk)->OnBoundary() )
4296 bndLinks1.insert( lnk->_qlink );
4298 interLinks.insert( lnk->_qlink );
4299 isCurved = isCurved || !lnk->IsStraight();
4302 return; // no need to move
4304 QLinkSet *curBndLinks = &bndLinks1, *newBndLinks = &bndLink2;
4306 while ( !interLinks.empty() && !curBndLinks->empty() )
4308 // propagate movement from boundary links to connected internal links
4309 QLinkSet::iterator bnd = curBndLinks->begin(), bndEnd = curBndLinks->end();
4310 for ( ; bnd != bndEnd; ++bnd )
4312 const QLink* bndLink = *bnd;
4313 for ( size_t i = 0; i < bndLink->_faces.size(); ++i ) // loop on faces of bndLink
4315 const QFace* face = bndLink->_faces[i]; // quadrange lateral face of a prism
4316 if ( !face ) continue;
4317 // find and move internal link opposite to bndLink within the face
4318 int interInd = ( face->LinkIndex( bndLink ) + 2 ) % face->_sides.size();
4319 const QLink* interLink = face->_sides[ interInd ];
4320 QLinkSet::iterator pInterLink = interLinks.find( interLink );
4321 if ( pInterLink == interLinks.end() ) continue; // not internal link
4322 interLink->Move( bndLink->_nodeMove );
4323 // treated internal links become new boundary ones
4324 interLinks.erase( pInterLink );
4325 newBndLinks->insert( interLink );
4328 curBndLinks->clear();
4329 std::swap( curBndLinks, newBndLinks );
4333 //================================================================================
4335 * \brief Fix links of continues triangles near curved boundary
4337 //================================================================================
4339 void fixTriaNearBoundary( TChain & allLinks, SMESH_MesherHelper& /*helper*/)
4341 if ( allLinks.empty() ) return;
4343 TLinkSet linkSet( allLinks.begin(), allLinks.end());
4344 TLinkInSet linkIt = linkSet.begin(), linksEnd = linkSet.end();
4346 for ( linkIt = linkSet.begin(); linkIt != linksEnd; ++linkIt)
4348 if ( linkIt->IsBoundary() && !linkIt->IsStraight() && linkIt->_qfaces[0])
4350 // move iff a boundary link is bent towards inside of a face (issue 0021084)
4351 const QFace* face = linkIt->_qfaces[0];
4352 gp_XYZ pIn = ( face->_sides[0]->MiddlePnt() +
4353 face->_sides[1]->MiddlePnt() +
4354 face->_sides[2]->MiddlePnt() ) / 3.;
4355 gp_XYZ insideDir( pIn - (*linkIt)->MiddlePnt());
4356 bool linkBentInside = ((*linkIt)->_nodeMove.Dot( insideDir ) > 0 );
4357 //if ( face->IsSpoiled( linkIt->_qlink ))
4358 if ( linkBentInside )
4359 face->MoveByBoundary( *linkIt, (*linkIt)->_nodeMove, linkSet );
4364 //================================================================================
4366 * \brief Detect rectangular structure of links and build chains from them
4368 //================================================================================
4370 enum TSplitTriaResult {
4371 _OK, _NO_CORNERS, _FEW_ROWS, _MANY_ROWS, _NO_SIDELINK, _BAD_MIDQUAD, _NOT_RECT,
4372 _NO_MIDQUAD, _NO_UPTRIA, _BAD_SET_SIZE, _BAD_CORNER, _BAD_START, _NO_BOTLINK, _TWISTED_CHAIN };
4374 TSplitTriaResult splitTrianglesIntoChains( TChain & allLinks,
4375 vector< TChain> & resultChains,
4376 SMDS_TypeOfPosition pos )
4378 // put links in the set and evaluate number of result chains by number of boundary links
4380 size_t nbBndLinks = 0;
4381 for ( TChain::iterator lnk = allLinks.begin(); lnk != allLinks.end(); ++lnk ) {
4382 linkSet.insert( *lnk );
4383 nbBndLinks += lnk->IsBoundary();
4385 resultChains.clear();
4386 resultChains.reserve( nbBndLinks / 2 );
4388 TLinkInSet linkIt, linksEnd = linkSet.end();
4390 // find a boundary link with corner node; corner node has position pos-2
4391 // i.e. SMDS_TOP_VERTEX for links on faces and SMDS_TOP_EDGE for
4393 SMDS_TypeOfPosition cornerPos = SMDS_TypeOfPosition(pos-2);
4394 const SMDS_MeshNode* corner = 0;
4395 for ( linkIt = linkSet.begin(); linkIt != linksEnd; ++linkIt )
4396 if ( linkIt->IsBoundary() && (corner = (*linkIt)->EndPosNode(cornerPos)))
4401 TLinkInSet startLink = linkIt;
4402 const SMDS_MeshNode* startCorner = corner;
4403 vector< TChain* > rowChains;
4406 while ( startLink != linksEnd) // loop on columns
4408 // We suppose we have a rectangular structure like shown here. We have found a
4409 // corner of the rectangle (startCorner) and a boundary link sharing
4410 // |/ |/ | the startCorner (startLink). We are going to loop on rows of the
4411 // --o---o---o structure making several chains at once. One chain (columnChain)
4412 // |\ | /| starts at startLink and continues upward (we look at the structure
4413 // \ | \ | / | from such point that startLink is on the bottom of the structure).
4414 // \| \|/ | While going upward we also fill horizontal chains (rowChains) we
4415 // --o---o---o encounter.
4417 // / | \ | \ | startCorner
4422 if ( resultChains.size() == nbBndLinks / 2 )
4424 resultChains.push_back( TChain() );
4425 TChain& columnChain = resultChains.back();
4427 TLinkInSet botLink = startLink; // current horizontal link to go up from
4428 corner = startCorner; // current corner the botLink ends at
4430 while ( botLink != linksEnd ) // loop on rows
4432 // add botLink to the columnChain
4433 columnChain.push_back( *botLink );
4435 const QFace* botTria = botLink->_qfaces[0]; // bottom triangle bound by botLink
4437 { // the column ends
4438 if ( botLink == startLink )
4439 return _TWISTED_CHAIN; // issue 0020951
4440 linkSet.erase( botLink );
4441 if ( iRow != rowChains.size() )
4442 return _FEW_ROWS; // different nb of rows in columns
4445 // find the link dividing the quadrangle (midQuadLink) and vertical boundary
4446 // link ending at <corner> (sideLink); there are two cases:
4447 // 1) midQuadLink does not end at <corner>, then we easily find it by botTria,
4448 // since midQuadLink is not at boundary while sideLink is.
4449 // 2) midQuadLink ends at <corner>
4451 TLinkInSet midQuadLink = linksEnd;
4452 TLinkInSet sideLink = botTria->GetBoundaryLink( linkSet, *botLink, &midQuadLink,
4454 if ( isCase2 ) { // find midQuadLink among links of botTria
4455 midQuadLink = botTria->GetLinkByNode( linkSet, *botLink, corner );
4456 if ( midQuadLink->IsBoundary() )
4457 return _BAD_MIDQUAD;
4459 if ( sideLink == linksEnd || midQuadLink == linksEnd || sideLink == midQuadLink )
4460 return sideLink == linksEnd ? _NO_SIDELINK : _NO_MIDQUAD;
4463 columnChain.push_back( *midQuadLink );
4464 if ( iRow >= rowChains.size() ) {
4466 return _MANY_ROWS; // different nb of rows in columns
4467 if ( resultChains.size() == nbBndLinks / 2 )
4469 resultChains.push_back( TChain() );
4470 rowChains.push_back( & resultChains.back() );
4472 rowChains[iRow]->push_back( *sideLink );
4473 rowChains[iRow]->push_back( *midQuadLink );
4475 const QFace* upTria = midQuadLink->NextFace( botTria ); // upper tria of the rectangle
4479 // prepare startCorner and startLink for the next column
4480 startCorner = startLink->NextNode( startCorner );
4482 startLink = botTria->GetBoundaryLink( linkSet, *botLink, 0, startCorner );
4484 startLink = upTria->GetBoundaryLink( linkSet, *midQuadLink, 0, startCorner );
4485 // check if no more columns remains
4486 if ( startLink != linksEnd ) {
4487 const SMDS_MeshNode* botNode = startLink->NextNode( startCorner );
4488 if ( (isCase2 ? botTria : upTria)->Contains( botNode ))
4489 startLink = linksEnd; // startLink bounds upTria or botTria
4490 else if ( startLink == botLink || startLink == midQuadLink || startLink == sideLink )
4494 // find bottom link and corner for the next row
4495 corner = sideLink->NextNode( corner );
4496 // next bottom link ends at the new corner
4497 linkSet.erase( botLink );
4498 botLink = upTria->GetLinkByNode( linkSet, (isCase2 ? *sideLink : *midQuadLink), corner );
4499 if ( botLink == linksEnd || botLink == midQuadLink || botLink == sideLink)
4501 if ( midQuadLink == startLink || sideLink == startLink )
4502 return _TWISTED_CHAIN; // issue 0020951
4503 linkSet.erase( midQuadLink );
4504 linkSet.erase( sideLink );
4506 // make faces neighboring the found ones be boundary
4507 if ( startLink != linksEnd ) {
4508 const QFace* tria = isCase2 ? botTria : upTria;
4509 for ( int iL = 0; iL < 3; ++iL ) {
4510 linkIt = linkSet.find( tria->_sides[iL] );
4511 if ( linkIt != linksEnd )
4512 linkIt->RemoveFace( tria );
4515 if ( botLink->_qfaces[0] == upTria || botLink->_qfaces[1] == upTria )
4516 botLink->RemoveFace( upTria ); // make next botTria first in vector
4523 // In the linkSet, there must remain the last links of rowChains; add them
4524 if ( linkSet.size() != rowChains.size() )
4525 return _BAD_SET_SIZE;
4526 for ( size_t iRow = 0; iRow < rowChains.size(); ++iRow ) {
4527 // find the link (startLink) ending at startCorner
4529 for ( startLink = linkSet.begin(); startLink != linksEnd; ++startLink ) {
4530 if ( (*startLink)->node1() == startCorner ) {
4531 corner = (*startLink)->node2(); break;
4533 else if ( (*startLink)->node2() == startCorner) {
4534 corner = (*startLink)->node1(); break;
4537 if ( startLink == linksEnd )
4539 rowChains[ iRow ]->push_back( *startLink );
4540 linkSet.erase( startLink );
4541 startCorner = corner;
4547 //================================================================================
4549 * \brief Place medium nodes at the link middle for elements whose corner nodes
4550 * are out of geometrical boundary to prevent distorting elements.
4551 * Issue 0020982, note 0013990
4553 //================================================================================
4555 void force3DOutOfBoundary( SMESH_MesherHelper& theHelper,
4556 SMESH_ComputeErrorPtr& theError)
4558 SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
4559 TopoDS_Shape shape = theHelper.GetSubShape().Oriented( TopAbs_FORWARD );
4560 if ( shape.IsNull() ) return;
4562 if ( !dynamic_cast<SMESH_BadInputElements*>( theError.get() ))
4565 theError.reset( new SMESH_BadInputElements( meshDS ));
4567 theError.reset( new SMESH_BadInputElements( meshDS,
4569 theError->myComment,
4574 if ( shape.ShapeType() == TopAbs_FACE ) // 2D
4576 if ( theHelper.GetMesh()->NbTriangles( ORDER_QUADRATIC ) < 1 ) return;
4578 SMESHDS_SubMesh* faceSM = meshDS->MeshElements( shape );
4579 if ( !faceSM ) return;
4581 const TopoDS_Face& face = TopoDS::Face( shape );
4582 Handle(Geom_Surface) surface = BRep_Tool::Surface( face );
4584 TopExp_Explorer edgeIt( face, TopAbs_EDGE );
4585 for ( ; edgeIt.More(); edgeIt.Next() ) // loop on EDGEs of a FACE
4587 // check if the EDGE needs checking
4588 const TopoDS_Edge& edge = TopoDS::Edge( edgeIt.Current() );
4589 if ( SMESH_Algo::isDegenerated( edge ) )
4591 if ( theHelper.IsRealSeam( edge ) &&
4592 edge.Orientation() == TopAbs_REVERSED )
4595 SMESHDS_SubMesh* edgeSM = meshDS->MeshElements( edge );
4596 if ( !edgeSM ) continue;
4599 Handle(Geom2d_Curve) pcurve = BRep_Tool::CurveOnSurface( edge, face, f, l );
4600 BRepAdaptor_Curve curve3D( edge );
4601 switch ( curve3D.GetType() ) {
4602 case GeomAbs_Line: continue;
4603 case GeomAbs_Circle:
4604 case GeomAbs_Ellipse:
4605 case GeomAbs_Hyperbola:
4606 case GeomAbs_Parabola:
4609 gp_Vec D1, D2, Du1, Dv1; gp_Pnt p;
4610 curve3D.D2( 0.5 * ( f + l ), p, D1, D2 );
4611 gp_Pnt2d uv = pcurve->Value( 0.5 * ( f + l ) );
4612 surface->D1( uv.X(), uv.Y(), p, Du1, Dv1 );
4613 gp_Vec fNorm = Du1 ^ Dv1;
4614 if ( fNorm.IsParallel( D2, M_PI * 25./180. ))
4615 continue; // face is normal to the curve3D
4617 gp_Vec curvNorm = fNorm ^ D1;
4618 if ( edge.Orientation() == TopAbs_REVERSED ) curvNorm.Reverse();
4619 if ( curvNorm * D2 > 0 )
4620 continue; // convex edge
4622 catch ( Standard_Failure )
4628 // get nodes shared by faces that may be distorted
4629 SMDS_NodeIteratorPtr nodeIt;
4630 if ( edgeSM->NbNodes() > 0 ) {
4631 nodeIt = edgeSM->GetNodes();
4634 SMESHDS_SubMesh* vertexSM = meshDS->MeshElements( theHelper.IthVertex( 0, edge ));
4636 vertexSM = meshDS->MeshElements( theHelper.IthVertex( 1, edge ));
4637 if ( !vertexSM ) continue;
4638 nodeIt = vertexSM->GetNodes();
4641 // find suspicious faces
4642 TIDSortedElemSet checkedFaces;
4643 vector< const SMDS_MeshNode* > nOnEdge( 2 );
4644 const SMDS_MeshNode* nOnFace;
4645 while ( nodeIt->more() )
4647 const SMDS_MeshNode* n = nodeIt->next();
4648 SMDS_ElemIteratorPtr faceIt = n->GetInverseElementIterator( SMDSAbs_Face );
4649 while ( faceIt->more() )
4651 const SMDS_MeshElement* f = faceIt->next();
4652 if ( !faceSM->Contains( f ) ||
4653 f->NbNodes() < 6 || // check quadratic triangles only
4654 !checkedFaces.insert( f ).second )
4657 // get nodes on EDGE and on FACE of a suspicious face
4658 nOnEdge.clear(); nOnFace = 0;
4659 SMDS_MeshElement::iterator triNode = f->begin_nodes();
4660 for ( int nbN = 0; nbN < 3; ++triNode, ++nbN )
4663 if ( n->GetPosition()->GetDim() == 2 )
4666 nOnEdge.push_back( n );
4669 // check if nOnFace is inside the FACE
4670 if ( nOnFace && nOnEdge.size() == 2 )
4672 theHelper.AddTLinks( static_cast< const SMDS_MeshFace* > ( f ));
4673 if ( !SMESH_MeshAlgos::FaceNormal( f, faceNorm, /*normalized=*/false ))
4675 gp_XYZ edgeDir = SMESH_TNodeXYZ( nOnEdge[0] ) - SMESH_TNodeXYZ( nOnEdge[1] );
4676 gp_XYZ edgeNorm = faceNorm ^ edgeDir;
4677 n = theHelper.GetMediumNode( nOnEdge[0], nOnEdge[1], true ); // find n, not create
4678 gp_XYZ pN0 = SMESH_TNodeXYZ( nOnEdge[0] );
4679 gp_XYZ pMedium = SMESH_TNodeXYZ( n ); // on-edge node location
4680 gp_XYZ pFaceN = SMESH_TNodeXYZ( nOnFace ); // on-face node location
4681 double hMedium = edgeNorm * gp_Vec( pN0, pMedium ).XYZ();
4682 double hFace = edgeNorm * gp_Vec( pN0, pFaceN ).XYZ();
4683 if ( Abs( hMedium ) > Abs( hFace * 0.6 ))
4685 // nOnFace is out of FACE, move a medium on-edge node to the middle
4686 gp_XYZ pMid3D = 0.5 * ( pN0 + SMESH_TNodeXYZ( nOnEdge[1] ));
4687 meshDS->MoveNode( n, pMid3D.X(), pMid3D.Y(), pMid3D.Z() );
4688 MSG( "move OUT of face " << n );
4689 static_cast<SMESH_BadInputElements*>( theError.get() )->add( f );
4695 if ( theError->HasBadElems() )
4696 theError->myName = EDITERR_NO_MEDIUM_ON_GEOM;
4699 } // 2D ==============================================================================
4701 if ( shape.ShapeType() == TopAbs_SOLID ) // 3D
4703 if ( theHelper.GetMesh()->NbTetras ( ORDER_QUADRATIC ) < 1 &&
4704 theHelper.GetMesh()->NbPyramids( ORDER_QUADRATIC ) < 1 ) return;
4706 SMESHDS_SubMesh* solidSM = meshDS->MeshElements( shape );
4707 if ( !solidSM ) return;
4709 // check if the SOLID is bound by concave FACEs
4710 vector< TopoDS_Face > concaveFaces;
4711 TopExp_Explorer faceIt( shape, TopAbs_FACE );
4712 for ( ; faceIt.More(); faceIt.Next() ) // loop on FACEs of a SOLID
4714 const TopoDS_Face& face = TopoDS::Face( faceIt.Current() );
4715 if ( !meshDS->MeshElements( face )) continue;
4717 BRepAdaptor_Surface surface( face );
4718 switch ( surface.GetType() ) {
4719 case GeomAbs_Plane: continue;
4720 case GeomAbs_Cylinder:
4722 case GeomAbs_Sphere:
4725 double u = 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() );
4726 double v = 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() );
4727 gp_Vec Du1, Dv1, Du2, Dv2, Duv2; gp_Pnt p;
4728 surface.D2( u,v, p, Du1, Dv1, Du2, Dv2, Duv2 );
4729 gp_Vec fNorm = Du1 ^ Dv1;
4730 if ( face.Orientation() == TopAbs_REVERSED ) fNorm.Reverse();
4731 bool concaveU = ( fNorm * Du2 > 1e-100 );
4732 bool concaveV = ( fNorm * Dv2 > 1e-100 );
4733 if ( concaveU || concaveV )
4734 concaveFaces.push_back( face );
4736 catch ( Standard_Failure )
4738 concaveFaces.push_back( face );
4743 if ( concaveFaces.empty() )
4746 // fix 2D mesh on the SOLID
4747 for ( faceIt.ReInit(); faceIt.More(); faceIt.Next() ) // loop on FACEs of a SOLID
4749 SMESH_MesherHelper faceHelper( *theHelper.GetMesh() );
4750 faceHelper.SetSubShape( faceIt.Current() );
4751 force3DOutOfBoundary( faceHelper, theError );
4754 // get an iterator over faces on concaveFaces
4755 vector< SMDS_ElemIteratorPtr > faceIterVec( concaveFaces.size() );
4756 for ( size_t i = 0; i < concaveFaces.size(); ++i )
4757 faceIterVec[i] = meshDS->MeshElements( concaveFaces[i] )->GetElements();
4758 typedef SMDS_IteratorOnIterators
4759 < const SMDS_MeshElement*, vector< SMDS_ElemIteratorPtr > > TIterOnIter;
4760 SMDS_ElemIteratorPtr faceIter( new TIterOnIter( faceIterVec ));
4762 // search to check if a volume is close to a concave face
4763 SMESHUtils::Deleter< SMESH_ElementSearcher > faceSearcher
4764 ( SMESH_MeshAlgos::GetElementSearcher( *theHelper.GetMeshDS(), faceIter ));
4767 //BRepClass3d_SolidClassifier solidClassifier( shape );
4769 TIDSortedElemSet checkedVols, movedNodes;
4770 //for ( faceIt.ReInit(); faceIt.More(); faceIt.Next() ) // loop on FACEs of a SOLID
4771 for ( size_t iF = 0; iF < concaveFaces.size(); ++iF ) // loop on concave FACEs
4773 //const TopoDS_Shape& face = faceIt.Current();
4774 const TopoDS_Shape& face = concaveFaces[ iF ];
4775 SMESHDS_SubMesh* faceSM = meshDS->MeshElements( face );
4776 if ( !faceSM ) continue;
4778 // get nodes shared by volumes (tet and pyra) on the FACE that may be distorted
4779 SMDS_NodeIteratorPtr nodeIt;
4780 if ( faceSM->NbNodes() > 0 ) {
4781 nodeIt = faceSM->GetNodes();
4784 TopExp_Explorer vertex( face, TopAbs_VERTEX );
4785 SMESHDS_SubMesh* vertexSM = meshDS->MeshElements( vertex.Current() );
4786 if ( !vertexSM ) continue;
4787 nodeIt = vertexSM->GetNodes();
4789 // get ids of sub-shapes of the FACE
4791 SMESH_subMeshIteratorPtr smIt =
4792 theHelper.GetMesh()->GetSubMesh( face )->getDependsOnIterator(/*includeSelf=*/true);
4793 while ( smIt->more() )
4794 subIDs.insert( smIt->next()->GetId() );
4796 // find suspicious volumes adjacent to the FACE
4797 vector< const SMDS_MeshNode* > nOnFace( 4 );
4798 const SMDS_MeshNode* nInSolid;
4799 while ( nodeIt->more() )
4801 const SMDS_MeshNode* n = nodeIt->next();
4802 SMDS_ElemIteratorPtr volIt = n->GetInverseElementIterator( SMDSAbs_Volume );
4803 while ( volIt->more() )
4805 const SMDS_MeshElement* vol = volIt->next();
4806 size_t nbN = vol->NbCornerNodes();
4807 if ( ( nbN != 4 && nbN != 5 ) ||
4808 !solidSM->Contains( vol ) ||
4809 !checkedVols.insert( vol ).second )
4812 // get nodes on FACE and in SOLID of a suspicious volume
4813 nOnFace.clear(); nInSolid = 0;
4814 SMDS_MeshElement::iterator volNode = vol->begin_nodes();
4815 for ( int nb = nbN; nb > 0; ++volNode, --nb )
4818 if ( n->GetPosition()->GetDim() == 3 )
4820 else if ( subIDs.count( n->getshapeId() ))
4821 nOnFace.push_back( n );
4825 if ( !nInSolid || nOnFace.size() != nbN - 1 )
4828 // get size of the vol
4829 SMESH_TNodeXYZ pInSolid( nInSolid ), pOnFace0( nOnFace[0] );
4830 double volLength = pInSolid.SquareDistance( nOnFace[0] );
4831 for ( size_t i = 1; i < nOnFace.size(); ++i )
4833 volLength = Max( volLength, pOnFace0.SquareDistance( nOnFace[i] ));
4836 // check if vol is close to concaveFaces
4837 const SMDS_MeshElement* closeFace =
4838 faceSearcher->FindClosestTo( pInSolid, SMDSAbs_Face );
4840 pInSolid.SquareDistance( closeFace->GetNode(0) ) > 4 * volLength )
4843 // check if vol is distorted, i.e. a medium node is much closer
4844 // to nInSolid than the link middle
4845 bool isDistorted = false;
4846 SMDS_FaceOfNodes onFaceTria( nOnFace[0], nOnFace[1], nOnFace[2] );
4847 if ( !SMESH_MeshAlgos::FaceNormal( &onFaceTria, faceNorm, /*normalized=*/false ))
4849 theHelper.AddTLinks( static_cast< const SMDS_MeshVolume* > ( vol ));
4850 vector< pair< SMESH_TLink, const SMDS_MeshNode* > > links;
4851 for ( size_t i = 0; i < nOnFace.size(); ++i ) // loop on links between nOnFace
4852 for ( size_t j = i+1; j < nOnFace.size(); ++j )
4854 SMESH_TLink link( nOnFace[i], nOnFace[j] );
4855 TLinkNodeMap::const_iterator linkIt =
4856 theHelper.GetTLinkNodeMap().find( link );
4857 if ( linkIt != theHelper.GetTLinkNodeMap().end() )
4859 links.push_back( make_pair( linkIt->first, linkIt->second ));
4860 if ( !isDistorted ) {
4861 // compare projections of nInSolid and nMedium to face normal
4862 gp_Pnt pMedium = SMESH_TNodeXYZ( linkIt->second );
4863 double hMedium = faceNorm * gp_Vec( pOnFace0, pMedium ).XYZ();
4864 double hVol = faceNorm * gp_Vec( pOnFace0, pInSolid ).XYZ();
4865 isDistorted = ( Abs( hMedium ) > Abs( hVol * 0.75 ));
4869 // move medium nodes to link middle
4872 for ( size_t i = 0; i < links.size(); ++i )
4874 const SMDS_MeshNode* nMedium = links[i].second;
4875 if ( movedNodes.insert( nMedium ).second )
4877 gp_Pnt pMid3D = 0.5 * ( SMESH_TNodeXYZ( links[i].first.node1() ) +
4878 SMESH_TNodeXYZ( links[i].first.node2() ));
4879 meshDS->MoveNode( nMedium, pMid3D.X(), pMid3D.Y(), pMid3D.Z() );
4880 MSG( "move OUT of solid " << nMedium );
4883 static_cast<SMESH_BadInputElements*>( theError.get() )->add( vol );
4885 } // loop on volumes sharing a node on FACE
4886 } // loop on nodes on FACE
4887 } // loop on FACEs of a SOLID
4889 if ( theError->HasBadElems() )
4890 theError->myName = EDITERR_NO_MEDIUM_ON_GEOM;
4896 //=======================================================================
4898 * \brief Move medium nodes of faces and volumes to fix distorted elements
4899 * \param error - container of fixed distorted elements
4900 * \param volumeOnly - to fix nodes on faces or not, if the shape is solid
4902 * Issue 0020307: EDF 992 SMESH : Linea/Quadratic with Medium Node on Geometry
4904 //=======================================================================
4906 void SMESH_MesherHelper::FixQuadraticElements(SMESH_ComputeErrorPtr& compError,
4909 //MESSAGE("FixQuadraticElements " << volumeOnly);
4910 // setenv NO_FixQuadraticElements to know if FixQuadraticElements() is guilty of bad conversion
4911 if ( getenv("NO_FixQuadraticElements") )
4914 // 0. Apply algorithm to SOLIDs or FACEs
4915 // ----------------------------------------------
4916 if ( myShape.IsNull() ) {
4917 if ( !myMesh->HasShapeToMesh() ) return;
4918 SetSubShape( myMesh->GetShapeToMesh() );
4922 TopTools_IndexedMapOfShape solids;
4923 TopExp::MapShapes(myShape,TopAbs_SOLID,solids);
4924 nbSolids = solids.Extent();
4926 TopTools_MapOfShape faces; // faces not in solid or in not meshed solid
4927 for ( TopExp_Explorer f(myShape,TopAbs_FACE,TopAbs_SOLID); f.More(); f.Next() ) {
4928 faces.Add( f.Current() ); // not in solid
4930 for ( TopExp_Explorer s(myShape,TopAbs_SOLID); s.More(); s.Next() ) {
4931 if ( myMesh->GetSubMesh( s.Current() )->IsEmpty() ) { // get faces of solid
4932 for ( TopExp_Explorer f( s.Current(), TopAbs_FACE); f.More(); f.Next() )
4933 faces.Add( f.Current() ); // in not meshed solid
4935 else { // fix nodes in the solid and its faces
4937 MSG("FIX SOLID " << nbSolids-- << " #" << GetMeshDS()->ShapeToIndex(s.Current()));
4939 SMESH_MesherHelper h(*myMesh);
4940 h.SetSubShape( s.Current() );
4941 h.ToFixNodeParameters(true);
4942 h.FixQuadraticElements( compError, false );
4945 // fix nodes on geom faces
4947 int nbfaces = nbSolids;
4948 nbfaces = faces.Extent(); /*avoid "unused varianbles": */ nbfaces++, nbfaces--;
4950 for ( TopTools_MapIteratorOfMapOfShape fIt( faces ); fIt.More(); fIt.Next() ) {
4951 MESSAGE("FIX FACE " << nbfaces-- << " #" << GetMeshDS()->ShapeToIndex(fIt.Key()));
4952 MSG("FIX FACE " << nbfaces-- << " #" << GetMeshDS()->ShapeToIndex(fIt.Key()));
4953 SMESH_MesherHelper h(*myMesh);
4954 h.SetSubShape( fIt.Key() );
4955 h.ToFixNodeParameters(true);
4956 h.FixQuadraticElements( compError, true);
4958 //perf_print_all_meters(1);
4959 if ( compError && compError->myName == EDITERR_NO_MEDIUM_ON_GEOM )
4960 compError->myComment = "during conversion to quadratic, "
4961 "some medium nodes were not placed on geometry to avoid distorting elements";
4965 // 1. Find out type of elements and get iterator on them
4966 // ---------------------------------------------------
4968 SMDS_ElemIteratorPtr elemIt;
4969 SMDSAbs_ElementType elemType = SMDSAbs_All;
4971 SMESH_subMesh* submesh = myMesh->GetSubMeshContaining( myShapeID );
4974 if ( SMESHDS_SubMesh* smDS = submesh->GetSubMeshDS() ) {
4975 elemIt = smDS->GetElements();
4976 if ( elemIt->more() ) {
4977 elemType = elemIt->next()->GetType();
4978 elemIt = smDS->GetElements();
4981 if ( !elemIt || !elemIt->more() || elemType < SMDSAbs_Face )
4984 // 2. Fill in auxiliary data structures
4985 // ----------------------------------
4989 set< QLink >::iterator pLink;
4990 set< QFace >::iterator pFace;
4992 bool isCurved = false;
4993 //bool hasRectFaces = false;
4994 //set<int> nbElemNodeSet;
4995 SMDS_VolumeTool volTool;
4997 TIDSortedNodeSet apexOfPyramid;
4998 const int apexIndex = 4;
5001 // Move medium nodes to the link middle for elements whose corner nodes
5002 // are out of geometrical boundary to fix distorted elements.
5003 force3DOutOfBoundary( *this, compError );
5005 if ( elemType == SMDSAbs_Volume )
5007 while ( elemIt->more() ) // loop on volumes
5009 const SMDS_MeshElement* vol = elemIt->next();
5010 if ( !vol->IsQuadratic() || !volTool.Set( vol ))
5012 double volMinSize2 = -1.;
5013 for ( int iF = 0; iF < volTool.NbFaces(); ++iF ) // loop on faces of volume
5015 int nbN = volTool.NbFaceNodes( iF );
5016 //nbElemNodeSet.insert( nbN );
5017 const SMDS_MeshNode** faceNodes = volTool.GetFaceNodes( iF );
5018 vector< const QLink* > faceLinks( nbN/2 );
5019 for ( int iN = 0; iN < nbN; iN += 2 ) // loop on links of a face
5022 QLink link( faceNodes[iN], faceNodes[iN+2], faceNodes[iN+1] );
5023 pLink = links.insert( link ).first;
5024 faceLinks[ iN/2 ] = & *pLink;
5026 if ( link.MediumPos() == SMDS_TOP_3DSPACE )
5028 if ( !link.IsStraight() )
5029 return; // already fixed
5031 else if ( !isCurved )
5033 if ( volMinSize2 < 0 ) volMinSize2 = volTool.MinLinearSize2();
5034 isCurved = !isStraightLink( volMinSize2, link._nodeMove.SquareMagnitude() );
5038 pFace = faces.insert( QFace( faceLinks )).first;
5039 if ( pFace->NbVolumes() == 0 )
5040 pFace->AddSelfToLinks();
5041 pFace->SetVolume( vol );
5042 // hasRectFaces = hasRectFaces ||
5043 // ( volTool.GetVolumeType() == SMDS_VolumeTool::QUAD_HEXA ||
5044 // volTool.GetVolumeType() == SMDS_VolumeTool::QUAD_PENTA );
5047 pFace->_face = GetMeshDS()->FindFace(faceNodes[0],faceNodes[2],faceNodes[4]);
5049 pFace->_face = GetMeshDS()->FindFace(faceNodes[0],faceNodes[2],
5050 faceNodes[4],faceNodes[6] );
5053 // collect pyramid apexes for further correction
5054 if ( vol->NbCornerNodes() == 5 )
5055 apexOfPyramid.insert( vol->GetNode( apexIndex ));
5057 set< QLink >::iterator pLink = links.begin();
5058 for ( ; pLink != links.end(); ++pLink )
5059 pLink->SetContinuesFaces();
5063 while ( elemIt->more() ) // loop on faces
5065 const SMDS_MeshElement* face = elemIt->next();
5066 if ( !face->IsQuadratic() )
5068 //nbElemNodeSet.insert( face->NbNodes() );
5069 int nbN = face->NbNodes()/2;
5070 vector< const QLink* > faceLinks( nbN );
5071 for ( int iN = 0; iN < nbN; ++iN ) // loop on links of a face
5074 QLink link( face->GetNode(iN), face->GetNode((iN+1)%nbN), face->GetNode(iN+nbN) );
5075 pLink = links.insert( link ).first;
5076 faceLinks[ iN ] = & *pLink;
5078 link.node1()->GetPosition()->GetTypeOfPosition() < 2 &&
5079 link.node2()->GetPosition()->GetTypeOfPosition() < 2 )
5080 isCurved = !link.IsStraight();
5083 pFace = faces.insert( QFace( faceLinks )).first;
5084 pFace->AddSelfToLinks();
5085 //hasRectFaces = ( hasRectFaces || nbN == 4 );
5089 return; // no curved edges of faces
5091 // 3. Compute displacement of medium nodes
5092 // ---------------------------------------
5094 SMESH_MesherHelper faceHlp(*myMesh);
5096 // two loops on QFaces: the first is to treat boundary links, the second is for internal ones.
5097 TopLoc_Location loc;
5099 // not to treat boundary of volumic sub-mesh.
5100 int isInside = ( elemType == SMDSAbs_Volume && volumeOnly ) ? 1 : 0;
5101 for ( ; isInside < 2; ++isInside )
5103 MSG( "--------------- LOOP (inside=" << isInside << ") ------------------");
5104 SMDS_TypeOfPosition pos = isInside ? SMDS_TOP_3DSPACE : SMDS_TOP_FACE;
5105 SMDS_TypeOfPosition bndPos = isInside ? SMDS_TOP_FACE : SMDS_TOP_EDGE;
5107 for ( pFace = faces.begin(); pFace != faces.end(); ++pFace ) {
5108 if ( bool(isInside) == pFace->IsBoundary() )
5110 for ( int dir = 0; dir < 2; ++dir ) // 2 directions of propagation from the quadrangle
5113 // make chain of links connected via continues faces
5116 if ( !pFace->GetLinkChain( dir, rawChain, pos, error) && error ==ERR_UNKNOWN ) continue;
5118 if ( !pFace->GetLinkChain( dir+2, rawChain, pos, error ) && error ==ERR_UNKNOWN ) continue;
5120 vector< TChain > chains;
5121 if ( error == ERR_OK ) { // chain contains continues rectangles
5123 chains[0].splice( chains[0].begin(), rawChain );
5125 else if ( error == ERR_TRI ) { // chain contains continues triangles
5126 TSplitTriaResult res = splitTrianglesIntoChains( rawChain, chains, pos );
5127 if ( res != _OK ) { // not 'quadrangles split into triangles' in chain
5128 fixTriaNearBoundary( rawChain, *this );
5132 else if ( error == ERR_PRISM ) { // quadrangle side faces of prisms
5133 fixPrism( rawChain );
5139 for ( size_t iC = 0; iC < chains.size(); ++iC )
5141 TChain& chain = chains[iC];
5142 if ( chain.empty() ) continue;
5143 if ( chain.front().IsStraight() && chain.back().IsStraight() ) {
5144 MSG("3D straight - ignore");
5147 if ( chain.front()->MediumPos() > bndPos ||
5148 chain.back() ->MediumPos() > bndPos ) {
5149 MSG("Internal chain - ignore");
5152 // measure chain length and compute link position along the chain
5153 double chainLen = 0;
5154 vector< double > linkPos;
5155 TChain savedChain; // backup
5156 MSGBEG( "Link medium nodes: ");
5157 TChain::iterator link0 = chain.begin(), link1 = chain.begin(), link2;
5158 for ( ++link1; link1 != chain.end(); ++link1, ++link0 ) {
5159 MSGBEG( (*link0)->_mediumNode->GetID() << "-" <<(*link1)->_mediumNode->GetID()<<" ");
5160 double len = ((*link0)->MiddlePnt() - (*link1)->MiddlePnt()).Modulus();
5161 while ( len < numeric_limits<double>::min() ) { // remove degenerated link
5162 if ( savedChain.empty() ) savedChain = chain;
5163 link1 = chain.erase( link1 );
5164 if ( link1 == chain.end() )
5166 len = ((*link0)->MiddlePnt() - (*link1)->MiddlePnt()).Modulus();
5169 linkPos.push_back( chainLen );
5172 if ( linkPos.size() <= 2 && savedChain.size() > 2 ) {
5177 for ( link1 = chain.begin(); link1 != chain.end(); ++link1 ) {
5179 linkPos.push_back( chainLen );
5182 gp_Vec move0 = chain.front()->_nodeMove;
5183 gp_Vec move1 = chain.back ()->_nodeMove;
5188 // compute node displacement of end links of chain in parametric space of FACE
5189 TChainLink& linkOnFace = *(++chain.begin());
5190 const SMDS_MeshNode* nodeOnFace = linkOnFace->_mediumNode;
5191 TopoDS_Shape f = GetSubShapeByNode( nodeOnFace, GetMeshDS() );
5192 if ( !f.IsNull() && f.ShapeType() == TopAbs_FACE )
5194 face = TopoDS::Face( f );
5195 faceHlp.SetSubShape( face );
5196 Handle(Geom_Surface) surf = BRep_Tool::Surface(face,loc);
5197 //bool isStraight[2]; // commented for issue 0023118
5198 for ( int is1 = 0; is1 < 2; ++is1 ) // move0 or move1
5200 TChainLink& link = is1 ? chain.back() : chain.front();
5201 gp_XY uvm = faceHlp.GetNodeUV( face, link->_mediumNode, nodeOnFace, &checkUV );
5202 gp_XY uv1 = faceHlp.GetNodeUV( face, link->node1(), nodeOnFace, &checkUV );
5203 gp_XY uv2 = faceHlp.GetNodeUV( face, link->node2(), nodeOnFace, &checkUV );
5204 gp_XY uv12 = faceHlp.GetMiddleUV( surf, uv1, uv2 );
5205 // uvMove = uvm - uv12
5206 gp_XY uvMove = ApplyIn2D(surf, uvm, uv12, gp_XY_Subtracted, /*inPeriod=*/false);
5207 ( is1 ? move1 : move0 ).SetCoord( uvMove.X(), uvMove.Y(), 0 );
5208 if ( !is1 ) // correct nodeOnFace for move1 (issue 0020919)
5209 nodeOnFace = (*(++chain.rbegin()))->_mediumNode;
5210 // isStraight[is1] = isStraightLink( (uv2-uv1).SquareModulus(),
5211 // 10 * uvMove.SquareModulus());
5213 // if ( isStraight[0] && isStraight[1] ) {
5214 // MSG("2D straight - ignore");
5215 // continue; // straight - no need to move nodes of internal links
5218 // check if a chain is already fixed
5219 gp_XY uvm = faceHlp.GetNodeUV( face, linkOnFace->_mediumNode, 0, &checkUV );
5220 gp_XY uv1 = faceHlp.GetNodeUV( face, linkOnFace->node1(), nodeOnFace, &checkUV );
5221 gp_XY uv2 = faceHlp.GetNodeUV( face, linkOnFace->node2(), nodeOnFace, &checkUV );
5222 gp_XY uv12 = faceHlp.GetMiddleUV( surf, uv1, uv2 );
5223 if (( uvm - uv12 ).SquareModulus() > 1e-10 )
5225 MSG("Already fixed - ignore");
5231 if ( isInside || face.IsNull() )
5233 // compute node displacement of end links in their local coord systems
5235 TChainLink& ln0 = chain.front(), ln1 = *(++chain.begin());
5236 trsf.SetTransformation( gp_Ax3( gp::Origin(), ln0.Normal(),
5237 gp_Vec( ln0->MiddlePnt(), ln1->MiddlePnt() )));
5238 move0.Transform(trsf);
5241 TChainLink& ln0 = *(++chain.rbegin()), ln1 = chain.back();
5242 trsf.SetTransformation( gp_Ax3( gp::Origin(), ln1.Normal(),
5243 gp_Vec( ln0->MiddlePnt(), ln1->MiddlePnt() )));
5244 move1.Transform(trsf);
5247 // compute displacement of medium nodes
5248 link2 = chain.begin();
5251 for ( int i = 0; link2 != chain.end(); ++link0, ++link1, ++link2, ++i )
5253 double r = linkPos[i] / chainLen;
5254 // displacement in local coord system
5255 gp_Vec move = (1. - r) * move0 + r * move1;
5256 if ( isInside || face.IsNull()) {
5257 // transform to global
5258 gp_Vec x01( (*link0)->MiddlePnt(), (*link1)->MiddlePnt() );
5259 gp_Vec x12( (*link1)->MiddlePnt(), (*link2)->MiddlePnt() );
5261 gp_Vec x = x01.Normalized() + x12.Normalized();
5262 trsf.SetTransformation( gp_Ax3( gp::Origin(), link1->Normal(), x), gp_Ax3() );
5263 } catch ( Standard_Failure ) {
5266 move.Transform(trsf);
5267 (*link1)->Move( move, /*sum=*/false, /*is2dFixed=*/false );
5270 // compute 3D displacement by 2D one
5271 Handle(Geom_Surface) s = BRep_Tool::Surface(face,loc);
5272 gp_XY oldUV = faceHlp.GetNodeUV( face, (*link1)->_mediumNode, 0, &checkUV );
5273 gp_XY newUV = ApplyIn2D( s, oldUV, gp_XY( move.X(),move.Y()), gp_XY_Added );
5274 gp_Pnt newPnt = s->Value( newUV.X(), newUV.Y());
5275 move = gp_Vec( XYZ((*link1)->_mediumNode), newPnt.Transformed(loc) );
5276 if ( SMDS_FacePositionPtr nPos = (*link1)->_mediumNode->GetPosition())
5277 nPos->SetParameters( newUV.X(), newUV.Y() );
5279 if ( (XYZ((*link1)->node1()) - XYZ((*link1)->node2())).SquareModulus() <
5280 move.SquareMagnitude())
5282 gp_XY uv0 = faceHlp.GetNodeUV( face, (*link0)->_mediumNode, 0, &checkUV );
5283 gp_XY uv2 = faceHlp.GetNodeUV( face, (*link2)->_mediumNode, 0, &checkUV );
5284 MSG( "TOO LONG MOVE \t" <<
5285 "uv0: "<<uv0.X()<<", "<<uv0.Y()<<" \t" <<
5286 "uv2: "<<uv2.X()<<", "<<uv2.Y()<<" \t" <<
5287 "uvOld: "<<oldUV.X()<<", "<<oldUV.Y()<<" \t" <<
5288 "newUV: "<<newUV.X()<<", "<<newUV.Y()<<" \t");
5289 uv0.SetX( uv2.X() ); // avoid warning: variable set but not used
5292 (*link1)->Move( move, /*sum=*/false, /*is2dFixed=*/true );
5294 MSG( "Move " << (*link1)->_mediumNode->GetID() << " following "
5295 << chain.front()->_mediumNode->GetID() <<"-"
5296 << chain.back ()->_mediumNode->GetID() <<
5297 " by " << move.Magnitude());
5299 } // loop on chains of links
5300 } // loop on 2 directions of propagation from quadrangle
5302 } // fix faces and/or volumes
5307 TIDSortedElemSet biQuadQuas, biQuadTris, triQuadHexa, biQuadPenta;
5308 const bool toFixCentralNodes = ( myMesh->NbBiQuadQuadrangles() +
5309 myMesh->NbBiQuadTriangles() +
5310 myMesh->NbTriQuadraticHexas() +
5311 myMesh->NbBiQuadPrisms());
5313 faceHlp.ToFixNodeParameters( true );
5315 for ( pLink = links.begin(); pLink != links.end(); ++pLink ) {
5316 if ( pLink->IsMoved() )
5318 gp_Pnt p = pLink->MiddlePnt() + pLink->Move();
5320 // put on surface nodes on FACE but moved in 3D (23050)
5321 if ( !pLink->IsFixedOnSurface() )
5323 faceHlp.SetSubShape( pLink->_mediumNode->getshapeId() );
5324 if ( faceHlp.GetSubShape().ShapeType() == TopAbs_FACE )
5326 const_cast<SMDS_MeshNode*>( pLink->_mediumNode )->setXYZ( p.X(), p.Y(), p.Z());
5327 p.Coord( distXYZ[1], distXYZ[2], distXYZ[3] );
5328 gp_XY uv( Precision::Infinite(), 0 );
5329 if ( faceHlp.CheckNodeUV( TopoDS::Face( faceHlp.GetSubShape() ), pLink->_mediumNode,
5330 uv, /*tol=*/pLink->Move().Modulus(), /*force=*/true, distXYZ ))
5331 p.SetCoord( distXYZ[1], distXYZ[2], distXYZ[3] );
5334 GetMeshDS()->MoveNode( pLink->_mediumNode, p.X(), p.Y(), p.Z());
5336 // collect bi-quadratic elements
5337 if ( toFixCentralNodes )
5339 SMDS_ElemIteratorPtr eIt = pLink->_mediumNode->GetInverseElementIterator();
5340 while ( eIt->more() )
5342 const SMDS_MeshElement* e = eIt->next();
5343 switch( e->GetEntityType() ) {
5344 case SMDSEntity_BiQuad_Quadrangle: biQuadQuas.insert( e ); break;
5345 case SMDSEntity_BiQuad_Triangle: biQuadTris.insert( e ); break;
5346 case SMDSEntity_TriQuad_Hexa: triQuadHexa.insert( e ); break;
5347 case SMDSEntity_BiQuad_Penta: biQuadPenta.insert( e ); break;
5354 // Fix positions of central nodes of bi-tri-quadratic elements
5356 // treat bi-quad quadrangles
5358 vector< const SMDS_MeshNode* > nodes( 9 );
5360 TIDSortedElemSet::iterator quadIt = biQuadQuas.begin();
5361 for ( ; quadIt != biQuadQuas.end(); ++quadIt )
5363 const SMDS_MeshElement* quad = *quadIt;
5366 nodes.assign( quad->begin_nodes(), quad->end_nodes() );
5368 TopoDS_Shape S = GetSubShapeByNode( nodes.back(), GetMeshDS() );
5369 if ( S.IsNull() || S.ShapeType() != TopAbs_FACE ) continue;
5370 const TopoDS_Face& F = TopoDS::Face( S );
5371 Handle( Geom_Surface ) surf = BRep_Tool::Surface( F, loc );
5372 const double tol = BRep_Tool::Tolerance( F );
5374 for ( int i = 0; i < 8; ++i )
5376 uv[ i ] = GetNodeUV( F, nodes[i], nodes[8], &checkUV );
5377 // as this method is used after mesh generation, UV of nodes is not
5378 // updated according to bending links, so we update
5379 if ( i > 3 && nodes[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE )
5380 CheckNodeUV( F, nodes[i], uv[ i ], 2*tol, /*force=*/true );
5382 AdjustByPeriod( F, uv, 8 ); // put uv[] within a period (IPAL52698)
5383 // move the central node
5384 gp_XY uvCent = calcTFI (0.5, 0.5, uv[0],uv[1],uv[2],uv[3],uv[4],uv[5],uv[6],uv[7] );
5385 gp_Pnt p = surf->Value( uvCent.X(), uvCent.Y() ).Transformed( loc );
5386 GetMeshDS()->MoveNode( nodes[8], p.X(), p.Y(), p.Z());
5390 // treat bi-quad triangles
5392 vector< const SMDS_MeshNode* > nodes;
5394 TIDSortedElemSet::iterator triIt = biQuadTris.begin();
5395 for ( ; triIt != biQuadTris.end(); ++triIt )
5397 const SMDS_MeshElement* tria = *triIt;
5399 const TopoDS_Shape& S = GetMeshDS()->IndexToShape( tria->getshapeId() );
5400 if ( S.IsNull() || S.ShapeType() != TopAbs_FACE ) continue;
5401 const TopoDS_Face& F = TopoDS::Face( S );
5402 Handle( Geom_Surface ) surf = BRep_Tool::Surface( F, loc );
5403 const double tol = BRep_Tool::Tolerance( F );
5406 nodes.assign( tria->begin_nodes(), tria->end_nodes() );
5408 bool uvOK = true, badTria = false;
5409 for ( int i = 0; i < 6; ++i )
5411 uv[ i ] = GetNodeUV( F, nodes[i], nodes[(i+1)%3], &uvOK );
5412 // as this method is used after mesh generation, UV of nodes is not
5413 // updated according to bending links, so we update
5414 if ( nodes[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE )
5415 CheckNodeUV( F, nodes[i], uv[ i ], 2*tol, /*force=*/true );
5418 // move the central node
5420 if ( !uvOK || badTria )
5422 p = ( SMESH_TNodeXYZ( nodes[3] ) +
5423 SMESH_TNodeXYZ( nodes[4] ) +
5424 SMESH_TNodeXYZ( nodes[5] )) / 3;
5428 AdjustByPeriod( F, uv, 6 ); // put uv[] within a period (IPAL52698)
5429 gp_XY uvCent = GetCenterUV( uv[0], uv[1], uv[2], uv[3], uv[4], uv[5], &badTria );
5430 p = surf->Value( uvCent.X(), uvCent.Y() ).Transformed( loc );
5432 GetMeshDS()->MoveNode( tria->GetNode(6), p.X(), p.Y(), p.Z() );
5436 // treat tri-quadratic hexahedra
5438 SMDS_VolumeTool volExp;
5439 TIDSortedElemSet::iterator hexIt = triQuadHexa.begin();
5440 for ( ; hexIt != triQuadHexa.end(); ++hexIt )
5442 volExp.Set( *hexIt, /*ignoreCentralNodes=*/false );
5444 // fix nodes central in sides
5445 for ( int iQuad = 0; iQuad < volExp.NbFaces(); ++iQuad )
5447 const SMDS_MeshNode** quadNodes = volExp.GetFaceNodes( iQuad );
5448 if ( quadNodes[8]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE )
5450 gp_XYZ p = calcTFI( 0.5, 0.5,
5451 SMESH_TNodeXYZ( quadNodes[0] ), SMESH_TNodeXYZ( quadNodes[2] ),
5452 SMESH_TNodeXYZ( quadNodes[4] ), SMESH_TNodeXYZ( quadNodes[6] ),
5453 SMESH_TNodeXYZ( quadNodes[1] ), SMESH_TNodeXYZ( quadNodes[3] ),
5454 SMESH_TNodeXYZ( quadNodes[5] ), SMESH_TNodeXYZ( quadNodes[7] ));
5455 GetMeshDS()->MoveNode( quadNodes[8], p.X(), p.Y(), p.Z());
5459 // fix the volume central node
5460 vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
5461 const SMDS_MeshNode** hexNodes = volExp.GetNodes();
5463 pointsOnShapes[ SMESH_Block::ID_V000 ] = SMESH_TNodeXYZ( hexNodes[ 0 ] );
5464 pointsOnShapes[ SMESH_Block::ID_V100 ] = SMESH_TNodeXYZ( hexNodes[ 3 ] );
5465 pointsOnShapes[ SMESH_Block::ID_V010 ] = SMESH_TNodeXYZ( hexNodes[ 1 ] );
5466 pointsOnShapes[ SMESH_Block::ID_V110 ] = SMESH_TNodeXYZ( hexNodes[ 2 ] );
5467 pointsOnShapes[ SMESH_Block::ID_V001 ] = SMESH_TNodeXYZ( hexNodes[ 4 ] );
5468 pointsOnShapes[ SMESH_Block::ID_V101 ] = SMESH_TNodeXYZ( hexNodes[ 7 ] );
5469 pointsOnShapes[ SMESH_Block::ID_V011 ] = SMESH_TNodeXYZ( hexNodes[ 5 ] );
5470 pointsOnShapes[ SMESH_Block::ID_V111 ] = SMESH_TNodeXYZ( hexNodes[ 6 ] );
5472 pointsOnShapes[ SMESH_Block::ID_Ex00 ] = SMESH_TNodeXYZ( hexNodes[ 11 ] );
5473 pointsOnShapes[ SMESH_Block::ID_Ex10 ] = SMESH_TNodeXYZ( hexNodes[ 9 ] );
5474 pointsOnShapes[ SMESH_Block::ID_E0y0 ] = SMESH_TNodeXYZ( hexNodes[ 8 ] );
5475 pointsOnShapes[ SMESH_Block::ID_E1y0 ] = SMESH_TNodeXYZ( hexNodes[ 10 ] );
5476 pointsOnShapes[ SMESH_Block::ID_Ex01 ] = SMESH_TNodeXYZ( hexNodes[ 15 ] );
5477 pointsOnShapes[ SMESH_Block::ID_Ex11 ] = SMESH_TNodeXYZ( hexNodes[ 13 ] );
5478 pointsOnShapes[ SMESH_Block::ID_E0y1 ] = SMESH_TNodeXYZ( hexNodes[ 12 ] );
5479 pointsOnShapes[ SMESH_Block::ID_E1y1 ] = SMESH_TNodeXYZ( hexNodes[ 14 ] );
5480 pointsOnShapes[ SMESH_Block::ID_E00z ] = SMESH_TNodeXYZ( hexNodes[ 16 ] );
5481 pointsOnShapes[ SMESH_Block::ID_E10z ] = SMESH_TNodeXYZ( hexNodes[ 19 ] );
5482 pointsOnShapes[ SMESH_Block::ID_E01z ] = SMESH_TNodeXYZ( hexNodes[ 17 ] );
5483 pointsOnShapes[ SMESH_Block::ID_E11z ] = SMESH_TNodeXYZ( hexNodes[ 18 ] );
5485 pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = SMESH_TNodeXYZ( hexNodes[ 20 ] );
5486 pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = SMESH_TNodeXYZ( hexNodes[ 25 ] );
5487 pointsOnShapes[ SMESH_Block::ID_Fx0z ] = SMESH_TNodeXYZ( hexNodes[ 21 ] );
5488 pointsOnShapes[ SMESH_Block::ID_Fx1z ] = SMESH_TNodeXYZ( hexNodes[ 23 ] );
5489 pointsOnShapes[ SMESH_Block::ID_F0yz ] = SMESH_TNodeXYZ( hexNodes[ 24 ] );
5490 pointsOnShapes[ SMESH_Block::ID_F1yz ] = SMESH_TNodeXYZ( hexNodes[ 22 ] );
5492 gp_XYZ nCenterParams(0.5, 0.5, 0.5), nCenterCoords;
5493 SMESH_Block::ShellPoint( nCenterParams, pointsOnShapes, nCenterCoords );
5494 GetMeshDS()->MoveNode( hexNodes[26],
5495 nCenterCoords.X(), nCenterCoords.Y(), nCenterCoords.Z());
5498 // treat tri-quadratic hexahedra
5500 SMDS_VolumeTool volExp;
5501 TIDSortedElemSet::iterator pentIt = biQuadPenta.begin();
5502 for ( ; pentIt != biQuadPenta.end(); ++pentIt )
5505 volExp.Set( *pentIt, /*ignoreCentralNodes=*/false );
5509 // avoid warning: defined but not used operator<<()
5510 SMESH_Comment() << *links.begin() << *faces.begin();
5514 //================================================================================
5518 //================================================================================
5520 void SMESH_MesherHelper::WriteShape(const TopoDS_Shape& s)
5522 const char* name = "/tmp/shape.brep";
5523 BRepTools::Write( s, name );
5525 std::cout << name << std::endl;