MCPcopy Create free account
hub / github.com/computationalpathologygroup/ASAP / loadFromRepo

Method loadFromRepo

annotation/ImageScopeRepository.cpp:33–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33bool ImageScopeRepository::loadFromRepo()
34{
35 if (!_list || _source.empty()) {
36 return false;
37 }
38
39 _list->removeAllAnnotations();
40 _list->removeAllGroups();
41
42 pugi::xml_document xml_doc;
43 pugi::xml_parse_result tree = xml_doc.load_file(_source.c_str());
44 pugi::xml_node root = xml_doc.child("Annotations");
45 if (root.empty()) {
46 return false;
47 }
48 unsigned int group_nr = 0;
49 unsigned int annot_nr = 0;
50 for (pugi::xml_node grpIt = root.child("Annotation"); grpIt; grpIt = grpIt.next_sibling("Annotation"))
51 {
52 std::string groupName = grpIt.attribute("Name").value();
53 unsigned int groupColorAsInt = core::fromstring<unsigned int>(std::string(grpIt.attribute("LineColor").value()));
54
55 std::stringstream stream;
56 stream << std::hex << groupColorAsInt;
57 std::string groupColorAsHex(stream.str());
58 while (groupColorAsHex.size() < 6) {
59 groupColorAsHex = "0" + groupColorAsHex;
60 }
61 groupColorAsHex = "#" + groupColorAsHex;
62
63 std::shared_ptr<AnnotationGroup> grp = std::make_shared<AnnotationGroup>();
64 grp->setColor(groupColorAsHex);
65 std::map<unsigned int, std::vector<std::pair<double, double> > > idToCoords;
66 std::map<unsigned int, std::string> idToName;
67 pugi::xml_node regions = grpIt.child("Regions");
68 for (pugi::xml_node annotation_xml = regions.child("Region"); annotation_xml; annotation_xml = annotation_xml.next_sibling("Region"))
69 {
70 unsigned int id = core::fromstring<int>(annotation_xml.attribute("Id").value());
71 idToName[id] = std::string(annotation_xml.attribute("Text").value());
72
73 pugi::xml_node vertices = annotation_xml.child("Vertices");
74 for (pugi::xml_node_iterator cit = vertices.begin(); cit != vertices.end(); ++cit)
75 {
76 double x = core::fromstring<double>(cit->attribute("X").value());
77 double y = core::fromstring<double>(cit->attribute("Y").value());
78 idToCoords[id].push_back(std::pair<double, double>(x, y));
79 }
80 }
81
82 std::map<unsigned int, unsigned int> usedIds;
83 for (std::map<unsigned int, std::string>::iterator idIt = idToName.begin(); idIt != idToName.end(); ++idIt) {
84 usedIds[idIt->first] = 0;
85 }
86 // Now figure out which regions belong together
87 for (std::map<unsigned int, std::vector<std::pair<double, double> > >::const_iterator coordIt = idToCoords.begin(); coordIt != idToCoords.end(); ++coordIt) {
88 unsigned int curId = coordIt->first;
89 if (usedIds[curId] == 1) {
90 continue;

Callers

nothing calls this directly

Calls 14

tostringFunction · 0.85
PointClass · 0.85
emptyMethod · 0.80
removeAllAnnotationsMethod · 0.80
removeAllGroupsMethod · 0.80
sizeMethod · 0.80
setColorMethod · 0.80
insertMethod · 0.80
setNameMethod · 0.80
setTypeFromStringMethod · 0.80
setGroupMethod · 0.80
addAnnotationMethod · 0.80

Tested by

no test coverage detected