1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0029484: Avoid inheritance of the BRepAlgoAPI_Check from BRepBuilderAPI_MakeShape

Inherit BRepAlgoAPI_Check class from BOPAlgo_Options instead of BRepAlgoAPI_Algo, as the latter is too excessive for checking purposes.

Implementation of the Draw command "bopapicheck" for testing the BRepAlgoAPI_Check algorithm.
This commit is contained in:
emv
2018-02-05 15:10:32 +03:00
committed by apn
parent 03a3ba9ebe
commit a981082925
4 changed files with 389 additions and 217 deletions

View File

@@ -14,20 +14,21 @@
// commercial license or contractual agreement.
#include <BOPAlgo_ArgumentAnalyzer.hxx>
#include <BRepAlgoAPI_Check.hxx>
#include <BOPAlgo_ArgumentAnalyzer.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <TopoDS_Shape.hxx>
//=======================================================================
//function : BRepAlgoAPI_Check
//purpose :
//=======================================================================
BRepAlgoAPI_Check::BRepAlgoAPI_Check()
:
BRepAlgoAPI_Algo(),
myAnalyzer(NULL),
myFuzzyValue(0.)
:
BOPAlgo_Options(),
myTestSE(Standard_True),
myTestSI(Standard_True),
myOperation(BOPAlgo_UNKNOWN)
{
}
@@ -38,11 +39,13 @@ BRepAlgoAPI_Check::BRepAlgoAPI_Check()
BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS,
const Standard_Boolean bTestSE,
const Standard_Boolean bTestSI)
: BRepAlgoAPI_Algo(),
myFuzzyValue(0.)
:
BOPAlgo_Options(),
myS1(theS),
myTestSE(bTestSE),
myTestSI(bTestSI),
myOperation(BOPAlgo_UNKNOWN)
{
Init(theS, TopoDS_Shape(), BOPAlgo_UNKNOWN, bTestSE, bTestSI);
//
Perform();
}
@@ -55,11 +58,14 @@ BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS1,
const BOPAlgo_Operation theOp,
const Standard_Boolean bTestSE,
const Standard_Boolean bTestSI)
: BRepAlgoAPI_Algo(),
myFuzzyValue(0.)
:
BOPAlgo_Options(),
myS1(theS1),
myS2(theS2),
myTestSE(bTestSE),
myTestSI(bTestSI),
myOperation(theOp)
{
Init(theS1, theS2, theOp, bTestSE, bTestSI);
//
Perform();
}
@@ -69,97 +75,6 @@ BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS1,
//=======================================================================
BRepAlgoAPI_Check::~BRepAlgoAPI_Check()
{
if(myAnalyzer){
delete myAnalyzer;
myAnalyzer=NULL;
}
myResult.Clear();
}
//=======================================================================
//function : SetFuzzyValue
//purpose :
//=======================================================================
void BRepAlgoAPI_Check::SetFuzzyValue(const Standard_Real theFuzz)
{
myFuzzyValue = (theFuzz < 0.) ? 0. : theFuzz;
}
//=======================================================================
//function : FuzzyValue
//purpose :
//=======================================================================
Standard_Real BRepAlgoAPI_Check::FuzzyValue() const
{
return myFuzzyValue;
}
//=======================================================================
//function : SetData
//purpose :
//=======================================================================
void BRepAlgoAPI_Check::SetData(const TopoDS_Shape& theS,
const Standard_Boolean bTestSE,
const Standard_Boolean bTestSI)
{
Init(theS, TopoDS_Shape(), BOPAlgo_UNKNOWN, bTestSE, bTestSI);
}
//=======================================================================
//function : SetData
//purpose :
//=======================================================================
void BRepAlgoAPI_Check::SetData(const TopoDS_Shape& theS1,
const TopoDS_Shape& theS2,
const BOPAlgo_Operation theOp,
const Standard_Boolean bTestSE,
const Standard_Boolean bTestSI)
{
Init(theS1, theS2, theOp, bTestSE, bTestSI);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void BRepAlgoAPI_Check::Init(const TopoDS_Shape& theS1,
const TopoDS_Shape& theS2,
const BOPAlgo_Operation theOp,
const Standard_Boolean bTestSE,
const Standard_Boolean bTestSI)
{
myResult.Clear();
myS1 = theS1;
myS2 = theS2;
//
myAnalyzer = new BOPAlgo_ArgumentAnalyzer();
//
myAnalyzer->SetShape1(myS1);
myAnalyzer->SetShape2(myS2);
myAnalyzer->OperationType() = theOp;
myAnalyzer->ArgumentTypeMode() = Standard_True;
myAnalyzer->SmallEdgeMode() = bTestSE;
myAnalyzer->SelfInterMode() = bTestSI;
//
myAnalyzer->SetRunParallel(myRunParallel);
myAnalyzer->SetProgressIndicator(myProgressIndicator);
myAnalyzer->SetFuzzyValue(myFuzzyValue);
}
//=======================================================================
//function : Result
//purpose :
//=======================================================================
const BOPAlgo_ListOfCheckResult& BRepAlgoAPI_Check::Result()
{
return myResult;
}
//=======================================================================
//function : IsValid
//purpose :
//=======================================================================
Standard_Boolean BRepAlgoAPI_Check::IsValid()
{
return myResult.IsEmpty();
}
//=======================================================================
@@ -168,38 +83,40 @@ Standard_Boolean BRepAlgoAPI_Check::IsValid()
//=======================================================================
void BRepAlgoAPI_Check::Perform()
{
Standard_Boolean isS1, isS2;
//incompatibility of shape types, small edges and self-interference
myAnalyzer->Perform();
if (myAnalyzer->HasFaulty()) {
myResult = myAnalyzer->GetCheckResult();
}
// Check the incompatibility of shapes types, small edges and self-interference
BOPAlgo_ArgumentAnalyzer anAnalyzer;
// Set the shapes and options for the check
anAnalyzer.SetShape1(myS1);
anAnalyzer.SetShape2(myS2);
anAnalyzer.OperationType() = myOperation;
anAnalyzer.ArgumentTypeMode() = Standard_True;
anAnalyzer.SmallEdgeMode() = myTestSE;
anAnalyzer.SelfInterMode() = myTestSI;
// Set options from BOPAlgo_Options
anAnalyzer.SetRunParallel(myRunParallel);
anAnalyzer.SetProgressIndicator(myProgressIndicator);
anAnalyzer.SetFuzzyValue(myFuzzyValue);
// Perform the check
anAnalyzer.Perform();
// Get the results
myFaultyShapes = anAnalyzer.GetCheckResult();
//topological validity
isS1 = !myS1.IsNull();
isS2 = !myS2.IsNull();
if (isS1) {
BRepCheck_Analyzer anS1(myS1);
isS1 = anS1.IsValid();
} else {
isS1 = Standard_True;
}
//
if (isS2) {
BRepCheck_Analyzer anS2(myS2);
isS2 = anS2.IsValid();
} else {
isS2 = Standard_True;
}
if (!isS1 || !isS2) {
// Check the topological validity of the shapes
Standard_Boolean isValidS1 = !myS1.IsNull() ?
BRepCheck_Analyzer(myS1).IsValid() : Standard_True;
Standard_Boolean isValidS2 = !myS2.IsNull() ?
BRepCheck_Analyzer(myS2).IsValid() : Standard_True;
if (!isValidS1 || !isValidS2) {
BOPAlgo_CheckResult aRes;
aRes.SetCheckStatus(BOPAlgo_NotValid);
if (!isS1) {
if (!isValidS1) {
aRes.SetShape1(myS1);
}
if (!isS1) {
if (!isValidS2) {
aRes.SetShape2(myS2);
}
myResult.Append(aRes);
myFaultyShapes.Append(aRes);
}
}

View File

@@ -20,121 +20,157 @@
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <TopoDS_Shape.hxx>
#include <BOPAlgo_PArgumentAnalyzer.hxx>
#include <BOPAlgo_ListOfCheckResult.hxx>
#include <Standard_Real.hxx>
#include <BRepAlgoAPI_Algo.hxx>
#include <Standard_Boolean.hxx>
#include <BOPAlgo_Operation.hxx>
class TopoDS_Shape;
#include <BOPAlgo_Options.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_Real.hxx>
#include <TopoDS_Shape.hxx>
//! The class Check provides a diagnostic tool for checking
//! single shape or couple of shapes.
//! Single shape is checking on topological validity, small edges
//! and self-interference. For couple of shapes added check
//! on validity for boolean operation of given type.
//! The class Check provides a diagnostic tool for checking the validity
//! of the single shape or couple of shapes.
//! The shapes are checked on:
//! - Topological validity;
//! - Small edges;
//! - Self-interference;
//! - Validity for Boolean operation of certain type (for couple of shapes only).
//!
//! The class provides two ways of checking shape(-s)
//! 1. Constructors
//! BRepAlgoAPI_Check aCh(theS);
//! Standard_Boolean bV=aCh.IsValid();
//! Standard_Boolean isValid = aCh.IsValid();
//! 2. Methods SetData and Perform
//! BRepAlgoAPI_Check aCh;
//! aCh.SetData(theS1, theS2, BOPAlgo_FUSE, Standard_False);
//! aCh.Perform();
//! Standard_Boolean bV=aCh.IsValid();
class BRepAlgoAPI_Check : public BRepAlgoAPI_Algo
//! Standard_Boolean isValid = aCh.IsValid();
//!
class BRepAlgoAPI_Check : public BOPAlgo_Options
{
public:
DEFINE_STANDARD_ALLOC
public: //! @name Constructors
//! Empty constructor.
Standard_EXPORT BRepAlgoAPI_Check();
Standard_EXPORT virtual ~BRepAlgoAPI_Check();
Standard_EXPORT virtual ~BRepAlgoAPI_Check();
//! Constructor for checking single shape.
//! It calls methods
//! Init(theS, TopoDS_Shape(), BOPAlgo_UNKNOWN, bTestSE, bTestSI)
//! and Perform().
//! Params:
//! theS - the shape that should be checked;
//! bTestSE - flag that specifies whether check on small edges
//! should be performed; by default it is set to TRUE;
//! bTestSI - flag that specifies whether check on self-interference
//! should be performed; by default it is set to TRUE;
Standard_EXPORT BRepAlgoAPI_Check(const TopoDS_Shape& theS, const Standard_Boolean bTestSE = Standard_True, const Standard_Boolean bTestSI = Standard_True);
//! Constructor for couple of shapes.
//! It calls methods
//! Init(theS1, theS2, theOp, bTestSE, bTestSI) and Perform().
//! Params:
//! theS1, theS2 - the initial shapes.
//! theOp - the type of Boolean Operation;
//! if it is not defined (set to UNKNOWN) for each shape
//! performed check as for single shape.
//! bTestSE - flag that specifies whether check on small edges
//! should be performed; by default it is set to TRUE;
//! bTestSI - flag that specifies whether check on self-interference
//! should be performed; by default it is set to TRUE;
Standard_EXPORT BRepAlgoAPI_Check(const TopoDS_Shape& theS1, const TopoDS_Shape& theS2, const BOPAlgo_Operation theOp = BOPAlgo_UNKNOWN, const Standard_Boolean bTestSE = Standard_True, const Standard_Boolean bTestSI = Standard_True);
//! Sets data for check by Init method.
//! The method provides alternative way for checking single shape.
Standard_EXPORT void SetData (const TopoDS_Shape& theS, const Standard_Boolean bTestSE = Standard_True, const Standard_Boolean bTestSI = Standard_True);
//! Sets data for check by Init method.
//! The method provides alternative way for checking couple of shapes.
Standard_EXPORT void SetData (const TopoDS_Shape& theS1, const TopoDS_Shape& theS2, const BOPAlgo_Operation theOp = BOPAlgo_UNKNOWN, const Standard_Boolean bTestSE = Standard_True, const Standard_Boolean bTestSI = Standard_True);
//!
//! @param theS [in] - the shape to check;
//! @param bTestSE [in] - flag which specifies whether to check the shape
//! on small edges or not; by default it is set to TRUE;
//! @param bTestSI [in] - flag which specifies whether to check the shape
//! on self-interference or not; by default it is set to TRUE;
Standard_EXPORT BRepAlgoAPI_Check(const TopoDS_Shape& theS,
const Standard_Boolean bTestSE = Standard_True,
const Standard_Boolean bTestSI = Standard_True);
//! Constructor for checking the couple of shapes.
//! Additionally to the validity checks of each given shape,
//! the types of the given shapes will be checked on validity
//! for Boolean operation of given type.
//!
//! @param theS1 [in] - the first shape to check;
//! @param theS2 [in] - the second shape to check;
//! @param theOp [in] - the type of Boolean Operation for which the validity
//! of given shapes should be checked.
//! @param bTestSE [in] - flag which specifies whether to check the shape
//! on small edges or not; by default it is set to TRUE;
//! @param bTestSI [in] - flag which specifies whether to check the shape
//! on self-interference or not; by default it is set to TRUE;
Standard_EXPORT BRepAlgoAPI_Check(const TopoDS_Shape& theS1,
const TopoDS_Shape& theS2,
const BOPAlgo_Operation theOp = BOPAlgo_UNKNOWN,
const Standard_Boolean bTestSE = Standard_True,
const Standard_Boolean bTestSI = Standard_True);
public: //! @name Initializing the algorithm
//! Initializes the algorithm with single shape.
//!
//! @param theS [in] - the shape to check;
//! @param bTestSE [in] - flag which specifies whether to check the shape
//! on small edges or not; by default it is set to TRUE;
//! @param bTestSI [in] - flag which specifies whether to check the shape
//! on self-interference or not; by default it is set to TRUE;
void SetData(const TopoDS_Shape& theS,
const Standard_Boolean bTestSE = Standard_True,
const Standard_Boolean bTestSI = Standard_True)
{
myS1 = theS;
myS2 = TopoDS_Shape();
myTestSE = bTestSE;
myTestSI = bTestSI;
myFaultyShapes.Clear();
}
//! Initializes the algorithm with couple of shapes.
//! Additionally to the validity checks of each given shape,
//! the types of the given shapes will be checked on validity
//! for Boolean operation of given type.
//!
//! @param theS1 [in] - the first shape to check;
//! @param theS2 [in] - the second shape to check;
//! @param theOp [in] - the type of Boolean Operation for which the validity
//! of given shapes should be checked.
//! @param bTestSE [in] - flag which specifies whether to check the shape
//! on small edges or not; by default it is set to TRUE;
//! @param bTestSI [in] - flag which specifies whether to check the shape
//! on self-interference or not; by default it is set to TRUE;
void SetData(const TopoDS_Shape& theS1,
const TopoDS_Shape& theS2,
const BOPAlgo_Operation theOp = BOPAlgo_UNKNOWN,
const Standard_Boolean bTestSE = Standard_True,
const Standard_Boolean bTestSI = Standard_True)
{
myS1 = theS1;
myS2 = theS2;
myOperation = theOp;
myTestSE = bTestSE;
myTestSI = bTestSI;
myFaultyShapes.Clear();
}
public: //! @name Performing the operation
//! Performs the check.
Standard_EXPORT void Perform();
public: //! @name Getting the results.
//! Shows whether shape(s) valid or not.
Standard_EXPORT Standard_Boolean IsValid();
Standard_Boolean IsValid()
{
return myFaultyShapes.IsEmpty();
}
//! Returns faulty shapes.
Standard_EXPORT const BOPAlgo_ListOfCheckResult& Result();
//! Sets the additional tolerance
Standard_EXPORT void SetFuzzyValue (const Standard_Real theFuzz);
//! Returns the additional tolerance
Standard_EXPORT Standard_Real FuzzyValue() const;
protected:
//! Initialyzes data.
Standard_EXPORT void Init (const TopoDS_Shape& theS1, const TopoDS_Shape& theS2, const BOPAlgo_Operation theOp, const Standard_Boolean bTestSE, const Standard_Boolean bTestSI);
TopoDS_Shape myS1;
TopoDS_Shape myS2;
BOPAlgo_PArgumentAnalyzer myAnalyzer;
BOPAlgo_ListOfCheckResult myResult;
Standard_Real myFuzzyValue;
private:
const BOPAlgo_ListOfCheckResult& Result()
{
return myFaultyShapes;
}
protected: //! @name Fields
// Inputs
TopoDS_Shape myS1; //!< The first shape
TopoDS_Shape myS2; //!< The second shape
Standard_Boolean myTestSE; //!< Flag defining whether to look for small edges in the given shapes or not
Standard_Boolean myTestSI; //!< Flag defining whether to check the input edges on self-interference or not
BOPAlgo_Operation myOperation; //!< Type of Boolean operation for which the validity of input shapes should be checked
// Results
BOPAlgo_ListOfCheckResult myFaultyShapes; //!< Found faulty shapes
};
#endif // _BRepAlgoAPI_Check_HeaderFile