package com.elphel.imagej.orthomosaic;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class PairwiseOrthoMatch implements Serializable {
	private static final long serialVersionUID = 1L;
	public double [][]           affine = new double[2][3];
	public transient double [][] jtj =    new double [6][6];
	public int zoom_lev;
	public double rms = Double.NaN;
	public PairwiseOrthoMatch() {
		
	}
	public PairwiseOrthoMatch(double [][] affine, double [][] jtj, double rms, int zoom_lev) {
		this.affine = affine;
		this.jtj = jtj;
	}
	public double [][] getAffine(){
		return affine;
	}
	
	private void writeObject(ObjectOutputStream oos) throws IOException {
		oos.defaultWriteObject();
		for (int i = 0; i < jtj.length; i++) {
			for (int j = i; j < jtj[i].length; j++) {
				oos.writeObject(jtj[i][j]);
			}
		}
	}
	private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
		ois.defaultReadObject();
		jtj = new double [6][6]; // readObject does not use constructor!
		for (int i = 0; i < jtj.length; i++) {
			for (int j = i; j < jtj[i].length; j++) {
				jtj[i][j] = (Double) ois.readObject();
				if (j > i) {
					jtj[j][i] = jtj[i][j];
				}
			}
		}
	}
	//private void readObjectNoData() throws ObjectStreamException; // used to modify default values
}
