Mercurial > hg > orthanc-stone
changeset 71:30c768873d47 wasm
OrthancSliceLoader::ScheduleLoadInstance
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 May 2017 10:27:18 +0200 |
parents | f73aed014bde |
children | c1cc3bdba18c |
files | Applications/Samples/SingleFrameApplication.h Framework/Widgets/LayerWidget.cpp UnitTestsSources/UnitTestsMain.cpp |
diffstat | 3 files changed, 90 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/SingleFrameApplication.h Mon May 22 21:43:49 2017 +0200 +++ b/Applications/Samples/SingleFrameApplication.h Wed May 24 10:27:18 2017 +0200 @@ -53,11 +53,9 @@ virtual void NotifySlicesAvailable(const ParallelSlices& slices) { - printf("ICI\n"); if (widget_ != NULL && slices.GetSliceCount() > 0) { - printf("GO\n"); widget_->SetSlice(slices.GetSlice(0), 1.0 /* TODO */); } } @@ -113,7 +111,7 @@ #else std::auto_ptr<LayerWidget> widget(new LayerWidget); -#if 0 +#if 1 std::auto_ptr<OrthancFrameLayerSource> layer (new OrthancFrameLayerSource(context.GetWebService(), instance, frame)); layer->SetObserver(*this);
--- a/Framework/Widgets/LayerWidget.cpp Mon May 22 21:43:49 2017 +0200 +++ b/Framework/Widgets/LayerWidget.cpp Wed May 24 10:27:18 2017 +0200 @@ -189,8 +189,7 @@ std::swap(ay, by); } - //LOG(INFO) << "Extent of layer " << i << ": (" << ax << "," << ay << ")->(" << bx << "," << by << ")"; - printf("Extent %d: (%f,%f) -> (%f,%f)\n", (int) i, ax, ay, bx, by); + LOG(INFO) << "Extent of layer " << i << ": (" << ax << "," << ay << ")->(" << bx << "," << by << ")"; if (first) { @@ -260,7 +259,7 @@ ILayerRenderer* renderer, const SliceGeometry& slice) { - printf("Updating layer %d\n", (int) index); + LOG(INFO) << "Updating layer " << index; std::auto_ptr<ILayerRenderer> tmp(renderer); @@ -391,7 +390,7 @@ { size_t i; if (LookupLayer(i, source)) - printf("Geometry ready for layer %d\n", (int) i); + LOG(INFO) << "Geometry ready for layer " << i; SetDefaultView(); layers_[i]->ScheduleLayerCreation(slice_); @@ -422,7 +421,7 @@ size_t i; if (LookupLayer(i, source)) - printf("Renderer ready for layer %d\n", (int) i); + LOG(INFO) << "Renderer ready for layer " << i; size_t index; if (LookupLayer(index, source))
--- a/UnitTestsSources/UnitTestsMain.cpp Mon May 22 21:43:49 2017 +0200 +++ b/UnitTestsSources/UnitTestsMain.cpp Wed May 24 10:27:18 2017 +0200 @@ -90,13 +90,16 @@ std::string position, orientation; if (dataset.GetStringValue(position, OrthancPlugins::DICOM_TAG_IMAGE_POSITION_PATIENT) && - dataset.GetStringValue(orientation, OrthancPlugins::DICOM_TAG_IMAGE_ORIENTATION_PATIENT) && - reader.GetUnsignedIntegerValue(width_, OrthancPlugins::DICOM_TAG_COLUMNS) && + dataset.GetStringValue(orientation, OrthancPlugins::DICOM_TAG_IMAGE_ORIENTATION_PATIENT)) + { + geometry_ = SliceGeometry(position, orientation); + } + + if (reader.GetUnsignedIntegerValue(width_, OrthancPlugins::DICOM_TAG_COLUMNS) && reader.GetUnsignedIntegerValue(height_, OrthancPlugins::DICOM_TAG_ROWS)) { orthancInstanceId_ = instanceId; frame_ = frame; - geometry_ = SliceGeometry(position, orientation); converter_.ReadParameters(dataset); type_ = Type_OrthancInstance; @@ -428,6 +431,7 @@ enum Mode { Mode_SeriesGeometry, + Mode_InstanceGeometry, Mode_LoadImage }; @@ -435,8 +439,10 @@ { private: Mode mode_; + unsigned int frame_; unsigned int sliceIndex_; const Slice* slice_; + std::string instanceId_; Operation(Mode mode) : mode_(mode) @@ -460,12 +466,33 @@ assert(mode_ == Mode_LoadImage && slice_ != NULL); return *slice_; } + + unsigned int GetFrame() const + { + assert(mode_ == Mode_InstanceGeometry); + return frame_; + } + + const std::string& GetInstanceId() const + { + assert(mode_ == Mode_InstanceGeometry); + return instanceId_; + } static Operation* DownloadSeriesGeometry() { return new Operation(Mode_SeriesGeometry); } + static Operation* DownloadInstanceGeometry(const std::string& instanceId, + unsigned int frame) + { + std::auto_ptr<Operation> operation(new Operation(Mode_InstanceGeometry)); + operation->instanceId_ = instanceId; + operation->frame_ = frame; + return operation.release(); + } + static Operation* DownloadSliceImage(unsigned int sliceIndex, const Slice& slice) { @@ -541,6 +568,38 @@ } + void ParseInstanceGeometry(const std::string& instanceId, + unsigned int frame, + const void* answer, + size_t size) + { + Json::Value tags; + if (!MessagingToolbox::ParseJson(tags, answer, size) || + tags.type() != Json::objectValue) + { + callback_.NotifyGeometryError(*this); + return; + } + + OrthancPlugins::FullOrthancDataset dataset(tags); + + state_ = State_GeometryReady; + + Slice slice; + if (slice.ParseOrthancFrame(dataset, instanceId, frame)) + { + LOG(INFO) << "Loaded instance " << instanceId; + slices_.AddSlice(slice); + callback_.NotifyGeometryReady(*this); + } + else + { + LOG(WARNING) << "Skipping invalid instance " << instanceId; + callback_.NotifyGeometryError(*this); + } + } + + void ParseSliceImage(const Operation& operation, const void* answer, size_t size) @@ -601,6 +660,22 @@ } } + void ScheduleLoadInstance(const std::string& instanceId, + unsigned int frame) + { + if (state_ != State_Initialization) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + state_ = State_LoadingGeometry; + std::string uri = "/instances/" + instanceId + "/tags"; + orthanc_.ScheduleGetRequest + (*this, uri, Operation::DownloadInstanceGeometry(instanceId, frame)); + } + } + size_t GetSliceCount() const { if (state_ != State_GeometryReady) @@ -669,6 +744,10 @@ ParseSeriesGeometry(answer, answerSize); break; + case Mode_InstanceGeometry: + ParseInstanceGeometry(operation->GetInstanceId(), operation->GetFrame(), answer, answerSize); + break; + case Mode_LoadImage: ParseSliceImage(*operation, answer, answerSize); break; @@ -748,7 +827,9 @@ OrthancStone::Tata tata; OrthancStone::OrthancSliceLoader loader(tata, orthanc); //loader.ScheduleLoadSeries("c1c4cb95-05e3bd11-8da9f5bb-87278f71-0b2b43f5"); - loader.ScheduleLoadSeries("67f1b334-02c16752-45026e40-a5b60b6b-030ecab5"); + //loader.ScheduleLoadSeries("67f1b334-02c16752-45026e40-a5b60b6b-030ecab5"); + + loader.ScheduleLoadInstance("19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5", 0); /*printf(">> %d\n", loader.GetSliceCount()); loader.ScheduleLoadSliceImage(31);*/