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

Method loadFromRepo

annotation/NDPARepository.cpp:33–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33bool NDPARepository::loadFromRepo()
34{
35 if (!_list || _source.empty()) {
36 return false;
37 }
38
39 _list->removeAllAnnotations();
40 _list->removeAllGroups();
41
42 std::shared_ptr<MultiResolutionImage> ndpi;
43 if (_ndpiSourceFile.empty()) {
44 std::vector<std::string> ndpaParts = core::split(_source, ".ndpa");
45 if (core::fileExists(ndpaParts[0])) {
46 MultiResolutionImageReader reader;
47 ndpi.reset(reader.open(ndpaParts[0]));
48 if (!ndpi) {
49 return false;
50 }
51 }
52 else {
53 return false;
54 }
55 }
56
57 float offsetX = core::fromstring<float>(ndpi->getProperty("hamamatsu.XOffsetFromSlideCentre"));
58 float offsetY = core::fromstring<float>(ndpi->getProperty("hamamatsu.YOffsetFromSlideCentre"));
59 float mppX = core::fromstring<float>(ndpi->getProperty("openslide.mpp-x"));
60 float mppY = core::fromstring<float>(ndpi->getProperty("openslide.mpp-y"));
61 std::vector<unsigned long long> dims = ndpi->getDimensions();
62
63 pugi::xml_document xml_doc;
64 pugi::xml_parse_result tree = xml_doc.load_file(_source.c_str());
65 pugi::xml_node root = xml_doc.child("annotations");
66 unsigned int annotation_nr = 0;
67 for (pugi::xml_node it = root.child("ndpviewstate"); it; it = it.next_sibling("ndpviewstate"))
68 {
69 for (pugi::xml_node annotation_xml = it.child("annotation"); annotation_xml; annotation_xml = annotation_xml.next_sibling("annotation"))
70 {
71 if (std::string(annotation_xml.attribute("type").value()) == std::string("freehand")) {
72 std::shared_ptr<Annotation> annotation = std::make_shared<Annotation>();
73
74 annotation->setName(std::string(it.child_value("title")) + "_" + core::tostring(annotation_nr));
75 annotation->setTypeFromString("Polygon");
76 std::string annotColor = annotation_xml.attribute("color").value();
77 if (!annotColor.empty()) {
78 annotation->setColor(annotColor);
79 }
80
81 pugi::xml_node coordinates = annotation_xml.child("pointlist");
82 for (pugi::xml_node_iterator cit = coordinates.begin(); cit != coordinates.end(); ++cit)
83 {
84 double x = core::fromstring<double>(cit->child_value("x"));
85 double y = core::fromstring<double>(cit->child_value("y"));
86 double corX = ((x - offsetX) / (mppX * 1000)) + (dims[0] / 2.);
87 double corY = ((y - offsetY) / (mppY * 1000)) + (dims[1] / 2.);
88 annotation->addCoordinate(corX, corY);
89 }
90 _list->addAnnotation(annotation);

Callers

nothing calls this directly

Calls 14

splitFunction · 0.85
fileExistsFunction · 0.85
tostringFunction · 0.85
emptyMethod · 0.80
removeAllAnnotationsMethod · 0.80
removeAllGroupsMethod · 0.80
openMethod · 0.80
setNameMethod · 0.80
setTypeFromStringMethod · 0.80
setColorMethod · 0.80
addAnnotationMethod · 0.80
getPropertyMethod · 0.45

Tested by

no test coverage detected