comparison OrthancServer/SliceOrdering.cpp @ 3899:104e27133ebd transcoding

'/ordered-slices': reverted the change introduced in 1.5.8 and go-back to 1.5.7 behaviour
author Alain Mazy <alain@mazy.be>
date Thu, 07 May 2020 12:23:40 +0200
parents 94f4a18a79cc
children
comparison
equal deleted inserted replaced
3897:a4c0ae644fe5 3899:104e27133ebd
318 bool SliceOrdering::SortUsingPositions() 318 bool SliceOrdering::SortUsingPositions()
319 { 319 {
320 if (instances_.size() <= 1) 320 if (instances_.size() <= 1)
321 { 321 {
322 // One single instance: It is sorted by default 322 // One single instance: It is sorted by default
323 sortedInstances_ = instances_;
324 return true; 323 return true;
325 } 324 }
326 325
327 if (!hasNormal_) 326 if (!hasNormal_)
328 { 327 {
329 return false; 328 return false;
330 } 329 }
331 330
332 sortedInstances_.clear();
333
334 // consider only the instances with a position and correctly oriented (if they have a normal)
335 for (size_t i = 0; i < instances_.size(); i++) 331 for (size_t i = 0; i < instances_.size(); i++)
336 { 332 {
337 assert(instances_[i] != NULL); 333 assert(instances_[i] != NULL);
338 if (instances_[i]->HasPosition() && 334
339 (!instances_[i]->HasNormal() || 335 if (!instances_[i]->HasPosition() ||
340 IsParallelOrOpposite(instances_[i]->GetNormal(), normal_))) 336 (instances_[i]->HasNormal() &&
341 { 337 !IsParallelOrOpposite(instances_[i]->GetNormal(), normal_)))
342 sortedInstances_.push_back(instances_[i]); 338 {
343 } 339 return false;
344 } 340 }
345
346 if (sortedInstances_.size() == 0)
347 {
348 return false;
349 } 341 }
350 342
351 PositionComparator comparator(normal_); 343 PositionComparator comparator(normal_);
352 std::sort(sortedInstances_.begin(), sortedInstances_.end(), comparator); 344 std::sort(instances_.begin(), instances_.end(), comparator);
353 345
354 float a = sortedInstances_[0]->ComputeRelativePosition(normal_); 346 float a = instances_[0]->ComputeRelativePosition(normal_);
355 for (size_t i = 1; i < sortedInstances_.size(); i++) 347 for (size_t i = 1; i < instances_.size(); i++)
356 { 348 {
357 float b = sortedInstances_[i]->ComputeRelativePosition(normal_); 349 float b = instances_[i]->ComputeRelativePosition(normal_);
358 350
359 if (std::fabs(b - a) <= 10.0f * std::numeric_limits<float>::epsilon()) 351 if (std::fabs(b - a) <= 10.0f * std::numeric_limits<float>::epsilon())
360 { 352 {
361 // Not enough space between two slices along the normal of the volume 353 // Not enough space between two slices along the normal of the volume
362 return false; 354 return false;
374 bool SliceOrdering::SortUsingIndexInSeries() 366 bool SliceOrdering::SortUsingIndexInSeries()
375 { 367 {
376 if (instances_.size() <= 1) 368 if (instances_.size() <= 1)
377 { 369 {
378 // One single instance: It is sorted by default 370 // One single instance: It is sorted by default
379 sortedInstances_ = instances_;
380 return true; 371 return true;
381 } 372 }
382 373
383 sortedInstances_.clear();
384
385 // consider only the instances with an index
386 for (size_t i = 0; i < instances_.size(); i++) 374 for (size_t i = 0; i < instances_.size(); i++)
387 { 375 {
388 assert(instances_[i] != NULL); 376 assert(instances_[i] != NULL);
389 if (instances_[i]->HasIndexInSeries()) 377 if (!instances_[i]->HasIndexInSeries())
390 { 378 {
391 sortedInstances_.push_back(instances_[i]); 379 return false;
392 } 380 }
393 } 381 }
394 382
395 if (sortedInstances_.size() == 0) // if we were not able to sort instances because none of them had an index, return all instances in a "random" order 383 std::sort(instances_.begin(), instances_.end(), IndexInSeriesComparator);
396 { 384
397 sortedInstances_ = instances_; 385 for (size_t i = 1; i < instances_.size(); i++)
398 } 386 {
399 else 387 if (instances_[i - 1]->GetIndexInSeries() == instances_[i]->GetIndexInSeries())
400 { 388 {
401 std::sort(sortedInstances_.begin(), sortedInstances_.end(), IndexInSeriesComparator); 389 // The current "IndexInSeries" occurs 2 times: Not a proper ordering
402 390 LOG(WARNING) << "This series contains 2 slices with the same index, trying to display it anyway";
403 for (size_t i = 1; i < sortedInstances_.size(); i++) 391 break;
404 {
405 if (sortedInstances_[i - 1]->GetIndexInSeries() == sortedInstances_[i]->GetIndexInSeries())
406 {
407 // The current "IndexInSeries" occurs 2 times: Not a proper ordering
408 LOG(WARNING) << "This series contains 2 slices with the same index, trying to display it anyway";
409 break;
410 }
411 } 392 }
412 } 393 }
413 394
414 return true; 395 return true;
415 } 396 }
444 } 425 }
445 } 426 }
446 } 427 }
447 428
448 429
449 const std::string& SliceOrdering::GetSortedInstanceId(size_t index) const 430 const std::string& SliceOrdering::GetInstanceId(size_t index) const
450 { 431 {
451 if (index >= sortedInstances_.size()) 432 if (index >= instances_.size())
452 { 433 {
453 throw OrthancException(ErrorCode_ParameterOutOfRange); 434 throw OrthancException(ErrorCode_ParameterOutOfRange);
454 } 435 }
455 else 436 else
456 { 437 {
457 return sortedInstances_[index]->GetIdentifier(); 438 return instances_[index]->GetIdentifier();
458 } 439 }
459 } 440 }
460 441
461 442
462 unsigned int SliceOrdering::GetSortedInstanceFramesCount(size_t index) const 443 unsigned int SliceOrdering::GetFramesCount(size_t index) const
463 { 444 {
464 if (index >= sortedInstances_.size()) 445 if (index >= instances_.size())
465 { 446 {
466 throw OrthancException(ErrorCode_ParameterOutOfRange); 447 throw OrthancException(ErrorCode_ParameterOutOfRange);
467 } 448 }
468 else 449 else
469 { 450 {
470 return sortedInstances_[index]->GetFramesCount(); 451 return instances_[index]->GetFramesCount();
471 } 452 }
472 } 453 }
473 454
474 455
475 void SliceOrdering::Format(Json::Value& result) const 456 void SliceOrdering::Format(Json::Value& result) const
476 { 457 {
477 result = Json::objectValue; 458 result = Json::objectValue;
478 result["Type"] = (isVolume_ ? "Volume" : "Sequence"); 459 result["Type"] = (isVolume_ ? "Volume" : "Sequence");
479 460
480 Json::Value tmp = Json::arrayValue; 461 Json::Value tmp = Json::arrayValue;
481 for (size_t i = 0; i < GetSortedInstancesCount(); i++) 462 for (size_t i = 0; i < GetInstancesCount(); i++)
482 { 463 {
483 tmp.append(GetBasePath(ResourceType_Instance, GetSortedInstanceId(i)) + "/file"); 464 tmp.append(GetBasePath(ResourceType_Instance, GetInstanceId(i)) + "/file");
484 } 465 }
485 466
486 result["Dicom"] = tmp; 467 result["Dicom"] = tmp;
487 468
488 Json::Value slicesShort = Json::arrayValue; 469 Json::Value slicesShort = Json::arrayValue;
489 470
490 tmp.clear(); 471 tmp.clear();
491 for (size_t i = 0; i < GetSortedInstancesCount(); i++) 472 for (size_t i = 0; i < GetInstancesCount(); i++)
492 { 473 {
493 std::string base = GetBasePath(ResourceType_Instance, GetSortedInstanceId(i)); 474 std::string base = GetBasePath(ResourceType_Instance, GetInstanceId(i));
494 for (size_t j = 0; j < GetSortedInstanceFramesCount(i); j++) 475 for (size_t j = 0; j < GetFramesCount(i); j++)
495 { 476 {
496 tmp.append(base + "/frames/" + boost::lexical_cast<std::string>(j)); 477 tmp.append(base + "/frames/" + boost::lexical_cast<std::string>(j));
497 } 478 }
498 479
499 Json::Value tmp2 = Json::arrayValue; 480 Json::Value tmp2 = Json::arrayValue;
500 tmp2.append(GetSortedInstanceId(i)); 481 tmp2.append(GetInstanceId(i));
501 tmp2.append(0); 482 tmp2.append(0);
502 tmp2.append(GetSortedInstanceFramesCount(i)); 483 tmp2.append(GetFramesCount(i));
503 484
504 slicesShort.append(tmp2); 485 slicesShort.append(tmp2);
505 } 486 }
506 487
507 result["Slices"] = tmp; 488 result["Slices"] = tmp;