2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: Content3D.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.7 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 20:59:53 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev.cluster.gui.impl.pca; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.BorderLayout; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Font; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.FontMetrics; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.GraphicsConfiguration; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
21 |
|
2 |
26 Feb 07 |
jari |
22 |
import javax.media.j3d.AmbientLight; |
2 |
26 Feb 07 |
jari |
23 |
import javax.media.j3d.Appearance; |
2 |
26 Feb 07 |
jari |
24 |
import javax.media.j3d.Background; |
2 |
26 Feb 07 |
jari |
25 |
import javax.media.j3d.BoundingSphere; |
2 |
26 Feb 07 |
jari |
26 |
import javax.media.j3d.BranchGroup; |
2 |
26 Feb 07 |
jari |
27 |
import javax.media.j3d.Canvas3D; |
2 |
26 Feb 07 |
jari |
28 |
import javax.media.j3d.ColoringAttributes; |
2 |
26 Feb 07 |
jari |
29 |
import javax.media.j3d.Font3D; |
2 |
26 Feb 07 |
jari |
30 |
import javax.media.j3d.FontExtrusion; |
2 |
26 Feb 07 |
jari |
31 |
import javax.media.j3d.ImageComponent; |
2 |
26 Feb 07 |
jari |
32 |
import javax.media.j3d.ImageComponent2D; |
2 |
26 Feb 07 |
jari |
33 |
import javax.media.j3d.Light; |
2 |
26 Feb 07 |
jari |
34 |
import javax.media.j3d.LineAttributes; |
2 |
26 Feb 07 |
jari |
35 |
import javax.media.j3d.Material; |
2 |
26 Feb 07 |
jari |
36 |
import javax.media.j3d.PointArray; |
2 |
26 Feb 07 |
jari |
37 |
import javax.media.j3d.PointAttributes; |
2 |
26 Feb 07 |
jari |
38 |
import javax.media.j3d.PointLight; |
2 |
26 Feb 07 |
jari |
39 |
import javax.media.j3d.Screen3D; |
2 |
26 Feb 07 |
jari |
40 |
import javax.media.j3d.Shape3D; |
2 |
26 Feb 07 |
jari |
41 |
import javax.media.j3d.Text3D; |
2 |
26 Feb 07 |
jari |
42 |
import javax.media.j3d.Transform3D; |
2 |
26 Feb 07 |
jari |
43 |
import javax.media.j3d.TransformGroup; |
2 |
26 Feb 07 |
jari |
44 |
import javax.media.j3d.TransparencyAttributes; |
2 |
26 Feb 07 |
jari |
45 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
46 |
import javax.vecmath.Color3f; |
2 |
26 Feb 07 |
jari |
47 |
import javax.vecmath.Point3d; |
2 |
26 Feb 07 |
jari |
48 |
import javax.vecmath.Point3f; |
2 |
26 Feb 07 |
jari |
49 |
import javax.vecmath.Vector3d; |
2 |
26 Feb 07 |
jari |
50 |
import javax.vecmath.Vector3f; |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
53 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
54 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
import com.sun.j3d.utils.geometry.Box; |
2 |
26 Feb 07 |
jari |
57 |
import com.sun.j3d.utils.geometry.Cone; |
2 |
26 Feb 07 |
jari |
58 |
import com.sun.j3d.utils.geometry.Cylinder; |
2 |
26 Feb 07 |
jari |
59 |
import com.sun.j3d.utils.geometry.Sphere; |
2 |
26 Feb 07 |
jari |
60 |
import com.sun.j3d.utils.picking.behaviors.PickRotateBehavior; |
2 |
26 Feb 07 |
jari |
61 |
import com.sun.j3d.utils.picking.behaviors.PickTranslateBehavior; |
2 |
26 Feb 07 |
jari |
62 |
import com.sun.j3d.utils.picking.behaviors.PickZoomBehavior; |
2 |
26 Feb 07 |
jari |
63 |
import com.sun.j3d.utils.universe.SimpleUniverse; |
2 |
26 Feb 07 |
jari |
64 |
|
2 |
26 Feb 07 |
jari |
65 |
public class Content3D extends JPanel { |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
private IData data; |
2 |
26 Feb 07 |
jari |
68 |
private int mode; |
2 |
26 Feb 07 |
jari |
69 |
private int xAxis, yAxis, zAxis; |
2 |
26 Feb 07 |
jari |
70 |
private int geneLabelIndex; |
2 |
26 Feb 07 |
jari |
71 |
private FloatMatrix U; |
2 |
26 Feb 07 |
jari |
72 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
73 |
private SimpleUniverse universe; |
2 |
26 Feb 07 |
jari |
74 |
private Canvas3D onScreenCanvas; |
2 |
26 Feb 07 |
jari |
75 |
private Canvas3D offScreenCanvas; |
2 |
26 Feb 07 |
jari |
76 |
private BranchGroup scene; |
2 |
26 Feb 07 |
jari |
77 |
private TransformGroup spinGroup; |
2 |
26 Feb 07 |
jari |
78 |
private boolean whiteBackground = false; |
2 |
26 Feb 07 |
jari |
79 |
private boolean selection = false; |
2 |
26 Feb 07 |
jari |
80 |
private boolean selectionBox = false; |
2 |
26 Feb 07 |
jari |
81 |
private boolean showSpheres = false; |
2 |
26 Feb 07 |
jari |
82 |
private boolean showText = false; |
2 |
26 Feb 07 |
jari |
83 |
private boolean geneViewer = true; |
2 |
26 Feb 07 |
jari |
84 |
private float scaleAxisX = 3f; |
2 |
26 Feb 07 |
jari |
85 |
private float scaleAxisY = 3f; |
2 |
26 Feb 07 |
jari |
86 |
private float scaleAxisZ = 3f; |
2 |
26 Feb 07 |
jari |
87 |
private float boxSizeX = 5f; |
2 |
26 Feb 07 |
jari |
88 |
private float boxSizeY = 5f; |
2 |
26 Feb 07 |
jari |
89 |
private float boxSizeZ = 5f; |
2 |
26 Feb 07 |
jari |
90 |
private float boxPositionX = 0f; |
2 |
26 Feb 07 |
jari |
91 |
private float boxPositionY = 0f; |
2 |
26 Feb 07 |
jari |
92 |
private float boxPositionZ = 0f; |
2 |
26 Feb 07 |
jari |
93 |
private float pointSize = 1.0f; |
2 |
26 Feb 07 |
jari |
94 |
private float selectedPointSize = 1.0f; |
2 |
26 Feb 07 |
jari |
95 |
private Color3f blackColor = new Color3f(0f, 0f, 0f); |
2 |
26 Feb 07 |
jari |
// private Color3f whiteColor = new Color3f(0.8f, 0.8f, 0.8f); |
2 |
26 Feb 07 |
jari |
//private Color3f whiteColor = new Color3f(0.98f, 0.98f, 0.98f); |
2 |
26 Feb 07 |
jari |
98 |
private Color3f whiteColor = new Color3f(1f, 1f, 1f); |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>Content3D</code> with specified mode, |
2 |
26 Feb 07 |
jari |
* U-matrix and an experiment data. |
2 |
26 Feb 07 |
jari |
103 |
* |
2 |
26 Feb 07 |
jari |
* @param mode the annotations drawing mode. |
2 |
26 Feb 07 |
jari |
* @param U the pca U-matrix. |
2 |
26 Feb 07 |
jari |
* @param experiment the experiment data. |
2 |
26 Feb 07 |
jari |
107 |
*/ |
2 |
26 Feb 07 |
jari |
108 |
public Content3D(int mode, FloatMatrix U, Experiment experiment) { |
2 |
26 Feb 07 |
jari |
109 |
this.mode = mode; |
2 |
26 Feb 07 |
jari |
110 |
this.U = U; |
2 |
26 Feb 07 |
jari |
111 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
112 |
initScales(U); |
2 |
26 Feb 07 |
jari |
113 |
setLayout(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
114 |
setPreferredSize(new Dimension(10, 10)); |
2 |
26 Feb 07 |
jari |
115 |
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); |
2 |
26 Feb 07 |
jari |
116 |
this.onScreenCanvas = new Canvas3D(config); |
2 |
26 Feb 07 |
jari |
117 |
this.universe = new SimpleUniverse(onScreenCanvas); |
2 |
26 Feb 07 |
jari |
118 |
universe.getViewingPlatform().setNominalViewingTransform(); |
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
120 |
boxSizeX = (float)(scaleAxisX/5f); |
2 |
26 Feb 07 |
jari |
121 |
boxSizeY = (float)(scaleAxisY/5f); |
2 |
26 Feb 07 |
jari |
122 |
boxSizeZ = (float)(scaleAxisZ/5f); |
2 |
26 Feb 07 |
jari |
//System.out.println("boxSize X, Y, Z = " + boxSizeX + ", " +boxSizeY + ", " + boxSizeZ); |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
125 |
offScreenCanvas = new Canvas3D(config, true); |
2 |
26 Feb 07 |
jari |
126 |
Screen3D sOn = onScreenCanvas.getScreen3D(); |
2 |
26 Feb 07 |
jari |
127 |
Screen3D sOff = offScreenCanvas.getScreen3D(); |
2 |
26 Feb 07 |
jari |
128 |
sOff.setSize(sOn.getSize()); |
2 |
26 Feb 07 |
jari |
129 |
sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); |
2 |
26 Feb 07 |
jari |
130 |
sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); |
2 |
26 Feb 07 |
jari |
// attach the offscreen canvas to the view |
2 |
26 Feb 07 |
jari |
132 |
universe.getViewer().getView().addCanvas3D(offScreenCanvas); |
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
add(onScreenCanvas, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
135 |
} |
2 |
26 Feb 07 |
jari |
136 |
|
2 |
26 Feb 07 |
jari |
137 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>Content3D</code> with specified mode, |
2 |
26 Feb 07 |
jari |
* U-matrix and an experiment data. |
2 |
26 Feb 07 |
jari |
140 |
* |
2 |
26 Feb 07 |
jari |
* @param mode the annotations drawing mode. |
2 |
26 Feb 07 |
jari |
* @param U the pca U-matrix. |
2 |
26 Feb 07 |
jari |
* @param experiment the experiment data. |
2 |
26 Feb 07 |
jari |
144 |
*/ |
2 |
26 Feb 07 |
jari |
145 |
public Content3D(int mode, FloatMatrix U, Experiment experiment, boolean geneViewer) { |
2 |
26 Feb 07 |
jari |
146 |
this.mode = mode; |
2 |
26 Feb 07 |
jari |
147 |
this.U = U; |
2 |
26 Feb 07 |
jari |
148 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
149 |
this.geneViewer = geneViewer; |
2 |
26 Feb 07 |
jari |
150 |
initScales(U); |
2 |
26 Feb 07 |
jari |
151 |
setLayout(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
152 |
setPreferredSize(new Dimension(10, 10)); |
2 |
26 Feb 07 |
jari |
153 |
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); |
2 |
26 Feb 07 |
jari |
154 |
this.onScreenCanvas = new Canvas3D(config); |
2 |
26 Feb 07 |
jari |
155 |
this.universe = new SimpleUniverse(onScreenCanvas); |
2 |
26 Feb 07 |
jari |
156 |
universe.getViewingPlatform().setNominalViewingTransform(); |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
boxSizeX = (float)(scaleAxisX/5f); |
2 |
26 Feb 07 |
jari |
159 |
boxSizeY = (float)(scaleAxisY/5f); |
2 |
26 Feb 07 |
jari |
160 |
boxSizeZ = (float)(scaleAxisZ/5f); |
2 |
26 Feb 07 |
jari |
161 |
|
2 |
26 Feb 07 |
jari |
162 |
offScreenCanvas = new Canvas3D(config, true); |
2 |
26 Feb 07 |
jari |
163 |
Screen3D sOn = onScreenCanvas.getScreen3D(); |
2 |
26 Feb 07 |
jari |
164 |
Screen3D sOff = offScreenCanvas.getScreen3D(); |
2 |
26 Feb 07 |
jari |
165 |
sOff.setSize(sOn.getSize()); |
2 |
26 Feb 07 |
jari |
166 |
sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); |
2 |
26 Feb 07 |
jari |
167 |
sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); |
2 |
26 Feb 07 |
jari |
// attach the offscreen canvas to the view |
2 |
26 Feb 07 |
jari |
169 |
universe.getViewer().getView().addCanvas3D(offScreenCanvas); |
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
171 |
add(onScreenCanvas, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
172 |
} |
2 |
26 Feb 07 |
jari |
173 |
|
2 |
26 Feb 07 |
jari |
174 |
public Content3D(int mode, FloatMatrix U, Experiment experiment, boolean geneViewer, int xAxis, int yAxis, int zAxis) { |
2 |
26 Feb 07 |
jari |
175 |
this.mode = mode; |
2 |
26 Feb 07 |
jari |
176 |
this.U = U; |
2 |
26 Feb 07 |
jari |
177 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
178 |
this.geneViewer = geneViewer; |
2 |
26 Feb 07 |
jari |
179 |
this.xAxis = xAxis; |
2 |
26 Feb 07 |
jari |
180 |
this.yAxis = yAxis; |
2 |
26 Feb 07 |
jari |
181 |
this.zAxis = zAxis; |
2 |
26 Feb 07 |
jari |
182 |
initScales(U); |
2 |
26 Feb 07 |
jari |
183 |
setLayout(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
184 |
setPreferredSize(new Dimension(10, 10)); |
2 |
26 Feb 07 |
jari |
185 |
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); |
2 |
26 Feb 07 |
jari |
186 |
this.onScreenCanvas = new Canvas3D(config); |
2 |
26 Feb 07 |
jari |
187 |
this.universe = new SimpleUniverse(onScreenCanvas); |
2 |
26 Feb 07 |
jari |
188 |
universe.getViewingPlatform().setNominalViewingTransform(); |
2 |
26 Feb 07 |
jari |
189 |
|
2 |
26 Feb 07 |
jari |
190 |
boxSizeX = (float)(scaleAxisX/5f); |
2 |
26 Feb 07 |
jari |
191 |
boxSizeY = (float)(scaleAxisY/5f); |
2 |
26 Feb 07 |
jari |
192 |
boxSizeZ = (float)(scaleAxisZ/5f); |
2 |
26 Feb 07 |
jari |
193 |
|
2 |
26 Feb 07 |
jari |
194 |
offScreenCanvas = new Canvas3D(config, true); |
2 |
26 Feb 07 |
jari |
195 |
Screen3D sOn = onScreenCanvas.getScreen3D(); |
2 |
26 Feb 07 |
jari |
196 |
Screen3D sOff = offScreenCanvas.getScreen3D(); |
2 |
26 Feb 07 |
jari |
197 |
sOff.setSize(sOn.getSize()); |
2 |
26 Feb 07 |
jari |
198 |
sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); |
2 |
26 Feb 07 |
jari |
199 |
sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); |
2 |
26 Feb 07 |
jari |
// attach the offscreen canvas to the view |
2 |
26 Feb 07 |
jari |
201 |
universe.getViewer().getView().addCanvas3D(offScreenCanvas); |
2 |
26 Feb 07 |
jari |
202 |
|
2 |
26 Feb 07 |
jari |
203 |
add(onScreenCanvas, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
204 |
} |
2 |
26 Feb 07 |
jari |
205 |
|
2 |
26 Feb 07 |
jari |
206 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the content data. |
2 |
26 Feb 07 |
jari |
208 |
*/ |
2 |
26 Feb 07 |
jari |
209 |
public void setData(IData data) { |
2 |
26 Feb 07 |
jari |
210 |
this.data = data; |
2 |
26 Feb 07 |
jari |
211 |
} |
2 |
26 Feb 07 |
jari |
212 |
|
2 |
26 Feb 07 |
jari |
213 |
/** |
2 |
26 Feb 07 |
jari |
* Returns x coordinate of the selection box. |
2 |
26 Feb 07 |
jari |
215 |
*/ |
2 |
26 Feb 07 |
jari |
216 |
public float getPositionX() { |
2 |
26 Feb 07 |
jari |
217 |
return boxPositionX; |
2 |
26 Feb 07 |
jari |
218 |
} |
2 |
26 Feb 07 |
jari |
219 |
|
2 |
26 Feb 07 |
jari |
220 |
/** |
2 |
26 Feb 07 |
jari |
* Returns y coordinate of the selection box. |
2 |
26 Feb 07 |
jari |
222 |
*/ |
2 |
26 Feb 07 |
jari |
223 |
public float getPositionY() { |
2 |
26 Feb 07 |
jari |
224 |
return boxPositionY; |
2 |
26 Feb 07 |
jari |
225 |
} |
2 |
26 Feb 07 |
jari |
226 |
|
2 |
26 Feb 07 |
jari |
227 |
/** |
2 |
26 Feb 07 |
jari |
* Returns z coordinate of the selection box. |
2 |
26 Feb 07 |
jari |
229 |
*/ |
2 |
26 Feb 07 |
jari |
230 |
public float getPositionZ() { |
2 |
26 Feb 07 |
jari |
231 |
return boxPositionZ; |
2 |
26 Feb 07 |
jari |
232 |
} |
2 |
26 Feb 07 |
jari |
233 |
|
2 |
26 Feb 07 |
jari |
234 |
/** |
2 |
26 Feb 07 |
jari |
* Returns x size of the selection box. |
2 |
26 Feb 07 |
jari |
236 |
*/ |
2 |
26 Feb 07 |
jari |
237 |
public float getSizeX() { |
2 |
26 Feb 07 |
jari |
238 |
return boxSizeX; |
2 |
26 Feb 07 |
jari |
239 |
} |
2 |
26 Feb 07 |
jari |
240 |
|
2 |
26 Feb 07 |
jari |
241 |
/** |
2 |
26 Feb 07 |
jari |
* Returns y size of the selection box. |
2 |
26 Feb 07 |
jari |
243 |
*/ |
2 |
26 Feb 07 |
jari |
244 |
public float getSizeY() { |
2 |
26 Feb 07 |
jari |
245 |
return boxSizeY; |
2 |
26 Feb 07 |
jari |
246 |
} |
2 |
26 Feb 07 |
jari |
247 |
|
2 |
26 Feb 07 |
jari |
248 |
/** |
2 |
26 Feb 07 |
jari |
* Returns z size of the selection box. |
2 |
26 Feb 07 |
jari |
250 |
*/ |
2 |
26 Feb 07 |
jari |
251 |
public float getSizeZ() { |
2 |
26 Feb 07 |
jari |
252 |
return boxSizeZ; |
2 |
26 Feb 07 |
jari |
253 |
} |
2 |
26 Feb 07 |
jari |
254 |
|
2 |
26 Feb 07 |
jari |
255 |
public void setGeneLabelIndex(int index){ |
2 |
26 Feb 07 |
jari |
256 |
geneLabelIndex = index; |
2 |
26 Feb 07 |
jari |
257 |
} |
2 |
26 Feb 07 |
jari |
258 |
|
2 |
26 Feb 07 |
jari |
259 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the selection box position. |
2 |
26 Feb 07 |
jari |
261 |
*/ |
2 |
26 Feb 07 |
jari |
262 |
public void setBoxPosition(float dimX, float dimY, float dimZ) { |
2 |
26 Feb 07 |
jari |
263 |
boxPositionX = dimX; |
2 |
26 Feb 07 |
jari |
264 |
boxPositionY = dimY; |
2 |
26 Feb 07 |
jari |
265 |
boxPositionZ = dimZ; |
2 |
26 Feb 07 |
jari |
266 |
} |
2 |
26 Feb 07 |
jari |
267 |
|
2 |
26 Feb 07 |
jari |
268 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the selection box size. |
2 |
26 Feb 07 |
jari |
270 |
*/ |
2 |
26 Feb 07 |
jari |
271 |
public void setBoxSize(float dimX, float dimY, float dimZ) { |
2 |
26 Feb 07 |
jari |
272 |
boxSizeX = dimX; |
2 |
26 Feb 07 |
jari |
273 |
boxSizeY = dimY; |
2 |
26 Feb 07 |
jari |
274 |
boxSizeZ = dimZ; |
2 |
26 Feb 07 |
jari |
275 |
} |
2 |
26 Feb 07 |
jari |
276 |
|
2 |
26 Feb 07 |
jari |
277 |
/** |
2 |
26 Feb 07 |
jari |
* Returns size of a selected point. |
2 |
26 Feb 07 |
jari |
279 |
*/ |
2 |
26 Feb 07 |
jari |
280 |
public float getSelectedPointSize() { |
2 |
26 Feb 07 |
jari |
281 |
return selectedPointSize; |
2 |
26 Feb 07 |
jari |
282 |
} |
2 |
26 Feb 07 |
jari |
283 |
|
2 |
26 Feb 07 |
jari |
284 |
/** |
2 |
26 Feb 07 |
jari |
* Sets size of a selected point. |
2 |
26 Feb 07 |
jari |
286 |
*/ |
2 |
26 Feb 07 |
jari |
287 |
public void setSelectedPointSize(float size) { |
2 |
26 Feb 07 |
jari |
288 |
selectedPointSize = size; |
2 |
26 Feb 07 |
jari |
289 |
} |
2 |
26 Feb 07 |
jari |
290 |
|
2 |
26 Feb 07 |
jari |
291 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a point size. |
2 |
26 Feb 07 |
jari |
293 |
*/ |
2 |
26 Feb 07 |
jari |
294 |
public float getPointSize() { |
2 |
26 Feb 07 |
jari |
295 |
return pointSize; |
2 |
26 Feb 07 |
jari |
296 |
} |
2 |
26 Feb 07 |
jari |
297 |
|
2 |
26 Feb 07 |
jari |
298 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a specified point size. |
2 |
26 Feb 07 |
jari |
300 |
*/ |
2 |
26 Feb 07 |
jari |
301 |
private float getPointSize(boolean selected) { |
2 |
26 Feb 07 |
jari |
302 |
return selected ? getSelectedPointSize() : getPointSize(); |
2 |
26 Feb 07 |
jari |
303 |
} |
2 |
26 Feb 07 |
jari |
304 |
|
2 |
26 Feb 07 |
jari |
305 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a point size. |
2 |
26 Feb 07 |
jari |
307 |
*/ |
2 |
26 Feb 07 |
jari |
308 |
public void setPointSize(float size) { |
2 |
26 Feb 07 |
jari |
309 |
pointSize = size; |
2 |
26 Feb 07 |
jari |
310 |
} |
2 |
26 Feb 07 |
jari |
311 |
|
2 |
26 Feb 07 |
jari |
312 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a scale of the x axis. |
2 |
26 Feb 07 |
jari |
314 |
*/ |
2 |
26 Feb 07 |
jari |
315 |
public float getScaleAxisX() { |
2 |
26 Feb 07 |
jari |
316 |
return scaleAxisX; |
2 |
26 Feb 07 |
jari |
317 |
} |
2 |
26 Feb 07 |
jari |
318 |
|
2 |
26 Feb 07 |
jari |
319 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a scale of the y axis. |
2 |
26 Feb 07 |
jari |
321 |
*/ |
2 |
26 Feb 07 |
jari |
322 |
public float getScaleAxisY() { |
2 |
26 Feb 07 |
jari |
323 |
return scaleAxisY; |
2 |
26 Feb 07 |
jari |
324 |
} |
2 |
26 Feb 07 |
jari |
325 |
|
2 |
26 Feb 07 |
jari |
326 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a scale of the z axis. |
2 |
26 Feb 07 |
jari |
328 |
*/ |
2 |
26 Feb 07 |
jari |
329 |
public float getScaleAxisZ() { |
2 |
26 Feb 07 |
jari |
330 |
return scaleAxisZ; |
2 |
26 Feb 07 |
jari |
331 |
} |
2 |
26 Feb 07 |
jari |
332 |
|
2 |
26 Feb 07 |
jari |
333 |
/** |
2 |
26 Feb 07 |
jari |
* Sets scales. |
2 |
26 Feb 07 |
jari |
335 |
*/ |
2 |
26 Feb 07 |
jari |
336 |
public void setScale(float dimX, float dimY, float dimZ) { |
2 |
26 Feb 07 |
jari |
337 |
scaleAxisX = dimX; |
2 |
26 Feb 07 |
jari |
338 |
scaleAxisY = dimY; |
2 |
26 Feb 07 |
jari |
339 |
scaleAxisZ = dimZ; |
2 |
26 Feb 07 |
jari |
340 |
} |
2 |
26 Feb 07 |
jari |
341 |
|
2 |
26 Feb 07 |
jari |
342 |
public float getMaxValue() { |
2 |
26 Feb 07 |
jari |
343 |
return Math.max(scaleAxisX, Math.max(scaleAxisY, scaleAxisZ)); |
2 |
26 Feb 07 |
jari |
344 |
} |
2 |
26 Feb 07 |
jari |
345 |
|
2 |
26 Feb 07 |
jari |
346 |
/** |
2 |
26 Feb 07 |
jari |
* Sets white background attribute. |
2 |
26 Feb 07 |
jari |
348 |
*/ |
2 |
26 Feb 07 |
jari |
349 |
public void setWhiteBackround(boolean value) { |
2 |
26 Feb 07 |
jari |
350 |
whiteBackground = value; |
2 |
26 Feb 07 |
jari |
351 |
} |
2 |
26 Feb 07 |
jari |
352 |
|
2 |
26 Feb 07 |
jari |
353 |
/** |
2 |
26 Feb 07 |
jari |
* @return true, if background is white. |
2 |
26 Feb 07 |
jari |
355 |
*/ |
2 |
26 Feb 07 |
jari |
356 |
public boolean isWhiteBackground() { |
2 |
26 Feb 07 |
jari |
357 |
return whiteBackground; |
2 |
26 Feb 07 |
jari |
358 |
} |
2 |
26 Feb 07 |
jari |
359 |
|
2 |
26 Feb 07 |
jari |
360 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the selection attribute. |
2 |
26 Feb 07 |
jari |
362 |
*/ |
2 |
26 Feb 07 |
jari |
363 |
public void setSelection(boolean value) { |
2 |
26 Feb 07 |
jari |
364 |
selection = value; |
2 |
26 Feb 07 |
jari |
365 |
} |
2 |
26 Feb 07 |
jari |
366 |
|
2 |
26 Feb 07 |
jari |
367 |
/** |
2 |
26 Feb 07 |
jari |
* Returns value of the selection attribute. |
2 |
26 Feb 07 |
jari |
369 |
*/ |
2 |
26 Feb 07 |
jari |
370 |
public boolean isSelection() { |
2 |
26 Feb 07 |
jari |
371 |
return selection; |
2 |
26 Feb 07 |
jari |
372 |
} |
2 |
26 Feb 07 |
jari |
373 |
|
2 |
26 Feb 07 |
jari |
374 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the selection box attribute. |
2 |
26 Feb 07 |
jari |
376 |
*/ |
2 |
26 Feb 07 |
jari |
377 |
public void setSelectionBox(boolean value) { |
2 |
26 Feb 07 |
jari |
378 |
selectionBox = value; |
2 |
26 Feb 07 |
jari |
379 |
} |
2 |
26 Feb 07 |
jari |
380 |
|
2 |
26 Feb 07 |
jari |
381 |
/** |
2 |
26 Feb 07 |
jari |
* Returns value of the selection box attribute. |
2 |
26 Feb 07 |
jari |
383 |
*/ |
2 |
26 Feb 07 |
jari |
384 |
public boolean isSelectionBox() { |
2 |
26 Feb 07 |
jari |
385 |
return selectionBox; |
2 |
26 Feb 07 |
jari |
386 |
} |
2 |
26 Feb 07 |
jari |
387 |
|
2 |
26 Feb 07 |
jari |
388 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the show spheres attribute. |
2 |
26 Feb 07 |
jari |
390 |
*/ |
2 |
26 Feb 07 |
jari |
391 |
public void setShowSpheres(boolean value) { |
2 |
26 Feb 07 |
jari |
392 |
showSpheres = value; |
2 |
26 Feb 07 |
jari |
393 |
} |
2 |
26 Feb 07 |
jari |
394 |
|
2 |
26 Feb 07 |
jari |
395 |
/** |
2 |
26 Feb 07 |
jari |
* Returns value of the show spheres attribute. |
2 |
26 Feb 07 |
jari |
397 |
*/ |
2 |
26 Feb 07 |
jari |
398 |
public boolean isShowSpheres() { |
2 |
26 Feb 07 |
jari |
399 |
return showSpheres; |
2 |
26 Feb 07 |
jari |
400 |
} |
2 |
26 Feb 07 |
jari |
401 |
|
2 |
26 Feb 07 |
jari |
402 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the show text attribute. |
2 |
26 Feb 07 |
jari |
404 |
*/ |
2 |
26 Feb 07 |
jari |
405 |
public void setShowText(boolean value) { |
2 |
26 Feb 07 |
jari |
406 |
showText = value; |
2 |
26 Feb 07 |
jari |
407 |
} |
2 |
26 Feb 07 |
jari |
408 |
|
2 |
26 Feb 07 |
jari |
409 |
/** |
2 |
26 Feb 07 |
jari |
* Returns value of the show text attribute. |
2 |
26 Feb 07 |
jari |
411 |
*/ |
2 |
26 Feb 07 |
jari |
412 |
public boolean isShowText() { |
2 |
26 Feb 07 |
jari |
413 |
return showText; |
2 |
26 Feb 07 |
jari |
414 |
} |
2 |
26 Feb 07 |
jari |
415 |
|
2 |
26 Feb 07 |
jari |
416 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the content image. |
2 |
26 Feb 07 |
jari |
418 |
*/ |
2 |
26 Feb 07 |
jari |
419 |
public BufferedImage createImage() { |
2 |
26 Feb 07 |
jari |
// ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGB, (BufferedImage)this.createImage(onScreenCanvas.getWidth(), onScreenCanvas.getHeight())); |
2 |
26 Feb 07 |
jari |
421 |
ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGB, (BufferedImage)java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(onScreenCanvas.getWidth(), onScreenCanvas.getHeight())); |
2 |
26 Feb 07 |
jari |
422 |
offScreenCanvas.setOffScreenLocation(onScreenCanvas.getLocationOnScreen()); |
2 |
26 Feb 07 |
jari |
423 |
offScreenCanvas.setOffScreenBuffer(buffer); |
2 |
26 Feb 07 |
jari |
424 |
offScreenCanvas.renderOffScreenBuffer(); |
2 |
26 Feb 07 |
jari |
425 |
offScreenCanvas.waitForOffScreenRendering(); |
2 |
26 Feb 07 |
jari |
426 |
BufferedImage offImage = offScreenCanvas.getOffScreenBuffer().getImage(); |
2 |
26 Feb 07 |
jari |
427 |
BufferedImage image = new BufferedImage(offImage.getWidth(), offImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR); |
2 |
26 Feb 07 |
jari |
//BufferedImage image = (BufferedImage)this.createImage(offImage.getWidth(), offImage.getHeight()); |
2 |
26 Feb 07 |
jari |
//BufferedImage image = (BufferedImage)java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(offImage.getWidth(), offImage.getHeight()); |
2 |
26 Feb 07 |
jari |
430 |
image.setData(offImage.getData()); |
2 |
26 Feb 07 |
jari |
431 |
return image; |
2 |
26 Feb 07 |
jari |
432 |
} |
2 |
26 Feb 07 |
jari |
433 |
|
2 |
26 Feb 07 |
jari |
434 |
/** |
2 |
26 Feb 07 |
jari |
* Resets spin coordinaties. |
2 |
26 Feb 07 |
jari |
436 |
*/ |
2 |
26 Feb 07 |
jari |
437 |
public void reset() { |
2 |
26 Feb 07 |
jari |
438 |
spinGroup.setTransform(new Transform3D()); |
2 |
26 Feb 07 |
jari |
439 |
} |
2 |
26 Feb 07 |
jari |
440 |
|
2 |
26 Feb 07 |
jari |
441 |
/** |
2 |
26 Feb 07 |
jari |
* Updates the universe scene. |
2 |
26 Feb 07 |
jari |
443 |
*/ |
2 |
26 Feb 07 |
jari |
444 |
protected void updateScene() { |
2 |
26 Feb 07 |
jari |
445 |
Transform3D spinTransform = new Transform3D(); |
2 |
26 Feb 07 |
jari |
446 |
if (scene != null) { |
2 |
26 Feb 07 |
jari |
447 |
spinGroup.getTransform(spinTransform); |
2 |
26 Feb 07 |
jari |
448 |
scene.detach(); |
2 |
26 Feb 07 |
jari |
449 |
} |
2 |
26 Feb 07 |
jari |
450 |
this.scene = createSceneGraph(onScreenCanvas, spinTransform); |
2 |
26 Feb 07 |
jari |
451 |
universe.addBranchGraph(scene); |
2 |
26 Feb 07 |
jari |
452 |
} |
2 |
26 Feb 07 |
jari |
453 |
|
2 |
26 Feb 07 |
jari |
454 |
/** |
2 |
26 Feb 07 |
jari |
* Sets scales according to U-matrix values. |
2 |
26 Feb 07 |
jari |
456 |
*/ |
2 |
26 Feb 07 |
jari |
457 |
private void initScales(FloatMatrix U) { |
2 |
26 Feb 07 |
jari |
458 |
float max = 0f; |
2 |
26 Feb 07 |
jari |
459 |
final int rows = U.getRowDimension(); |
2 |
26 Feb 07 |
jari |
460 |
for (int i = rows; --i >= 0;) { |
2 |
26 Feb 07 |
jari |
//max = Math.max(max, Math.max(Math.max(Math.abs(U.get(i, 0)), Math.abs(U.get(i, 1))), Math.abs(U.get(i, 2)))); |
2 |
26 Feb 07 |
jari |
462 |
max = Math.max(max, Math.max(Math.max(Math.abs(U.get(i, xAxis)), Math.abs(U.get(i, yAxis))), Math.abs(U.get(i, zAxis)))); |
2 |
26 Feb 07 |
jari |
463 |
} |
2 |
26 Feb 07 |
jari |
464 |
setScale(max, max, max); |
2 |
26 Feb 07 |
jari |
465 |
} |
2 |
26 Feb 07 |
jari |
466 |
|
2 |
26 Feb 07 |
jari |
467 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a branch group with specified canvas. |
2 |
26 Feb 07 |
jari |
469 |
*/ |
2 |
26 Feb 07 |
jari |
470 |
private BranchGroup createSceneGraph(Canvas3D canvas) { |
2 |
26 Feb 07 |
jari |
471 |
return createSceneGraph(canvas, null); |
2 |
26 Feb 07 |
jari |
472 |
} |
2 |
26 Feb 07 |
jari |
473 |
|
2 |
26 Feb 07 |
jari |
474 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a branch group with specified canvas and transformation object. |
2 |
26 Feb 07 |
jari |
476 |
*/ |
2 |
26 Feb 07 |
jari |
477 |
private BranchGroup createSceneGraph(Canvas3D canvas, Transform3D spinTransform) { |
2 |
26 Feb 07 |
jari |
478 |
BranchGroup objRoot = new BranchGroup(); |
2 |
26 Feb 07 |
jari |
479 |
objRoot.setCapability(BranchGroup.ALLOW_DETACH); |
2 |
26 Feb 07 |
jari |
480 |
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); |
2 |
26 Feb 07 |
jari |
481 |
|
2 |
26 Feb 07 |
jari |
482 |
this.spinGroup = createCoordinateSystem(bounds); |
2 |
26 Feb 07 |
jari |
483 |
if (spinTransform != null) { |
2 |
26 Feb 07 |
jari |
484 |
spinGroup.setTransform(spinTransform); |
2 |
26 Feb 07 |
jari |
485 |
} |
2 |
26 Feb 07 |
jari |
486 |
TransformGroup objScale = createScaleTransformGroup(bounds); |
2 |
26 Feb 07 |
jari |
487 |
objScale.addChild(spinGroup); |
2 |
26 Feb 07 |
jari |
488 |
objRoot.addChild(objScale); |
2 |
26 Feb 07 |
jari |
489 |
|
2 |
26 Feb 07 |
jari |
490 |
PickRotateBehavior rotateBehavior = new PickRotateBehavior(objRoot, canvas, bounds); |
2 |
26 Feb 07 |
jari |
491 |
objRoot.addChild(rotateBehavior); |
2 |
26 Feb 07 |
jari |
492 |
PickZoomBehavior zoomBehavior = new PickZoomBehavior(objRoot, canvas, bounds); |
2 |
26 Feb 07 |
jari |
493 |
objRoot.addChild(zoomBehavior); |
2 |
26 Feb 07 |
jari |
494 |
PickTranslateBehavior translateBehavior = new PickTranslateBehavior(objRoot, canvas, bounds); |
2 |
26 Feb 07 |
jari |
495 |
objRoot.addChild(translateBehavior); |
2 |
26 Feb 07 |
jari |
496 |
|
2 |
26 Feb 07 |
jari |
497 |
objRoot.compile(); |
2 |
26 Feb 07 |
jari |
498 |
return objRoot; |
2 |
26 Feb 07 |
jari |
499 |
} |
2 |
26 Feb 07 |
jari |
500 |
|
2 |
26 Feb 07 |
jari |
501 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a scale transform group. |
2 |
26 Feb 07 |
jari |
503 |
*/ |
2 |
26 Feb 07 |
jari |
504 |
private TransformGroup createScaleTransformGroup(BoundingSphere bounds) { |
2 |
26 Feb 07 |
jari |
505 |
Transform3D t = new Transform3D(); |
2 |
26 Feb 07 |
jari |
506 |
t.setScale(0.22); |
2 |
26 Feb 07 |
jari |
507 |
TransformGroup scale = new TransformGroup(t); |
2 |
26 Feb 07 |
jari |
508 |
|
2 |
26 Feb 07 |
jari |
509 |
Color3f bgColor = isWhiteBackground() ? whiteColor : blackColor; |
2 |
26 Feb 07 |
jari |
510 |
Background bg = new Background(bgColor); |
2 |
26 Feb 07 |
jari |
511 |
bg.setApplicationBounds(bounds); |
2 |
26 Feb 07 |
jari |
512 |
scale.addChild(bg); |
2 |
26 Feb 07 |
jari |
513 |
|
2 |
26 Feb 07 |
jari |
514 |
scale.addChild(createAmbientLight(bounds)); |
2 |
26 Feb 07 |
jari |
515 |
scale.addChild(createLight(bounds, new Vector3d(0.0, 0.0, 3.0))); |
2 |
26 Feb 07 |
jari |
516 |
scale.addChild(createLight(bounds, new Vector3d(0.0, 0.0, 10.0))); |
2 |
26 Feb 07 |
jari |
517 |
return scale; |
2 |
26 Feb 07 |
jari |
518 |
} |
2 |
26 Feb 07 |
jari |
519 |
|
2 |
26 Feb 07 |
jari |
520 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a coordinate system transform group. |
2 |
26 Feb 07 |
jari |
522 |
*/ |
2 |
26 Feb 07 |
jari |
523 |
private TransformGroup createCoordinateSystem(BoundingSphere bounds) { |
2 |
26 Feb 07 |
jari |
524 |
TransformGroup group = new TransformGroup(); |
2 |
26 Feb 07 |
jari |
525 |
group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); |
2 |
26 Feb 07 |
jari |
526 |
group.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); |
2 |
26 Feb 07 |
jari |
527 |
group.setCapability(TransformGroup.ENABLE_PICK_REPORTING); |
2 |
26 Feb 07 |
jari |
// add axises |
2 |
26 Feb 07 |
jari |
529 |
group.addChild(createXAxis()); |
2 |
26 Feb 07 |
jari |
530 |
group.addChild(createYAxis()); |
2 |
26 Feb 07 |
jari |
531 |
group.addChild(createZAxis()); |
2 |
26 Feb 07 |
jari |
532 |
|
2 |
26 Feb 07 |
jari |
533 |
if (isShowSpheres()) { |
2 |
26 Feb 07 |
jari |
// add spheres |
2 |
26 Feb 07 |
jari |
535 |
group.addChild(createSpheres()); |
2 |
26 Feb 07 |
jari |
536 |
} else { |
2 |
26 Feb 07 |
jari |
// add selected and not selected points |
2 |
26 Feb 07 |
jari |
538 |
if (getPointSize() > 0) { |
2 |
26 Feb 07 |
jari |
539 |
Shape3D[] pointShapes = createUsualPoints(); |
2 |
26 Feb 07 |
jari |
540 |
if (pointShapes != null) { |
2 |
26 Feb 07 |
jari |
541 |
for (int i=0; i<pointShapes.length; i++) { |
2 |
26 Feb 07 |
jari |
542 |
group.addChild(pointShapes[i]); |
2 |
26 Feb 07 |
jari |
543 |
} |
2 |
26 Feb 07 |
jari |
544 |
} |
2 |
26 Feb 07 |
jari |
545 |
Shape3D points = createSelectedPoints(); |
2 |
26 Feb 07 |
jari |
546 |
if (points != null) { |
2 |
26 Feb 07 |
jari |
547 |
group.addChild(points); |
2 |
26 Feb 07 |
jari |
548 |
} |
2 |
26 Feb 07 |
jari |
549 |
} |
2 |
26 Feb 07 |
jari |
550 |
} |
2 |
26 Feb 07 |
jari |
551 |
if (isSelectionBox()) { |
2 |
26 Feb 07 |
jari |
552 |
group.addChild(createSelectionBox()); |
2 |
26 Feb 07 |
jari |
553 |
} |
2 |
26 Feb 07 |
jari |
554 |
if (isShowText()) { |
2 |
26 Feb 07 |
jari |
555 |
group.addChild(createText()); |
2 |
26 Feb 07 |
jari |
556 |
} |
2 |
26 Feb 07 |
jari |
557 |
OpenBehavior openObject = new OpenBehavior(group); |
2 |
26 Feb 07 |
jari |
558 |
openObject.setSchedulingBounds(bounds); |
2 |
26 Feb 07 |
jari |
559 |
group.addChild(openObject); |
2 |
26 Feb 07 |
jari |
560 |
return group; |
2 |
26 Feb 07 |
jari |
561 |
} |
2 |
26 Feb 07 |
jari |
562 |
|
2 |
26 Feb 07 |
jari |
563 |
|
2 |
26 Feb 07 |
jari |
564 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a light transform group. |
2 |
26 Feb 07 |
jari |
566 |
*/ |
2 |
26 Feb 07 |
jari |
567 |
private TransformGroup createLight(BoundingSphere bounds, Vector3d vector) { |
2 |
26 Feb 07 |
jari |
568 |
Transform3D t = new Transform3D(); |
2 |
26 Feb 07 |
jari |
569 |
t.set(vector); |
2 |
26 Feb 07 |
jari |
570 |
TransformGroup lightGroup = new TransformGroup(t); |
2 |
26 Feb 07 |
jari |
571 |
lightGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); |
2 |
26 Feb 07 |
jari |
572 |
lightGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); |
2 |
26 Feb 07 |
jari |
573 |
lightGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING); |
2 |
26 Feb 07 |
jari |
574 |
|
2 |
26 Feb 07 |
jari |
575 |
ColoringAttributes attr = new ColoringAttributes(); |
2 |
26 Feb 07 |
jari |
576 |
Color3f color = new Color3f(1.0f, 1.0f, 1.0f); |
2 |
26 Feb 07 |
jari |
577 |
attr.setColor(color); |
2 |
26 Feb 07 |
jari |
578 |
Appearance appearance = new Appearance(); |
2 |
26 Feb 07 |
jari |
579 |
appearance.setColoringAttributes(attr); |
2 |
26 Feb 07 |
jari |
580 |
lightGroup.addChild(new Sphere(0.01f, Sphere.GENERATE_NORMALS, 15, appearance)); |
2 |
26 Feb 07 |
jari |
581 |
Light light = new PointLight(color, new Point3f(0.0f, 0.0f, 0.0f), new Point3f(1.0f, 0.0f, 0.0f)); |
2 |
26 Feb 07 |
jari |
582 |
light.setInfluencingBounds(bounds); |
2 |
26 Feb 07 |
jari |
583 |
lightGroup.addChild(light); |
2 |
26 Feb 07 |
jari |
584 |
return lightGroup; |
2 |
26 Feb 07 |
jari |
585 |
} |
2 |
26 Feb 07 |
jari |
586 |
|
2 |
26 Feb 07 |
jari |
587 |
|
2 |
26 Feb 07 |
jari |
588 |
/** |
2 |
26 Feb 07 |
jari |
* Creates an ambient light. |
2 |
26 Feb 07 |
jari |
590 |
*/ |
2 |
26 Feb 07 |
jari |
591 |
private AmbientLight createAmbientLight(BoundingSphere bounds) { |
2 |
26 Feb 07 |
jari |
592 |
AmbientLight light = new AmbientLight(new Color3f(0.2f, 0.2f, 0.2f)); |
2 |
26 Feb 07 |
jari |
593 |
light.setInfluencingBounds(bounds); |
2 |
26 Feb 07 |
jari |
594 |
return light; |
2 |
26 Feb 07 |
jari |
595 |
} |
2 |
26 Feb 07 |
jari |
596 |
|
2 |
26 Feb 07 |
jari |
597 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a cone shape. |
2 |
26 Feb 07 |
jari |
599 |
*/ |
2 |
26 Feb 07 |
jari |
600 |
private Cone createCone() { |
2 |
26 Feb 07 |
jari |
601 |
return new Cone(0.05f, 0.2f); |
2 |
26 Feb 07 |
jari |
602 |
} |
2 |
26 Feb 07 |
jari |
603 |
|
2 |
26 Feb 07 |
jari |
604 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a cylinder shape with specified color. |
2 |
26 Feb 07 |
jari |
606 |
*/ |
2 |
26 Feb 07 |
jari |
607 |
private Cylinder createCylinder(Color3f color) { |
2 |
26 Feb 07 |
jari |
608 |
Material material = new Material(color, blackColor, color, whiteColor, 100f); |
2 |
26 Feb 07 |
jari |
609 |
if (isWhiteBackground()) { |
2 |
26 Feb 07 |
jari |
610 |
material.setEmissiveColor(new Color3f(0.0f, 0.0f, 1.0f)); |
2 |
26 Feb 07 |
jari |
611 |
} |
2 |
26 Feb 07 |
jari |
612 |
Appearance appearance = new Appearance(); |
2 |
26 Feb 07 |
jari |
613 |
appearance.setLineAttributes(new LineAttributes(10, LineAttributes.PATTERN_SOLID, true)); |
2 |
26 Feb 07 |
jari |
614 |
appearance.setMaterial(material); |
2 |
26 Feb 07 |
jari |
615 |
return new Cylinder(0.025f, 6f, appearance); |
2 |
26 Feb 07 |
jari |
//return new Cylinder(0.025f, getMaxValue(), appearance); |
2 |
26 Feb 07 |
jari |
617 |
} |
2 |
26 Feb 07 |
jari |
618 |
|
2 |
26 Feb 07 |
jari |
619 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a selection box transform group. |
2 |
26 Feb 07 |
jari |
621 |
*/ |
2 |
26 Feb 07 |
jari |
622 |
private TransformGroup createSelectionBox() { |
2 |
26 Feb 07 |
jari |
623 |
Material material = new Material(new Color3f(0.5f, 0.5f, 0.5f), blackColor, new Color3f(0.5f, 0.5f, 0.5f), blackColor, 100.0f); |
2 |
26 Feb 07 |
jari |
624 |
material.setLightingEnable(true); |
2 |
26 Feb 07 |
jari |
625 |
Appearance appearance = new Appearance(); |
2 |
26 Feb 07 |
jari |
626 |
TransparencyAttributes ta = new TransparencyAttributes(); |
2 |
26 Feb 07 |
jari |
627 |
ta.setTransparency(0.5f); |
2 |
26 Feb 07 |
jari |
628 |
ta.setTransparencyMode(TransparencyAttributes.BLENDED); |
2 |
26 Feb 07 |
jari |
629 |
appearance.setTransparencyAttributes(ta); |
2 |
26 Feb 07 |
jari |
630 |
appearance.setMaterial(material); |
2 |
26 Feb 07 |
jari |
631 |
Transform3D transform = new Transform3D(); |
2 |
26 Feb 07 |
jari |
632 |
float factorX = 3f/scaleAxisX; |
2 |
26 Feb 07 |
jari |
633 |
float factorY = 3f/scaleAxisY; |
2 |
26 Feb 07 |
jari |
634 |
float factorZ = 3f/scaleAxisZ; |
2 |
26 Feb 07 |
jari |
635 |
Vector3f vector = new Vector3f(boxPositionX*factorX, boxPositionY*factorY, boxPositionZ*factorZ); |
2 |
26 Feb 07 |
jari |
636 |
transform.set(vector); |
2 |
26 Feb 07 |
jari |
637 |
TransformGroup selectionBox = new TransformGroup(transform); |
2 |
26 Feb 07 |
jari |
638 |
selectionBox.addChild(new Box(boxSizeX*factorX/2f, boxSizeY*factorY/2f, boxSizeZ*factorZ/2f, appearance)); |
2 |
26 Feb 07 |
jari |
639 |
return selectionBox; |
2 |
26 Feb 07 |
jari |
640 |
} |
2 |
26 Feb 07 |
jari |
641 |
|
2 |
26 Feb 07 |
jari |
642 |
/** |
2 |
26 Feb 07 |
jari |
* Checkes if specified point is selected. |
2 |
26 Feb 07 |
jari |
644 |
*/ |
2 |
26 Feb 07 |
jari |
645 |
private boolean isPointSelected(float x, float y, float z) { |
2 |
26 Feb 07 |
jari |
646 |
float X1 = boxPositionX-boxSizeX/2f; |
2 |
26 Feb 07 |
jari |
647 |
float X2 = boxPositionX+boxSizeX/2f; |
2 |
26 Feb 07 |
jari |
648 |
float Y1 = boxPositionY-boxSizeY/2f; |
2 |
26 Feb 07 |
jari |
649 |
float Y2 = boxPositionY+boxSizeY/2f; |
2 |
26 Feb 07 |
jari |
650 |
float Z1 = boxPositionZ-boxSizeZ/2f; |
2 |
26 Feb 07 |
jari |
651 |
float Z2 = boxPositionZ+boxSizeZ/2f; |
2 |
26 Feb 07 |
jari |
652 |
return x>=X1 && x<=X2 && y>=Y1 && y<=Y2 && z>=Z1 && z<=Z2; |
2 |
26 Feb 07 |
jari |
653 |
} |
2 |
26 Feb 07 |
jari |
654 |
|
2 |
26 Feb 07 |
jari |
655 |
/** |
2 |
26 Feb 07 |
jari |
* Returns an array of selected genes. |
2 |
26 Feb 07 |
jari |
657 |
*/ |
2 |
26 Feb 07 |
jari |
658 |
protected int[] getSelectedGenes() { |
2 |
26 Feb 07 |
jari |
659 |
int[] genes = new int[getPointsCount(true)]; |
2 |
26 Feb 07 |
jari |
660 |
int pos = 0; |
2 |
26 Feb 07 |
jari |
661 |
for (int i=0; i<U.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
//if (isPointSelected(U.get(i,0), U.get(i,1), U.get(i,2))) { |
2 |
26 Feb 07 |
jari |
663 |
if (isPointSelected(U.get(i,xAxis), U.get(i,yAxis), U.get(i,zAxis))) { |
2 |
26 Feb 07 |
jari |
664 |
if (this.geneViewer) { |
2 |
26 Feb 07 |
jari |
665 |
genes[pos] = experiment.getGeneIndexMappedToData(i); |
2 |
26 Feb 07 |
jari |
666 |
} else { |
2 |
26 Feb 07 |
jari |
667 |
genes[pos] = experiment.getSampleIndex(i); |
2 |
26 Feb 07 |
jari |
668 |
} |
2 |
26 Feb 07 |
jari |
669 |
pos++; |
2 |
26 Feb 07 |
jari |
670 |
} |
2 |
26 Feb 07 |
jari |
671 |
} |
2 |
26 Feb 07 |
jari |
672 |
return genes; |
2 |
26 Feb 07 |
jari |
673 |
} |
2 |
26 Feb 07 |
jari |
674 |
|
2 |
26 Feb 07 |
jari |
675 |
/** |
2 |
26 Feb 07 |
jari |
* @param selected true if we need number of the selected points. |
2 |
26 Feb 07 |
jari |
677 |
*/ |
2 |
26 Feb 07 |
jari |
678 |
private int getPointsCount(boolean selected) { |
2 |
26 Feb 07 |
jari |
679 |
int count = 0; |
2 |
26 Feb 07 |
jari |
680 |
int selCount = 0; |
2 |
26 Feb 07 |
jari |
681 |
for (int i=0; i<U.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
//if (isPointSelected(U.get(i,0), U.get(i,1), U.get(i,2))) { |
2 |
26 Feb 07 |
jari |
683 |
if (isPointSelected(U.get(i,xAxis), U.get(i,yAxis), U.get(i,zAxis))) { |
2 |
26 Feb 07 |
jari |
684 |
selCount++; |
2 |
26 Feb 07 |
jari |
685 |
} else { |
2 |
26 Feb 07 |
jari |
686 |
count++; |
2 |
26 Feb 07 |
jari |
687 |
} |
2 |
26 Feb 07 |
jari |
688 |
} |
2 |
26 Feb 07 |
jari |
689 |
return selected ? selCount : count; |
2 |
26 Feb 07 |
jari |
690 |
} |
2 |
26 Feb 07 |
jari |
691 |
|
2 |
26 Feb 07 |
jari |
692 |
/** |
2 |
26 Feb 07 |
jari |
* Returns number of unselected points. |
2 |
26 Feb 07 |
jari |
694 |
*/ |
2 |
26 Feb 07 |
jari |
695 |
private int getUsualPointsCount() { |
2 |
26 Feb 07 |
jari |
696 |
if (isSelection()) { |
2 |
26 Feb 07 |
jari |
697 |
return getPointsCount(false); |
2 |
26 Feb 07 |
jari |
698 |
} |
2 |
26 Feb 07 |
jari |
699 |
return U.getRowDimension(); |
2 |
26 Feb 07 |
jari |
700 |
} |
2 |
26 Feb 07 |
jari |
701 |
|
2 |
26 Feb 07 |
jari |
702 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a 3D shape which is set of selected points. |
2 |
26 Feb 07 |
jari |
704 |
*/ |
2 |
26 Feb 07 |
jari |
705 |
private Shape3D createSelectedPoints() { |
2 |
26 Feb 07 |
jari |
706 |
if (!isSelection()) { |
2 |
26 Feb 07 |
jari |
707 |
return null; |
2 |
26 Feb 07 |
jari |
708 |
} |
2 |
26 Feb 07 |
jari |
709 |
int count = getPointsCount(true); |
2 |
26 Feb 07 |
jari |
710 |
if (count < 1) { |
2 |
26 Feb 07 |
jari |
711 |
return null; |
2 |
26 Feb 07 |
jari |
712 |
} |
2 |
26 Feb 07 |
jari |
713 |
Color3f color = new Color3f(1.0f, 0.3f, 1.0f); |
2 |
26 Feb 07 |
jari |
714 |
Material material = new Material(color, color, color, color, 100.0f); |
2 |
26 Feb 07 |
jari |
715 |
material.setLightingEnable(true); |
2 |
26 Feb 07 |
jari |
716 |
Appearance appearance = new Appearance(); |
2 |
26 Feb 07 |
jari |
717 |
appearance.setPointAttributes(new PointAttributes(getSelectedPointSize(), false)); |
2 |
26 Feb 07 |
jari |
718 |
appearance.setMaterial(material); |
2 |
26 Feb 07 |
jari |
719 |
|
2 |
26 Feb 07 |
jari |
720 |
PointArray points = new PointArray(count, PointArray.COORDINATES | PointArray.COLOR_3 | PointArray.NORMALS); |
2 |
26 Feb 07 |
jari |
721 |
|
2 |
26 Feb 07 |
jari |
722 |
float factorX = 3f/scaleAxisX; |
2 |
26 Feb 07 |
jari |
723 |
float factorY = 3f/scaleAxisY; |
2 |
26 Feb 07 |
jari |
724 |
float factorZ = 3f/scaleAxisZ; |
2 |
26 Feb 07 |
jari |
725 |
|
2 |
26 Feb 07 |
jari |
726 |
float x, y, z; |
2 |
26 Feb 07 |
jari |
727 |
int index = 0; |
2 |
26 Feb 07 |
jari |
728 |
for (int i=0; i<U.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
//x = U.get(i,0); |
2 |
26 Feb 07 |
jari |
//y = U.get(i,1); |
2 |
26 Feb 07 |
jari |
//z = U.get(i,2); |
2 |
26 Feb 07 |
jari |
732 |
x = U.get(i,xAxis); |
2 |
26 Feb 07 |
jari |
733 |
y = U.get(i,yAxis); |
2 |
26 Feb 07 |
jari |
734 |
z = U.get(i,zAxis); |
2 |
26 Feb 07 |
jari |
735 |
if (isPointSelected(x, y, z)) { |
2 |
26 Feb 07 |
jari |
736 |
points.setCoordinate(index, new Point3f(x*factorX, y*factorY, z*factorZ)); |
2 |
26 Feb 07 |
jari |
737 |
index++; |
2 |
26 Feb 07 |
jari |
738 |
} |
2 |
26 Feb 07 |
jari |
739 |
} |
2 |
26 Feb 07 |
jari |
740 |
Shape3D pointsShape = new Shape3D(); |
2 |
26 Feb 07 |
jari |
741 |
pointsShape.setAppearance(appearance); |
2 |
26 Feb 07 |
jari |
742 |
pointsShape.setGeometry(points); |
2 |
26 Feb 07 |
jari |
743 |
return pointsShape; |
2 |
26 Feb 07 |
jari |
744 |
} |
2 |
26 Feb 07 |
jari |
745 |
|
2 |
26 Feb 07 |
jari |
746 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a point appearance with specified color. |
2 |
26 Feb 07 |
jari |
748 |
*/ |
2 |
26 Feb 07 |
jari |
749 |
private Appearance createPointAppearance(Color3f color) { |
2 |
26 Feb 07 |
jari |
750 |
Material material = new Material(color, color, color, color, 100.0f); |
2 |
26 Feb 07 |
jari |
751 |
material.setLightingEnable(true); |
2 |
26 Feb 07 |
jari |
752 |
Appearance appearance = new Appearance(); |
2 |
26 Feb 07 |
jari |
753 |
appearance.setPointAttributes(new PointAttributes(getPointSize(), false)); |
2 |
26 Feb 07 |
jari |
754 |
appearance.setMaterial(material); |
2 |
26 Feb 07 |
jari |
755 |
return appearance; |
2 |
26 Feb 07 |
jari |
756 |
} |
2 |
26 Feb 07 |
jari |
757 |
|
2 |
26 Feb 07 |
jari |
758 |
/** |
2 |
26 Feb 07 |
jari |
* Creates an array of 3D shapes which are sets of not selected points. |
2 |
26 Feb 07 |
jari |
760 |
*/ |
2 |
26 Feb 07 |
jari |
761 |
private Shape3D[] createUsualPoints() { |
2 |
26 Feb 07 |
jari |
762 |
int count = getUsualPointsCount(); |
2 |
26 Feb 07 |
jari |
763 |
if (count < 1) { |
2 |
26 Feb 07 |
jari |
764 |
return null; |
2 |
26 Feb 07 |
jari |
765 |
} |
2 |
26 Feb 07 |
jari |
766 |
int uncoloredCount; |
2 |
26 Feb 07 |
jari |
767 |
if (geneViewer) { |
2 |
26 Feb 07 |
jari |
768 |
uncoloredCount = data.getColoredProbesCount(-1); |
2 |
26 Feb 07 |
jari |
769 |
} else { |
2 |
26 Feb 07 |
jari |
770 |
uncoloredCount = data.getColoredExperimentsCount(-1); |
2 |
26 Feb 07 |
jari |
771 |
} |
2 |
26 Feb 07 |
jari |
772 |
|
2 |
26 Feb 07 |
jari |
773 |
int delta = uncoloredCount == 0 ? 0 : 1; |
2 |
26 Feb 07 |
jari |
774 |
|
2 |
26 Feb 07 |
jari |
775 |
Color[] colors; |
2 |
26 Feb 07 |
jari |
776 |
if(geneViewer) |
2 |
26 Feb 07 |
jari |
777 |
colors = data.getColors(); // get colored gene clusters |
2 |
26 Feb 07 |
jari |
778 |
else |
2 |
26 Feb 07 |
jari |
779 |
colors = data.getExperimentColors(); |
2 |
26 Feb 07 |
jari |
780 |
|
2 |
26 Feb 07 |
jari |
781 |
PointArray[] pointArrays = new PointArray[colors.length+delta]; |
2 |
26 Feb 07 |
jari |
782 |
Appearance[] appearances = new Appearance[colors.length+delta]; |
2 |
26 Feb 07 |
jari |
783 |
int[] counters = new int[colors.length+delta]; |
2 |
26 Feb 07 |
jari |
784 |
Color3f color; |
2 |
26 Feb 07 |
jari |
785 |
|
2 |
26 Feb 07 |
jari |
// not published probes |
2 |
26 Feb 07 |
jari |
787 |
if (uncoloredCount > 0) { |
2 |
26 Feb 07 |
jari |
788 |
appearances[0] = createPointAppearance(isWhiteBackground() ? blackColor : whiteColor); |
2 |
26 Feb 07 |
jari |
789 |
pointArrays[0] = new PointArray(uncoloredCount, PointArray.COORDINATES | PointArray.COLOR_3 | PointArray.NORMALS); |
2 |
26 Feb 07 |
jari |
790 |
counters[0] = 0; |
2 |
26 Feb 07 |
jari |
791 |
} |
2 |
26 Feb 07 |
jari |
792 |
if(geneViewer){ |
2 |
26 Feb 07 |
jari |
// published ones |
2 |
26 Feb 07 |
jari |
794 |
for (int i=0; i<colors.length; i++) { |
2 |
26 Feb 07 |
jari |
795 |
color = new Color3f(colors[i]); |
2 |
26 Feb 07 |
jari |
796 |
appearances[i+delta] = createPointAppearance(color); |
2 |
26 Feb 07 |
jari |
797 |
pointArrays[i+delta] = new PointArray(data.getColoredProbesCount(i), PointArray.COORDINATES | PointArray.COLOR_3 | PointArray.NORMALS); |
2 |
26 Feb 07 |
jari |
798 |
counters[i+delta] = 0; |
2 |
26 Feb 07 |
jari |
799 |
} |
2 |
26 Feb 07 |
jari |
800 |
} else{ //Experiment Viewer |
2 |
26 Feb 07 |
jari |
801 |
for (int i=0; i<colors.length; i++) { |
2 |
26 Feb 07 |
jari |
802 |
color = new Color3f(colors[i]); |
2 |
26 Feb 07 |
jari |
803 |
appearances[i+delta] = createPointAppearance(color); |
2 |
26 Feb 07 |
jari |
804 |
pointArrays[i+delta] = new PointArray(data.getColoredExperimentsCount(i), PointArray.COORDINATES | PointArray.COLOR_3 | PointArray.NORMALS); |
2 |
26 Feb 07 |
jari |
805 |
counters[i+delta] = 0; |
2 |
26 Feb 07 |
jari |
806 |
} |
2 |
26 Feb 07 |
jari |
807 |
} |
2 |
26 Feb 07 |
jari |
808 |
|
2 |
26 Feb 07 |
jari |
809 |
float factorX = 3f/scaleAxisX; |
2 |
26 Feb 07 |
jari |
810 |
float factorY = 3f/scaleAxisY; |
2 |
26 Feb 07 |
jari |
811 |
float factorZ = 3f/scaleAxisZ; |
2 |
26 Feb 07 |
jari |
812 |
float x, y, z; |
2 |
26 Feb 07 |
jari |
813 |
int index = 0; |
2 |
26 Feb 07 |
jari |
814 |
for (int i=0; i<U.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
//x = U.get(i,0); |
2 |
26 Feb 07 |
jari |
//y = U.get(i,1); |
2 |
26 Feb 07 |
jari |
//z = U.get(i,2); |
2 |
26 Feb 07 |
jari |
818 |
x = U.get(i,xAxis); |
2 |
26 Feb 07 |
jari |
819 |
y = U.get(i,yAxis); |
2 |
26 Feb 07 |
jari |
820 |
z = U.get(i,zAxis); |
2 |
26 Feb 07 |
jari |
821 |
if (!isSelection() || !isPointSelected(x, y, z)) { |
2 |
26 Feb 07 |
jari |
822 |
if(geneViewer) |
2 |
26 Feb 07 |
jari |
823 |
index = data.getProbeColorIndex(experiment.getGeneIndexMappedToData(i))+delta; |
2 |
26 Feb 07 |
jari |
824 |
else |
2 |
26 Feb 07 |
jari |
825 |
index = data.getExperimentColorIndex(i)+delta; |
2 |
26 Feb 07 |
jari |
826 |
|
2 |
26 Feb 07 |
jari |
827 |
pointArrays[index].setCoordinate(counters[index], new Point3f(x*factorX, y*factorY, z*factorZ)); |
2 |
26 Feb 07 |
jari |
828 |
counters[index]++; |
2 |
26 Feb 07 |
jari |
829 |
} |
2 |
26 Feb 07 |
jari |
830 |
} |
2 |
26 Feb 07 |
jari |
831 |
|
2 |
26 Feb 07 |
jari |
832 |
Shape3D[] pointShapes = new Shape3D[pointArrays.length]; |
2 |
26 Feb 07 |
jari |
833 |
for (int i=0; i<pointShapes.length; i++) { |
2 |
26 Feb 07 |
jari |
834 |
pointShapes[i] = new Shape3D(); |
2 |
26 Feb 07 |
jari |
835 |
pointShapes[i].setAppearance(appearances[i]); |
2 |
26 Feb 07 |
jari |
836 |
pointShapes[i].setGeometry(pointArrays[i]); |
2 |
26 Feb 07 |
jari |
837 |
} |
2 |
26 Feb 07 |
jari |
838 |
return pointShapes; |
2 |
26 Feb 07 |
jari |
839 |
} |
2 |
26 Feb 07 |
jari |
840 |
|
2 |
26 Feb 07 |
jari |
841 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a point appearance with specified color. |
2 |
26 Feb 07 |
jari |
843 |
*/ |
2 |
26 Feb 07 |
jari |
844 |
private Appearance createSphereAppearance(Color3f color) { |
2 |
26 Feb 07 |
jari |
845 |
Material material = new Material(color, this.blackColor, color, this.whiteColor, 100.0f); |
2 |
26 Feb 07 |
jari |
846 |
material.setLightingEnable(true); |
2 |
26 Feb 07 |
jari |
847 |
Appearance appearance = new Appearance(); |
2 |
26 Feb 07 |
jari |
848 |
appearance.setMaterial(material); |
2 |
26 Feb 07 |
jari |
849 |
return appearance; |
2 |
26 Feb 07 |
jari |
850 |
} |
2 |
26 Feb 07 |
jari |
851 |
|
2 |
26 Feb 07 |
jari |
852 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a spheres transform group. |
2 |
26 Feb 07 |
jari |
854 |
*/ |
2 |
26 Feb 07 |
jari |
855 |
private TransformGroup createSpheres() { |
2 |
26 Feb 07 |
jari |
856 |
TransformGroup spheres = new TransformGroup(); |
2 |
26 Feb 07 |
jari |
857 |
|
2 |
26 Feb 07 |
jari |
858 |
float factorX = 3f/scaleAxisX; |
2 |
26 Feb 07 |
jari |
859 |
float factorY = 3f/scaleAxisY; |
2 |
26 Feb 07 |
jari |
860 |
float factorZ = 3f/scaleAxisZ; |
2 |
26 Feb 07 |
jari |
861 |
|
2 |
26 Feb 07 |
jari |
// usual material |
2 |
26 Feb 07 |
jari |
863 |
Color3f uColor = isWhiteBackground() ? blackColor : whiteColor; |
2 |
26 Feb 07 |
jari |
864 |
Appearance uAppearance = createSphereAppearance(uColor); |
2 |
26 Feb 07 |
jari |
865 |
|
2 |
26 Feb 07 |
jari |
// selected material |
2 |
26 Feb 07 |
jari |
867 |
Color3f sColor = isSelection() ? new Color3f(1.0f, 0.3f, 1.0f) : uColor; |
2 |
26 Feb 07 |
jari |
868 |
Appearance sAppearance = createSphereAppearance(sColor); |
2 |
26 Feb 07 |
jari |
869 |
|
2 |
26 Feb 07 |
jari |
870 |
Transform3D transform; |
2 |
26 Feb 07 |
jari |
871 |
Vector3d vector3d; |
2 |
26 Feb 07 |
jari |
872 |
TransformGroup sphere; |
2 |
26 Feb 07 |
jari |
873 |
boolean selected; |
2 |
26 Feb 07 |
jari |
874 |
float x, y, z; |
2 |
26 Feb 07 |
jari |
875 |
|
2 |
26 Feb 07 |
jari |
876 |
for (int i=0; i<U.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
//x = U.get(i,0); |
2 |
26 Feb 07 |
jari |
//y = U.get(i,1); |
2 |
26 Feb 07 |
jari |
//z = U.get(i,2); |
2 |
26 Feb 07 |
jari |
880 |
x = U.get(i,xAxis); |
2 |
26 Feb 07 |
jari |
881 |
y = U.get(i,yAxis); |
2 |
26 Feb 07 |
jari |
882 |
z = U.get(i,zAxis); |
2 |
26 Feb 07 |
jari |
883 |
transform = new Transform3D(); |
2 |
26 Feb 07 |
jari |
884 |
vector3d = new Vector3d(x*factorX, y*factorY, z*factorZ); |
2 |
26 Feb 07 |
jari |
885 |
transform.set(vector3d); |
2 |
26 Feb 07 |
jari |
886 |
sphere = new TransformGroup(transform); |
2 |
26 Feb 07 |
jari |
887 |
selected = (isSelection() && isPointSelected(x, y, z)); |
2 |
26 Feb 07 |
jari |
888 |
if(geneViewer){ |
2 |
26 Feb 07 |
jari |
889 |
if (data.getProbeColor(experiment.getGeneIndexMappedToData(i)) == null) { |
2 |
26 Feb 07 |
jari |
890 |
sphere.addChild(new Sphere(getPointSize(selected)/20f, (selected ? sAppearance : uAppearance))); |
2 |
26 Feb 07 |
jari |
891 |
} else { |
2 |
26 Feb 07 |
jari |
892 |
sphere.addChild(new Sphere(getPointSize(selected)/20f, (selected ? sAppearance : createSphereAppearance(new Color3f(data.getProbeColor(experiment.getGeneIndexMappedToData(i))))))); |
2 |
26 Feb 07 |
jari |
893 |
} |
2 |
26 Feb 07 |
jari |
894 |
} |
2 |
26 Feb 07 |
jari |
895 |
else{ |
2 |
26 Feb 07 |
jari |
896 |
if (data.getExperimentColor(i) == null) { |
2 |
26 Feb 07 |
jari |
897 |
sphere.addChild(new Sphere(getPointSize(selected)/20f, (selected ? sAppearance : uAppearance))); |
2 |
26 Feb 07 |
jari |
898 |
} else { |
2 |
26 Feb 07 |
jari |
899 |
sphere.addChild(new Sphere(getPointSize(selected)/20f, (selected ? sAppearance : createSphereAppearance(new Color3f(data.getExperimentColor(i)))))); |
2 |
26 Feb 07 |
jari |
900 |
} |
2 |
26 Feb 07 |
jari |
901 |
} |
2 |
26 Feb 07 |
jari |
902 |
spheres.addChild(sphere); |
2 |
26 Feb 07 |
jari |
903 |
} |
2 |
26 Feb 07 |
jari |
904 |
return spheres; |
2 |
26 Feb 07 |
jari |
905 |
} |
2 |
26 Feb 07 |
jari |
906 |
|
2 |
26 Feb 07 |
jari |
907 |
|
2 |
26 Feb 07 |
jari |
908 |
|
2 |
26 Feb 07 |
jari |
909 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a text transform group. |
2 |
26 Feb 07 |
jari |
911 |
*/ |
2 |
26 Feb 07 |
jari |
912 |
private TransformGroup createText() { |
2 |
26 Feb 07 |
jari |
913 |
TransformGroup textGroup = new TransformGroup(); |
2 |
26 Feb 07 |
jari |
914 |
|
2 |
26 Feb 07 |
jari |
915 |
float factorX = 3f/scaleAxisX; |
2 |
26 Feb 07 |
jari |
916 |
float factorY = 3f/scaleAxisY; |
2 |
26 Feb 07 |
jari |
917 |
float factorZ = 3f/scaleAxisZ; |
2 |
26 Feb 07 |
jari |
918 |
|
2 |
26 Feb 07 |
jari |
//Font3D font = new Font3D(new Font("TestFont", Font.BOLD, 1), new FontExtrusion()); |
2 |
26 Feb 07 |
jari |
920 |
Font3D font = new Font3D(new Font("TestFont", Font.BOLD, (int)(Math.round(getPointSize(false)))), new FontExtrusion()); |
2 |
26 Feb 07 |
jari |
921 |
Font origFont = font.getFont(); |
2 |
26 Feb 07 |
jari |
922 |
|
2 |
26 Feb 07 |
jari |
923 |
FontMetrics fMet = onScreenCanvas.getFontMetrics(origFont); |
2 |
26 Feb 07 |
jari |
924 |
int ascent = fMet.getAscent(); |
2 |
26 Feb 07 |
jari |
925 |
|
2 |
26 Feb 07 |
jari |
926 |
Color3f color3f; |
2 |
26 Feb 07 |
jari |
927 |
if(!this.whiteBackground) |
2 |
26 Feb 07 |
jari |
928 |
color3f = new Color3f(1.0f, 1.0f, 1.0f); |
2 |
26 Feb 07 |
jari |
929 |
else |
2 |
26 Feb 07 |
jari |
930 |
color3f = new Color3f(0.0f, 0.0f, 0.0f); |
2 |
26 Feb 07 |
jari |
931 |
|
2 |
26 Feb 07 |
jari |
932 |
Material material; |
2 |
26 Feb 07 |
jari |
933 |
if(!this.whiteBackground) |
2 |
26 Feb 07 |
jari |
934 |
material = new Material(color3f, whiteColor, color3f, whiteColor, 100f); |
2 |
26 Feb 07 |
jari |
935 |
else |
2 |
26 Feb 07 |
jari |
936 |
material = new Material(color3f, blackColor, color3f, blackColor, 100f); |
2 |
26 Feb 07 |
jari |
937 |
|
2 |
26 Feb 07 |
jari |
938 |
material.setLightingEnable(true); |
2 |
26 Feb 07 |
jari |
//material.setLightingEnable(false); |
2 |
26 Feb 07 |
jari |
940 |
Appearance appearance = new Appearance(); |
2 |
26 Feb 07 |
jari |
941 |
appearance.setMaterial(material); |
2 |
26 Feb 07 |
jari |
942 |
|
2 |
26 Feb 07 |
jari |
943 |
Transform3D fontTransform = new Transform3D(); |
2 |
26 Feb 07 |
jari |
944 |
fontTransform.setScale(0.1); |
2 |
26 Feb 07 |
jari |
945 |
|
2 |
26 Feb 07 |
jari |
946 |
TransformGroup tempGroup; |
2 |
26 Feb 07 |
jari |
947 |
Text3D text3d; |
2 |
26 Feb 07 |
jari |
948 |
Shape3D shape3d; |
2 |
26 Feb 07 |
jari |
949 |
String text; |
2 |
26 Feb 07 |
jari |
950 |
float x, y, z; |
2 |
26 Feb 07 |
jari |
951 |
for (int i=0; i<U.getRowDimension(); i++) { |
2 |
26 Feb 07 |
jari |
//x = U.get(i,0); |
2 |
26 Feb 07 |
jari |
//y = U.get(i,1); |
2 |
26 Feb 07 |
jari |
//z = U.get(i,2); |
2 |
26 Feb 07 |
jari |
955 |
x = U.get(i,xAxis); |
2 |
26 Feb 07 |
jari |
956 |
y = U.get(i,yAxis); |
2 |
26 Feb 07 |
jari |
957 |
z = U.get(i,zAxis); |
2 |
26 Feb 07 |
jari |
958 |
tempGroup = new TransformGroup(fontTransform); |
2 |
26 Feb 07 |
jari |
//text = (mode == 1) ? data.getUniqueId(i) : data.getSampleName(experiment.getSampleIndex(i)); |
2 |
26 Feb 07 |
jari |
960 |
text = (mode == 1) ? data.getElementAttribute(experiment.getGeneIndexMappedToData(i), geneLabelIndex) : data.getSampleName(experiment.getSampleIndex(i)); |
2 |
26 Feb 07 |
jari |
//text3d = new Text3D(font, text, new Point3f(x*factorX*10f+getPointSize(isPointSelected(x, y, z)), (y-0.035f)*factorY*10f, z*factorZ*10f)); |
2 |
26 Feb 07 |
jari |
962 |
text3d = new Text3D(font, text, new Point3f(x*factorX*10f+getPointSize(isPointSelected(x, y, z)), (float)(y*factorY*10f - (float)ascent/2f), z*factorZ*10f)); |
2 |
26 Feb 07 |
jari |
963 |
shape3d = new Shape3D(); |
2 |
26 Feb 07 |
jari |
964 |
shape3d.setGeometry(text3d); |
2 |
26 Feb 07 |
jari |
965 |
shape3d.setAppearance(appearance); |
2 |
26 Feb 07 |
jari |
966 |
tempGroup.addChild(shape3d); |
2 |
26 Feb 07 |
jari |
967 |
textGroup.addChild(tempGroup); |
2 |
26 Feb 07 |
jari |
968 |
} |
2 |
26 Feb 07 |
jari |
969 |
return textGroup; |
2 |
26 Feb 07 |
jari |
970 |
} |
2 |
26 Feb 07 |
jari |
971 |
|
2 |
26 Feb 07 |
jari |
972 |
/** |
2 |
26 Feb 07 |
jari |
* Creates 3D shape for specified string. |
2 |
26 Feb 07 |
jari |
974 |
*/ |
2 |
26 Feb 07 |
jari |
975 |
private Shape3D createTextShape3D(String text) { |
2 |
26 Feb 07 |
jari |
976 |
Font3D axisFont = new Font3D(new Font("TestFont", Font.BOLD, 1), new FontExtrusion()); |
2 |
26 Feb 07 |
jari |
977 |
Text3D text3D = new Text3D(axisFont, text); |
2 |
26 Feb 07 |
jari |
978 |
Shape3D shape = new Shape3D(); |
2 |
26 Feb 07 |
jari |
979 |
shape.setGeometry(text3D); |
2 |
26 Feb 07 |
jari |
980 |
Color3f color3f; |
2 |
26 Feb 07 |
jari |
981 |
Material axisFontMaterial; |
2 |
26 Feb 07 |
jari |
982 |
if(!whiteBackground){ |
2 |
26 Feb 07 |
jari |
983 |
color3f = new Color3f(0.5f, 0.5f, 0.5f); |
2 |
26 Feb 07 |
jari |
984 |
axisFontMaterial = new Material(color3f, blackColor, color3f, whiteColor, 100f); |
2 |
26 Feb 07 |
jari |
985 |
} |
2 |
26 Feb 07 |
jari |
986 |
else{ |
2 |
26 Feb 07 |
jari |
987 |
color3f = new Color3f(0.0f, 0.0f, 0.0f); |
2 |
26 Feb 07 |
jari |
988 |
axisFontMaterial = new Material(color3f, blackColor, color3f, blackColor, 100f); |
2 |
26 Feb 07 |
jari |
989 |
} |
2 |
26 Feb 07 |
jari |
990 |
axisFontMaterial.setLightingEnable(true); |
2 |
26 Feb 07 |
jari |
991 |
Appearance axisFontAppearance = new Appearance(); |
2 |
26 Feb 07 |
jari |
992 |
axisFontAppearance.setMaterial(axisFontMaterial); |
2 |
26 Feb 07 |
jari |
993 |
shape.setAppearance(axisFontAppearance); |
2 |
26 Feb 07 |
jari |
994 |
return shape; |
2 |
26 Feb 07 |
jari |
995 |
} |
2 |
26 Feb 07 |
jari |
996 |
|
2 |
26 Feb 07 |
jari |
997 |
/** |
2 |
26 Feb 07 |
jari |
* Creates x-axis transform group. |
2 |
26 Feb 07 |
jari |
999 |
*/ |
2 |
26 Feb 07 |
jari |
1000 |
private TransformGroup createXAxis() { |
2 |
26 Feb 07 |
jari |
1001 |
Transform3D axisTrans = new Transform3D(); |
2 |
26 Feb 07 |
jari |
1002 |
axisTrans.rotZ(-Math.PI/2.0d); |
2 |
26 Feb 07 |
jari |
1003 |
Transform3D fontTrans = new Transform3D(); |
2 |
26 Feb 07 |
jari |
1004 |
fontTrans.rotZ(Math.PI/2.0d); |
2 |
26 Feb 07 |
jari |
1005 |
|
2 |
26 Feb 07 |
jari |
1006 |
if(!whiteBackground) |
2 |
26 Feb 07 |
jari |
//return createAxis("X", new Color3f(0.5f, 0.5f, 0.5f), axisTrans, fontTrans); |
2 |
26 Feb 07 |
jari |
1008 |
return createAxis("" + (xAxis + 1), new Color3f(0.5f, 0.5f, 0.5f), axisTrans, fontTrans); |
2 |
26 Feb 07 |
jari |
1009 |
else |
2 |
26 Feb 07 |
jari |
//return createAxis("X", new Color3f(0.0f, 0.0f, 0.0f), axisTrans, fontTrans); |
2 |
26 Feb 07 |
jari |
1011 |
return createAxis("" + (xAxis + 1), new Color3f(0.0f, 0.0f, 0.0f), axisTrans, fontTrans); |
2 |
26 Feb 07 |
jari |
1012 |
} |
2 |
26 Feb 07 |
jari |
1013 |
|
2 |
26 Feb 07 |
jari |
1014 |
/** |
2 |
26 Feb 07 |
jari |
* Creates y-axis transform group. |
2 |
26 Feb 07 |
jari |
1016 |
*/ |
2 |
26 Feb 07 |
jari |
1017 |
private TransformGroup createYAxis() { |
2 |
26 Feb 07 |
jari |
1018 |
|
2 |
26 Feb 07 |
jari |
1019 |
if(!whiteBackground) |
2 |
26 Feb 07 |
jari |
//return createAxis("Y", new Color3f(0.3f, 0.3f, 1f), null, null); |
2 |
26 Feb 07 |
jari |
1021 |
return createAxis("" + (yAxis + 1), new Color3f(0.3f, 0.3f, 1f), null, null); |
2 |
26 Feb 07 |
jari |
1022 |
else |
2 |
26 Feb 07 |
jari |
//return createAxis("Y", new Color3f(0.0f, 0.0f, 0.0f), null, null); |
2 |
26 Feb 07 |
jari |
1024 |
return createAxis("" + (yAxis + 1), new Color3f(0.0f, 0.0f, 0.0f), null, null); |
2 |
26 Feb 07 |
jari |
1025 |
} |
2 |
26 Feb 07 |
jari |
1026 |
|
2 |
26 Feb 07 |
jari |
1027 |
/** |
2 |
26 Feb 07 |
jari |
* Creates z-axis transform group. |
2 |
26 Feb 07 |
jari |
1029 |
*/ |
2 |
26 Feb 07 |
jari |
1030 |
private TransformGroup createZAxis() { |
2 |
26 Feb 07 |
jari |
1031 |
Transform3D axisTrans = new Transform3D(); |
2 |
26 Feb 07 |
jari |
1032 |
axisTrans.rotX(-Math.PI/2.0d); |
2 |
26 Feb 07 |
jari |
1033 |
Transform3D zTrans = new Transform3D(); |
2 |
26 Feb 07 |
jari |
1034 |
zTrans.rotY(Math.PI/2.0d); |
2 |
26 Feb 07 |
jari |
1035 |
axisTrans.mul(zTrans); |
2 |
26 Feb 07 |
jari |
1036 |
Transform3D fontTrans = new Transform3D(); |
2 |
26 Feb 07 |
jari |
1037 |
fontTrans.rotZ(Math.PI/2.0d); |
2 |
26 Feb 07 |
jari |
1038 |
if(!whiteBackground) |
2 |
26 Feb 07 |
jari |
//return createAxis("Z", new Color3f(1f, 0.3f, 1f), axisTrans, fontTrans); |
2 |
26 Feb 07 |
jari |
1040 |
return createAxis("" + (zAxis + 1), new Color3f(1f, 0.3f, 1f), axisTrans, fontTrans); |
2 |
26 Feb 07 |
jari |
1041 |
else |
2 |
26 Feb 07 |
jari |
//return createAxis("Z", new Color3f(0.0f, 0.0f, 0.0f), axisTrans, fontTrans); |
2 |
26 Feb 07 |
jari |
1043 |
return createAxis("" + (zAxis + 1), new Color3f(0.0f, 0.0f, 0.0f), axisTrans, fontTrans); |
2 |
26 Feb 07 |
jari |
1044 |
} |
2 |
26 Feb 07 |
jari |
1045 |
|
2 |
26 Feb 07 |
jari |
1046 |
/** |
2 |
26 Feb 07 |
jari |
* Creates an axis transform group. |
2 |
26 Feb 07 |
jari |
1048 |
*/ |
2 |
26 Feb 07 |
jari |
1049 |
private TransformGroup createAxis(String name, Color3f color, Transform3D axisTrans, Transform3D fontTrans) { |
2 |
26 Feb 07 |
jari |
1050 |
TransformGroup axis = new TransformGroup(); |
2 |
26 Feb 07 |
jari |
1051 |
if (axisTrans != null) { |
2 |
26 Feb 07 |
jari |
1052 |
axis.setTransform(axisTrans); |
2 |
26 Feb 07 |
jari |
1053 |
} |
2 |
26 Feb 07 |
jari |
1054 |
axis.addChild(createCylinder(color)); |
2 |
26 Feb 07 |
jari |
// Axis Positive End |
2 |
26 Feb 07 |
jari |
1056 |
Transform3D posTransform = new Transform3D(); |
2 |
26 Feb 07 |
jari |
1057 |
posTransform.set(new Vector3d(0.0, 3.1, 0.0)); |
2 |
26 Feb 07 |
jari |
1058 |
TransformGroup posEnd = new TransformGroup(posTransform); |
2 |
26 Feb 07 |
jari |
1059 |
posEnd.addChild(createCone()); |
2 |
26 Feb 07 |
jari |
// Axis Negative End |
2 |
26 Feb 07 |
jari |
1061 |
Transform3D negTransform = new Transform3D(); |
2 |
26 Feb 07 |
jari |
1062 |
negTransform.set(new Vector3d(0.0, -3.1, 0.0)); |
2 |
26 Feb 07 |
jari |
1063 |
Transform3D rotate180X = new Transform3D(); |
2 |
26 Feb 07 |
jari |
1064 |
rotate180X.rotX(Math.PI); |
2 |
26 Feb 07 |
jari |
1065 |
negTransform.mul(rotate180X); |
2 |
26 Feb 07 |
jari |
1066 |
TransformGroup negEnd = new TransformGroup(negTransform); |
2 |
26 Feb 07 |
jari |
1067 |
negEnd.addChild(createCone()); |
2 |
26 Feb 07 |
jari |
// Font |
2 |
26 Feb 07 |
jari |
1069 |
Transform3D fontTransform = new Transform3D(); |
2 |
26 Feb 07 |
jari |
1070 |
fontTransform.set(0.22, new Vector3d(0.25, 2.75, -0.0125)); |
2 |
26 Feb 07 |
jari |
1071 |
TransformGroup fontGroup = new TransformGroup(fontTransform); |
2 |
26 Feb 07 |
jari |
1072 |
|
2 |
26 Feb 07 |
jari |
1073 |
TransformGroup rotFontGroup = new TransformGroup(); |
2 |
26 Feb 07 |
jari |
1074 |
if (fontTrans != null) { |
2 |
26 Feb 07 |
jari |
1075 |
rotFontGroup.setTransform(fontTrans); |
2 |
26 Feb 07 |
jari |
1076 |
} |
2 |
26 Feb 07 |
jari |
1077 |
|
2 |
26 Feb 07 |
jari |
1078 |
Shape3D shape3D = createTextShape3D(name); |
2 |
26 Feb 07 |
jari |
1079 |
rotFontGroup.addChild(shape3D); |
2 |
26 Feb 07 |
jari |
1080 |
|
2 |
26 Feb 07 |
jari |
1081 |
fontGroup.addChild(rotFontGroup); |
2 |
26 Feb 07 |
jari |
1082 |
|
2 |
26 Feb 07 |
jari |
1083 |
axis.addChild(fontGroup); |
2 |
26 Feb 07 |
jari |
1084 |
axis.addChild(posEnd); |
2 |
26 Feb 07 |
jari |
1085 |
axis.addChild(negEnd); |
2 |
26 Feb 07 |
jari |
1086 |
return axis; |
2 |
26 Feb 07 |
jari |
1087 |
} |
2 |
26 Feb 07 |
jari |
1088 |
} |