mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-11 16:49:16 +05:00
Update screenshot code for Togl 2
This commit is contained in:
parent
f72a247815
commit
030ad1d732
@ -352,7 +352,7 @@ proc demoredraw { } {
|
||||
set file [tk_getSaveFile -filetypes $types]
|
||||
# -defaultextension ".ppm"]
|
||||
if {$file != ""} {
|
||||
.ndraw Ng_SnapShot $file }
|
||||
Ng_SnapShot .ndraw $file }
|
||||
}
|
||||
|
||||
|
||||
|
146
ng/ngpkg.cpp
146
ng/ngpkg.cpp
@ -1994,91 +1994,26 @@ namespace netgen
|
||||
}
|
||||
|
||||
|
||||
#if TOGL_MAJOR_VERSION==1
|
||||
|
||||
#ifndef JPEGLIB
|
||||
static int Ng_SnapShot (struct Togl * togl,
|
||||
int argc, tcl_const char *argv[])
|
||||
static int Ng_SnapShot(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const *argv)
|
||||
{
|
||||
const char * filename = argv[2];
|
||||
struct Togl *togl;
|
||||
if (Togl_GetToglFromObj(interp, argv[1], &togl) != TCL_OK)
|
||||
return TCL_ERROR;
|
||||
const char * filename = Tcl_GetString(argv[2]);
|
||||
|
||||
char str[250];
|
||||
char filename2[250];
|
||||
int len = strlen(filename);
|
||||
strcpy (filename2, filename);
|
||||
|
||||
filename2[len-3] = 'p';
|
||||
filename2[len-2] = 'p';
|
||||
filename2[len-1] = 'm';
|
||||
filename2[len] = 0;
|
||||
|
||||
cout << "Snapshot to file '" << filename << endl;
|
||||
|
||||
int w = Togl_Width (togl);
|
||||
w = int((w + 1) / 4) * 4 + 4;
|
||||
int h = Togl_Height (togl);
|
||||
|
||||
// unsigned char * buffer = new unsigned char[w*h*4];
|
||||
unsigned char * buffer = new unsigned char[w*h*3];
|
||||
glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
ofstream outfile(filename2);
|
||||
outfile << "P6" << endl
|
||||
<< "# CREATOR: Netgen" << endl
|
||||
<< w << " " << h << endl
|
||||
<< "255" << endl;
|
||||
for (int i = 0; i < h; i++)
|
||||
for (int j = 0; j < w; j++)
|
||||
for (int k = 0; k < 3; k++)
|
||||
outfile.put (buffer[k+3*j+3*w*(h-i-1)]);
|
||||
outfile << flush;
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
// convert image file (Unix/Linux only):
|
||||
sprintf(str,"convert -quality 100 %s %s", filename2, filename);
|
||||
|
||||
int err = system(str);
|
||||
if (err != 0)
|
||||
{
|
||||
Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot convert image file", TCL_VOLATILE);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(str,"rm %s", filename2);
|
||||
|
||||
err = system(str);
|
||||
if (err != 0)
|
||||
{
|
||||
Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot delete temporary file", TCL_VOLATILE);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
static int Ng_SnapShot (struct Togl * togl,
|
||||
int argc, tcl_const char *argv[])
|
||||
{
|
||||
const char * filename = argv[2];
|
||||
int len = strlen(filename);
|
||||
Array<char> buffer(w*h*3);
|
||||
glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]);
|
||||
|
||||
#ifdef JPEGLIB
|
||||
if (strcmp ("jpg", filename+len-3) == 0)
|
||||
{
|
||||
cout << "Snapshot to file '" << filename << "'" << endl;
|
||||
|
||||
int w = Togl_Width (togl);
|
||||
// w = int((w + 1) / 4) * 4 + 4;
|
||||
int h = Togl_Height (togl);
|
||||
|
||||
// unsigned char * buffer = new unsigned char[w*h*4];
|
||||
unsigned char * buffer = new unsigned char[w*h*3];
|
||||
glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
struct jpeg_compress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
FILE *outfile = fopen(filename,"wb");
|
||||
@ -2112,10 +2047,57 @@ namespace netgen
|
||||
fprintf( stdout, "done [ok]\n" );
|
||||
fflush( stdout );
|
||||
|
||||
free( buffer );
|
||||
return TCL_OK;
|
||||
}
|
||||
else
|
||||
#endif // JPEGLIB
|
||||
{
|
||||
char str[250];
|
||||
char filename2[250];
|
||||
int len = strlen(filename);
|
||||
strcpy (filename2, filename);
|
||||
|
||||
filename2[len-3] = 'p';
|
||||
filename2[len-2] = 'p';
|
||||
filename2[len-1] = 'm';
|
||||
filename2[len] = 0;
|
||||
|
||||
cout << "Snapshot to file '" << filename << endl;
|
||||
|
||||
int w = Togl_Width (togl);
|
||||
w = int((w + 1) / 4) * 4 + 4;
|
||||
int h = Togl_Height (togl);
|
||||
|
||||
ofstream outfile(filename2);
|
||||
outfile << "P6" << endl
|
||||
<< "# CREATOR: Netgen" << endl
|
||||
<< w << " " << h << endl
|
||||
<< "255" << endl;
|
||||
for (int i = 0; i < h; i++)
|
||||
for (int j = 0; j < w; j++)
|
||||
for (int k = 0; k < 3; k++)
|
||||
outfile.put (buffer[k+3*j+3*w*(h-i-1)]);
|
||||
outfile << flush;
|
||||
|
||||
// convert image file (Unix/Linux only):
|
||||
sprintf(str,"convert -quality 100 %s %s", filename2, filename);
|
||||
|
||||
int err = system(str);
|
||||
if (err != 0)
|
||||
{
|
||||
Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot convert image file", TCL_VOLATILE);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(str,"rm %s", filename2);
|
||||
|
||||
err = system(str);
|
||||
if (err != 0)
|
||||
{
|
||||
Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot delete temporary file", TCL_VOLATILE);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
cout << "Snapshot to " << filename << " not supported" << endl;
|
||||
return TCL_ERROR;
|
||||
@ -2123,18 +2105,6 @@ namespace netgen
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
|
||||
// TODO: JPEGLIB for Togl2
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef FFMPEG
|
||||
static int Ng_VideoClip(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const *argv)
|
||||
@ -3083,7 +3053,7 @@ void PlayAnimFile(const char* name, int speed, int maxcnt)
|
||||
Tcl_CreateObjCommand(interp, "reshape", reshape, NULL, NULL);
|
||||
|
||||
// Togl_TimerFunc( idle );
|
||||
// Togl_CreateCommand( (char*)"Ng_SnapShot", Ng_SnapShot);
|
||||
Tcl_CreateObjCommand(interp, "Ng_SnapShot", Ng_SnapShot, NULL, NULL);
|
||||
Tcl_CreateObjCommand(interp, "Ng_VideoClip", Ng_VideoClip, NULL, NULL);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
const char * ngscript[] = {""
|
||||
,"catch {lappend auto_path $env(NETGENDIR) }\n"
|
||||
,"catch {lappend auto_path $env(NETGENDIR)/../lib }\n"
|
||||
,"load libgui[info sharedlibextension] gui\n"
|
||||
,"set batchmode [Ng_GetCommandLineParameter batchmode]\n"
|
||||
,"if {$batchmode==\"undefined\"} {\n"
|
||||
,"if {[catch {package require tkdnd } result ]} {\n"
|
||||
@ -922,7 +924,7 @@ const char * ngscript[] = {""
|
||||
,"global videoactive\n"
|
||||
,"if { $videoactive == 1 } {\n"
|
||||
,"puts \"addframe\"\n"
|
||||
,".ndraw Ng_VideoClip addframe\n"
|
||||
,"Ng_VideoClip .ndraw addframe\n"
|
||||
,"}\n"
|
||||
,"if { $result == 0 && $stopdemo == 0 } {\n"
|
||||
,"after 1 { demoredraw }\n"
|
||||
@ -949,7 +951,7 @@ const char * ngscript[] = {""
|
||||
,"}\n"
|
||||
,"set file [tk_getSaveFile -filetypes $types]\n"
|
||||
,"if {$file != \"\"} {\n"
|
||||
,".ndraw Ng_SnapShot $file }\n"
|
||||
,"Ng_SnapShot .ndraw $file }\n"
|
||||
,"}\n"
|
||||
,".ngmenu.file add cascade -label \"Video clip\" -menu .ngmenu.file.video\n"
|
||||
,"menu .ngmenu.file.video\n"
|
||||
@ -961,13 +963,13 @@ const char * ngscript[] = {""
|
||||
,"}\n"
|
||||
,"set file [tk_getSaveFile -filetypes $types]\n"
|
||||
,"if {$file != \"\"} {\n"
|
||||
,".ndraw Ng_VideoClip init $file\n"
|
||||
,"Ng_VideoClip .ndraw init $file\n"
|
||||
,"global videoactive\n"
|
||||
,"set videoactive 1\n"
|
||||
,"}\n"
|
||||
,"}\n"
|
||||
,".ngmenu.file.video add command -label \"add frame...\" \\\n"
|
||||
,"-command {.ndraw Ng_VideoClip addframe }\n"
|
||||
,"-command {Ng_VideoClip .ndraw addframe }\n"
|
||||
,".ngmenu.file.video add command -label \"one cycle\" \\\n"
|
||||
,"-command {\n"
|
||||
,"set visoptions.redrawperiodic 1\n"
|
||||
@ -975,13 +977,13 @@ const char * ngscript[] = {""
|
||||
,"puts \"j = $j\"\n"
|
||||
,"Ng_Vis_Set time [expr (1000 * $j / 100)]\n"
|
||||
,"redraw\n"
|
||||
,".ndraw Ng_VideoClip addframe\n"
|
||||
,"Ng_VideoClip .ndraw addframe\n"
|
||||
,"after 200\n"
|
||||
,"}\n"
|
||||
,"}\n"
|
||||
,".ngmenu.file.video add command -label \"finalize...\" \\\n"
|
||||
,"-command {\n"
|
||||
,".ndraw Ng_VideoClip finalize\n"
|
||||
,"Ng_VideoClip .ndraw finalize\n"
|
||||
,"global videoactive\n"
|
||||
,"set videoactive 0\n"
|
||||
,"}\n"
|
||||
@ -993,6 +995,7 @@ const char * ngscript[] = {""
|
||||
,"puts \"Thank you for using $progname\";\n"
|
||||
,"if { [catch { unload libngsolve[info sharedlibextension] ngsolve } result ] } {\n"
|
||||
,"}\n"
|
||||
,"after cancel { timer2 }\n"
|
||||
,"Ng_Exit;\n"
|
||||
,"destroy .\n"
|
||||
,"}\n"
|
||||
@ -1336,7 +1339,7 @@ const char * ngscript[] = {""
|
||||
,"global videoactive\n"
|
||||
,"if { $videoactive == 1 } {\n"
|
||||
,"puts \"addframe\"\n"
|
||||
,".ndraw Ng_VideoClip addframe\n"
|
||||
,"Ng_VideoClip .ndraw addframe\n"
|
||||
,"}\n"
|
||||
,"}\n"
|
||||
,"if { $multithread_redraw == 2 } {\n"
|
||||
@ -1345,7 +1348,7 @@ const char * ngscript[] = {""
|
||||
,"global videoactive\n"
|
||||
,"if { $videoactive == 1 } {\n"
|
||||
,"puts \"addframe\"\n"
|
||||
,".ndraw Ng_VideoClip addframe\n"
|
||||
,"Ng_VideoClip .ndraw addframe\n"
|
||||
,"}\n"
|
||||
,"after 1 { timer2 }\n"
|
||||
,"return\n"
|
||||
@ -2535,10 +2538,10 @@ const char * ngscript[] = {""
|
||||
,"wm deiconify $w\n"
|
||||
,"} {\n"
|
||||
,"toplevel $w\n"
|
||||
,"frame $w.face -borderwidth 3\n"
|
||||
,"ttk::frame $w.face -borderwidth 3\n"
|
||||
,"pack $w.face -fill x\n"
|
||||
,"ttk::label $w.face.lab -text \"face index:\"\n"
|
||||
,"ttk::label $w.face.ent -text 1 -padx 4\n"
|
||||
,"ttk::label $w.face.ent -text 1\n"
|
||||
,"ttk::button $w.face.next -text \"next\" -command {\n"
|
||||
,"set w .bcprop_dlg;\n"
|
||||
,"set facenr [$w.face.ent cget -text]\n"
|
||||
@ -2570,7 +2573,7 @@ const char * ngscript[] = {""
|
||||
,"redraw\n"
|
||||
,"}\n"
|
||||
,"pack $w.face.lab $w.face.ent $w.face.prev $w.face.next -side left\n"
|
||||
,"frame $w.bc -borderwidth 3\n"
|
||||
,"ttk::frame $w.bc -borderwidth 3\n"
|
||||
,"pack $w.bc -fill x\n"
|
||||
,"ttk::label $w.bc.lab -text \"bc property:\"\n"
|
||||
,"entry $w.bc.ent -width 5 -relief sunken\n"
|
||||
@ -2583,12 +2586,12 @@ const char * ngscript[] = {""
|
||||
,"Ng_BCProp setall [$w.bc.ent get];\n"
|
||||
,"}\n"
|
||||
,"pack $w.bc.lab $w.bc.ent $w.bc.but $w.bc.but2 -side left -expand yes\n"
|
||||
,"frame $w.bcname -borderwidth 3\n"
|
||||
,"ttk::frame $w.bcname -borderwidth 3\n"
|
||||
,"pack $w.bcname -fill x\n"
|
||||
,"ttk::label $w.bcname.lab -text \"bc name:\"\n"
|
||||
,"ttk::label $w.bcname.ent -text \"-\"\n"
|
||||
,"pack $w.bcname.lab $w.bcname.ent -side left -expand yes\n"
|
||||
,"frame $w.bu\n"
|
||||
,"ttk::frame $w.bu\n"
|
||||
,"pack $w.bu -fill x -ipady 3\n"
|
||||
,"ttk::button $w.bu.close -text \"Close\" -command { destroy .bcprop_dlg }\n"
|
||||
,"pack $w.bu.close -expand yes -side left\n"
|
||||
|
Loading…
Reference in New Issue
Block a user