]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Optimize Boolean Fuse for the union of sub-solids of compsolid. occ/19115
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 19 May 2020 12:55:07 +0000 (15:55 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 19 May 2020 12:55:07 +0000 (15:55 +0300)
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp
src/FeaturesPlugin/Test/Test19115.py [new file with mode: 0644]

index 3dd2b67f837ea53ffb1ca8336efa60fa8b1f6526..5f3aa87e4303e3acbddaaaa45c8bfdeae2b07a7d 100644 (file)
@@ -662,4 +662,5 @@ ADD_UNIT_TESTS(TestExtrusion.py
                Test2817.py
                Test19065.py
                Test19066.py
+               Test19115.py
 )
index 2eb87085dc165d7e1a546ac460e6ab615f3139ca..4c43be8cc7e3840ac65d03260ea4e9f15657f070 100644 (file)
@@ -113,6 +113,8 @@ void FeaturesPlugin_BooleanFuse::execute()
   // in boolean operation and will be added to result.
   bool isProcessCompsolid = !isSimpleCreation || !aFuseVersion.empty();
   ListOfShape aShapesToAdd;
+  int aNbCompsolids = 0; // number of compsolids, which subs is taken into operation
+  bool hasSeparateSolids = false; // are solids or full results exist
   for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjectsHierarchy.begin();
        isProcessCompsolid && anObjectsIt != anObjectsHierarchy.end();
        ++anObjectsIt) {
@@ -120,6 +122,7 @@ void FeaturesPlugin_BooleanFuse::execute()
     GeomShapePtr aParent = anObjectsHierarchy.parent(anObject, false);
 
     if (aParent && aParent->shapeType() == GeomAPI_Shape::COMPSOLID) {
+      ++aNbCompsolids;
       // mark all subs of this parent as precessed to avoid handling twice
       aParent = anObjectsHierarchy.parent(anObject);
 
@@ -127,7 +130,10 @@ void FeaturesPlugin_BooleanFuse::execute()
       anObjectsHierarchy.splitCompound(aParent, aUsed, aNotUsed);
       aShapesToAdd.insert(aShapesToAdd.end(), aNotUsed.begin(), aNotUsed.end());
     }
+    else
+      hasSeparateSolids = true;
   }
+  bool isSingleCompsolid = aNbCompsolids == 1 && !hasSeparateSolids;
 
   ListOfShape anOriginalShapes = aSolidsToFuse;
   anOriginalShapes.insert(anOriginalShapes.end(), aShapesToAdd.begin(), aShapesToAdd.end());
@@ -150,7 +156,7 @@ void FeaturesPlugin_BooleanFuse::execute()
   }
 
   // If we have compsolids then cut with not used solids all others.
-  if (!aShapesToAdd.empty()) {
+  if (!aShapesToAdd.empty() && !isSingleCompsolid) {
     aSolidsToFuse.clear();
     for (ListOfShape::iterator
          anIt = anOriginalShapes.begin(); anIt != anOriginalShapes.end(); anIt++) {
diff --git a/src/FeaturesPlugin/Test/Test19115.py b/src/FeaturesPlugin/Test/Test19115.py
new file mode 100644 (file)
index 0000000..f7942d8
--- /dev/null
@@ -0,0 +1,87 @@
+# Copyright (C) 2020  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from GeomAPI import *
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+model.addParameter(Part_1_doc, "h", "1")
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 0.5, "h")
+Cylinder_2 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 0.1, "h")
+Cylinder_3 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 0.4, "h")
+Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOY"), 0.1, False)
+Partition_1_objects = [model.selection("SOLID", "Cylinder_1_1"), model.selection("SOLID", "Cylinder_2_1"), model.selection("SOLID", "Cylinder_3_1"), model.selection("FACE", "Plane_1"), model.selection("FACE", "PartSet/YOZ"), model.selection("FACE", "PartSet/XOZ")]
+Partition_1 = model.addPartition(Part_1_doc, Partition_1_objects, keepSubResults = True)
+Box_1 = model.addBox(Part_1_doc, 0.7, 0.1, 0.05)
+Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], 0, -0.05, "0.75*h")
+Recover_1 = model.addRecover(Part_1_doc, Partition_1, [Cylinder_1.result()])
+Cut_1 = model.addCut(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], [model.selection("SOLID", "Recover_1_1")], keepSubResults = True)
+Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Partition_1_1_14/Modified_Face&PartSet/XOZ/XOZ")])
+Recover_2 = model.addRecover(Part_1_doc, Face_1, [Partition_1.result()], True)
+Partition_2 = model.addPartition(Part_1_doc, [model.selection("COMPSOLID", "Recover_2_1"), model.selection("SOLID", "Cut_1_1")], keepSubResults = True)
+model.end()
+
+Fuse_objects = [model.selection("SOLID", "Partition_2_1_14"), model.selection("SOLID", "Partition_2_1_25"), model.selection("SOLID", "Partition_2_1_24")]
+
+
+import time
+
+tStart = time.time()
+
+model.begin()
+Union_1 = model.addUnion(Part_1_doc, Fuse_objects, keepSubResults = True)
+model.do()
+
+tUnion = time.time() - tStart
+
+model.testNbResults(Union_1, 1)
+model.testNbSubResults(Union_1, [23])
+model.testNbSubShapes(Union_1, GeomAPI_Shape.SOLID, [23])
+model.testNbSubShapes(Union_1, GeomAPI_Shape.FACE, [139])
+model.testNbSubShapes(Union_1, GeomAPI_Shape.EDGE, [550])
+model.testNbSubShapes(Union_1, GeomAPI_Shape.VERTEX, [1100])
+model.testResultsVolumes(Union_1, [0.78640233633346512398532])
+
+model.begin()
+Part_1_doc.removeFeature(Union_1.feature())
+model.end()
+
+tStart = time.time()
+
+model.begin()
+Fuse_1 = model.addFuse(Part_1_doc, Fuse_objects, keepSubResults = True)
+model.do()
+
+tFuse = time.time() - tStart
+
+model.testNbResults(Fuse_1, 1)
+model.testNbSubResults(Fuse_1, [23])
+model.testNbSubShapes(Fuse_1, GeomAPI_Shape.SOLID, [23])
+model.testNbSubShapes(Fuse_1, GeomAPI_Shape.FACE, [139])
+model.testNbSubShapes(Fuse_1, GeomAPI_Shape.EDGE, [550])
+model.testNbSubShapes(Fuse_1, GeomAPI_Shape.VERTEX, [1100])
+model.testResultsVolumes(Fuse_1, [0.78640233633346512398532])
+
+print("Elapsed time of Union: {}".format(tUnion))
+print("Elapsed time of Fuse: {}".format(tFuse))
+
+assert(tFuse <= tUnion * 1.35)