X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshers%2FStdMeshers_ViscousLayers2D.cxx;h=a17dd43add787d24534306959f05ae420721c595;hp=7e51343806582b8efe075c49f1ae779e1d08eeee;hb=a274ade365bd0f0e19d56c577acc4a13aa1972a7;hpb=5d68554076bbca0e1e95fb0db215a6c2b84b6c54 diff --git a/src/StdMeshers/StdMeshers_ViscousLayers2D.cxx b/src/StdMeshers/StdMeshers_ViscousLayers2D.cxx index 7e5134380..a17dd43ad 100644 --- a/src/StdMeshers/StdMeshers_ViscousLayers2D.cxx +++ b/src/StdMeshers/StdMeshers_ViscousLayers2D.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -30,6 +30,7 @@ #include "SMDS_SetIterator.hxx" #include "SMESHDS_Group.hxx" #include "SMESHDS_Hypothesis.hxx" +#include "SMESHDS_Mesh.hxx" #include "SMESH_Algo.hxx" #include "SMESH_ComputeError.hxx" #include "SMESH_ControlsDef.hxx" @@ -37,6 +38,7 @@ #include "SMESH_Group.hxx" #include "SMESH_HypoFilter.hxx" #include "SMESH_Mesh.hxx" +#include "SMESH_MeshEditor.hxx" #include "SMESH_MesherHelper.hxx" #include "SMESH_ProxyMesh.hxx" #include "SMESH_Quadtree.hxx" @@ -109,14 +111,15 @@ namespace VISCOUS_2D // Proxy sub-mesh of an EDGE. It contains nodes in _uvPtStructVec. struct _EdgeSubMesh : public SMESH_ProxyMesh::SubMesh { - _EdgeSubMesh(int index=0): SubMesh(index) {} + _EdgeSubMesh(const SMDS_Mesh* mesh, int index=0): SubMesh(mesh,index) {} //virtual int NbElements() const { return _elements.size()+1; } virtual int NbNodes() const { return Max( 0, _uvPtStructVec.size()-2 ); } void SetUVPtStructVec(UVPtStructVec& vec) { _uvPtStructVec.swap( vec ); } + UVPtStructVec& GetUVPtStructVec() { return _uvPtStructVec; } }; _ProxyMeshOfFace(const SMESH_Mesh& mesh): SMESH_ProxyMesh(mesh) {} _EdgeSubMesh* GetEdgeSubMesh(int ID) { return (_EdgeSubMesh*) getProxySubMesh(ID); } - virtual SubMesh* newSubmesh(int index=0) const { return new _EdgeSubMesh(index); } + virtual SubMesh* newSubmesh(int index=0) const { return new _EdgeSubMesh( GetMeshDS(), index); } }; //-------------------------------------------------------------------------------- /*! @@ -147,7 +150,7 @@ namespace VISCOUS_2D // Treat events void ProcessEvent(const int event, const int eventType, - SMESH_subMesh* subMesh, + SMESH_subMesh* /*subMesh*/, EventListenerData* data, const SMESH_Hypothesis* /*hyp*/) { @@ -174,7 +177,7 @@ namespace VISCOUS_2D */ struct _Segment { - const gp_XY* _uv[2]; // poiter to _LayerEdge::_uvIn + const gp_XY* _uv[2]; // pointer to _LayerEdge::_uvIn int _indexInLine; // position in _PolyLine _Segment() {} @@ -256,6 +259,7 @@ namespace VISCOUS_2D _PolyLine* _rightLine; int _firstPntInd; // index in vector of _wire int _lastPntInd; + int _index; // index in _ViscousBuilder2D::_polyLineVec vector< _LayerEdge > _lEdges; /* _lEdges[0] is usually is not treated as it is equal to the last one of the _leftLine */ @@ -298,6 +302,8 @@ namespace VISCOUS_2D double _D; // _vec1.Crossed( _vec2 ) double _param1, _param2; // intersection param on _seg1 and _seg2 + _SegmentIntersection(): _D(0), _param1(0), _param2(0) {} + bool Compute(const _Segment& seg1, const _Segment& seg2, bool seg2IsRay = false ) { // !!! If seg2IsRay, returns true at any _param2 !!! @@ -325,6 +331,7 @@ namespace VISCOUS_2D //-------------------------------------------------------------------------------- typedef map< const SMDS_MeshNode*, _LayerEdge*, TIDCompare > TNode2Edge; + typedef StdMeshers_ViscousLayers2D THypVL; //-------------------------------------------------------------------------------- /*! @@ -335,14 +342,17 @@ namespace VISCOUS_2D public: _ViscousBuilder2D(SMESH_Mesh& theMesh, const TopoDS_Face& theFace, - const StdMeshers_ViscousLayers2D* theHyp); + vector< const THypVL* > & theHyp, + vector< TopoDS_Shape > & theHypShapes); SMESH_ComputeErrorPtr GetError() const { return _error; } // does it's job - SMESH_ProxyMesh::Ptr Compute(const TopoDS_Shape& theShapeHypAssignedTo); + SMESH_ProxyMesh::Ptr Compute(); private: - bool findEdgesWithLayers(const TopoDS_Shape& theShapeHypAssignedTo); + friend class ::StdMeshers_ViscousLayers2D; + + bool findEdgesWithLayers(); bool makePolyLines(); bool inflate(); bool fixCollisions(); @@ -362,9 +372,13 @@ namespace VISCOUS_2D GeomAPI_ProjectPointOnSurf* faceProj); void adjustCommonEdge( _PolyLine& LL, _PolyLine& LR ); void calcLayersHeight(const double totalThick, - vector& heights); + vector& heights, + const THypVL* hyp); bool removeMeshFaces(const TopoDS_Shape& face); + const THypVL* getLineHypothesis(int iPL); + double getLineThickness (int iPL); + bool error( const string& text ); SMESHDS_Mesh* getMeshDS() { return _mesh->GetMeshDS(); } _ProxyMeshOfFace* getProxyMesh(); @@ -377,7 +391,8 @@ namespace VISCOUS_2D // input data SMESH_Mesh* _mesh; TopoDS_Face _face; - const StdMeshers_ViscousLayers2D* _hyp; + vector< const THypVL* > _hyps; + vector< TopoDS_Shape > _hypShapes; // result data SMESH_ProxyMesh::Ptr _proxyMesh; @@ -388,11 +403,12 @@ namespace VISCOUS_2D SMESH_MesherHelper _helper; TSideVector _faceSideVec; // wires (StdMeshers_FaceSide) of _face vector<_PolyLine> _polyLineVec; // fronts to advance + vector< const THypVL* > _hypOfEdge; // a hyp per an EDGE of _faceSideVec bool _is2DIsotropic; // is same U and V resoulution of _face vector _clearedFaces; // FACEs whose mesh was removed by shrink() - double _fPowN; // to compute thickness of layers - double _thickness; // required or possible layers thickness + //double _fPowN; // to compute thickness of layers + double _maxThickness; // max possible layers thickness // sub-shapes of _face set _ignoreShapeIds; // ids of EDGEs w/o layers @@ -409,15 +425,32 @@ namespace VISCOUS_2D /*! * \brief Returns StdMeshers_ViscousLayers2D for the FACE */ - const StdMeshers_ViscousLayers2D* findHyp(SMESH_Mesh& theMesh, - const TopoDS_Face& theFace, - TopoDS_Shape* assignedTo=0) + bool findHyps(SMESH_Mesh& theMesh, + const TopoDS_Face& theFace, + vector< const StdMeshers_ViscousLayers2D* > & theHyps, + vector< TopoDS_Shape > & theAssignedTo) { + theHyps.clear(); + theAssignedTo.clear(); SMESH_HypoFilter hypFilter ( SMESH_HypoFilter::HasName( StdMeshers_ViscousLayers2D::GetHypType() )); - const SMESH_Hypothesis * hyp = - theMesh.GetHypothesis( theFace, hypFilter, /*ancestors=*/true, assignedTo ); - return dynamic_cast< const StdMeshers_ViscousLayers2D* > ( hyp ); + list< const SMESHDS_Hypothesis * > hypList; + list< TopoDS_Shape > hypShapes; + int nbHyps = theMesh.GetHypotheses + ( theFace, hypFilter, hypList, /*ancestors=*/true, &hypShapes ); + if ( nbHyps ) + { + theHyps.reserve( nbHyps ); + theAssignedTo.reserve( nbHyps ); + list< const SMESHDS_Hypothesis * >::iterator hyp = hypList.begin(); + list< TopoDS_Shape >::iterator shape = hypShapes.begin(); + for ( ; hyp != hypList.end(); ++hyp, ++shape ) + { + theHyps.push_back( static_cast< const StdMeshers_ViscousLayers2D* > ( *hyp )); + theAssignedTo.push_back( *shape ); + } + } + return nbHyps; } //================================================================================ @@ -436,7 +469,7 @@ namespace VISCOUS_2D const SMESHDS_Mesh* theMesh, set< int > & theEdgeIds) { - int nbToEdgesIgnore = 0; + int nbEdgesToIgnore = 0; vector ids = theHyp->GetBndShapes(); if ( theHyp->IsToIgnoreShapes() ) // EDGEs to ignore are given { @@ -448,20 +481,20 @@ namespace VISCOUS_2D SMESH_MesherHelper::IsSubShape( E, theFace )) { theEdgeIds.insert( ids[i] ); - ++nbToEdgesIgnore; + ++nbEdgesToIgnore; } } } else // EDGEs to make the Viscous Layers on are given { TopExp_Explorer E( theFace, TopAbs_EDGE ); - for ( ; E.More(); E.Next(), ++nbToEdgesIgnore ) + for ( ; E.More(); E.Next(), ++nbEdgesToIgnore ) theEdgeIds.insert( theMesh->ShapeToIndex( E.Current() )); for ( size_t i = 0; i < ids.size(); ++i ) - nbToEdgesIgnore -= theEdgeIds.erase( ids[i] ); + nbEdgesToIgnore -= theEdgeIds.erase( ids[i] ); } - return nbToEdgesIgnore; + return nbEdgesToIgnore; } } // namespace VISCOUS_2D @@ -469,15 +502,15 @@ namespace VISCOUS_2D //================================================================================ // StdMeshers_ViscousLayers hypothesis // -StdMeshers_ViscousLayers2D::StdMeshers_ViscousLayers2D(int hypId, int studyId, SMESH_Gen* gen) - :StdMeshers_ViscousLayers(hypId, studyId, gen) +StdMeshers_ViscousLayers2D::StdMeshers_ViscousLayers2D(int hypId, SMESH_Gen* gen) + :StdMeshers_ViscousLayers(hypId, gen) { _name = StdMeshers_ViscousLayers2D::GetHypType(); _param_algo_dim = -2; // auxiliary hyp used by 2D algos } // -------------------------------------------------------------------------------- -bool StdMeshers_ViscousLayers2D::SetParametersByMesh(const SMESH_Mesh* theMesh, - const TopoDS_Shape& theShape) +bool StdMeshers_ViscousLayers2D::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) { // TODO ??? return false; @@ -487,32 +520,88 @@ SMESH_ProxyMesh::Ptr StdMeshers_ViscousLayers2D::Compute(SMESH_Mesh& theMesh, const TopoDS_Face& theFace) { - SMESH_ProxyMesh::Ptr pm; + using namespace VISCOUS_2D; + vector< const StdMeshers_ViscousLayers2D* > hyps; + vector< TopoDS_Shape > hypShapes; - TopoDS_Shape hypAssignedTo; - const StdMeshers_ViscousLayers2D* vlHyp = VISCOUS_2D::findHyp( theMesh, theFace, &hypAssignedTo ); - if ( vlHyp ) + SMESH_ProxyMesh::Ptr pm = _ProxyMeshHolder::FindProxyMeshOfFace( theFace, theMesh ); + if ( !pm ) { - VISCOUS_2D::_ViscousBuilder2D builder( theMesh, theFace, vlHyp ); - pm = builder.Compute( hypAssignedTo ); - SMESH_ComputeErrorPtr error = builder.GetError(); - if ( error && !error->IsOK() ) - theMesh.GetSubMesh( theFace )->GetComputeError() = error; - else if ( !pm ) + if ( findHyps( theMesh, theFace, hyps, hypShapes )) + { + VISCOUS_2D::_ViscousBuilder2D builder( theMesh, theFace, hyps, hypShapes ); + pm = builder.Compute(); + SMESH_ComputeErrorPtr error = builder.GetError(); + if ( error && !error->IsOK() ) + theMesh.GetSubMesh( theFace )->GetComputeError() = error; + else if ( !pm ) + pm.reset( new SMESH_ProxyMesh( theMesh )); + if ( getenv("__ONLY__VL2D__")) + pm.reset(); + } + else + { pm.reset( new SMESH_ProxyMesh( theMesh )); - if ( getenv("__ONLY__VL2D__")) - pm.reset(); + } } - else + return pm; +} +// -------------------------------------------------------------------------------- +void StdMeshers_ViscousLayers2D::SetProxyMeshOfEdge( const StdMeshers_FaceSide& edgeNodes ) +{ + using namespace VISCOUS_2D; + SMESH_ProxyMesh::Ptr pm = + _ProxyMeshHolder::FindProxyMeshOfFace( edgeNodes.Face(), *edgeNodes.GetMesh() ); + if ( !pm ) { + _ProxyMeshOfFace* proxyMeshOfFace = new _ProxyMeshOfFace( *edgeNodes.GetMesh() ); + pm.reset( proxyMeshOfFace ); + new _ProxyMeshHolder( edgeNodes.Face(), pm ); + } + _ProxyMeshOfFace* proxyMeshOfFace = static_cast<_ProxyMeshOfFace*>( pm.get() ); + _ProxyMeshOfFace::_EdgeSubMesh* sm = proxyMeshOfFace->GetEdgeSubMesh( edgeNodes.EdgeID(0) ); + sm->GetUVPtStructVec() = edgeNodes.GetUVPtStruct(); +} +// -------------------------------------------------------------------------------- +bool StdMeshers_ViscousLayers2D::HasProxyMesh( const TopoDS_Face& face, SMESH_Mesh& mesh ) +{ + return VISCOUS_2D::_ProxyMeshHolder::FindProxyMeshOfFace( face, mesh ).get(); +} +// -------------------------------------------------------------------------------- +SMESH_ComputeErrorPtr +StdMeshers_ViscousLayers2D::CheckHypothesis(SMESH_Mesh& theMesh, + const TopoDS_Shape& theShape, + SMESH_Hypothesis::Hypothesis_Status& theStatus) +{ + SMESH_ComputeErrorPtr error = SMESH_ComputeError::New(COMPERR_OK); + theStatus = SMESH_Hypothesis::HYP_OK; + + TopExp_Explorer exp( theShape, TopAbs_FACE ); + for ( ; exp.More() && theStatus == SMESH_Hypothesis::HYP_OK; exp.Next() ) { - pm.reset( new SMESH_ProxyMesh( theMesh )); + const TopoDS_Face& face = TopoDS::Face( exp.Current() ); + vector< const StdMeshers_ViscousLayers2D* > hyps; + vector< TopoDS_Shape > hypShapes; + if ( VISCOUS_2D::findHyps( theMesh, face, hyps, hypShapes )) + { + VISCOUS_2D::_ViscousBuilder2D builder( theMesh, face, hyps, hypShapes ); + builder._faceSideVec = + StdMeshers_FaceSide::GetFaceWires( face, theMesh, true, error, + NULL, SMESH_ProxyMesh::Ptr(), + /*theCheckVertexNodes=*/false); + if ( error->IsOK() && !builder.findEdgesWithLayers()) + { + error = builder.GetError(); + if ( error && !error->IsOK() ) + theStatus = SMESH_Hypothesis::HYP_INCOMPAT_HYPS; + } + } } - return pm; + return error; } // -------------------------------------------------------------------------------- void StdMeshers_ViscousLayers2D::RestoreListeners() const { - StudyContextStruct* sc = _gen->GetStudyContext( _studyId ); + StudyContextStruct* sc = _gen->GetStudyContext(); std::map < int, SMESH_Mesh * >::iterator i_smesh = sc->mapMesh.begin(); for ( ; i_smesh != sc->mapMesh.end(); ++i_smesh ) { @@ -547,19 +636,22 @@ using namespace VISCOUS_2D; */ //================================================================================ -_ViscousBuilder2D::_ViscousBuilder2D(SMESH_Mesh& theMesh, - const TopoDS_Face& theFace, - const StdMeshers_ViscousLayers2D* theHyp): - _mesh( &theMesh ), _face( theFace ), _hyp( theHyp ), _helper( theMesh ) +_ViscousBuilder2D::_ViscousBuilder2D(SMESH_Mesh& theMesh, + const TopoDS_Face& theFace, + vector< const THypVL* > & theHyps, + vector< TopoDS_Shape > & theAssignedTo): + _mesh( &theMesh ), _face( theFace ), _helper( theMesh ) { + _hyps.swap( theHyps ); + _hypShapes.swap( theAssignedTo ); + _helper.SetSubShape( _face ); _helper.SetElementsOnShape( true ); _face.Orientation( TopAbs_FORWARD ); // 2D logic works only in this case _surface = BRep_Tool::Surface( _face ); - if ( _hyp ) - _fPowN = pow( _hyp->GetStretchFactor(), _hyp->GetNumberLayers() ); + _error = SMESH_ComputeError::New(COMPERR_OK); _nbLE = 0; } @@ -593,14 +685,14 @@ bool _ViscousBuilder2D::error(const string& text ) */ //================================================================================ -SMESH_ProxyMesh::Ptr _ViscousBuilder2D::Compute(const TopoDS_Shape& theShapeHypAssignedTo) +SMESH_ProxyMesh::Ptr _ViscousBuilder2D::Compute() { - _error = SMESH_ComputeError::New(COMPERR_OK); - _faceSideVec = StdMeshers_FaceSide::GetFaceWires( _face, *_mesh, true, _error ); + _faceSideVec = StdMeshers_FaceSide::GetFaceWires( _face, *_mesh, true, _error, &_helper ); + if ( !_error->IsOK() ) return _proxyMesh; - if ( !findEdgesWithLayers(theShapeHypAssignedTo) ) // analysis of a shape + if ( !findEdgesWithLayers() ) // analysis of a shape return _proxyMesh; if ( ! makePolyLines() ) // creation of fronts @@ -629,21 +721,79 @@ SMESH_ProxyMesh::Ptr _ViscousBuilder2D::Compute(const TopoDS_Shape& theShapeHypA */ //================================================================================ -bool _ViscousBuilder2D::findEdgesWithLayers(const TopoDS_Shape& theShapeHypAssignedTo) +bool _ViscousBuilder2D::findEdgesWithLayers() { - // collect all EDGEs to ignore defined by hyp - int nbMyEdgesIgnored = getEdgesToIgnore( _hyp, _face, getMeshDS(), _ignoreShapeIds ); + // collect all EDGEs to ignore defined by _hyps + typedef std::pair< set, const THypVL* > TEdgesOfHyp; + vector< TEdgesOfHyp > ignoreEdgesOfHyp( _hyps.size() ); + for ( size_t i = 0; i < _hyps.size(); ++i ) + { + ignoreEdgesOfHyp[i].second = _hyps[i]; + getEdgesToIgnore( _hyps[i], _face, getMeshDS(), ignoreEdgesOfHyp[i].first ); + } // get all shared EDGEs TopTools_MapOfShape sharedEdges; + TopTools_IndexedMapOfShape hypFaces; // faces with VL hyps + for ( size_t i = 0; i < _hypShapes.size(); ++i ) + TopExp::MapShapes( _hypShapes[i], TopAbs_FACE, hypFaces ); TopTools_IndexedDataMapOfShapeListOfShape facesOfEdgeMap; - TopExp::MapShapesAndAncestors( theShapeHypAssignedTo, - TopAbs_EDGE, TopAbs_FACE, facesOfEdgeMap); + for ( int iF = 1; iF <= hypFaces.Extent(); ++iF ) + TopExp::MapShapesAndAncestors( hypFaces(iF), TopAbs_EDGE, TopAbs_FACE, facesOfEdgeMap); for ( int iE = 1; iE <= facesOfEdgeMap.Extent(); ++iE ) if ( facesOfEdgeMap( iE ).Extent() > 1 ) sharedEdges.Add( facesOfEdgeMap.FindKey( iE )); - // check all EDGEs of the _face + // fill _hypOfEdge + if ( _hyps.size() > 1 ) + { + // check if two hypotheses define different parameters for the same EDGE + for ( size_t iWire = 0; iWire < _faceSideVec.size(); ++iWire ) + { + StdMeshers_FaceSidePtr wire = _faceSideVec[ iWire ]; + for ( int iE = 0; iE < wire->NbEdges(); ++iE ) + { + const THypVL* hyp = 0; + const TGeomID edgeID = wire->EdgeID( iE ); + if ( !sharedEdges.Contains( wire->Edge( iE ))) + { + for ( size_t i = 0; i < ignoreEdgesOfHyp.size(); ++i ) + if ( ! ignoreEdgesOfHyp[i].first.count( edgeID )) + { + if ( hyp ) + return error(SMESH_Comment("Several hypotheses define " + "Viscous Layers on the edge #") << edgeID ); + hyp = ignoreEdgesOfHyp[i].second; + } + } + _hypOfEdge.push_back( hyp ); + if ( !hyp ) + _ignoreShapeIds.insert( edgeID ); + } + // check if two hypotheses define different number of viscous layers for + // adjacent EDGEs + const THypVL *hyp, *prevHyp = _hypOfEdge.back(); + size_t iH = _hypOfEdge.size() - wire->NbEdges(); + for ( ; iH < _hypOfEdge.size(); ++iH ) + { + hyp = _hypOfEdge[ iH ]; + if ( hyp && prevHyp && + hyp->GetNumberLayers() != prevHyp->GetNumberLayers() ) + { + return error("Two hypotheses define different number of " + "viscous layers on adjacent edges"); + } + prevHyp = hyp; + } + } + } + else if ( _hyps.size() == 1 ) + { + _ignoreShapeIds.swap( ignoreEdgesOfHyp[0].first ); + } + + // check all EDGEs of the _face to fill _ignoreShapeIds and _noShrinkVert + int totalNbEdges = 0; for ( size_t iWire = 0; iWire < _faceSideVec.size(); ++iWire ) { @@ -674,9 +824,9 @@ bool _ViscousBuilder2D::findEdgesWithLayers(const TopoDS_Shape& theShapeHypAssig for ( ; hyp != allHyps.end() && !viscHyp; ++hyp ) viscHyp = dynamic_cast( *hyp ); - set neighbourIgnoreEdges; - if (viscHyp) - getEdgesToIgnore( viscHyp, neighbourFace, getMeshDS(), neighbourIgnoreEdges ); + // set neighbourIgnoreEdges; + // if (viscHyp) + // getEdgesToIgnore( viscHyp, neighbourFace, getMeshDS(), neighbourIgnoreEdges ); for ( int iV = 0; iV < 2; ++iV ) { @@ -688,12 +838,22 @@ bool _ViscousBuilder2D::findEdgesWithLayers(const TopoDS_Shape& theShapeHypAssig PShapeIteratorPtr edgeIt = _helper.GetAncestors( vertex, *_mesh, TopAbs_EDGE ); while ( const TopoDS_Shape* edge = edgeIt->next() ) if ( !edge->IsSame( wire->Edge( iE )) && - _helper.IsSubShape( *edge, neighbourFace ) && - ( neighbourIgnoreEdges.count( getMeshDS()->ShapeToIndex( *edge )) || - sharedEdges.Contains( *edge ))) + _helper.IsSubShape( *edge, neighbourFace )) { - _noShrinkVert.insert( getMeshDS()->ShapeToIndex( vertex )); - break; + const TGeomID neighbourID = getMeshDS()->ShapeToIndex( *edge ); + bool hasVL = !sharedEdges.Contains( *edge ); + if ( hasVL ) + { + hasVL = false; + for ( hyp = allHyps.begin(); hyp != allHyps.end() && !hasVL; ++hyp ) + if (( viscHyp = dynamic_cast( *hyp ))) + hasVL = viscHyp->IsShapeWithLayers( neighbourID ); + } + if ( !hasVL ) + { + _noShrinkVert.insert( getMeshDS()->ShapeToIndex( vertex )); + break; + } } } } @@ -702,18 +862,20 @@ bool _ViscousBuilder2D::findEdgesWithLayers(const TopoDS_Shape& theShapeHypAssig } } + int nbMyEdgesIgnored = _ignoreShapeIds.size(); + // add VERTEXes w/o layers to _ignoreShapeIds (this is used by toShrinkForAdjacent()) - for ( size_t iWire = 0; iWire < _faceSideVec.size(); ++iWire ) - { - StdMeshers_FaceSidePtr wire = _faceSideVec[ iWire ]; - for ( int iE = 0; iE < wire->NbEdges(); ++iE ) - { - TGeomID edge1 = wire->EdgeID( iE ); - TGeomID edge2 = wire->EdgeID( iE+1 ); - if ( _ignoreShapeIds.count( edge1 ) && _ignoreShapeIds.count( edge2 )) - _ignoreShapeIds.insert( getMeshDS()->ShapeToIndex( wire->LastVertex( iE ))); - } - } + // for ( size_t iWire = 0; iWire < _faceSideVec.size(); ++iWire ) + // { + // StdMeshers_FaceSidePtr wire = _faceSideVec[ iWire ]; + // for ( int iE = 0; iE < wire->NbEdges(); ++iE ) + // { + // TGeomID edge1 = wire->EdgeID( iE ); + // TGeomID edge2 = wire->EdgeID( iE+1 ); + // if ( _ignoreShapeIds.count( edge1 ) && _ignoreShapeIds.count( edge2 )) + // _ignoreShapeIds.insert( getMeshDS()->ShapeToIndex( wire->LastVertex( iE ))); + // } + // } return ( nbMyEdgesIgnored < totalNbEdges ); } @@ -772,6 +934,7 @@ bool _ViscousBuilder2D::makePolyLines() for ( int iE = 0; iE < wire->NbEdges(); ++iE ) { _PolyLine& L = _polyLineVec[ iPoLine++ ]; + L._index = iPoLine-1; L._wire = wire.get(); L._edgeInd = iE; L._advancable = !_ignoreShapeIds.count( wire->EdgeID( iE )); @@ -846,13 +1009,16 @@ bool _ViscousBuilder2D::makePolyLines() // Evaluate max possible _thickness if required layers thickness seems too high // ---------------------------------------------------------------------------- - _thickness = _hyp->GetTotalThickness(); + _maxThickness = _hyps[0]->GetTotalThickness(); + for ( size_t iH = 1; iH < _hyps.size(); ++iH ) + _maxThickness = Max( _maxThickness, _hyps[iH]->GetTotalThickness() ); + _SegmentTree::box_type faceBndBox2D; for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine ) faceBndBox2D.Add( *_polyLineVec[ iPoLine]._segTree->getBox() ); - double boxTol = 1e-3 * sqrt( faceBndBox2D.SquareExtent() ); - // - if ( _thickness * maxLen2dTo3dRatio > sqrt( faceBndBox2D.SquareExtent() ) / 10 ) + const double boxTol = 1e-3 * sqrt( faceBndBox2D.SquareExtent() ); + + if ( _maxThickness * maxLen2dTo3dRatio > sqrt( faceBndBox2D.SquareExtent() ) / 10 ) { vector< const _Segment* > foundSegs; double maxPossibleThick = 0; @@ -885,7 +1051,7 @@ bool _ViscousBuilder2D::makePolyLines() } } if ( maxPossibleThick > 0. ) - _thickness = Min( _hyp->GetTotalThickness(), maxPossibleThick ); + _maxThickness = Min( _maxThickness, maxPossibleThick ); } // Adjust _LayerEdge's at _PolyLine's extremities @@ -930,13 +1096,14 @@ bool _ViscousBuilder2D::makePolyLines() for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine ) { lineBoxes[ iPoLine ] = *_polyLineVec[ iPoLine ]._segTree->getBox(); - lineBoxes[ iPoLine ].Enlarge( maxLen2dTo3dRatio * _thickness * + lineBoxes[ iPoLine ].Enlarge( maxLen2dTo3dRatio * getLineThickness( iPoLine ) * ( _polyLineVec[ iPoLine ]._advancable ? 2. : 1.2 )); } // _reachableLines for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine ) { _PolyLine& L1 = _polyLineVec[ iPoLine ]; + const double thick1 = getLineThickness( iPoLine ); for ( size_t iL2 = 0; iL2 < _polyLineVec.size(); ++iL2 ) { _PolyLine& L2 = _polyLineVec[ iL2 ]; @@ -950,7 +1117,7 @@ bool _ViscousBuilder2D::makePolyLines() { _LayerEdge& LE = L1._lEdges[iLE]; if ( !lineBoxes[ iL2 ].IsOut ( LE._uvOut, - LE._uvOut + LE._normal2D *_thickness * LE._len2dTo3dRatio )) + LE._uvOut + LE._normal2D * thick1 * LE._len2dTo3dRatio )) { L1._reachableLines.push_back( & L2 ); break; @@ -1023,10 +1190,10 @@ void _ViscousBuilder2D::adjustCommonEdge( _PolyLine& LL, _PolyLine& LR ) // Remove _LayerEdge's intersecting the normAvg to avoid collisions // during inflate(). // - // find max length of the VERTEX based _LayerEdge whose direction is normAvg - double maxLen2D = _thickness * EL._len2dTo3dRatio; - const gp_XY& pCommOut = ER._uvOut; - gp_XY pCommIn = pCommOut + normAvg * maxLen2D; + // find max length of the VERTEX-based _LayerEdge whose direction is normAvg + double maxLen2D = _maxThickness * EL._len2dTo3dRatio; + const gp_XY& pCommOut = ER._uvOut; + gp_XY pCommIn = pCommOut + normAvg * maxLen2D; _Segment segCommon( pCommOut, pCommIn ); _SegmentIntersection intersection; vector< const _Segment* > foundSegs; @@ -1067,7 +1234,7 @@ void _ViscousBuilder2D::adjustCommonEdge( _PolyLine& LL, _PolyLine& LR ) _SegmentIntersection lastIntersection; for ( ; iLE < L._lEdges.size(); ++iLE, eIt += dIt ) { - gp_XY uvIn = eIt->_uvOut + eIt->_normal2D * _thickness * eIt->_len2dTo3dRatio; + gp_XY uvIn = eIt->_uvOut + eIt->_normal2D * _maxThickness * eIt->_len2dTo3dRatio; _Segment segOfEdge( eIt->_uvOut, uvIn ); if ( !intersection.Compute( segCommon, segOfEdge )) break; @@ -1097,7 +1264,7 @@ void _ViscousBuilder2D::adjustCommonEdge( _PolyLine& LL, _PolyLine& LR ) if ( isR ) LR._lEdges.erase( LR._lEdges.begin()+1, eIt ); else - LL._lEdges.erase( eIt, --LL._lEdges.end() ); + LL._lEdges.erase( eIt+1, --LL._lEdges.end() ); // eIt = isR ? L._lEdges.begin()+1 : L._lEdges.end()-2; // for ( size_t i = 1; i < iLE; ++i, eIt += dIt ) // eIt->_isBlocked = true; @@ -1148,11 +1315,11 @@ void _ViscousBuilder2D::setLayerEdgeData( _LayerEdge& lEdge, gp_Vec faceNorm = du ^ dv; gp_Vec normal = faceNorm ^ tangent; normal.Normalize(); - p = pOut.XYZ() + normal.XYZ() * /*1e-2 * */_hyp->GetTotalThickness() / _hyp->GetNumberLayers(); + p = pOut.XYZ() + normal.XYZ() * /*1e-2 * */_hyps[0]->GetTotalThickness() / _hyps[0]->GetNumberLayers(); faceProj->Perform( p ); if ( !faceProj->IsDone() || faceProj->NbPoints() < 1 ) return setLayerEdgeData( lEdge, u, pcurve, curve, p, reverse, NULL ); - Quantity_Parameter U,V; + Standard_Real U,V; faceProj->LowerDistanceParameters(U,V); lEdge._normal2D.SetCoord( U - uv.X(), V - uv.Y() ); lEdge._normal2D.Normalize(); @@ -1205,7 +1372,7 @@ bool _ViscousBuilder2D::inflate() { // Limit size of inflation step by geometry size found by // itersecting _LayerEdge's with _Segment's - double minSize = _thickness, maxSize = 0; + double minSize = _maxThickness, maxSize = 0; vector< const _Segment* > foundSegs; _SegmentIntersection intersection; for ( size_t iL1 = 0; iL1 < _polyLineVec.size(); ++iL1 ) @@ -1233,29 +1400,30 @@ bool _ViscousBuilder2D::inflate() } } if ( minSize > maxSize ) // no collisions possible - maxSize = _thickness; + maxSize = _maxThickness; #ifdef __myDEBUG cout << "-- minSize = " << minSize << ", maxSize = " << maxSize << endl; #endif double curThick = 0, stepSize = minSize; int nbSteps = 0; - if ( maxSize > _thickness ) - maxSize = _thickness; + if ( maxSize > _maxThickness ) + maxSize = _maxThickness; while ( curThick < maxSize ) { curThick += stepSize * 1.25; - if ( curThick > _thickness ) - curThick = _thickness; + if ( curThick > _maxThickness ) + curThick = _maxThickness; // Elongate _LayerEdge's for ( size_t iL = 0; iL < _polyLineVec.size(); ++iL ) { _PolyLine& L = _polyLineVec[ iL ]; if ( !L._advancable ) continue; + const double lineThick = Min( curThick, getLineThickness( iL )); bool lenChange = false; for ( size_t iLE = L.FirstLEdge(); iLE < L._lEdges.size(); ++iLE ) - lenChange |= L._lEdges[iLE].SetNewLength( curThick ); + lenChange |= L._lEdges[iLE].SetNewLength( lineThick ); // for ( int k=0; k_length2D == 0 ) continue; _Segment seg1( eIt->_uvOut, eIt->_uvIn ); - for ( eIt += deltaIt; nbRemove < L._lEdges.size()-1; eIt += deltaIt ) + for ( eIt += deltaIt; nbRemove < (int)L._lEdges.size()-1; eIt += deltaIt ) { _Segment seg2( eIt->_uvOut, eIt->_uvIn ); if ( !intersection.Compute( seg1, seg2 )) @@ -1307,7 +1475,7 @@ bool _ViscousBuilder2D::inflate() ++nbRemove; } if ( nbRemove > 0 ) { - if ( nbRemove == L._lEdges.size()-1 ) // 1st and last _LayerEdge's intersect + if ( nbRemove == (int)L._lEdges.size()-1 ) // 1st and last _LayerEdge's intersect { --nbRemove; _LayerEdge& L0 = L._lEdges.front(); @@ -1533,26 +1701,28 @@ bool _ViscousBuilder2D::shrink() int iPFrom = L._firstPntInd, iPTo = L._lastPntInd; if ( isShrinkableL ) { + const THypVL* hyp = getLineHypothesis( L._leftLine->_index ); vector& uvVec = L._lEdges.front()._uvRefined; - for ( int i = 0; i < _hyp->GetNumberLayers(); ++i ) { + for ( int i = 0; i < hyp->GetNumberLayers(); ++i ) { const UVPtStruct& uvPt = points[ iPFrom + i + 1 ]; L._leftNodes.push_back( uvPt.node ); uvVec.push_back ( pcurve->Value( uvPt.param ).XY() ); } + iPFrom += hyp->GetNumberLayers(); } if ( isShrinkableR ) { + const THypVL* hyp = getLineHypothesis( L._rightLine->_index ); vector& uvVec = L._lEdges.back()._uvRefined; - for ( int i = 0; i < _hyp->GetNumberLayers(); ++i ) { + for ( int i = 0; i < hyp->GetNumberLayers(); ++i ) { const UVPtStruct& uvPt = points[ iPTo - i - 1 ]; L._rightNodes.push_back( uvPt.node ); uvVec.push_back ( pcurve->Value( uvPt.param ).XY() ); } + iPTo -= hyp->GetNumberLayers(); } // make proxy sub-mesh data of present nodes // - if ( isShrinkableL ) iPFrom += _hyp->GetNumberLayers(); - if ( isShrinkableR ) iPTo -= _hyp->GetNumberLayers(); UVPtStructVec nodeDataVec( & points[ iPFrom ], & points[ iPTo + 1 ]); double normSize = nodeDataVec.back().normParam - nodeDataVec.front().normParam; @@ -1571,9 +1741,48 @@ bool _ViscousBuilder2D::shrink() myEdgeSM->SetUVPtStructVec( nodeDataVec ); existingNodesFound = true; + break; } } // loop on FACEs sharing E + // Check if L is an already shrinked seam + if ( adjFace.IsNull() && _helper.IsRealSeam( edgeID )) + if ( L._wire->Edge( L._edgeInd ).Orientation() == TopAbs_FORWARD ) + continue; + // Commented as a case with a seam EDGE (issue 0052461) is hard to support + // because SMESH_ProxyMesh can't hold different sub-meshes for two + // 2D representations of the seam. But such a case is not a real practice one. + // { + // for ( int iL2 = iL1-1; iL2 > -1; --iL2 ) + // { + // _PolyLine& L2 = _polyLineVec[ iL2 ]; + // if ( edgeID == L2._wire->EdgeID( L2._edgeInd )) + // { + // // copy layer nodes + // const int seamPar = _helper.GetPeriodicIndex(); + // vector& uvVec = L._lEdges.front()._uvRefined; + // if ( isShrinkableL ) + // { + // L._leftNodes = L2._rightNodes; + // uvVec = L2._lEdges.back()._uvRefined; + // } + // if ( isShrinkableR ) + // { + // L._rightNodes = L2._leftNodes; + // uvVec = L2._lEdges.front()._uvRefined; + // } + // for ( size_t i = 0; i < uvVec.size(); ++i ) + // { + // gp_XY & uv = uvVec[i]; + // uv.SetCoord( seamPar, _helper.GetOtherParam( uv.Coord( seamPar ))); + // } + + // existingNodesFound = true; + // break; + // } + // } + // } + if ( existingNodesFound ) continue; // nothing more to do in this case @@ -1616,7 +1825,7 @@ bool _ViscousBuilder2D::shrink() // x-x-x-x-----x-----x---- // | | | | e1 e2 e3 - int isRShrinkedForAdjacent; + int isRShrinkedForAdjacent = 0; UVPtStructVec nodeDataForAdjacent; for ( int isR = 0; isR < 2; ++isR ) { @@ -1686,14 +1895,14 @@ bool _ViscousBuilder2D::shrink() ( isR ? L._leftLine->_lEdges.back() : L._rightLine->_lEdges.front() ); length2D = neighborLE._length2D; if ( length2D == 0 ) - length2D = _thickness * nearLE._len2dTo3dRatio; + length2D = _maxThickness * nearLE._len2dTo3dRatio; } } // move u to the internal boundary of layers // u --> u // x-x-x-x-----x-----x---- - double maxLen3D = Min( _thickness, edgeLen / ( 1 + nbAdvancable )); + double maxLen3D = Min( _maxThickness, edgeLen / ( 1 + nbAdvancable )); double maxLen2D = maxLen3D * nearLE._len2dTo3dRatio; if ( !length2D ) length2D = length1D / len1dTo2dRatio; if ( Abs( length2D ) > maxLen2D ) @@ -1709,7 +1918,8 @@ bool _ViscousBuilder2D::shrink() // compute params of layers on L vector heights; - calcLayersHeight( u - u0, heights ); + const THypVL* hyp = getLineHypothesis( L2->_index ); + calcLayersHeight( u - u0, heights, hyp ); // vector< double > params( heights.size() ); for ( size_t i = 0; i < params.size(); ++i ) @@ -1719,13 +1929,13 @@ bool _ViscousBuilder2D::shrink() // x-x-x-x--- vector< const SMDS_MeshNode* >& layersNode = isR ? L._rightNodes : L._leftNodes; vector& nodeUV = ( isR ? L._lEdges.back() : L._lEdges[0] )._uvRefined; - nodeUV.resize ( _hyp->GetNumberLayers() ); - layersNode.resize( _hyp->GetNumberLayers() ); + nodeUV.resize ( hyp->GetNumberLayers() ); + layersNode.resize( hyp->GetNumberLayers() ); const SMDS_MeshNode* vertexNode = nodeDataVec[ iPEnd ].node; const SMDS_MeshNode * prevNode = vertexNode; for ( size_t i = 0; i < params.size(); ++i ) { - gp_Pnt p = curve.Value( params[i] ); + const gp_Pnt p = curve.Value( params[i] ); layersNode[ i ] = helper.AddNode( p.X(), p.Y(), p.Z(), /*id=*/0, params[i] ); nodeUV [ i ] = pcurve->Value( params[i] ).XY(); helper.AddEdge( prevNode, layersNode[ i ] ); @@ -1736,7 +1946,7 @@ bool _ViscousBuilder2D::shrink() if ( !L2->_advancable ) { isRShrinkedForAdjacent = isR; - nodeDataForAdjacent.resize( _hyp->GetNumberLayers() ); + nodeDataForAdjacent.resize( hyp->GetNumberLayers() ); size_t iFrw = 0, iRev = nodeDataForAdjacent.size()-1, *i = isR ? &iRev : &iFrw; nodeDataForAdjacent[ *i ] = points[ isR ? L._lastPntInd : L._firstPntInd ]; @@ -1789,7 +1999,7 @@ bool _ViscousBuilder2D::shrink() throw SALOME_Exception(SMESH_Comment("ViscousBuilder2D: not SMDS_TOP_EDGE node position: ") << oldNode->GetPosition()->GetTypeOfPosition() << " of node " << oldNode->GetID()); - SMDS_EdgePosition* pos = static_cast( oldNode->GetPosition() ); + SMDS_EdgePositionPtr pos = oldNode->GetPosition(); pos->SetUParameter( nodeDataVec[iP].param ); gp_Pnt newP = curve.Value( nodeDataVec[iP].param ); @@ -1853,11 +2063,11 @@ bool _ViscousBuilder2D::shrink() { // refine the not shared _LayerEdge vector layersHeight; - calcLayersHeight( LE2._length2D, layersHeight ); + calcLayersHeight( LE2._length2D, layersHeight, getLineHypothesis( L2._index )); vector& nodeUV2 = LE2._uvRefined; - nodeUV2.resize ( _hyp->GetNumberLayers() ); - layerNodes2.resize( _hyp->GetNumberLayers() ); + nodeUV2.resize ( layersHeight.size() ); + layerNodes2.resize( layersHeight.size() ); for ( size_t i = 0; i < layersHeight.size(); ++i ) { gp_XY uv = LE2._uvOut + LE2._normal2D * layersHeight[i]; @@ -1912,15 +2122,16 @@ bool _ViscousBuilder2D::toShrinkForAdjacent( const TopoDS_Face& adjFace, const TopoDS_Edge& E, const TopoDS_Vertex& V) { - if ( _noShrinkVert.count( getMeshDS()->ShapeToIndex( V ))) + if ( _noShrinkVert.count( getMeshDS()->ShapeToIndex( V )) || adjFace.IsNull() ) return false; - TopoDS_Shape hypAssignedTo; - if ( const StdMeshers_ViscousLayers2D* vlHyp = findHyp( *_mesh, adjFace, &hypAssignedTo )) + vector< const StdMeshers_ViscousLayers2D* > hyps; + vector< TopoDS_Shape > hypShapes; + if ( VISCOUS_2D::findHyps( *_mesh, adjFace, hyps, hypShapes )) { - VISCOUS_2D::_ViscousBuilder2D builder( *_mesh, adjFace, vlHyp ); + VISCOUS_2D::_ViscousBuilder2D builder( *_mesh, adjFace, hyps, hypShapes ); builder._faceSideVec = StdMeshers_FaceSide::GetFaceWires( adjFace, *_mesh, true, _error ); - builder.findEdgesWithLayers( hypAssignedTo ); + builder.findEdgesWithLayers(); PShapeIteratorPtr edgeIt = _helper.GetAncestors( V, *_mesh, TopAbs_EDGE ); while ( const TopoDS_Shape* edgeAtV = edgeIt->next() ) @@ -1951,7 +2162,7 @@ bool _ViscousBuilder2D::refine() // store a proxyMesh in a sub-mesh // make faces on each _PolyLine vector< double > layersHeight; - double prevLen2D = -1; + //double prevLen2D = -1; for ( size_t iL = 0; iL < _polyLineVec.size(); ++iL ) { _PolyLine& L = _polyLineVec[ iL ]; @@ -1973,89 +2184,64 @@ bool _ViscousBuilder2D::refine() } // limit length of neighbour _LayerEdge's to avoid sharp change of layers thickness + vector< double > segLen( L._lEdges.size() ); segLen[0] = 0.0; - for ( size_t i = 1; i < segLen.size(); ++i ) - { - // accumulate length of segments - double sLen = (L._lEdges[i-1]._uvOut - L._lEdges[i]._uvOut ).Modulus(); - segLen[i] = segLen[i-1] + sLen; - } - for ( int isR = 0; isR < 2; ++isR ) + + // check if length modification is useful: look for _LayerEdge's + // with length limited due to collisions + bool lenLimited = false; + for ( size_t iLE = 1; ( iLE < L._lEdges.size()-1 && !lenLimited ); ++iLE ) + lenLimited = L._lEdges[ iLE ]._isBlocked; + + if ( lenLimited ) { - size_t iF = 0, iL = L._lEdges.size()-1; - size_t *i = isR ? &iL : &iF; - _LayerEdge* prevLE = & L._lEdges[ *i ]; - double weight = 0; - for ( ++iF, --iL; iF < L._lEdges.size()-1; ++iF, --iL ) + for ( size_t i = 1; i < segLen.size(); ++i ) + { + // accumulate length of segments + double sLen = (L._lEdges[i-1]._uvOut - L._lEdges[i]._uvOut ).Modulus(); + segLen[i] = segLen[i-1] + sLen; + } + const double totSegLen = segLen.back(); + // normalize the accumulated length + for ( size_t iS = 1; iS < segLen.size(); ++iS ) + segLen[iS] /= totSegLen; + + for ( int isR = 0; isR < 2; ++isR ) { - _LayerEdge& LE = L._lEdges[*i]; - if ( prevLE->_length2D > 0 ) + size_t iF = 0, iL = L._lEdges.size()-1; + size_t *i = isR ? &iL : &iF; + _LayerEdge* prevLE = & L._lEdges[ *i ]; + double weight = 0; + for ( ++iF, --iL; iF < L._lEdges.size()-1; ++iF, --iL ) { - gp_XY tangent ( LE._normal2D.Y(), -LE._normal2D.X() ); - weight += Abs( tangent * ( prevLE->_uvIn - LE._uvIn )) / segLen.back(); - // gp_XY prevTang( LE._uvOut - prevLE->_uvOut ); - // gp_XY prevNorm( -prevTang.Y(), prevTang.X() ); - gp_XY prevNorm = LE._normal2D; - double prevProj = prevNorm * ( prevLE->_uvIn - prevLE->_uvOut ); - if ( prevProj > 0 ) { - prevProj /= prevNorm.Modulus(); - if ( LE._length2D < prevProj ) - weight += 0.75 * ( 1 - weight ); // length decrease is more preferable - LE._length2D = weight * LE._length2D + ( 1 - weight ) * prevProj; - LE._uvIn = LE._uvOut + LE._normal2D * LE._length2D; + _LayerEdge& LE = L._lEdges[*i]; + if ( prevLE->_length2D > 0 ) + { + gp_XY tangent ( LE._normal2D.Y(), -LE._normal2D.X() ); + weight += Abs( tangent * ( prevLE->_uvIn - LE._uvIn )) / totSegLen; + // gp_XY prevTang( LE._uvOut - prevLE->_uvOut ); + // gp_XY prevNorm( -prevTang.Y(), prevTang.X() ); + gp_XY prevNorm = LE._normal2D; + double prevProj = prevNorm * ( prevLE->_uvIn - prevLE->_uvOut ); + if ( prevProj > 0 ) { + prevProj /= prevNorm.Modulus(); + if ( LE._length2D < prevProj ) + weight += 0.75 * ( 1 - weight ); // length decrease is more preferable + LE._length2D = weight * LE._length2D + ( 1 - weight ) * prevProj; + LE._uvIn = LE._uvOut + LE._normal2D * LE._length2D; + } } + prevLE = & LE; } - prevLE = & LE; } } // DEBUG: to see _uvRefined. cout can be redirected to hide NETGEN output // cerr << "import smesh" << endl << "mesh = smesh.Mesh()"<< endl; - // calculate intermediate UV on _LayerEdge's ( _LayerEdge::_uvRefined ) - size_t iLE = 0, nbLE = L._lEdges.size(); - if ( ! L._lEdges[0]._uvRefined.empty() ) ++iLE; - if ( ! L._lEdges.back()._uvRefined.empty() ) --nbLE; - for ( ; iLE < nbLE; ++iLE ) - { - _LayerEdge& LE = L._lEdges[iLE]; - if ( fabs( LE._length2D - prevLen2D ) > LE._length2D / 100. ) - { - calcLayersHeight( LE._length2D, layersHeight ); - prevLen2D = LE._length2D; - } - for ( size_t i = 0; i < layersHeight.size(); ++i ) - LE._uvRefined.push_back( LE._uvOut + LE._normal2D * layersHeight[i] ); - - // DEBUG: to see _uvRefined - // for ( size_t i = 0; i < LE._uvRefined.size(); ++i ) - // { - // gp_XY uv = LE._uvRefined[i]; - // gp_Pnt p = _surface->Value( uv.X(), uv.Y() ); - // cerr << "mesh.AddNode( " << p.X() << ", " << p.Y() << ", " << p.Z() << " )" << endl; - // } - } - - // nodes to create 1 layer of faces - vector< const SMDS_MeshNode* > outerNodes( L._lastPntInd - L._firstPntInd + 1 ); - vector< const SMDS_MeshNode* > innerNodes( L._lastPntInd - L._firstPntInd + 1 ); - - // initialize outerNodes by nodes of the L._wire const vector& points = L._wire->GetUVPtStruct(); - for ( int i = L._firstPntInd; i <= L._lastPntInd; ++i ) - outerNodes[ i-L._firstPntInd ] = points[i].node; - // compute normalized [0;1] node parameters of outerNodes - vector< double > normPar( L._lastPntInd - L._firstPntInd + 1 ); - const double - normF = L._wire->FirstParameter( L._edgeInd ), - normL = L._wire->LastParameter ( L._edgeInd ), - normDist = normL - normF; - for ( int i = L._firstPntInd; i <= L._lastPntInd; ++i ) - normPar[ i - L._firstPntInd ] = ( points[i].normParam - normF ) / normDist; - - // Create layers of faces - + // analyse extremities of the _PolyLine to find existing nodes const TopoDS_Vertex& V1 = L._wire->FirstVertex( L._edgeInd ); const TopoDS_Vertex& V2 = L._wire->LastVertex ( L._edgeInd ); const int v1ID = getMeshDS()->ShapeToIndex( V1 ); @@ -2067,28 +2253,81 @@ bool _ViscousBuilder2D::refine() bool hasRightNode = ( !L._rightLine->_leftNodes.empty() && rightEdgeShared ); bool hasOwnLeftNode = ( !L._leftNodes.empty() ); bool hasOwnRightNode = ( !L._rightNodes.empty() ); - bool isClosedEdge = ( outerNodes.front() == outerNodes.back() ); - size_t iS, + bool isClosedEdge = ( points[ L._firstPntInd ].node == points[ L._lastPntInd ].node ); + const size_t + nbN = L._lastPntInd - L._firstPntInd + 1, iN0 = ( hasLeftNode || hasOwnLeftNode || isClosedEdge || !isShrinkableL ), - nbN = innerNodes.size() - ( hasRightNode || hasOwnRightNode || !isShrinkableR); - L._leftNodes .reserve( _hyp->GetNumberLayers() ); - L._rightNodes.reserve( _hyp->GetNumberLayers() ); - int cur = 0, prev = -1; // to take into account orientation of _face - if ( isReverse ) std::swap( cur, prev ); - for ( int iF = 0; iF < _hyp->GetNumberLayers(); ++iF ) // loop on layers of faces + iNE = nbN - ( hasRightNode || hasOwnRightNode || !isShrinkableR ); + + // update _uvIn of end _LayerEdge's by existing nodes + const SMDS_MeshNode *nL = 0, *nR = 0; + if ( hasOwnLeftNode ) nL = L._leftNodes.back(); + else if ( hasLeftNode ) nL = L._leftLine->_rightNodes.back(); + if ( hasOwnRightNode ) nR = L._rightNodes.back(); + else if ( hasRightNode ) nR = L._rightLine->_leftNodes.back(); + if ( nL ) + L._lEdges[0]._uvIn = _helper.GetNodeUV( _face, nL, points[ L._firstPntInd + 1 ].node ); + if ( nR ) + L._lEdges.back()._uvIn = _helper.GetNodeUV( _face, nR, points[ L._lastPntInd - 1 ].node ); + + // compute normalized [0;1] node parameters of nodes on a _PolyLine + vector< double > normPar( nbN ); + const double + normF = L._wire->FirstParameter( L._edgeInd ), + normL = L._wire->LastParameter ( L._edgeInd ), + normDist = normL - normF; + for ( int i = L._firstPntInd; i <= L._lastPntInd; ++i ) + normPar[ i - L._firstPntInd ] = ( points[i].normParam - normF ) / normDist; + + // Calculate UV of most inner nodes + + vector< gp_XY > innerUV( nbN ); + + // check if innerUV should be interpolated between _LayerEdge::_uvIn's + const size_t nbLE = L._lEdges.size(); + bool needInterpol = ( nbN != nbLE ); + if ( !needInterpol ) { - // get accumulated length of intermediate segments + // more check: compare length of inner and outer end segments + double lenIn, lenOut; + for ( int isR = 0; isR < 2 && !needInterpol; ++isR ) + { + const _Segment& segIn = isR ? L._segments.back() : L._segments[0]; + const gp_XY& uvIn1 = segIn.p1(); + const gp_XY& uvIn2 = segIn.p2(); + const gp_XY& uvOut1 = L._lEdges[ isR ? nbLE-1 : 0 ]._uvOut; + const gp_XY& uvOut2 = L._lEdges[ isR ? nbLE-2 : 1 ]._uvOut; + if ( _is2DIsotropic ) + { + lenIn = ( uvIn1 - uvIn2 ).Modulus(); + lenOut = ( uvOut1 - uvOut2 ).Modulus(); + } + else + { + lenIn = _surface->Value( uvIn1.X(), uvIn1.Y() ) + .Distance( _surface->Value( uvIn2.X(), uvIn2.Y() )); + lenOut = _surface->Value( uvOut1.X(), uvOut1.Y() ) + .Distance( _surface->Value( uvOut2.X(), uvOut2.Y() )); + } + needInterpol = ( lenIn < 0.66 * lenOut ); + } + } + + if ( needInterpol ) + { + // compute normalized accumulated length of inner segments + size_t iS; if ( _is2DIsotropic ) for ( iS = 1; iS < segLen.size(); ++iS ) { - double sLen = (L._lEdges[iS-1]._uvRefined[iF] - L._lEdges[iS]._uvRefined[iF] ).Modulus(); + double sLen = ( L._lEdges[iS-1]._uvIn - L._lEdges[iS]._uvIn ).Modulus(); segLen[iS] = segLen[iS-1] + sLen; } else for ( iS = 1; iS < segLen.size(); ++iS ) { - const gp_XY& uv1 = L._lEdges[iS-1]._uvRefined[iF]; - const gp_XY& uv2 = L._lEdges[iS ]._uvRefined[iF]; + const gp_XY& uv1 = L._lEdges[iS-1]._uvIn; + const gp_XY& uv2 = L._lEdges[iS ]._uvIn; gp_Pnt p1 = _surface->Value( uv1.X(), uv1.Y() ); gp_Pnt p2 = _surface->Value( uv2.X(), uv2.Y() ); double sLen = p1.Distance( p2 ); @@ -2098,15 +2337,49 @@ bool _ViscousBuilder2D::refine() for ( iS = 1; iS < segLen.size(); ++iS ) segLen[iS] /= segLen.back(); - // create innerNodes of a current layer + // calculate UV of most inner nodes according to the normalized node parameters iS = 0; - for ( size_t i = iN0; i < nbN; ++i ) + for ( size_t i = 0; i < innerUV.size(); ++i ) { while ( normPar[i] > segLen[iS+1] ) ++iS; double r = ( normPar[i] - segLen[iS] ) / ( segLen[iS+1] - segLen[iS] ); - gp_XY uv = r * L._lEdges[iS+1]._uvRefined[iF] + (1-r) * L._lEdges[iS]._uvRefined[iF]; - gp_Pnt p = _surface->Value( uv.X(), uv.Y() ); + innerUV[ i ] = r * L._lEdges[iS+1]._uvIn + (1-r) * L._lEdges[iS]._uvIn; + } + } + else // ! needInterpol + { + for ( size_t i = 0; i < nbLE; ++i ) + innerUV[ i ] = L._lEdges[i]._uvIn; + } + + // normalized height of layers + const THypVL* hyp = getLineHypothesis( iL ); + calcLayersHeight( 1., layersHeight, hyp); + + // Create layers of faces + + // nodes to create 1 layer of faces + vector< const SMDS_MeshNode* > outerNodes( nbN ); + vector< const SMDS_MeshNode* > innerNodes( nbN ); + + // initialize outerNodes by nodes of the L._wire + for ( int i = L._firstPntInd; i <= L._lastPntInd; ++i ) + outerNodes[ i-L._firstPntInd ] = points[i].node; + + L._leftNodes .reserve( hyp->GetNumberLayers() ); + L._rightNodes.reserve( hyp->GetNumberLayers() ); + int cur = 0, prev = -1; // to take into account orientation of _face + if ( isReverse ) std::swap( cur, prev ); + for ( int iF = 0; iF < hyp->GetNumberLayers(); ++iF ) // loop on layers of faces + { + // create innerNodes of a current layer + for ( size_t i = iN0; i < iNE; ++i ) + { + gp_XY uvOut = points[ L._firstPntInd + i ].UV(); + gp_XY& uvIn = innerUV[ i ]; + gp_XY uv = layersHeight[ iF ] * uvIn + ( 1.-layersHeight[ iF ]) * uvOut; + gp_Pnt p = _surface->Value( uv.X(), uv.Y() ); innerNodes[i] = _helper.AddNode( p.X(), p.Y(), p.Z(), /*id=*/0, uv.X(), uv.Y() ); } // use nodes created for adjacent _PolyLine's @@ -2128,6 +2401,18 @@ bool _ViscousBuilder2D::refine() outerNodes.swap( innerNodes ); } + + // Add faces to a group + SMDS_MeshGroup* group = StdMeshers_ViscousLayers::CreateGroup( hyp->GetGroupName(), + *_helper.GetMesh(), + SMDSAbs_Face ); + if ( group ) + { + TIDSortedElemSet::iterator fIt = L._newFaces.begin(); + for ( ; fIt != L._newFaces.end(); ++fIt ) + group->Add( *fIt ); + } + // faces between not shared _LayerEdge's (at concave VERTEX) for ( int isR = 0; isR < 2; ++isR ) { @@ -2139,15 +2424,22 @@ bool _ViscousBuilder2D::refine() if ( lNodes.empty() || rNodes.empty() || lNodes.size() != rNodes.size() ) continue; + const SMDS_MeshElement* face = 0; for ( size_t i = 1; i < lNodes.size(); ++i ) - _helper.AddFace( lNodes[ i+prev ], rNodes[ i+prev ], - rNodes[ i+cur ], lNodes[ i+cur ]); + { + face = _helper.AddFace( lNodes[ i+prev ], rNodes[ i+prev ], + rNodes[ i+cur ], lNodes[ i+cur ]); + if ( group ) + group->Add( face ); + } const UVPtStruct& ptOnVertex = points[ isR ? L._lastPntInd : L._firstPntInd ]; if ( isReverse ) - _helper.AddFace( ptOnVertex.node, lNodes[ 0 ], rNodes[ 0 ]); + face = _helper.AddFace( ptOnVertex.node, lNodes[ 0 ], rNodes[ 0 ]); else - _helper.AddFace( ptOnVertex.node, rNodes[ 0 ], lNodes[ 0 ]); + face = _helper.AddFace( ptOnVertex.node, rNodes[ 0 ], lNodes[ 0 ]); + if ( group ) + group->Add( face ); } // Fill the _ProxyMeshOfFace @@ -2167,6 +2459,19 @@ bool _ViscousBuilder2D::refine() nodeDataVec.front().param = L._wire->FirstU( L._edgeInd ); nodeDataVec.back() .param = L._wire->LastU ( L._edgeInd ); + if (( nodeDataVec[0].node == nodeDataVec.back().node ) && + ( _helper.GetPeriodicIndex() == 1 || _helper.GetPeriodicIndex() == 2 )) // closed EDGE + { + const int iCoord = _helper.GetPeriodicIndex(); + gp_XY uv = nodeDataVec[0].UV(); + uv.SetCoord( iCoord, L._lEdges[0]._uvOut.Coord( iCoord )); + nodeDataVec[0].SetUV( uv ); + + uv = nodeDataVec.back().UV(); + uv.SetCoord( iCoord, L._lEdges.back()._uvOut.Coord( iCoord )); + nodeDataVec.back().SetUV( uv ); + } + _ProxyMeshOfFace::_EdgeSubMesh* edgeSM = getProxyMesh()->GetEdgeSubMesh( L._wire->EdgeID( L._edgeInd )); edgeSM->SetUVPtStructVec( nodeDataVec ); @@ -2259,6 +2564,30 @@ bool _ViscousBuilder2D::removeMeshFaces(const TopoDS_Shape& face) return thereWereElems; } +//================================================================================ +/*! + * \brief Returns a hypothesis for a _PolyLine + */ +//================================================================================ + +const StdMeshers_ViscousLayers2D* _ViscousBuilder2D::getLineHypothesis(int iPL) +{ + return iPL < (int)_hypOfEdge.size() ? _hypOfEdge[ iPL ] : _hyps[0]; +} + +//================================================================================ +/*! + * \brief Returns a layers thickness for a _PolyLine + */ +//================================================================================ + +double _ViscousBuilder2D::getLineThickness(int iPL) +{ + if ( const StdMeshers_ViscousLayers2D* h = getLineHypothesis( iPL )) + return Min( _maxThickness, h->GetTotalThickness() ); + return _maxThickness; +} + //================================================================================ /*! * \brief Creates a _ProxyMeshOfFace and store it in a sub-mesh of FACE @@ -2285,21 +2614,23 @@ _ProxyMeshOfFace* _ViscousBuilder2D::getProxyMesh() //================================================================================ void _ViscousBuilder2D::calcLayersHeight(const double totalThick, - vector& heights) + vector& heights, + const THypVL* hyp) { - heights.resize( _hyp->GetNumberLayers() ); + const double fPowN = pow( hyp->GetStretchFactor(), hyp->GetNumberLayers() ); + heights.resize( hyp->GetNumberLayers() ); double h0; - if ( _fPowN - 1 <= numeric_limits::min() ) - h0 = totalThick / _hyp->GetNumberLayers(); + if ( fPowN - 1 <= numeric_limits::min() ) + h0 = totalThick / hyp->GetNumberLayers(); else - h0 = totalThick * ( _hyp->GetStretchFactor() - 1 )/( _fPowN - 1 ); + h0 = totalThick * ( hyp->GetStretchFactor() - 1 )/( fPowN - 1 ); double hSum = 0, hi = h0; - for ( int i = 0; i < _hyp->GetNumberLayers(); ++i ) + for ( int i = 0; i < hyp->GetNumberLayers(); ++i ) { hSum += hi; heights[ i ] = hSum; - hi *= _hyp->GetStretchFactor(); + hi *= hyp->GetStretchFactor(); } } @@ -2400,7 +2731,7 @@ _SegmentTree::box_type* _SegmentTree::buildRootBox() void _SegmentTree::buildChildrenData() { - for ( int i = 0; i < _segments.size(); ++i ) + for ( size_t i = 0; i < _segments.size(); ++i ) for (int j = 0; j < nbChildren(); j++) if ( !myChildren[j]->getBox()->IsOut( *_segments[i]._seg->_uv[0], *_segments[i]._seg->_uv[1] )) @@ -2411,7 +2742,7 @@ void _SegmentTree::buildChildrenData() for (int j = 0; j < nbChildren(); j++) { _SegmentTree* child = static_cast<_SegmentTree*>( myChildren[j]); - child->myIsLeaf = ( child->_segments.size() <= maxNbSegInLeaf() ); + child->myIsLeaf = ((int) child->_segments.size() <= maxNbSegInLeaf() ); } } @@ -2429,7 +2760,7 @@ void _SegmentTree::GetSegmentsNear( const _Segment& seg, if ( isLeaf() ) { - for ( int i = 0; i < _segments.size(); ++i ) + for ( size_t i = 0; i < _segments.size(); ++i ) if ( !_segments[i].IsOut( seg )) found.push_back( _segments[i]._seg ); } @@ -2455,7 +2786,7 @@ void _SegmentTree::GetSegmentsNear( const gp_Ax2d& ray, if ( isLeaf() ) { - for ( int i = 0; i < _segments.size(); ++i ) + for ( size_t i = 0; i < _segments.size(); ++i ) if ( !_segments[i].IsOut( ray )) found.push_back( _segments[i]._seg ); }