Fraxinus  17.12-rc1
An IGT application
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 #if !defined(CX_VTK_OPENGL2) && !defined(WIN32)
64 
65 class cxResourceVisualization_EXPORT SingleVolumePainterHelper
66 {
67  GPUImageDataBufferPtr mVolumeBuffer;
68  GPUImageLutBufferPtr mLutBuffer;
69  int mIndex;
70  float mWindow;
71  float mLevel;
72  float mLLR;
73  float mAlpha;
74 
75 public:
76  explicit SingleVolumePainterHelper(int index);
79  void SetBuffer(GPUImageDataBufferPtr buffer);
80  void SetBuffer(GPUImageLutBufferPtr buffer);
81  void SetColorAttribute(float window, float level, float llr,float alpha);
82  void initializeRendering();
83  void setUniformiArray(vtkUniformVariables* uniforms, QString name, int val);
84  void setUniformfArray(vtkUniformVariables* uniforms, QString name, float val);
85  void eachRenderInternal(vtkSmartPointer<vtkShaderProgram2> shader);
86 };
87 
88 
97 class cxResourceVisualization_EXPORT TextureSlicePainter : public vtkOpenGLRepresentationPainter
98 {
99 public:
100  static TextureSlicePainter* New();
101  vtkTypeMacro(TextureSlicePainter, vtkOpenGLRepresentationPainter);
102 
103  virtual void ReleaseGraphicsResources(vtkWindow *);
104  void PrintSelf(ostream& os, vtkIndent indent);
105 
106  void setShaderPath(QString path);
107  void SetColorAttribute(int index, float window, float level, float llr, float alpha);
108  void SetVolumeBuffer(int index, GPUImageDataBufferPtr buffer);
109  void SetLutBuffer(int index, GPUImageLutBufferPtr buffer);
110  void releaseGraphicsResources(int index);
111 
112  static bool LoadRequiredExtensions(vtkOpenGLExtensionManager* mgr);
113 
114 protected:
116  virtual ~TextureSlicePainter();
117  virtual void PrepareForRendering(vtkRenderer*, vtkActor*);
118  void RenderInternal(vtkRenderer* renderer, vtkActor* actor, unsigned long typeflags, bool forceCompileOnly);
119  bool CanRender(vtkRenderer*, vtkActor*);
120  static bool LoadRequiredExtension(vtkOpenGLExtensionManager* mgr, QString id);
121  void ClearGraphicsResources();
122 
123 private:
124  QString loadShaderFile();
125  void buildProgram(QString shaderSource, vtkOpenGLRenderWindow* renderWindow);
126  SingleVolumePainterHelper& safeIndex(int index);
127  QString replaceShaderSourceMacros(QString shaderSource);
128 
129  bool hasLoadedExtensions;
130  QString mShaderPath;
131 
132  vtkWeakPointer<vtkRenderWindow> LastContext;
133  vtkSmartPointer<vtkShaderProgram2> Shader;
134  std::vector<SingleVolumePainterHelper> mElement;
135 };
136 
137 #endif //CX_VTK_OPENGL2
138 
139 
140 //---------------------------------------------------------
141 }//end namespace
142 //---------------------------------------------------------
143 #endif /* CXTEXTURESLICEPAINTER_H_ */
Helper class for GPU rendering of slices.
boost::shared_ptr< class GPUImageDataBuffer > GPUImageDataBufferPtr
boost::shared_ptr< class GPUImageLutBuffer > GPUImageLutBufferPtr
Namespace for all CustusX production code.