| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.geo.contouring; |
| 27 |
|
| 28 |
import dr.geo.contouring.ContourAttrib; |
| 29 |
|
| 30 |
import java.util.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public class ContourGenerator { |
| 57 |
|
| 58 |
|
| 59 |
private static final boolean DEBUG = false; |
| 60 |
|
| 61 |
|
| 62 |
private static final String kCancelMsg = "Method ContourGenerator.getContours() canceled by user."; |
| 63 |
private static final String kInconsistantArrMsg = "Inconsistant array sizes."; |
| 64 |
private static final String kArrSizeMsg = "Data arrays must have more than one row or column."; |
| 65 |
private static final String kNegLogDataMsg = "Function data must be > 0 for logarithmic intervals."; |
| 66 |
|
| 67 |
|
| 68 |
private static final int kBufSize = 1000; |
| 69 |
|
| 70 |
|
| 71 |
private static final int kMinNumPoints = 3; |
| 72 |
|
| 73 |
|
| 74 |
private List pathList = new ArrayList(); |
| 75 |
|
| 76 |
|
| 77 |
private boolean cCalculated = false; |
| 78 |
|
| 79 |
|
| 80 |
private double[][] xArray, yArray, funcArray; |
| 81 |
|
| 82 |
|
| 83 |
private double[] xArr1D, yArr1D; |
| 84 |
|
| 85 |
|
| 86 |
private ContourAttrib[] cAttr; |
| 87 |
|
| 88 |
|
| 89 |
private float fracComplete = 0; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
private boolean isCanceled = false; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
private double[] pathbufxt, pathbufyt; |
| 100 |
private int[] pathbufia; |
| 101 |
private int lnstrt; |
| 102 |
private int ignext; |
| 103 |
private int icont; |
| 104 |
private double cont; |
| 105 |
private int iss, iee, jss, jee; |
| 106 |
private int ima; |
| 107 |
private int iae; |
| 108 |
private int ibeg, jbeg; |
| 109 |
private int gi, gj; |
| 110 |
private double fij; |
| 111 |
private int idir; |
| 112 |
private int np=0; |
| 113 |
private double wx=0, wy=0; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public ContourGenerator(double[][] xArr, double[][] yArr, double[][] fArr, ContourAttrib[] cAttr) { |
| 127 |
|
| 128 |
|
| 129 |
if (yArr.length != xArr.length || yArr.length != fArr.length) |
| 130 |
throw new IllegalArgumentException(kInconsistantArrMsg); |
| 131 |
if (yArr[0].length != xArr[0].length || yArr[0].length != fArr[0].length) |
| 132 |
throw new IllegalArgumentException(kInconsistantArrMsg); |
| 133 |
if (xArr.length <= 1 || xArr[0].length <= 1) |
| 134 |
throw new IllegalArgumentException(kArrSizeMsg); |
| 135 |
|
| 136 |
this.cAttr = cAttr; |
| 137 |
xArray = xArr; |
| 138 |
yArray = yArr; |
| 139 |
funcArray = fArr; |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
public ContourGenerator(double[] xArr, double[] yArr, double[][] fArr, ContourAttrib[] cAttr) { |
| 156 |
|
| 157 |
|
| 158 |
if (yArr.length != fArr.length || xArr.length != fArr[0].length) |
| 159 |
throw new IllegalArgumentException(kInconsistantArrMsg); |
| 160 |
if (xArr.length <= 1) |
| 161 |
throw new IllegalArgumentException(kArrSizeMsg); |
| 162 |
|
| 163 |
this.cAttr = cAttr; |
| 164 |
xArr1D = xArr; |
| 165 |
yArr1D = yArr; |
| 166 |
funcArray = fArr; |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
public ContourGenerator(double[][] xArr, double[][] yArr, double[][] fArr, |
| 183 |
int nc, boolean logInterval) { |
| 184 |
|
| 185 |
|
| 186 |
if (yArr.length != xArr.length || yArr.length != fArr.length) |
| 187 |
throw new IllegalArgumentException(kInconsistantArrMsg); |
| 188 |
if (yArr[0].length != xArr[0].length || yArr[0].length != fArr[0].length) |
| 189 |
throw new IllegalArgumentException(kInconsistantArrMsg); |
| 190 |
if (xArr.length <= 1 || xArr[0].length <= 1) |
| 191 |
throw new IllegalArgumentException(kArrSizeMsg); |
| 192 |
|
| 193 |
xArray = xArr; |
| 194 |
yArray = yArr; |
| 195 |
funcArray = fArr; |
| 196 |
|
| 197 |
if (logInterval) |
| 198 |
findLogIntervals(nc); |
| 199 |
else |
| 200 |
findLinearIntervals(nc); |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
public ContourGenerator(double[] xArr, double[] yArr, double[][] fArr, |
| 219 |
int nc, boolean logInterval) { |
| 220 |
|
| 221 |
|
| 222 |
if (yArr.length != fArr.length || xArr.length != fArr[0].length) |
| 223 |
throw new IllegalArgumentException(kInconsistantArrMsg); |
| 224 |
if (xArr.length <= 1) |
| 225 |
throw new IllegalArgumentException(kArrSizeMsg); |
| 226 |
|
| 227 |
xArr1D = xArr; |
| 228 |
yArr1D = yArr; |
| 229 |
funcArray = fArr; |
| 230 |
|
| 231 |
if (logInterval) |
| 232 |
findLogIntervals(nc); |
| 233 |
else |
| 234 |
findLinearIntervals(nc); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public ContourPath[] getContours() throws InterruptedException { |
| 249 |
|
| 250 |
if (!cCalculated) { |
| 251 |
isCanceled = false; |
| 252 |
pathList.clear(); |
| 253 |
|
| 254 |
|
| 255 |
computeContours(); |
| 256 |
|
| 257 |
|
| 258 |
cAttr = null; |
| 259 |
xArray = yArray = funcArray = null; |
| 260 |
xArr1D = yArr1D = null; |
| 261 |
|
| 262 |
|
| 263 |
cCalculated = true; |
| 264 |
fracComplete = 1; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
int size = pathList.size(); |
| 269 |
ContourPath[] arr = new ContourPath[size]; |
| 270 |
for (int i=0; i < size; ++i) |
| 271 |
arr[i] = (ContourPath)pathList.get(i); |
| 272 |
|
| 273 |
return arr; |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
public boolean done() { |
| 280 |
return cCalculated; |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
public void cancel() { |
| 287 |
isCanceled = true; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
public float getProgress() { |
| 295 |
return fracComplete; |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
private void findLinearIntervals(int nc) { |
| 303 |
|
| 304 |
|
| 305 |
double zMin = Double.MAX_VALUE; |
| 306 |
double zMax = -zMin; |
| 307 |
int ni = funcArray.length; |
| 308 |
for (int i=0; i < ni; ++i) { |
| 309 |
int nj = funcArray[i].length; |
| 310 |
for (int j=0; j < nj; ++j) { |
| 311 |
double zVal = funcArray[i][j]; |
| 312 |
zMin = Math.min(zMin, zVal); |
| 313 |
zMax = Math.max(zMax, zVal); |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
cAttr = new ContourAttrib[nc]; |
| 319 |
|
| 320 |
|
| 321 |
double delta = (zMax-zMin)/(nc+1); |
| 322 |
for (int i=0; i < nc; i++) { |
| 323 |
cAttr[i] = new ContourAttrib( zMin + (i+1)*delta ); |
| 324 |
if (DEBUG) |
| 325 |
System.out.println("level[" + i + "] = " + (zMin + (i+1)*delta)); |
| 326 |
} |
| 327 |
|
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
private void findLogIntervals(int nc) { |
| 334 |
|
| 335 |
|
| 336 |
double zMin = Double.MAX_VALUE; |
| 337 |
double zMax = -zMin; |
| 338 |
int ni = funcArray.length; |
| 339 |
for (int i=0; i < ni; ++i) { |
| 340 |
int nj = funcArray[i].length; |
| 341 |
for (int j=0; j < nj; ++j) { |
| 342 |
double zVal = funcArray[i][j]; |
| 343 |
zMin = Math.min(zMin, zVal); |
| 344 |
zMax = Math.max(zMax, zVal); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
if (zMin < 0) |
| 349 |
throw new IllegalArgumentException(kNegLogDataMsg); |
| 350 |
|
| 351 |
|
| 352 |
cAttr = new ContourAttrib[nc]; |
| 353 |
|
| 354 |
|
| 355 |
double temp = Math.log(zMin); |
| 356 |
double delta = (Math.log(zMax) - temp)/(nc+1); |
| 357 |
for (int i=0; i < nc; i++) |
| 358 |
cAttr[i] = new ContourAttrib( Math.exp(temp + (i+1)*delta) ); |
| 359 |
|
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
private void computeContours() throws InterruptedException { |
| 369 |
|
| 370 |
int ncont = cAttr.length; |
| 371 |
|
| 372 |
|
| 373 |
int nx=0, ny=0; |
| 374 |
if (xArray != null) { |
| 375 |
ny = xArray.length; |
| 376 |
nx = xArray[0].length; |
| 377 |
} else { |
| 378 |
nx = xArr1D.length; |
| 379 |
ny = yArr1D.length; |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
pathbufxt = new double[kBufSize]; |
| 384 |
pathbufyt = new double[kBufSize]; |
| 385 |
pathbufia = new int[kBufSize*3]; |
| 386 |
|
| 387 |
|
| 388 |
lnstrt = 1; |
| 389 |
ignext = 0; |
| 390 |
|
| 391 |
|
| 392 |
for (icont = 0; icont < ncont; ++icont) { |
| 393 |
|
| 394 |
|
| 395 |
if (isCanceled) |
| 396 |
throw new InterruptedException(kCancelMsg); |
| 397 |
|
| 398 |
|
| 399 |
cont = cAttr[icont].getLevel(); |
| 400 |
iss = 1; |
| 401 |
iee = nx; |
| 402 |
jss = 1; |
| 403 |
jee = ny; |
| 404 |
|
| 405 |
boolean subDivFlg = false; |
| 406 |
do { |
| 407 |
|
| 408 |
FlagContourPassings(); |
| 409 |
|
| 410 |
boolean L10flg = false; |
| 411 |
do { |
| 412 |
|
| 413 |
if (!L10flg) { |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
ima = 1; |
| 418 |
ibeg = iss - 1; |
| 419 |
jbeg = jss; |
| 420 |
} |
| 421 |
|
| 422 |
imaLoop: |
| 423 |
do { |
| 424 |
|
| 425 |
if (!L10flg) { |
| 426 |
boolean imb = false; |
| 427 |
boolean doneFlg = false; |
| 428 |
do { |
| 429 |
|
| 430 |
switch(ima) { |
| 431 |
case 1: |
| 432 |
++ibeg; |
| 433 |
if (ibeg == iee) |
| 434 |
ima = 2; |
| 435 |
break; |
| 436 |
|
| 437 |
case 2: |
| 438 |
++jbeg; |
| 439 |
if (jbeg == jee) |
| 440 |
ima = 3; |
| 441 |
break; |
| 442 |
|
| 443 |
case 3: |
| 444 |
--ibeg; |
| 445 |
if (ibeg == iss) |
| 446 |
ima = 4; |
| 447 |
break; |
| 448 |
|
| 449 |
case 4: |
| 450 |
--jbeg; |
| 451 |
if (jbeg == jss) |
| 452 |
ima = 5; |
| 453 |
break; |
| 454 |
|
| 455 |
case 5: |
| 456 |
continue imaLoop; |
| 457 |
} |
| 458 |
|
| 459 |
if (funcArray[jbeg -1][ibeg -1] <= cont) { |
| 460 |
imb = true; |
| 461 |
doneFlg = false; |
| 462 |
|
| 463 |
} else if (imb == true) |
| 464 |
doneFlg = true; |
| 465 |
|
| 466 |
} while (!doneFlg); |
| 467 |
|
| 468 |
|
| 469 |
gi = ibeg; |
| 470 |
gj = jbeg; |
| 471 |
fij = funcArray[jbeg -1][ibeg -1]; |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
switch (ima) { |
| 481 |
case 1: |
| 482 |
Routine_L21(); |
| 483 |
break; |
| 484 |
|
| 485 |
case 2: |
| 486 |
if (gj != jss) { |
| 487 |
if (!Routine_L31()) |
| 488 |
Routine_L21(); |
| 489 |
} else |
| 490 |
Routine_L21(); |
| 491 |
break; |
| 492 |
|
| 493 |
case 3: |
| 494 |
if (gi != iee) { |
| 495 |
if (!Routine_L41()) |
| 496 |
Routine_L21(); |
| 497 |
} else { |
| 498 |
if (!Routine_L31()) |
| 499 |
Routine_L21(); |
| 500 |
} |
| 501 |
break; |
| 502 |
|
| 503 |
case 4: |
| 504 |
if (gj != jee) { |
| 505 |
if (!Routine_L51()) |
| 506 |
Routine_L21(); |
| 507 |
} else { |
| 508 |
if (!Routine_L41()) |
| 509 |
Routine_L21(); |
| 510 |
} |
| 511 |
break; |
| 512 |
|
| 513 |
case 5: |
| 514 |
if (!Routine_L51()) |
| 515 |
Routine_L21(); |
| 516 |
break; |
| 517 |
} |
| 518 |
|
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
L10flg = false; |
| 525 |
lnstrt = 1; |
| 526 |
ignext = 0; |
| 527 |
accumContour(np, icont, pathbufxt, pathbufyt, cAttr[icont]); |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
} while (ima != 5); |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
if (iae != 0) { |
| 536 |
int ntmp3 = iae; |
| 537 |
for (int iia = 1; iia <= ntmp3; ++iia) { |
| 538 |
if (pathbufia[iia -1] != 0) { |
| 539 |
|
| 540 |
gi = pathbufia[iia - 1]/1000; |
| 541 |
gj = pathbufia[iia - 1] - gi*1000; |
| 542 |
fij = funcArray[gj -1][gi -1]; |
| 543 |
pathbufia[iia - 1] = 0; |
| 544 |
|
| 545 |
Routine_L21(); |
| 546 |
|
| 547 |
L10flg = true; |
| 548 |
break; |
| 549 |
} |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
} while ( L10flg ); |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
subDivFlg = false; |
| 559 |
if (iee == nx) { |
| 560 |
if (jee != ny) { |
| 561 |
jss = jee; |
| 562 |
jee = ny; |
| 563 |
subDivFlg = true; |
| 564 |
} |
| 565 |
} else { |
| 566 |
iss = iee; |
| 567 |
iee = nx; |
| 568 |
subDivFlg = true; |
| 569 |
} |
| 570 |
|
| 571 |
} while (subDivFlg); |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
fracComplete = (float)(icont+1)/(float)(ncont); |
| 576 |
|
| 577 |
|
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
pathbufxt = null; |
| 583 |
pathbufyt = null; |
| 584 |
pathbufia = null; |
| 585 |
|
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
private void FlagContourPassings() { |
| 595 |
|
| 596 |
iae = 0; |
| 597 |
int ntmp2 = jee - 1; |
| 598 |
for (int j=jss + 1; j <= ntmp2; ++j) { |
| 599 |
boolean imb = false; |
| 600 |
int iaend = iae; |
| 601 |
int ntmp3 = iee; |
| 602 |
for (int i=iss; i <= ntmp3; ++i) { |
| 603 |
if (funcArray[j -1][i -1] <= cont) |
| 604 |
imb = true; |
| 605 |
else if (imb == true) { |
| 606 |
++iae; |
| 607 |
pathbufia[iae - 1] = i*1000 + j; |
| 608 |
imb = false; |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
if (iae == kBufSize*3) { |
| 617 |
if (j > jss + 1) { |
| 618 |
iae = iaend; |
| 619 |
jee = j; |
| 620 |
} else { |
| 621 |
|
| 622 |
jee = Math.min(j+1, jee); |
| 623 |
iee = i; |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
return; |
| 628 |
} |
| 629 |
} |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
private void Routine_L21() { |
| 640 |
while (true) { |
| 641 |
--gi; |
| 642 |
if (gi < iss) |
| 643 |
return; |
| 644 |
|
| 645 |
idir = 1; |
| 646 |
if (funcArray[gj -1][gi -1] <= cont) { |
| 647 |
|
| 648 |
if (iae != 0) { |
| 649 |
int ij = gi*1000 + gj + 1000; |
| 650 |
int ntmp3 = iae; |
| 651 |
for (int iia = 1; iia <= ntmp3; ++iia) { |
| 652 |
if (pathbufia[iia - 1] == ij) { |
| 653 |
pathbufia[iia - 1] = 0; |
| 654 |
break; |
| 655 |
} |
| 656 |
} |
| 657 |
} |
| 658 |
doInterpolation(); |
| 659 |
return; |
| 660 |
} |
| 661 |
|
| 662 |
fij = funcArray[gj -1][gi -1]; |
| 663 |
|
| 664 |
if (Routine_L31()) return; |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
private boolean Routine_L31() { |
| 673 |
--gj; |
| 674 |
if (gj < jss) |
| 675 |
return true; |
| 676 |
|
| 677 |
idir = 2; |
| 678 |
if (funcArray[gj -1][gi -1] <= cont) { |
| 679 |
doInterpolation(); |
| 680 |
return true; |
| 681 |
} |
| 682 |
|
| 683 |
fij = funcArray[gj -1][gi -1]; |
| 684 |
|
| 685 |
return (Routine_L41()); |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
private boolean Routine_L41() { |
| 693 |
++gi; |
| 694 |
if (gi > iee) |
| 695 |
return true; |
| 696 |
|
| 697 |
idir = 3; |
| 698 |
if (funcArray[gj -1][gi -1] <= cont) { |
| 699 |
doInterpolation(); |
| 700 |
return true; |
| 701 |
} |
| 702 |
|
| 703 |
fij = funcArray[gj -1][gi -1]; |
| 704 |
|
| 705 |
return (Routine_L51()); |
| 706 |
} |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
private boolean Routine_L51() { |
| 713 |
++gj; |
| 714 |
idir = 4; |
| 715 |
if (gj > jee) |
| 716 |
return true; |
| 717 |
|
| 718 |
if (funcArray[gj -1][gi -1] <= cont) { |
| 719 |
doInterpolation(); |
| 720 |
return true; |
| 721 |
} |
| 722 |
|
| 723 |
fij = funcArray[gj -1][gi -1]; |
| 724 |
|
| 725 |
return false; |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
private void doInterpolation() { |
| 735 |
|
| 736 |
|
| 737 |
double func = funcArray[gj -1][gi -1]; |
| 738 |
double xyf = (cont - func)/(fij - func); |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
if (xyf == 0) |
| 748 |
++ignext; |
| 749 |
|
| 750 |
double wxx=0, wyy=0; |
| 751 |
double xVal=0, yVal=0; |
| 752 |
if (xArray != null) { |
| 753 |
|
| 754 |
xVal = xArray[gj -1][gi -1]; |
| 755 |
yVal = yArray[gj -1][gi -1]; |
| 756 |
switch (idir) { |
| 757 |
case 1: |
| 758 |
wxx = xVal + xyf*(xArray[gj -1][gi + 1 -1] - xVal); |
| 759 |
wyy = yVal + xyf*(yArray[gj -1][gi + 1 -1] - yVal); |
| 760 |
break; |
| 761 |
|
| 762 |
case 2: |
| 763 |
wxx = xVal + xyf*(xArray[gj + 1 -1][gi -1] - xVal); |
| 764 |
wyy = yVal + xyf*(yArray[gj + 1 -1][gi -1] - yVal); |
| 765 |
break; |
| 766 |
|
| 767 |
case 3: |
| 768 |
wxx = xVal + xyf*(xArray[gj -1][gi - 1 -1] - xVal); |
| 769 |
wyy = yVal + xyf*(yArray[gj -1][gi - 1 -1] - yVal); |
| 770 |
break; |
| 771 |
|
| 772 |
case 4: |
| 773 |
wxx = xVal + xyf*(xArray[gj - 1 -1][gi -1] - xVal); |
| 774 |
wyy = yVal + xyf*(yArray[gj - 1 -1][gi -1] - yVal); |
| 775 |
break; |
| 776 |
} |
| 777 |
|
| 778 |
} else { |
| 779 |
|
| 780 |
xVal = xArr1D[gi -1]; |
| 781 |
yVal = yArr1D[gj -1]; |
| 782 |
switch (idir) { |
| 783 |
case 1: |
| 784 |
wxx = xVal + xyf*(xArr1D[gi + 1 -1] - xVal); |
| 785 |
wyy = yVal; |
| 786 |
break; |
| 787 |
|
| 788 |
case 2: |
| 789 |
wxx = xVal; |
| 790 |
wyy = yVal + xyf*(yArr1D[gj + 1 -1] - yVal); |
| 791 |
break; |
| 792 |
|
| 793 |
case 3: |
| 794 |
wxx = xVal + xyf*(xArr1D[gi - 1 -1] - xVal); |
| 795 |
wyy = yVal; |
| 796 |
break; |
| 797 |
|
| 798 |
case 4: |
| 799 |
wxx = xVal; |
| 800 |
wyy = yVal + xyf*(yArr1D[gj - 1 -1] - yVal); |
| 801 |
break; |
| 802 |
} |
| 803 |
} |
| 804 |
|
| 805 |
if (DEBUG) { |
| 806 |
System.out.println("i, j = " + gi + "," + gj); |
| 807 |
System.out.println("cont = " + (float)cont + ", fij = " + (float)fij + |
| 808 |
", func = " + (float)func + ", xyf = " + (float)xyf); |
| 809 |
System.out.println("xVal = " + (float)xVal + ", yVal = " + (float)yVal); |
| 810 |
System.out.println("wxx = " + (float)wxx + ", wyy = " + (float)wyy); |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
if (lnstrt == 1) { |
| 815 |
|
| 816 |
|
| 817 |
np = 1; |
| 818 |
pathbufxt[np -1] = wxx; |
| 819 |
pathbufyt[np -1] = wyy; |
| 820 |
|
| 821 |
|
| 822 |
wx = wxx; |
| 823 |
wy = wyy; |
| 824 |
|
| 825 |
|
| 826 |
lnstrt = 0; |
| 827 |
|
| 828 |
} else { |
| 829 |
|
| 830 |
boolean skipFlg = false; |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
if (ignext == 2) { |
| 835 |
if (wxx == pathbufxt[np -1] && wyy == pathbufyt[np -1]) { |
| 836 |
ignext = 0; |
| 837 |
skipFlg = true; |
| 838 |
|
| 839 |
} else |
| 840 |
ignext = 1; |
| 841 |
} |
| 842 |
|
| 843 |
if (!skipFlg) { |
| 844 |
|
| 845 |
|
| 846 |
++np; |
| 847 |
pathbufxt[np -1] = wxx; |
| 848 |
pathbufyt[np -1] = wyy; |
| 849 |
|
| 850 |
|
| 851 |
if (np == kBufSize) { |
| 852 |
accumContour(np, icont, pathbufxt, pathbufyt, cAttr[icont]); |
| 853 |
|
| 854 |
|
| 855 |
pathbufxt[0] = pathbufxt[np -1]; |
| 856 |
pathbufyt[0] = pathbufyt[np -1]; |
| 857 |
np =1; |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
if (wxx == wx && wyy == wy) |
| 862 |
return; |
| 863 |
} |
| 864 |
|
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
switch(idir) { |
| 869 |
case 1: |
| 870 |
++gi; |
| 871 |
if (!Routine_L51()) |
| 872 |
Routine_L21(); |
| 873 |
break; |
| 874 |
|
| 875 |
case 2: |
| 876 |
++gj; |
| 877 |
Routine_L21(); |
| 878 |
break; |
| 879 |
|
| 880 |
case 3: |
| 881 |
--gi; |
| 882 |
if (!Routine_L31()) |
| 883 |
Routine_L21(); |
| 884 |
break; |
| 885 |
|
| 886 |
case 4: |
| 887 |
--gj; |
| 888 |
if (!Routine_L41()) |
| 889 |
Routine_L21(); |
| 890 |
break; |
| 891 |
} |
| 892 |
|
| 893 |
return; |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
private void accumContour(int np, int icont, double[] x, double[] y, ContourAttrib cAttr) { |
| 906 |
|
| 907 |
|
| 908 |
if (np < kMinNumPoints) return; |
| 909 |
|
| 910 |
|
| 911 |
double[] xArr = new double[np]; |
| 912 |
double[] yArr = new double[np]; |
| 913 |
System.arraycopy(x, 0, xArr, 0, np); |
| 914 |
System.arraycopy(y, 0, yArr, 0, np); |
| 915 |
|
| 916 |
|
| 917 |
ContourPath path = new ContourPath(cAttr, icont, xArr, yArr); |
| 918 |
pathList.add(path); |
| 919 |
|
| 920 |
} |
| 921 |
|
| 922 |
} |
| 923 |
|