Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-03 08:32:26

0001 // Created by: Eugeny MALTCHIKOV
0002 // Copyright (c) 2018 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _BOPAlgo_RemoveFeatures_HeaderFile
0016 #define _BOPAlgo_RemoveFeatures_HeaderFile
0017 
0018 #include <Standard.hxx>
0019 #include <Standard_DefineAlloc.hxx>
0020 #include <Standard_Handle.hxx>
0021 
0022 #include <BOPAlgo_BuilderShape.hxx>
0023 #include <BRepTools_History.hxx>
0024 #include <TopoDS_Shape.hxx>
0025 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
0026 #include <TopTools_IndexedMapOfShape.hxx>
0027 #include <TopTools_ListOfShape.hxx>
0028 #include <TopTools_MapOfShape.hxx>
0029 
0030 //! The RemoveFeatures algorithm is intended for reconstruction of
0031 //! the shape by removal of the unwanted parts from it. These parts can
0032 //! be holes, protrusions, spikes, fillets etc.
0033 //! The shape itself is not modified, the new shape is built in
0034 //! the result.
0035 //!
0036 //! Currently, only the shapes of type SOLID, COMPSOLID, and
0037 //! COMPOUND of Solids are supported. And only the FACEs can be
0038 //! removed from the shape.
0039 //!
0040 //! On the input the algorithm accepts the shape itself and the
0041 //! faces which have to be removed. It does not matter how the faces
0042 //! are given. It could be the separate faces or the collections of faces.
0043 //! The faces should belong to the initial shape, and those that
0044 //! do not belong will be ignored.
0045 //! Before reconstructing the shape, the algorithm will sort all
0046 //! the given faces on the connected blocks (features).
0047 //!
0048 //! The features will be removed from the shape one by one.
0049 //! It will allow removing all possible features even if there
0050 //! were problems with the removal of some of them.
0051 //!
0052 //! The removed feature is filled by the extension of the faces adjacent
0053 //! to the feature. In general, the algorithm of removing of the single
0054 //! feature from the shape looks as follows:
0055 //! - Find the faces adjacent to the feature;
0056 //! - Extend the adjacent faces to cover the feature;
0057 //! - Trim the extended faces by the bounds of original face
0058 //!   (except for bounds common with the feature), so it will cover
0059 //!   the feature only;
0060 //! - Rebuild the solids with reconstructed adjacent faces
0061 //!   avoiding the faces from the feature.
0062 //!
0063 //! If the removal is successful, the result is overwritten with the
0064 //! new shape and the next feature is treated. Otherwise, the warning
0065 //! will be given.
0066 //!
0067 //! The algorithm has the following options:
0068 //! - History support;
0069 //!
0070 //! and the options available from base class:
0071 //! - Error/Warning reporting system;
0072 //! - Parallel processing mode.
0073 //!
0074 //! Please note that the other options of the base class are not supported
0075 //! here and will have no effect.
0076 //!
0077 //! <b>History support</b> allows tracking modification of the input shape
0078 //! in terms of Modified, IsDeleted and Generated. The history is
0079 //! available through the methods of the history tool *BRepTools_History*,
0080 //! which can be accessed here through the method *History()*.
0081 //! By default, the history is collected, but it is possible to disable it
0082 //! using the method *SetToFillHistory(false)*;
0083 //!
0084 //! <b>Error/Warning reporting system</b> - allows obtaining the extended overview
0085 //! of the Errors/Warnings occurred during the operation. As soon as any error
0086 //! appears the algorithm stops working. The warnings allow continuing the job,
0087 //! informing the user that something went wrong.
0088 //! The algorithm returns the following errors/warnings:
0089 //! - *BOPAlgo_AlertTooFewArguments* - the error alert is given if the input
0090 //!     shape does not contain any solids;
0091 //! - *BOPAlgo_AlertUnsupportedType* - the warning alert is given if the input
0092 //!     shape contains not only solids, but also other shapes;
0093 //! - *BOPAlgo_AlertNoFacesToRemove* - the error alert is given in case
0094 //!     there are no faces to remove from the shape (nothing to do);
0095 //! - *BOPAlgo_AlertUnableToRemoveTheFeature* - the warning alert is given to
0096 //!     inform the user the removal of the feature is not possible. The algorithm
0097 //!     will still try to remove the other features;
0098 //! - *BOPAlgo_AlertRemoveFeaturesFailed* - the error alert is given in case if
0099 //!     the operation was aborted by the unknown reason.
0100 //!
0101 //! <b>Parallel processing mode</b> - allows running the algorithm in parallel mode
0102 //! obtaining the result faster.
0103 //!
0104 //! The algorithm has certain limitations:
0105 //! - Intersection of the connected faces adjacent to the feature should not be empty.
0106 //!   It means, that such faces should not be tangent to each other.
0107 //!   If the intersection of the adjacent faces will be empty, the algorithm will
0108 //!   be unable to trim the faces correctly and, most likely, the feature will not be removed.
0109 //! - The algorithm does not process the INTERNAL parts of the solids, they are simply
0110 //!   removed during reconstruction.
0111 //!
0112 //! Note that for successful removal of the feature, the extended faces adjacent
0113 //! to the feature should cover the feature completely, otherwise the solids will
0114 //! not be rebuild.
0115 //!
0116 //! Here is the example of usage of the algorithm:
0117 //! ~~~~
0118 //! TopoDS_Shape aSolid = ...;              // Input shape to remove the features from
0119 //! TopTools_ListOfShape aFaces = ...;      // Faces to remove from the shape
0120 //! Standard_Boolean bRunParallel = ...;    // Parallel processing mode
0121 //! Standard_Boolean isHistoryNeeded = ...; // History support
0122 //!
0123 //! BOPAlgo_RemoveFeatures aRF;             // Feature removal algorithm
0124 //! aRF.SetShape(aSolid);                   // Set the shape
0125 //! aRF.AddFacesToRemove(aFaces);           // Add faces to remove
0126 //! aRF.SetRunParallel(bRunParallel);       // Define the processing mode (parallel or single)
0127 //! aRF.SetToFillHistory(isHistoryNeeded);  // Define whether to track the shapes modifications
0128 //! aRF.Perform();                          // Perform the operation
0129 //! if (aRF.HasErrors())                    // Check for the errors
0130 //! {
0131 //!   // error treatment
0132 //!   return;
0133 //! }
0134 //! if (aRF.HasWarnings())                  // Check for the warnings
0135 //! {
0136 //!   // warnings treatment
0137 //! }
0138 //! const TopoDS_Shape& aResult = aRF.Shape(); // Result shape
0139 //! ~~~~
0140 //!
0141 //! The algorithm preserves the type of the input shape in the result shape. Thus,
0142 //! if the input shape is a COMPSOLID, the resulting solids will also be put into a COMPSOLID.
0143 //!
0144 //! When all possible features are removed, the shape is simplified by
0145 //! removing extra edges and vertices, created during operation, from the result shape.
0146 //!
0147 class BOPAlgo_RemoveFeatures : public BOPAlgo_BuilderShape
0148 {
0149 public:
0150   DEFINE_STANDARD_ALLOC
0151 
0152 public: //! @name Constructors
0153   //! Empty constructor
0154   BOPAlgo_RemoveFeatures()
0155       : BOPAlgo_BuilderShape()
0156   {
0157   }
0158 
0159 public: //! @name Setting input data for the algorithm
0160   //! Sets the shape for processing.
0161   //! @param[in] theShape  The shape to remove the faces from.
0162   //!                      It should either be the SOLID, COMPSOLID or COMPOUND of Solids.
0163   void SetShape(const TopoDS_Shape& theShape) { myInputShape = theShape; }
0164 
0165   //! Returns the input shape
0166   const TopoDS_Shape& InputShape() const { return myInputShape; }
0167 
0168   //! Adds the face to remove from the input shape.
0169   //! @param[in] theFace  The shape to extract the faces for removal.
0170   void AddFaceToRemove(const TopoDS_Shape& theFace) { myFacesToRemove.Append(theFace); }
0171 
0172   //! Adds the faces to remove from the input shape.
0173   //! @param[in] theFaces  The list of shapes to extract the faces for removal.
0174   void AddFacesToRemove(const TopTools_ListOfShape& theFaces)
0175   {
0176     TopTools_ListIteratorOfListOfShape it(theFaces);
0177     for (; it.More(); it.Next())
0178       myFacesToRemove.Append(it.Value());
0179   }
0180 
0181   //! Returns the list of faces which have been requested for removal
0182   //! from the input shape.
0183   const TopTools_ListOfShape& FacesToRemove() const { return myFacesToRemove; }
0184 
0185 public: //! @name Performing the operation
0186   //! Performs the operation
0187   Standard_EXPORT virtual void Perform(
0188     const Message_ProgressRange& theRange = Message_ProgressRange()) Standard_OVERRIDE;
0189 
0190 public: //! @name Clearing the contents of the algorithm
0191   //! Clears the contents of the algorithm from previous run,
0192   //! allowing reusing it for following removals.
0193   virtual void Clear() Standard_OVERRIDE
0194   {
0195     BOPAlgo_BuilderShape::Clear();
0196     myInputShape.Nullify();
0197     myShape.Nullify();
0198     myFacesToRemove.Clear();
0199     myFeatures.Clear();
0200     myInputsMap.Clear();
0201   }
0202 
0203 protected: //! @name Protected methods performing the removal
0204   //! Checks the input data on validity for the algorithm:
0205   //! - The input shape must be either a SOLID, COMPSOLID or COMPOUND of Solids.
0206   //! If the input shape is not a solid, the method looks for the solids
0207   //! in <myInputShape> and uses only them. All other shapes are simply removed.
0208   //! If no solids were found, the Error of unsupported type is returned.
0209   Standard_EXPORT virtual void CheckData() Standard_OVERRIDE;
0210 
0211   //! Prepares the faces to remove:
0212   //! - Gets only faces contained in the input solids;
0213   //! - Builds connected blocks of faces creating separate features to remove.
0214   Standard_EXPORT void PrepareFeatures(const Message_ProgressRange& theRange);
0215 
0216   //! Removes the features and fills the created gaps by extension of the adjacent faces.
0217   //! Processes each feature separately.
0218   Standard_EXPORT void RemoveFeatures(const Message_ProgressRange& theRange);
0219 
0220   //! Remove the single feature from the shape.
0221   //! @param[in] theFeature  The feature to remove;
0222   //! @param[in] theSolids  The solids to be reconstructed after feature removal;
0223   //! @param[in] theFeatureFacesMap  The map of feature faces;
0224   //! @param[in] theHasAdjacentFaces  Shows whether the adjacent faces have been
0225   //!                                 found for the feature or not;
0226   //! @param[in] theAdjFaces  The reconstructed adjacent faces covering the feature;
0227   //! @param[in] theAdjFacesHistory  The history of the adjacent faces reconstruction;
0228   //! @param[in] theSolidsHistoryNeeded  Defines whether the history of solids
0229   //!                                    modifications should be tracked or not.
0230   Standard_EXPORT void RemoveFeature(const TopoDS_Shape&               theFeature,
0231                                      const TopTools_IndexedMapOfShape& theSolids,
0232                                      const TopTools_MapOfShape&        theFeatureFacesMap,
0233                                      const Standard_Boolean            theHasAdjacentFaces,
0234                                      const TopTools_IndexedDataMapOfShapeListOfShape& theAdjFaces,
0235                                      const Handle(BRepTools_History)& theAdjFacesHistory,
0236                                      const Standard_Boolean           theSolidsHistoryNeeded,
0237                                      const Message_ProgressRange&     theRange);
0238 
0239   //! Updates history with the removed features
0240   Standard_EXPORT void UpdateHistory(const Message_ProgressRange& theRange);
0241 
0242   //! Simplifies the result by removing extra edges and vertices created
0243   //! during removal of the features.
0244   Standard_EXPORT void SimplifyResult(const Message_ProgressRange& theRange);
0245 
0246   //! Post treatment - restore the type of the initial shape
0247   Standard_EXPORT void PostTreat();
0248 
0249   //! Filling steps for constant operations
0250   Standard_EXPORT void fillPIConstants(const Standard_Real theWhole,
0251                                        BOPAlgo_PISteps&    theSteps) const Standard_OVERRIDE;
0252 
0253 protected: //! @name Fields
0254   // Inputs
0255   TopoDS_Shape         myInputShape;    //!< Input shape
0256   TopTools_ListOfShape myFacesToRemove; //!< Faces to remove
0257 
0258   // Intermediate
0259   TopTools_ListOfShape myFeatures;        //!< List of not connected features to remove
0260                                           //! (each feature is a compound of faces)
0261   TopTools_IndexedMapOfShape myInputsMap; //!< Map of all sub-shapes of the input shape
0262 };
0263 
0264 #endif // _BOPAlgo_RemoveFeatures_HeaderFile