4e57c75e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 2010-2014 OPEN CASCADE SAS |
4e57c75e |
3 | // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE |
4 | // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, |
5 | // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS |
6 | // |
973c2be1 |
7 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
8 | // |
d5f74e42 |
9 | // This library is free software; you can redistribute it and/or modify it under |
10 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
11 | // by the Free Software Foundation, with special exception defined in the file |
12 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
13 | // distribution for complete text of the license and disclaimer of any warranty. |
4e57c75e |
14 | // |
973c2be1 |
15 | // Alternatively, this file may be used under the terms of Open CASCADE |
16 | // commercial license or contractual agreement. |
4e57c75e |
17 | |
4e57c75e |
18 | |
19 | #include <Bnd_Box.hxx> |
42cf5bc1 |
20 | #include <BOPAlgo_PaveFiller.hxx> |
21 | #include <BOPAlgo_SectionAttribute.hxx> |
22 | #include <BOPAlgo_Tools.hxx> |
3510db62 |
23 | #include <BOPCol_DataMapOfIntegerInteger.hxx> |
4e57c75e |
24 | #include <BOPCol_DataMapOfIntegerListOfInteger.hxx> |
4e57c75e |
25 | #include <BOPCol_ListOfShape.hxx> |
42cf5bc1 |
26 | #include <BOPCol_MapOfInteger.hxx> |
27 | #include <BOPDS_Curve.hxx> |
4e57c75e |
28 | #include <BOPDS_DS.hxx> |
29 | #include <BOPDS_Iterator.hxx> |
42cf5bc1 |
30 | #include <BOPDS_PaveBlock.hxx> |
4e57c75e |
31 | #include <BOPDS_ShapeInfo.hxx> |
42cf5bc1 |
32 | #include <BOPDS_VectorOfInterfVV.hxx> |
33 | #include <BOPTools_AlgoTools.hxx> |
34 | #include <BRepBndLib.hxx> |
3510db62 |
35 | #include <BRep_TVertex.hxx> |
36 | #include <BRep_Tool.hxx> |
42cf5bc1 |
37 | #include <gp_Pnt.hxx> |
38 | #include <IntTools_Context.hxx> |
39 | #include <NCollection_BaseAllocator.hxx> |
3510db62 |
40 | #include <Precision.hxx> |
41 | #include <TopoDS.hxx> |
42cf5bc1 |
42 | #include <TopoDS_Face.hxx> |
43 | #include <TopoDS_Vertex.hxx> |
4e57c75e |
44 | |
45 | //======================================================================= |
46 | // function: PerformVV |
47 | // purpose: |
48 | //======================================================================= |
488e5b9d |
49 | void BOPAlgo_PaveFiller::PerformVV() |
4e57c75e |
50 | { |
3510db62 |
51 | Standard_Integer n1, n2, iFlag, aSize, k, aNbBlocks; |
488e5b9d |
52 | Handle(NCollection_BaseAllocator) aAllocator; |
4e57c75e |
53 | // |
54 | myErrorStatus=0; |
55 | // |
56 | myIterator->Initialize(TopAbs_VERTEX, TopAbs_VERTEX); |
57 | aSize=myIterator->ExpectedLength(); |
58 | if (!aSize) { |
59 | return; |
60 | } |
61 | // |
4e57c75e |
62 | BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV(); |
4e57c75e |
63 | aVVs.SetIncrement(aSize); |
4e57c75e |
64 | // |
65 | //-----------------------------------------------------scope f |
488e5b9d |
66 | aAllocator= |
67 | NCollection_BaseAllocator::CommonBaseAllocator(); |
4e57c75e |
68 | BOPCol_IndexedDataMapOfIntegerListOfInteger aMILI(100, aAllocator); |
69 | BOPCol_DataMapOfIntegerListOfInteger aMBlocks(100, aAllocator); |
4e57c75e |
70 | // |
71 | // 1. Map V/LV |
72 | for (; myIterator->More(); myIterator->Next()) { |
25dfc507 |
73 | myIterator->Value(n1, n2); |
4e57c75e |
74 | // |
75 | const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(n1))); |
76 | const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(n2))); |
77 | // |
0d0481c7 |
78 | iFlag=BOPTools_AlgoTools::ComputeVV(aV1, aV2, myFuzzyValue); |
4e57c75e |
79 | if (!iFlag) { |
80 | BOPAlgo_Tools::FillMap(n1, n2, aMILI, aAllocator); |
81 | } |
82 | } |
83 | // |
84 | // 2. Make blocks |
85 | BOPAlgo_Tools::MakeBlocksCnx(aMILI, aMBlocks, aAllocator); |
86 | // |
87 | // 3. Make vertices |
88 | aNbBlocks=aMBlocks.Extent(); |
89 | for (k=0; k<aNbBlocks; ++k) { |
90 | const BOPCol_ListOfInteger& aLI=aMBlocks.Find(k); |
91 | // |
3510db62 |
92 | MakeSDVertices(aLI); |
93 | } |
94 | // |
95 | BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aItDMII; |
96 | // |
97 | BOPCol_DataMapOfIntegerInteger& aDMII=myDS->ShapesSD(); |
98 | aItDMII.Initialize(aDMII); |
99 | for (; aItDMII.More(); aItDMII.Next()) { |
100 | n1=aItDMII.Key(); |
101 | myDS->InitPaveBlocksForVertex(n1); |
4e57c75e |
102 | } |
4e57c75e |
103 | // |
104 | //-----------------------------------------------------scope t |
4e57c75e |
105 | aMBlocks.Clear(); |
106 | aMILI.Clear(); |
4e57c75e |
107 | } |
3510db62 |
108 | |
109 | //======================================================================= |
110 | // function: PerformVV |
111 | // purpose: |
112 | //======================================================================= |
0d0481c7 |
113 | Standard_Integer BOPAlgo_PaveFiller::MakeSDVertices |
114 | (const BOPCol_ListOfInteger& theVertIndices, |
115 | const Standard_Boolean theAddInterfs) |
3510db62 |
116 | { |
117 | TopoDS_Vertex aVSD, aVn; |
0d0481c7 |
118 | Standard_Integer nSD = -1; |
3510db62 |
119 | BOPCol_ListIteratorOfListOfInteger aItLI(theVertIndices); |
120 | BOPCol_ListOfShape aLV; |
121 | for (; aItLI.More(); aItLI.Next()) { |
0d0481c7 |
122 | Standard_Integer nX = aItLI.Value(), nSD1; |
123 | if (myDS->HasShapeSD(nX, nSD1)) { |
124 | const TopoDS_Shape& aVSD1 = myDS->Shape(nSD1); |
125 | if (nSD == -1) { |
126 | aVSD = TopoDS::Vertex(aVSD1); |
127 | nSD = nSD1; |
128 | } |
129 | else { |
130 | aLV.Append(aVSD1); |
131 | } |
3510db62 |
132 | } |
133 | const TopoDS_Shape& aV = myDS->Shape(nX); |
134 | aLV.Append(aV); |
135 | } |
136 | BOPTools_AlgoTools::MakeVertex(aLV, aVn); |
0d0481c7 |
137 | Standard_Integer nV; |
138 | if (nSD != -1) { |
3510db62 |
139 | // update old SD vertex with new value |
140 | Handle(BRep_TVertex)& aTVertex = |
141 | reinterpret_cast<Handle(BRep_TVertex)&>(const_cast<Handle(TopoDS_TShape)&>(aVSD.TShape())); |
142 | aTVertex->Pnt(BRep_Tool::Pnt(aVn)); |
143 | aTVertex->Tolerance(BRep_Tool::Tolerance(aVn)); |
0d0481c7 |
144 | aVn = aVSD; |
145 | nV = nSD; |
3510db62 |
146 | } |
0d0481c7 |
147 | else { |
148 | // Append new vertex to the DS |
149 | BOPDS_ShapeInfo aSIn; |
150 | aSIn.SetShapeType(TopAbs_VERTEX); |
151 | aSIn.SetShape(aVn); |
152 | nV = myDS->Append(aSIn); |
153 | } |
154 | BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(nV); |
3510db62 |
155 | Bnd_Box& aBox = aSIDS.ChangeBox(); |
156 | BRepBndLib::Add(aVn, aBox); |
157 | aBox.SetGap(aBox.GetGap() + Precision::Confusion()); |
158 | // |
159 | // Fill ShapesSD |
160 | BOPDS_VectorOfInterfVV& aVVs = myDS->InterfVV(); |
0d0481c7 |
161 | if (theAddInterfs) |
162 | aVVs.SetIncrement(theVertIndices.Extent()); |
3510db62 |
163 | // |
164 | aItLI.Initialize(theVertIndices); |
165 | for (; aItLI.More(); aItLI.Next()) { |
166 | Standard_Integer n1 = aItLI.Value(); |
0d0481c7 |
167 | myDS->AddShapeSD(n1, nV); |
3510db62 |
168 | // |
0d0481c7 |
169 | if (theAddInterfs) { |
170 | BOPCol_ListIteratorOfListOfInteger aItLI2 = aItLI; |
171 | aItLI2.Next(); |
172 | for (; aItLI2.More(); aItLI2.Next()) { |
173 | Standard_Integer n2 = aItLI2.Value(); |
174 | // |
175 | myDS->AddInterf(n1, n2); |
176 | BOPDS_InterfVV& aVV = aVVs.Append1(); |
177 | // |
178 | aVV.SetIndices(n1, n2); |
179 | aVV.SetIndexNew(nV); |
180 | } |
3510db62 |
181 | } |
182 | } |
0d0481c7 |
183 | return nV; |
3510db62 |
184 | } |