iMSTK
Interactive Medical Simulation Toolkit
imstkVTKRenderDelegate.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkEventObject.h"
10 #include "imstkMacros.h"
11 #include "imstkTextureManager.h"
12 #include "imstkVTKTextureDelegate.h"
13 
14 #include <vtkSmartPointer.h>
15 
16 class vtkAbstractMapper;
17 class vtkProp;
18 class vtkTransform;
19 class vtkTexture;
20 
21 namespace imstk
22 {
23 class Texture;
24 class RenderMaterial;
25 class VisualModel;
26 
32 class VTKRenderDelegate : public EventObject, public std::enable_shared_from_this<VTKRenderDelegate>
33 {
34 public:
35  ~VTKRenderDelegate() override = default;
36 
40  static std::shared_ptr<VTKRenderDelegate> makeDelegate(std::shared_ptr<VisualModel> visualModel);
41 
45  void initialize(std::shared_ptr<VisualModel> model);
46 
50  std::shared_ptr<VisualModel> getVisualModel() const { return m_visualModel; }
51 
55  vtkSmartPointer<vtkProp> getVtkActor() const { return m_actor; }
56 
60  void setTextureManager(std::weak_ptr<TextureManager<VTKTextureDelegate>> textureManager) { m_textureManager = textureManager; }
61 
65  void update();
66 
71  virtual void processEvents();
72 
76  virtual void updateRenderProperties() = 0;
77 
78 protected:
80 
81  virtual void init() = 0;
82 
86  void materialModified(Event* imstkNotUsed(e)) { updateRenderProperties(); }
87 
91  void visualModelModified(Event* e);
92 
93  vtkSmartPointer<vtkTexture> getVTKTexture(std::shared_ptr<Texture> texture);
94 
95  vtkSmartPointer<vtkTransform> m_transform;
96 
97  // VTK data members used to create the rendering pipeline
98  vtkSmartPointer<vtkProp> m_actor;
99  vtkSmartPointer<vtkAbstractMapper> m_mapper;
100 
101  std::shared_ptr<VisualModel> m_visualModel;
102  std::shared_ptr<RenderMaterial> m_material;
103 
104  std::weak_ptr<TextureManager<VTKTextureDelegate>> m_textureManager;
105 };
106 } // namespace imstk
void update()
Update render delegate.
void initialize(std::shared_ptr< VisualModel > model)
Setup the VTKRenderDelegate with given model.
std::shared_ptr< VisualModel > m_visualModel
imstk visual model (contains data (geometry) and render specification (render material)) ...
Base class for events which contain a type, priority, and data priority defaults to 0 and uses a grea...
Compound Geometry.
void visualModelModified(Event *e)
Callback for visual model modifications.
static std::shared_ptr< VTKRenderDelegate > makeDelegate(std::shared_ptr< VisualModel > visualModel)
Instantiate proper render delegate.
Base class for VTK render delegates.
std::shared_ptr< VisualModel > getVisualModel() const
Return geometry to render.
EventObject is the base class for all objects in iMSTK that can receive and emit events. It supports direct and queued observer functions. Direct observers receive events immediately on the same thread This can either be posted on an object or be a function pointer Queued observers receive events within their queue which they can process whenever they like. These can be connected with the connect/queuedConnect/disconnect functions Lambda recievers cannot be disconnected unless all receivers to a signal are removed.
The TextureManager provides delegates for textures, it will create new ones and cache old ones...
void materialModified(Event *imstkNotUsed(e))
Callback for updating render properties.
virtual void updateRenderProperties()=0
Updates the actor and mapper properties from the currently set VisualModel.
vtkSmartPointer< vtkProp > getVtkActor() const
Get VTK actor.
virtual void processEvents()
Process the event queue, default implementation processes visualModel events and its RenderMaterial e...
void setTextureManager(std::weak_ptr< TextureManager< VTKTextureDelegate >> textureManager)
Set the TextureManager.