Mercurial > hg > jslab
comparison src/samer/j3d/MatrixPoints4D.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 package samer.j3d; | |
2 | |
3 import samer.core.types.*; | |
4 import samer.maths.*; | |
5 import java.util.*; | |
6 import java.awt.Color; | |
7 import javax.media.j3d.*; | |
8 import javax.vecmath.*; | |
9 | |
10 | |
11 public class MatrixPoints4D extends PointArray implements Observer | |
12 { | |
13 int N; // number of points | |
14 Matrix P; // 3d positions of points | |
15 VVector A; // scalar activations | |
16 VDouble K; // scaling factor for activations | |
17 | |
18 Color4f carray[]; | |
19 | |
20 public MatrixPoints4D(Matrix points, VVector activities) | |
21 { | |
22 super(points.getRowDimension(), COORDINATES | COLOR_4); | |
23 | |
24 N=points.getRowDimension(); | |
25 P=points; | |
26 A=activities; | |
27 K=new VDouble("scale",1); | |
28 | |
29 carray=new Color4f[N]; | |
30 for (int i=0; i<N; i++) carray[i]=new Color4f(); | |
31 | |
32 // set capabilities for subsequent updates | |
33 setCapability(ALLOW_COORDINATE_WRITE); | |
34 setCapability(ALLOW_COLOR_WRITE); | |
35 | |
36 updatePoints(); | |
37 updateActivities(); | |
38 | |
39 A.addObserver(this); | |
40 P.addObserver(new Observer () { | |
41 public void update(Observable o, Object a) { | |
42 updatePoints(); | |
43 } | |
44 }); | |
45 } | |
46 | |
47 | |
48 public void update(Observable o, Object a) | |
49 { | |
50 updateActivities(); | |
51 } | |
52 | |
53 public void updatePoints() | |
54 { | |
55 // load points into point array | |
56 double [][] PA=P.getArray(); | |
57 double [] row; | |
58 | |
59 for (int i=0; i<N; i++) { | |
60 row=PA[i]; | |
61 setCoordinate(i,row); | |
62 | |
63 // choose color according to 4th dimension | |
64 carray[i].set(Color.getHSBColor((float)(row[3]*0.3)+0.16f,1f,1f)); | |
65 } | |
66 } | |
67 | |
68 public void updateActivities() | |
69 { | |
70 // load colours | |
71 double [] a=A.array(); | |
72 double k=K.value; | |
73 | |
74 for (int i=0; i<N; i++) { | |
75 float ai=(float)(a[i]*k); | |
76 carray[i].w=ai; | |
77 } | |
78 setColors(0,carray); | |
79 } | |
80 } |