1 // Copyright (c) 2020 OPEN CASCADE SAS
2 //
3 // This file is part of the examples of the Open CASCADE Technology software library.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
21 
22 #include "GeometrySamples.h"
23 
24 #include <limits>
25 
26 #include <gp_Pnt.hxx>
27 #include <gp_XYZ.hxx>
28 #include <gp_Vec.hxx>
29 #include <gp_Dir.hxx>
30 #include <gp_Ax1.hxx>
31 #include <gp_Ax2.hxx>
32 #include <gp_Ax3.hxx>
33 #include <gp_Lin.hxx>
34 #include <gp_Circ.hxx>
35 #include <gp_Elips.hxx>
36 #include <gp_Parab.hxx>
37 #include <gp_Hypr.hxx>
38 #include <gp_Cylinder.hxx>
39 #include <gp_Cone.hxx>
40 #include <gp_Sphere.hxx>
41 #include <gp_Torus.hxx>
42 
43 #include <gp_Pnt2d.hxx>
44 #include <gp_XY.hxx>
45 #include <gp_Ax2d.hxx>
46 #include <gp_Ax22d.hxx>
47 #include <gp_Lin2d.hxx>
48 #include <gp_Circ2d.hxx>
49 #include <gp_Elips2d.hxx>
50 #include <gp_Parab2d.hxx>
51 #include <gp_Hypr2d.hxx>
52 #include <Geom2d_BSplineCurve.hxx>
53 #include <Geom2d_BezierCurve.hxx>
54 #include <Geom2d_OffsetCurve.hxx>
55 #include <ProjLib.hxx>
56 #include <ElSLib.hxx>
57 #include <Extrema_ExtElCS.hxx>
58 #include <Extrema_POnCurv.hxx>
59 #include <IntAna_Quadric.hxx>
60 #include <IntAna_IntConicQuad.hxx>
61 #include <GccAna_Lin2d2Tan.hxx>
62 #include <GccEnt_QualifiedCirc.hxx>
63 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
64 #include <Geom2dAPI_ExtremaCurveCurve.hxx>
65 #include <Geom2dAPI_InterCurveCurve.hxx>
66 #include <Geom2dAPI_PointsToBSpline.hxx>
67 
68 #include <Geom_CartesianPoint.hxx>
69 #include <Geom_VectorWithMagnitude.hxx>
70 #include <Geom_Axis1Placement.hxx>
71 #include <Geom_Axis2Placement.hxx>
72 #include <Geom_Line.hxx>
73 #include <Geom_Circle.hxx>
74 #include <Geom_Ellipse.hxx>
75 #include <Geom_Parabola.hxx>
76 #include <Geom_Hyperbola.hxx>
77 #include <Geom_BSplineCurve.hxx>
78 #include <Geom_BezierCurve.hxx>
79 #include <Geom_TrimmedCurve.hxx>
80 #include <Geom_OffsetCurve.hxx>
81 #include <Geom_BSplineSurface.hxx>
82 #include <Geom_BezierSurface.hxx>
83 #include <Geom_Plane.hxx>
84 #include <Geom_CylindricalSurface.hxx>
85 #include <Geom_ConicalSurface.hxx>
86 #include <Geom_SphericalSurface.hxx>
87 #include <Geom_ToroidalSurface.hxx>
88 #include <Geom_RectangularTrimmedSurface.hxx>
89 #include <Geom_OffsetSurface.hxx>
90 #include <Geom_SurfaceOfLinearExtrusion.hxx>
91 #include <Geom_SurfaceOfRevolution.hxx>
92 
93 #include <BndLib_Add3dCurve.hxx>
94 #include <BndLib_AddSurface.hxx>
95 #include <GeomAdaptor_Curve.hxx>
96 #include <GeomAdaptor_Surface.hxx>
97 #include <GeomAPI_PointsToBSpline.hxx>
98 #include <GeomAPI_PointsToBSplineSurface.hxx>
99 #include <GeomConvert.hxx>
100 
101 #include "AdaptorPnt2d_AIS.h"
102 #include "AdaptorVec_AIS.h"
103 #include "AdaptorCurve_AIS.h"
104 #include "AdaptorCurve2d_AIS.h"
105 
106 #include <Geom2d_CartesianPoint.hxx>
107 #include <Geom2d_VectorWithMagnitude.hxx>
108 #include <Geom2d_Line.hxx>
109 #include <Geom2d_Circle.hxx>
110 #include <Geom2d_Ellipse.hxx>
111 #include <Geom2d_Parabola.hxx>
112 #include <Geom2d_Hyperbola.hxx>
113 #include <Geom2d_TrimmedCurve.hxx>
114 #include <Geom2dAdaptor_Curve.hxx>
115 #include <Bnd_Box2d.hxx>
116 #include <BndLib_Add2dCurve.hxx>
117 #include <Adaptor2d_Curve2d.hxx>
118 
119 #include <BRepBuilderAPI_MakeEdge.hxx>
120 #include <BRepBuilderAPI_MakeFace.hxx>
121 #include <BRepPrimAPI_MakeBox.hxx>
122 
123 #include <AIS_Point.hxx>
124 #include <AIS_TextLabel.hxx>
125 #include <AIS_Axis.hxx>
126 #include <AIS_InteractiveContext.hxx>
127 #include <AIS_Circle.hxx>
128 #include <AIS_Plane.hxx>
129 #include <AIS_Shape.hxx>
130 #include <AIS_ColoredShape.hxx>
131 
132 #include <GProp_PEquation.hxx>
133 
ExecuteSample(const TCollection_AsciiString & theSampleName)134 void GeometrySamples::ExecuteSample (const TCollection_AsciiString& theSampleName)
135 {
136   Standard_Boolean anIsSamplePresent = Standard_True;
137   FindSourceCode(theSampleName);
138   if (theSampleName == "ZeroDimensionObjects3dSample")
139     ZeroDimensionObjects3dSample();
140   else if (theSampleName == "Vectors3dSample")
141     Vectors3dSample();
142   else if (theSampleName == "InfinityLines3dSample")
143     InfinityLines3dSample();
144   else if (theSampleName == "SecondOrderCurves3dSample")
145     SecondOrderCurves3dSample();
146   else if (theSampleName == "PlaneSurfaces3dSample")
147     PlaneSurfaces3dSample();
148   else if (theSampleName == "SecondOrderSurfaces3dSample")
149     SecondOrderSurfaces3dSample();
150   else if (theSampleName == "ZeroDimensionObjects2dSample")
151     ZeroDimensionObjects2dSample();
152   else if (theSampleName == "Vectors2dSample")
153     Vectors2dSample();
154   else if (theSampleName == "InfinityLines2dSample")
155     InfinityLines2dSample();
156   else if (theSampleName == "SecondOrderCurves2dSample")
157     SecondOrderCurves2dSample();
158   else if (theSampleName == "BarycenterPoint3dSample")
159     BarycenterPoint3dSample();
160   else if (theSampleName == "RotatedVector3dSample")
161     RotatedVector3dSample();
162   else if (theSampleName == "MirroredLine3dSample")
163     MirroredLine3dSample();
164   else if (theSampleName == "ScaledEllipse3dSample")
165     ScaledEllipse3dSample();
166   else if (theSampleName == "TransformedCylinder3dSample")
167     TransformedCylinder3dSample();
168   else if (theSampleName == "TranslatedTorus3dSample")
169     TranslatedTorus3dSample();
170   else if (theSampleName == "ConjugateObjects3dSample")
171     ConjugateObjects3dSample();
172   else if (theSampleName == "ProjectionOfPoint3dSample")
173     ProjectionOfPoint3dSample();
174   else if (theSampleName == "MinimalDistance3dSample")
175     MinimalDistance3dSample();
176   else if (theSampleName == "MirroredAxis2dSample")
177     MirroredAxis2dSample();
178   else if (theSampleName == "TransformedEllipse2dSample")
179     TransformedEllipse2dSample();
180   else if (theSampleName == "ConjugateObjects2dSample")
181     ConjugateObjects2dSample();
182   else if (theSampleName == "Intersection3dSample")
183     Intersection3dSample();
184   else if (theSampleName == "TranslatedPoint2dSample")
185     TranslatedPoint2dSample();
186   else if (theSampleName == "RotatedDirection2dSample")
187     RotatedDirection2dSample();
188   else if (theSampleName == "Tangent2dSample")
189     Tangent2dSample();
190   else if (theSampleName == "ProjectionOfPoint2dSample")
191     ProjectionOfPoint2dSample();
192   else if (theSampleName == "MinimalDistance2dSample")
193     MinimalDistance2dSample();
194   else if (theSampleName == "Intersection2dSample")
195     Intersection2dSample();
196   else if (theSampleName == "PointInfo3dSample")
197     PointInfo3dSample();
198   else if (theSampleName == "EllipseInfo3dSample")
199     EllipseInfo3dSample();
200   else if (theSampleName == "PointInfo2dSample")
201     PointInfo2dSample();
202   else if (theSampleName == "CircleInfo2dSample")
203     CircleInfo2dSample();
204   else if (theSampleName == "SecondOrderCurves3dSample")
205     SecondOrderCurves3dSample();
206   else if (theSampleName == "FreeStyleCurves3dSample")
207     FreeStyleCurves3dSample();
208   else if (theSampleName == "AnalyticalSurfaces3dSample")
209     AnalyticalSurfaces3dSample();
210   else if (theSampleName == "FreeStyleSurfaces3dSample")
211     FreeStyleSurfaces3dSample();
212   else if (theSampleName == "SecondOrderCurves2dSample")
213     SecondOrderCurves2dSample();
214   else if (theSampleName == "FreeStyleCurves2dSample")
215     FreeStyleCurves2dSample();
216   else if (theSampleName == "TrimmedCurve3dSample")
217     TrimmedCurve3dSample();
218   else if (theSampleName == "OffsetCurve3dSample")
219     OffsetCurve3dSample();
220   else if (theSampleName == "BSplineFromCircle3dSample")
221     BSplineFromCircle3dSample();
222   else if (theSampleName == "TrimmedSurface3dSample")
223     TrimmedSurface3dSample();
224   else if (theSampleName == "OffsetSurface3dSample")
225     OffsetSurface3dSample();
226   else if (theSampleName == "ExtrusionSurface3dSample")
227     ExtrusionSurface3dSample();
228   else if (theSampleName == "RevolutionSurface3dSample")
229     RevolutionSurface3dSample();
230   else if (theSampleName == "TrimmedCurve2dSample")
231     TrimmedCurve2dSample();
232   else if (theSampleName == "OffsetCurve2dSample")
233     OffsetCurve2dSample();
234   else if (theSampleName == "BoundingBoxOfSurface3dSample")
235     BoundingBoxOfSurface3dSample();
236   else if (theSampleName == "BoundingBoxOfCurves3dSample")
237     BoundingBoxOfCurves3dSample();
238   else if (theSampleName == "BoundingBoxOfCurves2dSample")
239     BoundingBoxOfCurves2dSample();
240   else if (theSampleName == "DumpCircleInfoSample")
241     DumpCircleInfoSample();
242   else if (theSampleName == "DumpBSplineCurveInfoSample")
243     DumpBSplineCurveInfoSample();
244   else
245   {
246     myResult << "No function found: " << theSampleName;
247     myCode += TCollection_AsciiString("No function found: ") + theSampleName;
248     anIsSamplePresent = Standard_False;
249   }
250   myIsProcessed = anIsSamplePresent;
251 }
252 
DisplayPnt(const gp_Pnt2d & thePnt2d,const TCollection_AsciiString & theText,Aspect_TypeOfMarker theMarker,Standard_Real theDistance)253 void GeometrySamples::DisplayPnt (const gp_Pnt2d& thePnt2d, const TCollection_AsciiString& theText,
254                                   Aspect_TypeOfMarker theMarker, Standard_Real theDistance)
255 {
256   gp_Pnt aPnt(thePnt2d.X(), thePnt2d.Y(), 0.0);
257   Handle(Geom_CartesianPoint) aGeomPoint = new Geom_CartesianPoint(aPnt);
258   Handle(AIS_Point) anAisPoint = new AIS_Point(aGeomPoint);
259   anAisPoint->SetMarker(theMarker);
260   myObject2d.Append(anAisPoint);
261   Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel();
262   aPntLabel->SetText(theText);
263   aPntLabel->SetPosition(gp_Pnt(aPnt.X(), aPnt.Y() + theDistance, aPnt.Z()));
264   myObject2d.Append(aPntLabel);
265 }
DisplayPnt(const gp_Pnt & thePnt,const TCollection_AsciiString & theText,Aspect_TypeOfMarker theMarker,Standard_Real theDistance)266 void GeometrySamples::DisplayPnt (const gp_Pnt& thePnt, const TCollection_AsciiString& theText,
267                                   Aspect_TypeOfMarker theMarker, Standard_Real theDistance)
268 {
269   Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(thePnt);
270   Handle(AIS_Point) anAisPoint = new AIS_Point(aPoint);
271   anAisPoint->SetMarker(theMarker);
272   myObject3d.Append(anAisPoint);
273   Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel();
274   aPntLabel->SetText(theText);
275   aPntLabel->SetPosition(gp_Pnt(thePnt.X(), thePnt.Y(), thePnt.Z() + theDistance));
276   myObject3d.Append(aPntLabel);
277 }
278 
ZeroDimensionObjects3dSample()279 void GeometrySamples::ZeroDimensionObjects3dSample()
280 {
281   // gp_Pnt describes a point in 3D space. A Geom_CartesianPoint is defined by
282   // a gp_Pnt point, with its three Cartesian coordinates X, Y and Z.
283   gp_Pnt aCoordPnt(10.0, 20.0, 30.0);
284   Handle(Geom_CartesianPoint) aCoordGeomPoint = new Geom_CartesianPoint(aCoordPnt);
285   Handle(AIS_Point) aCoordAisPoint = new AIS_Point(aCoordGeomPoint);
286   myObject3d.Append(aCoordAisPoint);
287 
288   Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel();
289   aPntLabel->SetText("  gp_Pnt");
290   aPntLabel->SetPosition(gp_Pnt(aCoordPnt.X(), aCoordPnt.Y(), aCoordPnt.Z() + 5.0));
291   myObject3d.Append(aPntLabel);
292   myResult << "gp_Pnt was created" << std::endl;
293 
294   // gp_XYZ class describes a Cartesian coordinate entity in 3D space (X,Y,Z).
295   // This entity is used for algebraic calculation.
296   // This entity can be transformed with a "Trsf" or a "GTrsf" from package "gp".
297   // It is used in vectorial computations or for holding this type of information
298   // in data structures.
299   gp_XYZ aXyz1(10.0, 20.0, 30.0);
300   gp_XYZ aXyz2(20.0, 10.0, 30.0);
301   gp_XYZ aXyzSum = aXyz1 + aXyz2;
302   gp_Pnt aSumPnt(aXyzSum);
303   Handle(Geom_CartesianPoint) aXyzGeomPoint = new Geom_CartesianPoint(aSumPnt);
304   Handle(AIS_Point) aSumAisPoint = new AIS_Point(aXyzGeomPoint);
305   myObject3d.Append(aSumAisPoint);
306 
307   Handle(AIS_TextLabel) aXyzLabel = new AIS_TextLabel();
308   aXyzLabel->SetText("  gp_XYZ");
309   aXyzLabel->SetPosition(gp_Pnt(aXyzSum.X(), aXyzSum.Y(), aXyzSum.Z() + 5.0));
310   myObject3d.Append(aXyzLabel);
311   myResult << "gp_XYZ was created" << std::endl;
312 }
313 
Vectors3dSample()314 void GeometrySamples::Vectors3dSample()
315 {
316   gp_Pnt aPnt1(0.0, 0.0, 0.0);
317   gp_Pnt aPnt2(5.0, 0.0, 0.0);
318 
319   // gp_Vec defines a non-persistent vector in 3D space.
320   gp_Vec aVec(aPnt1, aPnt2);
321   Handle(AdaptorVec_AIS) aVecAIS = new AdaptorVec_AIS(aPnt1, aVec, 0.5);
322   aVecAIS->SetText("  gp_Vec");
323   myObject3d.Append(aVecAIS);
324   myResult << "gp_Vec magnitude: " << aVec.Magnitude() << std::endl;
325 
326   // Describes a unit vector in 3D space.
327   // This unit vector is also called "Direction".
328   // See Also gce_MakeDir which provides functions for more complex unit vector
329   // constructions Geom_Direction which provides additional functions
330   // for constructing unit vectors and works, in particular,
331   // with the parametric equations of unit vectors.
332   gp_Dir aDir(aVec);
333   Handle(AdaptorVec_AIS) aDirAIS = new AdaptorVec_AIS(gp_Pnt(0.0, 0.0, 10.0), aDir, 1.0, 0.5);
334   aDirAIS->SetText("  gp_Dir");
335   myObject3d.Append(aDirAIS);
336   myResult << "gp_Dir coordinates: X: " << aDir.X() << ", Y: " << aDir.Y() << ", Z: " << aDir.Z() << std::endl;
337 }
338 
InfinityLines3dSample()339 void GeometrySamples::InfinityLines3dSample()
340 {
341   gp_Pnt aBasePoint(0.0, 0.0, 0.0);
342   gp_Dir aX_Direction(1.0, 0.0, 0.0);
343   gp_Dir anY_Direction(0.0, 1.0, 0.0);
344   gp_Dir aZ_Direction(0.0, 0.0, 1.0);
345 
346   // Describes an axis in 3D space.
347   gp_Ax1 anAxis1(aBasePoint, aZ_Direction);
348   Handle(AdaptorVec_AIS) anAx1Ais = new AdaptorVec_AIS(anAxis1.Location(), anAxis1.Direction(), 1.0, 0.3);
349   anAx1Ais->SetText("  gp_Ax1");
350   myObject3d.Append(anAx1Ais);
351   myResult << "gp_Ax1 was created" << std::endl << std::endl;
352 
353   //  Describes a right - handed coordinate system in 3D space.
354   aBasePoint.SetCoord(0.0, 0.0, 3.0);
355   gp_Ax2 anAxis2(aBasePoint, aZ_Direction);
356   Handle(AdaptorVec_AIS) aAx2AisZ = new AdaptorVec_AIS(anAxis2.Location(), anAxis2.Direction(), 1.0, 0.3);
357   aAx2AisZ->SetText("  gp_Ax2 Z");
358   myObject3d.Append(aAx2AisZ);
359   Handle(AdaptorVec_AIS) aAx2AisX = new AdaptorVec_AIS(anAxis2.Location(), anAxis2.XDirection(), 1.0, 0.3);
360   aAx2AisX->SetText("  gp_Ax2 X");
361   myObject3d.Append(aAx2AisX);
362   Handle(AdaptorVec_AIS) aAx2AisY = new AdaptorVec_AIS(anAxis2.Location(), anAxis2.YDirection(), 1.0, 0.3);
363   aAx2AisY->SetText("  gp_Ax2 Y");
364   myObject3d.Append(aAx2AisY);
365   myResult << "gp_Ax2 was created" << std::endl;
366 
367   // Describes a coordinate system in 3D space.Unlike a gp_Ax2 coordinate system,
368   // a gp_Ax3 can be right - handed("direct sense") or left - handed("indirect sense").
369   gp_Ax3 anAxis3(gp_XYZ(0.0, 0.0, 6.0), aZ_Direction, aX_Direction);
370   anAxis3.YReverse();
371   Handle(AdaptorVec_AIS) anAx3AisZ = new AdaptorVec_AIS(anAxis3.Location(), anAxis3.Direction(), 1.0, 0.3);
372   anAx3AisZ->SetText("  gp_Ax3 Z");
373   myObject3d.Append(anAx3AisZ);
374   Handle(AdaptorVec_AIS) anAx3AisX = new AdaptorVec_AIS(anAxis3.Location(), anAxis3.XDirection(), 1.0, 0.3);
375   anAx3AisX->SetText("  gp_Ax3 X");
376   myObject3d.Append(anAx3AisX);
377   Handle(AdaptorVec_AIS) anAx3AisY = new AdaptorVec_AIS(anAxis3.Location(), anAxis3.YDirection(), 1.0, 0.3);
378   anAx3AisY->SetText("  gp_Ax3 Y");
379   myObject3d.Append(anAx3AisY);
380 
381   myResult << "gp_Ax3 was created" << std::endl;
382   const gp_Dir& anAxis3_xDir = anAxis3.XDirection();
383   const gp_Dir& anAxis3_yDir = anAxis3.YDirection();
384   myResult << "gp_Ax3 X direction: " << anAxis3_xDir.X() << " " << anAxis3_xDir.Y() << " " << anAxis3_xDir.Z() << std::endl;
385   myResult << "gp_Ax3 Y direction: " << anAxis3_yDir.X() << " " << anAxis3_yDir.Y() << " " << anAxis3_yDir.Z() << std::endl;
386   TCollection_AsciiString aDirectionDescription;
387   if (anAxis3.Direct())
388   {
389     aDirectionDescription = "anAxis3 is a right-handed axis system";
390   }
391   else
392   {
393     aDirectionDescription = "anAxis3 is a left-handed axis system";
394   }
395   myResult << aDirectionDescription << std::endl << std::endl;
396 
397   // Describes a line in 3D space. A line is positioned in space with an axis
398   // (a gp_Ax1 object) which gives it an origin and a unit vector.
399   gp_Lin aLine(gp_Pnt(5.0, 0.0, 0.0), gp_Dir(0.0, 1.0, 0.0));
400   Handle(AdaptorVec_AIS) anLineAis = new AdaptorVec_AIS(aLine.Location(), aLine.Direction(), 8.0);
401   anLineAis->SetText("  gp_Lin");
402   myObject3d.Append(anLineAis);
403   myResult << "gp_Lin was created" << std::endl << std::endl;
404 }
405 
SecondOrderCurves3dSample()406 void GeometrySamples::SecondOrderCurves3dSample()
407 {
408   gp_Ax2 anAxis2(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0));
409   gp_Circ aCirc(anAxis2, 10.0);
410   Handle(Geom_Circle) aGeomCircle = new Geom_Circle(aCirc);
411   Handle(AIS_Circle) anAisCircle = new AIS_Circle(aGeomCircle);
412   myObject3d.Append(anAisCircle);
413 
414   // Describes an ellipse in 3D space. An ellipse is defined by its major and minor
415   // radii and positioned in space with a coordinate system (a gp_Ax2 object)
416   gp_Elips anElips(anAxis2.Translated(gp_Vec(0.0, 0.0, 10.0)), 20.0, 10.0);
417   Handle(Geom_Ellipse) aGeomEllipse = new Geom_Ellipse(anElips);
418   Handle(AdaptorCurve_AIS) anAisEllipce = new AdaptorCurve_AIS(aGeomEllipse);
419   myObject3d.Append(anAisEllipce);
420 
421   // Describes a parabola in 3D space. A parabola is defined by its focal length
422   // (that is, the distance between its focus and apex) and positioned in space with
423   // a coordinate system (a gp_Ax2 object)
424   gp_Parab aParab(anAxis2.Translated(gp_Vec(0.0, 0.0, 20.0)), 2.0);
425   Handle(Geom_Parabola) aGeomParabola = new Geom_Parabola(aParab);
426   Handle(Geom_TrimmedCurve) aTrimmedParabola = new Geom_TrimmedCurve(aGeomParabola, 20.0, -20.0);
427   Handle(AdaptorCurve_AIS) anAisParabola = new AdaptorCurve_AIS(aTrimmedParabola);
428   myObject3d.Append(anAisParabola);
429 
430   // Describes a branch of a hyperbola in 3D space. A hyperbola is defined by its major
431   // and minor radii and positioned in space with a coordinate system (a gp_Ax2 object)
432   gp_Hypr aHypr(anAxis2.Translated(gp_Vec(0.0, 0.0, 30.0)), 20.0, 10.0);
433   Handle(Geom_Hyperbola) aGeomHyperbola = new Geom_Hyperbola(aHypr);
434   Handle(Geom_TrimmedCurve) aTrimmedHyperbola = new Geom_TrimmedCurve(aGeomHyperbola, 2.0, -2.0);
435   Handle(AdaptorCurve_AIS) anAisHyperbola = new AdaptorCurve_AIS(aTrimmedHyperbola);
436   myObject3d.Append(anAisHyperbola);
437 }
438 
PlaneSurfaces3dSample()439 void GeometrySamples::PlaneSurfaces3dSample()
440 {
441   // Describes a plane.A plane is positioned in space with a coordinate system(a gp_Ax3 object),
442   // such that the plane is defined by the origin, "X Direction" and "Y Direction" of this
443   // coordinate system, which is the "local coordinate system" of the plane.The "main Direction"
444   // of the coordinate system is a vector normal to the plane.
445   gp_Pln aPln(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0));
446   Handle(Geom_Plane) aPlane = new Geom_Plane(aPln);
447   Handle(AIS_Plane) anAisPlane = new AIS_Plane(aPlane, aPln.Location(),
448     gp_Pnt(10.0, 10.0, 0.0),
449     gp_Pnt(-10.0, -10.0, 0.0),
450     Standard_False);
451   myObject3d.Append(anAisPlane);
452 
453   // Describes an infinite cylindrical surface.A cylinder is defined by its radius and positioned
454   // in space with a coordinate system(a gp_Ax3 object), the "main Axis" of which is the axis of
455   // the cylinder.This coordinate system is the "local coordinate system" of the cylinder.
456   gp_Cylinder aCylinder(gp_Ax3(gp_Pnt(0.0, 0.0, 10.0), gp_Dir(0.0, 0.0, 1.0)), 10.0);
457   Handle(Geom_CylindricalSurface) aCylindricalSurface = new Geom_CylindricalSurface(aCylinder);
458   Handle(AIS_Shape) anAisCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace(
459     aCylindricalSurface, 0.0, 2.0*M_PI, 0.0, 10.0, Precision::Confusion()).Shape());
460   myObject3d.Append(anAisCylinder);
461 
462   // Defines an infinite conical surface. A cone is defined by its half-angle (can be negative) at
463   // the apex and positioned in space with a coordinate system (a gp_Ax3 object) and a "reference radius"
464   gp_Cone aCone(gp_Ax3(gp_Pnt(0.0, 0.0, 30.0), gp_Dir(0.0, 0.0, 1.0)), 0.25*M_PI, 0.0);
465   Handle(Geom_ConicalSurface) aConicalSurface = new Geom_ConicalSurface(aCone);
466   Handle(AIS_Shape) anAisCone = new AIS_Shape(BRepBuilderAPI_MakeFace(
467     aConicalSurface, 0.0, 2.0*M_PI, 0.0, 20.0, Precision::Confusion()).Shape());
468   myObject3d.Append(anAisCone);
469 }
470 
SecondOrderSurfaces3dSample()471 void GeometrySamples::SecondOrderSurfaces3dSample()
472 {
473   gp_Sphere aSphere(gp_Ax3(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)), 10.0);
474   Handle(Geom_SphericalSurface) aSphericalSurface = new Geom_SphericalSurface(aSphere);
475   Handle(AIS_Shape) anAisSphere = new AIS_Shape(BRepBuilderAPI_MakeFace(
476     aSphericalSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape());
477   myObject3d.Append(anAisSphere);
478 
479   gp_Torus aTorus(gp_Ax3(gp_Pnt(0.0, 0.0, 20.0), gp_Dir(0.0, 0.0, 1.0)), 40.0, 10.0);
480   Handle(Geom_ToroidalSurface) aToroidalSurface = new Geom_ToroidalSurface(aTorus);
481   Handle(AIS_Shape) anAisTorus = new AIS_Shape(BRepBuilderAPI_MakeFace(
482     aToroidalSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape());
483   myObject3d.Append(anAisTorus);
484 }
485 
ZeroDimensionObjects2dSample()486 void GeometrySamples::ZeroDimensionObjects2dSample()
487 {
488   // Defines a non-persistent 2D Cartesian point.
489   gp_Pnt2d aCoordPnt(10.0, 20.0);
490   Handle(Geom2d_CartesianPoint) aCoordGeomPoint = new Geom2d_CartesianPoint(aCoordPnt);
491   Handle(AdaptorPnt2d_AIS) aCoordAisPoint = new AdaptorPnt2d_AIS(aCoordGeomPoint);
492   myObject2d.Append(aCoordAisPoint);
493 
494   Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel();
495   aPntLabel->SetText("gp_Pnt2d");
496   aPntLabel->SetPosition(gp_Pnt(aCoordPnt.X(), aCoordPnt.Y() + 0.5, 0.0));
497   myObject2d.Append(aPntLabel);
498   myResult << "gp_Pnt was created" << std::endl;
499 
500   // This class describes a Cartesian coordinate entity in 2D space{ X,Y }.
501   // This class is non persistent.This entity used for algebraic calculation.
502   // An XY can be transformed with a Trsf2d or a GTrsf2d from package gp.
503   // It is used in vectorial computations or for holding this type of information in data structures.
504   gp_XY aXy(20.0, 10.0);
505   Handle(Geom2d_CartesianPoint) aXyGeomPoint = new Geom2d_CartesianPoint(aXy);
506   Handle(AdaptorPnt2d_AIS) aXyAisPoint = new AdaptorPnt2d_AIS(aXyGeomPoint);
507   myObject2d.Append(aXyAisPoint);
508 
509   Handle(AIS_TextLabel) aXyLabel = new AIS_TextLabel();
510   aXyLabel->SetText("  gp_XY");
511   aXyLabel->SetPosition(gp_Pnt(aXy.X(), aXy.Y() + 0.5, 0.0));
512   myObject2d.Append(aXyLabel);
513   myResult << "gp_XY was created" << std::endl;
514 }
515 
Vectors2dSample()516 void GeometrySamples::Vectors2dSample()
517 {
518   // Describes a unit vector in the plane (2D space).
519   // This unit vector is also called "Direction".
520   gp_Dir2d aDir(3.0, 4.0);
521   Handle(AdaptorVec_AIS) anAisDir = new AdaptorVec_AIS(gp_Pnt2d(0.0, 0.0), aDir, 1.0, 0.3);
522   anAisDir->SetText("  gp_Dir2d");
523   myObject2d.Append(anAisDir);
524   myResult << "gp_Dir2d coordinates: X: " << aDir.X() << ", Y: " << aDir.Y() << std::endl;
525 
526   // Defines a non-persistent vector in 2D space.
527   gp_Vec2d aVec(aDir);
528   aVec = aVec * 2;
529   Handle(AdaptorVec_AIS) anAisVec = new AdaptorVec_AIS(gp_Pnt2d(0.0, 5.0), aVec, 0.3);
530   anAisVec->SetText("  gp_Vec2d");
531   myObject2d.Append(anAisVec);
532   myResult << "gp_Vec2d magnitude: " << aVec.Magnitude() << std::endl;
533 }
534 
InfinityLines2dSample()535 void GeometrySamples::InfinityLines2dSample()
536 {
537   // Describes an axis in the plane (2D space)
538   gp_Ax2d anAx2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 0.0));
539   Handle(AdaptorVec_AIS) anAisAx2d = new AdaptorVec_AIS(anAx2d.Location(), anAx2d.Direction(), 1.0, 0.3);
540   anAisAx2d->SetText("  gp_Ax2d");
541   myObject2d.Append(anAisAx2d);
542 
543   // Describes a coordinate system in a plane (2D space).
544   gp_Ax22d anAx22d(gp_Pnt2d(0.0, 2.0), gp_Dir2d(1.0, 1.0), Standard_False);
545   Handle(AdaptorVec_AIS) anAisAx2d_X = new AdaptorVec_AIS(anAx22d.Location(), anAx22d.XDirection(), 1.0, 0.3);
546   anAisAx2d_X->SetText("  gp_Ax2d X");
547   myObject2d.Append(anAisAx2d_X);
548   Handle(AdaptorVec_AIS) anAisAx2d_Y = new AdaptorVec_AIS(anAx22d.Location(), anAx22d.YDirection(), 1.0, 0.3);
549   anAisAx2d_Y->SetText("  gp_Ax2d Y");
550   myObject2d.Append(anAisAx2d_Y);
551 
552   // Describes a line in 2D space. A line is positioned in the plane with an axis (a gp_Ax2d object) which gives
553   // the line its origin and unit vector. A line and an axis are similar objects, thus,
554   // we can convert one into the other. A line provides direct access to the majority of the edit and query
555   // functions available on its positioning axis.
556   gp_Lin2d aLin2d(gp_Pnt2d(2.0, 4.0), gp_Dir2d(0.0, -1.0));
557   Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aLin2d.Location(), aLin2d.Direction(), 1.0, 0.3);
558   anAisLin->SetText("  gp_Lin2d");
559   myObject2d.Append(anAisLin);
560 }
561 
SecondOrderCurves2dSample()562 void GeometrySamples::SecondOrderCurves2dSample()
563 {
564   // Describes a circle in the plane (2D space). A circle is defined by its radius
565   // and positioned in the plane with a coordinate system (a gp_Ax22d object)
566   gp_Circ2d aCirc2d;
567   aCirc2d.SetLocation(gp_Pnt2d(0.0, 0.0));
568   aCirc2d.SetRadius(10.0);
569   Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(aCirc2d);
570   Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle, Aspect_TOL_SOLID);
571   myObject2d.Append(anAisCirc);
572 
573   // Describes an ellipse in the plane (2D space). An ellipse is defined by its major
574   // and minor radii and positioned in the plane with a coordinate system (a gp_Ax22d object)
575   gp_Elips2d anElips(gp_Ax2d(gp_Pnt2d(0.0, 30.0), gp_Dir2d(1.0, 0.0)), 20.0, 10.0);
576   Handle(Geom2d_Ellipse) aGeomEllipse = new Geom2d_Ellipse(anElips);
577   Handle(AdaptorCurve2d_AIS) anAisEllipse = new AdaptorCurve2d_AIS(aGeomEllipse, Aspect_TOL_DASH);
578   myObject2d.Append(anAisEllipse);
579 
580   // Describes a parabola in the plane (2D space). A parabola is defined by its focal length
581   // (that is, the distance between its focus and apex) and positioned in the plane with
582   // a coordinate system (a gp_Ax22d object)
583   gp_Parab2d aParab2d(gp_Ax2d(gp_Pnt2d(20.0, 0.0), gp_Dir2d(1.0, 0.0)), 10.0);
584   Handle(Geom2d_Parabola) aGeomParabola = new Geom2d_Parabola(aParab2d);
585   Handle(Geom2d_TrimmedCurve) aTrimmedParabola = new Geom2d_TrimmedCurve(aGeomParabola, 40.0, -40.0);
586   Handle(AdaptorCurve2d_AIS) anAisParabola = new AdaptorCurve2d_AIS(aTrimmedParabola, Aspect_TOL_DOT);
587   myObject2d.Append(anAisParabola);
588 
589   // Describes a branch of a hyperbola in the plane (2D space). A hyperbola is defined by its major and
590   // minor radii, and positioned in the plane with a coordinate system (a gp_Ax22d object)
591   gp_Hypr2d aHypr2d(gp_Ax2d(gp_Pnt2d(20.0, 0.0), gp_Dir2d(1.0, 0.0)), 20.0, 10.0);
592   Handle(Geom2d_Hyperbola) aGeomHyperbola = new Geom2d_Hyperbola(aHypr2d);
593   Handle(Geom2d_TrimmedCurve) aTrimmedHyperbola = new Geom2d_TrimmedCurve(aGeomHyperbola, 2.0, -2.0);
594   Handle(AdaptorCurve2d_AIS) anAisHyperbola = new AdaptorCurve2d_AIS(aTrimmedHyperbola, Aspect_TOL_DOTDASH);
595   myObject2d.Append(anAisHyperbola);
596 }
597 
BarycenterPoint3dSample()598 void GeometrySamples::BarycenterPoint3dSample()
599 {
600   // Barycenter of 2 points
601   gp_Pnt aPnt1(11, 2, 3);
602   gp_Pnt aPnt2(13, 4, 5);
603   gp_Pnt aBarycenterPnt2 = aPnt1;
604   Standard_Real anAlpha = 3;
605   Standard_Real anBeta = 7;
606   // Assigns the result of the following expression to this point:
607   // (Alpha*this + Beta*P) / (Alpha + Beta)
608   aBarycenterPnt2.BaryCenter(anAlpha, aPnt2, anBeta);
609   DisplayPnt(aPnt1, "Pnt1", Aspect_TOM_PLUS, 0.5);
610   DisplayPnt(aPnt2, "Pnt2", Aspect_TOM_PLUS, 0.5);
611   DisplayPnt(aBarycenterPnt2, "Barycenter Pnt", Aspect_TOM_O_PLUS, 0.5);
612 
613   //  BaryCenter of an array of point
614   gp_Pnt aP1(0, 0, 5);
615   gp_Pnt aP2(1, 2, 3);
616   gp_Pnt aP3(2, 3, -2);
617   gp_Pnt aP4(4, 3, 5);
618   gp_Pnt aP5(5, 5, 4);
619   TColgp_Array1OfPnt aPntArray(1, 5);
620   aPntArray.SetValue(1, aP1);
621   aPntArray.SetValue(2, aP2);
622   aPntArray.SetValue(3, aP3);
623   aPntArray.SetValue(4, aP4);
624   aPntArray.SetValue(5, aP5);
625 
626   Standard_Real Tolerance = 8;
627   GProp_PEquation aPEquation(aPntArray, Tolerance);
628 
629   gp_Pnt aBarycenterPnt5; // P declaration
630   bool isPoint = false;
631   if (aPEquation.IsPoint())
632   {
633     isPoint = true;
634     aBarycenterPnt5 = aPEquation.Point();
635     myResult << "GProp_PEquation is a point" << std::endl;
636   }
637   else
638   {
639     isPoint = false;
640     myResult << "GProp_PEquation is not a point" << std::endl;
641   }
642 
643   if (aPEquation.IsLinear())
644   {
645     /*... */
646   }
647   if (aPEquation.IsPlanar())
648   {
649     /*... */
650   }
651   if (aPEquation.IsSpace())
652   {
653     /*... */
654   }
655 
656   const TCollection_AsciiString aPointName("P");
657   for (Standard_Integer i = aPntArray.Lower(); i <= aPntArray.Upper(); i++)
658   {
659     TCollection_AsciiString aString(i);
660     aString = aPointName + aString;
661     DisplayPnt(aPntArray(i), aString, Aspect_TOM_STAR, 0.5);
662   }
663 
664   DisplayPnt(aBarycenterPnt5, "Barycenter of 5 points", Aspect_TOM_O_STAR, 0.5);
665   myResult << " IsPoint = ";
666   if (isPoint)
667   {
668     myResult << "True   -->  " << " P ( " << aBarycenterPnt5.X() << aBarycenterPnt5.Y() << aBarycenterPnt5.Z() << " );" << std::endl;
669   }
670   else
671   {
672     myResult << "False";
673   }
674   myResult << std::endl << " IsLinear = " << (aPEquation.IsLinear() ? "True" : "False");
675   myResult << std::endl << " IsPlanar = " << (aPEquation.IsPlanar() ? "True" : "False");
676   myResult << std::endl << " IsSpace = "  << (aPEquation.IsSpace()  ? "True" : "False");
677 }
678 
RotatedVector3dSample()679 void GeometrySamples::RotatedVector3dSample()
680 {
681   gp_Vec aBaseVec(0.0, 0.0, 10.0);
682   gp_Pnt aZeroPnt(0.0, 0.0, 0.0);
683   gp_Vec aRotatedVec = aBaseVec.Rotated(gp_Ax1(aZeroPnt, gp_Dir(1.0, 0.0, 0.0)), M_PI_4);
684 
685   Handle(AdaptorVec_AIS) aBaseVecAIS = new AdaptorVec_AIS(aZeroPnt, aBaseVec);
686   aBaseVecAIS->SetText("  Base vector");
687   myObject3d.Append(aBaseVecAIS);
688   Handle(AdaptorVec_AIS) aRotatedVecAIS = new AdaptorVec_AIS(aZeroPnt, aRotatedVec);
689   aRotatedVecAIS->SetText("  Rotated vector");
690   myObject3d.Append(aRotatedVecAIS);
691   Standard_Real anAdgle = aBaseVec.Angle(aRotatedVec)*180.0 / M_PI;
692   myResult << "An angle between vectors = " << anAdgle << std::endl;
693 }
694 
MirroredLine3dSample()695 void GeometrySamples::MirroredLine3dSample()
696 {
697   gp_Lin aBaseLin(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(1.0, 1.0, 1.0));
698   gp_Ax2 aXyzAxis;
699   gp_Lin aMirroredLin = aBaseLin.Mirrored(aXyzAxis);
700 
701   Handle(AdaptorVec_AIS) aBaseLineAis = new AdaptorVec_AIS(aBaseLin.Location(), aBaseLin.Direction(), 8.0);
702   aBaseLineAis->SetText("  Base Line");
703   myObject3d.Append(aBaseLineAis);
704   Handle(AdaptorVec_AIS) aMirroredLineAis = new AdaptorVec_AIS(aMirroredLin.Location(), aMirroredLin.Direction(), 8.0);
705   aMirroredLineAis->SetText("  Mirrored Line");
706   myObject3d.Append(aMirroredLineAis);
707   Handle(AIS_Plane) anAisPlane = new AIS_Plane (new Geom_Plane(gp_Ax3(aXyzAxis)), aXyzAxis.Location(),
708                                                 gp_Pnt(10.0, 10.0, 0.0), gp_Pnt(-10.0, -10.0, 0.0), Standard_False);
709   myObject3d.Append(anAisPlane);
710   Standard_Real anAdgle = aBaseLin.Angle(aMirroredLin)*180.0 / M_PI;
711   myResult << "An angle between lines = " << anAdgle << std::endl;
712 }
713 
ScaledEllipse3dSample()714 void GeometrySamples::ScaledEllipse3dSample()
715 {
716   gp_Ax2 anAxis2(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0));
717   gp_Elips anBaseElips(anAxis2, 20.0, 10.0);
718   gp_Elips anScaledElips = anBaseElips.Scaled(gp_Pnt(), 2.5);
719 
720   Handle(Geom_Ellipse) aBaseGeomEllipse = new Geom_Ellipse(anBaseElips);
721   Handle(AdaptorCurve_AIS) anAisBaseEllipce = new AdaptorCurve_AIS(aBaseGeomEllipse);
722   myObject3d.Append(anAisBaseEllipce);
723 
724   Handle(Geom_Ellipse) aScaledGeomEllipse = new Geom_Ellipse(anScaledElips);
725   Handle(AdaptorCurve_AIS) anAisScaledEllipce = new AdaptorCurve_AIS(aScaledGeomEllipse);
726   myObject3d.Append(anAisScaledEllipce);
727 }
728 
TransformedCylinder3dSample()729 void GeometrySamples::TransformedCylinder3dSample()
730 {
731   gp_Cylinder aBaseCylinder(gp_Ax3(), 10.0);
732   gp_Trsf aRotTrsf;
733   aRotTrsf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(1.0, 0.0, 0.0)), M_PI_2);
734   gp_Trsf aScaleTrsf;
735   aScaleTrsf.SetScale(gp_Pnt(), 1.5);
736   gp_Trsf aTranslTrsf;
737   aTranslTrsf.SetTranslation(gp_Vec(30.0, 0.0, 0.0));
738   gp_Trsf aComplexTrsf = aRotTrsf * aScaleTrsf * aTranslTrsf;
739   gp_Cylinder aTransfCylinder = aBaseCylinder.Transformed(aComplexTrsf);
740 
741   Handle(Geom_CylindricalSurface) aBaseCylinderSurface = new Geom_CylindricalSurface(aBaseCylinder);
742   Handle(AIS_Shape) anAisBaseCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace(
743     aBaseCylinderSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape());
744   myObject3d.Append(anAisBaseCylinder);
745   Handle(Geom_CylindricalSurface) aTransfCylinderSurface = new Geom_CylindricalSurface(aTransfCylinder);
746   Handle(AIS_Shape) anAisTransfCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace(
747     aTransfCylinderSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape());
748   myObject3d.Append(anAisTransfCylinder);
749 }
750 
TranslatedTorus3dSample()751 void GeometrySamples::TranslatedTorus3dSample()
752 {
753   gp_Torus aBaseTorus(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 40.0, 10.0);
754   gp_Torus aTranslatedTorus = aBaseTorus.Translated(gp_Vec(70.0, 70.0, 70.0));
755 
756   Handle(Geom_ToroidalSurface) aBaseSurface = new Geom_ToroidalSurface(aBaseTorus);
757   Handle(AIS_Shape) anAisBaseShape = new AIS_Shape(BRepBuilderAPI_MakeFace(
758     aBaseSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape());
759   myObject3d.Append(anAisBaseShape);
760   Handle(Geom_ToroidalSurface) aTranslSurface = new Geom_ToroidalSurface(aTranslatedTorus);
761   Handle(AIS_Shape) anAisTranslShape = new AIS_Shape(BRepBuilderAPI_MakeFace(
762     aTranslSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape());
763   myObject3d.Append(anAisTranslShape);
764 }
765 
ConjugateObjects3dSample()766 void GeometrySamples::ConjugateObjects3dSample()
767 {
768   gp_Hypr aHypr(gp_Ax2(), 20.0, 10.0);
769   gp_Ax1 anAsymptote1 = aHypr.Asymptote1();
770   gp_Ax1 anAsymptote2 = aHypr.Asymptote2();
771   gp_Ax1 aDirectrix1 = aHypr.Directrix1();
772   gp_Ax1 aDirectrix2 = aHypr.Directrix2();
773   gp_Pnt aFocus1 = aHypr.Focus1();
774   gp_Pnt aFocus2 = aHypr.Focus2();
775   gp_Pnt aLocation = aHypr.Location();
776 
777   Handle(AdaptorVec_AIS) anAsy1AIS = new AdaptorVec_AIS(anAsymptote1.Location(), gp_Vec(anAsymptote1.Direction())*10.0);
778   anAsy1AIS->SetText("  Asymptote 1");
779   myObject3d.Append(anAsy1AIS);
780   Handle(AdaptorVec_AIS) anAsy2AIS = new AdaptorVec_AIS(anAsymptote2.Location(), gp_Vec(anAsymptote2.Direction())*10.0);
781   anAsy2AIS->SetText("  Asymptote 2");
782   myObject3d.Append(anAsy2AIS);
783   Handle(AdaptorVec_AIS) anDir1AIS = new AdaptorVec_AIS(aDirectrix1.Location(), gp_Vec(aDirectrix1.Direction())*10.0);
784   anDir1AIS->SetText("  Directrix 1");
785   myObject3d.Append(anDir1AIS);
786   Handle(AdaptorVec_AIS) anDir2AIS = new AdaptorVec_AIS(aDirectrix2.Location(), gp_Vec(aDirectrix2.Direction())*10.0);
787   anDir2AIS->SetText("  Directrix 2");
788   myObject3d.Append(anDir2AIS);
789 
790   DisplayPnt(aFocus1, "Focus 1", Aspect_TOM_PLUS, 2.0);
791   DisplayPnt(aFocus2, "Focus 2", Aspect_TOM_PLUS, 2.0);
792   DisplayPnt(aLocation, "Location", Aspect_TOM_O_STAR, 2.0);
793 
794   Handle(Geom_Hyperbola) aGeomHyperbola = new Geom_Hyperbola(aHypr);
795   Handle(Geom_TrimmedCurve) aTrimmedHyperbola = new Geom_TrimmedCurve(aGeomHyperbola, 2.0, -2.0);
796   Handle(AdaptorCurve_AIS) anAisHyperbola = new AdaptorCurve_AIS(aTrimmedHyperbola);
797   myObject3d.Append(anAisHyperbola);
798 }
799 
ProjectionOfPoint3dSample()800 void GeometrySamples::ProjectionOfPoint3dSample()
801 {
802   gp_Sphere aSphere(gp_Ax3(), 10.0);
803   gp_Pnt aBasePnt(20.0, 20.0, 20.0);
804   // A projection point in surface coordinate
805   gp_Pnt2d aPrjPnt2d = ProjLib::Project(aSphere, aBasePnt);
806   gp_Pnt aPrjPnt = ElSLib::Value(aPrjPnt2d.X(), aPrjPnt2d.Y(), aSphere);
807 
808   DisplayPnt(aBasePnt, "Base point", Aspect_TOM_PLUS, 2.0);
809   DisplayPnt(aPrjPnt, "Projection point", Aspect_TOM_O_STAR, 2.0);
810   Handle(Geom_SphericalSurface) aSphericalSurface = new Geom_SphericalSurface(aSphere);
811   Handle(AIS_Shape) anAisSphere = new AIS_Shape(BRepBuilderAPI_MakeFace(
812     aSphericalSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape());
813   myObject3d.Append(anAisSphere);
814 }
815 
MinimalDistance3dSample()816 void GeometrySamples::MinimalDistance3dSample()
817 {
818   gp_Cylinder aCylinder(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 10.0);
819   gp_Lin aLine(gp_Pnt(20.0, 0.0, 5.0), gp_Dir(0.0, 1.0, 0.0));
820   Extrema_ExtElCS anExtrema_ExtElCS(aLine, aCylinder);
821 
822   if (anExtrema_ExtElCS.IsDone())
823   {
824     NCollection_Array1<gp_Vec> aVecArray(1, anExtrema_ExtElCS.NbExt());
825     NCollection_Array1<gp_Pnt> aPntArray(1, anExtrema_ExtElCS.NbExt());
826     for (Standard_Integer i = 1; i <= anExtrema_ExtElCS.NbExt(); i++)
827     {
828       Extrema_POnCurv aCurvPoint;
829       Extrema_POnSurf aSurfPoint;
830       anExtrema_ExtElCS.Points(i, aCurvPoint, aSurfPoint);
831       gp_Pnt aCurvPnt = aCurvPoint.Value();
832       gp_Pnt aSurfPnt = aSurfPoint.Value();
833 
834       DisplayPnt(aCurvPnt, TCollection_AsciiString(i), Aspect_TOM_O_PLUS, 2.0);
835       DisplayPnt(aSurfPnt, TCollection_AsciiString(i), Aspect_TOM_O_STAR, 2.0);
836       gp_Vec aVec(aCurvPnt, aSurfPnt);
837       aVecArray.SetValue(i, aVec);
838       aPntArray.SetValue(i, aCurvPnt);
839     }
840     Standard_Integer aMinDistIndex(0);
841     Standard_Real aMinDistance = std::numeric_limits<Standard_Real>::max();
842     for (Standard_Integer i = 1; i <= anExtrema_ExtElCS.NbExt(); i++)
843     {
844       if (aMinDistance > aVecArray(i).Magnitude())
845       {
846         aMinDistIndex = i;
847         aMinDistance = aVecArray(i).Magnitude();
848       }
849     }
850     Handle(AdaptorVec_AIS) anMinDistanceAis =
851       new AdaptorVec_AIS(aPntArray(aMinDistIndex), aVecArray(aMinDistIndex));
852     anMinDistanceAis->SetText("  Min distance");
853     myObject3d.Append(anMinDistanceAis);
854   }
855   Handle(Geom_CylindricalSurface) aCylindricalSurface = new Geom_CylindricalSurface(aCylinder);
856   Handle(AIS_Shape) anAisCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace(
857     aCylindricalSurface, 0.0, 2.0*M_PI, 0.0, 10.0, Precision::Confusion()).Shape());
858   myObject3d.Append(anAisCylinder);
859   Handle(AdaptorVec_AIS) anLineAis = new AdaptorVec_AIS(aLine.Location(), aLine.Direction(), 8.0);
860   anLineAis->SetText("  gp_Lin");
861   myObject3d.Append(anLineAis);
862 }
863 
Intersection3dSample()864 void GeometrySamples::Intersection3dSample()
865 {
866   gp_Lin aLine(gp_Pnt(0.0, 0.0, 10.0), gp_Dir(0.0, 1.0, 0.0));
867   gp_Cone aCone(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 0.25*M_PI, 0.0);
868   IntAna_Quadric anIntAna_Quadric(aCone);
869   IntAna_IntConicQuad anIntAna_IntConicQuad(aLine, anIntAna_Quadric);
870   if (anIntAna_IntConicQuad.IsDone())
871   {
872     for (int i = 1; i <= anIntAna_IntConicQuad.NbPoints(); i++)
873     {
874       const gp_Pnt& aIntersectionPnt = anIntAna_IntConicQuad.Point(i);
875       DisplayPnt(aIntersectionPnt, TCollection_AsciiString(i));
876     }
877   }
878   Handle(AdaptorVec_AIS) aLineVecAIS = new AdaptorVec_AIS(aLine.Location(), gp_Vec(aLine.Direction())*5.0);
879   aLineVecAIS->SetText("  Base vector");
880   myObject3d.Append(aLineVecAIS);
881   Handle(Geom_ConicalSurface) aConicalSurface = new Geom_ConicalSurface(aCone);
882   Handle(AIS_Shape) anAisCone = new AIS_Shape(BRepBuilderAPI_MakeFace(
883     aConicalSurface, 0.0, 2.0*M_PI, 0.0, 20.0, Precision::Confusion()).Shape());
884   myObject3d.Append(anAisCone);
885 }
886 
TranslatedPoint2dSample()887 void GeometrySamples::TranslatedPoint2dSample()
888 {
889   gp_Pnt2d aPnt1;
890   gp_Pnt2d aPnt2 = aPnt1.Translated(gp_Vec2d(10.0, 10.0));
891   DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 1.0);
892   DisplayPnt(aPnt2, "2", Aspect_TOM_PLUS, 1.0);
893   gp_Vec2d aTranslationVec(aPnt1, aPnt2);
894   Handle(AdaptorVec_AIS) aVecAIS = new AdaptorVec_AIS(aPnt1, aTranslationVec);
895   aVecAIS->SetText("   Translation");
896   myObject2d.Append(aVecAIS);
897 }
898 
RotatedDirection2dSample()899 void GeometrySamples::RotatedDirection2dSample()
900 {
901   gp_Dir2d aBaseDir(1.0, 1.0);
902   gp_Dir2d aRotatedDir = aBaseDir.Rotated(M_PI_4);
903 
904   myResult << "An angle between directions: " << aBaseDir.Angle(aRotatedDir)*180.0 / M_PI << " grad";
905   Handle(AdaptorVec_AIS) aBaseAIS = new AdaptorVec_AIS(gp_Pnt2d(), aBaseDir, 5.0);
906   aBaseAIS->SetText("  Base");
907   myObject2d.Append(aBaseAIS);
908   Handle(AdaptorVec_AIS) aRotatedAIS = new AdaptorVec_AIS(gp_Pnt2d(), aRotatedDir, 5.0);
909   aRotatedAIS->SetText("  Rotated");
910   myObject2d.Append(aRotatedAIS);
911 }
912 
MirroredAxis2dSample()913 void GeometrySamples::MirroredAxis2dSample()
914 {
915   gp_Ax22d aBaseAx(gp_Pnt2d(10.0, 0.0), gp_Dir2d(1.0, 0.0), Standard_True);
916   gp_Ax22d aMirrorAx = aBaseAx.Mirrored(gp_Pnt2d());
917 
918   DisplayPnt(gp_Pnt2d(), "Mirror point", Aspect_TOM_PLUS, 1.0);
919   Handle(AdaptorVec_AIS) aBaseX_AIS = new AdaptorVec_AIS(aBaseAx.Location(), aBaseAx.XDirection(), 5.0);
920   aBaseX_AIS->SetText("  X (Base)");
921   myObject2d.Append(aBaseX_AIS);
922   Handle(AdaptorVec_AIS) aBaseY_AIS = new AdaptorVec_AIS(aBaseAx.Location(), aBaseAx.YDirection(), 5.0);
923   aBaseY_AIS->SetText("Y (Base)");
924   myObject2d.Append(aBaseY_AIS);
925   Handle(AdaptorVec_AIS) aMirrorX_AIS = new AdaptorVec_AIS(aMirrorAx.Location(), aMirrorAx.XDirection(), 5.0);
926   aMirrorX_AIS->SetText("X (Mirror)");
927   myObject2d.Append(aMirrorX_AIS);
928   Handle(AdaptorVec_AIS) aMirrorY_AIS = new AdaptorVec_AIS(aMirrorAx.Location(), aMirrorAx.YDirection(), 5.0);
929   aMirrorY_AIS->SetText("  Y (Mirror)");
930   myObject2d.Append(aMirrorY_AIS);
931 }
932 
TransformedEllipse2dSample()933 void GeometrySamples::TransformedEllipse2dSample()
934 {
935   // Creates an ellipse with the major axis, the major and the minor radius.
936   // The location of the MajorAxis is the center of the ellipse.The sense of
937   // parametrization is given by Sense.Warnings : It is possible to create
938   // an ellipse with MajorRadius = MinorRadius.Raises
939   // ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0.
940   gp_Elips2d aBaseEllips(gp_Ax2d(gp_Pnt2d(), gp_Dir2d(1.0, 0.0)), 20.0, 10.0);
941   gp_Trsf2d aRotTrsf;
942   aRotTrsf.SetRotation(gp_Pnt2d(), M_PI_4);
943   gp_Trsf2d aScaleTrsf;
944   aScaleTrsf.SetScale(gp_Pnt2d(), 1.5);
945   gp_Trsf2d aTranslTrsf;
946   aTranslTrsf.SetTranslation(gp_Vec2d(30.0, 0.0));
947   gp_Trsf2d aComplexTrsf = aRotTrsf * aScaleTrsf * aTranslTrsf;
948   gp_Elips2d aTransfEllips = aBaseEllips.Transformed(aComplexTrsf);
949 
950   Handle(Geom2d_Ellipse) aBaseEllipse = new Geom2d_Ellipse(aBaseEllips);
951   Handle(AdaptorCurve2d_AIS) anAisBaseEllipse = new AdaptorCurve2d_AIS(aBaseEllipse, Aspect_TOL_DASH);
952   myObject2d.Append(anAisBaseEllipse);
953   Handle(Geom2d_Ellipse) aTransfEllipse = new Geom2d_Ellipse(aTransfEllips);
954   Handle(AdaptorCurve2d_AIS) anAisTransfEllipse = new AdaptorCurve2d_AIS(aTransfEllipse, Aspect_TOL_DASH);
955   myObject2d.Append(anAisTransfEllipse);
956 }
957 
ConjugateObjects2dSample()958 void GeometrySamples::ConjugateObjects2dSample()
959 {
960   gp_Parab2d aParab(gp_Ax2d(), 20.0);
961   gp_Ax2d aDirectrix = aParab.Directrix();
962   gp_Pnt2d aFocus = aParab.Focus();
963   gp_Pnt2d aLocation = aParab.Location();
964   gp_Ax2d aMirror = aParab.MirrorAxis();
965 
966   Handle(AdaptorVec_AIS) aDirectAIS = new AdaptorVec_AIS(aDirectrix.Location(), gp_Vec2d(aDirectrix.Direction())*10.0);
967   aDirectAIS->SetText("  Directrix");
968   myObject2d.Append(aDirectAIS);
969   Handle(AdaptorVec_AIS) aMirrorAIS = new AdaptorVec_AIS(aMirror.Location(), gp_Vec2d(aMirror.Direction())*10.0);
970   aMirrorAIS->SetText("  Mirror Axis");
971   myObject2d.Append(aMirrorAIS);
972 
973   DisplayPnt(aFocus, "Focus", Aspect_TOM_PLUS, -3.0);
974   DisplayPnt(aLocation, "  Location", Aspect_TOM_O_STAR, 3.0);
975   Handle(Geom2d_Parabola) aGeomParabola = new Geom2d_Parabola(aParab);
976   Handle(Geom2d_TrimmedCurve) aTrimmedParabola = new Geom2d_TrimmedCurve(aGeomParabola, 40.0, -40.0);
977   Handle(AdaptorCurve2d_AIS) anAisParabola = new AdaptorCurve2d_AIS(aTrimmedParabola, Aspect_TOL_DOT);
978   myObject2d.Append(anAisParabola);
979 }
980 
Tangent2dSample()981 void GeometrySamples::Tangent2dSample()
982 {
983   gp_Circ2d aCirc1(gp_Ax2d(gp_Pnt2d(0.0, 0.0), gp_Vec2d(1.0, 0.0)), 10.0);
984   gp_Circ2d aCirc2 = aCirc1.Translated(gp_Vec2d(50.0, 0.0));
985   aCirc2.SetRadius(20.0);
986 
987   GccEnt_QualifiedCirc aQaCirc1(aCirc1, GccEnt_outside);
988   GccEnt_QualifiedCirc aQaCirc2(aCirc2, GccEnt_outside);
989 
990   GccAna_Lin2d2Tan aLin2d2Tan(aQaCirc1, aQaCirc2, 1E-6);
991   if (aLin2d2Tan.IsDone())
992   {
993     for (int i = 1; i <= aLin2d2Tan.NbSolutions(); i++)
994     {
995       const gp_Lin2d& aTangentLin = aLin2d2Tan.ThisSolution(i);
996       Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aTangentLin.Location(), aTangentLin.Direction(), 20.0);
997       myObject2d.Append(anAisLin);
998     }
999   }
1000 
1001   Handle(Geom2d_Circle) aCircle1 = new Geom2d_Circle(aCirc1);
1002   Handle(AdaptorCurve2d_AIS) anAisCirc1 = new AdaptorCurve2d_AIS(aCircle1, Aspect_TOL_SOLID);
1003   myObject2d.Append(anAisCirc1);
1004   Handle(Geom2d_Circle) aCircle2 = new Geom2d_Circle(aCirc2);
1005   Handle(AdaptorCurve2d_AIS) anAisCirc2 = new AdaptorCurve2d_AIS(aCircle2, Aspect_TOL_SOLID);
1006   myObject2d.Append(anAisCirc2);
1007 }
1008 
ProjectionOfPoint2dSample()1009 void GeometrySamples::ProjectionOfPoint2dSample()
1010 {
1011   gp_Pnt2d aPntToProject(40.0, 40.0);
1012   gp_Circ2d aCirc(gp_Ax2d(), 20.0);
1013   Handle(Geom2d_Circle) aGeom_Circle = new Geom2d_Circle(aCirc);
1014   Geom2dAPI_ProjectPointOnCurve aProjector(aPntToProject, aGeom_Circle);
1015   gp_Pnt2d aProjectionPnt = aProjector.NearestPoint();
1016 
1017   Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeom_Circle, Aspect_TOL_SOLID);
1018   myObject2d.Append(anAisCirc);
1019   DisplayPnt(aPntToProject, "Pnt to project");
1020   DisplayPnt(aProjectionPnt, "Projection Pnt", Aspect_TOM_O_STAR);
1021 }
1022 
MinimalDistance2dSample()1023 void GeometrySamples::MinimalDistance2dSample()
1024 {
1025   gp_Lin2d aLin(gp_Pnt2d(-40.0, 0.0), gp_Dir2d(1.0, 1.0));
1026   Handle(Geom2d_Line) aGeom_Line = new Geom2d_Line(aLin);
1027   gp_Circ2d aCirc(gp_Ax2d(), 20.0);
1028   Handle(Geom2d_Circle) aGeom_Circle = new Geom2d_Circle(aCirc);
1029 
1030   Geom2dAPI_ExtremaCurveCurve anExtremaFinder(aGeom_Line, aGeom_Circle,
1031     std::numeric_limits<Standard_Real>::min(),
1032     std::numeric_limits<Standard_Real>::max(), 0.0, M_PI*2.0);
1033   if (anExtremaFinder.NbExtrema())
1034   {
1035     gp_Pnt2d aPnt1, aPnt2;
1036     anExtremaFinder.NearestPoints(aPnt1, aPnt2);
1037     myResult << "Extrema found: " << anExtremaFinder.NbExtrema() << std::endl;
1038     myResult << "Minimal distance: " << anExtremaFinder.LowerDistance() << std::endl;
1039     DisplayPnt(aPnt1, "1");
1040     DisplayPnt(aPnt2, "2");
1041   }
1042   else
1043   {
1044     myResult << "No Extrema found" << std::endl;
1045   }
1046 
1047   Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeom_Circle, Aspect_TOL_SOLID);
1048   myObject2d.Append(anAisCirc);
1049   Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aLin.Location(), aLin.Direction(), 60.0);
1050   anAisLin->SetText("  gp_Lin2d");
1051   myObject2d.Append(anAisLin);
1052 }
1053 
Intersection2dSample()1054 void GeometrySamples::Intersection2dSample()
1055 {
1056   gp_Lin2d aLin(gp_Pnt2d(-20.0, 20.0), gp_Dir2d(1.0, -1.5));
1057   Handle(Geom2d_Line) aGeom_Line = new Geom2d_Line(aLin);
1058   gp_Parab2d aParab(gp_Ax2d(), 20.0);
1059   Handle(Geom2d_Parabola) aGeom_Parabola = new Geom2d_Parabola(aParab);
1060 
1061   Geom2dAPI_InterCurveCurve anIntersectFinder(aGeom_Line, aGeom_Parabola);
1062   for (Standard_Integer i = 1; i <= anIntersectFinder.NbPoints(); i++)
1063   {
1064     gp_Pnt2d aPnt = anIntersectFinder.Point(i);
1065     DisplayPnt(aPnt, i);
1066   }
1067 
1068   myResult << "Number of intersections : " << anIntersectFinder.NbPoints() << std::endl;
1069 
1070   Handle(Geom2d_Parabola) aGeomParabola = new Geom2d_Parabola(aParab);
1071   Handle(Geom2d_TrimmedCurve) aTrimmedParabola = new Geom2d_TrimmedCurve(aGeomParabola, 60.0, -60.0);
1072   Handle(AdaptorCurve2d_AIS) anAisParabola = new AdaptorCurve2d_AIS(aTrimmedParabola, Aspect_TOL_DOT);
1073   myObject2d.Append(anAisParabola);
1074   Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aLin.Location(), aLin.Direction(), 90.0);
1075   anAisLin->SetText("  gp_Lin2d");
1076   myObject2d.Append(anAisLin);
1077 }
1078 
PointInfo3dSample()1079 void GeometrySamples::PointInfo3dSample()
1080 {
1081   gp_Pnt aPnt1;
1082   gp_Pnt aPnt2(10.0, 10.0, 10.0);
1083   gp_Pnt aPnt3(10.0, -10.0, 0.0);
1084   gp_Pnt aPnt4(10.0, 10.0, 10.0);
1085   Standard_Boolean anIsEqual2_3 = aPnt2.IsEqual(aPnt3, 1E-6);
1086   Standard_Boolean anIsEqual2_4 = aPnt2.IsEqual(aPnt4, 1E-6);
1087   Standard_Real aDistance1_2 = aPnt1.Distance(aPnt2);
1088   Standard_Real aDistance2_4 = aPnt2.Distance(aPnt4);
1089   Standard_Real aSquareDistance1_2 = aPnt1.SquareDistance(aPnt2);
1090   Standard_Real aSquareDistance2_4 = aPnt2.SquareDistance(aPnt4);
1091 
1092   myResult << "A coordinate of a point 1: X: " << aPnt1.X() << " Y: " << aPnt1.Y() << " Z: " << aPnt1.Z() << std::endl;
1093   myResult << "A coordinate of a point 2: X: " << aPnt2.X() << " Y: " << aPnt2.Y() << " Z: " << aPnt2.Z() << std::endl;
1094   myResult << "A coordinate of a point 3: X: " << aPnt3.X() << " Y: " << aPnt3.Y() << " Z: " << aPnt3.Z() << std::endl;
1095   myResult << "A coordinate of a point 4: X: " << aPnt4.X() << " Y: " << aPnt4.Y() << " Z: " << aPnt4.Z() << std::endl;
1096 
1097   if (anIsEqual2_3)
1098   {
1099     myResult << "A point 2 is equal to a point 3" << std::endl;
1100   }
1101   else
1102   {
1103     myResult << "A point 2 is different from a point 3" << std::endl;
1104   }
1105   if (anIsEqual2_4)
1106   {
1107     myResult << "A point 2 is equal to a point 4" << std::endl;
1108   }
1109   else
1110   {
1111     myResult << "A point 2 is different from a point 4" << std::endl;
1112   }
1113   myResult << "A distance from a point 1 to a point 2 is: " << aDistance1_2 << std::endl;
1114   myResult << "A distance from a point 2 to a point 4 is: " << aDistance2_4 << std::endl;
1115 
1116   myResult << "A square distance from a point 1 to a point 2 is: " << aSquareDistance1_2 << std::endl;
1117   myResult << "A square distance from a point 2 to a point 4 is: " << aSquareDistance2_4 << std::endl;
1118 
1119   DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 0.5);
1120   DisplayPnt(aPnt2, "2 & 4", Aspect_TOM_PLUS, 0.5);
1121   DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 0.5);
1122   DisplayPnt(aPnt4, "", Aspect_TOM_PLUS, 0.5);
1123 }
1124 
EllipseInfo3dSample()1125 void GeometrySamples::EllipseInfo3dSample()
1126 {
1127   gp_Elips anElips(gp_Ax2(gp_Pnt(), gp_Dir(1.0, 0.0, 0.0)), 20.0, 10.0);
1128   Standard_Real anArea = anElips.Area();
1129   // Returns the eccentricity of the ellipse between 0.0 and 1.0
1130   // If f is the distance between the center of the ellipse and the Focus1 then
1131   // the eccentricity e = f / MajorRadius. Returns 0 if MajorRadius = 0.
1132   Standard_Real anEccentricity = anElips.Eccentricity();
1133   // Returns the distance between the center of the ellipse and focus1 or focus2.
1134   Standard_Real aFocal = anElips.Focal();
1135   // Returns p = (1 - e * e) * MajorRadius where e is the eccentricity
1136   // of the ellipse. Returns 0 if MajorRadius = 0.
1137   Standard_Real aParameter = anElips.Parameter();
1138 
1139   myResult << "Ellipse area = " << anArea << " square units" << std::endl;
1140   myResult << "Eccentricity = " << anEccentricity;
1141   myResult << "Focal distance = " << aFocal;
1142   myResult << "Ellipse parameter = " << aParameter;
1143 
1144   gp_Pnt aCenter = anElips.Location();
1145   gp_Pnt aFocus1 = anElips.Focus1();
1146   gp_Pnt aFocus2 = anElips.Focus2();
1147   DisplayPnt(aCenter, "Center", Aspect_TOM_PLUS, 2.0);
1148   DisplayPnt(aFocus1, "focus 1", Aspect_TOM_PLUS, 2.0);
1149   DisplayPnt(aFocus2, "focus 2", Aspect_TOM_PLUS, 2.0);
1150 
1151   Handle(Geom_Ellipse) aGeomEllipse = new Geom_Ellipse(anElips);
1152   Handle(AdaptorCurve_AIS) anAisEllipce = new AdaptorCurve_AIS(aGeomEllipse);
1153   myObject3d.Append(anAisEllipce);
1154 }
1155 
PointInfo2dSample()1156 void GeometrySamples::PointInfo2dSample()
1157 {
1158   gp_Pnt2d aPnt1;
1159   gp_Pnt2d aPnt2(10.0, 10.0);
1160   gp_Pnt2d aPnt3(10.0, -10.0);
1161   gp_Pnt2d aPnt4(10.0, 10.0);
1162   Standard_Boolean anIsEqual2_3 = aPnt2.IsEqual(aPnt3, 1E-6);
1163   Standard_Boolean anIsEqual2_4 = aPnt2.IsEqual(aPnt4, 1E-6);
1164   Standard_Real aDistance1_2 = aPnt1.Distance(aPnt2);
1165   Standard_Real aDistance2_4 = aPnt2.Distance(aPnt4);
1166   Standard_Real aSquareDistance1_2 = aPnt1.SquareDistance(aPnt2);
1167   Standard_Real aSquareDistance2_4 = aPnt2.SquareDistance(aPnt4);
1168 
1169   myResult << "A coordinate of a point 1: X: " << aPnt1.X() << " Y: " << aPnt1.Y() << std::endl;
1170   myResult << "A coordinate of a point 2: X: " << aPnt2.X() << " Y: " << aPnt2.Y() << std::endl;
1171   myResult << "A coordinate of a point 3: X: " << aPnt3.X() << " Y: " << aPnt3.Y() << std::endl;
1172   myResult << "A coordinate of a point 4: X: " << aPnt4.X() << " Y: " << aPnt4.Y() << std::endl;
1173   if (anIsEqual2_3)
1174   {
1175     myResult << "A point 2 is equal to a point 3" << std::endl;
1176   }
1177   else
1178   {
1179     myResult << "A point 2 is different from a point 3" << std::endl;
1180   }
1181   if (anIsEqual2_4)
1182   {
1183     myResult << "A point 2 is equal to a point 4" << std::endl;
1184   }
1185   else
1186   {
1187     myResult << "A point 2 is different from a point 4" << std::endl;
1188   }
1189 
1190   myResult << "A distance from a point 1  to a point 2 is: " << aDistance1_2 << std::endl;
1191   myResult << "A distance from a point 2  to a point 4 is: " << aDistance2_4 << std::endl;
1192 
1193   myResult << "A square distance from a point 1  to a point 2 is: " << aSquareDistance1_2 << std::endl;
1194   myResult << "A square distance from a point 2  to a point 4 is: " << aSquareDistance2_4 << std::endl;
1195 
1196   DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 0.5);
1197   DisplayPnt(aPnt2, "2 & 4", Aspect_TOM_PLUS, 0.5);
1198   DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 0.5);
1199   DisplayPnt(aPnt4, "");
1200 }
1201 
CircleInfo2dSample()1202 void GeometrySamples::CircleInfo2dSample()
1203 {
1204   gp_Circ2d aCirc(gp_Ax22d(gp_Pnt2d(10.0, 10.0), gp_Vec2d(1.0, 0.0)), 10.0);
1205   gp_Pnt2d aPnt1(0.0, 10.0);
1206   gp_Pnt2d aPnt2(10.0, 0.0);
1207   gp_Pnt2d aPnt3(20.0, 20.0);
1208 
1209   if (aCirc.Contains(aPnt1, 1E-6))
1210   {
1211     DisplayPnt(aPnt1, "1", Aspect_TOM_STAR, 3.0);
1212     myResult << "A circle contains a point 1" << std::endl;
1213   }
1214   else
1215   {
1216     DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 1.0);
1217     myResult << "A circle does contain a point 1" << std::endl;
1218   }
1219   if (aCirc.Contains(aPnt2, 1E-6))
1220   {
1221     DisplayPnt(aPnt2, "2", Aspect_TOM_STAR, 1.0);
1222     myResult << "A circle contains a point 2" << std::endl;
1223   }
1224   else
1225   {
1226     DisplayPnt(aPnt2, "2", Aspect_TOM_PLUS, 1.0);
1227     myResult << "A circle does contain a point 2" << std::endl;
1228   }
1229   if (aCirc.Contains(aPnt3, 1E-6))
1230   {
1231     DisplayPnt(aPnt3, "3", Aspect_TOM_STAR, 1.0);
1232     myResult << "A circle contains a point 3" << std::endl;
1233   }
1234   else
1235   {
1236     DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 1.0);
1237     myResult << "A circle does contain a point 3" << std::endl;
1238   }
1239   myResult << "Circle area = " << aCirc.Area() << "square units" << std::endl;
1240   Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(aCirc);
1241   Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle);
1242   myObject2d.Append(anAisCirc);
1243 }
1244 
FreeStyleCurves3dSample()1245 void GeometrySamples::FreeStyleCurves3dSample()
1246 {
1247   // Define points.
1248   gp_Pnt aPnt1(0.0, 0.0, 0.0);
1249   gp_Pnt aPnt2(5.0, 5.0, 0.0);
1250   gp_Pnt aPnt3(10.0, 5.0, 0.0);
1251   gp_Pnt aPnt4(15.0, 0.0, 0.0);
1252 
1253   // Add points to the curve poles array.
1254   TColgp_Array1OfPnt aPoles(1, 4);
1255   aPoles.SetValue(1, aPnt1);
1256   aPoles.SetValue(2, aPnt2);
1257   aPoles.SetValue(3, aPnt3);
1258   aPoles.SetValue(4, aPnt4);
1259 
1260   // Define BSpline weights.
1261   TColStd_Array1OfReal aBSplineWeights(1, 4);
1262   aBSplineWeights.SetValue(1, 1.0);
1263   aBSplineWeights.SetValue(2, 0.5);
1264   aBSplineWeights.SetValue(3, 0.5);
1265   aBSplineWeights.SetValue(4, 1.0);
1266 
1267   // Define knots.
1268   TColStd_Array1OfReal aKnots(1, 2);
1269   aKnots.SetValue(1, 0.0);
1270   aKnots.SetValue(2, 1.0);
1271 
1272   // Define multiplicities.
1273   TColStd_Array1OfInteger aMults(1, 2);
1274   aMults.SetValue(1, 4);
1275   aMults.SetValue(2, 4);
1276 
1277   // Define BSpline degree and periodicity.
1278   Standard_Integer aDegree = 3;
1279   Standard_Boolean aPeriodic = Standard_False;
1280 
1281   // Create a BSpline curve.
1282   Handle(Geom_BSplineCurve) aBSplineCurve = new Geom_BSplineCurve(
1283     aPoles, aBSplineWeights, aKnots, aMults, aDegree, aPeriodic);
1284   myResult << "Geom_BSplineCurve was created in red" << std::endl;
1285 
1286   // Define Bezier weights.
1287   TColStd_Array1OfReal aBezierWeights(1, 4);
1288   aBezierWeights.SetValue(1, 0.5);
1289   aBezierWeights.SetValue(2, 1.5);
1290   aBezierWeights.SetValue(3, 1.5);
1291   aBezierWeights.SetValue(4, 0.5);
1292 
1293   // Create Bezier curve.
1294   Handle(Geom_BezierCurve) aBezierCurve = new Geom_BezierCurve(aPoles, aBezierWeights);
1295   myResult << "Geom_BezierCurve was created in green" << std::endl;
1296 
1297   Handle(AIS_ColoredShape) anAisBSplineCurve = new AIS_ColoredShape(
1298     BRepBuilderAPI_MakeEdge(aBSplineCurve).Shape());
1299   Handle(AIS_ColoredShape) anAisBezierCurve = new AIS_ColoredShape(
1300     BRepBuilderAPI_MakeEdge(aBezierCurve).Shape());
1301   anAisBSplineCurve->SetColor(Quantity_Color(Quantity_NOC_RED));
1302   anAisBezierCurve->SetColor(Quantity_Color(Quantity_NOC_GREEN));
1303   myObject3d.Append(anAisBSplineCurve);
1304   myObject3d.Append(anAisBezierCurve);
1305   myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt1)));
1306   myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt2)));
1307   myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt3)));
1308   myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt4)));
1309 }
1310 
AnalyticalSurfaces3dSample()1311 void GeometrySamples::AnalyticalSurfaces3dSample()
1312 {
1313   // Define a XY plane.
1314   gp_Pln aPln(gp::Origin(), gp::DZ());
1315   // Create plane geometry.
1316   Handle(Geom_Plane) aPlaneSurf = new Geom_Plane(aPln);
1317   myResult << "Geom_Plane was created in red" << std::endl;
1318 
1319   // Define a cylinder.
1320   gp_Cylinder aCyl(gp::XOY(), 2.5);
1321   // Create cylindrical surface.
1322   Handle(Geom_CylindricalSurface) aCylSurf = new Geom_CylindricalSurface(aCyl);
1323   myResult << "Geom_CylindricalSurface was created in green" << std::endl;
1324 
1325   // Define a cone.
1326   gp_Cone aCone(gp::XOY(), M_PI_4, 2.5);
1327   // Create conical surface.
1328   Handle(Geom_ConicalSurface) aConeSurf = new Geom_ConicalSurface(aCone);
1329   myResult << "Geom_ConicalSurface was created in blue" << std::endl;
1330 
1331   // Define a sphere.
1332   gp_Pnt aSphereCenter(15.0, 15.0, 15.0);
1333   gp_Sphere aSphere(gp_Ax3(aSphereCenter, gp::DZ()), 8.0);
1334   // Create conical surface.
1335   Handle(Geom_SphericalSurface) aSphereSurf = new Geom_SphericalSurface(aSphere);
1336   myResult << "Geom_SphericalSurface was created in cyan" << std::endl;
1337 
1338   // Define a sphere.
1339   gp_Pnt aTorusCenter(-15.0, -15.0, 25.0);
1340   gp_Torus aTorus(gp_Ax3(aTorusCenter, gp::DZ()), 15.0, 5.0);
1341   // Create toroidal surface.
1342   Handle(Geom_ToroidalSurface) aTorusSurf = new Geom_ToroidalSurface(aTorus);
1343   myResult << "Geom_ToroidalSurface was created in yellow" << std::endl;
1344 
1345   Handle(AIS_ColoredShape) anAisPlane = new AIS_ColoredShape(BRepBuilderAPI_MakeFace(
1346     aPlaneSurf, 0.0, 20.0, 0.0, 20.0, Precision::Confusion()).Shape());
1347   Handle(AIS_ColoredShape) anAisCylinder = new AIS_ColoredShape(BRepBuilderAPI_MakeFace(
1348     aCylSurf, 0.0, 2.0 * M_PI, 5.0, 15.0, Precision::Confusion()).Shape());
1349   Handle(AIS_ColoredShape) anAisCone = new AIS_ColoredShape(BRepBuilderAPI_MakeFace(
1350     aConeSurf, 0.0, 2.0 * M_PI, 0.0, 15.0, Precision::Confusion()).Shape());
1351   Handle(AIS_ColoredShape) anAisSphere = new AIS_ColoredShape(BRepBuilderAPI_MakeFace(
1352     aSphereSurf, Precision::Confusion()).Shape());
1353   Handle(AIS_ColoredShape) anAisTorus = new AIS_ColoredShape(BRepBuilderAPI_MakeFace(
1354     aTorusSurf, Precision::Confusion()).Shape());
1355   anAisPlane->SetColor(Quantity_Color(Quantity_NOC_RED));
1356   anAisCylinder->SetColor(Quantity_Color(Quantity_NOC_GREEN));
1357   anAisCone->SetColor(Quantity_Color(Quantity_NOC_BLUE1));
1358   anAisSphere->SetColor(Quantity_Color(Quantity_NOC_CYAN1));
1359   anAisTorus->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
1360   myObject3d.Append(anAisPlane);
1361   myObject3d.Append(anAisCylinder);
1362   myObject3d.Append(anAisCone);
1363   myObject3d.Append(anAisSphere);
1364   myObject3d.Append(anAisTorus);
1365 }
1366 
FreeStyleSurfaces3dSample()1367 void GeometrySamples::FreeStyleSurfaces3dSample()
1368 {
1369   // Define a 4x4 grid of points for BSpline surface.
1370   TColgp_Array2OfPnt aBSplinePnts(1, 4, 1, 4);
1371   for (Standard_Integer i = 1; i <= 4; ++i)
1372   {
1373     gp_Pnt aPnt;
1374     aPnt.SetX(5.0 * i);
1375     for (Standard_Integer j = 1; j <= 4; ++j)
1376     {
1377       aPnt.SetY(5.0 * j);
1378       if (1 < i && i < 4 && 1 < j && j < 4)
1379       {
1380         aPnt.SetZ(5.0);
1381       }
1382       else
1383       {
1384         aPnt.SetZ(0.0);
1385       }
1386       aBSplinePnts.SetValue(i, j, aPnt);
1387     }
1388   }
1389 
1390   // Define a 4x4 grid of points for Bezier surface.
1391   TColgp_Array2OfPnt aBezierPnts(1, 4, 1, 4);
1392   for (Standard_Integer i = 1; i <= 4; ++i)
1393   {
1394     gp_Pnt aPnt;
1395     aPnt.SetX(20.0 + 5.0 * i);
1396     for (Standard_Integer j = 1; j <= 4; ++j)
1397     {
1398       aPnt.SetY(20.0 + 5.0 * j);
1399       if (1 < i && i < 4 && 1 < j && j < 4)
1400       {
1401         aPnt.SetZ(5.0);
1402       }
1403       else
1404       {
1405         aPnt.SetZ(0.0);
1406       }
1407       aBezierPnts.SetValue(i, j, aPnt);
1408     }
1409   }
1410 
1411   // Define BSpline weights.
1412   TColStd_Array2OfReal aBSplineWeights(1, 4, 1, 4);
1413   for (Standard_Integer i = 1; i <= 4; ++i)
1414   {
1415     for (Standard_Integer j = 1; j <= 4; ++j)
1416     {
1417       if (1 < i && i < 4 && 1 < j && j < 4)
1418       {
1419         aBSplineWeights.SetValue(i, j, 0.5);
1420       }
1421       else
1422       {
1423         aBSplineWeights.SetValue(i, j, 1.0);
1424       }
1425     }
1426   }
1427 
1428   // Define knots.
1429   TColStd_Array1OfReal aUKnots(1, 2), aVKnots(1, 2);
1430   aUKnots.SetValue(1, 0.0);
1431   aUKnots.SetValue(2, 1.0);
1432   aVKnots.SetValue(1, 0.0);
1433   aVKnots.SetValue(2, 1.0);
1434 
1435   // Define multiplicities.
1436   TColStd_Array1OfInteger aUMults(1, 2), aVMults(1, 2);
1437   aUMults.SetValue(1, 4);
1438   aUMults.SetValue(2, 4);
1439   aVMults.SetValue(1, 4);
1440   aVMults.SetValue(2, 4);
1441 
1442   // Define BSpline degree and periodicity.
1443   Standard_Integer aUDegree = 3;
1444   Standard_Integer aVDegree = 3;
1445   Standard_Boolean aUPeriodic = Standard_False;
1446   Standard_Boolean aVPeriodic = Standard_False;
1447 
1448   // Create a BSpline surface.
1449   Handle(Geom_BSplineSurface) aBSplineSurf = new Geom_BSplineSurface(
1450     aBSplinePnts, aBSplineWeights, aUKnots, aVKnots,
1451     aUMults, aVMults, aUDegree, aVDegree, aUPeriodic, aVPeriodic);
1452   myResult << "Geom_BSplineSurface was created in red" << std::endl;
1453 
1454   // Define BSpline weights.
1455   TColStd_Array2OfReal aBezierWeights(1, 4, 1, 4);
1456   for (Standard_Integer i = 1; i <= 4; ++i)
1457   {
1458     for (Standard_Integer j = 1; j <= 4; ++j)
1459     {
1460       if (1 < i && i < 4 && 1 < j && j < 4)
1461       {
1462         aBezierWeights.SetValue(i, j, 1.5);
1463       }
1464       else
1465       {
1466         aBezierWeights.SetValue(i, j, 0.5);
1467       }
1468     }
1469   }
1470 
1471   // Create a Bezier surface.
1472   Handle(Geom_BezierSurface) aBezierSurf = new Geom_BezierSurface(aBezierPnts, aBezierWeights);
1473   myResult << "Geom_BezierSurface was created in green" << std::endl;
1474 
1475   Handle(AIS_ColoredShape) anAisBSplineSurf = new AIS_ColoredShape(
1476     BRepBuilderAPI_MakeFace(aBSplineSurf, Precision::Confusion()).Shape());
1477   Handle(AIS_ColoredShape) anAisBezierSurf = new AIS_ColoredShape(
1478     BRepBuilderAPI_MakeFace(aBezierSurf, Precision::Confusion()).Shape());
1479   anAisBSplineSurf->SetColor(Quantity_Color(Quantity_NOC_RED));
1480   anAisBezierSurf->SetColor(Quantity_Color(Quantity_NOC_GREEN));
1481   myObject3d.Append(anAisBSplineSurf);
1482   myObject3d.Append(anAisBezierSurf);
1483   for (TColgp_Array2OfPnt::Iterator anIt(aBSplinePnts); anIt.More(); anIt.Next())
1484   {
1485     myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(anIt.Value())));
1486   }
1487   for (TColgp_Array2OfPnt::Iterator anIt(aBezierPnts); anIt.More(); anIt.Next())
1488   {
1489     myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(anIt.Value())));
1490   }
1491 }
1492 
FreeStyleCurves2dSample()1493 void GeometrySamples::FreeStyleCurves2dSample()
1494 {
1495 
1496   // Define points.
1497   gp_Pnt2d aPnt1(0.0, 0.0);
1498   gp_Pnt2d aPnt2(5.0, 5.0);
1499   gp_Pnt2d aPnt3(10.0, 5.0);
1500   gp_Pnt2d aPnt4(15.0, 0.0);
1501 
1502   // Add points to the curve poles array.
1503   TColgp_Array1OfPnt2d aBSplinePoles(1, 4);
1504   aBSplinePoles.SetValue(1, aPnt1);
1505   aBSplinePoles.SetValue(2, aPnt2);
1506   aBSplinePoles.SetValue(3, aPnt3);
1507   aBSplinePoles.SetValue(4, aPnt4);
1508 
1509   // Define BSpline weights.
1510   TColStd_Array1OfReal aBSplineWeights(1, 4);
1511   aBSplineWeights.SetValue(1, 1.0);
1512   aBSplineWeights.SetValue(2, 0.5);
1513   aBSplineWeights.SetValue(3, 0.5);
1514   aBSplineWeights.SetValue(4, 1.0);
1515 
1516   // Define knots.
1517   TColStd_Array1OfReal aKnots(1, 2);
1518   aKnots.SetValue(1, 0.0);
1519   aKnots.SetValue(2, 1.0);
1520 
1521   // Define multiplicities.
1522   TColStd_Array1OfInteger aMults(1, 2);
1523   aMults.SetValue(1, 4);
1524   aMults.SetValue(2, 4);
1525 
1526   // Define BSpline degree and periodicity.
1527   Standard_Integer aDegree = 3;
1528   Standard_Boolean aPeriodic = Standard_False;
1529 
1530   // Create a BSpline curve.
1531   Handle(Geom2d_BSplineCurve) aBSplineCurve =
1532     new Geom2d_BSplineCurve(aBSplinePoles, aBSplineWeights, aKnots, aMults, aDegree, aPeriodic);
1533 
1534 
1535   TColgp_Array1OfPnt2d aBezierPoles(1, 4);
1536   gp_Vec2d anUp10Vec(0.0, 10.0);
1537   aBezierPoles.SetValue(1, aPnt1.Translated(anUp10Vec));
1538   aBezierPoles.SetValue(2, aPnt2.Translated(anUp10Vec));
1539   aBezierPoles.SetValue(3, aPnt3.Translated(anUp10Vec));
1540   aBezierPoles.SetValue(4, aPnt4.Translated(anUp10Vec));
1541 
1542   // Define Bezier weights.
1543   TColStd_Array1OfReal aBezierWeights(1, 4);
1544   aBezierWeights.SetValue(1, 0.5);
1545   aBezierWeights.SetValue(2, 1.5);
1546   aBezierWeights.SetValue(3, 1.5);
1547   aBezierWeights.SetValue(4, 0.5);
1548 
1549   // Create Bezier curve.
1550   Handle(Geom2d_BezierCurve) aBezierCurve = new Geom2d_BezierCurve(aBezierPoles, aBezierWeights);
1551 
1552   Handle(AdaptorCurve2d_AIS) anAisBSpline = new AdaptorCurve2d_AIS(aBSplineCurve);
1553   myObject2d.Append(anAisBSpline);
1554   Handle(AdaptorCurve2d_AIS) anAisBezier = new AdaptorCurve2d_AIS(aBezierCurve);
1555   myObject2d.Append(anAisBezier);
1556 
1557   DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 0.5);
1558   DisplayPnt(aPnt2, "2", Aspect_TOM_PLUS, 0.5);
1559   DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 0.5);
1560   DisplayPnt(aPnt4, "4", Aspect_TOM_PLUS, 0.5);
1561 }
1562 
TrimmedCurve3dSample()1563 void GeometrySamples::TrimmedCurve3dSample()
1564 {
1565   // Define a circle placed in the origin of XY coordinate
1566   // plane and with the radius equal to 5.
1567   gp_Circ aCirc(gp::XOY(), 5.0);
1568   // Create a closed circular curve.
1569   Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc);
1570   myResult << "Geom_Circle was created in yellow" << std::endl;
1571 
1572   // Cut off a quarter of the circle.
1573   Handle(Geom_TrimmedCurve) aCircQuater = new Geom_TrimmedCurve(aCircCurve, 0.0, M_PI_2);
1574   myResult << "Geom_TrimmedCurve was created in red" << std::endl;
1575 
1576   Handle(AIS_ColoredShape) anAisCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircCurve).Shape());
1577   Handle(AIS_ColoredShape) anAisCircQuater = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircQuater).Shape());
1578   anAisCirc->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
1579   anAisCircQuater->SetColor(Quantity_Color(Quantity_NOC_RED));
1580   anAisCircQuater->SetWidth(2.5);
1581   myObject3d.Append(anAisCirc);
1582   myObject3d.Append(anAisCircQuater);
1583 }
1584 
OffsetCurve3dSample()1585 void GeometrySamples::OffsetCurve3dSample()
1586 {
1587   // Define a circle placed in the origin of XY coordinate
1588   // plane and with the radius equal to 5.
1589   gp_Circ aCirc(gp::XOY(), 5.0);
1590   // Create a closed circular curve.
1591   Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc);
1592   myResult << "Geom_Circle was created in yellow" << std::endl;
1593 
1594   // An offset curve is a curve at constant distance (Offset) from
1595   // a basis curve in a reference direction V.
1596   // The offset curve takes its parametrization from the basis curve.
1597   // The Offset curve is in the direction of the normal N
1598   // defined with the cross product T^V, where the vector T
1599   // is given by the first derivative on the basis curve with non zero length.
1600   // The distance offset may be positive or negative to indicate the
1601   // preferred side of the curve:
1602   // . distance offset >0 => the curve is in the direction of N
1603   // . distance offset <0 => the curve is in the direction of - N
1604   // On the Offset curve:
1605   // Value (U) = BasisCurve.Value(U) + (Offset * (T ^ V)) / ||T ^ V||
1606   // At any point the Offset direction V must not be parallel to the
1607   // vector T and the vector T must not have null length else the
1608   // offset curve is not defined.
1609 
1610   // Expand the circle by Offset equal to a quarter of the radius
1611   // with direction V equal to Z.
1612   Standard_Real anExpandOffset = +aCirc.Radius() / 4.0;
1613   gp_Dir anExpandDir = gp::DZ();
1614   Handle(Geom_OffsetCurve) anExpandCircCurve = new Geom_OffsetCurve(
1615     aCircCurve, anExpandOffset, anExpandDir);
1616   myResult << "Geom_OffsetCurve (expanded circle) was created in red" << std::endl;
1617 
1618   // Collapse the circle by Offset equal to a half of the radius with direction V equal to Z.
1619   Standard_Real anCollapseOffset = -aCirc.Radius() / 2.0;
1620   gp_Dir anCollapseDir = gp::DZ();
1621   Handle(Geom_OffsetCurve) anCollapseCircCurve = new Geom_OffsetCurve (aCircCurve, anCollapseOffset, anCollapseDir);
1622   myResult << "Geom_OffsetCurve (collapsed circle) was created in green" << std::endl;
1623 
1624   Handle(AIS_ColoredShape) anAisCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircCurve).Shape());
1625   Handle(AIS_ColoredShape) anAisExpandCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(anExpandCircCurve).Shape());
1626   Handle(AIS_ColoredShape) anAisCpllapsedCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(anCollapseCircCurve).Shape());
1627   anAisCirc->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
1628   anAisExpandCirc->SetColor(Quantity_Color(Quantity_NOC_RED));
1629   anAisCpllapsedCirc->SetColor(Quantity_Color(Quantity_NOC_GREEN));
1630   myObject3d.Append(anAisCirc);
1631   myObject3d.Append(anAisExpandCirc);
1632   myObject3d.Append(anAisCpllapsedCirc);
1633 }
1634 
BSplineFromCircle3dSample()1635 void GeometrySamples::BSplineFromCircle3dSample()
1636 {
1637   // Define a circle placed in the origin of XY coordinate
1638   // plane and with the radius equal to 5.
1639   gp_Circ aCirc(gp::XOY(), 5.0);
1640   // Create a closed circular curve.
1641   Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc);
1642   myResult << "Geom_Circle was created in yellow" << std::endl;
1643 
1644   // Convert the circle curve to a BSpline one.
1645   Handle(Geom_BSplineCurve) aBSplineFromCirc = GeomConvert::CurveToBSplineCurve(aCircCurve);
1646   myResult << "Geom_BSplineCurve was created in red:" << std::endl;
1647   myResult << "Degree:   " << aBSplineFromCirc->Degree() << std::endl;
1648   myResult << "Periodic: " << (aBSplineFromCirc->IsPeriodic() ? "Yes" : "No") << std::endl;
1649   myResult << "Poles: [" << aBSplineFromCirc->Poles().Size() << "]" << std::endl;
1650   for (TColgp_Array1OfPnt::Iterator anIt(aBSplineFromCirc->Poles()); anIt.More(); anIt.Next())
1651   {
1652     myResult << "  (" << anIt.Value().X() << ", " << anIt.Value().Y() << ", " << anIt.Value().Z() << ")" << std::endl;
1653   }
1654 
1655   Handle(AIS_ColoredShape) anAisCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircCurve).Shape());
1656   Handle(AIS_ColoredShape) anAisBSpline = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aBSplineFromCirc).Shape());
1657   anAisCirc->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
1658   anAisBSpline->SetColor(Quantity_Color(Quantity_NOC_RED));
1659   myObject3d.Append(anAisCirc);
1660   myObject3d.Append(anAisBSpline);
1661 }
1662 
TrimmedSurface3dSample()1663 void GeometrySamples::TrimmedSurface3dSample()
1664 {
1665   // Define a XY plane.
1666   gp_Pln aPln(gp::XOY());
1667   // Create a plane surface.
1668   Handle(Geom_Plane) aPlaneSurf = new Geom_Plane(aPln);
1669   myResult << "Geom_Plane was created" << std::endl;
1670 
1671   // Trim [0 ... 30 X 0 ... 50] rectangular range.
1672   Standard_Real aUMin = 0.0;
1673   Standard_Real aUMax = 30.0;
1674   Standard_Real aVMin = 0.0;
1675   Standard_Real aVMax = 50.0;
1676   Handle(Geom_RectangularTrimmedSurface) aTrimmedPlaneSurf
1677     = new Geom_RectangularTrimmedSurface(aPlaneSurf, aUMin, aUMax, aVMin, aVMax);
1678   myResult << "Geom_RectangularTrimmedSurface was created in red" << std::endl;
1679 
1680   Handle(AIS_Plane) anAisPlane = new AIS_Plane(aPlaneSurf);
1681   Handle(AIS_ColoredShape) anAisTimmedPlane = new AIS_ColoredShape (BRepBuilderAPI_MakeFace (aTrimmedPlaneSurf, 0.001).Shape());
1682   anAisTimmedPlane->SetColor(Quantity_Color(Quantity_NOC_RED));
1683   myObject3d.Append(anAisPlane);
1684   myObject3d.Append(anAisTimmedPlane);
1685 }
1686 
OffsetSurface3dSample()1687 void GeometrySamples::OffsetSurface3dSample()
1688 {
1689   // Define a XY plane.
1690   gp_Pln aPln(gp::XOY());
1691   // Create a plane surface.
1692   Handle(Geom_Plane) aPlaneSurf = new Geom_Plane(aPln);
1693   myResult << "Geom_Plane was created" << std::endl;
1694 
1695   // An offset surface is defined by:
1696   // - the basis surface to which it is parallel, and
1697   // - the distance between the offset surface and its basis surface.
1698   // A point on the offset surface is built by measuring the
1699   // offset value along the normal vector at a point on the
1700   // basis surface. This normal vector is given by the cross
1701   // product D1u^D1v, where D1u and D1v are the
1702   // vectors tangential to the basis surface in the u and v
1703   // parametric directions at this point. The side of the
1704   // basis surface on which the offset is measured
1705   // depends on the sign of the offset value.
1706 
1707   // Offset the plane in the normal direction.
1708   Standard_Real aPosOffset = 10.0;
1709   Handle(Geom_OffsetSurface) aPosOffsetSurf = new Geom_OffsetSurface(aPlaneSurf, aPosOffset);
1710   myResult << "Geom_OffsetSurface with " << aPosOffset << " was created in red" << std::endl;
1711 
1712   // Offset the plane in direction opposite to the normal one.
1713   Standard_Real aNegOffset = -15.0;
1714   Handle(Geom_OffsetSurface) aNegOffsetSurf = new Geom_OffsetSurface(aPlaneSurf, aNegOffset);
1715   myResult << "Geom_OffsetSurface with " << aNegOffset << " was created in green" << std::endl;
1716 
1717   Handle(AIS_ColoredShape) anAisPlane = new AIS_ColoredShape(
1718     BRepBuilderAPI_MakeFace(aPlaneSurf, 0.0, 10.0, 0.0, 10.0, Precision::Confusion()).Shape());
1719   Handle(AIS_ColoredShape) anAisPosOffsetPlane = new AIS_ColoredShape(
1720     BRepBuilderAPI_MakeFace(aPosOffsetSurf, 0.0, 10.0, 0.0, 10.0, Precision::Confusion()).Shape());
1721   Handle(AIS_ColoredShape) anAisNegOffsetPlane = new AIS_ColoredShape(
1722     BRepBuilderAPI_MakeFace(aNegOffsetSurf, 0.0, 10.0, 0.0, 10.0, Precision::Confusion()).Shape());
1723   anAisPosOffsetPlane->SetColor(Quantity_Color(Quantity_NOC_RED));
1724   anAisNegOffsetPlane->SetColor(Quantity_Color(Quantity_NOC_GREEN));
1725   myObject3d.Append(anAisPlane);
1726   myObject3d.Append(anAisPosOffsetPlane);
1727   myObject3d.Append(anAisNegOffsetPlane);
1728 }
1729 
ExtrusionSurface3dSample()1730 void GeometrySamples::ExtrusionSurface3dSample()
1731 {
1732   // Create an ellipse curve in XY plane.
1733   Standard_Real aMinorRadius = 10.0;
1734   Standard_Real aMajorRadius = 20.0;
1735   Handle(Geom_Ellipse) anEllipseCurve = new Geom_Ellipse(gp::XOY(), aMajorRadius, aMinorRadius);
1736   myResult << "Geom_Ellipse was created in yellow" << std::endl;
1737 
1738   // Make a linear extrusion of the ellipse at 45 degrees to Z axis
1739   gp_Dir aDirOfExtr = gp::DZ();
1740   Handle(Geom_SurfaceOfLinearExtrusion) aLinExtrSurf
1741     = new Geom_SurfaceOfLinearExtrusion(anEllipseCurve, aDirOfExtr);
1742   myResult << "Geom_SurfaceOfLinearExtrusion was created in red" << std::endl;
1743 
1744   Handle(AIS_ColoredShape) anAisEllipse = new AIS_ColoredShape(
1745     BRepBuilderAPI_MakeEdge(anEllipseCurve).Shape());
1746   Handle(AIS_ColoredShape) anAisExtrSurf = new AIS_ColoredShape(
1747     BRepBuilderAPI_MakeFace(aLinExtrSurf, 0.0, 2.0 * M_PI, 0.0, 30.0,
1748       Precision::Confusion()).Shape());
1749   anAisEllipse->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
1750   anAisEllipse->SetWidth(2.5);
1751   anAisExtrSurf->SetColor(Quantity_Color(Quantity_NOC_RED));
1752   myObject3d.Append(anAisEllipse);
1753   myObject3d.Append(anAisExtrSurf);
1754 }
1755 
RevolutionSurface3dSample()1756 void GeometrySamples::RevolutionSurface3dSample()
1757 {
1758   // Create an ellipse curve in XY plane with
1759   // the center at (-10, 0, 0).
1760   Standard_Real aMinorRadius = 5.0;
1761   Standard_Real aMajorRadius = 10.0;
1762   gp_Pnt aCenter(-30.0, 0.0, 0.0);
1763   Handle(Geom_Ellipse) anEllipseCurve = new Geom_Ellipse(gp_Ax2(aCenter, gp::DZ()),
1764     aMajorRadius, aMinorRadius);
1765   myResult << "Geom_Ellipse was created in yellow" << std::endl;
1766 
1767   // Make a revolution of the ellipse around Y axis
1768   Handle(Geom_SurfaceOfRevolution) aRevolSurf = new Geom_SurfaceOfRevolution(anEllipseCurve, gp::OY());
1769   myResult << "Geom_SurfaceOfRevolution was created in red" << std::endl;
1770 
1771   Handle(AIS_ColoredShape) anAisEllipse = new AIS_ColoredShape(
1772     BRepBuilderAPI_MakeEdge(anEllipseCurve).Shape());
1773   Handle(AIS_ColoredShape) anAisRevolSurf = new AIS_ColoredShape(
1774     BRepBuilderAPI_MakeFace(aRevolSurf, Precision::Confusion()).Shape());
1775   anAisEllipse->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
1776   anAisEllipse->SetWidth(2.5);
1777   anAisRevolSurf->SetColor(Quantity_Color(Quantity_NOC_RED));
1778   myObject3d.Append(anAisEllipse);
1779   myObject3d.Append(anAisRevolSurf);
1780 }
1781 
TrimmedCurve2dSample()1782 void GeometrySamples::TrimmedCurve2dSample()
1783 {
1784   // Create a closed circular curve.
1785   Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(), gp_Vec2d(1.0, 0.0)), 5.0);
1786   Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle);
1787   myObject2d.Append(anAisCirc);
1788 
1789   // Cut off a quarter of the circle.
1790   Handle(Geom2d_TrimmedCurve) aCircQuater = new Geom2d_TrimmedCurve(aGeomCircle, 0.0, M_PI_2);
1791   aCircQuater->Translate(gp_Vec2d(15.0, 0.0));
1792   Handle(AdaptorCurve2d_AIS) anAisCircQuater = new AdaptorCurve2d_AIS(aCircQuater);
1793   myObject2d.Append(anAisCircQuater);
1794 }
1795 
OffsetCurve2dSample()1796 void GeometrySamples::OffsetCurve2dSample()
1797 {
1798   Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(), gp_Vec2d(1.0, 0.0)), 5.0);
1799 
1800   Standard_Real anExpandOffset = aGeomCircle->Radius() / 4.0;
1801   Handle(Geom2d_OffsetCurve) anExpandCircCurve = new Geom2d_OffsetCurve(aGeomCircle, anExpandOffset);
1802 
1803   Standard_Real anCollapseOffset = -aGeomCircle->Radius() / 2.0;
1804   Handle(Geom2d_OffsetCurve) anCollapseCircCurve = new Geom2d_OffsetCurve(aGeomCircle, anCollapseOffset);
1805 
1806   Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle);
1807   myObject2d.Append(anAisCirc);
1808   Handle(AdaptorCurve2d_AIS) anAisExpand = new AdaptorCurve2d_AIS(anExpandCircCurve);
1809   myObject2d.Append(anAisExpand);
1810   Handle(AdaptorCurve2d_AIS) anAisCollapse = new AdaptorCurve2d_AIS(anCollapseCircCurve);
1811   myObject2d.Append(anAisCollapse);
1812 }
1813 
BoundingBoxOfSurface3dSample()1814 void GeometrySamples::BoundingBoxOfSurface3dSample()
1815 {
1816   // Define a 4x4 grid of points for BSpline surface.
1817   TColgp_Array2OfPnt aPoints(1, 4, 1, 4);
1818   for (Standard_Integer i = 1; i <= 4; ++i)
1819   {
1820     gp_Pnt aPnt;
1821     aPnt.SetX(5.0 * i);
1822     for (Standard_Integer j = 1; j <= 4; ++j)
1823     {
1824       aPnt.SetY(5.0 * j);
1825       if (1 < i && i < 4 && 1 < j && j < 4)
1826       {
1827         aPnt.SetZ(5.0);
1828       }
1829       else
1830       {
1831         aPnt.SetZ(0.0);
1832       }
1833       aPoints.SetValue(i, j, aPnt);
1834     }
1835   }
1836 
1837   // Make a BSpline surface from the points array.
1838   Handle(Geom_BSplineSurface) aBSplineSurf = GeomAPI_PointsToBSplineSurface(aPoints).Surface();
1839   myResult << "Geom_BSplineSurface was created" << std::endl;
1840 
1841   // Compute BSpline surface bounding box.
1842   Bnd_Box aBndBox;
1843   BndLib_AddSurface::AddOptimal(GeomAdaptor_Surface(aBSplineSurf), Precision::Confusion(), aBndBox);
1844   myResult << "Bounding box:" << std::endl;
1845   myResult << "  Min corner = [ "
1846            << aBndBox.CornerMin().X() << ", "
1847            << aBndBox.CornerMin().Y() << ", "
1848            << aBndBox.CornerMin().Z() << " ]" << std::endl;
1849   myResult << "  Max corner = [ "
1850            << aBndBox.CornerMax().X() << ", "
1851            << aBndBox.CornerMax().Y() << ", "
1852            << aBndBox.CornerMax().Z() << " ]" << std::endl;
1853 
1854   Handle(AIS_ColoredShape) anAisBSplineSurf = new AIS_ColoredShape(
1855     BRepBuilderAPI_MakeFace(aBSplineSurf, Precision::Confusion()).Shape());
1856   Handle(AIS_ColoredShape) anAisBndBox = new AIS_ColoredShape(
1857     BRepPrimAPI_MakeBox(aBndBox.CornerMin(), aBndBox.CornerMax()).Shell());
1858   myObject3d.Append(anAisBSplineSurf);
1859   myObject3d.Append(anAisBndBox);
1860   myContext->SetDisplayMode(anAisBndBox, 0, Standard_True);
1861 }
1862 
BoundingBoxOfCurves3dSample()1863 void GeometrySamples::BoundingBoxOfCurves3dSample()
1864 {
1865   // Define points.
1866   gp_Pnt aPnt1(0.0, 0.0, 10.0);
1867   gp_Pnt aPnt2(5.0, 5.0, 5.0);
1868   gp_Pnt aPnt3(10.0, 10.0, 15.0);
1869   gp_Pnt aPnt4(15.0, 5.0, 20.0);
1870 
1871   // Add points to the curve poles array.
1872   TColgp_Array1OfPnt aPoles(1, 4);
1873   aPoles.SetValue(1, aPnt1);
1874   aPoles.SetValue(2, aPnt2);
1875   aPoles.SetValue(3, aPnt3);
1876   aPoles.SetValue(4, aPnt4);
1877 
1878   // Make a BSpline curve from the points array.
1879   Handle(Geom_BSplineCurve) aBSplineCurve = GeomAPI_PointsToBSpline(aPoles).Curve();
1880   myResult << "aBSplineCurve was created" << std::endl;
1881 
1882   // Compute BSpline curve bounding box.
1883   Bnd_Box aBndBox;
1884   BndLib_Add3dCurve::AddOptimal(GeomAdaptor_Curve(aBSplineCurve), Precision::Confusion(), aBndBox);
1885   myResult << "Bounding box:" << std::endl;
1886   myResult << "  Min corner = [ "
1887            << aBndBox.CornerMin().X() << ", "
1888            << aBndBox.CornerMin().Y() << ", "
1889            << aBndBox.CornerMin().Z() << " ]" << std::endl;
1890   myResult << "  Max corner = [ "
1891            << aBndBox.CornerMax().X() << ", "
1892            << aBndBox.CornerMax().Y() << ", "
1893            << aBndBox.CornerMax().Z() << " ]" << std::endl;
1894 
1895   Handle(AIS_ColoredShape) anAisBSplineCurve = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aBSplineCurve).Shape());
1896   Handle(AIS_ColoredShape) anAisBndBox = new AIS_ColoredShape (BRepPrimAPI_MakeBox(aBndBox.CornerMin(), aBndBox.CornerMax()).Shell());
1897   myObject3d.Append(anAisBSplineCurve);
1898   myObject3d.Append(anAisBndBox);
1899   myContext->SetDisplayMode(anAisBndBox, 0, Standard_True);
1900 }
1901 
BoundingBoxOfCurves2dSample()1902 void GeometrySamples::BoundingBoxOfCurves2dSample()
1903 {
1904   // Define points.
1905   gp_Pnt2d aPnt1(0.0, 0.0);
1906   gp_Pnt2d aPnt2(5.0, 5.0);
1907   gp_Pnt2d aPnt3(10.0, 10.0);
1908   gp_Pnt2d aPnt4(15.0, 5.0);
1909 
1910   // Add points to the curve poles array.
1911   TColgp_Array1OfPnt2d aPoles(1, 4);
1912   aPoles.SetValue(1, aPnt1);
1913   aPoles.SetValue(2, aPnt2);
1914   aPoles.SetValue(3, aPnt3);
1915   aPoles.SetValue(4, aPnt4);
1916 
1917   // Make a BSpline curve from the points array.
1918   Handle(Geom2d_BSplineCurve) aBSplineCurve = Geom2dAPI_PointsToBSpline(aPoles).Curve();
1919 
1920   // Compute BSpline curve bounding box.
1921   Bnd_Box2d aBndBox;
1922   BndLib_Add2dCurve::AddOptimal(aBSplineCurve, 0.0, 1.0, Precision::PConfusion(), aBndBox);
1923   Standard_Real aXmin, aYmin, aXmax, aYmax;
1924   aBndBox.Get(aXmin, aYmin, aXmax, aYmax);
1925 
1926   myResult << "Bounding box:" << std::endl;
1927   myResult << "  Min corner = [ " << aXmin << ", " << aYmin << " ]" << std::endl;
1928   myResult << "  Max corner = [ " << aXmax << ", " << aYmax << " ]" << std::endl;
1929 
1930   Handle(AdaptorCurve2d_AIS) anAisBSpline = new AdaptorCurve2d_AIS(aBSplineCurve);
1931 
1932   Handle(AdaptorVec_AIS) anAisVec1 = new AdaptorVec_AIS(gp_Pnt2d(aXmin, aYmin), gp_Pnt2d(aXmin, aYmax));
1933   Handle(AdaptorVec_AIS) anAisVec2 = new AdaptorVec_AIS(gp_Pnt2d(aXmin, aYmax), gp_Pnt2d(aXmax, aYmax));
1934   Handle(AdaptorVec_AIS) anAisVec3 = new AdaptorVec_AIS(gp_Pnt2d(aXmax, aYmax), gp_Pnt2d(aXmax, aYmin));
1935   Handle(AdaptorVec_AIS) anAisVec4 = new AdaptorVec_AIS(gp_Pnt2d(aXmax, aYmin), gp_Pnt2d(aXmin, aYmin));
1936 
1937   myObject2d.Append(anAisBSpline);
1938   myObject2d.Append(anAisVec1);
1939   myObject2d.Append(anAisVec2);
1940   myObject2d.Append(anAisVec3);
1941   myObject2d.Append(anAisVec4);
1942 }
1943 
DumpCircleInfoSample()1944 void GeometrySamples::DumpCircleInfoSample()
1945 {
1946   // Define a circle placed in the origin of XY coordinate
1947   // plane and with the radius equal to 0.5.
1948   gp_Circ aCirc(gp::XOY(), 0.5);
1949   // Create a closed circular curve.
1950   Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc);
1951   myResult << "Geom_Circle was created:" << std::endl;
1952   myResult << " Center = [ "
1953            << aCircCurve->Position().Location().X() << ", "
1954            << aCircCurve->Position().Location().Y() << ", "
1955            << aCircCurve->Position().Location().Z() << " ]"
1956            << std::endl;
1957   myResult << " Radius = " << aCircCurve->Radius() << std::endl;
1958   myResult << " Plane normal = [ "
1959            << aCircCurve->Position().Direction().X() << ", "
1960            << aCircCurve->Position().Direction().Y() << ", "
1961            << aCircCurve->Position().Direction().Z() << " ]"
1962            << std::endl;
1963 
1964   Handle(AIS_Circle) anAisCircle = new AIS_Circle(aCircCurve);
1965   Handle(AIS_TextLabel) anAisCenterLabel = new AIS_TextLabel();
1966   anAisCenterLabel->SetText("  Center");
1967   anAisCenterLabel->SetPosition(aCircCurve->Position().Location());
1968   Handle(AIS_Point) anAisCenter = new AIS_Point(new Geom_CartesianPoint(aCirc.Location()));
1969   Handle(AIS_Axis) anAisAxis = new AIS_Axis(new Geom_Axis2Placement(aCircCurve->Position()), AIS_TOAX_ZAxis);
1970   myObject3d.Append(anAisCircle);
1971   myObject3d.Append(anAisCenterLabel);
1972   myObject3d.Append(anAisAxis);
1973 }
1974 
DumpBSplineCurveInfoSample()1975 void GeometrySamples::DumpBSplineCurveInfoSample()
1976 {
1977   // Define points.
1978   gp_Pnt aPnt1(0.0, 0.0, 10.0);
1979   gp_Pnt aPnt2(5.0, 5.0, 5.0);
1980   gp_Pnt aPnt3(10.0, 10.0, 15.0);
1981   gp_Pnt aPnt4(15.0, 5.0, 20.0);
1982 
1983   // Add points to the curve poles array.
1984   TColgp_Array1OfPnt aPoles(1, 4);
1985   aPoles.SetValue(1, aPnt1);
1986   aPoles.SetValue(2, aPnt2);
1987   aPoles.SetValue(3, aPnt3);
1988   aPoles.SetValue(4, aPnt4);
1989 
1990   // Make a BSpline curve from the points array
1991   Handle(Geom_BSplineCurve) aBSplineCurve = GeomAPI_PointsToBSpline(aPoles).Curve();
1992   myResult << "aBSplineCurve was created:" << std::endl;
1993   myResult << "  Degree = " << aBSplineCurve->Degree() << std::endl;
1994   myResult << "  Parameter range = [ "
1995     << aBSplineCurve->FirstParameter() << ", "
1996     << aBSplineCurve->LastParameter() << " ]"
1997     << std::endl;
1998   NCollection_List<Standard_Real> aParams;
1999   aParams.Append(0.75 * aBSplineCurve->FirstParameter() + 0.25 * aBSplineCurve->LastParameter());
2000   aParams.Append(0.50 * aBSplineCurve->FirstParameter() + 0.50 * aBSplineCurve->LastParameter());
2001   aParams.Append(0.25 * aBSplineCurve->FirstParameter() + 0.75 * aBSplineCurve->LastParameter());
2002   myResult << "  Curve info:" << std::endl;
2003   for (NCollection_List<Standard_Real>::Iterator anIt(aParams); anIt.More(); anIt.Next())
2004   {
2005     Standard_Real aParam = anIt.Value();
2006     gp_Pnt aPnt;
2007     gp_Vec aVec;
2008     aBSplineCurve->D1(aParam, aPnt, aVec);
2009     myResult << "    Param = " << aParam << std::endl;
2010     myResult << "        P = [ " << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl;
2011     myResult << "        D = [ " << aVec.X() << ", " << aVec.Y() << ", " << aVec.Z() << " ]" << std::endl;
2012     myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt)));
2013     Handle(AIS_TextLabel) anAisCenterLabel = new AIS_TextLabel();
2014     Standard_SStream aSS;
2015     aSS << "P [" << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << "]" << std::endl;
2016     aSS << "D [" << aVec.X() << ", " << aVec.Y() << ", " << aVec.Z() << "]" << std::endl;
2017     anAisCenterLabel->SetText(aSS.str().c_str());
2018     anAisCenterLabel->SetPosition(aPnt);
2019     myObject3d.Append(anAisCenterLabel);
2020     Handle(AIS_Axis) anAisD = new AIS_Axis(new Geom_Axis1Placement(gp_Ax1(aPnt, aVec)));
2021     myObject3d.Append(anAisD);
2022   }
2023 
2024   Handle(AIS_ColoredShape) anAisBSplineCurve = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aBSplineCurve).Shape());
2025   anAisBSplineCurve->SetColor(Quantity_Color(Quantity_NOC_RED));
2026   myObject3d.Append(anAisBSplineCurve);
2027 }
2028