comparison Applications/Samples/SimpleViewerApplication.h @ 270:2d64f4d39610 am-2

backup (work in progress)
author am@osimis.io
date Thu, 23 Aug 2018 14:45:04 +0200
parents 5bd4161bf11b
children 46c5296d867e
comparison
equal deleted inserted replaced
269:0dfa83535cd7 270:2d64f4d39610
120 } 120 }
121 } 121 }
122 }; 122 };
123 123
124 124
125 // void OffsetSlice(int offset)
126 // {
127 // if (source_ != NULL)
128 // {
129 // int slice = static_cast<int>(slice_) + offset;
130
131 // if (slice < 0)
132 // {
133 // slice = 0;
134 // }
135
136 // if (slice >= static_cast<int>(source_->GetSliceCount()))
137 // {
138 // slice = source_->GetSliceCount() - 1;
139 // }
140
141 // if (slice != static_cast<int>(slice_))
142 // {
143 // SetSlice(slice);
144 // }
145 // }
146 // }
147
148
149 // void SetSlice(size_t index)
150 // {
151 // if (source_ != NULL &&
152 // index < source_->GetSliceCount())
153 // {
154 // slice_ = index;
155
156 //#if 1
157 // widget_->SetSlice(source_->GetSlice(slice_).GetGeometry());
158 //#else
159 // // TEST for scene extents - Rotate the axes
160 // double a = 15.0 / 180.0 * M_PI;
161
162 //#if 1
163 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0);
164 // Vector y; GeometryToolbox::AssignVector(y, -sin(a), cos(a), 0);
165 //#else
166 // // Flip the normal
167 // Vector x; GeometryToolbox::AssignVector(x, cos(a), sin(a), 0);
168 // Vector y; GeometryToolbox::AssignVector(y, sin(a), -cos(a), 0);
169 //#endif
170
171 // SliceGeometry s(source_->GetSlice(slice_).GetGeometry().GetOrigin(), x, y);
172 // widget_->SetSlice(s);
173 //#endif
174 // }
175 // }
176
177
178 virtual void HandleMessage(IObservable& from, const IMessage& message) {
179 switch (message.GetType()) {
180 case MessageType_Widget_GeometryChanged:
181 dynamic_cast<LayerWidget&>(from).SetDefaultView();
182 break;
183 default:
184 VLOG("unhandled message type" << message.GetType());
185 }
186 }
187
188 std::unique_ptr<Interactor> interactor_; 125 std::unique_ptr<Interactor> interactor_;
189 LayoutWidget* mainLayout_; 126 LayoutWidget* mainLayout_;
190 LayoutWidget* thumbnailsLayout_; 127 LayoutWidget* thumbnailsLayout_;
191 LayerWidget* mainViewport_; 128 LayerWidget* mainViewport_;
192 std::vector<LayerWidget*> thumbnails_; 129 std::vector<LayerWidget*> thumbnails_;
193 std::vector<std::string> instances_; 130 std::vector<std::string> instances_;
131
194 unsigned int currentInstanceIndex_; 132 unsigned int currentInstanceIndex_;
195 OrthancStone::WidgetViewport* wasmViewport1_; 133 OrthancStone::WidgetViewport* wasmViewport1_;
196 OrthancStone::WidgetViewport* wasmViewport2_; 134 OrthancStone::WidgetViewport* wasmViewport2_;
197 135
198 IStatusBar* statusBar_; 136 IStatusBar* statusBar_;
199 unsigned int slice_; 137 unsigned int slice_;
200 std::unique_ptr<SmartLoader> smartLoader_; 138 std::unique_ptr<SmartLoader> smartLoader_;
139 std::unique_ptr<OrthancApiClient> orthancApiClient_;
201 140
202 public: 141 public:
203 SimpleViewerApplication(MessageBroker& broker) : 142 SimpleViewerApplication(MessageBroker& broker) :
204 IObserver(broker), 143 IObserver(broker),
205 mainLayout_(NULL), 144 mainLayout_(NULL),
208 wasmViewport2_(NULL), 147 wasmViewport2_(NULL),
209 slice_(0) 148 slice_(0)
210 { 149 {
211 DeclareIgnoredMessage(MessageType_Widget_ContentChanged); 150 DeclareIgnoredMessage(MessageType_Widget_ContentChanged);
212 DeclareHandledMessage(MessageType_Widget_GeometryChanged); 151 DeclareHandledMessage(MessageType_Widget_GeometryChanged);
152
153 DeclareHandledMessage(MessageType_OrthancApi_GetStudyIds_Ready);
154 DeclareHandledMessage(MessageType_OrthancApi_GetStudy_Ready);
155 DeclareHandledMessage(MessageType_OrthancApi_GetSeries_Ready);
213 } 156 }
214 157
215 virtual void Finalize() {} 158 virtual void Finalize() {}
216 virtual IWidget* GetCentralWidget() {return mainLayout_;} 159 virtual IWidget* GetCentralWidget() {return mainLayout_;}
217 160
219 { 162 {
220 boost::program_options::options_description generic("Sample options"); 163 boost::program_options::options_description generic("Sample options");
221 generic.add_options() 164 generic.add_options()
222 // ("study", boost::program_options::value<std::string>(), 165 // ("study", boost::program_options::value<std::string>(),
223 // "Orthanc ID of the study") 166 // "Orthanc ID of the study")
224 ("instance1", boost::program_options::value<std::string>(), 167 ("studyId", boost::program_options::value<std::string>(),
225 "Orthanc ID of the instances") 168 "Orthanc ID of the study")
226 ("instance2", boost::program_options::value<std::string>(),
227 "Orthanc ID of the instances")
228 ; 169 ;
229 170
230 options.add(generic); 171 options.add(generic);
231 } 172 }
232 173
236 { 177 {
237 using namespace OrthancStone; 178 using namespace OrthancStone;
238 179
239 context_ = context; 180 context_ = context;
240 statusBar_ = &statusBar; 181 statusBar_ = &statusBar;
182
183 {// initialize viewports and layout
184 mainLayout_ = new LayoutWidget();
185 mainLayout_->SetPadding(10);
186 mainLayout_->SetBackgroundCleared(true);
187 mainLayout_->SetBackgroundColor(0, 0, 0);
188 mainLayout_->SetHorizontal();
189
190 thumbnailsLayout_ = new LayoutWidget();
191 thumbnailsLayout_->SetPadding(10);
192 thumbnailsLayout_->SetBackgroundCleared(true);
193 thumbnailsLayout_->SetBackgroundColor(50, 50, 50);
194 thumbnailsLayout_->SetVertical();
195
196 mainViewport_ = new LayerWidget(broker_);
197 mainViewport_->RegisterObserver(*this);
198
199 // hierarchy
200 mainLayout_->AddWidget(thumbnailsLayout_);
201 mainLayout_->AddWidget(mainViewport_);
202
203 // sources
204 smartLoader_.reset(new SmartLoader(broker_, context_->GetWebService()));
205 smartLoader_->SetImageQuality(SliceImageQuality_FullPam);
206
207 // mainViewport_->AddLayer(smartLoader_->GetFrame(instances_[currentInstanceIndex_], 0));
208 // thumbnails_[0]->AddLayer(smartLoader_->GetFrame(instances_[0], 0));
209 // thumbnails_[1]->AddLayer(smartLoader_->GetFrame(instances_[1], 0));
210
211 mainLayout_->SetTransmitMouseOver(true);
212 interactor_.reset(new Interactor(*this));
213 mainViewport_->SetInteractor(*interactor_);
214 }
215
241 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout"); 216 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout");
242 statusBar.SetMessage("Use the key \"n\" to go to next image in the main viewport"); 217 statusBar.SetMessage("Use the key \"n\" to go to next image in the main viewport");
243 218
244 if (parameters.count("instance1") < 1) 219 orthancApiClient_.reset(new OrthancApiClient(broker_, context_->GetWebService()));
245 { 220
246 LOG(ERROR) << "The instance ID is missing"; 221 if (parameters.count("studyId") < 1)
247 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 222 {
248 } 223 LOG(WARNING) << "The study ID is missing, will take the first studyId found in Orthanc";
249 if (parameters.count("instance2") < 1) 224 orthancApiClient_->ScheduleGetStudyIds(*this);
250 { 225 }
251 LOG(ERROR) << "The instance ID is missing"; 226 else
252 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 227 {
253 } 228 SelectStudy(parameters["studyId"].as<std::string>());
254 instances_.push_back(parameters["instance1"].as<std::string>()); 229 }
255 instances_.push_back(parameters["instance2"].as<std::string>()); 230 }
256 231
257 mainLayout_ = new LayoutWidget(); 232 void OnStudyListReceived(const Json::Value& response)
258 mainLayout_->SetPadding(10); 233 {
259 mainLayout_->SetBackgroundCleared(true); 234 if (response.isArray() && response.size() > 1)
260 mainLayout_->SetBackgroundColor(0, 0, 0); 235 {
261 mainLayout_->SetHorizontal(); 236 SelectStudy(response[0].asString());
262 237 }
263 thumbnailsLayout_ = new LayoutWidget(); 238 }
264 thumbnailsLayout_->SetPadding(10); 239 void OnStudyReceived(const Json::Value& response)
265 thumbnailsLayout_->SetBackgroundCleared(true); 240 {
266 thumbnailsLayout_->SetBackgroundColor(50, 50, 50); 241 if (response.isObject() && response["Series"].isArray())
267 thumbnailsLayout_->SetVertical(); 242 {
268 243 for (size_t i=0; i < response["Series"].size(); i++)
269 mainViewport_ = new LayerWidget(broker_); 244 {
270 thumbnails_.push_back(new LayerWidget(broker_)); 245 orthancApiClient_->ScheduleGetSeries(*this, response["Series"][(int)i].asString());
271 thumbnails_.push_back(new LayerWidget(broker_)); 246 }
272 mainViewport_->RegisterObserver(*this); 247 }
273 thumbnails_[0]->RegisterObserver(*this); 248 }
274 thumbnails_[1]->RegisterObserver(*this); 249
275 250 void OnSeriesReceived(const Json::Value& response)
276 // hierarchy 251 {
277 mainLayout_->AddWidget(thumbnailsLayout_); 252 if (response.isObject() && response["Instances"].isArray() && response["Instances"].size() > 0)
278 mainLayout_->AddWidget(mainViewport_); 253 {
279 thumbnailsLayout_->AddWidget(thumbnails_[0]); 254 LoadThumbnailForSeries(response["ID"].asString(), response["Instances"][0].asString());
280 thumbnailsLayout_->AddWidget(thumbnails_[1]); 255 }
281 256 //TODO: create layout and start loading frames
282 // sources 257 //mainViewport_->AddLayer(smartLoader_->GetFrame(instances_[currentInstanceIndex_], 0));
283 smartLoader_.reset(new SmartLoader(broker_, context_->GetWebService())); 258 //thumbnails_[0]->AddLayer(smartLoader_->GetFrame(instances_[0], 0));
284 smartLoader_->SetImageQuality(SliceImageQuality_FullPam); 259 //thumbnails_[1]->AddLayer(smartLoader_->GetFrame(instances_[1], 0));
285 260 }
286 mainViewport_->AddLayer(smartLoader_->GetFrame(instances_[currentInstanceIndex_], 0)); 261
287 thumbnails_[0]->AddLayer(smartLoader_->GetFrame(instances_[0], 0)); 262 void LoadThumbnailForSeries(const std::string& seriesId, const std::string& instanceId)
288 thumbnails_[1]->AddLayer(smartLoader_->GetFrame(instances_[1], 0)); 263 {
289 264 LayerWidget* thumbnailWidget = new LayerWidget(broker_);
290 mainLayout_->SetTransmitMouseOver(true); 265 thumbnailWidget->RegisterObserver(*this);
291 interactor_.reset(new Interactor(*this)); 266 thumbnailWidget->AddLayer(smartLoader_->GetFrame(instanceId, 0));
292 mainViewport_->SetInteractor(*interactor_); 267 thumbnailsLayout_->AddWidget(thumbnailWidget);
268 thumbnails_.push_back(thumbnailWidget);
269 }
270
271 void SelectStudy(const std::string& studyId)
272 {
273 orthancApiClient_->ScheduleGetStudy(*this, studyId);
274 }
275
276 void LoadSeries(const std::vector<std::string>& seriesIds)
277 {
278 // instances_.push_back(parameters["studyId"].as<std::string>());
279 // instances_.push_back(parameters["instance2"].as<std::string>());
280 }
281
282 virtual void HandleMessage(IObservable& from, const IMessage& message) {
283 switch (message.GetType()) {
284 case MessageType_Widget_GeometryChanged:
285 dynamic_cast<LayerWidget&>(from).SetDefaultView();
286 break;
287 case MessageType_OrthancApi_GetStudyIds_Ready:
288 OnStudyListReceived(dynamic_cast<const OrthancApiClient::GetJsonResponseReadyMessage&>(message).response_);
289 break;
290 case MessageType_OrthancApi_GetSeries_Ready:
291 OnSeriesReceived(dynamic_cast<const OrthancApiClient::GetJsonResponseReadyMessage&>(message).response_);
292 break;
293 case MessageType_OrthancApi_GetStudy_Ready:
294 OnStudyReceived(dynamic_cast<const OrthancApiClient::GetJsonResponseReadyMessage&>(message).response_);
295 break;
296 default:
297 VLOG("unhandled message type" << message.GetType());
298 }
293 } 299 }
294 300
295 #if ORTHANC_ENABLE_SDL==0 301 #if ORTHANC_ENABLE_SDL==0
296 virtual void InitializeWasm() { 302 virtual void InitializeWasm() {
297 303