Slicer  4.10
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkOpenGLTextureImage.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: $RCSfile: vtkOpenGLTextureImage.h,v $
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkOpenGLTextureImage - OpenGL actor
16 // .SECTION Description
17 // vtkOpenGLTextureImage is an interface between an vtkImageData and and
18 // an OpenGL 3D texture object.
19 // This is a work in progress, but when complete it should be possible
20 // to easily move data back and forth between C++/Python and GLSL
21 // to support volume rendering and computation when used with
22 // the vtkOpenGLShaderComputation class.
23 
24 #ifndef __vtkOpenGLTextureImage_h
25 #define __vtkOpenGLTextureImage_h
26 
27 #include "vtk_glew.h"
28 
30 #include "vtkOpenGL.h"
31 
32 #include "vtkImageData.h"
33 
34 #include "vtkAddon.h"
35 
36 
37 /*
38 #ifndef _WIN32
39 
40 #include "vtkgl.h"
41 
42 #define glBindTexture vtkgl::BindTexture
43 #define glClear vtkgl::Clear
44 #define glClearColor vtkgl::ClearColor
45 #define glDeleteTextures vtkgl::DeleteTextures
46 #define glDisable vtkgl::Disable
47 #define glDrawArrays vtkgl::DrawArrays
48 #define glEnable vtkgl::Enable
49 #define glGenTextures vtkgl::GenTextures
50 #define glGetTexImage vtkgl::GetTexImage
51 #define glReadPixels vtkgl::ReadPixels
52 #define glTexParameteri vtkgl::TexParameteri
53 #define glViewport vtkgl::Viewport
54 
55 #endif
56 */
57 
58 class VTK_ADDON_EXPORT vtkOpenGLTextureImage : public vtkObject
59 {
60 protected:
61 
62 public:
63  static vtkOpenGLTextureImage *New();
64  vtkTypeMacro(vtkOpenGLTextureImage,vtkObject);
65  virtual void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
66 
67  // Description:
68  // The ShaderComputation used to manage the OpenGL context and shaders
69  vtkGetObjectMacro(ShaderComputation, vtkOpenGLShaderComputation);
70  vtkSetObjectMacro(ShaderComputation, vtkOpenGLShaderComputation);
71 
72  // Description:
73  // The image data that corresponds to the texture.
74  // Not all sizes and types of image data are supported, only
75  // those that map cleanly to textures. All are treated as
76  // 3D textures no matter the dimensions.
77  vtkGetObjectMacro(ImageData, vtkImageData);
78  vtkSetObjectMacro(ImageData, vtkImageData);
79 
80  // Description:
81  // The id provided by glGenTextures.
82  // It is actually in integer that is
83  // an opaque mapping to a hardware structure.
84  // Non-zero means the texture has been generated.
85  // Exposed here for introspection.
86  vtkGetMacro(TextureName, vtkTypeUInt32);
87 
88  // Description:
89  // True (default) to interpolate samples
90  vtkGetMacro(Interpolate, int);
91  vtkSetMacro(Interpolate, int);
92 
93  // Description:
94  // Texture wrap mode (ClampToEdge, MirroredRepeat)
95  vtkGetMacro(TextureWrap, int);
96  vtkSetMacro(TextureWrap, int);
97 
98  // Description:
99  // Make the image data available as GL_TEXTUREn
100  // where n is the texture unit. There are at least
101  // GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, which is variable
102  // by driver but must be at least 48.
103  // This method also checks the modification time of
104  // the image data to ensure the texture up to date and
105  // initiates the transfer if not.
106  void Activate(vtkTypeUInt32 unit);
107 
108  // Description:
109  // Creates/transfers image data to texture if needed.
110  bool UpdateTexture();
111 
112  // Description:
113  // Make the specified layer (slice) be the draw target.
114  // This is used to direct the output of the shading into
115  // the specified slice of the texture and can be used to
116  // implement volumetric algorithms. Iterated algorithms
117  // can be done fully on the GPU by swapping textures between
118  // active units and draw targets.
119  // Parameters:
120  // attachmentIndex is which color attachment to use (only valid for color)
121  // level is z slice to target
122  // attachment is 0 (color), 1 (depth), 2 (stencil), 3 (depth-stencil)
124  {
125  ColorAttachmentPoint = 0,
128  DepthStencilAttachmentPoint
129  };
130  void AttachAsDrawTarget(int layer=0, int attachement=0, int attachmentIndex=0);
131 
133  {
136  };
137 
138  // Description:
139  // Read the texture data back into the image data
140  // (assumes it has been written as a target)
141  // Warning: probably best to only use this to read back into the same buffer that was used
142  // when the data was uploaded (i.e. this will assume that the vtkImageData buffer pointer
143  // is the right size for the data).
144  void ReadBack();
145 
146  static GLenum vtkScalarTypeToGLType(int vtk_scalar_type);
147  // Description:
148  // TODO: options for min and mag filter, wrapping...
149 
150 protected:
153 
154 private:
155  vtkOpenGLTextureImage(const vtkOpenGLTextureImage&); // Not implemented.
156  void operator=(const vtkOpenGLTextureImage&); // Not implemented.
157 
158  vtkOpenGLShaderComputation *ShaderComputation;
159  vtkImageData *ImageData;
160  vtkTypeUInt32 TextureName;
161  int Interpolate;
162  unsigned long TextureMTime;
163  int TextureWrap;
164 
165 };
166 
167 #endif