Mercurial > hg > jslab
diff src/samer/j3d/MatrixPoints4D.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/j3d/MatrixPoints4D.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,80 @@ +package samer.j3d; + +import samer.core.types.*; +import samer.maths.*; +import java.util.*; +import java.awt.Color; +import javax.media.j3d.*; +import javax.vecmath.*; + + +public class MatrixPoints4D extends PointArray implements Observer +{ + int N; // number of points + Matrix P; // 3d positions of points + VVector A; // scalar activations + VDouble K; // scaling factor for activations + + Color4f carray[]; + + public MatrixPoints4D(Matrix points, VVector activities) + { + super(points.getRowDimension(), COORDINATES | COLOR_4); + + N=points.getRowDimension(); + P=points; + A=activities; + K=new VDouble("scale",1); + + carray=new Color4f[N]; + for (int i=0; i<N; i++) carray[i]=new Color4f(); + + // set capabilities for subsequent updates + setCapability(ALLOW_COORDINATE_WRITE); + setCapability(ALLOW_COLOR_WRITE); + + updatePoints(); + updateActivities(); + + A.addObserver(this); + P.addObserver(new Observer () { + public void update(Observable o, Object a) { + updatePoints(); + } + }); + } + + + public void update(Observable o, Object a) + { + updateActivities(); + } + + public void updatePoints() + { + // load points into point array + double [][] PA=P.getArray(); + double [] row; + + for (int i=0; i<N; i++) { + row=PA[i]; + setCoordinate(i,row); + + // choose color according to 4th dimension + carray[i].set(Color.getHSBColor((float)(row[3]*0.3)+0.16f,1f,1f)); + } + } + + public void updateActivities() + { + // load colours + double [] a=A.array(); + double k=K.value; + + for (int i=0; i<N; i++) { + float ai=(float)(a[i]*k); + carray[i].w=ai; + } + setColors(0,carray); + } +}