-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
188 lines (165 loc) · 7.39 KB
/
main.cpp
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// MarkerAlignator.cpp : Defines the entry point for the console application.
//
#include "MarkerFile.h"
#include "getopt_pp.h"
#include <stdio.h>
#define PBSTR "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
#define PBWIDTH 60
using namespace std;
using namespace GetOpt;
static void status(int percent)
{
int val = (int) (percent);
int lpad = (int) (percent/100. * PBWIDTH);
int rpad = PBWIDTH - lpad;
printf ("\r%3d%% [%.*s%*s]", val, lpad, PBSTR, rpad, "");
fflush(stdout);
//cout << percent << "%" << endl;
}
static void show_usage(){
string msg = "cAligner aligns tomographic tilt series based on fiducial marker positions on the projection images.\n"
"\n"
"Usage:\n"
"\tcAligner -input FILE -output FILE [OPTIONAL PARAMETERS]\n"
"\n"
"I/O (required):\n"
"\t-i; --input \t\t Input filename.\n"
"\t-o; --output \t\t Output filename.\n"
"\n"
"Alignment parameters:\n"
"\t-a; --activeMarker \t Marker to center alignment around (default 0).\n"
"\t-w; --width \t\t Projection width in pixels (default 7420).\n"
"\t-h; --height \t\t Projection height in pixels (default 7676).\n"
"\t--maAmount \t\t Magnification Anisotropy amount (default 1).\n"
"\t--maAangle \t\t Magnification Anisotropy angle in degrees (default 0).\n"
"\t--phi \t\t\t Beam declination angle in degrees (default 0).\n"
"\t--iter \t\t\t Number of iterations to run (default 20).\n"
"\t--iterSwitch \t\t Iteration after which to switch between theta/mags (default 10).\n"
"\t--zShift \t\t Additional z-shift applied during alignment.\n"
"\n"
"Alignment types:\n"
"\t--doPsi \t\t Align for image rotation.\n"
"\t--doFixedPsi \t\t Keep image rotation constant for all projections.\n"
"\t--doTheta \t\t Align tilt angles.\n"
"\t--doPhi \t\t Align for beam declination.\n"
"\t--doMags \t\t Align for magnification change.\n"
"\t--normMin \t\t Normalize mag change by minimum value\n"
"\t--normZeroTile \t\t Normalize mag change by 0-deg projection\n"
"\t--magsFirst \t\t Align for mag change first, then tilt angles\n";
cout << msg << endl;
}
static void print_params(int& activeMarker, int& width, int& height, float& phi, bool& doPsi, bool& doFixedPsi, bool& doTheta,
bool& doPhi, bool& doMags, bool& normMin, bool& normZeroTilt, bool& magsFirst, int& iterSwitch, int& iter, float& zShift){
string msg = "Alignment parameters:\n"
"\t Active marker:\t\t %d\n"
"\t Projection dimensions:\t %d x %d\n"
"\t Beam declination:\t %f\n"
"\t Additional z-shift:\t %f\n"
"\t Iterations:\t\t %d\n"
"\t Switching after:\t %d\n"
"\n"
"Aligning for:\n"
"\t Image rotation:\t\t %s (%s)\n"
"\t Tilt angles:\t\t\t %s\n"
"\t Beam declination:\t\t %s\n"
"\t Magnification change:\t\t %s\n"
"\t\t normalized by minimum:\t\t %s\n"
"\t\t normalized by maximum:\t\t %s\n"
"\t\t normalized by 0-deg projection: %s\n";
printf(msg.c_str(),
activeMarker,
width, height,
phi,
zShift,
iter,
iterSwitch,
doPsi?"true":"false", doFixedPsi?"fixed":"not fixed",
doTheta?"true":"false",
doPhi?"true":"false",
doMags?"true":"false",
normMin?"true":"false",
!(normMin || normZeroTilt)?"true":"false",
normZeroTilt?"true":"false");
}
int main(int argc, char* argv[])
{
// file names
string inputName = "";
string outputName = "";
// alignment parameters
int activeMarker = 0;
int width = 7420;
int height = 7676;
float magAnisotropyAmount = 1.;
float magAnisotropyAngle = 0.;
float phi = 0;
int iter = 20;
int iterSwitch = 10;
float zShift = 0;
// alignment type
bool doPsi = true;
bool doFixedPsi = false;
bool doTheta = true;
bool doPhi = false;
bool doMags = false;
bool normMin = false;
bool normZeroTilt = false;
bool magsFirst = false;
GetOpt_pp ops(argc, argv);
if (ops >> OptionPresent("help")){
show_usage();
return 0;
}
if (!(ops >> OptionPresent('i', "input")) || !(ops >> OptionPresent('o', "output"))){
cout << "Input and output names are required parameters." << endl;
return -1;
}
doPsi = (ops >> OptionPresent("doPsi"));
doFixedPsi = (ops >> OptionPresent("doFixedPsi"));
doTheta = (ops >> OptionPresent("doTheta"));
doPhi = (ops >> OptionPresent("doPhi"));
doMags = (ops >> OptionPresent("doMags"));
normMin = (ops >> OptionPresent("normMin"));
normZeroTilt = (ops >> OptionPresent("normZeroTilt"));
magsFirst = (ops >> OptionPresent("magsFirst"));
ops >> Option('i', "input", inputName)
>> Option('o', "output", outputName)
>> Option('a', "activeMarker", activeMarker)
>> Option('w', "width", width)
>> Option('h', "height", height)
>> Option("maAmount", magAnisotropyAmount)
>> Option("maAngle", magAnisotropyAngle)
>> Option("phi", phi)
>> Option("iter", iter)
>> Option("iterSwitch", iterSwitch)
>> Option("zShift", zShift);
MarkerFile marker(inputName);
float error = 0;
cout << "Using marker #" << activeMarker+1 << endl;
auto* perProj = new float[marker.GetProjectionCount()];
auto* perMarker = new float[marker.GetMarkerCount()];
auto* x = new float[marker.GetMarkerCount()];
auto* y = new float[marker.GetMarkerCount()];
auto* z = new float[marker.GetMarkerCount()];
//int width = 927;
//int height = 959;
//marker.SetMagAnisotropy(1.016f, 42.0f, 3720*2,3838*2);
marker.SetMagAnisotropy(magAnisotropyAmount, magAnisotropyAngle, (float)width, (float)height);
//cout << "Aligning for beam declination ..." << endl;
//marker.Align3D(activeMarker, width, height, error, phi, true, true, false, true, false, false, false, false, 0, 20, 0, perProj, perMarker, x, y, z, &status);
//cout << "Phi: " << phi << endl;
//cout << "Error score: " << error << endl;
print_params(activeMarker, width, height, phi, doPsi, doFixedPsi, doTheta, doPhi, doMags, normMin, normZeroTilt, magsFirst, iterSwitch, iter, zShift);
cout << "Starting Alignment ..." << endl;
marker.Align3D(activeMarker, width, height, error, phi, doPsi, doFixedPsi, doTheta, doPhi, doMags, normMin, normZeroTilt, magsFirst, iterSwitch, iter, 0, perProj, perMarker, x, y, z, &status);
cout << endl;
cout << "Phi: " << phi << endl;
cout << "Error score: " << error << endl;
//cout << "Aligning for tilt angles and image rotation ..." << endl;
//marker.Align3D(activeMarker, width, height, error, phi, true, false, true, false, false, false, false, false, 5, 20, 0, perProj, perMarker, x, y, z, &status);
//cout << "Error score: " << error << endl;
string name(outputName);
//cout << "Name: " << name << endl;
marker.Save(name);
return 0;
}