How to record the xyz coordinates of brachytherapy applicators in an excel file?
The following instructions extract from an rt-struct the coordinates of the brachytherapy applicators, and save them in an Excel file.
library (espadon)
library (openxlsx)
# path of the rt-struct file to analyze
struct.file <- file.choose ()
# loading of rt-struct in memory
S <- load.obj.from.dicom (struct.file, data = TRUE)
# coordinates of the brachytherapy applicators
coord <- lapply (S$roi.data[grepl ("^applicateur", S$roi.info$roi.pseudo)], function (l) l[[1]]$pt)
# formatting in a table
db <- as.data.frame (matrix ("", nrow = max (sapply (coord, nrow)) + 2, ncol = 4 * length (coord)))
db[1, 4 * (1:length (coord))-3] <- names (coord)
db[2, ] <- rep (c ("x", "y", "z", ""), length (coord))
for (i in 1:length (coord)) db[3:(2 + nrow (coord[[i]])), (i - 1) * 4 + (1:3)] <- coord[[i]]
# save as *.xlsx file
write.xlsx (db, file = "applicators.xlsx", colNames = FALSE,
rowNames = FALSE, overwrite = TRUE)