| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package footleg.cavesurvey.data.model; |
| 20 |
|
| 21 |
import java.util.ArrayList; |
| 22 |
import java.util.Date; |
| 23 |
import java.util.List; |
| 24 |
import java.util.ListIterator; |
| 25 |
|
| 26 |
import footleg.cavesurvey.converter.CaveConverter.BearingUnit; |
| 27 |
import footleg.cavesurvey.converter.CaveConverter.GradientUnit; |
| 28 |
import footleg.cavesurvey.converter.CaveConverter.LengthUnit; |
| 29 |
import footleg.cavesurvey.converter.Logger; |
| 30 |
import footleg.cavesurvey.tools.UtilityFunctions; |
| 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 |
|
| 57 |
|
| 58 |
public class SurveySeries { |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public class ToStnLRUD { |
| 70 |
private SurveyStation fromStn; |
| 71 |
|
| 72 |
|
| 73 |
private double left = 0.0; |
| 74 |
private double right = 0.0; |
| 75 |
private double up = 0.0; |
| 76 |
private double down = 0.0; |
| 77 |
|
| 78 |
|
| 79 |
public SurveyStation getFromStn() { |
| 80 |
return fromStn; |
| 81 |
} |
| 82 |
public void setFromStn(SurveyStation fromStn) { |
| 83 |
this.fromStn = fromStn; |
| 84 |
} |
| 85 |
public double getLeft() { |
| 86 |
return left; |
| 87 |
} |
| 88 |
public void setLeft(double left) { |
| 89 |
this.left = left; |
| 90 |
} |
| 91 |
public double getRight() { |
| 92 |
return right; |
| 93 |
} |
| 94 |
public void setRight(double right) { |
| 95 |
this.right = right; |
| 96 |
} |
| 97 |
public double getUp() { |
| 98 |
return up; |
| 99 |
} |
| 100 |
public void setUp(double up) { |
| 101 |
this.up = up; |
| 102 |
} |
| 103 |
public double getDown() { |
| 104 |
return down; |
| 105 |
} |
| 106 |
public void setDown(double down) { |
| 107 |
this.down = down; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
private String seriesName; |
| 112 |
private List<SurveyLeg> legs; |
| 113 |
private List<ToStnLRUD> toStnLRUDs; |
| 114 |
private List<SeriesLink> links; |
| 115 |
private List<SurveySeries> innerSeries; |
| 116 |
private int stnRenumberSequence; |
| 117 |
private List<String> stnRenameCache; |
| 118 |
private double declination = 0; |
| 119 |
private double tapeCalibration = 0; |
| 120 |
private double compassCalibration = 0; |
| 121 |
private double clinoCalibration = 0; |
| 122 |
private double clinoCalScaleFactor = 1; |
| 123 |
private Date surveyDate; |
| 124 |
private String comment = ""; |
| 125 |
private static double LRUD_SPECIAL_FLAG = -999; |
| 126 |
private LengthUnit lengthUnit = LengthUnit.Metres; |
| 127 |
private LengthUnit depthUnit = LengthUnit.Metres; |
| 128 |
private BearingUnit bearingUnit = BearingUnit.Degrees; |
| 129 |
private GradientUnit gradientUnit = GradientUnit.Degrees; |
| 130 |
private List<String> dataOrder; |
| 131 |
private List<String> dataOrder2; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public SurveySeries( String name ) { |
| 138 |
super(); |
| 139 |
init(); |
| 140 |
this.seriesName = name; |
| 141 |
} |
| 142 |
|
| 143 |
private void init() { |
| 144 |
legs = new ArrayList<SurveyLeg>(); |
| 145 |
toStnLRUDs = new ArrayList<ToStnLRUD>(); |
| 146 |
links = new ArrayList<SeriesLink>(); |
| 147 |
innerSeries = new ArrayList<SurveySeries>(); |
| 148 |
stnRenameCache = new ArrayList<String>(); |
| 149 |
stnRenumberSequence = 0; |
| 150 |
} |
| 151 |
|
| 152 |
public LengthUnit getLengthUnit() { |
| 153 |
return lengthUnit; |
| 154 |
} |
| 155 |
|
| 156 |
public void setLengthUnit(LengthUnit lengthUnit) { |
| 157 |
this.lengthUnit = lengthUnit; |
| 158 |
} |
| 159 |
|
| 160 |
public LengthUnit getDepthUnit() { |
| 161 |
return depthUnit; |
| 162 |
} |
| 163 |
|
| 164 |
public void setDepthUnit(LengthUnit depthUnit) { |
| 165 |
this.depthUnit = depthUnit; |
| 166 |
} |
| 167 |
|
| 168 |
public BearingUnit getBearingUnit() { |
| 169 |
return bearingUnit; |
| 170 |
} |
| 171 |
|
| 172 |
public void setBearingUnit(BearingUnit bearingUnit) { |
| 173 |
this.bearingUnit = bearingUnit; |
| 174 |
} |
| 175 |
|
| 176 |
public GradientUnit getGradientUnit() { |
| 177 |
return gradientUnit; |
| 178 |
} |
| 179 |
|
| 180 |
public void setGradientUnit(GradientUnit gradientUnit) { |
| 181 |
this.gradientUnit = gradientUnit; |
| 182 |
} |
| 183 |
|
| 184 |
public void addLeg(SurveyLeg leg) { |
| 185 |
|
| 186 |
this.legs.add(leg.clone()); |
| 187 |
} |
| 188 |
|
| 189 |
public void addLeg(SurveyLeg leg, int position) { |
| 190 |
|
| 191 |
this.legs.add( position, leg.clone() ); |
| 192 |
} |
| 193 |
|
| 194 |
public int legCount() { |
| 195 |
return legs.size(); |
| 196 |
} |
| 197 |
|
| 198 |
public List<ToStnLRUD> getToStnLRUDs() { |
| 199 |
return toStnLRUDs; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public void setStationIdFromName( SurveyStation stn ) { |
| 221 |
int stnId = stnNameToNumber( stn.getName() ); |
| 222 |
stn.setId( stnId ); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
private int stnNameToNumber( String stnName ) { |
| 230 |
int stn; |
| 231 |
try { |
| 232 |
stn = Integer.parseInt( stnName ); |
| 233 |
} |
| 234 |
catch (NumberFormatException nfe) { |
| 235 |
|
| 236 |
stn = this.getNumberToRepresentStnName( stnName ); |
| 237 |
} |
| 238 |
return stn; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
public int getNumberToRepresentStnName(String stnName) { |
| 255 |
int mappedStnNum = 0; |
| 256 |
|
| 257 |
|
| 258 |
ListIterator<String> stnCacheIterator = stnRenameCache.listIterator(); |
| 259 |
int stnIdx = 0; |
| 260 |
while ( ( mappedStnNum == 0 ) && ( stnCacheIterator.hasNext() ) ) { |
| 261 |
String cachedName = stnCacheIterator.next(); |
| 262 |
stnIdx--; |
| 263 |
if ( stnName.compareToIgnoreCase(cachedName) == 0 ) { |
| 264 |
|
| 265 |
mappedStnNum = stnIdx; |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
if ( mappedStnNum == 0 ) { |
| 270 |
|
| 271 |
stnRenumberSequence--; |
| 272 |
mappedStnNum = stnRenumberSequence; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
stnRenameCache.add(stnName); |
| 281 |
} |
| 282 |
|
| 283 |
return mappedStnNum; |
| 284 |
} |
| 285 |
|
| 286 |
public String getMappedStnName(int stn) { |
| 287 |
|
| 288 |
|
| 289 |
if ( stn < 0 ) { |
| 290 |
return stnRenameCache.get( Math.abs(stn) - 1 ); |
| 291 |
} |
| 292 |
else { |
| 293 |
return "" + stn; |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
public SurveyLeg getLegCorrected(int index) { |
| 299 |
SurveyLeg originalLeg = legs.get(index); |
| 300 |
SurveyLeg correctedLeg = originalLeg.clone(); |
| 301 |
|
| 302 |
|
| 303 |
correctedLeg.setLength( originalLeg.getLength(LengthUnit.Metres) - tapeCalibration, LengthUnit.Metres ); |
| 304 |
double compass = originalLeg.getCompass(BearingUnit.Degrees); |
| 305 |
if ( compass >= 0 && compass <= 360 ) { |
| 306 |
|
| 307 |
compass -= (compassCalibration + declination); |
| 308 |
} |
| 309 |
correctedLeg.setCompass( compass, BearingUnit.Degrees ); |
| 310 |
double clino = originalLeg.getClino(GradientUnit.Degrees); |
| 311 |
if ( clino >= -90 && clino <= 180 ) { |
| 312 |
|
| 313 |
clino = (clino - clinoCalibration) * clinoCalScaleFactor; |
| 314 |
} |
| 315 |
correctedLeg.setClino( clino, GradientUnit.Degrees ); |
| 316 |
|
| 317 |
|
| 318 |
return correctedLeg; |
| 319 |
} |
| 320 |
|
| 321 |
public SurveyLeg getLegRaw(int index) { |
| 322 |
return legs.get(index); |
| 323 |
} |
| 324 |
|
| 325 |
public void addSeries(SurveySeries series) { |
| 326 |
this.innerSeries.add(series); |
| 327 |
} |
| 328 |
|
| 329 |
public int innerSeriesCount() { |
| 330 |
return innerSeries.size(); |
| 331 |
} |
| 332 |
|
| 333 |
public SurveySeries getInnerSeries(int index) { |
| 334 |
return innerSeries.get(index); |
| 335 |
} |
| 336 |
|
| 337 |
public List<SurveySeries> getInnerSeriesList() { |
| 338 |
return innerSeries; |
| 339 |
} |
| 340 |
|
| 341 |
public SurveySeries findInnerSeriesByName(String name) { |
| 342 |
SurveySeries match = null; |
| 343 |
|
| 344 |
ListIterator<SurveySeries> innerIterator = innerSeries.listIterator(); |
| 345 |
while ( innerIterator.hasNext() ) { |
| 346 |
SurveySeries innerSeries = innerIterator.next(); |
| 347 |
if ( innerSeries.getSeriesName().equalsIgnoreCase( name ) ) { |
| 348 |
|
| 349 |
match = innerSeries; |
| 350 |
break; |
| 351 |
} |
| 352 |
} |
| 353 |
return match; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
public int getIndexOfChild(Object child) { |
| 362 |
int matchIndex = -1; |
| 363 |
|
| 364 |
ListIterator<SurveySeries> innerIterator = innerSeries.listIterator(); |
| 365 |
int idx = -1; |
| 366 |
while ( innerIterator.hasNext() ) { |
| 367 |
SurveySeries innerSeries = innerIterator.next(); |
| 368 |
idx++; |
| 369 |
if ( innerSeries.equals( child ) ) { |
| 370 |
|
| 371 |
matchIndex = idx; |
| 372 |
break; |
| 373 |
} |
| 374 |
} |
| 375 |
return matchIndex; |
| 376 |
} |
| 377 |
|
| 378 |
public void addLink(String series1Path, SurveyStation stn1, String series2Path, SurveyStation stn2 ) { |
| 379 |
|
| 380 |
SeriesLink link = new SeriesLink(series1Path, stn1, series2Path, stn2 ); |
| 381 |
links.add(link); |
| 382 |
} |
| 383 |
|
| 384 |
public List<SeriesLink> getLinks() { |
| 385 |
return links; |
| 386 |
} |
| 387 |
|
| 388 |
public String getSeriesName() { |
| 389 |
return seriesName; |
| 390 |
} |
| 391 |
|
| 392 |
public void setSeriesName(String seriesName) { |
| 393 |
this.seriesName = seriesName; |
| 394 |
} |
| 395 |
|
| 396 |
public List<String> getDataOrder() { |
| 397 |
|
| 398 |
|
| 399 |
List<String> tmpList = new ArrayList<String>(); |
| 400 |
if (dataOrder != null ) { |
| 401 |
tmpList.addAll(dataOrder); |
| 402 |
} |
| 403 |
|
| 404 |
return tmpList; |
| 405 |
} |
| 406 |
|
| 407 |
public List<String> getDataOrder2() { |
| 408 |
|
| 409 |
|
| 410 |
List<String> tmpList = new ArrayList<String>(); |
| 411 |
if (dataOrder2 != null ) { |
| 412 |
tmpList.addAll(dataOrder2); |
| 413 |
} |
| 414 |
|
| 415 |
return tmpList; |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
public boolean hasDataOrder() { |
| 425 |
boolean hasIt = false; |
| 426 |
if ( dataOrder != null ) { |
| 427 |
hasIt = (dataOrder.size() > 0); |
| 428 |
} |
| 429 |
return hasIt; |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
public void setDataOrder(List<String> dataOrder) { |
| 439 |
|
| 440 |
List<String> tmpList = new ArrayList<String>(); |
| 441 |
tmpList.addAll(dataOrder); |
| 442 |
|
| 443 |
this.dataOrder = tmpList; |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
public void setDataOrder2(List<String> dataOrder) { |
| 452 |
|
| 453 |
List<String> tmpList = new ArrayList<String>(); |
| 454 |
tmpList.addAll(dataOrder); |
| 455 |
|
| 456 |
this.dataOrder2 = tmpList; |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
public String toString() { |
| 464 |
String text = getSeriesName(); |
| 465 |
if ( ( text == null ) || ( text.equals("") ) ) { |
| 466 |
text = "Survey Series"; |
| 467 |
} |
| 468 |
return text; |
| 469 |
} |
| 470 |
|
| 471 |
public double getTapeCalibration(LengthUnit units) { |
| 472 |
return UtilityFunctions.lengthFromMetres( tapeCalibration, units ); |
| 473 |
} |
| 474 |
|
| 475 |
public void setTapeCalibration(double tapeCalibration, LengthUnit units) { |
| 476 |
this.tapeCalibration = UtilityFunctions.lengthToMetres(tapeCalibration, units); |
| 477 |
} |
| 478 |
|
| 479 |
public double getDeclination() { |
| 480 |
return declination; |
| 481 |
} |
| 482 |
|
| 483 |
public void setDeclination(double declination) { |
| 484 |
this.declination = declination; |
| 485 |
} |
| 486 |
|
| 487 |
public double getCompassCalibration(BearingUnit units) { |
| 488 |
return UtilityFunctions.bearingFromDegrees(compassCalibration, units) ; |
| 489 |
} |
| 490 |
|
| 491 |
public void setCompassCalibration(double compassCalibration, BearingUnit units) { |
| 492 |
this.compassCalibration = UtilityFunctions.bearingToDegrees(compassCalibration, units) ; |
| 493 |
} |
| 494 |
|
| 495 |
public double getClinoCalibration(GradientUnit units) { |
| 496 |
return UtilityFunctions.gradientFromDegrees(clinoCalibration, units) ; |
| 497 |
} |
| 498 |
|
| 499 |
public double getClinoScaleFactor() { |
| 500 |
return clinoCalScaleFactor; |
| 501 |
} |
| 502 |
|
| 503 |
public void setClinoCalibration(double clinoCalibration, GradientUnit units) { |
| 504 |
this.clinoCalibration = UtilityFunctions.gradientToDegrees(clinoCalibration, units); |
| 505 |
this.clinoCalScaleFactor = 1; |
| 506 |
} |
| 507 |
|
| 508 |
public void setClinoCalibration(double clinoCalibration, GradientUnit units, double clinoCalScaleFactor) { |
| 509 |
this.clinoCalibration = UtilityFunctions.gradientToDegrees(clinoCalibration, units);; |
| 510 |
this.clinoCalScaleFactor = clinoCalScaleFactor; |
| 511 |
} |
| 512 |
|
| 513 |
public Date getSurveyDate() { |
| 514 |
return surveyDate; |
| 515 |
} |
| 516 |
|
| 517 |
public void setSurveyDate(Date surveyDate) { |
| 518 |
this.surveyDate = surveyDate; |
| 519 |
} |
| 520 |
|
| 521 |
public String getComment() { |
| 522 |
return comment; |
| 523 |
} |
| 524 |
|
| 525 |
public void setComment(String comment) { |
| 526 |
this.comment = comment; |
| 527 |
} |
| 528 |
|
| 529 |
public void setCalibrationFromAnotherSeries(SurveySeries series) { |
| 530 |
setDeclination( series.getDeclination() ); |
| 531 |
setTapeCalibration( series.getTapeCalibration( LengthUnit.Metres ), LengthUnit.Metres ); |
| 532 |
setCompassCalibration( series.getCompassCalibration( BearingUnit.Degrees ), BearingUnit.Degrees ); |
| 533 |
setClinoCalibration( series.getClinoCalibration( GradientUnit.Degrees ), GradientUnit.Degrees, series.getClinoScaleFactor() ); |
| 534 |
} |
| 535 |
|
| 536 |
public SurveyLeg removeLeg(int index){ |
| 537 |
return legs.remove(index); |
| 538 |
} |
| 539 |
|
| 540 |
public void removeSplaysUsedForLRUD() { |
| 541 |
int i = legs.size() - 1; |
| 542 |
while ( i >= 0 ) { |
| 543 |
SurveyLeg leg = legs.get(i); |
| 544 |
if ( leg.isSplay() && leg.getDown( LengthUnit.Metres ) == LRUD_SPECIAL_FLAG ) { |
| 545 |
|
| 546 |
removeLeg(i); |
| 547 |
} |
| 548 |
else { |
| 549 |
i--; |
| 550 |
} |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
public void generateLRUDFromSplays( Logger logger ) { |
| 571 |
List<SurveyLeg> caveLegs = new ArrayList<SurveyLeg>(); |
| 572 |
List<List<SurveyLeg>> splayLegGroups = new ArrayList<List<SurveyLeg>>(); |
| 573 |
List<List<SurveyLeg>> previousLegGroups = new ArrayList<List<SurveyLeg>>(); |
| 574 |
|
| 575 |
|
| 576 |
ListIterator<SurveyLeg> legsIterator = legs.listIterator(); |
| 577 |
while ( legsIterator.hasNext() ) { |
| 578 |
SurveyLeg leg = legsIterator.next(); |
| 579 |
|
| 580 |
|
| 581 |
if ( leg.isSurface() == false ) { |
| 582 |
if ( leg.isSplay() ) { |
| 583 |
|
| 584 |
String stnName = leg.getFromStn().getName(); |
| 585 |
|
| 586 |
int groupIdx = -1; |
| 587 |
for ( int i = 0; groupIdx < 0 && i < splayLegGroups.size(); i++ ) { |
| 588 |
if ( splayLegGroups.get(i).get(0).getFromStn().getName().compareTo(stnName) == 0 ) { |
| 589 |
|
| 590 |
groupIdx = i; |
| 591 |
} |
| 592 |
} |
| 593 |
if ( groupIdx >= 0 ) { |
| 594 |
|
| 595 |
splayLegGroups.get(groupIdx).add(leg); |
| 596 |
} |
| 597 |
else { |
| 598 |
|
| 599 |
List<SurveyLeg> splays = new ArrayList<SurveyLeg>(); |
| 600 |
splays.add(leg); |
| 601 |
splayLegGroups.add(splays); |
| 602 |
} |
| 603 |
} |
| 604 |
else { |
| 605 |
|
| 606 |
caveLegs.add(leg); |
| 607 |
} |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
for ( int caveLegIdx = 0; caveLegIdx < caveLegs.size(); caveLegIdx++ ) { |
| 613 |
SurveyLeg leg = caveLegs.get(caveLegIdx); |
| 614 |
String legStartStn = leg.getFromStn().getName(); |
| 615 |
|
| 616 |
|
| 617 |
List<SurveyLeg> legGrp = new ArrayList<SurveyLeg>(); |
| 618 |
|
| 619 |
|
| 620 |
for ( int otherLegIdx = 0; otherLegIdx < caveLegs.size(); otherLegIdx++ ) { |
| 621 |
|
| 622 |
if ( otherLegIdx != caveLegIdx ) { |
| 623 |
SurveyLeg chkLeg = caveLegs.get(otherLegIdx); |
| 624 |
if ( legStartStn.compareToIgnoreCase( chkLeg.getToStn().getName() ) == 0 ) { |
| 625 |
|
| 626 |
legGrp.add(chkLeg); |
| 627 |
} |
| 628 |
else if ( legStartStn.compareToIgnoreCase( chkLeg.getFromStn().getName() ) == 0 ) { |
| 629 |
|
| 630 |
SurveyLeg revLeg = chkLeg.clone(); |
| 631 |
revLeg.reverseDirection(); |
| 632 |
legGrp.add( revLeg ); |
| 633 |
} |
| 634 |
} |
| 635 |
} |
| 636 |
|
| 637 |
previousLegGroups.add( legGrp ); |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
ListIterator<List<SurveyLeg>> spGroupsIter = splayLegGroups.listIterator(); |
| 642 |
List<String> stnsUsed = new ArrayList<String>(); |
| 643 |
while ( spGroupsIter.hasNext() ) { |
| 644 |
List<SurveyLeg> splaysGroup = spGroupsIter.next(); |
| 645 |
String stnName = splaysGroup.get(0).getFromStn().getName(); |
| 646 |
|
| 647 |
ListIterator<SurveyLeg> legsIter = caveLegs.listIterator(); |
| 648 |
int caveLegIdx = -1; |
| 649 |
while ( legsIter.hasNext() ) { |
| 650 |
SurveyLeg leg = legsIter.next(); |
| 651 |
caveLegIdx++; |
| 652 |
if ( leg.getFromStn().getName().compareTo(stnName) == 0 ) { |
| 653 |
|
| 654 |
generateLRUDForLeg( leg, splaysGroup, previousLegGroups.get(caveLegIdx), logger ); |
| 655 |
|
| 656 |
stnsUsed.add(stnName); |
| 657 |
|
| 658 |
legsIter.remove(); |
| 659 |
|
| 660 |
previousLegGroups.remove(caveLegIdx); |
| 661 |
caveLegIdx--; |
| 662 |
} |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
ListIterator<List<SurveyLeg>> spGroupsIter2 = splayLegGroups.listIterator(); |
| 669 |
List<List<SurveyLeg>> unusedSplayGroups = new ArrayList<List<SurveyLeg>>(); |
| 670 |
while ( spGroupsIter2.hasNext() ) { |
| 671 |
List<SurveyLeg> splaysGroup = spGroupsIter2.next(); |
| 672 |
String stnName = splaysGroup.get(0).getFromStn().getName(); |
| 673 |
|
| 674 |
|
| 675 |
boolean foundMatch = false; |
| 676 |
ListIterator<String> stnsUsedIter = stnsUsed.listIterator(); |
| 677 |
while ( stnsUsedIter.hasNext() ) { |
| 678 |
String grpName = stnsUsedIter.next(); |
| 679 |
if ( stnName.compareTo( grpName ) == 0 ) { |
| 680 |
|
| 681 |
foundMatch = true; |
| 682 |
break; |
| 683 |
} |
| 684 |
} |
| 685 |
|
| 686 |
if ( foundMatch == false ) { |
| 687 |
|
| 688 |
unusedSplayGroups.add( splaysGroup ); |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
ListIterator<List<SurveyLeg>> spGroupsIter3 = unusedSplayGroups.listIterator(); |
| 695 |
while ( spGroupsIter3.hasNext() ) { |
| 696 |
List<SurveyLeg> splaysGroup = spGroupsIter3.next(); |
| 697 |
String stnName = splaysGroup.get(0).getFromStn().getName(); |
| 698 |
|
| 699 |
|
| 700 |
for ( int legsIdx = 0; legsIdx < legs.size(); legsIdx++ ) { |
| 701 |
SurveyLeg leg = legs.get( legsIdx ); |
| 702 |
if ( ( leg.isSplay() == false ) |
| 703 |
&& ( leg.getToStn() != null ) |
| 704 |
&& ( leg.getToStn().getName().compareTo(stnName) == 0 ) ) { |
| 705 |
|
| 706 |
SurveyLeg tempLrudLeg = new SurveyLeg(); |
| 707 |
tempLrudLeg.setFromStn( leg.getToStn() ); |
| 708 |
tempLrudLeg.setLength( -1, LengthUnit.Metres ); |
| 709 |
tempLrudLeg.setCompass( leg.getCompass(BearingUnit.Degrees), BearingUnit.Degrees ); |
| 710 |
tempLrudLeg.setClino( leg.getClino(GradientUnit.Degrees), GradientUnit.Degrees ); |
| 711 |
|
| 712 |
|
| 713 |
List<SurveyLeg> otherLegs = new ArrayList<SurveyLeg>(); |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
for ( int legsIdx2 = legsIdx + 1; legsIdx2 < legs.size(); legsIdx2++ ) { |
| 723 |
SurveyLeg chkLeg = legs.get( legsIdx2 ); |
| 724 |
if ( ( chkLeg.isSplay() == false ) |
| 725 |
&& ( chkLeg.getToStn() != null ) |
| 726 |
&& ( chkLeg.getToStn().getName().compareTo(stnName) == 0 ) ) { |
| 727 |
|
| 728 |
|
| 729 |
SurveyLeg revLeg = chkLeg.clone(); |
| 730 |
revLeg.reverseDirection(); |
| 731 |
otherLegs.add(revLeg); |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
generateLRUDForLeg( tempLrudLeg, splaysGroup, otherLegs, logger ); |
| 736 |
|
| 737 |
ToStnLRUD newLrud = new ToStnLRUD(); |
| 738 |
newLrud.setFromStn( tempLrudLeg.getFromStn() ); |
| 739 |
newLrud.setLeft( tempLrudLeg.getLeft(LengthUnit.Metres) ); |
| 740 |
newLrud.setRight( tempLrudLeg.getRight(LengthUnit.Metres) ); |
| 741 |
newLrud.setUp( tempLrudLeg.getUp(LengthUnit.Metres) ); |
| 742 |
newLrud.setDown( tempLrudLeg.getDown(LengthUnit.Metres) ); |
| 743 |
|
| 744 |
toStnLRUDs.add(newLrud); |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
legsIdx = legs.size(); |
| 749 |
} |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
private void generateLRUDForLeg( SurveyLeg masterLeg, List<SurveyLeg> splayShots, List<SurveyLeg> otherLegs, Logger logger ) { |
| 763 |
int bearingTolerance = 3; |
| 764 |
List<SurveyLeg> leftShots = new ArrayList<SurveyLeg>(); |
| 765 |
List<SurveyLeg> rightShots = new ArrayList<SurveyLeg>(); |
| 766 |
List<SurveyLeg> upShots = new ArrayList<SurveyLeg>(); |
| 767 |
List<SurveyLeg> downShots = new ArrayList<SurveyLeg>(); |
| 768 |
|
| 769 |
|
| 770 |
double bestPrevBearing = 360.0; |
| 771 |
int bestPrevLegIdx = -1; |
| 772 |
for ( int i = 0; i < otherLegs.size(); i++ ) { |
| 773 |
|
| 774 |
double testBearing = UtilityFunctions.bearingDifferenceDegrees( otherLegs.get(i).getCompass(BearingUnit.Degrees), masterLeg.getCompass(BearingUnit.Degrees) ); |
| 775 |
if ( testBearing < bestPrevBearing ) { |
| 776 |
|
| 777 |
bestPrevBearing = testBearing; |
| 778 |
bestPrevLegIdx = i; |
| 779 |
} |
| 780 |
} |
| 781 |
|
| 782 |
|
| 783 |
double bearing = masterLeg.getCompass(BearingUnit.Degrees); |
| 784 |
if ( bestPrevLegIdx >= 0 ) { |
| 785 |
double[] bearings = new double[2]; |
| 786 |
|
| 787 |
bearings[0] = masterLeg.getCompass(BearingUnit.Degrees); |
| 788 |
bearings[1] = otherLegs.get(bestPrevLegIdx).getCompass(BearingUnit.Degrees); |
| 789 |
|
| 790 |
bearing = UtilityFunctions.averageCompassBearings(bearings); |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
for ( int i = 0; i < splayShots.size(); i++ ) { |
| 795 |
SurveyLeg splayLeg = splayShots.get(i); |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
boolean backShot = false; |
| 801 |
for ( int olegsIdx = -1; olegsIdx < otherLegs.size(); olegsIdx++ ) { |
| 802 |
|
| 803 |
SurveyLeg testLeg = masterLeg; |
| 804 |
if (olegsIdx > -1) { |
| 805 |
|
| 806 |
testLeg = otherLegs.get(olegsIdx).clone(); |
| 807 |
testLeg.reverseDirection(); |
| 808 |
} |
| 809 |
|
| 810 |
double bearingDiff = UtilityFunctions.bearingDifferenceDegrees( testLeg.getCompass(BearingUnit.Degrees), splayLeg.getCompass(BearingUnit.Degrees) ); |
| 811 |
if ( bearingDiff < bearingTolerance ) { |
| 812 |
|
| 813 |
double clinoDiff = UtilityFunctions.bearingDifferenceDegrees( testLeg.getClino(GradientUnit.Degrees), splayLeg.getClino(GradientUnit.Degrees) ); |
| 814 |
if ( clinoDiff < bearingTolerance ) { |
| 815 |
|
| 816 |
double lengthDiff = Math.abs( testLeg.getLength( LengthUnit.Metres ) - splayLeg.getLength( LengthUnit.Metres ) ); |
| 817 |
if ( lengthDiff < 0.2 ) { |
| 818 |
|
| 819 |
backShot = true; |
| 820 |
logger.logMessage("Ignoring splay from " + getSeriesName() + "." + splayLeg.getFromStn().getName() + |
| 821 |
" with length of " + splayLeg.getLength( LengthUnit.Metres ) + " as splay too closely matching a leg and so assumed to be a back-shot."); |
| 822 |
} |
| 823 |
} |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
if ( backShot == false ) { |
| 828 |
double splayClino = splayLeg.getClino(GradientUnit.Degrees); |
| 829 |
if ( splayClino > 20 ) { |
| 830 |
|
| 831 |
upShots.add(splayLeg); |
| 832 |
} |
| 833 |
else if ( splayClino < -20 ) { |
| 834 |
|
| 835 |
downShots.add(splayLeg); |
| 836 |
} |
| 837 |
|
| 838 |
if ( ( splayClino < 70 ) && ( splayClino > -70 ) ) { |
| 839 |
|
| 840 |
|
| 841 |
double masterBearing = masterLeg.getCompass(BearingUnit.Degrees); |
| 842 |
|
| 843 |
double splayCorrected = splayLeg.getCompass(BearingUnit.Degrees) - masterBearing; |
| 844 |
if ( splayCorrected < 0 ) { |
| 845 |
splayCorrected += 360; |
| 846 |
} |
| 847 |
if ( bestPrevLegIdx >= 0 ) { |
| 848 |
|
| 849 |
double prevLegBearing = otherLegs.get(bestPrevLegIdx).getCompass(BearingUnit.Degrees); |
| 850 |
|
| 851 |
double prevLegBackBearingCorrected = UtilityFunctions.adjustBearingWithinDegreesRange( |
| 852 |
180 + prevLegBearing - masterBearing, 0, 360 ); |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
if ( splayCorrected < prevLegBackBearingCorrected ) { |
| 860 |
|
| 861 |
rightShots.add(splayLeg); |
| 862 |
} |
| 863 |
else { |
| 864 |
|
| 865 |
leftShots.add(splayLeg); |
| 866 |
} |
| 867 |
} |
| 868 |
else { |
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
if ( ( splayCorrected > bearingTolerance ) || ( splayCorrected > (360 - bearingTolerance) ) ) { |
| 873 |
if ( splayCorrected < ( 180 - bearingTolerance) ) { |
| 874 |
|
| 875 |
rightShots.add(splayLeg); |
| 876 |
} |
| 877 |
else if ( splayCorrected > ( 180 + bearingTolerance) ) { |
| 878 |
|
| 879 |
leftShots.add(splayLeg); |
| 880 |
} |
| 881 |
else { |
| 882 |
|
| 883 |
logger.logMessage("Ignoring splay from " + getSeriesName() + "." + splayLeg.getFromStn().getName() + |
| 884 |
" with bearing of " + splayLeg.getCompass(BearingUnit.Degrees) + " as bearing is < " + bearingTolerance + " degrees off back bearing of leg."); |
| 885 |
} |
| 886 |
} |
| 887 |
else { |
| 888 |
|
| 889 |
logger.logMessage("Ignoring splay from " + getSeriesName() + "." + splayLeg.getFromStn().getName() + |
| 890 |
" with bearing of " + splayLeg.getCompass(BearingUnit.Degrees) + " as bearing is < " + bearingTolerance + " degrees off bearing of leg."); |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 894 |
} |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
boolean keepAllSplays = false; |
| 900 |
if (( upShots.size() > 1 ) |
| 901 |
|| ( downShots.size() > 1 ) |
| 902 |
|| ( leftShots.size() > 1 ) |
| 903 |
|| ( rightShots.size() > 1 )) { |
| 904 |
keepAllSplays = true; |
| 905 |
} |
| 906 |
|
| 907 |
|
| 908 |
double bestValue = 0.0; |
| 909 |
int bestIdx = -1; |
| 910 |
for ( int i = 0; i < upShots.size(); i++ ) { |
| 911 |
|
| 912 |
if ( upShots.get(i).getClino(GradientUnit.Degrees) > bestValue ) { |
| 913 |
|
| 914 |
bestValue = upShots.get(i).getClino(GradientUnit.Degrees); |
| 915 |
bestIdx = i; |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
if ( bestIdx >= 0 ) { |
| 920 |
|
| 921 |
masterLeg.setUp( upShots.get(bestIdx).getVerticalLength(), LengthUnit.Metres ); |
| 922 |
|
| 923 |
if ( keepAllSplays == false ) { |
| 924 |
upShots.get(bestIdx).setDown( LRUD_SPECIAL_FLAG, LengthUnit.Metres ); |
| 925 |
} |
| 926 |
} |
| 927 |
|
| 928 |
|
| 929 |
bestValue = 0.0; |
| 930 |
bestIdx = -1; |
| 931 |
for ( int i = 0; i < downShots.size(); i++ ) { |
| 932 |
|
| 933 |
if ( downShots.get(i).getClino(GradientUnit.Degrees) < bestValue ) { |
| 934 |
|
| 935 |
bestValue = downShots.get(i).getClino(GradientUnit.Degrees); |
| 936 |
bestIdx = i; |
| 937 |
} |
| 938 |
} |
| 939 |
|
| 940 |
if ( bestIdx >= 0 ) { |
| 941 |
|
| 942 |
masterLeg.setDown( downShots.get(bestIdx).getVerticalLength(), LengthUnit.Metres ); |
| 943 |
|
| 944 |
if ( keepAllSplays == false ) { |
| 945 |
downShots.get(bestIdx).setDown( LRUD_SPECIAL_FLAG, LengthUnit.Metres ); |
| 946 |
} |
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
bestIdx = findBestSplayForHorizontalDimension(leftShots, bearing, true); |
| 951 |
|
| 952 |
|
| 953 |
if ( bestIdx >= 0 ) { |
| 954 |
|
| 955 |
double horizontalLength = leftShots.get(bestIdx).getHorizontalLength(); |
| 956 |
double leftOrthoganal = bearing - 90; |
| 957 |
if ( leftOrthoganal < 0 ) { |
| 958 |
leftOrthoganal += 360; |
| 959 |
} |
| 960 |
masterLeg.setLeft( extentAlongBearing( leftOrthoganal, |
| 961 |
horizontalLength, leftShots.get(bestIdx).getCompass(BearingUnit.Degrees) ), LengthUnit.Metres ); |
| 962 |
|
| 963 |
if ( keepAllSplays == false ) { |
| 964 |
leftShots.get(bestIdx).setDown( LRUD_SPECIAL_FLAG, LengthUnit.Metres ); |
| 965 |
} |
| 966 |
} |
| 967 |
|
| 968 |
|
| 969 |
bestIdx = findBestSplayForHorizontalDimension(rightShots, bearing, false); |
| 970 |
|
| 971 |
|
| 972 |
if ( bestIdx >= 0 ) { |
| 973 |
|
| 974 |
double horizontalLength = rightShots.get(bestIdx).getHorizontalLength(); |
| 975 |
double rightOrthoganal = bearing + 90; |
| 976 |
if ( rightOrthoganal >= 360 ) { |
| 977 |
rightOrthoganal -= 360; |
| 978 |
} |
| 979 |
masterLeg.setRight( extentAlongBearing( rightOrthoganal, |
| 980 |
horizontalLength, rightShots.get(bestIdx).getCompass(BearingUnit.Degrees) ), LengthUnit.Metres ); |
| 981 |
|
| 982 |
if ( keepAllSplays == false ) { |
| 983 |
rightShots.get(bestIdx).setDown( LRUD_SPECIAL_FLAG, LengthUnit.Metres ); |
| 984 |
} |
| 985 |
} |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
private int findBestSplayForHorizontalDimension(List<SurveyLeg> splays, double forwardBearing, boolean left) { |
| 998 |
|
| 999 |
double bestValue = 0.0; |
| 1000 |
int bestIdx = -1; |
| 1001 |
for ( int i = 0; i < splays.size(); i++ ) { |
| 1002 |
|
| 1003 |
double shotCorrected = splays.get(i).getCompass(BearingUnit.Degrees) - forwardBearing; |
| 1004 |
if ( shotCorrected < 0 ) { |
| 1005 |
shotCorrected += 360; |
| 1006 |
} |
| 1007 |
|
| 1008 |
double orthogonal; |
| 1009 |
if ( left ) { |
| 1010 |
orthogonal = 270.0; |
| 1011 |
} |
| 1012 |
else { |
| 1013 |
orthogonal = 90.0; |
| 1014 |
} |
| 1015 |
double horizontalLength = splays.get(i).getHorizontalLength(); |
| 1016 |
double orthogonalExtent = extentAlongBearing( orthogonal, |
| 1017 |
horizontalLength, shotCorrected); |
| 1018 |
|
| 1019 |
if ( orthogonalExtent > bestValue ) { |
| 1020 |
|
| 1021 |
bestValue = orthogonalExtent; |
| 1022 |
bestIdx = i; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
|
| 1026 |
return bestIdx; |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
private double extentAlongBearing( double bearing, double vectorLength, |
| 1039 |
double vectorBearing) { |
| 1040 |
double bearingDifference = UtilityFunctions.bearingDifferenceDegrees(bearing, vectorBearing); |
| 1041 |
double distance = vectorLength * Math.cos(Math.PI * bearingDifference / 180); |
| 1042 |
|
| 1043 |
return distance; |
| 1044 |
} |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
} |