CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxImage.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 CXIMAGE_H_
35 #define CXIMAGE_H_
36 
37 #include "cxResourceExport.h"
38 #include "cxPrecompiledHeader.h"
39 
40 #include <map>
41 #include <vector>
42 #include <boost/shared_ptr.hpp>
43 #include "cxBoundingBox3D.h"
44 #include "vtkForwardDeclarations.h"
45 #include "cxForwardDeclarations.h"
46 #include "cxData.h"
47 
48 typedef boost::shared_ptr<std::map<int, int> > HistogramMapPtr;
49 
50 class QDomNode;
51 class QDomDocument;
52 
53 
54 namespace cx
55 {
56 typedef std::map<int, int> IntIntMap;
57 typedef std::map<int, QColor> ColorMap;
58 
66 class cxResource_EXPORT Image : public Data
67 {
68 Q_OBJECT
69 
70 public:
72  {
73  bool on;
74  double ambient;
75  double diffuse;
76  double specular;
77  double specularPower;
78 
79  ShadingStruct();
80  void addXml(QDomNode dataNode);
81  void parseXml(QDomNode dataNode);
82 
83  private:
84  double loadAttribute(QDomNode dataNode, QString name, double defVal);
85  };
86 
87  static ImagePtr create(const QString& uid, const QString& name);
88  ImagePtr copy();
89 
90  virtual ~Image();
91  Image(const QString& uid, const vtkImageDataPtr& data, const QString& name = "");
92 
95  virtual void intitializeFromParentImage(ImagePtr parentImage);
96  virtual void setVtkImageData(const vtkImageDataPtr& data, bool resetTransferFunctions = true);
97 
98  virtual vtkImageDataPtr getBaseVtkImageData();
99  virtual vtkImageDataPtr getGrayScaleVtkImageData();
100  virtual vtkImageDataPtr get8bitGrayScaleVtkImageData();
101 
104  virtual ImagePtr getUnsigned(ImagePtr self);
105 
106  virtual QString getModality() const;
107  virtual void setModality(const QString& val);
108  virtual QString getImageType() const;
109  virtual void setImageType(const QString& val);
110 
111  virtual ImageTF3DPtr getTransferFunctions3D();
112  virtual void setTransferFunctions3D(ImageTF3DPtr transferFuntion);
113  virtual ImageLUT2DPtr getLookupTable2D();
114  virtual void setLookupTable2D(ImageLUT2DPtr imageLookupTable2D);
115 
116  virtual void setInitialWindowLevel(double width, double level);
117  double getInitialWindowLevel() const { return mInitialWindowLevel; }
118  double getInitialWindowWidth() const { return mInitialWindowWidth; }
119 
120  virtual DoubleBoundingBox3D boundingBox() const;
121  virtual Eigen::Array3d getSpacing() const;
122  virtual vtkImageAccumulatePtr getHistogram();
123  virtual int getMax();
124  virtual int getMin();
125  virtual int getRange();
126  virtual int getMaxAlphaValue();
127  virtual void setShadingOn(bool on);
128  virtual bool getShadingOn() const;
129  virtual void setShadingAmbient(double ambient);
130  virtual void setShadingDiffuse(double diffuse);
131  virtual void setShadingSpecular(double specular);
132  virtual void setShadingSpecularPower(double specularPower);
133  virtual double getShadingAmbient();
134  virtual double getShadingDiffuse();
135  virtual double getShadingSpecular();
136  virtual double getShadingSpecularPower();
137  virtual Image::ShadingStruct getShading();
138  virtual void setShading(Image::ShadingStruct shading);
139 
140  void addXml(QDomNode& dataNode);
141  virtual void parseXml(QDomNode& dataNode);
142  virtual bool load(QString path);
143  virtual QString getType() const
144  {
145  return getTypeName();
146  }
147  static QString getTypeName()
148  {
149  return "image";
150  }
151 
152  // methods for defining and storing a cropping box. Image does not use these data, this is up to the mapper
153  virtual void setCropping(bool on);
154  virtual bool getCropping() const;
155  virtual void setCroppingBox(const DoubleBoundingBox3D& bb_d);
156  virtual DoubleBoundingBox3D getCroppingBox() const;
157 
158  // methods for defining and storing clip planes. Image does not use these data, this is up to the mapper
159  virtual void addPersistentClipPlane(vtkPlanePtr plane);
160  virtual std::vector<vtkPlanePtr> getAllClipPlanes();
161  virtual void clearPersistentClipPlanes();
162  virtual void setInteractiveClipPlane(vtkPlanePtr plane);
163 
164  void mergevtkSettingsIntosscTransform();
165 
166  void resetTransferFunctions(bool _2D=true, bool _3D=true);
167 
168  void moveThisAndChildrenToThread(QThread* thread);
169 
170  static vtkImageDataPtr createDummyImageData(int axisSize, int maxVoxelValue);
171 
172  void setInterpolationTypeToNearest();
173  void setInterpolationTypeToLinear();
174  void setInterpolationType(int val);
175  int getInterpolationType() const;
176 
177  vtkImageDataPtr resample(long maxVoxels);
178 
179  virtual void save(const QString &basePath);
180 
181  void startThresholdPreview(const Eigen::Vector2d& threshold);
182  void stopThresholdPreview();
183  int getVTKMinValue();
184  int getVTKMaxValue();
185 signals:
186  void vtkImageDataChanged();
187  void transferFunctionsChanged();
188  void clipPlanesChanged();
189  void cropBoxChanged();
190 
191 protected slots:
192  virtual void transformChangedSlot();
193 
194 protected:
197 // vtkImageReslicePtr mOrientator; ///< converts imagedata to outputimagedata
198 // vtkMatrix4x4Ptr mOrientatorMatrix;
199 // vtkImageDataPtr mReferenceImageData; ///< imagedata after filtering through the orientatior, given in reference space
202 
203 // LandmarksPtr mLandmarks;
204 
206 
209  std::vector<vtkPlanePtr> mPersistentClipPlanes;
211  QString mModality;
212  QString mImageType;
215 
216 
217 private:
218  Image(const Image& other);
219  Image& operator=(const Image& other);
220  void resetTransferFunction(ImageTF3DPtr imageTransferFunctions3D, ImageLUT2DPtr imageLookupTable2D);
221  void resetTransferFunction(ImageLUT2DPtr imageLookupTable2D);
222  void resetTransferFunction(ImageTF3DPtr imageTransferFunctions3D);
223  DoubleBoundingBox3D getInitialBoundingBox() const;
224  double loadAttribute(QDomNode dataNode, QString name, double defVal);
225 
226  double computeResampleFactor(long maxVoxels);
227 
228  ColorMap createPreviewColorMap(const Eigen::Vector2d &threshold);
229  IntIntMap createPreviewOpacityMap(const Eigen::Vector2d &threshold);
230  void createThresholdPreviewTransferFunctions3D(const Eigen::Vector2d &threshold);
231  void createThresholdPreviewLookupTable2D(const Eigen::Vector2d &threshold);
232 
233  ImageTF3DPtr getUnmodifiedTransferFunctions3D();
234  ImageLUT2DPtr getUnmodifiedLookupTable2D();
235 
236  ImageTF3DPtr mImageTransferFunctions3D;
237  ImageLUT2DPtr mImageLookupTable2D;
238 
239  double mInitialWindowWidth;
240  double mInitialWindowLevel;
241 
242  bool mThresholdPreview;
243  ImageTF3DPtr mTresholdPreviewTransferfunctions3D;
244  ImageLUT2DPtr mTresholdPreviewLookupTable2D;
245 };
246 
247 } // end namespace cx
248 
249 #endif /*CXIMAGE_H_*/
ShadingStruct mShading
Definition: cxImage.h:205
bool mUseCropping
image should be cropped using mCroppingBox
Definition: cxImage.h:207
double getInitialWindowLevel() const
Definition: cxImage.h:117
QString mImageType
type of the image, defined as DICOM tag (0008,0008) (mainly value 3, but might be a merge of value 4)...
Definition: cxImage.h:212
vtkSmartPointer< class vtkImageAccumulate > vtkImageAccumulatePtr
virtual QString getType() const
Definition: cxImage.h:143
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
double mMaxRGBIntensity
Definition: cxImage.h:213
double getInitialWindowWidth() const
Definition: cxImage.h:118
DoubleBoundingBox3D mCroppingBox_d
box defining the cropping size.
Definition: cxImage.h:208
ImagePtr mUnsigned
version of this containing unsigned data.
Definition: cxImage.h:201
std::map< int, QColor > ColorMap
Definition: cxImage.h:57
boost::shared_ptr< class ImageLUT2D > ImageLUT2DPtr
vtkPlanePtr mInteractiveClipPlane
Definition: cxImage.h:210
QString mModality
modality of the image, defined as DICOM tag (0008,0060), Section 3, C.7.3.1.1.1
Definition: cxImage.h:211
A volumetric data set.
Definition: cxImage.h:66
boost::shared_ptr< std::map< int, int > > HistogramMapPtr
Definition: cxImage.h:48
static QString getTypeName()
Definition: cxImage.h:147
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.
vtkImageAccumulatePtr mHistogramPtr
Histogram.
Definition: cxImage.h:200
Superclass for all data objects.
Definition: cxData.h:69
std::map< int, int > IntIntMap
Definition: cxImage.h:56
std::vector< vtkPlanePtr > mPersistentClipPlanes
Definition: cxImage.h:209
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
vtkImageDataPtr mBaseImageData
image data in data space
Definition: cxImage.h:195
int mInterpolationType
mirror the interpolationType in vtkVolumeProperty
Definition: cxImage.h:214
vtkSmartPointer< class vtkPlane > vtkPlanePtr
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr
vtkImageDataPtr mBaseGrayScaleImageData
image data in data space
Definition: cxImage.h:196