Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-25 08:30:24

0001 // Created on: 1998-06-03
0002 // Created by: data exchange team
0003 // Copyright (c) 1998-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 _ShapeFix_Face_HeaderFile
0018 #define _ShapeFix_Face_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_Type.hxx>
0022 
0023 #include <TopoDS_Face.hxx>
0024 #include <TopoDS_Shape.hxx>
0025 #include <Standard_Integer.hxx>
0026 #include <ShapeFix_Root.hxx>
0027 #include <TopTools_DataMapOfShapeListOfShape.hxx>
0028 #include <TopTools_SequenceOfShape.hxx>
0029 #include <ShapeFix_DataMapOfShapeBox2d.hxx>
0030 #include <ShapeExtend_Status.hxx>
0031 class ShapeAnalysis_Surface;
0032 class ShapeFix_Wire;
0033 class Geom_Surface;
0034 class ShapeExtend_BasicMsgRegistrator;
0035 class TopoDS_Wire;
0036 class ShapeExtend_WireData;
0037 class TopoDS_Vertex;
0038 
0039 // resolve name collisions with X11 headers
0040 #ifdef Status
0041   #undef Status
0042 #endif
0043 
0044 class ShapeFix_Face;
0045 DEFINE_STANDARD_HANDLE(ShapeFix_Face, ShapeFix_Root)
0046 
0047 //! This operator allows to perform various fixes on face
0048 //! and its wires: fixes provided by ShapeFix_Wire,
0049 //! fixing orientation of wires, addition of natural bounds,
0050 //! fixing of missing seam edge,
0051 //! and detection and removal of null-area wires
0052 class ShapeFix_Face : public ShapeFix_Root
0053 {
0054 
0055 public:
0056   //! Creates an empty tool
0057   Standard_EXPORT ShapeFix_Face();
0058 
0059   //! Creates a tool and loads a face
0060   Standard_EXPORT ShapeFix_Face(const TopoDS_Face& face);
0061 
0062   //! Sets all modes to default
0063   Standard_EXPORT virtual void ClearModes();
0064 
0065   //! Loads a whole face already created, with its wires, sense and
0066   //! location
0067   Standard_EXPORT void Init(const TopoDS_Face& face);
0068 
0069   //! Starts the creation of the face
0070   //! By default it will be FORWARD, or REVERSED if <fwd> is False
0071   Standard_EXPORT void Init(const Handle(Geom_Surface)& surf,
0072                             const Standard_Real         preci,
0073                             const Standard_Boolean      fwd = Standard_True);
0074 
0075   //! Starts the creation of the face
0076   //! By default it will be FORWARD, or REVERSED if <fwd> is False
0077   Standard_EXPORT void Init(const Handle(ShapeAnalysis_Surface)& surf,
0078                             const Standard_Real                  preci,
0079                             const Standard_Boolean               fwd = Standard_True);
0080 
0081   //! Sets message registrator
0082   Standard_EXPORT virtual void SetMsgRegistrator(
0083     const Handle(ShapeExtend_BasicMsgRegistrator)& msgreg) Standard_OVERRIDE;
0084 
0085   //! Sets basic precision value (also to FixWireTool)
0086   Standard_EXPORT virtual void SetPrecision(const Standard_Real preci) Standard_OVERRIDE;
0087 
0088   //! Sets minimal allowed tolerance (also to FixWireTool)
0089   Standard_EXPORT virtual void SetMinTolerance(const Standard_Real mintol) Standard_OVERRIDE;
0090 
0091   //! Sets maximal allowed tolerance (also to FixWireTool)
0092   Standard_EXPORT virtual void SetMaxTolerance(const Standard_Real maxtol) Standard_OVERRIDE;
0093 
0094   //! Returns (modifiable) the mode for applying fixes of
0095   //! ShapeFix_Wire, by default True.
0096   Standard_Integer& FixWireMode();
0097 
0098   //! Returns (modifiable) the fix orientation mode, by default
0099   //! True. If True, wires oriented to border limited square.
0100   Standard_Integer& FixOrientationMode();
0101 
0102   //! Returns (modifiable) the add natural bound mode.
0103   //! If true, natural boundary is added on faces that miss them.
0104   //! Default is False for faces with single wire (they are
0105   //! handled by FixOrientation in that case) and True for others.
0106   Standard_Integer& FixAddNaturalBoundMode();
0107 
0108   //! Returns (modifiable) the fix missing seam mode, by default
0109   //! True. If True, tries to insert seam is missed.
0110   Standard_Integer& FixMissingSeamMode();
0111 
0112   //! Returns (modifiable) the fix small area wire mode, by default
0113   //! False. If True, drops small wires.
0114   Standard_Integer& FixSmallAreaWireMode();
0115 
0116   //! Returns (modifiable) the remove face with small area, by default
0117   //! False. If True, drops faces with small outer wires.
0118   Standard_Integer& RemoveSmallAreaFaceMode();
0119 
0120   //! Returns (modifiable) the fix intersecting wires mode
0121   //! by default True.
0122   Standard_Integer& FixIntersectingWiresMode();
0123 
0124   //! Returns (modifiable) the fix loop wires mode
0125   //! by default True.
0126   Standard_Integer& FixLoopWiresMode();
0127 
0128   //! Returns (modifiable) the fix split face mode
0129   //! by default True.
0130   Standard_Integer& FixSplitFaceMode();
0131 
0132   //! Returns (modifiable) the auto-correct precision mode
0133   //! by default False.
0134   Standard_Integer& AutoCorrectPrecisionMode();
0135 
0136   //! Returns (modifiable) the activation flag for periodic
0137   //! degenerated fix. False by default.
0138   Standard_Integer& FixPeriodicDegeneratedMode();
0139 
0140   //! Returns a face which corresponds to the current state
0141   //! Warning: The finally produced face may be another one ... but with the
0142   //! same support
0143   TopoDS_Face Face() const;
0144 
0145   //! Returns resulting shape (Face or Shell if split)
0146   //! To be used instead of Face() if FixMissingSeam involved
0147   TopoDS_Shape Result() const;
0148 
0149   //! Add a wire to current face using BRep_Builder.
0150   //! Wire is added without taking into account orientation of face
0151   //! (as if face were FORWARD).
0152   Standard_EXPORT void Add(const TopoDS_Wire& wire);
0153 
0154   //! Performs all the fixes, depending on modes
0155   //! Function Status returns the status of last call to Perform()
0156   //! ShapeExtend_OK   : face was OK, nothing done
0157   //! ShapeExtend_DONE1: some wires are fixed
0158   //! ShapeExtend_DONE2: orientation of wires fixed
0159   //! ShapeExtend_DONE3: missing seam added
0160   //! ShapeExtend_DONE4: small area wire removed
0161   //! ShapeExtend_DONE5: natural bounds added
0162   //! ShapeExtend_FAIL1: some fails during fixing wires
0163   //! ShapeExtend_FAIL2: cannot fix orientation of wires
0164   //! ShapeExtend_FAIL3: cannot add missing seam
0165   //! ShapeExtend_FAIL4: cannot remove small area wire
0166   Standard_EXPORT Standard_Boolean Perform();
0167 
0168   //! Fixes orientation of wires on the face
0169   //! It tries to make all wires lie outside all others (according
0170   //! to orientation) by reversing orientation of some of them.
0171   //! If face lying on sphere or torus has single wire and
0172   //! AddNaturalBoundMode is True, that wire is not reversed in
0173   //! any case (supposing that natural bound will be added).
0174   //! Returns True if wires were reversed
0175   Standard_EXPORT Standard_Boolean FixOrientation();
0176 
0177   //! Fixes orientation of wires on the face
0178   //! It tries to make all wires lie outside all others (according
0179   //! to orientation) by reversing orientation of some of them.
0180   //! If face lying on sphere or torus has single wire and
0181   //! AddNaturalBoundMode is True, that wire is not reversed in
0182   //! any case (supposing that natural bound will be added).
0183   //! Returns True if wires were reversed
0184   //! OutWires return information about out wires + list of
0185   //! internal wires for each (for performing split face).
0186   Standard_EXPORT Standard_Boolean FixOrientation(TopTools_DataMapOfShapeListOfShape& MapWires);
0187 
0188   //! Adds natural boundary on face if it is missing.
0189   //! Two cases are supported:
0190   //! - face has no wires
0191   //! - face lies on geometrically double-closed surface
0192   //! (sphere or torus) and none of wires is left-oriented
0193   //! Returns True if natural boundary was added
0194   Standard_EXPORT Standard_Boolean FixAddNaturalBound();
0195 
0196   //! Detects and fixes the special case when face on a closed
0197   //! surface is given by two wires closed in 3d but with gap in 2d.
0198   //! In that case it creates a new wire from the two, and adds a
0199   //! missing seam edge
0200   //! Returns True if missing seam was added
0201   Standard_EXPORT Standard_Boolean FixMissingSeam();
0202 
0203   //! Detects wires with small area (that is less than
0204   //! 100*Precision::PConfusion(). Removes these wires if they are internal.
0205   //! Returns : True if at least one small wire removed,
0206   //! False if does nothing.
0207   Standard_EXPORT Standard_Boolean FixSmallAreaWire(const Standard_Boolean theIsRemoveSmallFace);
0208 
0209   //! Detects if wire has a loop and fixes this situation by splitting on the few parts.
0210   //! if wire has a loops and it was split Status was set to value ShapeExtend_DONE6.
0211   Standard_EXPORT Standard_Boolean FixLoopWire(TopTools_SequenceOfShape& aResWires);
0212 
0213   //! Detects and fixes the special case when face has more than one wire
0214   //! and this wires have intersection point
0215   Standard_EXPORT Standard_Boolean FixIntersectingWires();
0216 
0217   //! If wire contains two coincidence edges it must be removed
0218   //! Queries on status after Perform()
0219   Standard_EXPORT Standard_Boolean FixWiresTwoCoincEdges();
0220 
0221   //! Split face if there are more than one out wire
0222   //! using inrormation after FixOrientation()
0223   Standard_EXPORT Standard_Boolean FixSplitFace(const TopTools_DataMapOfShapeListOfShape& MapWires);
0224 
0225   //! Fixes topology for a specific case when face is composed
0226   //! by a single wire belting a periodic surface. In that case
0227   //! a degenerated edge is reconstructed in the degenerated pole
0228   //! of the surface. Initial wire gets consistent orientation.
0229   //! Must be used in couple and before FixMissingSeam routine
0230   Standard_EXPORT Standard_Boolean FixPeriodicDegenerated();
0231 
0232   //! Returns the status of last call to Perform()
0233   //! ShapeExtend_OK   : face was OK, nothing done
0234   //! ShapeExtend_DONE1: some wires are fixed
0235   //! ShapeExtend_DONE2: orientation of wires fixed
0236   //! ShapeExtend_DONE3: missing seam added
0237   //! ShapeExtend_DONE4: small area wire removed
0238   //! ShapeExtend_DONE5: natural bounds added
0239   //! ShapeExtend_DONE8: face may be splited
0240   //! ShapeExtend_FAIL1: some fails during fixing wires
0241   //! ShapeExtend_FAIL2: cannot fix orientation of wires
0242   //! ShapeExtend_FAIL3: cannot add missing seam
0243   //! ShapeExtend_FAIL4: cannot remove small area wire
0244   Standard_Boolean Status(const ShapeExtend_Status status) const;
0245 
0246   //! Returns tool for fixing wires.
0247   Handle(ShapeFix_Wire) FixWireTool();
0248 
0249   DEFINE_STANDARD_RTTIEXT(ShapeFix_Face, ShapeFix_Root)
0250 
0251 protected:
0252   Handle(ShapeAnalysis_Surface) mySurf;
0253   TopoDS_Face                   myFace;
0254   TopoDS_Shape                  myResult;
0255   Handle(ShapeFix_Wire)         myFixWire;
0256   Standard_Boolean              myFwd;
0257   Standard_Integer              myStatus;
0258 
0259 private:
0260   //! Returns True if the face needs to add natural bound and corresponded option of shape healing
0261   //! is ON
0262   Standard_Boolean isNeedAddNaturalBound(const TopTools_SequenceOfShape& theOrientedWires);
0263 
0264   Standard_EXPORT Standard_Boolean SplitEdge(const Handle(ShapeExtend_WireData)& sewd,
0265                                              const Standard_Integer              num,
0266                                              const Standard_Real                 param,
0267                                              const TopoDS_Vertex&                vert,
0268                                              const Standard_Real                 preci,
0269                                              ShapeFix_DataMapOfShapeBox2d&       boxes);
0270 
0271   Standard_EXPORT Standard_Boolean SplitEdge(const Handle(ShapeExtend_WireData)& sewd,
0272                                              const Standard_Integer              num,
0273                                              const Standard_Real                 param1,
0274                                              const Standard_Real                 param2,
0275                                              const TopoDS_Vertex&                vert,
0276                                              const Standard_Real                 preci,
0277                                              ShapeFix_DataMapOfShapeBox2d&       boxes);
0278 
0279   Standard_Integer myFixWireMode;
0280   Standard_Integer myFixOrientationMode;
0281   Standard_Integer myFixAddNaturalBoundMode;
0282   Standard_Integer myFixMissingSeamMode;
0283   Standard_Integer myFixSmallAreaWireMode;
0284   Standard_Integer myRemoveSmallAreaFaceMode;
0285   Standard_Integer myFixLoopWiresMode;
0286   Standard_Integer myFixIntersectingWiresMode;
0287   Standard_Integer myFixSplitFaceMode;
0288   Standard_Integer myAutoCorrectPrecisionMode;
0289   Standard_Integer myFixPeriodicDegenerated;
0290 };
0291 
0292 #include <ShapeFix_Face.lxx>
0293 
0294 #endif // _ShapeFix_Face_HeaderFile