From 1db58605595f2b040d3131f40d2e7e72762a84cc Mon Sep 17 00:00:00 2001 From: skv Date: Wed, 20 Nov 2013 11:46:04 +0000 Subject: [PATCH] 22315: Fix the imported shape orientation --- src/STLImport/STLImport.cxx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/STLImport/STLImport.cxx b/src/STLImport/STLImport.cxx index dcc71d7d3..5426b0190 100755 --- a/src/STLImport/STLImport.cxx +++ b/src/STLImport/STLImport.cxx @@ -25,8 +25,14 @@ #include "utilities.h" +#include +#include +#include +#include #include #include +#include +#include #include #include @@ -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; -- 2.39.2