VTKFIG  0.25.0
Easy VTK based in situ visualization
vtkfigFrame.h
Go to the documentation of this file.
1 #ifndef VTKFIG_FRAME_H
7 #define VTKFIG_FRAME_H
8 
9 #include <memory>
10 #include <vector>
11 #include <set>
12 
13 
14 #include <vtkSmartPointer.h>
15 #include <vtkRenderer.h>
16 #include <vtkCornerAnnotation.h>
17 #include <vtkOggTheoraWriter.h>
18 
19 #include "internals/vtkfigCommunicator.h"
20 
21 namespace vtkfig
22 {
23  class Figure;
24 
25  namespace internals
26  {
27  class Thread;
28  class InteractorStyle;
29  class TimerCallback;
30  class Client;
31  }
32 
38  class Frame
39  {
40 
41  public:
42 
43 
44 
45 
50  static std::shared_ptr<Frame> New();
51 
52 
58  void SetLayout(int nvpx, int nvpy);
59 
61  void RefreshState(int figurepos);
62 
67  void WritePNG(std::string fname);
68 
69 
74  void StartVideo(std::string fname);
75 
76 
80  void StopVideo();
81 
82 
86  void AddFigure(std::shared_ptr<Figure> figure);
87 
88 
95  void AddFigure(std::shared_ptr<Figure> figure, int ipos);
96 
97 
101  void RemoveFigure(std::shared_ptr<Figure> figure);
102 
106  void Clear(void);
107 
108 
110  void Unmap();
111 
117  void LinkCamera(int ivp,Frame& frame, int livp);
118 
124  void LinkCamera(int ivp, std::shared_ptr<Frame> frame, int livp) {LinkCamera(ivp,*frame,livp);}
125 
131  void LinkCamera(int ivp, Frame*frame, int livp) {LinkCamera(ivp, *frame,livp);}
132 
136  void LinkCamera(std::shared_ptr<Frame> frame) {LinkCamera(0,*frame,0);}
137 
141  void LinkCamera(Frame& frame) {LinkCamera(0,frame,0);}
142 
147  void SetSize(int x, int y);
148 
155  void SetWindowTitle(const std::string title);
156 
163 
164  void SetFrameTitle(const std::string title);
165 
171  void SetPosition(int x, int y);
172 
173 
177  void SetSingleSubFrameView(bool b);
178 
182  void SetActiveSubFrame(int iframe);
183 
187  void SetActiveSubFrameCameraViewAngle(double angle);
188 
192  void SetActiveSubFrameCameraFocalPoint(double x, double y, double z);
193 
197  void SetActiveSubFrameCameraPosition(double x, double y, double z);
198 
205  void Show();
206 
213  void Interact();
214 
215 
217  static Frame& FindFrame(int number_in_framelist);
218 
219  int GetStepNumber() { return step_number;}
220  void SetStepNumber(int n) { step_number=std::max(n,0);}
221 
222 
223  vtkSmartPointer<vtkRenderer> GetRenderer(std::shared_ptr<Figure> fig);
224 
225 
229  static constexpr const char* KeyboardHelp=
230 R"(
231 --------------------------------------
232  Key Realm Action
233 
234  Space Frame Block/unblock calculation, increase step number
235 BackSpace Frame Block/unblock calculation, decrease step number
236  Escape Figure Finish plane/level editing
237  Return Figure Store edited plane/level value and create new one
238  Delete Figure Delete last plane/level value
239  Prior Frame Show previous figure in single figure mode
240  Next Frame Show next figure in single figure mode
241  a Figure Start arrow scale editing
242  h Frame Print this help to standard output
243  l Figure Start isolevel editing
244  p Frame Write frame to png
245  r Figure Reset camera (must left click to see the result)
246  x Figure Start x plane editing (3D only)
247  y Figure Start y plane editing (3D only)
248  z Figure Start z plane editing (3D only)
249  A Figure Toggle axis+box visibility
250  B Figure Toggle boundary cell visibility in vtkfig::GridView
251  C Figure Toggle interior cell visibility in vtkfig::GridView
252  E Figure Toggle elevation view (2D only)
253  I Figure Toggle isosurface view (3D only)
254  L Figure Generate 11 equally spaced isolevels.
255  O Figure Toggle outline visibility
256  S Figure Toggle surface visibility
257  W Figure Toggle wireframe mode
258  * Frame Toggle single/multi figure view
259  ? Frame Print this help to standard output
260  / Figure Switch signs of cut plane
261  ctrl-q Frame Abort (calls std::terminate)
262 
263 In edit mode, left mouse, as well as cursor keys increase
264 resp. decrease the value of the plane/isolevel/arrowscale, respectively.
265 
266 Figures must be first clicked on before editing works.
267 --------------------------------------
268 )";
269 
270  protected:
271  Frame();
272  ~Frame();
274  public:
275 
276  friend class internals::Thread;
277  friend class internals::InteractorStyle;
278  friend class internals::TimerCallback;
279  friend class internals::Client;
280 
281  int step_number=0;
282 
285 
287  std::set<std::shared_ptr<Figure>>figures;
288 
290  int nvpx;
291 
293  int nvpy;
294 
295  struct SubFrame;
296 
297  void RTSetLayout(int nvpx, int nvpy);
298  void RTCalculateViewports(int nx, int ny);
299  void RTSetSingleViewport(int nx, int ny);
300  void RTResetRenderers(bool from_scratch);
301  void RTResetCamera(SubFrame& sf);
302 
303  void RTSetActiveSubFrameCameraViewAngle(SubFrame& sf, double a);
304  void RTSetActiveSubFrameCameraFocalPoint(SubFrame& sf, double a[3]);
305  void RTSetActiveSubFrameCameraPosition(SubFrame& sf, double a[3]);
306 
307 
308  void RTAddFigures();
309  void RTRemoveFigure(std::shared_ptr<Figure> figure);
310  void RTHideSubframe(SubFrame &subframe);
311  void RTUnHideSubframe(SubFrame &subframe);
312  void RTSetSingleView(bool single_viewport);
313  void RTSetActiveSubFrame(int isub, bool hide_old);
314  void SetAutoLayout(int nfig);
315 
316 
319  struct SubFrame
320  {
321  SubFrame(){};
322 
323  SubFrame(const double vp[4]):viewport{vp[0],vp[1],vp[2],vp[3]}{};
324 
325 
327  vtkSmartPointer<vtkRenderer> renderer;
328 
330  double viewport[4]={0,0,1,1};
331 
332  bool hidden=false;
333  };
334  bool single_subframe_view=false;
335  size_t active_subframe=0;
336 
338  std::vector<SubFrame> subframes;
339  SubFrame title_subframe;
340 
342  int pos(const int ivpx, const int ivpy) { return (nvpy-ivpy-1)*nvpx+ivpx;}
343  int ivpx(const int pos) { return pos%nvpx;}
344  int ivpy(const int pos) { return nvpy-pos/nvpx-1;}
345 
346 
348  const double default_camera_focal_point[3]={0.65,0.5,0};
349  const double default_camera_position[3]={0.65,0.5,10};
350  const double default_camera_view_angle={15};
351  // double default_camera_zoom={1};
352 
353 
355  struct
356  {
357  std::string filename;
358  std::string wintitle="vtkfig";
359  std::string frametitle="";
360 
362  int winsize_x=400;
363  int winsize_y=400;
364 
365  int winposition_x=0;
366  int winposition_y=0;
367 
368  double camera_view_angle=15;
369  double camera_focal_point[3]={0.65,0.5,0};
370  double camera_position[3]={0.65,0.5,10};
371 
372  int camlinkthisframepos;
373  int camlinkframepos;
374  int camlinkframenum;
375 
376  int nvpx;
377  int nvpy;
378 
379  int single_subframe_view;
380  int active_subframe;
381 
382  std::shared_ptr<Figure> current_figure;
383  int figurepos;
384  } parameter;
386  std::shared_ptr<internals::Thread> mainthread;
387 
389  void SendCommand(std::string source, internals::Communicator::Command cmd);
390 
392  vtkSmartPointer<vtkRenderWindow> window;
393 
395  vtkSmartPointer<vtkCornerAnnotation> title_actor=0;
396 
398  void RTInit();
399 
401  vtkSmartPointer<vtkOggTheoraWriter> videowriter=0;
402 
403 
404  };
405 }
406 
407 #endif
408 
vtkfig::Frame::number_in_frame_list
int number_in_frame_list
Number of this frame in global frame list.
Definition: vtkfigFrame.h:284
vtkfig::Frame::FindFrame
static Frame & FindFrame(int number_in_framelist)
Find frame with number.
vtkfig::Frame::pos
int pos(const int ivpx, const int ivpy)
Subframe position algebra.
Definition: vtkfigFrame.h:342
vtkfig::Frame::SubFrame::viewport
double viewport[4]
Viewport within frame.
Definition: vtkfigFrame.h:330
vtkfig::Frame::window
vtkSmartPointer< vtkRenderWindow > window
Window vontaining frame.
Definition: vtkfigFrame.h:392
vtkfig::Frame::SetPosition
void SetPosition(int x, int y)
Set frame position on screen.
vtkfig::Frame::SubFrame
Data structure decribing subframe Each subframe can hold several figures.
Definition: vtkfigFrame.h:319
vtkfig::Frame::default_camera_focal_point
const double default_camera_focal_point[3]
Default camera data.
Definition: vtkfigFrame.h:348
vtkfig::Frame::subframes
std::vector< SubFrame > subframes
List of subframes.
Definition: vtkfigFrame.h:338
vtkfig::Frame::SetActiveSubFrameCameraViewAngle
void SetActiveSubFrameCameraViewAngle(double angle)
Set view angle for camera in active frame relative to default.
vtkfig::Frame::parameter
struct vtkfig::Frame::@2 parameter
Parameters to be passed between threads.
vtkfig::Frame::SubFrame::renderer
vtkSmartPointer< vtkRenderer > renderer
vtkRenderer
Definition: vtkfigFrame.h:323
vtkfig::Frame::RemoveFigure
void RemoveFigure(std::shared_ptr< Figure > figure)
Remove figure.
vtkfig::Frame::AddFigure
void AddFigure(std::shared_ptr< Figure > figure)
Add figure at position (0)
vtkfig::Frame::LinkCamera
void LinkCamera(int ivp, std::shared_ptr< Frame > frame, int livp)
Link camera to other camera.
Definition: vtkfigFrame.h:124
vtkfig::Frame::SetLayout
void SetLayout(int nvpx, int nvpy)
Set layout of subframe grid.
vtkfig::Frame::Clear
void Clear(void)
Remove all figures.
vtkfig::Frame::Unmap
void Unmap()
Unmap frame from screen.
vtkfig::Frame::LinkCamera
void LinkCamera(Frame &frame)
Link camera to other frame at default positions.
Definition: vtkfigFrame.h:141
vtkfig::Frame::title_actor
vtkSmartPointer< vtkCornerAnnotation > title_actor
Actor for frame title annotation.
Definition: vtkfigFrame.h:395
vtkfig::Frame::videowriter
vtkSmartPointer< vtkOggTheoraWriter > videowriter
Video writer.
Definition: vtkfigFrame.h:401
vtkfig::Frame::Thread
friend class internals::Thread
!! private:
Definition: vtkfigFrame.h:276
vtkfig::Frame::StartVideo
void StartVideo(std::string fname)
Start video recording.
vtkfig::Frame::SetFrameTitle
void SetFrameTitle(const std::string title)
Set Frame title.
vtkfig::Frame
Provide a framework wrapping window+interactor+renderers from vtk.
Definition: vtkfigFrame.h:38
vtkfig::Frame::SetActiveSubFrame
void SetActiveSubFrame(int iframe)
Set active subframe number for editing, single/multiview etc.
vtkfig::Frame::mainthread
std::shared_ptr< internals::Thread > mainthread
The spinning main thread.
Definition: vtkfigFrame.h:386
vtkfig::Frame::StopVideo
void StopVideo()
Stop video recording.
vtkfig::Frame::SendCommand
void SendCommand(std::string source, internals::Communicator::Command cmd)
Blocking send of commands to main thread.
vtkfig::Frame::Show
void Show()
Show frame content and continue.
vtkfig::internals::Client
Client side visualization setup.
Definition: vtkfigClient.h:30
vtkfig::Frame::nvpx
int nvpx
Number of viewports in x direction.
Definition: vtkfigFrame.h:290
vtkfig::Frame::SetWindowTitle
void SetWindowTitle(const std::string title)
Set window title.
vtkfig::Frame::SetActiveSubFrameCameraPosition
void SetActiveSubFrameCameraPosition(double x, double y, double z)
Set view position for camera in active frame relative to default.
vtkfig::Frame::figures
std::set< std::shared_ptr< Figure > > figures
List of all figures in frame.
Definition: vtkfigFrame.h:287
vtkfig::Frame::nvpy
int nvpy
Number of viewports in y direction.
Definition: vtkfigFrame.h:293
vtkfig::Frame::KeyboardHelp
static constexpr const char * KeyboardHelp
Help string printed when pressing "h"/"?".
Definition: vtkfigFrame.h:229
vtkfig::Frame::winsize_x
int winsize_x
window sizes
Definition: vtkfigFrame.h:362
vtkfig::Frame::SetSize
void SetSize(int x, int y)
Set frame size in pixels.
vtkfig::Frame::Interact
void Interact()
Show frame content and wait for interaction.
vtkfig::Frame::RefreshState
void RefreshState(int figurepos)
Refresh frame state for figure.
vtkfig::Frame::LinkCamera
void LinkCamera(int ivp, Frame *frame, int livp)
Link camera to other camera.
Definition: vtkfigFrame.h:131
vtkfig::Frame::LinkCamera
void LinkCamera(std::shared_ptr< Frame > frame)
Link camera to other frame at default positions.
Definition: vtkfigFrame.h:136
vtkfig::Frame::WritePNG
void WritePNG(std::string fname)
Write png image of frame content.
vtkfig::Frame::RTInit
void RTInit()
Init title actor.
vtkfig::Frame::LinkCamera
void LinkCamera(int ivp, Frame &frame, int livp)
Link camera to other camera.
vtkfig::Frame::SetActiveSubFrameCameraFocalPoint
void SetActiveSubFrameCameraFocalPoint(double x, double y, double z)
Set focal point for camera in active frame relative to default.
vtkfig::Frame::SetSingleSubFrameView
void SetSingleSubFrameView(bool b)
Toggle single/multi view for frame with mutiple figures.
vtkfig::Frame::New
static std::shared_ptr< Frame > New()
Create smart pointer to frame.