Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Eamon Doyle
roiTool
Commits
7d901b47
Commit
7d901b47
authored
Apr 10, 2024
by
Eamon Doyle
Browse files
added git info and stats updates
parent
81c55d1c
Changes
2
Hide whitespace changes
Inline
Side-by-side
getGitInfo.m
0 → 100755
View file @
7d901b47
function
gitInfo
=
getGitInfo
()
% Get information about the Git repository in the current directory, including:
% - branch name of the current Git Repo
% -Git SHA1 HASH of the most recent commit
% -url of corresponding remote repository, if one exists
%
% The function first checks to see if a .git/ directory is present. If so it
% reads the .git/HEAD file to identify the branch name and then it looks up
% the corresponding commit.
%
% It then reads the .git/config file to find out the url of the
% corresponding remote repository. This is all stored in a gitInfo struct.
%
% Note this uses only file information, it makes no external program
% calls at all.
%
% This function must be in the base directory of the git repository
%
% Released under a BSD open source license. Based on a concept by Marc
% Gershow.
%
% Andrew Leifer
% Harvard University
% Program in Biophysics, Center for Brain Science,
% and Department of Physics
% leifer@fas.harvard.edu
% http://www.andrewleifer.com
% 12 September 2011
%
%
%
% Copyright 2011 Andrew Leifer. All rights reserved.
%
% Redistribution and use in source and binary forms, with or without modification, are
% permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice, this list of
% conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice, this list
% of conditions and the following disclaimer in the documentation and/or other materials
% provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
% WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
% FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
% CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
% ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
% ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%
% The views and conclusions contained in the software and documentation are those of the
% authors and should not be interpreted as representing official policies, either expressed
% or implied, of <copyright holder>.
gitInfo
=
[];
if
~
exist
(
'.git'
,
'file'
)
||
~
exist
(
'.git/HEAD'
,
'file'
)
%Git is not present
return
end
%Read in the HEAD information, this will tell us the location of the file
%containing the SHA1
text
=
fileread
(
'.git/HEAD'
);
parsed
=
textscan
(
text
,
'%s'
);
if
~
strcmp
(
parsed
{
1
}{
1
},
'ref:'
)
||
~
length
(
parsed
{
1
})
>
1
%the HEAD is not in the expected format.
%give up
return
end
path
=
parsed
{
1
}{
2
};
[
pathstr
,
name
,
ext
]
=
fileparts
(
path
);
branchName
=
name
;
%save branchname
gitInfo
.
branch
=
branchName
;
%Read in SHA1
SHA1text
=
fileread
(
fullfile
([
'.git/'
pathstr
],[
name
ext
]));
SHA1
=
textscan
(
SHA1text
,
'%s'
);
gitInfo
.
hash
=
SHA1
{
1
}{
1
};
%Read in config file
config
=
fileread
(
'.git/config'
);
%Find everything space delimited
temp
=
textscan
(
config
,
'%s'
,
'delimiter'
,
'\n'
);
lines
=
temp
{
1
};
remote
=
''
;
%Lets find the name of the remote corresponding to our branchName
for
k
=
1
:
length
(
lines
)
%Are we at the section describing our branch?
if
strcmp
(
lines
{
k
},[
'[branch "'
branchName
'"]'
])
m
=
k
+
1
;
%While we haven't run out of lines
%And while we haven't run into another section (which starts with
% an open bracket)
while
(
m
<=
length
(
lines
)
&&
~
strcmp
(
lines
{
m
}(
1
),
'['
)
)
temp
=
textscan
(
lines
{
m
},
'%s'
);
if
length
(
temp
{
1
})
>=
3
if
strcmp
(
temp
{
1
}{
1
},
'remote'
)
&&
strcmp
(
temp
{
1
}{
2
},
'='
)
%This is the line that tells us the name of the remote
remote
=
temp
{
1
}{
3
};
end
end
m
=
m
+
1
;
end
end
end
gitInfo
.
remote
=
remote
;
url
=
''
;
%Find the remote's url
for
k
=
1
:
length
(
lines
)
%Are we at the section describing our branch?
if
strcmp
(
lines
{
k
},[
'[remote "'
remote
'"]'
])
m
=
k
+
1
;
%While we haven't run out of lines
%And while we haven't run into another section (which starts with
% an open bracket)
while
(
m
<=
length
(
lines
)
&&
~
strcmp
(
lines
{
m
}(
1
),
'['
)
)
temp
=
textscan
(
lines
{
m
},
'%s'
);
if
length
(
temp
{
1
})
>=
3
if
strcmp
(
temp
{
1
}{
1
},
'url'
)
&&
strcmp
(
temp
{
1
}{
2
},
'='
)
%This is the line that tells us the name of the remote
url
=
temp
{
1
}{
3
};
end
end
m
=
m
+
1
;
end
end
end
gitInfo
.
url
=
url
;
\ No newline at end of file
mergeRoiTool.m
View file @
7d901b47
...
@@ -65,6 +65,7 @@ handles.needsReload = 1;
...
@@ -65,6 +65,7 @@ handles.needsReload = 1;
handles
.
roi
=
struct
;
handles
.
roi
=
struct
;
handles
.
roiCoords
=
struct
;
handles
.
roiCoords
=
struct
;
handles
.
lungGridSize
=
-
1
;
handles
.
lungGridSize
=
-
1
;
handles
.
gitInfo
=
getGitInfo
();
% Update handles structure
% Update handles structure
guidata
(
hObject
,
handles
);
guidata
(
hObject
,
handles
);
...
@@ -96,6 +97,7 @@ function pushbutton_save_Callback(hObject, eventdata, handles)
...
@@ -96,6 +97,7 @@ function pushbutton_save_Callback(hObject, eventdata, handles)
% eventdata reserved - to be defined in a future version of MATLAB
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% handles structure with handles and user data (see GUIDATA)
lungMatrix
=
handles
.
lungMatrix
;
lungMatrix
=
handles
.
lungMatrix
;
lungStats
=
handles
.
lungStats
;
savePath
=
[
handles
.
path
'/mergeLungROI'
];
savePath
=
[
handles
.
path
'/mergeLungROI'
];
fname
=
handles
.
curName
;
fname
=
handles
.
curName
;
...
@@ -730,6 +732,7 @@ lungHypo = size(find(handles.lungMatrix==2),1);
...
@@ -730,6 +732,7 @@ lungHypo = size(find(handles.lungMatrix==2),1);
lungHyper
=
size
(
find
(
handles
.
lungMatrix
==
3
),
1
);
lungHyper
=
size
(
find
(
handles
.
lungMatrix
==
3
),
1
);
lungBronchodyslasia
=
size
(
find
(
handles
.
lungMatrix
==
4
),
1
);
lungBronchodyslasia
=
size
(
find
(
handles
.
lungMatrix
==
4
),
1
);
lungVol
=
-
1
;
lungVol
=
-
1
;
if
strcmp
(
handles
.
dcminfo
.
SOPClassUID
,
'1.2.840.10008.5.1.4.1.1.4.1'
)
if
strcmp
(
handles
.
dcminfo
.
SOPClassUID
,
'1.2.840.10008.5.1.4.1.1.4.1'
)
%this is an enhanced dicom
%this is an enhanced dicom
d
=
handles
.
dcminfo
;
d
=
handles
.
dcminfo
;
...
@@ -756,8 +759,20 @@ st = st + sprintf(" Normal Lung Voxels: %d (%03.2f%%)\n",lungNormal, 100*lungN
...
@@ -756,8 +759,20 @@ st = st + sprintf(" Normal Lung Voxels: %d (%03.2f%%)\n",lungNormal, 100*lungN
st
=
st
+
sprintf
(
" Hypointense Voxels: %d (%03.2f%%)\n"
,
lungHypo
,
100
*
lungHypo
/
lungVoxels
);
st
=
st
+
sprintf
(
" Hypointense Voxels: %d (%03.2f%%)\n"
,
lungHypo
,
100
*
lungHypo
/
lungVoxels
);
st
=
st
+
sprintf
(
" Hyperintense Voxels: %d (%03.2f%%)\n"
,
lungHyper
,
100
*
lungHyper
/
lungVoxels
);
st
=
st
+
sprintf
(
" Hyperintense Voxels: %d (%03.2f%%)\n"
,
lungHyper
,
100
*
lungHyper
/
lungVoxels
);
st
=
st
+
sprintf
(
" Bronchodyspl Voxels: %d (%03.2f%%)\n"
,
lungBronchodyslasia
,
100
*
lungBronchodyslasia
/
lungVoxels
);
st
=
st
+
sprintf
(
" Bronchodyspl Voxels: %d (%03.2f%%)\n"
,
lungBronchodyslasia
,
100
*
lungBronchodyslasia
/
lungVoxels
);
st
=
st
+
sprintf
(
"\nVolumes:\n"
);
st
=
st
+
sprintf
(
"\n\n\nVolumes:\n\nWarning these may be very wrong\n"
);
st
=
st
+
sprintf
(
" Estimated Total Lung Volume: %06.1f cc"
,
lungVol
);
st
=
st
+
sprintf
(
" Estimated Total Lung Volume: %06.1f cc"
,
lungVol
);
set
(
handles
.
statsTextbox
,
'String'
,
st
);
set
(
handles
.
statsTextbox
,
'String'
,
st
);
lungStats
=
struct
(
"countLungVoxels"
,
lungVoxels
...
,
"countNormalVoxels"
,
lungNormal
...
,
"countHypointVoxels"
,
lungHypo
...
,
"countHyperintVoxels"
,
lungHyper
...
,
"countBronchodisplasticVoxels"
,
lungBronchodyslasia
...
,
"estimatedLungVolume"
,
lungVol
...
)
handles
.
lungStats
=
lungStats
;
guidata
(
hObject
,
handles
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment