Startup
This commit is contained in:
@@ -104,8 +104,10 @@ public class ScreenPanel extends Panel {
|
||||
DiscretePositioner screen;
|
||||
DiscretePositioner filter;
|
||||
boolean showFit;
|
||||
boolean showProfile;
|
||||
Overlay[] userOv;
|
||||
Overlay[] fitOv;
|
||||
Overlay[] profileOv;
|
||||
Overlay errorOverlay;
|
||||
boolean requestCameraListUpdate;
|
||||
Integer localServerPort;
|
||||
@@ -320,6 +322,7 @@ public class ScreenPanel extends Panel {
|
||||
renderer.getPopupMenu().setVisible(false);
|
||||
|
||||
showFit = buttonFit.isSelected();
|
||||
showProfile = buttonProfile.isSelected();
|
||||
|
||||
pauseSelection.setVisible(false);
|
||||
pauseSelection.setMinValue(1);
|
||||
@@ -519,10 +522,13 @@ public class ScreenPanel extends Panel {
|
||||
final Object lockOverlays = new Object();
|
||||
|
||||
void manageFit(BufferedImage bi, Data data) {
|
||||
Overlay[] fo = ((bi == null) || (!showFit)) ? null : getFitOverlays(data);
|
||||
Overlay[][] fo = ((bi == null) || ((!showFit && !showProfile))) ? null : getFitOverlays(data);
|
||||
synchronized(lockOverlays){
|
||||
renderer.updateOverlays(fo, fitOv);
|
||||
fitOv = fo;
|
||||
fo = (fo==null) ? new Overlay[][]{null, null} : fo;
|
||||
renderer.updateOverlays(fo[0], profileOv);
|
||||
profileOv = fo[0];
|
||||
renderer.updateOverlays(fo[1], fitOv);
|
||||
fitOv = fo[1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,6 +580,7 @@ public class ScreenPanel extends Panel {
|
||||
|
||||
renderer.setShowReticle(false);
|
||||
renderer.removeOverlays(fitOv);
|
||||
renderer.removeOverlays(profileOv);
|
||||
renderer.removeOverlays(userOv);
|
||||
renderer.clear();
|
||||
renderer.resetZoom();
|
||||
@@ -931,7 +938,7 @@ public class ScreenPanel extends Panel {
|
||||
Pen penFit = new Pen(new Color(192, 105, 0), 1);
|
||||
Pen penCross = new Pen(new Color(192, 105, 0), 1);
|
||||
|
||||
Overlay[] getFitOverlays(Data data) {
|
||||
Overlay[][] getFitOverlays(Data data) {
|
||||
Overlays.Polyline hgaussian = null;
|
||||
Overlays.Polyline vgaussian = null;
|
||||
Overlays.Polyline hprofile = null;
|
||||
@@ -1033,36 +1040,40 @@ public class ScreenPanel extends Panel {
|
||||
if (rangePlot <= 0) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
try {
|
||||
double[] sum = data.integrateVertically(true);
|
||||
double[] saux = new double[sum.length];
|
||||
double[] saux = new double[sum.length];
|
||||
int[] p = new int[sum.length];
|
||||
//xCom = getCom(sum);
|
||||
double[] x_egu = renderer.getCalibration().getAxisX(sum.length);
|
||||
xCom = getCom(sum, x_egu);
|
||||
int[] x = Arr.indexesInt(sum.length);
|
||||
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
|
||||
double min = stats.getMin();
|
||||
for (int i = 0; i < sum.length; i++) {
|
||||
saux[i] = sum[i] - min;
|
||||
}
|
||||
|
||||
double[] gaussian = fitGaussian(saux, x);
|
||||
if (gaussian != null) {
|
||||
if ((gaussian[2] < sum.length * 0.45)
|
||||
&& (gaussian[2] > 2)
|
||||
&& (gaussian[0] > min * 0.03)) {
|
||||
xNorm = gaussian[0];
|
||||
xMean = gaussian[1];
|
||||
xSigma = gaussian[2];
|
||||
double[] fit = getFitFunction(gaussian, x);
|
||||
int[] y = new int[x.length];
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize));
|
||||
p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize));
|
||||
}
|
||||
vgaussian = new Overlays.Polyline(penFit, x, y);
|
||||
vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p);
|
||||
if (showFit){
|
||||
double[] gaussian = fitGaussian(saux, x);
|
||||
if (gaussian != null) {
|
||||
if ((gaussian[2] < sum.length * 0.45)
|
||||
&& (gaussian[2] > 2)
|
||||
&& (gaussian[0] > min * 0.03)) {
|
||||
xNorm = gaussian[0];
|
||||
xMean = gaussian[1];
|
||||
xSigma = gaussian[2];
|
||||
double[] fit = getFitFunction(gaussian, x);
|
||||
int[] y = new int[x.length];
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize));
|
||||
p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize));
|
||||
}
|
||||
vgaussian = new Overlays.Polyline(penFit, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showProfile){
|
||||
vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -1071,7 +1082,8 @@ public class ScreenPanel extends Panel {
|
||||
double[] sum = data.integrateHorizontally(true);
|
||||
double[] saux = new double[sum.length];
|
||||
int[] p = new int[sum.length];
|
||||
//yCom = getCom(sum);
|
||||
double[] y_egu = renderer.getCalibration().getAxisY(sum.length);
|
||||
yCom = getCom(sum, y_egu);
|
||||
int[] x = Arr.indexesInt(sum.length);
|
||||
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
|
||||
double min = stats.getMin();
|
||||
@@ -1079,25 +1091,29 @@ public class ScreenPanel extends Panel {
|
||||
saux[i] = sum[i] - min;
|
||||
}
|
||||
|
||||
double[] gaussian = fitGaussian(saux, x);
|
||||
if (gaussian != null) {
|
||||
//Only aknowledge beam fully inside the image and peak over 3% of min
|
||||
if ((gaussian[2] < sum.length * 0.45)
|
||||
&& (gaussian[2] > 2)
|
||||
&& (gaussian[0] > min * 0.03)) {
|
||||
yNorm = gaussian[0];
|
||||
yMean = gaussian[1];
|
||||
ySigma = gaussian[2];
|
||||
double[] fit = getFitFunction(gaussian, x);
|
||||
if (showFit){
|
||||
double[] gaussian = fitGaussian(saux, x);
|
||||
if (gaussian != null) {
|
||||
//Only aknowledge beam fully inside the image and peak over 3% of min
|
||||
if ((gaussian[2] < sum.length * 0.45)
|
||||
&& (gaussian[2] > 2)
|
||||
&& (gaussian[0] > min * 0.03)) {
|
||||
yNorm = gaussian[0];
|
||||
yMean = gaussian[1];
|
||||
ySigma = gaussian[2];
|
||||
double[] fit = getFitFunction(gaussian, x);
|
||||
|
||||
int[] y = new int[x.length];
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize);
|
||||
p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize);
|
||||
}
|
||||
hgaussian = new Overlays.Polyline(penFit, y, x);
|
||||
hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x);
|
||||
int[] y = new int[x.length];
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize);
|
||||
p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize);
|
||||
}
|
||||
hgaussian = new Overlays.Polyline(penFit, y, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showProfile){
|
||||
hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
@@ -1117,35 +1133,42 @@ public class ScreenPanel extends Panel {
|
||||
yMean = data.getY((int) Math.round(yMean));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Overlays.Crosshairs cross = null;
|
||||
Overlays.Text textFit = null;
|
||||
if ((xMean != null) && (yMean != null)) {
|
||||
textFit = new Overlays.Text(penFit,
|
||||
String.format("x: m=%1.1f \u03C3=%1.1f\ny: m=%1.1f \u03C3=%1.1f",xMean, xSigma, yMean, ySigma),
|
||||
new Font(Font.MONOSPACED, 0, 14), new Point(20, 20));
|
||||
textFit.setFixed(true);
|
||||
textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT);
|
||||
|
||||
Point center = new Point(xMean.intValue(), yMean.intValue());
|
||||
if (renderer.getCalibration() != null) {
|
||||
center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean));
|
||||
xSigma /= renderer.getCalibration().getScaleX();
|
||||
ySigma /= renderer.getCalibration().getScaleY();
|
||||
}
|
||||
cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue())));
|
||||
}
|
||||
|
||||
}
|
||||
final String units = (renderer.getCalibration() != null) ? "\u00B5m" : "px";
|
||||
final String fmt = "%7.1f" + units;
|
||||
Overlays.Text textCom = null;
|
||||
if ((xCom != null) && (yCom != null)) {
|
||||
textCom = new Overlays.Text(renderer.getPenProfile(),
|
||||
String.format("x: m=%1.1f \u03C3=%1.1f\ny: m=%1.1f \u03C3=%1.1f",xCom, xRms,yCom, yRms),
|
||||
new Font(Font.MONOSPACED, 0, 14), new Point(20, 60));
|
||||
textCom.setFixed(true);
|
||||
textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT);
|
||||
}
|
||||
return new Overlay[]{hprofile, vprofile, hgaussian, vgaussian, cross, textFit, textCom};
|
||||
Overlay[] pOv=null, fOv=null;
|
||||
Point textPosition = new Point(12, 20);
|
||||
if (showProfile){
|
||||
if ((xCom != null) && (yCom != null)) {
|
||||
String text = ((xRms != null) && (yRms != null)) ?
|
||||
String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt,xCom, xRms,yCom, yRms) :
|
||||
String.format("com x: m=" + fmt + "\ncom y: m=" + fmt ,xCom, yCom);
|
||||
textCom = new Overlays.Text(renderer.getPenProfile(), text, new Font(Font.MONOSPACED, 0, 14), textPosition);
|
||||
textCom.setFixed(true);
|
||||
textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT);
|
||||
}
|
||||
pOv = new Overlay[]{hprofile, vprofile, textCom};
|
||||
}
|
||||
if (showFit){
|
||||
Overlays.Crosshairs cross = null;
|
||||
Overlays.Text textFit = null;
|
||||
if ((xMean != null) && (yMean != null)) {
|
||||
String text = String.format("fit x: m=" + fmt + " \u03C3=" + fmt + "\nfit y: m=" + fmt + " \u03C3=" + fmt,xMean, xSigma, yMean, ySigma);
|
||||
textFit = new Overlays.Text(penFit, text, new Font(Font.MONOSPACED, 0, 14), showProfile ? new Point(12, 54) : textPosition );
|
||||
textFit.setFixed(true);
|
||||
textFit.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT);
|
||||
Point center = new Point(xMean.intValue(), yMean.intValue());
|
||||
if (renderer.getCalibration() != null) {
|
||||
center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean));
|
||||
xSigma /= renderer.getCalibration().getScaleX();
|
||||
ySigma /= renderer.getCalibration().getScaleY();
|
||||
}
|
||||
cross = new Overlays.Crosshairs(penCross, center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue())));
|
||||
}
|
||||
fOv = new Overlay[]{hgaussian, vgaussian, cross, textFit};
|
||||
}
|
||||
return new Overlay[][]{pOv, fOv};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1265,7 +1288,7 @@ public class ScreenPanel extends Panel {
|
||||
return ret.toArray(new Overlay[0]);
|
||||
}
|
||||
|
||||
double getCom(double[] arr) {
|
||||
double getCom(double[] arr, double[] x) {
|
||||
if (arr == null) {
|
||||
return Double.NaN;
|
||||
}
|
||||
@@ -1273,7 +1296,7 @@ public class ScreenPanel extends Panel {
|
||||
double ret = 0;
|
||||
double total = 0;
|
||||
for (double v : arr) {
|
||||
ret += (v * index++);
|
||||
ret += (v * x[index++]);
|
||||
total += v;
|
||||
}
|
||||
if (total == 0) {
|
||||
@@ -1637,6 +1660,7 @@ public class ScreenPanel extends Panel {
|
||||
buttonFit = new javax.swing.JToggleButton();
|
||||
buttonReticle = new javax.swing.JToggleButton();
|
||||
buttonPause = new javax.swing.JToggleButton();
|
||||
buttonProfile = new javax.swing.JToggleButton();
|
||||
jPanel6 = new javax.swing.JPanel();
|
||||
textState = new javax.swing.JTextField();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
@@ -1731,6 +1755,14 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
});
|
||||
|
||||
buttonProfile.setSelected(true);
|
||||
buttonProfile.setText("Profile");
|
||||
buttonProfile.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonProfileActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
|
||||
jPanel7.setLayout(jPanel7Layout);
|
||||
jPanel7Layout.setHorizontalGroup(
|
||||
@@ -1741,17 +1773,19 @@ public class ScreenPanel extends Panel {
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonMarker)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonProfile)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonFit)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonReticle)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGap(18, 18, Short.MAX_VALUE)
|
||||
.addComponent(buttonGrabBackground)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonSave)
|
||||
.addGap(0, 0, 0))
|
||||
);
|
||||
|
||||
jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonReticle});
|
||||
jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonProfile, buttonReticle});
|
||||
|
||||
jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave});
|
||||
|
||||
@@ -1765,7 +1799,8 @@ public class ScreenPanel extends Panel {
|
||||
.addComponent(buttonMarker)
|
||||
.addComponent(buttonSave)
|
||||
.addComponent(buttonReticle)
|
||||
.addComponent(buttonGrabBackground))
|
||||
.addComponent(buttonGrabBackground)
|
||||
.addComponent(buttonProfile))
|
||||
.addGap(0, 0, 0))
|
||||
);
|
||||
|
||||
@@ -2450,11 +2485,11 @@ public class ScreenPanel extends Panel {
|
||||
private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed
|
||||
try {
|
||||
showFit = buttonFit.isSelected();
|
||||
if (!buttonFit.isSelected()) {
|
||||
renderer.removeOverlays(fitOv);
|
||||
fitOv = null;
|
||||
} else {
|
||||
if (showFit) {
|
||||
renderer.setProfile(Renderer.Profile.None);
|
||||
} else {
|
||||
renderer.removeOverlays(fitOv);
|
||||
fitOv = null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
@@ -2741,6 +2776,20 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
}//GEN-LAST:event_buttonStopActionPerformed
|
||||
|
||||
private void buttonProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProfileActionPerformed
|
||||
try {
|
||||
showProfile = buttonProfile.isSelected();
|
||||
if (showProfile) {
|
||||
renderer.setProfile(Renderer.Profile.None);
|
||||
} else {
|
||||
renderer.removeOverlays(profileOv);
|
||||
profileOv = null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
}//GEN-LAST:event_buttonProfileActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton buttonArgs;
|
||||
private javax.swing.JRadioButton buttonAutomatic;
|
||||
@@ -2760,6 +2809,7 @@ public class ScreenPanel extends Panel {
|
||||
private javax.swing.JRadioButton buttonManual;
|
||||
private javax.swing.JToggleButton buttonMarker;
|
||||
private javax.swing.JToggleButton buttonPause;
|
||||
private javax.swing.JToggleButton buttonProfile;
|
||||
private javax.swing.JRadioButton buttonRainbow;
|
||||
private javax.swing.JToggleButton buttonReticle;
|
||||
private javax.swing.JToggleButton buttonSave;
|
||||
|
||||
Reference in New Issue
Block a user