NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxTextureSlicePainter.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 /*
35  * vmTextureSlicePainter.h
36  *
37  * Created on: Oct 13, 2009
38  * Author: petterw
39  */
40 
41 #ifndef CXTEXTURESLICEPAINTER_H_
42 #define CXTEXTURESLICEPAINTER_H_
43 
44 #include "cxResourceVisualizationExport.h"
45 
46 #include <boost/shared_ptr.hpp>
47 #include <QString>
48 #include <vector>
49 #include "vtkForwardDeclarations.h"
50 #include "cxForwardDeclarations.h"
51 #include "cxConfig.h"
52 
53 #ifndef CX_VTK_OPENGL2
54 #include <vtkOpenGLRepresentationPainter.h>
55 #endif
56 
57 class vtkOpenGLRenderWindow;
58 class vtkUniformVariables;
59 //---------------------------------------------------------
60 namespace cx
61 {
62 
63 //#ifndef WIN32
64 //#ifndef CX_VTK_OPENGL2
65 #if !defined(CX_VTK_OPENGL2) && !defined(WIN32)
66 
67 class cxResourceVisualization_EXPORT SingleVolumePainterHelper
68 {
69  GPUImageDataBufferPtr mVolumeBuffer;
70  GPUImageLutBufferPtr mLutBuffer;
71  int mIndex;
72  float mWindow;
73  float mLevel;
74  float mLLR;
75  float mAlpha;
76 
77 public:
78  explicit SingleVolumePainterHelper(int index);
81  void SetBuffer(GPUImageDataBufferPtr buffer);
82  void SetBuffer(GPUImageLutBufferPtr buffer);
83  void SetColorAttribute(float window, float level, float llr,float alpha);
84  void initializeRendering();
85  void setUniformiArray(vtkUniformVariables* uniforms, QString name, int val);
86  void setUniformfArray(vtkUniformVariables* uniforms, QString name, float val);
87  void eachRenderInternal(vtkSmartPointer<vtkShaderProgram2> shader);
88 };
89 
90 
99 class cxResourceVisualization_EXPORT TextureSlicePainter : public vtkOpenGLRepresentationPainter
100 {
101 public:
102  static TextureSlicePainter* New();
103  vtkTypeMacro(TextureSlicePainter, vtkOpenGLRepresentationPainter);
104 
105  virtual void ReleaseGraphicsResources(vtkWindow *);
106  void PrintSelf(ostream& os, vtkIndent indent);
107 
108  void setShaderPath(QString path);
109  void SetColorAttribute(int index, float window, float level, float llr, float alpha);
110  void SetVolumeBuffer(int index, GPUImageDataBufferPtr buffer);
111  void SetLutBuffer(int index, GPUImageLutBufferPtr buffer);
112  void releaseGraphicsResources(int index);
113 
114  static bool LoadRequiredExtensions(vtkOpenGLExtensionManager* mgr);
115 
116 protected:
118  virtual ~TextureSlicePainter();
119  virtual void PrepareForRendering(vtkRenderer*, vtkActor*);
120  void RenderInternal(vtkRenderer* renderer, vtkActor* actor, unsigned long typeflags, bool forceCompileOnly);
121  bool CanRender(vtkRenderer*, vtkActor*);
122  static bool LoadRequiredExtension(vtkOpenGLExtensionManager* mgr, QString id);
123  void ClearGraphicsResources();
124 
125 private:
126  QString loadShaderFile();
127  void buildProgram(QString shaderSource, vtkOpenGLRenderWindow* renderWindow);
128  SingleVolumePainterHelper& safeIndex(int index);
129  QString replaceShaderSourceMacros(QString shaderSource);
130 
131  bool hasLoadedExtensions;
132  QString mShaderPath;
133 
134  vtkWeakPointer<vtkRenderWindow> LastContext;
135  vtkSmartPointer<vtkShaderProgram2> Shader;
136  std::vector<SingleVolumePainterHelper> mElement;
137 };
138 
139 #endif //CX_VTK_OPENGL2
140 //#endif // WIN32
141 
142 
143 //---------------------------------------------------------
144 }//end namespace
145 //---------------------------------------------------------
146 #endif /* CXTEXTURESLICEPAINTER_H_ */
Helper class for GPU rendering of slices.
boost::shared_ptr< class GPUImageDataBuffer > GPUImageDataBufferPtr
boost::shared_ptr< class GPUImageLutBuffer > GPUImageLutBufferPtr