From: duv Date: Fri, 9 Sep 2016 13:47:28 +0000 (+0300) Subject: API extension X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=30f7634bc774395a3c6a791ea52d5414908dcfda;p=occt-copy.git API extension --- diff --git a/src/BRepMesh/BRepMesh_RestoreOrientationTool.cxx b/src/BRepMesh/BRepMesh_RestoreOrientationTool.cxx index b5e9e772e1..3270da0d7f 100644 --- a/src/BRepMesh/BRepMesh_RestoreOrientationTool.cxx +++ b/src/BRepMesh/BRepMesh_RestoreOrientationTool.cxx @@ -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 aFlipped (myPatches.size(), 0); + myFlipped.resize (myPatches.size(), 0); std::vector aFlippedC (myPatches.size(), 0); Standard_Real aMaxCoherence = -std::numeric_limits::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 (aTriPatch->TotalArea() * anInvMaxArea * MAX_FACE_RAYS)); + Standard_Integer aRaysNb = Max (MinFaceRays, static_cast (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; } diff --git a/src/BRepMesh/BRepMesh_RestoreOrientationTool.hxx b/src/BRepMesh/BRepMesh_RestoreOrientationTool.hxx index 329de1c401..3787a8a756 100644 --- a/src/BRepMesh/BRepMesh_RestoreOrientationTool.hxx +++ b/src/BRepMesh/BRepMesh_RestoreOrientationTool.hxx @@ -86,16 +86,21 @@ typedef std::vector 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 myFaceIdIntervals; + // Flipped flags for all faces. + std::vector myFlipped; + //! Use only visibility metric? bool myVisibilityOnly; diff --git a/src/BRepMesh/BRepMesh_TriangulatedPatch.hxx b/src/BRepMesh/BRepMesh_TriangulatedPatch.hxx index 3b7c90f713..9a10c4f7b4 100644 --- a/src/BRepMesh/BRepMesh_TriangulatedPatch.hxx +++ b/src/BRepMesh/BRepMesh_TriangulatedPatch.hxx @@ -152,7 +152,7 @@ public: } //! Returns original topological face. - TopoDS_Face Face() + TopoDS_Face Face() const { return myFace; }