annotate OrthancServer/SliceOrdering.cpp @ 1726:9d8bb6bc2890

integration db-changes->mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Oct 2015 11:22:50 +0200
parents b80e76dd1d56
children ec66a16aa398
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "PrecompiledHeadersServer.h"
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "SliceOrdering.h"
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
36 #include "../Core/Logging.h"
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../Core/Toolbox.h"
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
38 #include "ServerEnumerations.h"
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
40 #include <algorithm>
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <boost/lexical_cast.hpp>
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
42 #include <boost/noncopyable.hpp>
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace Orthanc
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 static bool TokenizeVector(std::vector<float>& result,
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 const std::string& value,
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 unsigned int expectedSize)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 std::vector<std::string> tokens;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 Toolbox::TokenizeString(tokens, value, '\\');
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 if (tokens.size() != expectedSize)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 return false;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 result.resize(tokens.size());
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 for (size_t i = 0; i < tokens.size(); i++)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 try
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 result[i] = boost::lexical_cast<float>(tokens[i]);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 catch (boost::bad_lexical_cast&)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 return false;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 return true;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 static bool TokenizeVector(std::vector<float>& result,
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 const DicomMap& map,
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 const DicomTag& tag,
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 unsigned int expectedSize)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 const DicomValue* value = map.TestAndGetValue(tag);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 if (value == NULL ||
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 value->IsNull())
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 return false;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 else
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 return TokenizeVector(result, value->AsString(), expectedSize);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
96 struct SliceOrdering::Instance : public boost::noncopyable
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
98 private:
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 std::string instanceId_;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 bool hasPosition_;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 Vector position_;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 bool hasIndexInSeries_;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 size_t indexInSeries_;
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
104 unsigned int framesCount_;
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
106 public:
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 Instance(ServerIndex& index,
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
108 const std::string& instanceId) :
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
109 instanceId_(instanceId),
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
110 framesCount_(1)
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 DicomMap instance;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 if (!index.GetMainDicomTags(instance, instanceId, ResourceType_Instance, ResourceType_Instance))
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 throw OrthancException(ErrorCode_UnknownResource);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
117
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
118 const DicomValue* frames = instance.TestAndGetValue(DICOM_TAG_NUMBER_OF_FRAMES);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
119 if (frames != NULL &&
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
120 !frames->IsNull())
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
121 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
122 try
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
123 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
124 framesCount_ = boost::lexical_cast<unsigned int>(frames->AsString());
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
125 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
126 catch (boost::bad_lexical_cast&)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
127 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
128 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
129 }
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 std::vector<float> tmp;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 hasPosition_ = TokenizeVector(tmp, instance, DICOM_TAG_IMAGE_POSITION_PATIENT, 3);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 if (hasPosition_)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 position_[0] = tmp[0];
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 position_[1] = tmp[1];
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 position_[2] = tmp[2];
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 std::string s;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 hasIndexInSeries_ = false;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 try
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 if (index.LookupMetadata(s, instanceId, MetadataType_Instance_IndexInSeries))
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 indexInSeries_ = boost::lexical_cast<size_t>(s);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 hasIndexInSeries_ = true;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 catch (boost::bad_lexical_cast&)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
156
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
157 const std::string& GetIdentifier() const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
158 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
159 return instanceId_;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
160 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
161
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
162 bool HasPosition() const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
163 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
164 return hasPosition_;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
165 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
166
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
167 float ComputeRelativePosition(const Vector& normal) const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
168 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
169 assert(HasPosition());
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
170 return (normal[0] * position_[0] +
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
171 normal[1] * position_[1] +
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
172 normal[2] * position_[2]);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
173 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
174
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
175 bool HasIndexInSeries() const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
176 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
177 return hasIndexInSeries_;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
178 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
179
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
180 size_t GetIndexInSeries() const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
181 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
182 assert(HasIndexInSeries());
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
183 return indexInSeries_;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
184 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
185
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
186 unsigned int GetFramesCount() const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
187 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
188 return framesCount_;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
189 }
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 };
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
193 class SliceOrdering::PositionComparator
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
194 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
195 private:
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
196 const Vector& normal_;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
197
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
198 public:
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
199 PositionComparator(const Vector& normal) : normal_(normal)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
200 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
201 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
202
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
203 int operator() (const Instance* a,
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
204 const Instance* b) const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
205 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
206 return a->ComputeRelativePosition(normal_) < b->ComputeRelativePosition(normal_);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
207 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
208 };
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
209
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
210
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
211 bool SliceOrdering::IndexInSeriesComparator(const SliceOrdering::Instance* a,
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
212 const SliceOrdering::Instance* b)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
213 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
214 return a->GetIndexInSeries() < b->GetIndexInSeries();
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
215 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
216
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
217
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 void SliceOrdering::ComputeNormal()
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 DicomMap series;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 if (!index_.GetMainDicomTags(series, seriesId_, ResourceType_Series, ResourceType_Series))
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 throw OrthancException(ErrorCode_UnknownResource);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 std::vector<float> cosines;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 hasNormal_ = TokenizeVector(cosines, series, DICOM_TAG_IMAGE_ORIENTATION_PATIENT, 6);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 if (hasNormal_)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 normal_[0] = cosines[1] * cosines[5] - cosines[2] * cosines[4];
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 normal_[1] = cosines[2] * cosines[3] - cosines[0] * cosines[5];
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 normal_[2] = cosines[0] * cosines[4] - cosines[1] * cosines[3];
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 void SliceOrdering::CreateInstances()
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 std::list<std::string> instancesId;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 index_.GetChildren(instancesId, seriesId_);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 instances_.reserve(instancesId.size());
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 for (std::list<std::string>::const_iterator
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 it = instancesId.begin(); it != instancesId.end(); ++it)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 instances_.push_back(new Instance(index_, *it));
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 bool SliceOrdering::SortUsingPositions()
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
254 if (instances_.size() <= 1)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
255 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
256 // One single instance: It is sorted by default
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
257 return true;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
258 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
259
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 if (!hasNormal_)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 return false;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 for (size_t i = 0; i < instances_.size(); i++)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 assert(instances_[i] != NULL);
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
268 if (!instances_[i]->HasPosition())
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 return false;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
274 PositionComparator comparator(normal_);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
275 std::sort(instances_.begin(), instances_.end(), comparator);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
276
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
277 float a = instances_.front()->ComputeRelativePosition(normal_);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
278 float b = instances_.back()->ComputeRelativePosition(normal_);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
279
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
280 if (std::fabs(b - a) <= 10.0f * std::numeric_limits<float>::epsilon())
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
281 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
282 // Not enough difference between the minimum and maximum
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
283 // positions along the normal of the volume
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
284 return false;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
285 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
286 else
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
287 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
288 // This is a 3D volume
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
289 isVolume_ = true;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
290 return true;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
291 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
292 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
293
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
294
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
295 bool SliceOrdering::SortUsingIndexInSeries()
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
296 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
297 if (instances_.size() <= 1)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
298 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
299 // One single instance: It is sorted by default
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
300 return true;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
301 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
302
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
303 for (size_t i = 0; i < instances_.size(); i++)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
304 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
305 assert(instances_[i] != NULL);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
306 if (!instances_[i]->HasIndexInSeries())
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
307 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
308 return false;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
309 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
310 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
311
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
312 std::sort(instances_.begin(), instances_.end(), IndexInSeriesComparator);
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
314 for (size_t i = 1; i < instances_.size(); i++)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
315 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
316 if (instances_[i - 1]->GetIndexInSeries() == instances_[i]->GetIndexInSeries())
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
317 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
318 // The current "IndexInSeries" occurs 2 times: Not a proper ordering
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
319 return false;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
320 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
321 }
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 return true;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 SliceOrdering::SliceOrdering(ServerIndex& index,
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 const std::string& seriesId) :
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 index_(index),
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
330 seriesId_(seriesId),
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
331 isVolume_(false)
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 ComputeNormal();
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 CreateInstances();
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
335
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
336 if (!SortUsingPositions() &&
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
337 !SortUsingIndexInSeries())
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
338 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
339 LOG(ERROR) << "Unable to order the slices of the series " << seriesId;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
340 throw OrthancException(ErrorCode_CannotOrderSlices);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
341 }
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 SliceOrdering::~SliceOrdering()
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 for (std::vector<Instance*>::iterator
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 it = instances_.begin(); it != instances_.end(); ++it)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 if (*it != NULL)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 delete *it;
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 }
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
356
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
357
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
358 const std::string& SliceOrdering::GetInstanceId(size_t index) const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
359 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
360 if (index >= instances_.size())
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
361 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
362 throw OrthancException(ErrorCode_ParameterOutOfRange);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
363 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
364 else
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
365 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
366 return instances_[index]->GetIdentifier();
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
367 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
368 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
369
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
370
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
371 unsigned int SliceOrdering::GetFramesCount(size_t index) const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
372 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
373 if (index >= instances_.size())
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
374 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
375 throw OrthancException(ErrorCode_ParameterOutOfRange);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
376 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
377 else
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
378 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
379 return instances_[index]->GetFramesCount();
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
380 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
381 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
382
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
383
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
384 void SliceOrdering::Format(Json::Value& result) const
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
385 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
386 result = Json::objectValue;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
387 result["Type"] = (isVolume_ ? "Volume" : "Sequence");
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
388
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
389 Json::Value tmp = Json::arrayValue;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
390 for (size_t i = 0; i < GetInstancesCount(); i++)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
391 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
392 tmp.append(GetBasePath(ResourceType_Instance, GetInstanceId(i)) + "/file");
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
393 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
394
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
395 result["Dicom"] = tmp;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
396
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
397 tmp.clear();
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
398 for (size_t i = 0; i < GetInstancesCount(); i++)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
399 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
400 std::string base = GetBasePath(ResourceType_Instance, GetInstanceId(i));
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
401 for (size_t j = 0; j < GetFramesCount(i); j++)
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
402 {
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
403 tmp.append(base + "/frames/" + boost::lexical_cast<std::string>(j));
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
404 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
405 }
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
406
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
407 result["Slices"] = tmp;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
408 }
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 }