comparison Framework/Inputs/DicomPyramidLevel.cpp @ 55:b6432a00b103

use of simpler data structures
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Nov 2016 14:44:11 +0100
parents 7a88c614be04
children 83cd735c885d
comparison
equal deleted inserted replaced
54:06847108819c 55:b6432a00b103
26 26
27 #include <boost/lexical_cast.hpp> 27 #include <boost/lexical_cast.hpp>
28 28
29 namespace OrthancWSI 29 namespace OrthancWSI
30 { 30 {
31 DicomPyramidLevel::TileContent& DicomPyramidLevel::GetTileContent(unsigned int tileX,
32 unsigned int tileY)
33 {
34 if (tileX >= countTilesX_ ||
35 tileY >= countTilesY_)
36 {
37 LOG(ERROR) << "Tile location (" << tileX << "," << tileY << ") is outside the image";
38 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
39 }
40
41 return tiles_[tileY * countTilesX_ + tileX];
42 }
43
31 void DicomPyramidLevel::RegisterFrame(const DicomPyramidInstance& instance, 44 void DicomPyramidLevel::RegisterFrame(const DicomPyramidInstance& instance,
32 unsigned int frame) 45 unsigned int frame)
33 { 46 {
34 TileLocation location(instance.GetFrameLocationX(frame), 47 unsigned int tileX = instance.GetFrameLocationX(frame);
35 instance.GetFrameLocationY(frame)); 48 unsigned int tileY = instance.GetFrameLocationY(frame);
49 TileContent& tile = GetTileContent(tileX, tileY);
36 50
37 if (tiles_.find(location) != tiles_.end()) 51 if (tile.instance_ != NULL)
38 { 52 {
39 LOG(ERROR) << "Tile with location (" << location.first << "," 53 LOG(ERROR) << "Tile with location (" << tileX << ","
40 << location.second << ") is indexed twice in level of size " 54 << tileY << ") is indexed twice in level of size "
41 << totalWidth_ << "x" << totalHeight_; 55 << totalWidth_ << "x" << totalHeight_;
42 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 56 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
43 } 57 }
44 58
45 tiles_[location] = std::make_pair(&instance, frame); 59 tile.instance_ = &instance;
60 tile.frame_ = frame;
46 } 61 }
47 62
48 63
49 bool DicomPyramidLevel::LookupTile(TileContent& tile, 64 bool DicomPyramidLevel::LookupTile(TileContent& tile,
50 unsigned int tileX, 65 unsigned int tileX,
51 unsigned int tileY) const 66 unsigned int tileY) const
52 { 67 {
53 Tiles::const_iterator found = tiles_.find(std::make_pair(tileX, tileY)); 68 const TileContent& tmp = const_cast<DicomPyramidLevel&>(*this).GetTileContent(tileX, tileY);
54 if (found == tiles_.end()) 69
70 if (tmp.instance_ == NULL)
55 { 71 {
56 return false; 72 return false;
57 } 73 }
58 else 74 else
59 { 75 {
60 tile = found->second; 76 tile = tmp;
61 return true; 77 return true;
62 } 78 }
63 } 79 }
64 80
65 81
72 if (totalWidth_ == 0 || 88 if (totalWidth_ == 0 ||
73 totalHeight_ == 0) 89 totalHeight_ == 0)
74 { 90 {
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 91 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
76 } 92 }
93
94 countTilesX_ = CeilingDivision(totalWidth_, tileWidth_);
95 countTilesY_ = CeilingDivision(totalHeight_, tileHeight_);
96 tiles_.resize(countTilesX_ * countTilesY_);
77 97
78 AddInstance(instance); 98 AddInstance(instance);
79 } 99 }
80 100
81 101
86 instance.GetTileWidth() != tileWidth_ || 106 instance.GetTileWidth() != tileWidth_ ||
87 instance.GetTileHeight() != tileHeight_) 107 instance.GetTileHeight() != tileHeight_)
88 { 108 {
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); 109 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
90 } 110 }
91
92 instances_.push_back(&instance);
93 111
94 for (size_t frame = 0; frame < instance.GetFrameCount(); frame++) 112 for (size_t frame = 0; frame < instance.GetFrameCount(); frame++)
95 { 113 {
96 RegisterFrame(instance, frame); 114 RegisterFrame(instance, frame);
97 } 115 }
106 unsigned int tileY) const 124 unsigned int tileY) const
107 { 125 {
108 TileContent tile; 126 TileContent tile;
109 if (LookupTile(tile, tileX, tileY)) 127 if (LookupTile(tile, tileX, tileY))
110 { 128 {
111 assert(tile.first != NULL); 129 assert(tile.instance_ != NULL);
112 const DicomPyramidInstance& instance = *tile.first; 130 const DicomPyramidInstance& instance = *tile.instance_;
113 131
114 std::string uri = ("/instances/" + instance.GetInstanceId() + 132 std::string uri = ("/instances/" + instance.GetInstanceId() +
115 "/frames/" + boost::lexical_cast<std::string>(tile.second) + "/raw"); 133 "/frames/" + boost::lexical_cast<std::string>(tile.frame_) + "/raw");
116 134
117 orthanc.RestApiGet(raw, uri); 135 orthanc.RestApiGet(raw, uri);
118 136
119 compression = instance.GetImageCompression(); 137 compression = instance.GetImageCompression();
120 format = instance.GetPixelFormat(); 138 format = instance.GetPixelFormat();