# HG changeset patch # User Sebastien Jodogne # Date 1558943384 -7200 # Node ID 78fcb907caf6ad45b1ae6912430ff13cfa2f68a6 # Parent 7b404c853e665cc9b3fb7cb47e9e1c7515c2bf9d VolumeGeometryReadyMessage diff -r 7b404c853e66 -r 78fcb907caf6 Samples/Sdl/Loader.cpp --- a/Samples/Sdl/Loader.cpp Fri May 24 18:33:08 2019 +0200 +++ b/Samples/Sdl/Loader.cpp Mon May 27 09:49:44 2019 +0200 @@ -221,15 +221,28 @@ - // TODO -> Remove - class IVolumeImageSlicer : public IVolumeSlicer + class VolumeGeometryReadyMessage : public OriginMessage { + ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); + + private: + const VolumeImageGeometry& geometry_; + public: - virtual bool HasGeometry() const = 0; + VolumeGeometryReadyMessage(const IVolumeSlicer& slicer, + const VolumeImageGeometry& geometry) : + OriginMessage(slicer), + geometry_(geometry) + { + } - virtual const VolumeImageGeometry& GetGeometry() const = 0; + const VolumeImageGeometry& GetGeometry() const + { + return geometry_; + } }; + class InvalidExtractedSlice : public IVolumeSlicer::ExtractedSlice { @@ -666,7 +679,9 @@ class OrthancSeriesVolumeProgressiveLoader : - public IObserver + public IObserver, + public IObservable, + public IVolumeSlicer { private: static const unsigned int LOW_QUALITY = 0; @@ -753,6 +768,8 @@ } volume_.SetGeometry(slices); + + BroadcastMessage(VolumeGeometryReadyMessage(*this, volume_.GetGeometry())); } if (volume_.GetSlicesCount() != 0) @@ -811,63 +828,11 @@ std::auto_ptr strategy_; - IVolumeSlicer::ExtractedSlice* ExtractOrthogonalSlice(const CoordinateSystem3D& cuttingPlane) const - { - if (volume_.HasGeometry() && - volume_.GetSlicesCount() != 0) - { - std::auto_ptr slice - (new DicomSeriesVolumeImage::ExtractedOrthogonalSlice(volume_, cuttingPlane)); - - assert(slice.get() != NULL && - strategy_.get() != NULL); - - if (slice->IsValid() && - slice->GetProjection() == VolumeProjection_Axial) - { - strategy_->SetCurrent(slice->GetSliceIndex()); - } - - return slice.release(); - } - else - { - return new InvalidExtractedSlice; - } - } - - public: - class MPRSlicer : public IVolumeImageSlicer - { - private: - boost::shared_ptr that_; - - public: - MPRSlicer(const boost::shared_ptr& that) : - that_(that) - { - } - - virtual ExtractedSlice* ExtractSlice(const CoordinateSystem3D& cuttingPlane) const - { - return that_->ExtractOrthogonalSlice(cuttingPlane); - } - - virtual bool HasGeometry() const - { - return that_->GetVolume().HasGeometry(); - } - - virtual const VolumeImageGeometry& GetGeometry() const - { - return that_->GetVolume().GetGeometry(); - } - }; - OrthancSeriesVolumeProgressiveLoader(IOracle& oracle, IObservable& oracleObservable) : IObserver(oracleObservable.GetBroker()), + IObservable(oracleObservable.GetBroker()), oracle_(oracle), active_(false), simultaneousDownloads_(4), @@ -924,11 +889,40 @@ { return volume_; } + + + virtual ExtractedSlice* ExtractSlice(const CoordinateSystem3D& cuttingPlane) const + { + if (volume_.HasGeometry() && + volume_.GetSlicesCount() != 0) + { + std::auto_ptr slice + (new DicomSeriesVolumeImage::ExtractedOrthogonalSlice(volume_, cuttingPlane)); + + assert(slice.get() != NULL && + strategy_.get() != NULL); + + if (slice->IsValid() && + slice->GetProjection() == VolumeProjection_Axial) + { + strategy_->SetCurrent(slice->GetSliceIndex()); + } + + return slice.release(); + } + else + { + return new InvalidExtractedSlice; + } + } }; - class OrthancMultiframeVolumeLoader : public IObserver + class OrthancMultiframeVolumeLoader : + public IObserver, + public IObservable, + public IVolumeSlicer { private: class State : public Orthanc::IDynamicObject @@ -1176,6 +1170,8 @@ image_->Clear(); ScheduleFrameDownloads(); + + BroadcastMessage(VolumeGeometryReadyMessage(*this, *geometry_)); } @@ -1281,44 +1277,10 @@ public: - class MPRSlicer : public IVolumeImageSlicer - { - private: - boost::shared_ptr that_; - - public: - MPRSlicer(const boost::shared_ptr& that) : - that_(that) - { - } - - virtual ExtractedSlice* ExtractSlice(const CoordinateSystem3D& cuttingPlane) const - { - if (that_->HasGeometry()) - { - return new ExtractedOrthogonalSlice(*that_, cuttingPlane); - } - else - { - return new InvalidExtractedSlice; - } - } - - virtual bool HasGeometry() const - { - return that_->HasGeometry(); - } - - virtual const VolumeImageGeometry& GetGeometry() const - { - return that_->GetGeometry(); - } - }; - - OrthancMultiframeVolumeLoader(IOracle& oracle, IObservable& oracleObservable) : IObserver(oracleObservable.GetBroker()), + IObservable(oracleObservable.GetBroker()), oracle_(oracle), active_(false), revision_(0) @@ -1403,6 +1365,19 @@ } } } + + + virtual ExtractedSlice* ExtractSlice(const CoordinateSystem3D& cuttingPlane) const + { + if (HasGeometry()) + { + return new ExtractedOrthogonalSlice(*this, cuttingPlane); + } + else + { + return new InvalidExtractedSlice; + } + } }; @@ -1430,7 +1405,7 @@ public: VolumeSceneLayerSource(Scene2D& scene, int layerDepth, - IVolumeSlicer* slicer) : // Takes ownership + const boost::shared_ptr& slicer) : scene_(scene), layerDepth_(layerDepth), slicer_(slicer) @@ -1612,31 +1587,26 @@ class Toto : public OrthancStone::IObserver { private: - OrthancStone::IOracle& oracle_; + OrthancStone::CoordinateSystem3D plane_; + OrthancStone::IOracle& oracle_; OrthancStone::Scene2D scene_; std::auto_ptr source1_, source2_; - - OrthancStone::CoordinateSystem3D GetSamplePlane - (const OrthancStone::VolumeSceneLayerSource& source) const + + void Handle(const OrthancStone::VolumeGeometryReadyMessage& message) { - const OrthancStone::IVolumeImageSlicer& slicer = - dynamic_cast(source.GetSlicer()); - - OrthancStone::CoordinateSystem3D plane; - - if (slicer.HasGeometry()) + printf("Geometry ready\n"); + + if (&source1_->GetSlicer() == &message.GetOrigin()) { - //plane = slicer.GetGeometry().GetSagittalGeometry(); - //plane = slicer.GetGeometry().GetAxialGeometry(); - plane = slicer.GetGeometry().GetCoronalGeometry(); - plane.SetOrigin(slicer.GetGeometry().GetCoordinates(0.5f, 0.5f, 0.5f)); + //plane_ = message.GetGeometry().GetSagittalGeometry(); + //plane_ = message.GetGeometry().GetAxialGeometry(); + plane_ = message.GetGeometry().GetCoronalGeometry(); + plane_.SetOrigin(message.GetGeometry().GetCoordinates(0.5f, 0.5f, 0.5f)); } - - return plane; } - + void Handle(const OrthancStone::SleepOracleCommand::TimeoutMessage& message) { if (message.GetOrigin().HasPayload()) @@ -1647,25 +1617,14 @@ { printf("TIMEOUT\n"); - OrthancStone::CoordinateSystem3D plane; - if (source1_.get() != NULL) { - plane = GetSamplePlane(*source1_); - } - else if (source2_.get() != NULL) - { - plane = GetSamplePlane(*source2_); - } - - if (source1_.get() != NULL) - { - source1_->Update(plane); + source1_->Update(plane_); } if (source2_.get() != NULL) { - source2_->Update(plane); + source2_->Update(plane_); } scene_.FitContent(1024, 768); @@ -1761,9 +1720,13 @@ } void SetVolume1(int depth, - OrthancStone::IVolumeSlicer* volume, + const boost::shared_ptr& volume, OrthancStone::ILayerStyleConfigurator* style) { + dynamic_cast(*volume).RegisterObserverCallback + (new OrthancStone::Callable + (*this, &Toto::Handle)); + source1_.reset(new OrthancStone::VolumeSceneLayerSource(scene_, depth, volume)); if (style != NULL) @@ -1773,9 +1736,13 @@ } void SetVolume2(int depth, - OrthancStone::IVolumeSlicer* volume, + const boost::shared_ptr& volume, OrthancStone::ILayerStyleConfigurator* style) { + dynamic_cast(*volume).RegisterObserverCallback + (new OrthancStone::Callable + (*this, &Toto::Handle)); + source2_.reset(new OrthancStone::VolumeSceneLayerSource(scene_, depth, volume)); if (style != NULL) @@ -1801,6 +1768,9 @@ loader3.reset(new OrthancStone::OrthancMultiframeVolumeLoader(oracle, lock.GetOracleObservable())); } + toto->SetVolume1(0, loader1, new OrthancStone::GrayscaleStyleConfigurator); + toto->SetVolume2(1, loader3, new OrthancStone::LookupTableStyleConfigurator); + oracle.Schedule(*toto, new OrthancStone::SleepOracleCommand(100)); if (0) @@ -1890,15 +1860,11 @@ //loader1->LoadSeries("67f1b334-02c16752-45026e40-a5b60b6b-030ecab5"); // Lung 1/10mm - toto->SetVolume2(1, new OrthancStone::OrthancMultiframeVolumeLoader::MPRSlicer(loader3), - new OrthancStone::LookupTableStyleConfigurator); - toto->SetVolume1(0, new OrthancStone::OrthancSeriesVolumeProgressiveLoader::MPRSlicer(loader1), - new OrthancStone::GrayscaleStyleConfigurator); + { + LOG(WARNING) << "...Waiting for Ctrl-C..."; - { oracle.Start(); - LOG(WARNING) << "...Waiting for Ctrl-C..."; Orthanc::SystemToolbox::ServerBarrier(); /** @@ -1924,7 +1890,7 @@ int main(int argc, char* argv[]) { OrthancStone::StoneInitialize(); - Orthanc::Logging::EnableInfoLevel(true); + //Orthanc::Logging::EnableInfoLevel(true); try {