Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
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) 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 CXIMAGE_H_
14 #define CXIMAGE_H_
15 
16 #include "cxResourceExport.h"
17 #include "cxPrecompiledHeader.h"
18 
19 #include <map>
20 #include <vector>
21 #include <boost/shared_ptr.hpp>
22 #include "cxBoundingBox3D.h"
23 #include "vtkForwardDeclarations.h"
24 #include "cxForwardDeclarations.h"
25 #include "cxData.h"
26 
27 typedef boost::shared_ptr<std::map<int, int> > HistogramMapPtr;
28 
29 class QDomNode;
30 class QDomDocument;
31 
32 
33 namespace cx
34 {
35 typedef std::map<int, int> IntIntMap;
36 typedef std::map<int, QColor> ColorMap;
37 
45 class cxResource_EXPORT Image : public Data
46 {
47 Q_OBJECT
48 
49 public:
51  {
52  bool on;
53  double ambient;
54  double diffuse;
55  double specular;
56  double specularPower;
57 
58  ShadingStruct();
59  void addXml(QDomNode dataNode);
60  void parseXml(QDomNode dataNode);
61 
62  private:
63  double loadAttribute(QDomNode dataNode, QString name, double defVal);
64  };
65 
66  static ImagePtr create(const QString& uid, const QString& name);
67  ImagePtr copy();
68 
69  virtual ~Image();
70  Image(const QString& uid, const vtkImageDataPtr& data, const QString& name = "");
71 
74  virtual void intitializeFromParentImage(ImagePtr parentImage);
75  virtual void setVtkImageData(const vtkImageDataPtr& data, bool resetTransferFunctions = true);
76 
77  virtual vtkImageDataPtr getBaseVtkImageData();
78  virtual vtkImageDataPtr getGrayScaleVtkImageData();
79  virtual vtkImageDataPtr get8bitGrayScaleVtkImageData();
80 
83  virtual ImagePtr getUnsigned(ImagePtr self);
84 
85  virtual IMAGE_MODALITY getModality() const;
86  virtual void setModality(const IMAGE_MODALITY &val);
87  virtual IMAGE_SUBTYPE getImageType() const;
88  virtual void setImageType(const IMAGE_SUBTYPE &val);
89 
90  virtual ImageTF3DPtr getTransferFunctions3D();
91  virtual void setTransferFunctions3D(ImageTF3DPtr transferFuntion);
92  virtual ImageLUT2DPtr getLookupTable2D();
93  virtual void setLookupTable2D(ImageLUT2DPtr imageLookupTable2D);
94 
95  virtual void setInitialWindowLevel(double width, double level);
96  double getInitialWindowLevel() const { return mInitialWindowLevel; }
97  double getInitialWindowWidth() const { return mInitialWindowWidth; }
98 
99  virtual DoubleBoundingBox3D boundingBox() const;
100  virtual Eigen::Array3d getSpacing() const;
101  virtual vtkImageAccumulatePtr getHistogram();
102  virtual int getMax();
103  virtual int getMin();
104  virtual int getRange();
105  virtual int getMaxAlphaValue();
106  virtual void setShadingOn(bool on);
107  virtual bool getShadingOn() const;
108  virtual void setShadingAmbient(double ambient);
109  virtual void setShadingDiffuse(double diffuse);
110  virtual void setShadingSpecular(double specular);
111  virtual void setShadingSpecularPower(double specularPower);
112  virtual double getShadingAmbient();
113  virtual double getShadingDiffuse();
114  virtual double getShadingSpecular();
115  virtual double getShadingSpecularPower();
116  virtual Image::ShadingStruct getShading();
117  virtual void setShading(Image::ShadingStruct shading);
118 
119  void addXml(QDomNode& dataNode);
120  virtual void parseXml(QDomNode& dataNode);
121  virtual bool load(QString path, FileManagerServicePtr filemanager);
122  virtual QString getType() const
123  {
124  return getTypeName();
125  }
126  static QString getTypeName()
127  {
128  return "image";
129  }
130  virtual QIcon getIcon() {return QIcon(":/icons/volume.png");}
131 
132  // methods for defining and storing a cropping box. Image does not use these data, this is up to the mapper
133  virtual void setCropping(bool on);
134  virtual bool getCropping() const;
135  virtual void setCroppingBox(const DoubleBoundingBox3D& bb_d);
136  virtual DoubleBoundingBox3D getCroppingBox() const;
137 
138  void mergevtkSettingsIntosscTransform();
139 
140  void resetTransferFunctions(bool _2D=true, bool _3D=true);
141 
142  void moveThisAndChildrenToThread(QThread* thread);
143 
144  static vtkImageDataPtr createDummyImageData(int axisSize, int maxVoxelValue);
145 
146 // void setInterpolationTypeToNearest();
147 // void setInterpolationTypeToLinear();
148  void setInterpolationType(int val);
149  int getInterpolationType() const;
150 
151  vtkImageDataPtr resample(long maxVoxels);
152 
153  virtual void save(const QString &basePath, FileManagerServicePtr filemanager);
154 
155  void startThresholdPreview(const Eigen::Vector2d& threshold);
156  void stopThresholdPreview();
157  double getVTKMinValue();
158  double getVTKMaxValue();
159  bool is2D();
160  void setDicomSeriesNumber(QString seriesNumber);
161  QString getDicomSeriesNumber();
162 
163 signals:
164  void vtkImageDataChanged(QString uid = QString());
165  void transferFunctionsChanged();
166  void cropBoxChanged();
167 
168 protected slots:
169  virtual void transformChangedSlot();
170 
171 protected:
174 // vtkImageReslicePtr mOrientator; ///< converts imagedata to outputimagedata
175 // vtkMatrix4x4Ptr mOrientatorMatrix;
176 // vtkImageDataPtr mReferenceImageData; ///< imagedata after filtering through the orientatior, given in reference space
179 
180 // LandmarksPtr mLandmarks;
181 
183 
186 
187  IMAGE_MODALITY mModality;
188  IMAGE_SUBTYPE mImageType;
191 
192 
193 private:
194  Image(const Image& other);
195  Image& operator=(const Image& other);
196  void resetTransferFunction(ImageTF3DPtr imageTransferFunctions3D, ImageLUT2DPtr imageLookupTable2D);
197  void resetTransferFunction(ImageLUT2DPtr imageLookupTable2D);
198  void resetTransferFunction(ImageTF3DPtr imageTransferFunctions3D);
199  DoubleBoundingBox3D getInitialBoundingBox() const;
200  double loadAttribute(QDomNode dataNode, QString name, double defVal);
201 
202  double computeResampleFactor(long maxVoxels);
203 
204  ColorMap createPreviewColorMap(const Eigen::Vector2d &threshold);
205  IntIntMap createPreviewOpacityMap(const Eigen::Vector2d &threshold);
206  void createThresholdPreviewTransferFunctions3D(const Eigen::Vector2d &threshold);
207  void createThresholdPreviewLookupTable2D(const Eigen::Vector2d &threshold);
208 
209  ImageTF3DPtr getUnmodifiedTransferFunctions3D();
210  ImageLUT2DPtr getUnmodifiedLookupTable2D();
211 
212  ImageTF3DPtr mImageTransferFunctions3D;
213  ImageLUT2DPtr mImageLookupTable2D;
214 
215  double mInitialWindowWidth;
216  double mInitialWindowLevel;
217 
218  bool mThresholdPreview;
219  ImageTF3DPtr mTresholdPreviewTransferfunctions3D;
220  ImageLUT2DPtr mTresholdPreviewLookupTable2D;
221 
222  QString mDicomSeriesNumber;
223 };
224 
225 } // end namespace cx
226 
227 #endif /*CXIMAGE_H_*/
ShadingStruct mShading
Definition: cxImage.h:182
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
bool mUseCropping
image should be cropped using mCroppingBox
Definition: cxImage.h:184
double getInitialWindowLevel() const
Definition: cxImage.h:96
IMAGE_MODALITY mModality
modality of the image, defined as DICOM tag (0008,0060), Section 3, C.7.3.1.1.1
Definition: cxImage.h:187
vtkSmartPointer< class vtkImageAccumulate > vtkImageAccumulatePtr
virtual QString getType() const
Definition: cxImage.h:122
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
double mMaxRGBIntensity
Definition: cxImage.h:189
double getInitialWindowWidth() const
Definition: cxImage.h:97
DoubleBoundingBox3D mCroppingBox_d
box defining the cropping size.
Definition: cxImage.h:185
ImagePtr mUnsigned
version of this containing unsigned data.
Definition: cxImage.h:178
std::map< int, QColor > ColorMap
Definition: cxImage.h:36
IMAGE_SUBTYPE 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:188
boost::shared_ptr< class ImageLUT2D > ImageLUT2DPtr
A volumetric data set.
Definition: cxImage.h:45
boost::shared_ptr< std::map< int, int > > HistogramMapPtr
Definition: cxImage.h:27
static QString getTypeName()
Definition: cxImage.h:126
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:177
Superclass for all data objects.
Definition: cxData.h:89
std::map< int, int > IntIntMap
Definition: cxImage.h:35
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
vtkImageDataPtr mBaseImageData
image data in data space
Definition: cxImage.h:172
int mInterpolationType
mirror the interpolationType in vtkVolumeProperty
Definition: cxImage.h:190
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr
virtual QIcon getIcon()
Definition: cxImage.h:130
Namespace for all CustusX production code.
vtkImageDataPtr mBaseGrayScaleImageData
image data in data space
Definition: cxImage.h:173