7fd59977 |
1 | // TopLProps_Presentation.cpp: implementation of the TopLProps_Presentation class. |
2 | // Determine the local properties of shapes. |
3 | //////////////////////////////////////////////////////////////////////////// |
4 | |
5 | #include "stdafx.h" |
6 | #include "TopLProps_Presentation.h" |
7 | |
8 | #include <Precision.hxx> |
9 | #include <GeomAPI_PointsToBSpline.hxx> |
10 | #include <GeomAPI_PointsToBSplineSurface.hxx> |
11 | #include <Geom_BSplineCurve.hxx> |
12 | #include <Geom_BSplineSurface.hxx> |
13 | #include <Geom_SurfaceOfRevolution.hxx> |
14 | #include <Geom_Circle.hxx> |
15 | #include <GC_MakeSegment.hxx> |
16 | |
17 | #include <TColgp_Array1OfPnt.hxx> |
18 | #include <TColStd_Array2OfReal.hxx> |
19 | |
20 | #include <TopoDS.hxx> |
21 | #include <TopoDS_Shape.hxx> |
22 | #include <TopoDS_Compound.hxx> |
23 | #include <TopoDS_Face.hxx> |
24 | #include <TopoDS_Edge.hxx> |
25 | #include <TopExp_Explorer.hxx> |
26 | |
27 | #include <BRep_Builder.hxx> |
28 | #include <BRepBuilderAPI_MakeFace.hxx> |
29 | #include <BRepTools.hxx> |
30 | #include <BRep_Tool.hxx> |
31 | #include <BRepAdaptor_Curve.hxx> |
32 | #include <BRepAdaptor_Surface.hxx> |
33 | #include <BRepLProp_CLProps.hxx> |
34 | #include <BRepLProp_SLProps.hxx> |
35 | |
36 | |
37 | #ifdef WNT |
38 | #define EOL "\r\n" |
39 | #else |
40 | #define EOL "\n" |
41 | #endif |
42 | |
43 | #define SCALE 70 |
44 | #define ASTR(_val) TCollection_AsciiString(_val) |
45 | #define PRINT_COORDS(_p) ASTR((_p).X()) + " " + ASTR((_p).Y()) + " " + ASTR((_p).Z()) |
46 | |
47 | #define D1Color Quantity_Color(Quantity_NOC_DARKOLIVEGREEN4) |
48 | #define D2Color Quantity_Color(Quantity_NOC_DARKOLIVEGREEN) |
49 | #define D3Color Quantity_Color(Quantity_NOC_DARKGREEN) |
50 | #define TanColor Quantity_Color(Quantity_NOC_GREEN) |
51 | #define NormColor Quantity_Color(Quantity_NOC_CYAN4) |
52 | #define CrvtColor Quantity_Color(Quantity_NOC_BLUE1) |
53 | |
54 | |
55 | // Initialization of global variable with an instance of this class |
56 | OCCDemo_Presentation* OCCDemo_Presentation::Current = new TopLProps_Presentation; |
57 | |
58 | // Initialization of array of samples |
59 | const TopLProps_Presentation::PSampleFuncType TopLProps_Presentation::SampleFuncs[] = |
60 | { |
61 | &TopLProps_Presentation::sample1, |
62 | &TopLProps_Presentation::sample2, |
63 | &TopLProps_Presentation::sample3, |
64 | &TopLProps_Presentation::sample4 |
65 | }; |
66 | |
67 | ////////////////////////////////////////////////////////////////////// |
68 | // Construction/Destruction |
69 | ////////////////////////////////////////////////////////////////////// |
70 | |
71 | TopLProps_Presentation::TopLProps_Presentation() |
72 | { |
73 | myIndex = 0; |
74 | myNbSamples = sizeof(SampleFuncs)/sizeof(PSampleFuncType); |
75 | setName ("Local Properties of Shapes"); |
76 | } |
77 | |
78 | ////////////////////////////////////////////////////////////////////// |
79 | // Sample execution |
80 | ////////////////////////////////////////////////////////////////////// |
81 | |
82 | void TopLProps_Presentation::DoSample() |
83 | { |
84 | getAISContext()->EraseAll(); |
85 | if (myIndex >=0 && myIndex < myNbSamples) |
86 | (this->*SampleFuncs[myIndex])(); |
87 | } |
88 | |
89 | ////////////////////////////////////////////////////////////////////// |
90 | // Sample functions |
91 | ////////////////////////////////////////////////////////////////////// |
92 | //================================================================ |
93 | |
94 | //================================================================ |
95 | // Function : CreateRevolShape |
96 | // Purpose : |
97 | //================================================================ |
98 | |
99 | static TopoDS_Shape CreateRevolShape() |
100 | { |
101 | Standard_Real aCoords1[][3] = |
102 | { |
103 | {0,-8,2},{0,-7.5,1},{0,-7,0.5},{0,-6.5,1.5},{0,-6,2},{0,-5,2.5},{0,-4,2.8}, |
104 | {0,-3,2.6},{0,-2,2.4},{0,-1,2},{0,-0.5,1.5},{0,0,1.2} |
105 | }; |
106 | Standard_Real aCoords2[][3] = |
107 | { |
108 | {0,0,1.2},{0,0.5,1},{0,1,0.8},{0,2,1.2},{0,3,1.5},{0,4,2},{0,4.5,2.7},{0,5,3} |
109 | }; |
110 | |
111 | Standard_Integer nPoles1 = sizeof(aCoords1)/(sizeof(Standard_Real)*3); |
112 | Standard_Integer nPoles2 = sizeof(aCoords2)/(sizeof(Standard_Real)*3); |
113 | |
114 | TColgp_Array1OfPnt aCurvePoint1 (1, nPoles1); |
115 | TColgp_Array1OfPnt aCurvePoint2 (1, nPoles2); |
116 | |
117 | for (Standard_Integer i=0; i < nPoles1; i++) |
118 | aCurvePoint1(i+1) = gp_Pnt (aCoords1[i][0]*SCALE, aCoords1[i][1]*SCALE, aCoords1[i][2]*SCALE); |
119 | for ( i=0; i < nPoles2; i++) |
120 | aCurvePoint2(i+1) = gp_Pnt (aCoords2[i][0]*SCALE, aCoords2[i][1]*SCALE, aCoords2[i][2]*SCALE); |
121 | |
122 | GeomAPI_PointsToBSpline aPTB1 (aCurvePoint1,3,10,GeomAbs_C3,0.3*SCALE); |
123 | Handle (Geom_BSplineCurve) aCurve1 = aPTB1.Curve(); |
124 | GeomAPI_PointsToBSpline aPTB2 (aCurvePoint2,3,10,GeomAbs_C3,0.3*SCALE); |
125 | Handle (Geom_BSplineCurve) aCurve2 = aPTB2.Curve(); |
126 | |
127 | gp_Ax1 anAxis = gp_Ax1(gp_Pnt(0,0,0),gp::DY()); |
128 | GC_MakeSegment aSegment(gp_Pnt(0,-8*SCALE,0),gp_Pnt(0,-8*SCALE,2*SCALE)); |
129 | Handle_Geom_TrimmedCurve aLine = aSegment.Value(); |
130 | Handle_Geom_SurfaceOfRevolution aSurface1 = new Geom_SurfaceOfRevolution(aLine, anAxis); |
131 | Handle_Geom_SurfaceOfRevolution aSurface2 = new Geom_SurfaceOfRevolution(aCurve1, anAxis); |
132 | Handle_Geom_SurfaceOfRevolution aSurface3 = new Geom_SurfaceOfRevolution(aCurve2, anAxis); |
133 | |
134 | BRep_Builder aBuilder; |
135 | TopoDS_Compound aShape; |
136 | aBuilder.MakeCompound(aShape); |
137 | TopoDS_Face aFace1,aFace2,aFace3; |
138 | aFace1 = BRepBuilderAPI_MakeFace(aSurface1); |
139 | aFace2 = BRepBuilderAPI_MakeFace(aSurface2); |
140 | aFace3 = BRepBuilderAPI_MakeFace(aSurface3); |
141 | |
142 | aBuilder.Add(aShape,aFace1); |
143 | aBuilder.Add(aShape,aFace2); |
144 | aBuilder.Add(aShape,aFace3); |
145 | |
146 | return aShape; |
147 | } |
148 | |
149 | //================================================================ |
150 | // Function : CreateBSplShape |
151 | // Purpose : |
152 | //================================================================ |
153 | |
154 | static TopoDS_Shape CreateBSplnShape() |
155 | { |
156 | Standard_Real aZCoords1 [] = |
157 | { |
158 | -0.3,1.2,0,-0.5, |
159 | 1.5,0.5,1.5,-1.5, |
160 | 1.5,0.5,1.5,-1.5, |
161 | 0.5,-0.5,0.5,-0.5 |
162 | }; |
163 | Standard_Real aZCoords2 [] = |
164 | { |
165 | -0.3,1.2,0,-0.5, |
166 | 1.5,-1.5,-2,-1.5, |
167 | 1.5,-1.5,-2,-1.5, |
168 | 0.5,-0.5,0.5,-0.5 |
169 | }; |
170 | TColStd_Array2OfReal aZPoints1(1,4,1,4); |
171 | TColStd_Array2OfReal aZPoints2(1,4,1,4); |
172 | |
173 | Standard_Integer aColLength1 = aZPoints1.ColLength(); |
174 | Standard_Integer aRowLength1 = aZPoints1.RowLength(); |
175 | Standard_Integer aColLength2 = aZPoints2.ColLength(); |
176 | Standard_Integer aRowLength2 = aZPoints2.RowLength(); |
177 | Standard_Integer aIndex = -1; |
178 | |
179 | for(Standard_Integer i = 0 ; i < aRowLength1 ; i++) |
180 | { |
181 | for(Standard_Integer j = 0; j < aColLength1 ; j++) |
182 | { |
183 | aIndex++; |
184 | aZPoints1(i+1,j+1) = aZCoords1[aIndex]; |
185 | } |
186 | } |
187 | |
188 | aIndex = -1; |
189 | for( i = 0 ; i < aRowLength2 ; i++) |
190 | { |
191 | for(Standard_Integer j = 0; j < aColLength2 ; j++) |
192 | { |
193 | aIndex++; |
194 | aZPoints2(i+1,j+1) = aZCoords2[aIndex]; |
195 | } |
196 | } |
197 | |
198 | Standard_Real aXStep = 170, aYStep = 170; |
199 | Standard_Real aX0 = -350, aY0 = -250; |
200 | Standard_Real auxY0,auxX0 = aX0 - aXStep; |
201 | |
202 | for( i = 0 ; i < aColLength1 ; i++) |
203 | { |
204 | auxX0 += aXStep; |
205 | auxY0 = aY0 - aYStep; |
206 | |
207 | for(Standard_Integer j = 0 ; j < aRowLength1 ; j++) |
208 | { |
209 | aZPoints1(i+1,j+1) *=2*SCALE; |
210 | aZPoints2(i+1,j+1) *=2*SCALE; |
211 | auxY0 += aYStep; |
212 | } |
213 | } |
214 | |
215 | GeomAPI_PointsToBSplineSurface aPTBS; |
216 | aPTBS.Init(aZPoints1,aX0,aXStep,aY0,aYStep,3,10,GeomAbs_C3,0.3*SCALE); |
217 | Handle_Geom_BSplineSurface aSurface1 = aPTBS.Surface(); |
218 | |
219 | aPTBS.Init(aZPoints2,aX0,aXStep,aY0,aYStep,3,10,GeomAbs_C3,0.3*SCALE); |
220 | Handle_Geom_BSplineSurface aSurface2 = aPTBS.Surface(); |
221 | |
222 | TopoDS_Face aFace1,aFace2; |
223 | aFace1 = BRepBuilderAPI_MakeFace (aSurface1); |
224 | aFace2 = BRepBuilderAPI_MakeFace (aSurface2); |
225 | |
226 | BRep_Builder aBuilder; |
227 | TopoDS_Compound aShape; |
228 | aBuilder.MakeCompound(aShape); |
229 | aBuilder.Add(aShape,aFace1); |
230 | aBuilder.Add(aShape,aFace2); |
231 | |
232 | return aShape; |
233 | |
234 | } |
235 | |
236 | //================================================================ |
237 | // Function : TopLProps_Presentation::sample1 |
238 | // Purpose : |
239 | //================================================================ |
240 | |
241 | void TopLProps_Presentation::sample1() |
242 | { |
243 | TopoDS_Shape aShape = CreateRevolShape(); |
244 | |
245 | // get aNumEdge-th edge |
246 | int aNumEdge = 5; |
247 | TopExp_Explorer anExp(aShape, TopAbs_EDGE); |
248 | TopoDS_Edge aEdge; |
249 | for (int i=1; anExp.More() && i <= aNumEdge; anExp.Next(), i++) |
250 | aEdge = TopoDS::Edge(anExp.Current()); |
251 | if (aEdge.IsNull()) return; |
252 | |
253 | //show: |
254 | Handle_AIS_InteractiveObject aShowShape = drawShape(aShape); |
255 | if(WAIT_A_SECOND) return; |
256 | drawShape(aEdge,Quantity_NOC_RED); |
257 | if(WAIT_A_SECOND) return; |
258 | getAISContext()->Erase(aShowShape); |
259 | if(WAIT_A_LITTLE) return; |
260 | |
261 | Standard_Real aPoints [] = { 0.1,0.5,0.7}; |
262 | Standard_Integer aNbPoints = sizeof(aPoints)/sizeof(Standard_Real); |
263 | showEdgeLProps(aEdge,aNbPoints,aPoints); |
264 | } |
265 | |
266 | //================================================================ |
267 | // Function : TopLProps_Presentation::sample2 |
268 | // Purpose : |
269 | //================================================================ |
270 | |
271 | void TopLProps_Presentation::sample2() |
272 | { |
273 | TopoDS_Shape aShape = CreateRevolShape(); |
274 | |
275 | // get aNumFace-th face |
276 | int aNumFace = 3; |
277 | TopExp_Explorer anExp(aShape, TopAbs_FACE); |
278 | TopoDS_Face aFace; |
279 | for (int i=1; anExp.More() && i <= aNumFace; anExp.Next(), i++) |
280 | aFace = TopoDS::Face(anExp.Current()); |
281 | if (aFace.IsNull()) return; |
282 | |
283 | //show: |
284 | Handle_AIS_InteractiveObject aShowShape = drawShape(aShape); |
285 | if(WAIT_A_SECOND) return; |
286 | Handle_AIS_InteractiveObject aShowFace = drawShape(aFace,Graphic3d_NOM_BRASS,Standard_False); |
287 | getAISContext()->SetDisplayMode(aShowFace,AIS_WireFrame); |
288 | getAISContext()->Display(aShowFace); |
289 | if(WAIT_A_SECOND) return; |
290 | getAISContext()->UnsetDisplayMode(aShowFace); |
291 | getAISContext()->Erase(aShowShape); |
292 | if(WAIT_A_LITTLE) return; |
293 | |
294 | Standard_Real aPoints [][2] = { {0.1,0.1},{0.7,0.3},{0.5,0.6} }; |
295 | Standard_Integer aNbPoints = sizeof(aPoints)/(sizeof(Standard_Real)*2); |
296 | showFaceLProps(aFace,aNbPoints,aPoints); |
297 | } |
298 | |
299 | //================================================================ |
300 | // Function : TopLProps_Presentation::sample3 |
301 | // Purpose : |
302 | //================================================================ |
303 | |
304 | void TopLProps_Presentation::sample3() |
305 | { |
306 | TopoDS_Shape aShape = CreateBSplnShape(); |
307 | |
308 | // get aNumEdge-th edge |
309 | int aNumEdge = 1; |
310 | TopExp_Explorer anExp(aShape, TopAbs_EDGE); |
311 | TopoDS_Edge aEdge; |
312 | for (int i=1; anExp.More() && i <= aNumEdge; anExp.Next(), i++) |
313 | aEdge = TopoDS::Edge(anExp.Current()); |
314 | if (aEdge.IsNull()) return; |
315 | |
316 | Standard_Real aFirst,aLast; |
317 | BRep_Tool::Range(aEdge,aFirst,aLast) ; |
318 | |
319 | Standard_Real P1,P2,P3; |
320 | P1 = aFirst + (aLast-aFirst)*0.25; |
321 | P2 = aFirst + (aLast-aFirst)*0.5; |
322 | P3 = aFirst + (aLast-aFirst)*0.833; |
323 | Standard_Real aPoints [] = {P1,P2,P3 }; |
324 | Standard_Integer aNbPoints = sizeof(aPoints)/sizeof(Standard_Real); |
325 | |
326 | //show: |
327 | Handle_AIS_InteractiveObject aShowShape = drawShape(aShape); |
328 | if(WAIT_A_SECOND) return; |
329 | |
330 | drawShape(aEdge,Quantity_NOC_RED); |
331 | if(WAIT_A_SECOND) return; |
332 | getAISContext()->Erase(aShowShape); |
333 | if(WAIT_A_LITTLE) return; |
334 | |
335 | showEdgeLProps(aEdge,aNbPoints,aPoints); |
336 | } |
337 | |
338 | //================================================================ |
339 | // Function : TopLProps_Presentation::sample4 |
340 | // Purpose : |
341 | //================================================================ |
342 | |
343 | void TopLProps_Presentation::sample4() |
344 | { |
345 | TopoDS_Shape aShape = CreateBSplnShape(); |
346 | |
347 | // get aNumFace-th face |
348 | int aNumFace = 1; |
349 | TopExp_Explorer anExp(aShape, TopAbs_FACE); |
350 | TopoDS_Face aFace; |
351 | for (int i=1; anExp.More() && i <= aNumFace; anExp.Next(), i++) |
352 | aFace = TopoDS::Face(anExp.Current()); |
353 | if (aFace.IsNull()) return; |
354 | |
355 | Standard_Real UMin,UMax,VMin,VMax; |
356 | BRepTools::UVBounds(aFace,UMin,UMax,VMin,VMax); |
357 | Standard_Real U1 = UMin + (UMax-UMin)*0.769, |
358 | U2 = UMin + (UMax-UMin)*0.833, |
359 | U3 = UMin + (UMax-UMin)*0.333, |
360 | V1 = VMin + (VMax-VMin)*0.333, |
361 | V2 = VMin + (VMax-VMin)*0.5, |
362 | V3 = VMin + (VMax-VMin)*0.667; |
363 | Standard_Real aPoints [][2] = |
364 | { |
365 | {U1,V1},{U2,V2},{U3,V3} |
366 | }; |
367 | Standard_Integer aNbPoints = sizeof(aPoints)/(sizeof(Standard_Real)*2); |
368 | |
369 | //show: |
370 | Handle_AIS_InteractiveObject aShowShape = drawShape(aShape); |
371 | if(WAIT_A_SECOND) return; |
372 | Handle_AIS_InteractiveObject aShowFace = drawShape(aFace,Graphic3d_NOM_BRASS,Standard_False); |
373 | getAISContext()->SetDisplayMode(aShowFace,AIS_WireFrame); |
374 | getAISContext()->Display(aShowFace); |
375 | if(WAIT_A_SECOND) return; |
376 | getAISContext()->UnsetDisplayMode(aShowFace); |
377 | getAISContext()->Erase(aShowShape); |
378 | if(WAIT_A_LITTLE) return; |
379 | |
380 | showFaceLProps(aFace,aNbPoints,aPoints); |
381 | } |
382 | |
383 | //================================================================ |
384 | // Function : TopLProps_Presentation::showEdgeLProps |
385 | // Purpose : |
386 | //================================================================ |
387 | |
388 | void TopLProps_Presentation::showEdgeLProps(TopoDS_Edge& theEdge, |
389 | const Standard_Integer theNbPoints, |
390 | const Standard_Real thePoints[]) |
391 | { |
392 | TCollection_AsciiString aTitle ("Local properties on edge"); |
393 | TCollection_AsciiString aText = |
394 | " // Create an Edge" EOL |
395 | " TopoDS_Edge theEdge;" EOL |
396 | " // initialize theEdge" EOL |
397 | " // theEdge = ... ;" EOL EOL |
398 | |
399 | " // define parameter at which properties should be computed" EOL |
400 | " Standard_Real aParam;" EOL |
401 | " // aParam = ..." EOL EOL |
402 | |
403 | " // create an algorithm for computing the local properties" EOL |
404 | " // at a point on an edge" EOL |
405 | " BRepAdaptor_Curve anAdapCurve (theEdge) ;" EOL |
406 | " Standard_Integer maxOrder = 3;" EOL |
407 | " Standard_Real aResol = gp::Resolution();" EOL |
408 | " BRepLProp_CLProps aLProps (anAdapCurve,maxOrder,aResol);" EOL EOL |
409 | |
410 | " // compute local properties" EOL |
411 | " aLProps.SetParameter (aParam);" EOL |
412 | " gp_Pnt aPnt = aLProps.Value();" EOL |
413 | " gp_Vec aVecD1 = aLProps.D1();" EOL |
414 | " gp_Vec aVecD2 = aLProps.D2();" EOL |
415 | " gp_Vec aVecD3 = aLProps.D3();" EOL |
416 | " gp_Dir aTangent, aNormal;" EOL |
417 | " Standard_Real aCurvature;" EOL |
418 | " gp_Pnt aCentreOfCurvature;" EOL |
419 | " Standard_Boolean isCurvatureValid = Standard_False;" EOL |
420 | " Standard_Boolean isTan = aLProps.IsTangentDefined();" EOL EOL |
421 | |
422 | " // the tangent must be defined" EOL |
423 | " // to compute the curvature and the normal" EOL |
424 | " if (isTan)" EOL |
425 | " {" EOL |
426 | " aLProps.Tangent (aTangent);" EOL |
427 | " aCurvature = aLProps.Curvature();" EOL |
428 | " // the curvature must be non-null and finite" EOL |
429 | " // to compute the centre of curvature and the normal" EOL |
430 | " if (aCurvature > aResol && !Precision::IsInfinite(aCurvature))" EOL |
431 | " {" EOL |
432 | " isCurvatureValid = Standard_True;" EOL |
433 | " aLProps.CentreOfCurvature (aCentreOfCurvature);" EOL |
434 | " aLProps.Normal (aNormal);" EOL |
435 | " }" EOL |
436 | " }" EOL EOL |
437 | "//======================================" EOL; |
438 | setResultTitle (aTitle.ToCString()); |
439 | setResultText (aText.ToCString()); |
440 | |
441 | BRepAdaptor_Curve anAdapCurve (theEdge) ; |
442 | Handle_AIS_InteractiveObject aObjs[7]; |
443 | Standard_Integer maxOrder = 3; |
444 | Standard_Real aResol = gp::Resolution(); |
445 | BRepLProp_CLProps aLProps (anAdapCurve,maxOrder,aResol); |
446 | for(Standard_Integer i = 0; i < theNbPoints ; i++) |
447 | { |
448 | if (WAIT_A_LITTLE) return; |
449 | |
450 | for (int j=0; j < sizeof(aObjs)/sizeof(Handle(AIS_InteractiveObject)); j++) |
451 | if (!aObjs[j].IsNull()) |
452 | getAISContext()->Erase(aObjs[j]); |
453 | |
454 | // compute local properties |
455 | aLProps.SetParameter (thePoints[i]); |
456 | gp_Pnt aPnt = aLProps.Value(); |
457 | gp_Vec aVecD1 = aLProps.D1(); |
458 | gp_Vec aVecD2 = aLProps.D2(); |
459 | gp_Vec aVecD3 = aLProps.D3(); |
460 | gp_Dir aTangent, aNormal; |
461 | Standard_Real aCurvature; |
462 | gp_Pnt aCentreOfCurvature; |
463 | Standard_Boolean isCurvatureValid = Standard_False; |
464 | Standard_Boolean isTan = aLProps.IsTangentDefined(); |
465 | |
466 | // the tangent must be defined |
467 | // to compute the curvature and the normal |
468 | if (isTan) |
469 | { |
470 | aLProps.Tangent (aTangent); |
471 | aCurvature = aLProps.Curvature(); |
472 | // the curvature must be non-null and finite |
473 | // to compute the centre of curvature and the normal |
474 | if (aCurvature > aResol && !Precision::IsInfinite(aCurvature)) |
475 | { |
476 | isCurvatureValid = Standard_True; |
477 | aLProps.CentreOfCurvature (aCentreOfCurvature); |
478 | aLProps.Normal (aNormal); |
479 | } |
480 | } |
481 | |
482 | aText += EOL " Results with parameter "; |
483 | aText += ASTR(thePoints[i]) + " :" EOL |
484 | "aPnt = (" + PRINT_COORDS(aPnt) + ")" EOL |
485 | "aVecD1 = (" + PRINT_COORDS(aVecD1) + ")" EOL |
486 | "aVecD2 = (" + PRINT_COORDS(aVecD2) + ")" EOL |
487 | "aVecD3 = (" + PRINT_COORDS(aVecD3) + ")" EOL; |
488 | if (isTan) |
489 | { |
490 | aText = aText + |
491 | "aTangent = (" + PRINT_COORDS(aTangent) + ")" EOL |
492 | "aCurvature = " + ASTR(aCurvature) + EOL; |
493 | if (isCurvatureValid) |
494 | { |
495 | aText = aText + |
496 | "aCentreOfCurvature = (" + PRINT_COORDS(aCentreOfCurvature) + ")" EOL |
497 | "aNormal = (" + PRINT_COORDS(aNormal) + ")" EOL; |
498 | } |
499 | } |
500 | else |
501 | aText += "Tangent is not defined" EOL; |
502 | setResultText (aText.ToCString()); |
503 | |
504 | //show: |
505 | aObjs[0] = drawPoint (aPnt); |
506 | aObjs[3] = drawVector (aPnt, aVecD3, D3Color); |
507 | aObjs[2] = drawVector (aPnt, aVecD2, D2Color); |
508 | aObjs[1] = drawVector (aPnt, aVecD1, D1Color); |
509 | if (isTan) |
510 | aObjs[4] = drawVector (aPnt, gp_Vec(aTangent)*50, TanColor); |
511 | if (isCurvatureValid) |
512 | { |
513 | aObjs[5] = drawVector (aPnt, gp_Vec(aNormal)*50, NormColor); |
514 | Handle(Geom_Circle) aCircle = |
515 | new Geom_Circle (gp_Ax2 (aCentreOfCurvature, aNormal^aTangent), |
516 | aCentreOfCurvature.Distance(aPnt)); |
517 | aObjs[6] = drawCurve (aCircle, CrvtColor); |
518 | } |
519 | } |
520 | } |
521 | |
522 | //================================================================ |
523 | // Function : TopLProps_Presentation::showFaceLProps |
524 | // Purpose : |
525 | //================================================================ |
526 | |
527 | void TopLProps_Presentation::showFaceLProps(TopoDS_Face& theFace, |
528 | const Standard_Integer theNbPoints, |
529 | const Standard_Real thePoints[][2]) |
530 | { |
531 | TCollection_AsciiString aTitle ("Local properties on face"); |
532 | TCollection_AsciiString aText; |
533 | aText = |
534 | " // Create a Face" EOL |
535 | " TopoDS_Face theFace;" EOL |
536 | " // initialize aFace" EOL |
537 | " // aFace = ..." EOL EOL |
538 | |
539 | " // define U and V parameters at which properties should be computed" EOL |
540 | " Standard_Real aUParam, aVParam;" EOL |
541 | " // aUParam = ..." EOL |
542 | " // aVParam = ..." EOL EOL |
543 | |
544 | " // compute local properties" EOL |
545 | " Standard_Integer maxOrder = 2;" EOL |
546 | " Standard_Real aResol = gp::Resolution();" EOL |
547 | " GeomLProp_SLProps aLProps (theSurface, maxOrder, aResol);" EOL |
548 | " aLProps.SetParameters (aUParam, aVParam);" EOL |
549 | " gp_Pnt aPnt = aLProps.Value();" EOL |
550 | " gp_Vec aVecD1U = aLProps.D1U();" EOL |
551 | " gp_Vec aVecD1V = aLProps.D1V();" EOL |
552 | " gp_Vec aVecD2U = aLProps.D2U();" EOL |
553 | " gp_Vec aVecD2V = aLProps.D2V();" EOL |
554 | " gp_Vec aVecDUV = aLProps.DUV();" EOL |
555 | " gp_Dir aTangentU, aTangentV, aNormal, aMaxCurvD, aMinCurvD;" EOL |
556 | " Standard_Real aMaxCurvature, aMinCurvature, aMeanCurvature, aGausCurvature;" EOL |
557 | " // determine availability of properties" EOL |
558 | " Standard_Boolean isTanU = aLProps.IsTangentUDefined();" EOL |
559 | " Standard_Boolean isTanV = aLProps.IsTangentVDefined();" EOL |
560 | " Standard_Boolean isNormal = aLProps.IsNormalDefined();" EOL |
561 | " Standard_Boolean isCurvature = aLProps.IsCurvatureDefined();" EOL |
562 | " if (isTanU)" EOL |
563 | " aLProps.TangentU (aTangentU);" EOL |
564 | " if (isTanV)" EOL |
565 | " aLProps.TangentV (aTangentV);" EOL |
566 | " if (isNormal)" EOL |
567 | " aNormal = aLProps.Normal();" EOL |
568 | " if (isCurvature)" EOL |
569 | " {" EOL |
570 | " aMaxCurvature = aLProps.MaxCurvature();" EOL |
571 | " aMinCurvature = aLProps.MinCurvature();" EOL |
572 | " aGausCurvature = aLProps.GaussianCurvature();" EOL |
573 | " aMeanCurvature = aLProps.MeanCurvature();" EOL |
574 | " aLProps.CurvatureDirections (aMaxCurvD, aMinCurvD);" EOL |
575 | " }" EOL EOL |
576 | "//======================================" EOL EOL; |
577 | setResultTitle (aTitle.ToCString()); |
578 | setResultText (aText.ToCString()); |
579 | |
580 | BRepAdaptor_Surface anAdapSurface (theFace); |
581 | |
582 | Standard_Integer maxOrder = 2; |
583 | Standard_Real aResol = gp::Resolution(); |
584 | BRepLProp_SLProps aLProps ( anAdapSurface, maxOrder , aResol); |
585 | Handle(AIS_InteractiveObject) aObjs[11]; |
586 | for (int i=0; i < theNbPoints; i++) |
587 | { |
588 | if (WAIT_A_LITTLE) |
589 | return; |
590 | for (int j=0; j < sizeof(aObjs)/sizeof(Handle(AIS_InteractiveObject)); j++) |
591 | if (!aObjs[j].IsNull()) |
592 | getAISContext()->Erase(aObjs[j]); |
593 | |
594 | // compute local properties |
595 | aLProps.SetParameters (thePoints[i][0], thePoints[i][1]); |
596 | gp_Pnt aPnt = aLProps.Value(); |
597 | gp_Vec aVecD1U = aLProps.D1U(); |
598 | gp_Vec aVecD1V = aLProps.D1V(); |
599 | gp_Vec aVecD2U = aLProps.D2U(); |
600 | gp_Vec aVecD2V = aLProps.D2V(); |
601 | gp_Vec aVecDUV = aLProps.DUV(); |
602 | gp_Dir aTangentU, aTangentV, aNormal, aMaxCurvD, aMinCurvD; |
603 | Standard_Real aMaxCurvature, aMinCurvature, aMeanCurvature, aGausCurvature; |
604 | // determine availability of properties |
605 | Standard_Boolean isTanU = aLProps.IsTangentUDefined(); |
606 | Standard_Boolean isTanV = aLProps.IsTangentVDefined(); |
607 | Standard_Boolean isNormal = aLProps.IsNormalDefined(); |
608 | Standard_Boolean isCurvature = aLProps.IsCurvatureDefined(); |
609 | if (isTanU) |
610 | aLProps.TangentU (aTangentU); |
611 | if (isTanV) |
612 | aLProps.TangentV (aTangentV); |
613 | if (isNormal) |
614 | aNormal = aLProps.Normal(); |
615 | if (isCurvature) |
616 | { |
617 | aMaxCurvature = aLProps.MaxCurvature(); |
618 | aMinCurvature = aLProps.MinCurvature(); |
619 | aGausCurvature = aLProps.GaussianCurvature(); |
620 | aMeanCurvature = aLProps.MeanCurvature(); |
621 | aLProps.CurvatureDirections (aMaxCurvD, aMinCurvD); |
622 | } |
623 | |
624 | aText = aText + EOL " Results with parameters " |
625 | "U=" + ASTR(thePoints[i][0]) + " V=" + ASTR(thePoints[i][1]) + " :" EOL |
626 | "aPnt = (" + PRINT_COORDS(aPnt) + ")" EOL |
627 | "aVecD1U = (" + PRINT_COORDS(aVecD1U) + ")" EOL |
628 | "aVecD1V = (" + PRINT_COORDS(aVecD1V) + ")" EOL |
629 | "aVecD2U = (" + PRINT_COORDS(aVecD2U) + ")" EOL |
630 | "aVecD2V = (" + PRINT_COORDS(aVecD2V) + ")" EOL |
631 | "aVecDUV = (" + PRINT_COORDS(aVecDUV) + ")" EOL; |
632 | if (isTanU) |
633 | aText = aText + |
634 | "aTangentU = (" + PRINT_COORDS(aTangentU) + ")" EOL; |
635 | if (isTanV) |
636 | aText = aText + |
637 | "aTangentV = (" + PRINT_COORDS(aTangentV) + ")" EOL; |
638 | if (isNormal) |
639 | aText = aText + |
640 | "aNormal = (" + PRINT_COORDS(aNormal) + ")" EOL; |
641 | if (isCurvature) |
642 | aText = aText + |
643 | "aMaxCurvature = " + ASTR(aMaxCurvature) + EOL |
644 | "aMinCurvature = " + ASTR(aMinCurvature) + EOL |
645 | "aMeanCurvature = " + ASTR(aMeanCurvature) + EOL |
646 | "aGausCurvature = " + ASTR(aGausCurvature) + EOL |
647 | "aMaxCurvD = (" + PRINT_COORDS(aMaxCurvD) + ")" EOL |
648 | "aMinCurvD = (" + PRINT_COORDS(aMinCurvD) + ")" EOL; |
649 | setResultText (aText.ToCString()); |
650 | |
651 | //show: |
652 | aObjs[0] = drawPoint (aPnt); |
653 | aObjs[3] = drawVector (aPnt, aVecD2U, D2Color); |
654 | aObjs[4] = drawVector (aPnt, aVecD2V, D2Color); |
655 | aObjs[1] = drawVector (aPnt, aVecD1U, D1Color); |
656 | aObjs[2] = drawVector (aPnt, aVecD1V, D1Color); |
657 | aObjs[5] = drawVector (aPnt, aVecDUV, D3Color); |
658 | if (isTanU) |
659 | aObjs[6] = drawVector (aPnt, gp_Vec(aTangentU)*50, TanColor); |
660 | if (isTanV) |
661 | aObjs[7] = drawVector (aPnt, gp_Vec(aTangentV)*50, TanColor); |
662 | if (isNormal) |
663 | aObjs[8] = drawVector (aPnt, gp_Vec(aNormal)*50, NormColor); |
664 | if (isCurvature) |
665 | { |
666 | aObjs[9] = drawVector (aPnt, gp_Vec(aMaxCurvD)*50, CrvtColor); |
667 | aObjs[10] = drawVector (aPnt, gp_Vec(aMinCurvD)*50, CrvtColor); |
668 | } |
669 | |
670 | } |
671 | } |