Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:04

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