comparison UnitTestsSources/UnitTestsMain.cpp @ 88:90bf4116a23c wasm

ISlicedVolume
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 May 2017 16:11:52 +0200
parents 4a541cd4fa83
children f244018a4e4b
comparison
equal deleted inserted replaced
87:4a541cd4fa83 88:90bf4116a23c
28 #include "../Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.h" 28 #include "../Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.h"
29 #include "../Resources/Orthanc/Core/OrthancException.h" 29 #include "../Resources/Orthanc/Core/OrthancException.h"
30 30
31 #include "../Framework/Toolbox/IVolumeSlicesObserver.h" 31 #include "../Framework/Toolbox/IVolumeSlicesObserver.h"
32 #include "../Framework/Volumes/ImageBuffer3D.h" 32 #include "../Framework/Volumes/ImageBuffer3D.h"
33 #include "../Framework/Volumes/SlicedVolumeBase.h"
33 #include "../Framework/Toolbox/DownloadStack.h" 34 #include "../Framework/Toolbox/DownloadStack.h"
34 #include "../Resources/Orthanc/Core/Images/ImageProcessing.h" 35 #include "../Resources/Orthanc/Core/Images/ImageProcessing.h"
35 36
36 #include <boost/lexical_cast.hpp> 37 #include <boost/lexical_cast.hpp>
37 #include <boost/date_time/posix_time/posix_time.hpp> 38 #include <boost/date_time/posix_time/posix_time.hpp>
73 printf("ERROR 2\n"); 74 printf("ERROR 2\n");
74 } 75 }
75 }; 76 };
76 77
77 78
78 class OrthancVolumeImageLoader : private OrthancSlicesLoader::ICallback 79 class OrthancVolumeImageLoader :
80 public SlicedVolumeBase,
81 private OrthancSlicesLoader::ICallback
79 { 82 {
80 private: 83 private:
81 OrthancSlicesLoader loader_; 84 OrthancSlicesLoader loader_;
82 IVolumeSlicesObserver* observer_; 85 IVolumeSlicesObserver* observer_;
83 std::auto_ptr<ImageBuffer3D> image_; 86 std::auto_ptr<ImageBuffer3D> image_;
141 virtual void NotifyGeometryReady(const OrthancSlicesLoader& loader) 144 virtual void NotifyGeometryReady(const OrthancSlicesLoader& loader)
142 { 145 {
143 if (loader.GetSliceCount() == 0) 146 if (loader.GetSliceCount() == 0)
144 { 147 {
145 LOG(ERROR) << "Empty volume image"; 148 LOG(ERROR) << "Empty volume image";
149 SlicedVolumeBase::NotifyGeometryError();
146 return; 150 return;
147 } 151 }
148 152
149 for (size_t i = 1; i < loader.GetSliceCount(); i++) 153 for (size_t i = 1; i < loader.GetSliceCount(); i++)
150 { 154 {
151 if (!IsCompatible(loader.GetSlice(0), loader.GetSlice(i))) 155 if (!IsCompatible(loader.GetSlice(0), loader.GetSlice(i)))
152 { 156 {
157 SlicedVolumeBase::NotifyGeometryError();
153 return; 158 return;
154 } 159 }
155 } 160 }
156 161
157 double spacingZ; 162 double spacingZ;
170 for (size_t i = 1; i < loader.GetSliceCount(); i++) 175 for (size_t i = 1; i < loader.GetSliceCount(); i++)
171 { 176 {
172 if (!GeometryToolbox::IsNear(spacingZ, GetDistance(loader.GetSlice(i - 1), loader.GetSlice(i)))) 177 if (!GeometryToolbox::IsNear(spacingZ, GetDistance(loader.GetSlice(i - 1), loader.GetSlice(i))))
173 { 178 {
174 LOG(ERROR) << "The distance between successive slices is not constant in a volume image"; 179 LOG(ERROR) << "The distance between successive slices is not constant in a volume image";
180 SlicedVolumeBase::NotifyGeometryError();
175 return; 181 return;
176 } 182 }
177 } 183 }
178 184
179 unsigned int width = loader.GetSlice(0).GetWidth(); 185 unsigned int width = loader.GetSlice(0).GetWidth();
188 loader.GetSlice(0).GetPixelSpacingY(), spacingZ); 194 loader.GetSlice(0).GetPixelSpacingY(), spacingZ);
189 image_->Clear(); 195 image_->Clear();
190 196
191 downloadStack_.reset(new DownloadStack(loader.GetSliceCount())); 197 downloadStack_.reset(new DownloadStack(loader.GetSliceCount()));
192 198
199 SlicedVolumeBase::NotifyGeometryReady();
200
193 for (unsigned int i = 0; i < 4; i++) // Limit to 4 simultaneous downloads 201 for (unsigned int i = 0; i < 4; i++) // Limit to 4 simultaneous downloads
194 { 202 {
195 ScheduleSliceDownload(); 203 ScheduleSliceDownload();
196 } 204 }
197 } 205 }
207 Orthanc::ImageAccessor* image) 215 Orthanc::ImageAccessor* image)
208 { 216 {
209 std::auto_ptr<Orthanc::ImageAccessor> protection(image); 217 std::auto_ptr<Orthanc::ImageAccessor> protection(image);
210 218
211 { 219 {
212 ImageBuffer3D::SliceWriter writer(*image_, VolumeProjection_Axial, 0); 220 ImageBuffer3D::SliceWriter writer(*image_, VolumeProjection_Axial, sliceIndex);
213 Orthanc::ImageProcessing::Copy(writer.GetAccessor(), *protection); 221 Orthanc::ImageProcessing::Copy(writer.GetAccessor(), *protection);
214 } 222 }
223
224 SlicedVolumeBase::NotifySliceChange(sliceIndex, slice);
215 225
216 ScheduleSliceDownload(); 226 ScheduleSliceDownload();
217 } 227 }
218 228
219 virtual void NotifySliceImageError(const OrthancSlicesLoader& loader, 229 virtual void NotifySliceImageError(const OrthancSlicesLoader& loader,
240 unsigned int frame) 250 unsigned int frame)
241 { 251 {
242 loader_.ScheduleLoadInstance(instanceId, frame); 252 loader_.ScheduleLoadInstance(instanceId, frame);
243 } 253 }
244 254
255 virtual size_t GetSliceCount() const
256 {
257 return loader_.GetSliceCount();
258 }
259
260 virtual const Slice& GetSlice(size_t index) const
261 {
262 return loader_.GetSlice(index);
263 }
264
245 void SetObserver(IVolumeSlicesObserver& observer) 265 void SetObserver(IVolumeSlicesObserver& observer)
246 { 266 {
247 if (observer_ == NULL) 267 if (observer_ == NULL)
248 { 268 {
249 observer_ = &observer; 269 observer_ = &observer;