reformat all

This commit is contained in:
lucas lelievre committed 2022-04-27 21:39:54 +02:00
1 parent 9d6dda8b17
commit 9e12958ca6
105 files changed
+10092 -9417

No files matched your search

@@ -32,37 +32,37 @@ import dev.slimevr.vr.processor.skeleton.SkeletonConfigValue;
public class AutoBoneWindow extends JFrame {
private EJBox pane;
private final transient VRServer server;
private final transient SkeletonConfigGUI skeletonConfig;
private final transient PoseRecorder poseRecorder;
private final transient AutoBone autoBone;
private transient Thread recordingThread = null;
private transient Thread saveRecordingThread = null;
private transient Thread autoBoneThread = null;
private JButton saveRecordingButton;
private JButton adjustButton;
private JButton applyButton;
private JLabel processLabel;
private JLabel lengthsLabel;
public AutoBoneWindow(VRServer server, SkeletonConfigGUI skeletonConfig) {
super("Skeleton Auto-Configuration");
this.server = server;
this.skeletonConfig = skeletonConfig;
this.poseRecorder = new PoseRecorder(server);
this.autoBone = new AutoBone(server);
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
add(new JScrollPane(pane = new EJBox(BoxLayout.PAGE_AXIS), ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED));
build();
}
private float processFrames(PoseFrames frames) {
return autoBone.processFrames(frames, autoBone.calcInitError, autoBone.targetHeight, (epoch) -> {
@@ -70,7 +70,7 @@ public class AutoBoneWindow extends JFrame {
lengthsLabel.setText(autoBone.getLengthsString());
});
}
@AWTThread
private void build() {
pane.add(new EJBox(BoxLayout.LINE_AXIS) {
@@ -82,15 +82,15 @@ public class AutoBoneWindow extends JFrame {
@Override
public void mouseClicked(MouseEvent e) {
// Prevent running multiple times
if(!isEnabled() || recordingThread != null) {
if (!isEnabled() || recordingThread != null) {
return;
}
Thread thread = new Thread() {
@Override
public void run() {
try {
if(poseRecorder.isReadyToRecord()) {
if (poseRecorder.isReadyToRecord()) {
setText("Recording...");
// 1000 samples at 20 ms per sample is 20 seconds
int sampleCount = server.config.getInt("autobone.sampleCount", 1000);
@@ -98,11 +98,11 @@ public class AutoBoneWindow extends JFrame {
Future<PoseFrames> framesFuture = poseRecorder.startFrameRecording(sampleCount, sampleRate);
PoseFrames frames = framesFuture.get();
LogManager.log.info("[AutoBone] Done recording!");
saveRecordingButton.setEnabled(true);
adjustButton.setEnabled(true);
if(server.config.getBoolean("autobone.saveRecordings", false)) {
if (server.config.getBoolean("autobone.saveRecordings", false)) {
setText("Saving...");
autoBone.saveRecording(frames);
}
@@ -112,12 +112,12 @@ public class AutoBoneWindow extends JFrame {
Thread.sleep(3000); // Wait for 3 seconds
return;
}
} catch(Exception e) {
} catch (Exception e) {
setText("Recording Failed...");
LogManager.log.severe("[AutoBone] Failed recording!", e);
try {
Thread.sleep(3000); // Wait for 3 seconds
} catch(Exception e1) {
} catch (Exception e1) {
// Ignore
}
} finally {
@@ -126,14 +126,14 @@ public class AutoBoneWindow extends JFrame {
}
}
};
recordingThread = thread;
thread.start();
}
});
}
});
add(saveRecordingButton = new JButton("Save Recording") {
{
setEnabled(poseRecorder.hasRecording());
@@ -141,34 +141,34 @@ public class AutoBoneWindow extends JFrame {
@Override
public void mouseClicked(MouseEvent e) {
// Prevent running multiple times
if(!isEnabled() || saveRecordingThread != null) {
if (!isEnabled() || saveRecordingThread != null) {
return;
}
Thread thread = new Thread() {
@Override
public void run() {
try {
Future<PoseFrames> framesFuture = poseRecorder.getFramesAsync();
if(framesFuture != null) {
if (framesFuture != null) {
setText("Waiting for Recording...");
PoseFrames frames = framesFuture.get();
if(frames.getTrackerCount() <= 0) {
if (frames.getTrackerCount() <= 0) {
throw new IllegalStateException("Recording has no trackers");
}
if(frames.getMaxFrameCount() <= 0) {
if (frames.getMaxFrameCount() <= 0) {
throw new IllegalStateException("Recording has no frames");
}
setText("Saving...");
autoBone.saveRecording(frames);
setText("Recording Saved!");
try {
Thread.sleep(3000); // Wait for 3 seconds
} catch(Exception e1) {
} catch (Exception e1) {
// Ignore
}
} else {
@@ -176,17 +176,17 @@ public class AutoBoneWindow extends JFrame {
LogManager.log.severe("[AutoBone] Unable to save, no recording was done...");
try {
Thread.sleep(3000); // Wait for 3 seconds
} catch(Exception e1) {
} catch (Exception e1) {
// Ignore
}
return;
}
} catch(Exception e) {
} catch (Exception e) {
setText("Saving Failed...");
LogManager.log.severe("[AutoBone] Failed to save recording!", e);
try {
Thread.sleep(3000); // Wait for 3 seconds
} catch(Exception e1) {
} catch (Exception e1) {
// Ignore
}
} finally {
@@ -195,14 +195,14 @@ public class AutoBoneWindow extends JFrame {
}
}
};
saveRecordingThread = thread;
thread.start();
}
});
}
});
add(adjustButton = new JButton("Auto-Adjust") {
{
// If there are files to load, enable the button
@@ -211,56 +211,56 @@ public class AutoBoneWindow extends JFrame {
@Override
public void mouseClicked(MouseEvent e) {
// Prevent running multiple times
if(!isEnabled() || autoBoneThread != null) {
if (!isEnabled() || autoBoneThread != null) {
return;
}
Thread thread = new Thread() {
@Override
public void run() {
try {
setText("Load...");
List<Pair<String, PoseFrames>> frameRecordings = autoBone.loadRecordings();
if(!frameRecordings.isEmpty()) {
if (!frameRecordings.isEmpty()) {
LogManager.log.info("[AutoBone] Done loading frames!");
} else {
Future<PoseFrames> framesFuture = poseRecorder.getFramesAsync();
if(framesFuture != null) {
if (framesFuture != null) {
setText("Waiting for Recording...");
PoseFrames frames = framesFuture.get();
if(frames.getTrackerCount() <= 0) {
if (frames.getTrackerCount() <= 0) {
throw new IllegalStateException("Recording has no trackers");
}
if(frames.getMaxFrameCount() <= 0) {
if (frames.getMaxFrameCount() <= 0) {
throw new IllegalStateException("Recording has no frames");
}
frameRecordings.add(Pair.of("<Recording>", frames));
} else {
setText("No Recordings...");
LogManager.log.severe("[AutoBone] No recordings found in \"" + AutoBone.getLoadDir().getPath() + "\" and no recording was done...");
try {
Thread.sleep(3000); // Wait for 3 seconds
} catch(Exception e1) {
} catch (Exception e1) {
// Ignore
}
return;
}
}
setText("Processing...");
LogManager.log.info("[AutoBone] Processing frames...");
FastList<Float> heightPercentError = new FastList<Float>(frameRecordings.size());
for(Pair<String, PoseFrames> recording : frameRecordings) {
for (Pair<String, PoseFrames> recording : frameRecordings) {
LogManager.log.info("[AutoBone] Processing frames from \"" + recording.getKey() + "\"...");
heightPercentError.add(processFrames(recording.getValue()));
LogManager.log.info("[AutoBone] Done processing!");
applyButton.setEnabled(true);
//#region Stats/Values
Float neckLength = autoBone.getConfig(SkeletonConfigValue.NECK);
Float chestDistance = autoBone.getConfig(SkeletonConfigValue.CHEST);
@@ -268,44 +268,44 @@ public class AutoBoneWindow extends JFrame {
Float hipWidth = autoBone.getConfig(SkeletonConfigValue.HIPS_WIDTH);
Float legsLength = autoBone.getConfig(SkeletonConfigValue.LEGS_LENGTH);
Float kneeHeight = autoBone.getConfig(SkeletonConfigValue.KNEE_HEIGHT);
float neckTorso = neckLength != null && torsoLength != null ? neckLength / torsoLength : 0f;
float chestTorso = chestDistance != null && torsoLength != null ? chestDistance / torsoLength : 0f;
float torsoWaist = hipWidth != null && torsoLength != null ? hipWidth / torsoLength : 0f;
float legTorso = legsLength != null && torsoLength != null ? legsLength / torsoLength : 0f;
float legBody = legsLength != null && torsoLength != null && neckLength != null ? legsLength / (torsoLength + neckLength) : 0f;
float kneeLeg = kneeHeight != null && legsLength != null ? kneeHeight / legsLength : 0f;
LogManager.log.info("[AutoBone] Ratios: [{Neck-Torso: " + StringUtils.prettyNumber(neckTorso) + "}, {Chest-Torso: " + StringUtils.prettyNumber(chestTorso) + "}, {Torso-Waist: " + StringUtils.prettyNumber(torsoWaist) + "}, {Leg-Torso: " + StringUtils.prettyNumber(legTorso) + "}, {Leg-Body: " + StringUtils.prettyNumber(legBody) + "}, {Knee-Leg: " + StringUtils.prettyNumber(kneeLeg) + "}]");
String lengthsString = autoBone.getLengthsString();
LogManager.log.info("[AutoBone] Length values: " + lengthsString);
lengthsLabel.setText(lengthsString);
}
if(!heightPercentError.isEmpty()) {
if (!heightPercentError.isEmpty()) {
float mean = 0f;
for(float val : heightPercentError) {
for (float val : heightPercentError) {
mean += val;
}
mean /= heightPercentError.size();
float std = 0f;
for(float val : heightPercentError) {
for (float val : heightPercentError) {
float stdVal = val - mean;
std += stdVal * stdVal;
}
std = (float) Math.sqrt(std / heightPercentError.size());
LogManager.log.info("[AutoBone] Average height error: " + StringUtils.prettyNumber(mean, 6) + " (SD " + StringUtils.prettyNumber(std, 6) + ")");
}
//#endregion
} catch(Exception e) {
} catch (Exception e) {
setText("Failed...");
LogManager.log.severe("[AutoBone] Failed adjustment!", e);
try {
Thread.sleep(3000); // Wait for 3 seconds
} catch(Exception e1) {
} catch (Exception e1) {
// Ignore
}
} finally {
@@ -314,21 +314,21 @@ public class AutoBoneWindow extends JFrame {
}
}
};
autoBoneThread = thread;
thread.start();
}
});
}
});
add(applyButton = new JButton("Apply Values") {
{
setEnabled(false);
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(!isEnabled()) {
if (!isEnabled()) {
return;
}
@@ -341,21 +341,21 @@ public class AutoBoneWindow extends JFrame {
});
}
});
pane.add(new EJBox(BoxLayout.LINE_AXIS) {
{
setBorder(new EmptyBorder(i(5)));
add(processLabel = new JLabel("Processing has not been started..."));
}
});
pane.add(new EJBox(BoxLayout.LINE_AXIS) {
{
setBorder(new EmptyBorder(i(5)));
add(lengthsLabel = new JLabel(autoBone.getLengthsString()));
}
});
// Pack and display
pack();
setLocationRelativeTo(null);