CustusX  18.04-rc6
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 
49 cxResource_EXPORT QDateTime extractTimestamp(QString text);
50 
55 template<class T>
56 std::vector<T> sortOnAcquisitionTime(std::map<QString, T> input)
57 {
58  typedef std::multimap<QDateTime,T> SortedMap;
59  SortedMap sorted;
60 
61  for (typename std::map<QString, T>::iterator iter=input.begin(); iter!=input.end(); ++iter)
62  {
63  sorted.insert(std::make_pair(iter->second->getAcquisitionTime(), iter->second));
64  }
65 
66  std::vector<T> retval;
67  for (typename SortedMap::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
68  retval.push_back(iter->second);
69  return retval;
70 }
71 
76 template<class T>
77 std::vector<T> sortOnGroupsAndAcquisitionTime(std::map<QString, T> input)
78 {
79  typedef std::map<QString, T> DataMap;
80  std::map<QDateTime, DataMap> bin;
81 
82  for (typename DataMap::iterator iter=input.begin(); iter!=input.end(); ++iter)
83  {
84  QDateTime binTS = extractTimestamp(iter->second->getUid());
85  bin[binTS].insert(*iter);
86  }
87 
88 
89  std::vector<T> retval;
90 
91  for (typename std::map<QDateTime, DataMap>::iterator iter=bin.begin(); iter!=bin.end(); ++iter)
92  {
93  std::vector<T> localSorted = sortOnAcquisitionTime(iter->second);
94  std::copy(localSorted.begin(), localSorted.end(), back_inserter(retval));
95  }
96 
97  return retval;
98 }
99 
104 } // namespace cx
105 
106 
107 
108 #endif /* CXIMAGEALGORITHMS_H_ */
ImagePtr resampleImage(PatientModelServicePtr dataManager, ImagePtr image, Transform3D qMd)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkImageDataPtr cropImage(vtkImageDataPtr input, IntBoundingBox3D cropbox)
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
ImagePtr duplicateImage(PatientModelServicePtr dataManager, ImagePtr image)
std::vector< T > sortOnGroupsAndAcquisitionTime(std::map< QString, T > input)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
std::vector< T > sortOnAcquisitionTime(std::map< QString, T > input)
QDateTime extractTimestamp(QString text)
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
Namespace for all CustusX production code.