samer@0
|
1 /*
|
samer@0
|
2 * MatrixTImageSourceF.java
|
samer@0
|
3 *
|
samer@0
|
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
5 * All rights reserved.
|
samer@0
|
6 *
|
samer@0
|
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
8 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
9 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
10 */
|
samer@0
|
11
|
samer@0
|
12 package samer.maths;
|
samer@0
|
13 import samer.tools.*;
|
samer@0
|
14 import Jama.Matrix;
|
samer@0
|
15 import java.awt.image.*;
|
samer@0
|
16
|
samer@0
|
17 /** This one sends pixels in vertical strips: better for
|
samer@0
|
18 column vectors or very narrow matrices
|
samer@0
|
19 */
|
samer@0
|
20
|
samer@0
|
21 public class MatrixTImageSourceF extends ImageSourceBase
|
samer@0
|
22 {
|
samer@0
|
23 Matrix matrix;
|
samer@0
|
24 byte [] strip;
|
samer@0
|
25
|
samer@0
|
26 public MatrixTImageSourceF( Matrix mat)
|
samer@0
|
27 {
|
samer@0
|
28 matrix = mat;
|
samer@0
|
29 width = mat.getRowDimension();
|
samer@0
|
30 height = mat.getColumnDimension();
|
samer@0
|
31 strip = new byte[height];
|
samer@0
|
32 }
|
samer@0
|
33
|
samer@0
|
34 public void newMatrix(Matrix mat) { matrix=mat; sendPixels(); }
|
samer@0
|
35
|
samer@0
|
36 protected int getHints() {
|
samer@0
|
37 if (width==1) {
|
samer@0
|
38 return ImageConsumer.TOPDOWNLEFTRIGHT
|
samer@0
|
39 | ImageConsumer.COMPLETESCANLINES
|
samer@0
|
40 | ImageConsumer.SINGLEPASS;
|
samer@0
|
41 } else {
|
samer@0
|
42 return ImageConsumer.RANDOMPIXELORDER | ImageConsumer.SINGLEPASS;
|
samer@0
|
43 }
|
samer@0
|
44 }
|
samer@0
|
45 protected void sendPixels(ImageConsumer ic)
|
samer@0
|
46 {
|
samer@0
|
47 double[][] X=matrix.getArray();
|
samer@0
|
48
|
samer@0
|
49 for (int i=0; i<width; i++) {
|
samer@0
|
50 double[] Xi=X[i]; // can't believe compiler isn't doing this!
|
samer@0
|
51 for (int j=0; j<height; j++) {
|
samer@0
|
52 strip[height-1-j] = (byte)map.clipInt(Xi[j]);
|
samer@0
|
53 }
|
samer@0
|
54 ic.setPixels(i, 0, 1, height, model, strip, 0, 1);
|
samer@0
|
55 }
|
samer@0
|
56 }
|
samer@0
|
57 }
|