1 | //////////////////////////////////////////////////////////////////////// |
---|
2 | // |
---|
3 | // This file UpdateRayframeImmediatlyThread.java is part of SURFEX. |
---|
4 | // |
---|
5 | //////////////////////////////////////////////////////////////////////// |
---|
6 | |
---|
7 | //////////////////////////////////////////////////////////////////////// |
---|
8 | // |
---|
9 | // SURFEX version 0.90.00 |
---|
10 | // ================= |
---|
11 | // |
---|
12 | // Saarland University at Saarbruecken, Germany |
---|
13 | // Department of Mathematics and Computer Science |
---|
14 | // |
---|
15 | // SURFEX on the web: www.surfex.AlgebraicSurface.net |
---|
16 | // |
---|
17 | // Authors: Oliver Labs (2001-2008), Stephan Holzer (2004-2005) |
---|
18 | // |
---|
19 | // Copyright (C) 2001-2008 |
---|
20 | // |
---|
21 | // |
---|
22 | // *NOTICE* |
---|
23 | // ======== |
---|
24 | // |
---|
25 | // This program is free software; you can redistribute it and/or modify it |
---|
26 | // under the terms of the GNU General Public License as published by the |
---|
27 | // Free Software Foundation ( version 3 or later of the License ). |
---|
28 | // |
---|
29 | // See LICENCE.TXT for details. |
---|
30 | // |
---|
31 | ///////////////////////////////////////////////////////////////////////// |
---|
32 | |
---|
33 | import java.util.*; |
---|
34 | |
---|
35 | public class UpdateRayframeImmediatlyThread extends Thread implements Runnable { |
---|
36 | Project project; |
---|
37 | |
---|
38 | RayFrame rayFrame; |
---|
39 | |
---|
40 | surfex surfex_; |
---|
41 | |
---|
42 | Thread t; |
---|
43 | |
---|
44 | String old_surfCode = ""; |
---|
45 | |
---|
46 | jv4surfex jv4sx; |
---|
47 | jv4surfex jv4sx_project; |
---|
48 | |
---|
49 | boolean killMe = false; |
---|
50 | |
---|
51 | SavePic saveThread; |
---|
52 | |
---|
53 | boolean showOnlySelectedLamp = false; |
---|
54 | |
---|
55 | int rand; |
---|
56 | |
---|
57 | Vector Lamps; |
---|
58 | |
---|
59 | //boolean only |
---|
60 | Lamp selectedLamp; |
---|
61 | |
---|
62 | UpdateRayframeImmediatlyThread(RayFrame ray, surfex su, Project pro, |
---|
63 | jv4surfex jv4sx) { |
---|
64 | rayFrame = ray; |
---|
65 | this.jv4sx = jv4sx; |
---|
66 | surfex_ = su; |
---|
67 | project = pro; |
---|
68 | rand = (int) ((Math.random()) * 2000000000); |
---|
69 | //System.out.println(rand); |
---|
70 | Lamps = project.getAllLamps(); |
---|
71 | // System.out.println("pla1"); |
---|
72 | } |
---|
73 | |
---|
74 | UpdateRayframeImmediatlyThread(RayFrame ray, surfex su, Project pro, |
---|
75 | jv4surfex jv4sx,jv4surfex jv4sx_project, Vector Lamps, boolean showOnlySelectedLamp, |
---|
76 | Lamp selectedLamp) { |
---|
77 | // System.out.println("pla2"); |
---|
78 | rayFrame = ray; |
---|
79 | this.jv4sx = jv4sx; |
---|
80 | this.jv4sx_project = jv4sx_project; |
---|
81 | surfex_ = su; |
---|
82 | project = pro; |
---|
83 | rand = (int) ((Math.random()) * 2000000000); |
---|
84 | // System.out.println(rand); |
---|
85 | // denn es soll nureine Lampe an sein! |
---|
86 | this.Lamps = Lamps; |
---|
87 | //Lamps.add(lamp); |
---|
88 | this.selectedLamp = selectedLamp; |
---|
89 | this.showOnlySelectedLamp = showOnlySelectedLamp; |
---|
90 | |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | public void start() { |
---|
96 | if (t == null) { |
---|
97 | t = new Thread(this); |
---|
98 | t.start(); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | /* |
---|
103 | * public void stop() { killMe = true; t = null; // |
---|
104 | * System.out.println("comittsuicide" ); } |
---|
105 | */ |
---|
106 | |
---|
107 | public void run() { |
---|
108 | Thread me = Thread.currentThread(); |
---|
109 | String fn = surfex_.tmpDir + "uit" + rand + "test.png"; |
---|
110 | saveThread = new SavePic(fn, false, project.antialiasing.isSelected(), |
---|
111 | rayFrame.panel.getSize().height |
---|
112 | / project.getInterpolConst(), |
---|
113 | rayFrame.panel.getSize().width |
---|
114 | / project.getInterpolConst(), |
---|
115 | 72, surfex_, project, jv4sx.getCamPos(), jv4sx.getViewDir(), jv4sx.getUpVector(), |
---|
116 | jv4sx.getRightVector(),project.parAdmin.getAllParams(),project.parAdmin.getAllParamValues(), |
---|
117 | jv4sx, Lamps); |
---|
118 | // falls nur eine Lampe angezeigt werden soll:; |
---|
119 | if (surfex_.configFrame.surf.isSelected()) { |
---|
120 | fn = surfex_.tmpDir + project.tmp_surfex_file + "uit" |
---|
121 | + rand + ".jpg"; |
---|
122 | } else { |
---|
123 | fn = surfex_.tmpDir + "uit" + rand + "test.png"; |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | // System.out.println("Test"); |
---|
129 | while (me == t) { |
---|
130 | synchronized (this) { |
---|
131 | |
---|
132 | updateLamps(); |
---|
133 | |
---|
134 | if (project.equals(surfex_.getCurrentProject()) |
---|
135 | && rayFrame.isVisible()) { |
---|
136 | |
---|
137 | // System.out.println("visible:"+rand+"ray:"+rayFrame.rand); |
---|
138 | // nur neu berechnen, wenn dies das aktuelle project ist |
---|
139 | // und auch sichtbar ist |
---|
140 | |
---|
141 | // damit das Programm noch reagiert); |
---|
142 | /* |
---|
143 | * try { sleep(100); } catch (InterruptedException e) { } |
---|
144 | */ |
---|
145 | |
---|
146 | // das muss hier stehen, weil sonst aus irgendwelchen Gruenden |
---|
147 | // das normale previewFenster nicht mitupdated |
---|
148 | // wenn man Lampen nur an und aus schaltet |
---|
149 | saveThread = new SavePic( |
---|
150 | fn, |
---|
151 | false, |
---|
152 | project.antialiasing.isSelected(), |
---|
153 | rayFrame.panel.getSize().height |
---|
154 | / project.getInterpolConst(), |
---|
155 | rayFrame.panel.getSize().width |
---|
156 | / project.getInterpolConst(), 72, |
---|
157 | surfex_, project, jv4sx.getCamPos(), jv4sx |
---|
158 | .getViewDir(), jv4sx.getUpVector(), |
---|
159 | jv4sx.getRightVector(),project.parAdmin.getAllParams(),project.parAdmin.getAllParamValues(), jv4sx, Lamps, jv4sx_project); |
---|
160 | |
---|
161 | //int i=System.in.readln(); |
---|
162 | // System.out.println("1" ); |
---|
163 | if (saveThread.getSurfCode().equals(old_surfCode)) { |
---|
164 | //if |
---|
165 | // (saveThread.getSurfCode().equals(old_surfCodePart1)) |
---|
166 | // { |
---|
167 | // we do not have to recompute the same image! |
---|
168 | try { |
---|
169 | sleep(30); |
---|
170 | } catch (Exception e) { |
---|
171 | System.out.println("exception in UpdateRayFrameImmediatlythread jfdjgeig"); |
---|
172 | } |
---|
173 | } else { |
---|
174 | // System.out.println("do |
---|
175 | // recompute!"+this.showOnlySelectedLamp); |
---|
176 | //System.out.println(project.rand + " " |
---|
177 | // + project.equals(surfex_.getCurrentProject())); |
---|
178 | |
---|
179 | rayFrame.isWorking(true); // anzeigen, dass er arbeitet |
---|
180 | old_surfCode = saveThread.getSurfCode(); |
---|
181 | |
---|
182 | try { |
---|
183 | |
---|
184 | saveThread.start(); |
---|
185 | saveThread.join(); |
---|
186 | } catch (InterruptedException e) { |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | // falls nur eine Lampe angezeigt werden soll:; |
---|
191 | // System.out.println("finally"); |
---|
192 | Runtime r = Runtime.getRuntime(); |
---|
193 | Process p; |
---|
194 | try { |
---|
195 | if (project.getInterpolConst() != 1) { |
---|
196 | if (surfex_.OS == surfex_.osWINDOWS) { |
---|
197 | // p = r.exec(surfex_.configFrame.iviewPath |
---|
198 | // .getText() |
---|
199 | // + " " |
---|
200 | // + surfex_.tmpDir |
---|
201 | // + "uit" |
---|
202 | // + rand |
---|
203 | // + "test.png /resample=(0," |
---|
204 | // + rayFrame.getContentPane() |
---|
205 | // .getSize().height |
---|
206 | // + ") /convert=" |
---|
207 | // + surfex_.tmpDir |
---|
208 | // + "uit" + rand + "test.png"); |
---|
209 | // p.waitFor(); |
---|
210 | } else { |
---|
211 | // ??? unter Linux auch interpolieren? |
---|
212 | } |
---|
213 | } else { |
---|
214 | // p = r |
---|
215 | // .exec("iview\\i_view32.exe test.bmp |
---|
216 | // /convert=test.png"); |
---|
217 | |
---|
218 | } |
---|
219 | |
---|
220 | } catch (Exception er) { |
---|
221 | System.out.println(er); |
---|
222 | } |
---|
223 | if(surfex_.cygwin==1) { |
---|
224 | rayFrame.changeBackground(surfex.toWindows(fn)); |
---|
225 | } else { |
---|
226 | rayFrame.changeBackground(fn); |
---|
227 | } |
---|
228 | rayFrame.isWorking(false); |
---|
229 | } |
---|
230 | |
---|
231 | // thread ist fertig |
---|
232 | |
---|
233 | // SwingUtilities.updateComponentTreeUI(bt4); |
---|
234 | } else { |
---|
235 | |
---|
236 | // dieses Project ist nicht das aktuell betrachtete -> nichts machen |
---|
237 | try { |
---|
238 | sleep(50); |
---|
239 | } catch (Exception e) { |
---|
240 | System.out.println("exception in UpdateRayFrameImmediatlythread jfdjgeig"); |
---|
241 | } |
---|
242 | } |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | public String vec2Str(double[] v) { |
---|
248 | return ("<" + v[0] + "," + v[1] + "," + v[2] + ">"); |
---|
249 | } |
---|
250 | |
---|
251 | public synchronized void updateLamps() { |
---|
252 | if (showOnlySelectedLamp) { |
---|
253 | // update selected Lamp: |
---|
254 | if (project.lampAdmin != null && project.lampAdmin.lampIsSelected) { |
---|
255 | //project.lampAdmin |
---|
256 | // .getSelectedLamp() |
---|
257 | //.updateKoords_InvokedByUpdateFrameImmediatlyThread_LampAdmin( |
---|
258 | // jv4sx);//getCameraRotationYXZ()); |
---|
259 | } // System.out.println(selectedLamp+" "+jv4sx); |
---|
260 | // System.out.println("update selected Lamp"); |
---|
261 | /* |
---|
262 | * System.out.println("\n a"+jv4sx.getCameraRotationYXZ()[0]); |
---|
263 | * System.out.println("b"+jv4sx.getCamPos()[0]); |
---|
264 | * System.out.println("c"+jv4sx.getRightVector()[0]); |
---|
265 | * System.out.println("d"+jv4sx.getUpVector()[0]); |
---|
266 | * System.out.println("e"+jv4sx.getViewDir()[0]); |
---|
267 | */// Lamps=new Vector(); |
---|
268 | // Lamps.add(selectedLamp); |
---|
269 | //} |
---|
270 | |
---|
271 | // saveThread.updateLamps(Lamps); |
---|
272 | } else { |
---|
273 | // |
---|
274 | //System.out.println(rand); |
---|
275 | Lamps = project.getAllLamps(); |
---|
276 | //System.out.println("s" + vec2Str(jv4sx.getCamPos())); |
---|
277 | |
---|
278 | } |
---|
279 | } |
---|
280 | } // end class UpdateRayframeImmediatlyThread |
---|
281 | |
---|