NorMIT-nav  22.09
An IGT application
cxImageAlgorithms.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 #ifndef CXIMAGEALGORITHMS_H_
13 #define CXIMAGEALGORITHMS_H_
14 
15 #include "cxResourceExport.h"
16 
17 #include <map>
18 #include <vector>
19 #include <QDateTime>
20 #include <QRegExp>
21 #include "cxForwardDeclarations.h"
22 #include "cxTransform3D.h"
23 #include "cxTypeConversions.h"
24 #include "vtkForwardDeclarations.h"
25 #include "cxBoundingBox3D.h"
26 
27 namespace cx
28 {
29 
41 cxResource_EXPORT ImagePtr resampleImage(PatientModelServicePtr dataManager, ImagePtr image, const Vector3D spacing, QString uid="", QString name="");
42 cxResource_EXPORT ImagePtr resampleImage(PatientModelServicePtr dataManager, ImagePtr image, Transform3D refMi);
43 cxResource_EXPORT vtkImageDataPtr cropImage(vtkImageDataPtr input, IntBoundingBox3D cropbox);
44 cxResource_EXPORT ImagePtr cropImage(PatientModelServicePtr dataManager, ImagePtr image);
45 cxResource_EXPORT ImagePtr duplicateImage(PatientModelServicePtr dataManager, ImagePtr image);
46 
47 cxResource_EXPORT QImage vtkImageDataToQImage(vtkImageDataPtr imageData, bool overlay = false, QColor overlayColor = QColor(255, 255, 0, 70));
48 cxResource_EXPORT QRgb convertToQColor(unsigned char *colorsPtr, bool overlay, QColor overlayColor);
49 cxResource_EXPORT bool isDark(unsigned char *colorsPtr);
50 cxResource_EXPORT QRgb modifyOverlayColor(unsigned char *colorsPtr, QColor overlayColor);
51 
63 cxResource_EXPORT vtkImageDataPtr createSlice(ImagePtr image, PLANE_TYPE planeType, Vector3D outputSpacing, Eigen::Array3i outputDimensions, ToolPtr sliceTool, PatientModelServicePtr patientModel, bool applyLUT);
64 cxResource_EXPORT vtkImageDataPtr createSlice(ImagePtr image, PLANE_TYPE planeType, Vector3D position, Vector3D target, double offset = 0, bool applyLUT = true);
65 cxResource_EXPORT std::vector<int> getSliceVoxelFrom3Dposition(ImagePtr image, PLANE_TYPE planeType, Vector3D position);
66 cxResource_EXPORT int getSliceNumberFrom3Dposition(ImagePtr image, PLANE_TYPE planeType, Vector3D position);
67 cxResource_EXPORT Vector3D get3DpositionFromSliceVoxel(ImagePtr image, PLANE_TYPE planeType, std::vector<int> voxel, int sliceNumber);
70 cxResource_EXPORT QDateTime extractTimestamp(QString text);
71 
76 template<class T>
77 std::vector<T> sortOnAcquisitionTime(std::map<QString, T> input)
78 {
79  typedef std::multimap<QDateTime,T> SortedMap;
80  SortedMap sorted;
81 
82  for (typename std::map<QString, T>::iterator iter=input.begin(); iter!=input.end(); ++iter)
83  {
84  sorted.insert(std::make_pair(iter->second->getAcquisitionTime(), iter->second));
85  }
86 
87  std::vector<T> retval;
88  for (typename SortedMap::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
89  retval.push_back(iter->second);
90  return retval;
91 }
92 
97 template<class T>
98 std::vector<T> sortOnGroupsAndAcquisitionTime(std::map<QString, T> input)
99 {
100  typedef std::map<QString, T> DataMap;
101  std::map<QDateTime, DataMap> bin;
102 
103  for (typename DataMap::iterator iter=input.begin(); iter!=input.end(); ++iter)
104  {
105  QDateTime binTS = extractTimestamp(iter->second->getUid());
106  bin[binTS].insert(*iter);
107  }
108 
109 
110  std::vector<T> retval;
111 
112  for (typename std::map<QDateTime, DataMap>::iterator iter=bin.begin(); iter!=bin.end(); ++iter)
113  {
114  std::vector<T> localSorted = sortOnAcquisitionTime(iter->second);
115  std::copy(localSorted.begin(), localSorted.end(), back_inserter(retval));
116  }
117 
118  return retval;
119 }
120 
125 } // namespace cx
126 
127 
128 
129 #endif /* CXIMAGEALGORITHMS_H_ */
cx::isDark
bool isDark(unsigned char *colorsPtr)
Definition: cxImageAlgorithms.cpp:207
cx::resampleImage
ImagePtr resampleImage(PatientModelServicePtr dataManager, ImagePtr image, Transform3D qMd)
Definition: cxImageAlgorithms.cpp:44
cx::getSliceNumberFrom3Dposition
int getSliceNumberFrom3Dposition(ImagePtr image, PLANE_TYPE planeType, Vector3D position_r)
Definition: cxImageAlgorithms.cpp:453
cx::cropImage
vtkImageDataPtr cropImage(vtkImageDataPtr input, IntBoundingBox3D cropbox)
Definition: cxImageAlgorithms.cpp:113
cx::duplicateImage
ImagePtr duplicateImage(PatientModelServicePtr dataManager, ImagePtr image)
Definition: cxImageAlgorithms.cpp:104
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxForwardDeclarations.h
vtkImageDataPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
Definition: cxVideoConnectionWidget.h:30
cxBoundingBox3D.h
cx::modifyOverlayColor
QRgb modifyOverlayColor(unsigned char *colorsPtr, QColor overlayColor)
Definition: cxImageAlgorithms.cpp:217
cx::extractTimestamp
QDateTime extractTimestamp(QString text)
Definition: cxImageAlgorithms.cpp:153
cx::get3DpositionFromSliceVoxel
Vector3D get3DpositionFromSliceVoxel(ImagePtr image, PLANE_TYPE planeType, std::vector< int > voxel, int sliceNumber)
Definition: cxImageAlgorithms.cpp:478
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::vtkImageDataToQImage
QImage vtkImageDataToQImage(vtkImageDataPtr imageData, bool overlay, QColor overlayColor)
Definition: cxImageAlgorithms.cpp:166
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cx::sortOnGroupsAndAcquisitionTime
std::vector< T > sortOnGroupsAndAcquisitionTime(std::map< QString, T > input)
Definition: cxImageAlgorithms.h:98
cxTypeConversions.h
cx::createSlice
vtkImageDataPtr createSlice(ImagePtr image, PLANE_TYPE planeType, Vector3D outputSpacing, Eigen::Array3i outputDimensions, ToolPtr sliceTool, PatientModelServicePtr patientModel, bool applyLUT)
createSlice Creates a 2D slice through a 3D volume. Result slice will be oriented for radiological vi...
Definition: cxImageAlgorithms.cpp:226
vtkForwardDeclarations.h
cx::getSliceVoxelFrom3Dposition
std::vector< int > getSliceVoxelFrom3Dposition(ImagePtr image, PLANE_TYPE planeType, Vector3D position_r)
Definition: cxImageAlgorithms.cpp:422
cx::sortOnAcquisitionTime
std::vector< T > sortOnAcquisitionTime(std::map< QString, T > input)
Definition: cxImageAlgorithms.h:77
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::convertToQColor
QRgb convertToQColor(unsigned char *colorsPtr, bool overlay, QColor overlayColor)
Definition: cxImageAlgorithms.cpp:194
cxTransform3D.h
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42