diff --git a/utils/Slicer/@SlicerControlPoint/SlicerControlPoint.m b/utils/Slicer/@SlicerControlPoint/SlicerControlPoint.m new file mode 100644 index 0000000..2c12946 --- /dev/null +++ b/utils/Slicer/@SlicerControlPoint/SlicerControlPoint.m @@ -0,0 +1,32 @@ +classdef SlicerControlPoint < handle + + properties + id = ""; + label = ""; + description = ""; + associatedNodeID = ""; + position = nan; + orientation = [-1.0 + 0.0001... + 0.0 + 0.0001... + 0.0 + 0.0001... + 0.0 + 0.0001... + -1.0 + 0.0001... + 0.0 + 0.0001... + 0.0 + 0.0001... + 0.0 + 0.0001... + 1.0 - 0.0001... + ]; + selected = true; + locked = false; + visibility = true; + positionStatus = "defined"; + end + + methods + function obj = SlicerControlPoint(label, position) + obj.label = label; + obj.position = position; + end + end + +end \ No newline at end of file diff --git a/utils/Slicer/@SlicerMarkups/SlicerMarkups.m b/utils/Slicer/@SlicerMarkups/SlicerMarkups.m new file mode 100644 index 0000000..74e12e0 --- /dev/null +++ b/utils/Slicer/@SlicerMarkups/SlicerMarkups.m @@ -0,0 +1,87 @@ +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 + end + +end \ No newline at end of file diff --git a/utils/Slicer/@SlicerMarkupsFiducial/SlicerMarkupsFiducial.m b/utils/Slicer/@SlicerMarkupsFiducial/SlicerMarkupsFiducial.m new file mode 100644 index 0000000..7f23643 --- /dev/null +++ b/utils/Slicer/@SlicerMarkupsFiducial/SlicerMarkupsFiducial.m @@ -0,0 +1,10 @@ +classdef SlicerMarkupsFiducial < SlicerMarkups + + methods + function obj = SlicerMarkupsFiducial() + obj@SlicerMarkups("Fiducial"); + obj.measurements = []; + end + end + +end \ No newline at end of file diff --git a/utils/Slicer/@SlicerMarkupsPlane/SlicerMarkupsPlane.m b/utils/Slicer/@SlicerMarkupsPlane/SlicerMarkupsPlane.m new file mode 100644 index 0000000..aadb785 --- /dev/null +++ b/utils/Slicer/@SlicerMarkupsPlane/SlicerMarkupsPlane.m @@ -0,0 +1,17 @@ +classdef SlicerMarkupsPlane < SlicerMarkups + + methods + function obj = SlicerMarkupsPlane + obj@SlicerMarkups("Plane"); + obj.setDefaultMeasurements(); + end + + function setDefaultMeasurements(obj) + obj.measurements{1}.name = "area"; + obj.measurements{1}.enabled = false; + obj.measurements{1}.value = 0.0 + 0.0001; + obj.measurements{1}.printFormat = "%5.3f %s"; + end + end + +end \ No newline at end of file