fw4spl
fwRenderVTK/include/fwRenderVTK/SRender.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #pragma once
8 
9 #include "fwRenderVTK/config.hpp"
10 
11 #include <fwCom/helper/SigSlotConnection.hpp>
12 
13 #include <fwRender/IRender.hpp>
14 
15 #include <fwRuntime/ConfigurationElement.hpp>
16 
17 #include <fwServices/helper/Config.hpp>
18 
19 #include <map>
20 
21 class vtkRenderWindow;
22 class vtkRenderer;
23 class vtkAbstractPropPicker;
24 class vtkObject;
25 class vtkTransform;
26 
27 // Forward declarations
28 namespace fwData
29 {
30 class TransformationMatrix3D;
31 }
32 
33 namespace fwThread
34 {
35 class Timer;
36 }
37 
38 namespace fwRenderVTK
39 {
40 
41 class IAdaptor;
42 class IVtkRenderWindowInteractorManager;
43 
101 class FWRENDERVTK_CLASS_API SRender : public ::fwRender::IRender
102 {
103 public:
105 
106  typedef std::string RendererIdType;
107  typedef std::string PickerIdType;
108  typedef std::string ObjectIdType;
109  typedef std::string AdaptorIdType;
110  typedef std::string VtkObjectIdType;
111  typedef std::map< std::string, ::fwData::Object::csptr > ConstObjectMapType;
112 
113  FWRENDERVTK_API static const ::fwCom::Slots::SlotKeyType s_RENDER_SLOT;
114  FWRENDERVTK_API static const ::fwCom::Slots::SlotKeyType s_REQUEST_RENDER_SLOT;
115  FWRENDERVTK_API static const ::fwCom::Slots::SlotKeyType s_TOGGLE_AUTO_RENDER_SLOT;
116 
117  FWRENDERVTK_API static const ::fwCom::Signals::SignalKeyType s_DROPPED_SIG;
118  typedef ::fwCom::Signal< void (std::string)> DroppedSignalType;
119 
120  FWRENDERVTK_API SRender() noexcept;
121 
122  FWRENDERVTK_API virtual ~SRender() noexcept;
123 
125  FWRENDERVTK_API vtkRenderer* getRenderer(RendererIdType rendererId);
126 
128  bool isShownOnScreen();
129 
131  FWRENDERVTK_API vtkAbstractPropPicker* getPicker(PickerIdType pickerId);
132 
134  FWRENDERVTK_API vtkObject* getVtkObject(const VtkObjectIdType& objectId) const;
135 
137  FWRENDERVTK_API vtkTransform* getOrAddVtkTransform( const VtkObjectIdType& _id );
138 
139  bool getPendingRenderRequest() const;
140 
141  void setPendingRenderRequest(bool b);
142 
143  enum class RenderMode
144  {
145  NONE,
146  AUTO,
147  TIMER,
148  SYNC
149  };
150 
152  RenderMode getRenderMode() const;
153 
155  FWRENDERVTK_API bool isOffScreen() const;
156 
158  FWRENDERVTK_API void setOffScreenRenderSize(unsigned int _width, unsigned int _height);
159 
160 protected:
161 
163  FWRENDERVTK_API void render();
164 
166  FWRENDERVTK_API virtual void starting() override;
167 
169  FWRENDERVTK_API virtual void stopping() override;
170 
172  FWRENDERVTK_API virtual void configuring() override;
173 
175  FWRENDERVTK_API virtual void updating() override;
176 
178  FWRENDERVTK_API void addVtkObject( const VtkObjectIdType& _id, vtkObject* _vtkObj );
179 
180 private:
181 
183  void requestRender();
184 
186  void toggleAutoRender();
187 
189  void startContext();
190 
192  void stopContext();
193 
195  void configurePicker (const ConfigType& pickerConf );
196 
198  void configureRenderer (const ConfigType& rendererConf );
199 
201  void configureVtkObject(const ConfigType& vtkObjectConf );
202 
204  vtkTransform* createVtkTransform(const ConfigType& vtkObjectConf );
205 
207  SPTR( ::fwRenderVTK::IVtkRenderWindowInteractorManager ) m_interactorManager;
208 
210  typedef std::map< RendererIdType, vtkRenderer* > RenderersMapType;
211 
213  typedef std::map< PickerIdType, vtkAbstractPropPicker* > PickersMapType;
214 
216  typedef std::map< VtkObjectIdType, vtkObject* > VtkObjectMapType;
217 
218  RenderersMapType m_renderers;
219  PickersMapType m_pickers;
220  VtkObjectMapType m_vtkObjects;
221 
222  bool m_pendingRenderRequest;
223 
226  RenderMode m_renderMode;
227 
228  unsigned int m_width;
229  unsigned int m_height;
230  bool m_offScreen;
231  bool m_flip;
232 
234  SPTR( ::fwThread::Timer ) m_timer;
235 
237  ConfigType m_sceneConf;
238 };
239 
240 //-----------------------------------------------------------------------------
241 
242 inline bool SRender::getPendingRenderRequest() const
243 {
244  return m_pendingRenderRequest;
245 }
246 
247 //------------------------------------------------------------------------------
248 
249 inline void SRender::setPendingRenderRequest(bool b)
250 {
251  m_pendingRenderRequest = b;
252 }
253 
254 //-----------------------------------------------------------------------------
255 
256 inline SRender::RenderMode SRender::getRenderMode() const
257 {
258  return m_renderMode;
259 }
260 
261 }
#define SPTR(_cls_)
STL namespace.
Defines the service interface managing the rendering service for object.
Definition: IRender.hpp:36
The generic scene service shows adaptors in a 3D VTK scene.
Defines a class to manage vtkRenderWindowInteractor in a window.
#define fwCoreServiceClassDefinitionsMacro(_classinfo_)
Generate common code for services classes.
The namespace fwRenderVTK contains classes for rendering with VTK.
Contains the representation of the data objects used in the framework.
This namespace fwThread provides few tools to execute asynchronous tasks on different threads...