1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : StdMeshers_ViscousLayers2D.cxx
21 // Created : 23 Jul 2012
22 // Author : Edward AGAPOV (eap)
24 #include "StdMeshers_ViscousLayers2D.hxx"
26 #include "SMDS_EdgePosition.hxx"
27 #include "SMDS_FaceOfNodes.hxx"
28 #include "SMDS_FacePosition.hxx"
29 #include "SMDS_MeshNode.hxx"
30 #include "SMDS_SetIterator.hxx"
31 #include "SMESHDS_Group.hxx"
32 #include "SMESHDS_Hypothesis.hxx"
33 #include "SMESH_Algo.hxx"
34 #include "SMESH_ComputeError.hxx"
35 #include "SMESH_ControlsDef.hxx"
36 #include "SMESH_Gen.hxx"
37 #include "SMESH_Group.hxx"
38 #include "SMESH_HypoFilter.hxx"
39 #include "SMESH_Mesh.hxx"
40 #include "SMESH_MesherHelper.hxx"
41 #include "SMESH_ProxyMesh.hxx"
42 #include "SMESH_Quadtree.hxx"
43 #include "SMESH_subMesh.hxx"
44 #include "SMESH_subMeshEventListener.hxx"
45 #include "StdMeshers_FaceSide.hxx"
47 #include "utilities.h"
49 #include <BRepAdaptor_Curve.hxx>
50 #include <BRepAdaptor_Curve2d.hxx>
51 #include <BRep_Tool.hxx>
52 #include <Bnd_B2d.hxx>
53 #include <Bnd_B3d.hxx>
55 #include <GCPnts_AbscissaPoint.hxx>
56 #include <Geom2d_Circle.hxx>
57 #include <Geom2d_Line.hxx>
58 #include <Geom2d_TrimmedCurve.hxx>
59 #include <GeomAdaptor_Curve.hxx>
60 #include <Geom_Circle.hxx>
61 #include <Geom_Curve.hxx>
62 #include <Geom_Line.hxx>
63 #include <Geom_TrimmedCurve.hxx>
64 #include <Precision.hxx>
65 #include <Standard_ErrorHandler.hxx>
66 #include <TColStd_Array1OfReal.hxx>
68 #include <TopExp_Explorer.hxx>
69 #include <TopTools_IndexedMapOfShape.hxx>
70 #include <TopTools_MapOfShape.hxx>
72 #include <TopoDS_Edge.hxx>
73 #include <TopoDS_Face.hxx>
74 #include <TopoDS_Vertex.hxx>
88 //================================================================================
93 //--------------------------------------------------------------------------------
95 * \brief Proxy Mesh of FACE with viscous layers. It's needed only to
96 * redefine newSubmesh().
98 struct _ProxyMeshOfFace : public SMESH_ProxyMesh
100 //---------------------------------------------------
101 // Proxy sub-mesh of an EDGE. It contains nodes in _uvPtStructVec.
102 struct _EdgeSubMesh : public SMESH_ProxyMesh::SubMesh
104 _EdgeSubMesh(int index=0): SubMesh(index) {}
105 //virtual int NbElements() const { return _elements.size()+1; }
106 virtual int NbNodes() const { return Max( 0, _uvPtStructVec.size()-2 ); }
107 void SetUVPtStructVec(UVPtStructVec& vec) { _uvPtStructVec.swap( vec ); }
109 _ProxyMeshOfFace(const SMESH_Mesh& mesh): SMESH_ProxyMesh(mesh) {}
110 _EdgeSubMesh* GetEdgeSubMesh(int ID) { return (_EdgeSubMesh*) getProxySubMesh(ID); }
111 virtual SubMesh* newSubmesh(int index=0) const { return new _EdgeSubMesh(index); }
113 //--------------------------------------------------------------------------------
115 * \brief SMESH_subMeshEventListener used to store _ProxyMeshOfFace, computed
116 * by _ViscousBuilder2D, in a SMESH_subMesh of the FACE.
117 * This is to delete _ProxyMeshOfFace when StdMeshers_ViscousLayers2D
118 * hypothesis is modified
120 struct _ProxyMeshHolder : public SMESH_subMeshEventListener
122 _ProxyMeshHolder( const TopoDS_Face& face,
123 SMESH_ProxyMesh::Ptr& mesh)
124 : SMESH_subMeshEventListener( /*deletable=*/true, Name() )
126 SMESH_subMesh* faceSM = mesh->GetMesh()->GetSubMesh( face );
127 faceSM->SetEventListener( this, new _Data( mesh ), faceSM );
129 // Finds a proxy mesh of face
130 static SMESH_ProxyMesh::Ptr FindProxyMeshOfFace( const TopoDS_Shape& face,
133 SMESH_ProxyMesh::Ptr proxy;
134 SMESH_subMesh* faceSM = mesh.GetSubMesh( face );
135 if ( EventListenerData* ld = faceSM->GetEventListenerData( Name() ))
136 proxy = static_cast< _Data* >( ld )->_mesh;
140 void ProcessEvent(const int event,
142 SMESH_subMesh* subMesh,
143 EventListenerData* data,
144 const SMESH_Hypothesis* /*hyp*/)
146 if ( event == SMESH_subMesh::CLEAN && eventType == SMESH_subMesh::COMPUTE_EVENT)
147 ((_Data*) data)->_mesh.reset();
150 // holder of a proxy mesh
151 struct _Data : public SMESH_subMeshEventListenerData
153 SMESH_ProxyMesh::Ptr _mesh;
154 _Data( SMESH_ProxyMesh::Ptr& mesh )
155 :SMESH_subMeshEventListenerData( /*isDeletable=*/true), _mesh( mesh )
158 // Returns identifier string
159 static const char* Name() { return "VISCOUS_2D::_ProxyMeshHolder"; }
163 //--------------------------------------------------------------------------------
165 * \brief Segment connecting inner ends of two _LayerEdge's.
169 const gp_XY* _uv[2]; // poiter to _LayerEdge::_uvIn
170 int _indexInLine; // position in _PolyLine
173 _Segment(const gp_XY& p1, const gp_XY& p2):_indexInLine(-1) { _uv[0] = &p1; _uv[1] = &p2; }
174 const gp_XY& p1() const { return *_uv[0]; }
175 const gp_XY& p2() const { return *_uv[1]; }
177 //--------------------------------------------------------------------------------
179 * \brief Tree of _Segment's used for a faster search of _Segment's.
181 struct _SegmentTree : public SMESH_Quadtree
183 typedef boost::shared_ptr< _SegmentTree > Ptr;
185 _SegmentTree( const vector< _Segment >& segments );
186 void GetSegmentsNear( const _Segment& seg, vector< const _Segment* >& found );
187 void GetSegmentsNear( const gp_Ax2d& ray, vector< const _Segment* >& found );
190 _SegmentTree* newChild() const { return new _SegmentTree; }
191 void buildChildrenData();
192 Bnd_B2d* buildRootBox();
194 static int maxNbSegInLeaf() { return 5; }
197 const _Segment* _seg;
199 void Set( const _Segment& seg )
202 _iMin[0] = ( seg._uv[1]->X() < seg._uv[0]->X() );
203 _iMin[1] = ( seg._uv[1]->Y() < seg._uv[0]->Y() );
205 bool IsOut( const _Segment& seg ) const;
206 bool IsOut( const gp_Ax2d& ray ) const;
208 vector< _SegBox > _segments;
210 //--------------------------------------------------------------------------------
212 * \brief Edge normal to FACE boundary, connecting a point on EDGE (_uvOut)
213 * and a point of a layer internal boundary (_uvIn)
217 gp_XY _uvOut; // UV on the FACE boundary
218 gp_XY _uvIn; // UV inside the FACE
219 double _length2D; // distance between _uvOut and _uvIn
221 bool _isBlocked;// is more inflation possible or not
223 gp_XY _normal2D; // to pcurve
224 double _len2dTo3dRatio; // to pass 2D <--> 3D
225 gp_Ax2d _ray; // a ray starting at _uvOut
227 vector<gp_XY> _uvRefined; // divisions by layers
229 bool SetNewLength( const double length );
231 //--------------------------------------------------------------------------------
233 * \brief Poly line composed of _Segment's of one EDGE.
234 * It's used to detect intersection of inflated layers by intersecting
239 StdMeshers_FaceSide* _wire;
240 int _edgeInd; // index of my EDGE in _wire
241 bool _advancable; // true if there is a viscous layer on my EDGE
242 _PolyLine* _leftLine; // lines of neighbour EDGE's
243 _PolyLine* _rightLine;
244 int _firstPntInd; // index in vector<UVPtStruct> of _wire
247 vector< _LayerEdge > _lEdges; /* _lEdges[0] is usually is not treated
248 as it is equal to the last one of the _leftLine */
249 vector< _Segment > _segments; // segments connecting _uvIn's of _lEdges
250 _SegmentTree::Ptr _segTree;
252 vector< _PolyLine* > _reachableLines; // lines able to interfere with my layer
254 vector< const SMDS_MeshNode* > _leftNodes; // nodes built from a left VERTEX
255 vector< const SMDS_MeshNode* > _rightNodes; // nodes built from a right VERTEX
257 typedef vector< _Segment >::iterator TSegIterator;
258 typedef vector< _LayerEdge >::iterator TEdgeIterator;
260 bool IsCommonEdgeShared( const _PolyLine& other );
261 size_t FirstLEdge() const { return _leftLine->_advancable ? 1 : 0; }
262 bool IsAdjacent( const _Segment& seg ) const
264 return ( & seg == &_leftLine->_segments.back() ||
265 & seg == &_rightLine->_segments[0] );
268 //--------------------------------------------------------------------------------
270 * \brief Intersector of _Segment's
272 struct _SegmentIntersection
274 gp_XY _vec1, _vec2; // Vec( _seg.p1(), _seg.p2() )
275 gp_XY _vec21; // Vec( _seg2.p1(), _seg1.p1() )
276 double _D; // _vec1.Crossed( _vec2 )
277 double _param1, _param2; // intersection param on _seg1 and _seg2
279 bool Compute(const _Segment& seg1, const _Segment& seg2, bool seg2IsRay = false )
281 _vec1 = seg1.p2() - seg1.p1();
282 _vec2 = seg2.p2() - seg2.p1();
283 _vec21 = seg1.p1() - seg2.p1();
284 _D = _vec1.Crossed(_vec2);
285 if ( fabs(_D) < std::numeric_limits<double>::min())
287 _param1 = _vec2.Crossed(_vec21) / _D;
288 if (_param1 < 0 || _param1 > 1 )
290 _param2 = _vec1.Crossed(_vec21) / _D;
291 if (_param2 < 0 || ( !seg2IsRay && _param2 > 1 ))
295 bool Compute( const _Segment& seg1, const gp_Ax2d& ray )
297 gp_XY segEnd = ray.Location().XY() + ray.Direction().XY();
298 _Segment seg2( ray.Location().XY(), segEnd );
299 return Compute( seg1, seg2, true );
301 //gp_XY GetPoint() { return _seg1.p1() + _param1 * _vec1; }
303 //--------------------------------------------------------------------------------
305 typedef map< const SMDS_MeshNode*, _LayerEdge*, TIDCompare > TNode2Edge;
307 //--------------------------------------------------------------------------------
309 * \brief Builder of viscous layers
311 class _ViscousBuilder2D
314 _ViscousBuilder2D(SMESH_Mesh& theMesh,
315 const TopoDS_Face& theFace,
316 const StdMeshers_ViscousLayers2D* theHyp);
317 SMESH_ComputeErrorPtr GetError() const { return _error; }
319 SMESH_ProxyMesh::Ptr Compute();
323 bool findEdgesWithLayers();
324 bool makePolyLines();
326 bool fixCollisions();
329 bool toShrinkForAdjacent( const TopoDS_Face& adjFace,
330 const TopoDS_Edge& E,
331 const TopoDS_Vertex& V);
332 void setLenRatio( _LayerEdge& LE, const gp_Pnt& pOut );
333 void adjustCommonEdge( _PolyLine& LL, _PolyLine& LR );
334 void calcLayersHeight(const double totalThick,
335 vector<double>& heights);
336 bool removeMeshFaces(const TopoDS_Shape& face);
338 bool error( const string& text );
339 SMESHDS_Mesh* getMeshDS() { return _mesh->GetMeshDS(); }
340 _ProxyMeshOfFace* getProxyMesh();
343 //void makeGroupOfLE();
350 const StdMeshers_ViscousLayers2D* _hyp;
353 SMESH_ProxyMesh::Ptr _proxyMesh;
354 SMESH_ComputeErrorPtr _error;
357 Handle(Geom_Surface) _surface;
358 SMESH_MesherHelper _helper;
359 TSideVector _faceSideVec; // wires (StdMeshers_FaceSide) of _face
360 vector<_PolyLine> _polyLineVec; // fronts to advance
362 double _fPowN; // to compute thickness of layers
363 double _thickness; // required or possible layers thickness
365 // sub-shapes of _face
366 set<TGeomID> _ignoreShapeIds; // ids of EDGEs w/o layers
367 set<TGeomID> _noShrinkVert; // ids of VERTEXes that are extremities
368 // of EDGEs along which _LayerEdge can't be inflated because no viscous layers
369 // defined on neighbour FACEs sharing an EDGE. Nonetheless _LayerEdge's
370 // are inflated along such EDGEs but then such _LayerEdge's are turned into
371 // a node on VERTEX, i.e. all nodes on a _LayerEdge are melded into one node.
375 //================================================================================
377 * \brief Returns StdMeshers_ViscousLayers2D for the FACE
379 const StdMeshers_ViscousLayers2D* findHyp(SMESH_Mesh& theMesh,
380 const TopoDS_Face& theFace)
382 SMESH_HypoFilter hypFilter
383 ( SMESH_HypoFilter::HasName( StdMeshers_ViscousLayers2D::GetHypType() ));
384 const SMESH_Hypothesis * hyp =
385 theMesh.GetHypothesis( theFace, hypFilter, /*ancestors=*/true );
386 return dynamic_cast< const StdMeshers_ViscousLayers2D* > ( hyp );
389 } // namespace VISCOUS_2D
391 //================================================================================
392 // StdMeshers_ViscousLayers hypothesis
394 StdMeshers_ViscousLayers2D::StdMeshers_ViscousLayers2D(int hypId, int studyId, SMESH_Gen* gen)
395 :StdMeshers_ViscousLayers(hypId, studyId, gen)
397 _name = StdMeshers_ViscousLayers2D::GetHypType();
398 _param_algo_dim = -2; // auxiliary hyp used by 2D algos
400 // --------------------------------------------------------------------------------
401 bool StdMeshers_ViscousLayers2D::SetParametersByMesh(const SMESH_Mesh* theMesh,
402 const TopoDS_Shape& theShape)
407 // --------------------------------------------------------------------------------
409 StdMeshers_ViscousLayers2D::Compute(SMESH_Mesh& theMesh,
410 const TopoDS_Face& theFace)
412 SMESH_ProxyMesh::Ptr pm;
414 const StdMeshers_ViscousLayers2D* vlHyp = VISCOUS_2D::findHyp( theMesh, theFace );
417 VISCOUS_2D::_ViscousBuilder2D builder( theMesh, theFace, vlHyp );
418 pm = builder.Compute();
419 SMESH_ComputeErrorPtr error = builder.GetError();
420 if ( error && !error->IsOK() )
421 theMesh.GetSubMesh( theFace )->GetComputeError() = error;
423 pm.reset( new SMESH_ProxyMesh( theMesh ));
427 pm.reset( new SMESH_ProxyMesh( theMesh ));
431 // --------------------------------------------------------------------------------
432 void StdMeshers_ViscousLayers2D::RestoreListeners() const
434 StudyContextStruct* sc = _gen->GetStudyContext( _studyId );
435 std::map < int, SMESH_Mesh * >::iterator i_smesh = sc->mapMesh.begin();
436 for ( ; i_smesh != sc->mapMesh.end(); ++i_smesh )
438 SMESH_Mesh* smesh = i_smesh->second;
440 !smesh->HasShapeToMesh() ||
441 !smesh->GetMeshDS() ||
442 !smesh->GetMeshDS()->IsUsedHypothesis( this ))
445 // set event listeners to EDGE's of FACE where this hyp is used
446 TopoDS_Shape shape = i_smesh->second->GetShapeToMesh();
447 for ( TopExp_Explorer face( shape, TopAbs_FACE); face.More(); face.Next() )
448 if ( SMESH_Algo* algo = _gen->GetAlgo( *smesh, face.Current() ))
450 const std::list <const SMESHDS_Hypothesis *> & usedHyps =
451 algo->GetUsedHypothesis( *smesh, face.Current(), /*ignoreAuxiliary=*/false );
452 if ( std::find( usedHyps.begin(), usedHyps.end(), this ) != usedHyps.end() )
453 for ( TopExp_Explorer edge( face.Current(), TopAbs_EDGE); edge.More(); edge.Next() )
454 VISCOUS_3D::ToClearSubWithMain( smesh->GetSubMesh( edge.Current() ), face.Current() );
458 // END StdMeshers_ViscousLayers2D hypothesis
459 //================================================================================
461 using namespace VISCOUS_2D;
463 //================================================================================
465 * \brief Constructor of _ViscousBuilder2D
467 //================================================================================
469 _ViscousBuilder2D::_ViscousBuilder2D(SMESH_Mesh& theMesh,
470 const TopoDS_Face& theFace,
471 const StdMeshers_ViscousLayers2D* theHyp):
472 _mesh( &theMesh ), _face( theFace ), _hyp( theHyp ), _helper( theMesh )
474 _helper.SetSubShape( _face );
475 _helper.SetElementsOnShape(true);
477 _surface = BRep_Tool::Surface( theFace );
480 _fPowN = pow( _hyp->GetStretchFactor(), _hyp->GetNumberLayers() );
483 //================================================================================
485 * \brief Stores error description and returns false
487 //================================================================================
489 bool _ViscousBuilder2D::error(const string& text )
491 cout << "_ViscousBuilder2D::error " << text << endl;
492 _error->myName = COMPERR_ALGO_FAILED;
493 _error->myComment = string("Viscous layers builder 2D: ") + text;
494 if ( SMESH_subMesh* sm = _mesh->GetSubMesh( _face ) )
496 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
497 if ( smError && smError->myAlgo )
498 _error->myAlgo = smError->myAlgo;
501 //makeGroupOfLE(); // debug
506 //================================================================================
508 * \brief Does its job
510 //================================================================================
512 SMESH_ProxyMesh::Ptr _ViscousBuilder2D::Compute()
514 _error = SMESH_ComputeError::New(COMPERR_OK);
515 _faceSideVec = StdMeshers_FaceSide::GetFaceWires( _face, *_mesh, true, _error );
516 if ( !_error->IsOK() )
521 if ( !findEdgesWithLayers() ) // analysis of a shape
524 if ( ! makePolyLines() ) // creation of fronts
527 if ( ! inflate() ) // advance fronts
530 if ( !shrink() ) // shrink segments on edges w/o layers
533 if ( ! refine() ) // make faces
536 // for ( size_t i = 0; i < _facesToRecompute.size(); ++i )
537 // _mesh->GetSubMesh( _facesToRecompute[i] )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
539 //makeGroupOfLE(); // debug
540 //debugDump.Finish();
545 //================================================================================
547 * \brief Finds EDGE's to make viscous layers on.
549 //================================================================================
551 bool _ViscousBuilder2D::findEdgesWithLayers()
553 // collect all EDGEs to ignore defined by hyp
554 int nbMyEdgesIgnored = 0;
555 vector<TGeomID> ids = _hyp->GetBndShapesToIgnore();
556 for ( size_t i = 0; i < ids.size(); ++i )
558 const TopoDS_Shape& s = getMeshDS()->IndexToShape( ids[i] );
559 if ( !s.IsNull() && s.ShapeType() == TopAbs_EDGE ) {
560 _ignoreShapeIds.insert( ids[i] );
561 nbMyEdgesIgnored += ( _helper.IsSubShape( s, _face ));
565 // check all EDGEs of the _face
566 int totalNbEdges = 0;
567 for ( size_t iWire = 0; iWire < _faceSideVec.size(); ++iWire )
569 StdMeshers_FaceSidePtr wire = _faceSideVec[ iWire ];
570 totalNbEdges += wire->NbEdges();
571 for ( int iE = 0; iE < wire->NbEdges(); ++iE )
572 if ( _helper.NbAncestors( wire->Edge( iE ), *_mesh, TopAbs_FACE ) > 1 )
574 // ignore internal EDGEs (shared by several FACEs)
575 TGeomID edgeID = getMeshDS()->ShapeToIndex( wire->Edge( iE ));
576 _ignoreShapeIds.insert( edgeID );
578 // check if ends of an EDGE are to be added to _noShrinkVert
579 PShapeIteratorPtr faceIt = _helper.GetAncestors( wire->Edge( iE ), *_mesh, TopAbs_FACE );
580 while ( const TopoDS_Shape* neighbourFace = faceIt->next() )
582 if ( neighbourFace->IsSame( _face )) continue;
583 SMESH_Algo* algo = _mesh->GetGen()->GetAlgo( *_mesh, *neighbourFace );
584 if ( !algo ) continue;
586 const StdMeshers_ViscousLayers2D* viscHyp = 0;
587 const list <const SMESHDS_Hypothesis *> & allHyps =
588 algo->GetUsedHypothesis(*_mesh, *neighbourFace, /*noAuxiliary=*/false);
589 list< const SMESHDS_Hypothesis *>::const_iterator hyp = allHyps.begin();
590 for ( ; hyp != allHyps.end() && !viscHyp; ++hyp )
591 viscHyp = dynamic_cast<const StdMeshers_ViscousLayers2D*>( *hyp );
593 set<TGeomID> neighbourIgnoreEdges;
595 vector<TGeomID> ids = _hyp->GetBndShapesToIgnore();
596 neighbourIgnoreEdges.insert( ids.begin(), ids.end() );
598 for ( int iV = 0; iV < 2; ++iV )
600 TopoDS_Vertex vertex = iV ? wire->LastVertex(iE) : wire->FirstVertex(iE);
602 _noShrinkVert.insert( getMeshDS()->ShapeToIndex( vertex ));
605 PShapeIteratorPtr edgeIt = _helper.GetAncestors( vertex, *_mesh, TopAbs_EDGE );
606 while ( const TopoDS_Shape* edge = edgeIt->next() )
607 if ( !edge->IsSame( wire->Edge( iE )) &&
608 neighbourIgnoreEdges.count( getMeshDS()->ShapeToIndex( *edge )))
609 _noShrinkVert.insert( getMeshDS()->ShapeToIndex( vertex ));
615 return ( nbMyEdgesIgnored < totalNbEdges );
618 //================================================================================
620 * \brief Create the inner front of the viscous layers and prepare data for infation
622 //================================================================================
624 bool _ViscousBuilder2D::makePolyLines()
626 // Create _PolyLines and _LayerEdge's
628 // count total nb of EDGEs to allocate _polyLineVec
630 for ( size_t iWire = 0; iWire < _faceSideVec.size(); ++iWire )
631 nbEdges += _faceSideVec[ iWire ]->NbEdges();
632 _polyLineVec.resize( nbEdges );
634 // Assign data to _PolyLine's
635 // ---------------------------
638 for ( size_t iWire = 0; iWire < _faceSideVec.size(); ++iWire )
640 StdMeshers_FaceSidePtr wire = _faceSideVec[ iWire ];
641 const vector<UVPtStruct>& points = wire->GetUVPtStruct();
642 if ( points.empty() && wire->NbPoints() > 0 )
643 return error("Invalid node parameters on some EDGE");
645 for ( int iE = 0; iE < wire->NbEdges(); ++iE )
647 _PolyLine& L = _polyLineVec[ iPoLine++ ];
648 L._wire = wire.get();
650 L._advancable = !_ignoreShapeIds.count( wire->EdgeID( iE ));
652 int iRight = iPoLine - (( iE+1 < wire->NbEdges() ) ? 0 : wire->NbEdges() );
653 L._rightLine = &_polyLineVec[ iRight ];
654 _polyLineVec[ iRight ]._leftLine = &L;
656 L._firstPntInd = iPnt;
657 double lastNormPar = wire->LastParameter( iE ) - 1e-10;
658 while ( points[ iPnt ].normParam < lastNormPar )
660 L._lastPntInd = iPnt;
661 L._lEdges.resize( L._lastPntInd - L._firstPntInd + 1 );
663 // TODO: add more _LayerEdge's to strongly curved EDGEs
664 // in order not to miss collisions
666 Handle(Geom2d_Curve) pcurve = L._wire->Curve2d( L._edgeInd );
667 gp_Pnt2d uv; gp_Vec2d tangent;
668 for ( int i = L._firstPntInd; i <= L._lastPntInd; ++i )
670 _LayerEdge& lEdge = L._lEdges[ i - L._firstPntInd ];
671 const double u = ( i == L._firstPntInd ? wire->FirstU(iE) : points[ i ].param );
672 pcurve->D1( u , uv, tangent );
674 if ( L._wire->Edge( iE ).Orientation() == TopAbs_REVERSED )
676 lEdge._uvOut = lEdge._uvIn = uv.XY();
677 lEdge._normal2D.SetCoord( -tangent.Y(), tangent.X() );
678 lEdge._ray.SetLocation( lEdge._uvOut );
679 lEdge._ray.SetDirection( lEdge._normal2D );
680 lEdge._isBlocked = false;
683 setLenRatio( lEdge, SMESH_TNodeXYZ( points[ i ].node ) );
688 // Fill _PolyLine's with _segments
689 // --------------------------------
691 double maxLen2dTo3dRatio = 0;
692 for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine )
694 _PolyLine& L = _polyLineVec[ iPoLine ];
695 L._segments.resize( L._lEdges.size() - 1 );
696 for ( size_t i = 1; i < L._lEdges.size(); ++i )
698 _Segment & S = L._segments[i-1];
699 S._uv[0] = & L._lEdges[i-1]._uvIn;
700 S._uv[1] = & L._lEdges[i ]._uvIn;
701 S._indexInLine = i-1;
702 if ( maxLen2dTo3dRatio < L._lEdges[i]._len2dTo3dRatio )
703 maxLen2dTo3dRatio = L._lEdges[i]._len2dTo3dRatio;
705 // // connect _PolyLine's with segments, the 1st _LayerEdge of every _PolyLine
706 // // becomes not connected to any segment
707 // if ( L._leftLine->_advancable )
708 // L._segments[0]._uv[0] = & L._leftLine->_lEdges.back()._uvIn;
710 L._segTree.reset( new _SegmentTree( L._segments ));
713 // Evaluate possible _thickness if required layers thickness seems too high
714 // -------------------------------------------------------------------------
716 _thickness = _hyp->GetTotalThickness();
717 _SegmentTree::box_type faceBndBox2D;
718 for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine )
719 faceBndBox2D.Add( *_polyLineVec[ iPoLine]._segTree->getBox() );
721 if ( _thickness * maxLen2dTo3dRatio > sqrt( faceBndBox2D.SquareExtent() ) / 10 )
723 vector< const _Segment* > foundSegs;
724 double maxPossibleThick = 0;
725 _SegmentIntersection intersection;
726 for ( size_t iL1 = 0; iL1 < _polyLineVec.size(); ++iL1 )
728 _PolyLine& L1 = _polyLineVec[ iL1 ];
729 for ( size_t iL2 = iL1+1; iL2 < _polyLineVec.size(); ++iL2 )
731 _PolyLine& L2 = _polyLineVec[ iL2 ];
732 for ( size_t iLE = 1; iLE < L1._lEdges.size(); ++iLE )
735 L2._segTree->GetSegmentsNear( L1._lEdges[iLE]._ray, foundSegs );
736 for ( size_t i = 0; i < foundSegs.size(); ++i )
737 if ( intersection.Compute( *foundSegs[i], L1._lEdges[iLE]._ray ))
739 double distToL2 = intersection._param2 / L1._lEdges[iLE]._len2dTo3dRatio;
740 double psblThick = distToL2 / ( 1 + L1._advancable + L2._advancable );
741 if ( maxPossibleThick < psblThick )
742 maxPossibleThick = psblThick;
747 _thickness = Min( _hyp->GetTotalThickness(), maxPossibleThick );
750 // Adjust _LayerEdge's at _PolyLine's extremities
751 // -----------------------------------------------
753 for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine )
755 _PolyLine& LL = _polyLineVec[ iPoLine ];
756 _PolyLine& LR = *LL._rightLine;
757 adjustCommonEdge( LL, LR );
759 // recreate _segments if some _LayerEdge's have been removed by adjustCommonEdge()
760 for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine )
762 _PolyLine& L = _polyLineVec[ iPoLine ];
763 // if ( L._segments.size() == L._lEdges.size() - 1 )
765 L._segments.resize( L._lEdges.size() - 1 );
766 for ( size_t i = 1; i < L._lEdges.size(); ++i )
768 _Segment & S = L._segments[i-1];
769 S._uv[0] = & L._lEdges[i-1]._uvIn;
770 S._uv[1] = & L._lEdges[i ]._uvIn;
771 S._indexInLine = i-1;
773 L._segTree.reset( new _SegmentTree( L._segments ));
775 // connect _PolyLine's with segments, the 1st _LayerEdge of every _PolyLine
776 // becomes not connected to any segment
777 for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine )
779 _PolyLine& L = _polyLineVec[ iPoLine ];
780 if ( L._leftLine->_advancable )
781 L._segments[0]._uv[0] = & L._leftLine->_lEdges.back()._uvIn;
784 // Fill _reachableLines.
785 // ----------------------
787 // compute bnd boxes taking into account the layers total thickness
788 vector< _SegmentTree::box_type > lineBoxes( _polyLineVec.size() );
789 for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine )
791 lineBoxes[ iPoLine ] = *_polyLineVec[ iPoLine ]._segTree->getBox();
792 if ( _polyLineVec[ iPoLine ]._advancable )
793 lineBoxes[ iPoLine ].Enlarge( maxLen2dTo3dRatio * _thickness );
796 for ( iPoLine = 0; iPoLine < _polyLineVec.size(); ++iPoLine )
798 _PolyLine& L1 = _polyLineVec[ iPoLine ];
799 for ( size_t i = 0; i < _polyLineVec.size(); ++i )
801 _PolyLine& L2 = _polyLineVec[ i ];
802 if ( iPoLine == i || lineBoxes[ iPoLine ].IsOut( lineBoxes[ i ]))
804 if ( !L1._advancable && ( L1._leftLine == &L2 || L1._rightLine == &L2 ))
806 // check reachability by _LayerEdge's
807 int iDelta = 1; //Max( 1, L1._lEdges.size() / 100 );
808 for ( size_t iLE = 1; iLE < L1._lEdges.size(); iLE += iDelta )
810 _LayerEdge& LE = L1._lEdges[iLE];
811 if ( !lineBoxes[ i ].IsOut ( LE._uvOut,
812 LE._uvOut + LE._normal2D * _thickness * LE._len2dTo3dRatio )
814 !L1.IsAdjacent( L2._segments[0] ))
816 L1._reachableLines.push_back( & L2 );
821 // add self to _reachableLines
822 Geom2dAdaptor_Curve pcurve( L1._wire->Curve2d( L1._edgeInd ));
823 if ( pcurve.GetType() != GeomAbs_Line )
825 // TODO: check carefully
826 L1._reachableLines.push_back( & L1 );
833 //================================================================================
835 * \brief adjust common _LayerEdge of two adjacent _PolyLine's
836 * \param LL - left _PolyLine
837 * \param LR - right _PolyLine
839 //================================================================================
841 void _ViscousBuilder2D::adjustCommonEdge( _PolyLine& LL, _PolyLine& LR )
843 int nbAdvancableL = LL._advancable + LR._advancable;
844 if ( nbAdvancableL == 0 )
847 _LayerEdge& EL = LL._lEdges.back();
848 _LayerEdge& ER = LR._lEdges.front();
849 gp_XY normL = EL._normal2D;
850 gp_XY normR = ER._normal2D;
851 gp_XY tangL ( normL.Y(), -normL.X() );
852 //gp_XY tangR ( normR.Y(), -normR.X() );
854 gp_XY normCommon = ( normL + normR ).Normalized(); // average normal at VERTEX
856 EL._normal2D = normCommon;
857 EL._ray.SetLocation ( EL._uvOut );
858 EL._ray.SetDirection( EL._normal2D );
860 // update _LayerEdge::_len2dTo3dRatio according to a new direction
861 const vector<UVPtStruct>& points = LL._wire->GetUVPtStruct();
862 setLenRatio( EL, SMESH_TNodeXYZ( points[ LL._lastPntInd ].node ));
866 const double dotNormTang = normR * tangL;
867 const bool largeAngle = Abs( dotNormTang ) > 0.2;
870 // recompute _len2dTo3dRatio to take into account angle between EDGEs
871 gp_Vec2d oldNorm( LL._advancable ? normL : normR );
872 double fact = 1. / Max( 0.3, Cos( oldNorm.Angle( normCommon )));
873 EL._len2dTo3dRatio *= fact;
874 ER._len2dTo3dRatio = EL._len2dTo3dRatio;
876 if ( dotNormTang < 0. ) // ---------------------------- CONVEX ANGLE
878 // Remove _LayerEdge's intersecting the normCommon
880 const gp_XY& pCommOut = ER._uvOut;
881 gp_XY pCommIn( pCommOut + normCommon * _thickness * EL._len2dTo3dRatio );
882 _Segment segCommon( pCommOut, pCommIn );
883 _SegmentIntersection intersection;
884 for ( int isR = 0; isR < 2; ++isR ) // loop on [ LL, LR ]
886 _PolyLine& L = isR ? LR : LL;
887 _PolyLine::TEdgeIterator eIt = isR ? L._lEdges.begin()+1 : L._lEdges.end()-2;
888 int dIt = isR ? +1 : -1;
889 // at least 2 _LayerEdge's should remain in a _PolyLine (if _advancable)
890 if ( L._lEdges.size() < 3 ) continue;
892 for ( ; iLE < L._lEdges.size(); ++iLE, eIt += dIt )
894 gp_XY uvIn = eIt->_uvOut + eIt->_normal2D * _thickness * eIt->_len2dTo3dRatio;
895 _Segment segOfEdge( eIt->_uvOut, uvIn );
896 if ( !intersection.Compute( segCommon, segOfEdge ))
899 if ( iLE >= L._lEdges.size () - 1 )
901 // all _LayerEdge's intersect the segCommon, limit inflation
902 // of remaining 2 _LayerEdge's
903 vector< _LayerEdge > newEdgeVec( 2 );
904 newEdgeVec.front() = L._lEdges.front();
905 newEdgeVec.back() = L._lEdges.back();
906 L._lEdges.swap( newEdgeVec );
907 if ( !isR ) std::swap( intersection._param1 , intersection._param2 );
908 L._lEdges.front()._len2dTo3dRatio *= intersection._param1;
909 L._lEdges.back ()._len2dTo3dRatio *= intersection._param2;
913 // eIt points to the _LayerEdge not intersecting with segCommon
915 LR._lEdges.erase( LR._lEdges.begin()+1, eIt );
917 LL._lEdges.erase( eIt, --LL._lEdges.end() );
921 else // ------------------------------------------ CONCAVE ANGLE
923 if ( nbAdvancableL == 1 )
925 // make that the _LayerEdge at VERTEX is not shared by LL and LR
926 _LayerEdge& notSharedEdge = LL._advancable ? LR._lEdges[0] : LL._lEdges.back();
927 notSharedEdge._normal2D.SetCoord( 0.,0. );
933 //================================================================================
935 * \brief Compute and set _LayerEdge::_len2dTo3dRatio
937 //================================================================================
939 void _ViscousBuilder2D::setLenRatio( _LayerEdge& LE, const gp_Pnt& pOut )
941 const double probeLen2d = 1e-3;
943 gp_Pnt2d p2d = LE._uvOut + LE._normal2D * probeLen2d;
944 gp_Pnt p3d = _surface->Value( p2d.X(), p2d.Y() );
945 double len3d = p3d.Distance( pOut );
946 if ( len3d < std::numeric_limits<double>::min() )
947 LE._len2dTo3dRatio = std::numeric_limits<double>::min();
949 LE._len2dTo3dRatio = probeLen2d / len3d;
952 //================================================================================
954 * \brief Increase length of _LayerEdge's to reach the required thickness of layers
956 //================================================================================
958 bool _ViscousBuilder2D::inflate()
960 // Limit size of inflation step by geometry size found by
961 // itersecting _LayerEdge's with _Segment's
962 double minSize = _thickness, maxSize = 0;
963 vector< const _Segment* > foundSegs;
964 _SegmentIntersection intersection;
965 for ( size_t iL1 = 0; iL1 < _polyLineVec.size(); ++iL1 )
967 _PolyLine& L1 = _polyLineVec[ iL1 ];
968 for ( size_t iL2 = 0; iL2 < L1._reachableLines.size(); ++iL2 )
970 _PolyLine& L2 = * L1._reachableLines[ iL2 ];
971 for ( size_t iLE = 1; iLE < L1._lEdges.size(); ++iLE )
974 L2._segTree->GetSegmentsNear( L1._lEdges[iLE]._ray, foundSegs );
975 for ( size_t i = 0; i < foundSegs.size(); ++i )
976 if ( ! L1.IsAdjacent( *foundSegs[i] ) &&
977 intersection.Compute( *foundSegs[i], L1._lEdges[iLE]._ray ))
979 double distToL2 = intersection._param2 / L1._lEdges[iLE]._len2dTo3dRatio;
980 double size = distToL2 / ( 1 + L1._advancable + L2._advancable );
981 if ( size < minSize )
983 if ( size > maxSize )
989 if ( minSize > maxSize ) // no collisions possible
990 maxSize = _thickness;
992 cout << "-- minSize = " << minSize << ", maxSize = " << maxSize << endl;
995 double curThick = 0, stepSize = minSize;
997 if ( maxSize > _thickness )
998 maxSize = _thickness;
999 while ( curThick < maxSize )
1001 curThick += stepSize * 1.25;
1002 if ( curThick > _thickness )
1003 curThick = _thickness;
1005 // Elongate _LayerEdge's
1006 for ( size_t iL = 0; iL < _polyLineVec.size(); ++iL )
1008 _PolyLine& L = _polyLineVec[ iL ];
1009 if ( !L._advancable ) continue;
1010 bool lenChange = false;
1011 for ( size_t iLE = L.FirstLEdge(); iLE < L._lEdges.size(); ++iLE )
1012 lenChange |= L._lEdges[iLE].SetNewLength( curThick );
1013 // for ( int k=0; k<L._segments.size(); ++k)
1014 // cout << "( " << L._segments[k].p1().X() << ", " <<L._segments[k].p1().Y() << " ) "
1015 // << "( " << L._segments[k].p2().X() << ", " <<L._segments[k].p2().Y() << " ) "
1018 L._segTree.reset( new _SegmentTree( L._segments ));
1021 // Avoid intersection of _Segment's
1022 bool allBlocked = fixCollisions();
1025 break; // no more inflating possible
1027 stepSize = Max( stepSize , _thickness / 10. );
1031 // if (nbSteps == 0 )
1032 // return error("failed at the very first inflation step");
1037 //================================================================================
1039 * \brief Remove intersection of _PolyLine's
1041 //================================================================================
1043 bool _ViscousBuilder2D::fixCollisions()
1045 // look for intersections of _Segment's by intersecting _LayerEdge's with
1047 //double maxStep = 0, minStep = 1e+100;
1048 vector< const _Segment* > foundSegs;
1049 _SegmentIntersection intersection;
1051 list< pair< _LayerEdge*, double > > edgeLenLimitList;
1053 for ( size_t iL1 = 0; iL1 < _polyLineVec.size(); ++iL1 )
1055 _PolyLine& L1 = _polyLineVec[ iL1 ];
1056 //if ( !L1._advancable ) continue;
1057 for ( size_t iL2 = 0; iL2 < L1._reachableLines.size(); ++iL2 )
1059 _PolyLine& L2 = * L1._reachableLines[ iL2 ];
1060 //for ( size_t iLE = L1.FirstLEdge(); iLE < L1._lEdges.size(); ++iLE )
1061 for ( size_t iLE = 1; iLE < L1._lEdges.size()-1; ++iLE )
1063 _LayerEdge& LE1 = L1._lEdges[iLE];
1064 if ( LE1._isBlocked ) continue;
1066 L2._segTree->GetSegmentsNear( LE1._ray, foundSegs );
1067 for ( size_t i = 0; i < foundSegs.size(); ++i )
1069 if ( ! L1.IsAdjacent( *foundSegs[i] ) &&
1070 intersection.Compute( *foundSegs[i], LE1._ray ))
1072 const double dist2DToL2 = intersection._param2;
1073 double newLen2D = dist2DToL2 / 2;
1074 if ( newLen2D < 1.1 * LE1._length2D ) // collision!
1076 if ( newLen2D < LE1._length2D )
1078 if ( L1._advancable )
1080 edgeLenLimitList.push_back( make_pair( &LE1, newLen2D ));
1081 L2._lEdges[ foundSegs[i]->_indexInLine ]._isBlocked = true;
1082 L2._lEdges[ foundSegs[i]->_indexInLine + 1 ]._isBlocked = true;
1084 else // here dist2DToL2 < 0 and LE1._length2D == 0
1086 _LayerEdge LE2[2] = { L2._lEdges[ foundSegs[i]->_indexInLine ],
1087 L2._lEdges[ foundSegs[i]->_indexInLine + 1 ] };
1088 _Segment outSeg2( LE2[0]._uvOut, LE2[1]._uvOut );
1089 intersection.Compute( outSeg2, LE1._ray );
1090 newLen2D = intersection._param2 / 2;
1092 edgeLenLimitList.push_back( make_pair( &LE2[0], newLen2D ));
1093 edgeLenLimitList.push_back( make_pair( &LE2[1], newLen2D ));
1094 LE2[0]._isBlocked = true;
1095 LE2[1]._isBlocked = true;
1098 LE1._isBlocked = true; // !! after SetNewLength()
1102 // double step2D = newLen2D - LE1._length2D;
1103 // double step = step2D / LE1._len2dTo3dRatio;
1104 // if ( step > maxStep )
1106 // if ( step < minStep )
1115 // set limited length to _LayerEdge's
1116 list< pair< _LayerEdge*, double > >::iterator edge2Len = edgeLenLimitList.begin();
1117 for ( ; edge2Len != edgeLenLimitList.end(); ++edge2Len )
1119 _LayerEdge* LE = edge2Len->first;
1120 LE->SetNewLength( edge2Len->second / LE->_len2dTo3dRatio );
1123 for ( size_t iL = 0; iL < _polyLineVec.size(); ++iL )
1125 _PolyLine& L = _polyLineVec[ iL ];
1126 if ( !L._advancable ) continue;
1127 for ( size_t iLE = L.FirstLEdge(); iLE < L._lEdges.size(); ++iLE )
1128 if ( !L._lEdges[ iLE ]._isBlocked )
1135 //================================================================================
1137 * \brief Create new edges and shrink edges existing on a non-advancable _PolyLine
1138 * adjacent to an advancable one.
1140 //================================================================================
1142 bool _ViscousBuilder2D::shrink()
1144 gp_Pnt2d uv; gp_Vec2d tangent;
1145 _SegmentIntersection intersection;
1148 for ( size_t iL1 = 0; iL1 < _polyLineVec.size(); ++iL1 )
1150 _PolyLine& L = _polyLineVec[ iL1 ]; // line with no layers
1151 if ( L._advancable )
1153 if ( !L._rightLine->_advancable && !L._leftLine->_advancable )
1156 const TopoDS_Edge& E = L._wire->Edge ( L._edgeInd );
1157 const int edgeID = L._wire->EdgeID ( L._edgeInd );
1158 const double edgeLen = L._wire->EdgeLength( L._edgeInd );
1159 Handle(Geom2d_Curve) pcurve = L._wire->Curve2d ( L._edgeInd );
1160 const bool edgeReversed = ( E.Orientation() == TopAbs_REVERSED );
1162 SMESH_MesherHelper helper( *_mesh ); // to create nodes and edges on E
1163 helper.SetSubShape( E );
1164 helper.SetElementsOnShape( true );
1166 // Check a FACE adjacent to _face by E
1167 bool existingNodesFound = false;
1168 TopoDS_Face adjFace;
1169 PShapeIteratorPtr faceIt = _helper.GetAncestors( E, *_mesh, TopAbs_FACE );
1170 while ( const TopoDS_Shape* f = faceIt->next() )
1171 if ( !_face.IsSame( *f ))
1173 adjFace = TopoDS::Face( *f );
1174 SMESH_ProxyMesh::Ptr pm = _ProxyMeshHolder::FindProxyMeshOfFace( adjFace, *_mesh );
1175 if ( !pm || pm->NbProxySubMeshes() == 0 )
1177 // There are no viscous layers on an adjacent FACE, clear it's 2D mesh
1178 removeMeshFaces( adjFace );
1182 // There are viscous layers on the adjacent FACE; shrink must be already done;
1186 const vector<UVPtStruct>& points = L._wire->GetUVPtStruct();
1187 int iPFrom = L._firstPntInd, iPTo = L._lastPntInd;
1188 if ( L._leftLine->_advancable )
1190 vector<gp_XY>& uvVec = L._lEdges.front()._uvRefined;
1191 for ( int i = 0; i < _hyp->GetNumberLayers(); ++i ) {
1192 const UVPtStruct& uvPt = points[ iPFrom + i + 1 ];
1193 L._leftNodes.push_back( uvPt.node );
1194 uvVec.push_back ( pcurve->Value( uvPt.param ).XY() );
1197 if ( L._rightLine->_advancable )
1199 vector<gp_XY>& uvVec = L._lEdges.back()._uvRefined;
1200 for ( int i = 0; i < _hyp->GetNumberLayers(); ++i ) {
1201 const UVPtStruct& uvPt = points[ iPTo - i - 1 ];
1202 L._rightNodes.push_back( uvPt.node );
1203 uvVec.push_back ( pcurve->Value( uvPt.param ).XY() );
1206 // make proxy sub-mesh data of present nodes
1208 if ( L._leftLine->_advancable ) iPFrom += _hyp->GetNumberLayers();
1209 if ( L._rightLine->_advancable ) iPTo -= _hyp->GetNumberLayers();
1210 UVPtStructVec nodeDataVec( & points[ iPFrom ], & points[ iPTo + 1 ]);
1212 double normSize = nodeDataVec.back().normParam - nodeDataVec.front().normParam;
1213 for ( int iP = nodeDataVec.size()-1; iP >= 0 ; --iP )
1214 nodeDataVec[iP].normParam =
1215 ( nodeDataVec[iP].normParam - nodeDataVec[0].normParam ) / normSize;
1217 const SMDS_MeshNode* n = nodeDataVec.front().node;
1218 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
1219 nodeDataVec.front().param = L._wire->FirstU( L._edgeInd );
1220 n = nodeDataVec.back().node;
1221 if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
1222 nodeDataVec.back().param = L._wire->LastU( L._edgeInd );
1224 _ProxyMeshOfFace::_EdgeSubMesh* myEdgeSM = getProxyMesh()->GetEdgeSubMesh( edgeID );
1225 myEdgeSM->SetUVPtStructVec( nodeDataVec );
1227 existingNodesFound = true;
1229 } // loop on FACEs sharing E
1231 if ( existingNodesFound )
1232 continue; // nothing more to do in this case
1234 double u1 = L._wire->FirstU( L._edgeInd ), uf = u1;
1235 double u2 = L._wire->LastU ( L._edgeInd ), ul = u2;
1237 // Get length of existing segments (from edge start to node) and their nodes
1238 const vector<UVPtStruct>& points = L._wire->GetUVPtStruct();
1239 UVPtStructVec nodeDataVec( & points[ L._firstPntInd ],
1240 & points[ L._lastPntInd + 1 ]);
1241 nodeDataVec.front().param = u1; // U on vertex is correct on only one of shared edges
1242 nodeDataVec.back ().param = u2;
1243 nodeDataVec.front().normParam = 0;
1244 nodeDataVec.back ().normParam = 1;
1245 vector< double > segLengths( nodeDataVec.size() - 1 );
1246 BRepAdaptor_Curve curve( E );
1247 for ( size_t iP = 1; iP < nodeDataVec.size(); ++iP )
1249 const double len = GCPnts_AbscissaPoint::Length( curve, uf, nodeDataVec[iP].param );
1250 segLengths[ iP-1 ] = len;
1255 // x-----x-----x-----x-----
1260 // x-x-x-x-----x-----x----
1263 // Move first and last parameters on EDGE (U of n1) according to layers' thickness
1264 // and create nodes of layers on EDGE ( -x-x-x )
1265 int isRShrinkedForAdjacent;
1266 UVPtStructVec nodeDataForAdjacent;
1267 for ( int isR = 0; isR < 2; ++isR )
1269 _PolyLine* L2 = isR ? L._rightLine : L._leftLine; // line with layers
1270 if ( !L2->_advancable &&
1271 !toShrinkForAdjacent( adjFace, E, L._wire->FirstVertex( L._edgeInd + isR )))
1274 double & u = isR ? u2 : u1; // param to move
1275 double u0 = isR ? ul : uf; // init value of the param to move
1276 int iPEnd = isR ? nodeDataVec.size() - 1 : 0;
1278 // try to find length of advancement along L by intersecting L with
1279 // an adjacent _Segment of L2
1281 double & length2D = ( isR ? L._lEdges.back() : L._lEdges.front() )._length2D;
1282 sign = ( isR ^ edgeReversed ) ? -1. : 1.;
1283 pcurve->D1( u, uv, tangent );
1285 if ( L2->_advancable )
1287 gp_Ax2d edgeRay( uv, tangent * sign );
1288 const _Segment& seg2( isR ? L2->_segments.front() : L2->_segments.back() );
1289 // make an elongated seg2
1290 gp_XY seg2Vec( seg2.p2() - seg2.p1() );
1291 gp_XY longSeg2p1 = seg2.p1() - 1000 * seg2Vec;
1292 gp_XY longSeg2p2 = seg2.p2() + 1000 * seg2Vec;
1293 _Segment longSeg2( longSeg2p1, longSeg2p2 );
1294 if ( intersection.Compute( longSeg2, edgeRay )) { // convex VERTEX
1296 length2D = intersection._param2; /* |L seg2
1302 else { /* concave VERTEX */ /* o-----o---
1308 length2D = ( isR ? L2->_lEdges.front() : L2->_lEdges.back() )._length2D;
1311 else // L2 is advancable but in the face adjacent by L
1313 length2D = ( isR ? L._lEdges.front() : L._lEdges.back() )._length2D;
1314 if ( length2D == 0 )
1315 length2D = ( isR ? L._leftLine->_lEdges.back() : L._rightLine->_lEdges.front() )._length2D;
1317 // move u to the internal boundary of layers
1318 u += length2D * sign;
1319 nodeDataVec[ iPEnd ].param = u;
1321 gp_Pnt2d newUV = pcurve->Value( u );
1322 nodeDataVec[ iPEnd ].u = newUV.X();
1323 nodeDataVec[ iPEnd ].v = newUV.Y();
1325 // compute params of layers on L
1326 vector<double> heights;
1327 calcLayersHeight( u - u0, heights );
1329 vector< double > params( heights.size() );
1330 for ( size_t i = 0; i < params.size(); ++i )
1331 params[ i ] = u0 + heights[ i ];
1333 // create nodes of layers and edges between them
1334 vector< const SMDS_MeshNode* >& layersNode = isR ? L._rightNodes : L._leftNodes;
1335 vector<gp_XY>& nodeUV = ( isR ? L._lEdges.back() : L._lEdges[0] )._uvRefined;
1336 nodeUV.resize ( _hyp->GetNumberLayers() );
1337 layersNode.resize( _hyp->GetNumberLayers() );
1338 const SMDS_MeshNode* vertexNode = nodeDataVec[ iPEnd ].node;
1339 const SMDS_MeshNode * prevNode = vertexNode;
1340 for ( size_t i = 0; i < params.size(); ++i )
1342 gp_Pnt p = curve.Value( params[i] );
1343 layersNode[ i ] = helper.AddNode( p.X(), p.Y(), p.Z(), /*id=*/0, params[i] );
1344 nodeUV [ i ] = pcurve->Value( params[i] ).XY();
1345 helper.AddEdge( prevNode, layersNode[ i ] );
1346 prevNode = layersNode[ i ];
1349 // store data of layer nodes made for adjacent FACE
1350 if ( !L2->_advancable )
1352 isRShrinkedForAdjacent = isR;
1353 nodeDataForAdjacent.resize( _hyp->GetNumberLayers() );
1355 size_t iFrw = 0, iRev = nodeDataForAdjacent.size()-1, *i = isR ? &iRev : &iFrw;
1356 nodeDataForAdjacent[ *i ] = points[ isR ? L._lastPntInd : L._firstPntInd ];
1357 nodeDataForAdjacent[ *i ].param = u0;
1358 nodeDataForAdjacent[ *i ].normParam = isR;
1359 for ( ++iFrw, --iRev; iFrw < layersNode.size(); ++iFrw, --iRev )
1361 nodeDataForAdjacent[ *i ].node = layersNode[ iFrw - 1 ];
1362 nodeDataForAdjacent[ *i ].u = nodeUV [ iFrw - 1 ].X();
1363 nodeDataForAdjacent[ *i ].v = nodeUV [ iFrw - 1 ].Y();
1364 nodeDataForAdjacent[ *i ].param = params [ iFrw - 1 ];
1367 // replace a node on vertex by a node of last (most internal) layer
1368 // in a segment on E
1369 SMDS_ElemIteratorPtr segIt = vertexNode->GetInverseElementIterator( SMDSAbs_Edge );
1370 const SMDS_MeshNode* segNodes[3];
1371 while ( segIt->more() )
1373 const SMDS_MeshElement* segment = segIt->next();
1374 if ( segment->getshapeId() != edgeID ) continue;
1376 const int nbNodes = segment->NbNodes();
1377 for ( int i = 0; i < nbNodes; ++i )
1379 const SMDS_MeshNode* n = segment->GetNode( i );
1380 segNodes[ i ] = ( n == vertexNode ? layersNode.back() : n );
1382 getMeshDS()->ChangeElementNodes( segment, segNodes, nbNodes );
1385 nodeDataVec[ iPEnd ].node = layersNode.back();
1387 } // loop on the extremities of L
1389 // Shrink edges to fit in between the layers at EDGE ends
1391 const double newLength = GCPnts_AbscissaPoint::Length( curve, u1, u2 );
1392 const double lenRatio = newLength / edgeLen * ( edgeReversed ? -1. : 1. );
1393 for ( size_t iP = 1; iP < nodeDataVec.size()-1; ++iP )
1395 const SMDS_MeshNode* oldNode = nodeDataVec[iP].node;
1397 GCPnts_AbscissaPoint discret( curve, segLengths[iP-1] * lenRatio, u1 );
1398 if ( !discret.IsDone() )
1399 throw SALOME_Exception(LOCALIZED("GCPnts_AbscissaPoint failed"));
1401 nodeDataVec[iP].param = discret.Parameter();
1402 if ( oldNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_EDGE )
1403 throw SALOME_Exception(SMESH_Comment("ViscousBuilder2D: not SMDS_TOP_EDGE node position: ")
1404 << oldNode->GetPosition()->GetTypeOfPosition()
1405 << " of node " << oldNode->GetID());
1406 SMDS_EdgePosition* pos = static_cast<SMDS_EdgePosition*>( oldNode->GetPosition() );
1407 pos->SetUParameter( nodeDataVec[iP].param );
1409 gp_Pnt newP = curve.Value( nodeDataVec[iP].param );
1410 getMeshDS()->MoveNode( oldNode, newP.X(), newP.Y(), newP.Z() );
1412 gp_Pnt2d newUV = pcurve->Value( nodeDataVec[iP].param ).XY();
1413 nodeDataVec[iP].u = newUV.X();
1414 nodeDataVec[iP].v = newUV.Y();
1415 nodeDataVec[iP].normParam = segLengths[iP-1] / edgeLen;
1416 // nodeDataVec[iP].x = segLengths[iP-1] / edgeLen;
1417 // nodeDataVec[iP].y = segLengths[iP-1] / edgeLen;
1420 // add nodeDataForAdjacent to nodeDataVec
1421 if ( !nodeDataForAdjacent.empty() )
1423 const double par1 = isRShrinkedForAdjacent ? u2 : uf;
1424 const double par2 = isRShrinkedForAdjacent ? ul : u1;
1425 const double shrinkLen = GCPnts_AbscissaPoint::Length( curve, par1, par2 );
1427 // compute new normParam for nodeDataVec
1428 for ( size_t iP = 0; iP < nodeDataVec.size()-1; ++iP )
1429 nodeDataVec[iP+1].normParam = segLengths[iP] / ( edgeLen + shrinkLen );
1430 double normDelta = 1 - nodeDataVec.back().normParam;
1431 if ( !isRShrinkedForAdjacent )
1432 for ( size_t iP = 0; iP < nodeDataVec.size(); ++iP )
1433 nodeDataVec[iP].normParam += normDelta;
1435 // compute new normParam for nodeDataForAdjacent
1436 const double deltaR = isRShrinkedForAdjacent ? nodeDataVec.back().normParam : 0;
1437 for ( size_t iP = !isRShrinkedForAdjacent; iP < nodeDataForAdjacent.size(); ++iP )
1439 double lenFromPar1 =
1440 GCPnts_AbscissaPoint::Length( curve, par1, nodeDataForAdjacent[iP].param );
1441 nodeDataForAdjacent[iP].normParam = deltaR + normDelta * lenFromPar1 / shrinkLen;
1443 // concatenate nodeDataVec and nodeDataForAdjacent
1444 nodeDataVec.insert( isRShrinkedForAdjacent ? nodeDataVec.end() : nodeDataVec.begin(),
1445 nodeDataForAdjacent.begin(), nodeDataForAdjacent.end() );
1448 // create a proxy sub-mesh containing the moved nodes
1449 _ProxyMeshOfFace::_EdgeSubMesh* edgeSM = getProxyMesh()->GetEdgeSubMesh( edgeID );
1450 edgeSM->SetUVPtStructVec( nodeDataVec );
1452 // set a sub-mesh event listener to remove just created edges when
1453 // "ViscousLayers2D" hypothesis is modified
1454 VISCOUS_3D::ToClearSubWithMain( _mesh->GetSubMesh( E ), _face );
1456 } // loop on _polyLineVec
1461 //================================================================================
1463 * \brief Returns true if there will be a shrinked mesh on EDGE E of FACE adjFace
1466 //================================================================================
1468 bool _ViscousBuilder2D::toShrinkForAdjacent( const TopoDS_Face& adjFace,
1469 const TopoDS_Edge& E,
1470 const TopoDS_Vertex& V)
1472 if ( const StdMeshers_ViscousLayers2D* vlHyp = findHyp( *_mesh, adjFace ))
1474 VISCOUS_2D::_ViscousBuilder2D builder( *_mesh, adjFace, vlHyp );
1475 builder.findEdgesWithLayers();
1477 PShapeIteratorPtr edgeIt = _helper.GetAncestors( V, *_mesh, TopAbs_EDGE );
1478 while ( const TopoDS_Shape* edgeAtV = edgeIt->next() )
1480 if ( !edgeAtV->IsSame( E ) &&
1481 _helper.IsSubShape( *edgeAtV, adjFace ) &&
1482 !builder._ignoreShapeIds.count( getMeshDS()->ShapeToIndex( *edgeAtV )))
1491 //================================================================================
1495 //================================================================================
1497 bool _ViscousBuilder2D::refine()
1499 // remove elements and nodes from _face
1500 removeMeshFaces( _face );
1502 // store a proxyMesh in a sub-mesh
1503 // make faces on each _PolyLine
1504 vector< double > layersHeight;
1505 double prevLen2D = -1;
1506 for ( size_t iL = 0; iL < _polyLineVec.size(); ++iL )
1508 _PolyLine& L = _polyLineVec[ iL ];
1509 if ( !L._advancable ) continue;
1511 //if ( L._leftLine->_advancable ) L._lEdges[0] = L._leftLine->_lEdges.back();
1513 // calculate intermediate UV on _LayerEdge's ( _LayerEdge::_uvRefined )
1514 size_t iLE = 0, nbLE = L._lEdges.size();
1515 if ( /*!L._leftLine->_advancable &&*/ L.IsCommonEdgeShared( *L._leftLine ))
1517 L._lEdges[0] = L._leftLine->_lEdges.back();
1518 iLE += int( !L._leftLine->_advancable );
1520 if ( !L._rightLine->_advancable && L.IsCommonEdgeShared( *L._rightLine ))
1522 L._lEdges.back() = L._rightLine->_lEdges[0];
1525 for ( ; iLE < nbLE; ++iLE )
1527 _LayerEdge& LE = L._lEdges[iLE];
1528 if ( fabs( LE._length2D - prevLen2D ) > LE._length2D / 100. )
1530 calcLayersHeight( LE._length2D, layersHeight );
1531 prevLen2D = LE._length2D;
1533 for ( size_t i = 0; i < layersHeight.size(); ++i )
1534 LE._uvRefined.push_back( LE._uvOut + LE._normal2D * layersHeight[i] );
1537 // nodes to create 1 layer of faces
1538 vector< const SMDS_MeshNode* > outerNodes( L._lastPntInd - L._firstPntInd + 1 );
1539 vector< const SMDS_MeshNode* > innerNodes( L._lastPntInd - L._firstPntInd + 1 );
1541 // initialize outerNodes by node on the L._wire
1542 const vector<UVPtStruct>& points = L._wire->GetUVPtStruct();
1543 for ( int i = L._firstPntInd; i <= L._lastPntInd; ++i )
1544 outerNodes[ i-L._firstPntInd ] = points[i].node;
1546 // compute normalized [0;1] node parameters of outerNodes
1547 vector< double > normPar( L._lastPntInd - L._firstPntInd + 1 );
1549 normF = L._wire->FirstParameter( L._edgeInd ),
1550 normL = L._wire->LastParameter ( L._edgeInd ),
1551 normDist = normL - normF;
1552 for ( int i = L._firstPntInd; i <= L._lastPntInd; ++i )
1553 normPar[ i - L._firstPntInd ] = ( points[i].normParam - normF ) / normDist;
1555 // Create layers of faces
1557 int hasLeftNode = ( !L._leftLine->_rightNodes.empty() );
1558 int hasRightNode = ( !L._rightLine->_leftNodes.empty() );
1559 size_t iS, iN0 = hasLeftNode, nbN = innerNodes.size() - hasRightNode;
1560 L._leftNodes .resize( _hyp->GetNumberLayers() );
1561 L._rightNodes.resize( _hyp->GetNumberLayers() );
1562 vector< double > segLen( L._lEdges.size() );
1564 for ( int iF = 0; iF < _hyp->GetNumberLayers(); ++iF ) // loop on layers of faces
1566 // get accumulated length of intermediate segments
1567 for ( iS = 1; iS < segLen.size(); ++iS )
1569 double sLen = (L._lEdges[iS-1]._uvRefined[iF] - L._lEdges[iS]._uvRefined[iF] ).Modulus();
1570 segLen[iS] = segLen[iS-1] + sLen;
1572 // normalize the accumulated length
1573 for ( iS = 1; iS < segLen.size(); ++iS )
1574 segLen[iS] /= segLen.back();
1576 // create innerNodes
1578 for ( size_t i = iN0; i < nbN; ++i )
1580 while ( normPar[i] > segLen[iS+1] )
1582 double r = ( normPar[i] - segLen[iS] ) / ( segLen[iS+1] - segLen[iS] );
1583 gp_XY uv = r * L._lEdges[iS+1]._uvRefined[iF] + (1-r) * L._lEdges[iS]._uvRefined[iF];
1584 gp_Pnt p = _surface->Value( uv.X(), uv.Y() );
1585 innerNodes[i] = _helper.AddNode( p.X(), p.Y(), p.Z(), /*id=*/0, uv.X(), uv.Y() );
1587 if ( hasLeftNode ) innerNodes.front() = L._leftLine->_rightNodes[ iF ];
1588 if ( hasRightNode ) innerNodes.back() = L._rightLine->_leftNodes[ iF ];
1589 L._rightNodes[ iF ] = innerNodes.back();
1590 L._leftNodes [ iF ] = innerNodes.front();
1593 // TODO care of orientation
1594 for ( size_t i = 1; i < innerNodes.size(); ++i )
1595 _helper.AddFace( outerNodes[ i-1 ], outerNodes[ i ],
1596 innerNodes[ i ], innerNodes[ i-1 ]);
1598 outerNodes.swap( innerNodes );
1601 // Fill the _ProxyMeshOfFace
1603 UVPtStructVec nodeDataVec( outerNodes.size() ); // outerNodes swapped with innerNodes
1604 for ( size_t i = 0; i < outerNodes.size(); ++i )
1606 gp_XY uv = _helper.GetNodeUV( _face, outerNodes[i] );
1607 nodeDataVec[i].u = uv.X();
1608 nodeDataVec[i].v = uv.Y();
1609 nodeDataVec[i].node = outerNodes[i];
1610 nodeDataVec[i].param = points [i + L._firstPntInd].param;
1611 nodeDataVec[i].normParam = normPar[i];
1612 nodeDataVec[i].x = normPar[i];
1613 nodeDataVec[i].y = normPar[i];
1615 nodeDataVec.front().param = L._wire->FirstU( L._edgeInd );
1616 nodeDataVec.back() .param = L._wire->LastU ( L._edgeInd );
1618 _ProxyMeshOfFace::_EdgeSubMesh* edgeSM
1619 = getProxyMesh()->GetEdgeSubMesh( L._wire->EdgeID( L._edgeInd ));
1620 edgeSM->SetUVPtStructVec( nodeDataVec );
1622 } // loop on _PolyLine's
1627 //================================================================================
1629 * \brief Remove elements and nodes from a face
1631 //================================================================================
1633 bool _ViscousBuilder2D::removeMeshFaces(const TopoDS_Shape& face)
1635 // we don't use SMESH_subMesh::ComputeStateEngine() because of a listener
1636 // which clears EDGEs together with _face.
1637 bool thereWereElems = false;
1638 SMESH_subMesh* sm = _mesh->GetSubMesh( face );
1639 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
1641 SMDS_ElemIteratorPtr eIt = smDS->GetElements();
1642 thereWereElems = eIt->more();
1643 while ( eIt->more() ) getMeshDS()->RemoveFreeElement( eIt->next(), smDS );
1644 SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
1645 while ( nIt->more() ) getMeshDS()->RemoveFreeNode( nIt->next(), smDS );
1647 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1649 return thereWereElems;
1652 //================================================================================
1654 * \brief Creates a _ProxyMeshOfFace and store it in a sub-mesh of FACE
1656 //================================================================================
1658 _ProxyMeshOfFace* _ViscousBuilder2D::getProxyMesh()
1660 if ( _proxyMesh.get() )
1661 return (_ProxyMeshOfFace*) _proxyMesh.get();
1663 _ProxyMeshOfFace* proxyMeshOfFace = new _ProxyMeshOfFace( *_mesh );
1664 _proxyMesh.reset( proxyMeshOfFace );
1665 new _ProxyMeshHolder( _face, _proxyMesh );
1667 return proxyMeshOfFace;
1670 //================================================================================
1672 * \brief Calculate height of layers for the given thickness. Height is measured
1673 * from the outer boundary
1675 //================================================================================
1677 void _ViscousBuilder2D::calcLayersHeight(const double totalThick,
1678 vector<double>& heights)
1680 heights.resize( _hyp->GetNumberLayers() );
1682 if ( _fPowN - 1 <= numeric_limits<double>::min() )
1683 h0 = totalThick / _hyp->GetNumberLayers();
1685 h0 = totalThick * ( _hyp->GetStretchFactor() - 1 )/( _fPowN - 1 );
1687 double hSum = 0, hi = h0;
1688 for ( int i = 0; i < _hyp->GetNumberLayers(); ++i )
1691 heights[ i ] = hSum;
1692 hi *= _hyp->GetStretchFactor();
1696 //================================================================================
1698 * \brief Elongate this _LayerEdge
1700 //================================================================================
1702 bool _LayerEdge::SetNewLength( const double length3D )
1704 if ( _isBlocked ) return false;
1706 //_uvInPrev = _uvIn;
1707 _length2D = length3D * _len2dTo3dRatio;
1708 _uvIn = _uvOut + _normal2D * _length2D;
1712 //================================================================================
1714 * \brief Return true if _LayerEdge at a common VERTEX between EDGEs with
1715 * and w/o layer is common to the both _PolyLine's. If this is true, nodes
1716 * of this _LayerEdge are inflated along a _PolyLine w/o layer, else the nodes
1717 * are inflated along _normal2D of _LayerEdge of EDGE with layer
1719 //================================================================================
1721 bool _PolyLine::IsCommonEdgeShared( const _PolyLine& other )
1723 const double tol = 1e-30;
1725 if ( & other == _leftLine )
1726 return _lEdges[0]._normal2D.IsEqual( _leftLine->_lEdges.back()._normal2D, tol );
1728 if ( & other == _rightLine )
1729 return _lEdges.back()._normal2D.IsEqual( _rightLine->_lEdges[0]._normal2D, tol );
1734 //================================================================================
1736 * \brief Constructor of SegmentTree
1738 //================================================================================
1740 _SegmentTree::_SegmentTree( const vector< _Segment >& segments ):
1743 _segments.resize( segments.size() );
1744 for ( size_t i = 0; i < segments.size(); ++i )
1745 _segments[i].Set( segments[i] );
1750 //================================================================================
1752 * \brief Return the maximal bnd box
1754 //================================================================================
1756 _SegmentTree::box_type* _SegmentTree::buildRootBox()
1758 _SegmentTree::box_type* box = new _SegmentTree::box_type;
1759 for ( size_t i = 0; i < _segments.size(); ++i )
1761 box->Add( *_segments[i]._seg->_uv[0] );
1762 box->Add( *_segments[i]._seg->_uv[1] );
1767 //================================================================================
1769 * \brief Redistrubute _segments among children
1771 //================================================================================
1773 void _SegmentTree::buildChildrenData()
1775 for ( int i = 0; i < _segments.size(); ++i )
1776 for (int j = 0; j < nbChildren(); j++)
1777 if ( !myChildren[j]->getBox()->IsOut( *_segments[i]._seg->_uv[0],
1778 *_segments[i]._seg->_uv[1] ))
1779 ((_SegmentTree*)myChildren[j])->_segments.push_back( _segments[i]);
1781 SMESHUtils::FreeVector( _segments ); // = _elements.clear() + free memory
1783 for (int j = 0; j < nbChildren(); j++)
1785 _SegmentTree* child = static_cast<_SegmentTree*>( myChildren[j]);
1786 child->myIsLeaf = ( child->_segments.size() <= maxNbSegInLeaf() );
1790 //================================================================================
1792 * \brief Return elements which can include the point
1794 //================================================================================
1796 void _SegmentTree::GetSegmentsNear( const _Segment& seg,
1797 vector< const _Segment* >& found )
1799 if ( getBox()->IsOut( *seg._uv[0], *seg._uv[1] ))
1804 for ( int i = 0; i < _segments.size(); ++i )
1805 if ( !_segments[i].IsOut( seg ))
1806 found.push_back( _segments[i]._seg );
1810 for (int i = 0; i < nbChildren(); i++)
1811 ((_SegmentTree*) myChildren[i])->GetSegmentsNear( seg, found );
1816 //================================================================================
1818 * \brief Return segments intersecting a ray
1820 //================================================================================
1822 void _SegmentTree::GetSegmentsNear( const gp_Ax2d& ray,
1823 vector< const _Segment* >& found )
1825 if ( getBox()->IsOut( ray ))
1830 for ( int i = 0; i < _segments.size(); ++i )
1831 if ( !_segments[i].IsOut( ray ))
1832 found.push_back( _segments[i]._seg );
1836 for (int i = 0; i < nbChildren(); i++)
1837 ((_SegmentTree*) myChildren[i])->GetSegmentsNear( ray, found );
1841 //================================================================================
1843 * \brief Classify a _Segment
1845 //================================================================================
1847 bool _SegmentTree::_SegBox::IsOut( const _Segment& seg ) const
1849 const double eps = std::numeric_limits<double>::min();
1850 for ( int iC = 0; iC < 2; ++iC )
1852 if ( seg._uv[0]->Coord(iC+1) < _seg->_uv[ _iMin[iC]]->Coord(iC+1)+eps &&
1853 seg._uv[1]->Coord(iC+1) < _seg->_uv[ _iMin[iC]]->Coord(iC+1)+eps )
1855 if ( seg._uv[0]->Coord(iC+1) > _seg->_uv[ 1-_iMin[iC]]->Coord(iC+1)-eps &&
1856 seg._uv[1]->Coord(iC+1) > _seg->_uv[ 1-_iMin[iC]]->Coord(iC+1)-eps )
1862 //================================================================================
1864 * \brief Classify a ray
1866 //================================================================================
1868 bool _SegmentTree::_SegBox::IsOut( const gp_Ax2d& ray ) const
1870 double distBoxCenter2Ray =
1871 ray.Direction().XY() ^ ( ray.Location().XY() - 0.5 * (*_seg->_uv[0] + *_seg->_uv[1]));
1873 double boxSectionDiam =
1874 Abs( ray.Direction().X() ) * ( _seg->_uv[1-_iMin[1]]->Y() - _seg->_uv[_iMin[1]]->Y() ) +
1875 Abs( ray.Direction().Y() ) * ( _seg->_uv[1-_iMin[0]]->X() - _seg->_uv[_iMin[0]]->X() );
1877 return Abs( distBoxCenter2Ray ) > 0.5 * boxSectionDiam;