forked from LungNoodle/pulmonarytoolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PTKAddPaths.m
170 lines (144 loc) · 7.98 KB
/
PTKAddPaths.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
function PTKAddPaths(varargin)
reset = nargin > 0 && strcmp(varargin{1}, 'reset');
force = nargin > 0 && strcmp(varargin{1}, 'force');
if reset
path(pathdef);
force = true;
end
% This version number should be incremented whenever new paths are added to
% the list
PTKAddPaths_Version_Number = 6;
persistent PTK_PathsHaveBeenSet
full_path = mfilename('fullpath');
[path_root, ~, ~] = fileparts(full_path);
cached_pathname = [path_root '.' PTKAddPaths_Version_Number];
% We force a class reset if the paths have changed since the last run
clear_classes = ~isempty(PTK_PathsHaveBeenSet) && ~strcmp(PTK_PathsHaveBeenSet, cached_pathname);
if force || (isempty(PTK_PathsHaveBeenSet) || ~strcmp(PTK_PathsHaveBeenSet, cached_pathname))
path_folders = {};
% List of folders to add to the path
path_folders{end + 1} = '';
path_folders{end + 1} = 'User';
path_folders{end + 1} = 'bin';
path_folders{end + 1} = 'Gui';
path_folders{end + 1} = 'Library';
path_folders{end + 1} = 'Test';
path_folders{end + 1} = fullfile('Library', 'Airways');
path_folders{end + 1} = fullfile('Library', 'Analysis');
path_folders{end + 1} = fullfile('Library', 'Conversion');
path_folders{end + 1} = fullfile('Library', 'Dicom');
path_folders{end + 1} = fullfile('Library', 'GuiComponents');
path_folders{end + 1} = fullfile('Library', 'Lobes');
path_folders{end + 1} = fullfile('Library', 'Lungs');
path_folders{end + 1} = fullfile('Library', 'Registration');
path_folders{end + 1} = fullfile('Library', 'Segmentation');
path_folders{end + 1} = fullfile('Library', 'Test');
path_folders{end + 1} = fullfile('Library', 'Types');
path_folders{end + 1} = fullfile('Library', 'Vessels');
path_folders{end + 1} = fullfile('Library', 'Visualisation');
path_folders{end + 1} = 'Framework';
path_folders{end + 1} = 'Scripts';
path_folders{end + 1} = fullfile('External', 'coremat');
path_folders{end + 1} = fullfile('External', 'mim', 'Gui');
path_folders{end + 1} = fullfile('External', 'mim', 'Gui', 'Controllers');
path_folders{end + 1} = fullfile('External', 'mim', 'Gui', 'DatabaseSidePanel');
path_folders{end + 1} = fullfile('External', 'mim', 'Gui', 'Panels');
path_folders{end + 1} = fullfile('External', 'mim', 'Gui', 'PatientBrowser');
path_folders{end + 1} = fullfile('External', 'mim', 'Gui', 'Modes');
path_folders{end + 1} = fullfile('External', 'mim', 'Gui', 'Tools');
path_folders{end + 1} = fullfile('External', 'mim', 'Gui', 'ViewerPanel');
path_folders{end + 1} = fullfile('External', 'mim', 'Framework');
path_folders{end + 1} = fullfile('External', 'mim', 'Legacy');
path_folders{end + 1} = fullfile('External', 'mim', 'Library', 'Filters');
path_folders{end + 1} = fullfile('External', 'mim', 'Library', 'Visualisation');
path_folders{end + 1} = fullfile('External', 'mim', 'Library', 'Conversion');
path_folders{end + 1} = fullfile('External', 'mim', 'Library', 'File');
path_folders{end + 1} = fullfile('External', 'mim', 'Library', 'Segmentation');
path_folders{end + 1} = fullfile('External', 'mim', 'Library', 'Types');
path_folders{end + 1} = fullfile('External', 'mim', 'Library', 'Utilities');
path_folders{end + 1} = fullfile('External', 'mim', 'Viewer');
path_folders{end + 1} = fullfile('External', 'mim', 'WebSocket');
path_folders{end + 1} = fullfile('External', 'mim', 'WebSocket', 'StorageClass');
path_folders{end + 1} = fullfile('External', 'mim', 'WebSocket', 'Models');
path_folders{end + 1} = fullfile('External', 'mim', 'WebSocket', 'MimModelFramework');
path_folders{end + 1} = fullfile('External', 'gem');
path_folders{end + 1} = fullfile('External', 'matnat');
path_folders{end + 1} = fullfile('External', 'dicomat');
path_folders{end + 1} = fullfile('External', 'gerardus', 'matlab', 'PointsToolbox');
path_folders{end + 1} = fullfile('External', 'stlwrite');
path_folders{end + 1} = fullfile('External', 'npReg');
path_folders{end + 1} = fullfile('External', 'depmat');
path_folders{end + 1} = fullfile('External', 'MatlabWebSocket', 'src');
path_folders{end + 1} = fullfile('External', 'Nifti_tools');
path_folders{end + 1} = fullfile('External', 'jsonlab-1.5', 'jsonlab-1.5');
path_folders{end + 1} = fullfile('External', 'npReg', 'npRegLib');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'subfunctions');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'gipl');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'hdr');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'isi');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'mha');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'nii');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'par');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'v3d');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'vff');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'vmp');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'vtk');
path_folders{end + 1} = fullfile('External', 'ReadData3D', 'xif');
AddToPath(path_root, path_folders);
CoreAddPaths(varargin{:});
MatNatAddPaths(varargin{:});
% Now add the plugins (have to do this afterwards, because we rely on
% library functions, so the library paths have to be set first)
path_folders = {};
plugin_folders = CoreDiskUtilities.GetRecursiveListOfDirectories(fullfile(path_root, 'Gui', 'GuiPlugins'));
for folder = plugin_folders
path_folders{end + 1} = folder{1}.First;
end
plugin_folders = CoreDiskUtilities.GetRecursiveListOfDirectories(fullfile(path_root, 'Plugins'));
for folder = plugin_folders
path_folders{end + 1} = folder{1}.First;
end
plugin_folders = CoreDiskUtilities.GetRecursiveListOfDirectories(fullfile(path_root, 'External', 'mim', 'Plugins'));
for folder = plugin_folders
path_folders{end + 1} = folder{1}.First;
end
plugin_folders = CoreDiskUtilities.GetRecursiveListOfDirectories(fullfile(path_root, 'External', 'mim', 'Gui', 'GuiPlugins'));
for folder = plugin_folders
path_folders{end + 1} = folder{1}.First;
end
AddToPath('', path_folders);
PTK_PathsHaveBeenSet = cached_pathname;
end
% Add additional user-specific paths specified in the file
% User/PTKAddUserPaths.m if it exists
if ~PTKSoftwareInfo.DemoMode
user_function_name = 'PTKAddUserPaths';
user_add_paths_function = fullfile(path_root, 'User', [user_function_name '.m']);
if exist(user_add_paths_function, 'file')
if force
feval(user_function_name, 'force');
else
feval(user_function_name);
end
end
end
if clear_classes
close all
clear all classes
end
end
function AddToPath(path_root, path_folders)
full_paths_to_add = {};
% Get the full path for each folder but check it exists before adding to
% the list of paths to add
for i = 1 : length(path_folders)
full_path_name = fullfile(path_root, path_folders{i});
if exist(full_path_name, 'dir')
full_paths_to_add{end + 1} = full_path_name;
end
end
% Add all the paths together (much faster than adding them individually)
if ~isempty(full_paths_to_add)
addpath(full_paths_to_add{:});
end
end