-
Notifications
You must be signed in to change notification settings - Fork 53
/
glvis.cpp
2009 lines (1847 loc) · 55.3 KB
/
glvis.cpp
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2010-2024, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-443271.
//
// This file is part of the GLVis visualization tool and library. For more
// information and source code availability see https://glvis.org.
//
// GLVis is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.
// GLVis - an OpenGL visualization server based on the MFEM library
#include <limits>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstring>
#include <ctime>
// SDL may redefine main() as SDL_main() ostensibly to ease portability.
// (WinMain() instead of main() is used as the entry point in a non-console
// Windows program.)
//
// We must instead define SDL_MAIN_HANDLED so that SDL doesn't do this
// substitution, since we need a console to accept certain user input from
// stdin.
#ifdef _WIN32
#define SDL_MAIN_HANDLED
#endif
#include "mfem.hpp"
#include "lib/palettes.hpp"
#include "lib/visual.hpp"
#include "lib/stream_reader.hpp"
using namespace std;
using namespace mfem;
const char *string_none = "(none)";
const char *string_default = "(default)";
// Global variables for command line arguments
const char *mesh_file = string_none;
const char *sol_file = string_none;
const char *vec_sol_file = string_none;
const char *gfunc_file = string_none;
const char *qfunc_file = string_none;
const char *arg_keys = string_none;
int pad_digits = 6;
int gf_component = -1;
int qf_component = -1;
int window_x = 0; // not a command line option
int window_y = 0; // not a command line option
int window_w = 400;
int window_h = 350;
const char *window_title = string_default;
const char *c_plot_caption = string_none;
thread_local string plot_caption;
thread_local string extra_caption;
bool secure = socketstream::secure_default;
// Global variables
enum InputOptions
{
INPUT_SERVER_MODE = 1,
INPUT_MESH = 2,
INPUT_SCALAR_SOL = 4,
INPUT_VECTOR_SOL = 8,
//...
INPUT_PARALLEL = 256,
};
int input = INPUT_SERVER_MODE;
thread_local StreamState stream_state;
thread_local VisualizationSceneScalarData *vs = NULL;
extern thread_local GLVisCommand* glvis_command;
thread_local communication_thread *comm_thread = NULL;
thread_local GeometryRefiner GLVisGeometryRefiner;
const char *window_titles[] = { "GLVis [scalar data]",
"GLVis [vector data]",
"GLVis [mesh]"
};
istream *script = NULL;
int scr_running = 0;
int scr_level = 0;
Vector *init_nodes = NULL;
double scr_min_val, scr_max_val;
extern char **environ;
void PrintSampleUsage(ostream &out);
// read the mesh and the solution from a file
void ReadSerial(StreamState& state);
// choose grid function component and set the input flag
void SetGridFunction(StreamState& state);
// choose quadrature function component and set the input flag
void SetQuadFunction(StreamState& state);
// read the mesh and the solution from multiple files
void ReadParallel(int np, StreamState& state);
int ReadParMeshAndGridFunction(int np, const char *mesh_prefix,
const char *sol_prefix, StreamState& state);
int ReadParMeshAndQuadFunction(int np, const char *mesh_prefix,
const char *sol_prefix, StreamState& state);
// switch representation of the quadrature function
void SwitchQuadSolution();
// Visualize the data in the global variables mesh, sol/grid_f, etc
bool GLVisInitVis(StreamState::FieldType field_type,
StreamCollection input_streams)
{
if (field_type <= StreamState::FieldType::MIN
|| field_type >= StreamState::FieldType::MAX)
{
return false;
}
const char *win_title = (window_title == string_default) ?
window_titles[(int)field_type] : window_title;
if (InitVisualization(win_title, window_x, window_y, window_w, window_h))
{
cerr << "Initializing the visualization failed." << endl;
return false;
}
if (input_streams.size() > 0)
{
GetAppWindow()->setOnKeyDown(SDLK_SPACE, ThreadsPauseFunc);
glvis_command = new GLVisCommand(&vs, stream_state, &stream_state.keep_attr);
comm_thread = new communication_thread(std::move(input_streams), glvis_command);
}
if (stream_state.quad_f)
{
GetAppWindow()->setOnKeyDown('Q', SwitchQuadSolution);
}
double mesh_range = -1.0;
if (field_type == StreamState::FieldType::SCALAR
|| field_type == StreamState::FieldType::MESH)
{
if (stream_state.grid_f)
{
stream_state.grid_f->GetNodalValues(stream_state.sol);
}
if (stream_state.mesh->SpaceDimension() == 2)
{
VisualizationSceneSolution * vss;
if (stream_state.normals.Size() > 0)
{
vs = vss = new VisualizationSceneSolution(*stream_state.mesh, stream_state.sol,
stream_state.mesh_quad.get(), &stream_state.normals);
}
else
{
vs = vss = new VisualizationSceneSolution(*stream_state.mesh, stream_state.sol,
stream_state.mesh_quad.get());
}
if (stream_state.grid_f)
{
vss->SetGridFunction(*stream_state.grid_f);
}
if (field_type == StreamState::FieldType::MESH)
{
vs->OrthogonalProjection = 1;
vs->SetLight(false);
vs->Zoom(1.8);
// Use the 'bone' palette when visualizing a 2D mesh only (otherwise
// the 'jet-like' palette is used in 2D, see vssolution.cpp).
vs->palette.SetIndex(4);
}
}
else if (stream_state.mesh->SpaceDimension() == 3)
{
VisualizationSceneSolution3d * vss;
vs = vss = new VisualizationSceneSolution3d(*stream_state.mesh,
stream_state.sol, stream_state.mesh_quad.get());
if (stream_state.grid_f)
{
vss->SetGridFunction(stream_state.grid_f.get());
}
if (field_type == StreamState::FieldType::MESH)
{
if (stream_state.mesh->Dimension() == 3)
{
// Use the 'white' palette when visualizing a 3D volume mesh only
vss->palette.SetIndex(11);
vss->SetLightMatIdx(4);
}
else
{
// Use the 'bone' palette when visualizing a surface mesh only
vss->palette.SetIndex(4);
}
// Otherwise, the 'vivid' palette is used in 3D see vssolution3d.cpp
vss->ToggleDrawAxes();
vss->ToggleDrawMesh();
}
}
if (field_type == StreamState::FieldType::MESH)
{
if (stream_state.grid_f)
{
mesh_range = stream_state.grid_f->Max() + 1.0;
}
else
{
mesh_range = stream_state.sol.Max() + 1.0;
}
}
}
else if (field_type == StreamState::FieldType::VECTOR)
{
if (stream_state.mesh->SpaceDimension() == 2)
{
if (stream_state.grid_f)
{
vs = new VisualizationSceneVector(*stream_state.grid_f);
}
else
{
vs = new VisualizationSceneVector(*stream_state.mesh, stream_state.solu,
stream_state.solv, stream_state.mesh_quad.get());
}
}
else if (stream_state.mesh->SpaceDimension() == 3)
{
if (stream_state.grid_f)
{
stream_state.ProjectVectorFEGridFunction();
vs = new VisualizationSceneVector3d(*stream_state.grid_f,
stream_state.mesh_quad.get());
}
else
{
vs = new VisualizationSceneVector3d(*stream_state.mesh, stream_state.solu,
stream_state.solv, stream_state.solw,
stream_state.mesh_quad.get());
}
}
}
if (vs)
{
// increase the refinement factors if visualizing a GridFunction
if (stream_state.grid_f)
{
vs->AutoRefine();
vs->SetShading(VisualizationSceneScalarData::Shading::Noncomforming, true);
}
if (mesh_range > 0.0)
{
vs->SetValueRange(-mesh_range, mesh_range);
vs->SetAutoscale(0);
}
if (stream_state.mesh->SpaceDimension() == 2
&& field_type == StreamState::FieldType::MESH)
{
SetVisualizationScene(vs, 2, stream_state.keys.c_str());
}
else
{
SetVisualizationScene(vs, 3, stream_state.keys.c_str());
}
}
return true;
}
void GLVisStartVis()
{
RunVisualization(); // deletes vs
vs = NULL;
if (glvis_command)
{
glvis_command->Terminate();
delete comm_thread;
delete glvis_command;
glvis_command = NULL;
}
cout << "GLVis window closed." << endl;
}
int ScriptReadSolution(istream &scr, StreamState& state)
{
string mword,sword;
cout << "Script: solution: " << flush;
// read the mesh
scr >> ws >> mword; // mesh filename (can't contain spaces)
cout << "mesh: " << mword << "; " << flush;
named_ifgzstream imesh(mword.c_str());
if (!imesh)
{
cout << "Can not open mesh file: " << mword << endl;
return 1;
}
state.SetMesh(new Mesh(imesh, 1, 0, state.fix_elem_orient));
// read the solution (GridFunction)
scr >> ws >> sword;
if (sword == mword) // mesh and solution in the same file
{
cout << "solution: " << mword << endl;
state.SetGridFunction(new GridFunction(state.mesh.get(), imesh));
}
else
{
cout << "solution: " << sword << endl;
ifgzstream isol(sword.c_str());
if (!isol)
{
cout << "Can not open solution file: " << sword << endl;
return 2;
}
state.SetGridFunction(new GridFunction(state.mesh.get(), isol));
}
state.Extrude1DMeshAndSolution();
return 0;
}
int ScriptReadQuadrature(istream &scr, StreamState& state)
{
string mword,sword;
cout << "Script: quadrature: " << flush;
// read the mesh
scr >> ws >> mword; // mesh filename (can't contain spaces)
cout << "mesh: " << mword << "; " << flush;
named_ifgzstream imesh(mword.c_str());
if (!imesh)
{
cout << "Can not open mesh file: " << mword << endl;
return 1;
}
state.SetMesh(new Mesh(imesh, 1, 0, state.fix_elem_orient));
// read the quadrature (QuadratureFunction)
scr >> ws >> sword;
if (sword == mword) // mesh and quadrature in the same file
{
cout << "quadrature: " << mword << endl;
state.SetQuadFunction(new QuadratureFunction(state.mesh.get(), imesh));
}
else
{
cout << "quadrature: " << sword << endl;
ifgzstream isol(sword.c_str());
if (!isol)
{
cout << "Can not open quadrature file: " << sword << endl;
return 2;
}
state.SetQuadFunction(new QuadratureFunction(state.mesh.get(), isol));
}
state.SetQuadSolution();
state.Extrude1DMeshAndSolution();
return 0;
}
int ScriptReadParSolution(istream &scr, StreamState& state)
{
int np, scr_keep_attr, err_read;
string mesh_prefix, sol_prefix;
cout << "Script: psolution: " << flush;
// read number of processors
scr >> np;
cout << "# processors: " << np << "; " << flush;
// read the mesh prefix
scr >> ws >> mesh_prefix; // mesh prefix (can't contain spaces)
cout << "mesh prefix: " << mesh_prefix << "; " << flush;
scr >> ws >> scr_keep_attr;
if (scr_keep_attr)
{
cout << "(real attributes); " << flush;
}
else
{
cout << "(processor attributes); " << flush;
}
// read the solution prefix
scr >> ws >> sol_prefix;
cout << "solution prefix: " << sol_prefix << endl;
err_read = ReadParMeshAndGridFunction(np, mesh_prefix.c_str(),
sol_prefix.c_str(), state);
if (!err_read)
{
state.Extrude1DMeshAndSolution();
}
return err_read;
}
int ScriptReadParQuadrature(istream &scr, StreamState& state)
{
int np, scr_keep_attr, err_read;
string mesh_prefix, quad_prefix;
cout << "Script: pquadrature: " << flush;
// read number of processors
scr >> np;
cout << "# processors: " << np << "; " << flush;
// read the mesh prefix
scr >> ws >> mesh_prefix; // mesh prefix (can't contain spaces)
cout << "mesh prefix: " << mesh_prefix << "; " << flush;
scr >> ws >> scr_keep_attr;
if (scr_keep_attr)
{
cout << "(real attributes); " << flush;
}
else
{
cout << "(processor attributes); " << flush;
}
// read the quadrature prefix
scr >> ws >> quad_prefix;
cout << "quadrature prefix: " << quad_prefix << endl;
err_read = ReadParMeshAndQuadFunction(np, mesh_prefix.c_str(),
quad_prefix.c_str(), state);
if (!err_read)
{
state.SetQuadSolution();
state.Extrude1DMeshAndSolution();
}
return err_read;
}
int ScriptReadDisplMesh(istream &scr, StreamState& state)
{
StreamState meshstate;
string word;
cout << "Script: mesh: " << flush;
scr >> ws >> word;
{
named_ifgzstream imesh(word.c_str());
if (!imesh)
{
cout << "Can not open mesh file: " << word << endl;
return 1;
}
cout << word << endl;
meshstate.SetMesh(new Mesh(imesh, 1, 0, state.fix_elem_orient));
}
meshstate.Extrude1DMeshAndSolution();
Mesh* const m = meshstate.mesh.get();
if (init_nodes == NULL)
{
init_nodes = new Vector;
meshstate.mesh->GetNodes(*init_nodes);
state.SetMesh(NULL);
state.SetGridFunction(NULL);
}
else
{
FiniteElementCollection *vfec = NULL;
FiniteElementSpace *vfes;
vfes = (FiniteElementSpace *)m->GetNodalFESpace();
if (vfes == NULL)
{
vfec = new LinearFECollection;
vfes = new FiniteElementSpace(m, vfec, m->SpaceDimension());
}
meshstate.SetGridFunction(new GridFunction(vfes));
GridFunction * const g = meshstate.grid_f.get();
if (vfec)
{
g->MakeOwner(vfec);
}
m->GetNodes(*g);
if (g->Size() == init_nodes->Size())
{
subtract(*init_nodes, *g, *g);
}
else
{
cout << "Script: incompatible meshes!" << endl;
*g = 0.0;
}
state = std::move(meshstate);
}
return 0;
}
void ExecuteScriptCommand()
{
if (!script)
{
cout << "No script stream defined! (Bug?)" << endl;
return;
}
istream &scr = *script;
string word;
int done_one_command = 0;
while (!done_one_command)
{
scr >> ws;
if (!scr.good())
{
cout << "End of script." << endl;
scr_level = 0;
return;
}
if (scr.peek() == '#')
{
getline(scr, word);
continue;
}
scr >> word;
if (word == "{")
{
scr_level++;
}
else if (word == "}")
{
scr_level--;
if (scr_level < 0)
{
scr_level = 0;
}
}
else if (word == "solution" || word == "mesh" || word == "psolution"
|| word == "quadrature" || word == "pquadrature")
{
StreamState new_state;
if (word == "solution")
{
if (ScriptReadSolution(scr, new_state))
{
done_one_command = 1;
continue;
}
}
else if (word == "quadrature")
{
if (ScriptReadQuadrature(scr, new_state))
{
done_one_command = 1;
continue;
}
}
else if (word == "mesh")
{
if (ScriptReadDisplMesh(scr, new_state))
{
done_one_command = 1;
continue;
}
if (new_state.mesh == NULL)
{
cout << "Script: unexpected 'mesh' command!" << endl;
done_one_command = 1;
continue;
}
}
else if (word == "psolution")
{
if (ScriptReadParSolution(scr, new_state))
{
done_one_command = 1;
continue;
}
}
else if (word == "pquadrature")
{
if (ScriptReadParQuadrature(scr, new_state))
{
done_one_command = 1;
continue;
}
}
if (stream_state.SetNewMeshAndSolution(std::move(new_state), vs))
{
MyExpose();
}
else
{
cout << "Different type of mesh / solution." << endl;
}
}
else if (word == "screenshot")
{
scr >> ws >> word;
cout << "Script: screenshot: " << flush;
if (Screenshot(word.c_str(), true))
{
cout << "Screenshot(" << word << ") failed." << endl;
done_one_command = 1;
continue;
}
cout << "-> " << word << endl;
if (scr_min_val > vs->GetMinV())
{
scr_min_val = vs->GetMinV();
}
if (scr_max_val < vs->GetMaxV())
{
scr_max_val = vs->GetMaxV();
}
}
else if (word == "viewcenter")
{
scr >> vs->ViewCenterX >> vs->ViewCenterY;
cout << "Script: viewcenter: "
<< vs->ViewCenterX << ' ' << vs->ViewCenterY << endl;
MyExpose();
}
else if (word == "perspective")
{
scr >> ws >> word;
cout << "Script: perspective: " << word;
if (word == "off")
{
vs->OrthogonalProjection = 1;
}
else if (word == "on")
{
vs->OrthogonalProjection = 0;
}
else
{
cout << '?';
}
cout << endl;
MyExpose();
}
else if (word == "light")
{
scr >> ws >> word;
cout << "Script: light: " << word;
if (word == "off")
{
vs->SetLight(false);
}
else if (word == "on")
{
vs->SetLight(true);
}
else
{
cout << '?';
}
cout << endl;
MyExpose();
}
else if (word == "view")
{
double theta, phi;
scr >> theta >> phi;
cout << "Script: view: " << theta << ' ' << phi << endl;
vs->SetView(theta, phi);
MyExpose();
}
else if (word == "zoom")
{
double factor;
scr >> factor;
cout << "Script: zoom: " << factor << endl;
vs->Zoom(factor);
MyExpose();
}
else if (word == "shading")
{
scr >> ws >> word;
cout << "Script: shading: " << flush;
VisualizationSceneScalarData::Shading s =
VisualizationSceneScalarData::Shading::Invalid;
if (word == "flat")
{
s = VisualizationSceneScalarData::Shading::Flat;
}
else if (word == "smooth")
{
s = VisualizationSceneScalarData::Shading::Smooth;
}
else if (word == "cool")
{
s = VisualizationSceneScalarData::Shading::Noncomforming;
}
if (s != VisualizationSceneScalarData::Shading::Invalid)
{
vs->SetShading(s, false);
cout << word << endl;
MyExpose();
}
else
{
cout << word << " ?" << endl;
}
}
else if (word == "subdivisions")
{
int t, b;
scr >> t >> b;
cout << "Script: subdivisions: " << flush;
vs->SetRefineFactors(t, b);
cout << t << ' ' << b << endl;
MyExpose();
}
else if (word == "valuerange")
{
double min, max;
scr >> min >> max;
cout << "Script: valuerange: " << flush;
vs->SetValueRange(min, max);
cout << min << ' ' << max << endl;
MyExpose();
}
else if (word == "autoscale")
{
scr >> ws >> word;
cout << "Script: autoscale: " << word;
if (word == "off")
{
vs->SetAutoscale(0);
}
else if (word == "on")
{
vs->SetAutoscale(1);
}
else if (word == "value")
{
vs->SetAutoscale(2);
}
else if (word == "mesh")
{
vs->SetAutoscale(3);
}
else
{
cout << '?';
}
cout << endl;
}
else if (word == "levellines")
{
double min, max;
int num;
scr >> min >> max >> num;
cout << "Script: levellines: " << flush;
vs->SetLevelLines(min, max, num);
vs->UpdateLevelLines();
cout << min << ' ' << max << ' ' << num << endl;
MyExpose();
}
else if (word == "axis_numberformat")
{
char delim;
string axis_formatting;
scr >> ws >> delim;
getline(scr, axis_formatting, delim);
cout << "Script: axis_numberformat: " << flush;
vs->SetAxisNumberFormat(axis_formatting);
cout << axis_formatting << endl;
MyExpose();
}
else if (word == "colorbar_numberformat")
{
char delim;
string colorbar_formatting;
scr >> ws >> delim;
getline(scr, colorbar_formatting, delim);
cout << "Script: colorbar_numberformat: " << flush;
vs->SetColorbarNumberFormat(colorbar_formatting);
cout << colorbar_formatting << endl;
MyExpose();
}
else if (word == "window")
{
scr >> window_x >> window_y >> window_w >> window_h;
cout << "Script: window: " << window_x << ' ' << window_y
<< ' ' << window_w << ' ' << window_h << endl;
MoveResizeWindow(window_x, window_y, window_w, window_h);
MyExpose();
}
else if (word == "keys")
{
scr >> stream_state.keys;
cout << "Script: keys: '" << stream_state.keys << "'" << endl;
// SendKeySequence(keys.c_str());
CallKeySequence(stream_state.keys.c_str());
MyExpose();
}
else if (word == "palette")
{
int pal;
scr >> pal;
cout << "Script: palette: " << pal << endl;
vs->palette.SetIndex(pal-1);
MyExpose();
}
else if (word == "palette_repeat")
{
int rpt_times;
scr >> rpt_times;
cout << "Script: palette_repeat: " << rpt_times << endl;
vs->palette.SetRepeatTimes(rpt_times);
vs->palette.GenerateTextures();
MyExpose();
}
else if (word == "toggle_attributes")
{
Array<int> attr_list;
cout << "Script: toggle_attributes:";
for (scr >> ws; scr.peek() != ';'; scr >> ws)
{
attr_list.Append(0);
scr >> attr_list.Last();
if (attr_list.Size() <= 256)
{
cout << ' ' << attr_list.Last();
}
else if (attr_list.Size() == 257)
{
cout << " ... " << flush;
}
}
scr.get(); // read the end symbol: ';'
cout << endl;
vs->ToggleAttributes(attr_list);
MyExpose();
}
else if (word == "rotmat")
{
cout << "Script: rotmat:";
for (int i = 0; i < 16; i++)
{
scr >> vs->rotmat[i/4][i%4];
cout << ' ' << vs->rotmat[i/4][i%4];
}
cout << endl;
MyExpose();
}
else if (word == "camera")
{
double cam[9];
cout << "Script: camera:";
for (int i = 0; i < 9; i++)
{
scr >> cam[i];
cout << ' ' << cam[i];
}
cout << endl;
vs->cam.Set(cam);
MyExpose();
}
else if (word == "scale")
{
double scale;
cout << "Script: scale:";
scr >> scale;
cout << ' ' << scale;
cout << endl;
vs->Scale(scale);
MyExpose();
}
else if (word == "translate")
{
double x, y, z;
cout << "Script: translate:";
scr >> x >> y >> z;
cout << ' ' << x << ' ' << y << ' ' << z;
cout << endl;
vs->Translate(x, y, z);
MyExpose();
}
else if (word == "plot_caption")
{
char delim;
scr >> ws >> delim;
getline(scr, plot_caption, delim);
vs->PrepareCaption(); // turn on or off the caption
MyExpose();
}
else
{
cout << "Unknown command in script: " << word << endl;
}
done_one_command = 1;
}
}
void ScriptControl();
void ScriptIdleFunc()
{
ExecuteScriptCommand();
if (scr_level == 0)
{
ScriptControl();
}
}
void ScriptControl()
{
if (scr_running)
{
scr_running = 0;
RemoveIdleFunc(ScriptIdleFunc);
}
else
{
scr_running = 1;
AddIdleFunc(ScriptIdleFunc);
}
}
void PlayScript(istream &scr)
{
string word;
scr_min_val = numeric_limits<double>::infinity();
scr_max_val = -scr_min_val;
// read initializing commands
while (1)
{
scr >> ws;
if (!scr.good())
{
cout << "Error in script" << endl;
return;
}
if (scr.peek() == '#')
{
getline(scr, word);
continue;
}
scr >> word;
if (word == "window")
{
scr >> window_x >> window_y >> window_w >> window_h;
}
else if (word == "solution")
{
if (ScriptReadSolution(scr, stream_state))
{
return;
}
// start the visualization
break;
}
else if (word == "quadrature")
{
if (ScriptReadQuadrature(scr, stream_state))
{
return;
}
// start the visualization
break;
}
else if (word == "psolution")
{
if (ScriptReadParSolution(scr, stream_state))
{
return;
}
// start the visualization
break;
}
else if (word == "pquadrature")
{
if (ScriptReadParQuadrature(scr, stream_state))
{
return;
}
// start the visualization
break;
}