mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
0029481: Implementation of the Feature Removal algorithm
Implementation of the 3D model De-featuring algorithm intended for the removal of the unwanted parts (or features) from the model consisting of solids. The features can be the holes, protrusions, gaps, chamfers, fillets etc. The algorithm removes all possible requested features from the shape and builds the new shape as a result. The input model is not modified. On the API level the algorithm is implemented in the class *BRepAlgoAPI_Defeaturing*. The actual features removal is performed by the low-level algorithm *BOPAlgo_RemoveFeatures*. Documentation of the new classes. Implementation of the DRAW commands for working with new algorithm. Test cases for the new functionality. Changes in other algorithms used by De-featuring algorithm: - Provide history support for the solids in *ShapeUpgrade_UnifySameDomain* algorithm; - Implementation of the mechanism to merge History of any Algorithm with standard history methods such as IsDeleted(), Modified() and Generated() into *BRepTools_History*.
This commit is contained in:
@@ -76,3 +76,15 @@ Warning: Building 2D curve of edge on face has failed
|
||||
|
||||
.BOPAlgo_AlertAcquiredSelfIntersection
|
||||
Warning: Some sub-shapes of some of the argument become connected through other shapes and the argument became self-interfered
|
||||
|
||||
.BOPAlgo_AlertUnsupportedType
|
||||
Warning: Unsupported type of input shape
|
||||
|
||||
.BOPAlgo_AlertUnableToRemoveTheFeature
|
||||
Warning: Unable to remove the feature
|
||||
|
||||
.BOPAlgo_AlertNoFacesToRemove
|
||||
Error: No faces have been found for removal
|
||||
|
||||
.BOPAlgo_AlertRemoveFeaturesFailed
|
||||
Error: The Feature Removal algorithm has failed
|
||||
|
@@ -88,4 +88,16 @@ DEFINE_ALERT_WITH_SHAPE(BOPAlgo_AlertBuildingPCurveFailed)
|
||||
//! other shapes and the argument became self-interfered
|
||||
DEFINE_ALERT_WITH_SHAPE(BOPAlgo_AlertAcquiredSelfIntersection)
|
||||
|
||||
//! Unsupported type of input shape
|
||||
DEFINE_ALERT_WITH_SHAPE(BOPAlgo_AlertUnsupportedType)
|
||||
|
||||
//! No faces have been found for removal
|
||||
DEFINE_SIMPLE_ALERT(BOPAlgo_AlertNoFacesToRemove)
|
||||
|
||||
//! Unable to remove the feature
|
||||
DEFINE_ALERT_WITH_SHAPE(BOPAlgo_AlertUnableToRemoveTheFeature)
|
||||
|
||||
//! The Feature Removal algorithm has failed
|
||||
DEFINE_SIMPLE_ALERT(BOPAlgo_AlertRemoveFeaturesFailed)
|
||||
|
||||
#endif // _BOPAlgo_Alerts_HeaderFile
|
||||
|
@@ -78,4 +78,16 @@ static const char BOPAlgo_BOPAlgo_msg[] =
|
||||
"Warning: Building 2D curve of edge on face has failed\n"
|
||||
"\n"
|
||||
".BOPAlgo_AlertAcquiredSelfIntersection\n"
|
||||
"Warning: Some sub-shapes of some of the argument become connected through other shapes and the argument became self-interfered\n";
|
||||
"Warning: Some sub-shapes of some of the argument become connected through other shapes and the argument became self-interfered\n"
|
||||
"\n"
|
||||
".BOPAlgo_AlertUnsupportedType\n"
|
||||
"Warning: Unsupported type of input shape\n"
|
||||
"\n"
|
||||
".BOPAlgo_AlertUnableToRemoveTheFeature\n"
|
||||
"Warning: Unable to remove the feature\n"
|
||||
"\n"
|
||||
".BOPAlgo_AlertNoFacesToRemove\n"
|
||||
"Error: No faces have been found for removal\n"
|
||||
"\n"
|
||||
".BOPAlgo_AlertRemoveFeaturesFailed\n"
|
||||
"Error: The Feature Removal algorithm has failed\n";
|
||||
|
1671
src/BOPAlgo/BOPAlgo_RemoveFeatures.cxx
Normal file
1671
src/BOPAlgo/BOPAlgo_RemoveFeatures.cxx
Normal file
File diff suppressed because it is too large
Load Diff
315
src/BOPAlgo/BOPAlgo_RemoveFeatures.hxx
Normal file
315
src/BOPAlgo/BOPAlgo_RemoveFeatures.hxx
Normal file
@@ -0,0 +1,315 @@
|
||||
// Created by: Eugeny MALTCHIKOV
|
||||
// Copyright (c) 2018 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _BOPAlgo_RemoveFeatures_HeaderFile
|
||||
#define _BOPAlgo_RemoveFeatures_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
#include <Standard_Handle.hxx>
|
||||
|
||||
#include <BOPAlgo_Options.hxx>
|
||||
#include <BRepTools_History.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
|
||||
#include <TopTools_IndexedMapOfShape.hxx>
|
||||
#include <TopTools_ListOfShape.hxx>
|
||||
#include <TopTools_MapOfShape.hxx>
|
||||
|
||||
//! The RemoveFeatures algorithm is intended for reconstruction of
|
||||
//! the shape by removal of the unwanted parts from it. These parts can
|
||||
//! be holes, protrusions, spikes, fillets etc.
|
||||
//! The shape itself is not modified, the new shape is built in
|
||||
//! the result.
|
||||
//!
|
||||
//! Currently, only the shapes of type SOLID, COMPSOLID, and
|
||||
//! COMPOUND of Solids are supported. And only the FACEs can be
|
||||
//! removed from the shape.
|
||||
//!
|
||||
//! On the input the algorithm accepts the shape itself and the
|
||||
//! faces which have to be removed. It does not matter how the faces
|
||||
//! are given. It could be the separate faces or the collections of faces.
|
||||
//! The faces should belong to the initial shape, and those that
|
||||
//! do not belong will be ignored.
|
||||
//! Before reconstructing the shape, the algorithm will sort all
|
||||
//! the given faces on the connected blocks (features).
|
||||
//!
|
||||
//! The features will be removed from the shape one by one.
|
||||
//! It will allow removing all possible features even if there
|
||||
//! were problems with the removal of some of them.
|
||||
//!
|
||||
//! The removed feature is filled by the extension of the faces adjacent
|
||||
//! to the feature. In general, the algorithm of removing of the single
|
||||
//! feature from the shape looks as follows:
|
||||
//! - Find the faces adjacent to the feature;
|
||||
//! - Extend the adjacent faces to cover the feature;
|
||||
//! - Trim the extended faces by the bounds of original face
|
||||
//! (except for bounds common with the feature), so it will cover
|
||||
//! the feature only;
|
||||
//! - Rebuild the solids with reconstructed adjacent faces
|
||||
//! avoiding the faces from the feature.
|
||||
//!
|
||||
//! If the removal is successful, the result is overwritten with the
|
||||
//! new shape and the next feature is treated. Otherwise, the warning
|
||||
//! will be given.
|
||||
//!
|
||||
//! The algorithm has the following options:
|
||||
//! - History support;
|
||||
//!
|
||||
//! and the options available from base class:
|
||||
//! - Error/Warning reporting system;
|
||||
//! - Parallel processing mode.
|
||||
//!
|
||||
//! Please note that the other options of the base class are not supported
|
||||
//! here and will have no effect.
|
||||
//!
|
||||
//! <b>History support</b> allows tracking modification of the input shape
|
||||
//! in terms of Modified, IsDeleted and Generated. The history is
|
||||
//! available through the methods of the history tool *BRepTools_History*,
|
||||
//! which can be accessed here through the method *History()*.
|
||||
//! By default, the history is collected, but it is possible to disable it
|
||||
//! using the method *TrackHistory(false)*;
|
||||
//!
|
||||
//! <b>Error/Warning reporting system</b> - allows obtaining the extended overview
|
||||
//! of the Errors/Warnings occurred during the operation. As soon as any error
|
||||
//! appears the algorithm stops working. The warnings allow continuing the job,
|
||||
//! informing the user that something went wrong.
|
||||
//! The algorithm returns the following errors/warnings:
|
||||
//! - *BOPAlgo_AlertTooFewArguments* - the error alert is given if the input
|
||||
//! shape does not contain any solids;
|
||||
//! - *BOPAlgo_AlertUnsupportedType* - the warning alert is given if the input
|
||||
//! shape contains not only solids, but also other shapes;
|
||||
//! - *BOPAlgo_AlertNoFacesToRemove* - the error alert is given in case
|
||||
//! there are no faces to remove from the shape (nothing to do);
|
||||
//! - *BOPAlgo_AlertUnableToRemoveTheFeature* - the warning alert is given to
|
||||
//! inform the user the removal of the feature is not possible. The algorithm
|
||||
//! will still try to remove the other features;
|
||||
//! - *BOPAlgo_AlertRemoveFeaturesFailed* - the error alert is given in case if
|
||||
//! the operation was aborted by the unknown reason.
|
||||
//!
|
||||
//! <b>Parallel processing mode</b> - allows running the algorithm in parallel mode
|
||||
//! obtaining the result faster.
|
||||
//!
|
||||
//! The algorithm has certain limitations:
|
||||
//! - Intersection of the connected faces adjacent to the feature should not be empty.
|
||||
//! It means, that such faces should not be tangent to each other.
|
||||
//! If the intersection of the adjacent faces will be empty, the algorithm will
|
||||
//! be unable to trim the faces correctly and, most likely, the feature will not be removed.
|
||||
//! - The algorithm does not process the INTERNAL parts of the solids, they are simply
|
||||
//! removed during reconstruction.
|
||||
//!
|
||||
//! Note that for successful removal of the feature, the extended faces adjacent
|
||||
//! to the feature should cover the feature completely, otherwise the solids will
|
||||
//! not be rebuild.
|
||||
//!
|
||||
//! Here is the example of usage of the algorithm:
|
||||
//! ~~~~
|
||||
//! TopoDS_Shape aSolid = ...; // Input shape to remove the features from
|
||||
//! TopTools_ListOfShape aFaces = ...; // Faces to remove from the shape
|
||||
//! Standard_Boolean bRunParallel = ...; // Parallel processing mode
|
||||
//! Standard_Boolean isHistoryNeeded = ...; // History support
|
||||
//!
|
||||
//! BOPAlgo_RemoveFeatures aRF; // Feature removal algorithm
|
||||
//! aRF.SetShape(aSolid); // Set the shape
|
||||
//! aRF.AddFacesToRemove(aFaces); // Add faces to remove
|
||||
//! aRF.SetRunParallel(bRunParallel); // Define the processing mode (parallel or single)
|
||||
//! aRF.TrackHistory(isHistoryNeeded); // Define whether to track the shapes modifications
|
||||
//! aRF.Perform(); // Perform the operation
|
||||
//! if (aRF.HasErrors()) // Check for the errors
|
||||
//! {
|
||||
//! // error treatment
|
||||
//! return;
|
||||
//! }
|
||||
//! if (aRF.HasWarnings()) // Check for the warnings
|
||||
//! {
|
||||
//! // warnings treatment
|
||||
//! }
|
||||
//! const TopoDS_Shape& aResult = aRF.Shape(); // Result shape
|
||||
//! ~~~~
|
||||
//!
|
||||
//! The algorithm preserves the type of the input shape in the result shape. Thus,
|
||||
//! if the input shape is a COMPSOLID, the resulting solids will also be put into a COMPSOLID.
|
||||
//!
|
||||
//! When all possible features are removed, the shape is simplified by
|
||||
//! removing extra edges and vertices, created during operation, from the result shape.
|
||||
//!
|
||||
class BOPAlgo_RemoveFeatures: public BOPAlgo_Options
|
||||
{
|
||||
public:
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
public: //! @name Constructors
|
||||
|
||||
//! Empty constructor
|
||||
BOPAlgo_RemoveFeatures()
|
||||
:
|
||||
BOPAlgo_Options(),
|
||||
myTrackHistory(Standard_True)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public: //! @name Setting input data for the algorithm
|
||||
|
||||
//! Sets the shape for processing.
|
||||
//! @param theShape [in] The shape to remove the faces from.
|
||||
//! It should either be the SOLID, COMPSOLID or COMPOUND of Solids.
|
||||
void SetShape(const TopoDS_Shape& theShape)
|
||||
{
|
||||
myInputShape = theShape;
|
||||
}
|
||||
|
||||
//! Returns the input shape
|
||||
const TopoDS_Shape& InputShape() const
|
||||
{
|
||||
return myInputShape;
|
||||
}
|
||||
|
||||
//! Adds the face to remove from the input shape.
|
||||
//! @param theFace [in] The shape to extract the faces for removal.
|
||||
void AddFaceToRemove(const TopoDS_Shape& theFace)
|
||||
{
|
||||
myFacesToRemove.Append(theFace);
|
||||
}
|
||||
|
||||
//! Adds the faces to remove from the input shape.
|
||||
//! @param theFaces [in] The list of shapes to extract the faces for removal.
|
||||
void AddFacesToRemove(const TopTools_ListOfShape& theFaces)
|
||||
{
|
||||
TopTools_ListIteratorOfListOfShape it(theFaces);
|
||||
for (; it.More(); it.Next())
|
||||
myFacesToRemove.Append(it.Value());
|
||||
}
|
||||
|
||||
//! Returns the list of faces which have been requested for removal
|
||||
//! from the input shape.
|
||||
const TopTools_ListOfShape& FacesToRemove() const
|
||||
{
|
||||
return myFacesToRemove;
|
||||
}
|
||||
|
||||
|
||||
public: //! @name Performing the operation
|
||||
|
||||
//! Performs the operation
|
||||
Standard_EXPORT void Perform();
|
||||
|
||||
|
||||
public: //! @name Clearing the contents of the algorithm
|
||||
|
||||
//! Clears the contents of the algorithm from previous run,
|
||||
//! allowing reusing it for following removals.
|
||||
void Clear()
|
||||
{
|
||||
BOPAlgo_Options::Clear();
|
||||
myHistory.Nullify();
|
||||
myInputShape.Nullify();
|
||||
myShape.Nullify();
|
||||
myFacesToRemove.Clear();
|
||||
myFeatures.Clear();
|
||||
myInputsMap.Clear();
|
||||
myResultMap.Clear();
|
||||
}
|
||||
|
||||
|
||||
public: //! @name History support
|
||||
|
||||
//! Defines whether to track the modification of the shapes or not
|
||||
void TrackHistory(const Standard_Boolean theFlag)
|
||||
{
|
||||
myTrackHistory = theFlag;
|
||||
}
|
||||
|
||||
//! Gets the History object
|
||||
Handle(BRepTools_History) History()
|
||||
{
|
||||
return (myTrackHistory ? myHistory : NULL);
|
||||
}
|
||||
|
||||
|
||||
public: //! @name Obtaining the results
|
||||
|
||||
//! Returns the resulting shape
|
||||
const TopoDS_Shape& Shape() const
|
||||
{
|
||||
return myShape;
|
||||
}
|
||||
|
||||
|
||||
protected: //! @name Protected methods performing the removal
|
||||
|
||||
//! Checks the input data on validity for the algorithm:
|
||||
//! - The input shape must be either a SOLID, COMPSOLID or COMPOUND of Solids.
|
||||
//! If the input shape is not a solid, the method looks for the solids
|
||||
//! in <myInputShape> and uses only them. All other shapes are simply removed.
|
||||
//! If no solids were found, the Error of unsupported type is returned.
|
||||
Standard_EXPORT void CheckData();
|
||||
|
||||
//! Prepares the faces to remove:
|
||||
//! - Gets only faces contained in the input solids;
|
||||
//! - Builds connected blocks of faces creating separate features to remove.
|
||||
Standard_EXPORT void PrepareFeatures();
|
||||
|
||||
//! Removes the features and fills the created gaps by extension of the adjacent faces.
|
||||
//! Processes each feature separately.
|
||||
Standard_EXPORT void RemoveFeatures();
|
||||
|
||||
//! Remove the single feature from the shape.
|
||||
//! @param theFeature [in] The feature to remove;
|
||||
//! @param theSolids [in] The solids to be reconstructed after feature removal;
|
||||
//! @param theFeatureFacesMap [in] The map of feature faces;
|
||||
//! @param theHasAdjacentFaces [in] Shows whether the adjacent faces have been
|
||||
//! found for the feature or not;
|
||||
//! @param theAdjFaces [in] The reconstructed adjacent faces covering the feature;
|
||||
//! @param theAdjFacesHistory [in] The history of the adjacent faces reconstruction;
|
||||
//! @param theSolidsHistoryNeeded [in] Defines whether the history of solids
|
||||
//! modifications should be tracked or not.
|
||||
Standard_EXPORT void RemoveFeature(const TopoDS_Shape& theFeature,
|
||||
const TopTools_IndexedMapOfShape& theSolids,
|
||||
const TopTools_MapOfShape& theFeatureFacesMap,
|
||||
const Standard_Boolean theHasAdjacentFaces,
|
||||
const TopTools_IndexedDataMapOfShapeListOfShape& theAdjFaces,
|
||||
const Handle(BRepTools_History)& theAdjFacesHistory,
|
||||
const Standard_Boolean theSolidsHistoryNeeded);
|
||||
|
||||
//! Updates history with the removed features
|
||||
Standard_EXPORT void UpdateHistory();
|
||||
|
||||
//! Simplifies the result by removing extra edges and vertices created
|
||||
//! during removal of the features.
|
||||
Standard_EXPORT void SimplifyResult();
|
||||
|
||||
//! Post treatment - restore the type of the initial shape
|
||||
Standard_EXPORT void PostTreat();
|
||||
|
||||
protected: //! @name Fields
|
||||
|
||||
// Inputs
|
||||
TopoDS_Shape myInputShape; //!< Input shape
|
||||
TopTools_ListOfShape myFacesToRemove; //!< Faces to remove
|
||||
Standard_Boolean myTrackHistory; //!< Defines whether to track the history of shapes
|
||||
//! modifications or not (true by default)
|
||||
|
||||
// Intermediate
|
||||
TopTools_ListOfShape myFeatures; //!< List of not connected features to remove
|
||||
//! (each feature is a compound of faces)
|
||||
TopTools_IndexedMapOfShape myInputsMap; //!< Map of all sub-shapes of the input shape
|
||||
TopTools_MapOfShape myResultMap; //!< Map of all sub-shapes of the result shape
|
||||
|
||||
// Results
|
||||
TopoDS_Shape myShape; //!< Result shape
|
||||
Handle(BRepTools_History) myHistory; //!< History tool
|
||||
};
|
||||
|
||||
#endif // _BOPAlgo_RemoveFeatures_HeaderFile
|
@@ -53,6 +53,8 @@ BOPAlgo_PBuilder.hxx
|
||||
BOPAlgo_PPaveFiller.hxx
|
||||
BOPAlgo_PSection.hxx
|
||||
BOPAlgo_PWireEdgeSet.hxx
|
||||
BOPAlgo_RemoveFeatures.cxx
|
||||
BOPAlgo_RemoveFeatures.hxx
|
||||
BOPAlgo_Section.cxx
|
||||
BOPAlgo_Section.hxx
|
||||
BOPAlgo_SectionAttribute.hxx
|
||||
|
Reference in New Issue
Block a user