Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #ifndef CXGPUIMAGEBUFFER_H_
35 #define CXGPUIMAGEBUFFER_H_
36 
37 #include "cxResourceExport.h"
38 #include "cxPrecompiledHeader.h"
39 
40 #include <boost/shared_ptr.hpp>
41 #include <boost/weak_ptr.hpp>
42 #include <map>
43 #include <list>
44 #include "vtkForwardDeclarations.h"
45 
46 namespace cx
47 {
48 
60 class cxResource_EXPORT GPUImageDataBuffer
61 {
62 public:
63  virtual ~GPUImageDataBuffer() {}
68  virtual void allocate() = 0;
69 // /** Assuming imageData is changed,
70 // * send vtkImageData to GPU.
71 // */
72 // virtual void updateTexture() = 0;
77  virtual void bind(int textureUnitIndex) = 0;
78  virtual int getMemorySize() = 0;
79 
85  virtual unsigned int getTextureUid() const = 0;
86  //virtual vtkImageDataPtr getVtkImageData() = 0;
87 };
88 
89 typedef boost::shared_ptr<GPUImageDataBuffer> GPUImageDataBufferPtr;
90 typedef boost::weak_ptr<GPUImageDataBuffer> GPUImageDataBufferWeakPtr;
91 
93 
99 class cxResource_EXPORT GPUImageLutBuffer
100 {
101 public:
102  virtual ~GPUImageLutBuffer() {}
108  virtual void allocate() = 0;
109 // /** If data is changed, send data to GPU.
110 // */
111 // virtual void updateTexture() = 0;
116  virtual void bind(int textureUnitIndex) = 0;
119  virtual int getLutSize() const = 0;
120 };
121 
122 typedef boost::shared_ptr<GPUImageLutBuffer> GPUImageLutBufferPtr;
123 typedef boost::weak_ptr<GPUImageLutBuffer> GPUImageLutBufferWeakPtr;
124 
127 
133 class cxResource_EXPORT GPUImageBufferRepository
134 {
135 public:
136  static GPUImageBufferRepository* getInstance();
137  static void shutdown();
138 
139  GPUImageDataBufferPtr getGPUImageDataBuffer(vtkImageDataPtr volume);
140  GPUImageLutBufferPtr getGPUImageLutBuffer(vtkUnsignedCharArrayPtr lut);
141  int getMemoryUsage(int *textures);
145  void clear();
146 private:
149  class GPUImageBufferRepositoryInternal* mInternal;
150  static GPUImageBufferRepository* mInstance;
151  void tearDown();
152 };
153 
158 }
159 
160 #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