Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 09:16:28

0001 // Created on: 1995-12-08
0002 // Created by: Jacques GOUSSARD
0003 // Copyright (c) 1995-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _BRepCheck_Analyzer_HeaderFile
0018 #define _BRepCheck_Analyzer_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <TopoDS_Shape.hxx>
0025 #include <BRepCheck_Result.hxx>
0026 #include <NCollection_IndexedDataMap.hxx>
0027 #include <TopAbs_ShapeEnum.hxx>
0028 class BRepCheck_Result;
0029 
0030 //! A framework to check the overall
0031 //! validity of a shape. For a shape to be valid in Open
0032 //! CASCADE, it - or its component subshapes - must respect certain
0033 //! criteria. These criteria are checked by the function IsValid.
0034 //! Once you have determined whether a shape is valid or not, you can
0035 //! diagnose its specific anomalies and correct them using the services of
0036 //! the ShapeAnalysis, ShapeUpgrade, and ShapeFix packages.
0037 class BRepCheck_Analyzer
0038 {
0039 public:
0040   DEFINE_STANDARD_ALLOC
0041 
0042   //! Constructs a shape validation object defined by the shape S.
0043   //! <S> is the shape to control. <GeomControls> If
0044   //! False only topological informaions are checked.
0045   //! The geometricals controls are
0046   //! For a Vertex:
0047   //! BRepCheck_InvalidToleranceValue NYI
0048   //! For an Edge:
0049   //! BRepCheck_InvalidCurveOnClosedSurface,
0050   //! BRepCheck_InvalidCurveOnSurface,
0051   //! BRepCheck_InvalidSameParameterFlag,
0052   //! BRepCheck_InvalidToleranceValue NYI
0053   //! For a face:
0054   //! BRepCheck_UnorientableShape,
0055   //! BRepCheck_IntersectingWires,
0056   //! BRepCheck_InvalidToleranceValue NYI
0057   //! For a wire:
0058   //! BRepCheck_SelfIntersectingWire
0059   BRepCheck_Analyzer(const TopoDS_Shape& S,
0060                      const bool          GeomControls  = true,
0061                      const bool          theIsParallel = false,
0062                      const bool          theIsExact    = false)
0063       : myIsParallel(theIsParallel),
0064         myIsExact(theIsExact)
0065   {
0066     Init(S, GeomControls);
0067   }
0068 
0069   //! <S> is the shape to control. <GeomControls> If
0070   //! False only topological informaions are checked.
0071   //! The geometricals controls are
0072   //! For a Vertex:
0073   //! BRepCheck_InvalidTolerance NYI
0074   //! For an Edge:
0075   //! BRepCheck_InvalidCurveOnClosedSurface,
0076   //! BRepCheck_InvalidCurveOnSurface,
0077   //! BRepCheck_InvalidSameParameterFlag,
0078   //! BRepCheck_InvalidTolerance NYI
0079   //! For a face:
0080   //! BRepCheck_UnorientableShape,
0081   //! BRepCheck_IntersectingWires,
0082   //! BRepCheck_InvalidTolerance NYI
0083   //! For a wire:
0084   //! BRepCheck_SelfIntersectingWire
0085   Standard_EXPORT void Init(const TopoDS_Shape& S, const bool GeomControls = true);
0086 
0087   //! Sets method to calculate distance: Calculating in finite number of points (if theIsExact
0088   //! is false, faster, but possible not correct result) or exact calculating by using
0089   //! BRepLib_CheckCurveOnSurface class (if theIsExact is true, slowly, but more correctly).
0090   //! Exact method is used only when edge is SameParameter.
0091   //! Default method is calculating in finite number of points
0092   void SetExactMethod(const bool theIsExact) { myIsExact = theIsExact; }
0093 
0094   //! Returns true if exact method selected
0095   bool IsExactMethod() { return myIsExact; }
0096 
0097   //! Sets parallel flag
0098   void SetParallel(const bool theIsParallel) { myIsParallel = theIsParallel; }
0099 
0100   //! Returns true if parallel flag is set
0101   bool IsParallel() { return myIsParallel; }
0102 
0103   //! <S> is a subshape of the original shape. Returns
0104   //! <STandard_True> if no default has been detected on
0105   //! <S> and any of its subshape.
0106   Standard_EXPORT bool IsValid(const TopoDS_Shape& S) const;
0107 
0108   //! Returns true if no defect is
0109   //! detected on the shape S or any of its subshapes.
0110   //! Returns true if the shape S is valid.
0111   //! This function checks whether a given shape is valid by checking that:
0112   //! -      the topology is correct
0113   //! -      parameterization of edges in particular is correct.
0114   //! For the topology to be correct, the following conditions must be satisfied:
0115   //! -      edges should have at least two vertices if they are not
0116   //! degenerate edges. The vertices should be within the range of
0117   //! the bounding edges at the tolerance specified in the vertex,
0118   //! -      edges should share at least one face. The representation of
0119   //! the edges should be within the tolerance criterion assigned to them.
0120   //! -      wires defining a face should not self-intersect and should be closed,
0121   //! - there should be one wire which contains all other wires inside a face,
0122   //! -      wires should be correctly oriented with respect to each of the edges,
0123   //! -      faces should be correctly oriented, in particular with
0124   //! respect to adjacent faces if these faces define a solid,
0125   //! -      shells defining a solid should be closed. There should
0126   //! be one enclosing shell if the shape is a solid;
0127   //! To check parameterization of edge, there are 2 approaches depending on
0128   //! the edge?s contextual situation.
0129   //! -      if the edge is either single, or it is in the context
0130   //! of a wire or a compound, its parameterization is defined by
0131   //! the parameterization of its 3D curve and is considered as valid.
0132   //! -      If the edge is in the context of a face, it should
0133   //! have SameParameter and SameRange flags set to true. To
0134   //! check these flags, you should call the function
0135   //! BRep_Tool::SameParameter and BRep_Tool::SameRange for an
0136   //! edge. If at least one of these flags is set to false,
0137   //! the edge is considered as invalid without any additional check.
0138   //! If the edge is contained by a face, and it has SameParameter and
0139   //! SameRange flags set to true, IsValid checks
0140   //! whether representation of the edge on face, in context of which the
0141   //! edge is considered, has the same parameterization up to the
0142   //! tolerance value coded on the edge. For a given parameter t on the edge
0143   //! having C as a 3D curve and one PCurve P on a surface S (base
0144   //! surface of the reference face), this checks that |C(t) - S(P(t))|
0145   //! is less than or equal to tolerance, where tolerance is the tolerance
0146   //! value coded on the edge.
0147   bool IsValid() const { return IsValid(myShape); }
0148 
0149   const occ::handle<BRepCheck_Result>& Result(const TopoDS_Shape& theSubS) const
0150   {
0151     return myMap.FindFromKey(theSubS);
0152   }
0153 
0154 private:
0155   Standard_EXPORT void Put(const TopoDS_Shape& S, const bool Gctrl);
0156 
0157   Standard_EXPORT void Perform();
0158 
0159   Standard_EXPORT bool ValidSub(const TopoDS_Shape& S, const TopAbs_ShapeEnum SubType) const;
0160 
0161 private:
0162   TopoDS_Shape                                                            myShape;
0163   NCollection_IndexedDataMap<TopoDS_Shape, occ::handle<BRepCheck_Result>> myMap;
0164   bool                                                                    myIsParallel;
0165   bool                                                                    myIsExact;
0166 };
0167 
0168 #endif // _BRepCheck_Analyzer_HeaderFile