# HG changeset patch # User Sebastien Jodogne # Date 1557760744 -7200 # Node ID 1088d4c4d78cace5087687891de6bbd16a7d3509 # Parent 6af3099ed8da6d4c6b055588fc5b7401ca3ee38b cont diff -r 6af3099ed8da -r 1088d4c4d78c Framework/Toolbox/OrthancSlicesLoader.cpp --- a/Framework/Toolbox/OrthancSlicesLoader.cpp Mon May 13 17:03:46 2019 +0200 +++ b/Framework/Toolbox/OrthancSlicesLoader.cpp Mon May 13 17:19:04 2019 +0200 @@ -191,19 +191,7 @@ void OrthancSlicesLoader::SortAndFinalizeSlices() { - bool ok = false; - - if (slices_.GetSlicesCount() > 0) - { - Vector normal; - if (slices_.SelectNormal(normal)) - { - slices_.FilterNormal(normal); - slices_.SetNormal(normal); - slices_.Sort(); - ok = true; - } - } + bool ok = slices_.Sort(); state_ = State_GeometryReady; diff -r 6af3099ed8da -r 1088d4c4d78c Framework/Toolbox/Slice.h --- a/Framework/Toolbox/Slice.h Mon May 13 17:03:46 2019 +0200 +++ b/Framework/Toolbox/Slice.h Mon May 13 17:19:04 2019 +0200 @@ -29,7 +29,9 @@ namespace OrthancStone { - class Slice : public Orthanc::IDynamicObject + // TODO - Remove this class + class Slice : + public Orthanc::IDynamicObject /* to be used as a payload of SlicesSorter */ { private: enum Type diff -r 6af3099ed8da -r 1088d4c4d78c Framework/Toolbox/SlicesSorter.cpp --- a/Framework/Toolbox/SlicesSorter.cpp Mon May 13 17:03:46 2019 +0200 +++ b/Framework/Toolbox/SlicesSorter.cpp Mon May 13 17:19:04 2019 +0200 @@ -148,7 +148,7 @@ } - void SlicesSorter::Sort() + void SlicesSorter::SortInternal() { if (!hasNormal_) { @@ -237,6 +237,24 @@ } + bool SlicesSorter::Sort() + { + if (GetSlicesCount() > 0) + { + Vector normal; + if (SelectNormal(normal)) + { + FilterNormal(normal); + SetNormal(normal); + SortInternal(); + return true; + } + } + + return false; + } + + bool SlicesSorter::LookupClosestSlice(size_t& index, double& distance, const CoordinateSystem3D& slice) const diff -r 6af3099ed8da -r 1088d4c4d78c Framework/Toolbox/SlicesSorter.h --- a/Framework/Toolbox/SlicesSorter.h Mon May 13 17:03:46 2019 +0200 +++ b/Framework/Toolbox/SlicesSorter.h Mon May 13 17:19:04 2019 +0200 @@ -41,6 +41,14 @@ const SliceWithDepth& GetSlice(size_t i) const; + void SetNormal(const Vector& normal); + + void SortInternal(); + + void FilterNormal(const Vector& normal); + + bool SelectNormal(Vector& normal) const; + public: SlicesSorter() : hasNormal_(false) { @@ -71,15 +79,9 @@ bool HasSlicePayload(size_t i) const; const Orthanc::IDynamicObject& GetSlicePayload(size_t i) const; - - void SetNormal(const Vector& normal); + + bool Sort(); - void Sort(); - - void FilterNormal(const Vector& normal); - - bool SelectNormal(Vector& normal) const; - bool LookupClosestSlice(size_t& index, double& distance, const CoordinateSystem3D& slice) const; diff -r 6af3099ed8da -r 1088d4c4d78c Samples/Sdl/Loader.cpp --- a/Samples/Sdl/Loader.cpp Mon May 13 17:03:46 2019 +0200 +++ b/Samples/Sdl/Loader.cpp Mon May 13 17:19:04 2019 +0200 @@ -26,6 +26,7 @@ #include "../../Framework/StoneInitialization.h" #include "../../Framework/Toolbox/GeometryToolbox.h" #include "../../Framework/Volumes/ImageBuffer3D.h" +#include "../../Framework/Toolbox/SlicesSorter.h" // From Orthanc framework #include @@ -1138,7 +1139,8 @@ - class DicomInstanceParameters : public boost::noncopyable + class DicomInstanceParameters : + public Orthanc::IDynamicObject /* to be used as a payload of SlicesSorter */ { private: Orthanc::DicomImageInformation imageInformation_; @@ -1374,8 +1376,8 @@ double distance; - return (OrthancStone::CoordinateSystem3D::GetDistance(distance, tmp, plan) && - OrthancStone::LinearAlgebra::IsNear(distance, thickness_ / 2.0)); + return (OrthancStone::CoordinateSystem3D::GetDistance(distance, tmp, plane) && + distance <= thickness_ / 2.0); } bool IsColor() const @@ -1491,9 +1493,19 @@ Orthanc::DicomMap dicom; dicom.FromDicomAsJson(value[instances[i]]); - DicomInstanceParameters instance(dicom); + std::auto_ptr instance(new DicomInstanceParameters(dicom)); + + OrthancStone::CoordinateSystem3D geometry = instance->GetGeometry(); + that_.slices_.AddSlice(geometry, instance.release()); + } + if (!that_.slices_.Sort()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, + "Cannot sort the 3D slices of a DICOM series"); } + + printf("series sorted\n"); } }; @@ -1529,7 +1541,7 @@ bool active_; std::auto_ptr image_; - + OrthancStone::SlicesSorter slices_; public: AxialVolumeOrthancLoader(OrthancStone::IObservable& oracle) :