// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   NormalizedMatrix.java

package lt.monarch.chart;


public class NormalizedMatrix
{

	public final int resolutionX;
	public final int resolutionY;
	public double z[][];

	public void normalize(double d, double d1)
	{
		double d2 = d1 - d;
		for(int i = 0; i < resolutionY; i++)
		{
			for(int j = 0; j < resolutionX; j++)
				z[j][i] = (z[j][i] - d) / d2;

		}

	}

	public void normalize()
	{
		double d = 1.7976931348623157E+308D;
		double d1 = Double.MIN_VALUE;
		for(int i = 0; i < resolutionY; i++)
		{
			for(int j = 0; j < resolutionX; j++)
			{
				if(z[j][i] > d1 && z[j][i] != (1.0D / 0.0D))
					d1 = z[j][i];
				if(z[j][i] < d && z[j][i] != (-1.0D / 0.0D))
					d = z[j][i];
			}

		}

		normalize(d, d1);
	}

	public void logBase(double d)
	{
		for(int i = 0; i < resolutionY; i++)
		{
			for(int j = 0; j < resolutionX; j++)
				z[j][i] = Math.log(z[j][i] + d);

		}

	}

	public void soften3x3()
	{
		double ad[][] = new double[resolutionX + 2][resolutionY + 2];
		for(int i = 0; i < resolutionX; i++)
		{
			System.arraycopy(z[i], 0, ad[i + 1], 1, resolutionY);
			ad[i][0] = ad[i][1];
			ad[i][resolutionY + 1] = ad[i][resolutionY];
		}

		System.arraycopy(ad[1], 0, ad[0], 0, resolutionY + 2);
		System.arraycopy(ad[resolutionX], 0, ad[resolutionX + 1], 0, resolutionY + 2);
		for(int k = 0; k < resolutionY; k++)
		{
			for(int j = 0; j < resolutionX; j++)
				z[j][k] = (ad[j][k] * 1.0D + ad[j + 1][k] * 2D + ad[j + 2][k] * 1.0D + ad[j][k + 1] * 2D + ad[j + 1][k + 1] * 3D + ad[j + 2][k + 1] * 2D + ad[j][k + 2] * 1.0D + ad[j + 1][k + 2] * 2D + ad[j + 2][k + 2] * 1.0D) / 15D;

		}

	}

	public void soften5x5()
	{
		double ad[][] = new double[resolutionX + 4][resolutionY + 4];
		for(int i = 0; i < resolutionX; i++)
		{
			System.arraycopy(z[i], 0, ad[i + 2], 2, resolutionY);
			ad[i][0] = ad[i][1] = ad[i][2];
			ad[i][resolutionY + 3] = ad[i][resolutionY + 2] = ad[i][resolutionY + 1];
		}

		System.arraycopy(ad[2], 0, ad[0], 0, resolutionY + 4);
		System.arraycopy(ad[2], 0, ad[1], 0, resolutionY + 4);
		System.arraycopy(ad[resolutionX + 2], 0, ad[resolutionX + 2], 0, resolutionY + 4);
		System.arraycopy(ad[resolutionX + 2], 0, ad[resolutionX + 3], 0, resolutionY + 4);
		for(int k = 0; k < resolutionY; k++)
		{
			for(int j = 0; j < resolutionX; j++)
				z[j][k] = (ad[j][k] * 0.0D + ad[j + 1][k] * 1.0D + ad[j + 2][k] * 2D + ad[j + 3][k] * 1.0D + ad[j + 4][k] * 0.0D + ad[j][k + 1] * 1.0D + ad[j + 1][k + 1] * 2D + ad[j + 2][k + 1] * 3D + ad[j + 3][k + 1] * 2D + ad[j + 4][k + 1] * 1.0D + ad[j][k + 2] * 2D + ad[j + 1][k + 2] * 3D + ad[j + 2][k + 2] * 4D + ad[j + 3][k + 2] * 3D + ad[j + 4][k + 2] * 2D + ad[j][k + 3] * 1.0D + ad[j + 1][k + 3] * 2D + ad[j + 2][k + 3] * 3D + ad[j + 3][k + 3] * 2D + ad[j + 4][k + 3] * 1.0D + ad[j][k + 4] * 0.0D + ad[j + 1][k + 4] * 1.0D + ad[j + 2][k + 4] * 2D + ad[j + 3][k + 4] * 1.0D + ad[j + 4][k + 4] * 0.0D) / 40D;

		}

	}

	public NormalizedMatrix(int i, int j)
	{
		resolutionX = i;
		resolutionY = j;
		z = new double[resolutionX][resolutionY];
	}
}
