1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshers_FaceSide.hxx
24 // Created : Wed Jan 31 18:41:25 2007
25 // Author : Edward AGAPOV (eap)
28 #include "StdMeshers_FaceSide.hxx"
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_MeshNode.hxx"
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMESHDS_SubMesh.hxx"
34 #include "SMESH_Algo.hxx"
35 #include "SMESH_Mesh.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "SMESH_ComputeError.hxx"
38 #include "SMESH_Block.hxx"
40 #include <Adaptor2d_Curve2d.hxx>
41 #include <BRepAdaptor_CompCurve.hxx>
42 #include <BRep_Builder.hxx>
43 #include <BRep_Tool.hxx>
44 #include <GCPnts_AbscissaPoint.hxx>
45 #include <Geom2dAdaptor_Curve.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <TopoDS_Vertex.hxx>
51 #include <TopoDS_Wire.hxx>
55 #include "utilities.h"
57 //================================================================================
59 * \brief Constructor of a side of one edge
60 * \param theFace - the face
61 * \param theEdge - the edge
63 //================================================================================
65 StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace,
66 const TopoDS_Edge& theEdge,
68 const bool theIsForward,
69 const bool theIgnoreMediumNodes,
70 SMESH_ProxyMesh::Ptr theProxyMesh)
72 list<TopoDS_Edge> edges(1,theEdge);
73 *this = StdMeshers_FaceSide( theFace, edges, theMesh, theIsForward,
74 theIgnoreMediumNodes, theProxyMesh );
77 //================================================================================
79 * \brief Constructor of a side of several edges
80 * \param theFace - the face
81 * \param theEdge - the edge
83 //================================================================================
85 StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace,
86 list<TopoDS_Edge>& theEdges,
88 const bool theIsForward,
89 const bool theIgnoreMediumNodes,
90 SMESH_ProxyMesh::Ptr theProxyMesh)
92 int nbEdges = theEdges.size();
93 myEdge.resize ( nbEdges );
94 myEdgeID.resize ( nbEdges );
95 myC2d.resize ( nbEdges );
96 myC3dAdaptor.resize( nbEdges );
97 myFirst.resize ( nbEdges );
98 myLast.resize ( nbEdges );
99 myNormPar.resize ( nbEdges );
100 myEdgeLength.resize( nbEdges );
101 myIsUniform.resize ( nbEdges, true );
103 myNbPonits = myNbSegments = 0;
104 myProxyMesh = theProxyMesh;
105 myMissingVertexNodes = false;
106 myIgnoreMediumNodes = theIgnoreMediumNodes;
107 myDefaultPnt2d = gp_Pnt2d( 1e+100, 1e+100 );
108 if ( !myProxyMesh ) myProxyMesh.reset( new SMESH_ProxyMesh( *theMesh ));
109 if ( nbEdges == 0 ) return;
111 SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS();
114 list<TopoDS_Edge>::iterator edge = theEdges.begin();
115 TopoDS_Iterator vExp;
116 for ( int index = 0; edge != theEdges.end(); ++index, ++edge )
118 int i = theIsForward ? index : nbEdges-index-1;
119 myEdgeLength[i] = SMESH_Algo::EdgeLength( *edge );
120 if ( myEdgeLength[i] < DBL_MIN ) nbDegen++;
121 myLength += myEdgeLength[i];
123 myEdgeID[i] = meshDS->ShapeToIndex( *edge );
124 if ( !theIsForward ) myEdge[i].Reverse();
126 if ( theFace.IsNull() )
127 BRep_Tool::Range( *edge, myFirst[i], myLast[i] );
129 myC2d[i] = BRep_Tool::CurveOnSurface( *edge, theFace, myFirst[i], myLast[i] );
130 if ( myEdge[i].Orientation() == TopAbs_REVERSED )
131 std::swap( myFirst[i], myLast[i] );
133 if ( const SMESHDS_SubMesh* sm = myProxyMesh->GetSubMesh( *edge )) {
134 int nbN = sm->NbNodes();
135 if ( theIgnoreMediumNodes ) {
136 SMDS_ElemIteratorPtr elemIt = sm->GetElements();
137 if ( elemIt->more() && elemIt->next()->IsQuadratic() )
138 nbN -= sm->NbElements();
141 myNbSegments += sm->NbElements();
144 // TopExp::FirstVertex() and TopExp::LastVertex() return NULL from INTERNAL edge
145 vExp.Initialize( *edge );
146 if ( vExp.Value().Orientation() == TopAbs_REVERSED ) vExp.Next();
147 if ( SMESH_Algo::VertexNode( TopoDS::Vertex( vExp.Value()), meshDS ))
148 myNbPonits += 1; // for the first end
150 myMissingVertexNodes = true;
152 // check if the edge has a non-uniform parametrization (issue 0020705)
153 if ( !myC2d[i].IsNull() && myEdgeLength[i] > DBL_MIN)
155 Geom2dAdaptor_Curve A2dC( myC2d[i],
156 std::min( myFirst[i], myLast[i] ),
157 std::max( myFirst[i], myLast[i] ));
158 double p2 = myFirst[i]+(myLast[i]-myFirst[i])/2., p4 = myFirst[i]+(myLast[i]-myFirst[i])/4.;
159 double d2 = GCPnts_AbscissaPoint::Length( A2dC, myFirst[i], p2 );
160 double d4 = GCPnts_AbscissaPoint::Length( A2dC, myFirst[i], p4 );
161 //cout<<"len = "<<len<<" d2 = "<<d2<<" fabs(2*d2/len-1.0) = "<<fabs(2*d2/len-1.0)<<endl;
162 myIsUniform[i] = !( fabs(2*d2/myEdgeLength[i]-1.0) > 0.01 || fabs(2*d4/d2-1.0) > 0.01 );
163 //if ( !myIsUniform[i] ) to implement Value3d(u)
166 Handle(Geom_Curve) C3d = BRep_Tool::Curve(myEdge[i],fp,lp);
167 myC3dAdaptor[i].Load( C3d, fp,lp );
170 // reverse a proxy submesh
172 reverseProxySubmesh( myEdge[i] );
176 vExp.Initialize( theEdges.back() );
177 if ( vExp.Value().Orientation() != TopAbs_REVERSED ) vExp.Next();
180 if ( SMESH_Algo::VertexNode( TopoDS::Vertex( vExp.Value()), meshDS ))
181 myNbPonits++; // for the last end
183 myMissingVertexNodes = true;
185 if ( nbEdges > 1 && myLength > DBL_MIN ) {
186 const double degenNormLen = 1.e-5;
187 double totLength = myLength;
189 totLength += myLength * degenNormLen * nbDegen;
190 double prevNormPar = 0;
191 for ( int i = 0; i < nbEdges; ++i ) {
192 if ( myEdgeLength[ i ] < DBL_MIN )
193 myEdgeLength[ i ] = myLength * degenNormLen;
194 myNormPar[ i ] = prevNormPar + myEdgeLength[i]/totLength;
195 prevNormPar = myNormPar[ i ];
198 myNormPar[nbEdges-1] = 1.;
202 //================================================================================
204 * \brief Constructor of a side for vertex using data from other FaceSide
205 * \param theVertex - the vertex
206 * \param theSide - the side
208 //================================================================================
210 StdMeshers_FaceSide::StdMeshers_FaceSide(const SMDS_MeshNode* theNode,
211 const gp_Pnt2d thePnt2d,
212 const StdMeshers_FaceSide* theSide)
216 myProxyMesh = theSide->myProxyMesh;
217 myDefaultPnt2d = thePnt2d;
219 myPoints = theSide->GetUVPtStruct();
220 myNbPonits = myPoints.size();
221 myNbSegments = theSide->myNbSegments;
222 std::vector<uvPtStruct>::iterator it = myPoints.begin();
223 for(; it!=myPoints.end(); it++) {
224 (*it).u = thePnt2d.X();
225 (*it).v = thePnt2d.Y();
227 (*it).node = theNode;
231 //================================================================================
233 * \brief Return info on nodes on the side
234 * \retval UVPtStruct* - array of data structures
236 //================================================================================
238 const vector<UVPtStruct>& StdMeshers_FaceSide::GetUVPtStruct(bool isXConst,
239 double constValue) const
241 if ( myPoints.empty() ) {
243 if ( NbEdges() == 0 ) return myPoints;
245 SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS();
246 SMESH_MesherHelper helper(*myProxyMesh->GetMesh());
250 // sort nodes of all edges putting them into a map
252 map< double, const SMDS_MeshNode*> u2node;
253 vector< const SMESH_ProxyMesh::SubMesh* > proxySubMesh( myEdge.size());
254 int nbProxyNodes = 0;
255 for ( size_t iE = 0; iE < myEdge.size(); ++iE )
257 proxySubMesh[iE] = myProxyMesh->GetProxySubMesh( myEdge[iE] );
258 if ( proxySubMesh[iE] )
260 if ( proxySubMesh[iE]->GetUVPtStructVec().empty() ) {
261 proxySubMesh[iE] = 0;
264 nbProxyNodes += proxySubMesh[iE]->GetUVPtStructVec().size() - 1;
265 if ( iE+1 == myEdge.size() )
270 // Put 1st vertex node of a current edge
271 TopoDS_Vertex VV[2]; // TopExp::FirstVertex() returns NULL for INTERNAL edge
272 VV[0] = SMESH_MesherHelper::IthVertex( 0, myEdge[iE]);
273 VV[1] = SMESH_MesherHelper::IthVertex( 1, myEdge[iE]);
274 const SMDS_MeshNode* node = SMESH_Algo::VertexNode( VV[0], meshDS );
275 double prevNormPar = ( iE == 0 ? 0 : myNormPar[ iE-1 ]); // normalized param
276 if ( node ) { // nodes on internal vertices may be missing
277 u2node.insert( u2node.end(), make_pair( prevNormPar, node ));
279 else if ( iE == 0 ) {
280 MESSAGE(" NO NODE on VERTEX" );
284 // Put internal nodes
285 if ( const SMESHDS_SubMesh* sm = myProxyMesh->GetSubMesh( myEdge[iE] ))
287 vector< pair< double, const SMDS_MeshNode*> > u2nodeVec;
288 u2nodeVec.reserve( sm->NbNodes() );
289 SMDS_NodeIteratorPtr nItr = sm->GetNodes();
290 double paramSize = myLast[iE] - myFirst[iE];
291 double r = myNormPar[iE] - prevNormPar;
292 helper.SetSubShape( myEdge[iE] );
293 helper.ToFixNodeParameters( true );
294 if ( !myIsUniform[iE] )
295 while ( nItr->more() )
297 const SMDS_MeshNode* node = nItr->next();
298 if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge ))
300 double u = helper.GetNodeU( myEdge[iE], node, 0, ¶mOK );
301 double aLenU = GCPnts_AbscissaPoint::Length
302 ( const_cast<GeomAdaptor_Curve&>( myC3dAdaptor[iE]), myFirst[iE], u );
303 if ( myEdgeLength[iE] < aLenU ) // nonregression test "3D_mesh_NETGEN/G6"
308 double normPar = prevNormPar + r*aLenU/myEdgeLength[iE];
309 u2nodeVec.push_back( make_pair( normPar, node ));
311 nItr = sm->GetNodes();
312 if ( u2nodeVec.empty() )
313 while ( nItr->more() )
315 const SMDS_MeshNode* node = nItr->next();
316 if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge ))
318 double u = helper.GetNodeU( myEdge[iE], node, 0, ¶mOK );
320 // paramSize is signed so orientation is taken into account
321 double normPar = prevNormPar + r * ( u - myFirst[iE] ) / paramSize;
322 u2nodeVec.push_back( make_pair( normPar, node ));
324 for ( size_t j = 0; j < u2nodeVec.size(); ++j )
325 u2node.insert( u2node.end(), u2nodeVec[j] );
328 // Put 2nd vertex node for a last edge
329 if ( iE+1 == myEdge.size() ) {
330 node = SMESH_Algo::VertexNode( VV[1], meshDS );
332 MESSAGE(" NO NODE on VERTEX" );
335 u2node.insert( u2node.end(), make_pair( 1., node ));
337 } // loop on myEdge's
339 if ( u2node.size() + nbProxyNodes != myNbPonits &&
340 u2node.size() + nbProxyNodes != NbPoints( /*update=*/true ))
342 MESSAGE("Wrong node parameters on edges, u2node.size():"
343 <<u2node.size()<<" != myNbPonits:"<<myNbPonits);
347 // fill array of UVPtStruct
349 UVPtStructVec& points = const_cast< UVPtStructVec& >( myPoints );
350 points.resize( myNbPonits );
353 double prevNormPar = 0, paramSize = myNormPar[ 0 ];
354 map< double, const SMDS_MeshNode*>::iterator u_node = u2node.begin();
355 for ( size_t iE = 0; iE < myEdge.size(); ++iE )
357 if ( proxySubMesh[ iE ] ) // copy data from a proxy sub-mesh
359 const UVPtStructVec& edgeUVPtStruct = proxySubMesh[iE]->GetUVPtStructVec();
360 std::copy( edgeUVPtStruct.begin(), edgeUVPtStruct.end(), & points[iPt] );
362 double du1 = edgeUVPtStruct.back().param - edgeUVPtStruct[0].param;
363 double du2 = myLast[iE] - myFirst[iE];
365 std::reverse( & points[iPt], & points[iPt + edgeUVPtStruct.size()]);
366 // update normalized params
367 if ( myEdge.size() > 1 ) {
368 for ( size_t i = 0; i < edgeUVPtStruct.size(); ++i, ++iPt )
370 UVPtStruct & uvPt = points[iPt];
371 uvPt.normParam = prevNormPar + uvPt.normParam * paramSize;
372 uvPt.x = uvPt.y = uvPt.normParam;
374 --iPt; // to point to the 1st VERTEX of the next EDGE
379 for ( ; u_node != u2node.end(); ++u_node, ++iPt )
381 if ( myNormPar[ iE ]-eps < u_node->first )
382 break; // u_node is at VERTEX of the next EDGE
384 UVPtStruct & uvPt = points[iPt];
385 uvPt.node = u_node->second;
386 // -- normParam, x, y --------------------------------
387 uvPt.normParam = u_node->first;
388 uvPt.x = uvPt.y = uvPt.normParam;
389 // -- U ----------------------------------------------
390 const SMDS_EdgePosition* epos =
391 dynamic_cast<const SMDS_EdgePosition*>(uvPt.node->GetPosition());
393 uvPt.param = epos->GetUParameter();
396 double r = ( uvPt.normParam - prevNormPar )/ paramSize;
397 uvPt.param = ( r > 0.5 ? myLast[iE] : myFirst[iE] );
399 // -- UV ---------------------------------------------
400 if ( !myC2d[ iE ].IsNull() ) {
401 gp_Pnt2d p = myC2d[ iE ]->Value( uvPt.param );
406 uvPt.u = uvPt.v = 1e+100;
410 // prepare for the next EDGE
411 if ( iE+1 < myEdge.size() )
413 prevNormPar = myNormPar[ iE ];
414 paramSize = myNormPar[ iE+1 ] - prevNormPar;
416 } // loop on myEdge's
420 for ( iPt = 0; iPt < points.size(); ++iPt ) points[ iPt ].x = constValue;
422 for ( iPt = 0; iPt < points.size(); ++iPt ) points[ iPt ].y = constValue;
424 } // if ( myPoints.empty())
429 //================================================================================
431 * \brief Falsificate info on nodes
432 * \param nbSeg - nb of segments on the side
433 * \retval UVPtStruct* - array of data structures
435 //================================================================================
437 const vector<UVPtStruct>& StdMeshers_FaceSide::SimulateUVPtStruct(int nbSeg,
439 double constValue) const
441 if ( myFalsePoints.empty() ) {
443 if ( NbEdges() == 0 ) return myFalsePoints;
445 vector<uvPtStruct>* points = const_cast<vector<uvPtStruct>*>( &myFalsePoints );
446 points->resize( nbSeg+1 );
449 double prevNormPar = 0, paramSize = myNormPar[ EdgeIndex ];
450 for (int i = 0 ; i < myFalsePoints.size(); ++i ) {
451 double normPar = double(i) / double(nbSeg);
452 UVPtStruct & uvPt = (*points)[i];
454 uvPt.x = uvPt.y = uvPt.param = uvPt.normParam = normPar;
455 if ( isXConst ) uvPt.x = constValue;
456 else uvPt.y = constValue;
457 if ( myNormPar[ EdgeIndex ] < normPar ) {
458 prevNormPar = myNormPar[ EdgeIndex ];
460 paramSize = myNormPar[ EdgeIndex ] - prevNormPar;
462 double r = ( normPar - prevNormPar )/ paramSize;
463 uvPt.param = myFirst[EdgeIndex] * ( 1 - r ) + myLast[EdgeIndex] * r;
464 if ( !myC2d[ EdgeIndex ].IsNull() ) {
465 gp_Pnt2d p = myC2d[ EdgeIndex ]->Value( uvPt.param );
470 uvPt.u = uvPt.v = 1e+100;
474 return myFalsePoints;
477 //=======================================================================
478 //function : GetOrderedNodes
479 //purpose : Return nodes in the order they encounter while walking along the side
480 //=======================================================================
482 std::vector<const SMDS_MeshNode*> StdMeshers_FaceSide::GetOrderedNodes() const
484 vector<const SMDS_MeshNode*> resultNodes;
485 if ( myPoints.empty() )
487 if ( NbEdges() == 0 ) return resultNodes;
489 SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS();
490 SMESH_MesherHelper helper(*myProxyMesh->GetMesh());
493 // Sort nodes of all edges putting them into a map
495 map< double, const SMDS_MeshNode*> u2node;
496 for ( int i = 0; i < myEdge.size(); ++i )
498 // Put 1st vertex node of a current edge
499 TopoDS_Vertex VV[2]; // TopExp::FirstVertex() returns NULL for INTERNAL edge
500 VV[0] = SMESH_MesherHelper::IthVertex( 0, myEdge[i]);
501 VV[1] = SMESH_MesherHelper::IthVertex( 1, myEdge[i]);
502 const SMDS_MeshNode* node = SMESH_Algo::VertexNode( VV[0], meshDS );
503 double prevNormPar = ( i == 0 ? 0 : myNormPar[ i-1 ]); // normalized param
504 if ( node ) { // nodes on internal vertices may be missing
505 u2node.insert( make_pair( prevNormPar, node ));
508 MESSAGE(" NO NODE on VERTEX" );
512 // Put internal nodes
513 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements( myEdge[i] ))
515 SMDS_NodeIteratorPtr nItr = sm->GetNodes();
516 double paramSize = myLast[i] - myFirst[i];
517 double r = myNormPar[i] - prevNormPar;
518 helper.SetSubShape( myEdge[i] );
519 helper.ToFixNodeParameters( true );
520 while ( nItr->more() )
522 const SMDS_MeshNode* node = nItr->next();
523 if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge ))
525 double u = helper.GetNodeU( myEdge[i], node, 0, ¶mOK );
527 // paramSize is signed so orientation is taken into account
528 double normPar = prevNormPar + r * ( u - myFirst[i] ) / paramSize;
529 u2node.insert( u2node.end(), make_pair( normPar, node ));
533 // Put 2nd vertex node for a last edge
534 if ( i+1 == myEdge.size() ) {
535 node = SMESH_Algo::VertexNode( VV[1], meshDS );
539 u2node.insert( u2node.end(), make_pair( 1., node ));
543 // Fill the result vector
545 if ( u2node.size() == myNbPonits )
547 resultNodes.reserve( u2node.size() );
548 map< double, const SMDS_MeshNode*>::iterator u2n = u2node.begin();
549 for ( ; u2n != u2node.end(); ++u2n )
550 resultNodes.push_back( u2n->second );
555 resultNodes.resize( myPoints.size() );
556 for ( size_t i = 0; i < myPoints.size(); ++i )
557 resultNodes[i] = myPoints[i].node;
563 //================================================================================
565 * \brief reverse order of vector elements
566 * \param vec - vector to reverse
568 //================================================================================
570 template <typename T > void reverse(vector<T> & vec)
572 for ( int f=0, r=vec.size()-1; f < r; ++f, --r )
573 std::swap( vec[f], vec[r] );
576 //================================================================================
578 * \brief Change orientation of side geometry
580 //================================================================================
582 void StdMeshers_FaceSide::Reverse()
584 int nbEdges = myEdge.size();
585 for ( int i = nbEdges-1; i >= 0; --i ) {
586 std::swap( myFirst[i], myLast[i] );
588 if ( i > 0 ) // at the first loop 1. is overwritten
589 myNormPar[i] = 1 - myNormPar[i-1];
595 //reverse( myC3dAdaptor );
598 reverse( myNormPar );
599 reverse( myEdgeLength );
600 reverse( myIsUniform );
604 myNormPar[nbEdges-1]=1.;
606 myFalsePoints.clear();
607 for ( size_t i = 0; i < myEdge.size(); ++i )
608 reverseProxySubmesh( myEdge[i] );
610 for ( size_t i = 0; i < myEdge.size(); ++i )
613 Handle(Geom_Curve) C3d = BRep_Tool::Curve(myEdge[i],fp,lp);
615 myC3dAdaptor[i].Load( C3d, fp,lp );
619 //=======================================================================
620 //function : SetIgnoreMediumNodes
621 //purpose : Make ignore medium nodes
622 //=======================================================================
624 void StdMeshers_FaceSide::SetIgnoreMediumNodes(bool toIgnore)
626 if ( myIgnoreMediumNodes != toIgnore )
628 myIgnoreMediumNodes = toIgnore;
630 if ( !myPoints.empty() )
632 UVPtStructVec newPoints;
633 newPoints.reserve( myPoints.size()/2 + 1 );
634 for ( size_t i = 0; i < myPoints.size(); i += 2 )
635 newPoints.push_back( myPoints[i] );
637 myPoints.swap( newPoints );
641 NbPoints( /*update=*/true );
646 //=======================================================================
647 //function : NbPoints
648 //purpose : Return nb nodes on edges and vertices (+1 to be == GetUVPtStruct().size() )
649 // Call it with update == true if mesh of this side can be recomputed
650 // since creation of this side
651 //=======================================================================
653 int StdMeshers_FaceSide::NbPoints(const bool update) const
655 if ( !myPoints.empty() )
656 return myPoints.size();
658 // if ( !myFalsePoints.empty() )
659 // return myFalsePoints.size();
661 if ( update && myEdge.size() > 0 )
663 StdMeshers_FaceSide* me = (StdMeshers_FaceSide*) this;
665 me->myNbSegments = 0;
666 me->myMissingVertexNodes = false;
668 for ( int i = 0; i < NbEdges(); ++i )
670 TopoDS_Vertex v1 = SMESH_MesherHelper::IthVertex( 0, myEdge[i] );
671 if ( SMESH_Algo::VertexNode( v1, myProxyMesh->GetMeshDS() ))
672 me->myNbPonits += 1; // for the first end
674 me->myMissingVertexNodes = true;
676 if ( const SMESHDS_SubMesh* sm = myProxyMesh->GetSubMesh( Edge(i) )) {
677 int nbN = sm->NbNodes();
678 if ( myIgnoreMediumNodes ) {
679 SMDS_ElemIteratorPtr elemIt = sm->GetElements();
680 if ( elemIt->more() && elemIt->next()->IsQuadratic() )
681 nbN -= sm->NbElements();
683 me->myNbPonits += nbN;
684 me->myNbSegments += sm->NbElements();
687 TopoDS_Vertex v1 = SMESH_MesherHelper::IthVertex( 1, Edge( NbEdges()-1 ));
688 if ( SMESH_Algo::VertexNode( v1, myProxyMesh->GetMeshDS() ))
689 me->myNbPonits++; // for the last end
691 me->myMissingVertexNodes = true;
696 //=======================================================================
697 //function : NbSegments
698 //purpose : Return nb edges
699 // Call it with update == true if mesh of this side can be recomputed
700 // since creation of this side
701 //=======================================================================
703 int StdMeshers_FaceSide::NbSegments(const bool update) const
705 return NbPoints( update ), myNbSegments;
708 //================================================================================
710 * \brief Reverse UVPtStructVec if a proxy sub-mesh of E
712 //================================================================================
714 void StdMeshers_FaceSide::reverseProxySubmesh( const TopoDS_Edge& E )
716 if ( !myProxyMesh ) return;
717 if ( const SMESH_ProxyMesh::SubMesh* sm = myProxyMesh->GetProxySubMesh( E ))
719 UVPtStructVec& edgeUVPtStruct = (UVPtStructVec& ) sm->GetUVPtStructVec();
720 for ( size_t i = 0; i < edgeUVPtStruct.size(); ++i )
722 UVPtStruct & uvPt = edgeUVPtStruct[i];
723 uvPt.normParam = 1 - uvPt.normParam;
727 reverse( edgeUVPtStruct );
731 //================================================================================
733 * \brief Show side features
735 //================================================================================
737 void StdMeshers_FaceSide::dump(const char* msg) const
740 if (msg) MESSAGE ( std::endl << msg );
741 MESSAGE_BEGIN ("NB EDGES: "<< myEdge.size() );
742 MESSAGE_ADD ( "nbPoints: "<<myNbPonits<<" vecSize: " << myPoints.size()<<" "<<myFalsePoints.size() );
743 for ( int i=0; i<myEdge.size(); ++i)
745 MESSAGE_ADD ( "\t"<<i+1 );
746 MESSAGE_ADD ( "\tEDGE: " );
747 if (myEdge[i].IsNull()) {
748 MESSAGE_ADD ( "NULL" );
751 TopAbs::Print(myEdge[i].Orientation(),cout)<<" "<<myEdge[i].TShape().operator->()<<endl;
752 MESSAGE_ADD ( "\tV1: " << TopExp::FirstVertex( myEdge[i], 1).TShape().operator->()
753 << " V2: " << TopExp::LastVertex( myEdge[i], 1).TShape().operator->() );
755 MESSAGE_ADD ( "\tC2d: ");
757 if (myC2d[i].IsNull()) {
758 MESSAGE_ADD ( "NULL" );
761 MESSAGE_ADD ( myC2d[i].operator->() );
764 MESSAGE_ADD ( "\tF: "<<myFirst[i]<< " L: "<< myLast[i] );
765 MESSAGE_END ( "\tnormPar: "<<myNormPar[i]<<endl );
770 //================================================================================
772 * \brief Creates a Adaptor2d_Curve2d to be used in SMESH_Block
773 * \retval Adaptor2d_Curve2d* -
775 //================================================================================
777 struct Adaptor2dCurve2d : public Adaptor2d_Curve2d
779 const StdMeshers_FaceSide* mySide;
780 Adaptor2dCurve2d(const StdMeshers_FaceSide* faceSide):mySide(faceSide) {}
781 gp_Pnt2d Value(const Standard_Real U) const { return mySide->Value2d( U ); }
782 Standard_Real FirstParameter() const { return 0; }
783 Standard_Real LastParameter() const { return 1; }
786 Adaptor2d_Curve2d* StdMeshers_FaceSide::GetCurve2d() const
788 return new Adaptor2dCurve2d( this );
791 //================================================================================
793 * \brief Creates a fully functional Adaptor_Curve
795 //================================================================================
797 BRepAdaptor_CompCurve* StdMeshers_FaceSide::GetCurve3d() const
799 if ( myEdge.empty() )
803 BRep_Builder aBuilder;
804 aBuilder.MakeWire(aWire);
805 for ( int i=0; i<myEdge.size(); ++i )
806 aBuilder.Add( aWire, myEdge[i] );
808 if ( myEdge.size() == 2 && FirstVertex().IsSame( LastVertex() ))
809 aWire.Closed(true); // issue 0021141
811 return new BRepAdaptor_CompCurve( aWire );
814 //================================================================================
816 * \brief Return 2D point by normalized parameter
817 * \param U - normalized parameter value
818 * \retval gp_Pnt2d - point
820 //================================================================================
822 gp_Pnt2d StdMeshers_FaceSide::Value2d(double U) const
824 if ( !myC2d[0].IsNull() ) {
825 int i = EdgeIndex( U );
826 double prevU = i ? myNormPar[ i-1 ] : 0;
827 double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
829 double par = myFirst[i] * ( 1 - r ) + myLast[i] * r;
831 // check parametrization of curve
832 if( !myIsUniform[i] )
834 double aLen3dU = r * myEdgeLength[i] * ( myFirst[i]>myLast[i] ? -1. : 1.);
835 GCPnts_AbscissaPoint AbPnt
836 ( const_cast<GeomAdaptor_Curve&>( myC3dAdaptor[i]), aLen3dU, myFirst[i] );
837 if( AbPnt.IsDone() ) {
838 par = AbPnt.Parameter();
841 return myC2d[ i ]->Value(par);
844 return myDefaultPnt2d;
847 //================================================================================
849 * \brief Return XYZ by normalized parameter
850 * \param U - normalized parameter value
851 * \retval gp_Pnt - point
853 //================================================================================
855 gp_Pnt StdMeshers_FaceSide::Value3d(double U) const
857 int i = EdgeIndex( U );
858 double prevU = i ? myNormPar[ i-1 ] : 0;
859 double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
861 double par = myFirst[i] * ( 1 - r ) + myLast[i] * r;
863 // check parametrization of curve
864 if( !myIsUniform[i] )
866 double aLen3dU = r * myEdgeLength[i] * ( myFirst[i]>myLast[i] ? -1. : 1.);
867 GCPnts_AbscissaPoint AbPnt
868 ( const_cast<GeomAdaptor_Curve&>( myC3dAdaptor[i]), aLen3dU, myFirst[i] );
869 if( AbPnt.IsDone() ) {
870 par = AbPnt.Parameter();
873 return myC3dAdaptor[ i ].Value(par);
876 //================================================================================
878 * \brief Return wires of a face as StdMeshers_FaceSide's
880 //================================================================================
882 TSideVector StdMeshers_FaceSide::GetFaceWires(const TopoDS_Face& theFace,
883 SMESH_Mesh & theMesh,
884 const bool theIgnoreMediumNodes,
886 SMESH_ProxyMesh::Ptr theProxyMesh)
888 list< TopoDS_Edge > edges, internalEdges;
889 list< int > nbEdgesInWires;
890 int nbWires = SMESH_Block::GetOrderedEdges (theFace, edges, nbEdgesInWires);
892 // split list of all edges into separate wires
893 TSideVector wires( nbWires );
894 list< int >::iterator nbE = nbEdgesInWires.begin();
895 list< TopoDS_Edge >::iterator from = edges.begin(), to = from;
896 for ( int iW = 0; iW < nbWires; ++iW, ++nbE )
898 std::advance( to, *nbE );
899 if ( *nbE == 0 ) // Issue 0020676
903 wires.resize( nbWires );
906 list< TopoDS_Edge > wireEdges( from, to );
907 // assure that there is a node on the first vertex
908 // as StdMeshers_FaceSide::GetUVPtStruct() requires
909 if ( wireEdges.front().Orientation() != TopAbs_INTERNAL ) // Issue 0020676
911 while ( !SMESH_Algo::VertexNode( TopExp::FirstVertex( wireEdges.front(), true),
912 theMesh.GetMeshDS()))
914 wireEdges.splice(wireEdges.end(), wireEdges,
915 wireEdges.begin(), ++wireEdges.begin());
916 if ( from->IsSame( wireEdges.front() )) {
918 ( new SMESH_ComputeError(COMPERR_BAD_INPUT_MESH,"No nodes on vertices"));
919 return TSideVector(0);
923 else if ( *nbE > 1 ) // Issue 0020676 (Face_pb_netgen.brep) - several internal edges in a wire
925 internalEdges.splice( internalEdges.end(), wireEdges, ++wireEdges.begin(), wireEdges.end());
928 StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( theFace, wireEdges, &theMesh,
929 /*isForward=*/true, theIgnoreMediumNodes,
931 wires[ iW ] = StdMeshers_FaceSidePtr( wire );
934 while ( !internalEdges.empty() )
936 StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( theFace, internalEdges.back(), &theMesh,
937 /*isForward=*/true, theIgnoreMediumNodes,
939 wires.push_back( StdMeshers_FaceSidePtr( wire ));
940 internalEdges.pop_back();
945 //================================================================================
947 * \brief Return 1st vertex of the i-the edge
949 //================================================================================
951 TopoDS_Vertex StdMeshers_FaceSide::FirstVertex(int i) const
956 v = myEdge[i].Orientation() <= TopAbs_REVERSED ? // FORWARD || REVERSED
957 TopExp::FirstVertex( myEdge[i], 1 ) :
958 TopoDS::Vertex( TopoDS_Iterator( myEdge[i] ).Value() );
963 //================================================================================
965 * \brief Return last vertex of the i-the edge
967 //================================================================================
969 TopoDS_Vertex StdMeshers_FaceSide::LastVertex(int i) const
974 const TopoDS_Edge& edge = i<0 ? myEdge[ NbEdges() + i ] : myEdge[i];
975 if ( edge.Orientation() <= TopAbs_REVERSED ) // FORWARD || REVERSED
976 v = TopExp::LastVertex( edge, 1 );
978 for ( TopoDS_Iterator vIt( edge ); vIt.More(); vIt.Next() )
979 v = TopoDS::Vertex( vIt.Value() );