4e57c75e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
4e57c75e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
4e57c75e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
4e57c75e |
14 | |
42cf5bc1 |
15 | |
16 | #include <Bnd_Box.hxx> |
4e57c75e |
17 | #include <BOPDS_ListOfPave.hxx> |
42cf5bc1 |
18 | #include <BOPDS_Pave.hxx> |
19 | #include <BOPDS_PaveBlock.hxx> |
7a76337e |
20 | #include <BOPDS_VectorOfPave.hxx> |
4e57c75e |
21 | #include <NCollection_BaseAllocator.hxx> |
42cf5bc1 |
22 | #include <Standard.hxx> |
23 | #include <Standard_Type.hxx> |
4e57c75e |
24 | |
7a76337e |
25 | #include <algorithm> |
25e59720 |
26 | IMPLEMENT_STANDARD_RTTIEXT(BOPDS_PaveBlock,Standard_Transient) |
92efcf78 |
27 | |
4e57c75e |
28 | //======================================================================= |
29 | //function : |
30 | //purpose : |
31 | //======================================================================= |
32 | BOPDS_PaveBlock::BOPDS_PaveBlock() |
33 | : |
34 | myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()), |
35 | myExtPaves(myAllocator) |
36 | { |
37 | myEdge=-1; |
38 | myOriginalEdge=-1; |
39 | myTS1=-99.; |
40 | myTS2=myTS1; |
01b5b3df |
41 | myIsSplittable=Standard_False; |
4e57c75e |
42 | } |
43 | //======================================================================= |
44 | //function : |
45 | //purpose : |
46 | //======================================================================= |
47 | BOPDS_PaveBlock::BOPDS_PaveBlock(const Handle(NCollection_BaseAllocator)& theAllocator) |
48 | : |
49 | myAllocator(theAllocator), |
50 | myExtPaves(theAllocator), |
51 | myMFence(100, theAllocator) |
52 | { |
53 | myEdge=-1; |
54 | myOriginalEdge=-1; |
55 | myTS1=-99.; |
56 | myTS2=myTS1; |
01b5b3df |
57 | myIsSplittable=Standard_False; |
4e57c75e |
58 | } |
59 | |
60 | //======================================================================= |
61 | //function : SetEdge |
62 | //purpose : |
63 | //======================================================================= |
64 | void BOPDS_PaveBlock::SetEdge(const Standard_Integer theEdge) |
65 | { |
66 | myEdge=theEdge; |
67 | } |
68 | //======================================================================= |
69 | //function : Edge |
70 | //purpose : |
71 | //======================================================================= |
72 | Standard_Integer BOPDS_PaveBlock::Edge()const |
73 | { |
74 | return myEdge; |
75 | } |
76 | //======================================================================= |
77 | //function : HasEdge |
78 | //purpose : |
79 | //======================================================================= |
80 | Standard_Boolean BOPDS_PaveBlock::HasEdge()const |
81 | { |
82 | return (myEdge>=0); |
83 | } |
84 | //======================================================================= |
85 | //function : HasEdge |
86 | //purpose : |
87 | //======================================================================= |
88 | Standard_Boolean BOPDS_PaveBlock::HasEdge(Standard_Integer& theEdge)const |
89 | { |
90 | theEdge=myEdge; |
91 | return (myEdge>=0); |
92 | } |
93 | |
94 | //======================================================================= |
95 | //function : SetOriginalEdge |
96 | //purpose : |
97 | //======================================================================= |
98 | void BOPDS_PaveBlock::SetOriginalEdge(const Standard_Integer theEdge) |
99 | { |
100 | myOriginalEdge=theEdge; |
101 | } |
102 | //======================================================================= |
103 | //function : OriginalEdge |
104 | //purpose : |
105 | //======================================================================= |
106 | Standard_Integer BOPDS_PaveBlock::OriginalEdge()const |
107 | { |
108 | return myOriginalEdge; |
109 | } |
110 | //======================================================================= |
111 | //function : IsSplitEdge |
112 | //purpose : |
113 | //======================================================================= |
114 | Standard_Boolean BOPDS_PaveBlock::IsSplitEdge()const |
115 | { |
116 | return (myEdge!=myOriginalEdge); |
117 | } |
118 | //======================================================================= |
119 | //function : SetPave1 |
120 | //purpose : |
121 | //======================================================================= |
122 | void BOPDS_PaveBlock::SetPave1(const BOPDS_Pave& thePave) |
123 | { |
124 | myPave1=thePave; |
125 | } |
126 | //======================================================================= |
127 | //function : Pave1 |
128 | //purpose : |
129 | //======================================================================= |
130 | const BOPDS_Pave& BOPDS_PaveBlock::Pave1()const |
131 | { |
132 | return myPave1; |
133 | } |
134 | //======================================================================= |
135 | //function : SetPave2 |
136 | //purpose : |
137 | //======================================================================= |
138 | void BOPDS_PaveBlock::SetPave2(const BOPDS_Pave& thePave) |
139 | { |
140 | myPave2=thePave; |
141 | } |
142 | //======================================================================= |
143 | //function : Pave2 |
144 | //purpose : |
145 | //======================================================================= |
146 | const BOPDS_Pave& BOPDS_PaveBlock::Pave2()const |
147 | { |
148 | return myPave2; |
149 | } |
150 | //======================================================================= |
151 | //function : Range |
152 | //purpose : |
153 | //======================================================================= |
154 | void BOPDS_PaveBlock::Range(Standard_Real& theT1, |
155 | Standard_Real& theT2)const |
156 | { |
157 | theT1=myPave1.Parameter(); |
158 | theT2=myPave2.Parameter(); |
159 | } |
160 | //======================================================================= |
161 | //function : Indices |
162 | //purpose : |
163 | //======================================================================= |
164 | void BOPDS_PaveBlock::Indices(Standard_Integer& theIndex1, |
165 | Standard_Integer& theIndex2)const |
166 | { |
167 | theIndex1=myPave1.Index(); |
168 | theIndex2=myPave2.Index(); |
169 | } |
170 | //======================================================================= |
171 | //function : HasSameBounds |
172 | //purpose : |
173 | //======================================================================= |
174 | Standard_Boolean BOPDS_PaveBlock::HasSameBounds(const Handle(BOPDS_PaveBlock)& theOther)const |
175 | { |
176 | Standard_Boolean bFlag1, bFlag2; |
177 | Standard_Integer n11, n12, n21, n22; |
178 | // |
179 | Indices(n11, n12); |
180 | theOther->Indices(n21, n22); |
181 | // |
182 | bFlag1=(n11==n21) && (n12==n22); |
183 | bFlag2=(n11==n22) && (n12==n21); |
184 | // |
185 | return (bFlag1 || bFlag2); |
186 | } |
187 | |
188 | |
189 | // |
190 | // Extras |
191 | // |
192 | //======================================================================= |
193 | //function : AppendExtPave |
194 | //purpose : |
195 | //======================================================================= |
196 | void BOPDS_PaveBlock::AppendExtPave(const BOPDS_Pave& thePave) |
197 | { |
198 | if (myMFence.Add(thePave.Index())) { |
199 | myExtPaves.Append(thePave); |
200 | } |
201 | } |
202 | //======================================================================= |
203 | //function : AppendExtPave1 |
204 | //purpose : |
205 | //======================================================================= |
206 | void BOPDS_PaveBlock::AppendExtPave1(const BOPDS_Pave& thePave) |
207 | { |
208 | myExtPaves.Append(thePave); |
209 | } |
210 | //======================================================================= |
0d0481c7 |
211 | //function : RemoveExtPave |
212 | //purpose : |
213 | //======================================================================= |
214 | void BOPDS_PaveBlock::RemoveExtPave(const Standard_Integer theVertNum) |
215 | { |
216 | if (myMFence.Contains(theVertNum)) |
217 | { |
218 | BOPDS_ListOfPave::Iterator itPaves(myExtPaves); |
219 | while (itPaves.More()) |
220 | { |
221 | if (itPaves.Value().Index() == theVertNum) |
222 | myExtPaves.Remove(itPaves); |
223 | else |
224 | itPaves.Next(); |
225 | } |
226 | myMFence.Remove(theVertNum); |
227 | } |
228 | } |
229 | //======================================================================= |
4e57c75e |
230 | //function : ExtPaves |
231 | //purpose : |
232 | //======================================================================= |
233 | const BOPDS_ListOfPave& BOPDS_PaveBlock::ExtPaves()const |
234 | { |
235 | return myExtPaves; |
236 | } |
237 | //======================================================================= |
238 | //function : ChangeExtPaves |
239 | //purpose : |
240 | //======================================================================= |
241 | BOPDS_ListOfPave& BOPDS_PaveBlock::ChangeExtPaves() |
242 | { |
243 | return myExtPaves; |
244 | } |
245 | //======================================================================= |
246 | //function : IsToUpdate |
247 | //purpose : |
248 | //======================================================================= |
249 | Standard_Boolean BOPDS_PaveBlock::IsToUpdate()const |
250 | { |
251 | return !myExtPaves.IsEmpty(); |
252 | } |
253 | //======================================================================= |
254 | //function : ContainsParameter |
255 | //purpose : |
256 | //======================================================================= |
257 | Standard_Boolean BOPDS_PaveBlock::ContainsParameter(const Standard_Real theT, |
787c4320 |
258 | const Standard_Real theTol, |
259 | Standard_Integer& theInd) const |
4e57c75e |
260 | { |
261 | Standard_Boolean bRet; |
4e57c75e |
262 | BOPDS_ListIteratorOfListOfPave aIt; |
263 | // |
787c4320 |
264 | bRet = Standard_False; |
4e57c75e |
265 | aIt.Initialize(myExtPaves); |
266 | for (; aIt.More(); aIt.Next()) { |
787c4320 |
267 | const BOPDS_Pave& aPave = aIt.Value(); |
268 | bRet = (Abs(aPave.Parameter() - theT) < theTol); |
269 | if (bRet) { |
270 | theInd = aPave.Index(); |
4e57c75e |
271 | break; |
272 | } |
273 | } |
274 | return bRet; |
275 | } |
276 | //======================================================================= |
277 | //function : Update |
278 | //purpose : |
279 | //======================================================================= |
280 | void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB, |
281 | const Standard_Boolean theFlag) |
282 | { |
283 | Standard_Integer i, aNb; |
4e57c75e |
284 | BOPDS_Pave aPave1, aPave2; |
285 | Handle(BOPDS_PaveBlock) aPB; |
286 | BOPDS_ListIteratorOfListOfPave aIt; |
287 | // |
288 | aNb=myExtPaves.Extent(); |
289 | if (theFlag) { |
290 | aNb=aNb+2; |
291 | } |
292 | // |
7a76337e |
293 | if (aNb <= 1) { |
294 | myExtPaves.Clear(); |
295 | myMFence.Clear(); |
296 | return; |
4e57c75e |
297 | } |
298 | // |
7a76337e |
299 | BOPDS_VectorOfPave pPaves(1, aNb); |
300 | // |
301 | i=1; |
4e57c75e |
302 | if (theFlag) { |
7a76337e |
303 | pPaves(i) = myPave1; |
4e57c75e |
304 | ++i; |
7a76337e |
305 | pPaves(i) = myPave2; |
4e57c75e |
306 | ++i; |
307 | } |
308 | // |
309 | aIt.Initialize(myExtPaves); |
310 | for (; aIt.More(); aIt.Next()) { |
311 | const BOPDS_Pave& aPave=aIt.Value(); |
7a76337e |
312 | pPaves(i) = aPave; |
4e57c75e |
313 | ++i; |
314 | } |
315 | myExtPaves.Clear(); |
316 | myMFence.Clear(); |
317 | // |
7a76337e |
318 | std::sort(pPaves.begin(), pPaves.end()); |
4e57c75e |
319 | // |
7a76337e |
320 | for (i = 1; i <= aNb; ++i) { |
321 | const BOPDS_Pave& aPave = pPaves(i); |
322 | if (i == 1) { |
323 | aPave1 = aPave; |
4e57c75e |
324 | continue; |
325 | } |
326 | // |
7a76337e |
327 | aPave2 = aPave; |
328 | aPB = new BOPDS_PaveBlock; |
4e57c75e |
329 | aPB->SetOriginalEdge(myOriginalEdge); |
330 | aPB->SetPave1(aPave1); |
331 | aPB->SetPave2(aPave2); |
332 | // |
333 | theLPB.Append(aPB); |
334 | // |
7a76337e |
335 | aPave1 = aPave2; |
4e57c75e |
336 | } |
4e57c75e |
337 | } |
4e57c75e |
338 | // ShrunkData |
339 | //======================================================================= |
340 | //function : HasShrunkData |
341 | //purpose : |
342 | //======================================================================= |
343 | Standard_Boolean BOPDS_PaveBlock::HasShrunkData()const |
344 | { |
345 | return (!myShrunkBox.IsVoid()); |
346 | } |
347 | //======================================================================= |
348 | //function : SetShrunkData |
349 | //purpose : |
350 | //======================================================================= |
351 | void BOPDS_PaveBlock::SetShrunkData(const Standard_Real theT1, |
352 | const Standard_Real theT2, |
01b5b3df |
353 | const Bnd_Box& theBox, |
354 | const Standard_Boolean theIsSplittable) |
4e57c75e |
355 | { |
356 | myTS1=theT1; |
357 | myTS2=theT2; |
358 | myShrunkBox=theBox; |
01b5b3df |
359 | myIsSplittable=theIsSplittable; |
4e57c75e |
360 | } |
361 | //======================================================================= |
362 | //function : ShrunkData |
363 | //purpose : |
364 | //======================================================================= |
365 | void BOPDS_PaveBlock::ShrunkData(Standard_Real& theT1, |
366 | Standard_Real& theT2, |
01b5b3df |
367 | Bnd_Box& theBox, |
368 | Standard_Boolean& theIsSplittable) const |
4e57c75e |
369 | { |
370 | theT1=myTS1; |
371 | theT2=myTS2; |
372 | theBox=myShrunkBox; |
01b5b3df |
373 | theIsSplittable=myIsSplittable; |
4e57c75e |
374 | } |
375 | //======================================================================= |
376 | //function : Dump |
377 | //purpose : |
378 | //======================================================================= |
379 | void BOPDS_PaveBlock::Dump()const |
380 | { |
381 | printf(" PB:{ E:%d orE:%d", myEdge, myOriginalEdge); |
382 | printf(" Pave1:"); |
383 | myPave1.Dump(); |
384 | printf(" Pave2:"); |
385 | myPave2.Dump(); |
386 | printf(" }"); |
387 | } |