Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #ifndef CXIMAGEALGORITHMS_H_
34 #define CXIMAGEALGORITHMS_H_
35 
36 #include "cxResourceExport.h"
37 
38 #include <map>
39 #include <vector>
40 #include <QDateTime>
41 #include <QRegExp>
42 #include "cxForwardDeclarations.h"
43 #include "cxTransform3D.h"
44 #include "cxTypeConversions.h"
45 #include "vtkForwardDeclarations.h"
46 #include "cxBoundingBox3D.h"
47 
48 namespace cx
49 {
50 
62 cxResource_EXPORT ImagePtr resampleImage(PatientModelServicePtr dataManager, ImagePtr image, const Vector3D spacing, QString uid="", QString name="");
63 cxResource_EXPORT ImagePtr resampleImage(PatientModelServicePtr dataManager, ImagePtr image, Transform3D refMi);
64 cxResource_EXPORT vtkImageDataPtr cropImage(vtkImageDataPtr input, IntBoundingBox3D cropbox);
65 cxResource_EXPORT ImagePtr cropImage(PatientModelServicePtr dataManager, ImagePtr image);
66 cxResource_EXPORT ImagePtr duplicateImage(PatientModelServicePtr dataManager, ImagePtr image);
67 
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_ */
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:48
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:63
std::vector< T > sortOnAcquisitionTime(std::map< QString, T > input)
QDateTime extractTimestamp(QString text)
vtkSmartPointer< class vtkImageData > vtkImageDataPtr