Fraxinus  17.12
An IGT application
cxSharedOpenGLContext.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 #ifndef CXSHAREDOPENGLCONTEXT_H
34 #define CXSHAREDOPENGLCONTEXT_H
35 
36 #ifdef WIN32
37 #include <windows.h>
38 #endif
39 
40 #include <GL/glew.h>
41 
42 #include <boost/shared_ptr.hpp>
43 #include "vtkForwardDeclarations.h"
44 
45 #include "cxResourceVisualizationExport.h"
46 #include "cxForwardDeclarations.h"
47 #include "vtkForwardDeclarations.h"
48 
49 namespace cx
50 {
51 
52 typedef boost::shared_ptr<class SharedOpenGLContext> SharedOpenGLContextPtr;
53 
65 class cxResourceVisualization_EXPORT SharedOpenGLContext
66 {
67 public:
68  static bool isValid(vtkOpenGLRenderWindowPtr opengl_renderwindow, bool print=false);
69 
72 
73  bool makeCurrent() const;
74  int getNumberOfTexturesInUse() const;
75 
76  //Image textures are per image
77  bool uploadImage(ImagePtr image);
78  bool hasUploadedImage(QString image_uid) const;
79  vtkTextureObjectPtr get3DTextureForImage(QString image_uid) const;
80  bool delete3DTextureForImage(QString image_uid);
81 
82  //LUT textures are per image
83  bool uploadLUT(QString imageUid, vtkUnsignedCharArrayPtr lutTable);
84  bool hasUploadedLUT(QString image_uid) const;
85  vtkTextureObjectPtr get1DTextureForLUT(QString image_uid) const;
86  bool delete1DTextureForLUT(QString image_uid);
87 
88  //Texture coordinates are per view
89  bool upload3DTextureCoordinates(QString uid, vtkFloatArrayPtr texture_coordinates);
90  bool hasUploadedTextureCoordinates(QString uid) const;
91  vtkOpenGLBufferObjectPtr getTextureCoordinates(QString uid) const;
92  vtkImageDataPtr downloadImageFromTextureBuffer(QString image_uid);//For testing
93 
94 
95 private:
96  bool create1DTextureObject(vtkTextureObjectPtr texture_object, unsigned int width, int dataType, int numComps, void *data, vtkOpenGLRenderWindowPtr opengl_renderwindow) const;
97  bool create3DTextureObject(vtkTextureObjectPtr texture_object, unsigned int width, unsigned int height, unsigned int depth, int dataType, int numComps, void *data, vtkOpenGLRenderWindowPtr opengl_renderwindow) const;
98  vtkOpenGLBufferObjectPtr allocateAndUploadArrayBuffer(QString uid, int my_numberOfTextureCoordinates, int numberOfComponentsPerTexture, const float *texture_data) const;
99 
105  std::map<QString, std::pair<vtkTextureObjectPtr, unsigned long> > m1DTextureObjects;
106  std::map<QString, std::pair<vtkTextureObjectPtr, unsigned long> > m3DTextureObjects;
107 
108  std::map<QString, vtkOpenGLBufferObjectPtr > mTextureCoordinateBuffers;
109 
110  vtkOpenGLRenderWindowPtr mContext;
111 
112  SharedOpenGLContext(); //not implemented
113  bool useLinearInterpolation() const;
114 };
115 
116 }//cx
117 
118 #endif // CXSHAREDOPENGLCONTEXT_H
Shared OpenGL context.
vtkSmartPointer< class vtkTextureObject > vtkTextureObjectPtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
vtkSmartPointer< class vtkFloatArray > vtkFloatArrayPtr
vtkSmartPointer< class vtkUnsignedCharArray > vtkUnsignedCharArrayPtr
vtkSmartPointer< class vtkOpenGLBufferObject > vtkOpenGLBufferObjectPtr
vtkSmartPointer< class vtkOpenGLRenderWindow > vtkOpenGLRenderWindowPtr
boost::shared_ptr< class SharedOpenGLContext > SharedOpenGLContextPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
void print(QString header, QRect r)
Namespace for all CustusX production code.