Fraxinus  17.12-rc1
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) 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 CXTEXTURE3DSLICERPROXY_H_
35 #define CXTEXTURE3DSLICERPROXY_H_
36 
37 #include "cxResourceVisualizationExport.h"
38 
39 #include "cxRepImpl.h"
40 #include <vector>
41 #include "cxTransform3D.h"
42 #include "cxBoundingBox3D.h"
43 
44 #include "vtkForwardDeclarations.h"
45 #include "cxForwardDeclarations.h"
46 #include "cxConfig.h"
47 #include "cxShaderCallback.h"
48 
49 typedef vtkSmartPointer<class vtkPolyDataAlgorithm> vtkPolyDataAlgorithmPtr;
50 typedef vtkSmartPointer<class vtkOpenGLPolyDataMapper> vtkOpenGLPolyDataMapperPtr;
51 
52 //---------------------------------------------------------
53 namespace cx
54 {
55 
56 typedef vtkSmartPointer<class TextureSlicePainter> TextureSlicePainterPtr;
57 typedef boost::shared_ptr<class Texture3DSlicerProxy> Texture3DSlicerProxyPtr;
58 
70 class cxResourceVisualization_EXPORT Texture3DSlicerProxy: public QObject
71 {
72  Q_OBJECT
73 public:
74  static Texture3DSlicerProxyPtr New(SharedOpenGLContextPtr context);
75 
76  virtual ~Texture3DSlicerProxy() {}
77  virtual void setShaderPath(QString shaderFile) {}
78  virtual void setViewportData(const Transform3D& vpMs, const DoubleBoundingBox3D& vp) {}
79  virtual void setImages(std::vector<ImagePtr> images) {}
80  virtual std::vector<ImagePtr> getImages()
81  {
82  return std::vector<ImagePtr>();
83  }
84  virtual void setSliceProxy(SliceProxyPtr slicer) {}
86  {
87  return SliceProxyPtr();
88  }
89  virtual void setTargetSpaceToR() {}
91  {
92  return vtkActorPtr();
93  }
94  virtual void setRenderWindow(vtkRenderWindowPtr window) {};
95 
96  static bool isSupported(vtkRenderWindowPtr window)
97  {
98  return true;
99  };
100 
101 protected:
103 };
104 
105 //--------------------------------------------------------------------
106 
119 class cxResourceVisualization_EXPORT Texture3DSlicerProxyImpl: public Texture3DSlicerProxy
120 {
121  Q_OBJECT
122 
123 public:
124  static Texture3DSlicerProxyPtr New(SharedOpenGLContextPtr context);
125 
126  virtual ~Texture3DSlicerProxyImpl();
127 
128  void setViewportData(const Transform3D& vpMs, const DoubleBoundingBox3D& vp); // DEPRECATED: use zoomfactor in View and the object will auto-update
129  void setImages(std::vector<ImagePtr> images);
130  void setSliceProxy(SliceProxyPtr slicer);
131  SliceProxyPtr getSliceProxy();
132  void setTargetSpaceToR();
133  vtkActorPtr getActor();
134  std::vector<ImagePtr> getImages();
135  virtual void setRenderWindow(vtkRenderWindowPtr window);
136 
137 protected slots:
138  void transformChangedSlot();
139  void transferFunctionChangedSlot();
140  void imageChanged();
141 
142 protected:
144  void createGeometryPlane(Vector3D point1_s, Vector3D point2_s, Vector3D origin_s);
145 
146 private:
147  void resetGeometryPlane();
148 
149  void updateAndUploadImages(std::vector<ImagePtr> new_images_raw);
150  void updateAndUploadCoordinates();
151  void updateAndUploadColorAttribute();
152 
153  void uploadImagesToSharedContext(std::vector<ImagePtr> images, SharedOpenGLContextPtr sharedOpenGLContext, ShaderCallbackPtr shaderCallback) const;
154  void uploadTextureCoordinatesToSharedContext(QString image_uid, vtkFloatArrayPtr textureCoordinates, SharedOpenGLContextPtr sharedOpenGLContext, ShaderCallbackPtr shaderCallback) const;
155  void uploadColorAttributesToSharedContext(QString imageUid, float llr, vtkLookupTablePtr lut, float window, float level, float alpha, SharedOpenGLContextPtr sharedOpenGLContext, ShaderCallbackPtr shaderCallback) const;
156 
157  QString getTCoordName(int index);
158  void setColorAttributes(int i);
159  std::vector<ImagePtr> convertToUnsigned(std::vector<ImagePtr> images_raw);
160 
161  bool isNewInputImages(std::vector<ImagePtr> images_raw);
162 
163  QString generateTextureCoordinateName(QString imageUid) const;
164  void generateAndSetShaders();
165 
166 
167  SharedOpenGLContextPtr mSharedOpenGLContext;
168  ShaderCallbackPtr mShaderCallback;
169  QString mUid;
170 
171  DoubleBoundingBox3D mBB_s;
172  std::vector<ImagePtr> mImages;
173  std::vector<ImagePtr> mRawImages;
174  SliceProxyPtr mSliceProxy;
175  bool mTargetSpaceIsR;
176 
177  vtkActorPtr mActor;
178  vtkPolyDataPtr mPolyData;
179  vtkPlaneSourcePtr mPlaneSource;
180  vtkPolyDataAlgorithmPtr mPolyDataAlgorithm;
181  vtkOpenGLPolyDataMapperPtr mOpenGLPolyDataMapper;
182  vtkRenderWindowPtr mCurrentRenderWindow;
183 
184  vtkFloatArrayPtr mTextureCoordinates;
185 
186 };
187 //--------------------------------------------------------------------
188 
189 }//namespace cx
190 
191 #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:63
vtkSmartPointer< class vtkPlaneSource > vtkPlaneSourcePtr
vtkSmartPointer< class vtkPolyDataAlgorithm > vtkPolyDataAlgorithmPtr
Definition: cxViewWrapper.h:50
static bool isSupported(vtkRenderWindowPtr window)
virtual void setViewportData(const Transform3D &vpMs, const DoubleBoundingBox3D &vp)
Namespace for all CustusX production code.