Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/RadiotherapyRestApi.cpp @ 764:2f7802e95dd0 dicom-rt
fix build
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Apr 2014 16:09:55 +0200 |
parents | 12a3f2eaa99a |
children | c19552f604d5 |
comparison
equal
deleted
inserted
replaced
761:12a3f2eaa99a | 764:2f7802e95dd0 |
---|---|
28 * You should have received a copy of the GNU General Public License | 28 * You should have received a copy of the GNU General Public License |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #include "RadiotherapyRestApi.h" | 33 #include "OrthancRestApi.h" |
34 | 34 |
35 #include "ServerToolbox.h" | 35 #include "../ServerToolbox.h" |
36 | 36 |
37 #define RETRIEVE_CONTEXT(call) \ | |
38 OrthancRestApi& contextApi = \ | |
39 dynamic_cast<OrthancRestApi&>(call.GetContext()); \ | |
40 ServerContext& context = contextApi.GetContext() | |
41 | 37 |
42 | 38 |
43 // DICOM tags for RT-STRUCT | 39 // DICOM tags for RT-STRUCT |
44 | 40 |
45 /** | 41 /** |
118 | 114 |
119 static bool ContourToPoints(Json::Value& result, | 115 static bool ContourToPoints(Json::Value& result, |
120 const Json::Value& source) | 116 const Json::Value& source) |
121 { | 117 { |
122 std::vector<std::string> points; | 118 std::vector<std::string> points; |
123 Toolbox::Split(points, source.asString(), '\\'); | 119 Toolbox::TokenizeString(points, source.asString(), '\\'); |
124 | 120 |
125 if (points.size() % 3 != 0) | 121 if (points.size() % 3 != 0) |
126 { | 122 { |
127 return false; | 123 return false; |
128 } | 124 } |
244 contour.isMember(ROI_DISPLAY_COLOR) && | 240 contour.isMember(ROI_DISPLAY_COLOR) && |
245 contour.isMember(CONTOUR_SEQUENCE) && | 241 contour.isMember(CONTOUR_SEQUENCE) && |
246 contour[REFERENCED_ROI_NUMBER]["Value"].asString() == roiNumber) | 242 contour[REFERENCED_ROI_NUMBER]["Value"].asString() == roiNumber) |
247 { | 243 { |
248 std::vector<std::string> color; | 244 std::vector<std::string> color; |
249 Toolbox::Split(color, contour[ROI_DISPLAY_COLOR]["Value"].asString(), '\\'); | 245 Toolbox::TokenizeString(color, contour[ROI_DISPLAY_COLOR]["Value"].asString(), '\\'); |
250 | 246 |
251 result["DisplayColor"] = Json::arrayValue; | 247 result["DisplayColor"] = Json::arrayValue; |
252 if (color.size() != 3) | 248 if (color.size() != 3) |
253 { | 249 { |
254 return false; | 250 return false; |
362 | 358 |
363 | 359 |
364 | 360 |
365 static void GetRtStructuresInfo(RestApi::GetCall& call) | 361 static void GetRtStructuresInfo(RestApi::GetCall& call) |
366 { | 362 { |
367 RETRIEVE_CONTEXT(call); | 363 ServerContext& context = OrthancRestApi::GetContext(call); |
368 | 364 |
369 Json::Value study, series, content; | 365 Json::Value study, series, content; |
370 std::string frameOfReference; | 366 std::string frameOfReference; |
371 if (GetRtStructuresInfo(study, series, content, frameOfReference, context, call.GetUriComponent("id", ""))) | 367 if (GetRtStructuresInfo(study, series, content, frameOfReference, context, call.GetUriComponent("id", ""))) |
372 { | 368 { |
400 } | 396 } |
401 | 397 |
402 | 398 |
403 static void GetRtStructuresListOfROIs(RestApi::GetCall& call) | 399 static void GetRtStructuresListOfROIs(RestApi::GetCall& call) |
404 { | 400 { |
405 RETRIEVE_CONTEXT(call); | 401 ServerContext& context = OrthancRestApi::GetContext(call); |
406 | 402 |
407 Json::Value study, series, content; | 403 Json::Value study, series, content; |
408 std::string frameOfReference; | 404 std::string frameOfReference; |
409 if (GetRtStructuresInfo(study, series, content, frameOfReference, context, call.GetUriComponent("id", ""))) | 405 if (GetRtStructuresInfo(study, series, content, frameOfReference, context, call.GetUriComponent("id", ""))) |
410 { | 406 { |
426 } | 422 } |
427 | 423 |
428 | 424 |
429 static void GetRtStructuresROI(RestApi::GetCall& call) | 425 static void GetRtStructuresROI(RestApi::GetCall& call) |
430 { | 426 { |
431 RETRIEVE_CONTEXT(call); | 427 ServerContext& context = OrthancRestApi::GetContext(call); |
432 | 428 |
433 Json::Value roi, contour; | 429 Json::Value roi, contour; |
434 std::string instanceId; | 430 std::string instanceId; |
435 | 431 |
436 if (GetRtStructuresRoi(roi, contour, instanceId, context, | 432 if (GetRtStructuresRoi(roi, contour, instanceId, context, |
437 call.GetUriComponent("id", ""), | 433 call.GetUriComponent("id", ""), |
438 call.GetUriComponent("roi", ""))) | 434 call.GetUriComponent("roi", ""))) |
439 { | 435 { |
440 roi.removeMember("InternalIndex"); | 436 roi.removeMember("InternalIndex"); |
441 call.GetOutput().AnswerJson(roi); | 437 call.GetOutput().AnswerJson(roi); |
442 } | 438 } |
443 } | 439 } |
444 | 440 |
445 | 441 |
446 static void GetRtStructuresROIPoints(RestApi::GetCall& call) | 442 static void GetRtStructuresROIPoints(RestApi::GetCall& call) |
447 { | 443 { |
448 RETRIEVE_CONTEXT(call); | 444 ServerContext& context = OrthancRestApi::GetContext(call); |
449 | 445 |
450 Json::Value roi, contour; | 446 Json::Value roi, contour; |
451 std::string instanceId; | 447 std::string instanceId; |
452 | 448 |
453 if (GetRtStructuresRoi(roi, contour, instanceId, context, | 449 if (GetRtStructuresRoi(roi, contour, instanceId, context, |
454 call.GetUriComponent("id", ""), | 450 call.GetUriComponent("id", ""), |
455 call.GetUriComponent("roi", ""))) | 451 call.GetUriComponent("roi", ""))) |
456 { | 452 { |
457 Json::Value result = Json::arrayValue; | 453 Json::Value result = Json::arrayValue; |
458 | 454 |
459 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) | 455 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) |
460 { | 456 { |
461 if (contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "POINT") | 457 if (contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "POINT") |
462 { | 458 { |
463 Json::Value p; | 459 Json::Value p; |
464 if (ContourToPoints(p, contour[i][CONTOUR_DATA]["Value"].asString()) && | 460 if (ContourToPoints(p, contour[i][CONTOUR_DATA]["Value"].asString()) && |
465 p.size() == 1) | 461 p.size() == 1) |
466 { | 462 { |
467 result.append(p[0]); | 463 result.append(p[0]); |
468 } | 464 } |
469 } | 465 } |
470 } | 466 } |
471 | 467 |
472 call.GetOutput().AnswerJson(result); | 468 call.GetOutput().AnswerJson(result); |
473 } | 469 } |
474 } | 470 } |
475 | 471 |
476 | 472 |
477 static void GetRtStructuresListOfClosedPlanars(RestApi::GetCall& call) | 473 static void GetRtStructuresListOfClosedPlanars(RestApi::GetCall& call) |
478 { | 474 { |
479 RETRIEVE_CONTEXT(call); | 475 ServerContext& context = OrthancRestApi::GetContext(call); |
480 | 476 |
481 Json::Value roi, contour; | 477 Json::Value roi, contour; |
482 std::string instanceId; | 478 std::string instanceId; |
483 | 479 |
484 if (GetRtStructuresRoi(roi, contour, instanceId, context, | 480 if (GetRtStructuresRoi(roi, contour, instanceId, context, |
485 call.GetUriComponent("id", ""), | 481 call.GetUriComponent("id", ""), |
486 call.GetUriComponent("roi", ""))) | 482 call.GetUriComponent("roi", ""))) |
487 { | 483 { |
488 Json::Value result = Json::arrayValue; | 484 Json::Value result = Json::arrayValue; |
489 | 485 |
490 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) | 486 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) |
491 { | 487 { |
492 if (contour[i].isMember(CONTOUR_IMAGE_SEQUENCE) && | 488 if (contour[i].isMember(CONTOUR_IMAGE_SEQUENCE) && |
493 contour[i].isMember(CONTOUR_GEOMETRIC_TYPE) && | 489 contour[i].isMember(CONTOUR_GEOMETRIC_TYPE) && |
494 contour[i].isMember(NUMBER_OF_CONTOUR_POINTS) && | 490 contour[i].isMember(NUMBER_OF_CONTOUR_POINTS) && |
495 contour[i].isMember(CONTOUR_DATA) && | 491 contour[i].isMember(CONTOUR_DATA) && |
496 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"].size() == 1 && | 492 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"].size() == 1 && |
497 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0].isMember(REFERENCED_SOP_INSTANCE_UID) && | 493 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0].isMember(REFERENCED_SOP_INSTANCE_UID) && |
498 contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "CLOSED_PLANAR") | 494 contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "CLOSED_PLANAR") |
499 { | 495 { |
500 result.append(i); | 496 result.append(i); |
501 } | 497 } |
502 } | 498 } |
503 | 499 |
504 call.GetOutput().AnswerJson(result); | 500 call.GetOutput().AnswerJson(result); |
505 } | 501 } |
506 } | 502 } |
507 | 503 |
508 | 504 |
509 static void GetRtStructuresSingleClosedPlanar(RestApi::GetCall& call) | 505 static void GetRtStructuresSingleClosedPlanar(RestApi::GetCall& call) |
510 { | 506 { |
511 RETRIEVE_CONTEXT(call); | 507 ServerContext& context = OrthancRestApi::GetContext(call); |
512 | 508 |
513 Json::Value roi, contour, result; | 509 Json::Value roi, contour, result; |
514 std::string instanceId; | 510 std::string instanceId; |
515 | 511 |
516 if (GetRtStructuresRoi(roi, contour, instanceId, context, | 512 if (GetRtStructuresRoi(roi, contour, instanceId, context, |
517 call.GetUriComponent("id", ""), | 513 call.GetUriComponent("id", ""), |
518 call.GetUriComponent("roi", ""))) | 514 call.GetUriComponent("roi", ""))) |
519 { | 515 { |
520 unsigned int index = boost::lexical_cast<unsigned int>(call.GetUriComponent("polygon", "")); | 516 unsigned int index = boost::lexical_cast<unsigned int>(call.GetUriComponent("polygon", "")); |
521 | 517 |
522 if (GetClosedPlanarPoints(result, context, instanceId, roi, index)) | 518 if (GetClosedPlanarPoints(result, context, instanceId, roi, index)) |
523 { | 519 { |
524 call.GetOutput().AnswerJson(result); | 520 call.GetOutput().AnswerJson(result); |
525 } | 521 } |
526 } | 522 } |
527 } | 523 } |
528 | 524 |
529 | 525 |
530 static void GetRtStructuresClosedPlanarThickness(RestApi::GetCall& call) | 526 static void GetRtStructuresClosedPlanarThickness(RestApi::GetCall& call) |
531 { | 527 { |
532 RETRIEVE_CONTEXT(call); | 528 ServerContext& context = OrthancRestApi::GetContext(call); |
533 | 529 |
534 Json::Value roi, contour; | 530 Json::Value roi, contour; |
535 std::string instanceId; | 531 std::string instanceId; |
536 | 532 |
537 if (GetRtStructuresRoi(roi, contour, instanceId, context, | 533 if (GetRtStructuresRoi(roi, contour, instanceId, context, |
538 call.GetUriComponent("id", ""), | 534 call.GetUriComponent("id", ""), |
539 call.GetUriComponent("roi", ""))) | 535 call.GetUriComponent("roi", ""))) |
540 { | 536 { |
541 unsigned int index = boost::lexical_cast<unsigned int>(call.GetUriComponent("polygon", "")); | 537 unsigned int index = boost::lexical_cast<unsigned int>(call.GetUriComponent("polygon", "")); |
542 | 538 |
543 float thickness; | 539 float thickness; |
544 if (GetRtStructuresClosedPlanarThickness(thickness, context, contour[index])) | 540 if (GetRtStructuresClosedPlanarThickness(thickness, context, contour[index])) |
545 { | 541 { |
546 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(thickness), "text/plain"); | 542 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(thickness), "text/plain"); |
547 } | 543 } |
548 } | 544 } |
549 } | 545 } |
550 | 546 |
551 | 547 |
552 static bool ComputeClosedPlanarArea(double& area, | 548 static bool ComputeClosedPlanarArea(double& area, |
553 const Json::Value& vertices) | 549 const Json::Value& vertices) |
593 } | 589 } |
594 | 590 |
595 | 591 |
596 static void GetRtStructuresClosedPlanarArea(RestApi::GetCall& call) | 592 static void GetRtStructuresClosedPlanarArea(RestApi::GetCall& call) |
597 { | 593 { |
598 RETRIEVE_CONTEXT(call); | 594 ServerContext& context = OrthancRestApi::GetContext(call); |
599 | 595 |
600 Json::Value roi, contour, vertices; | 596 Json::Value roi, contour, vertices; |
601 std::string instanceId; | 597 std::string instanceId; |
602 | 598 |
603 if (GetRtStructuresRoi(roi, contour, instanceId, context, | 599 if (GetRtStructuresRoi(roi, contour, instanceId, context, |
604 call.GetUriComponent("id", ""), | 600 call.GetUriComponent("id", ""), |
605 call.GetUriComponent("roi", ""))) | 601 call.GetUriComponent("roi", ""))) |
606 { | 602 { |
607 unsigned int index = boost::lexical_cast<unsigned int>(call.GetUriComponent("polygon", "")); | 603 unsigned int index = boost::lexical_cast<unsigned int>(call.GetUriComponent("polygon", "")); |
608 | 604 |
609 double area; | 605 double area; |
610 if (GetClosedPlanarPoints(vertices, context, instanceId, roi, index) && | 606 if (GetClosedPlanarPoints(vertices, context, instanceId, roi, index) && |
611 ComputeClosedPlanarArea(area, vertices)) | 607 ComputeClosedPlanarArea(area, vertices)) |
612 { | 608 { |
613 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(area), "text/plain"); | 609 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(area), "text/plain"); |
614 } | 610 } |
615 } | 611 } |
616 } | 612 } |
617 | 613 |
618 | 614 |
619 static void GetRtStructuresInstanceOfClosedPlanar(RestApi::GetCall& call) | 615 static void GetRtStructuresInstanceOfClosedPlanar(RestApi::GetCall& call) |
620 { | 616 { |
621 RETRIEVE_CONTEXT(call); | 617 ServerContext& context = OrthancRestApi::GetContext(call); |
622 | 618 |
623 Json::Value roi, contour; | 619 Json::Value roi, contour; |
624 std::string instanceId; | 620 std::string instanceId; |
625 | 621 |
626 if (GetRtStructuresRoi(roi, contour, instanceId, context, | 622 if (GetRtStructuresRoi(roi, contour, instanceId, context, |
638 } | 634 } |
639 | 635 |
640 | 636 |
641 static void GetRtStructuresListOfInstances(RestApi::GetCall& call) | 637 static void GetRtStructuresListOfInstances(RestApi::GetCall& call) |
642 { | 638 { |
643 RETRIEVE_CONTEXT(call); | 639 ServerContext& context = OrthancRestApi::GetContext(call); |
644 | 640 |
645 Json::Value roi, contour; | 641 Json::Value roi, contour; |
646 std::string instanceId; | 642 std::string instanceId; |
647 | 643 |
648 if (GetRtStructuresRoi(roi, contour, instanceId, context, | 644 if (GetRtStructuresRoi(roi, contour, instanceId, context, |
649 call.GetUriComponent("id", ""), | 645 call.GetUriComponent("id", ""), |
650 call.GetUriComponent("roi", ""))) | 646 call.GetUriComponent("roi", ""))) |
651 { | 647 { |
652 Json::Value result = Json::arrayValue; | 648 Json::Value result = Json::arrayValue; |
653 | 649 |
654 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) | 650 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) |
655 { | 651 { |
656 if (contour[i].isMember(CONTOUR_IMAGE_SEQUENCE) && | 652 if (contour[i].isMember(CONTOUR_IMAGE_SEQUENCE) && |
657 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"].size() == 1 && | 653 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"].size() == 1 && |
658 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0].isMember(REFERENCED_SOP_INSTANCE_UID)) | 654 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0].isMember(REFERENCED_SOP_INSTANCE_UID)) |
659 { | 655 { |
660 std::string uid = contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0][REFERENCED_SOP_INSTANCE_UID]["Value"].asString(); | 656 std::string uid = contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0][REFERENCED_SOP_INSTANCE_UID]["Value"].asString(); |
661 | 657 |
662 std::list<std::string> instance; | 658 std::list<std::string> instance; |
663 context.GetIndex().LookupTagValue(instance, DICOM_TAG_SOP_INSTANCE_UID, uid); | 659 context.GetIndex().LookupTagValue(instance, DICOM_TAG_SOP_INSTANCE_UID, uid); |
664 | 660 |
665 if (instance.size() == 1) | 661 if (instance.size() == 1) |
666 { | 662 { |
667 result.append(instance.front()); | 663 result.append(instance.front()); |
668 } | 664 } |
669 } | 665 } |
670 } | 666 } |
671 | 667 |
672 call.GetOutput().AnswerJson(result); | 668 call.GetOutput().AnswerJson(result); |
673 } | 669 } |
674 } | 670 } |
675 | 671 |
676 | 672 |
677 | 673 |
678 static void GetRtStructuresClosedPlanarsOfInstance(RestApi::GetCall& call) | 674 static void GetRtStructuresClosedPlanarsOfInstance(RestApi::GetCall& call) |
679 { | 675 { |
680 RETRIEVE_CONTEXT(call); | 676 ServerContext& context = OrthancRestApi::GetContext(call); |
681 | 677 |
682 Json::Value roi, contour, instance; | 678 Json::Value roi, contour, instance; |
683 std::string instanceId; | 679 std::string instanceId; |
684 | 680 |
685 if (context.GetIndex().LookupResource(instance, call.GetUriComponent("instance", ""), ResourceType_Instance) && | 681 if (context.GetIndex().LookupResource(instance, call.GetUriComponent("instance", ""), ResourceType_Instance) && |
686 GetRtStructuresRoi(roi, contour, instanceId, context, | 682 GetRtStructuresRoi(roi, contour, instanceId, context, |
687 call.GetUriComponent("id", ""), | 683 call.GetUriComponent("id", ""), |
688 call.GetUriComponent("roi", ""))) | 684 call.GetUriComponent("roi", ""))) |
689 { | 685 { |
690 Json::Value result = Json::arrayValue; | 686 Json::Value result = Json::arrayValue; |
691 | 687 |
692 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) | 688 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) |
693 { | 689 { |
694 if (contour[i].isMember(CONTOUR_DATA) && | 690 if (contour[i].isMember(CONTOUR_DATA) && |
695 contour[i].isMember(CONTOUR_IMAGE_SEQUENCE) && | 691 contour[i].isMember(CONTOUR_IMAGE_SEQUENCE) && |
696 contour[i].isMember(NUMBER_OF_CONTOUR_POINTS) && | 692 contour[i].isMember(NUMBER_OF_CONTOUR_POINTS) && |
697 contour[i].isMember(CONTOUR_GEOMETRIC_TYPE) && | 693 contour[i].isMember(CONTOUR_GEOMETRIC_TYPE) && |
698 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"].size() == 1 && | 694 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"].size() == 1 && |
699 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0].isMember(REFERENCED_SOP_INSTANCE_UID) && | 695 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0].isMember(REFERENCED_SOP_INSTANCE_UID) && |
700 contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "CLOSED_PLANAR") | 696 contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "CLOSED_PLANAR") |
701 { | 697 { |
702 std::string uid = contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0][REFERENCED_SOP_INSTANCE_UID]["Value"].asString(); | 698 std::string uid = contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0][REFERENCED_SOP_INSTANCE_UID]["Value"].asString(); |
703 | 699 |
704 Json::Value points; | 700 Json::Value points; |
705 if (uid == instance["MainDicomTags"]["SOPInstanceUID"].asString() && | 701 if (uid == instance["MainDicomTags"]["SOPInstanceUID"].asString() && |
706 GetClosedPlanarPoints(points, context, instanceId, roi, i)) | 702 GetClosedPlanarPoints(points, context, instanceId, roi, i)) |
707 { | 703 { |
708 result.append(points); | 704 result.append(points); |
709 } | 705 } |
710 } | 706 } |
711 } | 707 } |
712 | 708 |
713 call.GetOutput().AnswerJson(result); | 709 call.GetOutput().AnswerJson(result); |
714 } | 710 } |
715 } | 711 } |
716 | 712 |
717 | 713 |
718 | 714 |
719 static void GetRtStructuresPointsOfInstance(RestApi::GetCall& call) | 715 static void GetRtStructuresPointsOfInstance(RestApi::GetCall& call) |
720 { | 716 { |
721 RETRIEVE_CONTEXT(call); | 717 ServerContext& context = OrthancRestApi::GetContext(call); |
722 | 718 |
723 Json::Value roi, contour, instance; | 719 Json::Value roi, contour, instance; |
724 std::string instanceId; | 720 std::string instanceId; |
725 | 721 |
726 if (context.GetIndex().LookupResource(instance, call.GetUriComponent("instance", ""), ResourceType_Instance) && | 722 if (context.GetIndex().LookupResource(instance, call.GetUriComponent("instance", ""), ResourceType_Instance) && |
727 GetRtStructuresRoi(roi, contour, instanceId, context, | 723 GetRtStructuresRoi(roi, contour, instanceId, context, |
728 call.GetUriComponent("id", ""), | 724 call.GetUriComponent("id", ""), |
729 call.GetUriComponent("roi", ""))) | 725 call.GetUriComponent("roi", ""))) |
730 { | 726 { |
731 Json::Value result = Json::arrayValue; | 727 Json::Value result = Json::arrayValue; |
732 | 728 |
733 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) | 729 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) |
734 { | 730 { |
735 if (contour[i].isMember(CONTOUR_DATA) && | 731 if (contour[i].isMember(CONTOUR_DATA) && |
736 contour[i].isMember(CONTOUR_IMAGE_SEQUENCE) && | 732 contour[i].isMember(CONTOUR_IMAGE_SEQUENCE) && |
737 contour[i].isMember(CONTOUR_GEOMETRIC_TYPE) && | 733 contour[i].isMember(CONTOUR_GEOMETRIC_TYPE) && |
738 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"].size() == 1 && | 734 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"].size() == 1 && |
739 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0].isMember(REFERENCED_SOP_INSTANCE_UID) && | 735 contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0].isMember(REFERENCED_SOP_INSTANCE_UID) && |
740 contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "POINT") | 736 contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "POINT") |
741 { | 737 { |
742 std::string uid = contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0][REFERENCED_SOP_INSTANCE_UID]["Value"].asString(); | 738 std::string uid = contour[i][CONTOUR_IMAGE_SEQUENCE]["Value"][0][REFERENCED_SOP_INSTANCE_UID]["Value"].asString(); |
743 | 739 |
744 if (uid == instance["MainDicomTags"]["SOPInstanceUID"].asString()) | 740 if (uid == instance["MainDicomTags"]["SOPInstanceUID"].asString()) |
745 { | 741 { |
746 Json::Value p; | 742 Json::Value p; |
747 if (ContourToPoints(p, contour[i][CONTOUR_DATA]["Value"].asString()) && | 743 if (ContourToPoints(p, contour[i][CONTOUR_DATA]["Value"].asString()) && |
748 p.size() == 1) | 744 p.size() == 1) |
749 { | 745 { |
750 result.append(p[0]); | 746 result.append(p[0]); |
751 } | 747 } |
752 } | 748 } |
753 } | 749 } |
754 } | 750 } |
755 | 751 |
756 call.GetOutput().AnswerJson(result); | 752 call.GetOutput().AnswerJson(result); |
757 } | 753 } |
758 } | 754 } |
759 | 755 |
760 | 756 |
761 static void GetRtStructuresVolume(RestApi::GetCall& call) | 757 static void GetRtStructuresVolume(RestApi::GetCall& call) |
762 { | 758 { |
763 RETRIEVE_CONTEXT(call); | 759 ServerContext& context = OrthancRestApi::GetContext(call); |
764 | 760 |
765 Json::Value roi, contour, vertices; | 761 Json::Value roi, contour, vertices; |
766 std::string instanceId; | 762 std::string instanceId; |
767 | 763 |
768 if (GetRtStructuresRoi(roi, contour, instanceId, context, | 764 if (GetRtStructuresRoi(roi, contour, instanceId, context, |
769 call.GetUriComponent("id", ""), | 765 call.GetUriComponent("id", ""), |
770 call.GetUriComponent("roi", ""))) | 766 call.GetUriComponent("roi", ""))) |
771 { | 767 { |
772 double volume = 0; | 768 double volume = 0; |
773 | 769 |
774 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) | 770 for (Json::Value::ArrayIndex i = 0; i < contour.size(); i++) |
775 { | 771 { |
776 double area; | 772 double area; |
777 float thickness; | 773 float thickness; |
778 | 774 |
779 if (contour[i].isMember(CONTOUR_GEOMETRIC_TYPE) && | 775 if (contour[i].isMember(CONTOUR_GEOMETRIC_TYPE) && |
780 contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "CLOSED_PLANAR" && | 776 contour[i][CONTOUR_GEOMETRIC_TYPE]["Value"].asString() == "CLOSED_PLANAR" && |
781 GetClosedPlanarPoints(vertices, context, instanceId, roi, i) && | 777 GetClosedPlanarPoints(vertices, context, instanceId, roi, i) && |
782 ComputeClosedPlanarArea(area, vertices) && | 778 ComputeClosedPlanarArea(area, vertices) && |
783 GetRtStructuresClosedPlanarThickness(thickness, context, contour[i])) | 779 GetRtStructuresClosedPlanarThickness(thickness, context, contour[i])) |
784 { | 780 { |
785 volume += area * static_cast<double>(thickness); | 781 volume += area * static_cast<double>(thickness); |
786 } | 782 } |
787 } | 783 } |
788 | 784 |
789 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(volume), "text/plain"); | 785 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(volume), "text/plain"); |
790 } | 786 } |
791 } | 787 } |
792 | 788 |
793 | 789 |
794 RadiotherapyRestApi::RadiotherapyRestApi(ServerContext& context) : OrthancRestApi(context) | 790 void OrthancRestApi::RegisterRadiotherapy() |
795 { | 791 { |
796 Register("/series/{id}/rt-structures", GetRtStructuresInfo); | 792 Register("/series/{id}/rt-structures", GetRtStructuresInfo); |
797 Register("/series/{id}/rt-structures/roi", GetRtStructuresListOfROIs); | 793 Register("/series/{id}/rt-structures/roi", GetRtStructuresListOfROIs); |
798 Register("/series/{id}/rt-structures/roi/{roi}/info", GetRtStructuresROI); | 794 Register("/series/{id}/rt-structures/roi/{roi}/info", GetRtStructuresROI); |
799 Register("/series/{id}/rt-structures/roi/{roi}/points", GetRtStructuresROIPoints); | 795 Register("/series/{id}/rt-structures/roi/{roi}/points", GetRtStructuresROIPoints); |