Mercurial > hg > orthanc-stone
comparison Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp @ 2093:c336e07b675c dicom-sr
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 08 Nov 2023 12:37:42 +0100 |
parents | b7d4d288459a |
children | 79e984a89a38 |
comparison
equal
deleted
inserted
replaced
2092:b7d4d288459a | 2093:c336e07b675c |
---|---|
216 | 216 |
217 virtual const OrthancStone::DicomInstanceParameters& GetInstanceOfFrame(size_t frameIndex) const = 0; | 217 virtual const OrthancStone::DicomInstanceParameters& GetInstanceOfFrame(size_t frameIndex) const = 0; |
218 | 218 |
219 virtual unsigned int GetFrameNumberInInstance(size_t frameIndex) const = 0; | 219 virtual unsigned int GetFrameNumberInInstance(size_t frameIndex) const = 0; |
220 | 220 |
221 // TODO - Could be removed | |
222 virtual OrthancStone::CoordinateSystem3D GetFrameGeometry(size_t frameIndex) const = 0; | |
223 | |
224 virtual bool LookupFrame(size_t& frameIndex, | 221 virtual bool LookupFrame(size_t& frameIndex, |
225 const std::string& sopInstanceUid, | 222 const std::string& sopInstanceUid, |
226 unsigned int frameNumber) const = 0; | 223 unsigned int frameNumber) const = 0; |
227 | 224 |
228 virtual bool FindClosestFrame(size_t& frameIndex, | 225 virtual bool FindClosestFrame(size_t& frameIndex, |
229 const OrthancStone::Vector& point, | 226 const OrthancStone::Vector& point, |
230 double maximumDistance) const = 0; | 227 double maximumDistance) const = 0; |
228 | |
229 static OrthancStone::CoordinateSystem3D GetFrameGeometry(const IFramesCollection& frames, | |
230 size_t frameIndex) | |
231 { | |
232 return frames.GetInstanceOfFrame(frameIndex).GetFrameGeometry(frames.GetFrameNumberInInstance(frameIndex)); | |
233 } | |
231 }; | 234 }; |
232 | 235 |
233 | 236 |
234 class SortedFramesCollection : public IFramesCollection | 237 class SortedFramesCollection : public IFramesCollection |
235 { | 238 { |
260 } | 263 } |
261 | 264 |
262 virtual unsigned int GetFrameNumberInInstance(size_t frameIndex) const ORTHANC_OVERRIDE | 265 virtual unsigned int GetFrameNumberInInstance(size_t frameIndex) const ORTHANC_OVERRIDE |
263 { | 266 { |
264 return frames_->GetFrameNumberInInstance(frameIndex); | 267 return frames_->GetFrameNumberInInstance(frameIndex); |
265 } | |
266 | |
267 virtual OrthancStone::CoordinateSystem3D GetFrameGeometry(size_t frameIndex) const ORTHANC_OVERRIDE | |
268 { | |
269 return frames_->GetFrameGeometry(frameIndex); | |
270 } | 268 } |
271 | 269 |
272 virtual bool LookupFrame(size_t& frameIndex, | 270 virtual bool LookupFrame(size_t& frameIndex, |
273 const std::string& sopInstanceUid, | 271 const std::string& sopInstanceUid, |
274 unsigned int frameNumber) const ORTHANC_OVERRIDE | 272 unsigned int frameNumber) const ORTHANC_OVERRIDE |
398 virtual unsigned int GetFrameNumberInInstance(size_t frameIndex) const ORTHANC_OVERRIDE | 396 virtual unsigned int GetFrameNumberInInstance(size_t frameIndex) const ORTHANC_OVERRIDE |
399 { | 397 { |
400 return GetFrame(frameIndex).GetInformation().GetFrameNumber(); | 398 return GetFrame(frameIndex).GetInformation().GetFrameNumber(); |
401 } | 399 } |
402 | 400 |
403 virtual OrthancStone::CoordinateSystem3D GetFrameGeometry(size_t frameIndex) const ORTHANC_OVERRIDE | |
404 { | |
405 return GetFrame(frameIndex).GetParameters().GetFrameGeometry(GetFrameNumberInInstance(frameIndex)); | |
406 } | |
407 | |
408 virtual bool LookupFrame(size_t& frameIndex, | 401 virtual bool LookupFrame(size_t& frameIndex, |
409 const std::string& sopInstanceUid, | 402 const std::string& sopInstanceUid, |
410 unsigned int frameNumber) const ORTHANC_OVERRIDE | 403 unsigned int frameNumber) const ORTHANC_OVERRIDE |
411 { | 404 { |
412 // TODO - Could be speeded up with an additional index | 405 // TODO - Could be speeded up with an additional index |
429 { | 422 { |
430 bool found = false; | 423 bool found = false; |
431 | 424 |
432 for (size_t i = 0; i < GetFramesCount(); i++) | 425 for (size_t i = 0; i < GetFramesCount(); i++) |
433 { | 426 { |
434 double distance = GetFrameGeometry(i).ComputeDistance(point); | 427 double distance = GetFrameGeometry(*this, i).ComputeDistance(point); |
435 if (distance <= maximumDistance) | 428 if (distance <= maximumDistance) |
436 { | 429 { |
437 found = true; | 430 found = true; |
438 frameIndex = i; | 431 frameIndex = i; |
439 } | 432 } |
2721 | 2714 |
2722 // Only change the scene if the loaded frame still corresponds to the current cursor | 2715 // Only change the scene if the loaded frame still corresponds to the current cursor |
2723 if (instance.GetSopInstanceUid() == loadedSopInstanceUid && | 2716 if (instance.GetSopInstanceUid() == loadedSopInstanceUid && |
2724 frameNumber == loadedFrameNumber) | 2717 frameNumber == loadedFrameNumber) |
2725 { | 2718 { |
2726 const OrthancStone::CoordinateSystem3D plane = frames_->GetFrameGeometry(cursorIndex); | 2719 const OrthancStone::CoordinateSystem3D plane = IFramesCollection::GetFrameGeometry(*frames_, cursorIndex); |
2727 | 2720 |
2728 if (quality == DisplayedFrameQuality_Low) | 2721 if (quality == DisplayedFrameQuality_Low) |
2729 { | 2722 { |
2730 FramesCache::Accessor accessor(*framesCache_, instance.GetSopInstanceUid(), frameNumber); | 2723 FramesCache::Accessor accessor(*framesCache_, instance.GetSopInstanceUid(), frameNumber); |
2731 if (accessor.IsValid() && | 2724 if (accessor.IsValid() && |
2880 | 2873 |
2881 lock->Invalidate(); | 2874 lock->Invalidate(); |
2882 } | 2875 } |
2883 } | 2876 } |
2884 | 2877 |
2885 | |
2886 ViewerViewport(OrthancStone::WebAssemblyLoadersContext& context, | 2878 ViewerViewport(OrthancStone::WebAssemblyLoadersContext& context, |
2887 const OrthancStone::DicomSource& source, | 2879 const OrthancStone::DicomSource& source, |
2888 const std::string& canvas, | 2880 const std::string& canvas, |
2889 boost::shared_ptr<FramesCache> cache, | 2881 boost::shared_ptr<FramesCache> cache, |
2890 bool softwareRendering, | 2882 bool softwareRendering, |
2975 | 2967 |
2976 if (that.synchronizationEnabled_) | 2968 if (that.synchronizationEnabled_) |
2977 { | 2969 { |
2978 const size_t currentCursorIndex = that.cursor_->GetCurrentIndex(); | 2970 const size_t currentCursorIndex = that.cursor_->GetCurrentIndex(); |
2979 | 2971 |
2980 const OrthancStone::CoordinateSystem3D current = | 2972 const OrthancStone::CoordinateSystem3D current = IFramesCollection::GetFrameGeometry(*that.frames_, currentCursorIndex); |
2981 that.frames_->GetFrameGeometry(currentCursorIndex); | |
2982 | 2973 |
2983 if (isShift && | 2974 if (isShift && |
2984 previousCursorIndex != currentCursorIndex) | 2975 previousCursorIndex != currentCursorIndex) |
2985 { | 2976 { |
2986 const OrthancStone::CoordinateSystem3D previous = | 2977 const OrthancStone::CoordinateSystem3D previous = IFramesCollection::GetFrameGeometry(*that.frames_, previousCursorIndex); |
2987 that.frames_->GetFrameGeometry(previousCursorIndex); | |
2988 that.synchronizationOffset_ += previous.GetOrigin() - current.GetOrigin(); | 2978 that.synchronizationOffset_ += previous.GetOrigin() - current.GetOrigin(); |
2989 } | 2979 } |
2990 | 2980 |
2991 that.observer_->SignalSynchronizedBrowsing( | 2981 that.observer_->SignalSynchronizedBrowsing( |
2992 that, current.GetOrigin() + that.synchronizationOffset_, current.GetNormal()); | 2982 that, current.GetOrigin() + that.synchronizationOffset_, current.GetNormal()); |
3256 const size_t frameNumber = frames_->GetFrameNumberInInstance(cursorIndex); | 3246 const size_t frameNumber = frames_->GetFrameNumberInInstance(cursorIndex); |
3257 | 3247 |
3258 FramesCache::Accessor accessor(*framesCache_, instance.GetSopInstanceUid(), frameNumber); | 3248 FramesCache::Accessor accessor(*framesCache_, instance.GetSopInstanceUid(), frameNumber); |
3259 if (accessor.IsValid()) | 3249 if (accessor.IsValid()) |
3260 { | 3250 { |
3261 RenderCurrentScene(accessor.GetImage(), instance, frameNumber, frames_->GetFrameGeometry(cursorIndex)); | 3251 RenderCurrentScene(accessor.GetImage(), instance, frameNumber, IFramesCollection::GetFrameGeometry(*frames_, cursorIndex)); |
3262 | 3252 |
3263 DisplayedFrameQuality quality; | 3253 DisplayedFrameQuality quality; |
3264 | 3254 |
3265 if (accessor.GetQuality() < QUALITY_FULL) | 3255 if (accessor.GetQuality() < QUALITY_FULL) |
3266 { | 3256 { |
3367 bool GetCurrentPlane(OrthancStone::CoordinateSystem3D& plane) const | 3357 bool GetCurrentPlane(OrthancStone::CoordinateSystem3D& plane) const |
3368 { | 3358 { |
3369 if (cursor_.get() != NULL && | 3359 if (cursor_.get() != NULL && |
3370 frames_.get() != NULL) | 3360 frames_.get() != NULL) |
3371 { | 3361 { |
3372 plane = frames_->GetFrameGeometry(cursor_->GetCurrentIndex()); | 3362 plane = IFramesCollection::GetFrameGeometry(*frames_, cursor_->GetCurrentIndex()); |
3373 return true; | 3363 return true; |
3374 } | 3364 } |
3375 else | 3365 else |
3376 { | 3366 { |
3377 return false; | 3367 return false; |
3867 frames_.get() != NULL && | 3857 frames_.get() != NULL && |
3868 cursor_.get() != NULL) | 3858 cursor_.get() != NULL) |
3869 { | 3859 { |
3870 const size_t currentCursorIndex = cursor_->GetCurrentIndex(); | 3860 const size_t currentCursorIndex = cursor_->GetCurrentIndex(); |
3871 | 3861 |
3872 const OrthancStone::CoordinateSystem3D current = | 3862 const OrthancStone::CoordinateSystem3D current = IFramesCollection::GetFrameGeometry(*frames_, currentCursorIndex); |
3873 frames_->GetFrameGeometry(currentCursorIndex); | |
3874 | 3863 |
3875 observer_->SignalSynchronizedBrowsing( | 3864 observer_->SignalSynchronizedBrowsing( |
3876 *this, current.GetOrigin() + synchronizationOffset_, current.GetNormal()); | 3865 *this, current.GetOrigin() + synchronizationOffset_, current.GetNormal()); |
3877 } | 3866 } |
3878 } | 3867 } |