]> OCCT Git - occt-copy.git/commitdiff
API extension CR0-CFM-NEW CR0-CFM-OCCT7.0
authorduv <duv@opencascade.com>
Fri, 9 Sep 2016 13:47:28 +0000 (16:47 +0300)
committerduv <duv@opencascade.com>
Fri, 9 Sep 2016 13:47:28 +0000 (16:47 +0300)
src/BRepMesh/BRepMesh_RestoreOrientationTool.cxx
src/BRepMesh/BRepMesh_RestoreOrientationTool.hxx
src/BRepMesh/BRepMesh_TriangulatedPatch.hxx

index b5e9e772e1d96cf17ef6ddfa85187c35820fe223..3270da0d7f1f8684eb2489eecc4c896f31b7bc31 100644 (file)
@@ -57,12 +57,6 @@ const BVH_Vec3d THE_MIN_VEC (1e-100, 1e-100, 1e-100);
 // Relative weight of coherency component for optimization.
 const Standard_Real COHERENCY_WEIGHT = 50.0;
 
-// Minimum number of traced rays per face.
-const Standard_Integer MIN_FACE_RAYS = 50;
-
-// Maximum number of traced rays per face.
-const Standard_Integer MAX_FACE_RAYS = 2000;
-
 // Indicates that ray does not hit any geometry.
 const Standard_Integer INVALID_HIT = -1;
 
@@ -232,8 +226,12 @@ bool overlapBoxes (const BVH_Vec3d& theBoxMin1,
 // function : BRepMesh_RestoreOrientationTool
 // purpose  :
 // =======================================================================
-BRepMesh_RestoreOrientationTool::BRepMesh_RestoreOrientationTool (const bool theVisibilityOnly /* false */)
-  : myIsDone (false),
+BRepMesh_RestoreOrientationTool::BRepMesh_RestoreOrientationTool (const bool theVisibilityOnly /* false */,
+                                                                  const Standard_Integer theMinFaceRays /* 50 */,
+                                                                  const Standard_Integer theMaxFaceRays /* 2000 */)
+  : MinFaceRays (theMinFaceRays),
+    MaxFaceRays (theMaxFaceRays),
+    myIsDone (false),
     myVisibilityOnly (theVisibilityOnly)
 {
   //
@@ -244,8 +242,12 @@ BRepMesh_RestoreOrientationTool::BRepMesh_RestoreOrientationTool (const bool the
 // purpose  :
 // =======================================================================
 BRepMesh_RestoreOrientationTool::BRepMesh_RestoreOrientationTool (const TopoDS_Shape& theShape,
-                                                                  const bool theVisibilityOnly /* false */)
-  : myIsDone (false),
+                                                                  const bool theVisibilityOnly /* false */,
+                                                                  const Standard_Integer theMinFaceRays /* 50 */,
+                                                                  const Standard_Integer theMaxFaceRays /* 2000 */)
+  : MinFaceRays (theMinFaceRays),
+    MaxFaceRays (theMaxFaceRays),
+    myIsDone (false),
     myVisibilityOnly (theVisibilityOnly)
 {
   Init (theShape);
@@ -257,6 +259,7 @@ BRepMesh_RestoreOrientationTool::BRepMesh_RestoreOrientationTool (const TopoDS_S
 // =======================================================================
 void BRepMesh_RestoreOrientationTool::Init (const TopoDS_Shape& theShape)
 {
+  myShape = TopoDS_Shape();
   if (theShape.IsNull())
   {
     Standard_NullObject::Raise();
@@ -653,7 +656,7 @@ void BRepMesh_RestoreOrientationTool::Perform (const Handle(Message_ProgressIndi
 #endif
 
   // Flipped flags for all patches.
-  std::vector<char> aFlipped (myPatches.size(), 0);
+  myFlipped.resize (myPatches.size(), 0);
   std::vector<char> aFlippedC (myPatches.size(), 0);
 
   Standard_Real aMaxCoherence = -std::numeric_limits<Standard_Real>::max();
@@ -744,7 +747,7 @@ void BRepMesh_RestoreOrientationTool::Perform (const Handle(Message_ProgressIndi
             aFlippedC[aPatchId] = aFlippedC[aPatchId] == 0 ? 1 : 0;
           }
 
-          aFlipped[aPatchId] = aFlipped[aPatchId] == 0 ? 1 : 0;
+          myFlipped[aPatchId] = myFlipped[aPatchId] == 0 ? 1 : 0;
         }
 
         for (Standard_Size i = 0; i < aTable->Size(); ++i)
@@ -837,10 +840,10 @@ void BRepMesh_RestoreOrientationTool::Perform (const Handle(Message_ProgressIndi
   for (Standard_Integer i = 0; i < aPatchesNb; ++i)
   {
     Handle (BRepMesh_TriangulatedPatch)& aTriPatch = myPatches[i];
-    Standard_Integer aRaysNb = Max (MIN_FACE_RAYS, static_cast<Standard_Integer> (aTriPatch->TotalArea() * anInvMaxArea * MAX_FACE_RAYS));
+    Standard_Integer aRaysNb = Max (MinFaceRays, static_cast<Standard_Integer> (aTriPatch->TotalArea() * anInvMaxArea * MaxFaceRays));
     computeVisibility (myTriangulation, aTriPatch, aRaysNb);
 
-    if (!myVisibilityOnly && aFlipped[i])
+    if (!myVisibilityOnly && myFlipped[i])
     {
       aTriPatch->FlipVisibility();
     }
@@ -896,7 +899,7 @@ void BRepMesh_RestoreOrientationTool::Perform (const Handle(Message_ProgressIndi
           continue;
         }
 
-        bool isCoherenceFlipped = (aFlipped[i] ^ aFlipped[j] ^ aFlippedC[i] ^ aFlippedC[j]) != 0;
+        bool isCoherenceFlipped = (myFlipped[i] ^ myFlipped[j] ^ aFlippedC[i] ^ aFlippedC[j]) != 0;
         Standard_Real aCoherence = aTable->getCoherence (i, j) * aInvMaxCoherence  * (isCoherenceFlipped ? -1.0 : 1.0);
 
         if (aCoherence > 0.0)
@@ -923,7 +926,7 @@ void BRepMesh_RestoreOrientationTool::Perform (const Handle(Message_ProgressIndi
   {
     if (aGraph->Label (aVariables[i]) == 1)
     {
-      aFlipped[i] = aFlipped[i] == 0 ? 1 : 0;
+      myFlipped[i] = myFlipped[i] == 0 ? 1 : 0;
     }
   }
 
@@ -932,19 +935,71 @@ void BRepMesh_RestoreOrientationTool::Perform (const Handle(Message_ProgressIndi
   std::cout << "Optimization time:  " << aTimer.ElapsedTime() << std::endl;
 #endif
 
-  BRep_Builder aBuilder;
-  TopoDS_Compound aCompound;
-  aBuilder.MakeCompound (aCompound);
+  aTable.reset();
+
+  myIsDone = true;
+}
+
+// =======================================================================
+// function : IsFlipped
+// purpose  :
+// =======================================================================
+bool BRepMesh_RestoreOrientationTool::IsFlipped (const TopoDS_Face theFace) const
+{
+  if (!myIsDone)
+  {
+    return false;
+  }
+
   for (Standard_Size i = 0; i < myPatches.size(); ++i)
   {
     TopoDS_Face aFace = myPatches[i]->Face();
-    if (aFlipped[i])
+    if (theFace == aFace)
     {
-      aFace.Reverse();
+      return myFlipped[i] != 0;
     }
-    aBuilder.Add (aCompound, aFace);
   }
 
-  myShape = aCompound;
-  myIsDone = true;
+  return false;
+}
+
+// =======================================================================
+// function : IsFlipped
+// purpose  :
+// =======================================================================
+bool BRepMesh_RestoreOrientationTool::IsFlipped (const Standard_Integer theFaceIndex) const
+{
+  if (!myIsDone || theFaceIndex < 0 || theFaceIndex >= (Standard_Integer) myFlipped.size())
+  {
+    return false;
+  }
+
+  return myFlipped[theFaceIndex] != 0;
+}
+
+// =======================================================================
+// function : Shape
+// purpose  :
+// =======================================================================
+TopoDS_Shape BRepMesh_RestoreOrientationTool::Shape() const
+{
+  if (myIsDone && myShape.IsNull())
+  {
+    BRep_Builder aBuilder;
+    TopoDS_Compound aCompound;
+    aBuilder.MakeCompound (aCompound);
+    for (Standard_Size i = 0; i < myPatches.size(); ++i)
+    {
+      TopoDS_Face aFace = myPatches[i]->Face();
+      if (myFlipped[i] != 0)
+      {
+        aFace.Reverse();
+      }
+      aBuilder.Add (aCompound, aFace);
+    }
+
+    myShape = aCompound;
+  }
+
+  return myShape;
 }
index 329de1c401de853fe8cc06fa5a6765019b67156d..3787a8a75624049cdfc05842480b1c9c1bd7fd9e 100644 (file)
@@ -86,16 +86,21 @@ typedef std::vector<TopoDS_Face> BRepMesh_FaceList;
 //! It takes as input OCCT shape and outputs a set of re-oriented faces.
 class BRepMesh_RestoreOrientationTool : public Standard_Transient
 {
+
 public:
 
   DEFINE_STANDARD_ALLOC
 
   //! Creates uninitialized orientation tool.
-  Standard_EXPORT BRepMesh_RestoreOrientationTool (const bool theVisibilityOnly = false);
+  Standard_EXPORT BRepMesh_RestoreOrientationTool (const bool theVisibilityOnly = false,
+                                                   const Standard_Integer theMinFaceRays = 50,
+                                                   const Standard_Integer theMaxFaceRays = 2000);
 
   //! Creates orientation tool from the given shape.
   Standard_EXPORT BRepMesh_RestoreOrientationTool (const TopoDS_Shape& theShape,
-                                                   const bool theVisibilityOnly = false);
+                                                   const bool theVisibilityOnly = false,
+                                                   const Standard_Integer theMinFaceRays = 50,
+                                                   const Standard_Integer theMaxFaceRays = 2000);
 
 public:
 
@@ -124,10 +129,18 @@ public:
   }
 
   //! Returns shape with restored normal orientation.
-  TopoDS_Shape Shape() const
-  {
-    return myShape;
-  }
+  Standard_EXPORT TopoDS_Shape Shape() const;
+
+  //! Returns true if the given face should be reversed according to the algorithm.
+  //! Valid only if IsDone() returns true.
+  //! O(N)
+  Standard_EXPORT bool IsFlipped (const TopoDS_Face theFace) const;
+
+  //! Returns true if the given face should be reversed according to the algorithm.
+  //! Valid only if IsDone() returns true.
+  //! Uses indices in order provided by TopExp_Explorer starting from zero.
+  //! O(1)
+  Standard_EXPORT bool IsFlipped (const Standard_Integer theFaceIndex) const;
 
 protected:
 
@@ -156,13 +169,21 @@ protected:
                                       const BRepMesh_OrientedEdge& theEdge2,
                                       const BRepMesh_TriangulatedPatch&  thePatch2);
 
+public:
+
+  // Minimum number of traced rays per face.
+  Standard_Integer MinFaceRays;
+
+  // Maximum number of traced rays per face.
+  Standard_Integer MaxFaceRays;
+
 protected:
 
   //! Is output ready?
   bool myIsDone;
 
   //! Resulted shape.
-  TopoDS_Shape myShape;
+  mutable TopoDS_Shape myShape;
 
   //! List of triangulated faces of the shape.
   BRepMesh_FaceList myFaceList;
@@ -178,6 +199,9 @@ protected:
   //! Maps Id intervals to topological faces.
   std::vector<Standard_Integer> myFaceIdIntervals;
 
+  // Flipped flags for all faces.
+  std::vector<char> myFlipped;
+
   //! Use only visibility metric?
   bool myVisibilityOnly;
 
index 3b7c90f71386dd75d37745b9bf191221fbbcb2f5..9a10c4f7b44e12a83e27b304e9ffacfda087d981 100644 (file)
@@ -152,7 +152,7 @@ public:
   }
 
   //! Returns original topological face.
-  TopoDS_Face Face()
+  TopoDS_Face Face() const
   {
     return myFace;
   }