Mercurial > hg > jslab
annotate src/samer/maths/MatrixImage.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
rev | line source |
---|---|
samer@0 | 1 /* |
samer@0 | 2 * MatrixImage.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.core.*; |
samer@0 | 14 import samer.tools.*; |
samer@0 | 15 import java.awt.Color; |
samer@0 | 16 |
samer@0 | 17 public class MatrixImage extends ImageViewer |
samer@0 | 18 { |
samer@0 | 19 Matrix M; |
samer@0 | 20 Node n; |
samer@0 | 21 |
samer@0 | 22 public MatrixImage( Matrix M) |
samer@0 | 23 { |
samer@0 | 24 // should make an intelligent choice of |
samer@0 | 25 // image source depending on shape of matrix |
samer@0 | 26 super(new MatrixImageSource( M, true),M.observable()); |
samer@0 | 27 this.n=Shell.env().node(); |
samer@0 | 28 this.M=M; |
samer@0 | 29 } |
samer@0 | 30 |
samer@0 | 31 public void scale() |
samer@0 | 32 { |
samer@0 | 33 double max, min, x; |
samer@0 | 34 int n=M.getRowDimension(); |
samer@0 | 35 int m=M.getColumnDimension(); |
samer@0 | 36 |
samer@0 | 37 min=max=M.get(0,0); |
samer@0 | 38 for (int i=0; i<n; i++) { |
samer@0 | 39 for (int j=0; j<m; j++) { |
samer@0 | 40 x=M.get(i,j); |
samer@0 | 41 if (x>max) max=x; |
samer@0 | 42 if (x<min) min=x; |
samer@0 | 43 } |
samer@0 | 44 } |
samer@0 | 45 |
samer@0 | 46 getVMap().setDomain(min,max); |
samer@0 | 47 getVMap().changed(this); |
samer@0 | 48 } |
samer@0 | 49 |
samer@0 | 50 public static Viewer getViewerFor(Matrix M) |
samer@0 | 51 { |
samer@0 | 52 Shell.push(new Node("image",M.getNode())); |
samer@0 | 53 Viewer vwr = new MatrixImage(M); |
samer@0 | 54 Shell.pop(); |
samer@0 | 55 |
samer@0 | 56 return vwr; |
samer@0 | 57 } |
samer@0 | 58 } |