Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkVtkShaderRepository.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef _MITKVTKSHADERREPOSITORY_H_
18 #define _MITKVTKSHADERREPOSITORY_H_
19 
20 #include "mitkIShaderRepository.h"
21 #include <vtkShaderProgram2.h>
22 #include <vtkXMLShader.h>
23 
24 class vtkXMLDataElement;
25 class vtkXMLMaterial;
26 class vtkProperty;
27 
28 namespace mitk
29 {
40  {
41  protected:
43  {
44  public:
45  mitkClassMacro(Shader, IShaderRepository::Shader) itkFactorylessNewMacro(Self)
46 
47  class Uniform : public itk::Object
48  {
49  public:
50  mitkClassMacroItkParent(Uniform, itk::Object) itkFactorylessNewMacro(Self)
51 
52  enum Type {
61  glsl_ivec4
62  };
63 
67  Uniform();
68 
72  ~Uniform();
73 
75  std::string name;
76 
77  int defaultInt[4];
78  float defaultFloat[4];
79 
80  void LoadFromXML(vtkXMLDataElement *e);
81  };
82 
83  std::list<Uniform::Pointer> uniforms;
84 
88  Shader();
89 
93  ~Shader();
94 
95  void SetVertexShaderCode(const std::string &code);
96  std::string GetVertexShaderCode() const;
97 
98  void SetFragmentShaderCode(const std::string &code);
99  std::string GetFragmentShaderCode() const;
100 
101  void SetGeometryShaderCode(const std::string &code);
102  std::string GetGeometryShaderCode() const;
103 
104  std::list<Uniform::Pointer> GetUniforms() const;
105 
106  private:
107  friend class VtkShaderRepository;
108 
109  std::string m_VertexShaderCode;
110  std::string m_FragmentShaderCode;
111  std::string m_GeometryShaderCode;
112 
113  void LoadXmlShader(std::istream &stream);
114  };
115 
116  void LoadShaders();
117 
118  Shader::Pointer GetShaderImpl(const std::string &name) const;
119 
120  private:
121  std::list<Shader::Pointer> shaders;
122 
123  static int shaderId;
124  static const bool debug;
125 
126  public:
131 
136 
138 
139  std::list<IShaderRepository::Shader::Pointer> GetShaders() const override;
140 
141  IShaderRepository::Shader::Pointer GetShader(const std::string &name) const override;
142 
143  IShaderRepository::Shader::Pointer GetShader(int id) const override;
144 
148  void AddDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer, bool overwrite) const override;
149 
154  int LoadShader(std::istream &stream, const std::string &name) override;
155 
156  bool UnloadShader(int id) override;
157 
159  DataNode *node,
160  BaseRenderer *renderer) const override;
161  };
162 
163 } // end of namespace mitk
164 #endif
void AddDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer, bool overwrite) const override
Adds all parsed shader uniforms to property list of the given DataNode; used by mappers.
IShaderRepository::Shader::Pointer GetShader(const std::string &name) const override
Return the named shader.
void SetVertexShaderCode(const std::string &code)
Organizes the rendering process.
DataCollection - Class to facilitate loading/accessing structured data.
void UpdateShaderProgram(mitk::IShaderRepository::ShaderProgram *shaderProgram, DataNode *node, BaseRenderer *renderer) const override
Applies shader and shader specific variables of the specified DataNode to the VTK object by updating ...
ShaderProgram::Pointer CreateShaderProgram() override
std::list< Uniform::Pointer > uniforms
Shader::Pointer GetShaderImpl(const std::string &name) const
Management class for vtkShader XML descriptions.
Management class for vtkShader XML descriptions.
void SetGeometryShaderCode(const std::string &code)
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:53
std::list< Uniform::Pointer > GetUniforms() const
mitkClassMacro(Shader, IShaderRepository::Shader) static Pointer New()
std::list< IShaderRepository::Shader::Pointer > GetShaders() const override
int LoadShader(std::istream &stream, const std::string &name) override
Applies shader and shader specific variables of the specified DataNode to the VTK object by updating ...
bool UnloadShader(int id) override
Unload a previously loaded shader.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
void SetFragmentShaderCode(const std::string &code)