-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot3D.java
More file actions
202 lines (176 loc) · 6.16 KB
/
Plot3D.java
File metadata and controls
202 lines (176 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//package org.freehep.j3d.plot;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.behaviors.mouse.*;
import java.awt.Color;
/**
* Abstract class extended by other 3D Plot widgets.
*
* Defines default mouse behaviour etc.
* @author Joy Kyriakopulos (joyk@fnal.gov)
* @version $Id: Plot3D.java 8584 2006-08-10 23:06:37Z duns $
*/
public abstract class Plot3D extends Canvas3D
{
protected boolean init = false;
protected boolean parallelProjection = false;
protected SimpleUniverse universe;
// MH 100111 changing background brightness
// Plot3D(double background)
Plot3D()
{
super(SimpleUniverse.getPreferredConfiguration());
}
// MH 100111 changing background brightness
// protected void init(double background)
protected void init()
{
double background;
// MH 050111
// background = 0.7;
// MH 100111 changing background brightness
background = 0;
//
Node plot = createPlot();
BranchGroup scene = defineMouseBehaviour(plot);
// MH 050111
// Set different background brightness
setupBackgroundColor(scene, background);
//
setupLights(scene); // Surface plot wants an extra light
scene.compile();
universe = new SimpleUniverse(this);
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(scene);
if (parallelProjection) {
setProjectionPolicy(universe, parallelProjection);
}
init = true;
}
// MH 050111
protected void setupBackgroundColor(BranchGroup root, double Col)
{
// Background background = new Background(new Color3f(255, 255, 255));
// Background background = new Background(new Color3f(1.0f, 1.0f, 1.0f));
Background background = new Background(new Color3f((float)Col, (float)Col, (float)Col));
// Background background = new Background(new Color3f(1.0f, 1.0f, 1.0f));
background.setApplicationBounds(bounds);
root.addChild(background);
}
//
// addNotify is called when the Canvas3D is added to a container
// MH 100111 changing background brightness
// public void addNotify(double background)
public void addNotify()
{
// MH 100111 changing background brightness
// if (!init) init( background);
if (!init) init();
super.addNotify(); // must call for Java3D to operate properly when overriding
}
public boolean getParallelProjection()
{
return parallelProjection;
}
public void setParallelProjection(boolean b)
{
if (parallelProjection != b) {
parallelProjection = b;
setProjectionPolicy(universe, parallelProjection);
}
}
/**
* Override to provide plot content
*/
protected abstract Node createPlot();
/**
* Override to provide different mouse behaviour
*/
protected BranchGroup defineMouseBehaviour(Node scene)
{
BranchGroup bg = new BranchGroup();
Bounds bounds = getDefaultBounds();
TransformGroup objTransform = new TransformGroup();
objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objTransform.addChild(scene);
bg.addChild(objTransform);
MouseRotate mouseRotate = new MouseRotate();
mouseRotate.setTransformGroup(objTransform);
mouseRotate.setSchedulingBounds(bounds);
bg.addChild(mouseRotate);
MouseTranslate mouseTranslate = new MouseTranslate();
mouseTranslate.setTransformGroup(objTransform);
mouseTranslate.setSchedulingBounds(bounds);
bg.addChild(mouseTranslate);
MouseZoom mouseZoom = new MouseZoom();
mouseZoom.setTransformGroup(objTransform);
mouseZoom.setSchedulingBounds(bounds);
bg.addChild(mouseZoom);
// Set initial transformation
Transform3D trans = createDefaultOrientation();
objTransform.setTransform(trans);
Behavior keyBehavior = new PlotKeyNavigatorBehavior(objTransform,.1f,10f);
objTransform.addChild(keyBehavior);
keyBehavior.setSchedulingBounds(bounds);
// set up a rotation animating behavior
// rotator = setupZRotator(dynamicXform);
// rotator.setSchedulingBounds(bounds);
// rotator.setEnable(false);
// dynamicXform.addChild(rotator);
return bg;
}
protected void setupLights(BranchGroup root)
{
DirectionalLight lightD = new DirectionalLight();
lightD.setDirection(new Vector3f(0.0f, -0.7f, -0.7f));
lightD.setInfluencingBounds(getDefaultBounds());
root.addChild(lightD);
// This second light is added for the Surface Plot, so you
// can see the "under" surface
DirectionalLight lightD1 = new DirectionalLight();
lightD1.setDirection(new Vector3f(0.0f, 0.7f, 0.7f));
lightD1.setInfluencingBounds(getDefaultBounds());
root.addChild(lightD1);
AmbientLight lightA = new AmbientLight();
lightA.setInfluencingBounds(getDefaultBounds());
root.addChild(lightA);
}
/**
* Override to set a different initial transformation
*/
protected Transform3D createDefaultOrientation()
{
Transform3D trans = new Transform3D();
trans.setIdentity();
trans.rotX(-Math.PI / 4.);
trans.setTranslation(new Vector3f(0.f, -.3f, 0.f));
return trans;
}
/**
* Set the projection policy for the plot - either perspective or projection
*/
protected void setProjectionPolicy(SimpleUniverse universe, boolean parallelProjection)
{
View view = universe.getViewer().getView();
if (parallelProjection)
view.setProjectionPolicy(View.PARALLEL_PROJECTION);
else
view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
}
/**
* Returns a bounds object that can be used for most behaviours,
* lighting models, etc.
*/
protected Bounds getDefaultBounds()
{
if (bounds == null)
{
Point3d center = new Point3d(0, 0, 0);
bounds = new BoundingSphere(center, 10);
}
return bounds;
}
protected Bounds bounds;
}