view src/samer/maths/MatrixTImageSourceF.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	MatrixTImageSourceF.java	
 *
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
 *	without even the implied warranty of MERCHANTABILITY or 
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.maths;
import  samer.tools.*;
import  Jama.Matrix;
import  java.awt.image.*;

/** This one sends pixels in vertical strips: better for
	column vectors or very narrow matrices
 */

public class MatrixTImageSourceF extends ImageSourceBase
{
	Matrix		matrix;
	byte []		strip;

	public MatrixTImageSourceF( Matrix mat)
	{
		matrix	= mat;
		width		= mat.getRowDimension();
		height	= mat.getColumnDimension();
		strip		= new byte[height];
	}

	public void newMatrix(Matrix mat) { matrix=mat; sendPixels();	}

	protected int getHints() { 
		if (width==1) {
			return  ImageConsumer.TOPDOWNLEFTRIGHT 
					| ImageConsumer.COMPLETESCANLINES
					| ImageConsumer.SINGLEPASS;
		} else {
			return ImageConsumer.RANDOMPIXELORDER | ImageConsumer.SINGLEPASS; 
		}
	}
	protected void sendPixels(ImageConsumer ic)
	{
		double[][] X=matrix.getArray();

		for (int i=0; i<width; i++) {
			double[] Xi=X[i]; // can't believe compiler isn't doing this!
			for (int j=0; j<height; j++) {
				strip[height-1-j] = (byte)map.clipInt(Xi[j]);
			}
			ic.setPixels(i, 0, 1, height, model, strip, 0, 1);
		} 
	}
}