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 :
*
* determined by the keyword OBJECT or POSITNID in the fits header of the image.
*/
private String name;
/** Image name in the project :
*
* 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;
/**
* Alpha coordinates of the image center in Hours, Minutes,
* Seconds.
*/
private HMS alpha;
/**
* Delta coordinates 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 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 tabMask = new ArrayList();
/**
* 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();
}
/**
* 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();
}
/**
* 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 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 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 : 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);
}
}