Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:57:03

0001 // Created by: Eugeny MALTCHIKOV
0002 // Copyright (c) 2015 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_CellsBuilder_HeaderFile
0016 #define _BOPAlgo_CellsBuilder_HeaderFile
0017 
0018 #include <Standard_Handle.hxx>
0019 
0020 #include <TopoDS_Shape.hxx>
0021 
0022 #include <BOPAlgo_Builder.hxx>
0023 
0024 #include <NCollection_List.hxx>
0025 #include <TopTools_ShapeMapHasher.hxx>
0026 #include <NCollection_IndexedDataMap.hxx>
0027 #include <Standard_Integer.hxx>
0028 #include <NCollection_DataMap.hxx>
0029 
0030 //! The algorithm is based on the General Fuse algorithm (GFA).
0031 //! The result of GFA is all split parts of the Arguments.
0032 //!
0033 //! The purpose of this algorithm is to provide the result with the content of:
0034 //! 1. Cells (parts) defined by the user;
0035 //! 2. Internal boundaries defined by the user.
0036 //!
0037 //! In other words the algorithm should provide the possibility for the user to add
0038 //! or remove any part to (from) result and remove any internal boundaries between parts.
0039 //!
0040 //! All the requirements of GFA for the DATA are inherited in this algorithm.
0041 //! The arguments could be of any type (dimension) and should be valid
0042 //! in terms of BRepCheck_Analyzer and BOPAlgo_ArgumentAnalyzer.
0043 //!
0044 //! Results:
0045 //!
0046 //! The result of the algorithm is compound containing selected parts of the basic types (VERTEX,
0047 //! EDGE, FACE or SOLID). The default result is empty compound. It is possible to add any split part
0048 //! to the result by using the methods AddToRessult() and AddAllToResult(). It is also possible to
0049 //! remove any part from the result by using methods RemoveFromResult() and RemoveAllFromResult().
0050 //! The method RemoveAllFromResult() is also suitable for clearing the result.
0051 //!
0052 //! To remove Internal boundaries it is necessary to set the same material to the
0053 //! parts between which the boundaries should be removed and call the method
0054 //! RemoveInternalBoundaries(). The material should not be equal to 0, as this is default material
0055 //! value. The boundaries between parts with this value will not be removed. One part cannot be
0056 //! added with the different materials. It is also possible to remove the boundaries during
0057 //! combining the result. To do this it is necessary to set the material for parts (not equal to 0)
0058 //! and set the flag bUpdate to TRUE. For the arguments of the types FACE or EDGE it is recommended
0059 //! to remove the boundaries in the end when the result is completely built.
0060 //! It will help to avoid self-intersections in the result.
0061 //!
0062 //! Note, that if the result contains the parts with same material but of different
0063 //! dimension the boundaries between such parts will not be removed.
0064 //! Currently, the removal of the internal boundaries between multi-dimensional shapes is not
0065 //! supported.
0066 //!
0067 //! It is possible to create typed Containers from the parts added to result by using method
0068 //! MakeContainers(). The type of the containers will depend on the type of the arguments: WIRES for
0069 //! EEDGE, SHELLS for FACES and COMPSOLIDS for SOLIDS. The result will be compound containing
0070 //! containers. Adding of the parts to such result will not update containers. The result compound
0071 //! will contain the containers and new added parts (of basic type). Removing of the parts from such
0072 //! result may affect some containers if the parts that should be removed is in container. In this
0073 //! case this container will be rebuilt without that part.
0074 //!
0075 //! History:
0076 //!
0077 //! The algorithm supports history information for basic types of the shapes - VERTEX, EDGE, FACE.
0078 //! This information available through the methods IsDeleted() and Modified().
0079 //!
0080 //! In DRAW Test Harness it is available through the same commands
0081 //! as for Boolean Operations (bmodified, bgenerated and bisdeleted).
0082 //!
0083 //! The algorithm can return the following Error Statuses:
0084 //! - Error status acquired in the General Fuse algorithm.
0085 //! The Error status can be checked with HasErrors() method.
0086 //! If the Error status is not equal to zero, the result cannot be trustworthy.
0087 //!
0088 //! The algorithm can set the following Warning Statuses:
0089 //! - Warning status acquired in the General Fuse algorithm;
0090 //! - BOPAlgo_AlertRemovalOfIBForMDimShapes
0091 //! - BOPAlgo_AlertRemovalOfIBForFacesFailed
0092 //! - BOPAlgo_AlertRemovalOfIBForEdgesFailed
0093 //! - BOPAlgo_AlertRemovalOfIBForSolidsFailed
0094 //!
0095 //! The Warning status can be checked with HasWarnings() method or printed with the DumpWarnings()
0096 //! method. If warnings are recorded, the result may be not as expected.
0097 //!
0098 //! Examples:
0099 //!
0100 //! 1. API
0101 //! @code
0102 //! BOPAlgo_CellsBuilder aCBuilder;
0103 //! NCollection_List<TopoDS_Shape> aLS = ...; // arguments
0104 //! // parallel or single mode (the default value is FALSE)
0105 //! bool toRunParallel = false;
0106 //! // fuzzy option (default value is 0)
0107 //! double aTol = 0.0;
0108 //! //
0109 //! aCBuilder.SetArguments (aLS);
0110 //! aCBuilder.SetRunParallel (toRunParallel);
0111 //! aCBuilder.SetFuzzyValue (aTol);
0112 //! //
0113 //! aCBuilder.Perform();
0114 //! if (aCBuilder.HasErrors()) // check error status
0115 //! {
0116 //!   return;
0117 //! }
0118 //! // empty compound, as nothing has been added yet
0119 //! const TopoDS_Shape& aRes = aCBuilder.Shape();
0120 //! // all split parts
0121 //! const TopoDS_Shape& aRes = aCBuilder.GetAllParts();
0122 //! //
0123 //! NCollection_List<TopoDS_Shape> aLSToTake  = ...; // parts of these arguments will be taken into
0124 //! result NCollection_List<TopoDS_Shape> aLSToAvoid = ...; // parts of these arguments will not be
0125 //! taken into result
0126 //! //
0127 //! // defines the material common for the cells,
0128 //! // i.e. the boundaries between cells with the same material will be removed.
0129 //! // By default it is set to 0.
0130 //! // Thus, to remove some boundary the value of this variable should not be equal to 0.
0131 //! int iMaterial = ...;
0132 //! // defines whether to update the result right now or not
0133 //! bool toUpdate = ...;
0134 //! // adding to result
0135 //! aCBuilder.AddToResult (aLSToTake, aLSToAvoid, iMaterial, toUpdate);
0136 //! aR = aCBuilder.Shape(); // the result
0137 //! // removing of the boundaries (should be called only if toUpdate is false)
0138 //! aCBuilder.RemoveInternalBoundaries();
0139 //! //
0140 //! // removing from result
0141 //! aCBuilder.AddAllToResult();
0142 //! aCBuilder.RemoveFromResult (aLSToTake, aLSToAvoid);
0143 //! aR = aCBuilder.Shape(); // the result
0144 //! @endcode
0145 //!
0146 //! 2. DRAW Test Harness
0147 //! @code
0148 //! psphere s1 15
0149 //! psphere s2 15
0150 //! psphere s3 15
0151 //! ttranslate s1 0 0 10
0152 //! ttranslate s2 20 0 10
0153 //! ttranslate s3 10 0 0
0154 //! # adding arguments
0155 //! bclearobjects; bcleartools
0156 //! baddobjects s1 s2 s3
0157 //! # intersection
0158 //! bfillds
0159 //! # rx will contain all split parts
0160 //! bcbuild rx
0161 //! # add to result the part that is common for all three spheres
0162 //! bcadd res s1 1 s2 1 s3 1 -m 1
0163 //! # add to result the part that is common only for first and third spheres
0164 //! bcadd res s1 1 s2 0 s3 1 -m 1
0165 //! # remove internal boundaries
0166 //! bcremoveint res
0167 //! @endcode
0168 class BOPAlgo_CellsBuilder : public BOPAlgo_Builder
0169 {
0170 public:
0171   DEFINE_STANDARD_ALLOC
0172 
0173   Standard_EXPORT BOPAlgo_CellsBuilder();
0174 
0175   Standard_EXPORT BOPAlgo_CellsBuilder(const occ::handle<NCollection_BaseAllocator>& theAllocator);
0176 
0177   Standard_EXPORT ~BOPAlgo_CellsBuilder() override;
0178 
0179   //! Redefined method Clear - clears the contents.
0180   Standard_EXPORT void Clear() override;
0181 
0182   //! Adding the parts to result.
0183   //! The parts are defined by two lists of shapes:
0184   //! <theLSToTake> defines the arguments which parts should be taken into result;
0185   //! <theLSToAvoid> defines the arguments which parts should not be taken into result;
0186   //! To be taken into result the part must be IN for all shapes from the list
0187   //! <theLSToTake> and must be OUT of all shapes from the list <theLSToAvoid>.
0188   //!
0189   //! To remove internal boundaries between any cells in the result
0190   //! <theMaterial> variable should be used. The boundaries between
0191   //! cells with the same material will be removed. Default value is 0.
0192   //! Thus, to remove any boundary the value of this variable should not be equal to 0.
0193   //! <theUpdate> parameter defines whether to remove boundaries now or not.
0194   Standard_EXPORT void AddToResult(const NCollection_List<TopoDS_Shape>& theLSToTake,
0195                                    const NCollection_List<TopoDS_Shape>& theLSToAvoid,
0196                                    const int                             theMaterial = 0,
0197                                    const bool                            theUpdate   = false);
0198 
0199   //! Add all split parts to result.
0200   //! <theMaterial> defines the removal of internal boundaries;
0201   //! <theUpdate> parameter defines whether to remove boundaries now or not.
0202   Standard_EXPORT void AddAllToResult(const int theMaterial = 0, const bool theUpdate = false);
0203 
0204   //! Removing the parts from result.
0205   //! The parts are defined by two lists of shapes:
0206   //! <theLSToTake> defines the arguments which parts should be removed from result;
0207   //! <theLSToAvoid> defines the arguments which parts should not be removed from result.
0208   //! To be removed from the result the part must be IN for all shapes from the list
0209   //! <theLSToTake> and must be OUT of all shapes from the list <theLSToAvoid>.
0210   Standard_EXPORT void RemoveFromResult(const NCollection_List<TopoDS_Shape>& theLSToTake,
0211                                         const NCollection_List<TopoDS_Shape>& theLSToAvoid);
0212 
0213   //! Remove all parts from result.
0214   Standard_EXPORT void RemoveAllFromResult();
0215 
0216   //! Removes internal boundaries between cells with the same material.
0217   //! If the result contains the cells with same material but of different dimension
0218   //! the removal of internal boundaries between these cells will not be performed.
0219   //! In case of some errors during the removal the method will set the appropriate warning
0220   //! status - use GetReport() to access them.
0221   Standard_EXPORT void RemoveInternalBoundaries();
0222 
0223   //! Get all split parts.
0224   Standard_EXPORT const TopoDS_Shape& GetAllParts() const;
0225 
0226   //! Makes the Containers of proper type from the parts added to result.
0227   Standard_EXPORT void MakeContainers();
0228 
0229 protected:
0230   //! Prepare information for history support taking into account
0231   //! local modification map of unified elements - myMapModified.
0232   Standard_EXPORT const NCollection_List<TopoDS_Shape>* LocModified(
0233     const TopoDS_Shape& theS) override;
0234 
0235   //! Redefined method PerformInternal1 - makes all split parts,
0236   //! nullifies the result <myShape>, and index all parts.
0237   Standard_EXPORT void PerformInternal1(const BOPAlgo_PaveFiller&    thePF,
0238                                         const Message_ProgressRange& theRange) override;
0239 
0240   //! Indexes the parts for quick access to the arguments.
0241   Standard_EXPORT void IndexParts();
0242 
0243   //! Looking for the parts defined by two lists.
0244   Standard_EXPORT void FindParts(const NCollection_List<TopoDS_Shape>& theLSToTake,
0245                                  const NCollection_List<TopoDS_Shape>& theLSToAvoid,
0246                                  NCollection_List<TopoDS_Shape>&       theParts);
0247 
0248   //! Removes internal boundaries between cells with the same material.
0249   //! Returns TRUE if any internal boundaries have been removed.
0250   Standard_EXPORT bool RemoveInternals(
0251     const NCollection_List<TopoDS_Shape>&                         theLS,
0252     NCollection_List<TopoDS_Shape>&                               theLSNew,
0253     const NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher>& theMapKeepBnd =
0254       NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher>());
0255 
0256   // fields
0257   TopoDS_Shape myAllParts; //!< All split parts of the arguments
0258   // clang-format off
0259   NCollection_IndexedDataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher> myIndex; //!< Connection map from all splits parts to the argument shapes from which they were created
0260   NCollection_DataMap<int, NCollection_List<TopoDS_Shape>> myMaterials;  //!< Map of assigned materials (material -> list of shape)
0261   NCollection_DataMap<TopoDS_Shape, int, TopTools_ShapeMapHasher> myShapeMaterial;    //!< Map of assigned materials (shape -> material)
0262   NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> myMapModified;        //!< Local modification map to track unification of the splits
0263   // clang-format on
0264 };
0265 
0266 #endif //_BOPAlgo_CellsBuilder_HeaderFile