| 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 | #include <BOPDS_PaveBlock.ixx> |
| 16 | #include <BOPDS_ListOfPave.hxx> |
| 17 | #include <Standard.hxx> |
| 18 | #include <NCollection_BaseAllocator.hxx> |
| 19 | |
| 20 | |
| 21 | #ifdef WNT |
| 22 | #pragma warning ( disable : 4291 ) |
| 23 | #endif |
| 24 | |
| 25 | static |
| 26 | void SortShell(const int n, BOPDS_Pave *a); |
| 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 | } |
| 42 | //======================================================================= |
| 43 | //function : |
| 44 | //purpose : |
| 45 | //======================================================================= |
| 46 | BOPDS_PaveBlock::BOPDS_PaveBlock(const Handle(NCollection_BaseAllocator)& theAllocator) |
| 47 | : |
| 48 | myAllocator(theAllocator), |
| 49 | myExtPaves(theAllocator), |
| 50 | myMFence(100, theAllocator) |
| 51 | { |
| 52 | myEdge=-1; |
| 53 | myOriginalEdge=-1; |
| 54 | myTS1=-99.; |
| 55 | myTS2=myTS1; |
| 56 | } |
| 57 | |
| 58 | //======================================================================= |
| 59 | //function : SetEdge |
| 60 | //purpose : |
| 61 | //======================================================================= |
| 62 | void BOPDS_PaveBlock::SetEdge(const Standard_Integer theEdge) |
| 63 | { |
| 64 | myEdge=theEdge; |
| 65 | } |
| 66 | //======================================================================= |
| 67 | //function : Edge |
| 68 | //purpose : |
| 69 | //======================================================================= |
| 70 | Standard_Integer BOPDS_PaveBlock::Edge()const |
| 71 | { |
| 72 | return myEdge; |
| 73 | } |
| 74 | //======================================================================= |
| 75 | //function : HasEdge |
| 76 | //purpose : |
| 77 | //======================================================================= |
| 78 | Standard_Boolean BOPDS_PaveBlock::HasEdge()const |
| 79 | { |
| 80 | return (myEdge>=0); |
| 81 | } |
| 82 | //======================================================================= |
| 83 | //function : HasEdge |
| 84 | //purpose : |
| 85 | //======================================================================= |
| 86 | Standard_Boolean BOPDS_PaveBlock::HasEdge(Standard_Integer& theEdge)const |
| 87 | { |
| 88 | theEdge=myEdge; |
| 89 | return (myEdge>=0); |
| 90 | } |
| 91 | |
| 92 | //======================================================================= |
| 93 | //function : SetOriginalEdge |
| 94 | //purpose : |
| 95 | //======================================================================= |
| 96 | void BOPDS_PaveBlock::SetOriginalEdge(const Standard_Integer theEdge) |
| 97 | { |
| 98 | myOriginalEdge=theEdge; |
| 99 | } |
| 100 | //======================================================================= |
| 101 | //function : OriginalEdge |
| 102 | //purpose : |
| 103 | //======================================================================= |
| 104 | Standard_Integer BOPDS_PaveBlock::OriginalEdge()const |
| 105 | { |
| 106 | return myOriginalEdge; |
| 107 | } |
| 108 | //======================================================================= |
| 109 | //function : IsSplitEdge |
| 110 | //purpose : |
| 111 | //======================================================================= |
| 112 | Standard_Boolean BOPDS_PaveBlock::IsSplitEdge()const |
| 113 | { |
| 114 | return (myEdge!=myOriginalEdge); |
| 115 | } |
| 116 | //======================================================================= |
| 117 | //function : SetPave1 |
| 118 | //purpose : |
| 119 | //======================================================================= |
| 120 | void BOPDS_PaveBlock::SetPave1(const BOPDS_Pave& thePave) |
| 121 | { |
| 122 | myPave1=thePave; |
| 123 | } |
| 124 | //======================================================================= |
| 125 | //function : Pave1 |
| 126 | //purpose : |
| 127 | //======================================================================= |
| 128 | const BOPDS_Pave& BOPDS_PaveBlock::Pave1()const |
| 129 | { |
| 130 | return myPave1; |
| 131 | } |
| 132 | //======================================================================= |
| 133 | //function : SetPave2 |
| 134 | //purpose : |
| 135 | //======================================================================= |
| 136 | void BOPDS_PaveBlock::SetPave2(const BOPDS_Pave& thePave) |
| 137 | { |
| 138 | myPave2=thePave; |
| 139 | } |
| 140 | //======================================================================= |
| 141 | //function : Pave2 |
| 142 | //purpose : |
| 143 | //======================================================================= |
| 144 | const BOPDS_Pave& BOPDS_PaveBlock::Pave2()const |
| 145 | { |
| 146 | return myPave2; |
| 147 | } |
| 148 | //======================================================================= |
| 149 | //function : Range |
| 150 | //purpose : |
| 151 | //======================================================================= |
| 152 | void BOPDS_PaveBlock::Range(Standard_Real& theT1, |
| 153 | Standard_Real& theT2)const |
| 154 | { |
| 155 | theT1=myPave1.Parameter(); |
| 156 | theT2=myPave2.Parameter(); |
| 157 | } |
| 158 | //======================================================================= |
| 159 | //function : Indices |
| 160 | //purpose : |
| 161 | //======================================================================= |
| 162 | void BOPDS_PaveBlock::Indices(Standard_Integer& theIndex1, |
| 163 | Standard_Integer& theIndex2)const |
| 164 | { |
| 165 | theIndex1=myPave1.Index(); |
| 166 | theIndex2=myPave2.Index(); |
| 167 | } |
| 168 | //======================================================================= |
| 169 | //function : HasSameBounds |
| 170 | //purpose : |
| 171 | //======================================================================= |
| 172 | Standard_Boolean BOPDS_PaveBlock::HasSameBounds(const Handle(BOPDS_PaveBlock)& theOther)const |
| 173 | { |
| 174 | Standard_Boolean bFlag1, bFlag2; |
| 175 | Standard_Integer n11, n12, n21, n22; |
| 176 | // |
| 177 | Indices(n11, n12); |
| 178 | theOther->Indices(n21, n22); |
| 179 | // |
| 180 | bFlag1=(n11==n21) && (n12==n22); |
| 181 | bFlag2=(n11==n22) && (n12==n21); |
| 182 | // |
| 183 | return (bFlag1 || bFlag2); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | // |
| 188 | // Extras |
| 189 | // |
| 190 | //======================================================================= |
| 191 | //function : AppendExtPave |
| 192 | //purpose : |
| 193 | //======================================================================= |
| 194 | void BOPDS_PaveBlock::AppendExtPave(const BOPDS_Pave& thePave) |
| 195 | { |
| 196 | if (myMFence.Add(thePave.Index())) { |
| 197 | myExtPaves.Append(thePave); |
| 198 | } |
| 199 | } |
| 200 | //======================================================================= |
| 201 | //function : AppendExtPave1 |
| 202 | //purpose : |
| 203 | //======================================================================= |
| 204 | void BOPDS_PaveBlock::AppendExtPave1(const BOPDS_Pave& thePave) |
| 205 | { |
| 206 | myExtPaves.Append(thePave); |
| 207 | } |
| 208 | //======================================================================= |
| 209 | //function : ExtPaves |
| 210 | //purpose : |
| 211 | //======================================================================= |
| 212 | const BOPDS_ListOfPave& BOPDS_PaveBlock::ExtPaves()const |
| 213 | { |
| 214 | return myExtPaves; |
| 215 | } |
| 216 | //======================================================================= |
| 217 | //function : ChangeExtPaves |
| 218 | //purpose : |
| 219 | //======================================================================= |
| 220 | BOPDS_ListOfPave& BOPDS_PaveBlock::ChangeExtPaves() |
| 221 | { |
| 222 | return myExtPaves; |
| 223 | } |
| 224 | //======================================================================= |
| 225 | //function : IsToUpdate |
| 226 | //purpose : |
| 227 | //======================================================================= |
| 228 | Standard_Boolean BOPDS_PaveBlock::IsToUpdate()const |
| 229 | { |
| 230 | return !myExtPaves.IsEmpty(); |
| 231 | } |
| 232 | //======================================================================= |
| 233 | //function : ContainsParameter |
| 234 | //purpose : |
| 235 | //======================================================================= |
| 236 | Standard_Boolean BOPDS_PaveBlock::ContainsParameter(const Standard_Real theT, |
| 237 | const Standard_Real theTol)const |
| 238 | { |
| 239 | Standard_Boolean bRet; |
| 240 | Standard_Real dT; |
| 241 | BOPDS_ListIteratorOfListOfPave aIt; |
| 242 | // |
| 243 | bRet=Standard_False; |
| 244 | aIt.Initialize(myExtPaves); |
| 245 | for (; aIt.More(); aIt.Next()) { |
| 246 | dT=aIt.Value().Parameter()-theT; |
| 247 | if (dT<0.) { |
| 248 | dT=-dT; |
| 249 | } |
| 250 | if (dT<theTol) { |
| 251 | bRet=!bRet; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | return bRet; |
| 256 | } |
| 257 | //======================================================================= |
| 258 | //function : Update |
| 259 | //purpose : |
| 260 | //======================================================================= |
| 261 | void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB, |
| 262 | const Standard_Boolean theFlag) |
| 263 | { |
| 264 | Standard_Integer i, aNb; |
| 265 | BOPDS_Pave *pPaves; |
| 266 | BOPDS_Pave aPave1, aPave2; |
| 267 | Handle(BOPDS_PaveBlock) aPB; |
| 268 | BOPDS_ListIteratorOfListOfPave aIt; |
| 269 | // |
| 270 | aNb=myExtPaves.Extent(); |
| 271 | if (theFlag) { |
| 272 | aNb=aNb+2; |
| 273 | } |
| 274 | // |
| 275 | pPaves=(BOPDS_Pave *)myAllocator->Allocate(aNb*sizeof(BOPDS_Pave)); |
| 276 | for (i=0; i<aNb; ++i) { |
| 277 | new (pPaves+i) BOPDS_Pave(); |
| 278 | } |
| 279 | // |
| 280 | i=0; |
| 281 | if (theFlag) { |
| 282 | pPaves[i]=myPave1; |
| 283 | ++i; |
| 284 | pPaves[i]=myPave2; |
| 285 | ++i; |
| 286 | } |
| 287 | // |
| 288 | aIt.Initialize(myExtPaves); |
| 289 | for (; aIt.More(); aIt.Next()) { |
| 290 | const BOPDS_Pave& aPave=aIt.Value(); |
| 291 | pPaves[i]=(aPave); |
| 292 | ++i; |
| 293 | } |
| 294 | myExtPaves.Clear(); |
| 295 | myMFence.Clear(); |
| 296 | // |
| 297 | SortShell(aNb, pPaves); |
| 298 | // |
| 299 | for (i=0; i<aNb; ++i) { |
| 300 | const BOPDS_Pave& aPave=pPaves[i]; |
| 301 | if (!i) { |
| 302 | aPave1=aPave; |
| 303 | continue; |
| 304 | } |
| 305 | // |
| 306 | aPave2=aPave; |
| 307 | aPB=new BOPDS_PaveBlock; |
| 308 | aPB->SetOriginalEdge(myOriginalEdge); |
| 309 | aPB->SetPave1(aPave1); |
| 310 | aPB->SetPave2(aPave2); |
| 311 | // |
| 312 | theLPB.Append(aPB); |
| 313 | // |
| 314 | aPave1=aPave2; |
| 315 | } |
| 316 | // |
| 317 | for (i=0; i<aNb; ++i) { |
| 318 | pPaves[i].~BOPDS_Pave(); |
| 319 | } |
| 320 | myAllocator->Free(pPaves); |
| 321 | } |
| 322 | |
| 323 | //======================================================================= |
| 324 | // function: SortShell |
| 325 | // purpose : |
| 326 | //======================================================================= |
| 327 | void SortShell(const int n, BOPDS_Pave *a) |
| 328 | { |
| 329 | int nd, i, j, l, d=1; |
| 330 | BOPDS_Pave x; |
| 331 | // |
| 332 | while(d<=n) { |
| 333 | d*=2; |
| 334 | } |
| 335 | // |
| 336 | while (d) { |
| 337 | d=(d-1)/2; |
| 338 | // |
| 339 | nd=n-d; |
| 340 | for (i=0; i<nd; ++i) { |
| 341 | j=i; |
| 342 | m30:; |
| 343 | l=j+d; |
| 344 | if (a[l] < a[j]){ |
| 345 | x=a[j]; |
| 346 | a[j]=a[l]; |
| 347 | a[l]=x; |
| 348 | j-=d; |
| 349 | if (j > -1) goto m30; |
| 350 | }//if (a[l] < a[j]){ |
| 351 | }//for (i=0; i<nd; ++i) |
| 352 | }//while (1) |
| 353 | } |
| 354 | |
| 355 | // ShrunkData |
| 356 | //======================================================================= |
| 357 | //function : HasShrunkData |
| 358 | //purpose : |
| 359 | //======================================================================= |
| 360 | Standard_Boolean BOPDS_PaveBlock::HasShrunkData()const |
| 361 | { |
| 362 | return (!myShrunkBox.IsVoid()); |
| 363 | } |
| 364 | //======================================================================= |
| 365 | //function : SetShrunkData |
| 366 | //purpose : |
| 367 | //======================================================================= |
| 368 | void BOPDS_PaveBlock::SetShrunkData(const Standard_Real theT1, |
| 369 | const Standard_Real theT2, |
| 370 | const Bnd_Box& theBox) |
| 371 | { |
| 372 | myTS1=theT1; |
| 373 | myTS2=theT2; |
| 374 | myShrunkBox=theBox; |
| 375 | } |
| 376 | //======================================================================= |
| 377 | //function : ShrunkData |
| 378 | //purpose : |
| 379 | //======================================================================= |
| 380 | void BOPDS_PaveBlock::ShrunkData(Standard_Real& theT1, |
| 381 | Standard_Real& theT2, |
| 382 | Bnd_Box& theBox)const |
| 383 | { |
| 384 | theT1=myTS1; |
| 385 | theT2=myTS2; |
| 386 | theBox=myShrunkBox; |
| 387 | } |
| 388 | //======================================================================= |
| 389 | //function : Dump |
| 390 | //purpose : |
| 391 | //======================================================================= |
| 392 | void BOPDS_PaveBlock::Dump()const |
| 393 | { |
| 394 | printf(" PB:{ E:%d orE:%d", myEdge, myOriginalEdge); |
| 395 | printf(" Pave1:"); |
| 396 | myPave1.Dump(); |
| 397 | printf(" Pave2:"); |
| 398 | myPave2.Dump(); |
| 399 | printf(" }"); |
| 400 | } |