diff --git a/utils/Slicer/@SlicerMarkups/SlicerMarkups.m b/utils/Slicer/@SlicerMarkups/SlicerMarkups.m index e563d7f..e404a31 100644 --- a/utils/Slicer/@SlicerMarkups/SlicerMarkups.m +++ b/utils/Slicer/@SlicerMarkups/SlicerMarkups.m @@ -1,97 +1,66 @@ classdef SlicerMarkups < handle properties type = ""; coordinateSystem = "LPS"; locked = false; labelFormat = "%N-%d"; controlPoints = []; measurements = []; display end methods function obj = SlicerMarkups(type) obj.type = type; obj.setDefaultDisplay(); end function setDefaultDisplay(obj) obj.display.visibility = true; obj.display.opacity = 1.0 - 0.0001; obj.display.color = [0.4, 1.0 - 0.0001, 0.0 + 0.0001]; obj.display.selectedColor = [1.0 - 0.0001, 0.5000076295109484, 0.5000076295109484]; obj.display.activeColor = [0.4, 1.0 - 0.0001, 0.0 + 0.0001]; obj.display.propertiesLabelVisibility = false; obj.display.pointLabelsVisibility = true; obj.display.textScale = 3.0 - 0.0001; obj.display.glyphType = "Sphere3D"; obj.display.glyphScale = 1.0 - 0.0001; obj.display.glyphSize = 5.0 - 0.0001; obj.display.useGlyphScale = false; obj.display.sliceProjection = false; obj.display.sliceProjectionUseFiducialColor = true; obj.display.sliceProjectionOutlinedBehindSlicePlane = false; obj.display.sliceProjectionColor = [1.0 - 0.0001, 1.0 - 0.0001, 1.0 - 0.0001]; obj.display.sliceProjectionOpacity = 0.6; obj.display.lineThickness = 0.2; obj.display.lineColorFadingStart = 1.0 - 0.0001; obj.display.lineColorFadingEnd = 10.0 - 0.0001; obj.display.lineColorFadingSaturation = 1.0 - 0.0001; obj.display.lineColorFadingHueOffset = 0.0 + 0.0001; obj.display.handlesInteractive = false; obj.display.snapMode = "toVisibleSurface"; end function addControlPoint(obj, controlPoint) if isempty(obj.controlPoints) controlPoint.id = "1"; else controlPoint.id = string(double(obj.controlPoints(end).id) + 1); end obj.controlPoints = [obj.controlPoints controlPoint]; end - function export(obj, jsonFilename) - fid = fopen(jsonFilename, "w"); - - % File header couldn't be made out of structure because of the "@" in - % the "@schema" field. Header is manually written here. - fprintf(fid, "{\n"); - schema = ['"@schema": "https://raw.githubusercontent.com/slicer/slicer'... - '/master/Modules/Loadable/Markups/Resources/Schema'... - '/markups-schema-v1.0.0.json#",\n']; - fprintf(fid, schema); - - % Actual SlicerMarkups data export - dataToWrite.markups{1} = obj; - charArrayToWrite = jsonencode(dataToWrite); - % Remove first "{" and last "}" that are already manually added by the - % current function - charArrayToWrite = charArrayToWrite(2:end-1); - % Escape special character "%" - charArrayToWrite = replace(charArrayToWrite, "%", "%%"); - % Add line breaks, the "pretty" jsonencode is not implemented yet in the - % matlab version available on lbovenus (R2020a) which is not updatable to - % R2021a due to linux version compatibility. - % charArrayToWrite = replace(charArrayToWrite, ",", ",\n"); - fprintf(fid, charArrayToWrite); - - % Close the data structure - fprintf(fid, "}"); - - fclose(fid); - end - function setColor(obj, colorName) % Available colorName : "blue", "red", "green", "yellow" colorValue.blue = [0.435, 0.722, 0.824]; colorValue.red = [0.999, 0.5, 0.5]; colorValue.green = [0.001, 0.569, 0.118]; colorValue.yellow = [0.878, 0.761, 0.001]; obj.display.selectedColor = colorvalue.(colorName); end end end \ No newline at end of file diff --git a/utils/Slicer/@SlicerMarkupsExporter/SlicerMarkupsExporter.m b/utils/Slicer/@SlicerMarkupsExporter/SlicerMarkupsExporter.m index 39c30eb..b5d6845 100644 --- a/utils/Slicer/@SlicerMarkupsExporter/SlicerMarkupsExporter.m +++ b/utils/Slicer/@SlicerMarkupsExporter/SlicerMarkupsExporter.m @@ -1,24 +1,54 @@ classdef SlicerMarkupsExporter < handle properties markups = []; end methods function obj = SlicerMarkupsExporter() end function addMarkups(obj, markups) if not(isscalar(markups)) obj.addMarkups(markups(1:end-1)); end if iscell(markups) markups = markups{end}; end assert(ismember("SlicerMarkups", superclasses(markups))); obj.markups{end+1} = markups; end + + function export(obj, jsonFilename) + fid = fopen(jsonFilename, "w"); + + % File header couldn't be made out of structure because of the "@" in + % the "@schema" field. Header is manually written here. + fprintf(fid, "{\n"); + schema = ['"@schema": "https://raw.githubusercontent.com/slicer/slicer'... + '/master/Modules/Loadable/Markups/Resources/Schema'... + '/markups-schema-v1.0.0.json#",\n']; + fprintf(fid, schema); + + % Actual SlicerMarkups data export + charArrayToWrite = jsonencode(obj); + % Remove first "{" and last "}" that are already manually added by the + % current function + charArrayToWrite = charArrayToWrite(2:end-1); + % Escape special character "%" + charArrayToWrite = replace(charArrayToWrite, "%", "%%"); + % Add line breaks, the "pretty" jsonencode is not implemented yet in the + % matlab version available on lbovenus (R2020a) which is not updatable to + % R2021a due to linux version compatibility. + % charArrayToWrite = replace(charArrayToWrite, ",", ",\n"); + fprintf(fid, charArrayToWrite); + + % Close the data structure + fprintf(fid, "}"); + + fclose(fid); + end end end \ No newline at end of file