comparison Framework/Toolbox/OrthancSlicesLoader.cpp @ 647:6af3099ed8da

uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 13 May 2019 17:03:46 +0200
parents 42dadae61fa9
children 1088d4c4d78c
comparison
equal deleted inserted replaced
646:b4fe9642e83b 647:6af3099ed8da
191 191
192 void OrthancSlicesLoader::SortAndFinalizeSlices() 192 void OrthancSlicesLoader::SortAndFinalizeSlices()
193 { 193 {
194 bool ok = false; 194 bool ok = false;
195 195
196 if (slices_.GetSliceCount() > 0) 196 if (slices_.GetSlicesCount() > 0)
197 { 197 {
198 Vector normal; 198 Vector normal;
199 if (slices_.SelectNormal(normal)) 199 if (slices_.SelectNormal(normal))
200 { 200 {
201 slices_.FilterNormal(normal); 201 slices_.FilterNormal(normal);
207 207
208 state_ = State_GeometryReady; 208 state_ = State_GeometryReady;
209 209
210 if (ok) 210 if (ok)
211 { 211 {
212 LOG(INFO) << "Loaded a series with " << slices_.GetSliceCount() << " slice(s)"; 212 LOG(INFO) << "Loaded a series with " << slices_.GetSlicesCount() << " slice(s)";
213 BroadcastMessage(SliceGeometryReadyMessage(*this)); 213 BroadcastMessage(SliceGeometryReadyMessage(*this));
214 } 214 }
215 else 215 else
216 { 216 {
217 LOG(ERROR) << "This series is empty"; 217 LOG(ERROR) << "This series is empty";
254 for (unsigned int frame = 0; frame < frames; frame++) 254 for (unsigned int frame = 0; frame < frames; frame++)
255 { 255 {
256 std::auto_ptr<Slice> slice(new Slice); 256 std::auto_ptr<Slice> slice(new Slice);
257 if (slice->ParseOrthancFrame(dicom, instances[i], frame)) 257 if (slice->ParseOrthancFrame(dicom, instances[i], frame))
258 { 258 {
259 slices_.AddSlice(slice.release()); 259 CoordinateSystem3D geometry = slice->GetGeometry();
260 slices_.AddSlice(geometry, slice.release());
260 } 261 }
261 else 262 else
262 { 263 {
263 LOG(WARNING) << "Skipping invalid frame " << frame << " within instance " << instances[i]; 264 LOG(WARNING) << "Skipping invalid frame " << frame << " within instance " << instances[i];
264 } 265 }
289 for (unsigned int frame = 0; frame < frames; frame++) 290 for (unsigned int frame = 0; frame < frames; frame++)
290 { 291 {
291 std::auto_ptr<Slice> slice(new Slice); 292 std::auto_ptr<Slice> slice(new Slice);
292 if (slice->ParseOrthancFrame(dicom, instanceId, frame)) 293 if (slice->ParseOrthancFrame(dicom, instanceId, frame))
293 { 294 {
294 slices_.AddSlice(slice.release()); 295 CoordinateSystem3D geometry = slice->GetGeometry();
296 slices_.AddSlice(geometry, slice.release());
295 } 297 }
296 else 298 else
297 { 299 {
298 LOG(WARNING) << "Skipping invalid multi-frame instance " << instanceId; 300 LOG(WARNING) << "Skipping invalid multi-frame instance " << instanceId;
299 BroadcastMessage(SliceGeometryErrorMessage(*this)); 301 BroadcastMessage(SliceGeometryErrorMessage(*this));
320 322
321 std::auto_ptr<Slice> slice(new Slice); 323 std::auto_ptr<Slice> slice(new Slice);
322 if (slice->ParseOrthancFrame(dicom, instanceId, frame)) 324 if (slice->ParseOrthancFrame(dicom, instanceId, frame))
323 { 325 {
324 LOG(INFO) << "Loaded instance geometry " << instanceId; 326 LOG(INFO) << "Loaded instance geometry " << instanceId;
325 slices_.AddSlice(slice.release()); 327
328 CoordinateSystem3D geometry = slice->GetGeometry();
329 slices_.AddSlice(geometry, slice.release());
330
326 BroadcastMessage(SliceGeometryReadyMessage(*this)); 331 BroadcastMessage(SliceGeometryReadyMessage(*this));
327 } 332 }
328 else 333 else
329 { 334 {
330 LOG(WARNING) << "Skipping invalid instance " << instanceId; 335 LOG(WARNING) << "Skipping invalid instance " << instanceId;
715 { 720 {
716 return state_ == State_GeometryReady; 721 return state_ == State_GeometryReady;
717 } 722 }
718 723
719 724
720 size_t OrthancSlicesLoader::GetSliceCount() const 725 size_t OrthancSlicesLoader::GetSlicesCount() const
721 { 726 {
722 if (state_ != State_GeometryReady) 727 if (state_ != State_GeometryReady)
723 { 728 {
724 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 729 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
725 } 730 }
726 731
727 return slices_.GetSliceCount(); 732 return slices_.GetSlicesCount();
728 } 733 }
729 734
730 735
731 const Slice& OrthancSlicesLoader::GetSlice(size_t index) const 736 const Slice& OrthancSlicesLoader::GetSlice(size_t index) const
732 { 737 {
733 if (state_ != State_GeometryReady) 738 if (state_ != State_GeometryReady)
734 { 739 {
735 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 740 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
736 } 741 }
737 742
738 return slices_.GetSlice(index); 743 return dynamic_cast<const Slice&>(slices_.GetSlicePayload(index));
739 } 744 }
740 745
741 746
742 bool OrthancSlicesLoader::LookupSlice(size_t& index, 747 bool OrthancSlicesLoader::LookupSlice(size_t& index,
743 const CoordinateSystem3D& plane) const 748 const CoordinateSystem3D& plane) const
744 { 749 {
745 if (state_ != State_GeometryReady) 750 if (state_ != State_GeometryReady)
746 { 751 {
747 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 752 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
748 } 753 }
749 754
750 return slices_.LookupSlice(index, plane); 755 double distance;
756 return (slices_.LookupClosestSlice(index, distance, plane) &&
757 distance <= GetSlice(index).GetThickness() / 2.0);
751 } 758 }
752 759
753 760
754 void OrthancSlicesLoader::ScheduleSliceImagePng(const Slice& slice, 761 void OrthancSlicesLoader::ScheduleSliceImagePng(const Slice& slice,
755 size_t index) 762 size_t index)