-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathAlgorithmCapsule.java
More file actions
197 lines (167 loc) · 6.02 KB
/
AlgorithmCapsule.java
File metadata and controls
197 lines (167 loc) · 6.02 KB
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
188
189
190
191
192
193
194
195
196
197
/*
* DeconvolutionLab2
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*
* Reference: DeconvolutionLab2: An Open-Source Software for Deconvolution
* Microscopy D. Sage, L. Donati, F. Soulez, D. Fortun, G. Schmit, A. Seitz,
* R. Guiet, C. Vonesch, M Unser, Methods of Elsevier, 2017.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package deconvolution.capsule;
import java.awt.Point;
import java.awt.Rectangle;
import javax.swing.JSplitPane;
import javax.swing.JViewport;
import bilib.component.HTMLPane;
import bilib.table.CustomizedTable;
import bilib.tools.NumFormat;
import deconvolution.Deconvolution;
import deconvolution.Features;
import deconvolution.algorithm.Algorithm;
import deconvolution.algorithm.AlgorithmList;
import deconvolution.algorithm.AlgorithmPanel;
import deconvolutionlab.monitor.Monitors;
import fft.AbstractFFT;
import fft.FFT;
import signal.ComplexSignal;
import signal.RealSignal;
import signal.SignalCollector;
/**
* This class is a information module for the algorithm.
*
* @author Daniel Sage
*
*/
public class AlgorithmCapsule extends AbstractCapsule implements Runnable {
private CustomizedTable table;
private HTMLPane doc;
public AlgorithmCapsule(Deconvolution deconvolution) {
super(deconvolution);
doc = new HTMLPane(100, 100);
table = new CustomizedTable(new String[] { "Features", "Values" }, false);
split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, table.getPane(100, 100), doc.getPane());
split.setDividerLocation(0.5);
}
@Override
public void update() {
if (doc == null)
return;
if (table == null)
return;
table.removeRows();
table.append(new String[] { "PSF", "Waiting for loading ..." });
Thread thread = new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
@Override
public String getID() {
return "Algorithm";
}
@Override
public void run() {
Features features = new Features();
if (deconvolution.getAlgorithm() == null) {
features.add("Algorithm", "No valid algorithm");
return;
}
Algorithm algo = deconvolution.getAlgorithm();
doc.clear();
String name = algo.getShortnames()[0];
AlgorithmPanel algoPanel = AlgorithmList.getPanel(name);
if (algoPanel != null)
doc.append(algoPanel.getDocumentation());
String p = algo.getParametersAsString();
features.add("<html><b>Parameters</b></html>", p.equals("") ? "Parameters free" : p);
features.add("Iteration", algo.isIterative() ? "" + algo.getIterationsMax() : "Direct");
if (deconvolution.getImage() == null) {
startAsynchronousTimer("Open image", 200);
deconvolution.setImage(deconvolution.openImage());
stopAsynchronousTimer();
}
if (deconvolution.getImage() == null) {
features.add("Image", "No valid input image");
return;
}
if (deconvolution.getController().getPadding() == null) {
features.add("Padding", "No valid padding");
return;
}
if (deconvolution.getController().getApodization() == null) {
features.add("Apodization", "No valid apodization");
return;
}
if (deconvolution.getPSF() == null) {
startAsynchronousTimer("Open PSF", 200);
deconvolution.setPSF( deconvolution.openPSF());
stopAsynchronousTimer();
}
if (deconvolution.getPSF() == null) {
features.add("Image", "No valid PSF");
return;
}
startAsynchronousTimer("Check Algorithm", 200);
AbstractFFT f = FFT.getFastestFFT().getDefaultFFT();
double Q = Math.sqrt(2);
if (deconvolution.getImage() != null) {
int mx = deconvolution.getImage().nx;
int my = deconvolution.getImage().ny;
int mz = deconvolution.getImage().nz;
while (mx * my * mz > Math.pow(2, 15)) {
mx = (int)(mx / Q);
my = (int)(my / Q);
mz = (int)(mz / Q);
}
double N = deconvolution.getImage().nx * deconvolution.getImage().ny * deconvolution.getImage().nz;
double M = mx * my * mz;
double ratio = 1;
if (M != 0)
ratio = (N * Math.log(N)) / (M * Math.log(M));
double chrono = System.nanoTime();
RealSignal x = new RealSignal("test", mx, my, mz);
ComplexSignal c = new ComplexSignal("test", mx, my, mz);
f.init(Monitors.createDefaultMonitor(), mx, my, mz);
f.transform(x, c);
SignalCollector.free(x);
SignalCollector.free(c);
chrono = (System.nanoTime() - chrono);
double chronoI = chrono * ratio * algo.getComplexityNumberofFFT();
features.add("<html><b>Estimation</b></html>", "");
features.add("Estimated time", NumFormat.time(chronoI) );
features.add("Estimated number of FFTs", "" + algo.getComplexityNumberofFFT());
features.add("<html><b>Run on tiny dataset</b></html>", mx + "x" + my + "x" + mz);
features.add("Elapsed time", NumFormat.time(chrono) );
}
else
features.add("Estimated time", "Error" );
double mem = (algo.getMemoryFootprintRatio() * deconvolution.getImage().nx * deconvolution.getImage().ny * deconvolution.getImage().nz * 4);
features.add("Required memory", NumFormat.bytes(mem));
table.removeRows();
for (String[] feature : features)
table.append(feature);
Rectangle rect = table.getCellRect(0, 0, true);
Point pt = ((JViewport) table.getParent()).getViewPosition();
rect.setLocation(rect.x - pt.x, rect.y - pt.y);
stopAsynchronousTimer();
}
}