package ac.essex.gp.util;

import ac.essex.gp.training.segmentation.TrainingImage;
import ac.essex.ooechs.imaging.commons.apps.shapes.SegmentedShape;

import java.util.Hashtable;

/**
 * The Data Stack is passed to all nodes as they are being executed. It acts as memory for the application
 * and allows each node access to the data that they will be processing. In practical terms it contains details
 * of which x,y coordinates are being looked at, and a reference to the current training image. 
 *
 * @author Olly Oechsle, University of Essex, Date: 15-Jan-2007
 * @version 1.0
 */
public class DataStack {

    /**
     * Image used for segmentation training
     */
    protected TrainingImage image;

    /**
     * Shape used for shape training
     */
    public SegmentedShape shape;

    public boolean usesImaging = false;

    public double value;

    // X and Y are commonly used, hence available via faster methods
    public int x;
    public int y;

    // All other common data is stored in this hashtable
    protected Hashtable<String, Object> values;

    public DataStack() {
        values = new Hashtable<String, Object>(10);
        this.value = 0d;
        this.image = null;
    }

    public void add(String key, Object value) {
        values.put(key, value);
    }

    public Object get(String key) {
        Object value = values.get(key);
        if (value == null) {
            throw new RuntimeException("No object exists in DataStack for key: " + key);
        } else {
            return value;
        }
    }

    public ac.essex.gp.training.segmentation.TrainingImage getImage() {
        return image;
    }

    public void setImage(TrainingImage image) {
        this.image = image;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }



}
