comparison Plugin/InstanceInformationAdapter.cpp @ 0:02f7a0400a91

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Feb 2015 13:45:35 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:02f7a0400a91
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public License
8 * as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20
21 #include "InstanceInformationAdapter.h"
22
23 #include "ViewerToolbox.h"
24 #include "InstanceInformation.h"
25
26 #include <json/value.h>
27
28 static const char* IMAGE_ORIENTATION_PATIENT = "ImageOrientationPatient";
29 static const char* IMAGE_POSITION_PATIENT = "ImagePositionPatient";
30 static const char* INDEX_IN_SERIES = "IndexInSeries";
31
32
33 namespace OrthancPlugins
34 {
35 bool InstanceInformationAdapter::Create(std::string& content,
36 const std::string& instanceId)
37 {
38 std::string message = "Creating spatial information for instance: " + instanceId;
39 OrthancPluginLogInfo(context_, message.c_str());
40
41 std::string uri = "/instances/" + instanceId;
42
43 Json::Value instance, tags;
44 if (!GetJsonFromOrthanc(instance, context_, uri) ||
45 !GetJsonFromOrthanc(tags, context_, uri + "/tags?simplify") ||
46 instance.type() != Json::objectValue ||
47 tags.type() != Json::objectValue)
48 {
49 return false;
50 }
51
52 InstanceInformation info;
53
54 if (tags.isMember(IMAGE_ORIENTATION_PATIENT) &&
55 tags.isMember(IMAGE_POSITION_PATIENT) &&
56 tags[IMAGE_ORIENTATION_PATIENT].type() == Json::stringValue &&
57 tags[IMAGE_POSITION_PATIENT].type() == Json::stringValue)
58 {
59 std::vector<float> cosines, position;
60 if (TokenizeVector(cosines, tags[IMAGE_ORIENTATION_PATIENT].asString(), 6) &&
61 TokenizeVector(position, tags[IMAGE_POSITION_PATIENT].asString(), 3))
62 {
63 std::vector<float> normal(3);
64 normal[0] = cosines[1] * cosines[5] - cosines[2] * cosines[4];
65 normal[1] = cosines[2] * cosines[3] - cosines[0] * cosines[5];
66 normal[2] = cosines[0] * cosines[4] - cosines[1] * cosines[3];
67
68 info.SetPosition(normal, position);
69 }
70 }
71
72 if (instance.isMember(INDEX_IN_SERIES) &&
73 instance[INDEX_IN_SERIES].type() == Json::intValue)
74 {
75 info.SetIndexInSeries(instance[INDEX_IN_SERIES].asInt());
76 }
77
78 info.Serialize(content);
79 return true;
80 }
81 }