]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
22315: Fix the imported shape orientation
authorskv <skv@opencascade.com>
Wed, 20 Nov 2013 11:46:04 +0000 (11:46 +0000)
committerskv <skv@opencascade.com>
Wed, 20 Nov 2013 11:46:04 +0000 (11:46 +0000)
src/STLImport/STLImport.cxx

index dcc71d7d392c734d584c6e8c9bb80d528ebebd9c..5426b01904cffac5bb0d3584ed924f3293af1d9b 100755 (executable)
 
 
 #include "utilities.h"
+#include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepClass3d_SolidClassifier.hxx>
+#include <Precision.hxx>
 #include <StlAPI_Reader.hxx>
 #include <TCollection_AsciiString.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+#include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TDF_Label.hxx>
 
@@ -65,6 +71,35 @@ STLIMPORT_EXPORT
 
     if (aShape.IsNull()) {
       theError = "STL Import failed";
+    } else {
+      // Fix the orientation of closed shell or solid.
+      if (BRep_Tool::IsClosed(aShape)) {
+        TopAbs_ShapeEnum aType = aShape.ShapeType();
+
+        if (aType == TopAbs_SHELL || aType == TopAbs_SOLID) {
+          TopoDS_Solid aSolid;
+
+          if (aType == TopAbs_SHELL) {
+            // Create a solid.
+            BRep_Builder aBuilder;
+
+            aBuilder.MakeSolid(aSolid);
+            aBuilder.Add(aSolid, aShape);
+          } else {
+            aSolid = TopoDS::Solid(aShape);
+          }
+
+          // Classify infinite point against solid.
+          BRepClass3d_SolidClassifier aClassifier(aSolid);
+
+          aClassifier.PerformInfinitePoint(Precision::Confusion());
+
+          if (aClassifier.State() == TopAbs_IN) {
+            // The shape is inverted. Reverse it.
+            aShape.Reverse();
+          }
+        }
+      }
     }
 
     return aShape;