annotate OrthancCppClient/Series.cpp @ 509:e7841864c97c

StableResourcesMonitor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Aug 2013 14:23:54 +0200
parents f3d4193c571a
children 7f7a2d174acb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
0cd977e94479 initial commit of the c++ client
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "Series.h"
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "OrthancConnection.h"
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../Core/OrthancException.h"
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <set>
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include <boost/lexical_cast.hpp>
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 namespace OrthancClient
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 namespace
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 class SliceLocator
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 private:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 float normal_[3];
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 public:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 SliceLocator(Instance& someSlice)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 /**
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 * Compute the slice normal from Image Orientation Patient.
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 * http://nipy.sourceforge.net/nibabel/dicom/dicom_orientation.html#dicom-z-from-slice
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 * http://www.itk.org/pipermail/insight-users/2003-September/004762.html
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 **/
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 std::vector<float> cosines;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 someSlice.SplitVectorOfFloats(cosines, "ImageOrientationPatient");
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 if (cosines.size() != 6)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 normal_[0] = cosines[1] * cosines[5] - cosines[2] * cosines[4];
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 normal_[1] = cosines[2] * cosines[3] - cosines[0] * cosines[5];
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 normal_[2] = cosines[0] * cosines[4] - cosines[1] * cosines[3];
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 /**
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 * Compute the distance of some slice along the slice normal.
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 **/
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 float ComputeSliceLocation(Instance& instance) const
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 std::vector<float> ipp;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 instance.SplitVectorOfFloats(ipp, "ImagePositionPatient");
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 if (ipp.size() != 3)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 float dist = 0;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 for (int i = 0; i < 3; i++)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 dist += normal_[i] * ipp[i];
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 return dist;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 };
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 class ImageDownloadCommand : public Orthanc::ICommand
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 private:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 Orthanc::PixelFormat format_;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 Orthanc::ImageExtractionMode mode_;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 Instance& instance_;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 void* target_;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 size_t lineStride_;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 public:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 ImageDownloadCommand(Instance& instance,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 Orthanc::PixelFormat format,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 Orthanc::ImageExtractionMode mode,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 void* target,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 size_t lineStride) :
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 format_(format),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 mode_(mode),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 instance_(instance),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 target_(target),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 lineStride_(lineStride)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 instance_.SetImageExtractionMode(mode);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 virtual bool Execute()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 using namespace Orthanc;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 unsigned int width = instance_.GetHeight();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 for (unsigned int y = 0; y < instance_.GetHeight(); y++)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 uint8_t* p = reinterpret_cast<uint8_t*>(target_) + y * lineStride_;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 if (instance_.GetPixelFormat() == format_)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 memcpy(p, instance_.GetBuffer(y), 2 * instance_.GetWidth());
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 else if (instance_.GetPixelFormat() == PixelFormat_Grayscale8 &&
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 format_ == PixelFormat_RGB24)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 const uint8_t* s = reinterpret_cast<const uint8_t*>(instance_.GetBuffer(y));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 for (unsigned int x = 0; x < width; x++, s++, p += 3)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 p[0] = *s;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 p[1] = *s;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 p[2] = *s;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 else
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 throw OrthancException(ErrorCode_NotImplemented);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 // Do not keep the image in memory, as we are loading 3D images
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 instance_.DiscardImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 return true;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 };
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 void Series::Check3DImage()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 if (!Is3DImage())
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 bool Series::Is3DImageInternal()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 try
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 if (GetInstanceCount() == 0)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 return true;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 for (unsigned int i = 0; i < GetInstanceCount(); i++)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 if (GetInstance(0).GetTagAsString("Columns") != GetInstance(i).GetTagAsString("Columns") ||
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 GetInstance(0).GetTagAsString("Rows") != GetInstance(i).GetTagAsString("Rows") ||
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 GetInstance(0).GetTagAsString("ImageOrientationPatient") != GetInstance(i).GetTagAsString("ImageOrientationPatient") ||
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 GetInstance(0).GetTagAsString("SliceThickness") != GetInstance(i).GetTagAsString("SliceThickness") ||
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 GetInstance(0).GetTagAsString("PixelSpacing") != GetInstance(i).GetTagAsString("PixelSpacing"))
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return false;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 SliceLocator locator(GetInstance(0));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 std::set<float> l;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 for (unsigned int i = 0; i < GetInstanceCount(); i++)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 l.insert(locator.ComputeSliceLocation(GetInstance(i)));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 return l.size() == GetInstanceCount();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 catch (Orthanc::OrthancException)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 return false;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 void Series::ReadSeries()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 Orthanc::HttpClient client(connection_.GetHttpClient());
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 client.SetUrl(connection_.GetOrthancUrl() + "/series/" + id_);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 Json::Value v;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 if (!client.Apply(series_))
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 Orthanc::IDynamicObject* Series::GetFillerItem(size_t index)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
492
f3d4193c571a switch to jsoncpp-0.6.0-rc2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 479
diff changeset
218 Json::Value::ArrayIndex tmp = static_cast<Json::Value::ArrayIndex>(index);
f3d4193c571a switch to jsoncpp-0.6.0-rc2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 479
diff changeset
219 return new Instance(connection_, series_["Instances"][tmp].asString());
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 Series::Series(const OrthancConnection& connection,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 const std::string& id) :
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 connection_(connection),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 id_(id),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 instances_(*this)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 ReadSeries();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 status_ = Status3DImage_NotTested;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 instances_.SetThreadCount(connection.GetThreadCount());
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 bool Series::Is3DImage()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 if (status_ == Status3DImage_NotTested)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 status_ = Is3DImageInternal() ? Status3DImage_True : Status3DImage_False;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 return status_ == Status3DImage_True;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 unsigned int Series::GetInstanceCount()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 return instances_.GetSize();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 Instance& Series::GetInstance(unsigned int index)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 return dynamic_cast<Instance&>(instances_.GetItem(index));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 std::string Series::GetUrl() const
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 return connection_.GetOrthancUrl() + "/series/" + id_;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 unsigned int Series::GetWidth()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 Check3DImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 if (GetInstanceCount() == 0)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 return 0;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 else
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 return GetInstance(0).GetTagAsInt("Columns");
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 unsigned int Series::GetHeight()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 Check3DImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 if (GetInstanceCount() == 0)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 return 0;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 else
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 return GetInstance(0).GetTagAsInt("Rows");
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 void Series::GetVoxelSize(float& sizeX, float& sizeY, float& sizeZ)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 Check3DImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 if (GetInstanceCount() == 0)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 sizeX = 0;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 sizeY = 0;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 sizeZ = 0;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 else
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 try
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 std::string s = GetInstance(0).GetTagAsString("PixelSpacing");
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 size_t pos = s.find('\\');
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 assert(pos != std::string::npos);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 std::string sy = s.substr(0, pos);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 std::string sx = s.substr(pos + 1);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 sizeX = boost::lexical_cast<float>(sx);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 sizeY = boost::lexical_cast<float>(sy);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 sizeZ = GetInstance(0).GetTagAsFloat("SliceThickness");
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 catch (boost::bad_lexical_cast)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 std::string Series::GetMainDicomTag(const char* tag, const char* defaultValue) const
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 if (series_["MainDicomTags"].isMember(tag))
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 return series_["MainDicomTags"][tag].asString();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 else
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 return defaultValue;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 void Series::Load3DImage(void* target,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 Orthanc::PixelFormat format,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 size_t lineStride,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 size_t stackStride,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 Orthanc::ThreadedCommandProcessor::IListener* listener)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 using namespace Orthanc;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 // Choose the extraction mode, depending on the format of the
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 // target image.
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 uint8_t bytesPerPixel;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 ImageExtractionMode mode;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 switch (format)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 case PixelFormat_RGB24:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 bytesPerPixel = 3;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 mode = ImageExtractionMode_Preview;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 case PixelFormat_Grayscale8:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 bytesPerPixel = 1;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 mode = ImageExtractionMode_UInt8; // Preview ???
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 case PixelFormat_Grayscale16:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 bytesPerPixel = 2;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 mode = ImageExtractionMode_UInt16;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 case PixelFormat_SignedGrayscale16:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 bytesPerPixel = 2;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 mode = ImageExtractionMode_UInt16;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 format = PixelFormat_Grayscale16;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 default:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 throw OrthancException(ErrorCode_NotImplemented);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 // Check that the target image is properly sized
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 unsigned int sx = GetWidth();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 unsigned int sy = GetHeight();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 if (lineStride < sx * bytesPerPixel ||
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 stackStride < sx * sy * bytesPerPixel)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 throw OrthancException(ErrorCode_BadRequest);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 if (sx == 0 || sy == 0 || GetInstanceCount() == 0)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 // Empty image, nothing to do
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 if (listener)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 listener->SignalSuccess(0);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 return;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 /**
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 * Order the stacks according to their distance along the slice
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 * normal (using the "Image Position Patient" tag). This works
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 * even if the "SliceLocation" tag is absent.
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 **/
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 SliceLocator locator(GetInstance(0));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 typedef std::map<float, Instance*> Instances;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 Instances instances;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 for (unsigned int i = 0; i < GetInstanceCount(); i++)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 float dist = locator.ComputeSliceLocation(GetInstance(i));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 instances[dist] = &GetInstance(i);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 if (instances.size() != GetInstanceCount())
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 // Several instances have the same Z coordinate
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 throw OrthancException(ErrorCode_NotImplemented);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 // Submit the download of each stack as a set of commands
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 ThreadedCommandProcessor processor(connection_.GetThreadCount());
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 if (listener != NULL)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 processor.SetListener(*listener);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 uint8_t* stackTarget = reinterpret_cast<uint8_t*>(target);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 for (Instances::iterator it = instances.begin(); it != instances.end(); it++)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 processor.Post(new ImageDownloadCommand(*it->second, format, mode, stackTarget, lineStride));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 stackTarget += stackStride;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 // Wait for all the stacks to be downloaded
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 if (!processor.Join())
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 throw OrthancException(ErrorCode_NetworkProtocol);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 }