VTKFIG  0.21.20191019
Easy VTK based in situ visualization
vtkfigMainThread.h
Go to the documentation of this file.
1 
7 #include <memory>
8 #include <mutex>
9 #include <thread>
10 #include <memory>
11 #include <map>
12 #include <condition_variable>
13 
14 #include <vtkRenderWindowInteractor.h>
15 
16 #include "vtkfigCommunicator.h"
17 
18 
19 
20 namespace vtkfig
21 {
22  class Frame;
23 
24  namespace internals
25  {
26 
31  class MainThread
32  {
33  friend class vtkfig::Frame;
34  friend class Client;
35  friend class MyTimerCallback;
36  friend class MyInteractorStyle;
37 
38  public:
39  ~MainThread();
40  MainThread();
41  private:
42  vtkSmartPointer<vtkRenderWindowInteractor> interactor;
43 
44 
49  static std::shared_ptr<MainThread> CreateMainThread();
50 
52  static std::shared_ptr<MainThread> mainthread;
53 
55  static void DeleteMainThread();
56 
58  void Show();
59 
62  void Interact();
63 
65  void AddFrame(std::shared_ptr<Frame> frame);
66 
68  void RemoveFrame(int number_in_framelist);
69 
72  void Start();
73 
75  void Update();
76 
78  void Terminate(void);
79 
81  std::map<int,std::shared_ptr<Frame>> framemap;
82 
84  static void PrepareRenderThread(MainThread& thd);
85 
87  static void RenderThread(MainThread& thd);
88 
90  static void PrepareCommunicatorThread(MainThread& thd);
91 
93  static void CommunicatorThread(MainThread& thd);
94 
97  static void CommunicatorThreadCallback(MainThread& thd);
98 
99 
101  static void RTAddFrame(MainThread& mt, int iframe);
102 
104  int lastframenum=0;
105 
107  std::shared_ptr<std::thread> thread;
108 
109 
111  bool double_buffering=true;
112 
116  double timer_interval=20;
117 
119  std::mutex mutex;
120 
122  std::condition_variable condition_variable;
123 
125  bool running_multithreaded=false;
126 
128  bool try_running_multithreaded=true;
129 
131  bool communication_blocked=false;
132 
133 
135  Communicator::Command cmd=Communicator::Command::Empty;
136 
137 
139  int iframe=-1;
140 
141 
143  void SendCommand(int iframe, const std::string from,Communicator::Command cmd);
144 
146  bool connection_open=false;
147 
149  void OpenConnection(int port, int wtime);
150 
152  vtkSmartPointer<Communicator> communicator;
153 
155  int debug_level=0;
156 
157 
158  };
159  }
160 }
Main communication thread.
Definition: vtkfigMainThread.h:31
Provide a framework wrapping window+interactor+renderers from vtk.
Definition: vtkfigFrame.h:38
Client side visualization setup.
Definition: vtkfigClient.h:29
Namespace vtkfig::internals: Tools for server-client communication.