Mercurial > hg > orthanc
annotate OrthancCppClient/Instance.cpp @ 797:37adac56017a
ImageAccessor abstraction
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 May 2014 12:47:26 +0200 |
parents | d380222b4c2a |
children | a811bdf8b8eb |
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 | 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 | 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 | 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 | 82 void Instance::DownloadDicom() |
83 { | |
84 if (dicom_.get() == NULL) | |
85 { | |
86 Orthanc::HttpClient client(connection_.GetHttpClient()); | |
87 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/file"); | |
88 | |
89 dicom_.reset(new std::string); | |
90 | |
91 if (!client.Apply(*dicom_)) | |
92 { | |
93 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol); | |
94 } | |
95 } | |
96 } | |
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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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(); |
797
37adac56017a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
728
diff
changeset
|
181 return reader_->GetConstBuffer(); |
479
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(); |
797
37adac56017a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
728
diff
changeset
|
187 return reader_->GetConstRow(y); |
479
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 | 195 void Instance::DiscardDicom() |
196 { | |
197 dicom_.reset(); | |
198 } | |
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 | 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 | 244 |
245 | |
246 const uint64_t Instance::GetDicomSize() | |
247 { | |
248 DownloadDicom(); | |
249 assert(dicom_.get() != NULL); | |
250 return dicom_->size(); | |
251 } | |
252 | |
253 const void* Instance::GetDicom() | |
254 { | |
255 DownloadDicom(); | |
256 assert(dicom_.get() != NULL); | |
257 | |
258 if (dicom_->size() == 0) | |
259 { | |
260 return NULL; | |
261 } | |
262 else | |
263 { | |
264 return &((*dicom_) [0]); | |
265 } | |
266 } | |
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 } |