Salome HOME
55ff0aa3b8278e8fa8b8ebe134e94440a2bb94e8
[modules/smesh.git] / src / StdMeshers / StdMeshers_FaceSide.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMESH : implementaion of SMESH idl descriptions
23 // File      : StdMeshers_FaceSide.hxx
24 // Created   : Wed Jan 31 18:41:25 2007
25 // Author    : Edward AGAPOV (eap)
26 // Module    : SMESH
27 //
28 #include "StdMeshers_FaceSide.hxx"
29
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"
39
40 #include <Adaptor2d_Curve2d.hxx>
41 #include <BRepAdaptor_CompCurve.hxx>
42 #include <BRepAdaptor_Curve.hxx>
43 #include <BRep_Builder.hxx>
44 #include <BRep_Tool.hxx>
45 #include <TopExp.hxx>
46 #include <TopExp_Explorer.hxx>
47 #include <TopoDS.hxx>
48 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Vertex.hxx>
50 #include <TopoDS_Wire.hxx>
51
52 #include <map>
53
54 #include "utilities.h"
55
56 //================================================================================
57 /*!
58  * \brief Constructor of a side of one edge
59   * \param theFace - the face
60   * \param theEdge - the edge
61  */
62 //================================================================================
63
64 StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace,
65                                          const TopoDS_Edge& theEdge,
66                                          SMESH_Mesh*        theMesh,
67                                          const bool         theIsForward,
68                                          const bool         theIgnoreMediumNodes)
69 {
70   list<TopoDS_Edge> edges(1,theEdge);
71   *this = StdMeshers_FaceSide( theFace, edges, theMesh, theIsForward, theIgnoreMediumNodes );
72 }
73
74 //================================================================================
75 /*!
76  * \brief Constructor of a side of several edges
77   * \param theFace - the face
78   * \param theEdge - the edge
79  */
80 //================================================================================
81
82 StdMeshers_FaceSide::StdMeshers_FaceSide(const TopoDS_Face& theFace,
83                                          list<TopoDS_Edge>& theEdges,
84                                          SMESH_Mesh*        theMesh,
85                                          const bool         theIsForward,
86                                          const bool         theIgnoreMediumNodes)
87 {
88   int nbEdges = theEdges.size();
89   myEdge.resize( nbEdges );
90   myC2d.resize( nbEdges );
91   myFirst.resize( nbEdges );
92   myLast.resize( nbEdges );
93   myNormPar.resize( nbEdges );
94   myLength = 0;
95   myNbPonits = myNbSegments = 0;
96   myMesh = theMesh;
97   myMissingVertexNodes = false;
98   myIgnoreMediumNodes = theIgnoreMediumNodes;
99   myDefaultPnt2d = gp_Pnt2d( 1e+100, 1e+100 );
100   if ( nbEdges == 0 ) return;
101
102   SMESHDS_Mesh* meshDS = theMesh->GetMeshDS();
103   vector<double> len( nbEdges );
104
105   int nbDegen = 0;
106   list<TopoDS_Edge>::iterator edge = theEdges.begin();
107   TopoDS_Iterator vExp;
108   for ( int index = 0; edge != theEdges.end(); ++index, ++edge )
109   {
110     int i = theIsForward ? index : nbEdges - index - 1;
111     len[i] = SMESH_Algo::EdgeLength( *edge );
112     if ( len[i] < DBL_MIN ) nbDegen++;
113     myLength += len[i];
114     myEdge[i] = *edge;
115     if ( !theIsForward ) myEdge[i].Reverse();
116
117     if ( theFace.IsNull() )
118       BRep_Tool::Range( *edge, myFirst[i], myLast[i] );
119     else
120       myC2d[i] = BRep_Tool::CurveOnSurface( *edge, theFace, myFirst[i], myLast[i] );
121     if ( myEdge[i].Orientation() == TopAbs_REVERSED )
122       std::swap( myFirst[i], myLast[i] );
123
124     if ( SMESHDS_SubMesh* sm = meshDS->MeshElements( *edge )) {
125       int nbN = sm->NbNodes();
126       if ( theIgnoreMediumNodes ) {
127         SMDS_ElemIteratorPtr elemIt = sm->GetElements();
128         if ( elemIt->more() && elemIt->next()->IsQuadratic() )
129           nbN -= sm->NbElements();
130       }
131       myNbPonits += nbN;
132       myNbSegments += sm->NbElements();
133     }
134     vExp.Initialize( *edge );
135     if ( SMESH_Algo::VertexNode( TopoDS::Vertex( vExp.Value()), meshDS ))
136       myNbPonits += 1; // for the first end
137     else
138       myMissingVertexNodes = true;
139   }
140   vExp.Next();
141   if ( vExp.More() )
142   {
143     if ( SMESH_Algo::VertexNode( TopoDS::Vertex( vExp.Value()), meshDS ))
144       myNbPonits++; // for the last end
145     else
146       myMissingVertexNodes = true;
147   }
148   if ( nbEdges > 1 && myLength > DBL_MIN ) {
149     const double degenNormLen = 1.e-5;
150     double totLength = myLength;
151     if ( nbDegen )
152       totLength += myLength * degenNormLen * nbDegen;
153     double prevNormPar = 0;
154     for ( int i = 0; i < nbEdges; ++i ) {
155       if ( len[ i ] < DBL_MIN )
156         len[ i ] = myLength * degenNormLen;
157       myNormPar[ i ] = prevNormPar + len[i]/totLength;
158       prevNormPar = myNormPar[ i ];
159     }
160   }
161   myNormPar[nbEdges-1] = 1.;
162   //dump();
163 }
164
165 //================================================================================
166 /*!
167  * \brief Constructor of a side for vertex using data from other FaceSide
168   * \param theVertex - the vertex
169   * \param theSide - the side
170  */
171 //================================================================================
172
173 StdMeshers_FaceSide::StdMeshers_FaceSide(const SMDS_MeshNode* theNode,
174                                          const gp_Pnt2d thePnt2d,
175                                          const StdMeshers_FaceSide* theSide)
176 {
177   myC2d.resize(1);
178   myLength = 0;
179   myMesh = theSide->GetMesh();
180   myDefaultPnt2d = thePnt2d;
181
182   myPoints = theSide->GetUVPtStruct();
183   myNbPonits = myNbSegments = myPoints.size();
184   std::vector<uvPtStruct>::iterator it = myPoints.begin();
185   for(; it!=myPoints.end(); it++) {
186     (*it).u = thePnt2d.X();
187     (*it).v = thePnt2d.Y();
188     (*it).y = 0.0;
189     (*it).node = theNode;
190   }
191 }
192
193 //================================================================================
194 /*!
195  * \brief Return info on nodes on the side
196   * \retval UVPtStruct* - array of data structures
197  */
198 //================================================================================
199
200 const vector<UVPtStruct>& StdMeshers_FaceSide::GetUVPtStruct(bool   isXConst,
201                                                              double constValue) const
202 {
203   if ( myPoints.empty() ) {
204
205     if ( NbEdges() == 0 ) return myPoints;
206
207     SMESHDS_Mesh* meshDS = myMesh->GetMeshDS();
208
209     // sort nodes of all edges putting them into a map
210
211     map< double, const SMDS_MeshNode*> u2node;
212     //int nbOnDegen = 0;
213     for ( int i = 0; i < myEdge.size(); ++i ) {
214       // put 1st vertex node
215       TopoDS_Vertex VV[2]; // TopExp::FirstVertex() returns NULL for INTERNAL edge
216       for ( TopoDS_Iterator vIt(myEdge[i]); vIt.More(); vIt.Next() )
217         VV[ VV[0].IsNull() ? 0 : 1 ] = TopoDS::Vertex(vIt.Value());
218       if ( VV[0].Orientation() == TopAbs_REVERSED ) std::swap ( VV[0], VV[1] );
219       const SMDS_MeshNode* node = SMESH_Algo::VertexNode( VV[0], meshDS );
220       double prevNormPar = ( i == 0 ? 0 : myNormPar[ i-1 ]); // normalized param
221       if ( node ) { // internal nodes may be missing
222         u2node.insert( make_pair( prevNormPar, node ));
223       }
224       else if ( i == 0 ) {
225         MESSAGE(" NO NODE on VERTEX" );
226         return myPoints;
227       }
228
229       // put 2nd vertex node for a last edge
230       if ( i+1 == myEdge.size() ) {
231         node = SMESH_Algo::VertexNode( VV[1], meshDS );
232         if ( !node ) {
233           MESSAGE(" NO NODE on VERTEX" );
234           return myPoints;
235         }
236         u2node.insert( make_pair( 1., node ));
237       }
238
239       // put internal nodes
240       SMESHDS_SubMesh* sm = meshDS->MeshElements( myEdge[i] );
241       if ( !sm ) continue;
242       SMDS_NodeIteratorPtr nItr = sm->GetNodes();
243       double paramSize = myLast[i] - myFirst[i], r = myNormPar[i] - prevNormPar;
244       while ( nItr->more() ) {
245         const SMDS_MeshNode* node = nItr->next();
246         if ( myIgnoreMediumNodes && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge ))
247           continue;
248         const SMDS_EdgePosition* epos =
249           static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
250         double u = epos->GetUParameter();
251         // paramSize is signed so orientation is taken into account
252         double normPar = prevNormPar + r * ( u - myFirst[i] ) / paramSize;
253 #ifdef _DEBUG_
254         if ( normPar > 1 || normPar < 0) {
255           dump("DEBUG");
256           MESSAGE ( "WRONG normPar: "<<normPar<< " prevNormPar="<<prevNormPar
257                     << " u="<<u << " myFirst[i]="<<myFirst[i]<< " myLast[i]="<<myLast[i]
258                     << " paramSize="<<paramSize );
259         }
260 #endif
261         u2node.insert( make_pair( normPar, node ));
262       }
263     }
264     if ( u2node.size() != myNbPonits ) {
265       MESSAGE("Wrong node parameters on edges, u2node.size():"
266               <<u2node.size()<<" !=  myNbPonits:"<<myNbPonits);
267       return myPoints;
268     }
269
270     // fill array of UVPtStruct
271
272     vector<uvPtStruct>* points = const_cast<vector<uvPtStruct>*>( &myPoints );
273     points->resize( myNbPonits );
274
275     int EdgeIndex = 0;
276     double prevNormPar = 0, paramSize = myNormPar[ EdgeIndex ];
277     map< double, const SMDS_MeshNode*>::iterator u_node = u2node.begin();
278     for (int i = 0 ; u_node != u2node.end(); ++u_node, ++i ) {
279       UVPtStruct & uvPt = (*points)[i];
280       uvPt.node = u_node->second;
281       uvPt.x = uvPt.y = uvPt.normParam = u_node->first;
282       if ( isXConst ) uvPt.x = constValue;
283       else            uvPt.y = constValue;
284       if ( myNormPar[ EdgeIndex ] < uvPt.normParam ) {
285         prevNormPar = myNormPar[ EdgeIndex ];
286         ++EdgeIndex;
287 #ifdef _DEBUG_
288         if ( EdgeIndex >= myEdge.size() ) {
289           dump("DEBUG");
290           MESSAGE ( "WRONg EdgeIndex " << 1+EdgeIndex
291                     << " myNormPar.size()="<<myNormPar.size()
292                     << " myNormPar["<< EdgeIndex<<"]="<< myNormPar[ EdgeIndex ]
293                     << " uvPt.normParam="<<uvPt.normParam );
294         }
295 #endif
296         paramSize = myNormPar[ EdgeIndex ] - prevNormPar;
297       }
298       const SMDS_EdgePosition* epos =
299         dynamic_cast<const SMDS_EdgePosition*>(uvPt.node->GetPosition().get());
300       if ( epos ) {
301         uvPt.param = epos->GetUParameter();
302       }
303       else {
304         double r = ( uvPt.normParam - prevNormPar )/ paramSize;
305 //         uvPt.param = myFirst[EdgeIndex] * ( 1 - r ) + myLast[EdgeIndex] * r;
306         uvPt.param = ( r > 0.5 ? myLast[EdgeIndex] : myFirst[EdgeIndex] );
307       }
308       if ( !myC2d[ EdgeIndex ].IsNull() ) {
309         gp_Pnt2d p = myC2d[ EdgeIndex ]->Value( uvPt.param );
310         uvPt.u = p.X();
311         uvPt.v = p.Y();
312       }
313       else {
314         uvPt.u = uvPt.v = 1e+100;
315       }
316     }
317   }
318   return myPoints;
319 }
320
321 //================================================================================
322 /*!
323  * \brief Falsificate info on nodes
324   * \param nbSeg - nb of segments on the side
325   * \retval UVPtStruct* - array of data structures
326  */
327 //================================================================================
328
329 const vector<UVPtStruct>& StdMeshers_FaceSide::SimulateUVPtStruct(int    nbSeg,
330                                                                   bool   isXConst,
331                                                                   double constValue) const
332 {
333   if ( myFalsePoints.empty() ) {
334
335     if ( NbEdges() == 0 ) return myFalsePoints;
336
337     vector<uvPtStruct>* points = const_cast<vector<uvPtStruct>*>( &myFalsePoints );
338     points->resize( nbSeg+1 );
339
340     int EdgeIndex = 0;
341     double prevNormPar = 0, paramSize = myNormPar[ EdgeIndex ];
342     for (int i = 0 ; i < myFalsePoints.size(); ++i ) {
343       double normPar = double(i) / double(nbSeg);
344       UVPtStruct & uvPt = (*points)[i];
345       uvPt.node = 0;
346       uvPt.x = uvPt.y = uvPt.param = uvPt.normParam = normPar;
347       if ( isXConst ) uvPt.x = constValue;
348       else            uvPt.y = constValue;
349       if ( myNormPar[ EdgeIndex ] < normPar ) {
350         prevNormPar = myNormPar[ EdgeIndex ];
351         ++EdgeIndex;
352         paramSize = myNormPar[ EdgeIndex ] - prevNormPar;
353       }
354       double r = ( normPar - prevNormPar )/ paramSize;
355       uvPt.param = myFirst[EdgeIndex] * ( 1 - r ) + myLast[EdgeIndex] * r;
356       if ( !myC2d[ EdgeIndex ].IsNull() ) {
357         gp_Pnt2d p = myC2d[ EdgeIndex ]->Value( uvPt.param );
358         uvPt.u = p.X();
359         uvPt.v = p.Y();
360       }
361       else {
362         uvPt.u = uvPt.v = 1e+100;
363       }
364     }
365   }
366   return myFalsePoints;
367 }
368 // gp_Pnt StdMeshers_FaceSide::Value(double U) const
369 // {
370 // }
371
372 //================================================================================
373 /*!
374  * \brief reverse order of vector elements
375   * \param vec - vector to reverse
376  */
377 //================================================================================
378
379 template <typename T > void reverse(vector<T> & vec)
380 {
381   for ( int f=0, r=vec.size()-1; f < r; ++f, --r )
382     std::swap( vec[f], vec[r] );
383 }
384
385 //================================================================================
386 /*!
387  * \brief Change orientation of side geometry
388  */
389 //================================================================================
390
391 void StdMeshers_FaceSide::Reverse()
392 {
393   int nbEdges = myEdge.size();
394   for ( int i = nbEdges-1; i >= 0; --i ) {
395     std::swap( myFirst[i], myLast[i] );
396     myEdge[i].Reverse();
397     if ( i > 0 ) // at the first loop 1. is overwritten
398       myNormPar[i] = 1 - myNormPar[i-1];
399   }
400   if ( nbEdges > 1 ) {
401     reverse( myEdge );
402     reverse( myC2d );
403     reverse( myFirst );
404     reverse( myLast );
405     reverse( myNormPar );
406   }
407   myNormPar[nbEdges-1]=1.;
408   myPoints.clear();
409   myFalsePoints.clear();
410 }
411
412 //================================================================================
413 /*!
414  * \brief Show side features
415  */
416 //================================================================================
417
418 void StdMeshers_FaceSide::dump(const char* msg) const
419 {
420 #ifdef _DEBUG_
421   if (msg) MESSAGE ( std::endl << msg );
422   MESSAGE_BEGIN ("NB EDGES: "<< myEdge.size() );
423   MESSAGE_ADD ( "nbPoints: "<<myNbPonits<<" vecSize: " << myPoints.size()<<" "<<myFalsePoints.size() );
424   for ( int i=0; i<myEdge.size(); ++i)
425   {
426     MESSAGE_ADD ( "\t"<<i+1 );
427     MESSAGE_ADD ( "\tEDGE: " );
428     if (myEdge[i].IsNull()) {
429       MESSAGE_ADD ( "NULL" );
430     }
431     else {
432       TopAbs::Print(myEdge[i].Orientation(),cout)<<" "<<myEdge[i].TShape().operator->()<<endl;
433       MESSAGE_ADD ( "\tV1: " << TopExp::FirstVertex( myEdge[i], 1).TShape().operator->()
434                  << "  V2: " << TopExp::LastVertex( myEdge[i], 1).TShape().operator->() );
435     }
436     MESSAGE_ADD ( "\tC2d: ");
437     
438     if (myC2d[i].IsNull()) {
439       MESSAGE_ADD ( "NULL" );
440     }
441     else {
442       MESSAGE_ADD ( myC2d[i].operator->() );
443     }
444       
445     MESSAGE_ADD ( "\tF: "<<myFirst[i]<< " L: "<< myLast[i] );
446     MESSAGE_END ( "\tnormPar: "<<myNormPar[i]<<endl );
447   }
448 #endif
449 }
450
451 //================================================================================
452 /*!
453  * \brief Creates a Adaptor2d_Curve2d to be used in SMESH_Block
454   * \retval Adaptor2d_Curve2d* - 
455  */
456 //================================================================================
457
458 struct Adaptor2dCurve2d : public Adaptor2d_Curve2d
459 {
460   const StdMeshers_FaceSide* mySide;
461   Adaptor2dCurve2d(const StdMeshers_FaceSide* faceSide):mySide(faceSide) {}
462   gp_Pnt2d Value(const Standard_Real U) const { return mySide->Value2d( U ); }
463   Standard_Real FirstParameter() const { return 0; }
464   Standard_Real LastParameter() const { return 1; }
465 };
466
467 Adaptor2d_Curve2d* StdMeshers_FaceSide::GetCurve2d() const
468 {
469   return new Adaptor2dCurve2d( this );
470 }
471
472 //================================================================================
473 /*!
474  * \brief Creates a fully functional Adaptor_Curve
475  */
476 //================================================================================
477
478 BRepAdaptor_CompCurve* StdMeshers_FaceSide::GetCurve3d() const
479 {
480   if ( myEdge.empty() )
481     return 0;
482
483 //   if ( myEdge.size() == 1 )
484 //     return new BRepAdaptor_Curve( myEdge[0] );
485
486   TopoDS_Wire aWire;
487   BRep_Builder aBuilder;
488   aBuilder.MakeWire(aWire);
489   for ( int i=0; i<myEdge.size(); ++i )
490     aBuilder.Add( aWire, myEdge[i] );
491   return new BRepAdaptor_CompCurve( aWire );
492 }
493
494 //================================================================================
495 /*!
496  * \brief Return 2D point by normalized parameter
497   * \param U - normalized parameter value
498   * \retval gp_Pnt2d - point
499  */
500 //================================================================================
501
502 gp_Pnt2d StdMeshers_FaceSide::Value2d(double U) const
503 {
504   if ( !myC2d[0].IsNull() ) {
505     int i = EdgeIndex( U );
506     double prevU = i ? myNormPar[ i-1 ] : 0;
507     double r = ( U - prevU )/ ( myNormPar[ i ] - prevU );
508     return myC2d[ i ]->Value( myFirst[i] * ( 1 - r ) + myLast[i] * r );
509   }
510   //return gp_Pnt2d( 1e+100, 1e+100 );
511   return myDefaultPnt2d;
512 }
513
514 //================================================================================
515 /*!
516  * \brief Return wires of a face as StdMeshers_FaceSide's
517  */
518 //================================================================================
519
520 TSideVector StdMeshers_FaceSide::GetFaceWires(const TopoDS_Face& theFace,
521                                               SMESH_Mesh &       theMesh,
522                                               const bool         theIgnoreMediumNodes,
523                                               TError &           theError)
524 {
525   TopoDS_Vertex V1;
526   list< TopoDS_Edge > edges;
527   list< int > nbEdgesInWires;
528   int nbWires = SMESH_Block::GetOrderedEdges (theFace, V1, edges, nbEdgesInWires);
529
530   // split list of all edges into separate wires
531   TSideVector wires( nbWires );
532   list< int >::iterator nbE = nbEdgesInWires.begin();
533   list< TopoDS_Edge >::iterator from, to;
534   from = to = edges.begin();
535   for ( int iW = 0; iW < nbWires; ++iW )
536   {
537     std::advance( to, *nbE++ );
538     if ( *nbE == 0 ) // Issue 0020676
539     {
540       --nbWires;
541       --iW;
542       wires.resize( nbWires );
543       continue;
544     }
545     list< TopoDS_Edge > wireEdges( from, to );
546     // assure that there is a node on the first vertex
547     // as StdMeshers_FaceSide::GetUVPtStruct() requires
548     if ( wireEdges.front().Orientation() != TopAbs_INTERNAL ) // Issue 0020676
549       while ( !SMESH_Algo::VertexNode( TopExp::FirstVertex( wireEdges.front(), true),
550                                        theMesh.GetMeshDS()))
551       {
552         wireEdges.splice(wireEdges.end(), wireEdges,
553                          wireEdges.begin(), ++wireEdges.begin());
554         if ( from->IsSame( wireEdges.front() )) {
555           theError = TError
556             ( new SMESH_ComputeError(COMPERR_BAD_INPUT_MESH,"No nodes on vertices"));
557           return TSideVector(0);
558         }
559       }
560     const bool isForward = true;
561     StdMeshers_FaceSide* wire = new StdMeshers_FaceSide( theFace, wireEdges, &theMesh,
562                                                          isForward, theIgnoreMediumNodes);
563     wires[ iW ] = StdMeshers_FaceSidePtr( wire );
564     from = to;
565   }
566   return wires;
567 }
568
569 //================================================================================
570 /*!
571  * \brief Return 1st vertex of the i-the edge
572  */
573 //================================================================================
574
575 TopoDS_Vertex StdMeshers_FaceSide::FirstVertex(int i) const
576 {
577   TopoDS_Vertex v;
578   if ( i < NbEdges() )
579   {
580     v = myEdge[i].Orientation() <= TopAbs_REVERSED ? // FORWARD || REVERSED
581         TopExp::FirstVertex( myEdge[i], 1 )        :
582         TopoDS::Vertex( TopoDS_Iterator( myEdge[i] ).Value() );
583   }
584   return v;
585 }
586
587 //================================================================================
588 /*!
589  * \brief Return last vertex of the i-the edge
590  */
591 //================================================================================
592
593 TopoDS_Vertex StdMeshers_FaceSide::LastVertex(int i) const
594 {
595   TopoDS_Vertex v;
596   if ( i < NbEdges() )
597   {
598     const TopoDS_Edge& edge = i<0 ? myEdge[ NbEdges() + i ] : myEdge[i];
599     if ( edge.Orientation() <= TopAbs_REVERSED ) // FORWARD || REVERSED
600       v = TopExp::LastVertex( edge, 1 );
601     else
602       for ( TopoDS_Iterator vIt( edge ); vIt.More(); vIt.Next() )
603         v = TopoDS::Vertex( vIt.Value() );
604   }
605   return v;
606 }
607