#include <GProp_GProps.hxx>
#include <TopoDS_Shape.hxx>
-
+//=================================================================================================
double GeomAlgoAPI_ShapeProps::volume(std::shared_ptr<GeomAPI_Shape> theShape)
{
GProp_GProps aGProps;
- TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ if(!theShape) {
+ return 0.0;
+ }
+ const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+ if(aShape.IsNull()) {
+ return 0.0;
+ }
BRepGProp::VolumeProperties(aShape, aGProps);
return aGProps.Mass();
-}
\ No newline at end of file
+}
+
+//=================================================================================================
+std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeProps::centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ GProp_GProps aGProps;
+ if(!theShape) {
+ return std::shared_ptr<GeomAPI_Pnt>();
+ }
+ const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+ if(aShape.IsNull()) {
+ return std::shared_ptr<GeomAPI_Pnt>();
+ }
+ BRepGProp::SurfaceProperties(aShape, aGProps);
+ gp_Pnt aCentre = aGProps.CentreOfMass();
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
+}