1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : 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>
46 #include <Geom_Line.hxx>
48 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Vertex.hxx>
52 #include <TopoDS_Wire.hxx>
57 #include "utilities.h"
59 //================================================================================
61 * \brief Constructor of a side of one edge
62 * \param theFace - the face
63 * \param theEdge - the edge
65 //================================================================================
67 StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace,
68 const TopoDS_Edge& theEdge,
70 const bool theIsForward,
71 const bool theIgnoreMediumNodes,
72 SMESH_ProxyMesh::Ptr theProxyMesh)
74 list<TopoDS_Edge> edges(1,theEdge);
75 *this = StdMeshers_FaceSide( theFace, edges, theMesh, theIsForward,
76 theIgnoreMediumNodes, theProxyMesh );
79 //================================================================================
81 * \brief Constructor of a side of several edges
82 * \param theFace - the face
83 * \param theEdge - the edge
85 //================================================================================
87 StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace,
88 list<TopoDS_Edge>& theEdges,
90 const bool theIsForward,
91 const bool theIgnoreMediumNodes,
92 SMESH_ProxyMesh::Ptr theProxyMesh)
94 int nbEdges = theEdges.size();
95 myEdge.resize ( nbEdges );
96 myEdgeID.resize ( nbEdges );
97 myC2d.resize ( nbEdges );
98 myC3dAdaptor.resize( nbEdges );
99 myFirst.resize ( nbEdges );
100 myLast.resize ( nbEdges );
101 myNormPar.resize ( nbEdges );
102 myEdgeLength.resize( nbEdges );
103 myIsUniform.resize ( nbEdges, true );
105 myNbPonits = myNbSegments = 0;
106 myProxyMesh = theProxyMesh;
107 myMissingVertexNodes = false;
108 myIgnoreMediumNodes = theIgnoreMediumNodes;
109 myDefaultPnt2d = gp_Pnt2d( 1e+100, 1e+100 );
110 if ( !myProxyMesh ) myProxyMesh.reset( new SMESH_ProxyMesh( *theMesh ));
111 if ( nbEdges == 0 ) return;
113 SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS();
116 list<TopoDS_Edge>::iterator edge = theEdges.begin();
117 TopoDS_Iterator vExp;
118 for ( int index = 0; edge != theEdges.end(); ++index, ++edge )
120 int i = theIsForward ? index : nbEdges-index-1;
121 myEdgeLength[i] = SMESH_Algo::EdgeLength( *edge );
122 if ( myEdgeLength[i] < DBL_MIN ) nbDegen++;
123 myLength += myEdgeLength[i];
125 myEdgeID[i] = meshDS->ShapeToIndex( *edge );
126 if ( !theIsForward ) myEdge[i].Reverse();
128 if ( theFace.IsNull() )
129 BRep_Tool::Range( *edge, myFirst[i], myLast[i] );
131 myC2d[i] = BRep_Tool::CurveOnSurface( *edge, theFace, myFirst[i], myLast[i] );
132 if ( myEdge[i].Orientation() == TopAbs_REVERSED )
133 std::swap( myFirst[i], myLast[i] );
135 if ( const SMESHDS_SubMesh* sm = myProxyMesh->GetSubMesh( *edge )) {
136 int nbN = sm->NbNodes();
137 if ( theIgnoreMediumNodes ) {
138 SMDS_ElemIteratorPtr elemIt = sm->GetElements();
139 if ( elemIt->more() && elemIt->next()->IsQuadratic() )
140 nbN -= sm->NbElements();
143 myNbSegments += sm->NbElements();
146 // TopExp::FirstVertex() and TopExp::LastVertex() return NULL from INTERNAL edge
147 vExp.Initialize( *edge );
148 if ( vExp.Value().Orientation() == TopAbs_REVERSED ) vExp.Next();
149 if ( SMESH_Algo::VertexNode( TopoDS::Vertex( vExp.Value()), meshDS ))
150 myNbPonits += 1; // for the first end
152 myMissingVertexNodes = true;
154 // check if the edge has a non-uniform parametrization (issue 0020705)
155 if ( !myC2d[i].IsNull() )
157 if ( myEdgeLength[i] > DBL_MIN)
159 Geom2dAdaptor_Curve A2dC( myC2d[i],
160 std::min( myFirst[i], myLast[i] ),
161 std::max( myFirst[i], myLast[i] ));
162 double p2 = myFirst[i]+(myLast[i]-myFirst[i])/2., p4 = myFirst[i]+(myLast[i]-myFirst[i])/4.;
163 double d2 = GCPnts_AbscissaPoint::Length( A2dC, myFirst[i], p2 );
164 double d4 = GCPnts_AbscissaPoint::Length( A2dC, myFirst[i], p4 );
165 //cout<<"len = "<<len<<" d2 = "<<d2<<" fabs(2*d2/len-1.0) = "<<fabs(2*d2/len-1.0)<<endl;
166 myIsUniform[i] = !( fabs(2*d2/myEdgeLength[i]-1.0) > 0.01 || fabs(2*d4/d2-1.0) > 0.01 );
167 Handle(Geom_Curve) C3d = BRep_Tool::Curve(myEdge[i],d2,d4);
168 myC3dAdaptor[i].Load( C3d, d2,d4 );
172 const TopoDS_Vertex& V = TopoDS::Vertex( vExp.Value() );
173 Handle(Geom_Curve) C3d = new Geom_Line( BRep_Tool::Pnt( V ), gp::DX() );
174 myC3dAdaptor[i].Load( C3d, 0, 0.5 * BRep_Tool::Tolerance( V ));
177 // reverse a proxy submesh
179 reverseProxySubmesh( myEdge[i] );
183 vExp.Initialize( theEdges.back() );
184 if ( vExp.Value().Orientation() != TopAbs_REVERSED ) vExp.Next();
187 if ( SMESH_Algo::VertexNode( TopoDS::Vertex( vExp.Value()), meshDS ))
188 myNbPonits++; // for the last end
190 myMissingVertexNodes = true;
192 if ( nbEdges > 1 && myLength > DBL_MIN ) {
193 const double degenNormLen = 1.e-5;
194 double totLength = myLength;
196 totLength += myLength * degenNormLen * nbDegen;
197 double prevNormPar = 0;
198 for ( int i = 0; i < nbEdges; ++i ) {
199 if ( myEdgeLength[ i ] < DBL_MIN )
200 myEdgeLength[ i ] = myLength * degenNormLen;
201 myNormPar[ i ] = prevNormPar + myEdgeLength[i]/totLength;
202 prevNormPar = myNormPar[ i ];
205 myNormPar[nbEdges-1] = 1.;
209 //================================================================================
211 * \brief Constructor of a side for vertex using data from other FaceSide
212 * \param theVertex - the vertex
213 * \param theSide - the side
215 //================================================================================
217 StdMeshers_FaceSide::StdMeshers_FaceSide(const StdMeshers_FaceSide* theSide,
218 const SMDS_MeshNode* theNode,
219 const gp_Pnt2d* thePnt2d1,
220 const gp_Pnt2d* thePnt2d2,
221 const Handle(Geom2d_Curve)& theC2d,
222 const double theUFirst,
223 const double theULast)
225 myC2d.push_back ( theC2d );
226 myFirst.push_back ( theUFirst );
227 myLast.push_back ( theULast );
228 myNormPar.push_back ( 1. );
229 myIsUniform.push_back( true );
230 myEdgeID.push_back ( 0 );
232 myProxyMesh = theSide->myProxyMesh;
233 myDefaultPnt2d = *thePnt2d1;
234 myPoints = theSide->GetUVPtStruct();
235 myNbPonits = myPoints.size();
236 myNbSegments = theSide->myNbSegments;
238 for ( size_t i = 0; i < myPoints.size(); ++i )
240 double r = i / ( myPoints.size() - 1. );
241 myPoints[i].u = (1-r) * thePnt2d1->X() + r * thePnt2d2->X();
242 myPoints[i].v = (1-r) * thePnt2d1->Y() + r * thePnt2d2->Y();
243 myPoints[i].node = theNode;
246 for ( size_t i = 0; i < myPoints.size(); ++i )
248 myPoints[i].u = thePnt2d1->X();
249 myPoints[i].v = thePnt2d1->Y();
250 myPoints[i].node = theNode;
254 //================================================================================
256 * Create a side from an UVPtStructVec
258 //================================================================================
260 StdMeshers_FaceSide::StdMeshers_FaceSide(UVPtStructVec& theSideNodes,
261 const TopoDS_Face& theFace)
264 myEdgeID.resize( 1, -1 );
266 myC3dAdaptor.resize( 1 );
267 myFirst.resize( 1, 0. );
268 myLast.resize( 1, 1. );
269 myNormPar.resize( 1, 1. );
270 myIsUniform.resize( 1, 1 );
271 myMissingVertexNodes = myIgnoreMediumNodes = false;
272 myDefaultPnt2d.SetCoord( 1e100, 1e100 );
274 myPoints = theSideNodes;
275 myNbPonits = myPoints.size();
276 myNbSegments = myNbPonits + 1;
279 if ( !myPoints.empty() )
281 myPoints[0].normParam = 0;
282 if ( myPoints[0].node &&
283 myPoints.back().node &&
284 myPoints[ myNbPonits/2 ].node )
286 gp_Pnt pPrev = SMESH_TNodeXYZ( myPoints[0].node );
287 for ( size_t i = 1; i < myPoints.size(); ++i )
289 gp_Pnt p = SMESH_TNodeXYZ( myPoints[i].node );
290 myLength += p.Distance( pPrev );
291 myPoints[i].normParam = myLength;
295 else if ( !theFace.IsNull() )
298 Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc );
299 gp_Pnt pPrev = surf->Value( myPoints[0].u, myPoints[0].v );
300 for ( size_t i = 1; i < myPoints.size(); ++i )
302 gp_Pnt p = surf->Value( myPoints[i].u, myPoints[i].v );
303 myLength += p.Distance( pPrev );
304 myPoints[i].normParam = myLength;
310 gp_Pnt2d pPrev = myPoints[0].UV();
311 for ( size_t i = 1; i < myPoints.size(); ++i )
313 gp_Pnt2d p = myPoints[i].UV();
314 myLength += p.Distance( pPrev );
315 myPoints[i].normParam = myLength;
319 if ( myLength > std::numeric_limits<double>::min() )
320 for ( size_t i = 1; i < myPoints.size(); ++i )
321 myPoints[i].normParam /= myLength;
323 myEdgeLength.resize( 1, myLength );
326 //================================================================================
328 * Return info on nodes on the side
330 //================================================================================
332 const vector<UVPtStruct>& StdMeshers_FaceSide::GetUVPtStruct(bool isXConst,
333 double constValue) const
335 if ( myPoints.empty() ) {
337 if ( NbEdges() == 0 ) return myPoints;
339 SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS();
340 SMESH_MesherHelper helper(*myProxyMesh->GetMesh());
344 // sort nodes of all edges putting them into a map
346 map< double, const SMDS_MeshNode*> u2node;
347 vector< const SMESH_ProxyMesh::SubMesh* > proxySubMesh( myEdge.size());
348 int nbProxyNodes = 0;
349 for ( size_t iE = 0; iE < myEdge.size(); ++iE )
351 proxySubMesh[iE] = myProxyMesh->GetProxySubMesh( myEdge[iE] );
352 if ( proxySubMesh[iE] )
354 if ( proxySubMesh[iE]->GetUVPtStructVec().empty() ) {
355 proxySubMesh[iE] = 0;
358 nbProxyNodes += proxySubMesh[iE]->GetUVPtStructVec().size() - 1;
359 if ( iE+1 == myEdge.size() )
364 // Put 1st vertex node of a current edge
365 TopoDS_Vertex VV[2]; // TopExp::FirstVertex() returns NULL for INTERNAL edge
366 VV[0] = SMESH_MesherHelper::IthVertex( 0, myEdge[iE]);
367 VV[1] = SMESH_MesherHelper::IthVertex( 1, myEdge[iE]);
368 const SMDS_MeshNode* node = SMESH_Algo::VertexNode( VV[0], meshDS );
369 double prevNormPar = ( iE == 0 ? 0 : myNormPar[ iE-1 ]); // normalized param
370 if ( node ) { // nodes on internal vertices may be missing
371 u2node.insert( u2node.end(), make_pair( prevNormPar, node ));
373 else if ( iE == 0 ) {
374 MESSAGE(" NO NODE on VERTEX" );
378 // Put internal nodes
379 if ( const SMESHDS_SubMesh* sm = myProxyMesh->GetSubMesh( myEdge[iE] ))
381 vector< pair< double, const SMDS_MeshNode*> > u2nodeVec;
382 u2nodeVec.reserve( sm->NbNodes() );
383 SMDS_NodeIteratorPtr nItr = sm->GetNodes();
384 double paramSize = myLast[iE] - myFirst[iE];
385 double r = myNormPar[iE] - prevNormPar;
386 helper.SetSubShape( myEdge[iE] );
387 helper.ToFixNodeParameters( true );
388 if ( !myIsUniform[iE] )
389 while ( nItr->more() )
391 const SMDS_MeshNode* node = nItr->next();
392 if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge ))
394 double u = helper.GetNodeU( myEdge[iE], node, 0, ¶mOK );
395 double aLenU = GCPnts_AbscissaPoint::Length
396 ( const_cast<GeomAdaptor_Curve&>( myC3dAdaptor[iE]), myFirst[iE], u );
397 if ( myEdgeLength[iE] < aLenU ) // nonregression test "3D_mesh_NETGEN/G6"
402 double normPar = prevNormPar + r*aLenU/myEdgeLength[iE];
403 u2nodeVec.push_back( make_pair( normPar, node ));
405 nItr = sm->GetNodes();
406 if ( u2nodeVec.empty() )
407 while ( nItr->more() )
409 const SMDS_MeshNode* node = nItr->next();
410 if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge ))
412 double u = helper.GetNodeU( myEdge[iE], node, 0, ¶mOK );
414 // paramSize is signed so orientation is taken into account
415 double normPar = prevNormPar + r * ( u - myFirst[iE] ) / paramSize;
416 u2nodeVec.push_back( make_pair( normPar, node ));
418 for ( size_t j = 0; j < u2nodeVec.size(); ++j )
419 u2node.insert( u2node.end(), u2nodeVec[j] );
422 // Put 2nd vertex node for a last edge
423 if ( iE+1 == myEdge.size() ) {
424 node = SMESH_Algo::VertexNode( VV[1], meshDS );
426 MESSAGE(" NO NODE on VERTEX" );
429 u2node.insert( u2node.end(), make_pair( 1., node ));
431 } // loop on myEdge's
433 if ( u2node.size() + nbProxyNodes != myNbPonits &&
434 u2node.size() + nbProxyNodes != NbPoints( /*update=*/true ))
436 MESSAGE("Wrong node parameters on edges, u2node.size():"
437 <<u2node.size()<<" != myNbPonits:"<<myNbPonits);
441 // fill array of UVPtStruct
443 UVPtStructVec& points = const_cast< UVPtStructVec& >( myPoints );
444 points.resize( myNbPonits );
447 double prevNormPar = 0, paramSize = myNormPar[ 0 ];
448 map< double, const SMDS_MeshNode*>::iterator u_node = u2node.begin();
449 for ( size_t iE = 0; iE < myEdge.size(); ++iE )
451 if ( proxySubMesh[ iE ] ) // copy data from a proxy sub-mesh
453 const UVPtStructVec& edgeUVPtStruct = proxySubMesh[iE]->GetUVPtStructVec();
454 std::copy( edgeUVPtStruct.begin(), edgeUVPtStruct.end(), & points[iPt] );
456 double du1 = edgeUVPtStruct.back().param - edgeUVPtStruct[0].param;
457 double du2 = myLast[iE] - myFirst[iE];
460 std::reverse( & points[iPt], & points[iPt + edgeUVPtStruct.size()]);
461 for ( size_t i = 0; i < edgeUVPtStruct.size(); ++i )
462 points[iPt+i].normParam = 1. - points[iPt+i].normParam;
464 // update normalized params
465 if ( myEdge.size() > 1 ) {
466 for ( size_t i = 0; i < edgeUVPtStruct.size(); ++i, ++iPt )
468 UVPtStruct & uvPt = points[iPt];
469 uvPt.normParam = prevNormPar + uvPt.normParam * paramSize;
470 uvPt.x = uvPt.y = uvPt.normParam;
472 --iPt; // to point to the 1st VERTEX of the next EDGE
477 for ( ; u_node != u2node.end(); ++u_node, ++iPt )
479 if ( myNormPar[ iE ]-eps < u_node->first )
480 break; // u_node is at VERTEX of the next EDGE
482 UVPtStruct & uvPt = points[iPt];
483 uvPt.node = u_node->second;
484 // -- normParam, x, y --------------------------------
485 uvPt.normParam = u_node->first;
486 uvPt.x = uvPt.y = uvPt.normParam;
487 // -- U ----------------------------------------------
488 const SMDS_EdgePosition* epos =
489 dynamic_cast<const SMDS_EdgePosition*>(uvPt.node->GetPosition());
491 uvPt.param = epos->GetUParameter();
494 double r = ( uvPt.normParam - prevNormPar )/ paramSize;
495 uvPt.param = ( r > 0.5 ? myLast[iE] : myFirst[iE] );
497 // -- UV ---------------------------------------------
498 if ( !myC2d[ iE ].IsNull() ) {
499 gp_Pnt2d p = myC2d[ iE ]->Value( uvPt.param );
504 uvPt.u = uvPt.v = 1e+100;
508 // prepare for the next EDGE
509 if ( iE+1 < myEdge.size() )
511 prevNormPar = myNormPar[ iE ];
512 paramSize = myNormPar[ iE+1 ] - prevNormPar;
514 } // loop on myEdge's
518 for ( iPt = 0; iPt < points.size(); ++iPt ) points[ iPt ].x = constValue;
520 for ( iPt = 0; iPt < points.size(); ++iPt ) points[ iPt ].y = constValue;
522 } // if ( myPoints.empty())
527 //================================================================================
529 * \brief Falsificate info on nodes
530 * \param nbSeg - nb of segments on the side
531 * \retval UVPtStruct* - array of data structures
533 //================================================================================
535 const vector<UVPtStruct>& StdMeshers_FaceSide::SimulateUVPtStruct(int nbSeg,
537 double constValue) const
539 if ( myFalsePoints.empty() ) {
541 if ( NbEdges() == 0 ) return myFalsePoints;
543 vector<uvPtStruct>* points = const_cast<vector<uvPtStruct>*>( &myFalsePoints );
544 points->resize( nbSeg+1 );
547 double prevNormPar = 0, paramSize = myNormPar[ EdgeIndex ];
548 for (int i = 0 ; i < myFalsePoints.size(); ++i ) {
549 double normPar = double(i) / double(nbSeg);
550 UVPtStruct & uvPt = (*points)[i];
552 uvPt.x = uvPt.y = uvPt.param = uvPt.normParam = normPar;
553 if ( isXConst ) uvPt.x = constValue;
554 else uvPt.y = constValue;
555 if ( myNormPar[ EdgeIndex ] < normPar ) {
556 prevNormPar = myNormPar[ EdgeIndex ];
558 paramSize = myNormPar[ EdgeIndex ] - prevNormPar;
560 double r = ( normPar - prevNormPar )/ paramSize;
561 uvPt.param = myFirst[EdgeIndex] * ( 1 - r ) + myLast[EdgeIndex] * r;
562 if ( !myC2d[ EdgeIndex ].IsNull() ) {
563 gp_Pnt2d p = myC2d[ EdgeIndex ]->Value( uvPt.param );
568 uvPt.u = uvPt.v = 1e+100;
572 return myFalsePoints;
575 //=======================================================================
576 //function : GetOrderedNodes
577 //purpose : Return nodes in the order they encounter while walking along the side
578 //=======================================================================
580 std::vector<const SMDS_MeshNode*> StdMeshers_FaceSide::GetOrderedNodes() const
582 vector<const SMDS_MeshNode*> resultNodes;
583 if ( myPoints.empty() )
585 if ( NbEdges() == 0 ) return resultNodes;
587 SMESHDS_Mesh* meshDS = myProxyMesh->GetMeshDS();
588 SMESH_MesherHelper helper(*myProxyMesh->GetMesh());
591 // Sort nodes of all edges putting them into a map
593 map< double, const SMDS_MeshNode*> u2node;
594 for ( int i = 0; i < myEdge.size(); ++i )
596 // Put 1st vertex node of a current edge
597 TopoDS_Vertex VV[2]; // TopExp::FirstVertex() returns NULL for INTERNAL edge
598 VV[0] = SMESH_MesherHelper::IthVertex( 0, myEdge[i]);
599 VV[1] = SMESH_MesherHelper::IthVertex( 1, myEdge[i]);
600 const SMDS_MeshNode* node = SMESH_Algo::VertexNode( VV[0], meshDS );
601 double prevNormPar = ( i == 0 ? 0 : myNormPar[ i-1 ]); // normalized param
602 if ( node ) { // nodes on internal vertices may be missing
603 u2node.insert( make_pair( prevNormPar, node ));
606 MESSAGE(" NO NODE on VERTEX" );
610 // Put internal nodes
611 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements( myEdge[i] ))
613 SMDS_NodeIteratorPtr nItr = sm->GetNodes();
614 double paramSize = myLast[i] - myFirst[i];
615 double r = myNormPar[i] - prevNormPar;
616 helper.SetSubShape( myEdge[i] );
617 helper.ToFixNodeParameters( true );
618 while ( nItr->more() )
620 const SMDS_MeshNode* node = nItr->next();
621 if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge ))
623 double u = helper.GetNodeU( myEdge[i], node, 0, ¶mOK );
625 // paramSize is signed so orientation is taken into account
626 double normPar = prevNormPar + r * ( u - myFirst[i] ) / paramSize;
627 u2node.insert( u2node.end(), make_pair( normPar, node ));
631 // Put 2nd vertex node for a last edge
632 if ( i+1 == myEdge.size() ) {
633 node = SMESH_Algo::VertexNode( VV[1], meshDS );
637 u2node.insert( u2node.end(), make_pair( 1., node ));
641 // Fill the result vector
643 if ( u2node.size() == myNbPonits )
645 resultNodes.reserve( u2node.size() );
646 map< double, const SMDS_MeshNode*>::iterator u2n = u2node.begin();
647 for ( ; u2n != u2node.end(); ++u2n )
648 resultNodes.push_back( u2n->second );
653 resultNodes.resize( myPoints.size() );
654 for ( size_t i = 0; i < myPoints.size(); ++i )
655 resultNodes[i] = myPoints[i].node;
661 //================================================================================
663 * \brief reverse order of vector elements
664 * \param vec - vector to reverse
666 //================================================================================
668 template <typename T > void reverse(vector<T> & vec)
670 for ( int f=0, r=vec.size()-1; f < r; ++f, --r )
671 std::swap( vec[f], vec[r] );
674 //================================================================================
676 * \brief Change orientation of side geometry
678 //================================================================================
680 void StdMeshers_FaceSide::Reverse()
682 int nbEdges = myEdge.size();
683 for ( int i = nbEdges-1; i >= 0; --i ) {
684 std::swap( myFirst[i], myLast[i] );
685 if ( !myEdge[i].IsNull() )
687 if ( i > 0 ) // at the first loop 1. is overwritten
688 myNormPar[i] = 1 - myNormPar[i-1];
694 //reverse( myC3dAdaptor );
697 reverse( myNormPar );
698 reverse( myEdgeLength );
699 reverse( myIsUniform );
703 myNormPar[nbEdges-1]=1.;
704 if ( !myEdge[0].IsNull() )
706 for ( size_t i = 0; i < myEdge.size(); ++i )
707 reverseProxySubmesh( myEdge[i] );
709 myFalsePoints.clear();
713 for ( size_t i = 0; i < myPoints.size(); ++i )
715 UVPtStruct & uvPt = myPoints[i];
716 uvPt.normParam = 1 - uvPt.normParam;
722 for ( size_t i = 0; i < myFalsePoints.size(); ++i )
724 UVPtStruct & uvPt = myFalsePoints[i];
725 uvPt.normParam = 1 - uvPt.normParam;
729 reverse( myFalsePoints );
732 for ( size_t i = 0; i < myEdge.size(); ++i )
734 if ( myEdge[i].IsNull() ) continue; // for a side on points only
736 Handle(Geom_Curve) C3d = BRep_Tool::Curve(myEdge[i],fp,lp);
738 myC3dAdaptor[i].Load( C3d, fp,lp );
742 //=======================================================================
743 //function : SetIgnoreMediumNodes
744 //purpose : Make ignore medium nodes
745 //=======================================================================
747 void StdMeshers_FaceSide::SetIgnoreMediumNodes(bool toIgnore)
749 if ( myIgnoreMediumNodes != toIgnore )
751 myIgnoreMediumNodes = toIgnore;
753 if ( !myPoints.empty() )
755 UVPtStructVec newPoints;
756 newPoints.reserve( myPoints.size()/2 + 1 );
757 for ( size_t i = 0; i < myPoints.size(); i += 2 )
758 newPoints.push_back( myPoints[i] );
760 myPoints.swap( newPoints );
764 NbPoints( /*update=*/true );
769 //=======================================================================
770 //function : NbPoints
771 //purpose : Return nb nodes on edges and vertices (+1 to be == GetUVPtStruct().size() )
772 // Call it with update == true if mesh of this side can be recomputed
773 // since creation of this side
774 //=======================================================================
776 int StdMeshers_FaceSide::NbPoints(const bool update) const
778 if ( !myPoints.empty() )
779 return myPoints.size();
781 // if ( !myFalsePoints.empty() )
782 // return myFalsePoints.size();
784 if ( update && myEdge.size() > 0 )
786 StdMeshers_FaceSide* me = (StdMeshers_FaceSide*) this;
788 me->myNbSegments = 0;
789 me->myMissingVertexNodes = false;
791 for ( int i = 0; i < NbEdges(); ++i )
793 TopoDS_Vertex v1 = SMESH_MesherHelper::IthVertex( 0, myEdge[i] );
794 if ( SMESH_Algo::VertexNode( v1, myProxyMesh->GetMeshDS() ))
795 me->myNbPonits += 1; // for the first end
797 me->myMissingVertexNodes = true;
799 if ( const SMESHDS_SubMesh* sm = myProxyMesh->GetSubMesh( Edge(i) )) {
800 int nbN = sm->NbNodes();
801 if ( myIgnoreMediumNodes ) {
802 SMDS_ElemIteratorPtr elemIt = sm->GetElements();
803 if ( elemIt->more() && elemIt->next()->IsQuadratic() )
804 nbN -= sm->NbElements();
806 me->myNbPonits += nbN;
807 me->myNbSegments += sm->NbElements();
810 TopoDS_Vertex v1 = SMESH_MesherHelper::IthVertex( 1, Edge( NbEdges()-1 ));
811 if ( SMESH_Algo::VertexNode( v1, myProxyMesh->GetMeshDS() ))
812 me->myNbPonits++; // for the last end
814 me->myMissingVertexNodes = true;
819 //=======================================================================
820 //function : NbSegments
821 //purpose : Return nb edges
822 // Call it with update == true if mesh of this side can be recomputed
823 // since creation of this side
824 //=======================================================================
826 int StdMeshers_FaceSide::NbSegments(const bool update) const
828 return NbPoints( update ), myNbSegments;
831 //================================================================================
833 * \brief Reverse UVPtStructVec if a proxy sub-mesh of E
835 //================================================================================
837 void StdMeshers_FaceSide::reverseProxySubmesh( const TopoDS_Edge& E )
839 if ( !myProxyMesh ) return;
840 if ( const SMESH_ProxyMesh::SubMesh* sm = myProxyMesh->GetProxySubMesh( E ))
842 UVPtStructVec& edgeUVPtStruct = (UVPtStructVec& ) sm->GetUVPtStructVec();
843 for ( size_t i = 0; i < edgeUVPtStruct.size(); ++i )
845 UVPtStruct & uvPt = edgeUVPtStruct[i];
846 uvPt.normParam = 1 - uvPt.normParam;
850 reverse( edgeUVPtStruct );
854 //================================================================================
856 * \brief Show side features
858 //================================================================================
860 void StdMeshers_FaceSide::dump(const char* msg) const
863 if (msg) MESSAGE ( std::endl << msg );
864 MESSAGE_BEGIN ("NB EDGES: "<< myEdge.size() );
865 MESSAGE_ADD ( "nbPoints: "<<myNbPonits<<" vecSize: " << myPoints.size()<<" "<<myFalsePoints.size() );
866 for ( int i=0; i<myEdge.size(); ++i)
868 MESSAGE_ADD ( "\t"<<i+1 );
869 MESSAGE_ADD ( "\tEDGE: " );
870 if (myEdge[i].IsNull()) {
871 MESSAGE_ADD ( "NULL" );
874 TopAbs::Print(myEdge[i].Orientation(),cout)<<" "<<myEdge[i].TShape().operator->()<<endl;
875 MESSAGE_ADD ( "\tV1: " << TopExp::FirstVertex( myEdge[i], 1).TShape().operator->()
876 << " V2: " << TopExp::LastVertex( myEdge[i], 1).TShape().operator->() );
878 MESSAGE_ADD ( "\tC2d: ");
880 if (myC2d[i].IsNull()) {
881 MESSAGE_ADD ( "NULL" );
884 MESSAGE_ADD ( myC2d[i].operator->() );
887 MESSAGE_ADD ( "\tF: "<<myFirst[i]<< " L: "<< myLast[i] );
888 MESSAGE_END ( "\tnormPar: "<<myNormPar[i]<<endl );
893 //================================================================================
895 * \brief Creates a Adaptor2d_Curve2d to be used in SMESH_Block
896 * \retval Adaptor2d_Curve2d* -
898 //================================================================================
900 struct Adaptor2dCurve2d : public Adaptor2d_Curve2d
902 const StdMeshers_FaceSide* mySide;
903 Adaptor2dCurve2d(const StdMeshers_FaceSide* faceSide):mySide(faceSide) {}
904 gp_Pnt2d Value(const Standard_Real U) const { return mySide->Value2d( U ); }
905 Standard_Real FirstParameter() const { return 0; }
906 Standard_Real LastParameter() const { return 1; }
909 Adaptor2d_Curve2d* StdMeshers_FaceSide::GetCurve2d() const
911 return new Adaptor2dCurve2d( this );
914 //================================================================================
916 * \brief Creates a fully functional Adaptor_Curve
918 //================================================================================
920 BRepAdaptor_CompCurve* StdMeshers_FaceSide::GetCurve3d() const
922 if ( myEdge.empty() )
926 BRep_Builder aBuilder;
927 aBuilder.MakeWire(aWire);
928 for ( int i=0; i<myEdge.size(); ++i )
929 aBuilder.Add( aWire, myEdge[i] );
931 if ( myEdge.size() == 2 && FirstVertex().IsSame( LastVertex() ))
932 aWire.Closed(true); // issue 0021141
934 return new BRepAdaptor_CompCurve( aWire );
937 //================================================================================
939 * \brief Return 2D point by normalized parameter
940 * \param U - normalized parameter value
941 * \retval gp_Pnt2d - point
943 //================================================================================
945 gp_Pnt2d StdMeshers_FaceSide::Value2d(double U) const
947 if ( !myC2d[0].IsNull() ) {
948 int i = EdgeIndex( U );
949 double prevU = i ? myNormPar[ i-1 ] : 0;
950 double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
952 double par = myFirst[i] * ( 1 - r ) + myLast[i] * r;
954 // check parametrization of curve
955 if( !myIsUniform[i] )
957 double aLen3dU = r * myEdgeLength[i] * ( myFirst[i]>myLast[i] ? -1. : 1.);
958 GCPnts_AbscissaPoint AbPnt
959 ( const_cast<GeomAdaptor_Curve&>( myC3dAdaptor[i]), aLen3dU, myFirst[i] );
960 if( AbPnt.IsDone() ) {
961 par = AbPnt.Parameter();
964 return myC2d[ i ]->Value(par);
967 else if ( !myPoints.empty() )
969 int i = U * double( myPoints.size()-1 );
970 while ( i > 0 && myPoints[ i ].normParam > U )
972 while ( i+1 < myPoints.size() && myPoints[ i+1 ].normParam < U )
974 double r = (( U - myPoints[ i ].normParam ) /
975 ( myPoints[ i+1 ].normParam - myPoints[ i ].normParam ));
976 return ( myPoints[ i ].UV() * ( 1 - r ) +
977 myPoints[ i+1 ].UV() * r );
979 return myDefaultPnt2d;
982 //================================================================================
984 * \brief Return XYZ by normalized parameter
985 * \param U - normalized parameter value
986 * \retval gp_Pnt - point
988 //================================================================================
990 gp_Pnt StdMeshers_FaceSide::Value3d(double U) const
992 int i = EdgeIndex( U );
993 double prevU = i ? myNormPar[ i-1 ] : 0;
994 double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
996 double par = myFirst[i] * ( 1 - r ) + myLast[i] * r;
998 // check parametrization of curve
999 if( !myIsUniform[i] )
1001 double aLen3dU = r * myEdgeLength[i] * ( myFirst[i]>myLast[i] ? -1. : 1.);
1002 GCPnts_AbscissaPoint AbPnt
1003 ( const_cast<GeomAdaptor_Curve&>( myC3dAdaptor[i]), aLen3dU, myFirst[i] );
1004 if( AbPnt.IsDone() ) {
1005 par = AbPnt.Parameter();
1008 return myC3dAdaptor[ i ].Value(par);
1011 //================================================================================
1013 * \brief Return wires of a face as StdMeshers_FaceSide's
1015 //================================================================================
1017 TSideVector StdMeshers_FaceSide::GetFaceWires(const TopoDS_Face& theFace,
1018 SMESH_Mesh & theMesh,
1019 const bool theIgnoreMediumNodes,
1021 SMESH_ProxyMesh::Ptr theProxyMesh,
1022 const bool theCheckVertexNodes)
1024 list< TopoDS_Edge > edges, internalEdges;
1025 list< int > nbEdgesInWires;
1026 int nbWires = SMESH_Block::GetOrderedEdges (theFace, edges, nbEdgesInWires);
1028 // split list of all edges into separate wires
1029 TSideVector wires( nbWires );
1030 list< int >::iterator nbE = nbEdgesInWires.begin();
1031 list< TopoDS_Edge >::iterator from = edges.begin(), to = from;
1032 for ( int iW = 0; iW < nbWires; ++iW, ++nbE )
1034 std::advance( to, *nbE );
1035 if ( *nbE == 0 ) // Issue 0020676
1039 wires.resize( nbWires );
1042 list< TopoDS_Edge > wireEdges( from, to );
1043 // assure that there is a node on the first vertex
1044 // as StdMeshers_FaceSide::GetUVPtStruct() requires
1045 if ( wireEdges.front().Orientation() != TopAbs_INTERNAL ) // Issue 0020676
1047 if ( theCheckVertexNodes )
1048 while ( !SMESH_Algo::VertexNode( TopExp::FirstVertex( wireEdges.front(), true),
1049 theMesh.GetMeshDS()))
1051 wireEdges.splice(wireEdges.end(), wireEdges,
1052 wireEdges.begin(), ++wireEdges.begin());
1053 if ( from->IsSame( wireEdges.front() )) {
1055 ( new SMESH_ComputeError(COMPERR_BAD_INPUT_MESH,"No nodes on vertices"));
1056 return TSideVector(0);
1060 else if ( *nbE > 1 ) // Issue 0020676 (Face_pb_netgen.brep) - several internal edges in a wire
1062 internalEdges.splice( internalEdges.end(), wireEdges, ++wireEdges.begin(), wireEdges.end());
1065 StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( theFace, wireEdges, &theMesh,
1066 /*isForward=*/true, theIgnoreMediumNodes,
1068 wires[ iW ] = StdMeshers_FaceSidePtr( wire );
1071 while ( !internalEdges.empty() )
1073 StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( theFace, internalEdges.back(), &theMesh,
1074 /*isForward=*/true, theIgnoreMediumNodes,
1076 wires.push_back( StdMeshers_FaceSidePtr( wire ));
1077 internalEdges.pop_back();
1082 //================================================================================
1084 * \brief Return 1st vertex of the i-the edge
1086 //================================================================================
1088 TopoDS_Vertex StdMeshers_FaceSide::FirstVertex(int i) const
1091 if ( i < NbEdges() )
1093 v = myEdge[i].Orientation() <= TopAbs_REVERSED ? // FORWARD || REVERSED
1094 TopExp::FirstVertex( myEdge[i], 1 ) :
1095 TopoDS::Vertex( TopoDS_Iterator( myEdge[i] ).Value() );
1100 //================================================================================
1102 * \brief Return last vertex of the i-the edge
1104 //================================================================================
1106 TopoDS_Vertex StdMeshers_FaceSide::LastVertex(int i) const
1109 if ( i < NbEdges() )
1111 const TopoDS_Edge& edge = i<0 ? myEdge[ NbEdges() + i ] : myEdge[i];
1112 if ( edge.Orientation() <= TopAbs_REVERSED ) // FORWARD || REVERSED
1113 v = TopExp::LastVertex( edge, 1 );
1115 for ( TopoDS_Iterator vIt( edge ); vIt.More(); vIt.Next() )
1116 v = TopoDS::Vertex( vIt.Value() );