1 // Copyright (C) 2007-2016 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_ProxyMesh.hxx"
40 #include "SMESH_subMesh.hxx"
42 #include <BRepAdaptor_Curve.hxx>
43 #include <BRepAdaptor_Surface.hxx>
44 #include <BRepTools.hxx>
45 #include <BRep_Tool.hxx>
46 #include <Geom2d_Curve.hxx>
47 #include <GeomAPI_ProjectPointOnCurve.hxx>
48 #include <GeomAPI_ProjectPointOnSurf.hxx>
49 #include <Geom_Curve.hxx>
50 #include <Geom_RectangularTrimmedSurface.hxx>
51 #include <Geom_Surface.hxx>
52 #include <ShapeAnalysis.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56 #include <TopTools_MapIteratorOfMapOfShape.hxx>
57 #include <TopTools_MapOfShape.hxx>
60 #include <gp_Pnt2d.hxx>
61 #include <gp_Trsf.hxx>
63 #include <Standard_Failure.hxx>
64 #include <Standard_ErrorHandler.hxx>
66 #include <utilities.h>
72 #define RETURN_BAD_RESULT(msg) { MESSAGE(msg); return false; }
76 inline SMESH_TNodeXYZ XYZ(const SMDS_MeshNode* n) { return SMESH_TNodeXYZ(n); }
78 enum { U_periodic = 1, V_periodic = 2 };
81 //================================================================================
85 //================================================================================
87 SMESH_MesherHelper::SMESH_MesherHelper(SMESH_Mesh& theMesh)
91 myCreateQuadratic(false),
92 myCreateBiQuadratic(false),
93 myFixNodeParameters(false)
95 myPar1[0] = myPar2[0] = myPar1[1] = myPar2[1] = 0;
96 mySetElemOnShape = ( ! myMesh->HasShapeToMesh() );
99 //=======================================================================
100 //function : ~SMESH_MesherHelper
102 //=======================================================================
104 SMESH_MesherHelper::~SMESH_MesherHelper()
107 TID2ProjectorOnSurf::iterator i_proj = myFace2Projector.begin();
108 for ( ; i_proj != myFace2Projector.end(); ++i_proj )
109 delete i_proj->second;
112 TID2ProjectorOnCurve::iterator i_proj = myEdge2Projector.begin();
113 for ( ; i_proj != myEdge2Projector.end(); ++i_proj )
114 delete i_proj->second;
118 //================================================================================
120 * \brief Return SMESH_Gen
122 //================================================================================
124 SMESH_Gen* SMESH_MesherHelper::GetGen() const
126 return GetMesh()->GetGen();
129 //================================================================================
131 * \brief Return mesh DS
133 //================================================================================
135 SMESHDS_Mesh* SMESH_MesherHelper::GetMeshDS() const
137 return GetMesh()->GetMeshDS();
140 //=======================================================================
141 //function : IsQuadraticSubMesh
142 //purpose : Check sub-meshes of a given shape: if all elements on sub-shapes
143 // are quadratic, quadratic elements will be created.
144 // Fill myTLinkNodeMap
145 //=======================================================================
147 bool SMESH_MesherHelper::IsQuadraticSubMesh(const TopoDS_Shape& aSh)
149 SMESHDS_Mesh* meshDS = GetMeshDS();
150 // we can create quadratic elements only if all elements
151 // created on sub-shapes of given shape are quadratic
152 myCreateQuadratic = true;
153 mySeamShapeIds.clear();
154 myDegenShapeIds.clear();
155 TopAbs_ShapeEnum subType( aSh.ShapeType()==TopAbs_FACE ? TopAbs_EDGE : TopAbs_FACE );
156 if ( aSh.ShapeType()==TopAbs_COMPOUND )
158 TopoDS_Iterator subIt( aSh );
160 subType = ( subIt.Value().ShapeType()==TopAbs_FACE ) ? TopAbs_EDGE : TopAbs_FACE;
162 SMDSAbs_ElementType elemType( subType==TopAbs_FACE ? SMDSAbs_Face : SMDSAbs_Edge );
164 if ( !myMesh->HasShapeToMesh() )
166 if (( myCreateQuadratic = myMesh->NbFaces( ORDER_QUADRATIC )))
168 SMDS_FaceIteratorPtr fIt = meshDS->facesIterator();
169 while ( fIt->more() )
170 AddTLinks( static_cast< const SMDS_MeshFace* >( fIt->next() ));
175 TopExp_Explorer exp( aSh, subType );
176 TopTools_MapOfShape checkedSubShapes;
177 for (; exp.More() && myCreateQuadratic; exp.Next()) {
178 if ( !checkedSubShapes.Add( exp.Current() ))
179 continue; // needed if aSh is compound of solids
180 if ( SMESHDS_SubMesh * subMesh = meshDS->MeshElements( exp.Current() )) {
181 if ( SMDS_ElemIteratorPtr it = subMesh->GetElements() ) {
183 const SMDS_MeshElement* e = it->next();
184 if ( e->GetType() != elemType || !e->IsQuadratic() ) {
185 myCreateQuadratic = false;
190 switch ( e->NbCornerNodes() ) {
192 AddTLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(2)); break;
194 AddTLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(3));
195 AddTLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(4));
196 AddTLinkNode(e->GetNode(2),e->GetNode(0),e->GetNode(5)); break;
198 AddTLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(4));
199 AddTLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(5));
200 AddTLinkNode(e->GetNode(2),e->GetNode(3),e->GetNode(6));
201 AddTLinkNode(e->GetNode(3),e->GetNode(0),e->GetNode(7));
204 myCreateQuadratic = false;
214 // if ( nbOldLinks == myTLinkNodeMap.size() ) -- 0023068
215 if ( myTLinkNodeMap.empty() )
216 myCreateQuadratic = false;
218 if ( !myCreateQuadratic )
219 myTLinkNodeMap.clear();
223 return myCreateQuadratic;
226 //=======================================================================
227 //function : SetSubShape
228 //purpose : Set geometry to make elements on
229 //=======================================================================
231 void SMESH_MesherHelper::SetSubShape(const int aShID)
233 if ( aShID == myShapeID )
236 SetSubShape( GetMeshDS()->IndexToShape( aShID ));
238 SetSubShape( TopoDS_Shape() );
241 //=======================================================================
242 //function : SetSubShape
243 //purpose : Set geometry to create elements on
244 //=======================================================================
246 void SMESH_MesherHelper::SetSubShape(const TopoDS_Shape& aSh)
248 if ( myShape.IsSame( aSh ))
252 mySeamShapeIds.clear();
253 myDegenShapeIds.clear();
255 if ( myShape.IsNull() ) {
259 SMESHDS_Mesh* meshDS = GetMeshDS();
260 myShapeID = meshDS->ShapeToIndex(aSh);
263 // treatment of periodic faces
264 for ( TopExp_Explorer eF( aSh, TopAbs_FACE ); eF.More(); eF.Next() )
266 const TopoDS_Face& face = TopoDS::Face( eF.Current() );
267 BRepAdaptor_Surface surf( face, false );
268 if ( surf.IsUPeriodic() || surf.IsUClosed() ) {
269 myParIndex |= U_periodic;
270 myPar1[0] = surf.FirstUParameter();
271 myPar2[0] = surf.LastUParameter();
273 if ( surf.IsVPeriodic() || surf.IsVClosed() ) {
274 myParIndex |= V_periodic;
275 myPar1[1] = surf.FirstVParameter();
276 myPar2[1] = surf.LastVParameter();
280 for (TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next())
282 // look for a "seam" edge, a real seam or an edge on period boundary
283 TopoDS_Edge edge = TopoDS::Edge( exp.Current() );
284 const int edgeID = meshDS->ShapeToIndex( edge );
287 BRep_Tool::UVPoints( edge, face, uv1, uv2 );
288 const double du = Abs( uv1.Coord(1) - uv2.Coord(1) );
289 const double dv = Abs( uv1.Coord(2) - uv2.Coord(2) );
291 bool isSeam = BRep_Tool::IsClosed( edge, face );
292 if ( isSeam ) // real seam - having two pcurves on face
294 // pcurve can lie not on pediod boundary (22582, mesh_Quadratic_01/C9)
297 double u1 = uv1.Coord(1);
299 BRep_Tool::UVPoints( edge, face, uv1, uv2 );
300 double u2 = uv1.Coord(1);
301 myPar1[0] = Min( u1, u2 );
302 myPar2[0] = Max( u1, u2 );
303 myParIndex |= U_periodic;
307 double v1 = uv1.Coord(2);
309 BRep_Tool::UVPoints( edge, face, uv1, uv2 );
310 double v2 = uv1.Coord(2);
311 myPar1[1] = Min( v1, v2 );
312 myPar2[1] = Max( v1, v2 );
313 myParIndex |= V_periodic;
316 else //if ( !isSeam )
318 // one pcurve but on period boundary (22772, mesh_Quadratic_01/D1)
319 if (( myParIndex & U_periodic ) && du < Precision::PConfusion() )
321 isSeam = ( Abs( uv1.Coord(1) - myPar1[0] ) < Precision::PConfusion() ||
322 Abs( uv1.Coord(1) - myPar2[0] ) < Precision::PConfusion() );
324 else if (( myParIndex & V_periodic ) && dv < Precision::PConfusion() )
326 isSeam = ( Abs( uv1.Coord(2) - myPar1[1] ) < Precision::PConfusion() ||
327 Abs( uv1.Coord(2) - myPar2[1] ) < Precision::PConfusion() );
329 if ( isSeam ) // vertices are on period boundary, check a middle point (23032)
331 double f,l, r = 0.2345;
332 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface( edge, face, f, l );
339 uv2 = C2d->Value( f * r + l * ( 1.-r ));
340 if ( du < Precision::PConfusion() )
341 isSeam = ( Abs( uv1.Coord(1) - uv2.Coord(1) ) < Precision::PConfusion() );
343 isSeam = ( Abs( uv1.Coord(2) - uv2.Coord(2) ) < Precision::PConfusion() );
349 // store seam shape indices, negative if shape encounters twice ('real seam')
350 mySeamShapeIds.insert( IsSeamShape( edgeID ) ? -edgeID : edgeID );
351 for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() ) {
352 int vertexID = meshDS->ShapeToIndex( v.Current() );
353 mySeamShapeIds.insert( IsSeamShape( vertexID ) ? -vertexID : vertexID );
357 // look for a degenerated edge
358 if ( SMESH_Algo::isDegenerated( edge )) {
359 myDegenShapeIds.insert( edgeID );
360 for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() )
361 myDegenShapeIds.insert( meshDS->ShapeToIndex( v.Current() ));
363 if ( !BRep_Tool::SameParameter( edge ) ||
364 !BRep_Tool::SameRange( edge ))
366 setPosOnShapeValidity( edgeID, false );
372 //=======================================================================
374 * \brief Copy shape information from another helper. Used to improve performance
375 * since SetSubShape() can be time consuming if there are many edges
377 //=======================================================================
379 void SMESH_MesherHelper::CopySubShapeInfo(const SMESH_MesherHelper& other)
381 this->myShape = other.myShape;
382 this->myShapeID = other.myShapeID;
383 this->myDegenShapeIds = other.myDegenShapeIds;
384 this->mySeamShapeIds = other.mySeamShapeIds;
385 this->myPar1[0] = other.myPar1[0];
386 this->myPar1[1] = other.myPar1[1];
387 this->myPar2[0] = other.myPar2[0];
388 this->myPar2[1] = other.myPar2[1];
389 this->myParIndex = other.myParIndex;
390 this->myFace2Surface = other.myFace2Surface;
393 //=======================================================================
394 //function : ShapeToIndex
395 //purpose : Convert a shape to its index in the SMESHDS_Mesh
396 //=======================================================================
398 int SMESH_MesherHelper::ShapeToIndex( const TopoDS_Shape& S ) const
400 return GetMeshDS()->ShapeToIndex( S );
403 //=======================================================================
404 //function : GetNodeUVneedInFaceNode
405 //purpose : Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
406 // Return true if the face is periodic.
407 // If F is Null, answer about sub-shape set through IsQuadraticSubMesh() or
409 //=======================================================================
411 bool SMESH_MesherHelper::GetNodeUVneedInFaceNode(const TopoDS_Face& F) const
413 if ( F.IsNull() ) return !mySeamShapeIds.empty();
415 if ( !F.IsNull() && !myShape.IsNull() && myShape.IsSame( F ))
416 return !mySeamShapeIds.empty();
419 Handle(Geom_Surface) aSurface = BRep_Tool::Surface( F,loc );
420 if ( !aSurface.IsNull() )
421 return ( aSurface->IsUPeriodic() || aSurface->IsVPeriodic() );
426 //=======================================================================
427 //function : IsMedium
429 //=======================================================================
431 bool SMESH_MesherHelper::IsMedium(const SMDS_MeshNode* node,
432 const SMDSAbs_ElementType typeToCheck)
434 return SMESH_MeshEditor::IsMedium( node, typeToCheck );
437 //=======================================================================
438 //function : GetSubShapeByNode
439 //purpose : Return support shape of a node
440 //=======================================================================
442 TopoDS_Shape SMESH_MesherHelper::GetSubShapeByNode(const SMDS_MeshNode* node,
443 const SMESHDS_Mesh* meshDS)
445 int shapeID = node ? node->getshapeId() : 0;
446 if ( 0 < shapeID && shapeID <= meshDS->MaxShapeIndex() )
447 return meshDS->IndexToShape( shapeID );
449 return TopoDS_Shape();
453 //=======================================================================
454 //function : AddTLinkNode
455 //purpose : add a link in my data structure
456 //=======================================================================
458 void SMESH_MesherHelper::AddTLinkNode(const SMDS_MeshNode* n1,
459 const SMDS_MeshNode* n2,
460 const SMDS_MeshNode* n12)
462 // add new record to map
463 SMESH_TLink link( n1, n2 );
464 myTLinkNodeMap.insert( make_pair(link,n12));
467 //================================================================================
469 * \brief Add quadratic links of edge to own data structure
471 //================================================================================
473 bool SMESH_MesherHelper::AddTLinks(const SMDS_MeshEdge* edge)
475 if ( edge && edge->IsQuadratic() )
476 AddTLinkNode(edge->GetNode(0), edge->GetNode(1), edge->GetNode(2));
482 //================================================================================
484 * \brief Add quadratic links of face to own data structure
486 //================================================================================
488 bool SMESH_MesherHelper::AddTLinks(const SMDS_MeshFace* f)
492 switch ( f->NbNodes() ) {
494 // myMapWithCentralNode.insert
495 // ( make_pair( TBiQuad( f->GetNode(0),f->GetNode(1),f->GetNode(2) ),
497 // break; -- add medium nodes as well
499 AddTLinkNode(f->GetNode(0),f->GetNode(1),f->GetNode(3));
500 AddTLinkNode(f->GetNode(1),f->GetNode(2),f->GetNode(4));
501 AddTLinkNode(f->GetNode(2),f->GetNode(0),f->GetNode(5)); break;
504 // myMapWithCentralNode.insert
505 // ( make_pair( TBiQuad( f->GetNode(0),f->GetNode(1),f->GetNode(2),f->GetNode(3) ),
507 // break; -- add medium nodes as well
509 AddTLinkNode(f->GetNode(0),f->GetNode(1),f->GetNode(4));
510 AddTLinkNode(f->GetNode(1),f->GetNode(2),f->GetNode(5));
511 AddTLinkNode(f->GetNode(2),f->GetNode(3),f->GetNode(6));
512 AddTLinkNode(f->GetNode(3),f->GetNode(0),f->GetNode(7)); break;
519 //================================================================================
521 * \brief Add quadratic links of volume to own data structure
523 //================================================================================
525 bool SMESH_MesherHelper::AddTLinks(const SMDS_MeshVolume* volume)
527 if ( volume->IsQuadratic() )
529 SMDS_VolumeTool vTool( volume );
530 const SMDS_MeshNode** nodes = vTool.GetNodes();
532 for ( int iF = 1; iF < vTool.NbFaces(); ++iF )
534 const int nbN = vTool.NbFaceNodes( iF );
535 const int* iNodes = vTool.GetFaceNodesIndices( iF );
536 for ( int i = 0; i < nbN; )
538 int iN1 = iNodes[i++];
539 int iN12 = iNodes[i++];
541 if ( iN1 > iN2 ) std::swap( iN1, iN2 );
542 int linkID = iN1 * vTool.NbNodes() + iN2;
543 pair< set<int>::iterator, bool > it_isNew = addedLinks.insert( linkID );
544 if ( it_isNew.second )
545 AddTLinkNode( nodes[iN1], nodes[iN2], nodes[iN12] );
547 addedLinks.erase( it_isNew.first ); // each link encounters only twice
549 if ( vTool.NbNodes() == 27 )
551 const SMDS_MeshNode* nFCenter = nodes[ vTool.GetCenterNodeIndex( iF )];
552 if ( nFCenter->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE )
553 myMapWithCentralNode.insert
554 ( make_pair( TBiQuad( nodes[ iNodes[0]], nodes[ iNodes[1]],
555 nodes[ iNodes[2]], nodes[ iNodes[3]] ),
564 //================================================================================
566 * \brief Return true if position of nodes on the shape hasn't yet been checked or
567 * the positions proved to be invalid
569 //================================================================================
571 bool SMESH_MesherHelper::toCheckPosOnShape(int shapeID ) const
573 map< int,bool >::const_iterator id_ok = myNodePosShapesValidity.find( shapeID );
574 return ( id_ok == myNodePosShapesValidity.end() || !id_ok->second );
577 //================================================================================
579 * \brief Set validity of positions of nodes on the shape.
580 * Once set, validity is not changed
582 //================================================================================
584 void SMESH_MesherHelper::setPosOnShapeValidity(int shapeID, bool ok ) const
586 std::map< int,bool >::iterator sh_ok =
587 ((SMESH_MesherHelper*)this)->myNodePosShapesValidity.insert( make_pair( shapeID, ok)).first;
592 //=======================================================================
593 //function : ToFixNodeParameters
594 //purpose : Enables fixing node parameters on EDGEs and FACEs in
595 // GetNodeU(...,check=true), GetNodeUV(...,check=true), CheckNodeUV() and
596 // CheckNodeU() in case if a node lies on a shape set via SetSubShape().
598 //=======================================================================
600 void SMESH_MesherHelper::ToFixNodeParameters(bool toFix)
602 myFixNodeParameters = toFix;
606 //=======================================================================
607 //function : getUVOnSeam
608 //purpose : Select UV on either of 2 pcurves of a seam edge, closest to the given UV
609 //=======================================================================
611 gp_Pnt2d SMESH_MesherHelper::getUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const
613 gp_Pnt2d result = uv1;
614 for ( int i = U_periodic; i <= V_periodic ; ++i )
616 if ( myParIndex & i )
618 double p1 = uv1.Coord( i );
619 double dp1 = Abs( p1-myPar1[i-1]), dp2 = Abs( p1-myPar2[i-1]);
620 if ( myParIndex == i ||
621 dp1 < ( myPar2[i-1] - myPar1[i-1] ) / 100. ||
622 dp2 < ( myPar2[i-1] - myPar1[i-1] ) / 100. )
624 double p2 = uv2.Coord( i );
625 double p1Alt = ( dp1 < dp2 ) ? myPar2[i-1] : myPar1[i-1];
626 if ( Abs( p2 - p1 ) > Abs( p2 - p1Alt ))
627 result.SetCoord( i, p1Alt );
634 //=======================================================================
635 //function : GetNodeUV
636 //purpose : Return node UV on face
637 //=======================================================================
639 gp_XY SMESH_MesherHelper::GetNodeUV(const TopoDS_Face& F,
640 const SMDS_MeshNode* n,
641 const SMDS_MeshNode* n2,
644 gp_Pnt2d uv( Precision::Infinite(), Precision::Infinite() );
646 SMDS_PositionPtr pos = n->GetPosition();
648 if ( pos->GetTypeOfPosition() == SMDS_TOP_FACE )
650 // node has position on face
651 SMDS_FacePositionPtr fpos = pos;
652 uv.SetCoord( fpos->GetUParameter(), fpos->GetVParameter() );
654 uvOK = CheckNodeUV( F, n, uv.ChangeCoord(), 2.*getFaceMaxTol( F )); // 2. from 22830
656 else if ( pos->GetTypeOfPosition() == SMDS_TOP_EDGE )
658 // node has position on EDGE => it is needed to find
659 // corresponding EDGE from FACE, get pcurve for this
660 // EDGE and retrieve value from this pcurve
661 SMDS_EdgePositionPtr epos = pos;
662 const int edgeID = n->getshapeId();
663 const TopoDS_Edge& E = TopoDS::Edge( GetMeshDS()->IndexToShape( edgeID ));
664 double f, l, u = epos->GetUParameter();
665 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface( E, F, f, l );
666 bool validU = ( !C2d.IsNull() && ( f < u ) && ( u < l ));
667 if ( validU ) uv = C2d->Value( u );
668 else uv.SetCoord( Precision::Infinite(),0.);
669 if ( check || !validU )
670 uvOK = CheckNodeUV( F, n, uv.ChangeCoord(), 2.*getFaceMaxTol( F ),/*force=*/ !validU );
672 // for a node on a seam EDGE select one of UVs on 2 pcurves
673 if ( n2 && IsSeamShape( edgeID ))
675 uv = getUVOnSeam( uv, GetNodeUV( F, n2, 0, check ));
678 { // adjust uv to period
680 Handle(Geom_Surface) S = BRep_Tool::Surface(F,loc);
681 Standard_Boolean isUPeriodic = S->IsUPeriodic();
682 Standard_Boolean isVPeriodic = S->IsVPeriodic();
684 if ( isUPeriodic || isVPeriodic ) {
685 Standard_Real UF,UL,VF,VL;
686 S->Bounds(UF,UL,VF,VL);
687 if ( isUPeriodic ) newUV.SetX( uv.X() + ShapeAnalysis::AdjustToPeriod(uv.X(),UF,UL));
688 if ( isVPeriodic ) newUV.SetY( uv.Y() + ShapeAnalysis::AdjustToPeriod(uv.Y(),VF,VL));
692 gp_Pnt2d uv2 = GetNodeUV( F, n2, 0, check );
693 if ( isUPeriodic && Abs( uv.X()-uv2.X() ) < Abs( newUV.X()-uv2.X() ))
694 newUV.SetX( uv.X() );
695 if ( isVPeriodic && Abs( uv.Y()-uv2.Y() ) < Abs( newUV.Y()-uv2.Y() ))
696 newUV.SetY( uv.Y() );
702 else if ( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX )
704 if ( int vertexID = n->getshapeId() ) {
705 const TopoDS_Vertex& V = TopoDS::Vertex(GetMeshDS()->IndexToShape(vertexID));
707 uv = BRep_Tool::Parameters( V, F );
710 catch (Standard_Failure& exc) {
714 if ( !IsSubShape( V, F ))
716 MESSAGE("GetNodeUV() Vertex "<< vertexID <<" not in face "<< GetMeshDS()->ShapeToIndex(F));
717 // get UV of a vertex closest to the node
719 gp_Pnt pn = XYZ( n );
720 for ( TopExp_Explorer vert( F,TopAbs_VERTEX ); !uvOK && vert.More(); vert.Next() ) {
721 TopoDS_Vertex curV = TopoDS::Vertex( vert.Current() );
722 gp_Pnt p = BRep_Tool::Pnt( curV );
723 double curDist = p.SquareDistance( pn );
724 if ( curDist < dist ) {
726 uv = BRep_Tool::Parameters( curV, F );
727 uvOK = ( dist < DBL_MIN );
734 TopTools_ListIteratorOfListOfShape it( myMesh->GetAncestors( V ));
735 for ( ; it.More(); it.Next() ) {
736 if ( it.Value().ShapeType() == TopAbs_EDGE ) {
737 const TopoDS_Edge & edge = TopoDS::Edge( it.Value() );
739 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(edge, F, f, l);
740 if ( !C2d.IsNull() ) {
741 double u = ( V == IthVertex( 0, edge )) ? f : l;
742 uv = C2d->Value( u );
748 if ( !uvOK && V.Orientation() == TopAbs_INTERNAL )
750 Handle(ShapeAnalysis_Surface) projector = GetSurface( F );
751 if ( n2 ) uv = GetNodeUV( F, n2 );
752 if ( Precision::IsInfinite( uv.X() ))
753 uv = projector->NextValueOfUV( uv, BRep_Tool::Pnt( V ), BRep_Tool::Tolerance( F ));
755 uv = projector->ValueOfUV( BRep_Tool::Pnt( V ), BRep_Tool::Tolerance( F ));
756 uvOK = ( projector->Gap() < getFaceMaxTol( F ));
760 if ( n2 && IsSeamShape( vertexID ))
762 bool isSeam = ( myShape.IsSame( F ));
764 SMESH_MesherHelper h( *myMesh );
766 isSeam = IsSeamShape( vertexID );
770 uv = getUVOnSeam( uv, GetNodeUV( F, n2, 0 ));
776 uvOK = CheckNodeUV( F, n, uv.ChangeCoord(), 2.*getFaceMaxTol( F ));
779 if ( check && !uvOK )
785 //=======================================================================
786 //function : CheckNodeUV
787 //purpose : Check and fix node UV on a face
788 //=======================================================================
790 bool SMESH_MesherHelper::CheckNodeUV(const TopoDS_Face& F,
791 const SMDS_MeshNode* n,
795 double distXYZ[4]) const
797 int shapeID = n->getshapeId();
799 if (( infinit = ( Precision::IsInfinite( uv.X() ) || Precision::IsInfinite( uv.Y() ))) ||
801 ( uv.X() == 0. && uv.Y() == 0. ) ||
802 ( toCheckPosOnShape( shapeID )))
804 // check that uv is correct
806 Handle(Geom_Surface) surface = BRep_Tool::Surface( F,loc );
807 gp_Pnt nodePnt = XYZ( n ), surfPnt(0,0,0);
809 if ( !loc.IsIdentity() ) nodePnt.Transform( loc.Transformation().Inverted() );
811 (dist = nodePnt.Distance( surfPnt = surface->Value( uv.X(), uv.Y() ))) > tol )
813 setPosOnShapeValidity( shapeID, false );
814 if ( !infinit && distXYZ ) {
815 surfPnt.Transform( loc );
817 distXYZ[1] = surfPnt.X(); distXYZ[2] = surfPnt.Y(); distXYZ[3]=surfPnt.Z();
819 // uv incorrect, project the node to surface
820 GeomAPI_ProjectPointOnSurf& projector = GetProjector( F, loc, tol );
821 projector.SetExtremaFlag( Extrema_ExtFlag_MIN );
822 projector.Perform( nodePnt );
823 if ( !projector.IsDone() || projector.NbPoints() < 1 )
825 MESSAGE( "SMESH_MesherHelper::CheckNodeUV() failed to project" );
829 projector.LowerDistanceParameters(U,V);
831 surfPnt = surface->Value( U, V );
832 dist = nodePnt.Distance( surfPnt );
834 surfPnt.Transform( loc );
836 distXYZ[1] = surfPnt.X(); distXYZ[2] = surfPnt.Y(); distXYZ[3]=surfPnt.Z();
840 Handle(ShapeAnalysis_Surface) sprojector = GetSurface( F );
841 uv = sprojector->ValueOfUV( nodePnt, tol ).XY();
842 surfPnt = sprojector->Value( uv );
843 dist = nodePnt.Distance( surfPnt );
845 surfPnt.Transform( loc );
847 distXYZ[1] = surfPnt.X(); distXYZ[2] = surfPnt.Y(); distXYZ[3]=surfPnt.Z();
851 MESSAGE( "SMESH_MesherHelper::CheckNodeUV(), invalid projection" );
855 // store the fixed UV on the face
856 if ( myShape.IsSame(F) && shapeID == myShapeID && myFixNodeParameters )
857 const_cast<SMDS_MeshNode*>(n)->SetPosition
858 ( SMDS_PositionPtr( new SMDS_FacePosition( U, V )));
860 else if ( myShape.IsSame(F) && uv.Modulus() > numeric_limits<double>::min() )
862 setPosOnShapeValidity( shapeID, true );
868 //=======================================================================
869 //function : GetProjector
870 //purpose : Return projector initialized by given face without location, which is returned
871 //=======================================================================
873 GeomAPI_ProjectPointOnSurf& SMESH_MesherHelper::GetProjector(const TopoDS_Face& F,
874 TopLoc_Location& loc,
877 Handle(Geom_Surface) surface = BRep_Tool::Surface( F,loc );
878 int faceID = GetMeshDS()->ShapeToIndex( F );
879 TID2ProjectorOnSurf& i2proj = const_cast< TID2ProjectorOnSurf&>( myFace2Projector );
880 TID2ProjectorOnSurf::iterator i_proj = i2proj.find( faceID );
881 if ( i_proj == i2proj.end() )
883 if ( tol == 0 ) tol = BRep_Tool::Tolerance( F );
884 double U1, U2, V1, V2;
885 surface->Bounds(U1, U2, V1, V2);
886 GeomAPI_ProjectPointOnSurf* proj = new GeomAPI_ProjectPointOnSurf();
887 proj->Init( surface, U1, U2, V1, V2, tol );
888 i_proj = i2proj.insert( make_pair( faceID, proj )).first;
890 return *( i_proj->second );
893 //=======================================================================
894 //function : GetSurface
895 //purpose : Return a cached ShapeAnalysis_Surface of a FACE
896 //=======================================================================
898 Handle(ShapeAnalysis_Surface) SMESH_MesherHelper::GetSurface(const TopoDS_Face& F ) const
900 Handle(Geom_Surface) surface = BRep_Tool::Surface( F );
901 int faceID = GetMeshDS()->ShapeToIndex( F );
902 TID2Surface::iterator i_surf = myFace2Surface.find( faceID );
903 if ( i_surf == myFace2Surface.end() && faceID )
905 Handle(ShapeAnalysis_Surface) surf( new ShapeAnalysis_Surface( surface ));
906 i_surf = myFace2Surface.insert( make_pair( faceID, surf )).first;
908 return i_surf->second;
913 gp_XY AverageUV(const gp_XY& uv1, const gp_XY& uv2) { return ( uv1 + uv2 ) / 2.; }
914 gp_XY_FunPtr(Added); // define gp_XY_Added pointer to function calling gp_XY::Added(gp_XY)
915 gp_XY_FunPtr(Subtracted);
918 //=======================================================================
919 //function : ApplyIn2D
920 //purpose : Perform given operation on two 2d points in parameric space of given surface.
921 // It takes into account period of the surface. Use gp_XY_FunPtr macro
922 // to easily define pointer to function of gp_XY class.
923 //=======================================================================
925 gp_XY SMESH_MesherHelper::ApplyIn2D(Handle(Geom_Surface) surface,
929 const bool resultInPeriod)
931 if ( surface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface )))
932 surface = Handle(Geom_RectangularTrimmedSurface)::DownCast( surface )->BasisSurface();
933 Standard_Boolean isUPeriodic = surface.IsNull() ? false : surface->IsUPeriodic();
934 Standard_Boolean isVPeriodic = surface.IsNull() ? false : surface->IsVPeriodic();
935 if ( !isUPeriodic && !isVPeriodic )
938 // move uv2 not far than half-period from uv1
940 uv2.X()+(isUPeriodic ? ShapeAnalysis::AdjustByPeriod(uv2.X(),uv1.X(),surface->UPeriod()) :0);
942 uv2.Y()+(isVPeriodic ? ShapeAnalysis::AdjustByPeriod(uv2.Y(),uv1.Y(),surface->VPeriod()) :0);
945 gp_XY res = fun( uv1, gp_XY(u2,v2) );
947 // move result within period
948 if ( resultInPeriod )
950 Standard_Real UF,UL,VF,VL;
951 surface->Bounds(UF,UL,VF,VL);
953 res.SetX( res.X() + ShapeAnalysis::AdjustToPeriod(res.X(),UF,UL));
955 res.SetY( res.Y() + ShapeAnalysis::AdjustToPeriod(res.Y(),VF,VL));
961 //=======================================================================
962 //function : AdjustByPeriod
963 //purpose : Move node positions on a FACE within surface period
964 //=======================================================================
966 void SMESH_MesherHelper::AdjustByPeriod( const TopoDS_Face& face, gp_XY uv[], const int nbUV )
968 SMESH_MesherHelper h( *myMesh ), *ph = face.IsSame( myShape ) ? this : &h;
969 ph->SetSubShape( face );
971 for ( int iCoo = U_periodic; iCoo <= V_periodic; ++iCoo )
972 if ( ph->GetPeriodicIndex() & iCoo )
974 const double period = ( ph->myPar2[iCoo-1] - ph->myPar1[iCoo-1] );
975 const double xRef = uv[0].Coord( iCoo );
976 for ( int i = 1; i < nbUV; ++i )
978 double x = uv[i].Coord( iCoo );
979 double dx = ShapeAnalysis::AdjustByPeriod( x, xRef, period );
980 uv[i].SetCoord( iCoo, x + dx );
985 //=======================================================================
986 //function : GetMiddleUV
987 //purpose : Return middle UV taking in account surface period
988 //=======================================================================
990 gp_XY SMESH_MesherHelper::GetMiddleUV(const Handle(Geom_Surface)& surface,
995 // the proper place of getting basic surface seems to be in ApplyIn2D()
996 // but we put it here to decrease a risk of regressions just before releasing a version
997 // Handle(Geom_Surface) surf = surface;
998 // while ( !surf.IsNull() && surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface )))
999 // surf = Handle(Geom_RectangularTrimmedSurface)::DownCast( surf )->BasisSurface();
1001 return ApplyIn2D( surface, p1, p2, & AverageUV );
1004 //=======================================================================
1005 //function : GetCenterUV
1006 //purpose : Return UV for the central node of a biquadratic triangle
1007 //=======================================================================
1009 gp_XY SMESH_MesherHelper::GetCenterUV(const gp_XY& uv1,
1015 bool * isBadTria/*=0*/)
1018 gp_XY uvAvg = ( uv12 + uv23 + uv31 ) / 3.;
1020 if (( badTria = (( uvAvg - uv1 ) * ( uvAvg - uv23 ) > 0 )))
1021 uvAvg = ( uv1 + uv23 ) / 2.;
1022 else if (( badTria = (( uvAvg - uv2 ) * ( uvAvg - uv31 ) > 0 )))
1023 uvAvg = ( uv2 + uv31 ) / 2.;
1024 else if (( badTria = (( uvAvg - uv3 ) * ( uvAvg - uv12 ) > 0 )))
1025 uvAvg = ( uv3 + uv12 ) / 2.;
1028 *isBadTria = badTria;
1032 //=======================================================================
1033 //function : GetNodeU
1034 //purpose : Return node U on edge
1035 //=======================================================================
1037 double SMESH_MesherHelper::GetNodeU(const TopoDS_Edge& E,
1038 const SMDS_MeshNode* n,
1039 const SMDS_MeshNode* inEdgeNode,
1042 double param = Precision::Infinite();
1044 const SMDS_PositionPtr pos = n->GetPosition();
1045 if ( pos->GetTypeOfPosition()==SMDS_TOP_EDGE )
1047 param = pos->GetParameters()[0];
1049 else if( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX )
1051 if ( inEdgeNode && TopExp::FirstVertex( E ).IsSame( TopExp::LastVertex( E ))) // issue 0020128
1054 BRep_Tool::Range( E, f,l );
1055 double uInEdge = GetNodeU( E, inEdgeNode );
1056 param = ( fabs( uInEdge - f ) < fabs( l - uInEdge )) ? f : l;
1060 SMESHDS_Mesh * meshDS = GetMeshDS();
1061 int vertexID = n->getshapeId();
1062 const TopoDS_Vertex& V = TopoDS::Vertex(meshDS->IndexToShape(vertexID));
1063 param = BRep_Tool::Parameter( V, E );
1068 double tol = BRep_Tool::Tolerance( E );
1069 double f,l; BRep_Tool::Range( E, f,l );
1070 bool force = ( param < f-tol || param > l+tol );
1071 if ( !force && pos->GetTypeOfPosition()==SMDS_TOP_EDGE )
1072 force = ( GetMeshDS()->ShapeToIndex( E ) != n->getshapeId() );
1074 *check = CheckNodeU( E, n, param, 2*tol, force );
1079 //=======================================================================
1080 //function : CheckNodeU
1081 //purpose : Check and fix node U on an edge
1082 // Return false if U is bad and could not be fixed
1083 //=======================================================================
1085 bool SMESH_MesherHelper::CheckNodeU(const TopoDS_Edge& E,
1086 const SMDS_MeshNode* n,
1090 double distXYZ[4]) const
1092 int shapeID = n->getshapeId();
1094 if (( infinit = Precision::IsInfinite( u )) ||
1097 ( toCheckPosOnShape( shapeID )))
1099 TopLoc_Location loc; double f,l;
1100 Handle(Geom_Curve) curve = BRep_Tool::Curve( E,loc,f,l );
1101 if ( curve.IsNull() ) // degenerated edge
1103 if ( u+tol < f || u-tol > l )
1105 double r = Max( 0.5, 1 - tol*n->GetID()); // to get a unique u on edge
1111 gp_Pnt nodePnt = SMESH_TNodeXYZ( n );
1112 if ( !loc.IsIdentity() ) nodePnt.Transform( loc.Transformation().Inverted() );
1114 double dist = 2*tol;
1117 curvPnt = curve->Value( u );
1118 dist = nodePnt.Distance( curvPnt );
1120 curvPnt.Transform( loc );
1122 distXYZ[1] = curvPnt.X(); distXYZ[2] = curvPnt.Y(); distXYZ[3]=curvPnt.Z();
1127 setPosOnShapeValidity( shapeID, false );
1128 // u incorrect, project the node to the curve
1129 int edgeID = GetMeshDS()->ShapeToIndex( E );
1130 TID2ProjectorOnCurve& i2proj = const_cast< TID2ProjectorOnCurve&>( myEdge2Projector );
1131 TID2ProjectorOnCurve::iterator i_proj =
1132 i2proj.insert( make_pair( edgeID, (GeomAPI_ProjectPointOnCurve*) 0 )).first;
1133 if ( !i_proj->second )
1135 i_proj->second = new GeomAPI_ProjectPointOnCurve();
1136 i_proj->second->Init( curve, f, l );
1138 GeomAPI_ProjectPointOnCurve* projector = i_proj->second;
1139 projector->Perform( nodePnt );
1140 if ( projector->NbPoints() < 1 )
1142 MESSAGE( "SMESH_MesherHelper::CheckNodeU() failed to project" );
1145 Standard_Real U = projector->LowerDistanceParameter();
1147 curvPnt = curve->Value( u );
1148 dist = nodePnt.Distance( curvPnt );
1150 curvPnt.Transform( loc );
1152 distXYZ[1] = curvPnt.X(); distXYZ[2] = curvPnt.Y(); distXYZ[3]=curvPnt.Z();
1156 MESSAGE( "CheckNodeU(), invalid projection; distance " << dist << "; tol " << tol );
1159 // store the fixed U on the edge
1160 if ( myShape.IsSame(E) && shapeID == myShapeID && myFixNodeParameters )
1161 const_cast<SMDS_MeshNode*>(n)->SetPosition
1162 ( SMDS_PositionPtr( new SMDS_EdgePosition( U )));
1164 else if ( fabs( u ) > numeric_limits<double>::min() )
1166 setPosOnShapeValidity( shapeID, true );
1168 if (( u < f-tol || u > l+tol ) && force )
1170 MESSAGE("u < f-tol || u > l+tol ; u " << u << " f " << f << " l " << l);
1171 // node is on vertex but is set on periodic but trimmed edge (issue 0020890)
1174 // do not use IsPeriodic() as Geom_TrimmedCurve::IsPeriodic () returns false
1175 double period = curve->Period();
1176 u = ( u < f ) ? u + period : u - period;
1178 catch (Standard_Failure& exc)
1188 //=======================================================================
1189 //function : GetMediumPos
1190 //purpose : Return index and type of the shape (EDGE or FACE only) to
1191 // set a medium node on
1192 //param : useCurSubShape - if true, returns the shape set via SetSubShape()
1194 //param : expectedSupport - shape type corresponding to element being created,
1195 // e.g TopAbs_EDGE if SMDSAbs_Edge is created
1196 // basing on \a n1 and \a n2
1197 // Calling GetMediumPos() with useCurSubShape=true is OK only for the
1198 // case where the lower dim mesh is already constructed and converted to quadratic,
1199 // else, nodes on EDGEs are assigned to FACE, for example.
1200 //=======================================================================
1202 std::pair<int, TopAbs_ShapeEnum>
1203 SMESH_MesherHelper::GetMediumPos(const SMDS_MeshNode* n1,
1204 const SMDS_MeshNode* n2,
1205 const bool useCurSubShape,
1206 TopAbs_ShapeEnum expectedSupport)
1208 if ( useCurSubShape && !myShape.IsNull() )
1209 return std::make_pair( myShapeID, myShape.ShapeType() );
1211 TopAbs_ShapeEnum shapeType = TopAbs_SHAPE;
1215 if (( myShapeID == n1->getshapeId() || myShapeID == n2->getshapeId() ) && myShapeID > 0 )
1217 shapeType = myShape.ShapeType();
1218 shapeID = myShapeID;
1220 else if ( n1->getshapeId() == n2->getshapeId() )
1222 shapeID = n2->getshapeId();
1223 shape = GetSubShapeByNode( n1, GetMeshDS() );
1225 else // 2 different shapes
1227 const SMDS_TypeOfPosition Pos1 = n1->GetPosition()->GetTypeOfPosition();
1228 const SMDS_TypeOfPosition Pos2 = n2->GetPosition()->GetTypeOfPosition();
1230 if ( Pos1 == SMDS_TOP_3DSPACE || Pos2 == SMDS_TOP_3DSPACE )
1234 else if ( Pos1 == SMDS_TOP_FACE || Pos2 == SMDS_TOP_FACE )
1237 if ( Pos1 != SMDS_TOP_FACE || Pos2 != SMDS_TOP_FACE ) // not 2 FACEs
1239 if ( Pos1 != SMDS_TOP_FACE ) std::swap( n1,n2 );
1240 TopoDS_Shape F = GetSubShapeByNode( n1, GetMeshDS() );
1241 TopoDS_Shape S = GetSubShapeByNode( n2, GetMeshDS() );
1242 if ( IsSubShape( S, F ))
1244 shapeType = TopAbs_FACE;
1245 shapeID = n1->getshapeId();
1249 else if ( Pos1 == SMDS_TOP_EDGE && Pos2 == SMDS_TOP_EDGE )
1251 TopoDS_Shape E1 = GetSubShapeByNode( n1, GetMeshDS() );
1252 TopoDS_Shape E2 = GetSubShapeByNode( n2, GetMeshDS() );
1253 shape = GetCommonAncestor( E1, E2, *myMesh, TopAbs_FACE );
1255 else if ( Pos1 == SMDS_TOP_VERTEX && Pos2 == SMDS_TOP_VERTEX )
1257 TopoDS_Shape V1 = GetSubShapeByNode( n1, GetMeshDS() );
1258 TopoDS_Shape V2 = GetSubShapeByNode( n2, GetMeshDS() );
1259 shape = GetCommonAncestor( V1, V2, *myMesh, TopAbs_EDGE );
1260 if ( shape.IsNull() ) shape = GetCommonAncestor( V1, V2, *myMesh, TopAbs_FACE );
1262 else // on VERTEX and EDGE
1264 if ( Pos1 != SMDS_TOP_VERTEX ) std::swap( n1,n2 );
1265 TopoDS_Shape V = GetSubShapeByNode( n1, GetMeshDS() );
1266 TopoDS_Shape E = GetSubShapeByNode( n2, GetMeshDS() );
1267 if ( IsSubShape( V, E ))
1270 shape = GetCommonAncestor( V, E, *myMesh, TopAbs_FACE );
1274 if ( !shape.IsNull() )
1277 shapeID = GetMeshDS()->ShapeToIndex( shape );
1278 shapeType = shape.ShapeType(); // EDGE or FACE
1280 if ( expectedSupport < shapeType &&
1281 expectedSupport != TopAbs_SHAPE &&
1282 !myShape.IsNull() &&
1283 myShape.ShapeType() == expectedSupport )
1285 // e.g. a side of triangle connects nodes on the same EDGE but does not
1286 // lie on this EDGE (an arc with a coarse mesh)
1287 // => shapeType == TopAbs_EDGE, expectedSupport == TopAbs_FACE;
1288 // hope that myShape is a right shape, return it if the found shape
1289 // has converted elements of corresponding dim (segments in our example)
1290 int nbConvertedElems = 0;
1291 SMDSAbs_ElementType type = ( shapeType == TopAbs_FACE ? SMDSAbs_Face : SMDSAbs_Edge );
1292 for ( int iN = 0; iN < 2; ++iN )
1294 const SMDS_MeshNode* n = iN ? n2 : n1;
1295 SMDS_ElemIteratorPtr it = n->GetInverseElementIterator( type );
1296 while ( it->more() )
1298 const SMDS_MeshElement* elem = it->next();
1299 if ( elem->getshapeId() == shapeID &&
1300 elem->IsQuadratic() )
1307 if ( nbConvertedElems == 2 )
1309 shapeType = myShape.ShapeType();
1310 shapeID = myShapeID;
1314 return make_pair( shapeID, shapeType );
1317 //=======================================================================
1318 //function : GetCentralNode
1319 //purpose : Return existing or create a new central node for a quardilateral
1320 // quadratic face given its 8 nodes.
1321 //@param : force3d - true means node creation in between the given nodes,
1322 // else node position is found on a geometrical face if any.
1323 //=======================================================================
1325 const SMDS_MeshNode* SMESH_MesherHelper::GetCentralNode(const SMDS_MeshNode* n1,
1326 const SMDS_MeshNode* n2,
1327 const SMDS_MeshNode* n3,
1328 const SMDS_MeshNode* n4,
1329 const SMDS_MeshNode* n12,
1330 const SMDS_MeshNode* n23,
1331 const SMDS_MeshNode* n34,
1332 const SMDS_MeshNode* n41,
1335 SMDS_MeshNode *centralNode = 0; // central node to return
1337 // Find an existing central node
1339 TBiQuad keyOfMap(n1,n2,n3,n4);
1340 std::map<TBiQuad, const SMDS_MeshNode* >::iterator itMapCentralNode;
1341 itMapCentralNode = myMapWithCentralNode.find( keyOfMap );
1342 if ( itMapCentralNode != myMapWithCentralNode.end() )
1344 return (*itMapCentralNode).second;
1347 // Get type of shape for the new central node
1349 TopAbs_ShapeEnum shapeType = TopAbs_SHAPE;
1353 TopTools_ListIteratorOfListOfShape it;
1355 std::map< int, int > faceId2nbNodes;
1356 std::map< int, int > ::iterator itMapWithIdFace;
1358 SMESHDS_Mesh* meshDS = GetMeshDS();
1360 // check if a face lies on a FACE, i.e. its all corner nodes lie either on the FACE or
1361 // on sub-shapes of the FACE
1362 if ( GetMesh()->HasShapeToMesh() )
1364 const SMDS_MeshNode* nodes[] = { n1, n2, n3, n4 };
1365 for(int i = 0; i < 4; i++)
1367 shape = GetSubShapeByNode( nodes[i], meshDS );
1368 if ( shape.IsNull() ) break;
1369 if ( shape.ShapeType() == TopAbs_SOLID )
1371 solidID = nodes[i]->getshapeId();
1372 shapeType = TopAbs_SOLID;
1375 if ( shape.ShapeType() == TopAbs_FACE )
1377 faceID = nodes[i]->getshapeId();
1378 itMapWithIdFace = faceId2nbNodes.insert( std::make_pair( faceID, 0 ) ).first;
1379 itMapWithIdFace->second++;
1383 PShapeIteratorPtr it = GetAncestors( shape, *GetMesh(), TopAbs_FACE );
1384 while ( const TopoDS_Shape* face = it->next() )
1386 faceID = meshDS->ShapeToIndex( *face );
1387 itMapWithIdFace = faceId2nbNodes.insert( std::make_pair( faceID, 0 )).first;
1388 itMapWithIdFace->second++;
1393 if ( solidID < 1 && !faceId2nbNodes.empty() ) // SOLID not found
1395 // find ID of the FACE the four corner nodes belong to
1396 itMapWithIdFace = faceId2nbNodes.find( myShapeID ); // IPAL52698
1397 if ( itMapWithIdFace != faceId2nbNodes.end() &&
1398 itMapWithIdFace->second == 4 )
1400 shapeType = TopAbs_FACE;
1405 itMapWithIdFace = faceId2nbNodes.begin();
1406 for ( ; itMapWithIdFace != faceId2nbNodes.end(); ++itMapWithIdFace)
1408 if ( itMapWithIdFace->second == 4 )
1410 shapeType = TopAbs_FACE;
1411 faceID = (*itMapWithIdFace).first;
1419 if ( shapeType == TopAbs_FACE )
1421 F = TopoDS::Face( meshDS->IndexToShape( faceID ));
1428 bool toCheck = true;
1429 if ( !F.IsNull() && !force3d )
1431 Handle(ShapeAnalysis_Surface) surface = GetSurface( F );
1432 if ( HasDegeneratedEdges() || surface->HasSingularities( 1e-7 ))
1434 gp_Pnt center = calcTFI (0.5, 0.5, // IPAL0052863
1435 SMESH_TNodeXYZ(n1), SMESH_TNodeXYZ(n2),
1436 SMESH_TNodeXYZ(n3), SMESH_TNodeXYZ(n4),
1437 SMESH_TNodeXYZ(n12), SMESH_TNodeXYZ(n23),
1438 SMESH_TNodeXYZ(n34), SMESH_TNodeXYZ(n41));
1439 gp_Pnt2d uv12 = GetNodeUV( F, n12, n3, &toCheck );
1440 uvAvg = surface->NextValueOfUV( uv12, center, BRep_Tool::Tolerance( F )).XY();
1445 GetNodeUV( F,n1, n3, &toCheck ),
1446 GetNodeUV( F,n2, n4, &toCheck ),
1447 GetNodeUV( F,n3, n1, &toCheck ),
1448 GetNodeUV( F,n4, n2, &toCheck ),
1449 GetNodeUV( F,n12, n3 ),
1450 GetNodeUV( F,n23, n4 ),
1451 GetNodeUV( F,n34, n2 ),
1452 GetNodeUV( F,n41, n2 )
1454 AdjustByPeriod( F, uv, 8 ); // put uv[] within a period (IPAL52698)
1456 uvAvg = calcTFI (0.5, 0.5, uv[0],uv[1],uv[2],uv[3], uv[4],uv[5],uv[6],uv[7] );
1458 P = surface->Value( uvAvg );
1459 centralNode = meshDS->AddNode( P.X(), P.Y(), P.Z() );
1460 // if ( mySetElemOnShape ) node is not elem!
1461 meshDS->SetNodeOnFace( centralNode, faceID, uvAvg.X(), uvAvg.Y() );
1463 else // ( force3d || F.IsNull() )
1465 P = calcTFI (0.5, 0.5,
1466 SMESH_TNodeXYZ(n1), SMESH_TNodeXYZ(n2),
1467 SMESH_TNodeXYZ(n3), SMESH_TNodeXYZ(n4),
1468 SMESH_TNodeXYZ(n12), SMESH_TNodeXYZ(n23),
1469 SMESH_TNodeXYZ(n34), SMESH_TNodeXYZ(n41));
1470 centralNode = meshDS->AddNode( P.X(), P.Y(), P.Z() );
1472 if ( !F.IsNull() ) // force3d
1474 uvAvg = (GetNodeUV(F,n1,n3,&toCheck) +
1475 GetNodeUV(F,n2,n4,&toCheck) +
1476 GetNodeUV(F,n3,n1,&toCheck) +
1477 GetNodeUV(F,n4,n2,&toCheck)) / 4;
1478 //CheckNodeUV( F, centralNode, uvAvg, 2*BRep_Tool::Tolerance( F ), /*force=*/true);
1479 meshDS->SetNodeOnFace( centralNode, faceID, uvAvg.X(), uvAvg.Y() );
1481 else if ( solidID > 0 )
1483 meshDS->SetNodeInVolume( centralNode, solidID );
1485 else if ( myShapeID > 0 && mySetElemOnShape )
1487 meshDS->SetMeshElementOnShape( centralNode, myShapeID );
1490 myMapWithCentralNode.insert( std::make_pair( keyOfMap, centralNode ) );
1494 //=======================================================================
1495 //function : GetCentralNode
1496 //purpose : Return existing or create a new central node for a
1497 // quadratic triangle given its 6 nodes.
1498 //@param : force3d - true means node creation in between the given nodes,
1499 // else node position is found on a geometrical face if any.
1500 //=======================================================================
1502 const SMDS_MeshNode* SMESH_MesherHelper::GetCentralNode(const SMDS_MeshNode* n1,
1503 const SMDS_MeshNode* n2,
1504 const SMDS_MeshNode* n3,
1505 const SMDS_MeshNode* n12,
1506 const SMDS_MeshNode* n23,
1507 const SMDS_MeshNode* n31,
1510 SMDS_MeshNode *centralNode = 0; // central node to return
1512 // Find an existing central node
1514 TBiQuad keyOfMap(n1,n2,n3);
1515 std::map<TBiQuad, const SMDS_MeshNode* >::iterator itMapCentralNode;
1516 itMapCentralNode = myMapWithCentralNode.find( keyOfMap );
1517 if ( itMapCentralNode != myMapWithCentralNode.end() )
1519 return (*itMapCentralNode).second;
1522 // Get type of shape for the new central node
1524 TopAbs_ShapeEnum shapeType = TopAbs_SHAPE;
1528 TopTools_ListIteratorOfListOfShape it;
1530 std::map< int, int > faceId2nbNodes;
1531 std::map< int, int > ::iterator itMapWithIdFace;
1533 SMESHDS_Mesh* meshDS = GetMeshDS();
1535 // check if a face lies on a FACE, i.e. its all corner nodes lie either on the FACE or
1536 // on sub-shapes of the FACE
1537 if ( GetMesh()->HasShapeToMesh() )
1539 const SMDS_MeshNode* nodes[] = { n1, n2, n3 };
1540 for(int i = 0; i < 3; i++)
1542 shape = GetSubShapeByNode( nodes[i], meshDS );
1543 if ( shape.IsNull() ) break;
1544 if ( shape.ShapeType() == TopAbs_SOLID )
1546 solidID = nodes[i]->getshapeId();
1547 shapeType = TopAbs_SOLID;
1550 if ( shape.ShapeType() == TopAbs_FACE )
1552 faceID = nodes[i]->getshapeId();
1553 itMapWithIdFace = faceId2nbNodes.insert( std::make_pair( faceID, 0 ) ).first;
1554 itMapWithIdFace->second++;
1558 PShapeIteratorPtr it = GetAncestors(shape, *GetMesh(), TopAbs_FACE );
1559 while ( const TopoDS_Shape* face = it->next() )
1561 faceID = meshDS->ShapeToIndex( *face );
1562 itMapWithIdFace = faceId2nbNodes.insert( std::make_pair( faceID, 0 ) ).first;
1563 itMapWithIdFace->second++;
1568 if ( solidID < 1 && !faceId2nbNodes.empty() ) // SOLID not found
1570 // find ID of the FACE the four corner nodes belong to
1571 itMapWithIdFace = faceId2nbNodes.find( myShapeID ); // IPAL52698
1572 if ( itMapWithIdFace != faceId2nbNodes.end() &&
1573 itMapWithIdFace->second == 4 )
1575 shapeType = TopAbs_FACE;
1580 itMapWithIdFace = faceId2nbNodes.begin();
1581 for ( ; itMapWithIdFace != faceId2nbNodes.end(); ++itMapWithIdFace)
1583 if ( itMapWithIdFace->second == 3 )
1585 shapeType = TopAbs_FACE;
1586 faceID = (*itMapWithIdFace).first;
1596 if ( shapeType == TopAbs_FACE )
1598 F = TopoDS::Face( meshDS->IndexToShape( faceID ));
1599 bool checkOK = true, badTria = false;
1601 GetNodeUV( F, n1, n23, &checkOK ),
1602 GetNodeUV( F, n2, n31, &checkOK ),
1603 GetNodeUV( F, n3, n12, &checkOK ),
1604 GetNodeUV( F, n12, n3, &checkOK ),
1605 GetNodeUV( F, n23, n1, &checkOK ),
1606 GetNodeUV( F, n31, n2, &checkOK )
1608 AdjustByPeriod( F, uv, 6 ); // put uv[] within a period (IPAL52698)
1610 uvAvg = GetCenterUV( uv[0],uv[1],uv[2], uv[3],uv[4],uv[5], &badTria );
1612 if ( badTria || !checkOK )
1616 // Create a central node
1619 if ( !F.IsNull() && !force3d )
1621 TopLoc_Location loc;
1622 Handle( Geom_Surface ) S = BRep_Tool::Surface( F, loc );
1623 P = S->Value( uvAvg.X(), uvAvg.Y() ).Transformed( loc );
1624 centralNode = meshDS->AddNode( P.X(), P.Y(), P.Z() );
1625 // if ( mySetElemOnShape ) node is not elem!
1626 meshDS->SetNodeOnFace( centralNode, faceID, uvAvg.X(), uvAvg.Y() );
1628 else // ( force3d || F.IsNull() )
1630 P = ( SMESH_TNodeXYZ( n12 ) +
1631 SMESH_TNodeXYZ( n23 ) +
1632 SMESH_TNodeXYZ( n31 ) ) / 3;
1633 centralNode = meshDS->AddNode( P.X(), P.Y(), P.Z() );
1635 if ( !F.IsNull() ) // force3d
1637 meshDS->SetNodeOnFace( centralNode, faceID, uvAvg.X(), uvAvg.Y() );
1639 else if ( solidID > 0 )
1641 meshDS->SetNodeInVolume( centralNode, solidID );
1643 else if ( myShapeID > 0 && mySetElemOnShape )
1645 meshDS->SetMeshElementOnShape( centralNode, myShapeID );
1648 myMapWithCentralNode.insert( std::make_pair( keyOfMap, centralNode ) );
1652 //=======================================================================
1653 //function : GetMediumNode
1654 //purpose : Return existing or create a new medium node between given ones
1655 //=======================================================================
1657 const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1,
1658 const SMDS_MeshNode* n2,
1660 TopAbs_ShapeEnum expectedSupport)
1662 // Find existing node
1664 SMESH_TLink link(n1,n2);
1665 ItTLinkNode itLN = myTLinkNodeMap.find( link );
1666 if ( itLN != myTLinkNodeMap.end() ) {
1667 return (*itLN).second;
1670 // Create medium node
1673 SMESHDS_Mesh* meshDS = GetMeshDS();
1675 if ( IsSeamShape( n1->getshapeId() ))
1676 // to get a correct UV of a node on seam, the second node must have checked UV
1677 std::swap( n1, n2 );
1679 // get type of shape for the new medium node
1680 int faceID = -1, edgeID = -1;
1681 TopoDS_Edge E; double u [2] = {0.,0.};
1682 TopoDS_Face F; gp_XY uv[2];
1683 bool uvOK[2] = { true, true };
1684 const bool useCurSubShape = ( !myShape.IsNull() && myShape.ShapeType() == TopAbs_EDGE );
1686 pair<int, TopAbs_ShapeEnum> pos = GetMediumPos( n1, n2, useCurSubShape, expectedSupport );
1688 // get positions of the given nodes on shapes
1689 if ( pos.second == TopAbs_FACE )
1691 F = TopoDS::Face(meshDS->IndexToShape( faceID = pos.first ));
1692 uv[0] = GetNodeUV(F,n1,n2, force3d ? 0 : &uvOK[0]);
1694 ( HasDegeneratedEdges() || GetSurface( F )->HasSingularities( 1e-7 )))
1696 // IPAL52850 (degen VERTEX not at singularity)
1697 // project middle point to a surface
1698 SMESH_TNodeXYZ p1( n1 ), p2( n2 );
1699 gp_Pnt pMid = 0.5 * ( p1 + p2 );
1700 Handle(ShapeAnalysis_Surface) projector = GetSurface( F );
1703 uvMid = projector->NextValueOfUV( uv[0], pMid, BRep_Tool::Tolerance( F ));
1705 uvMid = projector->ValueOfUV( pMid, getFaceMaxTol( F ));
1706 if ( projector->Gap() * projector->Gap() < ( p1 - p2 ).SquareModulus() / 4 )
1708 gp_Pnt pProj = projector->Value( uvMid );
1709 n12 = meshDS->AddNode( pProj.X(), pProj.Y(), pProj.Z() );
1710 meshDS->SetNodeOnFace( n12, faceID, uvMid.X(), uvMid.Y() );
1711 myTLinkNodeMap.insert( make_pair ( link, n12 ));
1715 uv[1] = GetNodeUV(F,n2,n1, force3d ? 0 : &uvOK[1]);
1717 else if ( pos.second == TopAbs_EDGE )
1719 const SMDS_PositionPtr Pos1 = n1->GetPosition();
1720 const SMDS_PositionPtr Pos2 = n2->GetPosition();
1721 if ( Pos1->GetTypeOfPosition()==SMDS_TOP_EDGE &&
1722 Pos2->GetTypeOfPosition()==SMDS_TOP_EDGE &&
1723 n1->getshapeId() != n2->getshapeId() )
1726 return getMediumNodeOnComposedWire(n1,n2,force3d);
1728 E = TopoDS::Edge(meshDS->IndexToShape( edgeID = pos.first ));
1730 u[0] = GetNodeU(E,n1,n2, force3d ? 0 : &uvOK[0]);
1731 u[1] = GetNodeU(E,n2,n1, force3d ? 0 : &uvOK[1]);
1733 catch ( Standard_Failure& f )
1735 // issue 22502 / a node is on VERTEX not belonging to E
1736 // issue 22568 / both nodes are on non-connected VERTEXes
1737 return getMediumNodeOnComposedWire(n1,n2,force3d);
1741 if ( !force3d & uvOK[0] && uvOK[1] )
1743 // we try to create medium node using UV parameters of
1744 // nodes, else - medium between corresponding 3d points
1747 //if ( uvOK[0] && uvOK[1] )
1749 if ( IsDegenShape( n1->getshapeId() )) {
1750 if ( myParIndex & U_periodic ) uv[0].SetCoord( 1, uv[1].Coord( 1 ));
1751 else uv[0].SetCoord( 2, uv[1].Coord( 2 ));
1753 else if ( IsDegenShape( n2->getshapeId() )) {
1754 if ( myParIndex & U_periodic ) uv[1].SetCoord( 1, uv[0].Coord( 1 ));
1755 else uv[1].SetCoord( 2, uv[0].Coord( 2 ));
1757 TopLoc_Location loc;
1758 Handle(Geom_Surface) S = BRep_Tool::Surface(F,loc);
1759 gp_XY UV = GetMiddleUV( S, uv[0], uv[1] );
1760 gp_Pnt P = S->Value( UV.X(), UV.Y() ).Transformed(loc);
1761 n12 = meshDS->AddNode(P.X(), P.Y(), P.Z());
1762 // if ( mySetElemOnShape ) node is not elem!
1763 meshDS->SetNodeOnFace(n12, faceID, UV.X(), UV.Y());
1764 myTLinkNodeMap.insert(make_pair(link,n12));
1768 else if ( !E.IsNull() )
1771 Handle(Geom_Curve) C = BRep_Tool::Curve(E, f, l);
1774 Standard_Boolean isPeriodic = C->IsPeriodic();
1777 Standard_Real Period = C->Period();
1778 Standard_Real p = u[1]+ShapeAnalysis::AdjustByPeriod(u[1],u[0],Period);
1779 Standard_Real pmid = (u[0]+p)/2.;
1780 U = pmid+ShapeAnalysis::AdjustToPeriod(pmid,C->FirstParameter(),C->LastParameter());
1785 gp_Pnt P = C->Value( U );
1786 n12 = meshDS->AddNode(P.X(), P.Y(), P.Z());
1787 //if ( mySetElemOnShape ) node is not elem!
1788 meshDS->SetNodeOnEdge(n12, edgeID, U);
1789 myTLinkNodeMap.insert(make_pair(link,n12));
1796 double x = ( n1->X() + n2->X() )/2.;
1797 double y = ( n1->Y() + n2->Y() )/2.;
1798 double z = ( n1->Z() + n2->Z() )/2.;
1799 n12 = meshDS->AddNode(x,y,z);
1801 //if ( mySetElemOnShape ) node is not elem!
1805 gp_XY UV = ( uv[0] + uv[1] ) / 2.;
1806 CheckNodeUV( F, n12, UV, 2 * BRep_Tool::Tolerance( F ), /*force=*/true);
1807 meshDS->SetNodeOnFace(n12, faceID, UV.X(), UV.Y() );
1809 else if ( !E.IsNull() )
1811 double U = ( u[0] + u[1] ) / 2.;
1812 CheckNodeU( E, n12, U, 2 * BRep_Tool::Tolerance( E ), /*force=*/true);
1813 meshDS->SetNodeOnEdge(n12, edgeID, U);
1815 else if ( myShapeID > 0 && mySetElemOnShape )
1817 meshDS->SetMeshElementOnShape(n12, myShapeID);
1821 myTLinkNodeMap.insert( make_pair( link, n12 ));
1825 //================================================================================
1827 * \brief Makes a medium node if nodes reside different edges
1829 //================================================================================
1831 const SMDS_MeshNode* SMESH_MesherHelper::getMediumNodeOnComposedWire(const SMDS_MeshNode* n1,
1832 const SMDS_MeshNode* n2,
1835 SMESH_TNodeXYZ p1( n1 ), p2( n2 );
1836 gp_Pnt middle = 0.5 * p1 + 0.5 * p2;
1837 SMDS_MeshNode* n12 = AddNode( middle.X(), middle.Y(), middle.Z() );
1839 // To find position on edge and 3D position for n12,
1840 // project <middle> to 2 edges and select projection most close to <middle>
1842 TopoDS_Edge bestEdge;
1843 double u = 0, distMiddleProj = Precision::Infinite(), distXYZ[4], f,l;
1845 // get shapes under the nodes
1846 TopoDS_Shape shape[2];
1848 for ( int is2nd = 0; is2nd < 2; ++is2nd )
1850 const SMDS_MeshNode* n = is2nd ? n2 : n1;
1851 TopoDS_Shape S = GetSubShapeByNode( n, GetMeshDS() );
1853 shape[ nbShapes++ ] = S;
1856 vector< TopoDS_Shape > edges;
1857 for ( int iS = 0; iS < nbShapes; ++iS )
1859 switch ( shape[iS].ShapeType() ) {
1862 edges.push_back( shape[iS] );
1868 if ( nbShapes == 2 && iS==0 && shape[1-iS].ShapeType() == TopAbs_VERTEX )
1869 edge = GetCommonAncestor( shape[iS], shape[1-iS], *myMesh, TopAbs_EDGE );
1871 if ( edge.IsNull() )
1873 PShapeIteratorPtr eIt = GetAncestors( shape[iS], *myMesh, TopAbs_EDGE );
1874 while( const TopoDS_Shape* e = eIt->next() )
1875 edges.push_back( *e );
1881 if ( nbShapes == 1 || shape[1-iS].ShapeType() < TopAbs_EDGE )
1882 for ( TopExp_Explorer e( shape[iS], TopAbs_EDGE ); e.More(); e.Next() )
1883 edges.push_back( e.Current() );
1890 // project to get U of projection and distance from middle to projection
1891 for ( size_t iE = 0; iE < edges.size(); ++iE )
1893 const TopoDS_Edge& edge = TopoDS::Edge( edges[ iE ]);
1894 distXYZ[0] = distMiddleProj;
1896 CheckNodeU( edge, n12, testU, 2 * BRep_Tool::Tolerance(edge), /*force=*/true, distXYZ );
1897 if ( distXYZ[0] < distMiddleProj )
1899 distMiddleProj = distXYZ[0];
1905 // // both projections failed; set n12 on the edge of n1 with U of a common vertex
1906 // TopoDS_Vertex vCommon;
1907 // if ( TopExp::CommonVertex( edges[0], edges[1], vCommon ))
1908 // u = BRep_Tool::Parameter( vCommon, edges[0] );
1911 // double f,l, u0 = GetNodeU( edges[0], n1 );
1912 // BRep_Tool::Range( edges[0],f,l );
1913 // u = ( fabs(u0-f) < fabs(u0-l) ) ? f : l;
1916 // distMiddleProj = 0;
1919 if ( !bestEdge.IsNull() )
1921 // move n12 to position of a successful projection
1922 //double tol = BRep_Tool::Tolerance(edges[ iOkEdge ]);
1923 if ( !force3d /*&& distMiddleProj > 2*tol*/ )
1925 TopLoc_Location loc;
1926 Handle(Geom_Curve) curve = BRep_Tool::Curve( bestEdge,loc,f,l );
1927 gp_Pnt p = curve->Value( u ).Transformed( loc );
1928 GetMeshDS()->MoveNode( n12, p.X(), p.Y(), p.Z() );
1930 //if ( mySetElemOnShape ) node is not elem!
1932 int edgeID = GetMeshDS()->ShapeToIndex( bestEdge );
1933 if ( edgeID != n12->getshapeId() )
1934 GetMeshDS()->UnSetNodeOnShape( n12 );
1935 GetMeshDS()->SetNodeOnEdge(n12, edgeID, u);
1938 myTLinkNodeMap.insert( make_pair( SMESH_TLink(n1,n2), n12 ));
1943 //=======================================================================
1944 //function : AddNode
1945 //purpose : Creates a node
1946 //=======================================================================
1948 SMDS_MeshNode* SMESH_MesherHelper::AddNode(double x, double y, double z, int ID,
1951 SMESHDS_Mesh * meshDS = GetMeshDS();
1952 SMDS_MeshNode* node = 0;
1954 node = meshDS->AddNodeWithID( x, y, z, ID );
1956 node = meshDS->AddNode( x, y, z );
1957 if ( mySetElemOnShape && myShapeID > 0 ) { // node is not elem ?
1958 switch ( myShape.ShapeType() ) {
1959 case TopAbs_SOLID: meshDS->SetNodeInVolume( node, myShapeID); break;
1960 case TopAbs_SHELL: meshDS->SetNodeInVolume( node, myShapeID); break;
1961 case TopAbs_FACE: meshDS->SetNodeOnFace( node, myShapeID, u, v); break;
1962 case TopAbs_EDGE: meshDS->SetNodeOnEdge( node, myShapeID, u); break;
1963 case TopAbs_VERTEX: meshDS->SetNodeOnVertex( node, myShapeID); break;
1970 //=======================================================================
1971 //function : AddEdge
1972 //purpose : Creates quadratic or linear edge
1973 //=======================================================================
1975 SMDS_MeshEdge* SMESH_MesherHelper::AddEdge(const SMDS_MeshNode* n1,
1976 const SMDS_MeshNode* n2,
1980 SMESHDS_Mesh * meshDS = GetMeshDS();
1982 SMDS_MeshEdge* edge = 0;
1983 if (myCreateQuadratic) {
1984 const SMDS_MeshNode* n12 = GetMediumNode(n1,n2,force3d);
1986 edge = meshDS->AddEdgeWithID(n1, n2, n12, id);
1988 edge = meshDS->AddEdge(n1, n2, n12);
1992 edge = meshDS->AddEdgeWithID(n1, n2, id);
1994 edge = meshDS->AddEdge(n1, n2);
1997 if ( mySetElemOnShape && myShapeID > 0 )
1998 meshDS->SetMeshElementOnShape( edge, myShapeID );
2003 //=======================================================================
2004 //function : AddFace
2005 //purpose : Creates quadratic or linear triangle
2006 //=======================================================================
2008 SMDS_MeshFace* SMESH_MesherHelper::AddFace(const SMDS_MeshNode* n1,
2009 const SMDS_MeshNode* n2,
2010 const SMDS_MeshNode* n3,
2014 SMESHDS_Mesh * meshDS = GetMeshDS();
2015 SMDS_MeshFace* elem = 0;
2017 if( n1==n2 || n2==n3 || n3==n1 )
2020 if(!myCreateQuadratic) {
2022 elem = meshDS->AddFaceWithID(n1, n2, n3, id);
2024 elem = meshDS->AddFace(n1, n2, n3);
2027 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_FACE );
2028 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_FACE );
2029 const SMDS_MeshNode* n31 = GetMediumNode( n3, n1, force3d, TopAbs_FACE );
2030 if(myCreateBiQuadratic)
2032 const SMDS_MeshNode* nCenter = GetCentralNode(n1, n2, n3, n12, n23, n31, force3d);
2034 elem = meshDS->AddFaceWithID(n1, n2, n3, n12, n23, n31, nCenter, id);
2036 elem = meshDS->AddFace(n1, n2, n3, n12, n23, n31, nCenter);
2041 elem = meshDS->AddFaceWithID(n1, n2, n3, n12, n23, n31, id);
2043 elem = meshDS->AddFace(n1, n2, n3, n12, n23, n31);
2046 if ( mySetElemOnShape && myShapeID > 0 )
2047 meshDS->SetMeshElementOnShape( elem, myShapeID );
2052 //=======================================================================
2053 //function : AddFace
2054 //purpose : Creates bi-quadratic, quadratic or linear quadrangle
2055 //=======================================================================
2057 SMDS_MeshFace* SMESH_MesherHelper::AddFace(const SMDS_MeshNode* n1,
2058 const SMDS_MeshNode* n2,
2059 const SMDS_MeshNode* n3,
2060 const SMDS_MeshNode* n4,
2064 SMESHDS_Mesh * meshDS = GetMeshDS();
2065 SMDS_MeshFace* elem = 0;
2068 return AddFace(n1,n3,n4,id,force3d);
2071 return AddFace(n1,n2,n4,id,force3d);
2074 return AddFace(n1,n2,n3,id,force3d);
2077 return AddFace(n1,n2,n4,id,force3d);
2080 return AddFace(n1,n2,n3,id,force3d);
2083 return AddFace(n1,n2,n3,id,force3d);
2086 if(!myCreateQuadratic) {
2088 elem = meshDS->AddFaceWithID(n1, n2, n3, n4, id);
2090 elem = meshDS->AddFace(n1, n2, n3, n4);
2093 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_FACE );
2094 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_FACE );
2095 const SMDS_MeshNode* n34 = GetMediumNode( n3, n4, force3d, TopAbs_FACE );
2096 const SMDS_MeshNode* n41 = GetMediumNode( n4, n1, force3d, TopAbs_FACE );
2097 if(myCreateBiQuadratic)
2099 const SMDS_MeshNode* nCenter = GetCentralNode(n1, n2, n3, n4, n12, n23, n34, n41, force3d);
2101 elem = meshDS->AddFaceWithID(n1, n2, n3, n4, n12, n23, n34, n41, nCenter, id);
2103 elem = meshDS->AddFace(n1, n2, n3, n4, n12, n23, n34, n41, nCenter);
2108 elem = meshDS->AddFaceWithID(n1, n2, n3, n4, n12, n23, n34, n41, id);
2110 elem = meshDS->AddFace(n1, n2, n3, n4, n12, n23, n34, n41);
2113 if ( mySetElemOnShape && myShapeID > 0 )
2114 meshDS->SetMeshElementOnShape( elem, myShapeID );
2119 //=======================================================================
2120 //function : AddPolygonalFace
2121 //purpose : Creates polygon, with additional nodes in quadratic mesh
2122 //=======================================================================
2124 SMDS_MeshFace* SMESH_MesherHelper::AddPolygonalFace (const vector<const SMDS_MeshNode*>& nodes,
2128 SMESHDS_Mesh * meshDS = GetMeshDS();
2129 SMDS_MeshFace* elem = 0;
2131 if(!myCreateQuadratic)
2134 elem = meshDS->AddPolygonalFaceWithID(nodes, id);
2136 elem = meshDS->AddPolygonalFace(nodes);
2140 vector<const SMDS_MeshNode*> newNodes( nodes.size() * 2 );
2142 for ( size_t i = 0; i < nodes.size(); ++i )
2144 const SMDS_MeshNode* n1 = nodes[i];
2145 const SMDS_MeshNode* n2 = nodes[(i+1)%nodes.size()];
2146 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_FACE );
2147 newNodes.push_back( n12 );
2150 elem = meshDS->AddQuadPolygonalFaceWithID(newNodes, id);
2152 elem = meshDS->AddQuadPolygonalFace(newNodes);
2154 if ( mySetElemOnShape && myShapeID > 0 )
2155 meshDS->SetMeshElementOnShape( elem, myShapeID );
2160 //=======================================================================
2161 //function : AddVolume
2162 //purpose : Creates quadratic or linear prism
2163 //=======================================================================
2165 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2166 const SMDS_MeshNode* n2,
2167 const SMDS_MeshNode* n3,
2168 const SMDS_MeshNode* n4,
2169 const SMDS_MeshNode* n5,
2170 const SMDS_MeshNode* n6,
2174 SMESHDS_Mesh * meshDS = GetMeshDS();
2175 SMDS_MeshVolume* elem = 0;
2176 if(!myCreateQuadratic) {
2178 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, id);
2180 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6);
2183 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2184 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_SOLID );
2185 const SMDS_MeshNode* n31 = GetMediumNode( n3, n1, force3d, TopAbs_SOLID );
2187 const SMDS_MeshNode* n45 = GetMediumNode( n4, n5, force3d, TopAbs_SOLID );
2188 const SMDS_MeshNode* n56 = GetMediumNode( n5, n6, force3d, TopAbs_SOLID );
2189 const SMDS_MeshNode* n64 = GetMediumNode( n6, n4, force3d, TopAbs_SOLID );
2191 const SMDS_MeshNode* n14 = GetMediumNode( n1, n4, force3d, TopAbs_SOLID );
2192 const SMDS_MeshNode* n25 = GetMediumNode( n2, n5, force3d, TopAbs_SOLID );
2193 const SMDS_MeshNode* n36 = GetMediumNode( n3, n6, force3d, TopAbs_SOLID );
2194 if ( myCreateBiQuadratic )
2196 const SMDS_MeshNode* n1245 = GetCentralNode( n1,n2,n4,n5,n12,n25,n45,n14,force3d );
2197 const SMDS_MeshNode* n1346 = GetCentralNode( n1,n3,n4,n6,n31,n36,n64,n14,force3d );
2198 const SMDS_MeshNode* n2356 = GetCentralNode( n2,n3,n6,n5,n23,n36,n56,n25,force3d );
2201 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6,
2202 n12, n23, n31, n45, n56, n64, n14, n25, n36,
2203 n1245, n2356, n1346, id);
2205 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6,
2206 n12, n23, n31, n45, n56, n64, n14, n25, n36,
2207 n1245, n2356, n1346);
2212 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6,
2213 n12, n23, n31, n45, n56, n64, n14, n25, n36, id);
2215 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6,
2216 n12, n23, n31, n45, n56, n64, n14, n25, n36);
2219 if ( mySetElemOnShape && myShapeID > 0 )
2220 meshDS->SetMeshElementOnShape( elem, myShapeID );
2225 //=======================================================================
2226 //function : AddVolume
2227 //purpose : Creates quadratic or linear tetrahedron
2228 //=======================================================================
2230 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2231 const SMDS_MeshNode* n2,
2232 const SMDS_MeshNode* n3,
2233 const SMDS_MeshNode* n4,
2237 SMESHDS_Mesh * meshDS = GetMeshDS();
2238 SMDS_MeshVolume* elem = 0;
2239 if(!myCreateQuadratic) {
2241 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, id);
2243 elem = meshDS->AddVolume(n1, n2, n3, n4);
2246 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2247 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_SOLID );
2248 const SMDS_MeshNode* n31 = GetMediumNode( n3, n1, force3d, TopAbs_SOLID );
2250 const SMDS_MeshNode* n14 = GetMediumNode( n1, n4, force3d, TopAbs_SOLID );
2251 const SMDS_MeshNode* n24 = GetMediumNode( n2, n4, force3d, TopAbs_SOLID );
2252 const SMDS_MeshNode* n34 = GetMediumNode( n3, n4, force3d, TopAbs_SOLID );
2255 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n12, n23, n31, n14, n24, n34, id);
2257 elem = meshDS->AddVolume(n1, n2, n3, n4, n12, n23, n31, n14, n24, n34);
2259 if ( mySetElemOnShape && myShapeID > 0 )
2260 meshDS->SetMeshElementOnShape( elem, myShapeID );
2265 //=======================================================================
2266 //function : AddVolume
2267 //purpose : Creates quadratic or linear pyramid
2268 //=======================================================================
2270 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2271 const SMDS_MeshNode* n2,
2272 const SMDS_MeshNode* n3,
2273 const SMDS_MeshNode* n4,
2274 const SMDS_MeshNode* n5,
2278 SMDS_MeshVolume* elem = 0;
2279 if(!myCreateQuadratic) {
2281 elem = GetMeshDS()->AddVolumeWithID(n1, n2, n3, n4, n5, id);
2283 elem = GetMeshDS()->AddVolume(n1, n2, n3, n4, n5);
2286 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2287 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_SOLID );
2288 const SMDS_MeshNode* n34 = GetMediumNode( n3, n4, force3d, TopAbs_SOLID );
2289 const SMDS_MeshNode* n41 = GetMediumNode( n4, n1, force3d, TopAbs_SOLID );
2291 const SMDS_MeshNode* n15 = GetMediumNode( n1, n5, force3d, TopAbs_SOLID );
2292 const SMDS_MeshNode* n25 = GetMediumNode( n2, n5, force3d, TopAbs_SOLID );
2293 const SMDS_MeshNode* n35 = GetMediumNode( n3, n5, force3d, TopAbs_SOLID );
2294 const SMDS_MeshNode* n45 = GetMediumNode( n4, n5, force3d, TopAbs_SOLID );
2297 elem = GetMeshDS()->AddVolumeWithID ( n1, n2, n3, n4, n5,
2302 elem = GetMeshDS()->AddVolume( n1, n2, n3, n4, n5,
2304 n15, n25, n35, n45);
2306 if ( mySetElemOnShape && myShapeID > 0 )
2307 GetMeshDS()->SetMeshElementOnShape( elem, myShapeID );
2312 //=======================================================================
2313 //function : AddVolume
2314 //purpose : Creates tri-quadratic, quadratic or linear hexahedron
2315 //=======================================================================
2317 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2318 const SMDS_MeshNode* n2,
2319 const SMDS_MeshNode* n3,
2320 const SMDS_MeshNode* n4,
2321 const SMDS_MeshNode* n5,
2322 const SMDS_MeshNode* n6,
2323 const SMDS_MeshNode* n7,
2324 const SMDS_MeshNode* n8,
2328 SMESHDS_Mesh * meshDS = GetMeshDS();
2329 SMDS_MeshVolume* elem = 0;
2330 if(!myCreateQuadratic) {
2332 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, id);
2334 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
2337 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2338 const SMDS_MeshNode* n23 = GetMediumNode( n2, n3, force3d, TopAbs_SOLID );
2339 const SMDS_MeshNode* n34 = GetMediumNode( n3, n4, force3d, TopAbs_SOLID );
2340 const SMDS_MeshNode* n41 = GetMediumNode( n4, n1, force3d, TopAbs_SOLID );
2342 const SMDS_MeshNode* n56 = GetMediumNode( n5, n6, force3d, TopAbs_SOLID );
2343 const SMDS_MeshNode* n67 = GetMediumNode( n6, n7, force3d, TopAbs_SOLID );
2344 const SMDS_MeshNode* n78 = GetMediumNode( n7, n8, force3d, TopAbs_SOLID );
2345 const SMDS_MeshNode* n85 = GetMediumNode( n8, n5, force3d, TopAbs_SOLID );
2347 const SMDS_MeshNode* n15 = GetMediumNode( n1, n5, force3d, TopAbs_SOLID );
2348 const SMDS_MeshNode* n26 = GetMediumNode( n2, n6, force3d, TopAbs_SOLID );
2349 const SMDS_MeshNode* n37 = GetMediumNode( n3, n7, force3d, TopAbs_SOLID );
2350 const SMDS_MeshNode* n48 = GetMediumNode( n4, n8, force3d, TopAbs_SOLID );
2351 if ( myCreateBiQuadratic )
2353 const SMDS_MeshNode* n1234 = GetCentralNode( n1,n2,n3,n4,n12,n23,n34,n41,force3d );
2354 const SMDS_MeshNode* n1256 = GetCentralNode( n1,n2,n5,n6,n12,n26,n56,n15,force3d );
2355 const SMDS_MeshNode* n2367 = GetCentralNode( n2,n3,n6,n7,n23,n37,n67,n26,force3d );
2356 const SMDS_MeshNode* n3478 = GetCentralNode( n3,n4,n7,n8,n34,n48,n78,n37,force3d );
2357 const SMDS_MeshNode* n1458 = GetCentralNode( n1,n4,n5,n8,n41,n48,n15,n85,force3d );
2358 const SMDS_MeshNode* n5678 = GetCentralNode( n5,n6,n7,n8,n56,n67,n78,n85,force3d );
2360 vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
2362 pointsOnShapes[ SMESH_Block::ID_V000 ] = SMESH_TNodeXYZ( n4 );
2363 pointsOnShapes[ SMESH_Block::ID_V100 ] = SMESH_TNodeXYZ( n8 );
2364 pointsOnShapes[ SMESH_Block::ID_V010 ] = SMESH_TNodeXYZ( n3 );
2365 pointsOnShapes[ SMESH_Block::ID_V110 ] = SMESH_TNodeXYZ( n7 );
2366 pointsOnShapes[ SMESH_Block::ID_V001 ] = SMESH_TNodeXYZ( n1 );
2367 pointsOnShapes[ SMESH_Block::ID_V101 ] = SMESH_TNodeXYZ( n5 );
2368 pointsOnShapes[ SMESH_Block::ID_V011 ] = SMESH_TNodeXYZ( n2 );
2369 pointsOnShapes[ SMESH_Block::ID_V111 ] = SMESH_TNodeXYZ( n6 );
2371 pointsOnShapes[ SMESH_Block::ID_Ex00 ] = SMESH_TNodeXYZ( n48 );
2372 pointsOnShapes[ SMESH_Block::ID_Ex10 ] = SMESH_TNodeXYZ( n37 );
2373 pointsOnShapes[ SMESH_Block::ID_E0y0 ] = SMESH_TNodeXYZ( n15 );
2374 pointsOnShapes[ SMESH_Block::ID_E1y0 ] = SMESH_TNodeXYZ( n26 );
2375 pointsOnShapes[ SMESH_Block::ID_Ex01 ] = SMESH_TNodeXYZ( n34 );
2376 pointsOnShapes[ SMESH_Block::ID_Ex11 ] = SMESH_TNodeXYZ( n78 );
2377 pointsOnShapes[ SMESH_Block::ID_E0y1 ] = SMESH_TNodeXYZ( n12 );
2378 pointsOnShapes[ SMESH_Block::ID_E1y1 ] = SMESH_TNodeXYZ( n56 );
2379 pointsOnShapes[ SMESH_Block::ID_E00z ] = SMESH_TNodeXYZ( n41 );
2380 pointsOnShapes[ SMESH_Block::ID_E10z ] = SMESH_TNodeXYZ( n85 );
2381 pointsOnShapes[ SMESH_Block::ID_E01z ] = SMESH_TNodeXYZ( n23 );
2382 pointsOnShapes[ SMESH_Block::ID_E11z ] = SMESH_TNodeXYZ( n67 );
2384 pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = SMESH_TNodeXYZ( n3478 );
2385 pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = SMESH_TNodeXYZ( n1256 );
2386 pointsOnShapes[ SMESH_Block::ID_Fx0z ] = SMESH_TNodeXYZ( n1458 );
2387 pointsOnShapes[ SMESH_Block::ID_Fx1z ] = SMESH_TNodeXYZ( n2367 );
2388 pointsOnShapes[ SMESH_Block::ID_F0yz ] = SMESH_TNodeXYZ( n1234 );
2389 pointsOnShapes[ SMESH_Block::ID_F1yz ] = SMESH_TNodeXYZ( n5678 );
2391 gp_XYZ centerCube(0.5, 0.5, 0.5);
2393 SMESH_Block::ShellPoint( centerCube, pointsOnShapes, nCenterElem );
2394 const SMDS_MeshNode* nCenter =
2395 meshDS->AddNode( nCenterElem.X(), nCenterElem.Y(), nCenterElem.Z() );
2396 meshDS->SetNodeInVolume( nCenter, myShapeID );
2399 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8,
2400 n12, n23, n34, n41, n56, n67,
2401 n78, n85, n15, n26, n37, n48,
2402 n1234, n1256, n2367, n3478, n1458, n5678, nCenter, id);
2404 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6, n7, n8,
2405 n12, n23, n34, n41, n56, n67,
2406 n78, n85, n15, n26, n37, n48,
2407 n1234, n1256, n2367, n3478, n1458, n5678, nCenter);
2412 elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8,
2413 n12, n23, n34, n41, n56, n67,
2414 n78, n85, n15, n26, n37, n48, id);
2416 elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6, n7, n8,
2417 n12, n23, n34, n41, n56, n67,
2418 n78, n85, n15, n26, n37, n48);
2421 if ( mySetElemOnShape && myShapeID > 0 )
2422 meshDS->SetMeshElementOnShape( elem, myShapeID );
2427 //=======================================================================
2428 //function : AddVolume
2429 //purpose : Creates LINEAR!!!!!!!!! octahedron
2430 //=======================================================================
2432 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
2433 const SMDS_MeshNode* n2,
2434 const SMDS_MeshNode* n3,
2435 const SMDS_MeshNode* n4,
2436 const SMDS_MeshNode* n5,
2437 const SMDS_MeshNode* n6,
2438 const SMDS_MeshNode* n7,
2439 const SMDS_MeshNode* n8,
2440 const SMDS_MeshNode* n9,
2441 const SMDS_MeshNode* n10,
2442 const SMDS_MeshNode* n11,
2443 const SMDS_MeshNode* n12,
2447 SMESHDS_Mesh * meshDS = GetMeshDS();
2448 SMDS_MeshVolume* elem = 0;
2450 elem = meshDS->AddVolumeWithID(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,id);
2452 elem = meshDS->AddVolume(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12);
2453 if ( mySetElemOnShape && myShapeID > 0 )
2454 meshDS->SetMeshElementOnShape( elem, myShapeID );
2458 //=======================================================================
2459 //function : AddPolyhedralVolume
2460 //purpose : Creates polyhedron. In quadratic mesh, adds medium nodes
2461 //=======================================================================
2464 SMESH_MesherHelper::AddPolyhedralVolume (const std::vector<const SMDS_MeshNode*>& nodes,
2465 const std::vector<int>& quantities,
2469 SMESHDS_Mesh * meshDS = GetMeshDS();
2470 SMDS_MeshVolume* elem = 0;
2471 if(!myCreateQuadratic)
2474 elem = meshDS->AddPolyhedralVolumeWithID(nodes, quantities, id);
2476 elem = meshDS->AddPolyhedralVolume(nodes, quantities);
2480 vector<const SMDS_MeshNode*> newNodes;
2481 vector<int> newQuantities;
2482 for ( size_t iFace = 0, iN = 0; iFace < quantities.size(); ++iFace )
2484 int nbNodesInFace = quantities[iFace];
2485 newQuantities.push_back(0);
2486 for ( int i = 0; i < nbNodesInFace; ++i )
2488 const SMDS_MeshNode* n1 = nodes[ iN + i ];
2489 newNodes.push_back( n1 );
2490 newQuantities.back()++;
2492 const SMDS_MeshNode* n2 = nodes[ iN + ( i+1==nbNodesInFace ? 0 : i+1 )];
2493 // if ( n1->GetPosition()->GetTypeOfPosition() != SMDS_TOP_3DSPACE &&
2494 // n2->GetPosition()->GetTypeOfPosition() != SMDS_TOP_3DSPACE )
2496 const SMDS_MeshNode* n12 = GetMediumNode( n1, n2, force3d, TopAbs_SOLID );
2497 newNodes.push_back( n12 );
2498 newQuantities.back()++;
2501 iN += nbNodesInFace;
2504 elem = meshDS->AddPolyhedralVolumeWithID( newNodes, newQuantities, id );
2506 elem = meshDS->AddPolyhedralVolume( newNodes, newQuantities );
2508 if ( mySetElemOnShape && myShapeID > 0 )
2509 meshDS->SetMeshElementOnShape( elem, myShapeID );
2516 //================================================================================
2518 * \brief Check if a node belongs to any face of sub-mesh
2520 //================================================================================
2522 bool isNodeInSubMesh( const SMDS_MeshNode* n, const SMESHDS_SubMesh* sm )
2524 SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator( SMDSAbs_Face );
2525 while ( fIt->more() )
2526 if ( sm->Contains( fIt->next() ))
2532 //=======================================================================
2533 //function : IsSameElemGeometry
2534 //purpose : Returns true if all elements of a sub-mesh are of same shape
2535 //=======================================================================
2537 bool SMESH_MesherHelper::IsSameElemGeometry(const SMESHDS_SubMesh* smDS,
2538 SMDSAbs_GeometryType shape,
2539 const bool nullSubMeshRes)
2541 if ( !smDS ) return nullSubMeshRes;
2543 SMDS_ElemIteratorPtr elemIt = smDS->GetElements();
2544 while ( elemIt->more() ) {
2545 const SMDS_MeshElement* e = elemIt->next();
2546 if ( e->GetGeomType() != shape )
2552 //=======================================================================
2553 //function : LoadNodeColumns
2554 //purpose : Load nodes bound to face into a map of node columns
2555 //=======================================================================
2557 bool SMESH_MesherHelper::LoadNodeColumns(TParam2ColumnMap & theParam2ColumnMap,
2558 const TopoDS_Face& theFace,
2559 const TopoDS_Edge& theBaseEdge,
2560 SMESHDS_Mesh* theMesh,
2561 SMESH_ProxyMesh* theProxyMesh)
2563 return LoadNodeColumns(theParam2ColumnMap,
2565 std::list<TopoDS_Edge>(1,theBaseEdge),
2570 //=======================================================================
2571 //function : LoadNodeColumns
2572 //purpose : Load nodes bound to face into a map of node columns
2573 //=======================================================================
2575 bool SMESH_MesherHelper::LoadNodeColumns(TParam2ColumnMap & theParam2ColumnMap,
2576 const TopoDS_Face& theFace,
2577 const std::list<TopoDS_Edge>& theBaseSide,
2578 SMESHDS_Mesh* theMesh,
2579 SMESH_ProxyMesh* theProxyMesh)
2581 // get a right sub-mesh of theFace
2583 const SMESHDS_SubMesh* faceSubMesh = 0;
2586 faceSubMesh = theProxyMesh->GetSubMesh( theFace );
2587 if ( !faceSubMesh ||
2588 faceSubMesh->NbElements() == 0 ||
2589 theProxyMesh->IsTemporary( faceSubMesh->GetElements()->next() ))
2591 // can use a proxy sub-mesh with not temporary elements only
2597 faceSubMesh = theMesh->MeshElements( theFace );
2598 if ( !faceSubMesh || faceSubMesh->NbElements() == 0 )
2601 if ( theParam2ColumnMap.empty() )
2603 // get data of edges for normalization of params
2604 vector< double > length;
2606 list<TopoDS_Edge>::const_iterator edge;
2608 for ( edge = theBaseSide.begin(); edge != theBaseSide.end(); ++edge )
2610 double len = std::max( 1e-10, SMESH_Algo::EdgeLength( *edge ));
2612 length.push_back( len );
2616 // get nodes on theBaseEdge sorted by param on edge and initialize theParam2ColumnMap with them
2617 const SMDS_MeshNode* prevEndNodes[2] = { 0, 0 };
2618 edge = theBaseSide.begin();
2619 for ( int iE = 0; edge != theBaseSide.end(); ++edge, ++iE )
2621 map< double, const SMDS_MeshNode*> sortedBaseNN;
2622 SMESH_Algo::GetSortedNodesOnEdge( theMesh, *edge,/*noMedium=*/true, sortedBaseNN );
2624 map< double, const SMDS_MeshNode*>::iterator u_n;
2625 // pb with mesh_Projection_2D_00/A1 fixed by adding expectedSupport arg to GetMediumPos()
2626 // so the following solution is commented (hope forever :)
2628 // SMESH_Algo::GetSortedNodesOnEdge( theMesh, *edge,/*noMedium=*/true, sortedBaseNN,
2629 // // SMDSAbs_Edge here is needed to be coherent with
2630 // // StdMeshers_FaceSide used by Quadrangle to get nodes
2631 // // on EDGE; else pb in mesh_Projection_2D_00/A1 where a
2632 // // medium node on EDGE is medium in a triangle but not
2635 // if ( faceSubMesh->GetElements()->next()->IsQuadratic() )
2636 // // filter off nodes medium in faces on theFace (same pb with mesh_Projection_2D_00/A1)
2637 // for ( u_n = sortedBaseNN.begin(); u_n != sortedBaseNN.end() ; )
2639 // const SMDS_MeshNode* node = u_n->second;
2640 // SMDS_ElemIteratorPtr faceIt = node->GetInverseElementIterator( SMDSAbs_Face );
2641 // if ( faceIt->more() && node ) {
2642 // const SMDS_MeshElement* face = faceIt->next();
2643 // if ( faceSubMesh->Contains( face ) && face->IsMediumNode( node ))
2647 // sortedBaseNN.erase( u_n++ );
2651 if ( sortedBaseNN.empty() ) continue;
2653 u_n = sortedBaseNN.begin();
2654 if ( theProxyMesh ) // from sortedBaseNN remove nodes not shared by faces of faceSubMesh
2656 const SMDS_MeshNode* n1 = (++sortedBaseNN.begin())->second;
2657 const SMDS_MeshNode* n2 = (++sortedBaseNN.rbegin())->second;
2658 bool allNodesAreProxy = ( n1 != theProxyMesh->GetProxyNode( n1 ) &&
2659 n2 != theProxyMesh->GetProxyNode( n2 ));
2660 if ( allNodesAreProxy )
2661 for ( u_n = sortedBaseNN.begin(); u_n != sortedBaseNN.end(); u_n++ )
2662 u_n->second = theProxyMesh->GetProxyNode( u_n->second );
2664 if ( u_n = sortedBaseNN.begin(), !isNodeInSubMesh( u_n->second, faceSubMesh ))
2666 while ( ++u_n != sortedBaseNN.end() && !isNodeInSubMesh( u_n->second, faceSubMesh ));
2667 sortedBaseNN.erase( sortedBaseNN.begin(), u_n );
2669 if ( !sortedBaseNN.empty() )
2670 if ( u_n = --sortedBaseNN.end(), !isNodeInSubMesh( u_n->second, faceSubMesh ))
2672 while ( u_n != sortedBaseNN.begin() && !isNodeInSubMesh( (--u_n)->second, faceSubMesh ));
2673 sortedBaseNN.erase( ++u_n, sortedBaseNN.end() );
2675 if ( sortedBaseNN.empty() ) continue;
2679 BRep_Tool::Range( *edge, f, l );
2680 if ( edge->Orientation() == TopAbs_REVERSED ) std::swap( f, l );
2681 const double coeff = 1. / ( l - f ) * length[iE] / fullLen;
2682 const double prevPar = theParam2ColumnMap.empty() ? 0 : theParam2ColumnMap.rbegin()->first;
2683 for ( u_n = sortedBaseNN.begin(); u_n != sortedBaseNN.end(); u_n++ )
2685 if ( u_n->second == prevEndNodes[0] ||
2686 u_n->second == prevEndNodes[1] )
2688 double par = prevPar + coeff * ( u_n->first - f );
2689 TParam2ColumnMap::iterator u2nn =
2690 theParam2ColumnMap.insert( theParam2ColumnMap.end(), make_pair( par, TNodeColumn()));
2691 u2nn->second.push_back( u_n->second );
2693 prevEndNodes[0] = sortedBaseNN.begin()->second;
2694 prevEndNodes[1] = sortedBaseNN.rbegin()->second;
2696 if ( theParam2ColumnMap.size() < 2 )
2701 size_t prevNbRows = theParam2ColumnMap.begin()->second.size(); // current, at least 1 here
2702 size_t expectNbRows = faceSubMesh->NbElements() / ( theParam2ColumnMap.size()-1 ); // to be added
2704 // fill theParam2ColumnMap column by column by passing from nodes on
2705 // theBaseEdge up via mesh faces on theFace
2707 TParam2ColumnMap::iterator par_nVec_1, par_nVec_2;
2708 par_nVec_2 = theParam2ColumnMap.begin();
2709 par_nVec_1 = par_nVec_2++;
2710 TIDSortedElemSet emptySet, avoidSet;
2711 for ( ; par_nVec_2 != theParam2ColumnMap.end(); ++par_nVec_1, ++par_nVec_2 )
2713 vector<const SMDS_MeshNode*>& nCol1 = par_nVec_1->second;
2714 vector<const SMDS_MeshNode*>& nCol2 = par_nVec_2->second;
2715 nCol1.resize( prevNbRows + expectNbRows );
2716 nCol2.resize( prevNbRows + expectNbRows );
2718 int i1, i2; size_t foundNbRows = 0;
2719 const SMDS_MeshNode *n1 = nCol1[ prevNbRows-1 ];
2720 const SMDS_MeshNode *n2 = nCol2[ prevNbRows-1 ];
2721 // find face sharing node n1 and n2 and belonging to faceSubMesh
2722 while ( const SMDS_MeshElement* face =
2723 SMESH_MeshAlgos::FindFaceInSet( n1, n2, emptySet, avoidSet, &i1, &i2))
2725 if ( faceSubMesh->Contains( face ))
2727 int nbNodes = face->NbCornerNodes();
2730 if ( foundNbRows + 1 > expectNbRows )
2732 n1 = face->GetNode( (i2+2) % 4 ); // opposite corner of quadrangle face
2733 n2 = face->GetNode( (i1+2) % 4 );
2734 nCol1[ prevNbRows + foundNbRows] = n1;
2735 nCol2[ prevNbRows + foundNbRows] = n2;
2738 avoidSet.insert( face );
2740 if ((size_t) foundNbRows != expectNbRows )
2744 return ( theParam2ColumnMap.size() > 1 &&
2745 theParam2ColumnMap.begin()->second.size() == prevNbRows + expectNbRows );
2750 //================================================================================
2752 * \brief Return true if a node is at a corner of a 2D structured mesh of FACE
2754 //================================================================================
2756 bool isCornerOfStructure( const SMDS_MeshNode* n,
2757 const SMESHDS_SubMesh* faceSM,
2758 SMESH_MesherHelper& faceAnalyser )
2760 int nbFacesInSM = 0;
2762 SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator( SMDSAbs_Face );
2763 while ( fIt->more() )
2764 nbFacesInSM += faceSM->Contains( fIt->next() );
2766 if ( nbFacesInSM == 1 )
2769 if ( nbFacesInSM == 2 && n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
2771 return faceAnalyser.IsRealSeam( n->getshapeId() );
2777 //=======================================================================
2778 //function : IsStructured
2779 //purpose : Return true if 2D mesh on FACE is a structured rectangle
2780 //=======================================================================
2782 bool SMESH_MesherHelper::IsStructured( SMESH_subMesh* faceSM )
2784 SMESHDS_SubMesh* fSM = faceSM->GetSubMeshDS();
2785 if ( !fSM || fSM->NbElements() == 0 )
2788 list< TopoDS_Edge > edges;
2789 list< int > nbEdgesInWires;
2790 int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( faceSM->GetSubShape() ),
2791 edges, nbEdgesInWires );
2792 if ( nbWires != 1 /*|| nbEdgesInWires.front() != 4*/ ) // allow composite sides
2795 // algo: find corners of a structure and then analyze nb of faces and
2796 // length of structure sides
2798 SMESHDS_Mesh* meshDS = faceSM->GetFather()->GetMeshDS();
2799 SMESH_MesherHelper faceAnalyser( *faceSM->GetFather() );
2800 faceAnalyser.SetSubShape( faceSM->GetSubShape() );
2802 // rotate edges to get the first node being at corner
2803 // (in principle it's not necessary because so far none SALOME algo can make
2804 // such a structured mesh that all corner nodes are not on VERTEXes)
2805 bool isCorner = false;
2806 int nbRemainEdges = nbEdgesInWires.front();
2808 TopoDS_Vertex V = IthVertex( 0, edges.front() );
2809 isCorner = isCornerOfStructure( SMESH_Algo::VertexNode( V, meshDS ),
2812 edges.splice( edges.end(), edges, edges.begin() );
2816 while ( !isCorner && nbRemainEdges > 0 );
2821 // get all nodes from EDGEs
2822 list< const SMDS_MeshNode* > nodes;
2823 list< TopoDS_Edge >::iterator edge = edges.begin();
2824 for ( ; edge != edges.end(); ++edge )
2826 map< double, const SMDS_MeshNode* > u2Nodes;
2827 if ( !SMESH_Algo::GetSortedNodesOnEdge( meshDS, *edge,
2828 /*skipMedium=*/true, u2Nodes ))
2831 list< const SMDS_MeshNode* > edgeNodes;
2832 map< double, const SMDS_MeshNode* >::iterator u2n = u2Nodes.begin();
2833 for ( ; u2n != u2Nodes.end(); ++u2n )
2834 edgeNodes.push_back( u2n->second );
2835 if ( edge->Orientation() == TopAbs_REVERSED )
2836 edgeNodes.reverse();
2838 if ( !nodes.empty() && nodes.back() == edgeNodes.front() )
2839 edgeNodes.pop_front();
2840 nodes.splice( nodes.end(), edgeNodes, edgeNodes.begin(), edgeNodes.end() );
2843 // get length of structured sides
2844 vector<int> nbEdgesInSide;
2846 list< const SMDS_MeshNode* >::iterator n = ++nodes.begin();
2847 for ( ; n != nodes.end(); ++n )
2850 if ( isCornerOfStructure( *n, fSM, faceAnalyser )) {
2851 nbEdgesInSide.push_back( nbEdges );
2857 if ( nbEdgesInSide.size() != 4 )
2859 if ( nbEdgesInSide[0] != nbEdgesInSide[2] )
2861 if ( nbEdgesInSide[1] != nbEdgesInSide[3] )
2863 if ( nbEdgesInSide[0] * nbEdgesInSide[1] != fSM->NbElements() )
2869 //=======================================================================
2870 //function : IsDistorted2D
2871 //purpose : Return true if 2D mesh on FACE is ditorted
2872 //=======================================================================
2874 bool SMESH_MesherHelper::IsDistorted2D( SMESH_subMesh* faceSM,
2876 SMESH_MesherHelper* faceHelper)
2878 if ( !faceSM || faceSM->GetSubShape().ShapeType() != TopAbs_FACE )
2881 bool haveBadFaces = false;
2883 SMESH_MesherHelper helper( *faceSM->GetFather() );
2885 helper.CopySubShapeInfo( *faceHelper );
2886 helper.SetSubShape( faceSM->GetSubShape() );
2888 const TopoDS_Face& F = TopoDS::Face( faceSM->GetSubShape() );
2889 SMESHDS_SubMesh* smDS = helper.GetMeshDS()->MeshElements( F );
2890 if ( !smDS || smDS->NbElements() == 0 ) return false;
2892 bool subIdsValid = true; // shape ID of nodes is OK
2893 if ( helper.HasSeam() )
2895 // check if nodes are bound to seam edges
2896 SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(/*includeSelf=*/false);
2897 while ( smIt->more() && subIdsValid )
2899 SMESH_subMesh* sm = smIt->next();
2900 if ( helper.IsSeamShape( sm->GetId() ) && sm->IsEmpty() )
2901 subIdsValid = false;
2904 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
2905 double prevArea = 0;
2906 vector< const SMDS_MeshNode* > nodes;
2908 bool* toCheckUV = checkUV ? & checkUV : 0;
2909 while ( faceIt->more() && !haveBadFaces )
2911 const SMDS_MeshElement* face = faceIt->next();
2914 nodes.resize( face->NbCornerNodes() );
2915 SMDS_MeshElement::iterator n = face->begin_nodes();
2916 for ( size_t i = 0; i < nodes.size(); ++n, ++i )
2919 // avoid elems on degenerate shapes as UV on them can be wrong
2920 if ( helper.HasDegeneratedEdges() )
2922 bool isOnDegen = false;
2923 for ( size_t i = 0; ( i < nodes.size() && !isOnDegen ); ++i )
2924 isOnDegen = helper.IsDegenShape( nodes[ i ]->getshapeId() );
2928 // prepare for getting UVs
2929 const SMDS_MeshNode* inFaceNode = 0;
2930 if ( helper.HasSeam() ) {
2931 for ( size_t i = 0; ( i < nodes.size() && !inFaceNode ); ++i )
2932 if ( !helper.IsSeamShape( nodes[ i ]->getshapeId() ))
2934 inFaceNode = nodes[ i ];
2937 gp_XY uv = helper.GetNodeUV( F, inFaceNode );
2938 if ( helper.IsOnSeam( uv ))
2946 uv.resize( nodes.size() );
2947 for ( size_t i = 0; i < nodes.size(); ++i )
2948 uv[ i ] = helper.GetNodeUV( F, nodes[ i ], inFaceNode, toCheckUV );
2950 if ( !subIdsValid ) // fix uv on seam
2952 gp_XY uvInFace = helper.GetNodeUV( F, inFaceNode );
2953 for ( size_t i = 0; i < uv.size(); ++i )
2954 if ( helper.IsOnSeam( uv[i] ))
2955 uv[i] = helper.getUVOnSeam( uv[i], uvInFace ).XY();
2958 // compare orientation of triangles
2959 double faceArea = 0;
2960 for ( int iT = 0, nbT = nodes.size()-2; iT < nbT; ++iT )
2962 gp_XY v1 = uv[ iT+1 ] - uv[ 0 ];
2963 gp_XY v2 = uv[ iT+2 ] - uv[ 0 ];
2964 faceArea += v2 ^ v1;
2966 haveBadFaces = ( faceArea * prevArea < 0 );
2967 prevArea = faceArea;
2970 return haveBadFaces;
2973 //================================================================================
2975 * \brief Find out elements orientation on a geometrical face
2976 * \param theFace - The face correctly oriented in the shape being meshed
2977 * \retval bool - true if the face normal and the normal of first element
2978 * in the corresponding submesh point in different directions
2980 //================================================================================
2982 bool SMESH_MesherHelper::IsReversedSubMesh (const TopoDS_Face& theFace)
2984 if ( theFace.IsNull() )
2987 // find out orientation of a meshed face
2988 int faceID = GetMeshDS()->ShapeToIndex( theFace );
2989 TopoDS_Shape aMeshedFace = GetMeshDS()->IndexToShape( faceID );
2990 bool isReversed = ( theFace.Orientation() != aMeshedFace.Orientation() );
2992 const SMESHDS_SubMesh * aSubMeshDSFace = GetMeshDS()->MeshElements( faceID );
2993 if ( !aSubMeshDSFace )
2996 // find an element on a bounday of theFace
2997 SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
2998 const SMDS_MeshNode* nn[2];
2999 while ( iteratorElem->more() ) // loop on elements on theFace
3001 const SMDS_MeshElement* elem = iteratorElem->next();
3002 if ( ! elem ) continue;
3004 // look for 2 nodes on EDGE
3005 int nbNodes = elem->NbCornerNodes();
3006 nn[0] = elem->GetNode( nbNodes-1 );
3007 for ( int iN = 0; iN < nbNodes; ++iN )
3009 nn[1] = elem->GetNode( iN );
3010 if ( nn[0]->GetPosition()->GetDim() < 2 &&
3011 nn[1]->GetPosition()->GetDim() < 2 )
3013 TopoDS_Shape s0 = GetSubShapeByNode( nn[0], GetMeshDS() );
3014 TopoDS_Shape s1 = GetSubShapeByNode( nn[1], GetMeshDS() );
3015 TopoDS_Shape E = GetCommonAncestor( s0, s1, *myMesh, TopAbs_EDGE );
3016 if ( !E.IsNull() && !s0.IsSame( s1 ) && E.Orientation() != TopAbs_INTERNAL )
3020 for ( TopExp_Explorer exp( theFace, TopAbs_EDGE ); exp.More(); exp.Next() )
3021 if ( E.IsSame( exp.Current() )) {
3023 E = exp.Current(); // to know orientation
3028 double u0 = GetNodeU( TopoDS::Edge( E ), nn[0], nn[1], &ok );
3029 double u1 = GetNodeU( TopoDS::Edge( E ), nn[1], nn[0], &ok );
3032 // check that the 2 nodes are connected with a segment (IPAL53055)
3034 const SMDS_MeshElement* seg;
3035 if ( SMESHDS_SubMesh* sm = GetMeshDS()->MeshElements( E ))
3036 if (( sm->NbElements() > 0 ) &&
3037 ( seg = GetMeshDS()->FindEdge( nn[0], nn[1] )))
3038 ok = sm->Contains( seg );
3042 isReversed = ( u0 > u1 );
3043 if ( E.Orientation() == TopAbs_REVERSED )
3044 isReversed = !isReversed;
3054 // find an element with a good normal
3056 bool normalOK = false;
3058 iteratorElem = aSubMeshDSFace->GetElements();
3059 while ( !normalOK && iteratorElem->more() ) // loop on elements on theFace
3061 const SMDS_MeshElement* elem = iteratorElem->next();
3062 if ( ! SMESH_MeshAlgos::FaceNormal( elem, const_cast<gp_XYZ&>( Ne.XYZ() ), /*normalized=*/0 ))
3066 // get UV of a node inside theFACE
3067 SMDS_ElemIteratorPtr nodesIt = elem->nodesIterator();
3068 const SMDS_MeshNode* nInFace = 0;
3069 int iPosDim = SMDS_TOP_VERTEX;
3070 while ( nodesIt->more() ) // loop on nodes
3072 const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>( nodesIt->next() );
3073 if ( n->GetPosition()->GetTypeOfPosition() >= iPosDim )
3076 iPosDim = n->GetPosition()->GetTypeOfPosition();
3079 uv = GetNodeUV( theFace, nInFace, 0, &normalOK );
3084 // face normal at node position
3085 TopLoc_Location loc;
3086 Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc );
3087 // if ( surf.IsNull() || surf->Continuity() < GeomAbs_C1 )
3088 // some surfaces not detected as GeomAbs_C1 are nevertheless correct for meshing
3089 if ( surf.IsNull() || surf->Continuity() < GeomAbs_C0 )
3092 gp_Vec d1u, d1v; gp_Pnt p;
3093 surf->D1( uv.X(), uv.Y(), p, d1u, d1v );
3094 gp_Vec Nf = (d1u ^ d1v).Transformed( loc );
3096 if ( theFace.Orientation() == TopAbs_REVERSED )
3099 return Ne * Nf < 0.;
3102 //=======================================================================
3104 //purpose : Count nb of sub-shapes
3105 //=======================================================================
3107 int SMESH_MesherHelper::Count(const TopoDS_Shape& shape,
3108 const TopAbs_ShapeEnum type,
3109 const bool ignoreSame)
3112 TopTools_IndexedMapOfShape map;
3113 TopExp::MapShapes( shape, type, map );
3114 return map.Extent();
3118 for ( TopExp_Explorer exp( shape, type ); exp.More(); exp.Next() )
3124 //=======================================================================
3125 //function : NbAncestors
3126 //purpose : Return number of unique ancestors of the shape
3127 //=======================================================================
3129 int SMESH_MesherHelper::NbAncestors(const TopoDS_Shape& shape,
3130 const SMESH_Mesh& mesh,
3131 TopAbs_ShapeEnum ancestorType/*=TopAbs_SHAPE*/)
3133 TopTools_MapOfShape ancestors;
3134 TopTools_ListIteratorOfListOfShape ansIt( mesh.GetAncestors(shape) );
3135 for ( ; ansIt.More(); ansIt.Next() ) {
3136 if ( ancestorType == TopAbs_SHAPE || ansIt.Value().ShapeType() == ancestorType )
3137 ancestors.Add( ansIt.Value() );
3139 return ancestors.Extent();
3142 //=======================================================================
3143 //function : GetSubShapeOri
3144 //purpose : Return orientation of sub-shape in the main shape
3145 //=======================================================================
3147 TopAbs_Orientation SMESH_MesherHelper::GetSubShapeOri(const TopoDS_Shape& shape,
3148 const TopoDS_Shape& subShape)
3150 TopAbs_Orientation ori = TopAbs_Orientation(-1);
3151 if ( !shape.IsNull() && !subShape.IsNull() )
3153 TopExp_Explorer e( shape, subShape.ShapeType() );
3154 if ( shape.Orientation() >= TopAbs_INTERNAL ) // TopAbs_INTERNAL or TopAbs_EXTERNAL
3155 e.Init( shape.Oriented(TopAbs_FORWARD), subShape.ShapeType() );
3156 for ( ; e.More(); e.Next())
3157 if ( subShape.IsSame( e.Current() ))
3160 ori = e.Current().Orientation();
3165 //=======================================================================
3166 //function : IsSubShape
3168 //=======================================================================
3170 bool SMESH_MesherHelper::IsSubShape( const TopoDS_Shape& shape,
3171 const TopoDS_Shape& mainShape )
3173 if ( !shape.IsNull() && !mainShape.IsNull() )
3175 for ( TopExp_Explorer exp( mainShape, shape.ShapeType());
3178 if ( shape.IsSame( exp.Current() ))
3184 //=======================================================================
3185 //function : IsSubShape
3187 //=======================================================================
3189 bool SMESH_MesherHelper::IsSubShape( const TopoDS_Shape& shape, SMESH_Mesh* aMesh )
3191 if ( shape.IsNull() || !aMesh )
3194 aMesh->GetMeshDS()->ShapeToIndex( shape ) ||
3196 (shape.ShapeType() == TopAbs_COMPOUND && aMesh->GetMeshDS()->IsGroupOfSubShapes( shape ));
3199 //=======================================================================
3200 //function : IsBlock
3202 //=======================================================================
3204 bool SMESH_MesherHelper::IsBlock( const TopoDS_Shape& shape )
3206 if ( shape.IsNull() )
3210 TopExp_Explorer exp( shape, TopAbs_SHELL );
3211 if ( !exp.More() ) return false;
3212 shell = TopoDS::Shell( exp.Current() );
3213 if ( exp.Next(), exp.More() ) return false;
3216 TopTools_IndexedMapOfOrientedShape map;
3217 return SMESH_Block::FindBlockShapes( shell, v, v, map );
3221 //================================================================================
3223 * \brief Return maximal tolerance of shape
3225 //================================================================================
3227 double SMESH_MesherHelper::MaxTolerance( const TopoDS_Shape& shape )
3229 double tol = Precision::Confusion();
3230 TopExp_Explorer exp;
3231 for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
3232 tol = Max( tol, BRep_Tool::Tolerance( TopoDS::Face( exp.Current())));
3233 for ( exp.Init( shape, TopAbs_EDGE ); exp.More(); exp.Next() )
3234 tol = Max( tol, BRep_Tool::Tolerance( TopoDS::Edge( exp.Current())));
3235 for ( exp.Init( shape, TopAbs_VERTEX ); exp.More(); exp.Next() )
3236 tol = Max( tol, BRep_Tool::Tolerance( TopoDS::Vertex( exp.Current())));
3241 //================================================================================
3243 * \brief Return MaxTolerance( face ), probably cached
3245 //================================================================================
3247 double SMESH_MesherHelper::getFaceMaxTol( const TopoDS_Shape& face ) const
3249 int faceID = GetMeshDS()->ShapeToIndex( face );
3251 SMESH_MesherHelper* me = const_cast< SMESH_MesherHelper* >( this );
3252 double & tol = me->myFaceMaxTol.insert( make_pair( faceID, -1. )).first->second;
3254 tol = MaxTolerance( face );
3259 //================================================================================
3261 * \brief Return an angle between two EDGEs sharing a common VERTEX with reference
3262 * of the FACE normal
3263 * \return double - the angle (between -Pi and Pi), negative if the angle is concave,
3264 * 1e100 in case of failure
3265 * \warning Care about order of the EDGEs and their orientation to be as they are
3266 * within the FACE! Don't pass degenerated EDGEs neither!
3268 //================================================================================
3270 double SMESH_MesherHelper::GetAngle( const TopoDS_Edge & theE1,
3271 const TopoDS_Edge & theE2,
3272 const TopoDS_Face & theFace,
3273 const TopoDS_Vertex & theCommonV,
3274 gp_Vec* theFaceNormal)
3276 double angle = 1e100;
3280 Handle(Geom_Curve) c1 = BRep_Tool::Curve( theE1, f,l );
3281 Handle(Geom_Curve) c2 = BRep_Tool::Curve( theE2, f,l );
3282 Handle(Geom2d_Curve) c2d1 = BRep_Tool::CurveOnSurface( theE1, theFace, f,l );
3283 Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace );
3284 double p1 = BRep_Tool::Parameter( theCommonV, theE1 );
3285 double p2 = BRep_Tool::Parameter( theCommonV, theE2 );
3286 if ( c1.IsNull() || c2.IsNull() )
3288 gp_XY uv = c2d1->Value( p1 ).XY();
3289 gp_Vec du, dv; gp_Pnt p;
3290 surf->D1( uv.X(), uv.Y(), p, du, dv );
3291 gp_Vec vec1, vec2, vecRef = du ^ dv;
3294 while ( vecRef.SquareMagnitude() < 1e-25 )
3296 double dp = ( l - f ) / 1000.;
3297 p1tmp += dp * (( Abs( p1 - f ) > Abs( p1 - l )) ? -1. : +1.);
3298 uv = c2d1->Value( p1tmp ).XY();
3299 surf->D1( uv.X(), uv.Y(), p, du, dv );
3301 if ( ++nbLoops > 10 )
3304 cout << "SMESH_MesherHelper::GetAngle(): Captured in a sigularity" << endl;
3309 if ( theFace.Orientation() == TopAbs_REVERSED )
3311 if ( theFaceNormal ) *theFaceNormal = vecRef;
3313 c1->D1( p1, p, vec1 );
3314 c2->D1( p2, p, vec2 );
3315 // TopoDS_Face F = theFace;
3316 // if ( F.Orientation() == TopAbs_INTERNAL )
3317 // F.Orientation( TopAbs_FORWARD );
3318 if ( theE1.Orientation() /*GetSubShapeOri( F, theE1 )*/ == TopAbs_REVERSED )
3320 if ( theE2.Orientation() /*GetSubShapeOri( F, theE2 )*/ == TopAbs_REVERSED )
3322 angle = vec1.AngleWithRef( vec2, vecRef );
3324 if ( Abs ( angle ) >= 0.99 * M_PI )
3326 BRep_Tool::Range( theE1, f, l );
3327 p1 += 1e-7 * ( p1-f < l-p1 ? +1. : -1. );
3328 c1->D1( p1, p, vec1 );
3329 if ( theE1.Orientation() == TopAbs_REVERSED )
3331 BRep_Tool::Range( theE2, f, l );
3332 p2 += 1e-7 * ( p2-f < l-p2 ? +1. : -1. );
3333 c2->D1( p2, p, vec2 );
3334 if ( theE2.Orientation() == TopAbs_REVERSED )
3336 angle = vec1.AngleWithRef( vec2, vecRef );
3345 //================================================================================
3347 * \brief Check if the first and last vertices of an edge are the same
3348 * \param anEdge - the edge to check
3349 * \retval bool - true if same
3351 //================================================================================
3353 bool SMESH_MesherHelper::IsClosedEdge( const TopoDS_Edge& anEdge )
3355 if ( anEdge.Orientation() >= TopAbs_INTERNAL )
3356 return IsClosedEdge( TopoDS::Edge( anEdge.Oriented( TopAbs_FORWARD )));
3357 return TopExp::FirstVertex( anEdge ).IsSame( TopExp::LastVertex( anEdge ));
3360 //================================================================================
3362 * \brief Wrapper over TopExp::FirstVertex() and TopExp::LastVertex() fixing them
3363 * in the case of INTERNAL edge
3365 //================================================================================
3367 TopoDS_Vertex SMESH_MesherHelper::IthVertex( const bool is2nd,
3371 if ( anEdge.Orientation() >= TopAbs_INTERNAL )
3372 anEdge.Orientation( TopAbs_FORWARD );
3374 const TopAbs_Orientation tgtOri = is2nd ? TopAbs_REVERSED : TopAbs_FORWARD;
3375 TopoDS_Iterator vIt( anEdge, CumOri );
3376 while ( vIt.More() && vIt.Value().Orientation() != tgtOri )
3379 return ( vIt.More() ? TopoDS::Vertex(vIt.Value()) : TopoDS_Vertex() );
3382 //================================================================================
3384 * \brief Return type of shape contained in a group
3385 * \param group - a shape of type TopAbs_COMPOUND
3386 * \param avoidCompound - not to return TopAbs_COMPOUND
3388 //================================================================================
3390 TopAbs_ShapeEnum SMESH_MesherHelper::GetGroupType(const TopoDS_Shape& group,
3391 const bool avoidCompound)
3393 if ( !group.IsNull() )
3395 if ( group.ShapeType() != TopAbs_COMPOUND )
3396 return group.ShapeType();
3398 // iterate on a compound
3399 TopoDS_Iterator it( group );
3401 return avoidCompound ? GetGroupType( it.Value() ) : it.Value().ShapeType();
3403 return TopAbs_SHAPE;
3406 //================================================================================
3408 * \brief Returns a shape, to which a hypothesis used to mesh a given shape is assigned
3409 * \param [in] hyp - the hypothesis
3410 * \param [in] shape - the shape, for meshing which the \a hyp is used
3411 * \param [in] mesh - the mesh
3412 * \return TopoDS_Shape - the shape the \a hyp is assigned to
3414 //================================================================================
3416 TopoDS_Shape SMESH_MesherHelper::GetShapeOfHypothesis( const SMESHDS_Hypothesis * hyp,
3417 const TopoDS_Shape& shape,
3420 const SMESH_Hypothesis* h = static_cast<const SMESH_Hypothesis*>( hyp );
3421 SMESH_HypoFilter hypFilter( SMESH_HypoFilter::Is( h ));
3423 TopoDS_Shape shapeOfHyp;
3424 mesh->GetHypothesis( shape, hypFilter, /*checkAncestors=*/true, &shapeOfHyp );
3428 //=======================================================================
3429 //function : IsQuadraticMesh
3430 //purpose : Check mesh without geometry for: if all elements on this shape are quadratic,
3431 // quadratic elements will be created.
3432 // Used then generated 3D mesh without geometry.
3433 //=======================================================================
3435 SMESH_MesherHelper:: MType SMESH_MesherHelper::IsQuadraticMesh()
3437 int NbAllEdgsAndFaces=0;
3438 int NbQuadFacesAndEdgs=0;
3439 int NbFacesAndEdges=0;
3440 //All faces and edges
3441 NbAllEdgsAndFaces = myMesh->NbEdges() + myMesh->NbFaces();
3442 if ( NbAllEdgsAndFaces == 0 )
3443 return SMESH_MesherHelper::LINEAR;
3445 //Quadratic faces and edges
3446 NbQuadFacesAndEdgs = myMesh->NbEdges(ORDER_QUADRATIC) + myMesh->NbFaces(ORDER_QUADRATIC);
3448 //Linear faces and edges
3449 NbFacesAndEdges = myMesh->NbEdges(ORDER_LINEAR) + myMesh->NbFaces(ORDER_LINEAR);
3451 if (NbAllEdgsAndFaces == NbQuadFacesAndEdgs) {
3453 return SMESH_MesherHelper::QUADRATIC;
3455 else if (NbAllEdgsAndFaces == NbFacesAndEdges) {
3457 return SMESH_MesherHelper::LINEAR;
3460 //Mesh with both type of elements
3461 return SMESH_MesherHelper::COMP;
3464 //=======================================================================
3465 //function : GetOtherParam
3466 //purpose : Return an alternative parameter for a node on seam
3467 //=======================================================================
3469 double SMESH_MesherHelper::GetOtherParam(const double param) const
3471 int i = myParIndex & U_periodic ? 0 : 1;
3472 return fabs(param-myPar1[i]) < fabs(param-myPar2[i]) ? myPar2[i] : myPar1[i];
3475 //=======================================================================
3476 //function : NbRealSeam
3477 //purpose : Return a number of real seam edges in the shape set through
3478 // IsQuadraticSubMesh() or SetSubShape(). A real seam edge encounters twice in a wire
3479 //=======================================================================
3481 size_t SMESH_MesherHelper::NbRealSeam() const
3485 std::set< int >::const_iterator id = mySeamShapeIds.begin();
3486 for ( ; id != mySeamShapeIds.end(); ++id )
3487 if ( *id < 0 ) ++nb;
3493 //=======================================================================
3494 //function : IsOnSeam
3495 //purpose : Check if UV is on seam. Return 0 if not, 1 for U seam, 2 for V seam
3496 //=======================================================================
3498 int SMESH_MesherHelper::IsOnSeam(const gp_XY& uv) const
3500 for ( int i = U_periodic; i <= V_periodic ; ++i )
3501 if ( myParIndex & i )
3503 double p = uv.Coord( i );
3504 double tol = ( myPar2[i-1] - myPar1[i-1] ) / 100.;
3505 if ( Abs( p - myPar1[i-1] ) < tol ||
3506 Abs( p - myPar2[i-1] ) < tol )
3514 //=======================================================================
3516 * \brief Iterator on ancestors of the given type
3518 //=======================================================================
3520 struct TAncestorsIterator : public SMDS_Iterator<const TopoDS_Shape*>
3522 TopTools_ListIteratorOfListOfShape _ancIter;
3523 TopAbs_ShapeEnum _type;
3524 TopTools_MapOfShape _encountered;
3525 TopTools_IndexedMapOfShape _allowed;
3526 TAncestorsIterator( const TopTools_ListOfShape& ancestors,
3527 TopAbs_ShapeEnum type,
3528 const TopoDS_Shape* container/* = 0*/)
3529 : _ancIter( ancestors ), _type( type )
3531 if ( container && !container->IsNull() )
3532 TopExp::MapShapes( *container, type, _allowed);
3533 if ( _ancIter.More() ) {
3534 if ( !isCurrentAllowed() ) next();
3535 else _encountered.Add( _ancIter.Value() );
3540 return _ancIter.More();
3542 virtual const TopoDS_Shape* next()
3544 const TopoDS_Shape* s = _ancIter.More() ? & _ancIter.Value() : 0;
3545 if ( _ancIter.More() )
3546 for ( _ancIter.Next(); _ancIter.More(); _ancIter.Next())
3547 if ( isCurrentAllowed() && _encountered.Add( _ancIter.Value() ))
3551 bool isCurrentAllowed()
3553 return (( _ancIter.Value().ShapeType() == _type ) &&
3554 ( _allowed.IsEmpty() || _allowed.Contains( _ancIter.Value() )));
3560 //=======================================================================
3562 * \brief Return iterator on ancestors of the given type, included into a container shape
3564 //=======================================================================
3566 PShapeIteratorPtr SMESH_MesherHelper::GetAncestors(const TopoDS_Shape& shape,
3567 const SMESH_Mesh& mesh,
3568 TopAbs_ShapeEnum ancestorType,
3569 const TopoDS_Shape* container)
3571 return PShapeIteratorPtr
3572 ( new TAncestorsIterator( mesh.GetAncestors(shape), ancestorType, container));
3575 //=======================================================================
3576 //function : GetCommonAncestor
3577 //purpose : Find a common ancestors of two shapes of the given type
3578 //=======================================================================
3580 TopoDS_Shape SMESH_MesherHelper::GetCommonAncestor(const TopoDS_Shape& shape1,
3581 const TopoDS_Shape& shape2,
3582 const SMESH_Mesh& mesh,
3583 TopAbs_ShapeEnum ancestorType)
3585 TopoDS_Shape commonAnc;
3586 if ( !shape1.IsNull() && !shape2.IsNull() )
3588 if ( shape1.ShapeType() == ancestorType && IsSubShape( shape2, shape1 ))
3590 if ( shape2.ShapeType() == ancestorType && IsSubShape( shape1, shape2 ))
3593 PShapeIteratorPtr ancIt = GetAncestors( shape1, mesh, ancestorType );
3594 while ( const TopoDS_Shape* anc = ancIt->next() )
3595 if ( IsSubShape( shape2, *anc ))
3604 //#include <Perf_Meter.hxx>
3606 //=======================================================================
3607 namespace { // Structures used by FixQuadraticElements()
3608 //=======================================================================
3610 #define __DMP__(txt) \
3612 #define MSG(txt) __DMP__(txt<<endl)
3613 #define MSGBEG(txt) __DMP__(txt)
3615 //const double straightTol2 = 1e-33; // to detect straing links
3616 bool isStraightLink(double linkLen2, double middleNodeMove2)
3618 // straight if <node move> < 1/15 * <link length>
3619 return middleNodeMove2 < 1/15./15. * linkLen2;
3623 // ---------------------------------------
3625 * \brief Quadratic link knowing its faces
3627 struct QLink: public SMESH_TLink
3629 const SMDS_MeshNode* _mediumNode;
3630 mutable vector<const QFace* > _faces;
3631 mutable gp_Vec _nodeMove;
3632 mutable int _nbMoves;
3633 mutable bool _is2dFixed; // is moved along surface or in 3D
3635 QLink(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2, const SMDS_MeshNode* nm):
3636 SMESH_TLink( n1,n2 ), _mediumNode(nm), _nodeMove(0,0,0), _nbMoves(0) {
3638 _nodeMove = MediumPnt() - MiddlePnt();
3639 _is2dFixed = ( MediumPos() != SMDS_TOP_FACE );
3641 void SetContinuesFaces() const;
3642 const QFace* GetContinuesFace( const QFace* face ) const;
3643 bool OnBoundary() const;
3644 gp_XYZ MiddlePnt() const { return ( XYZ( node1() ) + XYZ( node2() )) / 2.; }
3645 gp_XYZ MediumPnt() const { return XYZ( _mediumNode ); }
3647 SMDS_TypeOfPosition MediumPos() const
3648 { return _mediumNode->GetPosition()->GetTypeOfPosition(); }
3649 SMDS_TypeOfPosition EndPos(bool isSecond) const
3650 { return (isSecond ? node2() : node1())->GetPosition()->GetTypeOfPosition(); }
3651 const SMDS_MeshNode* EndPosNode(SMDS_TypeOfPosition pos) const
3652 { return EndPos(0) == pos ? node1() : EndPos(1) == pos ? node2() : 0; }
3654 void Move(const gp_Vec& move, bool sum=false, bool is2dFixed=false) const
3655 { _nodeMove += move; _nbMoves += sum ? (_nbMoves==0) : 1; _is2dFixed |= is2dFixed; }
3656 gp_XYZ Move() const { return _nodeMove.XYZ() / _nbMoves; }
3657 bool IsMoved() const { return (_nbMoves > 0 /*&& !IsStraight()*/); }
3658 bool IsFixedOnSurface() const { return _is2dFixed; }
3659 bool IsStraight() const
3660 { return isStraightLink( (XYZ(node1())-XYZ(node2())).SquareModulus(),
3661 _nodeMove.SquareMagnitude());
3663 bool operator<(const QLink& other) const {
3664 return (node1()->GetID() == other.node1()->GetID() ?
3665 node2()->GetID() < other.node2()->GetID() :
3666 node1()->GetID() < other.node1()->GetID());
3668 // struct PtrComparator {
3669 // bool operator() (const QLink* l1, const QLink* l2 ) const { return *l1 < *l2; }
3672 // ---------------------------------------------------------
3674 * \brief Link in the chain of links; it connects two faces
3678 const QLink* _qlink;
3679 mutable const QFace* _qfaces[2];
3681 TChainLink(const QLink* qlink=0):_qlink(qlink) {
3682 _qfaces[0] = _qfaces[1] = 0;
3684 void SetFace(const QFace* face) const { int iF = _qfaces[0] ? 1 : 0; _qfaces[iF]=face; }
3686 bool IsBoundary() const { return !_qfaces[1]; }
3688 void RemoveFace( const QFace* face ) const
3689 { _qfaces[(face == _qfaces[1])] = 0; if (!_qfaces[0]) std::swap(_qfaces[0],_qfaces[1]); }
3691 const QFace* NextFace( const QFace* f ) const
3692 { return _qfaces[0]==f ? _qfaces[1] : _qfaces[0]; }
3694 const SMDS_MeshNode* NextNode( const SMDS_MeshNode* n ) const
3695 { return n == _qlink->node1() ? _qlink->node2() : _qlink->node1(); }
3697 bool operator<(const TChainLink& other) const { return *_qlink < *other._qlink; }
3699 operator bool() const { return (_qlink); }
3701 const QLink* operator->() const { return _qlink; }
3703 gp_Vec Normal() const;
3705 bool IsStraight() const;
3707 // --------------------------------------------------------------------
3708 typedef list< TChainLink > TChain;
3709 typedef set < TChainLink > TLinkSet;
3710 typedef TLinkSet::const_iterator TLinkInSet;
3712 const int theFirstStep = 5;
3714 enum { ERR_OK, ERR_TRI, ERR_PRISM, ERR_UNKNOWN }; // errors of QFace::GetLinkChain()
3715 // --------------------------------------------------------------------
3717 * \brief Quadratic face shared by two volumes and bound by QLinks
3719 struct QFace: public TIDSortedNodeSet
3721 mutable const SMDS_MeshElement* _volumes[2];
3722 mutable vector< const QLink* > _sides;
3723 mutable bool _sideIsAdded[4]; // added in chain of links
3726 mutable const SMDS_MeshElement* _face;
3729 QFace( const vector< const QLink*>& links, const SMDS_MeshElement* face=0 );
3731 void SetVolume(const SMDS_MeshElement* v) const { _volumes[ _volumes[0] ? 1 : 0 ] = v; }
3733 int NbVolumes() const { return !_volumes[0] ? 0 : !_volumes[1] ? 1 : 2; }
3735 void AddSelfToLinks() const {
3736 for ( size_t i = 0; i < _sides.size(); ++i )
3737 _sides[i]->_faces.push_back( this );
3739 int LinkIndex( const QLink* side ) const {
3740 for (size_t i = 0; i<_sides.size(); ++i ) if ( _sides[i] == side ) return i;
3743 bool GetLinkChain( int iSide, TChain& chain, SMDS_TypeOfPosition pos, int& err) const;
3745 bool GetLinkChain( TChainLink& link, TChain& chain, SMDS_TypeOfPosition pos, int& err) const
3747 int i = LinkIndex( link._qlink );
3748 if ( i < 0 ) return true;
3749 _sideIsAdded[i] = true;
3750 link.SetFace( this );
3751 // continue from opposite link
3752 return GetLinkChain( (i+2)%_sides.size(), chain, pos, err );
3754 bool IsBoundary() const { return !_volumes[1]; }
3756 bool Contains( const SMDS_MeshNode* node ) const { return count(node); }
3758 bool IsSpoiled(const QLink* bentLink ) const;
3760 TLinkInSet GetBoundaryLink( const TLinkSet& links,
3761 const TChainLink& avoidLink,
3762 TLinkInSet * notBoundaryLink = 0,
3763 const SMDS_MeshNode* nodeToContain = 0,
3764 bool * isAdjacentUsed = 0,
3765 int nbRecursionsLeft = -1) const;
3767 TLinkInSet GetLinkByNode( const TLinkSet& links,
3768 const TChainLink& avoidLink,
3769 const SMDS_MeshNode* nodeToContain) const;
3771 const SMDS_MeshNode* GetNodeInFace() const {
3772 for ( size_t iL = 0; iL < _sides.size(); ++iL )
3773 if ( _sides[iL]->MediumPos() == SMDS_TOP_FACE ) return _sides[iL]->_mediumNode;
3777 gp_Vec LinkNorm(const int i, SMESH_MesherHelper* theFaceHelper=0) const;
3779 double MoveByBoundary( const TChainLink& theLink,
3780 const gp_Vec& theRefVec,
3781 const TLinkSet& theLinks,
3782 SMESH_MesherHelper* theFaceHelper=0,
3783 const double thePrevLen=0,
3784 const int theStep=theFirstStep,
3785 gp_Vec* theLinkNorm=0,
3786 double theSign=1.0) const;
3789 //================================================================================
3791 * \brief Dump QLink and QFace
3793 ostream& operator << (ostream& out, const QLink& l)
3795 out <<"QLink nodes: "
3796 << l.node1()->GetID() << " - "
3797 << l._mediumNode->GetID() << " - "
3798 << l.node2()->GetID() << endl;
3801 ostream& operator << (ostream& out, const QFace& f)
3803 out <<"QFace nodes: "/*<< &f << " "*/;
3804 for ( TIDSortedNodeSet::const_iterator n = f.begin(); n != f.end(); ++n )
3805 out << (*n)->GetID() << " ";
3806 out << " \tvolumes: "
3807 << (f._volumes[0] ? f._volumes[0]->GetID() : 0) << " "
3808 << (f._volumes[1] ? f._volumes[1]->GetID() : 0);
3809 out << " \tNormal: "<< f._normal.X() <<", "<<f._normal.Y() <<", "<<f._normal.Z() << endl;
3813 //================================================================================
3815 * \brief Construct QFace from QLinks
3817 //================================================================================
3819 QFace::QFace( const vector< const QLink*>& links, const SMDS_MeshElement* face )
3821 _volumes[0] = _volumes[1] = 0;
3823 _sideIsAdded[0]=_sideIsAdded[1]=_sideIsAdded[2]=_sideIsAdded[3]=false;
3824 _normal.SetCoord(0,0,0);
3825 for ( size_t i = 1; i < _sides.size(); ++i ) {
3826 const QLink *l1 = _sides[i-1], *l2 = _sides[i];
3827 insert( l1->node1() ); insert( l1->node2() );
3829 gp_Vec v1( XYZ( l1->node2()), XYZ( l1->node1()));
3830 gp_Vec v2( XYZ( l2->node1()), XYZ( l2->node2()));
3831 if ( l1->node1() != l2->node1() && l1->node2() != l2->node2() )
3835 double normSqSize = _normal.SquareMagnitude();
3836 if ( normSqSize > numeric_limits<double>::min() )
3837 _normal /= sqrt( normSqSize );
3839 _normal.SetCoord(1e-33,0,0);
3845 //================================================================================
3847 * \brief Make up a chain of links
3848 * \param iSide - link to add first
3849 * \param chain - chain to fill in
3850 * \param pos - position of medium nodes the links should have
3851 * \param error - out, specifies what is wrong
3852 * \retval bool - false if valid chain can't be built; "valid" means that links
3853 * of the chain belongs to rectangles bounding hexahedrons
3855 //================================================================================
3857 bool QFace::GetLinkChain( int iSide, TChain& chain, SMDS_TypeOfPosition pos, int& error) const
3859 if ( iSide >= (int)_sides.size() ) // wrong argument iSide
3861 if ( _sideIsAdded[ iSide ]) // already in chain
3864 if ( _sides.size() != 4 ) { // triangle - visit all my continuous faces
3867 list< const QFace* > faces( 1, this );
3868 while ( !faces.empty() ) {
3869 const QFace* face = faces.front();
3870 for ( size_t i = 0; i < face->_sides.size(); ++i ) {
3871 if ( !face->_sideIsAdded[i] && face->_sides[i] ) {
3872 face->_sideIsAdded[i] = true;
3873 // find a face side in the chain
3874 TLinkInSet chLink = links.insert( TChainLink(face->_sides[i])).first;
3875 // TChain::iterator chLink = chain.begin();
3876 // for ( ; chLink != chain.end(); ++chLink )
3877 // if ( chLink->_qlink == face->_sides[i] )
3879 // if ( chLink == chain.end() )
3880 // chLink = chain.insert( chain.begin(), TChainLink(face->_sides[i]));
3881 // add a face to a chained link and put a continues face in the queue
3882 chLink->SetFace( face );
3883 if ( face->_sides[i]->MediumPos() == pos )
3884 if ( const QFace* contFace = face->_sides[i]->GetContinuesFace( face ))
3885 if ( contFace->_sides.size() == 3 )
3886 faces.push_back( contFace );
3891 if ( error < ERR_TRI )
3893 chain.insert( chain.end(), links.begin(),links.end() );
3896 _sideIsAdded[iSide] = true; // not to add this link to chain again
3897 const QLink* link = _sides[iSide];
3901 // add link into chain
3902 TChain::iterator chLink = chain.insert( chain.begin(), TChainLink(link));
3903 chLink->SetFace( this );
3906 // propagate from a quadrangle to neighbour faces
3907 if ( link->MediumPos() >= pos ) {
3908 int nbLinkFaces = link->_faces.size();
3909 if ( nbLinkFaces == 4 || (/*nbLinkFaces < 4 && */link->OnBoundary())) {
3910 // hexahedral mesh or boundary quadrangles - goto a continuous face
3911 if ( const QFace* f = link->GetContinuesFace( this ))
3912 if ( f->_sides.size() == 4 )
3913 return f->GetLinkChain( *chLink, chain, pos, error );
3916 TChainLink chLink(link); // side face of prismatic mesh - visit all faces of iSide
3917 for ( int i = 0; i < nbLinkFaces; ++i )
3918 if ( link->_faces[i] )
3919 link->_faces[i]->GetLinkChain( chLink, chain, pos, error );
3920 if ( error < ERR_PRISM )
3928 //================================================================================
3930 * \brief Return a boundary link of the triangle face
3931 * \param links - set of all links
3932 * \param avoidLink - link not to return
3933 * \param notBoundaryLink - out, neither the returned link nor avoidLink
3934 * \param nodeToContain - node the returned link must contain; if provided, search
3935 * also performed on adjacent faces
3936 * \param isAdjacentUsed - returns true if link is found in adjacent faces
3937 * \param nbRecursionsLeft - to limit recursion
3939 //================================================================================
3941 TLinkInSet QFace::GetBoundaryLink( const TLinkSet& links,
3942 const TChainLink& avoidLink,
3943 TLinkInSet * notBoundaryLink,
3944 const SMDS_MeshNode* nodeToContain,
3945 bool * isAdjacentUsed,
3946 int nbRecursionsLeft) const
3948 TLinkInSet linksEnd = links.end(), boundaryLink = linksEnd;
3950 typedef list< pair< const QFace*, TLinkInSet > > TFaceLinkList;
3951 TFaceLinkList adjacentFaces;
3953 for ( size_t iL = 0; iL < _sides.size(); ++iL )
3955 if ( avoidLink._qlink == _sides[iL] )
3957 TLinkInSet link = links.find( _sides[iL] );
3958 if ( link == linksEnd ) continue;
3959 if ( (*link)->MediumPos() > SMDS_TOP_FACE )
3960 continue; // We work on faces here, don't go inside a solid
3963 if ( link->IsBoundary() ) {
3964 if ( !nodeToContain ||
3965 (*link)->node1() == nodeToContain ||
3966 (*link)->node2() == nodeToContain )
3968 boundaryLink = link;
3969 if ( !notBoundaryLink ) break;
3972 else if ( notBoundaryLink ) {
3973 *notBoundaryLink = link;
3974 if ( boundaryLink != linksEnd ) break;
3977 if ( boundaryLink == linksEnd && nodeToContain ) // collect adjacent faces
3978 if ( const QFace* adj = link->NextFace( this ))
3979 if ( adj->Contains( nodeToContain ))
3980 adjacentFaces.push_back( make_pair( adj, link ));
3983 if ( isAdjacentUsed ) *isAdjacentUsed = false;
3984 if ( boundaryLink == linksEnd && nodeToContain && nbRecursionsLeft) // check adjacent faces
3986 if ( nbRecursionsLeft < 0 )
3987 nbRecursionsLeft = nodeToContain->NbInverseElements();
3988 TFaceLinkList::iterator adj = adjacentFaces.begin();
3989 for ( ; boundaryLink == linksEnd && adj != adjacentFaces.end(); ++adj )
3990 boundaryLink = adj->first->GetBoundaryLink( links, *(adj->second), 0, nodeToContain,
3991 isAdjacentUsed, nbRecursionsLeft-1);
3992 if ( isAdjacentUsed ) *isAdjacentUsed = true;
3994 return boundaryLink;
3996 //================================================================================
3998 * \brief Return a link ending at the given node but not avoidLink
4000 //================================================================================
4002 TLinkInSet QFace::GetLinkByNode( const TLinkSet& links,
4003 const TChainLink& avoidLink,
4004 const SMDS_MeshNode* nodeToContain) const
4006 for ( size_t i = 0; i < _sides.size(); ++i )
4007 if ( avoidLink._qlink != _sides[i] &&
4008 (_sides[i]->node1() == nodeToContain || _sides[i]->node2() == nodeToContain ))
4009 return links.find( _sides[i] );
4013 //================================================================================
4015 * \brief Return normal to the i-th side pointing outside the face
4017 //================================================================================
4019 gp_Vec QFace::LinkNorm(const int i, SMESH_MesherHelper* /*uvHelper*/) const
4021 gp_Vec norm = _normal ^ gp_Vec( XYZ(_sides[i]->node1()), XYZ(_sides[i]->node2()));
4022 gp_XYZ pIn = ( _sides[ (i+1)%3 ]->MiddlePnt() +
4023 _sides[ (i+2)%3 ]->MiddlePnt() ) / 2.;
4024 gp_Vec vecOut = ( _sides[i]->MiddlePnt() - pIn );
4026 if ( norm * vecOut < 0 )
4028 double mag2 = norm.SquareMagnitude();
4029 if ( mag2 > numeric_limits<double>::min() )
4030 norm /= sqrt( mag2 );
4033 //================================================================================
4035 * \brief Move medium node of theLink according to its distance from boundary
4036 * \param theLink - link to fix
4037 * \param theRefVec - movement of boundary
4038 * \param theLinks - all adjacent links of continuous triangles
4039 * \param theFaceHelper - helper is not used so far
4040 * \param thePrevLen - distance from the boundary
4041 * \param theStep - number of steps till movement propagation limit
4042 * \param theLinkNorm - out normal to theLink
4043 * \param theSign - 1 or -1 depending on movement of boundary
4044 * \retval double - distance from boundary to propagation limit or other boundary
4046 //================================================================================
4048 double QFace::MoveByBoundary( const TChainLink& theLink,
4049 const gp_Vec& theRefVec,
4050 const TLinkSet& theLinks,
4051 SMESH_MesherHelper* theFaceHelper,
4052 const double thePrevLen,
4054 gp_Vec* theLinkNorm,
4055 double theSign) const
4058 return thePrevLen; // propagation limit reached
4060 size_t iL; // index of theLink
4061 for ( iL = 0; iL < _sides.size(); ++iL )
4062 if ( theLink._qlink == _sides[ iL ])
4065 MSG(string(theStep,'.')<<" Ref( "<<theRefVec.X()<<","<<theRefVec.Y()<<","<<theRefVec.Z()<<" )"
4066 <<" thePrevLen " << thePrevLen);
4067 MSG(string(theStep,'.')<<" "<<*theLink._qlink);
4069 gp_Vec linkNorm = -LinkNorm( iL/*, theFaceHelper*/ ); // normal to theLink
4070 double refProj = theRefVec * linkNorm; // project movement vector to normal of theLink
4071 if ( theStep == theFirstStep )
4072 theSign = refProj < 0. ? -1. : 1.;
4073 else if ( theSign * refProj < 0.4 * theRefVec.Magnitude())
4074 return thePrevLen; // to propagate movement forward only, not in side dir or backward
4076 int iL1 = (iL + 1) % 3, iL2 = (iL + 2) % 3; // indices of the two other links of triangle
4077 TLinkInSet link1 = theLinks.find( _sides[iL1] );
4078 TLinkInSet link2 = theLinks.find( _sides[iL2] );
4080 const QFace *f1 = 0, *f2 = 0; // adjacent faces
4081 bool isBndLink1 = true, isBndLink2 = true;
4082 if ( link1 != theLinks.end() && link2 != theLinks.end() )
4084 f1 = link1->NextFace( this );
4085 f2 = link2->NextFace( this );
4087 isBndLink1 = ( theLink->MediumPos() > (*link1)->MediumPos() );
4088 isBndLink2 = ( theLink->MediumPos() > (*link2)->MediumPos() );
4089 if ( theStep == theFirstStep ) // (issue 22541) quad-dominant mesh
4091 if ( !isBndLink1 && !f1 )
4092 f1 = (*link1)->GetContinuesFace( this ); // get a quadrangle face
4093 if ( !isBndLink2 && !f2 )
4094 f2 = (*link2)->GetContinuesFace( this );
4097 else if ( _sides.size() < 4 )
4100 // propagate to adjacent faces till limit step or boundary
4101 double len1 = thePrevLen + (theLink->MiddlePnt() - _sides[iL1]->MiddlePnt()).Modulus();
4102 double len2 = thePrevLen + (theLink->MiddlePnt() - _sides[iL2]->MiddlePnt()).Modulus();
4103 gp_Vec linkDir1(0,0,0); // initialize to avoid valgrind error ("Conditional jump...")
4104 gp_Vec linkDir2(0,0,0);
4107 if ( f1 && !isBndLink1 )
4108 len1 = f1->MoveByBoundary
4109 ( *link1, theRefVec, theLinks, theFaceHelper, len1, theStep-1, &linkDir1, theSign);
4111 linkDir1 = LinkNorm( iL1/*, theFaceHelper*/ );
4113 MSG( " --------------- EXCEPTION");
4118 if ( f2 && !isBndLink2 )
4119 len2 = f2->MoveByBoundary
4120 ( *link2, theRefVec, theLinks, theFaceHelper, len2, theStep-1, &linkDir2, theSign);
4122 linkDir2 = LinkNorm( iL2/*, theFaceHelper*/ );
4124 MSG( " --------------- EXCEPTION");
4129 if ( theStep != theFirstStep )
4131 // choose chain length by direction of propagation most codirected with theRefVec
4132 bool choose1 = ( theRefVec * linkDir1 * theSign > theRefVec * linkDir2 * theSign );
4133 fullLen = choose1 ? len1 : len2;
4134 double r = thePrevLen / fullLen;
4136 gp_Vec move = linkNorm * refProj * ( 1 - r );
4137 theLink->Move( move, /*sum=*/true );
4139 MSG(string(theStep,'.')<<" Move "<< theLink->_mediumNode->GetID()<<
4140 " by " << refProj * ( 1 - r ) << " following " <<
4141 (choose1 ? *link1->_qlink : *link2->_qlink)); // warning: link1 can be invalid
4143 if ( theLinkNorm ) *theLinkNorm = linkNorm;
4148 //================================================================================
4150 * \brief Checks if the face is distorted due to bentLink
4152 //================================================================================
4154 bool QFace::IsSpoiled(const QLink* bentLink ) const
4156 // code is valid for convex faces only
4158 for ( TIDSortedNodeSet::const_iterator n = begin(); n != end(); ++n )
4159 gc += XYZ( *n ) / double( size() );
4160 for ( size_t i = 0; i < _sides.size(); ++i )
4162 if ( _sides[i] == bentLink ) continue;
4163 gp_Vec linkNorm = _normal ^ gp_Vec( XYZ(_sides[i]->node1()), XYZ(_sides[i]->node2()));
4164 gp_Vec vecOut( gc, _sides[i]->MiddlePnt() );
4165 if ( linkNorm * vecOut < 0 )
4167 double mag2 = linkNorm.SquareMagnitude();
4168 if ( mag2 > numeric_limits<double>::min() )
4169 linkNorm /= sqrt( mag2 );
4170 gp_Vec vecBent ( _sides[i]->MiddlePnt(), bentLink->MediumPnt());
4171 gp_Vec vecStraight( _sides[i]->MiddlePnt(), bentLink->MiddlePnt());
4172 if ( vecBent * linkNorm > -0.1*vecStraight.Magnitude() )
4179 //================================================================================
4181 * \brief Find pairs of continues faces
4183 //================================================================================
4185 void QLink::SetContinuesFaces() const
4187 // x0 x - QLink, [-|] - QFace, v - volume
4189 // | Between _faces of link x2 two vertical faces are continues
4190 // x1----x2-----x3 and two horizontal faces are continues. We set vertical faces
4191 // | to _faces[0] and _faces[1] and horizontal faces to
4192 // v2 | v3 _faces[2] and _faces[3] (or vice versa).
4195 if ( _faces.empty() )
4197 int iFaceCont = -1, nbBoundary = 0, iBoundary[2]={-1,-1};
4198 if ( _faces[0]->IsBoundary() )
4199 iBoundary[ nbBoundary++ ] = 0;
4200 for ( size_t iF = 1; iFaceCont < 0 && iF < _faces.size(); ++iF )
4202 // look for a face bounding none of volumes bound by _faces[0]
4203 bool sameVol = false;
4204 int nbVol = _faces[iF]->NbVolumes();
4205 for ( int iV = 0; !sameVol && iV < nbVol; ++iV )
4206 sameVol = ( _faces[iF]->_volumes[iV] == _faces[0]->_volumes[0] ||
4207 _faces[iF]->_volumes[iV] == _faces[0]->_volumes[1]);
4210 if ( _faces[iF]->IsBoundary() )
4211 iBoundary[ nbBoundary++ ] = iF;
4213 // Set continues faces: arrange _faces to have
4214 // _faces[0] continues to _faces[1]
4215 // _faces[2] continues to _faces[3]
4216 if ( nbBoundary == 2 ) // bnd faces are continues
4218 if (( iBoundary[0] < 2 ) != ( iBoundary[1] < 2 ))
4220 int iNear0 = iBoundary[0] < 2 ? 1-iBoundary[0] : 5-iBoundary[0];
4221 std::swap( _faces[ iBoundary[1] ], _faces[iNear0] );
4224 else if ( iFaceCont > 0 ) // continues faces found
4226 if ( iFaceCont != 1 )
4227 std::swap( _faces[1], _faces[iFaceCont] );
4229 else if ( _faces.size() > 1 ) // not found, set NULL by the first face
4231 _faces.insert( ++_faces.begin(), (QFace*) 0 );
4234 //================================================================================
4236 * \brief Return a face continues to the given one
4238 //================================================================================
4240 const QFace* QLink::GetContinuesFace( const QFace* face ) const
4242 if ( _faces.size() <= 4 )
4243 for ( size_t i = 0; i < _faces.size(); ++i ) {
4244 if ( _faces[i] == face ) {
4245 int iF = i < 2 ? 1-i : 5-i;
4246 return iF < (int)_faces.size() ? _faces[iF] : 0;
4251 //================================================================================
4253 * \brief True if link is on mesh boundary
4255 //================================================================================
4257 bool QLink::OnBoundary() const
4259 for ( size_t i = 0; i < _faces.size(); ++i )
4260 if (_faces[i] && _faces[i]->IsBoundary()) return true;
4263 //================================================================================
4265 * \brief Return normal of link of the chain
4267 //================================================================================
4269 gp_Vec TChainLink::Normal() const {
4271 if (_qfaces[0]) norm = _qfaces[0]->_normal;
4272 if (_qfaces[1]) norm += _qfaces[1]->_normal;
4275 //================================================================================
4277 * \brief Test link curvature taking into account size of faces
4279 //================================================================================
4281 bool TChainLink::IsStraight() const
4283 bool isStraight = _qlink->IsStraight();
4284 if ( isStraight && _qfaces[0] && !_qfaces[1] )
4286 int i = _qfaces[0]->LinkIndex( _qlink );
4287 int iOpp = ( i + 2 ) % _qfaces[0]->_sides.size();
4288 gp_XYZ mid1 = _qlink->MiddlePnt();
4289 gp_XYZ mid2 = _qfaces[0]->_sides[ iOpp ]->MiddlePnt();
4290 double faceSize2 = (mid1-mid2).SquareModulus();
4291 isStraight = _qlink->_nodeMove.SquareMagnitude() < 1/10./10. * faceSize2;
4296 //================================================================================
4298 * \brief Move medium nodes of vertical links of pentahedrons adjacent by side faces
4300 //================================================================================
4302 void fixPrism( TChain& allLinks )
4304 // separate boundary links from internal ones
4305 typedef set<const QLink*/*, QLink::PtrComparator*/> QLinkSet;
4306 QLinkSet interLinks, bndLinks1, bndLink2;
4308 bool isCurved = false;
4309 for ( TChain::iterator lnk = allLinks.begin(); lnk != allLinks.end(); ++lnk ) {
4310 if ( (*lnk)->OnBoundary() )
4311 bndLinks1.insert( lnk->_qlink );
4313 interLinks.insert( lnk->_qlink );
4314 isCurved = isCurved || !lnk->IsStraight();
4317 return; // no need to move
4319 QLinkSet *curBndLinks = &bndLinks1, *newBndLinks = &bndLink2;
4321 while ( !interLinks.empty() && !curBndLinks->empty() )
4323 // propagate movement from boundary links to connected internal links
4324 QLinkSet::iterator bnd = curBndLinks->begin(), bndEnd = curBndLinks->end();
4325 for ( ; bnd != bndEnd; ++bnd )
4327 const QLink* bndLink = *bnd;
4328 for ( size_t i = 0; i < bndLink->_faces.size(); ++i ) // loop on faces of bndLink
4330 const QFace* face = bndLink->_faces[i]; // quadrange lateral face of a prism
4331 if ( !face ) continue;
4332 // find and move internal link opposite to bndLink within the face
4333 int interInd = ( face->LinkIndex( bndLink ) + 2 ) % face->_sides.size();
4334 const QLink* interLink = face->_sides[ interInd ];
4335 QLinkSet::iterator pInterLink = interLinks.find( interLink );
4336 if ( pInterLink == interLinks.end() ) continue; // not internal link
4337 interLink->Move( bndLink->_nodeMove );
4338 // treated internal links become new boundary ones
4339 interLinks.erase( pInterLink );
4340 newBndLinks->insert( interLink );
4343 curBndLinks->clear();
4344 std::swap( curBndLinks, newBndLinks );
4348 //================================================================================
4350 * \brief Fix links of continues triangles near curved boundary
4352 //================================================================================
4354 void fixTriaNearBoundary( TChain & allLinks, SMESH_MesherHelper& /*helper*/)
4356 if ( allLinks.empty() ) return;
4358 TLinkSet linkSet( allLinks.begin(), allLinks.end());
4359 TLinkInSet linkIt = linkSet.begin(), linksEnd = linkSet.end();
4361 for ( linkIt = linkSet.begin(); linkIt != linksEnd; ++linkIt)
4363 if ( linkIt->IsBoundary() && !linkIt->IsStraight() && linkIt->_qfaces[0])
4365 // move iff a boundary link is bent towards inside of a face (issue 0021084)
4366 const QFace* face = linkIt->_qfaces[0];
4367 gp_XYZ pIn = ( face->_sides[0]->MiddlePnt() +
4368 face->_sides[1]->MiddlePnt() +
4369 face->_sides[2]->MiddlePnt() ) / 3.;
4370 gp_XYZ insideDir( pIn - (*linkIt)->MiddlePnt());
4371 bool linkBentInside = ((*linkIt)->_nodeMove.Dot( insideDir ) > 0 );
4372 //if ( face->IsSpoiled( linkIt->_qlink ))
4373 if ( linkBentInside )
4374 face->MoveByBoundary( *linkIt, (*linkIt)->_nodeMove, linkSet );
4379 //================================================================================
4381 * \brief Detect rectangular structure of links and build chains from them
4383 //================================================================================
4385 enum TSplitTriaResult {
4386 _OK, _NO_CORNERS, _FEW_ROWS, _MANY_ROWS, _NO_SIDELINK, _BAD_MIDQUAD, _NOT_RECT,
4387 _NO_MIDQUAD, _NO_UPTRIA, _BAD_SET_SIZE, _BAD_CORNER, _BAD_START, _NO_BOTLINK, _TWISTED_CHAIN };
4389 TSplitTriaResult splitTrianglesIntoChains( TChain & allLinks,
4390 vector< TChain> & resultChains,
4391 SMDS_TypeOfPosition pos )
4393 // put links in the set and evaluate number of result chains by number of boundary links
4395 size_t nbBndLinks = 0;
4396 for ( TChain::iterator lnk = allLinks.begin(); lnk != allLinks.end(); ++lnk ) {
4397 linkSet.insert( *lnk );
4398 nbBndLinks += lnk->IsBoundary();
4400 resultChains.clear();
4401 resultChains.reserve( nbBndLinks / 2 );
4403 TLinkInSet linkIt, linksEnd = linkSet.end();
4405 // find a boundary link with corner node; corner node has position pos-2
4406 // i.e. SMDS_TOP_VERTEX for links on faces and SMDS_TOP_EDGE for
4408 SMDS_TypeOfPosition cornerPos = SMDS_TypeOfPosition(pos-2);
4409 const SMDS_MeshNode* corner = 0;
4410 for ( linkIt = linkSet.begin(); linkIt != linksEnd; ++linkIt )
4411 if ( linkIt->IsBoundary() && (corner = (*linkIt)->EndPosNode(cornerPos)))
4416 TLinkInSet startLink = linkIt;
4417 const SMDS_MeshNode* startCorner = corner;
4418 vector< TChain* > rowChains;
4421 while ( startLink != linksEnd) // loop on columns
4423 // We suppose we have a rectangular structure like shown here. We have found a
4424 // corner of the rectangle (startCorner) and a boundary link sharing
4425 // |/ |/ | the startCorner (startLink). We are going to loop on rows of the
4426 // --o---o---o structure making several chains at once. One chain (columnChain)
4427 // |\ | /| starts at startLink and continues upward (we look at the structure
4428 // \ | \ | / | from such point that startLink is on the bottom of the structure).
4429 // \| \|/ | While going upward we also fill horizontal chains (rowChains) we
4430 // --o---o---o encounter.
4432 // / | \ | \ | startCorner
4437 if ( resultChains.size() == nbBndLinks / 2 )
4439 resultChains.push_back( TChain() );
4440 TChain& columnChain = resultChains.back();
4442 TLinkInSet botLink = startLink; // current horizontal link to go up from
4443 corner = startCorner; // current corner the botLink ends at
4445 while ( botLink != linksEnd ) // loop on rows
4447 // add botLink to the columnChain
4448 columnChain.push_back( *botLink );
4450 const QFace* botTria = botLink->_qfaces[0]; // bottom triangle bound by botLink
4452 { // the column ends
4453 if ( botLink == startLink )
4454 return _TWISTED_CHAIN; // issue 0020951
4455 linkSet.erase( botLink );
4456 if ( iRow != rowChains.size() )
4457 return _FEW_ROWS; // different nb of rows in columns
4460 // find the link dividing the quadrangle (midQuadLink) and vertical boundary
4461 // link ending at <corner> (sideLink); there are two cases:
4462 // 1) midQuadLink does not end at <corner>, then we easily find it by botTria,
4463 // since midQuadLink is not at boundary while sideLink is.
4464 // 2) midQuadLink ends at <corner>
4466 TLinkInSet midQuadLink = linksEnd;
4467 TLinkInSet sideLink = botTria->GetBoundaryLink( linkSet, *botLink, &midQuadLink,
4469 if ( isCase2 ) { // find midQuadLink among links of botTria
4470 midQuadLink = botTria->GetLinkByNode( linkSet, *botLink, corner );
4471 if ( midQuadLink->IsBoundary() )
4472 return _BAD_MIDQUAD;
4474 if ( sideLink == linksEnd || midQuadLink == linksEnd || sideLink == midQuadLink )
4475 return sideLink == linksEnd ? _NO_SIDELINK : _NO_MIDQUAD;
4478 columnChain.push_back( *midQuadLink );
4479 if ( iRow >= rowChains.size() ) {
4481 return _MANY_ROWS; // different nb of rows in columns
4482 if ( resultChains.size() == nbBndLinks / 2 )
4484 resultChains.push_back( TChain() );
4485 rowChains.push_back( & resultChains.back() );
4487 rowChains[iRow]->push_back( *sideLink );
4488 rowChains[iRow]->push_back( *midQuadLink );
4490 const QFace* upTria = midQuadLink->NextFace( botTria ); // upper tria of the rectangle
4494 // prepare startCorner and startLink for the next column
4495 startCorner = startLink->NextNode( startCorner );
4497 startLink = botTria->GetBoundaryLink( linkSet, *botLink, 0, startCorner );
4499 startLink = upTria->GetBoundaryLink( linkSet, *midQuadLink, 0, startCorner );
4500 // check if no more columns remains
4501 if ( startLink != linksEnd ) {
4502 const SMDS_MeshNode* botNode = startLink->NextNode( startCorner );
4503 if ( (isCase2 ? botTria : upTria)->Contains( botNode ))
4504 startLink = linksEnd; // startLink bounds upTria or botTria
4505 else if ( startLink == botLink || startLink == midQuadLink || startLink == sideLink )
4509 // find bottom link and corner for the next row
4510 corner = sideLink->NextNode( corner );
4511 // next bottom link ends at the new corner
4512 linkSet.erase( botLink );
4513 botLink = upTria->GetLinkByNode( linkSet, (isCase2 ? *sideLink : *midQuadLink), corner );
4514 if ( botLink == linksEnd || botLink == midQuadLink || botLink == sideLink)
4516 if ( midQuadLink == startLink || sideLink == startLink )
4517 return _TWISTED_CHAIN; // issue 0020951
4518 linkSet.erase( midQuadLink );
4519 linkSet.erase( sideLink );
4521 // make faces neighboring the found ones be boundary
4522 if ( startLink != linksEnd ) {
4523 const QFace* tria = isCase2 ? botTria : upTria;
4524 for ( int iL = 0; iL < 3; ++iL ) {
4525 linkIt = linkSet.find( tria->_sides[iL] );
4526 if ( linkIt != linksEnd )
4527 linkIt->RemoveFace( tria );
4530 if ( botLink->_qfaces[0] == upTria || botLink->_qfaces[1] == upTria )
4531 botLink->RemoveFace( upTria ); // make next botTria first in vector
4538 // In the linkSet, there must remain the last links of rowChains; add them
4539 if ( linkSet.size() != rowChains.size() )
4540 return _BAD_SET_SIZE;
4541 for ( size_t iRow = 0; iRow < rowChains.size(); ++iRow ) {
4542 // find the link (startLink) ending at startCorner
4544 for ( startLink = linkSet.begin(); startLink != linksEnd; ++startLink ) {
4545 if ( (*startLink)->node1() == startCorner ) {
4546 corner = (*startLink)->node2(); break;
4548 else if ( (*startLink)->node2() == startCorner) {
4549 corner = (*startLink)->node1(); break;
4552 if ( startLink == linksEnd )
4554 rowChains[ iRow ]->push_back( *startLink );
4555 linkSet.erase( startLink );
4556 startCorner = corner;
4562 //================================================================================
4564 * \brief Place medium nodes at the link middle for elements whose corner nodes
4565 * are out of geometrical boundary to prevent distorting elements.
4566 * Issue 0020982, note 0013990
4568 //================================================================================
4570 void force3DOutOfBoundary( SMESH_MesherHelper& theHelper,
4571 SMESH_ComputeErrorPtr& theError)
4573 SMESHDS_Mesh* meshDS = theHelper.GetMeshDS();
4574 TopoDS_Shape shape = theHelper.GetSubShape().Oriented( TopAbs_FORWARD );
4575 if ( shape.IsNull() ) return;
4577 if ( !dynamic_cast<SMESH_BadInputElements*>( theError.get() ))
4580 theError.reset( new SMESH_BadInputElements( meshDS ));
4582 theError.reset( new SMESH_BadInputElements( meshDS,
4584 theError->myComment,
4589 if ( shape.ShapeType() == TopAbs_FACE ) // 2D
4591 if ( theHelper.GetMesh()->NbTriangles( ORDER_QUADRATIC ) < 1 ) return;
4593 SMESHDS_SubMesh* faceSM = meshDS->MeshElements( shape );
4594 if ( !faceSM ) return;
4596 const TopoDS_Face& face = TopoDS::Face( shape );
4597 Handle(Geom_Surface) surface = BRep_Tool::Surface( face );
4599 TopExp_Explorer edgeIt( face, TopAbs_EDGE );
4600 for ( ; edgeIt.More(); edgeIt.Next() ) // loop on EDGEs of a FACE
4602 // check if the EDGE needs checking
4603 const TopoDS_Edge& edge = TopoDS::Edge( edgeIt.Current() );
4604 if ( SMESH_Algo::isDegenerated( edge ) )
4606 if ( theHelper.IsRealSeam( edge ) &&
4607 edge.Orientation() == TopAbs_REVERSED )
4610 SMESHDS_SubMesh* edgeSM = meshDS->MeshElements( edge );
4611 if ( !edgeSM ) continue;
4614 Handle(Geom2d_Curve) pcurve = BRep_Tool::CurveOnSurface( edge, face, f, l );
4615 BRepAdaptor_Curve curve3D( edge );
4616 switch ( curve3D.GetType() ) {
4617 case GeomAbs_Line: continue;
4618 case GeomAbs_Circle:
4619 case GeomAbs_Ellipse:
4620 case GeomAbs_Hyperbola:
4621 case GeomAbs_Parabola:
4624 gp_Vec D1, D2, Du1, Dv1; gp_Pnt p;
4625 curve3D.D2( 0.5 * ( f + l ), p, D1, D2 );
4626 gp_Pnt2d uv = pcurve->Value( 0.5 * ( f + l ) );
4627 surface->D1( uv.X(), uv.Y(), p, Du1, Dv1 );
4628 gp_Vec fNorm = Du1 ^ Dv1;
4629 if ( fNorm.IsParallel( D2, M_PI * 25./180. ))
4630 continue; // face is normal to the curve3D
4632 gp_Vec curvNorm = fNorm ^ D1;
4633 if ( edge.Orientation() == TopAbs_REVERSED ) curvNorm.Reverse();
4634 if ( curvNorm * D2 > 0 )
4635 continue; // convex edge
4637 catch ( Standard_Failure )
4643 // get nodes shared by faces that may be distorted
4644 SMDS_NodeIteratorPtr nodeIt;
4645 if ( edgeSM->NbNodes() > 0 ) {
4646 nodeIt = edgeSM->GetNodes();
4649 SMESHDS_SubMesh* vertexSM = meshDS->MeshElements( theHelper.IthVertex( 0, edge ));
4651 vertexSM = meshDS->MeshElements( theHelper.IthVertex( 1, edge ));
4652 if ( !vertexSM ) continue;
4653 nodeIt = vertexSM->GetNodes();
4656 // find suspicious faces
4657 TIDSortedElemSet checkedFaces;
4658 vector< const SMDS_MeshNode* > nOnEdge( 2 );
4659 const SMDS_MeshNode* nOnFace;
4660 while ( nodeIt->more() )
4662 const SMDS_MeshNode* n = nodeIt->next();
4663 SMDS_ElemIteratorPtr faceIt = n->GetInverseElementIterator( SMDSAbs_Face );
4664 while ( faceIt->more() )
4666 const SMDS_MeshElement* f = faceIt->next();
4667 if ( !faceSM->Contains( f ) ||
4668 f->NbNodes() < 6 || // check quadratic triangles only
4669 !checkedFaces.insert( f ).second )
4672 // get nodes on EDGE and on FACE of a suspicious face
4673 nOnEdge.clear(); nOnFace = 0;
4674 SMDS_MeshElement::iterator triNode = f->begin_nodes();
4675 for ( int nbN = 0; nbN < 3; ++triNode, ++nbN )
4678 if ( n->GetPosition()->GetDim() == 2 )
4681 nOnEdge.push_back( n );
4684 // check if nOnFace is inside the FACE
4685 if ( nOnFace && nOnEdge.size() == 2 )
4687 theHelper.AddTLinks( static_cast< const SMDS_MeshFace* > ( f ));
4688 if ( !SMESH_MeshAlgos::FaceNormal( f, faceNorm, /*normalized=*/false ))
4690 gp_XYZ edgeDir = SMESH_TNodeXYZ( nOnEdge[0] ) - SMESH_TNodeXYZ( nOnEdge[1] );
4691 gp_XYZ edgeNorm = faceNorm ^ edgeDir;
4692 n = theHelper.GetMediumNode( nOnEdge[0], nOnEdge[1], true ); // find n, not create
4693 gp_XYZ pN0 = SMESH_TNodeXYZ( nOnEdge[0] );
4694 gp_XYZ pMedium = SMESH_TNodeXYZ( n ); // on-edge node location
4695 gp_XYZ pFaceN = SMESH_TNodeXYZ( nOnFace ); // on-face node location
4696 double hMedium = edgeNorm * gp_Vec( pN0, pMedium ).XYZ();
4697 double hFace = edgeNorm * gp_Vec( pN0, pFaceN ).XYZ();
4698 if ( Abs( hMedium ) > Abs( hFace * 0.6 ))
4700 // nOnFace is out of FACE, move a medium on-edge node to the middle
4701 gp_XYZ pMid3D = 0.5 * ( pN0 + SMESH_TNodeXYZ( nOnEdge[1] ));
4702 meshDS->MoveNode( n, pMid3D.X(), pMid3D.Y(), pMid3D.Z() );
4703 MSG( "move OUT of face " << n );
4704 static_cast<SMESH_BadInputElements*>( theError.get() )->add( f );
4710 if ( theError->HasBadElems() )
4711 theError->myName = EDITERR_NO_MEDIUM_ON_GEOM;
4714 } // 2D ==============================================================================
4716 if ( shape.ShapeType() == TopAbs_SOLID ) // 3D
4718 if ( theHelper.GetMesh()->NbTetras ( ORDER_QUADRATIC ) < 1 &&
4719 theHelper.GetMesh()->NbPyramids( ORDER_QUADRATIC ) < 1 ) return;
4721 SMESHDS_SubMesh* solidSM = meshDS->MeshElements( shape );
4722 if ( !solidSM ) return;
4724 // check if the SOLID is bound by concave FACEs
4725 vector< TopoDS_Face > concaveFaces;
4726 TopExp_Explorer faceIt( shape, TopAbs_FACE );
4727 for ( ; faceIt.More(); faceIt.Next() ) // loop on FACEs of a SOLID
4729 const TopoDS_Face& face = TopoDS::Face( faceIt.Current() );
4730 if ( !meshDS->MeshElements( face )) continue;
4732 BRepAdaptor_Surface surface( face );
4733 switch ( surface.GetType() ) {
4734 case GeomAbs_Plane: continue;
4735 case GeomAbs_Cylinder:
4737 case GeomAbs_Sphere:
4740 double u = 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() );
4741 double v = 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() );
4742 gp_Vec Du1, Dv1, Du2, Dv2, Duv2; gp_Pnt p;
4743 surface.D2( u,v, p, Du1, Dv1, Du2, Dv2, Duv2 );
4744 gp_Vec fNorm = Du1 ^ Dv1;
4745 if ( face.Orientation() == TopAbs_REVERSED ) fNorm.Reverse();
4746 bool concaveU = ( fNorm * Du2 > 1e-100 );
4747 bool concaveV = ( fNorm * Dv2 > 1e-100 );
4748 if ( concaveU || concaveV )
4749 concaveFaces.push_back( face );
4751 catch ( Standard_Failure )
4753 concaveFaces.push_back( face );
4758 if ( concaveFaces.empty() )
4761 // fix 2D mesh on the SOLID
4762 for ( faceIt.ReInit(); faceIt.More(); faceIt.Next() ) // loop on FACEs of a SOLID
4764 SMESH_MesherHelper faceHelper( *theHelper.GetMesh() );
4765 faceHelper.SetSubShape( faceIt.Current() );
4766 force3DOutOfBoundary( faceHelper, theError );
4769 // get an iterator over faces on concaveFaces
4770 vector< SMDS_ElemIteratorPtr > faceIterVec( concaveFaces.size() );
4771 for ( size_t i = 0; i < concaveFaces.size(); ++i )
4772 faceIterVec[i] = meshDS->MeshElements( concaveFaces[i] )->GetElements();
4773 typedef SMDS_IteratorOnIterators
4774 < const SMDS_MeshElement*, vector< SMDS_ElemIteratorPtr > > TIterOnIter;
4775 SMDS_ElemIteratorPtr faceIter( new TIterOnIter( faceIterVec ));
4777 // search to check if a volume is close to a concave face
4778 SMESHUtils::Deleter< SMESH_ElementSearcher > faceSearcher
4779 ( SMESH_MeshAlgos::GetElementSearcher( *theHelper.GetMeshDS(), faceIter ));
4782 //BRepClass3d_SolidClassifier solidClassifier( shape );
4784 TIDSortedElemSet checkedVols, movedNodes;
4785 //for ( faceIt.ReInit(); faceIt.More(); faceIt.Next() ) // loop on FACEs of a SOLID
4786 for ( size_t iF = 0; iF < concaveFaces.size(); ++iF ) // loop on concave FACEs
4788 //const TopoDS_Shape& face = faceIt.Current();
4789 const TopoDS_Shape& face = concaveFaces[ iF ];
4790 SMESHDS_SubMesh* faceSM = meshDS->MeshElements( face );
4791 if ( !faceSM ) continue;
4793 // get nodes shared by volumes (tet and pyra) on the FACE that may be distorted
4794 SMDS_NodeIteratorPtr nodeIt;
4795 if ( faceSM->NbNodes() > 0 ) {
4796 nodeIt = faceSM->GetNodes();
4799 TopExp_Explorer vertex( face, TopAbs_VERTEX );
4800 SMESHDS_SubMesh* vertexSM = meshDS->MeshElements( vertex.Current() );
4801 if ( !vertexSM ) continue;
4802 nodeIt = vertexSM->GetNodes();
4804 // get ids of sub-shapes of the FACE
4806 SMESH_subMeshIteratorPtr smIt =
4807 theHelper.GetMesh()->GetSubMesh( face )->getDependsOnIterator(/*includeSelf=*/true);
4808 while ( smIt->more() )
4809 subIDs.insert( smIt->next()->GetId() );
4811 // find suspicious volumes adjacent to the FACE
4812 vector< const SMDS_MeshNode* > nOnFace( 4 );
4813 const SMDS_MeshNode* nInSolid;
4814 while ( nodeIt->more() )
4816 const SMDS_MeshNode* n = nodeIt->next();
4817 SMDS_ElemIteratorPtr volIt = n->GetInverseElementIterator( SMDSAbs_Volume );
4818 while ( volIt->more() )
4820 const SMDS_MeshElement* vol = volIt->next();
4821 size_t nbN = vol->NbCornerNodes();
4822 if ( ( nbN != 4 && nbN != 5 ) ||
4823 !solidSM->Contains( vol ) ||
4824 !checkedVols.insert( vol ).second )
4827 // get nodes on FACE and in SOLID of a suspicious volume
4828 nOnFace.clear(); nInSolid = 0;
4829 SMDS_MeshElement::iterator volNode = vol->begin_nodes();
4830 for ( int nb = nbN; nb > 0; ++volNode, --nb )
4833 if ( n->GetPosition()->GetDim() == 3 )
4835 else if ( subIDs.count( n->getshapeId() ))
4836 nOnFace.push_back( n );
4840 if ( !nInSolid || nOnFace.size() != nbN - 1 )
4843 // get size of the vol
4844 SMESH_TNodeXYZ pInSolid( nInSolid ), pOnFace0( nOnFace[0] );
4845 double volLength = pInSolid.SquareDistance( nOnFace[0] );
4846 for ( size_t i = 1; i < nOnFace.size(); ++i )
4848 volLength = Max( volLength, pOnFace0.SquareDistance( nOnFace[i] ));
4851 // check if vol is close to concaveFaces
4852 const SMDS_MeshElement* closeFace =
4853 faceSearcher->FindClosestTo( pInSolid, SMDSAbs_Face );
4855 pInSolid.SquareDistance( closeFace->GetNode(0) ) > 4 * volLength )
4858 // check if vol is distorted, i.e. a medium node is much closer
4859 // to nInSolid than the link middle
4860 bool isDistorted = false;
4861 SMDS_FaceOfNodes onFaceTria( nOnFace[0], nOnFace[1], nOnFace[2] );
4862 if ( !SMESH_MeshAlgos::FaceNormal( &onFaceTria, faceNorm, /*normalized=*/false ))
4864 theHelper.AddTLinks( static_cast< const SMDS_MeshVolume* > ( vol ));
4865 vector< pair< SMESH_TLink, const SMDS_MeshNode* > > links;
4866 for ( size_t i = 0; i < nOnFace.size(); ++i ) // loop on links between nOnFace
4867 for ( size_t j = i+1; j < nOnFace.size(); ++j )
4869 SMESH_TLink link( nOnFace[i], nOnFace[j] );
4870 TLinkNodeMap::const_iterator linkIt =
4871 theHelper.GetTLinkNodeMap().find( link );
4872 if ( linkIt != theHelper.GetTLinkNodeMap().end() )
4874 links.push_back( make_pair( linkIt->first, linkIt->second ));
4875 if ( !isDistorted ) {
4876 // compare projections of nInSolid and nMedium to face normal
4877 gp_Pnt pMedium = SMESH_TNodeXYZ( linkIt->second );
4878 double hMedium = faceNorm * gp_Vec( pOnFace0, pMedium ).XYZ();
4879 double hVol = faceNorm * gp_Vec( pOnFace0, pInSolid ).XYZ();
4880 isDistorted = ( Abs( hMedium ) > Abs( hVol * 0.75 ));
4884 // move medium nodes to link middle
4887 for ( size_t i = 0; i < links.size(); ++i )
4889 const SMDS_MeshNode* nMedium = links[i].second;
4890 if ( movedNodes.insert( nMedium ).second )
4892 gp_Pnt pMid3D = 0.5 * ( SMESH_TNodeXYZ( links[i].first.node1() ) +
4893 SMESH_TNodeXYZ( links[i].first.node2() ));
4894 meshDS->MoveNode( nMedium, pMid3D.X(), pMid3D.Y(), pMid3D.Z() );
4895 MSG( "move OUT of solid " << nMedium );
4898 static_cast<SMESH_BadInputElements*>( theError.get() )->add( vol );
4900 } // loop on volumes sharing a node on FACE
4901 } // loop on nodes on FACE
4902 } // loop on FACEs of a SOLID
4904 if ( theError->HasBadElems() )
4905 theError->myName = EDITERR_NO_MEDIUM_ON_GEOM;
4911 //=======================================================================
4913 * \brief Move medium nodes of faces and volumes to fix distorted elements
4914 * \param error - container of fixed distorted elements
4915 * \param volumeOnly - to fix nodes on faces or not, if the shape is solid
4917 * Issue 0020307: EDF 992 SMESH : Linea/Quadratic with Medium Node on Geometry
4919 //=======================================================================
4921 void SMESH_MesherHelper::FixQuadraticElements(SMESH_ComputeErrorPtr& compError,
4924 //MESSAGE("FixQuadraticElements " << volumeOnly);
4925 // setenv NO_FixQuadraticElements to know if FixQuadraticElements() is guilty of bad conversion
4926 if ( getenv("NO_FixQuadraticElements") )
4929 // 0. Apply algorithm to SOLIDs or FACEs
4930 // ----------------------------------------------
4931 if ( myShape.IsNull() ) {
4932 if ( !myMesh->HasShapeToMesh() ) return;
4933 SetSubShape( myMesh->GetShapeToMesh() );
4937 TopTools_IndexedMapOfShape solids;
4938 TopExp::MapShapes(myShape,TopAbs_SOLID,solids);
4939 nbSolids = solids.Extent();
4941 TopTools_MapOfShape faces; // faces not in solid or in not meshed solid
4942 for ( TopExp_Explorer f(myShape,TopAbs_FACE,TopAbs_SOLID); f.More(); f.Next() ) {
4943 faces.Add( f.Current() ); // not in solid
4945 for ( TopExp_Explorer s(myShape,TopAbs_SOLID); s.More(); s.Next() ) {
4946 if ( myMesh->GetSubMesh( s.Current() )->IsEmpty() ) { // get faces of solid
4947 for ( TopExp_Explorer f( s.Current(), TopAbs_FACE); f.More(); f.Next() )
4948 faces.Add( f.Current() ); // in not meshed solid
4950 else { // fix nodes in the solid and its faces
4952 MSG("FIX SOLID " << nbSolids-- << " #" << GetMeshDS()->ShapeToIndex(s.Current()));
4954 SMESH_MesherHelper h(*myMesh);
4955 h.SetSubShape( s.Current() );
4956 h.ToFixNodeParameters(true);
4957 h.FixQuadraticElements( compError, false );
4960 // fix nodes on geom faces
4962 int nbfaces = nbSolids;
4963 nbfaces = faces.Extent(); /*avoid "unused varianbles": */ nbfaces++, nbfaces--;
4965 for ( TopTools_MapIteratorOfMapOfShape fIt( faces ); fIt.More(); fIt.Next() ) {
4966 MESSAGE("FIX FACE " << nbfaces-- << " #" << GetMeshDS()->ShapeToIndex(fIt.Key()));
4967 MSG("FIX FACE " << nbfaces-- << " #" << GetMeshDS()->ShapeToIndex(fIt.Key()));
4968 SMESH_MesherHelper h(*myMesh);
4969 h.SetSubShape( fIt.Key() );
4970 h.ToFixNodeParameters(true);
4971 h.FixQuadraticElements( compError, true);
4973 //perf_print_all_meters(1);
4974 if ( compError && compError->myName == EDITERR_NO_MEDIUM_ON_GEOM )
4975 compError->myComment = "during conversion to quadratic, "
4976 "some medium nodes were not placed on geometry to avoid distorting elements";
4980 // 1. Find out type of elements and get iterator on them
4981 // ---------------------------------------------------
4983 SMDS_ElemIteratorPtr elemIt;
4984 SMDSAbs_ElementType elemType = SMDSAbs_All;
4986 SMESH_subMesh* submesh = myMesh->GetSubMeshContaining( myShapeID );
4989 if ( SMESHDS_SubMesh* smDS = submesh->GetSubMeshDS() ) {
4990 elemIt = smDS->GetElements();
4991 if ( elemIt->more() ) {
4992 elemType = elemIt->next()->GetType();
4993 elemIt = smDS->GetElements();
4996 if ( !elemIt || !elemIt->more() || elemType < SMDSAbs_Face )
4999 // 2. Fill in auxiliary data structures
5000 // ----------------------------------
5004 set< QLink >::iterator pLink;
5005 set< QFace >::iterator pFace;
5007 bool isCurved = false;
5008 //bool hasRectFaces = false;
5009 //set<int> nbElemNodeSet;
5010 SMDS_VolumeTool volTool;
5012 TIDSortedNodeSet apexOfPyramid;
5013 const int apexIndex = 4;
5016 // Move medium nodes to the link middle for elements whose corner nodes
5017 // are out of geometrical boundary to fix distorted elements.
5018 force3DOutOfBoundary( *this, compError );
5020 if ( elemType == SMDSAbs_Volume )
5022 while ( elemIt->more() ) // loop on volumes
5024 const SMDS_MeshElement* vol = elemIt->next();
5025 if ( !vol->IsQuadratic() || !volTool.Set( vol ))
5027 double volMinSize2 = -1.;
5028 for ( int iF = 0; iF < volTool.NbFaces(); ++iF ) // loop on faces of volume
5030 int nbN = volTool.NbFaceNodes( iF );
5031 //nbElemNodeSet.insert( nbN );
5032 const SMDS_MeshNode** faceNodes = volTool.GetFaceNodes( iF );
5033 vector< const QLink* > faceLinks( nbN/2 );
5034 for ( int iN = 0; iN < nbN; iN += 2 ) // loop on links of a face
5037 QLink link( faceNodes[iN], faceNodes[iN+2], faceNodes[iN+1] );
5038 pLink = links.insert( link ).first;
5039 faceLinks[ iN/2 ] = & *pLink;
5041 if ( link.MediumPos() == SMDS_TOP_3DSPACE )
5043 if ( !link.IsStraight() )
5044 return; // already fixed
5046 else if ( !isCurved )
5048 if ( volMinSize2 < 0 ) volMinSize2 = volTool.MinLinearSize2();
5049 isCurved = !isStraightLink( volMinSize2, link._nodeMove.SquareMagnitude() );
5053 pFace = faces.insert( QFace( faceLinks )).first;
5054 if ( pFace->NbVolumes() == 0 )
5055 pFace->AddSelfToLinks();
5056 pFace->SetVolume( vol );
5057 // hasRectFaces = hasRectFaces ||
5058 // ( volTool.GetVolumeType() == SMDS_VolumeTool::QUAD_HEXA ||
5059 // volTool.GetVolumeType() == SMDS_VolumeTool::QUAD_PENTA );
5062 pFace->_face = GetMeshDS()->FindFace(faceNodes[0],faceNodes[2],faceNodes[4]);
5064 pFace->_face = GetMeshDS()->FindFace(faceNodes[0],faceNodes[2],
5065 faceNodes[4],faceNodes[6] );
5068 // collect pyramid apexes for further correction
5069 if ( vol->NbCornerNodes() == 5 )
5070 apexOfPyramid.insert( vol->GetNode( apexIndex ));
5072 set< QLink >::iterator pLink = links.begin();
5073 for ( ; pLink != links.end(); ++pLink )
5074 pLink->SetContinuesFaces();
5078 while ( elemIt->more() ) // loop on faces
5080 const SMDS_MeshElement* face = elemIt->next();
5081 if ( !face->IsQuadratic() )
5083 //nbElemNodeSet.insert( face->NbNodes() );
5084 int nbN = face->NbNodes()/2;
5085 vector< const QLink* > faceLinks( nbN );
5086 for ( int iN = 0; iN < nbN; ++iN ) // loop on links of a face
5089 QLink link( face->GetNode(iN), face->GetNode((iN+1)%nbN), face->GetNode(iN+nbN) );
5090 pLink = links.insert( link ).first;
5091 faceLinks[ iN ] = & *pLink;
5093 link.node1()->GetPosition()->GetTypeOfPosition() < 2 &&
5094 link.node2()->GetPosition()->GetTypeOfPosition() < 2 )
5095 isCurved = !link.IsStraight();
5098 pFace = faces.insert( QFace( faceLinks )).first;
5099 pFace->AddSelfToLinks();
5100 //hasRectFaces = ( hasRectFaces || nbN == 4 );
5104 return; // no curved edges of faces
5106 // 3. Compute displacement of medium nodes
5107 // ---------------------------------------
5109 SMESH_MesherHelper faceHlp(*myMesh);
5111 // two loops on QFaces: the first is to treat boundary links, the second is for internal ones.
5112 TopLoc_Location loc;
5114 // not to treat boundary of volumic sub-mesh.
5115 int isInside = ( elemType == SMDSAbs_Volume && volumeOnly ) ? 1 : 0;
5116 for ( ; isInside < 2; ++isInside )
5118 MSG( "--------------- LOOP (inside=" << isInside << ") ------------------");
5119 SMDS_TypeOfPosition pos = isInside ? SMDS_TOP_3DSPACE : SMDS_TOP_FACE;
5120 SMDS_TypeOfPosition bndPos = isInside ? SMDS_TOP_FACE : SMDS_TOP_EDGE;
5122 for ( pFace = faces.begin(); pFace != faces.end(); ++pFace ) {
5123 if ( bool(isInside) == pFace->IsBoundary() )
5125 for ( int dir = 0; dir < 2; ++dir ) // 2 directions of propagation from the quadrangle
5128 // make chain of links connected via continues faces
5131 if ( !pFace->GetLinkChain( dir, rawChain, pos, error) && error ==ERR_UNKNOWN ) continue;
5133 if ( !pFace->GetLinkChain( dir+2, rawChain, pos, error ) && error ==ERR_UNKNOWN ) continue;
5135 vector< TChain > chains;
5136 if ( error == ERR_OK ) { // chain contains continues rectangles
5138 chains[0].splice( chains[0].begin(), rawChain );
5140 else if ( error == ERR_TRI ) { // chain contains continues triangles
5141 TSplitTriaResult res = splitTrianglesIntoChains( rawChain, chains, pos );
5142 if ( res != _OK ) { // not 'quadrangles split into triangles' in chain
5143 fixTriaNearBoundary( rawChain, *this );
5147 else if ( error == ERR_PRISM ) { // quadrangle side faces of prisms
5148 fixPrism( rawChain );
5154 for ( size_t iC = 0; iC < chains.size(); ++iC )
5156 TChain& chain = chains[iC];
5157 if ( chain.empty() ) continue;
5158 if ( chain.front().IsStraight() && chain.back().IsStraight() ) {
5159 MSG("3D straight - ignore");
5162 if ( chain.front()->MediumPos() > bndPos ||
5163 chain.back() ->MediumPos() > bndPos ) {
5164 MSG("Internal chain - ignore");
5167 // measure chain length and compute link position along the chain
5168 double chainLen = 0;
5169 vector< double > linkPos;
5170 TChain savedChain; // backup
5171 MSGBEG( "Link medium nodes: ");
5172 TChain::iterator link0 = chain.begin(), link1 = chain.begin(), link2;
5173 for ( ++link1; link1 != chain.end(); ++link1, ++link0 ) {
5174 MSGBEG( (*link0)->_mediumNode->GetID() << "-" <<(*link1)->_mediumNode->GetID()<<" ");
5175 double len = ((*link0)->MiddlePnt() - (*link1)->MiddlePnt()).Modulus();
5176 while ( len < numeric_limits<double>::min() ) { // remove degenerated link
5177 if ( savedChain.empty() ) savedChain = chain;
5178 link1 = chain.erase( link1 );
5179 if ( link1 == chain.end() )
5181 len = ((*link0)->MiddlePnt() - (*link1)->MiddlePnt()).Modulus();
5184 linkPos.push_back( chainLen );
5187 if ( linkPos.size() <= 2 && savedChain.size() > 2 ) {
5192 for ( link1 = chain.begin(); link1 != chain.end(); ++link1 ) {
5194 linkPos.push_back( chainLen );
5197 gp_Vec move0 = chain.front()->_nodeMove;
5198 gp_Vec move1 = chain.back ()->_nodeMove;
5203 // compute node displacement of end links of chain in parametric space of FACE
5204 TChainLink& linkOnFace = *(++chain.begin());
5205 const SMDS_MeshNode* nodeOnFace = linkOnFace->_mediumNode;
5206 TopoDS_Shape f = GetSubShapeByNode( nodeOnFace, GetMeshDS() );
5207 if ( !f.IsNull() && f.ShapeType() == TopAbs_FACE )
5209 face = TopoDS::Face( f );
5210 faceHlp.SetSubShape( face );
5211 Handle(Geom_Surface) surf = BRep_Tool::Surface(face,loc);
5212 //bool isStraight[2]; // commented for issue 0023118
5213 for ( int is1 = 0; is1 < 2; ++is1 ) // move0 or move1
5215 TChainLink& link = is1 ? chain.back() : chain.front();
5216 gp_XY uvm = faceHlp.GetNodeUV( face, link->_mediumNode, nodeOnFace, &checkUV );
5217 gp_XY uv1 = faceHlp.GetNodeUV( face, link->node1(), nodeOnFace, &checkUV );
5218 gp_XY uv2 = faceHlp.GetNodeUV( face, link->node2(), nodeOnFace, &checkUV );
5219 gp_XY uv12 = faceHlp.GetMiddleUV( surf, uv1, uv2 );
5220 // uvMove = uvm - uv12
5221 gp_XY uvMove = ApplyIn2D(surf, uvm, uv12, gp_XY_Subtracted, /*inPeriod=*/false);
5222 ( is1 ? move1 : move0 ).SetCoord( uvMove.X(), uvMove.Y(), 0 );
5223 if ( !is1 ) // correct nodeOnFace for move1 (issue 0020919)
5224 nodeOnFace = (*(++chain.rbegin()))->_mediumNode;
5225 // isStraight[is1] = isStraightLink( (uv2-uv1).SquareModulus(),
5226 // 10 * uvMove.SquareModulus());
5228 // if ( isStraight[0] && isStraight[1] ) {
5229 // MSG("2D straight - ignore");
5230 // continue; // straight - no need to move nodes of internal links
5233 // check if a chain is already fixed
5234 gp_XY uvm = faceHlp.GetNodeUV( face, linkOnFace->_mediumNode, 0, &checkUV );
5235 gp_XY uv1 = faceHlp.GetNodeUV( face, linkOnFace->node1(), nodeOnFace, &checkUV );
5236 gp_XY uv2 = faceHlp.GetNodeUV( face, linkOnFace->node2(), nodeOnFace, &checkUV );
5237 gp_XY uv12 = faceHlp.GetMiddleUV( surf, uv1, uv2 );
5238 if (( uvm - uv12 ).SquareModulus() > 1e-10 )
5240 MSG("Already fixed - ignore");
5246 if ( isInside || face.IsNull() )
5248 // compute node displacement of end links in their local coord systems
5250 TChainLink& ln0 = chain.front(), ln1 = *(++chain.begin());
5251 trsf.SetTransformation( gp_Ax3( gp::Origin(), ln0.Normal(),
5252 gp_Vec( ln0->MiddlePnt(), ln1->MiddlePnt() )));
5253 move0.Transform(trsf);
5256 TChainLink& ln0 = *(++chain.rbegin()), ln1 = chain.back();
5257 trsf.SetTransformation( gp_Ax3( gp::Origin(), ln1.Normal(),
5258 gp_Vec( ln0->MiddlePnt(), ln1->MiddlePnt() )));
5259 move1.Transform(trsf);
5262 // compute displacement of medium nodes
5263 link2 = chain.begin();
5266 for ( int i = 0; link2 != chain.end(); ++link0, ++link1, ++link2, ++i )
5268 double r = linkPos[i] / chainLen;
5269 // displacement in local coord system
5270 gp_Vec move = (1. - r) * move0 + r * move1;
5271 if ( isInside || face.IsNull()) {
5272 // transform to global
5273 gp_Vec x01( (*link0)->MiddlePnt(), (*link1)->MiddlePnt() );
5274 gp_Vec x12( (*link1)->MiddlePnt(), (*link2)->MiddlePnt() );
5276 gp_Vec x = x01.Normalized() + x12.Normalized();
5277 trsf.SetTransformation( gp_Ax3( gp::Origin(), link1->Normal(), x), gp_Ax3() );
5278 } catch ( Standard_Failure ) {
5281 move.Transform(trsf);
5282 (*link1)->Move( move, /*sum=*/false, /*is2dFixed=*/false );
5285 // compute 3D displacement by 2D one
5286 Handle(Geom_Surface) s = BRep_Tool::Surface(face,loc);
5287 gp_XY oldUV = faceHlp.GetNodeUV( face, (*link1)->_mediumNode, 0, &checkUV );
5288 gp_XY newUV = ApplyIn2D( s, oldUV, gp_XY( move.X(),move.Y()), gp_XY_Added );
5289 gp_Pnt newPnt = s->Value( newUV.X(), newUV.Y());
5290 move = gp_Vec( XYZ((*link1)->_mediumNode), newPnt.Transformed(loc) );
5291 if ( SMDS_FacePositionPtr nPos = (*link1)->_mediumNode->GetPosition())
5292 nPos->SetParameters( newUV.X(), newUV.Y() );
5294 if ( (XYZ((*link1)->node1()) - XYZ((*link1)->node2())).SquareModulus() <
5295 move.SquareMagnitude())
5297 gp_XY uv0 = faceHlp.GetNodeUV( face, (*link0)->_mediumNode, 0, &checkUV );
5298 gp_XY uv2 = faceHlp.GetNodeUV( face, (*link2)->_mediumNode, 0, &checkUV );
5299 MSG( "TOO LONG MOVE \t" <<
5300 "uv0: "<<uv0.X()<<", "<<uv0.Y()<<" \t" <<
5301 "uv2: "<<uv2.X()<<", "<<uv2.Y()<<" \t" <<
5302 "uvOld: "<<oldUV.X()<<", "<<oldUV.Y()<<" \t" <<
5303 "newUV: "<<newUV.X()<<", "<<newUV.Y()<<" \t");
5304 uv0.SetX( uv2.X() ); // avoid warning: variable set but not used
5307 (*link1)->Move( move, /*sum=*/false, /*is2dFixed=*/true );
5309 MSG( "Move " << (*link1)->_mediumNode->GetID() << " following "
5310 << chain.front()->_mediumNode->GetID() <<"-"
5311 << chain.back ()->_mediumNode->GetID() <<
5312 " by " << move.Magnitude());
5314 } // loop on chains of links
5315 } // loop on 2 directions of propagation from quadrangle
5317 } // fix faces and/or volumes
5322 TIDSortedElemSet biQuadQuas, biQuadTris, triQuadHexa, biQuadPenta;
5323 const bool toFixCentralNodes = ( myMesh->NbBiQuadQuadrangles() +
5324 myMesh->NbBiQuadTriangles() +
5325 myMesh->NbTriQuadraticHexas() +
5326 myMesh->NbBiQuadPrisms());
5328 faceHlp.ToFixNodeParameters( true );
5330 for ( pLink = links.begin(); pLink != links.end(); ++pLink ) {
5331 if ( pLink->IsMoved() )
5333 gp_Pnt p = pLink->MiddlePnt() + pLink->Move();
5335 // put on surface nodes on FACE but moved in 3D (23050)
5336 if ( !pLink->IsFixedOnSurface() )
5338 faceHlp.SetSubShape( pLink->_mediumNode->getshapeId() );
5339 if ( faceHlp.GetSubShape().ShapeType() == TopAbs_FACE )
5341 const_cast<SMDS_MeshNode*>( pLink->_mediumNode )->setXYZ( p.X(), p.Y(), p.Z());
5342 p.Coord( distXYZ[1], distXYZ[2], distXYZ[3] );
5343 gp_XY uv( Precision::Infinite(), 0 );
5344 if ( faceHlp.CheckNodeUV( TopoDS::Face( faceHlp.GetSubShape() ), pLink->_mediumNode,
5345 uv, /*tol=*/pLink->Move().Modulus(), /*force=*/true, distXYZ ))
5346 p.SetCoord( distXYZ[1], distXYZ[2], distXYZ[3] );
5349 GetMeshDS()->MoveNode( pLink->_mediumNode, p.X(), p.Y(), p.Z());
5351 // collect bi-quadratic elements
5352 if ( toFixCentralNodes )
5354 SMDS_ElemIteratorPtr eIt = pLink->_mediumNode->GetInverseElementIterator();
5355 while ( eIt->more() )
5357 const SMDS_MeshElement* e = eIt->next();
5358 switch( e->GetEntityType() ) {
5359 case SMDSEntity_BiQuad_Quadrangle: biQuadQuas.insert( e ); break;
5360 case SMDSEntity_BiQuad_Triangle: biQuadTris.insert( e ); break;
5361 case SMDSEntity_TriQuad_Hexa: triQuadHexa.insert( e ); break;
5362 case SMDSEntity_BiQuad_Penta: biQuadPenta.insert( e ); break;
5369 // Fix positions of central nodes of bi-tri-quadratic elements
5371 // treat bi-quad quadrangles
5373 vector< const SMDS_MeshNode* > nodes( 9 );
5375 TIDSortedElemSet::iterator quadIt = biQuadQuas.begin();
5376 for ( ; quadIt != biQuadQuas.end(); ++quadIt )
5378 const SMDS_MeshElement* quad = *quadIt;
5381 nodes.assign( quad->begin_nodes(), quad->end_nodes() );
5383 TopoDS_Shape S = GetSubShapeByNode( nodes.back(), GetMeshDS() );
5384 if ( S.IsNull() || S.ShapeType() != TopAbs_FACE ) continue;
5385 const TopoDS_Face& F = TopoDS::Face( S );
5386 Handle( Geom_Surface ) surf = BRep_Tool::Surface( F, loc );
5387 const double tol = BRep_Tool::Tolerance( F );
5389 for ( int i = 0; i < 8; ++i )
5391 uv[ i ] = GetNodeUV( F, nodes[i], nodes[8], &checkUV );
5392 // as this method is used after mesh generation, UV of nodes is not
5393 // updated according to bending links, so we update
5394 if ( i > 3 && nodes[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE )
5395 CheckNodeUV( F, nodes[i], uv[ i ], 2*tol, /*force=*/true );
5397 AdjustByPeriod( F, uv, 8 ); // put uv[] within a period (IPAL52698)
5398 // move the central node
5399 gp_XY uvCent = calcTFI (0.5, 0.5, uv[0],uv[1],uv[2],uv[3],uv[4],uv[5],uv[6],uv[7] );
5400 gp_Pnt p = surf->Value( uvCent.X(), uvCent.Y() ).Transformed( loc );
5401 GetMeshDS()->MoveNode( nodes[8], p.X(), p.Y(), p.Z());
5405 // treat bi-quad triangles
5407 vector< const SMDS_MeshNode* > nodes;
5409 TIDSortedElemSet::iterator triIt = biQuadTris.begin();
5410 for ( ; triIt != biQuadTris.end(); ++triIt )
5412 const SMDS_MeshElement* tria = *triIt;
5414 const TopoDS_Shape& S = GetMeshDS()->IndexToShape( tria->getshapeId() );
5415 if ( S.IsNull() || S.ShapeType() != TopAbs_FACE ) continue;
5416 const TopoDS_Face& F = TopoDS::Face( S );
5417 Handle( Geom_Surface ) surf = BRep_Tool::Surface( F, loc );
5418 const double tol = BRep_Tool::Tolerance( F );
5421 nodes.assign( tria->begin_nodes(), tria->end_nodes() );
5423 bool uvOK = true, badTria = false;
5424 for ( int i = 0; i < 6; ++i )
5426 uv[ i ] = GetNodeUV( F, nodes[i], nodes[(i+1)%3], &uvOK );
5427 // as this method is used after mesh generation, UV of nodes is not
5428 // updated according to bending links, so we update
5429 if ( nodes[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE )
5430 CheckNodeUV( F, nodes[i], uv[ i ], 2*tol, /*force=*/true );
5433 // move the central node
5435 if ( !uvOK || badTria )
5437 p = ( SMESH_TNodeXYZ( nodes[3] ) +
5438 SMESH_TNodeXYZ( nodes[4] ) +
5439 SMESH_TNodeXYZ( nodes[5] )) / 3;
5443 AdjustByPeriod( F, uv, 6 ); // put uv[] within a period (IPAL52698)
5444 gp_XY uvCent = GetCenterUV( uv[0], uv[1], uv[2], uv[3], uv[4], uv[5], &badTria );
5445 p = surf->Value( uvCent.X(), uvCent.Y() ).Transformed( loc );
5447 GetMeshDS()->MoveNode( tria->GetNode(6), p.X(), p.Y(), p.Z() );
5451 // treat tri-quadratic hexahedra
5453 SMDS_VolumeTool volExp;
5454 TIDSortedElemSet::iterator hexIt = triQuadHexa.begin();
5455 for ( ; hexIt != triQuadHexa.end(); ++hexIt )
5457 volExp.Set( *hexIt, /*ignoreCentralNodes=*/false );
5459 // fix nodes central in sides
5460 for ( int iQuad = 0; iQuad < volExp.NbFaces(); ++iQuad )
5462 const SMDS_MeshNode** quadNodes = volExp.GetFaceNodes( iQuad );
5463 if ( quadNodes[8]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE )
5465 gp_XYZ p = calcTFI( 0.5, 0.5,
5466 SMESH_TNodeXYZ( quadNodes[0] ), SMESH_TNodeXYZ( quadNodes[2] ),
5467 SMESH_TNodeXYZ( quadNodes[4] ), SMESH_TNodeXYZ( quadNodes[6] ),
5468 SMESH_TNodeXYZ( quadNodes[1] ), SMESH_TNodeXYZ( quadNodes[3] ),
5469 SMESH_TNodeXYZ( quadNodes[5] ), SMESH_TNodeXYZ( quadNodes[7] ));
5470 GetMeshDS()->MoveNode( quadNodes[8], p.X(), p.Y(), p.Z());
5474 // fix the volume central node
5475 vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
5476 const SMDS_MeshNode** hexNodes = volExp.GetNodes();
5478 pointsOnShapes[ SMESH_Block::ID_V000 ] = SMESH_TNodeXYZ( hexNodes[ 0 ] );
5479 pointsOnShapes[ SMESH_Block::ID_V100 ] = SMESH_TNodeXYZ( hexNodes[ 3 ] );
5480 pointsOnShapes[ SMESH_Block::ID_V010 ] = SMESH_TNodeXYZ( hexNodes[ 1 ] );
5481 pointsOnShapes[ SMESH_Block::ID_V110 ] = SMESH_TNodeXYZ( hexNodes[ 2 ] );
5482 pointsOnShapes[ SMESH_Block::ID_V001 ] = SMESH_TNodeXYZ( hexNodes[ 4 ] );
5483 pointsOnShapes[ SMESH_Block::ID_V101 ] = SMESH_TNodeXYZ( hexNodes[ 7 ] );
5484 pointsOnShapes[ SMESH_Block::ID_V011 ] = SMESH_TNodeXYZ( hexNodes[ 5 ] );
5485 pointsOnShapes[ SMESH_Block::ID_V111 ] = SMESH_TNodeXYZ( hexNodes[ 6 ] );
5487 pointsOnShapes[ SMESH_Block::ID_Ex00 ] = SMESH_TNodeXYZ( hexNodes[ 11 ] );
5488 pointsOnShapes[ SMESH_Block::ID_Ex10 ] = SMESH_TNodeXYZ( hexNodes[ 9 ] );
5489 pointsOnShapes[ SMESH_Block::ID_E0y0 ] = SMESH_TNodeXYZ( hexNodes[ 8 ] );
5490 pointsOnShapes[ SMESH_Block::ID_E1y0 ] = SMESH_TNodeXYZ( hexNodes[ 10 ] );
5491 pointsOnShapes[ SMESH_Block::ID_Ex01 ] = SMESH_TNodeXYZ( hexNodes[ 15 ] );
5492 pointsOnShapes[ SMESH_Block::ID_Ex11 ] = SMESH_TNodeXYZ( hexNodes[ 13 ] );
5493 pointsOnShapes[ SMESH_Block::ID_E0y1 ] = SMESH_TNodeXYZ( hexNodes[ 12 ] );
5494 pointsOnShapes[ SMESH_Block::ID_E1y1 ] = SMESH_TNodeXYZ( hexNodes[ 14 ] );
5495 pointsOnShapes[ SMESH_Block::ID_E00z ] = SMESH_TNodeXYZ( hexNodes[ 16 ] );
5496 pointsOnShapes[ SMESH_Block::ID_E10z ] = SMESH_TNodeXYZ( hexNodes[ 19 ] );
5497 pointsOnShapes[ SMESH_Block::ID_E01z ] = SMESH_TNodeXYZ( hexNodes[ 17 ] );
5498 pointsOnShapes[ SMESH_Block::ID_E11z ] = SMESH_TNodeXYZ( hexNodes[ 18 ] );
5500 pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = SMESH_TNodeXYZ( hexNodes[ 20 ] );
5501 pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = SMESH_TNodeXYZ( hexNodes[ 25 ] );
5502 pointsOnShapes[ SMESH_Block::ID_Fx0z ] = SMESH_TNodeXYZ( hexNodes[ 21 ] );
5503 pointsOnShapes[ SMESH_Block::ID_Fx1z ] = SMESH_TNodeXYZ( hexNodes[ 23 ] );
5504 pointsOnShapes[ SMESH_Block::ID_F0yz ] = SMESH_TNodeXYZ( hexNodes[ 24 ] );
5505 pointsOnShapes[ SMESH_Block::ID_F1yz ] = SMESH_TNodeXYZ( hexNodes[ 22 ] );
5507 gp_XYZ nCenterParams(0.5, 0.5, 0.5), nCenterCoords;
5508 SMESH_Block::ShellPoint( nCenterParams, pointsOnShapes, nCenterCoords );
5509 GetMeshDS()->MoveNode( hexNodes[26],
5510 nCenterCoords.X(), nCenterCoords.Y(), nCenterCoords.Z());
5513 // treat tri-quadratic hexahedra
5515 SMDS_VolumeTool volExp;
5516 TIDSortedElemSet::iterator pentIt = biQuadPenta.begin();
5517 for ( ; pentIt != biQuadPenta.end(); ++pentIt )
5520 volExp.Set( *pentIt, /*ignoreCentralNodes=*/false );
5524 // avoid warning: defined but not used operator<<()
5525 SMESH_Comment() << *links.begin() << *faces.begin();
5529 //================================================================================
5533 //================================================================================
5535 void SMESH_MesherHelper::WriteShape(const TopoDS_Shape& s)
5537 const char* name = "/tmp/shape.brep";
5538 BRepTools::Write( s, name );
5540 std::cout << name << std::endl;