annotate OrthancCppClient/Instance.cpp @ 1331:77e129ba64e4

Prevent freeze on C-FIND if no DICOM tag is to be returned
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 12 Mar 2015 10:47:32 +0100
parents 6e7e5ed91c2d
children
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
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
4 * Department, University Hospital of Liege, Belgium
479
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
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 797
diff changeset
33 #include "../Core/PrecompiledHeaders.h"
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "Instance.h"
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "OrthancConnection.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 <boost/lexical_cast.hpp>
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace OrthancClient
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 void Instance::DownloadImage()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 if (reader_.get() == NULL)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 const char* suffix;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 switch (mode_)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 case Orthanc::ImageExtractionMode_Preview:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 suffix = "preview";
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 break;
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 case Orthanc::ImageExtractionMode_UInt8:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 suffix = "image-uint8";
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 case Orthanc::ImageExtractionMode_UInt16:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 suffix = "image-uint16";
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 case Orthanc::ImageExtractionMode_Int16:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 suffix = "image-int16";
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 default:
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
66 throw OrthancClientException(Orthanc::ErrorCode_NotImplemented);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 Orthanc::HttpClient client(connection_.GetHttpClient());
496
7f7a2d174acb preparing Laaw packaging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 479
diff changeset
70 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/" + suffix);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 std::string png;
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 if (!client.Apply(png))
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
75 throw OrthancClientException(Orthanc::ErrorCode_NotImplemented);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
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 reader_.reset(new Orthanc::PngReader);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 reader_->ReadFromMemory(png);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
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
540
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
83 void Instance::DownloadDicom()
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
84 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
85 if (dicom_.get() == NULL)
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
86 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
87 Orthanc::HttpClient client(connection_.GetHttpClient());
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
88 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/file");
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
89
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
90 dicom_.reset(new std::string);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
91
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
92 if (!client.Apply(*dicom_))
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
93 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
94 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
95 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
96 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
97 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
98
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 Instance::Instance(const OrthancConnection& connection,
496
7f7a2d174acb preparing Laaw packaging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 479
diff changeset
100 const char* id) :
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 connection_(connection),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 id_(id),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 mode_(Orthanc::ImageExtractionMode_Int16)
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 Orthanc::HttpClient client(connection_.GetHttpClient());
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
496
7f7a2d174acb preparing Laaw packaging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 479
diff changeset
107 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/simplified-tags");
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 Json::Value v;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 if (!client.Apply(tags_))
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
111 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
500
ec19da4a1fe7 fix api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 496
diff changeset
115 const char* Instance::GetTagAsString(const char* tag) const
479
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 if (tags_.isMember(tag))
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
500
ec19da4a1fe7 fix api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 496
diff changeset
119 return tags_[tag].asCString();
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 else
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
123 throw OrthancClientException(Orthanc::ErrorCode_InexistentItem);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }
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
500
ec19da4a1fe7 fix api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 496
diff changeset
127 float Instance::GetTagAsFloat(const char* tag) const
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 std::string value = GetTagAsString(tag);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 try
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 return boost::lexical_cast<float>(value);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 catch (boost::bad_lexical_cast)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
137 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
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
500
ec19da4a1fe7 fix api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 496
diff changeset
141 int Instance::GetTagAsInt(const char* tag) const
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 std::string value = GetTagAsString(tag);
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 try
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 return boost::lexical_cast<int>(value);
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 catch (boost::bad_lexical_cast)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
151 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 unsigned int Instance::GetWidth()
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 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 return reader_->GetWidth();
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 unsigned int Instance::GetHeight()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 return reader_->GetHeight();
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 unsigned int Instance::GetPitch()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 return reader_->GetPitch();
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 Orthanc::PixelFormat Instance::GetPixelFormat()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 return reader_->GetFormat();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
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 const void* Instance::GetBuffer()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 DownloadImage();
797
37adac56017a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 728
diff changeset
182 return reader_->GetConstBuffer();
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
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 const void* Instance::GetBuffer(unsigned int y)
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 DownloadImage();
797
37adac56017a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 728
diff changeset
188 return reader_->GetConstRow(y);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 void Instance::DiscardImage()
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 reader_.reset();
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
540
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
196 void Instance::DiscardDicom()
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
197 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
198 dicom_.reset();
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
199 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
200
479
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 void Instance::SetImageExtractionMode(Orthanc::ImageExtractionMode mode)
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 if (mode_ == mode)
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 return;
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 DiscardImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 mode_ = mode;
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
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 void Instance::SplitVectorOfFloats(std::vector<float>& target,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 const char* tag)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 const std::string value = GetTagAsString(tag);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 target.clear();
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 try
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 std::string tmp;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 for (size_t i = 0; i < value.size(); i++)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 if (value[i] == '\\')
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 target.push_back(boost::lexical_cast<float>(tmp));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 tmp.clear();
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 else
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 tmp.push_back(value[i]);
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 }
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 target.push_back(boost::lexical_cast<float>(tmp));
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 catch (boost::bad_lexical_cast)
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 // Unable to parse the Image Orientation Patient.
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
242 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
479
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 }
540
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
245
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
246
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
247 const uint64_t Instance::GetDicomSize()
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
248 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
249 DownloadDicom();
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
250 assert(dicom_.get() != NULL);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
251 return dicom_->size();
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
252 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
253
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
254 const void* Instance::GetDicom()
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
255 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
256 DownloadDicom();
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
257 assert(dicom_.get() != NULL);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
258
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
259 if (dicom_->size() == 0)
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
260 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
261 return NULL;
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
262 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
263 else
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
264 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
265 return &((*dicom_) [0]);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
266 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
267 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
268
728
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
269
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
270 void Instance::LoadTagContent(const char* path)
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
271 {
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
272 Orthanc::HttpClient client(connection_.GetHttpClient());
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
273 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/content/" + path);
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
274
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
275 if (!client.Apply(content_))
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
276 {
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
277 throw OrthancClientException(Orthanc::ErrorCode_UnknownResource);
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
278 }
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
279 }
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
280
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
281
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
282 const char* Instance::GetLoadedTagContent() const
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
283 {
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
284 return content_.c_str();
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
285 }
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 }