Fraxinus  2023.01.05-dev+develop.0da12
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) 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 #ifndef CXSHAREDOPENGLCONTEXT_H
13 #define CXSHAREDOPENGLCONTEXT_H
14 
15 #ifdef WIN32
16 #include <windows.h>
17 #endif
18 
19 #include <GL/glew.h>
20 
21 #include <boost/shared_ptr.hpp>
22 #include "vtkForwardDeclarations.h"
23 
24 #include "cxResourceVisualizationExport.h"
25 #include "cxForwardDeclarations.h"
26 #include "vtkForwardDeclarations.h"
27 
28 namespace cx
29 {
30 
31 typedef boost::shared_ptr<class SharedOpenGLContext> SharedOpenGLContextPtr;
32 
44 class cxResourceVisualization_EXPORT SharedOpenGLContext
45 {
46 public:
47  static bool isValid(vtkOpenGLRenderWindowPtr opengl_renderwindow, bool print=false);
48 
51 
52  bool makeCurrent() const;
53  int getNumberOfTexturesInUse() const;
54 
55  //Image textures are per image
56  bool uploadImage(ImagePtr image);
57  bool hasUploadedImage(QString image_uid) const;
58  vtkTextureObjectPtr get3DTextureForImage(QString image_uid) const;
59  bool delete3DTextureForImage(QString image_uid);
60 
61  //LUT textures are per image
62  bool uploadLUT(QString imageUid, vtkUnsignedCharArrayPtr lutTable);
63  bool hasUploadedLUT(QString image_uid) const;
64  vtkTextureObjectPtr get1DTextureForLUT(QString image_uid) const;
65  bool delete1DTextureForLUT(QString image_uid);
66 
67  //Texture coordinates are per view
68  bool upload3DTextureCoordinates(QString uid, vtkFloatArrayPtr texture_coordinates);
69  bool hasUploadedTextureCoordinates(QString uid) const;
70  vtkOpenGLBufferObjectPtr getTextureCoordinates(QString uid) const;
71  vtkImageDataPtr downloadImageFromTextureBuffer(QString image_uid);//For testing
72 
73 
74 private:
75  bool create1DTextureObject(vtkTextureObjectPtr texture_object, unsigned int width, int dataType, int numComps, void *data, vtkOpenGLRenderWindowPtr opengl_renderwindow) const;
76  bool create3DTextureObject(vtkTextureObjectPtr texture_object, unsigned int width, unsigned int height, unsigned int depth, int dataType, int numComps, void *data, vtkOpenGLRenderWindowPtr opengl_renderwindow) const;
77  vtkOpenGLBufferObjectPtr allocateAndUploadArrayBuffer(QString uid, int my_numberOfTextureCoordinates, int numberOfComponentsPerTexture, const float *texture_data) const;
78 
84  std::map<QString, std::pair<vtkTextureObjectPtr, unsigned long> > m1DTextureObjects;
85  std::map<QString, std::pair<vtkTextureObjectPtr, unsigned long> > m3DTextureObjects;
86 
87  std::map<QString, vtkOpenGLBufferObjectPtr > mTextureCoordinateBuffers;
88 
89  vtkOpenGLRenderWindowPtr mContext;
90 
91  SharedOpenGLContext(); //not implemented
92  bool useLinearInterpolation() const;
93 };
94 
95 }//cx
96 
97 #endif // CXSHAREDOPENGLCONTEXT_H
Shared OpenGL context.
vtkSmartPointer< class vtkTextureObject > vtkTextureObjectPtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
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.