Salome HOME
Copyright update 2020
[modules/shaper.git] / src / GeomAPI / GeomAPI_Edge.cpp
1 // Copyright (C) 2014-2020  CEA/DEN, EDF R&D
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include<GeomAPI_Edge.h>
21 #include<GeomAPI_Pln.h>
22 #include<GeomAPI_Pnt.h>
23 #include<GeomAPI_Circ.h>
24 #include<GeomAPI_Dir.h>
25 #include<GeomAPI_Lin.h>
26 #include<GeomAPI_Ax2.h>
27 #include<GeomAPI_Ellipse.h>
28 #include<GeomAPI_Vertex.h>
29
30 #include <BRepAdaptor_Curve.hxx>
31
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS.hxx>
35 #include <BRep_Builder.hxx>
36 #include <BRep_Tool.hxx>
37 #include <ElCLib.hxx>
38 #include <GCPnts_UniformAbscissa.hxx>
39 #include <Geom_BSplineCurve.hxx>
40 #include <Geom_Curve.hxx>
41 #include <Geom_Line.hxx>
42 #include <Geom_Circle.hxx>
43 #include <Geom_TrimmedCurve.hxx>
44 #include <Geom_Ellipse.hxx>
45 #include <Geom_Plane.hxx>
46 #include <GeomAPI_ExtremaCurveCurve.hxx>
47 #include <GeomAPI_ExtremaCurveSurface.hxx>
48 #include <GeomAPI_IntCS.hxx>
49 #include <GeomAdaptor_Curve.hxx>
50 #include <gp_Ax1.hxx>
51 #include <gp_Pln.hxx>
52 #include <gp_Elips.hxx>
53 #include <TopExp.hxx>
54
55 #include <GCPnts_AbscissaPoint.hxx>
56
57 GeomAPI_Edge::GeomAPI_Edge()
58 {
59   TopoDS_Edge* anEdge = new TopoDS_Edge;
60
61   BRep_Builder aBuilder;
62   aBuilder.MakeEdge(*anEdge);
63
64   setImpl(anEdge);
65 }
66
67 GeomAPI_Edge::GeomAPI_Edge(const std::shared_ptr<GeomAPI_Shape>& theShape)
68 {
69   if (!theShape->isNull() && theShape->isEdge()) {
70     setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
71   }
72 }
73
74 void GeomAPI_Edge::vertices(std::shared_ptr<GeomAPI_Vertex>& theStartVertex,
75                             std::shared_ptr<GeomAPI_Vertex>& theEndVertex) const
76 {
77   const TopoDS_Edge& anEdge = impl<TopoDS_Edge>();
78   TopoDS_Vertex aStart, aEnd;
79   TopExp::Vertices(anEdge, aStart, aEnd);
80   theStartVertex.reset(new GeomAPI_Vertex);
81   theStartVertex->setImpl(new TopoDS_Vertex(aStart));
82   theEndVertex.reset(new GeomAPI_Vertex);
83   theEndVertex->setImpl(new TopoDS_Vertex(aEnd));
84 }
85
86 static Handle(Geom_Curve) baseCurve(const TopoDS_Edge& theEdge)
87 {
88   double aFirst, aLast;
89   Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, aFirst, aLast);
90   while (aCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
91     Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
92     aCurve = tc->BasisCurve();
93   }
94   return aCurve;
95 }
96
97 bool GeomAPI_Edge::isSameGeometry(const std::shared_ptr<GeomAPI_Shape> theShape) const
98 {
99   if (!theShape->isEdge())
100     return false;
101   if (isSame(theShape))
102     return true;
103
104   TopoDS_Edge anOwnEdge = TopoDS::Edge(impl<TopoDS_Shape>());
105   TopoDS_Edge anOtherEdge = TopoDS::Edge(theShape->impl<TopoDS_Shape>());
106
107   Handle(Geom_Curve) anOwnCurve = baseCurve(anOwnEdge);
108   Handle(Geom_Curve) anOtherCurve = baseCurve(anOtherEdge);
109   GeomAPI_ExtremaCurveCurve anExtrema(anOwnCurve, anOtherCurve);
110
111   bool isSame = anExtrema.Extrema().IsParallel() &&
112                 anExtrema.TotalLowerDistance() < Precision::Confusion();
113   return isSame;
114 }
115
116 bool GeomAPI_Edge::isLine() const
117 {
118   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
119   double aFirst, aLast;
120   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
121   if (aCurve.IsNull()) // degenerative edge
122     return false;
123   if (aCurve->IsKind(STANDARD_TYPE(Geom_Line)))
124     return true;
125   return false;
126 }
127
128 /// extracts a circle curve from the arbitrary curve, returns null is it is different type
129 static Handle(Geom_Circle) circ(const Handle(Geom_Curve) theCurve)
130 {
131   Handle(Geom_Circle) aResult = Handle(Geom_Circle)::DownCast(theCurve);
132   if (!aResult.IsNull())
133     return aResult;
134   // check this may be a trimmed curve that contains circle inside
135   Handle(Geom_TrimmedCurve) aTrimmed = Handle(Geom_TrimmedCurve)::DownCast(theCurve);
136   while(!aTrimmed.IsNull()) {
137     aResult = Handle(Geom_Circle)::DownCast(aTrimmed->BasisCurve());
138     if (!aResult.IsNull())
139       return aResult;
140     aTrimmed = Handle(Geom_TrimmedCurve)::DownCast(aTrimmed->BasisCurve());
141   }
142   return aResult; // null, not circle
143 }
144
145 bool GeomAPI_Edge::isCircle() const
146 {
147   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
148   double aFirst, aLast;
149   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
150   if (!circ(aCurve).IsNull()) {
151     // Check the difference of first and last parameters to be equal to the curve period
152     if (Abs(aLast - aFirst - aCurve->Period()) < Precision::PConfusion())
153       return true;
154   }
155   return false;
156 }
157
158 bool GeomAPI_Edge::isArc() const
159 {
160   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
161   double aFirst, aLast;
162   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
163   if (!circ(aCurve).IsNull()) {
164     // Check the difference of first and last parameters is not equal the curve period
165     if (Abs(aLast - aFirst - aCurve->Period()) >= Precision::PConfusion())
166       return true;
167   }
168   return false;
169 }
170
171 bool GeomAPI_Edge::isEllipse() const
172 {
173   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
174   double aFirst, aLast;
175   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
176   if (aCurve.IsNull()) // degenerative edge
177     return false;
178   if (aCurve->IsKind(STANDARD_TYPE(Geom_Ellipse)))
179     return true;
180   return false;
181 }
182
183 bool GeomAPI_Edge::isBSpline() const
184 {
185   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
186   double aFirst, aLast;
187   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
188   if (aCurve.IsNull()) // degenerative edge
189     return false;
190   while (aCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)))
191     aCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
192   return aCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve));
193 }
194
195 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::firstPoint()
196 {
197   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
198   double aFirst, aLast;
199   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
200   gp_Pnt aPoint;
201   aCurve->D0(aFirst, aPoint);
202   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
203 }
204
205 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::lastPoint()
206 {
207   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
208   double aFirst, aLast;
209   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
210   gp_Pnt aPoint;
211   aCurve->D0(aLast, aPoint);
212   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
213 }
214
215 std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle() const
216 {
217   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
218   double aFirst, aLast;
219   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
220   Handle(Geom_Circle) aCirc = circ(aCurve);
221   if (!aCirc.IsNull()) {
222     gp_Pnt aLoc = aCirc->Location();
223     std::shared_ptr<GeomAPI_Pnt> aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
224     gp_Dir anAxis = aCirc->Axis().Direction();
225     std::shared_ptr<GeomAPI_Dir> aDir(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
226     return std::shared_ptr<GeomAPI_Circ>(new GeomAPI_Circ(aCenter, aDir, aCirc->Radius()));
227   }
228   return std::shared_ptr<GeomAPI_Circ>(); // not circle
229 }
230
231 std::shared_ptr<GeomAPI_Ellipse> GeomAPI_Edge::ellipse() const
232 {
233   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
234   double aFirst, aLast;
235   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
236   if (!aCurve.IsNull()) {
237     Handle(Geom_Ellipse) aElips = Handle(Geom_Ellipse)::DownCast(aCurve);
238     if (!aElips.IsNull()) {
239       gp_Elips aGpElips = aElips->Elips();
240       std::shared_ptr<GeomAPI_Ellipse> aEllipse(new GeomAPI_Ellipse());
241       aEllipse->setImpl(new gp_Elips(aGpElips));
242       return aEllipse;
243     }
244   }
245   return std::shared_ptr<GeomAPI_Ellipse>(); // not ellipse
246 }
247
248 std::shared_ptr<GeomAPI_Lin> GeomAPI_Edge::line() const
249 {
250   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
251   double aFirst, aLast;
252   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
253   if (aCurve) {
254     Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCurve);
255     if (aLine) {
256       gp_Pnt aStartPnt = aLine->Value(aFirst);
257       std::shared_ptr<GeomAPI_Pnt> aStart(
258           new GeomAPI_Pnt(aStartPnt.X(), aStartPnt.Y(), aStartPnt.Z()));
259       gp_Pnt aEndPnt = aLine->Value(aLast);
260       std::shared_ptr<GeomAPI_Pnt> aEnd(
261           new GeomAPI_Pnt(aEndPnt.X(), aEndPnt.Y(), aEndPnt.Z()));
262       return std::shared_ptr<GeomAPI_Lin>(new GeomAPI_Lin(aStart, aEnd));
263     }
264   }
265   return std::shared_ptr<GeomAPI_Lin>(); // not circle
266 }
267
268
269 bool GeomAPI_Edge::isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const
270 {
271   if (!theEdge.get() || ! theEdge->isEdge())
272     return false;
273   const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
274   const TopoDS_Shape& aInShape = theEdge->impl<TopoDS_Shape>();
275
276   if (aMyShape.IsNull() || aInShape.IsNull())
277     return false;
278
279   if (aMyShape.ShapeType() != aInShape.ShapeType())
280     return false;
281
282   double aMyStart, aMyEnd;
283   Handle(Geom_Curve) aMyCurve = BRep_Tool::Curve(TopoDS::Edge(aMyShape), aMyStart, aMyEnd);
284   double aInStart, aInEnd;
285   Handle(Geom_Curve) aInCurve = BRep_Tool::Curve(TopoDS::Edge(aInShape), aInStart, aInEnd);
286
287   // Check that end point parameters are the same
288   if ((aMyStart != aInStart) || (aMyEnd != aInEnd))
289     return false;
290
291   // Check that curves a the same type
292   GeomAdaptor_Curve aMyAdaptor(aMyCurve);
293   GeomAdaptor_Curve aInAdaptor(aInCurve);
294   if (aMyAdaptor.GetType() != aInAdaptor.GetType())
295     return false;
296
297   // Check that end points are equal
298   gp_Pnt aMyPnt1 = aMyAdaptor.Value(aMyStart);
299   gp_Pnt aMyPnt2 = aMyAdaptor.Value(aMyEnd);
300   gp_Pnt aInPnt1 = aInAdaptor.Value(aInStart);
301   gp_Pnt aInPnt2 = aInAdaptor.Value(aInEnd);
302
303   if ((!aMyPnt1.IsEqual(aInPnt1, Precision::Confusion())) ||
304     (!aMyPnt2.IsEqual(aInPnt2, Precision::Confusion())))
305     return false;
306
307   return true;
308 }
309
310 void GeomAPI_Edge::setRange(const double& theFirst, const double& theLast)
311 {
312   TopoDS_Edge anEdge = impl<TopoDS_Edge>();
313   double aFirst, aLast;
314   Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
315   double aTolerance = BRep_Tool::Tolerance(anEdge);
316   if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
317     aCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
318     BRep_Builder().UpdateEdge(anEdge, aCurve, aTolerance);
319   }
320   BRep_Builder().Range(anEdge, theFirst, theLast);
321 }
322
323 void GeomAPI_Edge::getRange(double& theFirst, double& theLast) const
324 {
325   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
326   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, theFirst, theLast);
327 }
328
329 // LCOV_EXCL_START
330 bool GeomAPI_Edge::isInPlane(std::shared_ptr<GeomAPI_Pln> thePlane) const
331 {
332   double aFirst, aLast;
333   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
334   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
335   if (aCurve.IsNull())
336     return false;
337
338   double A, B, C, D;
339   thePlane->coefficients(A, B, C, D);
340   gp_Pln aPlane(A, B, C, D);
341
342   bool inPlane = false;
343   if (aCurve->IsKind(STANDARD_TYPE(Geom_Line))) {
344     // check start and end points on the plane
345     gp_Pnt aFirstPnt = aCurve->Value(aFirst);
346     gp_Pnt aLastPnt = aCurve->Value(aLast);
347     inPlane = aPlane.SquareDistance(aFirstPnt) < Precision::SquareConfusion() &&
348               aPlane.SquareDistance(aLastPnt) < Precision::SquareConfusion();
349   } else {
350     Handle(Geom_Circle) aCirc = circ(aCurve);
351     if (!aCirc.IsNull()) {
352       gp_Pnt aCenter = aCirc->Location();
353       Standard_Real aDot = aPlane.Axis().Direction().Dot(aCirc->Axis().Direction());
354       inPlane = aPlane.SquareDistance(aCenter) < Precision::SquareConfusion() &&
355                 Abs(Abs(aDot) - 1.0) < Precision::Confusion();
356     } else {
357       // three points checking
358       gp_Pnt aFirstPnt = aCurve->Value(aFirst);
359       gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
360       gp_Pnt aLastPnt = aCurve->Value(aLast);
361       inPlane = aPlane.SquareDistance(aFirstPnt) < Precision::SquareConfusion() &&
362                 aPlane.SquareDistance(aMidPnt) < Precision::SquareConfusion() &&
363                 aPlane.SquareDistance(aLastPnt) < Precision::SquareConfusion();
364     }
365   }
366   return inPlane;
367 }
368 // LCOV_EXCL_STOP
369
370 void GeomAPI_Edge::intersectWithPlane(const std::shared_ptr<GeomAPI_Pln> thePlane,
371                                       std::list<std::shared_ptr<GeomAPI_Pnt>>& theResult) const
372 {
373   double aFirst, aLast;
374   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
375   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
376   if (!aCurve.IsNull()) {
377     double A, B, C, D;
378     thePlane->coefficients(A, B, C, D);
379     gp_Pln aPln(A, B, C, D);
380     Handle(Geom_Plane) aPlane = new Geom_Plane(aPln);
381
382     // intersect the plane with the curve
383     GeomAPI_IntCS aIntersect;
384     aIntersect.Perform(aCurve, aPlane);
385     if (aIntersect.IsDone() && (aIntersect.NbPoints() > 0)) {
386       gp_Pnt aPnt;
387       for (int i = 1; i <= aIntersect.NbPoints(); i++) {
388         // check the parameter of intersection in the edge range
389         aIntersect.Parameters(i, A, B, C);
390         if (aCurve->IsPeriodic())
391           C = ElCLib::InPeriod(C, aFirst, aFirst + aCurve->Period());
392         if (C < aFirst - Precision::PConfusion() || C > aLast + Precision::PConfusion())
393           continue;
394
395         // obtain intersection point
396         aPnt = aIntersect.Point(i);
397         std::shared_ptr<GeomAPI_Pnt> aPntPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
398         theResult.push_back(aPntPtr);
399       }
400     }
401     else {
402       // find minimal distance between the plane and the curve
403       GeomAPI_ExtremaCurveSurface anExtrema(aCurve, aPlane);
404       double aTolerance = BRep_Tool::Tolerance(TopoDS::Edge(aShape));
405       if (anExtrema.NbExtrema() > 0 &&
406           !anExtrema.Extrema().IsParallel() &&
407           anExtrema.LowerDistance() < aTolerance) {
408         // distance is lower than tolerance => tangent case
409         gp_Pnt aPntC, aPntS;
410         anExtrema.NearestPoints(aPntC, aPntS);
411         std::shared_ptr<GeomAPI_Pnt> aPntPtr(new GeomAPI_Pnt(aPntS.X(), aPntS.Y(), aPntS.Z()));
412         theResult.push_back(aPntPtr);
413       }
414     }
415   }
416 }
417
418 double GeomAPI_Edge::length() const
419 {
420   const TopoDS_Edge& anEdge = TopoDS::Edge(impl<TopoDS_Shape>());
421   BRepAdaptor_Curve aBRepAdaptor = BRepAdaptor_Curve(anEdge);
422   Adaptor3d_Curve* anAdaptor3d = &aBRepAdaptor;
423   return GCPnts_AbscissaPoint::Length(*anAdaptor3d);
424 }
425
426 bool GeomAPI_Edge::isClosed() const
427 {
428   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
429   if (aShape.IsNull())
430     return false;
431   double aFirst, aLast;
432   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
433   if (aCurve.IsNull() || !aCurve->IsPeriodic())
434     return false;
435   aLast += aLast > aFirst ? -aCurve->Period() : aCurve->Period();;
436
437   return fabs(aFirst - aLast) < 1.e-9;
438 }
439
440 bool GeomAPI_Edge::isDegenerated() const
441 {
442   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
443   if (aShape.IsNull() || aShape.ShapeType() != TopAbs_EDGE)
444     return false;
445   return BRep_Tool::Degenerated(TopoDS::Edge(aShape));
446 }
447
448 void GeomAPI_Edge::setFirstPointTolerance(const double theTolerance)
449 {
450   TopoDS_Edge anEdge = impl<TopoDS_Edge>();
451   TopoDS_Vertex aVFirst, aVLast;
452   TopExp::Vertices(anEdge, aVFirst, aVLast);
453   BRep_Builder().UpdateVertex(aVFirst, theTolerance);
454 }
455
456 void GeomAPI_Edge::setLastPointTolerance(const double theTolerance)
457 {
458   TopoDS_Edge anEdge = impl<TopoDS_Edge>();
459   TopoDS_Vertex aVFirst, aVLast;
460   TopExp::Vertices(anEdge, aVFirst, aVLast);
461   BRep_Builder().UpdateVertex(aVLast, theTolerance);
462 }
463
464 GeomPointPtr GeomAPI_Edge::middlePoint() const
465 {
466   GeomPointPtr aMiddlePoint;
467
468   const TopoDS_Edge& anEdge = impl<TopoDS_Edge>();
469   if (anEdge.IsNull())
470     return aMiddlePoint;
471   double aFirst, aLast;
472   Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
473   if (aCurve.IsNull())
474     return aMiddlePoint;
475
476   static const int NB_POINTS = 3;
477   GeomAdaptor_Curve aCurveAdaptor(aCurve, aFirst, aLast);
478   GCPnts_UniformAbscissa anAlgo(aCurveAdaptor, NB_POINTS);
479   if (anAlgo.IsDone()) {
480     gp_Pnt aPnt = aCurveAdaptor.Value(anAlgo.Parameter(2));
481     aMiddlePoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
482   }
483   return aMiddlePoint;
484 }