source: git/Singular/LIB/surfex/SaveMovie.java @ 2ab830

spielwiese
Last change on this file since 2ab830 was 3de2ca, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: surfex_0_90_00 git-svn-id: file:///usr/local/Singular/svn/trunk@11070 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 10.3 KB
Line 
1////////////////////////////////////////////////////////////////////////
2//
3// This file SaveMovie.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
33import java.util.*;
34import java.text.NumberFormat;
35import java.awt.*;
36
37import javax.swing.JComponent;
38import javax.swing.*;
39
40public class SaveMovie extends Thread {
41
42  int N;
43
44  // Rotation types:
45  //final int ROTATE_X_AXIS = 1;
46
47//  final int ROTATE_Y_AXIS = 2;
48
49  //final int ROTATE_Z_AXIS = 3;
50
51  //final int ROTATE_XY_AXIS = 4;
52
53//  final int ROTATE_XZ_AXIS = 5;
54
55  //final int ROTATE_YX_AXIS = 6;
56
57  //final int ROTATE_YZ_AXIS = 7;
58
59  //final int ROTATE_ZX_AXIS = 8;
60
61  //final int ROTATE_ZY_AXIS = 9;
62
63  String SaveToFileLocation;
64
65  boolean dithered, antialiasing;
66
67  surfex surfex_;
68
69  int fps;//, dpi;
70
71  int T;
72
73  int omitType;
74
75  boolean _3d;
76
77  int RotType;
78
79  int height, width;
80
81  SavePic savePic;
82
83  Project pro;
84
85  double[] CamPos;
86
87  double[] viewDir;
88
89  double[] upVector;
90
91  double[] rightVector;
92
93  int Xrot, Yrot, Zrot;
94
95  String[] parametersToRun;
96 
97  int rand;
98
99  public SaveMovie(String SaveToFileLocation, surfex su, int FramesPerSecond,
100                   int dpi, boolean dithered, boolean antialiasing, int Time,
101                   int omitType,
102                   int height, int width, boolean _3d, int RotType, Project pro,
103                   double[] CamPos, double[] viewDir, double[] upVector,
104                   double[] rightVector, int Xrot, int Yrot, int Zrot,
105                   String[] parametersToRun) {
106      this.SaveToFileLocation = SaveToFileLocation;
107      this.surfex_ = su;
108      this.fps = FramesPerSecond;
109      this.T = Time;
110      this.omitType = omitType;
111      this._3d = _3d;
112      this.RotType = 1;//RotType;
113      this.height = height;
114      this.width = width;
115      this.pro = pro;
116      this.dithered = dithered;
117      this.antialiasing = antialiasing;
118      this.width = width;
119      this.height = height;
120      //  this.dpi = dpi;
121      this.CamPos = CamPos;
122      this.viewDir = viewDir;
123      this.upVector = upVector;
124      this.rightVector = rightVector;
125      this.Xrot = Xrot;
126      this.Yrot = Yrot;
127      this.Zrot = Zrot;
128      this.parametersToRun = parametersToRun;
129     
130//     System.out.println(SaveToFileLocation + "SaveToFileLocation");
131//     System.out.println(this.surfex_ + "su");
132//     System.out.println(this.fps + "FramesPerSecond");
133//     System.out.println(this.T + "Time");
134//     System.out.println(this._3d + "_3d");
135//     System.out.println(this.RotType + "RotType");
136//     System.out.println(this.height + "height");
137//     System.out.println(this.width + "width");
138//     System.out.println(this.pro + "pro");
139//     System.out.println(this.dithered + " dithered");
140//     System.out.println(this.antialiasing + " antialiasing");
141//     System.out.println(this.width + " width");
142//     System.out.println(this.height + " height");
143//     System.out.println(this.dpi + " dpi");
144//     System.out.println(this.CamPos[0] + "CamPos 0");
145//     System.out.println(this.viewDir[0] + "viewDir0");
146//     System.out.println(this.upVector[0] + "upVector0");
147//     System.out.println(this.rightVector[0] + "rightVector0");
148//     System.out.println(this.Zrot + " xrot");
149//     System.out.println(this.Yrot + " yrot");
150//     System.out.println(this.Zrot + " zrot");
151
152      N = fps * T;
153     
154      rand=((int)(Math.random()*2000000000));
155      //RotTypeROTATE_y_AXIS();//pro.jv4sx.getCamPos(),pro.jv4sx.getViewDir(),pro.jv4sx.getUpVector(),pro.jv4sx.getRightVector());
156     
157  }
158   
159    public void run() {
160//     System.out.println("saveMovie gestartet");
161        MakeMovie(StandardRot(Xrot, Yrot, Zrot));//RotTypeROTATE_y_AXIS());
162    }
163   
164    private LinkedList getRotStrings(int rotType) {
165        switch (rotType) {
166            //case ROTATE_X_AXIS:
167            // return StandardRot(Xrot, Yrot, Zrot);
168            //    case ROTATE_Y_AXIS: return RotTypeROTATE_X_AXIS();
169            //  case ROTATE_Z_AXIS: return RotTypeROTATE_Z_AXIS();
170        }
171        return null; // wird aber nicht vorkommen
172       
173    }
174   
175    private LinkedList StandardRot(int Xrot, int Yrot, int Zrot) {
176        LinkedList rotStrings = new LinkedList();
177        double tmp;
178        for (int i = 0; i < N; i++) {
179            tmp = ((double) i) / N * 2 * Math.PI;
180            rotStrings.add("rot_x=" + (tmp * Xrot) + "; rot_y=" + (tmp * Yrot)
181                           + "; rot_z=" + (tmp * Zrot) + ";\n");
182        }
183        return rotStrings;
184    }
185   
186    private void MakeMovie(LinkedList rotateStrings){//double[] camPos, double[]
187        // viewDir,double[]
188        // upVector,double[]
189        // rightVector){
190        // eine Drehung produzieren:
191       
192        int i=-1;
193       
194        JFrame pframe=createAndShowGUI(N);
195       
196        double[] runningParametersValue=new double[N];
197       
198        NumberFormat nf=NumberFormat.getNumberInstance(); 
199        nf.setMinimumIntegerDigits(3); // ggf. mit fuehrenden Nullen ausgeben
200        ListIterator rotateStringsIterator=rotateStrings.listIterator();
201        OneParameter tmpParam;
202       
203        while(rotateStringsIterator.hasNext() && 
204              (!((ProgressFrame)pframe.getContentPane()).processCanceled)){ 
205            i++; 
206           
207            int j;
208            //System.out.println("calc parameters:"+parametersToRun.length);
209            for(j=0;j<parametersToRun.length;j++){
210                tmpParam=pro.parAdmin.getParameter(parametersToRun[j]);
211//              System.out.println("from:"+tmpParam.newFrom+", to:"+tmpParam.newTo);
212//              System.out.println("i:"+i+", N-1:"+(N-1));
213                runningParametersValue[j]=(tmpParam.newFrom+
214                                           (tmpParam.newTo-tmpParam.newFrom)*i/(N-1));
215//              System.out.println("param: "+j+" :"+parametersToRun[j]+" value:"+
216//                                 runningParametersValue[j]);
217            }
218           
219            //System.out.println((i+1)+" / "+N );
220            if(omitType==0 || 
221               (omitType==1 && i+1>1) || 
222               (omitType==2 && i+1<N)) {
223                if(surfex_.cygwin==1) {
224                    ((ProgressFrame)pframe.getContentPane()).refresh(i+1,
225                                                                     "Creating Frame "+(i+1)+"/"+N,
226                                                                     surfex_.toWindows(surfex_.tmpDir+"tmp_surfex_MoviePic_"+rand+"_"+nf.format(i-1)+".jpg"));
227                } else {
228                    ((ProgressFrame)pframe.getContentPane()).refresh(i+1,"Creating Frame "+(i+1)+"/"+N,
229                                                                     surfex_.tmpDir+"tmp_surfex_MoviePic_"+rand+"_"+nf.format(i-1)+".jpg");
230                }
231                try {
232                    SavePic save=new SavePic(surfex_.tmpDir+"tmp_surfex_MoviePic_"+rand+"_"+nf.format(i)+".jpg",false,
233                                             antialiasing,height, width,300, surfex_, pro, CamPos, 
234                                             viewDir, upVector, rightVector, parametersToRun, runningParametersValue, 
235                                             surfex_.jv4sx, pro.getAllLamps() );
236                    save.setRotateString((String) rotateStringsIterator.next());
237                    save.set3d(this._3d);
238                    //  System.out.println(save.rotateString);
239                    save.start();
240                    save.join();
241                    sleep(20); // damit das System auch noch was anderes machen kann
242                } catch(Exception e){
243                    System.out.println("exception in saveThread - saveMovie"+e);
244                }
245            } else {
246                rotateStringsIterator.next();
247//              System.out.println("omit:"+omitType+", i:"+i);
248            }
249        } // end while()
250
251       
252        if(((ProgressFrame)pframe.getContentPane()).processCanceled){
253            // user hat Prozess abgebrochen
254        }else{
255            ((ProgressFrame)pframe.getContentPane()).refresh(i+1+(N/20),"producing film from frames...");
256           
257            // convert the .jpg-files into a movie file:
258//     System.out.println("try convert...");
259            try {
260//         System.out.println("convert...");
261                Runtime r = Runtime.getRuntime();
262                int delay = 60 / fps;
263                //   
264//      System.out.println("sh -exec \"convert -delay "+delay+" -loop 0 "+surfex_.tmpDir+"tmp_surfex_MoviePic_"+rand+"*.jpg \\\""+surfex.toLinux(SaveToFileLocation)+"\\\"\"");
265//      System.out.println("sh -exec \"convert -delay "+delay+" -loop 0 "+
266//                         surfex.toWindows(surfex_.tmpDir+"tmp_surfex_MoviePic_"+rand+"*.jpg") +" \\\""+
267//                         surfex.toWindows(SaveToFileLocation)+"\\\"\"");
268                Process p;
269                if(surfex_.cygwin==1) {
270                    //      p = r.exec("sh -exec \"convert -delay "+delay+" -loop 0 "+surfex_.tmpDir+"tmp_surfex_MoviePic_"+rand+"*.jpg \\\""+surfex.toLinux(SaveToFileLocation)+"\\\"\"");
271                    p = r.exec("sh -exec \"convert -delay "+delay+" -loop 0 \\\""+
272                               (surfex.toWindows(surfex_.tmpDir+"tmp_surfex_MoviePic_"+rand+"_*.jpg")).replaceAll("\\\\","\\\\\\\\") +"\\\" \\\""+
273                               (surfex.toWindows(SaveToFileLocation)).replaceAll("\\\\","\\\\\\\\")+"\\\"\"");
274                } else {
275//                  System.out.println("try to save movie to:"+
276//                                     SaveToFileLocation.replaceAll(" ", "\\\\ ")+".");
277                    p = r.exec("convert -delay "+delay+" -loop 0 "+surfex_.tmpDir+
278                               "tmp_surfex_MoviePic_"+rand+"_*.jpg "+
279                               SaveToFileLocation.replaceAll(" ", "\\ ")+"");
280                }
281                p.waitFor();
282//         String tstr="sh -exec \"convert prevstart.jpg hhhhhhhhhhhhh.gif\"";
283//         Process p = r.exec(tstr);
284//         System.out.println(tstr);//+SaveToFileLocation);
285            } catch (Exception e1) {
286                System.out.println("convert problem.");
287                System.out.println(e1.toString());
288            }   
289//     System.out.println("convert done.");
290           
291           
292            ((ProgressFrame)pframe.getContentPane()).refresh((int)(N*1.2),"Film was produced successfully");
293           
294           
295        }
296        pframe.dispose();
297       
298    } 
299   
300    private JFrame createAndShowGUI(int N) {
301    //Make sure we have nice window decorations.
302    // JFrame.setDefaultLookAndFeelDecorated(true);
303
304    //Create and set up the window.
305    JFrame frame = new JFrame("creating " + SaveToFileLocation
306        + " movie ...");
307    // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
308
309    //Create and set up the content pane.
310    ProgressFrame pframe = new ProgressFrame((int) (N * 1.2));
311    JComponent newContentPane = pframe;
312
313    //newContentPane.setOpaque(true); //content panes must be opaque
314    frame.setContentPane(newContentPane);
315
316    //Display the window.
317    if(surfex_.showMoviePreview) {
318        frame.pack();
319        frame.setVisible(true);
320    }
321    return frame;
322    //JFrame s=new AskForRatioDialog(0.0);
323    //  Thread s=new ProgressBarThread();
324  }
325}
Note: See TracBrowser for help on using the repository browser.