Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkGPGPU.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 MITKGPGPU_H
18 #define MITKGPGPU_H
19 
20 #include <GL/glew.h>
21 
22 #include <MitkGPGPUExports.h>
23 
24 #ifdef _WIN32
25 #include <windows.h>
26 #else
27 #include <GL/glx.h>
28 #include <X11/Xlib.h>
29 #endif
30 
31 #include <GL/gl.h>
32 
33 #include "mitkCommon.h"
34 
35 namespace mitk
36 {
37  //##Documentation
38  //## @brief GPGPU
39 
41  {
42  public:
44  {
49  };
50 
52  {
53  public:
54  Texture(mitk::GPGPU::TextureFormat format, int width, int height, int depth = 0);
55  ~Texture();
56 
57  void ActivateAsSource(int unit);
58  void ActivateAsDestination();
59  void Upload(mitk::GPGPU::TextureFormat inputformat, const void *src);
60  void Download(mitk::GPGPU::TextureFormat inputformat, void *dst);
61  int GetWidth();
62  int GetHeigth();
63  int GetDepth();
64 
65  private:
67  int myWidth, myHeight, myDepth;
68 
69  int glTarget;
70  int glTextureHandle;
71  int glFBOHandle;
72  };
73 
75  {
76  public:
77  Shader(char *source);
78  ~Shader();
79 
80  void Activate();
81  void SetUniform(char *name, int i0);
82  void SetUniform(char *name, int i0, int i1);
83  void SetUniform(char *name, int i0, int i1, int i2);
84  void SetUniform(char *name, int i0, int i1, int i2, int i3);
85  void SetUniform(char *name, float i0);
86  void SetUniform(char *name, float i0, float i1);
87  void SetUniform(char *name, float i0, float i1, float i2);
88  void SetUniform(char *name, float i0, float i1, float i2, float i3);
89 
90  private:
91  int GetUniformLocation(char *name);
92 
93  int glHandleVertex;
94  int glHandleFragment;
95  int glHandleProgram;
96  };
97 
98  GPGPU();
99  ~GPGPU();
100 
101  void Activate();
102  void Deactivate();
103  void Run();
104  void Run(float start, float end);
105 
106  private:
107 #ifdef _WIN32
108  HWND windowHandle;
109  HDC windowsContext;
110  HGLRC openGLContext;
111 #else
112  GLXContext openGLContext;
113  GLXDrawable GLX_drawable;
114  Display *X_display;
115 #endif
116  };
117 
118 } // namespace mitk
119 
120 /*{
121  mitk::GPGPU *gpu=new mitk::GPGPU();
122 
123  gpu->Activate();
124 
125  mitk::GPGPU::Texture *input=new mitk::GPGPU::Texture( GLSL_FLOAT32_LUMINANCE , 128,128 );
126  mitk::GPGPU::Texture *output=new mitk::GPGPU::Texture( GLSL_FLOAT32_LUMINANCE , 128,128 );
127  mitk::GPGPU::Shader *shader = new mitk::GPGPU::Shader(
128  "uniform float invsize;\n"
129  "uniform sampler2D input;\n"
130  "uniform sampler2D input2;\n"
131  "uniform sampler2D input3;\n"
132  "void main()\n"
133  "{\n"
134  " vec2 pos=gl_FragCoord.xy*invsize; \n"
135  " int x; \n"
136  " float y; \n"
137  " vec2 z; \n"
138  " vec4 ddd; \n"
139  " vec4 gl_FragColor; \n"
140  " float x = texture2D(input,vec2(x,y) );
141  " gl_FragColor.r = x; \n"
142  "}\n" );
143 
144  input->Upload( GLSL_FLOAT32_LUMINANCE, eurerArray);
145 
146 
147  shader->Activate();
148  shader->SetUniform("input",0);
149 
150  gpu->ActivateAsSource(input,0);
151  gpu->ActivateAsDestination(output);
152  gpu->Run();
153 
154 
155  input2->ActivateAsSource(0);
156  output2->ActivateAsDestination();
157  gpu->Run();
158 
159  output->Download( GLSL_FLOAT32_LUMINANCE, zielArray);
160 
161  input2->Upload( GLSL_FLOAT32_LUMINANCE, eurerArray);
162 
163  input2->ActivateAsSource(0);
164  output2->ActivateAsDestination();
165  shader->SetUniform("input",0);
166 
167 
168 
169 
170 
171  gpu->Deactivate();
172 
173  delete gpu;
174 }*/
175 
176 #endif
DataCollection - Class to facilitate loading/accessing structured data.
#define MITKGPGPU_EXPORT
GPGPU.
Definition: mitkGPGPU.h:40