-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateNinjaCap.m
122 lines (101 loc) · 3.69 KB
/
generateNinjaCap.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
%% CODE FOR NINJACAP GENERATION
% Instructions to the user:
% 0. set up and install everything as described in the github HELP file
% here: https://github.com/neuluce/ninjaCap
% 1. provide probe file with name "probe.SD" in dir \userinput\probe.SD
% 2. run generateNinjaCap.m with head circumference(HC) in cm as input argument: e.g. generateNinjaCap(56)
% 3. when the files are generated, a blender workspace will be opened. Run
% the default python script (click <Text> -> <Run Script>, or press Alt+P.
% 4. your generated and assembled cap is saved in the folder \print\. Here
% you also find a default 3D printing profile for Cura LULZBOT TAZ 6 using
% ninjaflex.
function [] = generateNinjaCap(HC, head_model)
if ~exist('head_model','var')
head_model = 'Colin';
end
dirSave = pwd;
rootDir = fileparts(which(mfilename));
%% Change the current folder to the folder of this m-file.
% if(~isdeployed)
% rootDir = fileparts(which(mfilename));
% cd(rootDir);
% end
%% add this folder and subfolders to paths
% addpath(genpath(pwd))
%% AUTOMATED PANEL CREATION FROM SD FILES
% if you renamed your files, update the path and names here
if ~exist('HC','var')
HC = 56; % default cap size
end
circumference = HC; % cm (actual circumference, correction applied automatically)
%% CHECK FOR EXISTING AltasViewer FILE?
if exist([pwd filesep 'atlasViewer.mat'], 'file')
disp('An "atlasViewer.mat" file already exists.');
prompt = ['To overwrite file press Y/y otherwise N/n and confirm with Enter:'];
x = input(prompt,'s');
if (x == 'y') || (x=='Y')
delete([pwd filesep 'atlasViewer.mat'])
else
error('Stopped')
end
end
%% PREPARE ATLASVIEWER.MAT
% launch AtlasViewer
% DEPENDENCY HOMER 3 >> getAppDir()
%AtlasViewerGUI(pwd, [getAppDir() 'PACKAGES' filesep 'AtlasViewerGUI' filesep 'Data' filesep 'Colin'], 'userargs');
% appdir hardcoded
avMainFilepath = which('AtlasViewerGUI.m');
avAppDir = fileparts(avMainFilepath);
if strcmp(head_model,'Colin')
avDataDir = filesepStandard([avAppDir, '/Data/Colin']);
elseif strcmp(head_model,'ICBM')
avDataDir = filesepStandard([rootDir, '/Data/ICBM']);
else
disp('Specified head model does not exist')
return
end
AtlasViewerGUI(pwd, avDataDir, 'userargs');
% scale head to corrected circumference
generateScaleCircumference(circumference);
% load 10-10 points into AtlasViewer
generateLoad10_5();
% align to head surface
generateRegisterProbe();
% save state file
generateSaveViewerState();
%% RUN PANEL.m
cd(rootDir);
copyfile( [dirSave filesep 'atlasViewer.mat'],'.' );
panel('atlasViewer.mat', circumference);
drawnow
%% DELETE FILES
delete([pwd filesep 'atlasViewer.mat']);
% delete([pwd filesep 'digpts.txt']);
% delete([pwd filesep 'digpts2mc.txt']);
delete([dirSave filesep 'atlasViewer.mat']);
delete([dirSave filesep 'digpts.txt']);
delete([dirSave filesep 'digpts2mc.txt']);
%% RUN blender
system('wrkspace.blend')
%% Fix negitive z-coordinates issue with stl file
% I think this happens in Blender. This is a simple fix here but in the
% future need to fix in blender.
stl_files = dir(['print' filesep '*.stl']);
for u = 1:length(stl_files)
TR = stlread([stl_files(u).folder filesep stl_files(u).name]);
v = TR.Points;
idx = find(v(:,3) < 0);
v(idx,3) = 0;
f = TR.ConnectivityList;
TR = triangulation(f,v);
stlwrite( TR,[stl_files(u).folder filesep stl_files(u).name],'text');
end
%% COPY BLENDER OUTPUT TO WORKING DIRECTORY
if ~isdir([dirSave filesep 'print'])
mkdir([dirSave filesep 'print']);
end
copyfile( ['print' filesep '*.stl'], [dirSave filesep 'print'] );
copyfile( ['print' filesep '*.curaprofile'], [dirSave filesep 'print'] );
copyfile( 'stl_image.png', [dirSave filesep 'print'] );
cd(dirSave)
end