Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev rc/v3 bug fix #785

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions matRad/IO/matRad_readMHD.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@
T = zeros(3);
T(:) = cell2mat(tmp);

if ~isequal(T, diag(ones(1,numel(dimensions))))
matRad_cfg.dispWarning('Non identity transformation matrix detected in the loaded cube. This might lead to reconstruction inconsistency.')

Check warning on line 72 in matRad/IO/matRad_readMHD.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_readMHD.m#L71-L72

Added lines #L71 - L72 were not covered by tests
end

% Apply Matlab permutation
% This ensures that the cube is reverted back to the matLab standard
% indexing
Tmatlab = [0 1 0; 1 0 0; 0 0 1];
%T = T * [0 1 0; 1 0 0; 0 0 1];
T = T*Tmatlab;

Check warning on line 79 in matRad/IO/matRad_readMHD.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_readMHD.m#L79

Added line #L79 was not covered by tests

% get data type
idx = find(~cellfun(@isempty,strfind(s{1}, 'ElementType')),1,'first');
Expand All @@ -84,20 +90,18 @@
fseek(headerFileHandle,-S.bytes*prod(dimensions),'eof');
cube = fread(headerFileHandle,prod(dimensions),type,endian);
cube = reshape(cube,dimensions);
cube = permute(cube,[2 1 3]);
%matRad_cfg.dispError('MHA not implemented!');
cube = permute(cube,abs([1 2 3]*T));

Check warning on line 93 in matRad/IO/matRad_readMHD.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_readMHD.m#L93

Added line #L93 was not covered by tests
else
%% read data
[filepath,~,~] = fileparts(filename);
dataFileHandle = fopen(fullfile(filepath,dataFilename),'r');
cube = reshape(fread(dataFileHandle,inf,type,endian),dimensions);
cube = permute(cube,[2 1 3]);
%cube = flip(cube,1);
cube = permute(cube,abs([1 2 3]*T));

Check warning on line 99 in matRad/IO/matRad_readMHD.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_readMHD.m#L99

Added line #L99 was not covered by tests
fclose(dataFileHandle);
end
fclose(headerFileHandle);
metadata.resolution = resolution;
metadata.cubeDim = dimensions * Tmatlab;
metadata.cubeDim = dimensions * T;

Check warning on line 104 in matRad/IO/matRad_readMHD.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_readMHD.m#L104

Added line #L104 was not covered by tests

end

Expand Down
33 changes: 20 additions & 13 deletions matRad/IO/matRad_writeMHA.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,28 @@
%cleaner = onCleanup(@() fclose(fid));

%We perform the permutation
if isfield(metadata,'axisPermutation')
cube = permute(cube,metadata.axisPermutation);
if ~isfield(metadata, 'axisPermutation')
% This reverts the matRlab conventianl indexing
axisPermutation = [2,1,3];

Check warning on line 53 in matRad/IO/matRad_writeMHA.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeMHA.m#L53

Added line #L53 was not covered by tests
elseif ~isequal(metadata.axisPermutation, [2,1,3])
matRad_cfg.dispWarning('Unconventianal permutation of patient indexing, this might cause inconsistency');
axisPermutation = metadata.axisPermutation;

Check warning on line 56 in matRad/IO/matRad_writeMHA.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeMHA.m#L55-L56

Added lines #L55 - L56 were not covered by tests
end

%Set up Transform Matrix
T=zeros(4);
ixOnes = sub2ind([4 4],metadata.axisPermutation,[1 2 3]);
T(ixOnes) = 1;
T(4,4) = 1;
% Force the permutation here according to the axis permutation
cube = permute(cube, axisPermutation);

% Need to permute the dimensions as well
dimensions = size(cube);

Check warning on line 63 in matRad/IO/matRad_writeMHA.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeMHA.m#L63

Added line #L63 was not covered by tests

% Note in the cube permutation:
% Permutation of the cube is enforced here to standdard indexing so that
% reconstruction of the cube for further use does not rely on the use of
% a transformation matrix, which is now only the identity matrix.

%The transformation matrix is now the unit matrix
transformMatrix = diag(ones(1,numel(dimensions)));
tmString = sprintf(' %d',transformMatrix(:));

Check warning on line 72 in matRad/IO/matRad_writeMHA.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeMHA.m#L71-L72

Added lines #L71 - L72 were not covered by tests

%Correct for coordinate system
switch metadata.coordinateSystem
Expand All @@ -68,12 +81,6 @@
matRad_cfg.dispError('Only LPS currently supported for export!');
end

%Now add Translation
%The transformation matrix is now the unit matrix
%transformMatrix = diag(ones(1,numel(dimensions)));
%tmString = sprintf(' %d',transformMatrix(:));

tmString = sprintf(' %d',T(1:3,1:3));

%Determine the endian
[~,~,endian] = computer;
Expand Down
20 changes: 18 additions & 2 deletions matRad/IO/matRad_writeMHD.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,25 @@
end

%We perform the permutation
if isfield(metadata,'axisPermutation')
cube = permute(cube,metadata.axisPermutation);
if ~isfield(metadata, 'axisPermutation')
% This reverts the matRlab conventianl indexing
axisPermutation = [2,1,3];

Check warning on line 52 in matRad/IO/matRad_writeMHD.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeMHD.m#L52

Added line #L52 was not covered by tests
elseif ~isequal(metadata.axisPermutation, [2,1,3])
matRad_cfg.dispWarning('Unconventianal permutation of patient indexing, this might cause inconsistency');
axisPermutation = metadata.axisPermutation;

Check warning on line 55 in matRad/IO/matRad_writeMHD.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeMHD.m#L54-L55

Added lines #L54 - L55 were not covered by tests
end

% Force the permutation here according to the axis permutation
cube = permute(cube, axisPermutation);

% Need to permute the dimensions as well
dimensions = size(cube);

Check warning on line 62 in matRad/IO/matRad_writeMHD.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeMHD.m#L62

Added line #L62 was not covered by tests

% Note in the cube permutation:
% Permutation of the cube is enforced here to standdard indexing so that
% reconstruction of the cube for further use does not rely on the use of
% a transformation matrix, which is now only the identity matrix.

%The transformation matrix is now the unit matrix
transformMatrix = diag(ones(1,numel(dimensions)));
tmString = sprintf(' %d',transformMatrix(:));
Expand Down
15 changes: 12 additions & 3 deletions matRad/IO/matRad_writeVTK.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@
end
cleaner = onCleanup(@() fclose(fid));

%We perform
if isfield(metadata,'axisPermutation')
cube = permute(cube,metadata.axisPermutation);
%We perform the permutation
if ~isfield(metadata, 'axisPermutation')
% This reverts the matRlab conventianl indexing
axisPermutation = [2,1,3];

Check warning on line 50 in matRad/IO/matRad_writeVTK.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeVTK.m#L50

Added line #L50 was not covered by tests
elseif ~isequal(metadata.axisPermutation, [2,1,3])
matRad_cfg.dispWarning('Unconventianal permutation of patient indexing, this might cause inconsistency');
axisPermutation = metadata.axisPermutation;

Check warning on line 53 in matRad/IO/matRad_writeVTK.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeVTK.m#L52-L53

Added lines #L52 - L53 were not covered by tests
end

% Force the permutation here according to the axis permutation
cube = permute(cube, axisPermutation);

% Need to permute the dimensions as well
dimensions = size(cube);

Check warning on line 60 in matRad/IO/matRad_writeVTK.m

View check run for this annotation

Codecov / codecov/patch

matRad/IO/matRad_writeVTK.m#L60

Added line #L60 was not covered by tests

fprintf(fid, '# vtk DataFile Version 3.0\n');
fprintf(fid, 'vtk output\n');
Expand Down
2 changes: 1 addition & 1 deletion matRad/steering/matRad_StfGeneratorBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function assignPropertiesFromPln(this,pln,warnWhenPropertyChanged)
methods (Access = protected)
function initialize(this)
%Do nothing

matRad_cfg = MatRad_Config.instance();
% get machine
if ~isstruct(this.machine)
try
Expand Down
Loading