GLVis  v4.2
Accurate and flexible finite element visualization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
threads.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-443271.
4 //
5 // This file is part of the GLVis visualization tool and library. For more
6 // information and source code availability see https://glvis.org.
7 //
8 // GLVis is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #include "visual.hpp"
13 #include "palettes.hpp"
14 
15 using namespace std;
16 
17 extern const char *strings_off_on[]; // defined in vsdata.cpp
18 
19 
21  VisualizationSceneScalarData **_vs, StreamState& state, bool *_keep_attr)
22  : curr_state(state)
23 {
24  vs = _vs;
25  keep_attr = _keep_attr;
26  // should be set in this thread by a call to InitVisualization()
27  thread_wnd = GetAppWindow();
28 
29  num_waiting = 0;
30  terminating = false;
31  command = NO_COMMAND;
32 
33  autopause = 0;
34 }
35 
36 int GLVisCommand::lock()
37 {
38  int my_id;
39  unique_lock<mutex> scope_lock(glvis_mutex);
40  if (terminating)
41  {
42  return -1;
43  }
44  my_id = num_waiting++;
45  while (my_id > 0)
46  {
47  glvis_cond.wait(scope_lock);
48  if (terminating)
49  {
50  num_waiting--;
51  return -1;
52  }
53  my_id--;
54  }
55  return 0;
56 }
57 
58 int GLVisCommand::signal()
59 {
60  command_ready = true;
61 
62  if (thread_wnd)
63  {
64  thread_wnd->signalLoop();
65  }
66 
67  return 0;
68 }
69 
70 void GLVisCommand::unlock()
71 {
72  command_ready = false;
73 
74  lock_guard<mutex> scope_lock(glvis_mutex);
75  num_waiting--;
76  if (num_waiting > 0)
77  {
78  glvis_cond.notify_all();
79  }
80 }
81 
82 int GLVisCommand::NewMeshAndSolution(std::unique_ptr<Mesh> _new_m,
83  std::unique_ptr<GridFunction> _new_g)
84 {
85  if (lock() < 0)
86  {
87  return -1;
88  }
89  command = NEW_MESH_AND_SOLUTION;
90  new_state.mesh = std::move(_new_m);
91  new_state.grid_f = std::move(_new_g);
92  if (signal() < 0)
93  {
94  return -2;
95  }
96  return 0;
97 }
98 
99 int GLVisCommand::Screenshot(const char *filename)
100 {
101  if (lock() < 0)
102  {
103  return -1;
104  }
105  command = SCREENSHOT;
106  screenshot_filename = filename;
107  if (signal() < 0)
108  {
109  return -2;
110  }
111  return 0;
112 }
113 
114 int GLVisCommand::KeyCommands(const char *keys)
115 {
116  if (lock() < 0)
117  {
118  return -1;
119  }
120  command = KEY_COMMANDS;
121  key_commands = keys;
122  if (signal() < 0)
123  {
124  return -2;
125  }
126  return 0;
127 }
128 
129 int GLVisCommand::WindowSize(int w, int h)
130 {
131  if (lock() < 0)
132  {
133  return -1;
134  }
135  command = WINDOW_SIZE;
136  window_w = w;
137  window_h = h;
138  if (signal() < 0)
139  {
140  return -2;
141  }
142  return 0;
143 }
144 
145 int GLVisCommand::WindowGeometry(int x, int y, int w, int h)
146 {
147  if (lock() < 0)
148  {
149  return -1;
150  }
151  command = WINDOW_GEOMETRY;
152  window_x = x;
153  window_y = y;
154  window_w = w;
155  window_h = h;
156  if (signal() < 0)
157  {
158  return -2;
159  }
160  return 0;
161 }
162 
163 int GLVisCommand::WindowTitle(const char *title)
164 {
165  if (lock() < 0)
166  {
167  return -1;
168  }
169  command = WINDOW_TITLE;
170  window_title = title;
171  if (signal() < 0)
172  {
173  return -2;
174  }
175  return 0;
176 }
177 
178 int GLVisCommand::PlotCaption(const char *caption)
179 {
180  if (lock() < 0)
181  {
182  return -1;
183  }
184  command = PLOT_CAPTION;
185  plot_caption = caption;
186  if (signal() < 0)
187  {
188  return -2;
189  }
190  return 0;
191 }
192 
193 int GLVisCommand::AxisLabels(const char *a_x, const char *a_y, const char *a_z)
194 {
195  if (lock() < 0)
196  {
197  return -1;
198  }
199  command = AXIS_LABELS;
200  axis_label_x = a_x;
201  axis_label_y = a_y;
202  axis_label_z = a_z;
203  if (signal() < 0)
204  {
205  return -2;
206  }
207  return 0;
208 }
209 
211 {
212  if (lock() < 0)
213  {
214  return -1;
215  }
216  command = PAUSE;
217  if (signal() < 0)
218  {
219  return -2;
220  }
221  return 0;
222 }
223 
224 int GLVisCommand::ViewAngles(double theta, double phi)
225 {
226  if (lock() < 0)
227  {
228  return -1;
229  }
230  command = VIEW_ANGLES;
231  view_ang_theta = theta;
232  view_ang_phi = phi;
233  if (signal() < 0)
234  {
235  return -2;
236  }
237  return 0;
238 }
239 
240 int GLVisCommand::Zoom(double factor)
241 {
242  if (lock() < 0)
243  {
244  return -1;
245  }
246  command = ZOOM;
247  zoom_factor = factor;
248  if (signal() < 0)
249  {
250  return -2;
251  }
252  return 0;
253 }
254 
255 int GLVisCommand::Subdivisions(int tot, int bdr)
256 {
257  if (lock() < 0)
258  {
259  return -1;
260  }
261  command = SUBDIVISIONS;
262  subdiv_tot = tot;
263  subdiv_bdr = bdr;
264  if (signal() < 0)
265  {
266  return -2;
267  }
268  return 0;
269 }
270 
271 int GLVisCommand::ValueRange(double minv, double maxv)
272 {
273  if (lock() < 0)
274  {
275  return -1;
276  }
277  command = VALUE_RANGE;
278  val_min = minv;
279  val_max = maxv;
280  if (signal() < 0)
281  {
282  return -2;
283  }
284  return 0;
285 }
286 
287 int GLVisCommand::SetShading(const char *shd)
288 {
289  if (lock() < 0)
290  {
291  return -1;
292  }
293  command = SHADING;
294  shading = shd;
295  if (signal() < 0)
296  {
297  return -2;
298  }
299  return 0;
300 }
301 
302 int GLVisCommand::ViewCenter(double x, double y)
303 {
304  if (lock() < 0)
305  {
306  return -1;
307  }
308  command = VIEW_CENTER;
309  view_center_x = x;
310  view_center_y = y;
311  if (signal() < 0)
312  {
313  return -2;
314  }
315  return 0;
316 }
317 
318 int GLVisCommand::Autoscale(const char *mode)
319 {
320  if (lock() < 0)
321  {
322  return -1;
323  }
324  command = AUTOSCALE;
325  autoscale_mode = mode;
326  if (signal() < 0)
327  {
328  return -2;
329  }
330  return 0;
331 }
332 
334 {
335  if (lock() < 0)
336  {
337  return -1;
338  }
339  command = PALETTE;
340  palette = pal;
341  if (signal() < 0)
342  {
343  return -2;
344  }
345  return 0;
346 }
347 
349 {
350  if (lock() < 0)
351  {
352  return -1;
353  }
354  command = PALETTE_REPEAT;
355  palette_repeat = n;
356  if (signal() < 0)
357  {
358  return -2;
359  }
360  return 0;
361 }
362 
363 int GLVisCommand::Camera(const double cam[])
364 {
365  if (lock() < 0)
366  {
367  return -1;
368  }
369  command = CAMERA;
370  for (int i = 0; i < 9; i++)
371  {
372  camera[i] = cam[i];
373  }
374  if (signal() < 0)
375  {
376  return -2;
377  }
378  return 0;
379 }
380 
381 int GLVisCommand::Autopause(const char *mode)
382 {
383  if (lock() < 0)
384  {
385  return -1;
386  }
387  command = AUTOPAUSE;
388  autopause_mode = mode;
389  if (signal() < 0)
390  {
391  return -2;
392  }
393  return 0;
394 }
395 
397 {
398  if (!command_ready)
399  {
400  return 1;
401  }
402 
403  switch (command)
404  {
405  case NO_COMMAND:
406  break;
407 
408  case NEW_MESH_AND_SOLUTION:
409  {
410  double mesh_range = -1.0;
411  if (!new_state.grid_f)
412  {
413  new_state.save_coloring = false;
414  new_state.SetMeshSolution();
415  mesh_range = new_state.grid_f->Max() + 1.0;
416  }
417  if (curr_state.SetNewMeshAndSolution(std::move(new_state), *vs))
418  {
419  if (mesh_range > 0.0)
420  {
421  (*vs)->SetValueRange(-mesh_range, mesh_range);
422  }
423  MyExpose();
424  }
425  else
426  {
427  cout << "Stream: field type does not match!" << endl;
428  }
429  if (autopause)
430  {
431  cout << "Autopause ..." << endl;
432  ThreadsStop();
433  }
434  break;
435  }
436 
437  case SCREENSHOT:
438  {
439  cout << "Command: screenshot -> " << screenshot_filename << endl;
440  // Allow SdlWindow to handle the expose and screenshot action, in case
441  // any actions need to be taken before MyExpose().
442  GetAppWindow()->screenshot(screenshot_filename, true);
443  break;
444  }
445 
446  case KEY_COMMANDS:
447  {
448  cout << "Command: keys: '" << key_commands << "'" << endl;
449  // SendKeySequence(key_commands.c_str());
450  CallKeySequence(key_commands.c_str());
451  MyExpose();
452  break;
453  }
454 
455  case WINDOW_SIZE:
456  {
457  cout << "Command: window_size: " << window_w << " x " << window_h << endl;
458  ResizeWindow(window_w, window_h);
459  break;
460  }
461 
462  case WINDOW_GEOMETRY:
463  {
464  cout << "Command: window_geometry: "
465  << "@(" << window_x << "," << window_y << ") "
466  << window_w << " x " << window_h << endl;
467  MoveResizeWindow(window_x, window_y, window_w, window_h);
468  break;
469  }
470 
471  case WINDOW_TITLE:
472  {
473  cout << "Command: window_title: " << window_title << endl;
474  SetWindowTitle(window_title.c_str());
475  break;
476  }
477 
478  case PLOT_CAPTION:
479  {
480  cout << "Command: plot_caption: " << plot_caption << endl;
481  ::plot_caption = plot_caption;
482  (*vs)->PrepareCaption(); // turn on or off the caption
483  MyExpose();
484  break;
485  }
486 
487  case AXIS_LABELS:
488  {
489  cout << "Command: axis_labels: '" << axis_label_x << "' '"
490  << axis_label_y << "' '" << axis_label_z << "'" << endl;
491  (*vs)->SetAxisLabels(axis_label_x.c_str(), axis_label_y.c_str(),
492  axis_label_z.c_str());
493  MyExpose();
494  break;
495  }
496 
497  case PAUSE:
498  {
499  cout << "Command: pause: ";
500  ToggleThreads();
501  break;
502  }
503 
504  case VIEW_ANGLES:
505  {
506  cout << "Command: view: " << view_ang_theta << ' ' << view_ang_phi
507  << endl;
508  (*vs)->SetView(view_ang_theta, view_ang_phi);
509  MyExpose();
510  break;
511  }
512 
513  case ZOOM:
514  {
515  cout << "Command: zoom: " << zoom_factor << endl;
516  (*vs)->Zoom(zoom_factor);
517  MyExpose();
518  break;
519  }
520 
521  case SUBDIVISIONS:
522  {
523  cout << "Command: subdivisions: " << flush;
524  (*vs)->SetRefineFactors(subdiv_tot, subdiv_bdr);
525  cout << subdiv_tot << ' ' << subdiv_bdr << endl;
526  MyExpose();
527  break;
528  }
529 
530  case VALUE_RANGE:
531  {
532  cout << "Command: valuerange: " << flush;
533  (*vs)->SetValueRange(val_min, val_max);
534  cout << val_min << ' ' << val_max << endl;
535  MyExpose();
536  break;
537  }
538 
539  case SHADING:
540  {
541  cout << "Command: shading: " << flush;
542  int s = -1;
543  if (shading == "flat")
544  {
545  s = 0;
546  }
547  else if (shading == "smooth")
548  {
549  s = 1;
550  }
551  else if (shading == "cool")
552  {
553  s = 2;
554  }
555  if (s != -1)
556  {
557  (*vs)->SetShading(s, false);
558  cout << shading << endl;
559  MyExpose();
560  }
561  else
562  {
563  cout << shading << " ?" << endl;
564  }
565  break;
566  }
567 
568  case VIEW_CENTER:
569  {
570  cout << "Command: viewcenter: "
571  << view_center_x << ' ' << view_center_y << endl;
572  (*vs)->ViewCenterX = view_center_x;
573  (*vs)->ViewCenterY = view_center_y;
574  MyExpose();
575  break;
576  }
577 
578  case AUTOSCALE:
579  {
580  cout << "Command: autoscale: " << autoscale_mode;
581  if (autoscale_mode == "off")
582  {
583  (*vs)->SetAutoscale(0);
584  }
585  else if (autoscale_mode == "on")
586  {
587  (*vs)->SetAutoscale(1);
588  }
589  else if (autoscale_mode == "value")
590  {
591  (*vs)->SetAutoscale(2);
592  }
593  else if (autoscale_mode == "mesh")
594  {
595  (*vs)->SetAutoscale(3);
596  }
597  else
598  {
599  cout << '?';
600  }
601  cout << endl;
602  break;
603  }
604 
605  case PALETTE:
606  {
607  cout << "Command: palette: " << palette << endl;
608  (*vs)->palette.SetIndex(palette-1);
609  if (!GetUseTexture())
610  {
611  (*vs)->EventUpdateColors();
612  }
613  MyExpose();
614  break;
615  }
616 
617  case PALETTE_REPEAT:
618  {
619  cout << "Command: palette_repeat: " << palette_repeat << endl;
620  (*vs)->palette.SetRepeatTimes(palette_repeat);
621  (*vs)->palette.Init();
622 
623  if (!GetUseTexture())
624  {
625  (*vs)->EventUpdateColors();
626  }
627  MyExpose();
628  break;
629  }
630 
631  case CAMERA:
632  {
633  cout << "Command: camera: ";
634  for (int i = 0; i < 9; i++)
635  {
636  cout << ' ' << camera[i];
637  }
638  cout << endl;
639  (*vs)->cam.Set(camera);
640  MyExpose();
641  break;
642  }
643 
644  case AUTOPAUSE:
645  {
646  if (autopause_mode == "off" || autopause_mode == "0")
647  {
648  autopause = 0;
649  }
650  else
651  {
652  autopause = 1;
653  }
654  cout << "Command: autopause: " << strings_off_on[autopause] << endl;
655  if (autopause)
656  {
657  ThreadsStop();
658  }
659  else
660  {
661  ThreadsRun(); // probably not needed
662  }
663  break;
664  }
665 
666  }
667 
668  command = NO_COMMAND;
669  unlock();
670  return 0;
671 }
672 
674 {
675  {
676  lock_guard<mutex> scope_lock(glvis_mutex);
677  terminating = true;
678  }
679  {
680  lock_guard<mutex> scope_lock(glvis_mutex);
681  if (num_waiting > 0)
682  {
683  glvis_cond.notify_all();
684  }
685  }
686 }
687 
689 {
690  autopause = autopause ? 0 : 1;
691  cout << "Autopause: " << strings_off_on[autopause] << endl;
692  if (autopause)
693  {
694  ThreadsStop();
695  }
696  else
697  {
698  ThreadsRun();
699  }
700 }
701 
703 {
704  if (num_waiting > 0)
705  {
706  cout << "\nGLVisCommand::~GLVisCommand() : num_waiting = "
707  << num_waiting << '\n' << endl;
708  }
709 }
710 
712  GLVisCommand* cmd)
713  : is(std::move(_is)), glvis_command(cmd)
714 {
715  new_m = NULL;
716  new_g = NULL;
717 
718  if (is.size() > 0)
719  {
720  tid = std::thread(&communication_thread::execute, this);
721  }
722 }
723 
725 {
726  if (is.size() > 0)
727  {
728  terminate_thread = true;
729  tid.join();
730  }
731 }
732 
733 void communication_thread::execute()
734 {
735  while (1)
736  {
737  *is[0] >> ws;
738  // thread cancellation point
739  if (terminate_thread) { break; }
740 
741  *is[0] >> ident;
742  if (!(*is[0]))
743  {
744  break;
745  }
746 
747  if (ident == "mesh" || ident == "solution" ||
748  ident == "parallel")
749  {
750  bool fix_elem_orient = glvis_command->FixElementOrientations();
751  StreamState tmp;
752  if (ident == "mesh")
753  {
754  tmp.mesh.reset(new Mesh(*is[0], 1, 0, fix_elem_orient));
755  if (!(*is[0]))
756  {
757  break;
758  }
759  tmp.grid_f = NULL;
760  }
761  else if (ident == "solution")
762  {
763  tmp.mesh.reset(new Mesh(*is[0], 1, 0, fix_elem_orient));
764  if (!(*is[0]))
765  {
766  break;
767  }
768  tmp.grid_f.reset(new GridFunction(tmp.mesh.get(), *is[0]));
769  if (!(*is[0]))
770  {
771  break;
772  }
773  }
774  else if (ident == "parallel")
775  {
776  Array<Mesh *> mesh_array;
777  Array<GridFunction *> gf_array;
778  int proc, nproc, np = 0;
779  bool keep_attr = glvis_command->KeepAttrib();
780  do
781  {
782  istream &isock = *is[np];
783  isock >> nproc >> proc >> ws;
784 #ifdef GLVIS_DEBUG
785  cout << "connection[" << np << "]: parallel " << nproc << ' '
786  << proc << endl;
787 #endif
788  isock >> ident >> ws; // "solution"
789  mesh_array.SetSize(nproc);
790  gf_array.SetSize(nproc);
791  mesh_array[proc] = new Mesh(isock, 1, 0, fix_elem_orient);
792  if (!keep_attr)
793  {
794  // set element and boundary attributes to proc+1
795  for (int i = 0; i < mesh_array[proc]->GetNE(); i++)
796  {
797  mesh_array[proc]->GetElement(i)->SetAttribute(proc+1);
798  }
799  for (int i = 0; i < mesh_array[proc]->GetNBE(); i++)
800  {
801  mesh_array[proc]->GetBdrElement(i)->SetAttribute(proc+1);
802  }
803  }
804  gf_array[proc] = new GridFunction(mesh_array[proc], isock);
805  np++;
806  if (np == nproc)
807  {
808  break;
809  }
810  *is[np] >> ident >> ws; // "parallel"
811  }
812  while (1);
813  tmp.mesh.reset(new Mesh(mesh_array, nproc));
814  tmp.grid_f.reset(new GridFunction(tmp.mesh.get(), gf_array, nproc));
815 
816  for (int p = 0; p < nproc; p++)
817  {
818  delete gf_array[nproc-1-p];
819  delete mesh_array[nproc-1-p];
820  }
821  gf_array.DeleteAll();
822  mesh_array.DeleteAll();
823  }
824 
825  // cout << "Stream: new solution" << endl;
826 
828 
829  if (glvis_command->NewMeshAndSolution(std::move(tmp.mesh),
830  std::move(tmp.grid_f)))
831  {
832  goto comm_terminate;
833  }
834  }
835  else if (ident == "screenshot")
836  {
837  string filename;
838 
839  *is[0] >> ws >> filename;
840 
841  // all processors sent the screenshot command
842  for (size_t i = 1; i < is.size(); i++)
843  {
844  *is[i] >> ws >> ident; // 'screenshot'
845  *is[i] >> ws >> ident; // filename
846  }
847 
848  if (glvis_command->Screenshot(filename.c_str()))
849  {
850  goto comm_terminate;
851  }
852  }
853  else if (ident == "keys")
854  {
855  string keys;
856 
857  *is[0] >> ws >> keys;
858 
859  // all processors sent the command
860  for (size_t i = 1; i < is.size(); i++)
861  {
862  *is[i] >> ws >> ident; // 'keys'
863  *is[i] >> ws >> ident; // keys
864  }
865 
866  if (glvis_command->KeyCommands(keys.c_str()))
867  {
868  goto comm_terminate;
869  }
870  }
871  else if (ident == "window_size")
872  {
873  int w, h, t;
874 
875  *is[0] >> w >> h;
876 
877  // all processors sent the command
878  for (size_t i = 1; i < is.size(); i++)
879  {
880  *is[i] >> ws >> ident; // 'window_size'
881  *is[i] >> t >> t;
882  }
883 
884  if (glvis_command->WindowSize(w, h))
885  {
886  goto comm_terminate;
887  }
888  }
889  else if (ident == "window_geometry")
890  {
891  int x, y, w, h, t;
892 
893  *is[0] >> x >> y >> w >> h;
894 
895  // all processors sent the command
896  for (size_t i = 1; i < is.size(); i++)
897  {
898  *is[i] >> ws >> ident; // 'window_geometry'
899  *is[i] >> t >> t >> t >> t;
900  }
901 
902  if (glvis_command->WindowGeometry(x, y, w, h))
903  {
904  goto comm_terminate;
905  }
906  }
907  else if (ident == "window_title")
908  {
909  char c;
910  string title;
911 
912  *is[0] >> ws >> c; // read the opening char
913  // use the opening char as termination as well
914  getline(*is[0], title, c);
915 
916  // all processors sent the command
917  for (size_t i = 1; i < is.size(); i++)
918  {
919  *is[i] >> ws >> ident; // 'window_title'
920  *is[i] >> ws >> c;
921  getline(*is[i], ident, c);
922  }
923 
924  if (glvis_command->WindowTitle(title.c_str()))
925  {
926  goto comm_terminate;
927  }
928  }
929  else if (ident == "plot_caption")
930  {
931  char c;
932  string caption;
933 
934  *is[0] >> ws >> c; // read the opening char
935  // use the opening char as termination as well
936  getline(*is[0], caption, c);
937 
938  // all processors sent the command
939  for (size_t i = 1; i < is.size(); i++)
940  {
941  *is[i] >> ws >> ident; // 'plot_caption'
942  *is[i] >> ws >> c;
943  getline(*is[i], ident, c);
944  }
945 
946  if (glvis_command->PlotCaption(caption.c_str()))
947  {
948  goto comm_terminate;
949  }
950  }
951  else if (ident == "axis_labels")
952  {
953  char c;
954  string label_x, label_y, label_z;
955 
956  *is[0] >> ws >> c; // read the opening char
957  // use the opening char as termination as well
958  getline(*is[0], label_x, c);
959  *is[0] >> ws >> c;
960  getline(*is[0], label_y, c);
961  *is[0] >> ws >> c;
962  getline(*is[0], label_z, c);
963 
964  // all processors sent the command
965  for (size_t i = 1; i < is.size(); i++)
966  {
967  *is[i] >> ws >> ident; // 'axis_label'
968  *is[i] >> ws >> c;
969  getline(*is[i], ident, c);
970  *is[i] >> ws >> c;
971  getline(*is[i], ident, c);
972  *is[i] >> ws >> c;
973  getline(*is[i], ident, c);
974  }
975 
976  if (glvis_command->AxisLabels(label_x.c_str(),
977  label_y.c_str(),
978  label_z.c_str()))
979  {
980  goto comm_terminate;
981  }
982  }
983  else if (ident == "pause")
984  {
985  // all processors sent the command
986  for (size_t i = 1; i < is.size(); i++)
987  {
988  *is[i] >> ws >> ident; // 'pause'
989  }
990 
991  if (glvis_command->Pause())
992  {
993  goto comm_terminate;
994  }
995  }
996  else if (ident == "view")
997  {
998  double theta, phi, a;
999 
1000  *is[0] >> theta >> phi;
1001 
1002  // all processors sent the command
1003  for (size_t i = 1; i < is.size(); i++)
1004  {
1005  *is[i] >> ws >> ident; // 'view'
1006  *is[i] >> a >> a;
1007  }
1008 
1009  if (glvis_command->ViewAngles(theta, phi))
1010  {
1011  goto comm_terminate;
1012  }
1013  }
1014  else if (ident == "zoom")
1015  {
1016  double factor, a;
1017 
1018  *is[0] >> factor;
1019 
1020  // all processors sent the command
1021  for (size_t i = 1; i < is.size(); i++)
1022  {
1023  *is[i] >> ws >> ident; // 'zoom'
1024  *is[i] >> a;
1025  }
1026 
1027  if (glvis_command->Zoom(factor))
1028  {
1029  goto comm_terminate;
1030  }
1031  }
1032  else if (ident == "subdivisions")
1033  {
1034  int tot, bdr, a;
1035 
1036  *is[0] >> tot >> bdr;
1037 
1038  // all processors sent the command
1039  for (size_t i = 1; i < is.size(); i++)
1040  {
1041  *is[i] >> ws >> ident; // 'subdivisions'
1042  *is[i] >> a >> a;
1043  }
1044 
1045  if (glvis_command->Subdivisions(tot, bdr))
1046  {
1047  goto comm_terminate;
1048  }
1049  }
1050  else if (ident == "valuerange")
1051  {
1052  double minv, maxv, a;
1053 
1054  *is[0] >> minv >> maxv;
1055 
1056  // all processors sent the command
1057  for (size_t i = 1; i < is.size(); i++)
1058  {
1059  *is[i] >> ws >> ident; // 'valuerange'
1060  *is[i] >> a >> a;
1061  }
1062 
1063  if (glvis_command->ValueRange(minv, maxv))
1064  {
1065  goto comm_terminate;
1066  }
1067  }
1068  else if (ident == "shading")
1069  {
1070  string shd;
1071 
1072  *is[0] >> ws >> shd;
1073 
1074  // all processors sent the command
1075  for (size_t i = 1; i < is.size(); i++)
1076  {
1077  *is[i] >> ws >> ident; // 'shading'
1078  *is[i] >> ws >> ident;
1079  }
1080 
1081  if (glvis_command->SetShading(shd.c_str()))
1082  {
1083  goto comm_terminate;
1084  }
1085  }
1086  else if (ident == "viewcenter")
1087  {
1088  double x, y, a;
1089 
1090  *is[0] >> x >> y;
1091 
1092  // all processors sent the command
1093  for (size_t i = 1; i < is.size(); i++)
1094  {
1095  *is[i] >> ws >> ident; // 'viewcenter'
1096  *is[i] >> a >> a;
1097  }
1098 
1099  if (glvis_command->ViewCenter(x, y))
1100  {
1101  goto comm_terminate;
1102  }
1103  }
1104  else if (ident == "autoscale")
1105  {
1106  string mode;
1107 
1108  *is[0] >> ws >> mode;
1109 
1110  // all processors sent the command
1111  for (size_t i = 1; i < is.size(); i++)
1112  {
1113  *is[i] >> ws >> ident; // 'autoscale'
1114  *is[i] >> ws >> ident;
1115  }
1116 
1117  if (glvis_command->Autoscale(mode.c_str()))
1118  {
1119  goto comm_terminate;
1120  }
1121  }
1122  else if (ident == "palette")
1123  {
1124  int pal, a;
1125 
1126  *is[0] >> pal;
1127 
1128  // all processors sent the command
1129  for (size_t i = 1; i < is.size(); i++)
1130  {
1131  *is[i] >> ws >> ident; // 'palette'
1132  *is[i] >> a;
1133  }
1134 
1135  if (glvis_command->Palette(pal))
1136  {
1137  goto comm_terminate;
1138  }
1139  }
1140  else if (ident == "palette_repeat")
1141  {
1142  int n, a;
1143 
1144  *is[0] >> n;
1145 
1146  // all processors sent the command
1147  for (size_t i = 1; i < is.size(); i++)
1148  {
1149  *is[i] >> ws >> ident; // 'palette_repeat'
1150  *is[i] >> a;
1151  }
1152 
1153  if (glvis_command->PaletteRepeat(n))
1154  {
1155  goto comm_terminate;
1156  }
1157  }
1158  else if (ident == "camera")
1159  {
1160  double cam[9], a;
1161 
1162  for (int i = 0; i < 9; i++)
1163  {
1164  *is[0] >> cam[i];
1165  }
1166 
1167  // all processors sent the command
1168  for (size_t i = 1; i < is.size(); i++)
1169  {
1170  *is[i] >> ws >> ident; // 'camera'
1171  for (int j = 0; j < 9; j++)
1172  {
1173  *is[i] >> a;
1174  }
1175  }
1176 
1177  if (glvis_command->Camera(cam))
1178  {
1179  goto comm_terminate;
1180  }
1181  }
1182  else if (ident == "autopause")
1183  {
1184  string mode;
1185 
1186  *is[0] >> ws >> mode;
1187 
1188  // all processors sent the command
1189  for (size_t i = 1; i < is.size(); i++)
1190  {
1191  *is[i] >> ws >> ident; // 'autopause'
1192  *is[i] >> ws >> ident;
1193  }
1194 
1195  if (glvis_command->Autopause(mode.c_str()))
1196  {
1197  goto comm_terminate;
1198  }
1199  }
1200  else
1201  {
1202  cout << "Stream: unknown command: " << ident << endl;
1203  }
1204  }
1205 
1206  cout << "Stream: end of input." << endl;
1207 
1208 comm_terminate:
1209  for (size_t i = 0; i < is.size(); i++)
1210  {
1211  socketstream *isock = dynamic_cast<socketstream *>(is[i].get());
1212  if (isock)
1213  {
1214  isock->close();
1215  }
1216  }
1217 }
void Terminate()
Definition: threads.cpp:673
int ValueRange(double minv, double maxv)
Definition: threads.cpp:271
int Palette(int pal)
Definition: threads.cpp:333
bool FixElementOrientations()
Definition: threads.hpp:103
void Extrude1DMeshAndSolution()
Helper function for visualizing 1D data.
int WindowTitle(const char *title)
Definition: threads.cpp:163
void MyExpose(GLsizei w, GLsizei h)
Definition: aux_vis.cpp:389
int WindowGeometry(int x, int y, int w, int h)
Definition: threads.cpp:145
int SetShading(const char *shd)
Definition: threads.cpp:287
void signalLoop()
Definition: sdl.cpp:524
std::unique_ptr< mfem::GridFunction > grid_f
int AxisLabels(const char *a_x, const char *a_y, const char *a_z)
Definition: threads.cpp:193
int PaletteRepeat(int n)
Definition: threads.cpp:348
std::vector< std::unique_ptr< std::istream >> StreamCollection
Definition: threads.hpp:143
void screenshot(std::string filename, bool convert=false)
Queues a screenshot to be taken.
Definition: sdl.hpp:241
void ToggleThreads()
Definition: aux_vis.cpp:1237
communication_thread(StreamCollection _is, GLVisCommand *cmd)
Definition: threads.cpp:711
int NewMeshAndSolution(std::unique_ptr< Mesh > _new_m, std::unique_ptr< GridFunction > _new_g)
Definition: threads.cpp:82
void SetMeshSolution()
Set a (checkerboard) solution when only the mesh is given.
void ThreadsStop()
Definition: aux_vis.cpp:1259
bool SetNewMeshAndSolution(StreamState new_state, VisualizationScene *vs)
bool KeepAttrib()
Definition: threads.hpp:102
int PlotCaption(const char *caption)
Definition: threads.cpp:178
std::unique_ptr< mfem::Mesh > mesh
void ResizeWindow(int w, int h)
Definition: aux_vis.cpp:1546
int Execute()
Definition: threads.cpp:396
SdlWindow * GetAppWindow()
Definition: aux_vis.cpp:58
void MoveResizeWindow(int x, int y, int w, int h)
Definition: aux_vis.cpp:1540
void ToggleAutopause()
Definition: threads.cpp:688
thread_local GLVisCommand * glvis_command
Definition: aux_vis.cpp:39
int KeyCommands(const char *keys)
Definition: threads.cpp:114
void SetWindowTitle(const char *title)
Definition: aux_vis.cpp:1551
int WindowSize(int w, int h)
Definition: threads.cpp:129
int Zoom(double factor)
Definition: threads.cpp:240
int Autoscale(const char *mode)
Definition: threads.cpp:318
int Subdivisions(int tot, int bdr)
Definition: threads.cpp:255
int Pause()
Definition: threads.cpp:210
int Screenshot(const char *filename)
Definition: threads.cpp:99
int Autopause(const char *mode)
Definition: threads.cpp:381
const char * strings_off_on[]
Definition: vsdata.cpp:27
void ThreadsRun()
Definition: aux_vis.cpp:1267
GLVisCommand(VisualizationSceneScalarData **_vs, StreamState &thread_state, bool *_keep_attr)
Definition: threads.cpp:20
bool keep_attr
Definition: glvis.cpp:53
void CallKeySequence(const char *seq)
Definition: aux_vis.cpp:253
int ViewCenter(double x, double y)
Definition: threads.cpp:302
int GetUseTexture()
Definition: aux_vis.cpp:1556
int ViewAngles(double theta, double phi)
Definition: threads.cpp:224
int Camera(const double cam[])
Definition: threads.cpp:363