Salome HOME
Fix problem with partition (merge fix of PKV from BR_QT4_Dev branch)
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_FinderShapeOn.cxx
index c3a5b7cfc0cab8a32b34f5728c8d7b8118183bd2..237e81ef4775d21e29b041eea9ffdf7d8e7120b0 100644 (file)
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <TopTools_DataMapOfShapeShape.hxx>
 
+#include <Bnd_Box.hxx>
+#include <BRepBndLib.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
+
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 
@@ -527,6 +531,58 @@ void GEOMAlgo_FinderShapeOn::CopySource(const TopoDS_Shape& aE,
   //
   aEx.Free(bFree);
 }
+//
+//=======================================================================
+//function : BuildTriangulation
+//purpose  : 
+//=======================================================================
+bool GEOMAlgo_FinderShapeOn::BuildTriangulation (const TopoDS_Shape& theShape)
+{
+  // calculate deflection
+  Standard_Real aDeviationCoefficient = 0.001;
+
+  Bnd_Box B;
+  BRepBndLib::Add(theShape, B);
+  Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+  B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+
+  Standard_Real dx = aXmax - aXmin, dy = aYmax - aYmin, dz = aZmax - aZmin;
+  Standard_Real aDeflection = Max(Max(dx, dy), dz) * aDeviationCoefficient * 4;
+  Standard_Real aHLRAngle = 0.349066;
+
+  // build triangulation
+  BRepMesh_IncrementalMesh Inc (theShape, aDeflection, Standard_False, aHLRAngle);
+
+  // check triangulation
+  bool isTriangulation = true;
+
+  TopExp_Explorer exp (theShape, TopAbs_FACE);
+  if (exp.More())
+  {
+    TopLoc_Location aTopLoc;
+    Handle(Poly_Triangulation) aTRF;
+    aTRF = BRep_Tool::Triangulation(TopoDS::Face(exp.Current()), aTopLoc);
+    if (aTRF.IsNull()) {
+      isTriangulation = false;
+    }
+  }
+  else // no faces, try edges
+  {
+    TopExp_Explorer expe (theShape, TopAbs_EDGE);
+    if (!expe.More()) {
+      isTriangulation = false;
+    }
+    else {
+      TopLoc_Location aLoc;
+      Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(TopoDS::Edge(expe.Current()), aLoc);
+      if (aPE.IsNull()) {
+        isTriangulation = false;
+      }
+    }
+  }
+
+  return isTriangulation;
+}
 
 //
 // myErrorStatus :
@@ -544,4 +600,3 @@ void GEOMAlgo_FinderShapeOn::CopySource(const TopoDS_Shape& aE,
 // myWarningStatus
 //
 // 10 -subshapes of type myShapeType can not be fond in myShape
-