comparison Framework/dev.h @ 266:c9cf95b49a86 am-2

removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
author am@osimis.io
date Tue, 21 Aug 2018 18:14:22 +0200
parents 40b21c1f8b8d
children 89d02de83c03
comparison
equal deleted inserted replaced
265:30dc6e383b0b 266:c9cf95b49a86
41 namespace OrthancStone 41 namespace OrthancStone
42 { 42 {
43 // TODO: Handle errors while loading 43 // TODO: Handle errors while loading
44 class OrthancVolumeImage : 44 class OrthancVolumeImage :
45 public SlicedVolumeBase, 45 public SlicedVolumeBase,
46 private OrthancSlicesLoader::ISliceLoaderObserver 46 public OrthancStone::IObserver
47 { 47 {
48 private: 48 private:
49 OrthancSlicesLoader loader_; 49 OrthancSlicesLoader loader_;
50 std::auto_ptr<ImageBuffer3D> image_; 50 std::auto_ptr<ImageBuffer3D> image_;
51 std::auto_ptr<DownloadStack> downloadStack_; 51 std::auto_ptr<DownloadStack> downloadStack_;
104 return fabs(a.GetGeometry().ProjectAlongNormal(a.GetGeometry().GetOrigin()) - 104 return fabs(a.GetGeometry().ProjectAlongNormal(a.GetGeometry().GetOrigin()) -
105 a.GetGeometry().ProjectAlongNormal(b.GetGeometry().GetOrigin())); 105 a.GetGeometry().ProjectAlongNormal(b.GetGeometry().GetOrigin()));
106 } 106 }
107 107
108 108
109 virtual void OnSliceGeometryReady(const OrthancSlicesLoader& loader) 109 void OnSliceGeometryReady(const OrthancSlicesLoader& loader)
110 { 110 {
111 if (loader.GetSliceCount() == 0) 111 if (loader.GetSliceCount() == 0)
112 { 112 {
113 LOG(ERROR) << "Empty volume image"; 113 LOG(ERROR) << "Empty volume image";
114 SlicedVolumeBase::NotifyGeometryError(); 114 SlicedVolumeBase::NotifyGeometryError();
149 } 149 }
150 150
151 unsigned int width = loader.GetSlice(0).GetWidth(); 151 unsigned int width = loader.GetSlice(0).GetWidth();
152 unsigned int height = loader.GetSlice(0).GetHeight(); 152 unsigned int height = loader.GetSlice(0).GetHeight();
153 Orthanc::PixelFormat format = loader.GetSlice(0).GetConverter().GetExpectedPixelFormat(); 153 Orthanc::PixelFormat format = loader.GetSlice(0).GetConverter().GetExpectedPixelFormat();
154 LOG(INFO) << "Creating a volume image of size " << width << "x" << height 154 LOG(INFO) << "Creating a volume image of size " << width << "x" << height
155 << "x" << loader.GetSliceCount() << " in " << Orthanc::EnumerationToString(format); 155 << "x" << loader.GetSliceCount() << " in " << Orthanc::EnumerationToString(format);
156 156
157 image_.reset(new ImageBuffer3D(format, width, height, loader.GetSliceCount(), computeRange_)); 157 image_.reset(new ImageBuffer3D(format, width, height, loader.GetSliceCount(), computeRange_));
158 image_->SetAxialGeometry(loader.GetSlice(0).GetGeometry()); 158 image_->SetAxialGeometry(loader.GetSlice(0).GetGeometry());
159 image_->SetVoxelDimensions(loader.GetSlice(0).GetPixelSpacingX(), 159 image_->SetVoxelDimensions(loader.GetSlice(0).GetPixelSpacingX(),
160 loader.GetSlice(0).GetPixelSpacingY(), spacingZ); 160 loader.GetSlice(0).GetPixelSpacingY(), spacingZ);
161 image_->Clear(); 161 image_->Clear();
162 162
163 downloadStack_.reset(new DownloadStack(loader.GetSliceCount())); 163 downloadStack_.reset(new DownloadStack(loader.GetSliceCount()));
164 pendingSlices_ = loader.GetSliceCount(); 164 pendingSlices_ = loader.GetSliceCount();
165 165
166 for (unsigned int i = 0; i < 4; i++) // Limit to 4 simultaneous downloads 166 for (unsigned int i = 0; i < 4; i++) // Limit to 4 simultaneous downloads
167 { 167 {
169 } 169 }
170 170
171 // TODO Check the DicomFrameConverter are constant 171 // TODO Check the DicomFrameConverter are constant
172 172
173 SlicedVolumeBase::NotifyGeometryReady(); 173 SlicedVolumeBase::NotifyGeometryReady();
174 }
175
176 virtual void OnSliceGeometryError(const OrthancSlicesLoader& loader)
177 {
178 LOG(ERROR) << "Unable to download a volume image";
179 SlicedVolumeBase::NotifyGeometryError();
180 } 174 }
181 175
182 virtual void OnSliceImageReady(const OrthancSlicesLoader& loader, 176 virtual void OnSliceImageReady(const OrthancSlicesLoader& loader,
183 unsigned int sliceIndex, 177 unsigned int sliceIndex,
184 const Slice& slice, 178 const Slice& slice,
188 { 182 {
189 ImageBuffer3D::SliceWriter writer(*image_, VolumeProjection_Axial, sliceIndex); 183 ImageBuffer3D::SliceWriter writer(*image_, VolumeProjection_Axial, sliceIndex);
190 Orthanc::ImageProcessing::Copy(writer.GetAccessor(), *image); 184 Orthanc::ImageProcessing::Copy(writer.GetAccessor(), *image);
191 } 185 }
192 186
193 SlicedVolumeBase::NotifySliceChange(sliceIndex, slice); 187 SlicedVolumeBase::NotifySliceChange(sliceIndex, slice);
194 188
195 if (pendingSlices_ == 1) 189 if (pendingSlices_ == 1)
196 { 190 {
197 SlicedVolumeBase::NotifyVolumeReady(); 191 SlicedVolumeBase::NotifyVolumeReady();
198 pendingSlices_ = 0; 192 pendingSlices_ = 0;
203 } 197 }
204 198
205 ScheduleSliceDownload(); 199 ScheduleSliceDownload();
206 } 200 }
207 201
208 virtual void OnSliceImageError(const OrthancSlicesLoader& loader, 202 virtual void HandleMessage(const IObservable& from, const IMessage& message)
209 unsigned int sliceIndex, 203 {
210 const Slice& slice, 204 switch (message.GetType())
211 SliceImageQuality quality) 205 {
212 { 206 case MessageType_SliceGeometryReady:
213 LOG(ERROR) << "Cannot download slice " << sliceIndex << " in a volume image"; 207 OnSliceGeometryReady(dynamic_cast<const OrthancSlicesLoader&>(from));
214 ScheduleSliceDownload(); 208 case MessageType_SliceGeometryError:
209 {
210 LOG(ERROR) << "Unable to download a volume image";
211 SlicedVolumeBase::NotifyGeometryError();
212 }; break;
213 case MessageType_SliceImageReady:
214 {
215 const OrthancSlicesLoader::SliceImageReadyMessage& msg = dynamic_cast<const OrthancSlicesLoader::SliceImageReadyMessage&>(message);
216 OnSliceImageReady(dynamic_cast<const OrthancSlicesLoader&>(from),
217 msg.sliceIndex_,
218 msg.slice_,
219 msg.image_,
220 msg.effectiveQuality_);
221 }; break;
222 case MessageType_SliceImageError:
223 {
224 const OrthancSlicesLoader::SliceImageErrorMessage& msg = dynamic_cast<const OrthancSlicesLoader::SliceImageErrorMessage&>(message);
225 LOG(ERROR) << "Cannot download slice " << msg.sliceIndex_ << " in a volume image";
226 ScheduleSliceDownload();
227 }; break;
228 default:
229 VLOG("unhandled message type" << message.GetType());
230 }
215 } 231 }
216 232
217 public: 233 public:
218 OrthancVolumeImage(MessageBroker& broker, 234 OrthancVolumeImage(MessageBroker& broker,
219 IWebService& orthanc, 235 IWebService& orthanc,
220 bool computeRange) : 236 bool computeRange) :
221 OrthancSlicesLoader::ISliceLoaderObserver(broker), 237 OrthancStone::IObserver(broker),
222 loader_(broker, *this, orthanc), 238 loader_(broker, orthanc),
223 computeRange_(computeRange), 239 computeRange_(computeRange),
224 pendingSlices_(0) 240 pendingSlices_(0)
225 { 241 {
242 loader_.RegisterObserver(*this);
226 } 243 }
227 244
228 void ScheduleLoadSeries(const std::string& seriesId) 245 void ScheduleLoadSeries(const std::string& seriesId)
229 { 246 {
230 loader_.ScheduleLoadSeries(seriesId); 247 loader_.ScheduleLoadSeries(seriesId);