Image.java
17 KB
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
package osp;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import jsky.coords.DMS;
import jsky.coords.HMS;
import jsky.coords.WorldCoords;
import jsky.image.fits.codec.FITSImage;
/**
* Class representing an image with a list of objects and masks.
*/
public class Image extends Observable {
/**
* Unique number (id) of the image. Used to construct the image name and
* masks name.
*/
private int id;
/** Absolute path of the FITS file of the image. */
private String absPath;
/**
* Image name :
* <br>
* determined by the keyword OBJECT or POSITNID in the fits header of the image.
*/
private String name;
/** Image name in the project :
* <br>
* Constructed with the image name and an ID before following the rank in the project.
*
* */
private String pImName;
/** If image from catalog */
private String imCatalog=null;
/**
* Image Center world coords
*/
private WorldCoords imCenterWc;
/**
* <I>Alpha coordinates</I> of the image center in Hours, Minutes,
* Seconds.
*/
private HMS alpha;
/**
* <I>Delta coordinates</I> of the Image center in Degrees, Minutes,
* Seconds.
*/
private DMS delta;
/** Position of the center of the display in canvas coordinates. */
private Point2D.Double center;
/** Scale of the display. */
private float scale;
/** Number of the current mask, -1 if no mask is selected. */
private int selectedMask;
/** Cut levels definition */
private double lowCut, highCut;
/** Colors definition */
private String colorMap;
private String cIntensityName;
private int colorAlgo;
/** Number of reference objects on the image. */
public int refObjNb;
/** List of sky objects on the image. */
private List<SkyObject> listObjects;
/** FITSImage object. */
public FITSImage im_fits;
/** Width and height in pixels of the fits image. */
private double width, height;
/**
* Resolution of the image, computed as follow : Size_In_pixels /
* (Size_In_Deg * 3600). Unit is pixels/arcsec.
*/
private double resol;
/** Flag to tell if the image is loaded and exists */
public boolean isImage;
/** Flag marking if the colors were changed. */
public boolean colorsChanged;
/** Flag marking if the cuts levels were changed. */
public boolean cutsChanged;
/** Flag marking if there's a search ongoing. */
public boolean searching = false;
/** Active object number */
private int activeObject = -1;
/**
* Number of masks. It's used to construct unique name for each mask.
*/
private int totalMasks;
/** List of the masks associated to the image. */
private List<Mask> tabMask = new ArrayList<Mask>();
/**
* Constructs a new image from the given FITS image.
* @param im : FITS image
* @param n : Number of the image
*/
public Image(FITSImage im, int n) {
try {
im_fits = im;
} catch (Exception exception) {
exception.printStackTrace();
}
absPath = new String();
id = n + 1;
String stringValue = im_fits.getHeader().getStringValue("OBJECT");
if (stringValue == null)
stringValue = im_fits.getHeader().getStringValue("POSITNID");
pImName = id + "_" + stringValue;
name=stringValue;
center = new Point2D.Double(0.0, 0.0);
width = im_fits.getWidth(); // In pixels
height = im_fits.getHeight(); // In Pixels
scale = 1.0F;
cutsChanged = false;
refObjNb = 0;
selectedMask = -1;
totalMasks = 0;
setAlpha(null);
setDelta(null);
listObjects = new ArrayList<SkyObject>();
}
/**
* Constructs a new image from the given FITS image.
* @param im : FITS image
* @param n : Number of the image
*/
public Image(FITSImage im, int n,String imName, String imCat) {
try {
im_fits = im;
} catch (Exception exception) {
exception.printStackTrace();
}
absPath = new String();
id = n + 1;
if (imCat=="Local File")
{
String stringValue = im_fits.getHeader().getStringValue("OBJECT");
if (stringValue == null)
stringValue = im_fits.getHeader().getStringValue("POSITNID");
pImName = id + "_" + stringValue;
name=stringValue;
}
else
{
pImName = id + "_" + imName;
name=imName;
}
imCatalog = imCat;
center = new Point2D.Double(0.0, 0.0);
width = im_fits.getWidth(); // In pixels
height = im_fits.getHeight(); // In Pixels
scale = 1.0F;
cutsChanged = false;
refObjNb = 0;
selectedMask = -1;
totalMasks = 0;
listObjects = new ArrayList<SkyObject>();
}
/**
* Returns the id number of the image.
* @return Number of the image.
*/
public int getId() {
return id;
}
/**
* Sets the absolute path of the FITS image.
* @param s : Path of the FITS file.
*/
public void setAbsPath(String s) {
absPath = s;
}
/**
* Returns the absolute path of the FITS image.
* @return Path of the FITS file.
*/
public String getAbsPath() {
return absPath;
}
/**
* Notifies observers of changes.
*/
public void update() {
setChanged();
notifyObservers();
}
/**
* Sets the center of the image in screen coordinates.(Ok)
* @param c : New center for the image.
*/
public void setCenter(Point2D.Double c) {
center.x = c.x;
center.y = c.y;
}
/**
* Returns the center of the image (in canvas coordinates)
* @return The center of the image.
*/
public Point2D.Double getCenter() {
return center;
}
/**
* Sets the scale of the display for the image.
* @param s : The new scale.
*/
public void setScale(float s) {
scale = s;
}
/**
* Returns the scale of the display for the image.
* @return The scale of the display.
*/
public float getScale() {
return scale;
}
/**
* Returns the name of the image in the project.
* @return pImName project image's name.
*/
public String getProjImName() {
return pImName;
}
/**
* Returns the name of the image.
* @return image's name.
*/
public String getImName() {
return name;
}
/**
* Returns the FITSImage object associated with this image.
* @return The FITSImage for this image.
*/
public FITSImage getFitsImage() {
return im_fits;
}
/**
* set image center world coords
*/
public void setImCenterWc(HMS ra, DMS dec)
{
imCenterWc=new WorldCoords(ra,dec);
alpha=ra;
delta=dec;
}
/**
* Sets the alpha of the Image.
* @param ra : New RA coordinate for the Image.
*/
public void setAlpha(HMS ra) {
alpha = ra;
}
/**
* Sets the alpha of the Image.
* @param ra : Decimal value of the new RA coordinate for the Image.
*/
public void setAlpha(double ra) {
alpha = new HMS(ra);
}
/**
* Returns the RA coordinate of the Image.
* @return Alpha of the Image.
*/
public HMS getAlpha() {
return alpha;
}
/**
* Returns the RA coordinate of the Image as a decimal value.
* @return Alpha of the Image.
*/
public double getAlphaDouble() {
return alpha.getVal();
}
/**
* Sets the delta of the Image.
* @param dec : New DEC coordinate for the Image.
*/
public void setDelta(DMS dec) {
delta = dec;
}
/**
* Sets the delta of the Image.
* @param dec : Decimal value of the new DEC coordinate for the Image.
*/
public void setDelta(double dec) {
delta = new DMS(dec);
}
/**
* Returns the DEC coordinate of the mask.
* @return Delta of the mask.
*/
public DMS getDelta() {
return delta;
}
/**
* Returns the DEC coordinate of the mask as a decimal value.
* @return Delta of the mask.
*/
public double getDeltaDouble() {
return delta.getVal();
}
/** Get and set image Catalog */
public void setImageCatalog(String cat)
{
imCatalog=cat;
System.out.println("Im 247 cat : "+cat);
}
public String getImageCatalog()
{
return imCatalog;
}
// Images cuts levels.
/**
* Sets the low cut level for this image.
* @param lC : Low cut level.
*/
public void setCutsLevels(double lC, double hC) {
lowCut = lC;
highCut = hC;
}
public void setLowCut(double lC) {
lowCut = lC;
}
/**
* Returns the low cut level for this image.
*
* @return The low cut level.
*/
public double getLowCut() {
return lowCut;
}
/**
* Sets the high cut level for this image.
* @param hC : High cut level.
*/
public void setHighCut(double hC) {
highCut = hC;
}
/**
* Returns the high cut level for this image.
* @return The high cut level.
*/
public double getHighCut() {
return highCut;
}
public void setImageColors(String cMap, String cIntens, int cAlgo) {
colorMap = cMap;
cIntensityName = cIntens;
colorAlgo = cAlgo;
}
/**
* Get the image colors
* @return The color map.
*/
public String getColorMap() {
return colorMap;
}
/**
* Set the image colors
* @param color map
*/
public void setColorMap(String cMap) {
colorsChanged = true;
colorMap = cMap;
}
/**
* get the colors intensity
* @return String cIntensityName
*/
public String getColorIntensity() {
return cIntensityName;
}
/**
* Set the image colors intensity
* @param String cIntensityName
*/
public void setColorIntensity(String cIntensity) {
cIntensityName = cIntensity;
colorsChanged = true;
}
/**
* Get the color algorithm
* @return colorAlgo
*/
public int getColorAlgorithm() {
return colorAlgo;
}
/**
* Set the image colors algorithm
* @param int colorAlgo
*/
public void setColorAlgorithm(int cAlgo) {
colorsChanged = true;
colorAlgo = cAlgo;
}
/**
* Set the flag when Image is loaded, added to the project
*/
public void setImageValid() {
isImage = true;
}
/**
* Sets the image width in pixels.
*
* @param w
* Width of the image.
*/
public void setWidth(double w) {
width = w;
} // unused
/**
* Returns the image width (in pixels).
*
* @return Width of the image.
*/
public double getWidth() {
return width;
}
/**
* Sets the image height in pixels.
*
* @param h : Height of the image.
*/
public void setHeight(double h) {
height = h;
} // unused
/**
* Returns the image height (in pixels).
*
* @return Height of the image.
*/
public double getHeight() {
return height;
}
/**
* Sets the image resolution. The resolution should be in pixels/arcsecs.
*
* @param res : The resolution of the image.
*/
public void setResol(double res) {
resol = res;
}
/**
* Returns the image resolution. The resolution is in pixels/arcsecs.
*
* @return The resolution of the image.
*/
public double getResol() {
return resol;
}
/**
* Returns a list of all masks present on the image.
* @return The list of masks.
*/
public List<Mask> getListMasks() {
return tabMask;
}
/**
* Sets the current mask. The value -1 is used to specify that no mask is
* selected.
* @param n : Number of the current mask.
*/
public void setSelectedMask(int n) {
selectedMask = n;
}
/**
* Returns the current mask number.
* @return Number of the current mask, -1 if there is no current mask.
*/
public int getSelectedMask() {
return selectedMask;
}
/**
* Creates and adds a new mask to the image, at the position p.
* @param p : Position of the new mask on the image, point is image display center (user coord)
*/
public void addMask(Point2D.Double p) {
Mask m = new Mask(this, totalMasks);
Point2D.Double center = new Point2D.Double();
center.x = p.getX();
center.y = p.getY();
m.setCenter(center);
m.setCurrentSlit(0);
tabMask.add(m);
setSelectedMask(tabMask.size() - 1);
totalMasks++;
}
/**
* Adds a previously created mask on the image.
* @param m : The mask to add to the image.
*/
public void addMask(Mask m) {
tabMask.add(m);
setSelectedMask(tabMask.size() - 1);
totalMasks++;
}
/**
* Returns the mask number num.
* @param num : Number of the mask to get.
*
* @return The corresponding mask.
*/
public Mask getMask(int num) {
return (tabMask.get(num));
}
/**
* Returns the current mask.
* @return The current mask.
*/
public Mask getCurrentMask() {
Mask mask = null;
if (tabMask.size() >= 0 && selectedMask!= -1){
mask = tabMask.get(selectedMask);
}
return mask;
}
/**
* Returns the number of masks on the image.
* @return Number of masks on the image.
*/
public int getNbrMasks() {
return tabMask.size();
}
/**
* Removes the mask number num from the image.
*
* @param num
* Number of the mask to remove.
*/
public void removeMask(int num) {
tabMask.remove(num);
if (num == tabMask.size())
setSelectedMask((tabMask.size() - 1));
}
/**
* Resets the total number of masks that have been added on this image
* (including masks that have been deleted), and deletes all masks currently
* on the image.
*/
public void resetTotalMask() {
for (int i = tabMask.size() - 1; i >= 0; i--)
removeMask(i);
totalMasks = 0;
}
/**
* Returns the number of objects on the image.
*
* @return Number of objects on the image.
*/
public int getNbrObjects() {
return listObjects.size();
}
/**
* Returns the list of objects present on the image.
* @return List of object on the image.
*/
public List<SkyObject> getListObjects() {
return listObjects;
}
/**
* Returns the n object in the image object list
* @return object
*/
public SkyObject getObject(int id) {
return listObjects.get(id);
}
/**
* Returns the last sky object added on the image.
* @return Last object of the image.
*/
public SkyObject getLastObject() {
return listObjects.get(listObjects.size() - 1);
}
/**
* Returns the object that is currently active on the image.
* @return The active object, -1 if there is no active object.
*/
public int getActiveObject() {
return activeObject;
}
/**
* Sets the active object.
* @param i : Number of the active object, -1 if no object is active.
*/
public void setActiveObject(int i) {
activeObject = i;
}
/**
* Adds a new sky object on the image.
* (Used only when loading a project - Reader)
* @param id : Object id.
* @param num : Object number in the project.
* @param isRef : true if the object is a reference.
* @param from : Where the object has been obtained.
* @param fromLib : Libelle of where the object comes from
* @param pos : Position of the object.
* @param wcObject : Object world coordinates in J2000
* @param prior : Object priority
* @throws IndexOutOfBoundsException
* If the number of the object is negative or higher than the
* last object.
*/
// public void addObject(int id,int num, boolean isRef,int f, String from, Point2D.Double pos, WorldCoords wcObject, int prior)
public void addObject(String id,int num, boolean isRef,int f, String from, Point2D.Double pos, WorldCoords wcObject, int prior)
throws IndexOutOfBoundsException {
// System.out.println(" Image addObj1 "+id +" "+num); /*cat "+from+" Ty "+f+" Pr "+prior);*/
//listObjects.add(num, new SkyObject(String.valueOf(id), num, isRef, f, from, pos, wcObject, prior));
listObjects.add(num, new SkyObject(id, num, isRef, f, from, pos, wcObject, prior));
}
/**
* Adds a new sky object on the image.
* Used to create a new object when using a manual selection-clic on image
* Or when loaded by local catalog or from a server.
* @param isRef : true if the object is a reference.
* @param f : load catalog number.
* @param props : <String> List of properties when local cat, or catalog name when download from server.
* @param pos : Position of the object.
* @param wcObject : Object world coordinates in J2000
* @param priority : Object priority
*/
// public void addObject(int id, boolean isRef, int f, String from, Point2D.Double pos, WorldCoords wcObject, int prior) {
public void addObject(String id, boolean isRef, int f, String props, Point2D.Double pos, WorldCoords wcObject, int prior) {
//System.out.println(" Image addObj 2 "+id);
// if (id==-1) id=listObjects.size();
if (id=="-1") id=String.valueOf(listObjects.size());
listObjects.add(new SkyObject(id, listObjects.size(), isRef, f, props, pos, wcObject,prior));
}
/**
* Removes the object number i from the image.
* @param i : Number of the object to remove.
*/
public void removeObject(int i) {
listObjects.remove(i);
// When remove an object, set the id again for the rest of the list.
for (int h = i; h < listObjects.size(); h++) {
listObjects.get(h).reSetNum(h);
}
}
/**
* Removes the last object added to the image.
*/
public void removeLastObject() {
listObjects.remove(listObjects.size() - 1);
}
/**
* Removes all objects from the image.
*/
public void removeAllObjects() {
for (int i = listObjects.size() - 1; i >= 0; i--)
removeObject(i);
}
}