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

Method convert

annotation/AnnotationToMask.cpp:15–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13}
14
15void AnnotationToMask::convert(const std::shared_ptr<AnnotationList>& annotationList, const std::string& maskFile, const std::vector<unsigned long long>& dimensions, const std::vector<double>& spacing, const std::map<std::string, int> nameToLabel, const std::vector<std::string> nameOrder) const {
16 bool hasGroups = !annotationList->getGroups().empty();
17 std::vector<std::shared_ptr<Annotation> > annotations = annotationList->getAnnotations();
18 for (auto annotation = annotations.begin(); annotation != annotations.end(); ++annotation) {
19 if (!(*annotation)->isClockwise()) {
20 std::vector<Point> coords = (*annotation)->getCoordinates();
21 std::reverse(coords.begin(), coords.end());
22 (*annotation)->setCoordinates(coords);
23 }
24 }
25 if (!nameOrder.empty() && !nameToLabel.empty()) {
26 std::vector<std::shared_ptr<Annotation> > unorderedAnnotations = annotations;
27 annotations.clear();
28 for (unsigned int i = 0; i < nameOrder.size(); ++i) {
29 std::string currentName = nameOrder[i];
30 for (std::vector<std::shared_ptr<Annotation> >::iterator it = unorderedAnnotations.begin(); it != unorderedAnnotations.end(); ++it) {
31 bool matchesName = false;
32 if (hasGroups) {
33 if ((*it)->getGroup()) {
34 if ((*it)->getGroup()->getName() == currentName) {
35 matchesName = true;
36 }
37 }
38 }
39 else {
40 if ((*it)->getName() == currentName) {
41 matchesName = true;
42 }
43 }
44 if (matchesName) {
45 annotations.push_back((*it));
46 }
47 }
48 }
49 }
50 MultiResolutionImageWriter writer;
51 if (_monitor) {
52 writer.setProgressMonitor(_monitor);
53 }
54 if (writer.openFile(maskFile) == 0) {
55 writer.setColorType(pathology::ColorType::Monochrome);
56 writer.setCompression(pathology::Compression::LZW);
57 writer.setTileSize(512);
58 writer.setDataType(pathology::DataType::UChar);
59 writer.setInterpolation(pathology::Interpolation::NearestNeighbor);
60 std::vector<double> spacing_copy(spacing);
61 writer.setSpacing(spacing_copy);
62 writer.writeImageInformation(dimensions[0], dimensions[1]);
63 unsigned char* buffer = new unsigned char[512 * 512];
64 for (unsigned long long ty = 0; ty < dimensions[1]; ty += 512) {
65 for (unsigned long long tx = 0; tx < dimensions[0]; tx += 512) {
66 std::fill(buffer, buffer + 512 * 512, 0);
67 for (std::vector<std::shared_ptr<Annotation> >::const_iterator annotation = annotations.begin(); annotation != annotations.end(); ++annotation) {
68 if (!nameToLabel.empty() && !(*annotation)->getGroup() && hasGroups) {
69 continue;
70 }
71 std::string nm = (*annotation)->getName();
72 std::vector<Point> coords = (*annotation)->getCoordinates();

Callers 1

onSaveButtonPressedMethod · 0.80

Calls 15

PointClass · 0.85
emptyMethod · 0.80
getGroupsMethod · 0.80
getAnnotationsMethod · 0.80
isClockwiseMethod · 0.80
getCoordinatesMethod · 0.80
sizeMethod · 0.80
getNameMethod · 0.80
writeImageInformationMethod · 0.80
writeBaseImagePartMethod · 0.80
setCoordinatesMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected