NorMIT-nav  2023.01.05-dev+develop.0da12
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 /*
14  * vmTextureSlicePainter.h
15  *
16  * Created on: Oct 13, 2009
17  * Author: petterw
18  */
19 
20 #ifndef CXTEXTURESLICEPAINTER_H_
21 #define CXTEXTURESLICEPAINTER_H_
22 
23 #include "cxResourceVisualizationExport.h"
24 
25 #include <boost/shared_ptr.hpp>
26 #include <QString>
27 #include <vector>
28 #include "vtkForwardDeclarations.h"
29 #include "cxForwardDeclarations.h"
30 #include "cxConfig.h"
31 
32 #ifndef CX_VTK_OPENGL2
33 #include <vtkOpenGLRepresentationPainter.h>
34 #endif
35 
36 class vtkOpenGLRenderWindow;
37 class vtkUniformVariables;
38 //---------------------------------------------------------
39 namespace cx
40 {
41 
42 #if !defined(CX_VTK_OPENGL2) && !defined(WIN32)
43 
44 class cxResourceVisualization_EXPORT SingleVolumePainterHelper
45 {
46  GPUImageDataBufferPtr mVolumeBuffer;
47  GPUImageLutBufferPtr mLutBuffer;
48  int mIndex;
49  float mWindow;
50  float mLevel;
51  float mLLR;
52  float mAlpha;
53 
54 public:
55  explicit SingleVolumePainterHelper(int index);
58  void SetBuffer(GPUImageDataBufferPtr buffer);
59  void SetBuffer(GPUImageLutBufferPtr buffer);
60  void SetColorAttribute(float window, float level, float llr,float alpha);
61  void initializeRendering();
62  void setUniformiArray(vtkUniformVariables* uniforms, QString name, int val);
63  void setUniformfArray(vtkUniformVariables* uniforms, QString name, float val);
64  void eachRenderInternal(vtkSmartPointer<vtkShaderProgram2> shader);
65 };
66 
67 
76 class cxResourceVisualization_EXPORT TextureSlicePainter : public vtkOpenGLRepresentationPainter
77 {
78 public:
79  static TextureSlicePainter* New();
80  vtkTypeMacro(TextureSlicePainter, vtkOpenGLRepresentationPainter);
81 
82  virtual void ReleaseGraphicsResources(vtkWindow *);
83  void PrintSelf(ostream& os, vtkIndent indent);
84 
85  void setShaderPath(QString path);
86  void SetColorAttribute(int index, float window, float level, float llr, float alpha);
87  void SetVolumeBuffer(int index, GPUImageDataBufferPtr buffer);
88  void SetLutBuffer(int index, GPUImageLutBufferPtr buffer);
89  void releaseGraphicsResources(int index);
90 
91  static bool LoadRequiredExtensions(vtkOpenGLExtensionManager* mgr);
92 
93 protected:
95  virtual ~TextureSlicePainter();
96  virtual void PrepareForRendering(vtkRenderer*, vtkActor*);
97  void RenderInternal(vtkRenderer* renderer, vtkActor* actor, unsigned long typeflags, bool forceCompileOnly);
98  bool CanRender(vtkRenderer*, vtkActor*);
99  static bool LoadRequiredExtension(vtkOpenGLExtensionManager* mgr, QString id);
100  void ClearGraphicsResources();
101 
102 private:
103  QString loadShaderFile();
104  void buildProgram(QString shaderSource, vtkOpenGLRenderWindow* renderWindow);
105  SingleVolumePainterHelper& safeIndex(int index);
106  QString replaceShaderSourceMacros(QString shaderSource);
107 
108  bool hasLoadedExtensions;
109  QString mShaderPath;
110 
111  vtkWeakPointer<vtkRenderWindow> LastContext;
112  vtkSmartPointer<vtkShaderProgram2> Shader;
113  std::vector<SingleVolumePainterHelper> mElement;
114 };
115 
116 #endif //CX_VTK_OPENGL2
117 
118 
119 //---------------------------------------------------------
120 }//end namespace
121 //---------------------------------------------------------
122 #endif /* CXTEXTURESLICEPAINTER_H_ */
cx::GPUImageLutBufferPtr
boost::shared_ptr< class GPUImageLutBuffer > GPUImageLutBufferPtr
Definition: cxForwardDeclarations.h:55
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxForwardDeclarations.h
cx::GPUImageDataBufferPtr
boost::shared_ptr< class GPUImageDataBuffer > GPUImageDataBufferPtr
Definition: cxForwardDeclarations.h:53
cx::SingleVolumePainterHelper
Definition: cxTextureSlicePainter.h:44
cx::TextureSlicePainter
Helper class for GPU rendering of slices.
Definition: cxTextureSlicePainter.h:76
vtkForwardDeclarations.h