Startup
This commit is contained in:
@@ -132,31 +132,39 @@ public class ScreenPanel extends Panel {
|
||||
double[] getCamtoolDoubleArray(String name) {
|
||||
return (double[]) Convert.toDouble(((Camtool) camera).getValue(name));
|
||||
}
|
||||
|
||||
Double getCamtoolDouble(String name, StreamValue cache) {
|
||||
return (Double) Convert.toDouble(cache.__getitem__(name));
|
||||
}
|
||||
|
||||
double[] getCamtoolDoubleArray(String name, StreamValue cache) {
|
||||
return (double[]) Convert.toDouble(cache.__getitem__(name));
|
||||
}
|
||||
|
||||
|
||||
class ImageData {
|
||||
ImageData(){
|
||||
if (camera instanceof Camtool) {
|
||||
cache = ((Camtool) camera).getStream().take();
|
||||
StreamValue cache = ((Camtool) camera).getStream().take();
|
||||
|
||||
String prefix = goodRegion ? "gr_" : "";
|
||||
x_fit_mean = getDouble(prefix + "x_fit_mean");
|
||||
y_fit_mean = getDouble(prefix + "y_fit_mean");
|
||||
x_fit_standard_deviation = getDouble(prefix + "x_fit_standard_deviation");
|
||||
y_fit_standard_deviation = getDouble(prefix + "y_fit_standard_deviation");
|
||||
x_fit_gauss_function = getDoubleArray(prefix +"x_fit_gauss_function");
|
||||
y_fit_gauss_function = getDoubleArray(prefix +"y_fit_gauss_function");
|
||||
x_profile = getDoubleArray("x_profile");
|
||||
y_profile = getDoubleArray("y_profile");
|
||||
x_center_of_mass = getDouble("x_center_of_mass");
|
||||
y_center_of_mass = getDouble("y_center_of_mass");
|
||||
x_rms = getDouble("x_rms");
|
||||
y_rms = getDouble("y_rms");
|
||||
x_fit_mean = getCamtoolDouble(prefix + "x_fit_mean", cache);
|
||||
y_fit_mean = getCamtoolDouble(prefix + "y_fit_mean", cache);
|
||||
x_fit_standard_deviation = getCamtoolDouble(prefix + "x_fit_standard_deviation", cache);
|
||||
y_fit_standard_deviation = getCamtoolDouble(prefix + "y_fit_standard_deviation", cache);
|
||||
x_fit_gauss_function = getCamtoolDoubleArray(prefix +"x_fit_gauss_function", cache);
|
||||
y_fit_gauss_function = getCamtoolDoubleArray(prefix +"y_fit_gauss_function", cache);
|
||||
x_profile = getCamtoolDoubleArray("x_profile", cache);
|
||||
y_profile = getCamtoolDoubleArray("y_profile", cache);
|
||||
x_center_of_mass = getCamtoolDouble("x_center_of_mass", cache);
|
||||
y_center_of_mass = getCamtoolDouble("y_center_of_mass", cache);
|
||||
x_rms = getCamtoolDouble("x_rms", cache);
|
||||
y_rms = getCamtoolDouble("y_rms", cache);
|
||||
if (goodRegion){
|
||||
double[] gX2 = new double[x_profile.length];
|
||||
Arrays.fill(gX2, Double.NaN);
|
||||
try{
|
||||
double x = getDoubleArray("gr_x_axis")[0];
|
||||
double x = getCamtoolDoubleArray("gr_x_axis", cache)[0];
|
||||
System.arraycopy(x_fit_gauss_function, 0, gX2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x): x), x_fit_gauss_function.length);
|
||||
} catch (Exception ex){
|
||||
}
|
||||
@@ -164,7 +172,7 @@ public class ScreenPanel extends Panel {
|
||||
double[] gY2 = new double[y_profile.length];
|
||||
Arrays.fill(gY2, Double.NaN);
|
||||
try{
|
||||
double y = getDoubleArray("gr_y_axis")[0];
|
||||
double y = getCamtoolDoubleArray("gr_y_axis", cache)[0];
|
||||
System.arraycopy(y_fit_gauss_function, 0, gY2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageY(y): y), y_fit_gauss_function.length);
|
||||
} catch (Exception ex){
|
||||
}
|
||||
@@ -183,17 +191,7 @@ public class ScreenPanel extends Panel {
|
||||
public double[] x_profile;
|
||||
public double[] x_fit_gauss_function;
|
||||
public double[] y_profile;
|
||||
public double[] y_fit_gauss_function;
|
||||
|
||||
StreamValue cache;
|
||||
|
||||
Double getDouble(String name) {
|
||||
return (Double) Convert.toDouble(cache.__getitem__(name));
|
||||
}
|
||||
|
||||
double[] getDoubleArray(String name) {
|
||||
return (double[]) Convert.toDouble(cache.__getitem__(name));
|
||||
}
|
||||
public double[] y_fit_gauss_function;
|
||||
|
||||
}
|
||||
|
||||
@@ -206,6 +204,7 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
|
||||
final ArrayList<Frame> imageBuffer = new ArrayList();
|
||||
Frame currentFrame;
|
||||
int imageBufferLenght = 0;
|
||||
Text imageBufferOverlay;
|
||||
|
||||
@@ -671,6 +670,12 @@ public class ScreenPanel extends Panel {
|
||||
if (cameraName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (imageBuffer) {
|
||||
currentFrame = null;
|
||||
imageBuffer.clear();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null);
|
||||
@@ -752,11 +757,11 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
//renderer.setCalibration(camera.getCalibration());
|
||||
if (!renderer.isPaused()) {
|
||||
|
||||
if (imageBufferLenght > 1) {
|
||||
if (data != null) {
|
||||
synchronized (imageBuffer) {
|
||||
imageBuffer.add(new Frame(data));
|
||||
if (data != null) {
|
||||
synchronized (imageBuffer) {
|
||||
currentFrame =new Frame(data);
|
||||
if (imageBufferLenght > 1) {
|
||||
imageBuffer.add(currentFrame);
|
||||
if (imageBuffer.size() > imageBufferLenght) {
|
||||
imageBuffer.remove(0);
|
||||
}
|
||||
@@ -1011,31 +1016,25 @@ public class ScreenPanel extends Panel {
|
||||
Pen penCross = new Pen(new Color(192, 105, 0), 1);
|
||||
|
||||
|
||||
ImageData getCurrentImageData(){
|
||||
return getImageData(null);
|
||||
Frame getCurrentFrame(){
|
||||
if ((imageBufferLenght > 1) && (renderer.isPaused())) {
|
||||
int index = ((int) pauseSelection.getValue()) - 1;
|
||||
synchronized (imageBuffer) {
|
||||
return (index < imageBuffer.size()) ? imageBuffer.get(index) : null;
|
||||
}
|
||||
}
|
||||
return currentFrame;
|
||||
}
|
||||
|
||||
ImageData getImageData(Data data){
|
||||
ImageData id = null;
|
||||
if (renderer.isPaused()) {
|
||||
synchronized (imageBuffer) {
|
||||
if (data == null){
|
||||
int index = ((int) pauseSelection.getValue()) - 1;
|
||||
if (index < imageBuffer.size()) {
|
||||
data = imageBuffer.get(index).data;
|
||||
}
|
||||
}
|
||||
for (Frame f : imageBuffer) {
|
||||
if (f.data == data) {
|
||||
id = f;
|
||||
break;
|
||||
}
|
||||
Frame getFrame(Data data){
|
||||
synchronized (imageBuffer) {
|
||||
for (Frame f : imageBuffer) {
|
||||
if (f.data == data) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
id = new ImageData();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Overlay[][] getFitOverlays(Data data) {
|
||||
@@ -1054,7 +1053,7 @@ public class ScreenPanel extends Panel {
|
||||
if ((useCamtoolStats) && (camera instanceof Camtool)) {
|
||||
try {
|
||||
|
||||
ImageData id = getImageData(data);
|
||||
ImageData id = getFrame(data);
|
||||
if (id==null){
|
||||
return null;
|
||||
}
|
||||
@@ -1573,22 +1572,23 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
}
|
||||
|
||||
void writeFrameMetadata(String path, ImageData id) throws Exception{
|
||||
void writeFrameMetadata(String path, Frame frame) throws Exception{
|
||||
getContext().getDataManager().setAttribute("/", "Camera", String.valueOf(cameraName));
|
||||
getContext().getDataManager().setAttribute("/", "Screen", String.valueOf(valueScreen.getLabel().getText()));
|
||||
getContext().getDataManager().setAttribute("/", "Filter", String.valueOf(valueFilter.getLabel().getText()));
|
||||
Calibration cal = renderer.getCalibration();
|
||||
getContext().getDataManager().setAttribute("/", "Calibration", cal == null ? new double[]{1,1,0,0} :
|
||||
new double[]{cal.getScaleX(), cal.getScaleY(), cal.getOffsetX(), cal.getOffsetY()});
|
||||
new double[]{cal.getScaleX(), cal.getScaleY(), cal.getOffsetX(), cal.getOffsetY()});
|
||||
getContext().getDataManager().setAttribute(path, "Timestamp", Chrono.getTimeStr(frame.data.getTimestamp(), "HH:mm:ss.SSS"));
|
||||
if (camera instanceof Camtool){
|
||||
try{
|
||||
getContext().getDataManager().setAttribute("/", "ROI", ((Camtool) camera).getRoi());
|
||||
} catch (Exception ex){
|
||||
getContext().getDataManager().setAttribute("/", "ROI", new int[]{0,0,-1,-1});
|
||||
}
|
||||
if (id!=null){
|
||||
if (frame!=null){
|
||||
for (Field f:ImageData.class.getFields()){
|
||||
Object value = f.get(id);
|
||||
Object value = f.get(frame);
|
||||
getContext().getDataManager().setAttribute(path, f.getName(), (value == null) ? Double.NaN : value);
|
||||
}
|
||||
}
|
||||
@@ -1607,16 +1607,17 @@ public class ScreenPanel extends Panel {
|
||||
String path = "/data";
|
||||
String snapshotFile = null;
|
||||
synchronized (imageBuffer) {
|
||||
ImageData id = getCurrentImageData();
|
||||
//Object data = renderer.getData().getMatrix();
|
||||
Object data = Convert.toBidimensional(id.getDoubleArray("image"),
|
||||
//width & height are not always in the stream
|
||||
renderer.getData().getWidth(), renderer.getData().getHeight());
|
||||
getContext().getDataManager().setDataset(path, data, renderer.getData().isUnsigned());
|
||||
Frame id = getCurrentFrame();
|
||||
if (id==null){
|
||||
throw new Exception("No current image");
|
||||
}
|
||||
Object data = id.data.getMatrix();
|
||||
getContext().getDataManager().setDataset(path, data, id.data.isUnsigned());
|
||||
writeFrameMetadata(path, id);
|
||||
getContext().getDataManager().closeOutput();
|
||||
getContext().getDataManager().closeOutput();
|
||||
//Enforce the same timestamp to data & image files.
|
||||
snapshotFile = getContext().getSetup().expandPath("{images}/{date}_{time}_snapshot.png", getContext().getExecutionPars().getStart());
|
||||
//snapshotFile = getContext().getSetup().expandPath("{images}/{date}_{time}_snapshot.png", getContext().getExecutionPars().getStart());
|
||||
snapshotFile = getContext().getExecutionPars().getPath() + ".png";
|
||||
renderer.saveSnapshot(snapshotFile, "png", true);
|
||||
}
|
||||
|
||||
@@ -1670,7 +1671,7 @@ public class ScreenPanel extends Panel {
|
||||
Frame frame = imageBuffer.get(i);
|
||||
String path = "/data_" + i;
|
||||
getContext().getDataManager().setDataset(path, frame.data.getMatrix(), frame.data.isUnsigned());
|
||||
writeFrameMetadata(path, getImageData(frame.data));
|
||||
writeFrameMetadata(path, frame);
|
||||
x.add(frame.x_fit_mean);
|
||||
y.add(frame.y_fit_mean);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user