0028259: Method MakeBlocksCnx is duplicated in two different places in BOPAlgo
[occt.git] / src / BOPAlgo / BOPAlgo_Tools.hxx
CommitLineData
42cf5bc1 1// Created by: Peter KURNEV
2// Copyright (c) 1999-2014 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
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.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#ifndef _BOPAlgo_Tools_HeaderFile
16#define _BOPAlgo_Tools_HeaderFile
17
18#include <Standard.hxx>
19#include <Standard_DefineAlloc.hxx>
20#include <Standard_Handle.hxx>
21
42cf5bc1 22#include <BOPCol_BaseAllocator.hxx>
edfa30de 23#include <BOPDS_IndexedDataMapOfPaveBlockListOfInteger.hxx>
42cf5bc1 24#include <BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock.hxx>
42cf5bc1 25#include <BOPDS_PDS.hxx>
26#include <Standard_Integer.hxx>
42cf5bc1 27
7f22979e 28class BOPDS_PaveBlock;
3510db62 29class BOPDS_CommonBlock;
30class IntTools_Context;
e6ae74fd 31class TopoDS_Shape;
42cf5bc1 32
edfa30de 33class BOPAlgo_Tools
42cf5bc1 34{
35public:
36
edfa30de 37 //! Makes the chains of the connected elements from the given connexity map
38 template <class theType, class theTypeHasher>
39 static void MakeBlocks(const NCollection_IndexedDataMap<theType, NCollection_List<theType>, theTypeHasher>& theMILI,
40 NCollection_List<NCollection_List<theType>>& theMBlocks,
41 const BOPCol_BaseAllocator& theAllocator)
42 {
43 NCollection_Map<theType, theTypeHasher> aMFence;
44 Standard_Integer i, aNb = theMILI.Extent();
45 for (i = 1; i <= aNb; ++i) {
46 const theType& n = theMILI.FindKey(i);
47 if (!aMFence.Add(n))
48 continue;
49 //
50 // Start the chain
51 NCollection_List<theType>& aChain = theMBlocks.Append(NCollection_List<theType>(theAllocator));
52 aChain.Append(n);
53 // Look for connected elements
54 typename NCollection_List<theType>::Iterator aItLChain(aChain);
55 for (; aItLChain.More(); aItLChain.Next()) {
56 const theType& n1 = aItLChain.Value();
57 const NCollection_List<theType>& aLI = theMILI.FindFromKey(n1);
58 // Add connected elements into the chain
59 typename NCollection_List<theType>::Iterator aItLI(aLI);
60 for (; aItLI.More(); aItLI.Next()) {
61 const theType& n2 = aItLI.Value();
62 if (aMFence.Add(n2)) {
63 aChain.Append(n2);
64 }
65 }
66 }
67 }
68 }
42cf5bc1 69
edfa30de 70 //! Fills the map with the connected entities
71 template <class theType, class theTypeHasher>
72 static void FillMap(const theType& n1,
73 const theType& n2,
74 NCollection_IndexedDataMap<theType, NCollection_List<theType>, theTypeHasher>& theMILI,
75 const BOPCol_BaseAllocator& theAllocator)
76 {
77 NCollection_List<theType> *pList1 = theMILI.ChangeSeek(n1);
78 if (!pList1) {
79 pList1 = &theMILI(theMILI.Add(n1, NCollection_List<theType>(theAllocator)));
80 }
81 pList1->Append(n2);
82 //
83 NCollection_List<theType> *pList2 = theMILI.ChangeSeek(n2);
84 if (!pList2) {
85 pList2 = &theMILI(theMILI.Add(n2, NCollection_List<theType>(theAllocator)));
86 }
87 pList2->Append(n1);
88 }
89
90 Standard_EXPORT static void FillMap(const Handle(BOPDS_PaveBlock)& thePB1,
91 const Standard_Integer theF,
92 BOPDS_IndexedDataMapOfPaveBlockListOfInteger& theMILI,
93 const BOPCol_BaseAllocator& theAllocator);
42cf5bc1 94
edfa30de 95 Standard_EXPORT static void PerformCommonBlocks(BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& theMBlocks,
96 const BOPCol_BaseAllocator& theAllocator,
97 BOPDS_PDS& theDS);
98
99 Standard_EXPORT static void PerformCommonBlocks(const BOPDS_IndexedDataMapOfPaveBlockListOfInteger& theMBlocks,
100 const BOPCol_BaseAllocator& theAllocator,
101 BOPDS_PDS& pDS);
42cf5bc1 102
3510db62 103 Standard_EXPORT static Standard_Real ComputeToleranceOfCB
104 (const Handle(BOPDS_CommonBlock)& theCB,
105 const BOPDS_PDS theDS,
106 const Handle(IntTools_Context)& theContext);
107
e6ae74fd 108 //! Creates planar wires from the given edges.<br>
109 //! The input edges are expected to be planar. And for the performance
110 //! sake the method does not check if the edges are really planar.<br>
111 //! Thus, the result wires will also be not planar if the input edges are not planar.<br>
112 //! The edges may be not shared, but the resulting wires will be sharing the
113 //! coinciding parts and intersecting parts.<br>
114 //! The output wires may be non-manifold and contain free and multi-connected vertices.<br>
115 //! Parameters:
116 //! <theEdges> - input edges;<br>
117 //! <theWires> - output wires;<br>
118 //! <theShared> - boolean flag which defines whether the input edges are already
119 //! shared or have to be intersected;<br>
120 //! <theAngTol> - the angular tolerance which will be used for distinguishing
121 //! the planes in which the edges are located. Default value is
122 //! 1.e-8 which is used for intersection of planes in IntTools_FaceFace.<br>
123 //! Method returns the following error statuses:<br>
124 //! 0 - in case of success (at least one wire has been built);<br>
125 //! 1 - in case there are no edges in the given shape;<br>
126 //! 2 - sharing of the edges has failed.<br>
127 Standard_EXPORT static Standard_Integer EdgesToWires(const TopoDS_Shape& theEdges,
128 TopoDS_Shape& theWires,
129 const Standard_Boolean theShared = Standard_False,
130 const Standard_Real theAngTol = 1.e-8);
131
132 //! Creates planar faces from given planar wires.<br>
133 //! The method does not check if the wires are really planar.<br>
134 //! The input wires may be non-manifold but should be shared.<br>
135 //! The wires located in the same planes and included into other wires will create
136 //! holes in the faces built from outer wires.<br>
137 //! The tolerance values of the input shapes may be modified during the operation
138 //! due to projection of the edges on the planes for creation of 2D curves.<br>
139 //! Parameters:
140 //! <theWires> - the given wires;<br>
141 //! <theFaces> - the output faces;<br>
142 //! <theAngTol> - the angular tolerance for distinguishing the planes in which
143 //! the wires are located. Default value is 1.e-8 which is used
144 //! for intersection of planes in IntTools_FaceFace.<br>
145 //! Method returns TRUE in case of success, i.e. at least one face has been built.<br>
146 Standard_EXPORT static Standard_Boolean WiresToFaces(const TopoDS_Shape& theWires,
147 TopoDS_Shape& theFaces,
148 const Standard_Real theAngTol = 1.e-8);
42cf5bc1 149};
150
42cf5bc1 151#endif // _BOPAlgo_Tools_HeaderFile