0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / samples / mfc / occtdemo / Extrema / Extrema_Presentation.cpp
1 // Extrema_Presentation.cpp: implementation of the Extrema_Presentation class.
2 // Calculation of extrema between geometries or shapes
3 //////////////////////////////////////////////////////////////////////
4
5 #include "stdafx.h"
6 #include "Extrema_Presentation.h"
7
8 #include <BRepBuilderAPI_MakeEdge.hxx>
9 #include <BRepPrimAPI_MakeBox.hxx>
10 #include <BRepPrimAPI_MakeCylinder.hxx>
11 #include <BRepExtrema_DistShapeShape.hxx>
12 #include <BRepBuilderAPI_MakeShell.hxx>
13 #include <BRepBuilderAPI_TransitionMode.hxx>
14
15 #include <TColgp_Array1OfPnt.hxx>
16 #include <TColgp_Array2OfPnt.hxx>
17 #include <TColgp_HArray1OfPnt.hxx>
18
19 #include <GeomAPI_ExtremaCurveCurve.hxx>
20 #include <GeomAPI_ExtremaCurveSurface.hxx>
21 #include <GeomAPI_ExtremaSurfaceSurface.hxx>
22 #include <GeomAPI_Interpolate.hxx>
23 #include <GeomFill_Pipe.hxx>
24 #include <GeomFill_Trihedron.hxx>
25
26 #include <Geom_SphericalSurface.hxx>
27 #include <Geom_ToroidalSurface.hxx>
28 #include <Geom_BezierCurve.hxx>
29 #include <Geom_Circle.hxx>
30 #include <Geom_BezierSurface.hxx>
31
32 #include <gp_Pnt.hxx>
33 #include <gp_Ax3.hxx>
34 #include <Precision.hxx>
35 #include <AIS_Shape.hxx>
36
37 #include <TopoDS_Solid.hxx>
38 #include <TopoDS_Shell.hxx>
39 #include <TopoDS_Edge.hxx>
40
41 #ifdef WNT
42  #define EOL "\r\n"
43 #else
44  #define EOL "\n"
45 #endif
46
47 // Initialization of global variable with an instance of this class
48 OCCDemo_Presentation* OCCDemo_Presentation::Current = new Extrema_Presentation;
49
50 // Initialization of array of samples
51 const Extrema_Presentation::PSampleFuncType Extrema_Presentation::SampleFuncs[] =
52 {
53   &Extrema_Presentation::sampleCurveCurve,
54   &Extrema_Presentation::sampleCurveSur,
55   &Extrema_Presentation::sampleSurSur,
56   &Extrema_Presentation::sampleShapeShape,
57   &Extrema_Presentation::sampleShellShell
58 };
59
60 //////////////////////////////////////////////////////////////////////
61 // Construction/Destruction
62 //////////////////////////////////////////////////////////////////////
63
64 Extrema_Presentation::Extrema_Presentation()
65 {
66   myIndex = 0;
67   myNbSamples = sizeof(SampleFuncs)/sizeof(PSampleFuncType);
68   setName ("Calculation of Extrema");
69 }
70
71 //////////////////////////////////////////////////////////////////////
72 // Sample execution
73 //////////////////////////////////////////////////////////////////////
74
75 void Extrema_Presentation::DoSample()
76 {
77   if (myIndex >=0 && myIndex < myNbSamples)
78     (this->*SampleFuncs[myIndex])();
79 }
80
81 //================================================================
82 // Function : displayExtemaEdge
83 // Purpose  : displays an edge between the two given points with white color
84 //================================================================
85 void Extrema_Presentation::displayExtemaEdge(const gp_Pnt& p1, const gp_Pnt& p2)
86 {
87   Handle(AIS_Shape) anExtremaIO = new AIS_Shape(BRepBuilderAPI_MakeEdge(p1,p2));
88   anExtremaIO->SetColor(Quantity_NOC_WHITE);
89   anExtremaIO->SetWidth(3);
90   drawPoint(p1, Quantity_Color(Quantity_NOC_WHITE));
91   drawPoint(p2, Quantity_Color(Quantity_NOC_WHITE));
92   getAISContext()->Display(anExtremaIO);
93 }
94
95 //////////////////////////////////////////////////////////////////////
96 // Sample functions
97 //////////////////////////////////////////////////////////////////////
98 //================================================================
99 // Function : Extrema_Presentation::samplePoints
100 // Purpose  : curve <-> curve extrema
101 //================================================================
102 void Extrema_Presentation::sampleCurveCurve()
103 {
104   getAISContext()->EraseAll();
105
106   ResetView();
107   SetViewCenter(282.89618368456, 81.618799162700);
108   SetViewScale(1.0106109766380);
109
110   setResultTitle("Extrema between curve and curve");
111
112   TCollection_AsciiString aText(
113     "  // initializing array of bezier curve poles" EOL
114     "  Standard_Real aCoords[][3] = {" EOL
115     "    {0,0,0},{0,1,0},{1,1,0.2},{1,2,0.2},{2,2,0.4},{2,1,0.4},{3,1,0.6},{3,0,0.6}," EOL
116     "    {2,0,0.8},{2,-1,0},{3,-1,0},{3,-2,-0.5},{4,-2,1},{4,-1,1.2},{5,-1,1.2}," EOL
117     "    {5,0,1.4},{6,0,1.4},{6,-1,1.6},{7,-1,1.6},{7,0,1.8},{8,0,1.8},{8,1,2}" EOL
118     "  };" EOL
119     "  Standard_Integer nPoles = sizeof(aCoords)/(sizeof(Standard_Real)*3);" EOL
120     "  TColgp_Array1OfPnt aPoles (1, nPoles);" EOL
121     "  for (Standard_Integer i=0; i < nPoles; i++)" EOL
122     "    aPoles(i+1) = gp_Pnt (aCoords[i][0]*100, aCoords[i][1]*100, aCoords[i][2]*100);" EOL EOL
123
124     "  // Two curves for finding extrema between them" EOL
125     "  Handle(Geom_Curve) aCurve1 = new Geom_BezierCurve(aPoles);" EOL
126     "  Handle(Geom_Curve) aCurve2 = new Geom_Circle(gp_Ax2(gp_Pnt(100,100,400), gp_Dir(0,0,1)), 300);" EOL EOL
127
128     "  // Finding extrema between the curves" EOL
129     "  GeomAPI_ExtremaCurveCurve anExtrema (aCurve1, aCurve2);" EOL EOL
130
131     "  Standard_Real aShortestDistance = anExtrema.LowerDistance();" EOL
132     "  Standard_Real u1, u2;" EOL
133     "  gp_Pnt P1, P2;" EOL
134     "  anExtrema.LowerDistanceParameters(u1, u2);" EOL
135     "  anExtrema.NearestPoints(P1,P2);" EOL EOL
136
137     "  // iterating through all solutions" EOL
138     "  for (i = 0; i <= anExtrema.NbExtrema(); i++)" EOL
139     "  {" EOL
140     "    Standard_Real aDistance = anExtrema.Distance(i);" EOL
141     "    anExtrema.Parameters(i, u1, u2);" EOL
142     "    anExtrema.Points(i, P1, P2);" EOL
143     "  }" EOL EOL
144   );
145   setResultText(aText.ToCString());
146
147   // points to build the curves
148   Standard_Real aCoords[][3] = {
149     {0,0,0},{0,1,0},{1,1,0.2},{1,2,0.2},{2,2,0.4},{2,1,0.4},{3,1,0.6},{3,0,0.6},
150     {2,0,0.8},{2,-1,0},{3,-1,0},{3,-2,-0.5},{4,-2,1},{4,-1,1.2},{5,-1,1.2},
151     {5,0,1.4},{6,0,1.4},{6,-1,1.6},{7,-1,1.6},{7,0,1.8},{8,0,1.8},{8,1,2}
152   };
153   Standard_Integer nPoles = sizeof(aCoords)/(sizeof(Standard_Real)*3);
154   TColgp_Array1OfPnt aPoles (1, nPoles);
155   for (Standard_Integer i=0; i < nPoles; i++)
156     aPoles(i+1) = gp_Pnt (aCoords[i][0]*100, aCoords[i][1]*100, aCoords[i][2]*100);
157   
158   Handle(Geom_Curve) aCurve1 = new Geom_BezierCurve(aPoles);
159   Handle(Geom_Curve) aCurve2 = new Geom_Circle(gp_Ax2(gp_Pnt(100,100,400), gp_Dir(0,0,1)), 300);
160
161   // displaying the curves in the viewer
162   drawCurve(aCurve1);
163   if (WAIT_A_LITTLE) return;
164   drawCurve(aCurve2);
165   if (WAIT_A_LITTLE) return;
166
167   // Finding shortest extrema between the curves
168   gp_Pnt P1, P2;
169   GeomAPI_ExtremaCurveCurve anExtrema(aCurve1, aCurve2);
170   anExtrema.NearestPoints(P1,P2);
171   displayExtemaEdge(P1,P2);
172
173   Standard_Real aShortestDistance = anExtrema.LowerDistance();
174   Standard_Real u1, u2;
175   anExtrema.LowerDistanceParameters(u1, u2);
176
177   char buffer[256];
178   sprintf(buffer, 
179     "  // DISTANCE BETWEEN THE CURVES = %.2f" EOL
180     "  // PARAMETER ON CURVE1 = %.2f" EOL
181     "  // PARAMETER ON CURVE2 = %.2f" EOL, aShortestDistance, u1, u2);
182   aText += buffer;
183   setResultText(aText.ToCString());
184 }
185
186 //================================================================
187 // Function : Extrema_Presentation::sampleCurveSur
188 // Purpose  : Curve <-> Surface extrema
189 //================================================================
190 void Extrema_Presentation::sampleCurveSur()
191 {
192   getAISContext()->EraseAll();
193
194   ResetView();
195   SetViewCenter(-107.67723432505, 109.55602570748);
196   SetViewScale(0.63361834647187);
197
198   setResultTitle("Extrema between curve and surface");
199   TCollection_AsciiString aText(
200     "  // the curve - first object for finding the extrema." EOL
201     "  Handle(Geom_Curve) aCurve;" EOL
202     "  Handle(TColgp_HArray1OfPnt) aPoles = new TColgp_HArray1OfPnt(1, 4);" EOL EOL
203
204     "  // points to build the curves" EOL
205     "  Standard_Real a[][3] = {{2,1,10},{0,12,0},{5,6,0},{0,10,11}};  " EOL EOL
206  
207     "  // filling the arrays of poles, scaling them, displaying the points" EOL
208     "  for (Standard_Integer i=0; i < 4; i++)" EOL
209     "    aPoles->SetValue(i+1, gp_Pnt(a[i][0]*75-300, a[i][1]*75-300, a[i][2]*75-400));" EOL EOL
210
211     "  //Creating an interpolation curve" EOL
212     "  GeomAPI_Interpolate aInterpolate1(aPoles, false, Precision::Confusion());" EOL
213     "  aInterpolate1.Perform();" EOL
214     "  if (aInterpolate1.IsDone())    aCurve = aInterpolate1.Curve();" EOL EOL
215   
216     "  // creating an axis parallel to Z axis " EOL
217     "  gp_Ax3 anAx(gp_Pnt(-400, -400, -200), gp_Dir(0,0,1)); " EOL
218     "  // creating a spherical surface" EOL
219     "  Handle(Geom_SphericalSurface) aSurface = new Geom_SphericalSurface(anAx, 1);" EOL EOL
220
221     "  // Finding extrema between the curve and the surface" EOL
222     "  GeomAPI_ExtremaCurveSurface anExtrema(aCurve, aSurface);" EOL EOL
223
224     "  Standard_Real aShortestDistance = anExtrema.LowerDistance();" EOL
225     "  Standard_Real w, u, v;" EOL
226     "  gp_Pnt P1, P2;" EOL
227     "  anExtrema.LowerDistanceParameters(w, u, v);" EOL
228     "  anExtrema.NearestPoints(P1,P2);" EOL EOL
229
230     "  // iterating through all solutions" EOL
231     "  for (i = 0; i <= anExtrema.NbExtrema(); i++)" EOL
232     "  {" EOL
233     "    Standard_Real aDistance = anExtrema.Distance(i);" EOL
234     "    anExtrema.Parameters(i, w, u, v);" EOL
235     "    anExtrema.Points(i, P1, P2);" EOL
236     "  }" EOL EOL
237   );
238   setResultText(aText.ToCString());
239   
240   // the curve - first object for finding the extrema.
241   Handle(Geom_Curve) aCurve;
242   Handle(TColgp_HArray1OfPnt) aPoles = new TColgp_HArray1OfPnt(1, 4); 
243
244   // points to build the curves
245   Standard_Real a[][3] = {{2,1,10},{0,12,0},{5,6,0},{0,10,11}};  
246  
247   // filling the arrays of poles, scaling them, displaying the points
248   for (Standard_Integer i=0; i < 4; i++)
249     aPoles->SetValue(i+1, gp_Pnt(a[i][0]*75-300, a[i][1]*75-300, a[i][2]*75-400));
250
251   //Creating an interpolation curve
252   GeomAPI_Interpolate aInterpolate1(aPoles, false, Precision::Confusion());
253   aInterpolate1.Perform();
254   if (aInterpolate1.IsDone())    aCurve = aInterpolate1.Curve();
255   
256   // creating an axis parallel to Z axis 
257   gp_Ax3 anAx(gp_Pnt(-400, -400, -200), gp_Dir(0,0,1)); 
258   // creating a spherical surface - second object to find the extrema between
259   Handle(Geom_SphericalSurface) aSurface = new Geom_SphericalSurface(anAx, 200);
260
261   drawCurve(aCurve);
262   if (WAIT_A_LITTLE) return;
263   drawSurface(aSurface);  
264   if (WAIT_A_LITTLE) return;
265
266   // Finding extrema between the curve and the surface
267   gp_Pnt P1, P2;
268   GeomAPI_ExtremaCurveSurface anExtrema(aCurve, aSurface);
269   anExtrema.NearestPoints(P1,P2);
270   displayExtemaEdge(P1,P2);
271
272   Standard_Real aShortestDistance = anExtrema.LowerDistance();
273   Standard_Real w, u, v;
274   anExtrema.LowerDistanceParameters(w, u, v);
275
276   char buffer[256];
277   sprintf(buffer, 
278     "  // DISTANCE BETWEEN THE CURVE AND THE SURFACE = %.2f" EOL
279     "  // PARAMETER ON THE CURVE = %.2f" EOL
280     "  // PARAMETERS ON THE SURFACE: U = %.2f, V = %.2f" EOL, aShortestDistance, w, u, v);
281   aText += buffer;
282   setResultText(aText.ToCString());  
283 }
284
285
286 //================================================================
287 // Function : Extrema_Presentation::sampleSurSur
288 // Purpose  : Surface <-> Surface extrema
289 //================================================================
290 void Extrema_Presentation::sampleSurSur()
291 {
292   getAISContext()->EraseAll();
293   setResultTitle("Extrema between surface and surface");
294   TCollection_AsciiString aText(
295     "  // creating an axis parallel to Z axis" EOL
296     "  gp_Ax3 anAx1(gp_Pnt(-400,-400,-200), gp_Dir(0,0,1)); " EOL
297     "  // creating a spherical surface" EOL
298     "  Handle(Geom_SphericalSurface) aSphericalSur = new Geom_SphericalSurface(anAx1,200);" EOL EOL 
299
300     "  // creating an axis parallel to Y axis " EOL
301     "  gp_Ax3 anAx2(gp_Pnt(300,300,300), gp_Dir(0,0,1)); " EOL
302     "  // creating a toroidal surface" EOL
303     "  Handle(Geom_ToroidalSurface) aToroidalSur = new Geom_ToroidalSurface(anAx2, 300, 100);" EOL EOL 
304   
305     "  // Finding extrema between the surfaces" EOL
306     "  GeomAPI_ExtremaSurfaceSurface anExtrema(aSphericalSur,aToroidalSur);" EOL EOL
307
308     "  Standard_Real aShortestDistance = anExtrema.LowerDistance();" EOL
309     "  Standard_Real u1, v1, u2, v2;" EOL
310     "  gp_Pnt P1, P2;" EOL
311     "  anExtrema.LowerDistanceParameters(u1, v1, u2, v2);" EOL
312     "  anExtrema.NearestPoints(P1,P2);" EOL EOL
313
314     "  // iterating through all solutions" EOL
315     "  for (i = 0; i <= anExtrema.NbExtrema(); i++)" EOL
316     "  {" EOL
317     "    Standard_Real aDistance = anExtrema.Distance(i);" EOL
318     "    anExtrema.Parameters(i, u1, v1, u2, v2);" EOL
319     "    anExtrema.Points(i, P1, P2);" EOL
320     "  }" EOL EOL
321   );
322   setResultText(aText.ToCString());
323   
324   // creating an axis parallel to Z axis 
325   gp_Ax3 anAx1(gp_Pnt(-400,-400,-200), gp_Dir(0,0,1)); 
326   // creating a spherical surface
327   Handle(Geom_SphericalSurface) aSphericalSur = new Geom_SphericalSurface(anAx1,200);  
328
329   // creating an axis parallel to Y axis 
330   gp_Ax3 anAx2(gp_Pnt(300,300,300), gp_Dir(0,0,1)); 
331   // creating a toroidal surface
332   Handle(Geom_ToroidalSurface) aToroidalSur = new Geom_ToroidalSurface(anAx2, 300, 100);
333   
334   drawSurface(aSphericalSur);
335   if (WAIT_A_LITTLE) return;
336   drawSurface(aToroidalSur);
337   if (WAIT_A_LITTLE) return;
338
339   // Finding extrema between the surfaces
340   gp_Pnt P1, P2;
341   GeomAPI_ExtremaSurfaceSurface anExtrema(aSphericalSur,aToroidalSur);
342   anExtrema.NearestPoints(P1,P2);
343   displayExtemaEdge(P1, P2);
344
345   Standard_Real aShortestDistance = anExtrema.LowerDistance();
346   Standard_Real u1, v1, u2, v2;
347   anExtrema.LowerDistanceParameters(u1, v1, u2, v2);
348
349   char buffer[256];
350   sprintf(buffer,
351     "  // DISTANCE BETWEEN THE SURFACES = %.2f" EOL
352     "  // PARAMETERS ON SURFACE1: U = %.2f, V = %.2f" EOL
353     "  // PARAMETERS ON SURFACE2: U = %.2f, V = %.2f" EOL, aShortestDistance, u1, v1, u2, v2);
354   aText += buffer;
355   setResultText(aText.ToCString());
356 }
357
358 //================================================================
359 // Function : Extrema_Presentation::sampleShapeShape
360 // Purpose  : TopoDS_Shape <-> TopoDS_Shape extrema
361 //================================================================
362 void Extrema_Presentation::sampleShapeShape()
363 {
364   getAISContext()->EraseAll();
365   setResultTitle("Extrema between shapes");
366   TCollection_AsciiString aText(
367     "  Standard_Real a = 500;" EOL
368     "  Standard_Real b = a/2;" EOL
369     "  BRepPrimAPI_MakeBox aBoxMaker (gp_Pnt(0, -b, -b), a, a, a);" EOL
370     "  BRepPrimAPI_MakeCylinder aCylMaker(gp_Ax2(gp_Pnt(-a,0,0), gp_Dir(.2,-.3,.5)), a/4, a);" EOL EOL
371   );
372   setResultText(aText.ToCString());
373   
374   Standard_Real a = 500;
375   Standard_Real b = a/2;
376   BRepPrimAPI_MakeBox aBoxMaker (gp_Pnt(0, -b, -b), a, a, a);
377   BRepPrimAPI_MakeCylinder aCylMaker(gp_Ax2(gp_Pnt(-a,0,0), gp_Dir(.2,-.3,.5)), a/4, a);
378
379   TopoDS_Solid aShape1 = aBoxMaker.Solid();
380   TopoDS_Solid aShape2 = aCylMaker.Solid();
381
382   doShapeShapeExtrema(aShape1, aShape2, aText);
383 }
384
385
386 //================================================================
387 // Function : Extrema_Presentation::sampleShellShell
388 // Purpose  : 
389 //================================================================
390 void Extrema_Presentation::sampleShellShell()
391 {
392   getAISContext()->EraseAll();
393   setResultTitle("Extrema between two shells");
394   TCollection_AsciiString aText(
395     "  // building a first shell: the underlaying surface is created" EOL
396     "  // using sweep algorythm.  One bezier curve is swept along another bezier curve." EOL
397     "  // creating the curves" EOL
398     "  Standard_Real aCoords1[][3] = {{0,0,0},{10,0,0},{20,10,12},{25,30,20},{50,40,50}};" EOL
399     "  Standard_Real aCoords2[][3] = {{0,0,0},{0,0,10},{0,10,10},{0,10,20}};" EOL
400     "  Standard_Integer nPoles1 = sizeof(aCoords1)/(sizeof(Standard_Real)*3);" EOL
401     "  Standard_Integer nPoles2 = sizeof(aCoords2)/(sizeof(Standard_Real)*3);" EOL
402     "  TColgp_Array1OfPnt aPoles1 (1, nPoles1);" EOL
403     "  TColgp_Array1OfPnt aPoles2 (1, nPoles2);" EOL
404     "  for (Standard_Integer i=0; i < nPoles1; i++)" EOL
405     "    aPoles1(i+1) = gp_Pnt (aCoords1[i][0]*10-250, aCoords1[i][1]*10-250, aCoords1[i][2]*10-50);" EOL
406     "  for (i=0; i < nPoles2; i++)" EOL
407     "    aPoles2(i+1) = gp_Pnt (aCoords2[i][0]*10-250, aCoords2[i][1]*10-250, aCoords2[i][2]*10-50);" EOL EOL
408   
409     "  Handle(Geom_Curve) aPathCurve = new Geom_BezierCurve(aPoles1);" EOL
410     "  Handle(Geom_Curve) aSweepCurve = new Geom_BezierCurve(aPoles2);" EOL EOL
411
412     "  // creating the surface: sweeping aSweepCurve along aPathCurve" EOL
413     "  GeomFill_Trihedron Option = GeomFill_IsFrenet;" EOL
414     "  GeomFill_Pipe aSweepMaker;" EOL
415     "  aSweepMaker.GenerateParticularCase(Standard_True);" EOL
416     "  aSweepMaker.Init(aPathCurve, aSweepCurve, Option);" EOL
417     "  Standard_Integer NbSeg = 30, MaxDegree = 10;" EOL
418     "  Standard_Real Tol = 1.e-4;" EOL
419     "  aSweepMaker.Perform(Precision::Confusion(), Standard_False,  GeomAbs_C2, MaxDegree, NbSeg);" EOL EOL
420
421     "  // creating a TopoDS_Shell from Geom_Surface" EOL
422     "  TopoDS_Shell aShape1 = BRepBuilderAPI_MakeShell(aSweepMaker.Surface());" EOL EOL
423
424     "  // creating a second shell based on a bezier surface" EOL
425     "  Standard_Real aSurCoords[][3] = {{-10,-10,-30},{-10,50,40},{-10,70,-20},{50,-10,40}," EOL
426     "                              {50,50,0},{50,70,30},{70,-10,20},{70,50,30},{70,70,-20}};" EOL
427     "  TColgp_Array2OfPnt aSurPoles(1,3,1,3);" EOL
428     "  for (i=0; i < 3; i++)" EOL
429     "    for (Standard_Integer j=0; j < 3; j++)" EOL
430     "      aSurPoles(i+1,j+1) = gp_Pnt (aSurCoords[i*3+j][0]*10-250, aSurCoords[i*3+j][1]*10-250, aSurCoords[i*3+j][2]*10-350);" EOL EOL
431
432     "  Handle(Geom_BezierSurface) aSurface = new Geom_BezierSurface(aSurPoles);" EOL EOL
433
434     "  // creating a TopoDS_Shell from Geom_Surface" EOL 
435     "  TopoDS_Shell aShape2 = BRepBuilderAPI_MakeShell(aSurface);" EOL EOL
436   );
437   setResultText(aText.ToCString());
438
439   // building a first shell: the underlaying surface is created
440   // using sweep algorythm.  One bezier curve is swept along another bezier curve.
441   // creating the curves
442   Standard_Real aCoords1[][3] = {{0,0,0},{10,0,0},{20,10,12},{25,30,20},{50,40,50}};
443   Standard_Real aCoords2[][3] = {{0,0,0},{0,0,10},{0,10,10},{0,10,20}};
444   Standard_Integer nPoles1 = sizeof(aCoords1)/(sizeof(Standard_Real)*3);
445   Standard_Integer nPoles2 = sizeof(aCoords2)/(sizeof(Standard_Real)*3);
446   TColgp_Array1OfPnt aPoles1 (1, nPoles1);
447   TColgp_Array1OfPnt aPoles2 (1, nPoles2);
448   for (Standard_Integer i=0; i < nPoles1; i++)
449     aPoles1(i+1) = gp_Pnt (aCoords1[i][0]*10-250, aCoords1[i][1]*10-250, aCoords1[i][2]*10-50);
450   for (i=0; i < nPoles2; i++)
451     aPoles2(i+1) = gp_Pnt (aCoords2[i][0]*10-250, aCoords2[i][1]*10-250, aCoords2[i][2]*10-50);
452   
453   Handle(Geom_Curve) aPathCurve = new Geom_BezierCurve(aPoles1);
454   Handle(Geom_Curve) aSweepCurve = new Geom_BezierCurve(aPoles2);
455
456   // creating the surface: sweeping aSweepCurve along aPathCurve
457   GeomFill_Trihedron Option = GeomFill_IsFrenet;
458   GeomFill_Pipe aSweepMaker;
459   aSweepMaker.GenerateParticularCase(Standard_True);
460   aSweepMaker.Init(aPathCurve, aSweepCurve, Option);
461   Standard_Integer NbSeg = 30, MaxDegree = 10;
462   Standard_Real Tol = 1.e-4;
463   aSweepMaker.Perform(Precision::Confusion(), Standard_False,  GeomAbs_C2, MaxDegree, NbSeg);
464
465   // creating a TopoDS_Shell from Geom_Surface
466   TopoDS_Shell aShape1 = BRepBuilderAPI_MakeShell(aSweepMaker.Surface());
467
468   // creating a second shell based on a bezier surface
469   Standard_Real aSurCoords[][3] = {{-10,-10,-30},{-10,50,40},{-10,70,-20},{50,-10,40},
470                                    {50,50,0},{50,70,30},{70,-10,20},{70,50,30},{70,70,-20}};
471   TColgp_Array2OfPnt aSurPoles(1,3,1,3);
472   for (i=0; i < 3; i++)
473     for (Standard_Integer j=0; j < 3; j++)
474       aSurPoles(i+1,j+1) = gp_Pnt (aSurCoords[i*3+j][0]*10-250, aSurCoords[i*3+j][1]*10-250, aSurCoords[i*3+j][2]*10-350);
475
476   Handle(Geom_BezierSurface) aSurface = new Geom_BezierSurface(aSurPoles);
477
478   // creating a TopoDS_Shell from Geom_Surface
479   TopoDS_Shell aShape2 = BRepBuilderAPI_MakeShell(aSurface);
480
481   // displaying extrema between shape and shape
482   doShapeShapeExtrema(aShape1, aShape2, aText);
483 }
484
485
486 //================================================================
487 // Function : Extrema_Presentation::doShapeShapeExtrema
488 // Purpose  : 
489 //================================================================
490 void Extrema_Presentation::doShapeShapeExtrema(const TopoDS_Shape& theShape1, 
491                                                const TopoDS_Shape& theShape2,
492                                                TCollection_AsciiString& theText)
493 {
494   theText += 
495     "  BRepExtrema_DistShapeShape anExtrema(aShape1, aShape2);" EOL
496     "  if (anExtrema.IsDone())" EOL
497     "  {" EOL
498     "    Standard_Real aShortestDistance = anExtrema.Value();" EOL
499     "    Standard_Real w1, w2, u1, v1, u2, v2;" EOL EOL
500
501     "    // iterating through ALL solutions, 1 solution in our case" EOL
502     "    for (Standard_Integer i = 1; i <= anExtrema.NbSolution(); i++)" EOL
503     "    {" EOL
504     "      gp_Pnt p1 = anExtrema.PointOnShape1(i);" EOL
505     "      gp_Pnt p2 = anExtrema.PointOnShape2(i);" EOL EOL
506
507     "      TopoDS_Shape aSupportShape1 = anExtrema.SupportOnShape1(i);" EOL
508     "      TopoDS_Shape aSupportShape2 = anExtrema.SupportOnShape2(i);" EOL EOL
509
510     "      if (anExtrema.SupportTypeOnShape1() == BRepExtrema::IsOnEdge)" EOL
511     "        anExtrema.ParOnEdgeS1(i, w1);" EOL
512     "      if (anExtrema.SupportTypeOnShape2() == BRepExtrema::IsOnEdge)" EOL
513     "        anExtrema.ParOnEdgeS2(i, w2);" EOL
514     "      if (anExtrema.SupportTypeOnShape1() == BRepExtrema::IsOnFace)" EOL
515     "        anExtrema.ParOnEdgeS1(i, u1, v1);" EOL
516     "      if (anExtrema.SupportTypeOnShape2() == BRepExtrema::IsOnFace)" EOL
517     "        anExtrema.ParOnEdgeS2(i, u2, v2);" EOL
518     "    }" EOL
519     "  }" EOL EOL;
520
521   getAISContext()->Display(new AIS_Shape(theShape1));
522   if (WAIT_A_LITTLE) return;
523   getAISContext()->Display(new AIS_Shape(theShape2));
524   if (WAIT_A_LITTLE) return;
525
526   // calculating shell-shell extrema
527   BRepExtrema_DistShapeShape anExtrema(theShape1, theShape2);
528   if (anExtrema.IsDone())
529   {
530     Standard_Real aShortestDistance = anExtrema.Value();
531     Standard_Real w1, w2, u1, v1, u2, v2;
532
533     // displaying ALL solutions
534     for (Standard_Integer i = 1; i <= anExtrema.NbSolution(); i++)
535     {
536       displayExtemaEdge(anExtrema.PointOnShape1(i), anExtrema.PointOnShape2(i));
537
538       Handle(AIS_Shape) aSupportShape1 = new AIS_Shape(anExtrema.SupportOnShape1(i));
539       aSupportShape1->SetMaterial(Graphic3d_NOM_PLASTIC);
540       aSupportShape1->SetColor(Quantity_NOC_GRAY97);
541       Handle(AIS_Shape) aSupportShape2 = new AIS_Shape(anExtrema.SupportOnShape2(i));
542       aSupportShape2->SetMaterial(Graphic3d_NOM_PLASTIC);
543       aSupportShape2->SetColor(Quantity_NOC_GRAY97);
544       getAISContext()->Display(aSupportShape1, Standard_False);
545       getAISContext()->Display(aSupportShape2);
546
547       char buffer[512];
548       sprintf(buffer,
549         "  // DISTANCE BETWEEN THE SHAPES = %.2f" EOL, aShortestDistance);      
550       theText += buffer;
551
552       if (anExtrema.SupportTypeShape1(i) == BRepExtrema_IsOnEdge)
553       {
554         anExtrema.ParOnEdgeS1(i, w1);
555         sprintf(buffer,
556           "  // TYPE OF SUPPORTING SHAPE ON SHAPE1 IS \"EDGE\","EOL
557           "  //     VALUES OF PARAMETER = %.2f" EOL, w1);
558         theText += buffer;
559       }
560       if (anExtrema.SupportTypeShape2(i) == BRepExtrema_IsOnEdge)
561       {
562         anExtrema.ParOnEdgeS2(i, w2);
563         sprintf(buffer,
564           "  // TYPE OF SUPPORTING SHAPE ON SHAPE2 IS \"EDGE\","EOL
565           "  //     VALUES OF PARAMETER = %.2f" EOL, w2);
566         theText += buffer;
567       }
568       if (anExtrema.SupportTypeShape1(i) == BRepExtrema_IsInFace)
569       {
570         anExtrema.ParOnFaceS1(i, u1, v1);
571         sprintf(buffer,
572           "  // TYPE OF SUPPORTING SHAPE ON SHAPE1 IS \"FACE\","EOL
573           "  //     VALUES OF PARAMETERS: U = %.2f, V = %.2f" EOL, u1, v1);
574         theText += buffer;
575
576       }
577       if (anExtrema.SupportTypeShape2(i) == BRepExtrema_IsInFace)
578       {
579         anExtrema.ParOnFaceS2(i, u2, v2);
580         sprintf(buffer,
581           "  // TYPE OF SUPPORTING SHAPE ON SHAPE2 IS \"FACE\","EOL
582           "  //     VALUES OF PARAMETERS: U = %.2f, V = %.2f" EOL, u2, v2);
583         theText += buffer;
584       }
585
586       setResultText(theText.ToCString());
587     }
588   }
589 }
590
591