1 // GProps_Presentation.cpp: implementation of the GProps_Presentation class.
2 // Global Properties of Shapes
3 //////////////////////////////////////////////////////////////////////
6 #include "GProps_Presentation.h"
8 #include <BRepTools.hxx>
9 #include <TopoDS_Shape.hxx>
10 #include <BRep_Builder.hxx>
11 #include <GProp_PGProps.hxx>
12 #include <TColgp_Array1OfPnt.hxx>
13 #include <TColStd_Array1OfReal.hxx>
14 #include <Geom_TrimmedCurve.hxx>
15 #include <Geom_Circle.hxx>
16 #include <BRepGProp.hxx>
17 #include <GProp_PrincipalProps.hxx>
18 #include <Geom_BezierCurve.hxx>
19 #include <TopoDS_Edge.hxx>
20 #include <BRepBuilderAPI_MakeEdge.hxx>
21 #include <BRepBuilderAPI_MakeWire.hxx>
22 #include <TopoDS_Wire.hxx>
23 #include <TopoDS_Shell.hxx>
24 #include <TopExp_Explorer.hxx>
25 #include <BRepBuilderAPI_MakeShell.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <AIS_Point.hxx>
29 #include <TopoDS_Solid.hxx>
31 #include <Geom_SurfaceOfRevolution.hxx>
32 #include <BRepBuilderAPI_MakeFace.hxx>
33 #include <BRepBuilderAPI_Transform.hxx>
34 #include <gp_Ax2d.hxx>
35 #include <gp_Trsf2d.hxx>
36 #include <gp_Trsf.hxx>
37 #include <BRepBuilderAPI_MakeSolid.hxx>
38 #include <TopoDS_Compound.hxx>
39 #include <TColgp_Array2OfPnt.hxx>
40 #include <GeomAPI_PointsToBSplineSurface.hxx>
43 // Initialization of global variable with an instance of this class
44 OCCDemo_Presentation* OCCDemo_Presentation::Current = new GProps_Presentation;
46 // Initialization of array of samples
47 const GProps_Presentation::PSampleFuncType GProps_Presentation::SampleFuncs[] =
49 &GProps_Presentation::samplePoints,
50 &GProps_Presentation::sampleCurves,
51 &GProps_Presentation::sampleSurfaces,
52 &GProps_Presentation::sampleVolumes,
53 &GProps_Presentation::sampleSystem
62 #define CUSTOM_INERTIAL_ELEMS_COLOR Quantity_NOC_CYAN1
63 #define MAIN_ELEMS_COLOR Quantity_NOC_RED
64 #define SEC_AXIS_COLOR Quantity_NOC_GREEN
66 #define SCALE_FACTOR 15
67 #define SCALE_FACTOR_FOR_VECTORS SCALE_FACTOR*5
69 //////////////////////////////////////////////////////////////////////
70 // Construction/Destruction
71 //////////////////////////////////////////////////////////////////////
73 GProps_Presentation::GProps_Presentation()
75 myNbSamples = sizeof(SampleFuncs)/sizeof(PSampleFuncType);
76 setName ("Global Properties of Points, Lines, Surfaces and Volumes");
79 //////////////////////////////////////////////////////////////////////
81 //////////////////////////////////////////////////////////////////////
83 void GProps_Presentation::DoSample()
85 getAISContext()->EraseAll();
86 if (myIndex >=0 && myIndex < myNbSamples)
87 (this->*SampleFuncs[myIndex])();
90 //////////////////////////////////////////////////////////////////////
92 //////////////////////////////////////////////////////////////////////
94 Standard_Boolean GProps_Presentation::GProps(GProp_GProps& aProps,
95 gp_Ax1& anAxisForInertialProp,
96 TCollection_AsciiString& theText,
97 TCollection_AsciiString theMassStr)
100 " gp_Pnt aCenterOfMass;// center of mass of the system" EOL
101 " Standard_Real aMass; // mass of the system" EOL
103 " Standard_Real aRadiusOfGyration;// radius of gyration around a given axis" EOL
104 " Standard_Real aMomentOfInertia; // moment of inertia around a given axis" EOL
106 " Standard_Real aPrincipalRadiusOfGyrationXX; // radiuses of gyration around " EOL
107 " Standard_Real aPrincipalRadiusOfGyrationYY; // the main inertial axes" EOL
108 " Standard_Real aPrincipalRadiusOfGyrationZZ;" EOL
110 " Standard_Real aPrincipalMomentOfInertiaXX; // moments of inertia around " EOL
111 " Standard_Real aPrincipalMomentOfInertiaYY; // the main inertial axes" EOL
112 " Standard_Real aPrincipalMomentOfInertiaZZ;" EOL
114 " gp_Ax1 anAxisForInertialProp; // axis to compute inertial properties" EOL
115 " // initializing anAxisForInertialProp" EOL
118 " GProp_PrincipalProps aPrincipalProps; // the object that returns inertial properties" EOL
120 " gp_Vec aFInertiaAxVec; // inertial axes as they are returned by aPrincipalProps" EOL
121 " gp_Vec aSInertiaAxVec;" EOL
122 " gp_Vec aTInertiaAxVec;" EOL
124 " aCenterOfMass = aProps.CentreOfMass();" EOL
125 " aMass = aProps.Mass();" EOL
127 " // axis for calculation gyration and inertia properties" EOL
128 " aPrincipalProps = aProps.PrincipalProperties();" EOL
130 " if (!aPrincipalProps.HasSymmetryPoint())" EOL
132 " aFInertiaAxVec = aPrincipalProps.FirstAxisOfInertia();" EOL
134 " // computing a radiuses of gyration and moment of inertia " EOL
135 " // around the main axes of inertia" EOL
136 " aPrincipalProps.RadiusOfGyration(aPrincipalRadiusOfGyrationXX, " EOL
137 " aPrincipalRadiusOfGyrationYY, aPrincipalRadiusOfGyrationZZ);" EOL
138 " aPrincipalProps.Moments(aPrincipalMomentOfInertiaXX, " EOL
139 " aPrincipalMomentOfInertiaYY, aPrincipalMomentOfInertiaZZ); " EOL
141 " if (!aPrincipalProps.HasSymmetryAxis())" EOL
143 " aSInertiaAxVec = aPrincipalProps.SecondAxisOfInertia();" EOL
144 " aTInertiaAxVec = aPrincipalProps.ThirdAxisOfInertia();" EOL
148 " // computing a radius of gyration and moment of inertia around a given axis" EOL
149 " aRadiusOfGyration = aProps.RadiusOfGyration(anAxisForInertialProp);" EOL
150 " aMomentOfInertia = aProps.MomentOfInertia(anAxisForInertialProp);" EOL;
151 setResultText(theText.ToCString());
153 gp_Pnt aCenterOfMass;// center of mass of the system
154 Standard_Real aMass; // mass of the system
156 Standard_Real aRadiusOfGyration;// radius of gyration around a given axis
157 Standard_Real aMomentOfInertia; // moment of inertia around a given axis
159 Standard_Real aPrincipalRadiusOfGyrationXX; // radiuses of gyration around
160 Standard_Real aPrincipalRadiusOfGyrationYY; // the main inertial axes
161 Standard_Real aPrincipalRadiusOfGyrationZZ;
163 Standard_Real aPrincipalMomentOfInertiaXX; // moments of inertia around
164 Standard_Real aPrincipalMomentOfInertiaYY; // the main inertial axes
165 Standard_Real aPrincipalMomentOfInertiaZZ;
167 GProp_PrincipalProps aPrincipalProps; // the object that returns inertial properties
169 gp_Vec aFInertiaAxVec; // inertial axes as they are returned by aPrincipalProps
170 gp_Vec aSInertiaAxVec;
171 gp_Vec aTInertiaAxVec;
173 aCenterOfMass = aProps.CentreOfMass();
174 aMass = aProps.Mass();
176 theText = theText + EOL EOL
177 " //=================================================" EOL EOL
179 " Total " + theMassStr + " = " + TCollection_AsciiString(aMass) + EOL
180 " Center of mass: ["+TCollection_AsciiString(aCenterOfMass.X())+","
181 +TCollection_AsciiString(aCenterOfMass.Y())+","
182 +TCollection_AsciiString(aCenterOfMass.Z())+"]";
184 // axis for calculation gyration and inertia properties
185 aPrincipalProps = aProps.PrincipalProperties();
187 if (!aPrincipalProps.HasSymmetryPoint())
189 aFInertiaAxVec = aPrincipalProps.FirstAxisOfInertia();
191 // computing a radiuses of gyration and moment of inertia
192 // around the main axes of inertia
193 aPrincipalProps.RadiusOfGyration(aPrincipalRadiusOfGyrationXX,
194 aPrincipalRadiusOfGyrationYY, aPrincipalRadiusOfGyrationZZ);
195 aPrincipalProps.Moments(aPrincipalMomentOfInertiaXX,
196 aPrincipalMomentOfInertiaYY, aPrincipalMomentOfInertiaZZ);
198 theText = theText + EOL EOL
199 " Moment of inertia around the first axis of inertia = " + TCollection_AsciiString(aPrincipalMomentOfInertiaXX) + EOL
200 " Moment of inertia around the second axis of inertia = " + TCollection_AsciiString(aPrincipalMomentOfInertiaYY) + EOL
201 " Moment of inertia around the third axis of inertia = " + TCollection_AsciiString(aPrincipalMomentOfInertiaZZ) + EOL EOL
203 " Radius of gyration around the first axis of inertia = " + TCollection_AsciiString(aPrincipalRadiusOfGyrationXX) + EOL
204 " Radius of gyration around the second axis of inertia = " + TCollection_AsciiString(aPrincipalRadiusOfGyrationYY) + EOL
205 " Radius of gyration around the third axis of inertia = " + TCollection_AsciiString(aPrincipalRadiusOfGyrationZZ);
207 if (!aPrincipalProps.HasSymmetryAxis())
209 aSInertiaAxVec = aPrincipalProps.SecondAxisOfInertia();
210 aTInertiaAxVec = aPrincipalProps.ThirdAxisOfInertia();
214 // computing a radius of gyration and moment of inertia around a given axis
215 aRadiusOfGyration = aProps.RadiusOfGyration(anAxisForInertialProp);
216 aMomentOfInertia = aProps.MomentOfInertia(anAxisForInertialProp);
218 theText = theText + EOL + EOL
219 " Radius of gyration around an axis = " + TCollection_AsciiString(aRadiusOfGyration) + EOL
220 " Moment of inertia around an axis = " + TCollection_AsciiString(aMomentOfInertia) + EOL;
221 setResultText(theText.ToCString());
223 // ========= output =======================================
224 // display the given axis
225 gp_Lin aLin(anAxisForInertialProp.Location(), anAxisForInertialProp.Direction());
226 // aParam = Parameter Of Projection Of CenterOfMass Onto AxisForInertialProp
227 Standard_Real aParam = ElCLib::Parameter(aLin, aCenterOfMass);
228 gp_Pnt aProjectedCenterOfMass = ElCLib::Value(aParam, aLin);
230 gp_Ax2 anInertialCoordSys;
231 anInertialCoordSys.SetDirection(anAxisForInertialProp.Direction());
232 anInertialCoordSys.SetLocation(aProjectedCenterOfMass);
234 // display a point on the axis around which the properties were calculated
235 drawPoint(aProjectedCenterOfMass, CUSTOM_INERTIAL_ELEMS_COLOR);
237 // display the axis around which the properties were calculated
238 gp_Vec aVec(anAxisForInertialProp.Direction());
239 aVec.SetXYZ(aVec.XYZ()*SCALE_FACTOR_FOR_VECTORS);
240 drawVector(aProjectedCenterOfMass, aVec, CUSTOM_INERTIAL_ELEMS_COLOR);
242 if (WAIT_A_SECOND) return Standard_False;
244 Handle(AIS_Point) aPointIO = drawPoint(
245 aCenterOfMass, MAIN_ELEMS_COLOR, Standard_False);
246 aPointIO->UnsetMarker();
247 aPointIO->SetMarker(Aspect_TOM_O);
248 getAISContext()->Display(aPointIO);
250 if (WAIT_A_SECOND) return Standard_False;
252 // displaying inertial axes, main in red, other use default color
253 if (!aPrincipalProps.HasSymmetryPoint())
255 aFInertiaAxVec.SetXYZ(aFInertiaAxVec.XYZ()*SCALE_FACTOR_FOR_VECTORS);
256 drawVector(aCenterOfMass, aFInertiaAxVec, MAIN_ELEMS_COLOR);
257 if (!aPrincipalProps.HasSymmetryAxis())
259 aSInertiaAxVec.SetXYZ(aSInertiaAxVec.XYZ()*SCALE_FACTOR_FOR_VECTORS);
260 aTInertiaAxVec.SetXYZ(aTInertiaAxVec.XYZ()*SCALE_FACTOR_FOR_VECTORS);
261 drawVector(aCenterOfMass, aSInertiaAxVec, SEC_AXIS_COLOR);
262 drawVector(aCenterOfMass, aTInertiaAxVec, SEC_AXIS_COLOR);
264 if (WAIT_A_SECOND) return Standard_False;
267 // display the cirle with radius = aRadiusOfGyration
268 Handle(Geom_Circle) aCirc = new Geom_Circle(anInertialCoordSys, aRadiusOfGyration);
269 drawCurve(aCirc, CUSTOM_INERTIAL_ELEMS_COLOR);
271 return Standard_True;
275 //================================================================
276 // Function : GProps_Presentation::samplePoints
278 //================================================================
279 void GProps_Presentation::samplePoints()
282 SetViewCenter(63.470922672300, 35.981561054950);
283 SetViewScale(4.2572644504009);
285 setResultTitle("Global Properties of Points");
286 TCollection_AsciiString aText(
287 " TColgp_Array1OfPnt aPoints (1, nPoints); // points to analyze" EOL
288 " TColStd_Array1OfReal aDens (1, nPoints); // dencities of points, weights" EOL
289 " // initializing arrays of points and densities" EOL
292 " GProp_PGProps aProps(aPoints, aDens);" EOL
294 " gp_Pnt aBaryCentre; // geometric centre of shape that consists all the points" EOL
295 " aBaryCentre = GProp_PGProps::Barycentre(aPoints);" EOL);
297 // points to build the curves
298 Standard_Real aCoords[][3] = {
299 {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},
300 {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},
301 {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}
303 Standard_Integer nPoints = sizeof(aCoords)/(sizeof(Standard_Real)*3);
304 TColgp_Array1OfPnt aPoints (1, nPoints); // points to analyze
305 TColStd_Array1OfReal aDens (1, nPoints); // dencities of points, weights
306 Standard_Integer aOneColorSection = nPoints/5;
307 Standard_Integer k = SCALE_FACTOR;
308 for (Standard_Integer i=0; i < nPoints; i++)
310 aPoints(i+1) = gp_Pnt (aCoords[i][0]*k, aCoords[i][1]*k, aCoords[i][2]*k);
313 // displaying points in different colors according to their weight
314 Quantity_NameOfColor aColorName = Quantity_NOC_BLUE1;
315 if (i <= 1*aOneColorSection) aColorName = Quantity_NOC_WHITESMOKE;
316 else if (i <= 2*aOneColorSection) aColorName = Quantity_NOC_ANTIQUEWHITE1;
317 else if (i <= 3*aOneColorSection) aColorName = Quantity_NOC_YELLOW;
318 else if (i <= 4*aOneColorSection) aColorName = Quantity_NOC_GREEN;
320 drawPoint(aPoints(i+1), Quantity_Color(aColorName));
323 GProp_PGProps aProps(aPoints, aDens);
325 gp_Pnt aBaryCentre; // geometric centre of shape that consists all the points
326 aBaryCentre = GProp_PGProps::Barycentre(aPoints);
328 //if (WAIT_A_SECOND) return;
330 Handle(AIS_Point) aPointIO = drawPoint(
331 aBaryCentre, MAIN_ELEMS_COLOR, Standard_False);
332 aPointIO->SetMarker(Aspect_TOM_STAR);
333 getAISContext()->Display(aPointIO);
335 // building a CUSTOM axis for calculation of inertial properties
336 gp_Ax1 anAxisForInertialProp(gp_Pnt(5*k,5*k,5*k), gp_Dir(0.2,0.8,0));
338 if (!GProps(aProps, anAxisForInertialProp, aText, "Mass")) return;
342 //================================================================
343 // Function : GProps_Presentation::sampleCurves
345 //================================================================
346 void GProps_Presentation::sampleCurves()
349 SetViewCenter(61.308121161914, 17.674575084056);
350 SetViewScale(5.3585487153415);
352 setResultTitle("Global Linear Properties of Curves");
353 TCollection_AsciiString aText(
354 " TopoDS_Wire aWire;" EOL
355 " // initializing aWire" EOL
357 " GProp_GProps aProps; // Global properties object" EOL
359 " // initializing Global properties object with linear properties of aWire" EOL
360 " BRepGProp::LinearProperties(aWire, aProps);" EOL);
362 // constructing a wire made of several edges
363 // initializing array of points mainly used for construction of anEdge2
364 Standard_Real aCoords[][3] = {
365 {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},
366 {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},
367 {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}
369 Standard_Integer nPoints = sizeof(aCoords)/(sizeof(Standard_Real)*3);
370 TColgp_Array1OfPnt aPoints (1, nPoints);
371 Standard_Integer k = SCALE_FACTOR;
372 for (Standard_Integer i=0; i < nPoints; i++)
373 aPoints(i+1) = gp_Pnt (aCoords[i][0]*k, aCoords[i][1]*k, aCoords[i][2]*k);
375 // edge 2 is a bezier curve that starts in edge1's end point
376 Handle(Geom_BezierCurve) aCurve = new Geom_BezierCurve(aPoints);
377 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(aCurve);
379 // edge 1 is a linear edge between 2 points
380 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(-k, -k, 0), aCurve->StartPoint());
382 // edge 3 is a linear section as well
383 //TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aCurve->EndPoint(), gp_Pnt(1000, 300, 400));
385 // creating a wire that consists of the edges defined above
386 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire (anEdge1, anEdge2);
390 GProp_GProps aProps; // Global properties object
392 // initializing Global properties object with linear properties of aWire
393 BRepGProp::LinearProperties(aWire, aProps);
395 // building a CUSTOM axis for calculation of inertial properties
396 gp_Ax1 anAxisForInertialProp(gp_Pnt(5*k,3*k,3*k), gp_Dir(0.1,0.2,0.7));
398 if (!GProps(aProps, anAxisForInertialProp, aText, "Length")) return;
401 //================================================================
402 // Function : GProps_Presentation::sampleSurfaces
404 //================================================================
405 void GProps_Presentation::sampleSurfaces()
408 SetViewCenter(7.3480331410807, 5.9413176110886);
409 SetViewScale(6.0684301060407);
411 setResultTitle("Global Surface Properties of Shapes");
412 TCollection_AsciiString aText(
413 " TopoDS_Shell aShell;" EOL
414 " // initializing initial surface" EOL
417 " GProp_GProps aProps; // Global properties object" EOL
419 " // initializing Global properties object with surface properties of aShell" EOL
420 " BRepGProp::SurfaceProperties(aShell, aProps);" EOL);
422 // constructing initial surface
423 Standard_Real aZCoords [] = {{-1},{0},{0},{1},{0},{-1},{-1},{0},{0},{-1.5},{-2.5},{0},{1},{-2},{-3},{0}};
425 TColStd_Array2OfReal aZPoints(1,4,1,4);
426 TColgp_Array2OfPnt aPnt(1,4,1,4);
428 Standard_Integer aColLength = aZPoints.ColLength();
429 Standard_Integer aRowLength = aZPoints.RowLength();
430 Standard_Integer aIndex = 0;
431 Standard_Integer k = SCALE_FACTOR;
433 for(Standard_Integer i = 0 ; i < aRowLength ; i++)
434 for(Standard_Integer j = 0; j < aColLength ; j++)
435 aZPoints(i+1,j+1) = (aZCoords[aIndex++] * k);
437 Standard_Real aXStep = 1.75*k, aYStep = 1.75*k;
438 Standard_Real aXBound = -3*k, aYBound = -2*k;
440 GeomAPI_PointsToBSplineSurface aPTBS(
441 aZPoints,aXBound,aXStep,aYBound,aYStep,3,8,GeomAbs_C3,k);
443 TopoDS_Shell aShell = BRepBuilderAPI_MakeShell(aPTBS.Surface());
447 GProp_GProps aProps; // Global properties object
449 // initializing Global properties object with surface properties of aShell
450 BRepGProp::SurfaceProperties(aShell, aProps);
452 // building a CUSTOM axis for calculation of inertial properties
453 gp_Ax1 anAxisForInertialProp(gp_Pnt(-3*k,-3*k,-3*k), gp_Dir(0.33,0.33,0.33));
455 if (!GProps(aProps, anAxisForInertialProp, aText, "Area")) return;
458 //================================================================
459 // Function : GProps_Presentation::sampleVolumes
461 //================================================================
462 void GProps_Presentation::sampleVolumes()
465 SetViewCenter(83.572045344035, 38.188854653904);
466 SetViewScale(5.2570164985648);
468 setResultTitle("Global Volume Properties of Solids");
469 TCollection_AsciiString aText(
470 " TopoDS_Solid aSolid;" EOL
471 " // initializing the solid" EOL
474 " GProp_GProps aProps; // Global properties object" EOL
476 " // initializing Global properties object with volume properties of aSolid" EOL
477 " BRepGProp::VolumeProperties(aSolid, aProps);" EOL);
479 // constructing initial surface
481 BRep_Builder aBuilder;
482 TCollection_AsciiString aFileName(GetDataDir());
483 aFileName += "\\shape1.brep";
484 Standard_Boolean Result = BRepTools::Read(aShape, aFileName.ToCString(), aBuilder);
488 aFileName += " was not found. The sample can not be shown.";
489 setResultText(aFileName.ToCString());
494 TopExp_Explorer anExp(aShape, TopAbs_SOLID);
496 aSolid = TopoDS::Solid(anExp.Current());
500 GProp_GProps aProps; // Global properties object
502 // initializing Global properties object with volume properties of aSolid
503 BRepGProp::VolumeProperties(aSolid, aProps);
505 // building a CUSTOM axis for calculation of inertial properties
506 Standard_Integer k = SCALE_FACTOR;
507 gp_Ax1 anAxisForInertialProp(gp_Pnt(2.5*k,2.5*k,2.5*k), gp_Dir(0.2,0.8,0));
509 if (!GProps(aProps, anAxisForInertialProp, aText, "Volume")) return;
513 //================================================================
514 // Function : GProps_Presentation::sampleSystem
516 //================================================================
517 void GProps_Presentation::sampleSystem()
520 SetViewCenter(107.10015835676, 76.510352154100);
521 SetViewScale(2.3110667631188);
523 setResultTitle("Global Properties of System of Shapes");
524 TCollection_AsciiString aText(
525 " TopoDS_Compound aShape;" EOL
526 " // initializing the shape" EOL
529 " GProp_GProps aProps;" EOL
530 " GProp_GProps aLinearProps;" EOL
531 " GProp_GProps aSurfaceProps;" EOL
532 " GProp_GProps aVolumeProps;" EOL
534 " // creating a linear system, system that consists of all edges" EOL
535 " TopExp_Explorer anExp(aShape, TopAbs_EDGE, TopAbs_FACE);" EOL
536 " while (anExp.More())" EOL
538 " GProp_GProps lp;" EOL
539 " BRepGProp::LinearProperties(anExp.Current(), lp);" EOL
540 " aLinearProps.Add(lp);" EOL
544 " // creating a surface system, system that consists of all faces" EOL
545 " anExp.Init(aShape, TopAbs_FACE, TopAbs_SHELL);" EOL
546 " while (anExp.More())" EOL
548 " GProp_GProps sp;" EOL
549 " BRepGProp::SurfaceProperties(anExp.Current(), sp);" EOL
550 " aSurfaceProps.Add(sp);" EOL
554 " // creating a volume system, system that consists of all solids" EOL
555 " anExp.Init(aShape, TopAbs_SOLID);" EOL
556 " while (anExp.More())" EOL
558 " GProp_GProps vp;" EOL
559 " BRepGProp::VolumeProperties(anExp.Current(), vp);" EOL
560 " aVolumeProps.Add(vp);" EOL
564 " Standard_Real aSurfaceDensity = 2;" EOL
565 " Standard_Real aVolumeDensity = 3;" EOL
566 " aProps.Add (aLinearProps); // density = 1.0" EOL
567 " aProps.Add (aSurfaceProps, aSurfaceDensity);" EOL
568 " aProps.Add (aVolumeProps, aVolumeDensity);" EOL);
570 // building a shape "space ship" that consists of a solid, 2 faces, and 2 edges
571 Standard_Real aCoords[][3] = {{3,-1,0},{1,0,0},{0,1,0},{0,7,0},{1,8,0},{3,9,0}};
572 Standard_Integer nPoints = sizeof(aCoords)/(sizeof(Standard_Real)*3);
573 TColgp_Array1OfPnt aPoints (1, nPoints);
574 Standard_Integer k = 15;
575 for (Standard_Integer i=0; i < nPoints; i++)
576 aPoints(i+1) = gp_Pnt (aCoords[i][0]*k, aCoords[i][1]*k, aCoords[i][2]*k);
578 Handle(Geom_BezierCurve) aCurve = new Geom_BezierCurve(aPoints);
579 gp_Ax1 anAxis(aPoints(1), gp_Dir(0,1,0));
580 Handle(Geom_SurfaceOfRevolution) aSurface = new Geom_SurfaceOfRevolution(aCurve, anAxis);
581 TopoDS_Solid aSolid = BRepBuilderAPI_MakeSolid(BRepBuilderAPI_MakeShell(aSurface));
583 TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(gp_Pnt(5*k, 2*k, 0), gp_Pnt(12*k, 7*k, 0));
584 TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(gp_Pnt(12*k, 7*k, 0), gp_Pnt(12*k, 11*k, 0));
585 TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(gp_Pnt(12*k, 11*k, 0), gp_Pnt(5*k, 5*k, 0));
586 TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(gp_Pnt(5*k, 5*k, 0), gp_Pnt(5*k, 2*k, 0));
587 TopoDS_Face aWing1 = BRepBuilderAPI_MakeFace(BRepBuilderAPI_MakeWire(e1, e2, e3, e4));
589 gp_Ax2d aMirrorAx(gp_Pnt2d(3*k, 0), gp_Dir2d(0,1));
591 aTrsf2d.SetMirror(aMirrorAx);
592 gp_Trsf aTrsf(aTrsf2d);
593 BRepBuilderAPI_Transform aBuilder(aWing1, aTrsf, Standard_True);
595 aBuilder.Perform(aWing1, Standard_True);
596 TopoDS_Face aWing2 = TopoDS::Face(aBuilder.Shape());
598 Handle(Geom_Circle) aCirc = new Geom_Circle(gp_Ax2(gp_Pnt(3*k, 11*k, 0), gp_Dir(0,-0.2,0.8)), (12-3)*k);
599 Handle(Geom_TrimmedCurve) aTrimCirc = new Geom_TrimmedCurve(aCirc, -PI/2, PI/2);
600 TopoDS_Edge aSpoiler = BRepBuilderAPI_MakeEdge(aTrimCirc);
602 TopoDS_Edge anArrow = BRepBuilderAPI_MakeEdge(gp_Pnt(3*k, 0, 0), gp_Pnt(3*k, -5*k, 0));
604 TopoDS_Compound aShape;
605 BRep_Builder aCompoundBuilder;
606 aCompoundBuilder.MakeCompound(aShape);
607 aCompoundBuilder.Add(aShape,aSolid);
608 aCompoundBuilder.Add(aShape,aWing1);
609 aCompoundBuilder.Add(aShape,aWing2);
610 aCompoundBuilder.Add(aShape,anArrow);
611 aCompoundBuilder.Add(aShape,aSpoiler);
616 drawShape(anArrow, Quantity_NOC_GOLD);
617 drawShape(aSpoiler, Quantity_NOC_GOLD);
620 GProp_GProps aLinearProps;
621 GProp_GProps aSurfaceProps;
622 GProp_GProps aVolumeProps;
624 GProp_PrincipalProps aPrincipalProps;
626 // creating a linear system, system that consists of all edges
627 TopExp_Explorer anExp(aShape, TopAbs_EDGE, TopAbs_FACE);
631 BRepGProp::LinearProperties(anExp.Current(), lp);
632 aLinearProps.Add(lp);
636 // creating a surface system, system that consists of all faces
637 anExp.Init(aShape, TopAbs_FACE, TopAbs_SHELL);
641 BRepGProp::SurfaceProperties(anExp.Current(), sp);
642 aSurfaceProps.Add(sp);
646 // creating a volume system, system that consists of all solids
647 anExp.Init(aShape, TopAbs_SOLID);
651 BRepGProp::VolumeProperties(anExp.Current(), vp);
652 aVolumeProps.Add(vp);
656 Standard_Real aSurfaceDensity = 2;
657 Standard_Real aVolumeDensity = 3;
658 aProps.Add (aLinearProps); // density = 1.0
659 aProps.Add (aSurfaceProps, aSurfaceDensity);
660 aProps.Add (aVolumeProps, aVolumeDensity);
662 // Length of free edges
663 Standard_Real aEdgesLength = aLinearProps.Mass();
664 Standard_Real aFacesArea = aSurfaceProps.Mass();
665 Standard_Real aSolidsVolume = aVolumeProps.Mass();
667 // building a CUSTOM axis for calculation of inertial properties
668 gp_Ax1 anAxisForInertialProp(gp_Pnt(3.5*k,2*k,7*k), gp_Dir(-0.33,-0.33,-0.33));
670 if (!GProps(aProps, anAxisForInertialProp, aText, "Mass")) return;
673 " Length of free edges = " + TCollection_AsciiString(aEdgesLength) + EOL
674 " Area of free faces = " + TCollection_AsciiString(aFacesArea) + EOL
675 " Volume of solids = " + TCollection_AsciiString(aSolidsVolume);
676 setResultText(aText.ToCString());