diff --git a/matlab/buildfile.m b/matlab/buildfile.m index 2d3b893..640acd9 100644 --- a/matlab/buildfile.m +++ b/matlab/buildfile.m @@ -1,49 +1,57 @@ -function plan = buildfile - % import matlab.buildtool.tasks.CodeIssuesTask - % import matlab.buildtool.tasks.TestTask +function plan = buildfile % import matlab.buildtool.tasks.CodeIssuesTask + % import matlab.buildtool.tasks.TestTask - plan = buildplan(localfunctions); - % plan("check") = CodeIssuesTask(Results="tests/results/static-analysis-results.sarif"); - % plan("test") = TestTask("tests", SourceFiles="toolbox", TestResults="tests/results/test-results.xml"); + plan + = buildplan (localfunctions); +% plan ("check") + = CodeIssuesTask (Results = "tests/results/static-analysis-results.sarif"); +% plan ("test") = TestTask ("tests", SourceFiles = "toolbox", + TestResults = "tests/results/test-results.xml"); - % plan("packageToolbox").Dependencies = ["check" "test"]; +% plan ("packageToolbox").Dependencies = ["check" + "test"]; - plan.DefaultTasks = ["packageToolbox"]; +plan.DefaultTasks = ["packageToolbox"]; end -function packageToolboxTask(~) - buildToolbox("release"); + function packageToolboxTask (~) buildToolbox ("release"); end -function buildToolbox(outdir) - if ~exist(outdir, 'dir') - mkdir(outdir); - end + function buildToolbox (outdir) if ~exist (outdir, 'dir') mkdir (outdir); +end - uuid = string(java.util.UUID.randomUUID()); - toolboxFolder = "./toolbox/"; - opts = matlab.addons.toolbox.ToolboxOptions(toolboxFolder, uuid); + uuid + = string (java.util.UUID.randomUUID ()); +toolboxFolder = "./toolbox/"; +opts = matlab.addons.toolbox.ToolboxOptions (toolboxFolder, uuid); - toolboxDirs = unique(fileparts(opts.ToolboxFiles)); - if ~all(contains(toolboxDirs, opts.ToolboxFolder)) - error("No symbolic links allowed in toolboxFolder (BUG through at least R2023a)"); - end +toolboxDirs = unique (fileparts (opts.ToolboxFiles)); +if + ~all (contains (toolboxDirs, opts.ToolboxFolder)) + error ("No symbolic links allowed in toolboxFolder (BUG through at " + "least R2023a)"); +end - opts.ToolboxName = "PETSIRD"; + opts.ToolboxName + = "PETSIRD"; - opts.ToolboxVersion = "0.2.0"; - opts.OutputFile = fullfile(outdir, sprintf("petsird-%s.mltbx", opts.ToolboxVersion)); +opts.ToolboxVersion = "0.2.0"; +opts.OutputFile + = fullfile (outdir, sprintf ("petsird-%s.mltbx", opts.ToolboxVersion)); - opts.Description = "Positron Emission Tomography Standardization Initiative Raw Data (PETSIRD) toolbox for MATLAB"; - % opts.Summary = ""; - % opts.AuthorCompany = ""; +opts.Description = "Positron Emission Tomography Standardization Initiative " + "Raw Data (PETSIRD) toolbox for MATLAB"; +% opts.Summary = ""; +% opts.AuthorCompany = ""; - opts.MinimumMatlabRelease = "R2022b"; +opts.MinimumMatlabRelease = "R2022b"; - % Must also specify which folders should be added to MATLAB path upon toolbox installation. - % Must also include at least one *file* in the toolbox folder. - % This seems to be bug on Linux, Matlab R2023a. On Windows, this isn't required. - opts.ToolboxMatlabPath = toolboxFolder; +% Must also specify which folders should be added to MATLAB path upon toolbox + installation. + % Must also include at least one *file *in the toolbox folder. + % This seems to be bug on Linux, + Matlab R2023a.On Windows, + this isn't required. opts.ToolboxMatlabPath = toolboxFolder; - matlab.addons.toolbox.packageToolbox(opts); +matlab.addons.toolbox.packageToolbox (opts); end diff --git a/matlab/toolbox/+petsird/+binary/AnnulusShapeSerializer.m b/matlab/toolbox/+petsird/+binary/AnnulusShapeSerializer.m index 62d85a3..745286f 100644 --- a/matlab/toolbox/+petsird/+binary/AnnulusShapeSerializer.m +++ b/matlab/toolbox/+petsird/+binary/AnnulusShapeSerializer.m @@ -1,27 +1,31 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef AnnulusShapeSerializer < yardl.binary.RecordSerializer - methods - function self = AnnulusShapeSerializer() - field_serializers{1} = yardl.binary.Float32Serializer; - field_serializers{2} = yardl.binary.Float32Serializer; - field_serializers{3} = yardl.binary.Float32Serializer; - field_serializers{4} = yardl.binary.FixedVectorSerializer(yardl.binary.Float32Serializer, 2); - self@yardl.binary.RecordSerializer('petsird.AnnulusShape', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.AnnulusShape - end - self.write_(outstream, value.inner_radius, value.outer_radius, value.thickness, value.angular_range); - end + classdef AnnulusShapeSerializer + < yardl.binary.RecordSerializer methods function self + = AnnulusShapeSerializer () field_serializers{ 1 } += yardl.binary.Float32Serializer; +field_serializers{ 2 } = yardl.binary.Float32Serializer; +field_serializers{ 3 } = yardl.binary.Float32Serializer; +field_serializers{ 4 } += yardl.binary.FixedVectorSerializer (yardl.binary.Float32Serializer, 2); +self + @yardl.binary.RecordSerializer ('petsird.AnnulusShape', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.AnnulusShape(inner_radius=fields{1}, outer_radius=fields{2}, thickness=fields{3}, angular_range=fields{4}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.AnnulusShape end self.write_ (outstream, + value.inner_radius, + value.outer_radius, + value.thickness, + value.angular_range); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.AnnulusShape ( + inner_radius = fields{ 1 }, outer_radius = fields{ 2 }, + thickness = fields{ 3 }, angular_range = fields{ 4 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/AtomSerializer.m b/matlab/toolbox/+petsird/+binary/AtomSerializer.m index 9d6555d..a3f001c 100644 --- a/matlab/toolbox/+petsird/+binary/AtomSerializer.m +++ b/matlab/toolbox/+petsird/+binary/AtomSerializer.m @@ -1,25 +1,21 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef AtomSerializer < yardl.binary.RecordSerializer - methods - function self = AtomSerializer() - field_serializers{1} = yardl.binary.Uint32Serializer; - field_serializers{2} = yardl.binary.Uint32Serializer; - self@yardl.binary.RecordSerializer('petsird.Atom', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.Atom - end - self.write_(outstream, value.mass_number, value.atomic_number); - end + classdef AtomSerializer + < yardl.binary.RecordSerializer methods function self + = AtomSerializer () field_serializers{ 1 } = yardl.binary.Uint32Serializer; +field_serializers{ 2 } = yardl.binary.Uint32Serializer; +self @yardl.binary.RecordSerializer ('petsird.Atom', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.Atom(mass_number=fields{1}, atomic_number=fields{2}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.Atom end self.write_ (outstream, value.mass_number, + value.atomic_number); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.Atom (mass_number = fields{ 1 }, atomic_number = fields{ 2 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/BedMovementTimeBlockSerializer.m b/matlab/toolbox/+petsird/+binary/BedMovementTimeBlockSerializer.m index 2c66a2e..daa91b6 100644 --- a/matlab/toolbox/+petsird/+binary/BedMovementTimeBlockSerializer.m +++ b/matlab/toolbox/+petsird/+binary/BedMovementTimeBlockSerializer.m @@ -1,25 +1,26 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef BedMovementTimeBlockSerializer < yardl.binary.RecordSerializer - methods - function self = BedMovementTimeBlockSerializer() - field_serializers{1} = yardl.binary.Uint32Serializer; - field_serializers{2} = petsird.binary.RigidTransformationSerializer(); - self@yardl.binary.RecordSerializer('petsird.BedMovementTimeBlock', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.BedMovementTimeBlock - end - self.write_(outstream, value.start, value.transform); - end + classdef BedMovementTimeBlockSerializer + < yardl.binary.RecordSerializer methods function self + = BedMovementTimeBlockSerializer () field_serializers{ 1 } += yardl.binary.Uint32Serializer; +field_serializers{ 2 } = petsird.binary.RigidTransformationSerializer (); +self @yardl.binary.RecordSerializer ('petsird.BedMovementTimeBlock', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.BedMovementTimeBlock(start=fields{1}, transform=fields{2}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, + 1) petsird.BedMovementTimeBlock end self.write_ (outstream, + value.start, + value.transform); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.BedMovementTimeBlock (start = fields{ 1 }, + transform = fields{ 2 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/BoxShapeSerializer.m b/matlab/toolbox/+petsird/+binary/BoxShapeSerializer.m index beef341..00a87f3 100644 --- a/matlab/toolbox/+petsird/+binary/BoxShapeSerializer.m +++ b/matlab/toolbox/+petsird/+binary/BoxShapeSerializer.m @@ -1,24 +1,21 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef BoxShapeSerializer < yardl.binary.RecordSerializer - methods - function self = BoxShapeSerializer() - field_serializers{1} = yardl.binary.FixedVectorSerializer(petsird.binary.CoordinateSerializer(), 8); - self@yardl.binary.RecordSerializer('petsird.BoxShape', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.BoxShape - end - self.write_(outstream, value.corners); - end + classdef BoxShapeSerializer + < yardl.binary.RecordSerializer methods function self + = BoxShapeSerializer () field_serializers{ 1 } += yardl.binary.FixedVectorSerializer (petsird.binary.CoordinateSerializer (), + 8); +self @yardl.binary.RecordSerializer ('petsird.BoxShape', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.BoxShape(corners=fields{1}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.BoxShape end self.write_ (outstream, value.corners); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.BoxShape (corners = fields{ 1 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/BulkMaterialSerializer.m b/matlab/toolbox/+petsird/+binary/BulkMaterialSerializer.m index a98eedc..fd62ae4 100644 --- a/matlab/toolbox/+petsird/+binary/BulkMaterialSerializer.m +++ b/matlab/toolbox/+petsird/+binary/BulkMaterialSerializer.m @@ -1,28 +1,33 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef BulkMaterialSerializer < yardl.binary.RecordSerializer - methods - function self = BulkMaterialSerializer() - field_serializers{1} = yardl.binary.Uint32Serializer; - field_serializers{2} = yardl.binary.StringSerializer; - field_serializers{3} = yardl.binary.Float32Serializer; - field_serializers{4} = yardl.binary.VectorSerializer(petsird.binary.AtomSerializer()); - field_serializers{5} = yardl.binary.VectorSerializer(yardl.binary.Float32Serializer); - self@yardl.binary.RecordSerializer('petsird.BulkMaterial', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.BulkMaterial - end - self.write_(outstream, value.id, value.name, value.density, value.atoms, value.mass_fractions); - end + classdef BulkMaterialSerializer + < yardl.binary.RecordSerializer methods function self + = BulkMaterialSerializer () field_serializers{ 1 } += yardl.binary.Uint32Serializer; +field_serializers{ 2 } = yardl.binary.StringSerializer; +field_serializers{ 3 } = yardl.binary.Float32Serializer; +field_serializers{ 4 } += yardl.binary.VectorSerializer (petsird.binary.AtomSerializer ()); +field_serializers{ 5 } += yardl.binary.VectorSerializer (yardl.binary.Float32Serializer); +self + @yardl.binary.RecordSerializer ('petsird.BulkMaterial', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.BulkMaterial(id=fields{1}, name=fields{2}, density=fields{3}, atoms=fields{4}, mass_fractions=fields{5}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.BulkMaterial end self.write_ (outstream, value.id, + value.name, + value.density, + value.atoms, + value.mass_fractions); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.BulkMaterial (id = fields{ 1 }, name = fields{ 2 }, + density = fields{ 3 }, atoms = fields{ 4 }, + mass_fractions = fields{ 5 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/CoincidenceEventSerializer.m b/matlab/toolbox/+petsird/+binary/CoincidenceEventSerializer.m index aab45ad..da9003c 100644 --- a/matlab/toolbox/+petsird/+binary/CoincidenceEventSerializer.m +++ b/matlab/toolbox/+petsird/+binary/CoincidenceEventSerializer.m @@ -1,26 +1,27 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef CoincidenceEventSerializer < yardl.binary.RecordSerializer - methods - function self = CoincidenceEventSerializer() - field_serializers{1} = yardl.binary.FixedVectorSerializer(yardl.binary.Uint32Serializer, 2); - field_serializers{2} = yardl.binary.Uint32Serializer; - field_serializers{3} = yardl.binary.FixedVectorSerializer(yardl.binary.Uint32Serializer, 2); - self@yardl.binary.RecordSerializer('petsird.CoincidenceEvent', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.CoincidenceEvent - end - self.write_(outstream, value.detector_ids, value.tof_idx, value.energy_indices); - end + classdef CoincidenceEventSerializer + < yardl.binary.RecordSerializer methods function self + = CoincidenceEventSerializer () field_serializers{ 1 } += yardl.binary.FixedVectorSerializer (yardl.binary.Uint32Serializer, 2); +field_serializers{ 2 } = yardl.binary.Uint32Serializer; +field_serializers{ 3 } += yardl.binary.FixedVectorSerializer (yardl.binary.Uint32Serializer, 2); +self @yardl.binary.RecordSerializer ('petsird.CoincidenceEvent', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.CoincidenceEvent(detector_ids=fields{1}, tof_idx=fields{2}, energy_indices=fields{3}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.CoincidenceEvent end self.write_ ( + outstream, value.detector_ids, value.tof_idx, value.energy_indices); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.CoincidenceEvent (detector_ids = fields{ 1 }, + tof_idx = fields{ 2 }, + energy_indices = fields{ 3 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/CoordinateSerializer.m b/matlab/toolbox/+petsird/+binary/CoordinateSerializer.m index 4219342..7dd8c73 100644 --- a/matlab/toolbox/+petsird/+binary/CoordinateSerializer.m +++ b/matlab/toolbox/+petsird/+binary/CoordinateSerializer.m @@ -1,24 +1,20 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef CoordinateSerializer < yardl.binary.RecordSerializer - methods - function self = CoordinateSerializer() - field_serializers{1} = yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [3]); - self@yardl.binary.RecordSerializer('petsird.Coordinate', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.Coordinate - end - self.write_(outstream, value.c); - end + classdef CoordinateSerializer + < yardl.binary.RecordSerializer methods function self + = CoordinateSerializer () field_serializers{ 1 } += yardl.binary.FixedNDArraySerializer (yardl.binary.Float32Serializer, [3]); +self @yardl.binary.RecordSerializer ('petsird.Coordinate', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.Coordinate(c=fields{1}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.Coordinate end self.write_ (outstream, value.c); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.Coordinate (c = fields{ 1 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/DeadTimeTimeBlockSerializer.m b/matlab/toolbox/+petsird/+binary/DeadTimeTimeBlockSerializer.m index f18eb0a..9ef6c5c 100644 --- a/matlab/toolbox/+petsird/+binary/DeadTimeTimeBlockSerializer.m +++ b/matlab/toolbox/+petsird/+binary/DeadTimeTimeBlockSerializer.m @@ -1,26 +1,29 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef DeadTimeTimeBlockSerializer < yardl.binary.RecordSerializer - methods - function self = DeadTimeTimeBlockSerializer() - field_serializers{1} = petsird.binary.TimeIntervalSerializer(); - field_serializers{2} = yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2); - field_serializers{3} = yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2); - self@yardl.binary.RecordSerializer('petsird.DeadTimeTimeBlock', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.DeadTimeTimeBlock - end - self.write_(outstream, value.time_interval, value.singles_alive_time_fraction, value.module_coincidence_alive_time_fraction); - end + classdef DeadTimeTimeBlockSerializer + < yardl.binary.RecordSerializer methods function self + = DeadTimeTimeBlockSerializer () field_serializers{ 1 } += petsird.binary.TimeIntervalSerializer (); +field_serializers{ 2 } += yardl.binary.NDArraySerializer (yardl.binary.Float32Serializer, 2); +field_serializers{ 3 } += yardl.binary.NDArraySerializer (yardl.binary.Float32Serializer, 2); +self @yardl.binary.RecordSerializer ('petsird.DeadTimeTimeBlock', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.DeadTimeTimeBlock(time_interval=fields{1}, singles_alive_time_fraction=fields{2}, module_coincidence_alive_time_fraction=fields{3}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.DeadTimeTimeBlock end self.write_ ( + outstream, value.time_interval, value.singles_alive_time_fraction, + value.module_coincidence_alive_time_fraction); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.DeadTimeTimeBlock ( + time_interval = fields{ 1 }, singles_alive_time_fraction = fields{ 2 }, + module_coincidence_alive_time_fraction = fields{ 3 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/DetectionEfficienciesSerializer.m b/matlab/toolbox/+petsird/+binary/DetectionEfficienciesSerializer.m index 19ba038..e1dc6de 100644 --- a/matlab/toolbox/+petsird/+binary/DetectionEfficienciesSerializer.m +++ b/matlab/toolbox/+petsird/+binary/DetectionEfficienciesSerializer.m @@ -1,26 +1,31 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef DetectionEfficienciesSerializer < yardl.binary.RecordSerializer - methods - function self = DetectionEfficienciesSerializer() - field_serializers{1} = yardl.binary.OptionalSerializer(yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2)); - field_serializers{2} = yardl.binary.OptionalSerializer(yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2)); - field_serializers{3} = yardl.binary.OptionalSerializer(yardl.binary.VectorSerializer(petsird.binary.ModulePairEfficienciesSerializer())); - self@yardl.binary.RecordSerializer('petsird.DetectionEfficiencies', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.DetectionEfficiencies - end - self.write_(outstream, value.det_el_efficiencies, value.module_pair_sgidlut, value.module_pair_efficiencies_vector); - end + classdef DetectionEfficienciesSerializer + < yardl.binary.RecordSerializer methods function self + = DetectionEfficienciesSerializer () field_serializers{ 1 } += yardl.binary.OptionalSerializer ( + yardl.binary.NDArraySerializer (yardl.binary.Float32Serializer, 2)); +field_serializers{ 2 } = yardl.binary.OptionalSerializer ( + yardl.binary.NDArraySerializer (yardl.binary.Int32Serializer, 2)); +field_serializers{ 3 } += yardl.binary.OptionalSerializer (yardl.binary.VectorSerializer ( + petsird.binary.ModulePairEfficienciesSerializer ())); +self @yardl.binary.RecordSerializer ('petsird.DetectionEfficiencies', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.DetectionEfficiencies(det_el_efficiencies=fields{1}, module_pair_sgidlut=fields{2}, module_pair_efficiencies_vector=fields{3}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.DetectionEfficiencies end self.write_ ( + outstream, value.det_el_efficiencies, value.module_pair_sgidlut, + value.module_pair_efficiencies_vector); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.DetectionEfficiencies ( + det_el_efficiencies = fields{ 1 }, module_pair_sgidlut = fields{ 2 }, + module_pair_efficiencies_vector = fields{ 3 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/DetectorModuleSerializer.m b/matlab/toolbox/+petsird/+binary/DetectorModuleSerializer.m index 5e4a724..5098694 100644 --- a/matlab/toolbox/+petsird/+binary/DetectorModuleSerializer.m +++ b/matlab/toolbox/+petsird/+binary/DetectorModuleSerializer.m @@ -1,26 +1,39 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef DetectorModuleSerializer < yardl.binary.RecordSerializer - methods - function self = DetectorModuleSerializer() - field_serializers{1} = yardl.binary.VectorSerializer(petsird.binary.ReplicatedObjectSerializer(petsird.binary.SolidVolumeSerializer(petsird.binary.BoxShapeSerializer()))); - field_serializers{2} = yardl.binary.VectorSerializer(yardl.binary.Uint32Serializer); - field_serializers{3} = yardl.binary.VectorSerializer(petsird.binary.ReplicatedObjectSerializer(petsird.binary.SolidVolumeSerializer(yardl.binary.UnionSerializer('petsird.GeometricShape', {petsird.binary.BoxShapeSerializer(), petsird.binary.AnnulusShapeSerializer()}, {@petsird.GeometricShape.BoxShape, @petsird.GeometricShape.AnnulusShape})))); - self@yardl.binary.RecordSerializer('petsird.DetectorModule', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.DetectorModule - end - self.write_(outstream, value.detecting_elements, value.detecting_element_ids, value.non_detecting_elements); - end + classdef DetectorModuleSerializer + < yardl.binary.RecordSerializer methods function self + = DetectorModuleSerializer () field_serializers{ 1 } += yardl.binary.VectorSerializer (petsird.binary.ReplicatedObjectSerializer ( + petsird.binary.SolidVolumeSerializer ( + petsird.binary.BoxShapeSerializer ()))); +field_serializers{ 2 } += yardl.binary.VectorSerializer (yardl.binary.Uint32Serializer); +field_serializers{ 3 } += yardl.binary.VectorSerializer (petsird.binary.ReplicatedObjectSerializer ( + petsird.binary.SolidVolumeSerializer (yardl.binary.UnionSerializer ( + 'petsird.GeometricShape', + { petsird.binary.BoxShapeSerializer (), + petsird.binary.AnnulusShapeSerializer () }, + { + @petsird.GeometricShape.BoxShape, + @petsird.GeometricShape.AnnulusShape + })))); +self @yardl.binary.RecordSerializer ('petsird.DetectorModule', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.DetectorModule(detecting_elements=fields{1}, detecting_element_ids=fields{2}, non_detecting_elements=fields{3}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.DetectorModule end self.write_ ( + outstream, value.detecting_elements, value.detecting_element_ids, + value.non_detecting_elements); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.DetectorModule (detecting_elements = fields{ 1 }, + detecting_element_ids = fields{ 2 }, + non_detecting_elements = fields{ 3 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/DirectionMatrixSerializer.m b/matlab/toolbox/+petsird/+binary/DirectionMatrixSerializer.m index 179b6b1..1b5a882 100644 --- a/matlab/toolbox/+petsird/+binary/DirectionMatrixSerializer.m +++ b/matlab/toolbox/+petsird/+binary/DirectionMatrixSerializer.m @@ -1,24 +1,23 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef DirectionMatrixSerializer < yardl.binary.RecordSerializer - methods - function self = DirectionMatrixSerializer() - field_serializers{1} = yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [3, 3]); - self@yardl.binary.RecordSerializer('petsird.DirectionMatrix', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.DirectionMatrix - end - self.write_(outstream, value.matrix); - end + classdef DirectionMatrixSerializer + < yardl.binary.RecordSerializer methods function self + = DirectionMatrixSerializer () field_serializers{ 1 } += yardl.binary.FixedNDArraySerializer (yardl.binary.Float32Serializer, + [ 3, 3 ]); +self @yardl.binary.RecordSerializer ('petsird.DirectionMatrix', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.DirectionMatrix(matrix=fields{1}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.DirectionMatrix end self.write_ (outstream, + value.matrix); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.DirectionMatrix (matrix = fields{ 1 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/DirectionSerializer.m b/matlab/toolbox/+petsird/+binary/DirectionSerializer.m index 77401b4..93de244 100644 --- a/matlab/toolbox/+petsird/+binary/DirectionSerializer.m +++ b/matlab/toolbox/+petsird/+binary/DirectionSerializer.m @@ -1,24 +1,20 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef DirectionSerializer < yardl.binary.RecordSerializer - methods - function self = DirectionSerializer() - field_serializers{1} = yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [3]); - self@yardl.binary.RecordSerializer('petsird.Direction', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.Direction - end - self.write_(outstream, value.c); - end + classdef DirectionSerializer + < yardl.binary.RecordSerializer methods function self + = DirectionSerializer () field_serializers{ 1 } += yardl.binary.FixedNDArraySerializer (yardl.binary.Float32Serializer, [3]); +self @yardl.binary.RecordSerializer ('petsird.Direction', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.Direction(c=fields{1}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.Direction end self.write_ (outstream, value.c); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.Direction (c = fields{ 1 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/EventTimeBlockSerializer.m b/matlab/toolbox/+petsird/+binary/EventTimeBlockSerializer.m index b2bfec0..d4fc97a 100644 --- a/matlab/toolbox/+petsird/+binary/EventTimeBlockSerializer.m +++ b/matlab/toolbox/+petsird/+binary/EventTimeBlockSerializer.m @@ -1,27 +1,34 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef EventTimeBlockSerializer < yardl.binary.RecordSerializer - methods - function self = EventTimeBlockSerializer() - field_serializers{1} = yardl.binary.Uint32Serializer; - field_serializers{2} = yardl.binary.VectorSerializer(petsird.binary.CoincidenceEventSerializer()); - field_serializers{3} = yardl.binary.OptionalSerializer(yardl.binary.VectorSerializer(petsird.binary.CoincidenceEventSerializer())); - field_serializers{4} = yardl.binary.OptionalSerializer(yardl.binary.VectorSerializer(petsird.binary.TripleEventSerializer())); - self@yardl.binary.RecordSerializer('petsird.EventTimeBlock', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.EventTimeBlock - end - self.write_(outstream, value.start, value.prompt_events, value.delayed_events, value.triple_events); - end + classdef EventTimeBlockSerializer + < yardl.binary.RecordSerializer methods function self + = EventTimeBlockSerializer () field_serializers{ 1 } += yardl.binary.Uint32Serializer; +field_serializers{ 2 } += yardl.binary.VectorSerializer (petsird.binary.CoincidenceEventSerializer ()); +field_serializers{ 3 } += yardl.binary.OptionalSerializer (yardl.binary.VectorSerializer ( + petsird.binary.CoincidenceEventSerializer ())); +field_serializers{ 4 } = yardl.binary.OptionalSerializer ( + yardl.binary.VectorSerializer (petsird.binary.TripleEventSerializer ())); +self @yardl.binary.RecordSerializer ('petsird.EventTimeBlock', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.EventTimeBlock(start=fields{1}, prompt_events=fields{2}, delayed_events=fields{3}, triple_events=fields{4}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.EventTimeBlock end self.write_ (outstream, + value.start, + value.prompt_events, + value.delayed_events, + value.triple_events); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.EventTimeBlock ( + start = fields{ 1 }, prompt_events = fields{ 2 }, + delayed_events = fields{ 3 }, triple_events = fields{ 4 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/ExamInformationSerializer.m b/matlab/toolbox/+petsird/+binary/ExamInformationSerializer.m index 317561f..80ae5e5 100644 --- a/matlab/toolbox/+petsird/+binary/ExamInformationSerializer.m +++ b/matlab/toolbox/+petsird/+binary/ExamInformationSerializer.m @@ -1,27 +1,30 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ExamInformationSerializer < yardl.binary.RecordSerializer - methods - function self = ExamInformationSerializer() - field_serializers{1} = petsird.binary.SubjectSerializer(); - field_serializers{2} = petsird.binary.InstitutionSerializer(); - field_serializers{3} = yardl.binary.OptionalSerializer(yardl.binary.StringSerializer); - field_serializers{4} = yardl.binary.OptionalSerializer(yardl.binary.DatetimeSerializer); - self@yardl.binary.RecordSerializer('petsird.ExamInformation', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.ExamInformation - end - self.write_(outstream, value.subject, value.institution, value.protocol, value.start_of_acquisition); - end + classdef ExamInformationSerializer + < yardl.binary.RecordSerializer methods function self + = ExamInformationSerializer () field_serializers{ 1 } += petsird.binary.SubjectSerializer (); +field_serializers{ 2 } = petsird.binary.InstitutionSerializer (); +field_serializers{ 3 } += yardl.binary.OptionalSerializer (yardl.binary.StringSerializer); +field_serializers{ 4 } += yardl.binary.OptionalSerializer (yardl.binary.DatetimeSerializer); +self @yardl.binary.RecordSerializer ('petsird.ExamInformation', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.ExamInformation(subject=fields{1}, institution=fields{2}, protocol=fields{3}, start_of_acquisition=fields{4}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.ExamInformation end self.write_ ( + outstream, value.subject, value.institution, value.protocol, + value.start_of_acquisition); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.ExamInformation ( + subject = fields{ 1 }, institution = fields{ 2 }, protocol = fields{ 3 }, + start_of_acquisition = fields{ 4 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/ExternalSignalTimeBlockSerializer.m b/matlab/toolbox/+petsird/+binary/ExternalSignalTimeBlockSerializer.m index 9e820fe..a9c4a74 100644 --- a/matlab/toolbox/+petsird/+binary/ExternalSignalTimeBlockSerializer.m +++ b/matlab/toolbox/+petsird/+binary/ExternalSignalTimeBlockSerializer.m @@ -1,26 +1,26 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ExternalSignalTimeBlockSerializer < yardl.binary.RecordSerializer - methods - function self = ExternalSignalTimeBlockSerializer() - field_serializers{1} = yardl.binary.Uint32Serializer; - field_serializers{2} = yardl.binary.Uint32Serializer; - field_serializers{3} = yardl.binary.VectorSerializer(yardl.binary.Float32Serializer); - self@yardl.binary.RecordSerializer('petsird.ExternalSignalTimeBlock', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.ExternalSignalTimeBlock - end - self.write_(outstream, value.start, value.signal_id, value.signal_values); - end + classdef ExternalSignalTimeBlockSerializer + < yardl.binary.RecordSerializer methods function self + = ExternalSignalTimeBlockSerializer () field_serializers{ 1 } += yardl.binary.Uint32Serializer; +field_serializers{ 2 } = yardl.binary.Uint32Serializer; +field_serializers{ 3 } += yardl.binary.VectorSerializer (yardl.binary.Float32Serializer); +self @yardl.binary.RecordSerializer ('petsird.ExternalSignalTimeBlock', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.ExternalSignalTimeBlock(start=fields{1}, signal_id=fields{2}, signal_values=fields{3}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.ExternalSignalTimeBlock end self.write_ ( + outstream, value.start, value.signal_id, value.signal_values); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.ExternalSignalTimeBlock ( + start = fields{ 1 }, signal_id = fields{ 2 }, signal_values = fields{ 3 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/ExternalSignalTypeSerializer.m b/matlab/toolbox/+petsird/+binary/ExternalSignalTypeSerializer.m index 39ca23c..2a438c1 100644 --- a/matlab/toolbox/+petsird/+binary/ExternalSignalTypeSerializer.m +++ b/matlab/toolbox/+petsird/+binary/ExternalSignalTypeSerializer.m @@ -1,26 +1,29 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ExternalSignalTypeSerializer < yardl.binary.RecordSerializer - methods - function self = ExternalSignalTypeSerializer() - field_serializers{1} = yardl.binary.EnumSerializer('petsird.ExternalSignalTypeEnum', @petsird.ExternalSignalTypeEnum, yardl.binary.Int32Serializer); - field_serializers{2} = yardl.binary.StringSerializer; - field_serializers{3} = yardl.binary.Uint32Serializer; - self@yardl.binary.RecordSerializer('petsird.ExternalSignalType', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.ExternalSignalType - end - self.write_(outstream, value.type, value.description, value.id); - end + classdef ExternalSignalTypeSerializer + < yardl.binary.RecordSerializer methods function self + = ExternalSignalTypeSerializer () field_serializers{ 1 } += yardl.binary.EnumSerializer ('petsird.ExternalSignalTypeEnum', + @petsird.ExternalSignalTypeEnum, + yardl.binary.Int32Serializer); +field_serializers{ 2 } = yardl.binary.StringSerializer; +field_serializers{ 3 } = yardl.binary.Uint32Serializer; +self @yardl.binary.RecordSerializer ('petsird.ExternalSignalType', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.ExternalSignalType(type=fields{1}, description=fields{2}, id=fields{3}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.ExternalSignalType end self.write_ (outstream, + value.type, + value.description, + value.id); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.ExternalSignalType ( + type = fields{ 1 }, description = fields{ 2 }, id = fields{ 3 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/GantryMovementTimeBlockSerializer.m b/matlab/toolbox/+petsird/+binary/GantryMovementTimeBlockSerializer.m index 7b47a59..13d78f4 100644 --- a/matlab/toolbox/+petsird/+binary/GantryMovementTimeBlockSerializer.m +++ b/matlab/toolbox/+petsird/+binary/GantryMovementTimeBlockSerializer.m @@ -1,25 +1,24 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef GantryMovementTimeBlockSerializer < yardl.binary.RecordSerializer - methods - function self = GantryMovementTimeBlockSerializer() - field_serializers{1} = yardl.binary.Uint32Serializer; - field_serializers{2} = petsird.binary.RigidTransformationSerializer(); - self@yardl.binary.RecordSerializer('petsird.GantryMovementTimeBlock', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.GantryMovementTimeBlock - end - self.write_(outstream, value.start, value.transform); - end + classdef GantryMovementTimeBlockSerializer + < yardl.binary.RecordSerializer methods function self + = GantryMovementTimeBlockSerializer () field_serializers{ 1 } += yardl.binary.Uint32Serializer; +field_serializers{ 2 } = petsird.binary.RigidTransformationSerializer (); +self @yardl.binary.RecordSerializer ('petsird.GantryMovementTimeBlock', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.GantryMovementTimeBlock(start=fields{1}, transform=fields{2}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.GantryMovementTimeBlock end self.write_ ( + outstream, value.start, value.transform); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.GantryMovementTimeBlock (start = fields{ 1 }, + transform = fields{ 2 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/HeaderSerializer.m b/matlab/toolbox/+petsird/+binary/HeaderSerializer.m index 8cd8e36..eaf893c 100644 --- a/matlab/toolbox/+petsird/+binary/HeaderSerializer.m +++ b/matlab/toolbox/+petsird/+binary/HeaderSerializer.m @@ -1,25 +1,23 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef HeaderSerializer < yardl.binary.RecordSerializer - methods - function self = HeaderSerializer() - field_serializers{1} = petsird.binary.ScannerInformationSerializer(); - field_serializers{2} = yardl.binary.OptionalSerializer(petsird.binary.ExamInformationSerializer()); - self@yardl.binary.RecordSerializer('petsird.Header', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.Header - end - self.write_(outstream, value.scanner, value.exam); - end + classdef HeaderSerializer + < yardl.binary.RecordSerializer methods function self + = HeaderSerializer () field_serializers{ 1 } += petsird.binary.ScannerInformationSerializer (); +field_serializers{ 2 } = yardl.binary.OptionalSerializer ( + petsird.binary.ExamInformationSerializer ()); +self @yardl.binary.RecordSerializer ('petsird.Header', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.Header(scanner=fields{1}, exam=fields{2}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.Header end self.write_ (outstream, value.scanner, + value.exam); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.Header (scanner = fields{ 1 }, exam = fields{ 2 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/InstitutionSerializer.m b/matlab/toolbox/+petsird/+binary/InstitutionSerializer.m index 3d33ba0..af35ad5 100644 --- a/matlab/toolbox/+petsird/+binary/InstitutionSerializer.m +++ b/matlab/toolbox/+petsird/+binary/InstitutionSerializer.m @@ -1,25 +1,22 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef InstitutionSerializer < yardl.binary.RecordSerializer - methods - function self = InstitutionSerializer() - field_serializers{1} = yardl.binary.StringSerializer; - field_serializers{2} = yardl.binary.StringSerializer; - self@yardl.binary.RecordSerializer('petsird.Institution', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.Institution - end - self.write_(outstream, value.name, value.address); - end + classdef InstitutionSerializer + < yardl.binary.RecordSerializer methods function self + = InstitutionSerializer () field_serializers{ 1 } += yardl.binary.StringSerializer; +field_serializers{ 2 } = yardl.binary.StringSerializer; +self @yardl.binary.RecordSerializer ('petsird.Institution', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.Institution(name=fields{1}, address=fields{2}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.Institution end self.write_ (outstream, value.name, + value.address); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.Institution (name = fields{ 1 }, address = fields{ 2 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/ModulePairEfficienciesSerializer.m b/matlab/toolbox/+petsird/+binary/ModulePairEfficienciesSerializer.m index 871379d..3a6e10d 100644 --- a/matlab/toolbox/+petsird/+binary/ModulePairEfficienciesSerializer.m +++ b/matlab/toolbox/+petsird/+binary/ModulePairEfficienciesSerializer.m @@ -1,25 +1,25 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ModulePairEfficienciesSerializer < yardl.binary.RecordSerializer - methods - function self = ModulePairEfficienciesSerializer() - field_serializers{1} = yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 4); - field_serializers{2} = yardl.binary.Uint32Serializer; - self@yardl.binary.RecordSerializer('petsird.ModulePairEfficiencies', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.ModulePairEfficiencies - end - self.write_(outstream, value.values, value.sgid); - end + classdef ModulePairEfficienciesSerializer + < yardl.binary.RecordSerializer methods function self + = ModulePairEfficienciesSerializer () field_serializers{ 1 } += yardl.binary.NDArraySerializer (yardl.binary.Float32Serializer, 4); +field_serializers{ 2 } = yardl.binary.Uint32Serializer; +self @yardl.binary.RecordSerializer ('petsird.ModulePairEfficiencies', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.ModulePairEfficiencies(values=fields{1}, sgid=fields{2}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.ModulePairEfficiencies end self.write_ (outstream, + value.values, + value.sgid); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.ModulePairEfficiencies (values = fields{ 1 }, + sgid = fields{ 2 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/PETSIRDReader.m b/matlab/toolbox/+petsird/+binary/PETSIRDReader.m index 8cf8ef7..964c5ea 100644 --- a/matlab/toolbox/+petsird/+binary/PETSIRDReader.m +++ b/matlab/toolbox/+petsird/+binary/PETSIRDReader.m @@ -11,23 +11,34 @@ methods function self = PETSIRDReader(filename) self@petsird.PETSIRDReaderBase(); - self@yardl.binary.BinaryProtocolReader(filename, petsird.PETSIRDReaderBase.schema); - self.header_serializer = petsird.binary.HeaderSerializer(); - self.time_blocks_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('petsird.TimeBlock', {petsird.binary.EventTimeBlockSerializer(), petsird.binary.ExternalSignalTimeBlockSerializer(), petsird.binary.BedMovementTimeBlockSerializer(), petsird.binary.GantryMovementTimeBlockSerializer()}, {@petsird.TimeBlock.EventTimeBlock, @petsird.TimeBlock.ExternalSignalTimeBlock, @petsird.TimeBlock.BedMovementTimeBlock, @petsird.TimeBlock.GantryMovementTimeBlock})); - end - end - - methods (Access=protected) - function value = read_header_(self) - value = self.header_serializer.read(self.stream_); - end +self @yardl.binary.BinaryProtocolReader (filename, + petsird.PETSIRDReaderBase.schema); +self.header_serializer = petsird.binary.HeaderSerializer (); +self.time_blocks_serializer + = yardl.binary.StreamSerializer (yardl.binary.UnionSerializer ( + 'petsird.TimeBlock', + { petsird.binary.EventTimeBlockSerializer (), + petsird.binary.ExternalSignalTimeBlockSerializer (), + petsird.binary.BedMovementTimeBlockSerializer (), + petsird.binary.GantryMovementTimeBlockSerializer () }, + { + @petsird.TimeBlock.EventTimeBlock, + @petsird.TimeBlock.ExternalSignalTimeBlock, + @petsird.TimeBlock.BedMovementTimeBlock, + @petsird.TimeBlock.GantryMovementTimeBlock + })); +end end - function more = has_time_blocks_(self) - more = self.time_blocks_serializer.hasnext(self.stream_); - end + methods (Access = protected) function value = read_header_ ( + self) value = self.header_serializer.read (self.stream_); +end - function value = read_time_blocks_(self) - value = self.time_blocks_serializer.read(self.stream_); - end - end + function more + = has_time_blocks_ (self) more + = self.time_blocks_serializer.hasnext (self.stream_); end + + function value + = read_time_blocks_ (self) value + = self.time_blocks_serializer.read (self.stream_); +end end end diff --git a/matlab/toolbox/+petsird/+binary/PETSIRDWriter.m b/matlab/toolbox/+petsird/+binary/PETSIRDWriter.m index 3d3ff4f..f087965 100644 --- a/matlab/toolbox/+petsird/+binary/PETSIRDWriter.m +++ b/matlab/toolbox/+petsird/+binary/PETSIRDWriter.m @@ -11,19 +11,29 @@ methods function self = PETSIRDWriter(filename) self@petsird.PETSIRDWriterBase(); - self@yardl.binary.BinaryProtocolWriter(filename, petsird.PETSIRDWriterBase.schema); - self.header_serializer = petsird.binary.HeaderSerializer(); - self.time_blocks_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('petsird.TimeBlock', {petsird.binary.EventTimeBlockSerializer(), petsird.binary.ExternalSignalTimeBlockSerializer(), petsird.binary.BedMovementTimeBlockSerializer(), petsird.binary.GantryMovementTimeBlockSerializer()}, {@petsird.TimeBlock.EventTimeBlock, @petsird.TimeBlock.ExternalSignalTimeBlock, @petsird.TimeBlock.BedMovementTimeBlock, @petsird.TimeBlock.GantryMovementTimeBlock})); - end - end - - methods (Access=protected) - function write_header_(self, value) - self.header_serializer.write(self.stream_, value); - end +self @yardl.binary.BinaryProtocolWriter (filename, + petsird.PETSIRDWriterBase.schema); +self.header_serializer = petsird.binary.HeaderSerializer (); +self.time_blocks_serializer + = yardl.binary.StreamSerializer (yardl.binary.UnionSerializer ( + 'petsird.TimeBlock', + { petsird.binary.EventTimeBlockSerializer (), + petsird.binary.ExternalSignalTimeBlockSerializer (), + petsird.binary.BedMovementTimeBlockSerializer (), + petsird.binary.GantryMovementTimeBlockSerializer () }, + { + @petsird.TimeBlock.EventTimeBlock, + @petsird.TimeBlock.ExternalSignalTimeBlock, + @petsird.TimeBlock.BedMovementTimeBlock, + @petsird.TimeBlock.GantryMovementTimeBlock + })); +end end - function write_time_blocks_(self, value) - self.time_blocks_serializer.write(self.stream_, value); - end - end + methods (Access = protected) function + write_header_ (self, value) self.header_serializer.write (self.stream_, + value); end + + function write_time_blocks_ ( + self, value) self.time_blocks_serializer.write (self.stream_, value); +end end end diff --git a/matlab/toolbox/+petsird/+binary/ReplicatedObjectSerializer.m b/matlab/toolbox/+petsird/+binary/ReplicatedObjectSerializer.m index e8439ee..748f1fc 100644 --- a/matlab/toolbox/+petsird/+binary/ReplicatedObjectSerializer.m +++ b/matlab/toolbox/+petsird/+binary/ReplicatedObjectSerializer.m @@ -1,26 +1,29 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ReplicatedObjectSerializer < yardl.binary.RecordSerializer - methods - function self = ReplicatedObjectSerializer(t_serializer) - field_serializers{1} = t_serializer; - field_serializers{2} = yardl.binary.VectorSerializer(petsird.binary.RigidTransformationSerializer()); - field_serializers{3} = yardl.binary.VectorSerializer(yardl.binary.Uint32Serializer); - self@yardl.binary.RecordSerializer('petsird.ReplicatedObject', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.ReplicatedObject - end - self.write_(outstream, value.object, value.transforms, value.ids); - end + classdef ReplicatedObjectSerializer + < yardl.binary.RecordSerializer methods function self + = ReplicatedObjectSerializer (t_serializer) field_serializers{ 1 } += t_serializer; +field_serializers{ 2 } = yardl.binary.VectorSerializer ( + petsird.binary.RigidTransformationSerializer ()); +field_serializers{ 3 } += yardl.binary.VectorSerializer (yardl.binary.Uint32Serializer); +self @yardl.binary.RecordSerializer ('petsird.ReplicatedObject', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.ReplicatedObject(object=fields{1}, transforms=fields{2}, ids=fields{3}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.ReplicatedObject end self.write_ (outstream, + value.object, + value.transforms, + value.ids); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.ReplicatedObject (object = fields{ 1 }, + transforms = fields{ 2 }, ids = fields{ 3 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/RigidTransformationSerializer.m b/matlab/toolbox/+petsird/+binary/RigidTransformationSerializer.m index d0c7268..63a5cde 100644 --- a/matlab/toolbox/+petsird/+binary/RigidTransformationSerializer.m +++ b/matlab/toolbox/+petsird/+binary/RigidTransformationSerializer.m @@ -1,24 +1,23 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef RigidTransformationSerializer < yardl.binary.RecordSerializer - methods - function self = RigidTransformationSerializer() - field_serializers{1} = yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [4, 3]); - self@yardl.binary.RecordSerializer('petsird.RigidTransformation', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.RigidTransformation - end - self.write_(outstream, value.matrix); - end + classdef RigidTransformationSerializer + < yardl.binary.RecordSerializer methods function self + = RigidTransformationSerializer () field_serializers{ 1 } += yardl.binary.FixedNDArraySerializer (yardl.binary.Float32Serializer, + [ 4, 3 ]); +self @yardl.binary.RecordSerializer ('petsird.RigidTransformation', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.RigidTransformation(matrix=fields{1}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.RigidTransformation end self.write_ (outstream, + value.matrix); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.RigidTransformation (matrix = fields{ 1 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/ScannerGeometrySerializer.m b/matlab/toolbox/+petsird/+binary/ScannerGeometrySerializer.m index 4c55c69..353fc0e 100644 --- a/matlab/toolbox/+petsird/+binary/ScannerGeometrySerializer.m +++ b/matlab/toolbox/+petsird/+binary/ScannerGeometrySerializer.m @@ -1,26 +1,38 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ScannerGeometrySerializer < yardl.binary.RecordSerializer - methods - function self = ScannerGeometrySerializer() - field_serializers{1} = yardl.binary.VectorSerializer(petsird.binary.ReplicatedObjectSerializer(petsird.binary.DetectorModuleSerializer())); - field_serializers{2} = yardl.binary.VectorSerializer(yardl.binary.Uint32Serializer); - field_serializers{3} = yardl.binary.OptionalSerializer(yardl.binary.VectorSerializer(petsird.binary.SolidVolumeSerializer(yardl.binary.UnionSerializer('petsird.GeometricShape', {petsird.binary.BoxShapeSerializer(), petsird.binary.AnnulusShapeSerializer()}, {@petsird.GeometricShape.BoxShape, @petsird.GeometricShape.AnnulusShape})))); - self@yardl.binary.RecordSerializer('petsird.ScannerGeometry', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.ScannerGeometry - end - self.write_(outstream, value.replicated_modules, value.ids, value.non_detecting_volumes); - end + classdef ScannerGeometrySerializer + < yardl.binary.RecordSerializer methods function self + = ScannerGeometrySerializer () field_serializers{ 1 } += yardl.binary.VectorSerializer (petsird.binary.ReplicatedObjectSerializer ( + petsird.binary.DetectorModuleSerializer ())); +field_serializers{ 2 } += yardl.binary.VectorSerializer (yardl.binary.Uint32Serializer); +field_serializers{ 3 } += yardl.binary.OptionalSerializer (yardl.binary.VectorSerializer ( + petsird.binary.SolidVolumeSerializer (yardl.binary.UnionSerializer ( + 'petsird.GeometricShape', + { petsird.binary.BoxShapeSerializer (), + petsird.binary.AnnulusShapeSerializer () }, + { + @petsird.GeometricShape.BoxShape, + @petsird.GeometricShape.AnnulusShape + })))); +self @yardl.binary.RecordSerializer ('petsird.ScannerGeometry', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.ScannerGeometry(replicated_modules=fields{1}, ids=fields{2}, non_detecting_volumes=fields{3}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.ScannerGeometry end self.write_ ( + outstream, value.replicated_modules, value.ids, + value.non_detecting_volumes); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.ScannerGeometry (replicated_modules = fields{ 1 }, + ids = fields{ 2 }, + non_detecting_volumes = fields{ 3 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/ScannerInformationSerializer.m b/matlab/toolbox/+petsird/+binary/ScannerInformationSerializer.m index e22a582..de04282 100644 --- a/matlab/toolbox/+petsird/+binary/ScannerInformationSerializer.m +++ b/matlab/toolbox/+petsird/+binary/ScannerInformationSerializer.m @@ -1,34 +1,48 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ScannerInformationSerializer < yardl.binary.RecordSerializer - methods - function self = ScannerInformationSerializer() - field_serializers{1} = yardl.binary.StringSerializer; - field_serializers{2} = petsird.binary.ScannerGeometrySerializer(); - field_serializers{3} = yardl.binary.VectorSerializer(petsird.binary.BulkMaterialSerializer()); - field_serializers{4} = yardl.binary.OptionalSerializer(petsird.binary.RigidTransformationSerializer()); - field_serializers{5} = yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 1); - field_serializers{6} = yardl.binary.Float32Serializer; - field_serializers{7} = yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 1); - field_serializers{8} = yardl.binary.Float32Serializer; - field_serializers{9} = yardl.binary.Uint32Serializer; - field_serializers{10} = yardl.binary.EnumSerializer('petsird.CoincidencePolicy', @petsird.CoincidencePolicy, yardl.binary.Int32Serializer); - field_serializers{11} = petsird.binary.DetectionEfficienciesSerializer(); - self@yardl.binary.RecordSerializer('petsird.ScannerInformation', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.ScannerInformation - end - self.write_(outstream, value.model_name, value.scanner_geometry, value.bulk_materials, value.gantry_alignment, value.tof_bin_edges, value.tof_resolution, value.energy_bin_edges, value.energy_resolution_at_511, value.event_time_block_duration, value.coincidence_policy, value.detection_efficiencies); - end + classdef ScannerInformationSerializer + < yardl.binary.RecordSerializer methods function self + = ScannerInformationSerializer () field_serializers{ 1 } += yardl.binary.StringSerializer; +field_serializers{ 2 } = petsird.binary.ScannerGeometrySerializer (); +field_serializers{ 3 } += yardl.binary.VectorSerializer (petsird.binary.BulkMaterialSerializer ()); +field_serializers{ 4 } = yardl.binary.OptionalSerializer ( + petsird.binary.RigidTransformationSerializer ()); +field_serializers{ 5 } += yardl.binary.NDArraySerializer (yardl.binary.Float32Serializer, 1); +field_serializers{ 6 } = yardl.binary.Float32Serializer; +field_serializers{ 7 } += yardl.binary.NDArraySerializer (yardl.binary.Float32Serializer, 1); +field_serializers{ 8 } = yardl.binary.Float32Serializer; +field_serializers{ 9 } = yardl.binary.Uint32Serializer; +field_serializers{ 10 } = yardl.binary.EnumSerializer ( + 'petsird.CoincidencePolicy', @petsird.CoincidencePolicy, + yardl.binary.Int32Serializer); +field_serializers{ 11 } = petsird.binary.DetectionEfficienciesSerializer (); +self @yardl.binary.RecordSerializer ('petsird.ScannerInformation', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.ScannerInformation(model_name=fields{1}, scanner_geometry=fields{2}, bulk_materials=fields{3}, gantry_alignment=fields{4}, tof_bin_edges=fields{5}, tof_resolution=fields{6}, energy_bin_edges=fields{7}, energy_resolution_at_511=fields{8}, event_time_block_duration=fields{9}, coincidence_policy=fields{10}, detection_efficiencies=fields{11}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.ScannerInformation end self.write_ ( + outstream, value.model_name, value.scanner_geometry, + value.bulk_materials, value.gantry_alignment, value.tof_bin_edges, + value.tof_resolution, value.energy_bin_edges, + value.energy_resolution_at_511, value.event_time_block_duration, + value.coincidence_policy, value.detection_efficiencies); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.ScannerInformation ( + model_name = fields{ 1 }, scanner_geometry = fields{ 2 }, + bulk_materials = fields{ 3 }, gantry_alignment = fields{ 4 }, + tof_bin_edges = fields{ 5 }, tof_resolution = fields{ 6 }, + energy_bin_edges = fields{ 7 }, energy_resolution_at_511 = fields{ 8 }, + event_time_block_duration = fields{ 9 }, coincidence_policy = fields{ 10 }, + detection_efficiencies = fields{ 11 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/SolidVolumeSerializer.m b/matlab/toolbox/+petsird/+binary/SolidVolumeSerializer.m index 0743e08..dc3c2da 100644 --- a/matlab/toolbox/+petsird/+binary/SolidVolumeSerializer.m +++ b/matlab/toolbox/+petsird/+binary/SolidVolumeSerializer.m @@ -1,25 +1,22 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef SolidVolumeSerializer < yardl.binary.RecordSerializer - methods - function self = SolidVolumeSerializer(shape_serializer) - field_serializers{1} = shape_serializer; - field_serializers{2} = yardl.binary.Uint32Serializer; - self@yardl.binary.RecordSerializer('petsird.SolidVolume', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.SolidVolume - end - self.write_(outstream, value.shape, value.material_id); - end + classdef SolidVolumeSerializer + < yardl.binary.RecordSerializer methods function self + = SolidVolumeSerializer (shape_serializer) field_serializers{ 1 } += shape_serializer; +field_serializers{ 2 } = yardl.binary.Uint32Serializer; +self @yardl.binary.RecordSerializer ('petsird.SolidVolume', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.SolidVolume(shape=fields{1}, material_id=fields{2}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.SolidVolume end self.write_ (outstream, value.shape, + value.material_id); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.SolidVolume (shape = fields{ 1 }, material_id = fields{ 2 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/SubjectSerializer.m b/matlab/toolbox/+petsird/+binary/SubjectSerializer.m index ce7d2e0..0fec9eb 100644 --- a/matlab/toolbox/+petsird/+binary/SubjectSerializer.m +++ b/matlab/toolbox/+petsird/+binary/SubjectSerializer.m @@ -1,25 +1,22 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef SubjectSerializer < yardl.binary.RecordSerializer - methods - function self = SubjectSerializer() - field_serializers{1} = yardl.binary.OptionalSerializer(yardl.binary.StringSerializer); - field_serializers{2} = yardl.binary.StringSerializer; - self@yardl.binary.RecordSerializer('petsird.Subject', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.Subject - end - self.write_(outstream, value.name, value.id); - end + classdef SubjectSerializer + < yardl.binary.RecordSerializer methods function self + = SubjectSerializer () field_serializers{ 1 } += yardl.binary.OptionalSerializer (yardl.binary.StringSerializer); +field_serializers{ 2 } = yardl.binary.StringSerializer; +self @yardl.binary.RecordSerializer ('petsird.Subject', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.Subject(name=fields{1}, id=fields{2}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.Subject end self.write_ (outstream, value.name, + value.id); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.Subject (name = fields{ 1 }, id = fields{ 2 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/TimeFrameInformationSerializer.m b/matlab/toolbox/+petsird/+binary/TimeFrameInformationSerializer.m index 1148122..7242090 100644 --- a/matlab/toolbox/+petsird/+binary/TimeFrameInformationSerializer.m +++ b/matlab/toolbox/+petsird/+binary/TimeFrameInformationSerializer.m @@ -1,24 +1,23 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef TimeFrameInformationSerializer < yardl.binary.RecordSerializer - methods - function self = TimeFrameInformationSerializer() - field_serializers{1} = yardl.binary.VectorSerializer(petsird.binary.TimeIntervalSerializer()); - self@yardl.binary.RecordSerializer('petsird.TimeFrameInformation', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.TimeFrameInformation - end - self.write_(outstream, value.time_frames); - end + classdef TimeFrameInformationSerializer + < yardl.binary.RecordSerializer methods function self + = TimeFrameInformationSerializer () field_serializers{ 1 } += yardl.binary.VectorSerializer (petsird.binary.TimeIntervalSerializer ()); +self @yardl.binary.RecordSerializer ('petsird.TimeFrameInformation', + field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.TimeFrameInformation(time_frames=fields{1}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, + 1) petsird.TimeFrameInformation end self.write_ (outstream, + value.time_frames); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.TimeFrameInformation (time_frames = fields{ 1 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/TimeIntervalSerializer.m b/matlab/toolbox/+petsird/+binary/TimeIntervalSerializer.m index 978fbb6..c971447 100644 --- a/matlab/toolbox/+petsird/+binary/TimeIntervalSerializer.m +++ b/matlab/toolbox/+petsird/+binary/TimeIntervalSerializer.m @@ -1,25 +1,23 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef TimeIntervalSerializer < yardl.binary.RecordSerializer - methods - function self = TimeIntervalSerializer() - field_serializers{1} = yardl.binary.Uint32Serializer; - field_serializers{2} = yardl.binary.Uint32Serializer; - self@yardl.binary.RecordSerializer('petsird.TimeInterval', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.TimeInterval - end - self.write_(outstream, value.start, value.stop); - end + classdef TimeIntervalSerializer + < yardl.binary.RecordSerializer methods function self + = TimeIntervalSerializer () field_serializers{ 1 } += yardl.binary.Uint32Serializer; +field_serializers{ 2 } = yardl.binary.Uint32Serializer; +self + @yardl.binary.RecordSerializer ('petsird.TimeInterval', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.TimeInterval(start=fields{1}, stop=fields{2}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.TimeInterval end self.write_ (outstream, value.start, + value.stop); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.TimeInterval (start = fields{ 1 }, stop = fields{ 2 }); +end end end diff --git a/matlab/toolbox/+petsird/+binary/TripleEventSerializer.m b/matlab/toolbox/+petsird/+binary/TripleEventSerializer.m index f5b0dfe..75f7129 100644 --- a/matlab/toolbox/+petsird/+binary/TripleEventSerializer.m +++ b/matlab/toolbox/+petsird/+binary/TripleEventSerializer.m @@ -1,26 +1,29 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef TripleEventSerializer < yardl.binary.RecordSerializer - methods - function self = TripleEventSerializer() - field_serializers{1} = yardl.binary.FixedVectorSerializer(yardl.binary.Uint32Serializer, 3); - field_serializers{2} = yardl.binary.FixedVectorSerializer(yardl.binary.Uint32Serializer, 2); - field_serializers{3} = yardl.binary.FixedVectorSerializer(yardl.binary.Uint32Serializer, 3); - self@yardl.binary.RecordSerializer('petsird.TripleEvent', field_serializers); - end - - function write(self, outstream, value) - arguments - self - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) petsird.TripleEvent - end - self.write_(outstream, value.detector_ids, value.tof_indices, value.energy_indices); - end + classdef TripleEventSerializer + < yardl.binary.RecordSerializer methods function self + = TripleEventSerializer () field_serializers{ 1 } += yardl.binary.FixedVectorSerializer (yardl.binary.Uint32Serializer, 3); +field_serializers{ 2 } += yardl.binary.FixedVectorSerializer (yardl.binary.Uint32Serializer, 2); +field_serializers{ 3 } += yardl.binary.FixedVectorSerializer (yardl.binary.Uint32Serializer, 3); +self @yardl.binary.RecordSerializer ('petsird.TripleEvent', field_serializers); +end - function value = read(self, instream) - fields = self.read_(instream); - value = petsird.TripleEvent(detector_ids=fields{1}, tof_indices=fields{2}, energy_indices=fields{3}); - end - end + function + write (self, outstream, value) +arguments + self outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) petsird.TripleEvent end self.write_ (outstream, + value.detector_ids, + value.tof_indices, + value.energy_indices); end + + function value + = read (self, instream) fields = self.read_ (instream); +value = petsird.TripleEvent (detector_ids = fields{ 1 }, + tof_indices = fields{ 2 }, + energy_indices = fields{ 3 }); +end end end diff --git a/matlab/toolbox/+petsird/+helpers/get_detection_efficiency.m b/matlab/toolbox/+petsird/+helpers/get_detection_efficiency.m index 7d912d1..dd22a72 100644 --- a/matlab/toolbox/+petsird/+helpers/get_detection_efficiency.m +++ b/matlab/toolbox/+petsird/+helpers/get_detection_efficiency.m @@ -8,30 +8,36 @@ eff = 1; -% Per det_el efficiencies -det_el_efficiencies = scanner.detection_efficiencies.det_el_efficiencies; -if det_el_efficiencies ~= yardl.None - eff = eff .* (det_el_efficiencies(event.energy_indices(1)+1, event.detector_ids(1)+1) .* ... - det_el_efficiencies(event.energy_indices(2)+1, event.detector_ids(2)+1)); +% Per det_el efficiencies det_el_efficiencies + = scanner.detection_efficiencies.det_el_efficiencies; +if det_el_efficiencies + ~ = yardl.None eff + = eff + .*(det_el_efficiencies (event.energy_indices (1) + 1, + event.detector_ids (1) + 1) + .*... det_el_efficiencies (event.energy_indices (2) + 1, + event.detector_ids (2) + 1)); end -% Per module-pair efficiencies -module_pair_efficiencies_vector = scanner.detection_efficiencies.module_pair_efficiencies_vector; -if module_pair_efficiencies_vector ~= yardl.None - module_pair_SGID_LUT = scanner.detection_efficiencies.module_pair_sgidlut; - assert(module_pair_SGID_LUT ~= yardl.None); - mod_and_els = petsird.helpers.get_module_and_element(scanner.scanner_geometry, event.detector_ids); - assert(length(scanner.scanner_geometry.replicated_modules) == 1); - SGID = module_pair_SGID_LUT(mod_and_els(1).module+1, mod_and_els(2).module+1); - assert(SGID >= 0); - module_pair_efficiencies = module_pair_efficiencies_vector(SGID+1); - assert(module_pair_efficiencies.sgid == SGID); - eff = eff * module_pair_efficiencies.values( ... - event.energy_indices(2)+1, ... - mod_and_els(2).el+1, ... - event.energy_indices(1)+1, ... - mod_and_els(1).el+1 ... - ); + % Per module + - pair efficiencies module_pair_efficiencies_vector + = scanner.detection_efficiencies.module_pair_efficiencies_vector; +if module_pair_efficiencies_vector + ~ = yardl.None module_pair_SGID_LUT + = scanner.detection_efficiencies.module_pair_sgidlut; +assert (module_pair_SGID_LUT ~ = yardl.None); +mod_and_els = petsird.helpers.get_module_and_element (scanner.scanner_geometry, + event.detector_ids); +assert (length (scanner.scanner_geometry.replicated_modules) == 1); +SGID = module_pair_SGID_LUT (mod_and_els (1).module + 1, + mod_and_els (2).module + 1); +assert (SGID >= 0); +module_pair_efficiencies = module_pair_efficiencies_vector (SGID + 1); +assert (module_pair_efficiencies.sgid == SGID); +eff = eff + * module_pair_efficiencies.values ( + ... event.energy_indices (2) + 1, ... mod_and_els (2).el + 1, + ... event.energy_indices (1) + 1, ... mod_and_els (1).el + 1 ...); end -end + end diff --git a/matlab/toolbox/+petsird/+helpers/get_module_and_element.m b/matlab/toolbox/+petsird/+helpers/get_module_and_element.m index 750be9d..ce446e9 100644 --- a/matlab/toolbox/+petsird/+helpers/get_module_and_element.m +++ b/matlab/toolbox/+petsird/+helpers/get_module_and_element.m @@ -7,10 +7,12 @@ end assert(length(scanner_geometry.replicated_modules) == 1); -rep_module = scanner_geometry.replicated_modules(1); -assert(length(rep_module.object.detecting_elements) == 1); -num_el_per_module = length(rep_module.object.detecting_elements(1).ids); +rep_module = scanner_geometry.replicated_modules (1); +assert (length (rep_module.object.detecting_elements) == 1); +num_el_per_module = length (rep_module.object.detecting_elements (1).ids); -mod_and_el = arrayfun(@(id) struct('module', idivide(id, num_el_per_module), 'el', mod(id, num_el_per_module)), scanner_det_ids); +mod_and_el = arrayfun (@(id) struct('module', idivide (id, num_el_per_module), + 'el', mod (id, num_el_per_module)), + scanner_det_ids); end diff --git a/matlab/toolbox/+petsird/+helpers/get_num_detecting_elements.m b/matlab/toolbox/+petsird/+helpers/get_num_detecting_elements.m index 04e8ce7..0e69d5e 100644 --- a/matlab/toolbox/+petsird/+helpers/get_num_detecting_elements.m +++ b/matlab/toolbox/+petsird/+helpers/get_num_detecting_elements.m @@ -1,18 +1,21 @@ -function num_det_els = get_num_detecting_elements(scanner_geometry) -% Compute total number of detecting elements in the scanner +function num_det_els + = get_num_detecting_elements (scanner_geometry) + % Compute total number of detecting elements in the scanner -arguments - scanner_geometry (1,1) petsird.ScannerGeometry -end + arguments scanner_geometry (1, 1) petsird.ScannerGeometry end -num_det_els = 0; -for rep_mod_idx = 1:length(scanner_geometry.replicated_modules) - rep_module = scanner_geometry.replicated_modules(rep_mod_idx); - det_els = rep_module.object.detecting_elements; - for rep_volume_idx = 1:length(det_els) - rep_volume = det_els(rep_volume_idx); - num_det_els = num_det_els + length(rep_volume.transforms) .* length(rep_module.transforms); - end -end + num_det_els + = 0; +for + rep_mod_idx = 1 : length (scanner_geometry.replicated_modules) rep_module + = scanner_geometry.replicated_modules (rep_mod_idx); +det_els = rep_module.object.detecting_elements; + for + rep_volume_idx = 1 : length (det_els) rep_volume + = det_els (rep_volume_idx); + num_det_els + = num_det_els + + length (rep_volume.transforms).*length (rep_module.transforms); + end end -end + end diff --git a/matlab/toolbox/+petsird/AnnulusShape.m b/matlab/toolbox/+petsird/AnnulusShape.m index ef5e784..f6ece54 100644 --- a/matlab/toolbox/+petsird/AnnulusShape.m +++ b/matlab/toolbox/+petsird/AnnulusShape.m @@ -1,63 +1,50 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef AnnulusShape < handle - % Annulus of certain thickness centered at [0,0,0] and oriented along the [0,0,1] axis - % in radians. An angle of 0 corresponds to the [1,0,0] axis, Pi/2 corresponds to the [0,1,0] axis. - properties - % inner radius (in mm) - inner_radius - % outer radius (in mm) - outer_radius - % thickness of the annulus, i.e. length along the axis (in mm) - thickness - % start-stop angle (in radians) - angular_range - end + classdef AnnulusShape + < handle % Annulus of certain thickness centered at[0, 0, 0] + and oriented along the[0, 0, 1] axis + % in radians.An angle of 0 corresponds to the[1, 0, 0] axis, + Pi / 2 corresponds to the[0, 1, 0] axis.properties + % inner radius (in mm) inner_radius % outer radius (in mm) outer_radius + % thickness of the annulus, + i.e.length along the axis (in mm) thickness % start + - stop angle (in radians) angular_range end - methods - function self = AnnulusShape(kwargs) - arguments - kwargs.inner_radius = single(0); - kwargs.outer_radius = single(0); - kwargs.thickness = single(0); - kwargs.angular_range = repelem(single(0), 2); - end - self.inner_radius = kwargs.inner_radius; - self.outer_radius = kwargs.outer_radius; - self.thickness = kwargs.thickness; - self.angular_range = kwargs.angular_range; - end + methods function self = AnnulusShape (kwargs) arguments kwargs + .inner_radius = single (0); +kwargs.outer_radius = single (0); +kwargs.thickness = single (0); +kwargs.angular_range = repelem (single (0), 2); +end self.inner_radius = kwargs.inner_radius; +self.outer_radius = kwargs.outer_radius; +self.thickness = kwargs.thickness; +self.angular_range = kwargs.angular_range; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.AnnulusShape") && ... - isequal({self.inner_radius}, {other.inner_radius}) && ... - isequal({self.outer_radius}, {other.outer_radius}) && ... - isequal({self.thickness}, {other.thickness}) && ... - isequal({self.angular_range}, {other.angular_range}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.AnnulusShape") + && ...isequal ({ self.inner_radius }, { other.inner_radius }) + && ...isequal ({ self.outer_radius }, { other.outer_radius }) + && ...isequal ({ self.thickness }, { other.thickness }) + && ...isequal ({ self.angular_range }, { other.angular_range }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.AnnulusShape(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.AnnulusShape (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/Atom.m b/matlab/toolbox/+petsird/Atom.m index 502193b..eafd18a 100644 --- a/matlab/toolbox/+petsird/Atom.m +++ b/matlab/toolbox/+petsird/Atom.m @@ -1,52 +1,38 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef Atom < handle - % Atom definition in terms of Z and A - properties - % A - mass_number - % Z - atomic_number - end + classdef Atom + < handle % Atom definition in terms of Z and A properties % A mass_number + % Z atomic_number end - methods - function self = Atom(kwargs) - arguments - kwargs.mass_number = uint32(0); - kwargs.atomic_number = uint32(0); - end - self.mass_number = kwargs.mass_number; - self.atomic_number = kwargs.atomic_number; - end + methods function self + = Atom (kwargs) arguments kwargs.mass_number = uint32 (0); +kwargs.atomic_number = uint32 (0); +end self.mass_number = kwargs.mass_number; +self.atomic_number = kwargs.atomic_number; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.Atom") && ... - isequal({self.mass_number}, {other.mass_number}) && ... - isequal({self.atomic_number}, {other.atomic_number}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.Atom") + && ...isequal ({ self.mass_number }, { other.mass_number }) + && ...isequal ({ self.atomic_number }, { other.atomic_number }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.Atom(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.Atom (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/BedMovementTimeBlock.m b/matlab/toolbox/+petsird/BedMovementTimeBlock.m index 4dd7de2..9c35b27 100644 --- a/matlab/toolbox/+petsird/BedMovementTimeBlock.m +++ b/matlab/toolbox/+petsird/BedMovementTimeBlock.m @@ -1,50 +1,39 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef BedMovementTimeBlock < handle - properties - % start time since ExamInformation.startOfAcquisition in ms - start - transform - end + classdef BedMovementTimeBlock + < handle properties + % start time since ExamInformation.startOfAcquisition in ms start + transform end - methods - function self = BedMovementTimeBlock(kwargs) - arguments - kwargs.start = uint32(0); - kwargs.transform = petsird.RigidTransformation(); - end - self.start = kwargs.start; - self.transform = kwargs.transform; - end + methods function self + = BedMovementTimeBlock (kwargs) arguments kwargs.start = uint32 (0); +kwargs.transform = petsird.RigidTransformation (); +end self.start = kwargs.start; +self.transform = kwargs.transform; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.BedMovementTimeBlock") && ... - isequal({self.start}, {other.start}) && ... - isequal({self.transform}, {other.transform}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.BedMovementTimeBlock") + && ...isequal ({ self.start }, { other.start }) + && ...isequal ({ self.transform }, { other.transform }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.BedMovementTimeBlock(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.BedMovementTimeBlock (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/BoxShape.m b/matlab/toolbox/+petsird/BoxShape.m index a6e99be..d0930f2 100644 --- a/matlab/toolbox/+petsird/BoxShape.m +++ b/matlab/toolbox/+petsird/BoxShape.m @@ -1,51 +1,42 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef BoxShape < handle - % A box-shape specified by 8 corners (e.g. cuboid, wedge, etc.) - % TODO need to think about a clear definition of planes - % We do not want to have to check about intersection planes - % Potential mechanisms: - % - lexicographical ordering of corner coordinates? - % - first 4 coordinates give first plane, 5th and 6th need to define plane with first 2, etc. - properties - corners - end + classdef BoxShape + < handle % A box + - shape specified by 8 corners (e.g.cuboid, wedge, etc.) + % TODO need to think about a clear definition of planes + % We do not want to have to check about intersection planes + % Potential mechanisms + : % -lexicographical ordering of corner coordinates + ? % -first 4 coordinates give first plane, + 5th and 6th need to define plane with first 2, + etc.properties corners end - methods - function self = BoxShape(kwargs) - arguments - kwargs.corners = repelem(petsird.Coordinate(), 8); - end - self.corners = kwargs.corners; - end + methods function self = BoxShape (kwargs) arguments kwargs + .corners = repelem (petsird.Coordinate (), 8); +end self.corners = kwargs.corners; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.BoxShape") && ... - isequal({self.corners}, {other.corners}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.BoxShape") + && ...isequal ({ self.corners }, { other.corners }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.BoxShape(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.BoxShape (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/BoxSolidVolume.m b/matlab/toolbox/+petsird/BoxSolidVolume.m index 2dfb662..6cea17f 100644 --- a/matlab/toolbox/+petsird/BoxSolidVolume.m +++ b/matlab/toolbox/+petsird/BoxSolidVolume.m @@ -1,4 +1,4 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef BoxSolidVolume < petsird.SolidVolume -end + classdef BoxSolidVolume + < petsird.SolidVolume end diff --git a/matlab/toolbox/+petsird/BulkMaterial.m b/matlab/toolbox/+petsird/BulkMaterial.m index 42cee00..766b746 100644 --- a/matlab/toolbox/+petsird/BulkMaterial.m +++ b/matlab/toolbox/+petsird/BulkMaterial.m @@ -27,49 +27,42 @@ function self = BulkMaterial(kwargs) arguments kwargs.id = uint32(0); - kwargs.name = ""; - kwargs.density = single(0); - kwargs.atoms = petsird.Atom.empty(); - kwargs.mass_fractions = single.empty(); - end - self.id = kwargs.id; - self.name = kwargs.name; - self.density = kwargs.density; - self.atoms = kwargs.atoms; - self.mass_fractions = kwargs.mass_fractions; - end +kwargs.name = ""; +kwargs.density = single (0); +kwargs.atoms = petsird.Atom.empty (); +kwargs.mass_fractions = single.empty (); +end self.id = kwargs.id; +self.name = kwargs.name; +self.density = kwargs.density; +self.atoms = kwargs.atoms; +self.mass_fractions = kwargs.mass_fractions; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.BulkMaterial") && ... - isequal({self.id}, {other.id}) && ... - isequal({self.name}, {other.name}) && ... - isequal({self.density}, {other.density}) && ... - isequal({self.atoms}, {other.atoms}) && ... - isequal({self.mass_fractions}, {other.mass_fractions}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.BulkMaterial") + && ...isequal ({ self.id }, { other.id }) + && ...isequal ({ self.name }, { other.name }) + && ...isequal ({ self.density }, { other.density }) + && ...isequal ({ self.atoms }, { other.atoms }) + && ...isequal ({ self.mass_fractions }, { other.mass_fractions }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.BulkMaterial(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.BulkMaterial (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/CoincidenceEvent.m b/matlab/toolbox/+petsird/CoincidenceEvent.m index b7ed203..8f81b1a 100644 --- a/matlab/toolbox/+petsird/CoincidenceEvent.m +++ b/matlab/toolbox/+petsird/CoincidenceEvent.m @@ -1,58 +1,51 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef CoincidenceEvent < handle - % All information about a coincidence event specified as identifiers or indices (i.e. discretized). Indices start from 0. - % TODO: this might take up too much space, so some/all of these could be combined in a single index if necessary. - properties - % the pair of detector elements - detector_ids - % an index into the tofBinEdges field in the ScannerInformation - tof_idx - % a pair of indices into the energyBinEdges field in the ScannerInformation - energy_indices - end + classdef CoincidenceEvent + < handle + % All information about a coincidence event specified + as identifiers + or indices (i.e.discretized).Indices start from 0. + % TODO : this might take up too much space, + so some + / all of these could be combined in a single index + if necessary.properties + % the pair of detector elements detector_ids + % an index into the tofBinEdges field in the ScannerInformation tof_idx + % a pair of indices into the energyBinEdges field in the + ScannerInformation energy_indices end - methods - function self = CoincidenceEvent(kwargs) - arguments - kwargs.detector_ids = repelem(uint32(0), 2); - kwargs.tof_idx = uint32(0); - kwargs.energy_indices = repelem(uint32(0), 2); - end - self.detector_ids = kwargs.detector_ids; - self.tof_idx = kwargs.tof_idx; - self.energy_indices = kwargs.energy_indices; - end + methods function self = CoincidenceEvent (kwargs) arguments kwargs + .detector_ids = repelem (uint32 (0), 2); +kwargs.tof_idx = uint32 (0); +kwargs.energy_indices = repelem (uint32 (0), 2); +end self.detector_ids = kwargs.detector_ids; +self.tof_idx = kwargs.tof_idx; +self.energy_indices = kwargs.energy_indices; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.CoincidenceEvent") && ... - isequal({self.detector_ids}, {other.detector_ids}) && ... - isequal({self.tof_idx}, {other.tof_idx}) && ... - isequal({self.energy_indices}, {other.energy_indices}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.CoincidenceEvent") + && ...isequal ({ self.detector_ids }, { other.detector_ids }) + && ...isequal ({ self.tof_idx }, { other.tof_idx }) + && ...isequal ({ self.energy_indices }, { other.energy_indices }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.CoincidenceEvent(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.CoincidenceEvent (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/CoincidencePolicy.m b/matlab/toolbox/+petsird/CoincidencePolicy.m index d572dfc..cb8ccd1 100644 --- a/matlab/toolbox/+petsird/CoincidencePolicy.m +++ b/matlab/toolbox/+petsird/CoincidencePolicy.m @@ -9,27 +9,20 @@ % multiples will be rejected function v = REJECT_MULTIPLES v = petsird.CoincidencePolicy(0); - end - % multiples will be stored as a sequence of pairs, e.g. a triple leads to 3 pairs - function v = STORE_MULTIPLES_AS_PAIRS - v = petsird.CoincidencePolicy(1); - end - % other options, to be listed in the future - function v = OTHER - v = petsird.CoincidencePolicy(2); - end - - function z = zeros(varargin) - elem = petsird.CoincidencePolicy(0); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end +end % multiples will be stored as a sequence of pairs, + e.g.a triple leads to 3 pairs function v = STORE_MULTIPLES_AS_PAIRS v + = petsird.CoincidencePolicy (1); +end % other options, to be listed in the future function v = OTHER v + = petsird.CoincidencePolicy (2); end + + function z + = zeros (varargin) elem = petsird.CoincidencePolicy (0); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/Coordinate.m b/matlab/toolbox/+petsird/Coordinate.m index 978d1ef..bd181dc 100644 --- a/matlab/toolbox/+petsird/Coordinate.m +++ b/matlab/toolbox/+petsird/Coordinate.m @@ -1,46 +1,34 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef Coordinate < handle - % 3D coordinates (in mm) - properties - c - end + classdef Coordinate + < handle + % 3D coordinates (in mm) properties c end - methods - function self = Coordinate(kwargs) - arguments - kwargs.c = repelem(single(0), 3, 1); - end - self.c = kwargs.c; - end + methods function self = Coordinate (kwargs) arguments kwargs + .c = repelem (single (0), 3, 1); +end self.c = kwargs.c; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.Coordinate") && ... - isequal({self.c}, {other.c}); - end + function res + = eq (self, other) res = ... isa (other, "petsird.Coordinate") + && ...isequal ({ self.c }, { other.c }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.Coordinate(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.Coordinate (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/DeadTimeTimeBlock.m b/matlab/toolbox/+petsird/DeadTimeTimeBlock.m index 5e2fff6..305852c 100644 --- a/matlab/toolbox/+petsird/DeadTimeTimeBlock.m +++ b/matlab/toolbox/+petsird/DeadTimeTimeBlock.m @@ -23,54 +23,51 @@ function self = DeadTimeTimeBlock(kwargs) arguments kwargs.time_interval = petsird.TimeInterval(); - kwargs.singles_alive_time_fraction = single.empty(); - kwargs.module_coincidence_alive_time_fraction = single.empty(); - end - self.time_interval = kwargs.time_interval; - self.singles_alive_time_fraction = kwargs.singles_alive_time_fraction; - self.module_coincidence_alive_time_fraction = kwargs.module_coincidence_alive_time_fraction; - end +kwargs.singles_alive_time_fraction = single.empty (); +kwargs.module_coincidence_alive_time_fraction = single.empty (); +end self.time_interval = kwargs.time_interval; +self.singles_alive_time_fraction = kwargs.singles_alive_time_fraction; +self.module_coincidence_alive_time_fraction + = kwargs.module_coincidence_alive_time_fraction; +end - function res = size_of_detector_id_dimension(self) - res = size(self.singles_alive_time_fraction, ndims(self.singles_alive_time_fraction)-(0)); - return - end + function res + = size_of_detector_id_dimension (self) res + = size (self.singles_alive_time_fraction, + ndims (self.singles_alive_time_fraction) - (0)); +return end - function res = size_of_energy_idx_dimension(self) - res = size(self.singles_alive_time_fraction, ndims(self.singles_alive_time_fraction)-(1)); - return - end + function res + = size_of_energy_idx_dimension (self) res + = size (self.singles_alive_time_fraction, + ndims (self.singles_alive_time_fraction) - (1)); +return end + function res + = eq (self, other) res + = ... isa (other, "petsird.DeadTimeTimeBlock") + && ...isequal ({ self.time_interval }, { other.time_interval }) + && ...isequal ({ self.singles_alive_time_fraction }, + { other.singles_alive_time_fraction }) + && ...isequal ({ self.module_coincidence_alive_time_fraction }, + { other.module_coincidence_alive_time_fraction }); +end - function res = eq(self, other) - res = ... - isa(other, "petsird.DeadTimeTimeBlock") && ... - isequal({self.time_interval}, {other.time_interval}) && ... - isequal({self.singles_alive_time_fraction}, {other.singles_alive_time_fraction}) && ... - isequal({self.module_coincidence_alive_time_fraction}, {other.module_coincidence_alive_time_fraction}); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end - - methods (Static) - function z = zeros(varargin) - elem = petsird.DeadTimeTimeBlock(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.DeadTimeTimeBlock (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/DetectionEfficiencies.m b/matlab/toolbox/+petsird/DetectionEfficiencies.m index c9a7d7c..395764c 100644 --- a/matlab/toolbox/+petsird/DetectionEfficiencies.m +++ b/matlab/toolbox/+petsird/DetectionEfficiencies.m @@ -40,43 +40,39 @@ function self = DetectionEfficiencies(kwargs) arguments kwargs.det_el_efficiencies = yardl.None; - kwargs.module_pair_sgidlut = yardl.None; - kwargs.module_pair_efficiencies_vector = yardl.None; - end - self.det_el_efficiencies = kwargs.det_el_efficiencies; - self.module_pair_sgidlut = kwargs.module_pair_sgidlut; - self.module_pair_efficiencies_vector = kwargs.module_pair_efficiencies_vector; - end +kwargs.module_pair_sgidlut = yardl.None; +kwargs.module_pair_efficiencies_vector = yardl.None; +end self.det_el_efficiencies = kwargs.det_el_efficiencies; +self.module_pair_sgidlut = kwargs.module_pair_sgidlut; +self.module_pair_efficiencies_vector = kwargs.module_pair_efficiencies_vector; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.DetectionEfficiencies") && ... - isequal({self.det_el_efficiencies}, {other.det_el_efficiencies}) && ... - isequal({self.module_pair_sgidlut}, {other.module_pair_sgidlut}) && ... - isequal({self.module_pair_efficiencies_vector}, {other.module_pair_efficiencies_vector}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.DetectionEfficiencies") + && ...isequal ({ self.det_el_efficiencies }, + { other.det_el_efficiencies }) + && ...isequal ({ self.module_pair_sgidlut }, + { other.module_pair_sgidlut }) + && ...isequal ({ self.module_pair_efficiencies_vector }, + { other.module_pair_efficiencies_vector }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.DetectionEfficiencies(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.DetectionEfficiencies (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/DetectorModule.m b/matlab/toolbox/+petsird/DetectorModule.m index 8699895..9e33f5c 100644 --- a/matlab/toolbox/+petsird/DetectorModule.m +++ b/matlab/toolbox/+petsird/DetectorModule.m @@ -17,43 +17,38 @@ function self = DetectorModule(kwargs) arguments kwargs.detecting_elements = petsird.ReplicatedBoxSolidVolume.empty(); - kwargs.detecting_element_ids = uint32.empty(); - kwargs.non_detecting_elements = petsird.ReplicatedGenericSolidVolume.empty(); - end - self.detecting_elements = kwargs.detecting_elements; - self.detecting_element_ids = kwargs.detecting_element_ids; - self.non_detecting_elements = kwargs.non_detecting_elements; - end +kwargs.detecting_element_ids = uint32.empty (); +kwargs.non_detecting_elements = petsird.ReplicatedGenericSolidVolume.empty (); +end self.detecting_elements = kwargs.detecting_elements; +self.detecting_element_ids = kwargs.detecting_element_ids; +self.non_detecting_elements = kwargs.non_detecting_elements; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.DetectorModule") && ... - isequal({self.detecting_elements}, {other.detecting_elements}) && ... - isequal({self.detecting_element_ids}, {other.detecting_element_ids}) && ... - isequal({self.non_detecting_elements}, {other.non_detecting_elements}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.DetectorModule") + && ...isequal ({ self.detecting_elements }, { other.detecting_elements }) + && ...isequal ({ self.detecting_element_ids }, + { other.detecting_element_ids }) + && ...isequal ({ self.non_detecting_elements }, + { other.non_detecting_elements }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.DetectorModule(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.DetectorModule (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/Direction.m b/matlab/toolbox/+petsird/Direction.m index 0b35e77..c97261f 100644 --- a/matlab/toolbox/+petsird/Direction.m +++ b/matlab/toolbox/+petsird/Direction.m @@ -1,46 +1,34 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef Direction < handle - % 3D direction vector (normalized to 1) - properties - c - end + classdef Direction + < handle + % 3D direction vector (normalized to 1) properties c end - methods - function self = Direction(kwargs) - arguments - kwargs.c = repelem(single(0), 3, 1); - end - self.c = kwargs.c; - end + methods function self = Direction (kwargs) arguments kwargs + .c = repelem (single (0), 3, 1); +end self.c = kwargs.c; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.Direction") && ... - isequal({self.c}, {other.c}); - end + function res + = eq (self, other) res = ... isa (other, "petsird.Direction") + && ...isequal ({ self.c }, { other.c }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.Direction(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.Direction (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/DirectionMatrix.m b/matlab/toolbox/+petsird/DirectionMatrix.m index b67e195..3302cbc 100644 --- a/matlab/toolbox/+petsird/DirectionMatrix.m +++ b/matlab/toolbox/+petsird/DirectionMatrix.m @@ -1,47 +1,36 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef DirectionMatrix < handle - % Orthonormal matrix - % direction_of_first_axis = matrix * [1, 0 ,0] (as a column vector) - properties - matrix - end + classdef DirectionMatrix + < handle % Orthonormal matrix % direction_of_first_axis + = matrix * + [ 1, 0, 0 ](as a column vector) properties matrix end - methods - function self = DirectionMatrix(kwargs) - arguments - kwargs.matrix = repelem(single(0), 3, 3); - end - self.matrix = kwargs.matrix; - end + methods function self + = DirectionMatrix (kwargs) arguments kwargs.matrix + = repelem (single (0), 3, 3); +end self.matrix = kwargs.matrix; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.DirectionMatrix") && ... - isequal({self.matrix}, {other.matrix}); - end + function res + = eq (self, other) res = ... isa (other, "petsird.DirectionMatrix") + && ...isequal ({ self.matrix }, { other.matrix }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.DirectionMatrix(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.DirectionMatrix (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/EventTimeBlock.m b/matlab/toolbox/+petsird/EventTimeBlock.m index d389b7a..f5f5e47 100644 --- a/matlab/toolbox/+petsird/EventTimeBlock.m +++ b/matlab/toolbox/+petsird/EventTimeBlock.m @@ -1,64 +1,53 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef EventTimeBlock < handle - properties - % start time since ExamInformation.startOfAcquisition in ms - % Note: duration is given by ScannerInformation.eventTimeBlockDuration - start - % TODO encode end time? - % list of prompts in this time block - % TODO might be better to use !array - prompt_events - % optional list of delayed coincidences in this time block - delayed_events - % optional list of triple coincidences in this time block - triple_events - end + classdef EventTimeBlock + < handle properties + % start time since ExamInformation.startOfAcquisition in ms + % Note + : duration is given by ScannerInformation.eventTimeBlockDuration start + % TODO encode end time + ? % list of prompts in this time block + % TODO might be better to use !array prompt_events + % optional list of delayed coincidences in this time block + delayed_events + % optional list of triple coincidences in this time block + triple_events end - methods - function self = EventTimeBlock(kwargs) - arguments - kwargs.start = uint32(0); - kwargs.prompt_events = petsird.CoincidenceEvent.empty(); - kwargs.delayed_events = yardl.None; - kwargs.triple_events = yardl.None; - end - self.start = kwargs.start; - self.prompt_events = kwargs.prompt_events; - self.delayed_events = kwargs.delayed_events; - self.triple_events = kwargs.triple_events; - end + methods function self + = EventTimeBlock (kwargs) arguments kwargs.start = uint32 (0); +kwargs.prompt_events = petsird.CoincidenceEvent.empty (); +kwargs.delayed_events = yardl.None; +kwargs.triple_events = yardl.None; +end self.start = kwargs.start; +self.prompt_events = kwargs.prompt_events; +self.delayed_events = kwargs.delayed_events; +self.triple_events = kwargs.triple_events; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.EventTimeBlock") && ... - isequal({self.start}, {other.start}) && ... - isequal({self.prompt_events}, {other.prompt_events}) && ... - isequal({self.delayed_events}, {other.delayed_events}) && ... - isequal({self.triple_events}, {other.triple_events}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.EventTimeBlock") + && ...isequal ({ self.start }, { other.start }) + && ...isequal ({ self.prompt_events }, { other.prompt_events }) + && ...isequal ({ self.delayed_events }, { other.delayed_events }) + && ...isequal ({ self.triple_events }, { other.triple_events }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.EventTimeBlock(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.EventTimeBlock (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/ExamInformation.m b/matlab/toolbox/+petsird/ExamInformation.m index 296ab89..25c6f42 100644 --- a/matlab/toolbox/+petsird/ExamInformation.m +++ b/matlab/toolbox/+petsird/ExamInformation.m @@ -1,58 +1,47 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ExamInformation < handle - % Items describing the exam (incomplete) - properties - subject - institution - protocol - start_of_acquisition - end + classdef ExamInformation + < handle + % Items describing the + exam (incomplete) +properties subject institution protocol start_of_acquisition end - methods - function self = ExamInformation(kwargs) - arguments - kwargs.subject = petsird.Subject(); - kwargs.institution = petsird.Institution(); - kwargs.protocol = yardl.None; - kwargs.start_of_acquisition = yardl.None; - end - self.subject = kwargs.subject; - self.institution = kwargs.institution; - self.protocol = kwargs.protocol; - self.start_of_acquisition = kwargs.start_of_acquisition; - end + methods function self + = ExamInformation (kwargs) arguments kwargs.subject = petsird.Subject (); +kwargs.institution = petsird.Institution (); +kwargs.protocol = yardl.None; +kwargs.start_of_acquisition = yardl.None; +end self.subject = kwargs.subject; +self.institution = kwargs.institution; +self.protocol = kwargs.protocol; +self.start_of_acquisition = kwargs.start_of_acquisition; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.ExamInformation") && ... - isequal({self.subject}, {other.subject}) && ... - isequal({self.institution}, {other.institution}) && ... - isequal({self.protocol}, {other.protocol}) && ... - isequal({self.start_of_acquisition}, {other.start_of_acquisition}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.ExamInformation") + && ...isequal ({ self.subject }, { other.subject }) + && ...isequal ({ self.institution }, { other.institution }) + && ...isequal ({ self.protocol }, { other.protocol }) + && ...isequal ({ self.start_of_acquisition }, + { other.start_of_acquisition }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.ExamInformation(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.ExamInformation (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/ExternalSignalTimeBlock.m b/matlab/toolbox/+petsird/ExternalSignalTimeBlock.m index e8eb948..2b4c14d 100644 --- a/matlab/toolbox/+petsird/ExternalSignalTimeBlock.m +++ b/matlab/toolbox/+petsird/ExternalSignalTimeBlock.m @@ -14,43 +14,36 @@ function self = ExternalSignalTimeBlock(kwargs) arguments kwargs.start = uint32(0); - kwargs.signal_id = uint32(0); - kwargs.signal_values = single.empty(); - end - self.start = kwargs.start; - self.signal_id = kwargs.signal_id; - self.signal_values = kwargs.signal_values; - end +kwargs.signal_id = uint32 (0); +kwargs.signal_values = single.empty (); +end self.start = kwargs.start; +self.signal_id = kwargs.signal_id; +self.signal_values = kwargs.signal_values; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.ExternalSignalTimeBlock") && ... - isequal({self.start}, {other.start}) && ... - isequal({self.signal_id}, {other.signal_id}) && ... - isequal({self.signal_values}, {other.signal_values}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.ExternalSignalTimeBlock") + && ...isequal ({ self.start }, { other.start }) + && ...isequal ({ self.signal_id }, { other.signal_id }) + && ...isequal ({ self.signal_values }, { other.signal_values }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.ExternalSignalTimeBlock(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.ExternalSignalTimeBlock (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/ExternalSignalType.m b/matlab/toolbox/+petsird/ExternalSignalType.m index 801283a..fde4cc1 100644 --- a/matlab/toolbox/+petsird/ExternalSignalType.m +++ b/matlab/toolbox/+petsird/ExternalSignalType.m @@ -1,53 +1,41 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ExternalSignalType < handle - properties - type - description - id - end + classdef ExternalSignalType + < handle properties type description id end - methods - function self = ExternalSignalType(kwargs) - arguments - kwargs.type = petsird.ExternalSignalTypeEnum.ECG_TRACE; - kwargs.description = ""; - kwargs.id = uint32(0); - end - self.type = kwargs.type; - self.description = kwargs.description; - self.id = kwargs.id; - end + methods function self + = ExternalSignalType (kwargs) arguments kwargs.type + = petsird.ExternalSignalTypeEnum.ECG_TRACE; +kwargs.description = ""; +kwargs.id = uint32 (0); +end self.type = kwargs.type; +self.description = kwargs.description; +self.id = kwargs.id; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.ExternalSignalType") && ... - isequal({self.type}, {other.type}) && ... - isequal({self.description}, {other.description}) && ... - isequal({self.id}, {other.id}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.ExternalSignalType") + && ...isequal ({ self.type }, { other.type }) + && ...isequal ({ self.description }, { other.description }) + && ...isequal ({ self.id }, { other.id }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.ExternalSignalType(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.ExternalSignalType (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/ExternalSignalTypeEnum.m b/matlab/toolbox/+petsird/ExternalSignalTypeEnum.m index f331e5a..e282085 100644 --- a/matlab/toolbox/+petsird/ExternalSignalTypeEnum.m +++ b/matlab/toolbox/+petsird/ExternalSignalTypeEnum.m @@ -1,44 +1,26 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ExternalSignalTypeEnum < uint64 - methods (Static) - function v = ECG_TRACE - v = petsird.ExternalSignalTypeEnum(0); - end - function v = ECG_TRIGGER - v = petsird.ExternalSignalTypeEnum(1); - end - function v = RESP_TRACE - v = petsird.ExternalSignalTypeEnum(2); - end - function v = RESP_TRIGGER - v = petsird.ExternalSignalTypeEnum(3); - end - function v = OTHER_MOTION_SIGNAL - v = petsird.ExternalSignalTypeEnum(4); - end - function v = OTHER_MOTION_TRIGGER - v = petsird.ExternalSignalTypeEnum(5); - end - function v = EXTERNAL_SYNC - v = petsird.ExternalSignalTypeEnum(6); - end - % other options, to be listed in the future - function v = OTHER - v = petsird.ExternalSignalTypeEnum(7); - end - - function z = zeros(varargin) - elem = petsird.ExternalSignalTypeEnum(0); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end + classdef ExternalSignalTypeEnum + < uint64 + methods (Static) +function v = ECG_TRACE v = petsird.ExternalSignalTypeEnum (0); +end function v = ECG_TRIGGER v = petsird.ExternalSignalTypeEnum (1); +end function v = RESP_TRACE v = petsird.ExternalSignalTypeEnum (2); +end function v = RESP_TRIGGER v = petsird.ExternalSignalTypeEnum (3); +end function v = OTHER_MOTION_SIGNAL v = petsird.ExternalSignalTypeEnum (4); +end function v = OTHER_MOTION_TRIGGER v = petsird.ExternalSignalTypeEnum (5); +end function v = EXTERNAL_SYNC v = petsird.ExternalSignalTypeEnum (6); +end % other options, to be listed in the future function v = OTHER v + = petsird.ExternalSignalTypeEnum (7); end + + function z + = zeros (varargin) elem = petsird.ExternalSignalTypeEnum (0); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/GantryMovementTimeBlock.m b/matlab/toolbox/+petsird/GantryMovementTimeBlock.m index b453d33..12d34a1 100644 --- a/matlab/toolbox/+petsird/GantryMovementTimeBlock.m +++ b/matlab/toolbox/+petsird/GantryMovementTimeBlock.m @@ -1,50 +1,39 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef GantryMovementTimeBlock < handle - properties - % start time since ExamInformation.startOfAcquisition in ms - start - transform - end + classdef GantryMovementTimeBlock + < handle properties + % start time since ExamInformation.startOfAcquisition in ms start + transform end - methods - function self = GantryMovementTimeBlock(kwargs) - arguments - kwargs.start = uint32(0); - kwargs.transform = petsird.RigidTransformation(); - end - self.start = kwargs.start; - self.transform = kwargs.transform; - end + methods function self + = GantryMovementTimeBlock (kwargs) arguments kwargs.start = uint32 (0); +kwargs.transform = petsird.RigidTransformation (); +end self.start = kwargs.start; +self.transform = kwargs.transform; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.GantryMovementTimeBlock") && ... - isequal({self.start}, {other.start}) && ... - isequal({self.transform}, {other.transform}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.GantryMovementTimeBlock") + && ...isequal ({ self.start }, { other.start }) + && ...isequal ({ self.transform }, { other.transform }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.GantryMovementTimeBlock(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.GantryMovementTimeBlock (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/GenericSolidVolume.m b/matlab/toolbox/+petsird/GenericSolidVolume.m index 6532a9d..9a4642d 100644 --- a/matlab/toolbox/+petsird/GenericSolidVolume.m +++ b/matlab/toolbox/+petsird/GenericSolidVolume.m @@ -1,4 +1,4 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef GenericSolidVolume < petsird.SolidVolume -end + classdef GenericSolidVolume + < petsird.SolidVolume end diff --git a/matlab/toolbox/+petsird/GeometricShape.m b/matlab/toolbox/+petsird/GeometricShape.m index ae20a90..2ade374 100644 --- a/matlab/toolbox/+petsird/GeometricShape.m +++ b/matlab/toolbox/+petsird/GeometricShape.m @@ -1,49 +1,45 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -classdef GeometricShape < yardl.Union - methods (Static) - function res = BoxShape(value) - res = petsird.GeometricShape(1, value); - end - - function res = AnnulusShape(value) - res = petsird.GeometricShape(2, value); - end - - function z = zeros(varargin) - elem = petsird.GeometricShape(0, yardl.None); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end - - methods - function res = isBoxShape(self) - res = self.index == 1; - end - - function res = isAnnulusShape(self) - res = self.index == 2; - end - - function eq = eq(self, other) - eq = isa(other, "petsird.GeometricShape") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); - end - - function ne = ne(self, other) - ne = ~self.eq(other); - end - - function t = tag(self) - tags_ = ["BoxShape", "AnnulusShape"]; - t = tags_(self.index_); - end - end +% This file was generated by the "yardl" tool.DO NOT EDIT. + + classdef GeometricShape + < yardl.Union + methods (Static) +function res = BoxShape (value) res = petsird.GeometricShape (1, value); +end + + function res + = AnnulusShape (value) res = petsird.GeometricShape (2, value); +end + + function z + = zeros (varargin) elem = petsird.GeometricShape (0, yardl.None); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end + + methods function res + = isBoxShape (self) res = self.index == 1; +end + + function res + = isAnnulusShape (self) res = self.index == 2; +end + + function eq + = eq (self, other) eq = isa (other, "petsird.GeometricShape") + && all ([self.index_] == [other.index_], 'all') + && all ([self.value] == [other.value], 'all'); end + + function ne + = ne (self, other) ne = ~self.eq (other); +end + + function t + = tag (self) tags_ = [ "BoxShape", "AnnulusShape" ]; +t = tags_ (self.index_); +end end end diff --git a/matlab/toolbox/+petsird/Header.m b/matlab/toolbox/+petsird/Header.m index fca99e7..f05be67 100644 --- a/matlab/toolbox/+petsird/Header.m +++ b/matlab/toolbox/+petsird/Header.m @@ -1,49 +1,37 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef Header < handle - properties - scanner - exam - end + classdef Header + < handle properties scanner exam end - methods - function self = Header(kwargs) - arguments - kwargs.scanner = petsird.ScannerInformation(); - kwargs.exam = yardl.None; - end - self.scanner = kwargs.scanner; - self.exam = kwargs.exam; - end + methods function self + = Header (kwargs) arguments kwargs.scanner = petsird.ScannerInformation (); +kwargs.exam = yardl.None; +end self.scanner = kwargs.scanner; +self.exam = kwargs.exam; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.Header") && ... - isequal({self.scanner}, {other.scanner}) && ... - isequal({self.exam}, {other.exam}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.Header") + && ...isequal ({ self.scanner }, { other.scanner }) + && ...isequal ({ self.exam }, { other.exam }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.Header(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.Header (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/Institution.m b/matlab/toolbox/+petsird/Institution.m index c81859f..524d251 100644 --- a/matlab/toolbox/+petsird/Institution.m +++ b/matlab/toolbox/+petsird/Institution.m @@ -1,49 +1,37 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef Institution < handle - properties - name - address - end + classdef Institution + < handle properties name address end - methods - function self = Institution(kwargs) - arguments - kwargs.name = ""; - kwargs.address = ""; - end - self.name = kwargs.name; - self.address = kwargs.address; - end + methods function self + = Institution (kwargs) arguments kwargs.name = ""; +kwargs.address = ""; +end self.name = kwargs.name; +self.address = kwargs.address; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.Institution") && ... - isequal({self.name}, {other.name}) && ... - isequal({self.address}, {other.address}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.Institution") + && ...isequal ({ self.name }, { other.name }) + && ...isequal ({ self.address }, { other.address }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.Institution(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.Institution (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/ModulePairEfficiencies.m b/matlab/toolbox/+petsird/ModulePairEfficiencies.m index 2dc8aac..d5fd8ed 100644 --- a/matlab/toolbox/+petsird/ModulePairEfficiencies.m +++ b/matlab/toolbox/+petsird/ModulePairEfficiencies.m @@ -17,40 +17,32 @@ function self = ModulePairEfficiencies(kwargs) arguments kwargs.values = single.empty(); - kwargs.sgid = uint32(0); - end - self.values = kwargs.values; - self.sgid = kwargs.sgid; - end +kwargs.sgid = uint32 (0); +end self.values = kwargs.values; +self.sgid = kwargs.sgid; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.ModulePairEfficiencies") && ... - isequal({self.values}, {other.values}) && ... - isequal({self.sgid}, {other.sgid}); - end + function res + = eq (self, other) res = ... isa (other, "petsird.ModulePairEfficiencies") + && ...isequal ({ self.values }, { other.values }) + && ...isequal ({ self.sgid }, { other.sgid }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.ModulePairEfficiencies(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.ModulePairEfficiencies (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/PETSIRDReaderBase.m b/matlab/toolbox/+petsird/PETSIRDReaderBase.m index ac4c006..9294a32 100644 --- a/matlab/toolbox/+petsird/PETSIRDReaderBase.m +++ b/matlab/toolbox/+petsird/PETSIRDReaderBase.m @@ -1,93 +1,73 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -% Definition of the stream of data -classdef PETSIRDReaderBase < handle - properties (Access=protected) - state_ - end + % Definition of the stream of data classdef PETSIRDReaderBase + < handle properties (Access = protected) state_ end - methods - function self = PETSIRDReaderBase() - self.state_ = 0; - end - - function close(self) - self.close_(); - if self.state_ ~= 2 - expected_method = self.state_to_method_name_(self.state_); - throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); - end - end + methods function self = PETSIRDReaderBase () self.state_ = 0; +end - % Ordinal 0 - function value = read_header(self) - if self.state_ ~= 0 - self.raise_unexpected_state_(0); - end + function close (self) self.close_ (); +if self + .state_ ~ = 2 expected_method = self.state_to_method_name_ (self.state_); +throw (yardl.ProtocolError ("Protocol reader closed before all data was " + "consumed. Expected call to '%s'.", + expected_method)); +end end - value = self.read_header_(); - self.state_ = 1; - end + % Ordinal 0 function value + = read_header (self) if self.state_ ~ = 0 self.raise_unexpected_state_ (0); +end - % Ordinal 1 - function more = has_time_blocks(self) - if self.state_ ~= 1 - self.raise_unexpected_state_(1); - end + value + = self.read_header_ (); +self.state_ = 1; +end - more = self.has_time_blocks_(); - if ~more - self.state_ = 2; - end - end + % Ordinal 1 function more + = has_time_blocks ( + self) if self.state_ ~ = 1 self.raise_unexpected_state_ (1); +end - function value = read_time_blocks(self) - if self.state_ ~= 1 - self.raise_unexpected_state_(1); - end + more + = self.has_time_blocks_ (); +if + ~more self.state_ = 2; +end end - value = self.read_time_blocks_(); - end + function value + = read_time_blocks ( + self) if self.state_ ~ = 1 self.raise_unexpected_state_ (1); +end - function copy_to(self, writer) - writer.write_header(self.read_header()); - while self.has_time_blocks() - item = self.read_time_blocks(); - writer.write_time_blocks({item}); - end - writer.end_time_blocks(); - end - end + value + = self.read_time_blocks_ (); +end - methods (Static) - function res = schema() - res = petsird.PETSIRDWriterBase.schema; - end - end + function copy_to (self, writer) writer.write_header (self.read_header ()); +while + self.has_time_blocks () item = self.read_time_blocks (); +writer.write_time_blocks ({ item }); +end writer.end_time_blocks (); +end end - methods (Abstract, Access=protected) - read_header_(self) - has_time_blocks_(self) - read_time_blocks_(self) +methods (Static) +function res = schema () res = petsird.PETSIRDWriterBase.schema; +end end - close_(self) - end + methods (Abstract, Access = protected) read_header_ (self) + has_time_blocks_ (self) read_time_blocks_ (self) - methods (Access=private) - function raise_unexpected_state_(self, actual) - actual_method = self.state_to_method_name_(actual); - expected_method = self.state_to_method_name_(self.state_); - throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); - end + close_ (self) end - function name = state_to_method_name_(self, state) - if state == 0 - name = "read_header"; - elseif state == 1 - name = "read_time_blocks"; - else - name = ""; - end - end - end + methods (Access = private) function raise_unexpected_state_ (self, actual) + actual_method = self.state_to_method_name_ (actual); +expected_method = self.state_to_method_name_ (self.state_); +throw (yardl.ProtocolError ("Expected call to '%s' but received call to '%s'.", + expected_method, actual_method)); end + + function name + = state_to_method_name_ (self, state) if state == 0 name = "read_header"; +elseif state == 1 name = "read_time_blocks"; +else name = ""; +end end end end diff --git a/matlab/toolbox/+petsird/PETSIRDWriterBase.m b/matlab/toolbox/+petsird/PETSIRDWriterBase.m index 1782c67..e4045f6 100644 --- a/matlab/toolbox/+petsird/PETSIRDWriterBase.m +++ b/matlab/toolbox/+petsird/PETSIRDWriterBase.m @@ -10,74 +10,58 @@ methods function self = PETSIRDWriterBase() self.state_ = 0; - end - - function close(self) - self.close_(); - if self.state_ ~= 2 - expected_method = self.state_to_method_name_(self.state_); - throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); - end - end +end - % Ordinal 0 - function write_header(self, value) - if self.state_ ~= 0 - self.raise_unexpected_state_(0); - end + function close (self) self.close_ (); +if self + .state_ ~ = 2 expected_method = self.state_to_method_name_ (self.state_); +throw (yardl.ProtocolError ("Protocol writer closed before all steps were " + "called. Expected call to '%s'.", + expected_method)); +end end - self.write_header_(value); - self.state_ = 1; - end + % Ordinal 0 function write_header (self, value) if self.state_ + ~ = 0 self.raise_unexpected_state_ (0); +end - % Ordinal 1 - function write_time_blocks(self, value) - if self.state_ ~= 1 - self.raise_unexpected_state_(1); - end + self.write_header_ (value); +self.state_ = 1; +end - self.write_time_blocks_(value); - end + % Ordinal 1 function write_time_blocks (self, value) if self.state_ + ~ = 1 self.raise_unexpected_state_ (1); +end - function end_time_blocks(self) - if self.state_ ~= 1 - self.raise_unexpected_state_(1); - end + self.write_time_blocks_ (value); +end - self.end_stream_(); - self.state_ = 2; - end - end + function end_time_blocks (self) if self.state_ + ~ = 1 self.raise_unexpected_state_ (1); +end - methods (Static) - function res = schema() - res = string('{"protocol":{"name":"PETSIRD","sequence":[{"name":"header","type":"PETSIRD.Header"},{"name":"timeBlocks","type":{"stream":{"items":"PETSIRD.TimeBlock"}}}]},"types":[{"name":"AnnulusShape","fields":[{"name":"innerRadius","type":"float32"},{"name":"outerRadius","type":"float32"},{"name":"thickness","type":"float32"},{"name":"angularRange","type":{"vector":{"items":"float32","length":2}}}]},{"name":"Atom","fields":[{"name":"massNumber","type":"uint32"},{"name":"atomicNumber","type":"uint32"}]},{"name":"BedMovementTimeBlock","fields":[{"name":"start","type":"uint32"},{"name":"transform","type":"PETSIRD.RigidTransformation"}]},{"name":"BoxShape","fields":[{"name":"corners","type":{"vector":{"items":"PETSIRD.Coordinate","length":8}}}]},{"name":"BoxSolidVolume","type":{"name":"PETSIRD.SolidVolume","typeArguments":["PETSIRD.BoxShape"]}},{"name":"BulkMaterial","fields":[{"name":"id","type":"uint32"},{"name":"name","type":"string"},{"name":"density","type":"float32"},{"name":"atoms","type":{"vector":{"items":"PETSIRD.Atom"}}},{"name":"massFractions","type":{"vector":{"items":"float32"}}}]},{"name":"CoincidenceEvent","fields":[{"name":"detectorIds","type":{"vector":{"items":"uint32","length":2}}},{"name":"tofIdx","type":"uint32"},{"name":"energyIndices","type":{"vector":{"items":"uint32","length":2}}}]},{"name":"CoincidencePolicy","values":[{"symbol":"rejectMultiples","value":0},{"symbol":"storeMultiplesAsPairs","value":1},{"symbol":"other","value":2}]},{"name":"Coordinate","fields":[{"name":"c","type":{"array":{"items":"float32","dimensions":[{"length":3}]}}}]},{"name":"DetElEfficiencies","type":{"array":{"items":"float32","dimensions":[{"name":"detElIdx"},{"name":"energyBinIdx"}]}}},{"name":"DetectionEfficiencies","fields":[{"name":"detElEfficiencies","type":[null,"PETSIRD.DetElEfficiencies"]},{"name":"modulePairSGIDLUT","type":[null,"PETSIRD.ModulePairSGIDLUT"]},{"name":"modulePairEfficienciesVector","type":[null,"PETSIRD.ModulePairEfficienciesVector"]}]},{"name":"DetectorModule","fields":[{"name":"detectingElements","type":{"vector":{"items":"PETSIRD.ReplicatedBoxSolidVolume"}}},{"name":"detectingElementIds","type":{"vector":{"items":"uint32"}}},{"name":"nonDetectingElements","type":{"vector":{"items":"PETSIRD.ReplicatedGenericSolidVolume"}}}]},{"name":"EventTimeBlock","fields":[{"name":"start","type":"uint32"},{"name":"promptEvents","type":{"vector":{"items":"PETSIRD.CoincidenceEvent"}}},{"name":"delayedEvents","type":[null,{"vector":{"items":"PETSIRD.CoincidenceEvent"}}]},{"name":"tripleEvents","type":[null,{"vector":{"items":"PETSIRD.TripleEvent"}}]}]},{"name":"ExamInformation","fields":[{"name":"subject","type":"PETSIRD.Subject"},{"name":"institution","type":"PETSIRD.Institution"},{"name":"protocol","type":[null,"string"]},{"name":"startOfAcquisition","type":[null,"datetime"]}]},{"name":"ExternalSignalTimeBlock","fields":[{"name":"start","type":"uint32"},{"name":"signalID","type":"uint32"},{"name":"signalValues","type":{"vector":{"items":"float32"}}}]},{"name":"GantryMovementTimeBlock","fields":[{"name":"start","type":"uint32"},{"name":"transform","type":"PETSIRD.RigidTransformation"}]},{"name":"GenericSolidVolume","type":{"name":"PETSIRD.SolidVolume","typeArguments":["PETSIRD.GeometricShape"]}},{"name":"GeometricShape","type":[{"tag":"BoxShape","type":"PETSIRD.BoxShape"},{"tag":"AnnulusShape","type":"PETSIRD.AnnulusShape"}]},{"name":"Header","fields":[{"name":"scanner","type":"PETSIRD.ScannerInformation"},{"name":"exam","type":[null,"PETSIRD.ExamInformation"]}]},{"name":"Institution","fields":[{"name":"name","type":"string"},{"name":"address","type":"string"}]},{"name":"ModulePairEfficiencies","fields":[{"name":"values","type":{"array":{"items":"float32","dimensions":[{"name":"detElIdx1"},{"name":"energyBinIdx1"},{"name":"detElIdx2"},{"name":"energyBinIdx2"}]}}},{"name":"sgid","type":"uint32"}]},{"name":"ModulePairEfficienciesVector","type":{"vector":{"items":"PETSIRD.ModulePairEfficiencies"}}},{"name":"ModulePairSGIDLUT","type":{"array":{"items":"int32","dimensions":[{"name":"moduleIdx1"},{"name":"moduleIdx2"}]}}},{"name":"ReplicatedBoxSolidVolume","type":{"name":"PETSIRD.ReplicatedObject","typeArguments":["PETSIRD.BoxSolidVolume"]}},{"name":"ReplicatedDetectorModule","type":{"name":"PETSIRD.ReplicatedObject","typeArguments":["PETSIRD.DetectorModule"]}},{"name":"ReplicatedGenericSolidVolume","type":{"name":"PETSIRD.ReplicatedObject","typeArguments":["PETSIRD.GenericSolidVolume"]}},{"name":"ReplicatedObject","typeParameters":["T"],"fields":[{"name":"object","type":"T"},{"name":"transforms","type":{"vector":{"items":"PETSIRD.RigidTransformation"}}},{"name":"ids","type":{"vector":{"items":"uint32"}}}]},{"name":"RigidTransformation","fields":[{"name":"matrix","type":{"array":{"items":"float32","dimensions":[{"length":3},{"length":4}]}}}]},{"name":"ScannerGeometry","fields":[{"name":"replicatedModules","type":{"vector":{"items":"PETSIRD.ReplicatedDetectorModule"}}},{"name":"ids","type":{"vector":{"items":"uint32"}}},{"name":"nonDetectingVolumes","type":[null,{"vector":{"items":"PETSIRD.GenericSolidVolume"}}]}]},{"name":"ScannerInformation","fields":[{"name":"modelName","type":"string"},{"name":"scannerGeometry","type":"PETSIRD.ScannerGeometry"},{"name":"bulkMaterials","type":{"vector":{"items":"PETSIRD.BulkMaterial"}}},{"name":"gantryAlignment","type":[null,"PETSIRD.RigidTransformation"]},{"name":"tofBinEdges","type":{"array":{"items":"float32","dimensions":1}}},{"name":"tofResolution","type":"float32"},{"name":"energyBinEdges","type":{"array":{"items":"float32","dimensions":1}}},{"name":"energyResolutionAt511","type":"float32"},{"name":"eventTimeBlockDuration","type":"uint32"},{"name":"coincidencePolicy","type":"PETSIRD.CoincidencePolicy"},{"name":"detectionEfficiencies","type":"PETSIRD.DetectionEfficiencies"}]},{"name":"SolidVolume","typeParameters":["Shape"],"fields":[{"name":"shape","type":"Shape"},{"name":"materialId","type":"uint32"}]},{"name":"Subject","fields":[{"name":"name","type":[null,"string"]},{"name":"id","type":"string"}]},{"name":"TimeBlock","type":[{"tag":"EventTimeBlock","type":"PETSIRD.EventTimeBlock"},{"tag":"ExternalSignalTimeBlock","type":"PETSIRD.ExternalSignalTimeBlock"},{"tag":"BedMovementTimeBlock","type":"PETSIRD.BedMovementTimeBlock"},{"tag":"GantryMovementTimeBlock","type":"PETSIRD.GantryMovementTimeBlock"}]},{"name":"TripleEvent","fields":[{"name":"detectorIds","type":{"vector":{"items":"uint32","length":3}}},{"name":"tofIndices","type":{"vector":{"items":"uint32","length":2}}},{"name":"energyIndices","type":{"vector":{"items":"uint32","length":3}}}]}]}'); - end - end + self.end_stream_ (); +self.state_ = 2; +end end - methods (Abstract, Access=protected) - write_header_(self, value) - write_time_blocks_(self, value) +methods (Static) +function res = schema () res = string ( + '{"protocol":{"name":"PETSIRD","sequence":[{"name":"header","type":"PETSIRD.Header"},{"name":"timeBlocks","type":{"stream":{"items":"PETSIRD.TimeBlock"}}}]},"types":[{"name":"AnnulusShape","fields":[{"name":"innerRadius","type":"float32"},{"name":"outerRadius","type":"float32"},{"name":"thickness","type":"float32"},{"name":"angularRange","type":{"vector":{"items":"float32","length":2}}}]},{"name":"Atom","fields":[{"name":"massNumber","type":"uint32"},{"name":"atomicNumber","type":"uint32"}]},{"name":"BedMovementTimeBlock","fields":[{"name":"start","type":"uint32"},{"name":"transform","type":"PETSIRD.RigidTransformation"}]},{"name":"BoxShape","fields":[{"name":"corners","type":{"vector":{"items":"PETSIRD.Coordinate","length":8}}}]},{"name":"BoxSolidVolume","type":{"name":"PETSIRD.SolidVolume","typeArguments":["PETSIRD.BoxShape"]}},{"name":"BulkMaterial","fields":[{"name":"id","type":"uint32"},{"name":"name","type":"string"},{"name":"density","type":"float32"},{"name":"atoms","type":{"vector":{"items":"PETSIRD.Atom"}}},{"name":"massFractions","type":{"vector":{"items":"float32"}}}]},{"name":"CoincidenceEvent","fields":[{"name":"detectorIds","type":{"vector":{"items":"uint32","length":2}}},{"name":"tofIdx","type":"uint32"},{"name":"energyIndices","type":{"vector":{"items":"uint32","length":2}}}]},{"name":"CoincidencePolicy","values":[{"symbol":"rejectMultiples","value":0},{"symbol":"storeMultiplesAsPairs","value":1},{"symbol":"other","value":2}]},{"name":"Coordinate","fields":[{"name":"c","type":{"array":{"items":"float32","dimensions":[{"length":3}]}}}]},{"name":"DetElEfficiencies","type":{"array":{"items":"float32","dimensions":[{"name":"detElIdx"},{"name":"energyBinIdx"}]}}},{"name":"DetectionEfficiencies","fields":[{"name":"detElEfficiencies","type":[null,"PETSIRD.DetElEfficiencies"]},{"name":"modulePairSGIDLUT","type":[null,"PETSIRD.ModulePairSGIDLUT"]},{"name":"modulePairEfficienciesVector","type":[null,"PETSIRD.ModulePairEfficienciesVector"]}]},{"name":"DetectorModule","fields":[{"name":"detectingElements","type":{"vector":{"items":"PETSIRD.ReplicatedBoxSolidVolume"}}},{"name":"detectingElementIds","type":{"vector":{"items":"uint32"}}},{"name":"nonDetectingElements","type":{"vector":{"items":"PETSIRD.ReplicatedGenericSolidVolume"}}}]},{"name":"EventTimeBlock","fields":[{"name":"start","type":"uint32"},{"name":"promptEvents","type":{"vector":{"items":"PETSIRD.CoincidenceEvent"}}},{"name":"delayedEvents","type":[null,{"vector":{"items":"PETSIRD.CoincidenceEvent"}}]},{"name":"tripleEvents","type":[null,{"vector":{"items":"PETSIRD.TripleEvent"}}]}]},{"name":"ExamInformation","fields":[{"name":"subject","type":"PETSIRD.Subject"},{"name":"institution","type":"PETSIRD.Institution"},{"name":"protocol","type":[null,"string"]},{"name":"startOfAcquisition","type":[null,"datetime"]}]},{"name":"ExternalSignalTimeBlock","fields":[{"name":"start","type":"uint32"},{"name":"signalID","type":"uint32"},{"name":"signalValues","type":{"vector":{"items":"float32"}}}]},{"name":"GantryMovementTimeBlock","fields":[{"name":"start","type":"uint32"},{"name":"transform","type":"PETSIRD.RigidTransformation"}]},{"name":"GenericSolidVolume","type":{"name":"PETSIRD.SolidVolume","typeArguments":["PETSIRD.GeometricShape"]}},{"name":"GeometricShape","type":[{"tag":"BoxShape","type":"PETSIRD.BoxShape"},{"tag":"AnnulusShape","type":"PETSIRD.AnnulusShape"}]},{"name":"Header","fields":[{"name":"scanner","type":"PETSIRD.ScannerInformation"},{"name":"exam","type":[null,"PETSIRD.ExamInformation"]}]},{"name":"Institution","fields":[{"name":"name","type":"string"},{"name":"address","type":"string"}]},{"name":"ModulePairEfficiencies","fields":[{"name":"values","type":{"array":{"items":"float32","dimensions":[{"name":"detElIdx1"},{"name":"energyBinIdx1"},{"name":"detElIdx2"},{"name":"energyBinIdx2"}]}}},{"name":"sgid","type":"uint32"}]},{"name":"ModulePairEfficienciesVector","type":{"vector":{"items":"PETSIRD.ModulePairEfficiencies"}}},{"name":"ModulePairSGIDLUT","type":{"array":{"items":"int32","dimensions":[{"name":"moduleIdx1"},{"name":"moduleIdx2"}]}}},{"name":"ReplicatedBoxSolidVolume","type":{"name":"PETSIRD.ReplicatedObject","typeArguments":["PETSIRD.BoxSolidVolume"]}},{"name":"ReplicatedDetectorModule","type":{"name":"PETSIRD.ReplicatedObject","typeArguments":["PETSIRD.DetectorModule"]}},{"name":"ReplicatedGenericSolidVolume","type":{"name":"PETSIRD.ReplicatedObject","typeArguments":["PETSIRD.GenericSolidVolume"]}},{"name":"ReplicatedObject","typeParameters":["T"],"fields":[{"name":"object","type":"T"},{"name":"transforms","type":{"vector":{"items":"PETSIRD.RigidTransformation"}}},{"name":"ids","type":{"vector":{"items":"uint32"}}}]},{"name":"RigidTransformation","fields":[{"name":"matrix","type":{"array":{"items":"float32","dimensions":[{"length":3},{"length":4}]}}}]},{"name":"ScannerGeometry","fields":[{"name":"replicatedModules","type":{"vector":{"items":"PETSIRD.ReplicatedDetectorModule"}}},{"name":"ids","type":{"vector":{"items":"uint32"}}},{"name":"nonDetectingVolumes","type":[null,{"vector":{"items":"PETSIRD.GenericSolidVolume"}}]}]},{"name":"ScannerInformation","fields":[{"name":"modelName","type":"string"},{"name":"scannerGeometry","type":"PETSIRD.ScannerGeometry"},{"name":"bulkMaterials","type":{"vector":{"items":"PETSIRD.BulkMaterial"}}},{"name":"gantryAlignment","type":[null,"PETSIRD.RigidTransformation"]},{"name":"tofBinEdges","type":{"array":{"items":"float32","dimensions":1}}},{"name":"tofResolution","type":"float32"},{"name":"energyBinEdges","type":{"array":{"items":"float32","dimensions":1}}},{"name":"energyResolutionAt511","type":"float32"},{"name":"eventTimeBlockDuration","type":"uint32"},{"name":"coincidencePolicy","type":"PETSIRD.CoincidencePolicy"},{"name":"detectionEfficiencies","type":"PETSIRD.DetectionEfficiencies"}]},{"name":"SolidVolume","typeParameters":["Shape"],"fields":[{"name":"shape","type":"Shape"},{"name":"materialId","type":"uint32"}]},{"name":"Subject","fields":[{"name":"name","type":[null,"string"]},{"name":"id","type":"string"}]},{"name":"TimeBlock","type":[{"tag":"EventTimeBlock","type":"PETSIRD.EventTimeBlock"},{"tag":"ExternalSignalTimeBlock","type":"PETSIRD.ExternalSignalTimeBlock"},{"tag":"BedMovementTimeBlock","type":"PETSIRD.BedMovementTimeBlock"},{"tag":"GantryMovementTimeBlock","type":"PETSIRD.GantryMovementTimeBlock"}]},{"name":"TripleEvent","fields":[{"name":"detectorIds","type":{"vector":{"items":"uint32","length":3}}},{"name":"tofIndices","type":{"vector":{"items":"uint32","length":2}}},{"name":"energyIndices","type":{"vector":{"items":"uint32","length":3}}}]}]}'); +end end - end_stream_(self) - close_(self) - end + methods (Abstract, Access = protected) write_header_ (self, value) + write_time_blocks_ (self, value) - methods (Access=private) - function raise_unexpected_state_(self, actual) - expected_method = self.state_to_method_name_(self.state_); - actual_method = self.state_to_method_name_(actual); - throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); - end + end_stream_ (self) close_ (self) end - function name = state_to_method_name_(self, state) - if state == 0 - name = "write_header"; - elseif state == 1 - name = "write_time_blocks or end_time_blocks"; - else - name = ''; - end - end - end + methods (Access = private) function raise_unexpected_state_ (self, actual) + expected_method = self.state_to_method_name_ (self.state_); +actual_method = self.state_to_method_name_ (actual); +throw (yardl.ProtocolError ("Expected call to '%s' but received call to '%s'", + expected_method, actual_method)); end + + function name + = state_to_method_name_ (self, state) if state == 0 name = "write_header"; +elseif state == 1 name = "write_time_blocks or end_time_blocks"; +else name = ''; +end end end end diff --git a/matlab/toolbox/+petsird/ReplicatedBoxSolidVolume.m b/matlab/toolbox/+petsird/ReplicatedBoxSolidVolume.m index 285e8e2..5ec5314 100644 --- a/matlab/toolbox/+petsird/ReplicatedBoxSolidVolume.m +++ b/matlab/toolbox/+petsird/ReplicatedBoxSolidVolume.m @@ -1,5 +1,6 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ReplicatedBoxSolidVolume < petsird.ReplicatedObject - % A list of identical SolidVolumes at different locations -end + classdef ReplicatedBoxSolidVolume + < petsird.ReplicatedObject + % A list of identical SolidVolumes at different locations + end diff --git a/matlab/toolbox/+petsird/ReplicatedDetectorModule.m b/matlab/toolbox/+petsird/ReplicatedDetectorModule.m index cdbff3e..b254b34 100644 --- a/matlab/toolbox/+petsird/ReplicatedDetectorModule.m +++ b/matlab/toolbox/+petsird/ReplicatedDetectorModule.m @@ -1,5 +1,5 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ReplicatedDetectorModule < petsird.ReplicatedObject - % A list of identical modules at different locations -end + classdef ReplicatedDetectorModule + < petsird.ReplicatedObject + % A list of identical modules at different locations end diff --git a/matlab/toolbox/+petsird/ReplicatedGenericSolidVolume.m b/matlab/toolbox/+petsird/ReplicatedGenericSolidVolume.m index 161cd0e..e01d1ee 100644 --- a/matlab/toolbox/+petsird/ReplicatedGenericSolidVolume.m +++ b/matlab/toolbox/+petsird/ReplicatedGenericSolidVolume.m @@ -1,5 +1,6 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef ReplicatedGenericSolidVolume < petsird.ReplicatedObject - % A list of identical SolidVolumes at different locations -end + classdef ReplicatedGenericSolidVolume + < petsird.ReplicatedObject + % A list of identical SolidVolumes at different + locations end diff --git a/matlab/toolbox/+petsird/ReplicatedObject.m b/matlab/toolbox/+petsird/ReplicatedObject.m index 2815d97..608aad0 100644 --- a/matlab/toolbox/+petsird/ReplicatedObject.m +++ b/matlab/toolbox/+petsird/ReplicatedObject.m @@ -16,52 +16,43 @@ function self = ReplicatedObject(kwargs) arguments kwargs.object; - kwargs.transforms = petsird.RigidTransformation.empty(); - kwargs.ids = uint32.empty(); - end - if ~isfield(kwargs, "object") - throw(yardl.TypeError("Missing required keyword argument 'object'")) - end - self.object = kwargs.object; - self.transforms = kwargs.transforms; - self.ids = kwargs.ids; - end - - function res = number_of_objects(self) - res = length(self.transforms); - return - end - - - function res = eq(self, other) - res = ... - isa(other, "petsird.ReplicatedObject") && ... - isequal({self.object}, {other.object}) && ... - isequal({self.transforms}, {other.transforms}) && ... - isequal({self.ids}, {other.ids}); - end +kwargs.transforms = petsird.RigidTransformation.empty (); +kwargs.ids = uint32.empty (); +end if ~isfield (kwargs, "object") throw ( + yardl.TypeError ("Missing required keyword argument 'object'")) end self + .object = kwargs.object; +self.transforms = kwargs.transforms; +self.ids = kwargs.ids; +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = number_of_objects (self) res = length (self.transforms); +return end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = eq (self, other) res + = ... isa (other, "petsird.ReplicatedObject") + && ...isequal ({ self.object }, { other.object }) + && ...isequal ({ self.transforms }, { other.transforms }) + && ...isequal ({ self.ids }, { other.ids }); +end - methods (Static) - function z = zeros(varargin) - elem = petsird.ReplicatedObject(object=yardl.None); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end + function res + = ne (self, other) res = ~self.eq (other); end + + function res + = isequal (self, other) res = all (eq (self, other)); +end end + +methods (Static) +function z = zeros (varargin) elem + = petsird.ReplicatedObject (object = yardl.None); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/RigidTransformation.m b/matlab/toolbox/+petsird/RigidTransformation.m index 947958c..e2f6f59 100644 --- a/matlab/toolbox/+petsird/RigidTransformation.m +++ b/matlab/toolbox/+petsird/RigidTransformation.m @@ -1,48 +1,37 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef RigidTransformation < handle - % Rigid transformation, encoded via homogenous transformation - % transformed_coord = matrix * [c, 1] (where [c,1] is a column vector) - % with `c` of type `Coordinate` - properties - matrix - end + classdef RigidTransformation + < handle % Rigid transformation, + encoded via homogenous transformation % transformed_coord + = matrix * [ c, 1 ](where[c, 1] is a column vector) + % with `c` of type `Coordinate` properties matrix end - methods - function self = RigidTransformation(kwargs) - arguments - kwargs.matrix = repelem(single(0), 4, 3); - end - self.matrix = kwargs.matrix; - end + methods function self + = RigidTransformation (kwargs) arguments kwargs.matrix + = repelem (single (0), 4, 3); +end self.matrix = kwargs.matrix; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.RigidTransformation") && ... - isequal({self.matrix}, {other.matrix}); - end + function res + = eq (self, other) res = ... isa (other, "petsird.RigidTransformation") + && ...isequal ({ self.matrix }, { other.matrix }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.RigidTransformation(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.RigidTransformation (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/ScannerGeometry.m b/matlab/toolbox/+petsird/ScannerGeometry.m index 43d20c6..6411d5e 100644 --- a/matlab/toolbox/+petsird/ScannerGeometry.m +++ b/matlab/toolbox/+petsird/ScannerGeometry.m @@ -17,43 +17,37 @@ function self = ScannerGeometry(kwargs) arguments kwargs.replicated_modules = petsird.ReplicatedDetectorModule.empty(); - kwargs.ids = uint32.empty(); - kwargs.non_detecting_volumes = yardl.None; - end - self.replicated_modules = kwargs.replicated_modules; - self.ids = kwargs.ids; - self.non_detecting_volumes = kwargs.non_detecting_volumes; - end +kwargs.ids = uint32.empty (); +kwargs.non_detecting_volumes = yardl.None; +end self.replicated_modules = kwargs.replicated_modules; +self.ids = kwargs.ids; +self.non_detecting_volumes = kwargs.non_detecting_volumes; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.ScannerGeometry") && ... - isequal({self.replicated_modules}, {other.replicated_modules}) && ... - isequal({self.ids}, {other.ids}) && ... - isequal({self.non_detecting_volumes}, {other.non_detecting_volumes}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.ScannerGeometry") + && ...isequal ({ self.replicated_modules }, { other.replicated_modules }) + && ...isequal ({ self.ids }, { other.ids }) + && ...isequal ({ self.non_detecting_volumes }, + { other.non_detecting_volumes }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.ScannerGeometry(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.ScannerGeometry (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/ScannerInformation.m b/matlab/toolbox/+petsird/ScannerInformation.m index 567bbbb..898e6d9 100644 --- a/matlab/toolbox/+petsird/ScannerInformation.m +++ b/matlab/toolbox/+petsird/ScannerInformation.m @@ -40,78 +40,72 @@ function self = ScannerInformation(kwargs) arguments kwargs.model_name = ""; - kwargs.scanner_geometry = petsird.ScannerGeometry(); - kwargs.bulk_materials = petsird.BulkMaterial.empty(); - kwargs.gantry_alignment = yardl.None; - kwargs.tof_bin_edges = single.empty(); - kwargs.tof_resolution = single(0); - kwargs.energy_bin_edges = single.empty(); - kwargs.energy_resolution_at_511 = single(0); - kwargs.event_time_block_duration = uint32(0); - kwargs.coincidence_policy = petsird.CoincidencePolicy.REJECT_MULTIPLES; - kwargs.detection_efficiencies = petsird.DetectionEfficiencies(); - end - self.model_name = kwargs.model_name; - self.scanner_geometry = kwargs.scanner_geometry; - self.bulk_materials = kwargs.bulk_materials; - self.gantry_alignment = kwargs.gantry_alignment; - self.tof_bin_edges = kwargs.tof_bin_edges; - self.tof_resolution = kwargs.tof_resolution; - self.energy_bin_edges = kwargs.energy_bin_edges; - self.energy_resolution_at_511 = kwargs.energy_resolution_at_511; - self.event_time_block_duration = kwargs.event_time_block_duration; - self.coincidence_policy = kwargs.coincidence_policy; - self.detection_efficiencies = kwargs.detection_efficiencies; - end +kwargs.scanner_geometry = petsird.ScannerGeometry (); +kwargs.bulk_materials = petsird.BulkMaterial.empty (); +kwargs.gantry_alignment = yardl.None; +kwargs.tof_bin_edges = single.empty (); +kwargs.tof_resolution = single (0); +kwargs.energy_bin_edges = single.empty (); +kwargs.energy_resolution_at_511 = single (0); +kwargs.event_time_block_duration = uint32 (0); +kwargs.coincidence_policy = petsird.CoincidencePolicy.REJECT_MULTIPLES; +kwargs.detection_efficiencies = petsird.DetectionEfficiencies (); +end self.model_name = kwargs.model_name; +self.scanner_geometry = kwargs.scanner_geometry; +self.bulk_materials = kwargs.bulk_materials; +self.gantry_alignment = kwargs.gantry_alignment; +self.tof_bin_edges = kwargs.tof_bin_edges; +self.tof_resolution = kwargs.tof_resolution; +self.energy_bin_edges = kwargs.energy_bin_edges; +self.energy_resolution_at_511 = kwargs.energy_resolution_at_511; +self.event_time_block_duration = kwargs.event_time_block_duration; +self.coincidence_policy = kwargs.coincidence_policy; +self.detection_efficiencies = kwargs.detection_efficiencies; +end - function res = number_of_tof_bins(self) - res = numel(self.tof_bin_edges) - 1; - return - end + function res + = number_of_tof_bins (self) res = numel (self.tof_bin_edges) - 1; +return end - function res = number_of_energy_bins(self) - res = numel(self.energy_bin_edges) - 1; - return - end + function res + = number_of_energy_bins (self) res = numel (self.energy_bin_edges) - 1; +return end + function res + = eq (self, other) res + = ... isa (other, "petsird.ScannerInformation") + && ...isequal ({ self.model_name }, { other.model_name }) + && ...isequal ({ self.scanner_geometry }, { other.scanner_geometry }) + && ...isequal ({ self.bulk_materials }, { other.bulk_materials }) + && ...isequal ({ self.gantry_alignment }, { other.gantry_alignment }) + && ...isequal ({ self.tof_bin_edges }, { other.tof_bin_edges }) + && ...isequal ({ self.tof_resolution }, { other.tof_resolution }) + && ...isequal ({ self.energy_bin_edges }, { other.energy_bin_edges }) + && ...isequal ({ self.energy_resolution_at_511 }, + { other.energy_resolution_at_511 }) + && ...isequal ({ self.event_time_block_duration }, + { other.event_time_block_duration }) + && ...isequal ({ self.coincidence_policy }, + { other.coincidence_policy }) + && ...isequal ({ self.detection_efficiencies }, + { other.detection_efficiencies }); +end - function res = eq(self, other) - res = ... - isa(other, "petsird.ScannerInformation") && ... - isequal({self.model_name}, {other.model_name}) && ... - isequal({self.scanner_geometry}, {other.scanner_geometry}) && ... - isequal({self.bulk_materials}, {other.bulk_materials}) && ... - isequal({self.gantry_alignment}, {other.gantry_alignment}) && ... - isequal({self.tof_bin_edges}, {other.tof_bin_edges}) && ... - isequal({self.tof_resolution}, {other.tof_resolution}) && ... - isequal({self.energy_bin_edges}, {other.energy_bin_edges}) && ... - isequal({self.energy_resolution_at_511}, {other.energy_resolution_at_511}) && ... - isequal({self.event_time_block_duration}, {other.event_time_block_duration}) && ... - isequal({self.coincidence_policy}, {other.coincidence_policy}) && ... - isequal({self.detection_efficiencies}, {other.detection_efficiencies}); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end - - methods (Static) - function z = zeros(varargin) - elem = petsird.ScannerInformation(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.ScannerInformation (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/SolidVolume.m b/matlab/toolbox/+petsird/SolidVolume.m index bbb6179..f76ec8a 100644 --- a/matlab/toolbox/+petsird/SolidVolume.m +++ b/matlab/toolbox/+petsird/SolidVolume.m @@ -1,54 +1,41 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef SolidVolume < handle - % A shape filled with a uniform material - properties - shape - % identifier referring to `ScannerInformation.bulkMaterials` list - material_id - end + classdef SolidVolume + < handle % A shape filled with a uniform material properties shape + % identifier referring + to `ScannerInformation.bulkMaterials` list material_id end - methods - function self = SolidVolume(kwargs) - arguments - kwargs.shape; - kwargs.material_id = uint32(0); - end - if ~isfield(kwargs, "shape") - throw(yardl.TypeError("Missing required keyword argument 'shape'")) - end - self.shape = kwargs.shape; - self.material_id = kwargs.material_id; - end + methods function self + = SolidVolume (kwargs) arguments kwargs.shape; +kwargs.material_id = uint32 (0); +end if ~isfield (kwargs, "shape") throw ( + yardl.TypeError ("Missing required keyword argument 'shape'")) end self + .shape = kwargs.shape; +self.material_id = kwargs.material_id; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.SolidVolume") && ... - isequal({self.shape}, {other.shape}) && ... - isequal({self.material_id}, {other.material_id}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.SolidVolume") + && ...isequal ({ self.shape }, { other.shape }) + && ...isequal ({ self.material_id }, { other.material_id }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.SolidVolume(shape=yardl.None); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.SolidVolume (shape = yardl.None); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/Subject.m b/matlab/toolbox/+petsird/Subject.m index 07c8271..c9c33bc 100644 --- a/matlab/toolbox/+petsird/Subject.m +++ b/matlab/toolbox/+petsird/Subject.m @@ -1,49 +1,36 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef Subject < handle - properties - name - id - end + classdef Subject + < handle properties name id end - methods - function self = Subject(kwargs) - arguments - kwargs.name = yardl.None; - kwargs.id = ""; - end - self.name = kwargs.name; - self.id = kwargs.id; - end + methods function self + = Subject (kwargs) arguments kwargs.name = yardl.None; +kwargs.id = ""; +end self.name = kwargs.name; +self.id = kwargs.id; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.Subject") && ... - isequal({self.name}, {other.name}) && ... - isequal({self.id}, {other.id}); - end + function res + = eq (self, other) res = ... isa (other, "petsird.Subject") + && ...isequal ({ self.name }, { other.name }) + && ...isequal ({ self.id }, { other.id }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.Subject(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.Subject (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/TimeBlock.m b/matlab/toolbox/+petsird/TimeBlock.m index e00300f..a8818be 100644 --- a/matlab/toolbox/+petsird/TimeBlock.m +++ b/matlab/toolbox/+petsird/TimeBlock.m @@ -1,65 +1,64 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef TimeBlock < yardl.Union - methods (Static) - function res = EventTimeBlock(value) - res = petsird.TimeBlock(1, value); - end - - function res = ExternalSignalTimeBlock(value) - res = petsird.TimeBlock(2, value); - end + classdef TimeBlock + < yardl.Union + methods (Static) +function res = EventTimeBlock (value) res = petsird.TimeBlock (1, value); +end - function res = BedMovementTimeBlock(value) - res = petsird.TimeBlock(3, value); - end + function res + = ExternalSignalTimeBlock (value) res = petsird.TimeBlock (2, value); +end - function res = GantryMovementTimeBlock(value) - res = petsird.TimeBlock(4, value); - end + function res + = BedMovementTimeBlock (value) res = petsird.TimeBlock (3, value); +end - function z = zeros(varargin) - elem = petsird.TimeBlock(0, yardl.None); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end + function res + = GantryMovementTimeBlock (value) res = petsird.TimeBlock (4, value); +end - methods - function res = isEventTimeBlock(self) - res = self.index == 1; - end + function z + = zeros (varargin) elem = petsird.TimeBlock (0, yardl.None); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end - function res = isExternalSignalTimeBlock(self) - res = self.index == 2; - end + methods function res + = isEventTimeBlock (self) res = self.index == 1; +end - function res = isBedMovementTimeBlock(self) - res = self.index == 3; - end + function res + = isExternalSignalTimeBlock (self) res = self.index == 2; +end - function res = isGantryMovementTimeBlock(self) - res = self.index == 4; - end + function res + = isBedMovementTimeBlock (self) res = self.index == 3; +end - function eq = eq(self, other) - eq = isa(other, "petsird.TimeBlock") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); - end + function res + = isGantryMovementTimeBlock (self) res = self.index == 4; +end - function ne = ne(self, other) - ne = ~self.eq(other); - end + function eq + = eq (self, other) eq = isa (other, "petsird.TimeBlock") + && all ([self.index_] == [other.index_], 'all') + && all ([self.value] == [other.value], 'all'); +end - function t = tag(self) - tags_ = ["EventTimeBlock", "ExternalSignalTimeBlock", "BedMovementTimeBlock", "GantryMovementTimeBlock"]; - t = tags_(self.index_); - end - end + function ne + = ne (self, other) ne = ~self.eq (other); end + + function t + = tag (self) tags_ = [ + "EventTimeBlock", "ExternalSignalTimeBlock", "BedMovementTimeBlock", + "GantryMovementTimeBlock" + ]; +t = tags_ (self.index_); +end end end diff --git a/matlab/toolbox/+petsird/TimeFrameInformation.m b/matlab/toolbox/+petsird/TimeFrameInformation.m index 1619b43..21b598a 100644 --- a/matlab/toolbox/+petsird/TimeFrameInformation.m +++ b/matlab/toolbox/+petsird/TimeFrameInformation.m @@ -1,52 +1,41 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef TimeFrameInformation < handle - % A sequence of time intervals (could be consecutive) - properties - time_frames - end + classdef TimeFrameInformation + < handle + % A sequence of time intervals (could be consecutive) + properties time_frames end - methods - function self = TimeFrameInformation(kwargs) - arguments - kwargs.time_frames = petsird.TimeInterval.empty(); - end - self.time_frames = kwargs.time_frames; - end - - function res = number_of_time_frames(self) - res = length(self.time_frames); - return - end - - - function res = eq(self, other) - res = ... - isa(other, "petsird.TimeFrameInformation") && ... - isequal({self.time_frames}, {other.time_frames}); - end + methods function + self = TimeFrameInformation (kwargs) arguments kwargs + .time_frames = petsird.TimeInterval.empty (); +end self.time_frames = kwargs.time_frames; +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = number_of_time_frames (self) res = length (self.time_frames); +return end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = eq (self, other) res + = ... isa (other, "petsird.TimeFrameInformation") + && ...isequal ({ self.time_frames }, { other.time_frames }); +end - methods (Static) - function z = zeros(varargin) - elem = petsird.TimeFrameInformation(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end + function res + = ne (self, other) res = ~self.eq (other); end + + function res + = isequal (self, other) res = all (eq (self, other)); +end end + +methods (Static) +function z = zeros (varargin) elem = petsird.TimeFrameInformation (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/TimeInterval.m b/matlab/toolbox/+petsird/TimeInterval.m index 130cfe0..ec8343b 100644 --- a/matlab/toolbox/+petsird/TimeInterval.m +++ b/matlab/toolbox/+petsird/TimeInterval.m @@ -1,50 +1,38 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. +% This file was generated by the "yardl" tool.DO NOT EDIT. -classdef TimeInterval < handle - % Time interval in milliseconds since start of acquisition - properties - start - stop - end + classdef TimeInterval + < handle + % Time interval in milliseconds since start of acquisition properties + start stop end - methods - function self = TimeInterval(kwargs) - arguments - kwargs.start = uint32(0); - kwargs.stop = uint32(0); - end - self.start = kwargs.start; - self.stop = kwargs.stop; - end + methods function self + = TimeInterval (kwargs) arguments kwargs.start = uint32 (0); +kwargs.stop = uint32 (0); +end self.start = kwargs.start; +self.stop = kwargs.stop; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.TimeInterval") && ... - isequal({self.start}, {other.start}) && ... - isequal({self.stop}, {other.stop}); - end + function res + = eq (self, other) res = ... isa (other, "petsird.TimeInterval") + && ...isequal ({ self.start }, { other.start }) + && ...isequal ({ self.stop }, { other.stop }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.TimeInterval(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.TimeInterval (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+petsird/TripleEvent.m b/matlab/toolbox/+petsird/TripleEvent.m index 518d24a..d65bdc4 100644 --- a/matlab/toolbox/+petsird/TripleEvent.m +++ b/matlab/toolbox/+petsird/TripleEvent.m @@ -17,43 +17,36 @@ function self = TripleEvent(kwargs) arguments kwargs.detector_ids = repelem(uint32(0), 3); - kwargs.tof_indices = repelem(uint32(0), 2); - kwargs.energy_indices = repelem(uint32(0), 3); - end - self.detector_ids = kwargs.detector_ids; - self.tof_indices = kwargs.tof_indices; - self.energy_indices = kwargs.energy_indices; - end +kwargs.tof_indices = repelem (uint32 (0), 2); +kwargs.energy_indices = repelem (uint32 (0), 3); +end self.detector_ids = kwargs.detector_ids; +self.tof_indices = kwargs.tof_indices; +self.energy_indices = kwargs.energy_indices; +end - function res = eq(self, other) - res = ... - isa(other, "petsird.TripleEvent") && ... - isequal({self.detector_ids}, {other.detector_ids}) && ... - isequal({self.tof_indices}, {other.tof_indices}) && ... - isequal({self.energy_indices}, {other.energy_indices}); - end + function res + = eq (self, other) res + = ... isa (other, "petsird.TripleEvent") + && ...isequal ({ self.detector_ids }, { other.detector_ids }) + && ...isequal ({ self.tof_indices }, { other.tof_indices }) + && ...isequal ({ self.energy_indices }, { other.energy_indices }); +end - function res = ne(self, other) - res = ~self.eq(other); - end + function res + = ne (self, other) res = ~self.eq (other); +end - function res = isequal(self, other) - res = all(eq(self, other)); - end - end + function res + = isequal (self, other) res = all (eq (self, other)); +end end - methods (Static) - function z = zeros(varargin) - elem = petsird.TripleEvent(); - if nargin == 0 - z = elem; - return; - end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end -end +methods (Static) +function z = zeros (varargin) elem = petsird.TripleEvent (); +if nargin + == 0 z = elem; +return; +end sz = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+yardl/+binary/BinaryProtocolReader.m b/matlab/toolbox/+yardl/+binary/BinaryProtocolReader.m index 1180269..e249307 100644 --- a/matlab/toolbox/+yardl/+binary/BinaryProtocolReader.m +++ b/matlab/toolbox/+yardl/+binary/BinaryProtocolReader.m @@ -1,40 +1,39 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef BinaryProtocolReader < handle + classdef BinaryProtocolReader < handle - properties (Access=protected) - stream_ - end + properties (Access = protected) stream_ end - methods - function self = BinaryProtocolReader(infile, expected_schema) - self.stream_ = yardl.binary.CodedInputStream(infile); - magic_bytes = self.stream_.read_bytes(length(yardl.binary.MAGIC_BYTES)); - if magic_bytes ~= yardl.binary.MAGIC_BYTES - throw(yardl.ProtocolError("Invalid magic bytes")); - end + methods function self = BinaryProtocolReader (infile, expected_schema) self + .stream_ = yardl.binary.CodedInputStream ( + infile); +magic_bytes = self.stream_.read_bytes (length (yardl.binary.MAGIC_BYTES)); +if magic_bytes + ~ = yardl.binary.MAGIC_BYTES throw ( + yardl.ProtocolError ("Invalid magic bytes")); +end - version = read_fixed_int32(self.stream_); - if version ~= yardl.binary.CURRENT_BINARY_FORMAT_VERSION - throw(yardl.ProtocolError("Invalid binary format version")); - end + version + = read_fixed_int32 (self.stream_); +if version + ~ = yardl.binary.CURRENT_BINARY_FORMAT_VERSION throw ( + yardl.ProtocolError ("Invalid binary format version")); +end - s = yardl.binary.StringSerializer(); - schema = s.read(self.stream_); - if ~isempty(expected_schema) & schema ~= expected_schema - throw(yardl.ProtocolError("Invalid schema")); - end - end - end + s + = yardl.binary.StringSerializer (); +schema = s.read (self.stream_); +if + ~isempty (expected_schema) + & schema + ~ = expected_schema throw (yardl.ProtocolError ("Invalid schema")); +end end end - methods (Access=protected) - function close_(self) - self.stream_.close(); - end - end -end + methods (Access = protected) function close_ (self) self.stream_.close (); +end end end -function res = read_fixed_int32(stream) - res = typecast(stream.read_bytes(4), "int32"); + function res + = read_fixed_int32 (stream) res + = typecast (stream.read_bytes (4), "int32"); end diff --git a/matlab/toolbox/+yardl/+binary/BinaryProtocolWriter.m b/matlab/toolbox/+yardl/+binary/BinaryProtocolWriter.m index 4a5378a..bf98ed6 100644 --- a/matlab/toolbox/+yardl/+binary/BinaryProtocolWriter.m +++ b/matlab/toolbox/+yardl/+binary/BinaryProtocolWriter.m @@ -1,37 +1,30 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef BinaryProtocolWriter < handle + classdef BinaryProtocolWriter < handle - properties (Access=protected) - stream_ - end + properties (Access = protected) stream_ end - methods - function self = BinaryProtocolWriter(outfile, schema) - self.stream_ = yardl.binary.CodedOutputStream(outfile); - self.stream_.write_bytes(yardl.binary.MAGIC_BYTES); - write_fixed_int32(self.stream_, yardl.binary.CURRENT_BINARY_FORMAT_VERSION); - s = yardl.binary.StringSerializer(); - s.write(self.stream_, schema); - end - end + methods function self = BinaryProtocolWriter (outfile, schema) self + .stream_ = yardl.binary.CodedOutputStream ( + outfile); +self.stream_.write_bytes (yardl.binary.MAGIC_BYTES); +write_fixed_int32 (self.stream_, yardl.binary.CURRENT_BINARY_FORMAT_VERSION); +s = yardl.binary.StringSerializer (); +s.write (self.stream_, schema); +end end - methods (Access=protected) - function end_stream_(self) - self.stream_.write_byte(uint8(0)); - end - - function close_(self) - self.stream_.close(); - end - end + methods (Access = protected) function + end_stream_ (self) self.stream_.write_byte (uint8 (0)); end -function write_fixed_int32(stream, value) - arguments - stream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeA(value, "int32")} - end - stream.write_bytes(typecast(value, "uint8")); + function close_ (self) self.stream_.close (); +end end end + + function + write_fixed_int32 (stream, value) +arguments stream (1, 1) yardl.binary + .CodedOutputStream value (1, 1){ + mustBeA (value, "int32") + } end stream.write_bytes (typecast (value, "uint8")); end diff --git a/matlab/toolbox/+yardl/+binary/BoolSerializer.m b/matlab/toolbox/+yardl/+binary/BoolSerializer.m index 8311273..4abfd7c 100644 --- a/matlab/toolbox/+yardl/+binary/BoolSerializer.m +++ b/matlab/toolbox/+yardl/+binary/BoolSerializer.m @@ -1,28 +1,25 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef BoolSerializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeInRange(value, 0, 1)} - end - byte = cast(value, "uint8"); - outstream.write_bytes(byte); - end - - function res = read(instream) - byte = instream.read_byte(); - res = cast(byte, "logical"); - end + classdef BoolSerializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1){ mustBeInRange (value, 0, 1) } end byte = cast (value, + "uint8"); +outstream.write_bytes (byte); +end - function c = get_class() - c = "logical"; - end + function res + = read (instream) byte = instream.read_byte (); +res = cast (byte, "logical"); +end - function trivial = is_trivially_serializable() - trivial = true; - end - end + function c + = get_class () c = "logical"; end + + function trivial + = is_trivially_serializable () trivial = true; +end end end diff --git a/matlab/toolbox/+yardl/+binary/CURRENT_BINARY_FORMAT_VERSION.m b/matlab/toolbox/+yardl/+binary/CURRENT_BINARY_FORMAT_VERSION.m index 2fcacad..c333a92 100644 --- a/matlab/toolbox/+yardl/+binary/CURRENT_BINARY_FORMAT_VERSION.m +++ b/matlab/toolbox/+yardl/+binary/CURRENT_BINARY_FORMAT_VERSION.m @@ -1,6 +1,5 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function res = CURRENT_BINARY_FORMAT_VERSION - res = int32(1); + function res = CURRENT_BINARY_FORMAT_VERSION res = int32 (1); end diff --git a/matlab/toolbox/+yardl/+binary/CodedInputStream.m b/matlab/toolbox/+yardl/+binary/CodedInputStream.m index 34e03ca..8fe82f9 100644 --- a/matlab/toolbox/+yardl/+binary/CodedInputStream.m +++ b/matlab/toolbox/+yardl/+binary/CodedInputStream.m @@ -1,74 +1,60 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. - -classdef CodedInputStream < handle - - properties (Access=private) - fid_ - owns_stream_ - end - - methods - function self = CodedInputStream(infile) - if isa(infile, "string") || isa(infile, "char") - [fileId, errMsg] = fopen(infile, "r"); - if fileId < 0 - throw(yardl.RuntimeError(errMsg)); - end - self.fid_ = fileId; - self.owns_stream_ = true; - else - self.fid_ = infile; - self.owns_stream_ = false; - end - end - - function close(self) - if self.owns_stream_ && self.fid_ > 2 - fclose(self.fid_); - self.fid_ = -1; - end - end - - function res = read_bytes(self, count) - res = fread(self.fid_, count, "*uint8"); - if iscolumn(res) - res = transpose(res); - end - end - - function res = read_byte(self) - res = fread(self.fid_, 1, "*uint8"); - end - - function res = read_values_directly(self, shape, precision) - res = fread(self.fid_, shape, "*"+precision); - if iscolumn(res) - res = transpose(res); - end - end - - function res = read_unsigned_varint(self) - res = uint64(0); - shift = uint8(0); - - while true - byte = self.read_byte(); - res = bitor(res, bitshift(uint64(bitand(byte, 0x7F)), shift)); - if byte < 0x80 - return - end - shift = shift + 7; - end - end - - function res = zigzag_decode(~, value) - value = uint64(value); - res = bitxor(int64(bitshift(value, -1)), -int64(bitand(value, 1))); - end + % Licensed under the MIT License. + + classdef CodedInputStream < handle + + properties (Access = private) fid_ owns_stream_ end + + methods function self = CodedInputStream (infile) if isa (infile, "string") + || isa (infile, "char")[fileId, errMsg] + = fopen (infile, "r"); +if fileId + < 0 throw (yardl.RuntimeError (errMsg)); +end self.fid_ = fileId; +self.owns_stream_ = true; +else self.fid_ = infile; +self.owns_stream_ = false; +end end + + function close (self) if self.owns_stream_ &&self.fid_ + > 2 fclose (self.fid_); +self.fid_ = -1; +end end + + function res + = read_bytes (self, count) res = fread (self.fid_, count, "*uint8"); +if iscolumn (res) + res = transpose (res); +end end + + function res + = read_byte (self) res = fread (self.fid_, 1, "*uint8"); +end - function res = read_signed_varint(self) - res = self.zigzag_decode(self.read_unsigned_varint()); - end - end + function res + = read_values_directly (self, shape, precision) res + = fread (self.fid_, shape, "*" + precision); +if iscolumn (res) + res = transpose (res); +end end + + function res + = read_unsigned_varint (self) res = uint64 (0); +shift = uint8 (0); + +while + true byte = self.read_byte (); +res = bitor (res, bitshift (uint64 (bitand(byte, 0x7F)), shift)); +if byte + < 0x80 return end shift = shift + 7; +end end + + function res + = zigzag_decode (~, value) value = uint64 (value); +res = bitxor (int64 (bitshift (value, -1)), -int64 (bitand(value, 1))); end + + function res + = read_signed_varint (self) res + = self.zigzag_decode (self.read_unsigned_varint ()); +end end end diff --git a/matlab/toolbox/+yardl/+binary/CodedOutputStream.m b/matlab/toolbox/+yardl/+binary/CodedOutputStream.m index c2aedf3..cf53460 100644 --- a/matlab/toolbox/+yardl/+binary/CodedOutputStream.m +++ b/matlab/toolbox/+yardl/+binary/CodedOutputStream.m @@ -1,84 +1,66 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef CodedOutputStream < handle + classdef CodedOutputStream < handle - properties (Access=private) - fid_ - owns_stream_ - end + properties (Access = private) fid_ owns_stream_ end - methods - function self = CodedOutputStream(outfile) - if isa(outfile, "string") || isa(outfile, "char") - [fileId, errMsg] = fopen(outfile, "W"); - if fileId < 0 - throw(yardl.RuntimeError(errMsg)); - end - self.fid_ = fileId; - self.owns_stream_ = true; - else - self.fid_ = outfile; - self.owns_stream_ = false; - end - end + methods function self = CodedOutputStream (outfile) if isa (outfile, + "string") + || isa (outfile, "char")[fileId, errMsg] + = fopen (outfile, "W"); +if fileId + < 0 throw (yardl.RuntimeError (errMsg)); +end self.fid_ = fileId; +self.owns_stream_ = true; +else self.fid_ = outfile; +self.owns_stream_ = false; +end end - function close(self) - if self.owns_stream_ && self.fid_ > 2 - fclose(self.fid_); - self.fid_ = -1; - end - end + function close (self) if self.owns_stream_ &&self.fid_ + > 2 fclose (self.fid_); +self.fid_ = -1; +end end - function write_bytes(self, bytes) - arguments - self - bytes (1,:) {mustBeA(bytes, "uint8")} - end - fwrite(self.fid_, bytes, "uint8"); - end - - function write_byte(self, value) - arguments - self - value (1,1) {mustBeA(value, "uint8")} - end - fwrite(self.fid_, value, "uint8"); - end + function + write_bytes (self, bytes) +arguments self bytes (1, + :){ mustBeA (bytes, "uint8") } end + fwrite (self.fid_, bytes, "uint8"); +end - function write_values_directly(self, values, precision) - fwrite(self.fid_, values, precision); - end + function + write_byte (self, value) +arguments self value (1, 1){ mustBeA (value, "uint8") } end + fwrite (self.fid_, value, "uint8"); +end - function write_unsigned_varint(self, value) - arguments - self - value (1,1) {mustBeInteger,mustBeNonnegative} - end + function write_values_directly (self, values, precision) + fwrite (self.fid_, values, precision); +end - int_val = uint64(value); - while true - if int_val < 0x80 - self.write_byte(uint8(int_val)); - return - end + function + write_unsigned_varint (self, value) +arguments self value (1, 1){ mustBeInteger, mustBeNonnegative } end - self.write_byte(uint8(bitor(bitand(int_val, uint64(0x7F)), uint64(0x80)))); - int_val = bitshift(int_val, -7); - end - end + int_val = uint64 (value); +while + true if int_val < 0x80 self.write_byte (uint8 (int_val)); +return end - function res = zigzag_encode(~, value) - int_val = int64(value); - res = bitxor(bitshift(int_val, 1), bitshift(int_val, -63)); - end + self.write_byte ( + uint8 (bitor (bitand(int_val, uint64 (0x7F)), uint64 (0x80)))); +int_val = bitshift (int_val, -7); +end end - function write_signed_varint(self, value) - arguments - self - value (1,1) {mustBeInteger} - end - self.write_unsigned_varint(self.zigzag_encode(value)); - end - end + function res + = zigzag_encode (~, value) int_val = int64 (value); +res = bitxor (bitshift (int_val, 1), bitshift (int_val, -63)); end + + function + write_signed_varint (self, value) +arguments self value (1, 1){ + mustBeInteger +} end self.write_unsigned_varint (self.zigzag_encode (value)); +end end end diff --git a/matlab/toolbox/+yardl/+binary/Complexfloat32Serializer.m b/matlab/toolbox/+yardl/+binary/Complexfloat32Serializer.m index 041edb8..cbf8d92 100644 --- a/matlab/toolbox/+yardl/+binary/Complexfloat32Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Complexfloat32Serializer.m @@ -1,49 +1,44 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Complexfloat32Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) single - end - real_bytes = typecast(single(real(value)), "uint8"); - imag_bytes = typecast(single(imag(value)), "uint8"); - outstream.write_bytes(real_bytes); - outstream.write_bytes(imag_bytes); - end - - function res = read(instream) - real_bytes = instream.read_bytes(4); - imag_bytes = instream.read_bytes(4); - res = complex(typecast(real_bytes, "single"), typecast(imag_bytes, "single")); - end + classdef Complexfloat32Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) single end real_bytes = typecast (single (real (value)), + "uint8"); +imag_bytes = typecast (single (imag (value)), "uint8"); +outstream.write_bytes (real_bytes); +outstream.write_bytes (imag_bytes); +end - function c = get_class() - c = "single"; - end + function res + = read (instream) real_bytes = instream.read_bytes (4); +imag_bytes = instream.read_bytes (4); +res = complex (typecast (real_bytes, "single"), + typecast (imag_bytes, "single")); +end - function trivial = is_trivially_serializable() - trivial = true; - end - end + function c + = get_class () c = "single"; +end - methods - function write_trivially(self, stream, values) - rp = real(values); - ip = imag(values); - parts(1, :) = rp(:); - parts(2, :) = ip(:); - stream.write_values_directly(parts, self.get_class()); - end + function trivial + = is_trivially_serializable () trivial = true; +end end - function res = read_trivially(self, stream, shape) - assert(ndims(shape) == 2); - partshape = [2*shape(1) shape(2)]; - res = stream.read_values_directly(partshape, self.get_class()); - res = reshape(res, [2 shape]); - res = squeeze(complex(res(1, :, :), res(2, :, :))); - end - end + methods function write_trivially (self, stream, values) rp = real (values); +ip = imag (values); +parts (1, :) = rp ( :); +parts (2, :) = ip ( :); +stream.write_values_directly (parts, self.get_class ()); end + + function res + = read_trivially (self, stream, shape) assert (ndims (shape) == 2); +partshape = [2 * shape (1) shape (2)]; +res = stream.read_values_directly (partshape, self.get_class ()); +res = reshape (res, [2 shape]); +res = squeeze (complex (res (1, :, :), res (2, :, :))); +end end end diff --git a/matlab/toolbox/+yardl/+binary/Complexfloat64Serializer.m b/matlab/toolbox/+yardl/+binary/Complexfloat64Serializer.m index 5f6fba6..498bb63 100644 --- a/matlab/toolbox/+yardl/+binary/Complexfloat64Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Complexfloat64Serializer.m @@ -1,49 +1,44 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Complexfloat64Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) double - end - real_bytes = typecast(double(real(value)), "uint8"); - imag_bytes = typecast(double(imag(value)), "uint8"); - outstream.write_bytes(real_bytes); - outstream.write_bytes(imag_bytes); - end - - function res = read(instream) - real_bytes = instream.read_bytes(8); - imag_bytes = instream.read_bytes(8); - res = complex(typecast(real_bytes, "double"), typecast(imag_bytes, "double")); - end + classdef Complexfloat64Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) double end real_bytes = typecast (double (real (value)), + "uint8"); +imag_bytes = typecast (double (imag (value)), "uint8"); +outstream.write_bytes (real_bytes); +outstream.write_bytes (imag_bytes); +end - function c = get_class() - c = "double"; - end + function res + = read (instream) real_bytes = instream.read_bytes (8); +imag_bytes = instream.read_bytes (8); +res = complex (typecast (real_bytes, "double"), + typecast (imag_bytes, "double")); +end - function trivial = is_trivially_serializable() - trivial = true; - end - end + function c + = get_class () c = "double"; +end - methods - function write_trivially(self, stream, values) - rp = real(values); - ip = imag(values); - parts(1, :) = rp(:); - parts(2, :) = ip(:); - stream.write_values_directly(parts, self.get_class()); - end + function trivial + = is_trivially_serializable () trivial = true; +end end - function res = read_trivially(self, stream, shape) - assert(ndims(shape) == 2); - partshape = [2*shape(1) shape(2)]; - res = stream.read_values_directly(partshape, self.get_class()); - res = reshape(res, [2 shape]); - res = squeeze(complex(res(1, :, :), res(2, :, :))); - end - end + methods function write_trivially (self, stream, values) rp = real (values); +ip = imag (values); +parts (1, :) = rp ( :); +parts (2, :) = ip ( :); +stream.write_values_directly (parts, self.get_class ()); end + + function res + = read_trivially (self, stream, shape) assert (ndims (shape) == 2); +partshape = [2 * shape (1) shape (2)]; +res = stream.read_values_directly (partshape, self.get_class ()); +res = reshape (res, [2 shape]); +res = squeeze (complex (res (1, :, :), res (2, :, :))); +end end end diff --git a/matlab/toolbox/+yardl/+binary/DateSerializer.m b/matlab/toolbox/+yardl/+binary/DateSerializer.m index 20f78c3..95ad5c6 100644 --- a/matlab/toolbox/+yardl/+binary/DateSerializer.m +++ b/matlab/toolbox/+yardl/+binary/DateSerializer.m @@ -1,26 +1,21 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef DateSerializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - if isa(value, "datetime") - value = yardl.Date.from_datetime(value).value; - elseif isa(value, "yardl.Date") - value = value.value; - else - throw(yardl.TypeError("Expected datetime or yardl.Date, got %s", class(value))); - end - outstream.write_signed_varint(value); - end - - function res = read(instream) - value = instream.read_signed_varint(); - res = yardl.Date(value); - end + classdef DateSerializer < yardl.binary.TypeSerializer + methods (Static) +function write (outstream, value) if isa ( + value, "datetime") value = yardl.Date.from_datetime (value).value; +elseif isa (value, "yardl.Date") value = value.value; +else throw ( + yardl.TypeError ("Expected datetime or yardl.Date, got %s", class(value))); +end outstream.write_signed_varint (value); +end - function c = get_class() - c = "yardl.Date"; - end - end + function res + = read (instream) value = instream.read_signed_varint (); +res = yardl.Date (value); end + + function c + = get_class () c = "yardl.Date"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/DatetimeSerializer.m b/matlab/toolbox/+yardl/+binary/DatetimeSerializer.m index 07f813b..fbe4c2a 100644 --- a/matlab/toolbox/+yardl/+binary/DatetimeSerializer.m +++ b/matlab/toolbox/+yardl/+binary/DatetimeSerializer.m @@ -1,26 +1,21 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef DatetimeSerializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - if isa(value, "datetime") - value = yardl.DateTime.from_datetime(value).value; - elseif isa(value, "yardl.DateTime") - value = value.value; - else - throw(yardl.TypeError("Expected datetime or yardl.DateTime, got %s", class(value))); - end - outstream.write_signed_varint(value); - end - - function res = read(instream) - value = instream.read_signed_varint(); - res = yardl.DateTime(value); - end + classdef DatetimeSerializer < yardl.binary.TypeSerializer + methods (Static) +function write (outstream, value) if isa ( + value, "datetime") value = yardl.DateTime.from_datetime (value).value; +elseif isa (value, "yardl.DateTime") value = value.value; +else throw (yardl.TypeError ("Expected datetime or yardl.DateTime, got %s", + class(value))); +end outstream.write_signed_varint (value); +end - function c = get_class() - c = "yardl.DateTime"; - end - end + function res + = read (instream) value = instream.read_signed_varint (); +res = yardl.DateTime (value); end + + function c + = get_class () c = "yardl.DateTime"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/DynamicNDArraySerializer.m b/matlab/toolbox/+yardl/+binary/DynamicNDArraySerializer.m index 4f7f8c5..e6067ed 100644 --- a/matlab/toolbox/+yardl/+binary/DynamicNDArraySerializer.m +++ b/matlab/toolbox/+yardl/+binary/DynamicNDArraySerializer.m @@ -1,47 +1,49 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef DynamicNDArraySerializer < yardl.binary.NDArraySerializerBase + classdef + DynamicNDArraySerializer < yardl.binary.NDArraySerializerBase - methods - function self = DynamicNDArraySerializer(item_serializer) - self@yardl.binary.NDArraySerializerBase(item_serializer); - end + methods function + self = DynamicNDArraySerializer ( + item_serializer) self @yardl + .binary.NDArraySerializerBase ( + item_serializer); +end - function write(self, outstream, values) - item_shape = self.item_serializer_.get_shape(); - shape = size(values); - if isempty(item_shape) - % values is an array of variable-length vectors or arrays - values = values(:); - elseif isscalar(item_shape) - % values is an array of scalars - values = values(:); - else - % values is an array of fixed-length vectors or arrays - item_shape = item_shape(item_shape > 1); - outer_shape = shape(length(item_shape) + 1:end); - values = reshape(values, [item_shape prod(outer_shape)]); - shape = outer_shape; - end + function write (self, outstream, + values) item_shape = self.item_serializer_.get_shape (); +shape = size (values); +if isempty (item_shape) + % values is an array of variable - length vectors or arrays values = values ( + :); +elseif isscalar (item_shape) % values is an array of scalars values = values ( + :); +else % values is an array of fixed - length vectors or arrays item_shape + = item_shape (item_shape > 1); +outer_shape = shape (length (item_shape) + 1 : end); +values = reshape (values, [item_shape prod (outer_shape)]); +shape = outer_shape; +end - outstream.write_unsigned_varint(length(shape)); - flipped_shape = flip(shape); - for dim = 1:length(flipped_shape) - outstream.write_unsigned_varint(flipped_shape(dim)); + outstream.write_unsigned_varint (length (shape)); +flipped_shape = flip (shape); + for + dim = 1 + : length (flipped_shape) + outstream.write_unsigned_varint (flipped_shape (dim)); end - self.write_data_(outstream, values); - end - - function value = read(self, instream) - ndims = instream.read_unsigned_varint(); - flipped_shape = zeros(1, ndims); - for dim = 1:ndims - flipped_shape(dim) = instream.read_unsigned_varint(); + self.write_data_ (outstream, values); end - shape = flip(flipped_shape); - value = self.read_data_(instream, shape); - end - end -end + + function value + = read (self, instream) ndims + = instream.read_unsigned_varint (); + flipped_shape = zeros (1, ndims); + for + dim = 1 : ndims flipped_shape (dim) + = instream.read_unsigned_varint (); + end shape = flip (flipped_shape); + value = self.read_data_ (instream, shape); + end end end diff --git a/matlab/toolbox/+yardl/+binary/EnumSerializer.m b/matlab/toolbox/+yardl/+binary/EnumSerializer.m index 307eeb9..4e6b860 100644 --- a/matlab/toolbox/+yardl/+binary/EnumSerializer.m +++ b/matlab/toolbox/+yardl/+binary/EnumSerializer.m @@ -1,43 +1,44 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. - -classdef EnumSerializer < yardl.binary.TypeSerializer - properties - classname_; - constructor_; - integer_serializer_; - end - - methods - function self = EnumSerializer(classname, classconstructor, integer_serializer) - self.classname_ = classname; - self.constructor_ = classconstructor; - self.integer_serializer_ = integer_serializer; - end - - function write(self, outstream, value) - self.integer_serializer_.write(outstream, value); - end - - function res = read(self, instream) - int_value = self.integer_serializer_.read(instream); - res = self.constructor_(int_value); - end - - function c = get_class(self) - c = self.classname_; - end - - function trivial = is_trivially_serializable(self) - trivial = self.integer_serializer_.is_trivially_serializable(); - end - - function write_trivially(self, outstream, values) - self.integer_serializer_.write_trivially(outstream, values); - end - - function res = read_trivially(self, instream, shape) - res = self.integer_serializer_.read_trivially(instream, shape); - end - end + % Licensed under the MIT License. + + classdef + EnumSerializer < yardl.binary.TypeSerializer properties classname_; +constructor_; +integer_serializer_; +end + + methods function self + = EnumSerializer (classname, classconstructor, integer_serializer) + self.classname_ + = classname; +self.constructor_ = classconstructor; +self.integer_serializer_ = integer_serializer; +end + + function write (self, outstream, + value) self.integer_serializer_.write (outstream, value); +end + + function res + = read (self, instream) int_value + = self.integer_serializer_.read (instream); +res = self.constructor_ (int_value); end + + function c + = get_class (self) c = self.classname_; +end + + function trivial + = is_trivially_serializable (self) trivial + = self.integer_serializer_.is_trivially_serializable (); +end + + function write_trivially (self, outstream, values) self.integer_serializer_ + .write_trivially (outstream, values); +end + + function res + = read_trivially (self, instream, shape) res + = self.integer_serializer_.read_trivially (instream, shape); +end end end diff --git a/matlab/toolbox/+yardl/+binary/FixedNDArraySerializer.m b/matlab/toolbox/+yardl/+binary/FixedNDArraySerializer.m index 58871f4..d20ab34 100644 --- a/matlab/toolbox/+yardl/+binary/FixedNDArraySerializer.m +++ b/matlab/toolbox/+yardl/+binary/FixedNDArraySerializer.m @@ -1,72 +1,79 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef FixedNDArraySerializer < yardl.binary.NDArraySerializerBase + classdef + FixedNDArraySerializer < yardl.binary.NDArraySerializerBase - properties - shape_ - end + properties shape_ end - methods - function self = FixedNDArraySerializer(item_serializer, shape) - self@yardl.binary.NDArraySerializerBase(item_serializer); - self.shape_ = shape; - end - - function write(self, outstream, values) - if numel(values) == prod(self.shape_) - % This is an NDArray of scalars - self.write_data_(outstream, values(:)); - return; - end + methods function + self = FixedNDArraySerializer ( + item_serializer, shape) self + @yardl.binary.NDArraySerializerBase ( + item_serializer); +self.shape_ = shape; +end - sz = size(values); - if length(sz) < length(self.shape_) - expected = sprintf("%d ", self.shape_); - actual = sprintf("%d ", sz); - throw(yardl.ValueError("Expected shape [%s], got [%s]", expected, actual)); - end + function write (self, outstream, values) if numel (values) + == prod (self.shape_) + % This is an NDArray of scalars self.write_data_ (outstream, + values ( + :)); +return; +end - fixedSize = sz(end-length(self.shape_)+1:end); - if fixedSize ~= self.shape_ - expected = sprintf("%d ", self.shape_); - actual = sprintf("%d ", fixedSize); - throw(yardl.ValueError("Expected shape [%s], got [%s]", expected, actual)); - end + sz + = size (values); +if length (sz) + < length (self.shape_) expected = sprintf ("%d ", self.shape_); +actual = sprintf ("%d ", sz); +throw (yardl.ValueError ("Expected shape [%s], got [%s]", expected, actual)); +end - inner_shape = sz(1:end-length(self.shape_)); - values = reshape(values, [inner_shape prod(self.shape_)]); + fixedSize + = sz (end - length (self.shape_) + 1 + : end); +if fixedSize + ~ = self.shape_ expected = sprintf ("%d ", self.shape_); +actual = sprintf ("%d ", fixedSize); +throw (yardl.ValueError ("Expected shape [%s], got [%s]", expected, actual)); +end - self.write_data_(outstream, values); - end + inner_shape + = sz (1 + : end - length (self.shape_)); +values = reshape (values, [inner_shape prod (self.shape_)]); - function value = read(self, instream) - value = self.read_data_(instream, self.shape_); - end +self.write_data_ (outstream, values); +end - function s = get_shape(self) - item_shape = self.item_serializer_.get_shape(); - if isempty(item_shape) - s = self.shape_; - else - s = [item_shape self.shape_]; - end + function value + = read (self, instream) value = self.read_data_ (instream, self.shape_); +end - if length(s) > 2 - s = s(s>1); - end - end + function s + = get_shape (self) item_shape = self.item_serializer_.get_shape (); +if isempty (item_shape) + s = self.shape_; +else + s = [item_shape self.shape_]; +end - function trivial = is_trivially_serializable(self) - trivial = self.item_serializer_.is_trivially_serializable(); - end + if length (s) + > 2 s + = s (s > 1); +end end - function write_trivially(self, outstream, values) - self.item_serializer_.write_trivially(outstream, values); - end + function trivial + = is_trivially_serializable (self) trivial + = self.item_serializer_.is_trivially_serializable (); +end - function res = read_trivially(self, instream, shape) - res = self.item_serializer_.read_trivially(instream, shape); - end - end + function write_trivially (self, outstream, values) self.item_serializer_ + .write_trivially (outstream, values); end + + function res + = read_trivially (self, instream, shape) res + = self.item_serializer_.read_trivially (instream, shape); +end end end diff --git a/matlab/toolbox/+yardl/+binary/FixedVectorSerializer.m b/matlab/toolbox/+yardl/+binary/FixedVectorSerializer.m index 35dafc2..15cb043 100644 --- a/matlab/toolbox/+yardl/+binary/FixedVectorSerializer.m +++ b/matlab/toolbox/+yardl/+binary/FixedVectorSerializer.m @@ -1,51 +1,46 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. - -classdef FixedVectorSerializer < yardl.binary.VectorSerializerBase - properties - length_; - end - - methods (Access=protected) - function handle_write_count_(self, ~, count) - if count ~= self.length_ - throw(yardl.ValueError("Expected an array of length %d, got %d", self.length_, count)); - end - end - - function count = get_read_count_(self, ~) - count = self.length_; - end - end - - methods - function self = FixedVectorSerializer(item_serializer, length) - self@yardl.binary.VectorSerializerBase(item_serializer); - self.length_ = length; - end - - function s = get_shape(self) - item_shape = self.item_serializer_.get_shape(); - if isempty(item_shape) - s = [1, self.length_]; - elseif isscalar(item_shape) - s = [item_shape self.length_]; - else - s = [item_shape self.length_]; - s = s(s>1); - end - end - - function trivial = is_trivially_serializable(self) - trivial = self.item_serializer_.is_trivially_serializable(); - end - - function write_trivially(self, outstream, values) - self.item_serializer_.write_trivially(outstream, values); - end - - function res = read_trivially(self, instream, shape) - res = self.item_serializer_.read_trivially(instream, shape); - end - end + % Licensed under the MIT License. + + classdef FixedVectorSerializer < yardl.binary.VectorSerializerBase + properties length_; +end + + methods (Access = protected) function + handle_write_count_ (self, ~, count) if count + ~ = self.length_ + throw (yardl.ValueError ("Expected an array of length %d, got %d", + self.length_, count)); +end end + + function count + = get_read_count_ (self, ~) count = self.length_; +end end + + methods function self + = FixedVectorSerializer (item_serializer, length) self + @yardl.binary.VectorSerializerBase (item_serializer); +self.length_ = length; +end + + function s + = get_shape (self) item_shape = self.item_serializer_.get_shape (); +if isempty (item_shape) + s = [ 1, self.length_ ]; +elseif isscalar (item_shape) s = [item_shape self.length_]; +else s = [item_shape self.length_]; +s = s (s > 1); +end end + + function trivial + = is_trivially_serializable (self) trivial + = self.item_serializer_.is_trivially_serializable (); +end + + function write_trivially (self, outstream, values) self.item_serializer_ + .write_trivially (outstream, values); end + + function res + = read_trivially (self, instream, shape) res + = self.item_serializer_.read_trivially (instream, shape); +end end end diff --git a/matlab/toolbox/+yardl/+binary/Float32Serializer.m b/matlab/toolbox/+yardl/+binary/Float32Serializer.m index 021e623..190d597 100644 --- a/matlab/toolbox/+yardl/+binary/Float32Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Float32Serializer.m @@ -1,29 +1,26 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Float32Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) single - end + classdef Float32Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) single end - bytes = typecast(single(value), "uint8"); - outstream.write_bytes(bytes); - end - - function res = read(instream) - bytes = instream.read_bytes(4); - res = typecast(bytes, "single"); - end + bytes = typecast (single (value), "uint8"); +outstream.write_bytes (bytes); +end - function c = get_class() - c = "single"; - end + function res + = read (instream) bytes = instream.read_bytes (4); +res = typecast (bytes, "single"); +end - function trivial = is_trivially_serializable() - trivial = true; - end - end + function c + = get_class () c = "single"; end + + function trivial + = is_trivially_serializable () trivial = true; +end end end diff --git a/matlab/toolbox/+yardl/+binary/Float64Serializer.m b/matlab/toolbox/+yardl/+binary/Float64Serializer.m index 4f58367..ec456da 100644 --- a/matlab/toolbox/+yardl/+binary/Float64Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Float64Serializer.m @@ -1,28 +1,24 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Float64Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) double - end - bytes = typecast(double(value), "uint8"); - outstream.write_bytes(bytes); - end - - function res = read(instream) - bytes = instream.read_bytes(8); - res = typecast(bytes, "double"); - end + classdef Float64Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1) double end bytes = typecast (double (value), "uint8"); +outstream.write_bytes (bytes); +end - function c = get_class() - c = "double"; - end + function res + = read (instream) bytes = instream.read_bytes (8); +res = typecast (bytes, "double"); +end - function trivial = is_trivially_serializable() - trivial = true; - end - end + function c + = get_class () c = "double"; end + + function trivial + = is_trivially_serializable () trivial = true; +end end end diff --git a/matlab/toolbox/+yardl/+binary/Int16Serializer.m b/matlab/toolbox/+yardl/+binary/Int16Serializer.m index 8f140d8..aed5c95 100644 --- a/matlab/toolbox/+yardl/+binary/Int16Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Int16Serializer.m @@ -1,22 +1,20 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Int16Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeInRange(value, -32768, 32767)} - end - outstream.write_signed_varint(value); - end - - function res = read(instream) - res = int16(instream.read_signed_varint()); - end + classdef Int16Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary + .CodedOutputStream value (1, 1){ + mustBeInRange (value, -32768, 32767) + } end outstream.write_signed_varint (value); +end - function c = get_class() - c = "int16"; - end - end + function res + = read (instream) res = int16 (instream.read_signed_varint ()); end + + function c + = get_class () c = "int16"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/Int32Serializer.m b/matlab/toolbox/+yardl/+binary/Int32Serializer.m index 20fc3d3..30e8a70 100644 --- a/matlab/toolbox/+yardl/+binary/Int32Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Int32Serializer.m @@ -1,22 +1,20 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Int32Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeInRange(value, -2147483648, 2147483647)} - end - outstream.write_signed_varint(value); - end - - function res = read(instream) - res = int32(instream.read_signed_varint()); - end + classdef Int32Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary + .CodedOutputStream value (1, 1){ + mustBeInRange (value, -2147483648, 2147483647) + } end outstream.write_signed_varint (value); +end - function c = get_class() - c = "int32"; - end - end + function res + = read (instream) res = int32 (instream.read_signed_varint ()); end + + function c + = get_class () c = "int32"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/Int64Serializer.m b/matlab/toolbox/+yardl/+binary/Int64Serializer.m index 2176a93..de023f6 100644 --- a/matlab/toolbox/+yardl/+binary/Int64Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Int64Serializer.m @@ -1,22 +1,20 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Int64Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeInRange(value, -9223372036854775808, 9223372036854775807)} - end - outstream.write_signed_varint(value); - end - - function res = read(instream) - res = int64(instream.read_signed_varint()); - end + classdef Int64Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary + .CodedOutputStream value (1, 1){ + mustBeInRange (value, -9223372036854775808, 9223372036854775807) + } end outstream.write_signed_varint (value); +end - function c = get_class() - c = "int64"; - end - end + function res + = read (instream) res = int64 (instream.read_signed_varint ()); end + + function c + = get_class () c = "int64"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/Int8Serializer.m b/matlab/toolbox/+yardl/+binary/Int8Serializer.m index ecf037c..ac3755d 100644 --- a/matlab/toolbox/+yardl/+binary/Int8Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Int8Serializer.m @@ -1,27 +1,24 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Int8Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeInRange(value, -128, 127)} - end - byte = typecast(int8(value), "uint8"); - outstream.write_byte(byte); - end - - function res = read(instream) - res = typecast(instream.read_byte(), "int8"); - end + classdef Int8Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary.CodedOutputStream value (1, 1){ + mustBeInRange (value, -128, 127) +} end byte = typecast (int8 (value), "uint8"); +outstream.write_byte (byte); +end - function c = get_class() - c = "int8"; - end + function res + = read (instream) res = typecast (instream.read_byte (), "int8"); +end - function trivial = is_trivially_serializable() - trivial = true; - end - end + function c + = get_class () c = "int8"; end + + function trivial + = is_trivially_serializable () trivial = true; +end end end diff --git a/matlab/toolbox/+yardl/+binary/MAGIC_BYTES.m b/matlab/toolbox/+yardl/+binary/MAGIC_BYTES.m index 4391975..1aec956 100644 --- a/matlab/toolbox/+yardl/+binary/MAGIC_BYTES.m +++ b/matlab/toolbox/+yardl/+binary/MAGIC_BYTES.m @@ -1,6 +1,5 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function res = MAGIC_BYTES - res = unicode2native('yardl'); + function res = MAGIC_BYTES res = unicode2native ('yardl'); end diff --git a/matlab/toolbox/+yardl/+binary/MapSerializer.m b/matlab/toolbox/+yardl/+binary/MapSerializer.m index e8dfcec..32be241 100644 --- a/matlab/toolbox/+yardl/+binary/MapSerializer.m +++ b/matlab/toolbox/+yardl/+binary/MapSerializer.m @@ -1,51 +1,45 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef MapSerializer < yardl.binary.TypeSerializer - properties - key_serializer_; - value_serializer_; - end + classdef MapSerializer < yardl.binary.TypeSerializer properties + key_serializer_; +value_serializer_; +end - methods - function self = MapSerializer(key_serializer, value_serializer) - self.key_serializer_ = key_serializer; - self.value_serializer_ = value_serializer; - end + methods function self + = MapSerializer (key_serializer, value_serializer) self.key_serializer_ + = key_serializer; +self.value_serializer_ = value_serializer; +end - function write(self, outstream, value) - arguments - self (1,1) - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) yardl.Map - end + function + write (self, outstream, value) +arguments self (1, 1) + outstream (1, 1) yardl.binary.CodedOutputStream value (1, 1) yardl.Map end - count = numEntries(value); - outstream.write_unsigned_varint(count); - if count == 0 - return - end + count = numEntries (value); +outstream.write_unsigned_varint (count); +if count + == 0 return end - ks = keys(value); - vs = values(value); - for i = 1:count - self.key_serializer_.write(outstream, ks(i)); - self.value_serializer_.write(outstream, vs(i)); - end - end + ks + = keys (value); +vs = values (value); + for + i = 1 : count self.key_serializer_.write (outstream, ks (i)); + self.value_serializer_.write (outstream, vs (i)); + end end - function res = read(self, instream) - count = instream.read_unsigned_varint(); - res = yardl.Map(); - for i = 1:count - k = self.key_serializer_.read(instream); - v = self.value_serializer_.read(instream); - insert(res, k, v); - end - end + function res + = read (self, instream) count + = instream.read_unsigned_varint (); + res = yardl.Map (); + for + i = 1 : count k = self.key_serializer_.read (instream); + v = self.value_serializer_.read (instream); + insert (res, k, v); + end end - function c = get_class(~) - c = "yardl.Map"; - end - end -end + function c + = get_class (~) c = "yardl.Map"; + end end end diff --git a/matlab/toolbox/+yardl/+binary/NDArraySerializer.m b/matlab/toolbox/+yardl/+binary/NDArraySerializer.m index cde6434..5361914 100644 --- a/matlab/toolbox/+yardl/+binary/NDArraySerializer.m +++ b/matlab/toolbox/+yardl/+binary/NDArraySerializer.m @@ -1,51 +1,52 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef NDArraySerializer < yardl.binary.NDArraySerializerBase + classdef + NDArraySerializer < yardl.binary.NDArraySerializerBase - properties - ndims_ - end + properties ndims_ end - methods - function self = NDArraySerializer(item_serializer, ndims) - self@yardl.binary.NDArraySerializerBase(item_serializer); - self.ndims_ = ndims; - end - - function write(self, outstream, values) - sz = size(values); - if ndims(values) < self.ndims_ - sz = [sz ones(1, self.ndims_-ndims(values))]; - end + methods function + self = NDArraySerializer (item_serializer, + ndims) self + @yardl.binary.NDArraySerializerBase ( + item_serializer); +self.ndims_ = ndims; +end - flipped_shape = flip(sz); - for dim = 1:self.ndims_ - len = flipped_shape(dim); - outstream.write_unsigned_varint(len); - end + function write (self, outstream, values) sz = size (values); +if ndims (values) + < self.ndims_ sz = [sz ones (1, self.ndims_ - ndims (values))]; +end - if length(sz) == self.ndims_ - % This is an NDArray of scalars - self.write_data_(outstream, values(:)); - return + flipped_shape + = flip (sz); + for + dim = 1 : self.ndims_ len = flipped_shape (dim); + outstream.write_unsigned_varint (len); end - % This is an NDArray of vectors/arrays - inner_shape = sz(1:end-self.ndims_); - outer_shape = sz(end-self.ndims_+1:end); - values = reshape(values, [inner_shape prod(outer_shape)]); + if length (sz) + == self.ndims_ + % This is an NDArray of scalars + self.write_data_ (outstream, values ( + :)); + return end - self.write_data_(outstream, values); - end + % This is an NDArray of vectors / arrays inner_shape + = sz (1 + : end - self.ndims_); + outer_shape = sz (end - self.ndims_ + 1 : end); + values = reshape (values, [inner_shape prod (outer_shape)]); - function value = read(self, instream) - flipped_shape = zeros(1, self.ndims_); - for dim = 1:self.ndims_ - flipped_shape(dim) = instream.read_unsigned_varint(); + self.write_data_ (outstream, values); end - shape = flip(flipped_shape); - value = self.read_data_(instream, shape); - end - end -end + + function value + = read (self, instream) flipped_shape = zeros (1, self.ndims_); + for + dim = 1 : self.ndims_ flipped_shape (dim) + = instream.read_unsigned_varint (); + end shape = flip (flipped_shape); + value = self.read_data_ (instream, shape); + end end end diff --git a/matlab/toolbox/+yardl/+binary/NDArraySerializerBase.m b/matlab/toolbox/+yardl/+binary/NDArraySerializerBase.m index 12cf775..36aedf2 100644 --- a/matlab/toolbox/+yardl/+binary/NDArraySerializerBase.m +++ b/matlab/toolbox/+yardl/+binary/NDArraySerializerBase.m @@ -1,106 +1,101 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. - -classdef NDArraySerializerBase < yardl.binary.TypeSerializer - - properties - item_serializer_ - end - - methods (Abstract) - write(self, outstream, values) - read(self, instream) - end - - methods (Access=protected) - function self = NDArraySerializerBase(item_serializer) - self.item_serializer_ = item_serializer; - end - - function write_data_(self, outstream, values) - % values is an array of shape [A, B, ..., N], where - % N is the "flattened" dimension of the NDArray, and - % A, B, ... are the dimensions of the inner items. - - if ~iscell(values) && self.item_serializer_.is_trivially_serializable() - self.item_serializer_.write_trivially(outstream, values); - return; - end - - sz = size(values); - - if ndims(values) > 2 - count = sz(end); - inner_shape = sz(1:end-1); - r = reshape(values, [], count); - for i = 1:count - val = reshape(r(:, i), inner_shape); - self.item_serializer_.write(outstream, val); - end - elseif isrow(values) || iscolumn(values) - count = prod(sz); - if iscell(values) - for i = 1:count - self.item_serializer_.write(outstream, values{i}); + % Licensed under the MIT License. + + classdef + NDArraySerializerBase < yardl.binary.TypeSerializer + + properties item_serializer_ end + + methods (Abstract) + write (self, outstream, values) + read (self, instream) end + + methods (Access = protected) function + self = NDArraySerializerBase ( + item_serializer) self + .item_serializer_ = item_serializer; +end + + function write_data_ (self, outstream, values) + % values is an array of shape[A, B, ..., N], + where % N is the "flattened" dimension of the NDArray, and % A, B, + ... are the dimensions of the inner items. + + if ~iscell (values) + && self.item_serializer_.is_trivially_serializable () self + .item_serializer_.write_trivially (outstream, values); +return; +end + + sz + = size (values); + +if ndims (values) + > 2 count = sz (end); +inner_shape = sz (1 : end - 1); +r = reshape (values, [], count); + for + i = 1 : count val = reshape (r ( :, i), inner_shape); + self.item_serializer_.write (outstream, val); + end elseif isrow (values) + || iscolumn (values) count = prod (sz); + if iscell (values) + for + i = 1 : count self.item_serializer_.write (outstream, + values{ i }); end else for i = 1:count self.item_serializer_.write(outstream, values(i)); - end + end end else count = sz (end); + for + i = 1 : count self.item_serializer_.write (outstream, + values ( + :, i)); + end end end + + function res + = read_data_ (self, instream, shape) flat_length + = prod (shape); + + item_shape = self.item_serializer_.get_shape (); + + if isempty (item_shape) + res = cell (shape); + for + i = 1 : flat_length res{ i } + = self.item_serializer_.read (instream); + end return end + + if self.item_serializer_.is_trivially_serializable () res + = self.item_serializer_.read_trivially ( + instream, [ prod (item_shape), flat_length ]); + else res = yardl.allocate (self.get_class (), + [ prod (item_shape), flat_length ]); + for + i = 1 : flat_length item + = self.item_serializer_.read (instream); + res ( :, i) = item ( :); + end end + + % Tricky reshaping to remove unnecessary singleton + dimensions in + % subarrays, + arrays of fixed vectors, + etc.item_shape = item_shape (item_shape > 1); + if isempty (item_shape) + &&isscalar (shape) item_shape = 1; + end newshape = [item_shape shape]; + res = reshape (res, newshape); + + if iscolumn (res) + res = transpose (res); + end end end + + methods function c + = get_class (self) c = self.item_serializer_.get_class (); end - else - count = sz(end); - for i = 1:count - self.item_serializer_.write(outstream, values(:, i)); - end - end - end - - function res = read_data_(self, instream, shape) - flat_length = prod(shape); - item_shape = self.item_serializer_.get_shape(); - - if isempty(item_shape) - res = cell(shape); - for i = 1:flat_length - res{i} = self.item_serializer_.read(instream); - end - return - end - - if self.item_serializer_.is_trivially_serializable() - res = self.item_serializer_.read_trivially(instream, [prod(item_shape), flat_length]); - else - res = yardl.allocate(self.get_class(), [prod(item_shape), flat_length]); - for i = 1:flat_length - item = self.item_serializer_.read(instream); - res(:, i) = item(:); - end - end - - % Tricky reshaping to remove unnecessary singleton dimensions in - % subarrays, arrays of fixed vectors, etc. - item_shape = item_shape(item_shape > 1); - if isempty(item_shape) && isscalar(shape) - item_shape = 1; - end - newshape = [item_shape shape]; - res = reshape(res, newshape); - - if iscolumn(res) - res = transpose(res); - end - end - end - - methods - function c = get_class(self) - c = self.item_serializer_.get_class(); - end - - function s = get_shape(~) - s = []; - end - end -end + function s + = get_shape (~) s = []; + end end end diff --git a/matlab/toolbox/+yardl/+binary/NoneSerializer.m b/matlab/toolbox/+yardl/+binary/NoneSerializer.m index 9986594..6139ad9 100644 --- a/matlab/toolbox/+yardl/+binary/NoneSerializer.m +++ b/matlab/toolbox/+yardl/+binary/NoneSerializer.m @@ -1,17 +1,13 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef NoneSerializer < yardl.binary.TypeSerializer - methods (Static) - function write(~, ~) - end + classdef NoneSerializer < yardl.binary.TypeSerializer + methods (Static) +function write (~, ~) end - function res = read(~) - res = yardl.None; - end - - function c = get_class() - c = "yardl.Optional"; - end - end + function res = read (~) res = yardl.None; end + + function c + = get_class () c = "yardl.Optional"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/OptionalSerializer.m b/matlab/toolbox/+yardl/+binary/OptionalSerializer.m index a4f7960..57fd8f3 100644 --- a/matlab/toolbox/+yardl/+binary/OptionalSerializer.m +++ b/matlab/toolbox/+yardl/+binary/OptionalSerializer.m @@ -1,43 +1,34 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef OptionalSerializer < yardl.binary.TypeSerializer - properties - item_serializer_; - end + classdef OptionalSerializer < yardl.binary.TypeSerializer properties + item_serializer_; +end - methods - function self = OptionalSerializer(item_serializer) - self.item_serializer_ = item_serializer; - end + methods function self + = OptionalSerializer (item_serializer) self.item_serializer_ + = item_serializer; +end - function write(self, outstream, value) - if isa(value, "yardl.Optional") - if value.has_value() - outstream.write_byte(uint8(1)); - self.item_serializer_.write(outstream, value.value()); - else - outstream.write_byte(uint8(0)); - return - end - else - outstream.write_byte(uint8(1)); - self.item_serializer_.write(outstream, value); - end - end + function write (self, outstream, value) if isa (value, + "yardl.Optional") if value + .has_value () outstream.write_byte (uint8 (1)); +self.item_serializer_.write (outstream, value.value ()); +else outstream.write_byte (uint8 (0)); +return end else outstream.write_byte (uint8 (1)); +self.item_serializer_.write (outstream, value); +end end - function res = read(self, instream) - % Returns either yardl.None or the inner optional value - has_value = instream.read_byte(); - if has_value == 0 - res = yardl.None; - else - res = self.item_serializer_.read(instream); - end - end + function res + = read (self, instream) % Returns either yardl.None + or the inner optional value has_value + = instream.read_byte (); +if has_value + == 0 res = yardl.None; +else + res = self.item_serializer_.read (instream); +end end - function c = get_class(~) - c = "yardl.Optional"; - end - end -end + function c + = get_class (~) c = "yardl.Optional"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/RecordSerializer.m b/matlab/toolbox/+yardl/+binary/RecordSerializer.m index d6a2fb5..92b3b9e 100644 --- a/matlab/toolbox/+yardl/+binary/RecordSerializer.m +++ b/matlab/toolbox/+yardl/+binary/RecordSerializer.m @@ -1,21 +1,20 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef RecordSerializer < yardl.binary.TypeSerializer + classdef + RecordSerializer < yardl.binary.TypeSerializer - properties - field_serializers - classname - end + properties field_serializers classname end - methods - function self = RecordSerializer(classname, field_serializers) - self.classname = classname; - self.field_serializers = field_serializers; - end + methods function + self = RecordSerializer (classname, + field_serializers) self + .classname = classname; +self.field_serializers = field_serializers; +end - function c = get_class(self) - c = self.classname; + function c + = get_class (self) c = self.classname; end end @@ -23,17 +22,15 @@ function write_(self, outstream, varargin) for i = 1:nargin-2 fs = self.field_serializers{i}; - field_value = varargin{i}; - fs.write(outstream, field_value); - end - end + field_value = varargin{ i }; + fs.write (outstream, field_value); + end end - function res = read_(self, instream) - res = cell(size(self.field_serializers)); - for i = 1:length(self.field_serializers) - fs = self.field_serializers{i}; - res{i} = fs.read(instream); - end - end - end -end + function res + = read_ (self, instream) res + = cell (size (self.field_serializers)); + for + i = 1 : length (self.field_serializers) fs + = self.field_serializers{ i }; + res{ i } = fs.read (instream); + end end end end diff --git a/matlab/toolbox/+yardl/+binary/SizeSerializer.m b/matlab/toolbox/+yardl/+binary/SizeSerializer.m index a613e23..d08950b 100644 --- a/matlab/toolbox/+yardl/+binary/SizeSerializer.m +++ b/matlab/toolbox/+yardl/+binary/SizeSerializer.m @@ -1,5 +1,4 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef SizeSerializer < yardl.binary.Uint64Serializer -end + classdef SizeSerializer < yardl.binary.Uint64Serializer end diff --git a/matlab/toolbox/+yardl/+binary/StreamSerializer.m b/matlab/toolbox/+yardl/+binary/StreamSerializer.m index 233bf2b..0f435ff 100644 --- a/matlab/toolbox/+yardl/+binary/StreamSerializer.m +++ b/matlab/toolbox/+yardl/+binary/StreamSerializer.m @@ -1,79 +1,69 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef StreamSerializer < yardl.binary.TypeSerializer - properties - item_serializer_; - items_remaining_; - end + classdef StreamSerializer < yardl.binary.TypeSerializer properties + item_serializer_; +items_remaining_; +end - methods - function self = StreamSerializer(item_serializer) - self.item_serializer_ = item_serializer; - self.items_remaining_ = 0; - end + methods function self + = StreamSerializer (item_serializer) self.item_serializer_ + = item_serializer; +self.items_remaining_ = 0; +end - function write(self, outstream, values) - if isempty(values) - return; - end + function write (self, outstream, values) if isempty (values) return; +end - if iscolumn(values) - values = transpose(values); - end - s = size(values); - count = s(end); - outstream.write_unsigned_varint(count); + if iscolumn (values) values + = transpose (values); +end s = size (values); +count = s (end); +outstream.write_unsigned_varint (count); - if iscell(values) - if ~isvector(s) - throw(yardl.ValueError("cell array must be a vector")); +if iscell (values) + if + ~isvector (s) throw (yardl.ValueError ("cell array must be a vector")); end for i = 1:count self.item_serializer_.write(outstream, values{i}); - end - else - if ndims(values) > 2 - r = reshape(values, [], count); - inner_shape = s(1:end-1); - for i = 1:count - val = reshape(r(:, i), inner_shape); - self.item_serializer_.write(outstream, val); + end else if ndims (values) > 2 r = reshape (values, [], count); + inner_shape = s (1 : end - 1); + for + i = 1 : count val = reshape (r ( :, i), inner_shape); + self.item_serializer_.write (outstream, val); end else for i = 1:count self.item_serializer_.write(outstream, transpose(values(:, i))); - end - end - end - end + end end end end - function res = hasnext(self, instream) - if self.items_remaining_ <= 0 - self.items_remaining_ = instream.read_unsigned_varint(); - if self.items_remaining_ <= 0 - res = false; + function res + = hasnext (self, instream) if self.items_remaining_ + <= 0 self.items_remaining_ + = instream.read_unsigned_varint (); + if self + .items_remaining_ <= 0 res = false; return; - end - end - res = true; - end + end end res = true; + end - function res = read(self, instream) - if self.items_remaining_ <= 0 - throw(yardl.RuntimeError("Stream has been exhausted")); - end + function res + = read (self, instream) if self.items_remaining_ + <= 0 throw (yardl.RuntimeError ( + "Stream has been exhausted")); + end - res = self.item_serializer_.read(instream); - self.items_remaining_ = self.items_remaining_ - 1; - end + res + = self.item_serializer_.read (instream); + self.items_remaining_ = self.items_remaining_ - 1; + end - function c = get_class(self) - c = self.item_serializer_.get_class(); - end + function c + = get_class (self) c + = self.item_serializer_.get_class (); + end - function s = get_shape(~) - s = []; - end - end -end + function s + = get_shape (~) s = []; + end end end diff --git a/matlab/toolbox/+yardl/+binary/StringSerializer.m b/matlab/toolbox/+yardl/+binary/StringSerializer.m index d96ff6c..f5e033d 100644 --- a/matlab/toolbox/+yardl/+binary/StringSerializer.m +++ b/matlab/toolbox/+yardl/+binary/StringSerializer.m @@ -1,26 +1,23 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef StringSerializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeTextScalar} - end - bytes = unicode2native(value, "utf-8"); - outstream.write_unsigned_varint(length(bytes)); - outstream.write_bytes(bytes); - end - - function res = read(instream) - len = instream.read_unsigned_varint(); - bytes = instream.read_bytes(len); - res = convertCharsToStrings(native2unicode(bytes, "utf-8")); - end + classdef StringSerializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary.CodedOutputStream + value (1, 1){ mustBeTextScalar } end bytes = unicode2native (value, + "utf-8"); +outstream.write_unsigned_varint (length (bytes)); +outstream.write_bytes (bytes); +end - function c = get_class() - c = "string"; - end - end + function res + = read (instream) len = instream.read_unsigned_varint (); +bytes = instream.read_bytes (len); +res = convertCharsToStrings (native2unicode (bytes, "utf-8")); end + + function c + = get_class () c = "string"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/TimeSerializer.m b/matlab/toolbox/+yardl/+binary/TimeSerializer.m index e612d9f..8f57db5 100644 --- a/matlab/toolbox/+yardl/+binary/TimeSerializer.m +++ b/matlab/toolbox/+yardl/+binary/TimeSerializer.m @@ -1,27 +1,23 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef TimeSerializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - if isa(value, "datetime") - value = yardl.Time.from_datetime(value).value; - elseif isa(value, "yardl.Time") - value = value.value; - else - throw(yardl.TypeError("Expected datetime or yardl.Time, got %s", class(value))); - end - - outstream.write_signed_varint(value); - end + classdef TimeSerializer < yardl.binary.TypeSerializer + methods (Static) +function write (outstream, value) if isa ( + value, "datetime") value = yardl.Time.from_datetime (value).value; +elseif isa (value, "yardl.Time") value = value.value; +else throw ( + yardl.TypeError ("Expected datetime or yardl.Time, got %s", class(value))); +end - function res = read(instream) - value = instream.read_signed_varint(); - res = yardl.Time(value); - end + outstream.write_signed_varint (value); +end - function c = get_class() - c = "yardl.Time"; - end - end + function res + = read (instream) value = instream.read_signed_varint (); +res = yardl.Time (value); end + + function c + = get_class () c = "yardl.Time"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/TypeSerializer.m b/matlab/toolbox/+yardl/+binary/TypeSerializer.m index 0cbb6f1..dc5cad0 100644 --- a/matlab/toolbox/+yardl/+binary/TypeSerializer.m +++ b/matlab/toolbox/+yardl/+binary/TypeSerializer.m @@ -1,36 +1,27 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef TypeSerializer < handle - methods (Static, Abstract) - write(self, stream, value) - res = read(self, stream) - c = get_class(self) - end + classdef TypeSerializer < handle methods (Static, Abstract) + write (self, stream, + value) res = read (self, stream) c = get_class (self) end methods (Static) - function s = get_shape() - s = 1; - end - - function trivial = is_trivially_serializable() - trivial = false; - end - end +function s = get_shape () s = 1; +end - methods - function write_trivially(self, stream, values) - if ~self.is_trivially_serializable() - throw(yardl.TypeError("Not implemented for non-trivially-serializable types")); - end - stream.write_values_directly(values, self.get_class()); - end + function trivial + = is_trivially_serializable () trivial = false; +end end - function res = read_trivially(self, stream, shape) - if ~self.is_trivially_serializable() - throw(yardl.TypeError("Not implemented for non-trivially-serializable types")); - end - res = stream.read_values_directly(shape, self.get_class()); - end - end + methods function write_trivially (self, stream, values) if ~self + .is_trivially_serializable () throw (yardl.TypeError ( + "Not implemented for non-trivially-serializable types")); +end stream.write_values_directly (values, self.get_class ()); end + + function res + = read_trivially (self, stream, shape) if ~self + .is_trivially_serializable () throw (yardl.TypeError ( + "Not implemented for non-trivially-serializable types")); +end res = stream.read_values_directly (shape, self.get_class ()); +end end end diff --git a/matlab/toolbox/+yardl/+binary/Uint16Serializer.m b/matlab/toolbox/+yardl/+binary/Uint16Serializer.m index 5e33f7d..87d512f 100644 --- a/matlab/toolbox/+yardl/+binary/Uint16Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Uint16Serializer.m @@ -1,22 +1,20 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Uint16Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeInRange(value, 0, 65535)} - end - outstream.write_unsigned_varint(value); - end - - function res = read(instream) - res = uint16(instream.read_unsigned_varint()); - end + classdef Uint16Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary + .CodedOutputStream value (1, 1){ + mustBeInRange (value, 0, 65535) + } end outstream.write_unsigned_varint (value); +end - function c = get_class() - c = "uint16"; - end - end + function res + = read (instream) res = uint16 (instream.read_unsigned_varint ()); end + + function c + = get_class () c = "uint16"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/Uint32Serializer.m b/matlab/toolbox/+yardl/+binary/Uint32Serializer.m index 5bf4c54..29a8d22 100644 --- a/matlab/toolbox/+yardl/+binary/Uint32Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Uint32Serializer.m @@ -1,22 +1,20 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Uint32Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeInRange(value, 0, 4294967295)} - end - outstream.write_unsigned_varint(value); - end - - function res = read(instream) - res = uint32(instream.read_unsigned_varint()); - end + classdef Uint32Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary + .CodedOutputStream value (1, 1){ + mustBeInRange (value, 0, 4294967295) + } end outstream.write_unsigned_varint (value); +end - function c = get_class() - c = "uint32"; - end - end + function res + = read (instream) res = uint32 (instream.read_unsigned_varint ()); end + + function c + = get_class () c = "uint32"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/Uint64Serializer.m b/matlab/toolbox/+yardl/+binary/Uint64Serializer.m index 3d51f62..5812dd6 100644 --- a/matlab/toolbox/+yardl/+binary/Uint64Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Uint64Serializer.m @@ -1,22 +1,20 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Uint64Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeInRange(value, 0, 18446744073709551615)} - end - outstream.write_unsigned_varint(value); - end - - function res = read(instream) - res = uint64(instream.read_unsigned_varint()); - end + classdef Uint64Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary + .CodedOutputStream value (1, 1){ + mustBeInRange (value, 0, 18446744073709551615) + } end outstream.write_unsigned_varint (value); +end - function c = get_class() - c = "uint64"; - end - end + function res + = read (instream) res = uint64 (instream.read_unsigned_varint ()); end + + function c + = get_class () c = "uint64"; +end end end diff --git a/matlab/toolbox/+yardl/+binary/Uint8Serializer.m b/matlab/toolbox/+yardl/+binary/Uint8Serializer.m index 28c873b..71965c8 100644 --- a/matlab/toolbox/+yardl/+binary/Uint8Serializer.m +++ b/matlab/toolbox/+yardl/+binary/Uint8Serializer.m @@ -1,26 +1,24 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Uint8Serializer < yardl.binary.TypeSerializer - methods (Static) - function write(outstream, value) - arguments - outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) {mustBeInRange(value, 0, 255)} - end - outstream.write_byte(uint8(value)); - end - - function res = read(instream) - res = instream.read_byte(); - end + classdef Uint8Serializer < yardl.binary.TypeSerializer + methods (Static) +function +write (outstream, value) +arguments outstream (1, 1) yardl.binary + .CodedOutputStream value (1, 1){ + mustBeInRange (value, 0, 255) + } end outstream.write_byte (uint8 (value)); +end - function c = get_class() - c = "uint8"; - end + function res + = read (instream) res = instream.read_byte (); +end - function trivial = is_trivially_serializable() - trivial = true; - end - end + function c + = get_class () c = "uint8"; end + + function trivial + = is_trivially_serializable () trivial = true; +end end end diff --git a/matlab/toolbox/+yardl/+binary/UnionSerializer.m b/matlab/toolbox/+yardl/+binary/UnionSerializer.m index ba935c9..e4d0773 100644 --- a/matlab/toolbox/+yardl/+binary/UnionSerializer.m +++ b/matlab/toolbox/+yardl/+binary/UnionSerializer.m @@ -1,81 +1,73 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. + + classdef UnionSerializer < handle + + properties (Access = protected) + classname_ case_serializers_ case_factories_ offset_ end + + methods function self = UnionSerializer ( + union_class, case_serializers, + case_factories) self.classname_ = union_class; +self.case_serializers_ = case_serializers; +self.case_factories_ = case_factories; + +if isa (case_serializers{ 1 }, "yardl.binary.NoneSerializer") + self.offset_ = 1; +else + self.offset_ = 0; +end end + + function + write (self, outstream, value) if isa (value, "yardl." + "Optional") if ~isa ( + self.case_serializers_{ 1 }, + "yardl.binary.NoneSerializer") throw (yardl + .TypeError ( + "Optional is not " + "valid for this " + "union type")) end + + if value.has_value () value = value.value; +else outstream.write_byte (uint8 (0)); +return; +end end + + if ~isa (value, self.classname_) throw ( + yardl.TypeError ("Expected union value of type %s, got %s", + self.classname_, class(value))) end + + tag_index = uint8 (value.index + self.offset_); +outstream.write_byte (tag_index - 1); + +serializer = self.case_serializers_{ tag_index }; +serializer.write (outstream, value.value); +end -classdef UnionSerializer < handle + function res + = read (self, instream) case_index = instream.read_byte () + 1; - properties (Access=protected) - classname_ - case_serializers_ - case_factories_ - offset_ - end +if case_index + == 1 &&self.offset_ == 1 res = yardl.None; +return end - methods - function self = UnionSerializer(union_class, case_serializers, case_factories) - self.classname_ = union_class; - self.case_serializers_ = case_serializers; - self.case_factories_ = case_factories; - - if isa(case_serializers{1}, "yardl.binary.NoneSerializer") - self.offset_ = 1; - else - self.offset_ = 0; - end - end - - function write(self, outstream, value) - if isa(value, "yardl.Optional") - if ~isa(self.case_serializers_{1}, "yardl.binary.NoneSerializer") - throw(yardl.TypeError("Optional is not valid for this union type")) - end - - if value.has_value() - value = value.value; - else - outstream.write_byte(uint8(0)); - return; - end - end - - if ~isa(value, self.classname_) - throw(yardl.TypeError("Expected union value of type %s, got %s", self.classname_, class(value))) - end - - tag_index = uint8(value.index + self.offset_); - outstream.write_byte(tag_index-1); - - serializer = self.case_serializers_{tag_index}; - serializer.write(outstream, value.value); - end - - function res = read(self, instream) - case_index = instream.read_byte() + 1; - - if case_index == 1 && self.offset_ == 1 - res = yardl.None; - return - end - - serializer = self.case_serializers_{case_index}; - value = serializer.read(instream); - - factory = self.case_factories_{case_index}; - res = factory(value); - end - - function c = get_class(self) - if isa(self.case_serializers_{1}, "yardl.binary.NoneSerializer") - c = "yardl.Optional"; - else - c = self.classname_; - end - end + serializer + = self.case_serializers_{ case_index }; +value = serializer.read (instream); + +factory = self.case_factories_{ case_index }; +res = factory (value); +end + + function c + = get_class (self) if isa (self.case_serializers_{ 1 }, + "yardl.binary.NoneSerializer") c + = "yardl.Optional"; +else c = self.classname_; +end end end methods (Static) - function s = get_shape() - s = 1; - end - end -end +function s = get_shape () s = 1; +end end end diff --git a/matlab/toolbox/+yardl/+binary/VectorSerializer.m b/matlab/toolbox/+yardl/+binary/VectorSerializer.m index 04982ef..2830cc6 100644 --- a/matlab/toolbox/+yardl/+binary/VectorSerializer.m +++ b/matlab/toolbox/+yardl/+binary/VectorSerializer.m @@ -1,25 +1,24 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef VectorSerializer < yardl.binary.VectorSerializerBase + classdef VectorSerializer < yardl.binary + .VectorSerializerBase - methods (Access=protected) - function handle_write_count_(~, outstream, count) - outstream.write_unsigned_varint(count); - end - - function count = get_read_count_(~, instream) - count = instream.read_unsigned_varint(); - end - end + methods (Access = protected) function + handle_write_count_ (~, outstream, + count) outstream + .write_unsigned_varint (count); +end - methods - function self = VectorSerializer(item_serializer) - self@yardl.binary.VectorSerializerBase(item_serializer); - end + function count + = get_read_count_ (~, instream) count = instream.read_unsigned_varint (); +end end - function s = get_shape(~) - s = []; - end - end + methods function self + = VectorSerializer (item_serializer) self + @yardl.binary.VectorSerializerBase (item_serializer); end + + function s + = get_shape (~) s = []; +end end end diff --git a/matlab/toolbox/+yardl/+binary/VectorSerializerBase.m b/matlab/toolbox/+yardl/+binary/VectorSerializerBase.m index dbe1694..7976444 100644 --- a/matlab/toolbox/+yardl/+binary/VectorSerializerBase.m +++ b/matlab/toolbox/+yardl/+binary/VectorSerializerBase.m @@ -1,95 +1,84 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef VectorSerializerBase < yardl.binary.TypeSerializer - properties - item_serializer_; - end + classdef VectorSerializerBase < yardl.binary.TypeSerializer + properties item_serializer_; +end - methods (Abstract, Access=protected) - handle_write_count_(self, outstream, values) - get_read_count_(self, instream) - end + methods (Abstract, Access = protected) + handle_write_count_ (self, outstream, values) + get_read_count_ (self, instream) end - methods (Access=protected) - function self = VectorSerializerBase(item_serializer) - self.item_serializer_ = item_serializer; - end - end + methods (Access = protected) function + self = VectorSerializerBase ( + item_serializer) self.item_serializer_ = item_serializer; +end end - methods - function write(self, outstream, values) - if iscolumn(values) - values = transpose(values); - end - s = size(values); - count = s(end); + methods function write (self, outstream, values) if iscolumn ( + values) values = transpose (values); +end s = size (values); +count = s (end); - self.handle_write_count_(outstream, count); +self.handle_write_count_ (outstream, count); - if iscell(values) - % values is a cell array, so must be a vector of shape [1, COUNT] - if ~isvector(s) - throw(yardl.ValueError("cell array must be a vector")); +if iscell (values) + % values is a cell array, + so must be a vector of shape[1, COUNT] if ~isvector (s) throw ( + yardl.ValueError ("cell array must be a vector")); end for i = 1:count self.item_serializer_.write(outstream, values{i}); - end - else - % values is an array, so must have shape [A, B, ..., COUNT] - if self.item_serializer_.is_trivially_serializable() - self.item_serializer_.write_trivially(outstream, values); - return - end + end else % values is an array, + so must have shape[A, B, ..., COUNT] if self + .item_serializer_.is_trivially_serializable () self + .item_serializer_.write_trivially (outstream, values); + return end - if ndims(values) > 2 - r = reshape(values, [], count); - for i = 1:count - val = reshape(r(:, i), s(1:end-1)); - self.item_serializer_.write(outstream, val); + if ndims (values) + > 2 r + = reshape (values, [], count); + for + i = 1 : count val = reshape (r ( :, i), s (1 : end - 1)); + self.item_serializer_.write (outstream, val); end else for i = 1:count self.item_serializer_.write(outstream, transpose(values(:, i))); - end - end - end - end + end end end end - function res = read(self, instream) - count = self.get_read_count_(instream); - if count == 0 - res = yardl.allocate(self.get_class(), 0); - return; - end + function res + = read (self, instream) count + = self.get_read_count_ (instream); + if count + == 0 res = yardl.allocate (self.get_class (), 0); + return; + end - item_shape = self.item_serializer_.get_shape(); - if isempty(item_shape) - res = cell(1, count); - for i = 1:count - res{i} = self.item_serializer_.read(instream); - end - return - end + item_shape + = self.item_serializer_.get_shape (); + if isempty (item_shape) + res = cell (1, count); + for + i = 1 : count res{ i } + = self.item_serializer_.read (instream); + end return end - if self.item_serializer_.is_trivially_serializable() - res = self.item_serializer_.read_trivially(instream, [prod(item_shape), count]); - else - res = yardl.allocate(self.get_class(), [prod(item_shape), count]); - for i = 1:count - item = self.item_serializer_.read(instream); - res(:, i) = item(:); - end - end + if self.item_serializer_.is_trivially_serializable () res + = self.item_serializer_.read_trivially ( + instream, [ prod (item_shape), count ]); + else res = yardl.allocate (self.get_class (), + [ prod (item_shape), count ]); + for + i = 1 : count item = self.item_serializer_.read (instream); + res ( :, i) = item ( :); + end end - res = squeeze(reshape(res, [item_shape, count])); - if iscolumn(res) - res = transpose(res); - end - end + res + = squeeze (reshape (res, [ item_shape, count ])); + if iscolumn (res) + res = transpose (res); + end end - function c = get_class(self) - c = self.item_serializer_.get_class(); - end - end -end + function c + = get_class (self) c = self.item_serializer_.get_class (); + end end end diff --git a/matlab/toolbox/+yardl/Date.m b/matlab/toolbox/+yardl/Date.m index cbae0f5..35e172f 100644 --- a/matlab/toolbox/+yardl/Date.m +++ b/matlab/toolbox/+yardl/Date.m @@ -1,70 +1,66 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License + . -classdef Date < handle + classdef Date 0 self + .days_since_epoch = days_since_epoch; +else self.days_since_epoch = 0; +end end - methods - function self = Date(days_since_epoch) - if nargin > 0 - self.days_since_epoch = days_since_epoch; - else - self.days_since_epoch = 0; - end - end + function value + = value (self) value = self.days_since_epoch; +end - function value = value(self) - value = self.days_since_epoch; - end + function dt + = to_datetime (self) dt + = datetime (0, 'ConvertFrom', 'epochtime') + days (self.days_since_epoch); +end - function dt = to_datetime(self) - dt = datetime(0, 'ConvertFrom', 'epochtime') + days(self.days_since_epoch); - end + function eq + = eq (self, other) if isa (other, 'datetime') other + = yardl.Date.from_datetime (other); +end - function eq = eq(self, other) - if isa(other, 'datetime') - other = yardl.Date.from_datetime(other); - end + eq + = isa (other, 'yardl.Date') + && ...all ([self.days_since_epoch] == [other.days_since_epoch]); +end - eq = isa(other, 'yardl.Date') && ... - all([self.days_since_epoch] == [other.days_since_epoch]); - end + function ne + = ne (self, other) ne = ~self.eq (other); +end - function ne = ne(self, other) - ne = ~self.eq(other); - end + function isequal + = isequal (self, other) isequal = all (eq (self, other)); +end end - function isequal = isequal(self, other) - isequal = all(eq(self, other)); - end - end +methods (Static) +function d = from_datetime (value) dur + = value - datetime (0, 'ConvertFrom', 'epochtime'); +d = yardl.Date (days (dur)); +end - methods (Static) - function d = from_datetime(value) - dur = value - datetime(0, 'ConvertFrom', 'epochtime'); - d = yardl.Date(days(dur)); - end + function d + = from_components (y, m, d) d + = yardl.Date.from_datetime (datetime (y, m, d)); +end - function d = from_components(y, m, d) - d = yardl.Date.from_datetime(datetime(y, m, d)); - end + function z + = zeros (varargin) elem = yardl.Date (0); +if nargin + == 0 z = elem; +return end - function z = zeros(varargin) - elem = yardl.Date(0); - if nargin == 0 - z = elem; - return - end + sz + = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end end - -end diff --git a/matlab/toolbox/+yardl/DateTime.m b/matlab/toolbox/+yardl/DateTime.m index af710ec..e90fa65 100644 --- a/matlab/toolbox/+yardl/DateTime.m +++ b/matlab/toolbox/+yardl/DateTime.m @@ -1,81 +1,84 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License + . -classdef DateTime < handle - % A basic datetime with nanosecond precision, always in UTC. + classdef + DateTime 0 - self.nanoseconds_since_epoch = nanoseconds_since_epoch; - else - self.nanoseconds_since_epoch = 0; - end - end + methods function self + = DateTime (nanoseconds_since_epoch) if nargin> 0 self + .nanoseconds_since_epoch = nanoseconds_since_epoch; +else self.nanoseconds_since_epoch = 0; +end end - function value = value(self) - value = self.nanoseconds_since_epoch; - end + function value + = value (self) value = self.nanoseconds_since_epoch; +end - function dt = to_datetime(self) - dt = datetime(self.nanoseconds_since_epoch, 'ConvertFrom', 'epochtime', 'TicksPerSecond', 1e9); - end + function dt + = to_datetime (self) dt + = datetime (self.nanoseconds_since_epoch, 'ConvertFrom', 'epochtime', + 'TicksPerSecond', 1e9); +end - function eq = eq(self, other) - if isa(other, 'datetime') - other = yardl.DateTime.from_datetime(other); - end + function eq + = eq (self, other) if isa (other, 'datetime') other + = yardl.DateTime.from_datetime (other); +end - eq = isa(other, 'yardl.DateTime') && ... - all([self.nanoseconds_since_epoch] == [other.nanoseconds_since_epoch]); - end + eq + = isa (other, 'yardl.DateTime') + && ...all ([self.nanoseconds_since_epoch] == + [other.nanoseconds_since_epoch]); +end - function ne = ne(self, other) - ne = ~self.eq(other); - end + function ne + = ne (self, other) ne = ~self.eq (other); +end - function isequal = isequal(self, other) - isequal = all(eq(self, other)); - end - end + function isequal + = isequal (self, other) isequal = all (eq (self, other)); +end end - methods (Static) - function dt = from_datetime(value) - value.TimeZone = 'UTC'; - nanoseconds_since_epoch = convertTo(value, 'epochtime', 'TicksPerSecond', 1e9); - dt = yardl.DateTime(nanoseconds_since_epoch); - end +methods (Static) +function dt = from_datetime (value) value.TimeZone = 'UTC'; +nanoseconds_since_epoch + = convertTo (value, 'epochtime', 'TicksPerSecond', 1e9); +dt = yardl.DateTime (nanoseconds_since_epoch); +end + + function dt + = from_components ( + year, month, day, hour, minute, second, + nanosecond) if ~(nanosecond >= 0 + && nanosecond + < 999999999) throw (yardl + .ValueError ( + "nanosecond must " + "be in 0..1e9")); +end mdt = datetime (year, month, day, hour, minute, second, 'TimeZone', 'UTC'); +seconds_since_epoch = convertTo (mdt, 'epochtime'); +dt = yardl.DateTime (seconds_since_epoch * 1e9 + nanosecond); +end - function dt = from_components(year, month, day, hour, minute, second, nanosecond) - if ~(nanosecond >= 0 && nanosecond < 999999999) - throw(yardl.ValueError("nanosecond must be in 0..1e9")); - end - mdt = datetime(year, month, day, hour, minute, second, 'TimeZone', 'UTC'); - seconds_since_epoch = convertTo(mdt, 'epochtime'); - dt = yardl.DateTime(seconds_since_epoch * 1e9 + nanosecond); - end + function dt + = now (~) dt = yardl.DateTime.from_datetime (datetime ('now')); +end - function dt = now(~) - dt = yardl.DateTime.from_datetime(datetime('now')); - end + function z + = zeros (varargin) elem = yardl.DateTime (0); +if nargin + == 0 z = elem; +return end - function z = zeros(varargin) - elem = yardl.DateTime(0); - if nargin == 0 - z = elem; - return - end + sz + = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end end - -end diff --git a/matlab/toolbox/+yardl/Exception.m b/matlab/toolbox/+yardl/Exception.m index 131fd04..00e17ff 100644 --- a/matlab/toolbox/+yardl/Exception.m +++ b/matlab/toolbox/+yardl/Exception.m @@ -1,6 +1,6 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function err = Exception(id, varargin) - err = MException(id, varargin{:}); + function err = Exception (id, varargin) err = MException (id, + varargin{ : }); end diff --git a/matlab/toolbox/+yardl/Map.m b/matlab/toolbox/+yardl/Map.m index 5b446cc..772ff6f 100644 --- a/matlab/toolbox/+yardl/Map.m +++ b/matlab/toolbox/+yardl/Map.m @@ -1,73 +1,60 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Map < handle - properties (SetAccess=protected) - dict - end + classdef Map < handle properties (SetAccess = protected) dict end methods - function self = Map(varargin) - self.dict = dictionary(varargin{:}); - end - - function k = keys(self) - k = keys(self.dict); - end - - function v = values(self) - v = values(self.dict); - end - - function l = lookup(self, varargin) - l = lookup(self.dict, varargin{:}); - end + function self = Map (varargin) self.dict = dictionary (varargin{ : }); +end - function insert(self, varargin) - self.dict = insert(self.dict, varargin{:}); - end + function k + = keys (self) k = keys (self.dict); +end - function remove(self, varargin) - self.dict = remove(self.dict, varargin{:}); - end + function v + = values (self) v = values (self.dict); +end - function n = numEntries(self) - n = numEntries(self.dict); - end + function l + = lookup (self, varargin) l = lookup (self.dict, varargin{ : }); +end - function res = eq(a, b) - if isa(b, 'yardl.Map') - res = isequal({a.dict}, {b.dict}); - elseif isa(b, 'dictionary') - res = isequal({a.dict}, {b}); - else - res = false; - end - end + function insert (self, varargin) self.dict = insert (self.dict, + varargin{ : }); +end - function ne = ne(a, b) - ne = ~eq(a, b); - end + function remove (self, varargin) self.dict = remove (self.dict, + varargin{ : }); +end - function isequal = isequal(self, other) - isequal = all(eq(self, other)); - end - end + function n + = numEntries (self) n = numEntries (self.dict); +end - methods (Static) - function z = zeros(varargin) - elem = yardl.Map(); - if nargin == 0 - z = elem; - return - end + function res + = eq (a, b) if isa (b, 'yardl.Map') res = isequal ({ a.dict }, { b.dict }); +elseif isa (b, 'dictionary') res = isequal ({ a.dict }, { b }); +else res = false; +end end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end + function ne + = ne (a, b) ne = ~eq (a, b); end + + function isequal + = isequal (self, other) isequal = all (eq (self, other)); +end end + +methods (Static) +function z = zeros (varargin) elem = yardl.Map (); +if nargin + == 0 z = elem; +return end + + sz + = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+yardl/None.m b/matlab/toolbox/+yardl/None.m index 728123d..ca1b072 100644 --- a/matlab/toolbox/+yardl/None.m +++ b/matlab/toolbox/+yardl/None.m @@ -1,6 +1,5 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function n = None() - n = yardl.Optional(); + function n = None () n = yardl.Optional (); end diff --git a/matlab/toolbox/+yardl/Optional.m b/matlab/toolbox/+yardl/Optional.m index 574bd79..ba73765 100644 --- a/matlab/toolbox/+yardl/Optional.m +++ b/matlab/toolbox/+yardl/Optional.m @@ -1,83 +1,58 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License + . -classdef Optional < handle - properties (SetAccess=protected) - has_value - end + classdef Optional 0 - self.value_ = varargin{1}; - self.has_value = true; - else - self.has_value = false; - end - end + methods function self + = Optional (varargin) if nargin> 0 self + .value_ = varargin{ 1 }; +self.has_value = true; +else self.has_value = false; +end end - function v = value(self) - if ~self.has_value - throw(yardl.ValueError("Optional type does not have a value")); - end - v = self.value_; - end - - function eq = eq(a, b) - if isa(a, 'yardl.Optional') - if isa(b, 'yardl.Optional') - if all([a.has_value]) && all([b.has_value]) - eq = isequal([a.value_], [b.value_]); - else - eq = [a.has_value] == [b.has_value]; - end - else - if all([a.has_value]) - eq = isequal(b, [a.value_]); - else - eq = false; - end - end - else - % b is the Optional - if all([b.has_value]) - eq = isequal(a, [b.value_]); - else - eq = false; - end - end - end - - function ne = ne(a, b) - ne = ~eq(a, b); - end - - function isequal = isequal(a, varargin) - isequal = all(eq(a, [varargin{:}])); - end - - function isequaln = isequaln(a, varargin) - isequaln = isequal(a, [varargin{:}]); - end - end + function v + = value (self) if ~self.has_value throw ( + yardl.ValueError ("Optional type does not have a value")); +end v = self.value_; +end - methods (Static) - function z = zeros(varargin) - elem = yardl.None; - if nargin == 0 - z = elem; - return - end + function eq + = eq (a, b) if isa (a, 'yardl.Optional') if isa ( + b, 'yardl.Optional') if all ([a.has_value]) + && all ([b.has_value]) eq + = isequal ([a.value_], [b.value_]); +else eq = [a.has_value] == [b.has_value]; +end else if all ([a.has_value]) eq = isequal (b, [a.value_]); +else eq = false; +end end else % b is the Optional if all ([b.has_value]) eq + = isequal (a, [b.value_]); +else eq = false; +end end end + + function ne + = ne (a, b) ne = ~eq (a, b); +end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end - end + function isequal + = isequal (a, varargin) isequal = all (eq (a, [varargin{ : }])); end + + function isequaln + = isequaln (a, varargin) isequaln = isequal (a, [varargin{ : }]); +end end + +methods (Static) +function z = zeros (varargin) elem = yardl.None; +if nargin + == 0 z = elem; +return end + + sz + = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end end diff --git a/matlab/toolbox/+yardl/ProtocolError.m b/matlab/toolbox/+yardl/ProtocolError.m index eac33ad..ea5f7ae 100644 --- a/matlab/toolbox/+yardl/ProtocolError.m +++ b/matlab/toolbox/+yardl/ProtocolError.m @@ -1,6 +1,6 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function err = ProtocolError(varargin) - err = yardl.Exception("yardl:ProtocolError", varargin{:}); + function err = ProtocolError (varargin) err = yardl.Exception ( + "yardl:ProtocolError", varargin{ : }); end diff --git a/matlab/toolbox/+yardl/RuntimeError.m b/matlab/toolbox/+yardl/RuntimeError.m index d2a2d61..64f1eb1 100644 --- a/matlab/toolbox/+yardl/RuntimeError.m +++ b/matlab/toolbox/+yardl/RuntimeError.m @@ -1,6 +1,6 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function err = RuntimeError(varargin) - err = yardl.Exception("yardl:RuntimeError", varargin{:}); + function err = RuntimeError (varargin) err = yardl.Exception ( + "yardl:RuntimeError", varargin{ : }); end diff --git a/matlab/toolbox/+yardl/Time.m b/matlab/toolbox/+yardl/Time.m index 533d5de..26a5bea 100644 --- a/matlab/toolbox/+yardl/Time.m +++ b/matlab/toolbox/+yardl/Time.m @@ -1,90 +1,95 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Time < handle - % A basic time of day with nanosecond precision. It is not timezone-aware and is - % meant to represent a wall clock time. + classdef Time< + handle + % A basic time of day with nanosecond + precision.It is not timezone + - aware + and is + % meant to represent a wall clock time. - properties (SetAccess=private) - nanoseconds_since_midnight - end + properties (SetAccess = private) + nanoseconds_since_midnight end - methods - function self = Time(nanoseconds_since_midnight) - if nargin > 0 - if nanoseconds_since_midnight < 0 || nanoseconds_since_midnight >= 24*60*60*1e9 - throw(yardl.ValuError("Time must be between 00:00:00 and 23:59:59.999999999")); - end - self.nanoseconds_since_midnight = nanoseconds_since_midnight; - else - self.nanoseconds_since_midnight = 0; - end - end + methods function self + = Time ( + nanoseconds_since_midnight) if nargin> 0 if nanoseconds_since_midnight < 0 + || nanoseconds_since_midnight + >= 24 * 60 * 60 + * 1e9 throw (yardl.ValuError ( + "Time must be between 00:00:00 and 23:59:59.999999999")); +end self.nanoseconds_since_midnight = nanoseconds_since_midnight; +else self.nanoseconds_since_midnight = 0; +end end - function value = value(self) - value = self.nanoseconds_since_midnight; - end + function value + = value (self) value = self.nanoseconds_since_midnight; +end - function dt = to_datetime(self) - dt = datetime(self.nanoseconds_since_midnight, 'ConvertFrom', 'epochtime', 'Epoch', datetime('today'), 'TicksPerSecond', 1e9); - end + function dt + = to_datetime (self) dt + = datetime (self.nanoseconds_since_midnight, 'ConvertFrom', 'epochtime', + 'Epoch', datetime ('today'), 'TicksPerSecond', 1e9); +end - function eq = eq(self, other) - if isa(other, 'datetime') - other = yardl.Time.from_datetime(other); - end + function eq + = eq (self, other) if isa (other, 'datetime') other + = yardl.Time.from_datetime (other); +end - eq = isa(other, 'yardl.Time') && ... - all([self.nanoseconds_since_midnight] == [other.nanoseconds_since_midnight]); - end + eq + = isa (other, 'yardl.Time') + && ...all ([self.nanoseconds_since_midnight] == + [other.nanoseconds_since_midnight]); +end - function ne = ne(self, other) - ne = ~self.eq(other); - end + function ne + = ne (self, other) ne = ~self.eq (other); +end - function isequal = isequal(self, other) - isequal = all(eq(self, other)); - end - end + function isequal + = isequal (self, other) isequal = all (eq (self, other)); +end end - methods (Static) - function t = from_datetime(value) - nanoseconds_since_midnight = convertTo(value, 'epochtime', ... - 'Epoch', datetime(value.Year, value.Month, value.Day, 'TimeZone', value.TimeZone), ... - 'TicksPerSecond', 1e9); - t = yardl.Time(nanoseconds_since_midnight); - end +methods (Static) +function t = from_datetime (value) nanoseconds_since_midnight = convertTo ( + value, 'epochtime', ... 'Epoch', + datetime (value.Year, value.Month, value.Day, 'TimeZone', value.TimeZone), + ... 'TicksPerSecond', 1e9); +t = yardl.Time (nanoseconds_since_midnight); +end + + function t + = from_components (hour, minute, second, nanosecond) if ~( + hour >= 0 + && hour <= 23) throw (yardl + .ValueError ( + "hour must be between 0 and 23")); +end if ~(minute >= 0 && minute <= 59) throw ( + yardl.ValueError ("minute must be between 0 and 59")); +end if ~(second >= 0 && second <= 59) throw ( + yardl.ValueError ("second must be between 0 and 59")); +end if ~(nanosecond >= 0 && nanosecond <= 999999999) throw ( + yardl.ValueError ("nanosecond must be between 0 and 999999999")); +end - function t = from_components(hour, minute, second, nanosecond) - if ~(hour >= 0 && hour <= 23) - throw(yardl.ValueError("hour must be between 0 and 23")); - end - if ~(minute >= 0 && minute <= 59) - throw(yardl.ValueError("minute must be between 0 and 59")); - end - if ~(second >= 0 && second <= 59) - throw(yardl.ValueError("second must be between 0 and 59")); - end - if ~(nanosecond >= 0 && nanosecond <= 999999999) - throw(yardl.ValueError("nanosecond must be between 0 and 999999999")); - end + t + = yardl.Time (hour * 60 * 60 * 1e9 + minute * 60 * 1e9 + second * 1e9 + + nanosecond); +end - t = yardl.Time(hour * 60*60*1e9 + minute * 60*1e9 + second * 1e9 + nanosecond); - end + function z + = zeros (varargin) elem = yardl.Time (0); +if nargin + == 0 z = elem; +return end - function z = zeros(varargin) - elem = yardl.Time(0); - if nargin == 0 - z = elem; - return - end + sz + = [varargin{ : }]; +if isscalar (sz) + sz = [ sz, sz ]; +end z = reshape (repelem (elem, prod (sz)), sz); +end end - sz = [varargin{:}]; - if isscalar(sz) - sz = [sz, sz]; - end - z = reshape(repelem(elem, prod(sz)), sz); - end end - -end diff --git a/matlab/toolbox/+yardl/TypeError.m b/matlab/toolbox/+yardl/TypeError.m index d37b4d6..c0d2cc5 100644 --- a/matlab/toolbox/+yardl/TypeError.m +++ b/matlab/toolbox/+yardl/TypeError.m @@ -1,6 +1,6 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function err = TypeError(varargin) - err = yardl.Exception("yardl:TypeError", varargin{:}); + function err = TypeError (varargin) err = yardl.Exception ( + "yardl:TypeError", varargin{ : }); end diff --git a/matlab/toolbox/+yardl/Union.m b/matlab/toolbox/+yardl/Union.m index 7079c97..444766a 100644 --- a/matlab/toolbox/+yardl/Union.m +++ b/matlab/toolbox/+yardl/Union.m @@ -1,41 +1,28 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -classdef Union < handle & matlab.mixin.CustomDisplay - properties (Access=protected) - index_ - end + classdef Union < handle &matlab.mixin.CustomDisplay + properties (Access = protected) index_ end - properties (SetAccess=protected) - value - end + properties (SetAccess = protected) value end - methods - function self = Union(index, value) - self.index_ = index; - self.value = value; - end + methods function self = Union (index, value) self + .index_ = index; +self.value = value; +end - function i = index(self) - i = self.index_; - end + function i + = index (self) i = self.index_; +end - function isequal = isequal(self, other) - isequal = all(eq(self, other)); - end - end + function isequal + = isequal (self, other) isequal = all (eq (self, other)); +end end - methods (Abstract) - t = tag(self) - end + methods (Abstract) t = tag (self) end - methods (Access=protected) - function displayScalarObject(obj) - className = matlab.mixin.CustomDisplay.getClassNameForHeader(obj); - header = sprintf('%s.%s\n', className, obj.tag()); - disp(header) - propgroup = getPropertyGroups(obj); - matlab.mixin.CustomDisplay.displayPropertyGroups(obj,propgroup) - end - end -end + methods (Access = protected) function displayScalarObject (obj) + className = matlab.mixin.CustomDisplay.getClassNameForHeader (obj); +header = sprintf ('%s.%s\n', className, obj.tag ()); +disp (header) propgroup = getPropertyGroups (obj); +matlab.mixin.CustomDisplay.displayPropertyGroups (obj, propgroup) end end end diff --git a/matlab/toolbox/+yardl/ValueError.m b/matlab/toolbox/+yardl/ValueError.m index 3c0bd3f..c0b2080 100644 --- a/matlab/toolbox/+yardl/ValueError.m +++ b/matlab/toolbox/+yardl/ValueError.m @@ -1,6 +1,6 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function err = ValueError(varargin) - err = yardl.Exception("yardl:ValueError", varargin{:}); + function err = ValueError (varargin) err = yardl.Exception ( + "yardl:ValueError", varargin{ : }); end diff --git a/matlab/toolbox/+yardl/allocate.m b/matlab/toolbox/+yardl/allocate.m index f99f87f..e6f917b 100644 --- a/matlab/toolbox/+yardl/allocate.m +++ b/matlab/toolbox/+yardl/allocate.m @@ -1,11 +1,8 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function res = allocate(classname, varargin) - % Wrapper around zeros, used to preallocate arrays of yardl objects - if classname == "string" - res = strings(varargin{:}); - else - res = zeros(varargin{:}, classname); - end -end + function res = allocate (classname, varargin) % Wrapper around zeros, + used to preallocate arrays of yardl objects if classname + == "string" res = strings (varargin{ : }); +else res = zeros (varargin{ : }, classname); +end end diff --git a/matlab/toolbox/+yardl/dimension_count.m b/matlab/toolbox/+yardl/dimension_count.m index 2156767..a364c24 100644 --- a/matlab/toolbox/+yardl/dimension_count.m +++ b/matlab/toolbox/+yardl/dimension_count.m @@ -1,9 +1,8 @@ % Copyright (c) Microsoft Corporation. -% Licensed under the MIT License. + % Licensed under the MIT License. -function c = dimension_count(arr) - % Alternative to Matlab's `ndims` function - % Collapses dimensions of size 1 (making it behave like numpy.array.ndim) - s = size(arr); - c = length(s(s > 1)); + function c = dimension_count (arr) % Alternative to Matlab's `ndims` function + % Collapses dimensions of size + 1(making it behave like numpy.array.ndim)s = size (arr); +c = length (s (s > 1)); end diff --git a/matlab/toolbox/petsird_analysis.m b/matlab/toolbox/petsird_analysis.m index 0e9975a..826e4a1 100644 --- a/matlab/toolbox/petsird_analysis.m +++ b/matlab/toolbox/petsird_analysis.m @@ -1,80 +1,103 @@ -function petsird_generator(input) +function +petsird_generator (input) -arguments - input (1,1) string -end +arguments input (1, 1) string end -reader = petsird.binary.PETSIRDReader(input); + reader = petsird.binary.PETSIRDReader (input); -header = reader.read_header(); +header = reader.read_header (); -if header.exam ~= yardl.None - fprintf("Subject ID: %s\n", header.exam.subject.id); +if header + .exam ~ = yardl.None fprintf ("Subject ID: %s\n", header.exam.subject.id); end -fprintf("Scanner name: %s\n", header.scanner.model_name); + fprintf ("Scanner name: %s\n", header.scanner.model_name); -fprintf("Types of modules: %d\n", length(header.scanner.scanner_geometry.replicated_modules)); -fprintf("Number of modules of first type: %d\n", ... - length(header.scanner.scanner_geometry.replicated_modules(1).transforms)); -fprintf("Number of types of detecting elements in modules of first type: %d\n", ... - length(header.scanner.scanner_geometry.replicated_modules(1).object.detecting_elements)); -fprintf("Number of elements of first type in modules of first type: %d\n", ... - length(header.scanner.scanner_geometry.replicated_modules(1).object.detecting_elements(1).transforms)); -fprintf("Total number of 'crystals': %d\n", ... - petsird.helpers.get_num_detecting_elements(header.scanner.scanner_geometry)); -fprintf("Number of TOF bins: %d\n", header.scanner.number_of_tof_bins()); -fprintf("Number of energy bins: %d\n", header.scanner.number_of_energy_bins()); +fprintf ("Types of modules: %d\n", + length (header.scanner.scanner_geometry.replicated_modules)); +fprintf ("Number of modules of first type: %d\n", + ... length (header.scanner.scanner_geometry.replicated_modules (1) + .transforms)); +fprintf ( + "Number of types of detecting elements in modules of first type: %d\n", + ... length (header.scanner.scanner_geometry.replicated_modules (1) + .object.detecting_elements)); +fprintf ("Number of elements of first type in modules of first type: %d\n", + ... length (header.scanner.scanner_geometry.replicated_modules (1) + .object.detecting_elements (1) + .transforms)); +fprintf ("Total number of 'crystals': %d\n", + ... petsird.helpers.get_num_detecting_elements ( + header.scanner.scanner_geometry)); +fprintf ("Number of TOF bins: %d\n", header.scanner.number_of_tof_bins ()); +fprintf ("Number of energy bins: %d\n", + header.scanner.number_of_energy_bins ()); energy_bin_edges = header.scanner.energy_bin_edges; -fprintf("Energy bin edges: " + join(repelem("%f", length(energy_bin_edges))) + "\n", energy_bin_edges); +fprintf ("Energy bin edges: " + + join (repelem ("%f", length (energy_bin_edges))) + "\n", + energy_bin_edges); -energy_mid_points = (energy_bin_edges(1:end-1) + energy_bin_edges(2:end)) / 2; -fprintf("Energy mid points: " + join(repelem("%f", length(energy_mid_points))) + "\n", energy_mid_points); +energy_mid_points = (energy_bin_edges (1 + : end - 1) + + energy_bin_edges (2 + : end)) + / 2; +fprintf ("Energy mid points: " + + join (repelem ("%f", length (energy_mid_points))) + "\n", + energy_mid_points); % sgidlut = header.scanner.detection_efficiencies.module_pair_sgidlut; -% fprintf("SGID LUT:\n"); -% disp(sgidlut); +% fprintf ("SGID LUT:\n"); +% disp (sgidlut); energy_1 = 0.0; energy_2 = 0.0; num_prompts = 0; num_delayeds = 0; last_time = 0; -while reader.has_time_blocks() - time_block = reader.read_time_blocks(); +while + reader.has_time_blocks () time_block = reader.read_time_blocks (); - if time_block.isEventTimeBlock() - last_time = time_block.value.start; - num_prompts = num_prompts + length(time_block.value.prompt_events); - if time_block.value.delayed_events ~= yardl.None - num_delayeds = num_delayeds + length(time_block.value.delayed_events.value); - end - fprintf("===================== Events in time block from %f ==============\n", last_time); - for event_idx = 1:length(time_block.value.prompt_events) - event = time_block.value.prompt_events(event_idx); - energy_1 = energy_1 + energy_mid_points(event.energy_indices(1) + 1); - energy_2 = energy_2 + energy_mid_points(event.energy_indices(2) + 1); +if time_block + .isEventTimeBlock () last_time = time_block.value.start; +num_prompts = num_prompts + length (time_block.value.prompt_events); +if time_block + .value.delayed_events ~ = yardl.None num_delayeds + = num_delayeds + length (time_block.value.delayed_events.value); +end fprintf ( + "===================== Events in time block from %f ==============\n", + last_time); + for + event_idx = 1 : length (time_block.value.prompt_events) event + = time_block.value.prompt_events (event_idx); + energy_1 = energy_1 + energy_mid_points (event.energy_indices (1) + 1); + energy_2 = energy_2 + energy_mid_points (event.energy_indices (2) + 1); - fprintf("CoincidenceEvent(detectorIds=[%d, %d], tofIdx=%d, energyIndices=[%d, %d])\n", ... - event.detector_ids(1), event.detector_ids(2), event.tof_idx, ... - event.energy_indices(1), event.energy_indices(2)); - mod_and_el = petsird.helpers.get_module_and_element(header.scanner.scanner_geometry, event.detector_ids); - fprintf(" [ModuleAndElement(module=%d, el=%d), ModuleAndElement(module=%d, el=%d)]\n", ... - mod_and_el(1).module, mod_and_el(1).el, mod_and_el(2).module, mod_and_el(2).el); - fprintf(" efficiency: %f\n", petsird.helpers.get_detection_efficiency(header.scanner, event)); - end - end -end + fprintf ("CoincidenceEvent(detectorIds=[%d, %d], tofIdx=%d, " + "energyIndices=[%d, %d])\n", + ... event.detector_ids (1), event.detector_ids (2), + event.tof_idx, ... event.energy_indices (1), + event.energy_indices (2)); + mod_and_el = petsird.helpers.get_module_and_element ( + header.scanner.scanner_geometry, event.detector_ids); + fprintf (" [ModuleAndElement(module=%d, el=%d), " + "ModuleAndElement(module=%d, el=%d)]\n", + ... mod_and_el (1).module, mod_and_el (1).el, + mod_and_el (2).module, mod_and_el (2).el); + fprintf (" efficiency: %f\n", + petsird.helpers.get_detection_efficiency (header.scanner, + event)); + end end end -fprintf("Last time block at %f ms\n", last_time); -fprintf("Number of prompt events: %d\n", num_prompts); -fprintf("Number of delayed events: %d\n", num_delayeds); -if num_prompts > 0 - fprintf("Average energy_1: %f\n", energy_1 / num_prompts) - fprintf("Average energy_2: %f\n", energy_2 / num_prompts) -end + fprintf ("Last time block at %f ms\n", last_time); + fprintf ("Number of prompt events: %d\n", num_prompts); + fprintf ("Number of delayed events: %d\n", num_delayeds); + if num_prompts + > 0 fprintf ("Average energy_1: %f\n", energy_1 / num_prompts) + fprintf ("Average energy_2: %f\n", + energy_2 / num_prompts) end -reader.close(); + reader.close (); -end + end diff --git a/matlab/toolbox/petsird_generator.m b/matlab/toolbox/petsird_generator.m index ab92524..3654398 100644 --- a/matlab/toolbox/petsird_generator.m +++ b/matlab/toolbox/petsird_generator.m @@ -1,4 +1,5 @@ -function petsird_generator(output) +function +petsird_generator (output) arguments output (1,1) string @@ -8,102 +9,110 @@ function petsird_generator(output) config.NUMBER_OF_ENERGY_BINS = 3; config.NUMBER_OF_TOF_BINS = 300; config.RADIUS = 400; -config.CRYSTAL_LENGTH = [20, 4, 4]; -config.NUM_CRYSTALS_PER_MODULE = [2, 4, 7]; +config.CRYSTAL_LENGTH = [ 20, 4, 4 ]; +config.NUM_CRYSTALS_PER_MODULE = [ 2, 4, 7 ]; config.NUM_MODULES_ALONG_RING = 20; config.NUM_MODULES_ALONG_AXIS = 2; -config.MODULE_AXIS_SPACING = (config.NUM_CRYSTALS_PER_MODULE(3) + 4) * config.CRYSTAL_LENGTH(3); +config.MODULE_AXIS_SPACING + = (config.NUM_CRYSTALS_PER_MODULE (3) + 4) * config.CRYSTAL_LENGTH (3); config.NUMBER_OF_TIME_BLOCKS = 6; config.COUNT_RATE = 500; -writer = petsird.binary.PETSIRDWriter(output); +writer = petsird.binary.PETSIRDWriter (output); -header = get_header(config); -writer.write_header(header); +header = get_header (config); +writer.write_header (header); -for t = 0:config.NUMBER_OF_TIME_BLOCKS-1 - start = t * header.scanner.event_time_block_duration; +for + t = 0 : config.NUMBER_OF_TIME_BLOCKS - 1 start + = t * header.scanner.event_time_block_duration; % TODO: Need Statistics and Machine Learning Toolbox for Poisson distribution functions % num_prompts_this_block = poissrnd(COUNT_RATE); - num_prompts_this_block = randi(config.COUNT_RATE); - prompts_this_block = get_events(header, num_prompts_this_block, config); + num_prompts_this_block = randi (config.COUNT_RATE); + prompts_this_block = get_events (header, num_prompts_this_block, config); - tb = petsird.TimeBlock.EventTimeBlock(... - petsird.EventTimeBlock(start=start, prompt_events=prompts_this_block) ... - ); - writer.write_time_blocks(tb) -end + tb = petsird.TimeBlock.EventTimeBlock (... petsird.EventTimeBlock ( + start = start, prompt_events = prompts_this_block)...); + writer + .write_time_blocks (tb) end -writer.end_time_blocks(); -writer.close(); + writer.end_time_blocks (); + writer.close (); -end + end -function h = get_header(cfg) - subject = petsird.Subject(id="123456"); - institution = petsird.Institution(name="University of Somewhere", address="Didcot, Oxfordshire, Ox11 0DE, UK"); - h = petsird.Header(); - h.exam = petsird.ExamInformation(subject=subject, institution=institution); - h.scanner = get_scanner_info(cfg); -end + function h + = get_header (cfg) subject = petsird.Subject (id = "123456"); + institution + = petsird.Institution (name = "University of Somewhere", + address = "Didcot, Oxfordshire, Ox11 0DE, UK"); + h = petsird.Header (); + h.exam = petsird.ExamInformation (subject = subject, + institution = institution); + h.scanner = get_scanner_info (cfg); + end -function scanner = get_scanner_info(cfg) - scanner_geometry = get_scanner_geometry(cfg); + function scanner + = get_scanner_info (cfg) scanner_geometry = get_scanner_geometry (cfg); % TODO scanner_info.bulk_materials - % TOF info (in mm) - tofBinEdges = single(linspace(-cfg.RADIUS, cfg.RADIUS, cfg.NUMBER_OF_TOF_BINS + 1)); - energyBinEdges = single(linspace(430, 650, cfg.NUMBER_OF_ENERGY_BINS + 1)); + % TOF info (in mm) tofBinEdges = single ( + linspace (-cfg.RADIUS, cfg.RADIUS, cfg.NUMBER_OF_TOF_BINS + 1)); + energyBinEdges + = single (linspace (430, 650, cfg.NUMBER_OF_ENERGY_BINS + 1)); % We need energy bin info before being able to construct the detection - % efficiencies, so we first construct a scanner without the efficiencies - scanner = petsird.ScannerInformation(... - model_name="PETSIRD_TEST", ... - scanner_geometry=scanner_geometry, ... - tof_bin_edges=tofBinEdges, ... - tof_resolution=9.4, ... % in mm - energy_bin_edges=energyBinEdges, ... - energy_resolution_at_511=0.11, ... % as fraction of 511 - event_time_block_duration=1 ... % ms - ); - - % Now added the efficiencies - scanner.detection_efficiencies = get_detection_efficiencies(scanner, cfg); -end + % efficiencies, + so we first construct a scanner without the efficiencies scanner + = petsird.ScannerInformation ( + ... model_name = "PETSIRD_TEST", + ... scanner_geometry = scanner_geometry, + ... tof_bin_edges = tofBinEdges, ... tof_resolution = 9.4, + ... % in mm energy_bin_edges = energyBinEdges, + ... energy_resolution_at_511 = 0.11, + ... % as fraction of 511 event_time_block_duration = 1 ... % ms); -function geometry = get_scanner_geometry(cfg) - detector_module = get_detector_module(cfg); + % Now added the efficiencies scanner.detection_efficiencies + = get_detection_efficiencies (scanner, cfg); + end + + function geometry + = get_scanner_geometry (cfg) detector_module + = get_detector_module (cfg); - rep_module = petsird.ReplicatedDetectorModule(object=detector_module); + rep_module = petsird.ReplicatedDetectorModule (object = detector_module); module_id = 0; - for i = 0:cfg.NUM_MODULES_ALONG_RING-1 - angle = 2 * pi * i / cfg.NUM_MODULES_ALONG_RING; - for ax_mod = 0:cfg.NUM_MODULES_ALONG_AXIS-1 - transform = petsird.RigidTransformation(matrix=... - transpose([... - cos(angle), -sin(angle), 0, 0; ... - sin(angle), cos(angle), 0, 0; ... - 0, 0, 1, cfg.MODULE_AXIS_SPACING * ax_mod; ... - ]) ... - ); - rep_module.transforms = [rep_module.transforms transform]; - rep_module.ids = [rep_module.ids module_id]; - module_id = module_id + 1; - end - end + for + i = 0 : cfg.NUM_MODULES_ALONG_RING - 1 angle + = 2 * pi * i / cfg.NUM_MODULES_ALONG_RING; + for + ax_mod = 0 : cfg.NUM_MODULES_ALONG_AXIS - 1 transform + = petsird.RigidTransformation ( + matrix = ... transpose ([ + ... cos (angle), -sin (angle), 0, 0; + ... sin (angle), cos (angle), 0, 0; + ... 0, 0, 1, cfg.MODULE_AXIS_SPACING *ax_mod;... + ])...); + rep_module.transforms = [rep_module.transforms transform]; + rep_module.ids = [rep_module.ids module_id]; + module_id = module_id + 1; + end end - geometry = petsird.ScannerGeometry(replicated_modules=[rep_module], ids=[0]); -end + geometry + = petsird.ScannerGeometry (replicated_modules = [rep_module], + ids = [0]); + end -function detector = get_detector_module(cfg) - % Return a module of NUM_CRYSTALS_PER_MODULE cuboids - crystal = get_crystal(cfg); - rep_volume = petsird.ReplicatedBoxSolidVolume(object=crystal); - N0 = cfg.NUM_CRYSTALS_PER_MODULE(1); - N1 = cfg.NUM_CRYSTALS_PER_MODULE(2); - N2 = cfg.NUM_CRYSTALS_PER_MODULE(3); - id = 0; + function detector + = get_detector_module (cfg) + % Return a module of NUM_CRYSTALS_PER_MODULE cuboids crystal + = get_crystal (cfg); + rep_volume = petsird.ReplicatedBoxSolidVolume (object = crystal); + N0 = cfg.NUM_CRYSTALS_PER_MODULE (1); + N1 = cfg.NUM_CRYSTALS_PER_MODULE (2); + N2 = cfg.NUM_CRYSTALS_PER_MODULE (3); + id = 0; for rep0 = 0:N0-1 for rep1 = 0:N1-1 for rep2 = 0:N2-1 @@ -113,76 +122,96 @@ function petsird_generator(output) 0, 1, 0, (rep1 - N1 / 2) * cfg.CRYSTAL_LENGTH(2); ... 0, 0, 1, (rep2 - N2 / 2) * cfg.CRYSTAL_LENGTH(3); ... ])); - rep_volume.transforms = [rep_volume.transforms transform]; - rep_volume.ids = [rep_volume.ids id]; - id = id + 1; - end - end + rep_volume.transforms = [rep_volume.transforms transform]; + rep_volume.ids = [rep_volume.ids id]; + id = id + 1; + end end end detector = petsird.DetectorModule ( + detecting_elements = [rep_volume], detecting_element_ids = [0]); end - detector = petsird.DetectorModule(detecting_elements=[rep_volume], detecting_element_ids=[0]); -end -function crystal = get_crystal(cfg) - % Return a cuboid shape - crystal_shape = petsird.BoxShape(... - corners = [... - petsird.Coordinate(c=[0, 0, 0]), ... - petsird.Coordinate(c=[0, 0, cfg.CRYSTAL_LENGTH(3)]), ... - petsird.Coordinate(c=[0, cfg.CRYSTAL_LENGTH(2), cfg.CRYSTAL_LENGTH(3)]), ... - petsird.Coordinate(c=[0, cfg.CRYSTAL_LENGTH(2), 0]), ... - petsird.Coordinate(c=[cfg.CRYSTAL_LENGTH(1), 0, 0]), ... - petsird.Coordinate(c=[cfg.CRYSTAL_LENGTH(1), 0, cfg.CRYSTAL_LENGTH(3)]), ... - petsird.Coordinate(c=[cfg.CRYSTAL_LENGTH(1), cfg.CRYSTAL_LENGTH(2), cfg.CRYSTAL_LENGTH(3)]) ... - petsird.Coordinate(c=[cfg.CRYSTAL_LENGTH(1), cfg.CRYSTAL_LENGTH(2), 0]), ... - ]); - crystal = petsird.BoxSolidVolume(shape=crystal_shape, material_id=1); -end + function crystal + = get_crystal (cfg) % Return a cuboid shape crystal_shape + = petsird.BoxShape (... corners = [ + ... petsird.Coordinate (c = [ 0, 0, 0 ]), + ... petsird.Coordinate (c = [ 0, 0, cfg.CRYSTAL_LENGTH (3) ]), + ... petsird.Coordinate ( + c = [ 0, cfg.CRYSTAL_LENGTH (2), cfg.CRYSTAL_LENGTH (3) ]), + ... petsird.Coordinate (c = [ 0, cfg.CRYSTAL_LENGTH (2), 0 ]), + ... petsird.Coordinate (c = [ cfg.CRYSTAL_LENGTH (1), 0, 0 ]), + ... petsird.Coordinate ( + c = [ cfg.CRYSTAL_LENGTH (1), 0, cfg.CRYSTAL_LENGTH (3) ]), + ... petsird + .Coordinate (c = + [ + cfg.CRYSTAL_LENGTH (1), + cfg.CRYSTAL_LENGTH (2), + cfg.CRYSTAL_LENGTH (3) + ])... petsird + .Coordinate ( + c = [ cfg.CRYSTAL_LENGTH (1), cfg.CRYSTAL_LENGTH (2), 0 ]), + ... + ]); + crystal = petsird.BoxSolidVolume (shape = crystal_shape, material_id = 1); + end -function efficiencies = get_detection_efficiencies(scanner, cfg) - % Return some (non-physical) detection efficiencies - num_det_els = petsird.helpers.get_num_detecting_elements(scanner.scanner_geometry); + function efficiencies + = get_detection_efficiencies (scanner, cfg) + % Return some (non - physical) detection efficiencies num_det_els + = petsird.helpers.get_num_detecting_elements ( + scanner.scanner_geometry); - % det_el_efficiencies = ones(num_det_els, scanner.number_of_energy_bins(), "single"); - det_el_efficiencies = ones(scanner.number_of_energy_bins(), num_det_els, "single"); + % det_el_efficiencies + = ones (num_det_els, scanner.number_of_energy_bins (), "single"); + det_el_efficiencies + = ones (scanner.number_of_energy_bins (), num_det_els, "single"); % Only 1 type of module in the current scanner - assert(length(scanner.scanner_geometry.replicated_modules) == 1); - rep_module = scanner.scanner_geometry.replicated_modules(1); - num_modules = int32(length(rep_module.transforms)); + assert (length (scanner.scanner_geometry.replicated_modules) == 1); + rep_module = scanner.scanner_geometry.replicated_modules (1); + num_modules = int32 (length (rep_module.transforms)); % We will use rotational symmetries translation along the axis - % We assume all module-pairs are in coincidence, except those - % with the same angle. - % Writing a module number as (z-position, angle): - % eff((z1,a1), (z2, a2)) == eff((z1,0), (z2, abs(a2-a1))) - % or in linear indices - % eff(z1 + NZ * a1, z2 + NZ * a2) == eff(z1, z2 + NZ * abs(a2 - a1)) - % (coincident) SGIDs need to start from 0, so ignoring self-coincident - % angles we get - % SGID = z1 + NZ * (z2 + NZ * abs(a2 - a1) - 1) - num_SGIDs = cfg.NUM_MODULES_ALONG_AXIS * cfg.NUM_MODULES_ALONG_AXIS * (cfg.NUM_MODULES_ALONG_RING - 1); + % We assume all module + - pairs are in coincidence, + except those % with the same angle. + % Writing a module number as (z - position, angle) + : % eff ((z1, a1), (z2, a2)) + == eff ((z1, 0), (z2, abs (a2 - a1))) % + or in linear indices % eff (z1 + NZ * a1, z2 + NZ * a2) + == eff (z1, z2 + NZ * abs (a2 - a1)) + % (coincident)SGIDs need to start from 0, + so ignoring self + - coincident % angles we get + % SGID = z1 + + NZ + * (z2 + NZ * abs (a2 - a1) + - 1) num_SGIDs = cfg.NUM_MODULES_ALONG_AXIS + * cfg.NUM_MODULES_ALONG_AXIS + * (cfg.NUM_MODULES_ALONG_RING + - 1); NZ = cfg.NUM_MODULES_ALONG_AXIS; - module_pair_SGID_LUT = zeros(num_modules, "int32"); + module_pair_SGID_LUT = zeros (num_modules, "int32"); for mod1 = 0:num_modules-1 for mod2 = 0:num_modules-1 z1 = mod(mod1, NZ); - a1 = idivide(mod1, NZ); - z2 = mod(mod2, NZ); - a2 = idivide(mod2, NZ); - if a1 == a2 - module_pair_SGID_LUT(mod2+1, mod1+1) = -1; - else - module_pair_SGID_LUT(mod2+1, mod1+1) = z1 + NZ * (z2 + NZ * (abs(a2 - a1) - 1)); - end - end - end + a1 = idivide (mod1, NZ); + z2 = mod (mod2, NZ); + a2 = idivide (mod2, NZ); + if a1 + == a2 module_pair_SGID_LUT (mod2 + 1, mod1 + 1) = -1; + else + module_pair_SGID_LUT (mod2 + 1, mod1 + 1) + = z1 + NZ * (z2 + NZ * (abs (a2 - a1) - 1)); + end end end - % fprint("SGID LUT:\n", module_pair_SGID_LUT, file=sys.stderr) - assert(max(module_pair_SGID_LUT(:)) == num_SGIDs - 1); + % fprint ("SGID LUT:\n", module_pair_SGID_LUT, file = sys.stderr) + assert (max (module_pair_SGID_LUT ( + :)) + == num_SGIDs - 1); module_pair_efficiencies_vector = []; - assert(length(rep_module.object.detecting_elements) == 1); - detecting_elements = rep_module.object.detecting_elements(1); - num_det_els_in_module = length(detecting_elements.transforms); + assert (length (rep_module.object.detecting_elements) == 1); + detecting_elements = rep_module.object.detecting_elements (1); + num_det_els_in_module = length (detecting_elements.transforms); for SGID = 0:num_SGIDs-1 % Extract first module_pair for this SGID. However, as this % currently unused, it is commented out @@ -194,39 +223,49 @@ function petsird_generator(output) scanner.number_of_energy_bins(), ... num_det_els_in_module ... ); - % give some (non-physical) value + % give some (non - physical) value module_pair_efficiencies = module_pair_efficiencies * SGID; - module_pair_efficiencies_vector = [module_pair_efficiencies_vector ... - petsird.ModulePairEfficiencies(values=module_pair_efficiencies, sgid=SGID)]; - assert(length(module_pair_efficiencies_vector) == SGID + 1); + module_pair_efficiencies_vector = + [module_pair_efficiencies_vector... petsird.ModulePairEfficiencies ( + values = module_pair_efficiencies, sgid = SGID)]; + assert (length (module_pair_efficiencies_vector) == SGID + 1); end - efficiencies = petsird.DetectionEfficiencies(... - det_el_efficiencies=det_el_efficiencies, ... - module_pair_sgidlut=module_pair_SGID_LUT, ... - module_pair_efficiencies_vector=module_pair_efficiencies_vector ... - ); -end - + efficiencies + = petsird.DetectionEfficiencies ( + ... det_el_efficiencies = det_el_efficiencies, + ... module_pair_sgidlut = module_pair_SGID_LUT, + ... module_pair_efficiencies_vector + = module_pair_efficiencies_vector...); + end -function events = get_events(header, num_events, cfg) - % Generate some random events - detector_count = petsird.helpers.get_num_detecting_elements(header.scanner.scanner_geometry); + function events + = get_events (header, num_events, cfg) + % Generate some random events detector_count + = petsird.helpers.get_num_detecting_elements ( + header.scanner.scanner_geometry); events = []; - for i = 1:num_events - while true - detector_ids = int32([randi([0, detector_count-1]), randi([0, detector_count-1])]); - mod_and_els = petsird.helpers.get_module_and_element(header.scanner.scanner_geometry, detector_ids); - if header.scanner.detection_efficiencies.module_pair_sgidlut(mod_and_els(1).module+1, mod_and_els(2).module+1) >= 0 - % in coincidence, we can get out of the loop - break - end - end + for + i = 1 : num_events while true detector_ids = int32 ([ + randi ([ 0, detector_count - 1 ]), randi ([ 0, detector_count - 1 ]) + ]); + mod_and_els = petsird.helpers.get_module_and_element ( + header.scanner.scanner_geometry, detector_ids); + if header + .scanner.detection_efficiencies.module_pair_sgidlut ( + mod_and_els (1).module + 1, mod_and_els (2).module + 1) + >= 0 % in coincidence, + we can get out of the loop break end end - events = [events, petsird.CoincidenceEvent(... - detector_ids = detector_ids, ... - energy_indices = [randi([0, cfg.NUMBER_OF_ENERGY_BINS-1]), randi([0, cfg.NUMBER_OF_ENERGY_BINS-1])], ... - tof_idx=randi([0, cfg.NUMBER_OF_TOF_BINS-1])... - )]; - end -end + events = [ + events, + petsird.CoincidenceEvent ( + ... detector_ids = detector_ids, + ... energy_indices = + [ + randi ([ 0, cfg.NUMBER_OF_ENERGY_BINS - 1 ]), + randi ([ 0, cfg.NUMBER_OF_ENERGY_BINS - 1 ]) + ], + ... tof_idx = randi ([ 0, cfg.NUMBER_OF_TOF_BINS - 1 ])...) + ]; + end end