annotate OrthancCppClient/Instance.cpp @ 793:145604a97914

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 06 May 2014 10:28:04 +0200
parents d380222b4c2a
children 37adac56017a
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
689
2d0a347e8cfc switch to 2014
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 540
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
479
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 "Instance.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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <boost/lexical_cast.hpp>
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace OrthancClient
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 void Instance::DownloadImage()
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 if (reader_.get() == NULL)
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 const char* suffix;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 switch (mode_)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 case Orthanc::ImageExtractionMode_Preview:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 suffix = "preview";
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 case Orthanc::ImageExtractionMode_UInt8:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 suffix = "image-uint8";
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 case Orthanc::ImageExtractionMode_UInt16:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 suffix = "image-uint16";
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 break;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 case Orthanc::ImageExtractionMode_Int16:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 suffix = "image-int16";
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 break;
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 default:
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
65 throw OrthancClientException(Orthanc::ErrorCode_NotImplemented);
479
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 Orthanc::HttpClient client(connection_.GetHttpClient());
496
7f7a2d174acb preparing Laaw packaging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 479
diff changeset
69 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
70 std::string png;
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 if (!client.Apply(png))
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
74 throw OrthancClientException(Orthanc::ErrorCode_NotImplemented);
479
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 reader_.reset(new Orthanc::PngReader);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 reader_->ReadFromMemory(png);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
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
540
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
82 void Instance::DownloadDicom()
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
83 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
84 if (dicom_.get() == NULL)
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
85 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
86 Orthanc::HttpClient client(connection_.GetHttpClient());
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
87 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/file");
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
88
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
89 dicom_.reset(new std::string);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
90
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
91 if (!client.Apply(*dicom_))
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
92 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
93 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
94 }
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
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 Instance::Instance(const OrthancConnection& connection,
496
7f7a2d174acb preparing Laaw packaging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 479
diff changeset
99 const char* id) :
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 connection_(connection),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 id_(id),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 mode_(Orthanc::ImageExtractionMode_Int16)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 Orthanc::HttpClient client(connection_.GetHttpClient());
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
496
7f7a2d174acb preparing Laaw packaging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 479
diff changeset
106 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
107 Json::Value v;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 if (!client.Apply(tags_))
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
110 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
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
500
ec19da4a1fe7 fix api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 496
diff changeset
114 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
115 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 if (tags_.isMember(tag))
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
500
ec19da4a1fe7 fix api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 496
diff changeset
118 return tags_[tag].asCString();
479
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 else
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
122 throw OrthancClientException(Orthanc::ErrorCode_InexistentItem);
479
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 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
500
ec19da4a1fe7 fix api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 496
diff changeset
126 float Instance::GetTagAsFloat(const char* tag) const
479
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 std::string value = GetTagAsString(tag);
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 try
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 return boost::lexical_cast<float>(value);
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 catch (boost::bad_lexical_cast)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
136 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
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
500
ec19da4a1fe7 fix api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 496
diff changeset
140 int Instance::GetTagAsInt(const char* tag) const
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 std::string value = GetTagAsString(tag);
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 try
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 return boost::lexical_cast<int>(value);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 catch (boost::bad_lexical_cast)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
150 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
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 unsigned int Instance::GetWidth()
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 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 return reader_->GetWidth();
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 unsigned int Instance::GetHeight()
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 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 return reader_->GetHeight();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
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 unsigned int Instance::GetPitch()
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 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 return reader_->GetPitch();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
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 Orthanc::PixelFormat Instance::GetPixelFormat()
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 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 return reader_->GetFormat();
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 const void* Instance::GetBuffer()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 return reader_->GetBuffer();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
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 const void* Instance::GetBuffer(unsigned int y)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 DownloadImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 return reader_->GetBuffer(y);
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 void Instance::DiscardImage()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 reader_.reset();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
540
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
195 void Instance::DiscardDicom()
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
196 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
197 dicom_.reset();
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
198 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
199
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 void Instance::SetImageExtractionMode(Orthanc::ImageExtractionMode mode)
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 if (mode_ == mode)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 return;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
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 DiscardImage();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 mode_ = mode;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
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 void Instance::SplitVectorOfFloats(std::vector<float>& target,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 const char* tag)
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 const std::string value = GetTagAsString(tag);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 target.clear();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 try
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 std::string tmp;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 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
224 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 if (value[i] == '\\')
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 target.push_back(boost::lexical_cast<float>(tmp));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 tmp.clear();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 else
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 tmp.push_back(value[i]);
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
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 target.push_back(boost::lexical_cast<float>(tmp));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 catch (boost::bad_lexical_cast)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 // Unable to parse the Image Orientation Patient.
504
50d9660f960c laaw exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 500
diff changeset
241 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
540
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
244
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 const uint64_t Instance::GetDicomSize()
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
247 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
248 DownloadDicom();
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
249 assert(dicom_.get() != NULL);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
250 return dicom_->size();
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
251 }
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 const void* Instance::GetDicom()
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
254 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
255 DownloadDicom();
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
256 assert(dicom_.get() != NULL);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
257
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
258 if (dicom_->size() == 0)
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
259 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
260 return NULL;
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
261 }
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
262 else
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
263 {
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
264 return &((*dicom_) [0]);
eaca3d38b2aa many fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 504
diff changeset
265 }
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
728
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
268
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
269 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
270 {
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
271 Orthanc::HttpClient client(connection_.GetHttpClient());
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
272 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
273
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
274 if (!client.Apply(content_))
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
275 {
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
276 throw OrthancClientException(Orthanc::ErrorCode_UnknownResource);
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
277 }
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 const char* Instance::GetLoadedTagContent() const
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
282 {
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
283 return content_.c_str();
d380222b4c2a Load a raw tag from the DICOM file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
284 }
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }