1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _BOPAlgo_Tools_HeaderFile
16 #define _BOPAlgo_Tools_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
22 #include <BOPCol_BaseAllocator.hxx>
23 #include <BOPCol_DataMapOfShapeBox.hxx>
24 #include <BOPCol_DataMapOfShapeListOfShape.hxx>
25 #include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
26 #include <BOPCol_IndexedDataMapOfShapeReal.hxx>
27 #include <BOPCol_ListOfListOfShape.hxx>
28 #include <BOPCol_MapOfShape.hxx>
29 #include <BOPCol_ListOfShape.hxx>
31 #include <BOPDS_IndexedDataMapOfPaveBlockListOfInteger.hxx>
32 #include <BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock.hxx>
33 #include <BOPDS_PDS.hxx>
35 #include <Standard_Integer.hxx>
37 class BOPDS_PaveBlock;
38 class BOPDS_CommonBlock;
39 class IntTools_Context;
46 //! Makes the chains of the connected elements from the given connexity map
47 template <class theType, class theTypeHasher>
48 static void MakeBlocks(const NCollection_IndexedDataMap<theType, NCollection_List<theType>, theTypeHasher>& theMILI,
49 NCollection_List<NCollection_List<theType>>& theMBlocks,
50 const BOPCol_BaseAllocator& theAllocator)
52 NCollection_Map<theType, theTypeHasher> aMFence;
53 Standard_Integer i, aNb = theMILI.Extent();
54 for (i = 1; i <= aNb; ++i) {
55 const theType& n = theMILI.FindKey(i);
60 NCollection_List<theType>& aChain = theMBlocks.Append(NCollection_List<theType>(theAllocator));
62 // Look for connected elements
63 typename NCollection_List<theType>::Iterator aItLChain(aChain);
64 for (; aItLChain.More(); aItLChain.Next()) {
65 const theType& n1 = aItLChain.Value();
66 const NCollection_List<theType>& aLI = theMILI.FindFromKey(n1);
67 // Add connected elements into the chain
68 typename NCollection_List<theType>::Iterator aItLI(aLI);
69 for (; aItLI.More(); aItLI.Next()) {
70 const theType& n2 = aItLI.Value();
71 if (aMFence.Add(n2)) {
79 //! Fills the map with the connected entities
80 template <class theType, class theTypeHasher>
81 static void FillMap(const theType& n1,
83 NCollection_IndexedDataMap<theType, NCollection_List<theType>, theTypeHasher>& theMILI,
84 const BOPCol_BaseAllocator& theAllocator)
86 NCollection_List<theType> *pList1 = theMILI.ChangeSeek(n1);
88 pList1 = &theMILI(theMILI.Add(n1, NCollection_List<theType>(theAllocator)));
92 NCollection_List<theType> *pList2 = theMILI.ChangeSeek(n2);
94 pList2 = &theMILI(theMILI.Add(n2, NCollection_List<theType>(theAllocator)));
99 Standard_EXPORT static void FillMap(const Handle(BOPDS_PaveBlock)& thePB1,
100 const Standard_Integer theF,
101 BOPDS_IndexedDataMapOfPaveBlockListOfInteger& theMILI,
102 const BOPCol_BaseAllocator& theAllocator);
104 Standard_EXPORT static void PerformCommonBlocks(BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& theMBlocks,
105 const BOPCol_BaseAllocator& theAllocator,
108 Standard_EXPORT static void PerformCommonBlocks(const BOPDS_IndexedDataMapOfPaveBlockListOfInteger& theMBlocks,
109 const BOPCol_BaseAllocator& theAllocator,
112 Standard_EXPORT static Standard_Real ComputeToleranceOfCB
113 (const Handle(BOPDS_CommonBlock)& theCB,
114 const BOPDS_PDS theDS,
115 const Handle(IntTools_Context)& theContext);
117 //! Creates planar wires from the given edges.<br>
118 //! The input edges are expected to be planar. And for the performance
119 //! sake the method does not check if the edges are really planar.<br>
120 //! Thus, the result wires will also be not planar if the input edges are not planar.<br>
121 //! The edges may be not shared, but the resulting wires will be sharing the
122 //! coinciding parts and intersecting parts.<br>
123 //! The output wires may be non-manifold and contain free and multi-connected vertices.<br>
125 //! <theEdges> - input edges;<br>
126 //! <theWires> - output wires;<br>
127 //! <theShared> - boolean flag which defines whether the input edges are already
128 //! shared or have to be intersected;<br>
129 //! <theAngTol> - the angular tolerance which will be used for distinguishing
130 //! the planes in which the edges are located. Default value is
131 //! 1.e-8 which is used for intersection of planes in IntTools_FaceFace.<br>
132 //! Method returns the following error statuses:<br>
133 //! 0 - in case of success (at least one wire has been built);<br>
134 //! 1 - in case there are no edges in the given shape;<br>
135 //! 2 - sharing of the edges has failed.<br>
136 Standard_EXPORT static Standard_Integer EdgesToWires(const TopoDS_Shape& theEdges,
137 TopoDS_Shape& theWires,
138 const Standard_Boolean theShared = Standard_False,
139 const Standard_Real theAngTol = 1.e-8);
141 //! Creates planar faces from given planar wires.<br>
142 //! The method does not check if the wires are really planar.<br>
143 //! The input wires may be non-manifold but should be shared.<br>
144 //! The wires located in the same planes and included into other wires will create
145 //! holes in the faces built from outer wires.<br>
146 //! The tolerance values of the input shapes may be modified during the operation
147 //! due to projection of the edges on the planes for creation of 2D curves.<br>
149 //! <theWires> - the given wires;<br>
150 //! <theFaces> - the output faces;<br>
151 //! <theAngTol> - the angular tolerance for distinguishing the planes in which
152 //! the wires are located. Default value is 1.e-8 which is used
153 //! for intersection of planes in IntTools_FaceFace.<br>
154 //! Method returns TRUE in case of success, i.e. at least one face has been built.<br>
155 Standard_EXPORT static Standard_Boolean WiresToFaces(const TopoDS_Shape& theWires,
156 TopoDS_Shape& theFaces,
157 const Standard_Real theAngTol = 1.e-8);
159 //! Finds chains of intersecting vertices
160 Standard_EXPORT static void IntersectVertices(const BOPCol_IndexedDataMapOfShapeReal& theVertices,
161 const Standard_Boolean theRunParallel,
162 const Standard_Real theFuzzyValue,
163 BOPCol_ListOfListOfShape& theChains);
165 //! Collect in the output list recursively all non-compound subshapes of the first level
166 //! of the given shape theS. If a shape presents in the map theMFence it is skipped.
167 //! All shapes put in the output are also added into theMFence.
168 Standard_EXPORT static void TreatCompound(const TopoDS_Shape& theS,
169 BOPCol_MapOfShape& theMFence,
170 BOPCol_ListOfShape& theLS);
172 //! Classifies the faces <theFaces> relatively solids <theSolids>.
173 //! The IN faces for solids are stored into output data map <theInParts>.
175 //! The map <theSolidsIF> contains INTERNAL faces of the solids, to avoid
176 //! their additional classification.
178 //! Firstly, it checks the intersection of bounding boxes of the shapes.
179 //! If the Box is not stored in the <theShapeBoxMap> map, it builds the box.
180 //! If the bounding boxes of solid and face are interfering the classification is performed.
182 //! It is assumed that all faces and solids are already intersected and
183 //! do not have any geometrically coinciding parts without topological
184 //! sharing of these parts
185 Standard_EXPORT static void ClassifyFaces(const BOPCol_ListOfShape& theFaces,
186 const BOPCol_ListOfShape& theSolids,
187 const Standard_Boolean theRunParallel,
188 Handle(IntTools_Context)& theContext,
189 BOPCol_IndexedDataMapOfShapeListOfShape& theInParts,
190 const BOPCol_DataMapOfShapeBox& theShapeBoxMap = BOPCol_DataMapOfShapeBox(),
191 const BOPCol_DataMapOfShapeListOfShape& theSolidsIF = BOPCol_DataMapOfShapeListOfShape());
195 #endif // _BOPAlgo_Tools_HeaderFile