// 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;
// 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)
{
//
// 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);
// =======================================================================
void BRepMesh_RestoreOrientationTool::Init (const TopoDS_Shape& theShape)
{
+ myShape = TopoDS_Shape();
if (theShape.IsNull())
{
Standard_NullObject::Raise();
#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();
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)
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();
}
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)
{
if (aGraph->Label (aVariables[i]) == 1)
{
- aFlipped[i] = aFlipped[i] == 0 ? 1 : 0;
+ myFlipped[i] = myFlipped[i] == 0 ? 1 : 0;
}
}
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;
}
//! 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:
}
//! 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:
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;
//! 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;