-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMosaicData.java
executable file
·3063 lines (2701 loc) · 116 KB
/
MosaicData.java
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
27
28
29
30
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// MosaicData - this class tracks the data for the scenes to display
//
// Note: this file was created to separate the data representation from
// the code that displays the data. Much of this code used to
// be in the ImagePane class.
//
// Threading Design Notes:
// A separate thread is used to load TOC files. This allows the applet
// to remain fairly responsive to the user even if data is being loaded
// over a slow network connection. The class also knows when image
// files are being loaded by the imageLoader object.
//
// The design assumes that only two threads interact directly with this
// class - the GUI thread and the TOC loading thread. The design attempts
// to minimize the amount of waiting the GUI thread does so that it can
// remain responsive and animate a busy indicator while data is being
// loaded over the network.
//
// Be very careful when making changes to this file. Pay attention to
// which thread will be making changes to data members. Basically, only
// the GUI thread should be changing most data members so the applet
// always sees a consistent state when making updates to the GUI.
//
// The image member of the Metadata is only updated after a browse image
// has completed loading in the ImageLoader. So, it is safe to flush
// images any time from this file. However, since the image loader may
// complete a load of an image after it should have been flushed here,
// sometimes resources will be held for the image eventhough it isn't
// currently displayed. That is okay since the final clean up a TOC
// is done only after the ImageLoader has completed and any resources that
// were not free'd due to timing will definitely be free'd then.
//
//----------------------------------------------------------------------------
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Polygon;
import java.net.URL;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
import javax.swing.JOptionPane;
public class MosaicData extends Observable implements Runnable, WorkMonitor
{
private imgViewer applet; // reference to the applet
private LocatorMap locatorMap; // locator map reference
public static final Object DISPLAY_MODE_CHANGED = new Object();
// object passed as part of the observer interface to indicate
// the display mode changed
public Point targetXY = new Point();
// object passed as part of the observer interface to indicate
// there is a specific target X/Y location (used to set scroll
// position when scrollbars are present)
private boolean isTargetXY = false; // flag to indicate the display is
// trying to move to a target X/Y
private final int mosaicWidth = 3; // width of mosaic array - MUST BE ODD
private final int mosaicHeight = 3; // height of mosaic array - MUST BE ODD
private final int mosaicSize = mosaicWidth * mosaicHeight;
// size of mosaic array
private final int colCenterIndex = (mosaicWidth - 1) / 2;
// index to center column of mosaic
private final int rowCenterIndex = (mosaicHeight - 1) / 2;
// index to center row of mosaic
private final int mosaicCenterIndex = colCenterIndex * mosaicHeight
+ rowCenterIndex;
// index to center cell of mosaic
private int activeCellIndex = mosaicCenterIndex; // index of the active
// (selected) cell in the mosaicCells array
private int[] defaultZOrder; // default Z-order indices
int gridCol; // grid column of center cell (path for WRS-2)
int gridRow; // grid row of center cell (row for WRS-2)
private ProjectionTransformation proj; // Projection transformation object
private int projectionCode; // current projection code used to display data
private TOC[] mosaicCells; // array of TOC's for the mosaic area
private int cellsToDisplay; // count of cells to display for current
// resolution, or Sensor.SINGLE_SCENE if only one scene
// should be displayed. A value of 1 is not the
// same as SINGLE_SCENE since 1 means it could still
// be a mosaic of images in one cell (i.e. ASTER 400m)
private Sensor currSensor; // currently selected sensor object
int pixelSize; // currently displayed pixel size
double actualPixelSize; // the actual size of the pixels currently
// displayed. The same as pixelSize for most
// sensors, but sometimes different (i.e. MODIS)
// since the browse may be a slightly different
// resolution than advertised.
MapLayers mapLayers; // map layers container
private DateCache dateCache;// cache of dates for recent areas visited
// where the date is no longer the default date
int maxCloudCover = 100; // maximum cloud cover to display
private ZOrderList zOrderList; // list for tracking the Z-order of scenes
// in the mosaic view.
private ImagePane pane; // image pane for displaying the mosaic
private Dimension displaySize; // dimensions needed to display the images
public MosaicCoords mosaicCoords;// object to hold mosaic coordinate info
public SceneFilter sceneFilter;// scene filter to use for filtering scenes
// based on things like cloud cover
private int subCol; // fractional column step when displaying 1 cell
private int subRow; // fractional row step when displaying 1 cell
public final static int STEPS = 3; // number of fractional steps when
// displaying a single cell
public ImageLoader imageLoader; // image loader object
private boolean areImagesLoading;// flag to indicate images are loading
private int notifyType; // type of notify last sent to observers
// defined types of notifies sent to observers
private static final int NORMAL_NOTIFY = 0;
private static final int TARGETXY_NOTIFY = 1;
private static final int DISPLAY_MODE_CHANGE_NOTIFY = 2;
private Thread loaderThread; // thread for loading TOC files
private Object loadLock; // mutex for exclusive access
private boolean killThread; // flag to indicate the thread should
// be killed
private boolean isLoading; // TOC files are loading flag
private boolean isLoadCancelled; // cancel TOC files loading flag
private TOC[] loadingMosaicCells;// array of TOCs being loaded by the load
// thread
private int loadingActiveCellIndex; // index into mosaicCells that should
// be active after new TOCs are loaded
private boolean loadingPreserveZOrder; // flag to preserve the displayed
// z-order of scenes after new TOCs are
// loaded
private boolean[] loadingUsed; // array of flags to indicate which entries
// of mosaicCells have been reused in the
// loadingMosaicCells so the correct cells
// can be cleaned up when a new TOC array
// is activated.
private boolean loadCompleted; // flag to indicate the TOC load is done
private boolean tocChangePending;// flag to indicate a change to a new TOC
// array is being loaded
private boolean resolutionChangePending;// flag that indicates a resolution
// change is pending (delayed due to the
// user changing resolution in the middle
// of a TOC load)
private Metadata targetScene; // reference to the target scene when
// showScene is called. It is stored
// here temporarily while the inventory
// TOC files load.
private Metadata refScrollScene; // reference to a scene in the current
// swath when scrolling a full-mosaic
// sensor. This helps stay on the same
// swath when scrolling up and down.
private int numTocsToLoad; // total number of TOC files to load
private int currTocLoading; // current TOC loading of total number
private boolean isCalledFromScrolledData;// flag indicating if display
//was scrolled
private Metadata targetDateScene;// current selected scene
private LatLong targetLatLong; // target lat/long for gotoLatLong
// Constructor for the ImagePane. Allocates array space and sets variables.
//--------------------------------------------------------------------------
MosaicData(imgViewer parent, ImagePane paneIn, LocatorMap locatorMap)
{
applet = parent; // Save ptr to parent
pane = paneIn;
this.locatorMap = locatorMap;
isCalledFromScrolledData = false;
targetDateScene = null;
// Setup space for the Table-of-Contents files
mosaicCells = new TOC[mosaicSize];
// define the default zorder (from lowest to highest order)
defaultZOrder = new int[mosaicSize];
int index = 0;
for (int col = 0; col < mosaicWidth; col++)
{
// skip the middle column
if (col == colCenterIndex)
continue;
for (int row = 0; row < mosaicHeight; row++)
{
defaultZOrder[index] = col * mosaicHeight + row;
index++;
}
}
int col = colCenterIndex;
for (int row = 0; row < mosaicHeight; row++)
{
// skip the middle row
if (row == rowCenterIndex)
continue;
defaultZOrder[index] = col * mosaicHeight + row;
index++;
}
defaultZOrder[index] = mosaicCenterIndex;
// create the image loader
imageLoader = new ImageLoader(parent,paneIn);
// create the date cache for the last 20 scenes changed from the
// default date
dateCache = new DateCache(20);
// create the mosaic Z-order list
zOrderList = new ZOrderList();
mapLayers = new MapLayers(applet,pane);
sceneFilter = new LandsatSceneFilter(this);
mosaicCoords = new MosaicCoords();
// initialize the display size since it is possible to use it before
// it is set normally
displaySize = new Dimension(1,1);
// create objects for threading support
loadLock = new Object();
loaderThread = new Thread(this,"TOC Loader Thread");
loaderThread.start();
}
// methods required for the WorkMonitor interface
//-----------------------------------------------
public String getWorkLabel() { return "Reading Inventory"; }
public boolean isWorking() { return isUnstableTOC(); }
public int getTotalWork() { return numTocsToLoad; }
public int getWorkComplete() { return currTocLoading; }
// helper routine to set a default z-order
//----------------------------------------
private void setDefaultZOrder()
{
TOC cell;
// if the current sensor is a full mosaic, make the initial z-order
// be sorted by cloud cover
if (currSensor.isFullMosaic)
{
for (int i = 0; i < mosaicCells.length; i++)
{
cell = mosaicCells[defaultZOrder[i]];
// if the cell is valid, insert the scenes in cloud cover order
if (cell.valid)
{
for (int j = 0; j < cell.numImg; j++)
zOrderList.insertByCloudCover(cell.scenes[j]);
}
}
}
// when default to selected date is enabled set the default scenes
// to display.
if (applet.toolsMenu.isDefaultToDateEnabled())
{
cell = mosaicCells[activeCellIndex];
if (cell.valid)
setDefaultToSelectedDate(cell.scenes[cell.currentDateIndex]);
}
// now make sure the current date index in each cell is on top
for (int i = 0; i < mosaicCells.length; i++)
{
cell = mosaicCells[defaultZOrder[i]];
// if the cell is valid, put the scene on top
if (cell.valid)
{
// then make sure the current date index is on top
zOrderList.putOnTop(cell.scenes[cell.currentDateIndex]);
}
}
// when in swath mode, make sure the active swath is on top of the
// other scenes
if (currSensor.hasSwathMode && applet.toolsMenu.isSwathModeEnabled())
{
cell = mosaicCells[activeCellIndex];
if (cell.valid)
buildSwath(cell.scenes[cell.currentDateIndex], true);
}
}
// helper routine to set the selected scene in the displayed area
//-------------------------------------------------------------------
public void setSelectedScene(Metadata scene)
{
// update the selected scene
updateSelectedScene(scene);
// notify the observers that the data has changed
notifyType = MosaicData.NORMAL_NOTIFY;
setChanged();
notifyObservers();
}
// helper method to put the update the needed items for the currently
// selected scene
//-------------------------------------------------------------------
private void updateSelectedScene(Metadata scene)
{
// put the selected scene on top
zOrderList.putOnTop(scene);
// find the cell index for the scene
int cellIndex = colRowToCell(scene.gridCol,scene.gridRow);
if (cellIndex == -1)
{
// bug that should never happen
System.out.println("Bug detected in updateSelectedScene");
return;
}
TOC cell = mosaicCells[cellIndex];
// find the scene index so the currentDateIndex can be updated
int index;
for (index = 0; index < cell.numImg; index++)
{
if (scene == cell.scenes[index])
break;
}
if (index < cell.numImg)
cell.currentDateIndex = index;
else
System.out.println("Bug in updateSelectedScene");
// set the new active cell and filter the scenes
activeCellIndex = cellIndex;
sceneFilter.filter();
// when in swath mode, make sure the swath for the selected scene
// is shown and that new scenes are loaded if needed
if (currSensor.hasSwathMode && applet.toolsMenu.isSwathModeEnabled())
{
buildSwath(scene, true);
mosaicCoordsUpdate();
loadScenes();
}
}
// helper routine to set the selected cell in the Mosaic.
// The activeCellIndex value should only be changed by calling this method
// unless you are absolutely sure of what you are doing.
//-------------------------------------------------------------------
private void setSelectedCell(int cellIndex, boolean preserveZOrder)
{
// if not preserving the z-order, select the correct scene to be
// on top
if (!preserveZOrder)
{
boolean cellSet = false;
// if a sub-cell step is in effect, make sure the selected scene is
// selected from the visible scenes
if ((subCol != 0) || (subRow != 0))
{
zOrderList.top();
Metadata scene;
while ((scene = zOrderList.down()) != null)
{
if (scene.visible)
{
updateSelectedScene(scene);
cellSet = true;
break;
}
}
}
if (!cellSet)
{
// set the scene index at the top of the z-order
TOC cell = mosaicCells[cellIndex];
if (cell.valid)
zOrderList.putOnTop(cell.scenes[cell.currentDateIndex]);
activeCellIndex = cellIndex;
sceneFilter.filter();
}
}
else
sceneFilter.filter();
// notify the observers that the data has changed
setChanged();
// if there is a target X/Y notify observers including that,
// otherwise just do a normal notify
if (isTargetXY)
{
notifyType = MosaicData.TARGETXY_NOTIFY;
notifyObservers(targetXY);
}
else
{
notifyType = MosaicData.NORMAL_NOTIFY;
notifyObservers();
}
}
// method to determine if a given scene is in the active swath. Returns
// true if the scene is in the active swath.
//----------------------------------------------------------------------
private boolean isInActiveSwath(Metadata scene)
{
// this assumes that anything with the same date and sensor is in the
// same swath
Metadata currScene = getCurrentScene();
if ((currScene != null) && (currScene.date == scene.date)
&& (currScene.getSensor() == scene.getSensor()))
return true;
else
return false;
}
// method to lower the top scene to the bottom of the Z-order and select
// a new scene to be the selected scene
//----------------------------------------------------------------------
public void lowerScene(Metadata sceneToLower)
{
// nothing to do if only a single scene is visible
if (cellsToDisplay == Sensor.SINGLE_SCENE)
return;
// if in swath mode and a scene in the active swath it being lowered,
// it requires special handling to lower the entire swath
if (currSensor.hasSwathMode && applet.toolsMenu.isSwathModeEnabled())
{
if (isInActiveSwath(sceneToLower))
{
// get the list of the scenes in the swath
Vector swathScenes = getScenesInSwath(sceneToLower);
// lower all the scenes in the swath
for (int i = 0; i < swathScenes.size(); i++)
{
Metadata scene = (Metadata)swathScenes.elementAt(i);
zOrderList.putOnBottom(scene);
}
// get new top scene
zOrderList.top();
Metadata topScene = zOrderList.down();
// make the swath for the new top scene the active swath
int cellNum = colRowToCell(topScene.gridCol, topScene.gridRow);
TOC cell = mosaicCells[cellNum];
int dateIndex = cell.getIndexOfDate(topScene.date,
topScene.getSensor());
cell.currentDateIndex = dateIndex;
activeCellIndex = cellNum;
buildSwath(topScene, true);
// load new scenes in case some of the scenes in the new active
// swath haven't been loaded yet
mosaicCoordsUpdate();
loadScenes();
// return since lowering a scene for this special case has
// now been entirely handled
return;
}
}
// get the top scene
zOrderList.top();
Metadata topScene = zOrderList.down();
// if the selected scene is being lowered, look for the scene closest
// to the top that intersects (if nothing intersects, do not do
// anything since there is no need to lower the scene)
if (topScene == sceneToLower)
{
Polygon topSceneLocation = topScene.screenLocation;
Metadata scene;
boolean intersects = false;
while ((scene = zOrderList.down()) != null)
{
// skip scenes that are not visible
if (!scene.visible)
continue;
// cache the points in the current scene
int[] x = scene.screenLocation.xpoints;
int[] y = scene.screenLocation.ypoints;
// check each point to see if it intersects with the
// top scene's location
for (int i = 0; i < 4; i++)
{
if (topSceneLocation.contains(x[i],y[i]))
{
intersects = true;
break;
}
}
if (intersects)
break;
}
// if an intersecting scene was found, make it the selected
// scene
if (intersects)
{
// put the old scene on the bottom
zOrderList.putOnBottom(sceneToLower);
// make the new scene the current scene in its cell and
int cellNum = colRowToCell(scene.gridCol,scene.gridRow);
int i;
for (i = 0; i < mosaicCells[cellNum].numImg; i++)
if (mosaicCells[cellNum].scenes[i] == scene)
break;
if (i < mosaicCells[cellNum].numImg)
mosaicCells[cellNum].currentDateIndex = i;
// set the new selected cell, not preserving the Z-order
setSelectedCell(cellNum, false);
}
}
else
{
// not lowering the selected scene, so just put this scene on the
// bottom and repaint
zOrderList.putOnBottom(sceneToLower);
pane.repaint();
}
}
// method to select scenes that are close to the date of the target
// scene and show a mosaic for that date range.
//----------------------------------------------------------------------
public void setScenesToDate (Metadata targetSetToScene)
{
// looping through each cell
for (int cellNum = 0; cellNum < mosaicCells.length; cellNum++)
{
mosaicCells[cellNum].findSceneClosestToDate(targetSetToScene);
}
// rebuild the z-order for the scenes that are visible
rebuildZOrder();
// load scenes to match the current selected dates
mosaicCoordsUpdate();
loadScenes();
// notify the observers that the data has changed
notifyType = MosaicData.NORMAL_NOTIFY;
setChanged();
notifyObservers();
}
// method to set the default to selected date
//--------------------------------------------------
public void setDefaultToSelectedDate(Metadata scene)
{
if (applet.toolsMenu.isDefaultToDateEnabled())
{
if (targetDateScene == null)
{
targetDateScene = scene;
}
// only update the targetDateScene if the
// display was not scrolled.
if (!isCalledFromScrolledData)
{
targetDateScene = scene;
}
//looping through each cell
for (int cellNum = 0; cellNum < mosaicCells.length; cellNum++)
{
mosaicCells[cellNum].findSceneClosestToDate(targetDateScene);
}
isCalledFromScrolledData = false;
}
}
//method to reset the default scenes displayed
//--------------------------------------------
public void resetTargetDate()
{
targetDateScene = null;
}
// method to select the default scene the cell was originally
// set to.
//------------------------------------------------------------------
public void setDefaultScene(Metadata scene)
{
// get the cellIndex of the scene
int cellIndex = colRowToCell(scene.gridCol,scene.gridRow);
TOC cell = mosaicCells[cellIndex];
// if the TOC is changing, no need to do anything else since the new
// limit will be enforced when the new TOC is activated
if (!isUnstableTOC())
{
if (cell.valid)
{
// pick the most recent, lowest cloud cover scene
int index = pickDefaultScene(cellIndex);
// Flush the date index
flushCurrentDateIndex(cell);
// Set the new date index
cell.currentDateIndex = index;
// Remove entry from cache
dateCache.remove(cell.gridCol,cell.gridRow);
// if in swath mode, pick the scenes in the swaths
if (currSensor.hasSwathMode &&
applet.toolsMenu.isSwathModeEnabled())
{
buildSwath(cell.scenes[cell.currentDateIndex], true);
}
// when default to selected date is enabled set the default
// scenes to display.
if (applet.toolsMenu.isDefaultToDateEnabled())
{
setDefaultToSelectedDate(
cell.scenes[cell.currentDateIndex]);
}
// rebuild the z-order for the scenes that are visible
rebuildZOrder();
// load scenes to match the current selected dates
mosaicCoordsUpdate();
loadScenes();
// notify the observers that the data has changed
notifyType = MosaicData.NORMAL_NOTIFY;
setChanged();
notifyObservers();
}
}
}
// method to add all scene in the user defined area
//-------------------------------------------------
public void selectUserAreaScenes(Metadata currentScene)
{
// only one image in display, so just add it (if visible)
if (cellsToDisplay == Sensor.SINGLE_SCENE)
{
TOC cell = mosaicCells[activeCellIndex];
Metadata scene = cell.scenes[cell.currentDateIndex];
if (scene.visible)
{
currSensor.sceneList.add(scene);
}
}
else
{
// create pointers to User Defined Area values before we get
// into for loops below
UserDefinedArea userDefinedArea =
applet.userDefinedAreaDialog.getUserDefinedArea();
boolean userAreaFilterEnabled =
applet.searchLimitDialog.isUserDefinedAreaEnabled();
// go through each cell and add all scenes that are in the
// user defined area.
for (int cellNum = 0; cellNum < mosaicCells.length; cellNum++)
{
TOC cell = mosaicCells[cellNum];
// protect against invalid array checking
if (cell.valid)
{
// get every visible scene within the user defined area
// need to go and check each scene in the cell if it
// intersects the user defined area polygon
for (int i = 0; i < cell.numImg; i++)
{
Metadata scene = cell.scenes[i];
// if the user defined area filter has been
// enabled, the only scenes visible are those
// within the user defined area. No need to check
// if the scene intersects the user defined polygon
if (userAreaFilterEnabled)
{
if (scene.visible)
{
currSensor.sceneList.add(scene);
}
}
// filter not enabled, so check each scene if it
// intersects the user defined area polygon
else
{
if (scene.visible &&
userDefinedArea.sceneIntersects(scene))
{
currSensor.sceneList.add(scene);
}
}
}
}
}
}
}
// method to add all visible scenes to the scene list
//---------------------------------------------------
public void selectAllScenes (Metadata currentScene)
{
// only one image in display, so just add it
if (cellsToDisplay == Sensor.SINGLE_SCENE)
{
TOC cell = mosaicCells[activeCellIndex];
Metadata scene = cell.scenes[cell.currentDateIndex];
if (scene.visible)
{
currSensor.sceneList.add(scene);
}
}
else //add all current images in mosaicCells to list
{
for (int cellNum = 0; cellNum < mosaicCells.length; cellNum++)
{
TOC cell = mosaicCells[cellNum];
// protect against invalid array checking
if (cell.valid)
{
Metadata scene = cell.scenes[cell.currentDateIndex];
if (scene.visible)
{
currSensor.sceneList.add(scene);
}
}
}
}
}
// method to add all scenes in the selected swath to the scene list
//-----------------------------------------------------------------
public void selectSwathScenes (Metadata currentScene, boolean useHiddenList)
{
Vector scenes = getScenesInSwath(currentScene);
for (int i = 0; i < scenes.size(); i++)
{
Metadata scene = (Metadata)scenes.elementAt(i);
if (scene.visible)
{
if (useHiddenList)
currSensor.hiddenSceneList.add(scene);
else
currSensor.sceneList.add(scene);
}
}
// if hiding scenes, make sure the newly selected swath is on top of
// everything else (needed scenes already being loaded by the hiding
// mechanism)
if (useHiddenList)
{
zOrderList.top();
Metadata scene = zOrderList.down();
buildSwath(scene,true);
}
}
// method to set the ImagePane for the indicated sensor. Note that the
// border adjustments are needed since the image extents read from the TOC
// file are not accurate enough to be visually pleasing. The values were
// found by experimentation.
//------------------------------------------------------------------------
public void setSensor(Sensor newSensor)
{
// cancel any loads in process, making sure to clear the
// areImagesLoading flag to prevent a race condition from using stale
// TOC data
cancelLoad();
imageLoader.cancelLoad();
areImagesLoading = false;
mapLayers.cancelLoad();
// flush the date cache when the sensor is switched
if (currSensor != newSensor)
{
dateCache.flush();
zOrderList.empty();
}
// convert the current grid location to lat/long location in case the
// navigation model changes with the new sensor. If the currSensor is
// null, this is being called during initialization, so just use the
// new sensor navigation model to establish the location.
LatLong loc = null;
if (currSensor == null)
loc = newSensor.navModel.gridToLatLong(gridCol,gridRow);
else
{
if ((cellsToDisplay == 1)
|| (cellsToDisplay == Sensor.SINGLE_SCENE))
{
// displaying a single cell or single scene, so center the
// new sensor on the displayed cell
TOC cell = mosaicCells[activeCellIndex];
if (cell.valid)
{
loc = currSensor.navModel.gridToLatLong(cell.gridCol,
cell.gridRow);
}
}
if (loc == null)
{
// displaying mosaic, so the location displayed for the
// new sensor should be the center of the mosaic
loc = currSensor.navModel.gridToLatLong(gridCol,gridRow);
}
}
mosaicCoords.invalidate();
// make all the cells invalid so they aren't used until they are read
// from the server for the new sensor
for (int i = 0; i < mosaicCells.length; i++)
mosaicCells[i].valid = false;
// update the resolution selection widget so it is current for the
// selected sensor and get the pixel size for this sensor
pixelSize = applet.resolutionMenu.setSensor(currSensor, newSensor);
currSensor = newSensor;
subCol = 0;
subRow = 0;
// if the current sensor mosaics all available data, configure the
// z-order list for multiple scene mode, otherwise single scene mode
if (currSensor.isFullMosaic)
zOrderList.setMultipleSceneMode();
else
zOrderList.setSingleSceneMode();
// get the actual pixel size
actualPixelSize = currSensor.getActualResolution(pixelSize);
// get the number of cells to display at the current resolution
cellsToDisplay = currSensor.getNumCellsAtResolution(pixelSize);
// convert the lat/long location to the current sensor's grid layout
Point grid = currSensor.navModel.latLongToGrid(loc.latitude,
loc.longitude);
// verify the new sensor can actually move to the grid location
if (!canMoveToMapArea(grid.x, grid.y))
{
// can't move to the grid, so go to the center of the defined area
GeographicLocatorMapConfig config
= locatorMap.getMapConfig(currSensor.locatorMap);
loc.latitude = (config.topLat + config.bottomLat) / 2.0;
loc.longitude = (config.leftLon + config.rightLon) / 2.0;
grid = currSensor.navModel.latLongToGrid(loc.latitude,
loc.longitude);
}
gridCol = grid.x;
gridRow = grid.y;
// scroll to the current location for this sensor
scrollData(gridCol,gridRow,0,0,false,false,false);
}
// This routine picks the projection code preferred for the current
// scenes being viewed in the mosaic. It picks the center scene's
// proj Code if valid, otherwise it picks the proj Code that is present
// in more scenes. The proper thing to do is really have scenes within
// three scenes of a boundary processed to multiple projections.
//---------------------------------------------------------------------
private int pickPreferredProjCode()
{
int code = 1100;
// if the center scene has valid projection info, use it as the code to
// display
if (mosaicCells[mosaicCenterIndex].valid)
{
code = mosaicCells[mosaicCenterIndex].projCode;
}
else
{
/* center scene does not have valid projection info, so select the
code with the most scenes in the displayed area */
int altCode = 1100;
int codeCount = 0;
int validCount = 0;
for (int i = 0; i < mosaicCells.length; i++)
{
TOC cell = mosaicCells[i];
if (cell.valid)
{
if (validCount == 0)
{
code = cell.projCode;
altCode = code;
}
validCount++;
if (code == cell.projCode)
codeCount++;
else
altCode = cell.projCode;
}
}
// switch to the alternate proj code if the current didn't account
// for at least half of the scenes that had a valid projection code.
// This assumes only two codes will be present in an area.
if (2 * codeCount < validCount)
code = altCode;
}
return code;
}
// method to provide access to the projection code
//------------------------------------------------
public int getProjectionCode()
{
return projectionCode;
}
// method to pick the most recent, highest quality and lowest
// cloud cover scene
//-----------------------------------------------------------
private int pickDefaultScene(int cellIndex)
{
TOC cell = mosaicCells[cellIndex];
int index = -1;
final int maxCloudCover = 101;
final int minQuality = 0;
int ignoreVisibleIndex = -1;
// To make quality the primary value in selecting a scene
final int cloudCoverWeight = 1;
final int qualityWeight = 101;
// Start with the worst rating and improve as we find nice scenes
int bestSceneRating = ((cloudCoverWeight * maxCloudCover) +
(qualityWeight * (9 - minQuality)));
int ignoreVisibleBestSceneRating = bestSceneRating;
int sceneQuality = 0;
int sceneCloudCover = 0;
int sceneRating = 0; // lower rating = better scene
for (int m = cell.numImg - 1; m >= 0; m--)
{
Metadata scene = cell.scenes[m];
// Find the latest visible image with the high quality and least
// cloud cover to display
sceneQuality = scene.getQuality();
// if quality isn't available, set it to 9 to remove it from the
// consideration
if (sceneQuality == -1)
sceneQuality = 9;
sceneCloudCover = scene.cloudCover;
// if the cloud cover isn't available, set it to the max
if (sceneCloudCover < 0)
sceneCloudCover = maxCloudCover;
sceneRating = ((cloudCoverWeight * sceneCloudCover) +
(qualityWeight * (9 - sceneQuality)));
if ((sceneRating < bestSceneRating) && scene.visible)
{
bestSceneRating = sceneRating;
index = m;
}
if (sceneRating < ignoreVisibleBestSceneRating)
{
ignoreVisibleBestSceneRating = sceneRating;
ignoreVisibleIndex = m;
}
}