comparison Framework/Inputs/DicomPyramidLevel.cpp @ 0:4a7a53257c7d

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 22 Oct 2016 21:48:33 +0200
parents
children 7a88c614be04
comparison
equal deleted inserted replaced
-1:000000000000 0:4a7a53257c7d
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 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 "DicomPyramidLevel.h"
22
23 #include "../Orthanc/Core/Logging.h"
24 #include "../Orthanc/Core/OrthancException.h"
25
26 #include <boost/lexical_cast.hpp>
27
28 namespace OrthancWSI
29 {
30 void DicomPyramidLevel::RegisterFrame(const DicomPyramidInstance& instance,
31 unsigned int frame)
32 {
33 TileLocation location(instance.GetFrameLocationX(frame),
34 instance.GetFrameLocationY(frame));
35
36 if (tiles_.find(location) != tiles_.end())
37 {
38 LOG(ERROR) << "Tile with location (" << location.first << ","
39 << location.second << ") is indexed twice in level of size "
40 << totalWidth_ << "x" << totalHeight_;
41 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
42 }
43
44 tiles_[location] = std::make_pair(&instance, frame);
45 }
46
47
48 bool DicomPyramidLevel::LookupTile(TileContent& tile,
49 unsigned int tileX,
50 unsigned int tileY) const
51 {
52 Tiles::const_iterator found = tiles_.find(std::make_pair(tileX, tileY));
53 if (found == tiles_.end())
54 {
55 return false;
56 }
57 else
58 {
59 tile = found->second;
60 return true;
61 }
62 }
63
64
65 DicomPyramidLevel::DicomPyramidLevel(const DicomPyramidInstance& instance) :
66 totalWidth_(instance.GetTotalWidth()),
67 totalHeight_(instance.GetTotalHeight()),
68 tileWidth_(instance.GetTileWidth()),
69 tileHeight_(instance.GetTileHeight())
70 {
71 if (totalWidth_ == 0 ||
72 totalHeight_ == 0)
73 {
74 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
75 }
76
77 AddInstance(instance);
78 }
79
80
81 void DicomPyramidLevel::AddInstance(const DicomPyramidInstance& instance)
82 {
83 if (instance.GetTotalWidth() != totalWidth_ ||
84 instance.GetTotalHeight() != totalHeight_ ||
85 instance.GetTileWidth() != tileWidth_ ||
86 instance.GetTileHeight() != tileHeight_)
87 {
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
89 }
90
91 instances_.push_back(&instance);
92
93 for (size_t frame = 0; frame < instance.GetFrameCount(); frame++)
94 {
95 RegisterFrame(instance, frame);
96 }
97 }
98
99
100 bool DicomPyramidLevel::DownloadRawTile(ImageCompression& compression /* out */,
101 Orthanc::PixelFormat& format /* out */,
102 std::string& raw /* out */,
103 IOrthancConnection& orthanc,
104 unsigned int tileX,
105 unsigned int tileY) const
106 {
107 TileContent tile;
108 if (LookupTile(tile, tileX, tileY))
109 {
110 assert(tile.first != NULL);
111 const DicomPyramidInstance& instance = *tile.first;
112
113 std::string uri = ("/instances/" + instance.GetInstanceId() +
114 "/frames/" + boost::lexical_cast<std::string>(tile.second) + "/raw");
115
116 orthanc.RestApiGet(raw, uri);
117
118 compression = instance.GetImageCompression();
119 format = instance.GetPixelFormat();
120
121 return true;
122 }
123 else
124 {
125 return false;
126 }
127 }
128 }