comparison OrthancStone/Sources/Loaders/SeriesFramesLoader.cpp @ 1679:5b8b88e5bfd6

successfully running unit tests in WebAssembly
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2020 12:59:10 +0100
parents 51bab5188a13
children 0257339b0884
comparison
equal deleted inserted replaced
1678:1393e3393a0b 1679:5b8b88e5bfd6
305 HandleDicomWebRendered(dynamic_cast<const Payload&>(message.GetOrigin().GetPayload()), 305 HandleDicomWebRendered(dynamic_cast<const Payload&>(message.GetOrigin().GetPayload()),
306 message.GetAnswer(), message.GetAnswerHeaders()); 306 message.GetAnswer(), message.GetAnswerHeaders());
307 } 307 }
308 308
309 309
310 static void GetBounds(float& low,
311 float& high,
312 double center, // in
313 double width) // in
314 {
315 low = static_cast<float>(center - width / 2.0);
316 high = static_cast<float>(center + width / 2.0);
317 }
318
319
320 void SeriesFramesLoader::GetPreviewWindowing(float& center,
321 float& width,
322 size_t index) const
323 {
324 const Orthanc::DicomMap& instance = frames_.GetInstance(index);
325 const DicomInstanceParameters& parameters = frames_.GetInstanceParameters(index);
326
327 size_t s = parameters.GetPresetWindowingsCount();
328
329 if (s > 0)
330 {
331 // Use the largest windowing given all the preset windowings
332 // that are available in the DICOM tags
333 float low, high;
334 GetBounds(low, high, parameters.GetPresetWindowingCenter(0),
335 parameters.GetPresetWindowingWidth(0));
336
337 for (size_t i = 1; i < s; i++)
338 {
339 float a, b;
340 GetBounds(a, b, parameters.GetPresetWindowingCenter(i),
341 parameters.GetPresetWindowingWidth(i));
342 low = std::min(low, a);
343 high = std::max(high, b);
344 }
345
346 assert(low <= high);
347
348 if (LinearAlgebra::IsNear(low, high))
349 {
350 // Cannot infer a suitable windowing from the available tags
351 center = 128.0f;
352 width = 256.0f;
353 }
354 else
355 {
356 center = (low + high) / 2.0f;
357 width = (high - low);
358 printf(">> %f %f\n", center, width);
359 }
360 }
361 else
362 {
363 float a, b;
364 if (instance.ParseFloat(a, Orthanc::DICOM_TAG_SMALLEST_IMAGE_PIXEL_VALUE) &&
365 instance.ParseFloat(b, Orthanc::DICOM_TAG_LARGEST_IMAGE_PIXEL_VALUE) &&
366 a < b)
367 {
368 center = (a + b) / 2.0f;
369 width = (b - a);
370 }
371 else
372 {
373 // Cannot infer a suitable windowing from the available tags
374 center = 128.0f;
375 width = 256.0f;
376 }
377 }
378 }
379
380
381 Orthanc::IDynamicObject& SeriesFramesLoader::FrameLoadedMessage::GetUserPayload() const 310 Orthanc::IDynamicObject& SeriesFramesLoader::FrameLoadedMessage::GetUserPayload() const
382 { 311 {
383 if (userPayload_) 312 if (userPayload_)
384 { 313 {
385 return *userPayload_; 314 return *userPayload_;
483 "/instances/" + sopInstanceUid); 412 "/instances/" + sopInstanceUid);
484 413
485 if (source.HasDicomWebRendered() && 414 if (source.HasDicomWebRendered() &&
486 quality == 0) 415 quality == 0)
487 { 416 {
417 const DicomInstanceParameters& parameters = frames_.GetInstanceParameters(index);
418
488 float c, w; 419 float c, w;
489 GetPreviewWindowing(c, w, index); 420 parameters.GetWindowingPresetsUnion(c, w);
490 421
491 std::map<std::string, std::string> arguments, headers; 422 std::map<std::string, std::string> arguments, headers;
492 arguments["window"] = (boost::lexical_cast<std::string>(c) + "," + 423 arguments["window"] = (boost::lexical_cast<std::string>(c) + "," +
493 boost::lexical_cast<std::string>(w) + ",linear"); 424 boost::lexical_cast<std::string>(w) + ",linear");
494 headers["Accept"] = "image/jpeg"; 425 headers["Accept"] = "image/jpeg";