Skip to content

Commit

Permalink
Feature/gui tools (#195)
Browse files Browse the repository at this point in the history
Co-authored-by: James Foster <jfoster@ihmc.org>
  • Loading branch information
PotatoPeeler3000 and james-p-foster authored Nov 13, 2024
1 parent cf4bf8f commit 5409289
Show file tree
Hide file tree
Showing 10 changed files with 877 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package us.ihmc.scs2.examples.simulations;

import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import us.ihmc.scs2.SimulationConstructionSet2;
import us.ihmc.yoVariables.math.YoMatrix;

public class YoHeatMapGraphic
{
public static void main(String[] args)
{
SimulationConstructionSet2 scs = new SimulationConstructionSet2(SimulationConstructionSet2.doNothingPhysicsEngine());
YoMatrix matrix = new YoMatrix("matrix", 3, 3, scs.getRootRegistry());
for (int row = 0; row < matrix.getNumRows(); row++)
{
for (int column = 0; column < matrix.getNumCols(); column++)
{
matrix.set(row, column, Math.random());
}
}

scs.start(true, false, false);

Platform.runLater(() ->
{
Stage window = new Stage();
window.setTitle("YoHeatMapGraphic");
HeatMapPane heatMapPane = new HeatMapPane();
heatMapPane.matrixProperty.setValue(matrix);
heatMapPane.start();
window.setScene(new Scene(heatMapPane, 600, 400));

window.setOnCloseRequest(e -> heatMapPane.stop());
scs.addVisualizerShutdownListener(window::close);
window.show();
});
}

private static class HeatMapPane extends GridPane
{

private StackPane[][] cells;
private final Property<YoMatrix> matrixProperty = new SimpleObjectProperty<>(this, "matrix", null);
private final AnimationTimer animationTimer;

public HeatMapPane()
{
setVgap(2.0);
setHgap(2.0);
setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);

setStyle("-fx-background-color: grey;");

animationTimer = new AnimationTimer()
{
@Override
public void handle(long now)
{
YoMatrix matrix = matrixProperty.getValue();
if (matrix == null)
{
getChildren().clear();
cells = null;
return;
}

double max = Double.NEGATIVE_INFINITY;
double min = Double.POSITIVE_INFINITY;

for (int row = 0; row < matrix.getNumRows(); row++)
{
for (int column = 0; column < matrix.getNumCols(); column++)
{
double value = matrix.get(row, column);
max = Math.max(max, value);
min = Math.min(min, value);
}
}

if (cells == null || cells.length != matrix.getNumRows() || cells[0].length != matrix.getNumCols())
{
getChildren().clear();
cells = new StackPane[matrix.getNumRows()][matrix.getNumCols()];

for (int row = 0; row < matrix.getNumRows(); row++)
{
for (int column = 0; column < matrix.getNumCols(); column++)
{
StackPane cell = new StackPane();
cell.setMinSize(1.0, 1.0);
cell.setPrefSize(10.0, 10.0);
cell.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
cells[row][column] = cell;
add(cell, column, row);
GridPane.setHgrow(cell, Priority.ALWAYS);
GridPane.setVgrow(cell, Priority.ALWAYS);
}
}
}

for (int row = 0; row < matrix.getNumRows(); row++)
{
for (int column = 0; column < matrix.getNumCols(); column++)
{
double value = matrix.get(row, column);
double normalizedValue = (value - min) / (max - min);
// Render the value at (row, column) with normalizedValue
double hue = 240.0 * normalizedValue;
cells[row][column].setStyle("-fx-background-color: hsb(" + hue + ", 100%, 100%);");
}
}
}
};
}

public void start()
{
animationTimer.start();
}

public void stop()
{
animationTimer.stop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public class SessionVisualizerIOTools
private static final String YO_GRAPHIC_2D = YO_GRAPHIC + "graphic2D/";
private static final String YO_GRAPHIC_3D = YO_GRAPHIC + "graphic3D/";
private static final String YO_GRAPHIC_GROUP = YO_GRAPHIC + "group/";
private static final String YO_PIE_CHART = "yoPieChart/";
private static final String YO_EDITOR = "editor/";
private static final String YO_SLIDERBOARD = "yoSliderboard/";
private static final String YO_SLIDERBOARD_BCF2000 = YO_SLIDERBOARD + "bcf2000/";
Expand Down Expand Up @@ -164,6 +165,8 @@ public class SessionVisualizerIOTools
public static final URL PLOTTER2D_OPTIONS_STAGE_URL = getFXMLResource(YO_GRAPHIC, "Plotter2DOptionsStage");
public static final URL CAMERA3D_OPTIONS_PANE_URL = getFXMLResource("camera/Camera3DOptionsPane");

public static final URL YO_PIE_CHART_WINDOW_URL = getFXMLResource(YO_PIE_CHART, "YoPieChartWindow");

public static final URL CHART_PANEL_FXML_URL = getFXMLResource(CHART, "YoChartPanel");
public static final URL CHART_GROUP_PANEL_URL = getFXMLResource(CHART, "YoChartGroupPanel");
public static final URL CHART_GROUP_MODEL_EDITOR_PANE_URL = getFXMLResource(CHART, "YoChartGroupModelEditorPane");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ private void updateMenuItemText()
}
}

@FXML
public void openPieChartWindow()
{
messager.submitMessage(topics.getOpenWindowRequest(), NewWindowRequest.pieChartWindow(owner));
}

@FXML
public void loadChartGroup()
{
Expand Down
Loading

0 comments on commit 5409289

Please sign in to comment.