]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improve GeomAlgoAPI_ShapeTools::volume() method to return the volume of the shape...
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 9 Feb 2021 14:47:18 +0000 (17:47 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 9 Feb 2021 14:47:18 +0000 (17:47 +0300)
src/BuildPlugin/Test/TestFace_WholeSketch_1.py
src/BuildPlugin/Test/TestFace_WholeSketch_2.py
src/BuildPlugin/Test/TestShell_WholeSketch_1.py
src/BuildPlugin/Test/TestShell_WholeSketch_2.py
src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp
src/FeaturesPlugin/FeaturesPlugin_BooleanSmash.cpp
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp
src/PythonAPI/model/tests/tests.py

index cc6020f426d2c4dfdddcdd7fd5e9cb9139db151f..af3b48ae51b5a2e8223266234143bce8eec6e5d5 100644 (file)
@@ -44,6 +44,6 @@ model.testNbResults(Face_1, 1)
 model.testNbSubShapes(Face_1, GeomAPI_Shape.FACE, [1])
 model.testNbSubShapes(Face_1, GeomAPI_Shape.EDGE, [3])
 model.testNbSubShapes(Face_1, GeomAPI_Shape.VERTEX, [6])
-model.testResultsVolumes(Face_1, [441.0539215686274])
+model.testResultsAreas(Face_1, [441.0539215686274])
 
 assert(model.checkPythonDump())
index 3bd558fec0cdf390c55239989d33302ec97b4730..a6b249a9a0e232d2a4ee3e309419dfb416d9f729 100644 (file)
@@ -44,6 +44,6 @@ model.testNbResults(Face_1, 3)
 model.testNbSubShapes(Face_1, GeomAPI_Shape.FACE, [1, 1, 1])
 model.testNbSubShapes(Face_1, GeomAPI_Shape.EDGE, [3, 2, 2])
 model.testNbSubShapes(Face_1, GeomAPI_Shape.VERTEX, [6, 4, 4])
-model.testResultsVolumes(Face_1, [441.0539215686274, 628.318530717958, 628.318530717958])
+model.testResultsAreas(Face_1, [441.0539215686274, 628.318530717958, 628.318530717958])
 
 assert(model.checkPythonDump())
index 552fcb8ce20e8a1d7906f2c0369c5c0c98e2db3e..79badd494f635f5f669fd7dc49db6492c76ca254 100644 (file)
@@ -44,6 +44,6 @@ model.testNbResults(Shell_1, 1)
 model.testNbSubShapes(Shell_1, GeomAPI_Shape.FACE, [1])
 model.testNbSubShapes(Shell_1, GeomAPI_Shape.EDGE, [3])
 model.testNbSubShapes(Shell_1, GeomAPI_Shape.VERTEX, [6])
-model.testResultsVolumes(Shell_1, [441.0539215686274])
+model.testResultsAreas(Shell_1, [441.0539215686274])
 
 assert(model.checkPythonDump())
index 147ba773d459677e5cd10b2d788e4d05708a0c92..553bc86668dcc1c7b4ceaad5b91eec43a53d09e8 100644 (file)
@@ -44,6 +44,6 @@ model.testNbResults(Shell_1, 2)
 model.testNbSubShapes(Shell_1, GeomAPI_Shape.FACE, [1, 2])
 model.testNbSubShapes(Shell_1, GeomAPI_Shape.EDGE, [3, 4])
 model.testNbSubShapes(Shell_1, GeomAPI_Shape.VERTEX, [6, 8])
-model.testResultsVolumes(Shell_1, [441.0539215686274, 1256.637061435917])
+model.testResultsAreas(Shell_1, [441.0539215686274, 1256.637061435917])
 
 assert(model.checkPythonDump())
index 3ab6d589c74eababd55b07e1fc95a50cc32cf734..58af291134b36127279bcd1daecfbad96e574546 100644 (file)
@@ -185,7 +185,7 @@ void FeaturesPlugin_BooleanFuse::execute()
       std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(
         new GeomAlgoAPI_Boolean(aOneObjectList, aShapesToAdd, GeomAlgoAPI_Tools::BOOL_CUT));
 
-      if (GeomAlgoAPI_ShapeTools::volume(aCutAlgo->shape()) > 1.e-27) {
+      if (GeomAlgoAPI_ShapeTools::area(aCutAlgo->shape()) > 1.e-27) {
         aSolidsToFuse.push_back(aCutAlgo->shape());
         aMakeShapeList->appendAlgo(aCutAlgo);
       }
index 0c7f3bab1f292731aa907c874482204f10440651..c38e8c5ee18436a588f3ed85933936049eaced4b 100644 (file)
@@ -110,7 +110,7 @@ void FeaturesPlugin_BooleanSmash::execute()
                               aShapesToAdd,
                               GeomAlgoAPI_Tools::BOOL_CUT));
 
-    if (GeomAlgoAPI_ShapeTools::volume(anObjectsCutAlgo->shape()) > 1.e-27) {
+    if (GeomAlgoAPI_ShapeTools::area(anObjectsCutAlgo->shape()) > 1.e-27) {
       aShapesToSmash.clear();
       aShapesToSmash.push_back(anObjectsCutAlgo->shape());
       aMakeShapeList->appendAlgo(anObjectsCutAlgo);
@@ -122,7 +122,7 @@ void FeaturesPlugin_BooleanSmash::execute()
                               aShapesToAdd,
                               GeomAlgoAPI_Tools::BOOL_CUT));
 
-    if (GeomAlgoAPI_ShapeTools::volume(aToolsCutAlgo->shape()) > 1.e-27) {
+    if (GeomAlgoAPI_ShapeTools::area(aToolsCutAlgo->shape()) > 1.e-27) {
       aTools.clear();
       aTools.push_back(aToolsCutAlgo->shape());
       aMakeShapeList->appendAlgo(aToolsCutAlgo);
index cf8706cac042826d0420bf069f56dd503e0eea14..db491704810ad039a277bd1caa1253870fad21d4 100644 (file)
@@ -181,7 +181,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools,
           return false;
         }
 
-        if(GeomAlgoAPI_ShapeTools::volume(aBoolAlgo->shape()) > 1.e-27) {
+        if(GeomAlgoAPI_ShapeTools::area(aBoolAlgo->shape()) > 1.e-27) {
           theObjects.push_back(anObject);
           theMakeShapes.push_back(aBoolAlgo);
         }
@@ -238,7 +238,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools,
           aMakeShapeList->appendAlgo(aFillerAlgo);
         }
 
-        if(GeomAlgoAPI_ShapeTools::volume(aBoolRes) > 1.e-27) {
+        if(GeomAlgoAPI_ShapeTools::area(aBoolRes) > 1.e-27) {
           theObjects.push_back(aCompSolid);
           theMakeShapes.push_back(aMakeShapeList);
         }
@@ -323,7 +323,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools,
         std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(new GeomAlgoAPI_Boolean(aSolidsToFuse,
                                                               aShapesToAdd,
                                                               GeomAlgoAPI_Tools::BOOL_CUT));
-        if(aCutAlgo->isDone() && GeomAlgoAPI_ShapeTools::volume(aCutAlgo->shape()) > 1.e-27) {
+        if(aCutAlgo->isDone() && GeomAlgoAPI_ShapeTools::area(aCutAlgo->shape()) > 1.e-27) {
           aSolidsToFuse.clear();
           aSolidsToFuse.push_back(aCutAlgo->shape());
           aMakeShapeList->appendAlgo(aCutAlgo);
index c7dc30cf9ad61c8565cae8d619235b2544c2b9f4..db8ad226bc02d7a1645718506941ed864dd863a6 100644 (file)
@@ -135,20 +135,13 @@ double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theSh
     return 0.0;
   }
   const Standard_Real anEps = 1.e-6;
-  TopExp_Explorer anExp(aShape, TopAbs_SOLID);
-  if (anExp.More()) { // return volume if there is at least one solid
-    double aVolume = 0.0;
-    for (; anExp.More(); anExp.Next()) {
-      GProp_GProps aGProps;
-      BRepGProp::VolumeProperties(anExp.Current(), aGProps, anEps);
-      aVolume += aGProps.Mass();
-    }
-    return aVolume;
+  double aVolume = 0.0;
+  for (TopExp_Explorer anExp(aShape, TopAbs_SOLID); anExp.More(); anExp.Next()) {
+    GProp_GProps aGProps;
+    BRepGProp::VolumeProperties(anExp.Current(), aGProps, anEps);
+    aVolume += aGProps.Mass();
   }
-  // return surfaces area
-  GProp_GProps aGProps;
-  BRepGProp::SurfaceProperties(aShape, aGProps, anEps);
-  return aGProps.Mass();
+  return aVolume;
 }
 
 //==================================================================================================
index 58e32136f2cd9decca891e655dcaf325fbd8b13a..ebfbfce0580400b304f4ec01ac693d3412ad4a19 100644 (file)
@@ -423,6 +423,16 @@ std::string ModelHighAPI_FeatureStore::dumpShape(std::shared_ptr<GeomAPI_Shape>&
       aResult<<std::fixed<<std::setprecision(3);
     aResult<<aVolume<<std::endl;
   }
+  double anArea = GeomAlgoAPI_ShapeTools::area(theShape);
+  if (anArea > 1.e-5) {
+    aResult << "Area: ";
+    // volumes of too huge shapes write in the scientific format
+    if (anArea >= 1.e5)
+      aResult << std::scientific << std::setprecision(7);
+    else
+      aResult << std::fixed << std::setprecision(3);
+    aResult << anArea << std::endl;
+  }
   std::shared_ptr<GeomAPI_Pnt> aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
   aResult<<"Center of mass: ";
   double aCenterVals[3] = {aCenter->x(), aCenter->y(), aCenter->z()};
index 90fe18fa6e59f55faf384cdc5ecfae30ecd6920f..a2ea86bcade75df046829b90666ae1fcd16f6b63 100644 (file)
@@ -72,6 +72,13 @@ def generateTests(theFeature, theFeatureName, theTestsList = []):
       aResultsVolumes.append(GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape()))
     print("model.testResultsVolumes({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes)))
 
+  if "testResultsAreas" in theTestsList or len(theTestsList) == 0:
+    aNbResults = len(theFeature.results())
+    aResultsVolumes = []
+    for anIndex in range(0, aNbResults):
+      aResultsAreas.append(GeomAlgoAPI_ShapeTools_area(theFeature.results()[anIndex].resultSubShapePair()[0].shape()))
+    print("model.testResultsAreas({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes)))
+
 
 def testNbResults(theFeature, theExpectedNbResults):
   """ Tests number of feature results.
@@ -132,6 +139,24 @@ def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDi
     anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0")
     assert math.fabs(aResultVolume - anExpectedResultVolume) <= aTolerance * math.fabs(anExpectedResultVolume), "Volume of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits)
 
+
+def testResultsAreas(theFeature, theExpectedResultsAreas, theNbSignificantDigits = 7):
+  """ Tests results areas.
+  :param theFeature: feature to test.
+  :param theExpectedResultsAreas: list of results volumes. Size of list should be equal to len(theFeature.results()).
+  """
+  aTolerance = 10**(-theNbSignificantDigits)
+  aNbResults = len(theFeature.results())
+  aListSize = len(theExpectedResultsVolumes)
+  assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
+  for anIndex in range(0, aNbResults):
+    aResultVolume = GeomAlgoAPI_ShapeTools_area(theFeature.results()[anIndex].resultSubShapePair()[0].shape())
+    aResultVolumeStr = "{:0.27f}".format(aResultVolume).lstrip("0").lstrip(".").lstrip("0")
+    anExpectedResultVolume = theExpectedResultsVolumes[anIndex]
+    anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0")
+    assert math.fabs(aResultVolume - anExpectedResultVolume) <= aTolerance * math.fabs(anExpectedResultVolume), "Area of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits)
+
+
 def testHaveNamingFaces(theFeature, theModel, thePartDoc) :
   """ Tests if all faces of result have a name
   :param theFeature: feature to test.