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