Fraxinus  16.5.0-fx-rc1
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  virtual QIcon getIcon() {return QIcon(":/icons/volume.png");}
152 
153  // methods for defining and storing a cropping box. Image does not use these data, this is up to the mapper
154  virtual void setCropping(bool on);
155  virtual bool getCropping() const;
156  virtual void setCroppingBox(const DoubleBoundingBox3D& bb_d);
157  virtual DoubleBoundingBox3D getCroppingBox() const;
158 
159  void mergevtkSettingsIntosscTransform();
160 
161  void resetTransferFunctions(bool _2D=true, bool _3D=true);
162 
163  void moveThisAndChildrenToThread(QThread* thread);
164 
165  static vtkImageDataPtr createDummyImageData(int axisSize, int maxVoxelValue);
166 
167 // void setInterpolationTypeToNearest();
168 // void setInterpolationTypeToLinear();
169  void setInterpolationType(int val);
170  int getInterpolationType() const;
171 
172  vtkImageDataPtr resample(long maxVoxels);
173 
174  virtual void save(const QString &basePath);
175 
176  void startThresholdPreview(const Eigen::Vector2d& threshold);
177  void stopThresholdPreview();
178  int getVTKMinValue();
179  int getVTKMaxValue();
180 signals:
181  void vtkImageDataChanged();
182  void transferFunctionsChanged();
183  void cropBoxChanged();
184 
185 protected slots:
186  virtual void transformChangedSlot();
187 
188 protected:
191 // vtkImageReslicePtr mOrientator; ///< converts imagedata to outputimagedata
192 // vtkMatrix4x4Ptr mOrientatorMatrix;
193 // vtkImageDataPtr mReferenceImageData; ///< imagedata after filtering through the orientatior, given in reference space
196 
197 // LandmarksPtr mLandmarks;
198 
200 
203 
204  QString mModality;
205  QString mImageType;
208 
209 
210 private:
211  Image(const Image& other);
212  Image& operator=(const Image& other);
213  void resetTransferFunction(ImageTF3DPtr imageTransferFunctions3D, ImageLUT2DPtr imageLookupTable2D);
214  void resetTransferFunction(ImageLUT2DPtr imageLookupTable2D);
215  void resetTransferFunction(ImageTF3DPtr imageTransferFunctions3D);
216  DoubleBoundingBox3D getInitialBoundingBox() const;
217  double loadAttribute(QDomNode dataNode, QString name, double defVal);
218 
219  double computeResampleFactor(long maxVoxels);
220 
221  ColorMap createPreviewColorMap(const Eigen::Vector2d &threshold);
222  IntIntMap createPreviewOpacityMap(const Eigen::Vector2d &threshold);
223  void createThresholdPreviewTransferFunctions3D(const Eigen::Vector2d &threshold);
224  void createThresholdPreviewLookupTable2D(const Eigen::Vector2d &threshold);
225 
226  ImageTF3DPtr getUnmodifiedTransferFunctions3D();
227  ImageLUT2DPtr getUnmodifiedLookupTable2D();
228 
229  ImageTF3DPtr mImageTransferFunctions3D;
230  ImageLUT2DPtr mImageLookupTable2D;
231 
232  double mInitialWindowWidth;
233  double mInitialWindowLevel;
234 
235  bool mThresholdPreview;
236  ImageTF3DPtr mTresholdPreviewTransferfunctions3D;
237  ImageLUT2DPtr mTresholdPreviewLookupTable2D;
238 };
239 
240 } // end namespace cx
241 
242 #endif /*CXIMAGE_H_*/
ShadingStruct mShading
Definition: cxImage.h:199
bool mUseCropping
image should be cropped using mCroppingBox
Definition: cxImage.h:201
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:205
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:206
double getInitialWindowWidth() const
Definition: cxImage.h:118
DoubleBoundingBox3D mCroppingBox_d
box defining the cropping size.
Definition: cxImage.h:202
ImagePtr mUnsigned
version of this containing unsigned data.
Definition: cxImage.h:195
std::map< int, QColor > ColorMap
Definition: cxImage.h:57
boost::shared_ptr< class ImageLUT2D > ImageLUT2DPtr
QString mModality
modality of the image, defined as DICOM tag (0008,0060), Section 3, C.7.3.1.1.1
Definition: cxImage.h:204
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:194
Superclass for all data objects.
Definition: cxData.h:109
std::map< int, int > IntIntMap
Definition: cxImage.h:56
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
vtkImageDataPtr mBaseImageData
image data in data space
Definition: cxImage.h:189
int mInterpolationType
mirror the interpolationType in vtkVolumeProperty
Definition: cxImage.h:207
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr
virtual QIcon getIcon()
Definition: cxImage.h:151
vtkImageDataPtr mBaseGrayScaleImageData
image data in data space
Definition: cxImage.h:190