Fraxinus  22.04-rc5
An IGT application
cxGPUImageBuffer.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 #ifndef CXGPUIMAGEBUFFER_H_
14 #define CXGPUIMAGEBUFFER_H_
15 
16 #include "cxResourceExport.h"
17 #include "cxPrecompiledHeader.h"
18 
19 #include <boost/shared_ptr.hpp>
20 #include <boost/weak_ptr.hpp>
21 #include <map>
22 #include <list>
23 #include "vtkForwardDeclarations.h"
24 
25 namespace cx
26 {
27 
39 class cxResource_EXPORT GPUImageDataBuffer
40 {
41 public:
42  virtual ~GPUImageDataBuffer() {}
47  virtual void allocate(int textureUnitIndex) = 0;
48 // /** Assuming imageData is changed,
49 // * send vtkImageData to GPU.
50 // */
51 // virtual void updateTexture() = 0;
56  virtual void bind(int textureUnitIndex) = 0;
57  virtual int getMemorySize() = 0;
58 
64  virtual unsigned int getTextureUid() const = 0;
65  //virtual vtkImageDataPtr getVtkImageData() = 0;
66 };
67 
68 typedef boost::shared_ptr<GPUImageDataBuffer> GPUImageDataBufferPtr;
69 typedef boost::weak_ptr<GPUImageDataBuffer> GPUImageDataBufferWeakPtr;
70 
71 cxResource_EXPORT GPUImageDataBufferPtr createGPUImageDataBuffer(vtkImageDataPtr volume);
72 
78 class cxResource_EXPORT GPUImageLutBuffer
79 {
80 public:
81  virtual ~GPUImageLutBuffer() {}
87  virtual void allocate() = 0;
88 // /** If data is changed, send data to GPU.
89 // */
90 // virtual void updateTexture() = 0;
95  virtual void bind(int textureUnitIndex) = 0;
98  virtual int getLutSize() const = 0;
99 };
100 
101 typedef boost::shared_ptr<GPUImageLutBuffer> GPUImageLutBufferPtr;
102 typedef boost::weak_ptr<GPUImageLutBuffer> GPUImageLutBufferWeakPtr;
103 
104 cxResource_EXPORT GPUImageDataBufferPtr createGPUImageDataBuffer(vtkImageDataPtr volume);
105 cxResource_EXPORT GPUImageLutBufferPtr createGPUImageLutBuffer(vtkUnsignedCharArrayPtr lut);
106 
112 class cxResource_EXPORT GPUImageBufferRepository
113 {
114 public:
115  static GPUImageBufferRepository* getInstance();
116  static void shutdown();
117 
118  GPUImageDataBufferPtr getGPUImageDataBuffer(vtkImageDataPtr volume);
119  GPUImageLutBufferPtr getGPUImageLutBuffer(vtkUnsignedCharArrayPtr lut);
120  int getMemoryUsage(int *textures);
124  void clear();
125 private:
128  class GPUImageBufferRepositoryInternal* mInternal;
129  static GPUImageBufferRepository* mInstance;
130  void tearDown();
131 };
132 
133 // Not allowed to export static functions from dll on Windows,
134 // so we have to use this funciton instead of GPUImageBufferRepository::getInstance
136 
141 }
142 
143 #endif /*CXGPUIMAGEBUFFER_H_*/
Helper class for sharing GPU memory over several Views (GL contexts).
GPUImageDataBufferPtr createGPUImageDataBuffer(vtkImageDataPtr volume)
Repository for GPU buffers.
vtkSmartPointer< class vtkUnsignedCharArray > vtkUnsignedCharArrayPtr
boost::weak_ptr< class GPUImageDataBuffer > GPUImageDataBufferWeakPtr
boost::weak_ptr< class GPUImageLutBuffer > GPUImageLutBufferWeakPtr
GPUImageLutBufferPtr createGPUImageLutBuffer(vtkUnsignedCharArrayPtr lut)
boost::shared_ptr< class GPUImageDataBuffer > GPUImageDataBufferPtr
boost::shared_ptr< class GPUImageLutBuffer > GPUImageLutBufferPtr
Helper class for sharing GPU memory over several Views (GL contexts).
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
GPUImageBufferRepository * getGPUImageBufferRepository()
Namespace for all CustusX production code.