/** CS400 3DMotionCapture
 * Mkr
 * 
 * Stores the information for the makers we find in each picture. 
 * In the MakerTracking process, this class forms doubly-linked list.
 * 
 * @author Kohei Shinkawa & Will Levine*/

public class Mkr {

	private double x,y,z;
	private Mkr prev, next;
	private int guess = 0; /*Keeps track of how many guesses was made to create the instance*/
	private boolean disable, assinged; /*Boolean flags used for the guessing process*/
	private int frameNum = 0;
	
	
	public boolean isAssinged() {
		return assinged;
	}

	public void setAssinged(boolean assinged) {
		this.assinged = assinged;
	}

	public Mkr(){
		prev = null;
		next = null;
		disable = false;
	}
	
	public Mkr(double x, double y, double z){
		prev = null;
		next = null;
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public double getX() {
		return x;
	}
	public void setX(double x) {
		this.x = x;
	}
	public double getY() {
		return y;
	}
	public void setY(double y) {
		this.y = y;
	}
	public double getZ() {
		return z;
	}
	public void setZ(double z) {
		this.z = z;
	}
	public Mkr getPrev() {
		return prev;
	}
	
	public void setPrev(Mkr prev) {
		this.prev = prev;
		setFrameNum(prev.getFrameNum() + 1);
	}
	public Mkr getNext() {
		return next;
	}
	public void setNext(Mkr next) {
		this.next = next;
	}
	public int getGuess() {
		return guess;
	}
	public void setGuess(int guess) {
		this.guess = guess;
	}
	public boolean isDisable() {
		return disable;
	}
	public void setDisable(boolean disable) {
		this.disable = disable;
	}
	
	public int getFrameNum() {
		return frameNum;
	}

	public void setFrameNum(int frameNum) {
		this.frameNum = frameNum;
	}

	/*Recursively finds the first node*/
	public Mkr getHeader(){
		if(prev == null)return this;
		return this.prev.getHeader();
	}
	
	/*Recursively finds the last mkr that is not made from guessing*/
	public Mkr findLastKnown(){
		if(guess == 0) return this;
		return this.prev.findLastKnown();
	}
	
	/*Create a new mkr from this point and one previous point*/
	public Mkr predictPoint(){
		if(prev == null) 
			return new Mkr(x, y, z);
		else{
			return new Mkr(x+x-prev.getX(), y+y-prev.getY(), z+z-prev.getZ());
		}
	}
	
	/*Produces all the coordinates of the mkrs in order*/
	public double[] getcoordinates(){
		double[] coordinates = new double[frameNum*3];
		int count = 0;
		Mkr temp = getHeader();
		while(temp != null){
			coordinates[count] = temp.getX();
			coordinates[count+1] = temp.getY();
			coordinates[count+2] = temp.getZ();
			count = count +3;
			temp = temp.getNext();
		}
		return coordinates;
	}
}
