-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackgroundTask.java
More file actions
138 lines (91 loc) · 4.43 KB
/
Copy pathBackgroundTask.java
File metadata and controls
138 lines (91 loc) · 4.43 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
package wf.util;
import javafx.concurrent.Task;
import javafx.scene.chart.XYChart;
public class BackgroundTask extends Task<Object> {
private static DataHistoHandler dataHistoHandler = DataHistoHandler.getInstance();
private static final BackgroundTask INSTANCE = new BackgroundTask();
private int progressCounter;
private int numberOfSeries;
private int pointsOfSereis;
private double sumYValue;
private double bgValueAvg; //Average of the background t be subtracted
public static BackgroundTask getInstance() {
return INSTANCE;
}
@Override
public Object call() throws Exception {
return null;
}
public Task<Void> subtractBackground(int points, int seriesTotalNumber) {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
progressCounter = 0;
for(int channel = 0; channel < 4; channel++) {
//System.out.println("Channel: " + channel);
if(dataHistoHandler.getSeriesValues().get(channel).size() > 0) {
// number of series per channel
numberOfSeries = dataHistoHandler.getSeriesValues().get(channel).size();
//loop through all the series of a channel
for(int series = 0; series < numberOfSeries; series++) {
//System.out.println("Series: " + series);
//loop through the series for background subtraction
pointsOfSereis = dataHistoHandler.getSeriesValues()
.get(channel).get(series).getData().size();
sumYValue = 0;
XYChart.Series<Number, Number> genericSeries = new XYChart.Series<>();
genericSeries.setName(String.valueOf(series));
for(int p = 0; p < pointsOfSereis; p++) {
if(p < points) {
//execute background subtraction accessing Y data
sumYValue = sumYValue + (double) dataHistoHandler.getSeriesValues()
.get(channel).get(series).getData()
.get(p).getYValue();
//System.out.println("Sum Y Value " + sumYValue);
} else {
//Compute background to be subtracted
bgValueAvg = sumYValue / (double) points;
//System.out.println("Sum Y Value " + sumYValue);
//System.out.println("Points " + points);
//System.out.println("Background " + bgValueAvg);
//Copy raw Series into Processed Series corrected for background
dataHistoHandler.getSeriesValuesProc().get(channel)
.add(genericSeries);
//populating the series with data
for(int i = 0; i < pointsOfSereis; i++) {
dataHistoHandler.getSeriesValuesProc().get(channel)
.get(series).getData()
.add(new XYChart.Data<Number, Number>(i, (double) dataHistoHandler
.getSeriesValues().get(channel).get(series)
.getData().get(i).getYValue() - bgValueAvg));
}
DataWaveformHandler.getWaveforms().get(channel).get(series).set_wf_bg(round(bgValueAvg,3));
update(++progressCounter, seriesTotalNumber);
//this.updateProgress(progressCounter++, seriesTotalNumber);
//Progress is related to the channels processed
//System.out.println(progressCounter);
//System.out.println(seriesTotalNumber);
break;
}
}
}
}
//Progress is related to the channels processed
//this.updateProgress(channel+1, 4);
}
return null;
}
};
}
private double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();
long factor = (long) Math.pow(10, places);
value = value * factor;
long tmp = Math.round(value);
return (double) tmp / factor;
}
private void update(int value1, int value2) {
this.updateProgress(value1, value2);
//System.out.println("Value " + value);
}
}