Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 09:02:29

0001 // Created by: Peter KURNEV
0002 // Copyright (c) 1999-2014 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_Tools_HeaderFile
0016 #define _BOPAlgo_Tools_HeaderFile
0017 
0018 #include <Standard.hxx>
0019 #include <Standard_DefineAlloc.hxx>
0020 
0021 #include <NCollection_IndexedDataMap.hxx>
0022 #include <Standard_Integer.hxx>
0023 #include <NCollection_List.hxx>
0024 #include <BOPDS_PaveBlock.hxx>
0025 #include <Standard_Handle.hxx>
0026 #include <BOPDS_PDS.hxx>
0027 #include <NCollection_BaseAllocator.hxx>
0028 #include <Bnd_Box.hxx>
0029 #include <TopoDS_Shape.hxx>
0030 #include <TopTools_ShapeMapHasher.hxx>
0031 #include <NCollection_DataMap.hxx>
0032 #include <NCollection_Map.hxx>
0033 #include <Message_ProgressRange.hxx>
0034 
0035 class BOPDS_PaveBlock;
0036 class BOPDS_CommonBlock;
0037 class IntTools_Context;
0038 class TopoDS_Shape;
0039 
0040 //! Provides tools used in the intersection part of Boolean operations
0041 class BOPAlgo_Tools
0042 {
0043 public:
0044   //! Makes the chains of the connected elements from the given convexity map
0045   template <class TheMap, class TheList>
0046   static void MakeBlocks(const TheMap&                                 theMILI,
0047                          TheList&                                      theMBlocks,
0048                          const occ::handle<NCollection_BaseAllocator>& theAllocator)
0049   {
0050     NCollection_Map<typename TheMap::key_type, typename TheMap::hasher> aMFence;
0051     int                                                                 i, aNb = theMILI.Extent();
0052     for (i = 1; i <= aNb; ++i)
0053     {
0054       const typename TheMap::key_type& n = theMILI.FindKey(i);
0055       if (!aMFence.Add(n))
0056         continue;
0057       //
0058       // Start the chain
0059       typename TheList::value_type& aChain =
0060         theMBlocks.Append(typename TheList::value_type(theAllocator));
0061       aChain.Append(n);
0062       // Look for connected elements
0063       typename TheList::value_type::Iterator aItLChain(aChain);
0064       for (; aItLChain.More(); aItLChain.Next())
0065       {
0066         const typename TheMap::key_type&    n1  = aItLChain.Value();
0067         const typename TheList::value_type& aLI = theMILI.FindFromKey(n1);
0068         // Add connected elements into the chain
0069         typename TheList::value_type::Iterator aItLI(aLI);
0070         for (; aItLI.More(); aItLI.Next())
0071         {
0072           const typename TheMap::key_type& n2 = aItLI.Value();
0073           if (aMFence.Add(n2))
0074           {
0075             aChain.Append(n2);
0076           }
0077         }
0078       }
0079     }
0080   }
0081 
0082   //! Fills the map with the connected entities
0083   template <class TheType, class TheMap>
0084   static void FillMap(const TheType&                                n1,
0085                       const TheType&                                n2,
0086                       TheMap&                                       theMILI,
0087                       const occ::handle<NCollection_BaseAllocator>& theAllocator)
0088   {
0089     typename TheMap::value_type* pList1 = theMILI.ChangeSeek(n1);
0090     if (!pList1)
0091     {
0092       pList1 = &theMILI(theMILI.Add(n1, NCollection_List<TheType>(theAllocator)));
0093     }
0094     pList1->Append(n2);
0095     //
0096     typename TheMap::value_type* pList2 = theMILI.ChangeSeek(n2);
0097     if (!pList2)
0098     {
0099       pList2 = &theMILI(theMILI.Add(n2, typename TheMap::value_type(theAllocator)));
0100     }
0101     pList2->Append(n1);
0102   }
0103 
0104   Standard_EXPORT static void FillMap(
0105     const occ::handle<BOPDS_PaveBlock>&                                              thePB1,
0106     const int                                                                        theF,
0107     NCollection_IndexedDataMap<occ::handle<BOPDS_PaveBlock>, NCollection_List<int>>& theMILI,
0108     const occ::handle<NCollection_BaseAllocator>&                                    theAllocator);
0109 
0110   //! Create Common Blocks from the groups of pave blocks of <theMBlocks>
0111   //! connection map.
0112   Standard_EXPORT static void PerformCommonBlocks(
0113     NCollection_IndexedDataMap<occ::handle<BOPDS_PaveBlock>,
0114                                NCollection_List<occ::handle<BOPDS_PaveBlock>>>& theMBlocks,
0115     const occ::handle<NCollection_BaseAllocator>&                               theAllocator,
0116     BOPDS_PDS&                                                                  theDS,
0117     const occ::handle<IntTools_Context>& theContext = occ::handle<IntTools_Context>());
0118 
0119   //! Create Common Blocks on faces using the PB->Faces connection map <theMBlocks>.
0120   Standard_EXPORT static void PerformCommonBlocks(
0121     const NCollection_IndexedDataMap<occ::handle<BOPDS_PaveBlock>, NCollection_List<int>>&
0122                                                   theMBlocks,
0123     const occ::handle<NCollection_BaseAllocator>& theAllocator,
0124     BOPDS_PDS&                                    pDS,
0125     const occ::handle<IntTools_Context>&          theContext = occ::handle<IntTools_Context>());
0126 
0127   Standard_EXPORT static double ComputeToleranceOfCB(
0128     const occ::handle<BOPDS_CommonBlock>& theCB,
0129     const BOPDS_PDS                       theDS,
0130     const occ::handle<IntTools_Context>&  theContext);
0131 
0132   //! Creates planar wires from the given edges.
0133   //! The input edges are expected to be planar. And for the performance
0134   //! sake the method does not check if the edges are really planar.
0135   //! Thus, the result wires will also be not planar if the input edges are not planar.
0136   //! The edges may be not shared, but the resulting wires will be sharing the
0137   //! coinciding parts and intersecting parts.
0138   //! The output wires may be non-manifold and contain free and multi-connected vertices.
0139   //! Parameters:
0140   //! <theEdges> - input edges;
0141   //! <theWires> - output wires;
0142   //! <theShared> - boolean flag which defines whether the input edges are already
0143   //!               shared or have to be intersected;
0144   //! <theAngTol> - the angular tolerance which will be used for distinguishing
0145   //!               the planes in which the edges are located. Default value is
0146   //!               1.e-8 which is used for intersection of planes in IntTools_FaceFace.
0147   //! Method returns the following error statuses:
0148   //! 0 - in case of success (at least one wire has been built);
0149   //! 1 - in case there are no edges in the given shape;
0150   //! 2 - sharing of the edges has failed.
0151   Standard_EXPORT static int EdgesToWires(const TopoDS_Shape& theEdges,
0152                                           TopoDS_Shape&       theWires,
0153                                           const bool          theShared = false,
0154                                           const double        theAngTol = 1.e-8);
0155 
0156   //! Creates planar faces from given planar wires.
0157   //! The method does not check if the wires are really planar.
0158   //! The input wires may be non-manifold but should be shared.
0159   //! The wires located in the same planes and included into other wires will create
0160   //! holes in the faces built from outer wires.
0161   //! The tolerance values of the input shapes may be modified during the operation
0162   //! due to projection of the edges on the planes for creation of 2D curves.
0163   //! Parameters:
0164   //! <theWires> - the given wires;
0165   //! <theFaces> - the output faces;
0166   //! <theAngTol> - the angular tolerance for distinguishing the planes in which
0167   //!               the wires are located. Default value is 1.e-8 which is used
0168   //!               for intersection of planes in IntTools_FaceFace.
0169   //! Method returns TRUE in case of success, i.e. at least one face has been built.
0170   Standard_EXPORT static bool WiresToFaces(const TopoDS_Shape& theWires,
0171                                            TopoDS_Shape&       theFaces,
0172                                            const double        theAngTol = 1.e-8);
0173 
0174   //! Finds chains of intersecting vertices
0175   Standard_EXPORT static void IntersectVertices(
0176     const NCollection_IndexedDataMap<TopoDS_Shape, double, TopTools_ShapeMapHasher>& theVertices,
0177     const double                                                                     theFuzzyValue,
0178     NCollection_List<NCollection_List<TopoDS_Shape>>&                                theChains);
0179 
0180   //! Classifies the faces <theFaces> relatively solids <theSolids>.
0181   //! The IN faces for solids are stored into output data map <theInParts>.
0182   //!
0183   //! The map <theSolidsIF> contains INTERNAL faces of the solids, to avoid
0184   //! their additional classification.
0185   //!
0186   //! Firstly, it checks the intersection of bounding boxes of the shapes.
0187   //! If the Box is not stored in the <theShapeBoxMap> map, it builds the box.
0188   //! If the bounding boxes of solid and face are interfering the classification is performed.
0189   //!
0190   //! It is assumed that all faces and solids are already intersected and
0191   //! do not have any geometrically coinciding parts without topological
0192   //! sharing of these parts
0193   Standard_EXPORT static void ClassifyFaces(
0194     const NCollection_List<TopoDS_Shape>&                                      theFaces,
0195     const NCollection_List<TopoDS_Shape>&                                      theSolids,
0196     const bool                                                                 theRunParallel,
0197     occ::handle<IntTools_Context>&                                             theContext,
0198     NCollection_IndexedDataMap<TopoDS_Shape,
0199                                NCollection_List<TopoDS_Shape>,
0200                                TopTools_ShapeMapHasher>&                       theInParts,
0201     const NCollection_DataMap<TopoDS_Shape, Bnd_Box, TopTools_ShapeMapHasher>& theShapeBoxMap =
0202       NCollection_DataMap<TopoDS_Shape, Bnd_Box, TopTools_ShapeMapHasher>(),
0203     const NCollection_DataMap<TopoDS_Shape,
0204                               NCollection_List<TopoDS_Shape>,
0205                               TopTools_ShapeMapHasher>& theSolidsIF =
0206       NCollection_DataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>(),
0207     const Message_ProgressRange& theRange = Message_ProgressRange());
0208 
0209   //! Classifies the given parts relatively the given solids and
0210   //! fills the solids with the parts classified as INTERNAL.
0211   //!
0212   //! @param theSolids  - The solids to put internals to
0213   //! @param theParts   - The parts to classify relatively solids
0214   //! @param theImages  - Possible images of the parts that has to be classified
0215   //! @param theContext - cached geometrical tools to speed-up classifications
0216   Standard_EXPORT static void FillInternals(
0217     const NCollection_List<TopoDS_Shape>&               theSolids,
0218     const NCollection_List<TopoDS_Shape>&               theParts,
0219     const NCollection_DataMap<TopoDS_Shape,
0220                               NCollection_List<TopoDS_Shape>,
0221                               TopTools_ShapeMapHasher>& theImages,
0222     const occ::handle<IntTools_Context>&                theContext);
0223 
0224   //! Computes the transformation needed to move the objects
0225   //! to the given point to increase the quality of computations.
0226   //! Returns true if the objects are located far from the given point
0227   //! (relatively given criteria), false otherwise.
0228   //! @param theBox1 the AABB of the first object
0229   //! @param theBox2 the AABB of the second object
0230   //! @param theTrsf the computed transformation
0231   //! @param thePoint the Point to compute transformation to
0232   //! @param theCriteria the Criteria to check whether thranformation is required
0233   Standard_EXPORT static bool TrsfToPoint(const Bnd_Box& theBox1,
0234                                           const Bnd_Box& theBox2,
0235                                           gp_Trsf&       theTrsf,
0236                                           const gp_Pnt&  thePoint    = gp_Pnt(0.0, 0.0, 0.0),
0237                                           const double   theCriteria = 1.e+5);
0238 };
0239 
0240 #endif // _BOPAlgo_Tools_HeaderFile