Mercurial > hg > orthanc-stone
comparison Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp @ 1800:2c0497d61a5d
unserialization of annotations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 May 2021 12:05:15 +0200 |
parents | 1125793d82d3 |
children | 64dad1d7aca4 |
comparison
equal
deleted
inserted
replaced
1799:1125793d82d3 | 1800:2c0497d61a5d |
---|---|
650 { | 650 { |
651 } | 651 } |
652 | 652 |
653 virtual ~Text() | 653 virtual ~Text() |
654 { | 654 { |
655 if (content_.get() != NULL) | 655 if (!first_) |
656 { | 656 { |
657 that_.TagSubLayerToRemove(subLayer_); | 657 that_.TagSubLayerToRemove(subLayer_); |
658 } | 658 } |
659 } | 659 } |
660 | 660 |
846 target[KEY_X1] = handle1_.GetCenter().GetX(); | 846 target[KEY_X1] = handle1_.GetCenter().GetX(); |
847 target[KEY_Y1] = handle1_.GetCenter().GetY(); | 847 target[KEY_Y1] = handle1_.GetCenter().GetY(); |
848 target[KEY_X2] = handle2_.GetCenter().GetX(); | 848 target[KEY_X2] = handle2_.GetCenter().GetX(); |
849 target[KEY_Y2] = handle2_.GetCenter().GetY(); | 849 target[KEY_Y2] = handle2_.GetCenter().GetY(); |
850 } | 850 } |
851 | |
852 static void Unserialize(AnnotationsOverlay& target, | |
853 const Json::Value& source) | |
854 { | |
855 if (source.isMember(KEY_X1) && | |
856 source.isMember(KEY_Y1) && | |
857 source.isMember(KEY_X2) && | |
858 source.isMember(KEY_Y2) && | |
859 source[KEY_X1].isNumeric() && | |
860 source[KEY_Y1].isNumeric() && | |
861 source[KEY_X2].isNumeric() && | |
862 source[KEY_Y2].isNumeric()) | |
863 { | |
864 new SegmentAnnotation(target, true, | |
865 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), | |
866 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); | |
867 } | |
868 else | |
869 { | |
870 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an segment annotation"); | |
871 } | |
872 } | |
851 }; | 873 }; |
852 | 874 |
853 | 875 |
854 class AngleAnnotation : public Annotation | 876 class AngleAnnotation : public Annotation |
855 { | 877 { |
962 target[KEY_X2] = middleHandle_.GetCenter().GetX(); | 984 target[KEY_X2] = middleHandle_.GetCenter().GetX(); |
963 target[KEY_Y2] = middleHandle_.GetCenter().GetY(); | 985 target[KEY_Y2] = middleHandle_.GetCenter().GetY(); |
964 target[KEY_X3] = endHandle_.GetCenter().GetX(); | 986 target[KEY_X3] = endHandle_.GetCenter().GetX(); |
965 target[KEY_Y3] = endHandle_.GetCenter().GetY(); | 987 target[KEY_Y3] = endHandle_.GetCenter().GetY(); |
966 } | 988 } |
989 | |
990 static void Unserialize(AnnotationsOverlay& target, | |
991 const Json::Value& source) | |
992 { | |
993 if (source.isMember(KEY_X1) && | |
994 source.isMember(KEY_Y1) && | |
995 source.isMember(KEY_X2) && | |
996 source.isMember(KEY_Y2) && | |
997 source.isMember(KEY_X3) && | |
998 source.isMember(KEY_Y3) && | |
999 source[KEY_X1].isNumeric() && | |
1000 source[KEY_Y1].isNumeric() && | |
1001 source[KEY_X2].isNumeric() && | |
1002 source[KEY_Y2].isNumeric() && | |
1003 source[KEY_X3].isNumeric() && | |
1004 source[KEY_Y3].isNumeric()) | |
1005 { | |
1006 new AngleAnnotation(target, | |
1007 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), | |
1008 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble()), | |
1009 ScenePoint2D(source[KEY_X3].asDouble(), source[KEY_Y3].asDouble())); | |
1010 } | |
1011 else | |
1012 { | |
1013 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an angle annotation"); | |
1014 } | |
1015 } | |
967 }; | 1016 }; |
968 | 1017 |
969 | 1018 |
970 class CircleAnnotation : public Annotation | 1019 class CircleAnnotation : public Annotation |
971 { | 1020 { |
1059 target[KEY_X1] = handle1_.GetCenter().GetX(); | 1108 target[KEY_X1] = handle1_.GetCenter().GetX(); |
1060 target[KEY_Y1] = handle1_.GetCenter().GetY(); | 1109 target[KEY_Y1] = handle1_.GetCenter().GetY(); |
1061 target[KEY_X2] = handle2_.GetCenter().GetX(); | 1110 target[KEY_X2] = handle2_.GetCenter().GetX(); |
1062 target[KEY_Y2] = handle2_.GetCenter().GetY(); | 1111 target[KEY_Y2] = handle2_.GetCenter().GetY(); |
1063 } | 1112 } |
1113 | |
1114 static void Unserialize(AnnotationsOverlay& target, | |
1115 const Json::Value& source) | |
1116 { | |
1117 if (source.isMember(KEY_X1) && | |
1118 source.isMember(KEY_Y1) && | |
1119 source.isMember(KEY_X2) && | |
1120 source.isMember(KEY_Y2) && | |
1121 source[KEY_X1].isNumeric() && | |
1122 source[KEY_Y1].isNumeric() && | |
1123 source[KEY_X2].isNumeric() && | |
1124 source[KEY_Y2].isNumeric()) | |
1125 { | |
1126 new CircleAnnotation(target, | |
1127 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), | |
1128 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); | |
1129 } | |
1130 else | |
1131 { | |
1132 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an circle annotation"); | |
1133 } | |
1134 } | |
1064 }; | 1135 }; |
1065 | 1136 |
1066 | 1137 |
1067 class CreateSegmentOrCircleTracker : public IFlexiblePointerTracker | 1138 class CreateSegmentOrCircleTracker : public IFlexiblePointerTracker |
1068 { | 1139 { |
1487 annotations.append(item); | 1558 annotations.append(item); |
1488 } | 1559 } |
1489 | 1560 |
1490 target = Json::objectValue; | 1561 target = Json::objectValue; |
1491 target[KEY_ANNOTATIONS] = annotations; | 1562 target[KEY_ANNOTATIONS] = annotations; |
1563 } | |
1564 | |
1565 | |
1566 void Unserialize(const Json::Value& serialized) | |
1567 { | |
1568 Clear(); | |
1569 | |
1570 if (serialized.type() != Json::objectValue || | |
1571 !serialized.isMember(KEY_ANNOTATIONS) || | |
1572 serialized[KEY_ANNOTATIONS].type() != Json::arrayValue) | |
1573 { | |
1574 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a set of annotations"); | |
1575 } | |
1576 | |
1577 const Json::Value& annotations = serialized[KEY_ANNOTATIONS]; | |
1578 | |
1579 for (Json::Value::ArrayIndex i = 0; i < annotations.size(); i++) | |
1580 { | |
1581 if (annotations[i].type() != Json::objectValue || | |
1582 !annotations[i].isMember(KEY_TYPE) || | |
1583 annotations[i][KEY_TYPE].type() != Json::stringValue) | |
1584 { | |
1585 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
1586 } | |
1587 | |
1588 const std::string& type = annotations[i][KEY_TYPE].asString(); | |
1589 | |
1590 if (type == VALUE_ANGLE) | |
1591 { | |
1592 AngleAnnotation::Unserialize(*this, annotations[i]); | |
1593 } | |
1594 else if (type == VALUE_CIRCLE) | |
1595 { | |
1596 CircleAnnotation::Unserialize(*this, annotations[i]); | |
1597 } | |
1598 else if (type == VALUE_SEGMENT) | |
1599 { | |
1600 SegmentAnnotation::Unserialize(*this, annotations[i]); | |
1601 } | |
1602 else | |
1603 { | |
1604 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type; | |
1605 } | |
1606 } | |
1492 } | 1607 } |
1493 }; | 1608 }; |
1494 } | 1609 } |
1495 #endif | 1610 #endif |
1496 | 1611 |
1641 | 1756 |
1642 { | 1757 { |
1643 Json::Value v; | 1758 Json::Value v; |
1644 overlay.Serialize(v); | 1759 overlay.Serialize(v); |
1645 std::cout << v.toStyledString() << std::endl; | 1760 std::cout << v.toStyledString() << std::endl; |
1761 overlay.Clear(); | |
1762 overlay.Unserialize(v); | |
1646 } | 1763 } |
1647 | 1764 |
1648 boost::shared_ptr<SdlSimpleViewerApplication> application( | 1765 boost::shared_ptr<SdlSimpleViewerApplication> application( |
1649 SdlSimpleViewerApplication::Create(context, viewport)); | 1766 SdlSimpleViewerApplication::Create(context, viewport)); |
1650 | 1767 |