Skip to content

Update setpaths for generalizability #64

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

Open
wants to merge 24 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c90b4ad
Update setpaths.m
kk1995 Oct 4, 2023
16c742a
removed filesepStandard_startup
kk1995 Oct 4, 2023
bff1df1
Fix an issue while changing Atlas
sreekanthkura7 Oct 11, 2023
20a507e
Fix bug in tranforming brain vol to head space in import MRI anatomy …
sreekanthkura7 Oct 30, 2023
9bc565b
v2.48.1, Fix image reconstruction generating bad image that might be…
jayd1860 Nov 16, 2023
3a3ca9a
FIx a bug in probe design in AV
sreekanthkura7 Nov 21, 2023
31da485
Update ImageRecon.m
mayucel Nov 30, 2023
293e1ae
Update showReducedMesh.m
mayucel Dec 1, 2023
3e49e7a
Fix isProbeAlreadyRegistered issue
sreekanthkura7 Dec 4, 2023
cb66ada
update code to add transformation matrix from mcspace to mni space af…
sreekanthkura7 Jan 30, 2024
2424a2b
Merge branch 'development' into development
sreekanthkura7 Jan 30, 2024
c200ae5
Merge pull request #67 from sreekanthkura7/development
sreekanthkura7 Jan 30, 2024
ff0cfac
Fix merging error
sreekanthkura7 Feb 8, 2024
64b9940
Merge pull request #68 from sreekanthkura7/development
sreekanthkura7 Feb 8, 2024
86324b0
-- Add unit test script to test DataFilesClass with simulated dataset
jayd1860 Feb 19, 2024
85b3841
v2.49.0
jayd1860 Feb 19, 2024
ec4b214
v2.50.0
jayd1860 Apr 23, 2024
4f46e7f
v2.50.1
jayd1860 Apr 25, 2024
2a36f99
v2.50.2
jayd1860 May 1, 2024
eb407c9
v2.51.0
jayd1860 May 8, 2024
ea27b6a
Update hmrConc2OD.m
dboas May 14, 2024
b5cc866
Merge branch 'development' of https://github.com/kk1995/AtlasViewer i…
kk1995 May 29, 2024
3e5cebf
make filesepStandard_startup compatible with \\ at beginning
kk1995 May 29, 2024
d022741
Revert "Merge branch 'development' of https://github.com/kk1995/Atlas…
kk1995 May 29, 2024
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
60 changes: 17 additions & 43 deletions AtlasViewerGUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ function ParseArgs(args)
atlasViewer.dirnameAtlas = getAtlasDir(args);
end
if length(args)>3
atlasViewer.handles.dataTree = args{4};
atlasViewer.dataTree = get(atlasViewer.handles.dataTree, 'userdata');
if sum(isgraphics(args{4}))
atlasViewer.handles.dataTree = args{4};
atlasViewer.dataTree = get(atlasViewer.handles.dataTree, 'userdata');
end
end

% Change current folder to dirnameSubj and load data
Expand Down Expand Up @@ -651,29 +653,12 @@ function pushbuttonRegisterProbeToSurface_Callback(hObject, eventdata, handles)
refpts = set_eeg_active_pts(refpts, [], false);

% Finish registration
if isPreRegisteredProbe(probe, refpts)
if 0 %isPreRegisteredProbe(probe, refpts)

% check if probe is already on the surface
probe_on_surface = true;
if ~isempty(atlasViewer.probe.registration.al)
for u = 1:size(atlasViewer.probe.registration.al,1)
ii = ismember(atlasViewer.refpts.labels,atlasViewer.probe.registration.al{u,2});
refpt_pos = atlasViewer.refpts.pos(ii,:);
opt_pos = atlasViewer.probe.optpos_reg(atlasViewer.probe.registration.al{u,1},:);
dist_refpt_to_opt = sqrt(sum(refpt_pos-opt_pos).^2);
if dist_refpt_to_opt > 1
probe_on_surface = false;
break;
end
end
end

% Register probe by simply pulling (or pushing) optodes toward surface
% toward (or away from) center of head.
if ~ probe_on_surface
probe = pullProbeToHeadsurf(probe, headobj);
probe.hOptodesIdx = 1;
end

else

Expand Down Expand Up @@ -1281,15 +1266,13 @@ function menuItemGenerateMCInput_Callback(hObject, eventdata, handles)
imgrecon = atlasViewer.imgrecon;
hbconc = atlasViewer.hbconc;
probe = atlasViewer.probe;
headvol = atlasViewer.headvol;
pialsurf = atlasViewer.pialsurf;
headsurf = atlasViewer.headsurf;
dirnameSubj = atlasViewer.dirnameSubj;
axesv = atlasViewer.axesv;

try
if isempty(eventdata) || strcmp(eventdata.EventName,'Action')
fwmodel = genSensitivityProfile(fwmodel,probe,headvol,pialsurf,headsurf,dirnameSubj);
fwmodel = genSensitivityProfile(fwmodel, probe, dirnameSubj);
if isempty(fwmodel.Adot)
return;
end
Expand Down Expand Up @@ -1512,7 +1495,7 @@ function menuItemFs2Viewer_Callback(hObject, eventdata, handles)


% --------------------------------------------------------------------
function menuItemShowRefpts_Callback(hObject, eventdata, handles)
function menuItemShowRefpts_Callback(hObject, ~, ~)
global atlasViewer

switch(get(hObject, 'tag'))
Expand Down Expand Up @@ -1592,7 +1575,6 @@ function pushbuttonCopyFigure_Callback(~, ~, ~)
axis equal
axis vis3d
set(gca, 'unit','normalized');
p = get(gca, 'position');
set(gca, 'unit','normalized', 'position', [.20, .30, .40, .40]);

% colormap is a propery of figure not axes. Since we don't want to
Expand Down Expand Up @@ -1666,10 +1648,10 @@ function menuItemLighting_Callback(hObject, eventdata, handles)

axesv = atlasViewer.axesv;

if strcmp(get(hObject,'checked'), 'on');
if strcmp(get(hObject,'checked'), 'on')
set(hObject,'checked', 'off');
val=0;
elseif strcmp(get(hObject,'checked'), 'off');
elseif strcmp(get(hObject,'checked'), 'off')
set(hObject,'checked', 'on');
val=1;
end
Expand All @@ -1686,12 +1668,12 @@ function menuItemLighting_Callback(hObject, eventdata, handles)


% --------------------------------------------------------------------
function menuItemFindRefpts_Callback(hObject, eventdata, handles)
function menuItemFindRefpts_Callback(~, ~, ~)
FindRefptsGUI();


% --------------------------------------------------------------------
function menuProbePlacementVariation_Callback(hObject, eventdata, handles)
function menuProbePlacementVariation_Callback(~, ~, ~)
plotProbePlacementVariation();


Expand Down Expand Up @@ -1958,7 +1940,7 @@ function menuCalcOptProp_Callback(~, ~, ~)
set(hLabelsSurf,'FaceVertexCData',faceVertexCData);
faceVertexAlphaData(iFace(iFaceMin)) = ones(length(iFace(iFaceMin)),1);
set(hLabelsSurf,'FaceVertexAlphaData',faceVertexAlphaData);
iFaces = [iFaces iFace(iFaceMin)];
iFaces = [iFaces, iFace(iFaceMin)];
end
if all(ishandles(hProjectionRays))
set(hProjectionRays,'color','k');
Expand Down Expand Up @@ -2245,13 +2227,8 @@ function menuItemGetSensitivityatMNICoordinates_Callback(~, ~, handles)


% --------------------------------------------------------------------
function checkbox_Display_MNI_Projection_Callback(hObject, eventdata, handles)
function checkbox_Display_MNI_Projection_Callback(hObject, ~, ~)
global atlasViewer

fwmodel = atlasViewer.fwmodel;
headvol = atlasViewer.headvol;
labelssurf = atlasViewer.labelssurf;
headvol = atlasViewer.headvol;
headsurf = atlasViewer.headsurf;

if get(hObject,'value')==1 % if checkbox is checked
Expand All @@ -2268,12 +2245,12 @@ function checkbox_Display_MNI_Projection_Callback(hObject, eventdata, handles)
foo = num2str(coordinate_mni);
fooi = sprintf(foo(1,:));
if no_mni == 1
defaultanswer = {[fooi]};
defaultanswer = {fooi};
else
for i = 2:no_mni
foon = ['; ' sprintf(foo(i,:))];
defaultanswer = {[fooi foon]};
fooi = [fooi foon];
fooi = [fooi, foon];
end %defaultanswer = {[sprintf(foo(1,:)) ';' sprintf(foo(2,:))]}
end
else
Expand All @@ -2300,7 +2277,6 @@ function checkbox_Display_MNI_Projection_Callback(hObject, eventdata, handles)
h2 = findobj('Marker','o');
set(h2,'Visible','off');

headvol = atlasViewer.headvol;
vertices = atlasViewer.labelssurf.mesh.vertices;

% Project MNI in MC space to head surface and pial surface
Expand Down Expand Up @@ -2379,7 +2355,6 @@ function menuItemSaveAnatomy_Callback(~, ~, ~)
pialsurf = atlasViewer.pialsurf;
labelssurf = atlasViewer.labelssurf;
refpts = atlasViewer.refpts;
dirnameSubj = atlasViewer.dirnameSubj;

saveHeadvol(headvol);
saveHeadsurf(headsurf, headvol.T_2mc);
Expand All @@ -2390,12 +2365,11 @@ function menuItemSaveAnatomy_Callback(~, ~, ~)


% --------------------------------------------------------------------
function menuItemLoadPrecalculatedProfile_Callback(hObject, eventdata, handles)
function menuItemLoadPrecalculatedProfile_Callback(~, ~, handles)
global atlasViewer

fwmodel = atlasViewer.fwmodel;
headvol = atlasViewer.headvol;
pialsurf = atlasViewer.pialsurf;
probe = atlasViewer.probe;
T_vol2mc = headvol.T_2mc;

Expand Down Expand Up @@ -2482,7 +2456,7 @@ function popupmenuImageDisplay_Callback(hObject, ~, handles)


% --------------------------------------------------------------------
function popupmenuImageDisplay_CreateFcn(hObject, eventdata, handles)
function popupmenuImageDisplay_CreateFcn(hObject, ~, ~)
global popupmenuorder;

popupmenuorder = struct(...
Expand Down
31 changes: 18 additions & 13 deletions ForwardModel/genSensitivityProfile.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function fwmodel = genSensitivityProfile(fwmodel,probe,headvol,pialsurf,headsurf,dirnameSubj)
function fwmodel = genSensitivityProfile(fwmodel, probe, dirnameSubj)

% Compute volume sensitivity matrix from Monte Carlo simulations and then
% projects volume sensitivity onto pial mesh to obtain surface sensitivity
Expand All @@ -12,6 +12,9 @@
% usage:
% call function Adot in subject directory or registered atlas
% directory.
global logger

logger = InitLogger(logger);

fwmodel = resetSensitivity(fwmodel,probe,dirnameSubj);
if dirnameSubj(end)~='/' && dirnameSubj(end)~='\'
Expand Down Expand Up @@ -76,13 +79,6 @@
Adot = single(zeros(nMeas,nNode,nWav));
% Adot_scalp = single(zeros(nMeas,nNode_scalp,nWav));


% We don't want to reserve the whole matrix in memory (too large).
% rather append each channel's sensitivity to a file.
A = single(zeros(nx,ny,nz));
As = single(zeros(nx,ny,nz));
Ad = single(zeros(nx,ny,nz));

if fwmodel.AdotVolFlag
fprintf('Warning: option to generate Adot 3 pt file enabled - May run out of memory\n');
fid1 = fopen([dirnameOut 'AdotVol.3pt'],'wb');
Expand All @@ -108,11 +104,11 @@
% load 2pt for given measurement from mc2 mcextreme output
iS = probe.ml(iM,1);
fileS = sprintf('%sfw%d.s%d.%s', dirnameOut, iW, iS, mc_output_ext);
As = loadMCFuncPtr(fileS, [nx ny nz 1]);
As = loadMCFuncPtr(fileS, [nx, ny, nz, 1]);

iD = probe.ml(iM,2);
fileD = sprintf('%sfw%d.d%d.%s', dirnameOut, iW, iD, mc_output_ext);
Ad = loadMCFuncPtr(fileD, [nx ny nz 1]);
Ad = loadMCFuncPtr(fileD, [nx, ny, nz, 1]);

if fwmodel.normalizeFluence

Expand All @@ -134,7 +130,7 @@
if sum_p~=0
As(idx_p) = As(idx_p) * (1 - abs(sum_n)) / sum_p;
else
disp(sprintf('No photons launched into tissue from Src %d',iS))
logger.Write('No photons launched into tissue from Src %d\n',iS)
As(idx_p) = 0;
end

Expand All @@ -156,7 +152,7 @@
if sum_p~=0
Ad(idx_p) = Ad(idx_p) * (1 - abs(sum_n)) / sum_p;
else
fprintf('No photons launched into tissue form Det %d\n',iD)
logger.Write('No photons launched into tissue form Det %d\n',iD)
Ad(idx_p) = 0;
end

Expand Down Expand Up @@ -186,12 +182,18 @@
normfactor_d = As(floor(detpos{1}),floor(detpos{2}),floor(detpos{3}));
end

[~, fs] = fileparts(fileS);
[~, fd] = fileparts(fileD);
logger.Write('Ch %d. Loading fluence files [%s, %s]\n', iM, fs, fd);
logger.Write('Generating sensitivity for ch %d = [%d, %d, %d], (s%d pos = [%0.1f, %0.1f, %0.1f], d%d pos = [%0.1f, %0.1f, %0.1f])\n', ...
iM, probe.ml(iM,1), probe.ml(iM,2), iW, iS, srcpos{1}, srcpos{2}, srcpos{3}, iD, detpos{1}, detpos{2}, detpos{3});

% Get Adot
normfactor = (normfactor_s + normfactor_d)/2;
if normfactor~=0
A = (As.*Ad)/normfactor;
else
fprintf('No photons detected between Src %d and Det %d',iS,iD);
logger.Write('No photons detected between Src %d and Det %d\n',iS,iD);
A = zeros(size(As));
end
if fwmodel.AdotVolFlag
Expand All @@ -203,6 +205,9 @@
% memory function only available on windows
memory;
end


logger.Write('\n');

% Extract sensitivity values for the nodes of the low res mesh
% (Adot) from the sensitivity matrix volume (A)
Expand Down
28 changes: 1 addition & 27 deletions ForwardModel/getFwmodel.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,7 @@
% Look at MC input files for forward model params only
% if not using precalculated fluence files
if isempty(fwmodel.fluenceProfFnames)

% Wavelength 1
if exist([dirnameOut, 'fw1.s1.inp'],'file')
config = read_tMCimg_inp([dirnameOut, 'fw1.s1.inp']);
fwmodel.nphotons = config.phot_num;
for ii=1:size(config.tiss_prop,1)
fwmodel.headvol.tiss_prop(ii).scattering(:,1) = config.tiss_prop(ii,1);
fwmodel.headvol.tiss_prop(ii).anisotropy(:,1) = config.tiss_prop(ii,2);
fwmodel.headvol.tiss_prop(ii).absorption(:,1) = config.tiss_prop(ii,3);
fwmodel.headvol.tiss_prop(ii).refraction(:,1) = config.tiss_prop(ii,4);
end
fwmodel.nWavelengths = 1;
end

% Wavelength 2
if exist([dirnameOut, 'fw2.s1.inp'],'file')
config = read_tMCimg_inp([dirnameOut, 'fw2.s1.inp']);
fwmodel.nphotons = config.phot_num;
for ii=1:size(config.tiss_prop,1)
fwmodel.headvol.tiss_prop(ii).scattering(:,2) = config.tiss_prop(ii,1);
fwmodel.headvol.tiss_prop(ii).anisotropy(:,2) = config.tiss_prop(ii,2);
fwmodel.headvol.tiss_prop(ii).absorption(:,2) = config.tiss_prop(ii,3);
fwmodel.headvol.tiss_prop(ii).refraction(:,2) = config.tiss_prop(ii,4);
end
fwmodel.nWavelengths = 2;
end

fwmodel.nWavelengths = length(fwmodel.headvol.tiss_prop(1).scattering);
end
end

Expand Down
Loading