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
16 #include <Bnd_Box.hxx>
17 #include <BOPDS_ListOfPave.hxx>
18 #include <BOPDS_Pave.hxx>
19 #include <BOPDS_PaveBlock.hxx>
20 #include <BOPDS_VectorOfPave.hxx>
21 #include <NCollection_BaseAllocator.hxx>
22 #include <Standard.hxx>
23 #include <Standard_Type.hxx>
24
25 #include <algorithm>
IMPLEMENT_STANDARD_RTTIEXT(BOPDS_PaveBlock,Standard_Transient)26 IMPLEMENT_STANDARD_RTTIEXT(BOPDS_PaveBlock,Standard_Transient)
27
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;
41 myIsSplittable=Standard_False;
42 }
43 //=======================================================================
44 //function :
45 //purpose :
46 //=======================================================================
BOPDS_PaveBlock(const Handle (NCollection_BaseAllocator)& theAllocator)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;
57 myIsSplittable=Standard_False;
58 }
59
60 //=======================================================================
61 //function : SetEdge
62 //purpose :
63 //=======================================================================
SetEdge(const Standard_Integer theEdge)64 void BOPDS_PaveBlock::SetEdge(const Standard_Integer theEdge)
65 {
66 myEdge=theEdge;
67 }
68 //=======================================================================
69 //function : Edge
70 //purpose :
71 //=======================================================================
Edge() const72 Standard_Integer BOPDS_PaveBlock::Edge()const
73 {
74 return myEdge;
75 }
76 //=======================================================================
77 //function : HasEdge
78 //purpose :
79 //=======================================================================
HasEdge() const80 Standard_Boolean BOPDS_PaveBlock::HasEdge()const
81 {
82 return (myEdge>=0);
83 }
84 //=======================================================================
85 //function : HasEdge
86 //purpose :
87 //=======================================================================
HasEdge(Standard_Integer & theEdge) const88 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 //=======================================================================
SetOriginalEdge(const Standard_Integer theEdge)98 void BOPDS_PaveBlock::SetOriginalEdge(const Standard_Integer theEdge)
99 {
100 myOriginalEdge=theEdge;
101 }
102 //=======================================================================
103 //function : OriginalEdge
104 //purpose :
105 //=======================================================================
OriginalEdge() const106 Standard_Integer BOPDS_PaveBlock::OriginalEdge()const
107 {
108 return myOriginalEdge;
109 }
110 //=======================================================================
111 //function : IsSplitEdge
112 //purpose :
113 //=======================================================================
IsSplitEdge() const114 Standard_Boolean BOPDS_PaveBlock::IsSplitEdge()const
115 {
116 return (myEdge!=myOriginalEdge);
117 }
118 //=======================================================================
119 //function : SetPave1
120 //purpose :
121 //=======================================================================
SetPave1(const BOPDS_Pave & thePave)122 void BOPDS_PaveBlock::SetPave1(const BOPDS_Pave& thePave)
123 {
124 myPave1=thePave;
125 }
126 //=======================================================================
127 //function : Pave1
128 //purpose :
129 //=======================================================================
Pave1() const130 const BOPDS_Pave& BOPDS_PaveBlock::Pave1()const
131 {
132 return myPave1;
133 }
134 //=======================================================================
135 //function : SetPave2
136 //purpose :
137 //=======================================================================
SetPave2(const BOPDS_Pave & thePave)138 void BOPDS_PaveBlock::SetPave2(const BOPDS_Pave& thePave)
139 {
140 myPave2=thePave;
141 }
142 //=======================================================================
143 //function : Pave2
144 //purpose :
145 //=======================================================================
Pave2() const146 const BOPDS_Pave& BOPDS_PaveBlock::Pave2()const
147 {
148 return myPave2;
149 }
150 //=======================================================================
151 //function : Range
152 //purpose :
153 //=======================================================================
Range(Standard_Real & theT1,Standard_Real & theT2) const154 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 //=======================================================================
Indices(Standard_Integer & theIndex1,Standard_Integer & theIndex2) const164 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 //=======================================================================
HasSameBounds(const Handle (BOPDS_PaveBlock)& theOther) const174 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 //=======================================================================
AppendExtPave(const BOPDS_Pave & thePave)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 //=======================================================================
AppendExtPave1(const BOPDS_Pave & thePave)206 void BOPDS_PaveBlock::AppendExtPave1(const BOPDS_Pave& thePave)
207 {
208 myExtPaves.Append(thePave);
209 }
210 //=======================================================================
211 //function : RemoveExtPave
212 //purpose :
213 //=======================================================================
RemoveExtPave(const Standard_Integer theVertNum)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 //=======================================================================
230 //function : ExtPaves
231 //purpose :
232 //=======================================================================
ExtPaves() const233 const BOPDS_ListOfPave& BOPDS_PaveBlock::ExtPaves()const
234 {
235 return myExtPaves;
236 }
237 //=======================================================================
238 //function : ChangeExtPaves
239 //purpose :
240 //=======================================================================
ChangeExtPaves()241 BOPDS_ListOfPave& BOPDS_PaveBlock::ChangeExtPaves()
242 {
243 return myExtPaves;
244 }
245 //=======================================================================
246 //function : IsToUpdate
247 //purpose :
248 //=======================================================================
IsToUpdate() const249 Standard_Boolean BOPDS_PaveBlock::IsToUpdate()const
250 {
251 return !myExtPaves.IsEmpty();
252 }
253 //=======================================================================
254 //function : ContainsParameter
255 //purpose :
256 //=======================================================================
ContainsParameter(const Standard_Real theT,const Standard_Real theTol,Standard_Integer & theInd) const257 Standard_Boolean BOPDS_PaveBlock::ContainsParameter(const Standard_Real theT,
258 const Standard_Real theTol,
259 Standard_Integer& theInd) const
260 {
261 Standard_Boolean bRet;
262 BOPDS_ListIteratorOfListOfPave aIt;
263 //
264 bRet = Standard_False;
265 aIt.Initialize(myExtPaves);
266 for (; aIt.More(); aIt.Next()) {
267 const BOPDS_Pave& aPave = aIt.Value();
268 bRet = (Abs(aPave.Parameter() - theT) < theTol);
269 if (bRet) {
270 theInd = aPave.Index();
271 break;
272 }
273 }
274 return bRet;
275 }
276 //=======================================================================
277 //function : Update
278 //purpose :
279 //=======================================================================
Update(BOPDS_ListOfPaveBlock & theLPB,const Standard_Boolean theFlag)280 void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB,
281 const Standard_Boolean theFlag)
282 {
283 Standard_Integer i, aNb;
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 //
293 if (aNb <= 1) {
294 myExtPaves.Clear();
295 myMFence.Clear();
296 return;
297 }
298 //
299 BOPDS_VectorOfPave pPaves(1, aNb);
300 //
301 i=1;
302 if (theFlag) {
303 pPaves(i) = myPave1;
304 ++i;
305 pPaves(i) = myPave2;
306 ++i;
307 }
308 //
309 aIt.Initialize(myExtPaves);
310 for (; aIt.More(); aIt.Next()) {
311 const BOPDS_Pave& aPave=aIt.Value();
312 pPaves(i) = aPave;
313 ++i;
314 }
315 myExtPaves.Clear();
316 myMFence.Clear();
317 //
318 std::sort(pPaves.begin(), pPaves.end());
319 //
320 for (i = 1; i <= aNb; ++i) {
321 const BOPDS_Pave& aPave = pPaves(i);
322 if (i == 1) {
323 aPave1 = aPave;
324 continue;
325 }
326 //
327 aPave2 = aPave;
328 aPB = new BOPDS_PaveBlock;
329 aPB->SetOriginalEdge(myOriginalEdge);
330 aPB->SetPave1(aPave1);
331 aPB->SetPave2(aPave2);
332 //
333 theLPB.Append(aPB);
334 //
335 aPave1 = aPave2;
336 }
337 }
338 // ShrunkData
339 //=======================================================================
340 //function : HasShrunkData
341 //purpose :
342 //=======================================================================
HasShrunkData() const343 Standard_Boolean BOPDS_PaveBlock::HasShrunkData()const
344 {
345 return (!myShrunkBox.IsVoid());
346 }
347 //=======================================================================
348 //function : SetShrunkData
349 //purpose :
350 //=======================================================================
SetShrunkData(const Standard_Real theT1,const Standard_Real theT2,const Bnd_Box & theBox,const Standard_Boolean theIsSplittable)351 void BOPDS_PaveBlock::SetShrunkData(const Standard_Real theT1,
352 const Standard_Real theT2,
353 const Bnd_Box& theBox,
354 const Standard_Boolean theIsSplittable)
355 {
356 myTS1=theT1;
357 myTS2=theT2;
358 myShrunkBox=theBox;
359 myIsSplittable=theIsSplittable;
360 }
361 //=======================================================================
362 //function : ShrunkData
363 //purpose :
364 //=======================================================================
ShrunkData(Standard_Real & theT1,Standard_Real & theT2,Bnd_Box & theBox,Standard_Boolean & theIsSplittable) const365 void BOPDS_PaveBlock::ShrunkData(Standard_Real& theT1,
366 Standard_Real& theT2,
367 Bnd_Box& theBox,
368 Standard_Boolean& theIsSplittable) const
369 {
370 theT1=myTS1;
371 theT2=myTS2;
372 theBox=myShrunkBox;
373 theIsSplittable=myIsSplittable;
374 }
375 //=======================================================================
376 //function : Dump
377 //purpose :
378 //=======================================================================
Dump() const379 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 }
388