Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxTexture3DSlicerProxy.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 CXTEXTURE3DSLICERPROXY_H_
14 #define CXTEXTURE3DSLICERPROXY_H_
15 
16 #include "cxResourceVisualizationExport.h"
17 
18 #include "cxRepImpl.h"
19 #include <vector>
20 #include "cxTransform3D.h"
21 #include "cxBoundingBox3D.h"
22 
23 #include "vtkForwardDeclarations.h"
24 #include "cxForwardDeclarations.h"
25 #include "cxConfig.h"
26 #include "cxShaderCallback.h"
27 
28 typedef vtkSmartPointer<class vtkPolyDataAlgorithm> vtkPolyDataAlgorithmPtr;
29 typedef vtkSmartPointer<class vtkOpenGLPolyDataMapper> vtkOpenGLPolyDataMapperPtr;
30 
31 //---------------------------------------------------------
32 namespace cx
33 {
34 
35 typedef vtkSmartPointer<class TextureSlicePainter> TextureSlicePainterPtr;
36 typedef boost::shared_ptr<class Texture3DSlicerProxy> Texture3DSlicerProxyPtr;
37 
49 class cxResourceVisualization_EXPORT Texture3DSlicerProxy: public QObject
50 {
51  Q_OBJECT
52 public:
53  static Texture3DSlicerProxyPtr New(SharedOpenGLContextPtr context);
54 
55  virtual ~Texture3DSlicerProxy() {}
56  virtual void setShaderPath(QString shaderFile) {}
57  virtual void setViewportData(const Transform3D& vpMs, const DoubleBoundingBox3D& vp) {}
58  virtual void setImages(std::vector<ImagePtr> images) {}
59  virtual std::vector<ImagePtr> getImages()
60  {
61  return std::vector<ImagePtr>();
62  }
63  virtual void setSliceProxy(SliceProxyPtr slicer) {}
65  {
66  return SliceProxyPtr();
67  }
68  virtual void setTargetSpaceToR() {}
70  {
71  return vtkActorPtr();
72  }
73  virtual void setRenderWindow(vtkRenderWindowPtr window) {};
74 
75  static bool isSupported(vtkRenderWindowPtr window)
76  {
77  return true;
78  };
79 
80 protected:
82 };
83 
84 //--------------------------------------------------------------------
85 
98 class cxResourceVisualization_EXPORT Texture3DSlicerProxyImpl: public Texture3DSlicerProxy
99 {
100  Q_OBJECT
101 
102 public:
103  static Texture3DSlicerProxyPtr New(SharedOpenGLContextPtr context);
104 
105  virtual ~Texture3DSlicerProxyImpl();
106 
107  void setViewportData(const Transform3D& vpMs, const DoubleBoundingBox3D& vp); // DEPRECATED: use zoomfactor in View and the object will auto-update
108  void setImages(std::vector<ImagePtr> images);
109  void setSliceProxy(SliceProxyPtr slicer);
110  SliceProxyPtr getSliceProxy();
111  void setTargetSpaceToR();
112  vtkActorPtr getActor();
113  std::vector<ImagePtr> getImages();
114  virtual void setRenderWindow(vtkRenderWindowPtr window);
115 
116 protected slots:
117  void transformChangedSlot();
118  void transferFunctionChangedSlot();
119  void uploadChangedImage(QString uid);
120 
121 protected:
123  void createGeometryPlane(Vector3D point1_s, Vector3D point2_s, Vector3D origin_s);
124 
125 private:
126  void resetGeometryPlane();
127 
128  void updateAndUploadImages(std::vector<ImagePtr> new_images_raw);
129  void updateAndUploadCoordinates();
130  void updateAndUploadColorAttribute();
131 
132  void uploadImagesToSharedContext(std::vector<ImagePtr> images, SharedOpenGLContextPtr sharedOpenGLContext, ShaderCallbackPtr shaderCallback) const;
133  void uploadTextureCoordinatesToSharedContext(QString image_uid, vtkFloatArrayPtr textureCoordinates, SharedOpenGLContextPtr sharedOpenGLContext, ShaderCallbackPtr shaderCallback) const;
134  void uploadColorAttributesToSharedContext(QString imageUid, float llr, vtkLookupTablePtr lut, float window, float level, float alpha, SharedOpenGLContextPtr sharedOpenGLContext, ShaderCallbackPtr shaderCallback) const;
135 
136  QString getTCoordName(int index);
137  void setColorAttributes(int i);
138  std::vector<ImagePtr> convertToUnsigned(std::vector<ImagePtr> images_raw);
139 
140  bool isNewInputImages(std::vector<ImagePtr> images_raw);
141 
142  QString generateTextureCoordinateName(QString imageUid) const;
143  void generateAndSetShaders();
144 
145 
146  SharedOpenGLContextPtr mSharedOpenGLContext;
147  ShaderCallbackPtr mShaderCallback;
148  QString mUid;
149 
150  DoubleBoundingBox3D mBB_s;
151  std::vector<ImagePtr> mImages;
152  std::vector<ImagePtr> mRawImages;
153  SliceProxyPtr mSliceProxy;
154  bool mTargetSpaceIsR;
155 
156  vtkActorPtr mActor;
157  vtkPolyDataPtr mPolyData;
158  vtkPlaneSourcePtr mPlaneSource;
159  vtkPolyDataAlgorithmPtr mPolyDataAlgorithm;
160  vtkOpenGLPolyDataMapperPtr mOpenGLPolyDataMapper;
161  vtkRenderWindowPtr mCurrentRenderWindow;
162 
163  vtkFloatArrayPtr mTextureCoordinates;
164 
165 };
166 //--------------------------------------------------------------------
167 
168 }//namespace cx
169 
170 #endif /* CXTEXTURE3DSLICERPROXY_H_ */
virtual std::vector< ImagePtr > getImages()
virtual SliceProxyPtr getSliceProxy()
vtkSmartPointer< class vtkActor > vtkActorPtr
vtkSmartPointer< class TextureSlicePainter > TextureSlicePainterPtr
vtkSmartPointer< class ShaderCallback > ShaderCallbackPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
vtkSmartPointer< class vtkFloatArray > vtkFloatArrayPtr
vtkSmartPointer< class vtkRenderWindow > vtkRenderWindowPtr
vtkSmartPointer< class vtkPolyDataAlgorithm > vtkPolyDataAlgorithmPtr
virtual void setImages(std::vector< ImagePtr > images)
virtual vtkActorPtr getActor()
Slice volumes using a SliceProxy.
virtual void setSliceProxy(SliceProxyPtr slicer)
virtual void setRenderWindow(vtkRenderWindowPtr window)
boost::shared_ptr< class SharedOpenGLContext > SharedOpenGLContextPtr
vtkSmartPointer< class vtkOpenGLPolyDataMapper > vtkOpenGLPolyDataMapperPtr
Helper class for GPU-based slicing.
virtual void setShaderPath(QString shaderFile)
vtkSmartPointer< class vtkLookupTable > vtkLookupTablePtr
boost::shared_ptr< class Texture3DSlicerProxy > Texture3DSlicerProxyPtr
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
vtkSmartPointer< class vtkPlaneSource > vtkPlaneSourcePtr
vtkSmartPointer< class vtkPolyDataAlgorithm > vtkPolyDataAlgorithmPtr
Definition: cxViewWrapper.h:29
static bool isSupported(vtkRenderWindowPtr window)
virtual void setViewportData(const Transform3D &vpMs, const DoubleBoundingBox3D &vp)
Namespace for all CustusX production code.