Skip to content

Commit

Permalink
Shape layer refactoring
Browse files Browse the repository at this point in the history
See merge request main/Sumatra!1872

sumatra-commit: f197940db7cc0d694e67b822a712b542c8c3ce3f
  • Loading branch information
mickmack1213 authored and TIGERs GitLab committed Jul 8, 2024
1 parent 238b208 commit 7a4b8a6
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class ShapeLayerFactory
private int order;


public ShapeLayerIdentifier.ShapeLayerIdentifierBuilder layer(String name)
public ShapeLayerIdentifier.ShapeLayerIdentifierBuilder category(String name)
{
return ShapeLayerIdentifier.builder()
.layerName(name)
.category(name)
.orderId(order++);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ public class EAutoRefShapesLayer
private static final String AUTO_REFEREE = "AutoReferee";

public static final IShapeLayerIdentifier ENGINE = F.create(
F.layer("Engine").category(AUTO_REFEREE).visibleByDefault(true));
F.category(AUTO_REFEREE).layerName("Engine").visibleByDefault(true));
public static final IShapeLayerIdentifier LAST_BALL_CONTACT = F.create(
F.layer("Ball Contact").category(AUTO_REFEREE).visibleByDefault(true));
F.category(AUTO_REFEREE).layerName("Ball Contact").visibleByDefault(true));
public static final IShapeLayerIdentifier BALL_LEFT_FIELD = F.create(
F.layer("Ball Left Field").category(AUTO_REFEREE).visibleByDefault(true));
F.category(AUTO_REFEREE).layerName("Ball Left Field").visibleByDefault(true));
public static final IShapeLayerIdentifier ALLOWED_DISTANCES = F.create(
F.layer("Allowed Distances").category(AUTO_REFEREE).visibleByDefault(true));
F.category(AUTO_REFEREE).layerName("Allowed Distances").visibleByDefault(true));
public static final IShapeLayerIdentifier ALLOWED_DRIBBLING_DISTANCE = F.create(
F.layer("Allowed Dribbling Distances").category(AUTO_REFEREE).visibleByDefault(true));
F.category(AUTO_REFEREE).layerName("Allowed Dribbling Distances").visibleByDefault(true));
public static final IShapeLayerIdentifier VIOLATED_DISTANCES = F.create(
F.layer("Violated Distances").category(AUTO_REFEREE).visibleByDefault(true));
F.category(AUTO_REFEREE).layerName("Violated Distances").visibleByDefault(true));
public static final IShapeLayerIdentifier MODE = F.create(
F.layer("AutoRef Mode").category(AUTO_REFEREE).visibleByDefault(true));
F.category(AUTO_REFEREE).layerName("AutoRef Mode").visibleByDefault(true));
public static final IShapeLayerIdentifier PUSHING = F.create(
F.layer("Pushing Detector").category(AUTO_REFEREE).visibleByDefault(true));
F.category(AUTO_REFEREE).layerName("Pushing Detector").visibleByDefault(true));
public static final IShapeLayerIdentifier PASS_DETECTION = F.create(
F.layer("Pass Detection").category(AUTO_REFEREE).visibleByDefault(true));
F.category(AUTO_REFEREE).layerName("Pass Detection").visibleByDefault(true));
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
public final class EVisionFilterShapesLayer
{
private static final ShapeLayerFactory F = new ShapeLayerFactory(EVisionFilterShapesLayer.class, 10);
private static final String CATEGORY = "Vision Filter";
private static final String VISION_FILTER = "Vision Filter";

public static final IShapeLayerIdentifier QUALITY_SHAPES = F.create(
F.layer("Quality Inspector").category(CATEGORY));
F.category(VISION_FILTER).layerName("Quality Inspector"));
public static final IShapeLayerIdentifier CAM_INFO_SHAPES = F.create(
F.layer("Cam Info").category(CATEGORY));
F.category(VISION_FILTER).layerName("Cam Info"));
public static final IShapeLayerIdentifier VIEWPORT_SHAPES = F.create(
F.layer("Viewports").category(CATEGORY));
F.category(VISION_FILTER).layerName("Viewports"));
public static final IShapeLayerIdentifier ROBOT_TRACKER_SHAPES = F.create(
F.layer("Robot Trackers").category(CATEGORY)
F.category(VISION_FILTER).layerName("Robot Trackers")
.persistenceType(EShapeLayerPersistenceType.ALWAYS_PERSIST));
public static final IShapeLayerIdentifier ROBOT_QUALITY_INSPECTOR = F.create(
F.layer("Robot Quality Inspector").category(CATEGORY));
F.category(VISION_FILTER).layerName("Robot Quality Inspector"));
public static final IShapeLayerIdentifier BALL_TRACKER_SHAPES_IMPORTANT = F.create(
F.layer("Ball Trackers").category(CATEGORY));
F.category(VISION_FILTER).layerName("Ball Trackers"));
public static final IShapeLayerIdentifier BALL_TRACKER_SHAPES = F.create(
F.layer("Ball Trackers Debug").category(CATEGORY)
F.category(VISION_FILTER).layerName("Ball Trackers Debug")
.persistenceType(EShapeLayerPersistenceType.NEVER_PERSIST));
public static final IShapeLayerIdentifier VIRTUAL_BALL_SHAPES = F.create(
F.layer("Virtual Balls").category(CATEGORY));
F.category(VISION_FILTER).layerName("Virtual Balls"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ShapeMap createShapeMap()
}

ShapeMap shapeMap = new ShapeMap();
shapeMap.get(EWpShapesLayer.VISION).addAll(shapes);
shapeMap.get(EWpShapesLayer.RAW_VISION).addAll(shapes);
return shapeMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BorderVisCalc implements IWpCalc
@Override
public void process(final WorldFrameWrapper wfw, final ShapeMap shapeMap)
{
List<IDrawableShape> shapes = shapeMap.get(EWpShapesLayer.FIELD_BORDERS);
List<IDrawableShape> shapes = shapeMap.get(EWpShapesLayer.FIELD_LINES_REGULAR);

var widthHalf = Geometry.getFieldWidth() / 2.0;
var lengthHalf = Geometry.getFieldLength() / 2.0;
Expand All @@ -48,7 +48,7 @@ public void process(final WorldFrameWrapper wfw, final ShapeMap shapeMap)
drawLine(shapes, new DrawableShapeBoundary(Geometry.getPenaltyAreaOur()));
drawLine(shapes, new DrawableShapeBoundary(Geometry.getPenaltyAreaTheir()));

List<IDrawableShape> additionalShapes = shapeMap.get(EWpShapesLayer.FIELD_BORDERS_ADDITIONAL);
List<IDrawableShape> additionalShapes = shapeMap.get(EWpShapesLayer.FIELD_LINES_ADDITIONAL);
drawLine(additionalShapes, new DrawableLine(Vector2.fromX(-lengthHalf), Vector2.fromX(lengthHalf)));
drawLine(additionalShapes,
new DrawableLine(Vector2.fromXY(-lengthQuarter, -widthHalf), Vector2.fromXY(-lengthQuarter, widthHalf)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,50 @@ public final class EWpShapesLayer
{
private static final ShapeLayerFactory F = new ShapeLayerFactory(EWpShapesLayer.class, 10);
private static final String FIELD = "Field";
private static final String BALL_INFO = "Ball Info";
private static final String BOT_STATES = "Bot States";
private static final String BASIC = "Basic";
private static final String REFEREE = "Referee";

public static final IShapeLayerIdentifier FIELD_BORDERS = F.create(F.layer("Borders")
.category(FIELD)
.category(BASIC)
.visibleByDefault(true)
.orderId(-100));
public static final IShapeLayerIdentifier FIELD_BORDERS_ADDITIONAL = F.create(F.layer("Additional Borders")
.category(FIELD)
.orderId(-90)
.persistenceType(DEBUG_PERSIST));
public static final IShapeLayerIdentifier REFEREE = F.create(F.layer("Referee")
.category("Annotations")
.visibleByDefault(true));
public static final IShapeLayerIdentifier BALL_BUFFER = F.create(F.layer("Ball Buffer")
.category(FIELD)
.category("Buffers"));
public static final IShapeLayerIdentifier BOT_BUFFER = F.create(F.layer("Bot Buffers")
.category(FIELD)
.category("Buffers"));
public static final IShapeLayerIdentifier BOTS = F.create(F.layer("Bots")
.category(FIELD)
.category(BASIC)
.visibleByDefault(true));
public static final IShapeLayerIdentifier BOT_FEEDBACK = F.create(F.layer("Feedback")
.category(FIELD)
.category(BOT_STATES));
public static final IShapeLayerIdentifier BOT_FILTER = F.create(F.layer("Filtered")
.category(FIELD)
.category(BOT_STATES));
public static final IShapeLayerIdentifier BOT_PATTERNS = F.create(F.layer("Pattern")
.category(FIELD)
.category(BOT_STATES));
public static final IShapeLayerIdentifier BALL = F.create(F.layer("Ball")
.category(FIELD)
.category(BASIC)
.visibleByDefault(true));
public static final IShapeLayerIdentifier BALL_HIGHLIGHTER = F.create(F.layer("Ball Highlighter")
.category(FIELD)
.category(BALL_INFO));
public static final IShapeLayerIdentifier BALL_PREDICTION = F.create(F.layer("Prediction")
.category(FIELD)
.category(BALL_INFO));
public static final IShapeLayerIdentifier VELOCITY = F.create(F.layer("Velocities")
.category(FIELD));
public static final IShapeLayerIdentifier VISION = F.create(F.layer("Vision")
.category(FIELD));
private static final String FIELD_LINES = "Field Lines";
private static final String VISION = "Vision";
private static final String CAT_BOTS = "Bots";
private static final String CAT_BALL = "Ball";
private static final String BOT_STATES = "States";

public static final IShapeLayerIdentifier CAM_OBJECT_FILTER = F.create(F.layer("CamObject Filter")
.category(FIELD)
.category(BASIC)
.visibleByDefault(true));
public static final IShapeLayerIdentifier FIELD_LINES_REGULAR = F.create(
F.category(FIELD).category(FIELD_LINES).layerName("Regular").visibleByDefault(true).orderId(-100));
public static final IShapeLayerIdentifier FIELD_LINES_ADDITIONAL = F.create(
F.category(FIELD).category(FIELD_LINES).layerName("Additional").orderId(-90).persistenceType(DEBUG_PERSIST));

public static final IShapeLayerIdentifier REFEREE_HEADER = F.create(
F.category(REFEREE).layerName("Header").visibleByDefault(true));

public static final IShapeLayerIdentifier RAW_VISION = F.create(
F.category(FIELD).category(VISION).layerName("Raw Vision"));
public static final IShapeLayerIdentifier CAM_OBJECT_FILTER = F.create(
F.category(FIELD).category(VISION).layerName("CamObject Filter").visibleByDefault(true));

public static final IShapeLayerIdentifier BOTS = F.create(
F.category(FIELD).category(CAT_BOTS).layerName("Bots").visibleByDefault(true));
public static final IShapeLayerIdentifier BOT_VELOCITIES = F.create(
F.category(FIELD).category(CAT_BOTS).layerName("Velocities"));
public static final IShapeLayerIdentifier BOT_BUFFER = F.create(
F.category(FIELD).category(CAT_BOTS).layerName("Buffers"));
public static final IShapeLayerIdentifier BOT_PATTERNS = F.create(
F.category(FIELD).category(CAT_BOTS).layerName("Pattern"));

public static final IShapeLayerIdentifier BOT_FEEDBACK = F.create(
F.category(FIELD).category(CAT_BOTS).category(BOT_STATES).layerName("Feedback"));
public static final IShapeLayerIdentifier BOT_FILTER = F.create(
F.category(FIELD).category(CAT_BOTS).category(BOT_STATES).layerName("Filtered"));

public static final IShapeLayerIdentifier BALL = F.create(
F.category(FIELD).category(CAT_BALL).layerName("Ball").visibleByDefault(true));
public static final IShapeLayerIdentifier BALL_VELOCITY = F.create(
F.category(FIELD).category(CAT_BALL).layerName("Velocity"));
public static final IShapeLayerIdentifier BALL_BUFFER = F.create(
F.category(FIELD).category(CAT_BALL).layerName("Buffer"));

public static final IShapeLayerIdentifier BALL_HIGHLIGHTER = F.create(
F.category(FIELD).category(CAT_BALL).layerName("Highlighter").visibleByDefault(true));
public static final IShapeLayerIdentifier BALL_PREDICTION = F.create(
F.category(FIELD).category(CAT_BALL).layerName("Prediction"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public void process(final WorldFrameWrapper wfw, final ShapeMap shapeMap)
txtShapes.add(text(8, 2, proposedGameEvents));
txtShapes.add(text(8, 3, getSubstitutionString(msg)));

shapeMap.get(EWpShapesLayer.REFEREE).addAll(txtShapes);
paintShapes(shapeMap.get(EWpShapesLayer.REFEREE), wfw);
shapeMap.get(EWpShapesLayer.REFEREE_HEADER).addAll(txtShapes);
paintShapes(shapeMap.get(EWpShapesLayer.REFEREE_HEADER), wfw);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import edu.tigers.sumatra.drawable.DrawableAnnotation;
import edu.tigers.sumatra.drawable.DrawableLine;
import edu.tigers.sumatra.drawable.IDrawableShape;
import edu.tigers.sumatra.drawable.ShapeMap;
import edu.tigers.sumatra.math.line.Lines;
import edu.tigers.sumatra.wp.data.ITrackedBall;
Expand All @@ -15,7 +14,6 @@

import java.awt.Color;
import java.text.DecimalFormat;
import java.util.List;


/**
Expand All @@ -29,15 +27,13 @@ public class VelocityVisCalc implements IWpCalc
@Override
public void process(final WorldFrameWrapper wfw, final ShapeMap shapeMap)
{
List<IDrawableShape> shapes = shapeMap.get(EWpShapesLayer.VELOCITY);

ITrackedBall ball = wfw.getSimpleWorldFrame().getBall();
if (ball.getVel().getLength() > 0.1)
{
var ballVelLine = Lines.segmentFromOffset(ball.getPos(), ball.getVel().multiplyNew(1000));
DrawableLine dBallVelLine = new DrawableLine(ballVelLine, Color.cyan);
dBallVelLine.setStrokeWidth(20);
shapes.add(dBallVelLine);
shapeMap.get(EWpShapesLayer.BALL_VELOCITY).add(dBallVelLine);
}

for (ITrackedBot bot : wfw.getSimpleWorldFrame().getBots().values())
Expand All @@ -47,11 +43,11 @@ public void process(final WorldFrameWrapper wfw, final ShapeMap shapeMap)
var velLine = Lines.segmentFromOffset(bot.getPos(), bot.getVel().multiplyNew(1000));
DrawableLine line = new DrawableLine(velLine, Color.cyan);
line.setStrokeWidth(20);
shapes.add(line);
shapeMap.get(EWpShapesLayer.BOT_VELOCITIES).add(line);
final DrawableAnnotation annotation = new DrawableAnnotation(velLine.getPathEnd(),
df.format(bot.getVel().getLength2()));
annotation.setColor(Color.cyan);
shapes.add(annotation);
shapeMap.get(EWpShapesLayer.BOT_VELOCITIES).add(annotation);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import edu.tigers.sumatra.views.ESumatraViewType;
import edu.tigers.sumatra.views.EViewMode;
import edu.tigers.sumatra.views.ISumatraPresenter;
import edu.tigers.sumatra.visualizer.VisualizerPresenter;
import edu.tigers.sumatra.wp.IWorldFrameObserver;
import edu.tigers.sumatra.wp.data.WorldFrameWrapper;
import lombok.extern.log4j.Log4j2;
Expand Down Expand Up @@ -80,6 +81,12 @@ public ReplayPresenter(AMainFrame mainFrame)
{
replayControlPresenter = (ReplayControlPresenter) view.getPresenter();
}

if (view.getType() == ESumatraViewType.VISUALIZER)
{
var visualizerPresenter = (VisualizerPresenter) view.getPresenter();
visualizerPresenter.setPropertiesPrefix(ReplayPresenter.class.getCanonicalName() + ".VisualizerPresenter.");
}
}

List<IWorldFrameObserver> wFrameObservers = getMainFrame().getObservers(IWorldFrameObserver.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import edu.tigers.sumatra.wp.AWorldPredictor;
import edu.tigers.sumatra.wp.IWorldFrameObserver;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;

Expand Down Expand Up @@ -60,6 +61,9 @@ public class VisualizerPresenter implements ISumatraViewPresenter, IWorldFrameOb
viewPanel.getFieldPanel()
);

@Setter
private String propertiesPrefix = VisualizerPresenter.class.getCanonicalName() + ".";

private final BallInteractor ballInteractor = new BallInteractor();
private final MediaRecorder mediaRecorder = new MediaRecorder();
private Thread updateThread;
Expand Down Expand Up @@ -140,10 +144,10 @@ private void setShapeSelectionPanelVisibility(boolean visible)

private void connect(JTextField textField, String key, String defValue, Consumer<String> consumer)
{
String value = SumatraModel.getInstance().getUserProperty(VisualizerPresenter.class, key, defValue);
String value = SumatraModel.getInstance().getUserProperty(propertiesPrefix + key, defValue);
textField.setText(value);
textField.getDocument().addDocumentListener((SimpleDocumentListener) e -> {
SumatraModel.getInstance().setUserProperty(VisualizerPresenter.class, key, textField.getText());
SumatraModel.getInstance().setUserProperty(propertiesPrefix + key, textField.getText());
consumer.accept(textField.getText());
});
consumer.accept(textField.getText());
Expand All @@ -152,11 +156,11 @@ private void connect(JTextField textField, String key, String defValue, Consumer

private void connect(AbstractButton button, String key, boolean defValue, Consumer<Boolean> consumer)
{
boolean value = SumatraModel.getInstance().getUserProperty(VisualizerPresenter.class, key, defValue);
boolean value = SumatraModel.getInstance().getUserProperty(propertiesPrefix + key, defValue);
button.setSelected(value);
button.addActionListener(e -> consumer.accept(button.isSelected()));
button.addActionListener(e -> SumatraModel.getInstance()
.setUserProperty(VisualizerPresenter.class, key, String.valueOf(button.isSelected())));
.setUserProperty(propertiesPrefix + key, String.valueOf(button.isSelected())));
consumer.accept(button.isSelected());
}

Expand Down Expand Up @@ -270,7 +274,7 @@ private void updateVisibility()
shapeSelectionModel.getLayers().forEach((layer, node) -> {
boolean visible = isSelected(node);
fieldPresenter.setShapeLayerVisibility(layer.getId(), visible);
SumatraModel.getInstance().setUserProperty(layer.getId(), String.valueOf(visible));
SumatraModel.getInstance().setUserProperty(propertiesPrefix + layer.getId(), String.valueOf(visible));
});
viewPanel.getShapeSelectionPanel().getTree().updateUI();
}
Expand All @@ -296,7 +300,7 @@ private void setDefaultVisibility(DefaultMutableTreeNode node)
if (node.getUserObject() instanceof IShapeLayerIdentifier shapeLayer)
{
boolean visible = SumatraModel.getInstance().getUserProperty(
shapeLayer.getId(),
propertiesPrefix + shapeLayer.getId(),
shapeLayer.isVisibleByDefault()
);
if (visible)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@
public final class EFieldPanelShapeLayer
{
private static final ShapeLayerFactory F = new ShapeLayerFactory(EFieldPanelShapeLayer.class, 50);
private static final String CATEGORY = "Panel";
private static final String PANEL = "Panel";

public static final IShapeLayerIdentifier FPS = F.create(F.layer("FPS")
.category(CATEGORY)
.visibleByDefault(true));
public static final IShapeLayerIdentifier COORDINATES = F.create(F.layer("Coordinates")
.category(CATEGORY)
.visibleByDefault(true));
public static final IShapeLayerIdentifier RULER = F.create(F.layer("Ruler")
.category(CATEGORY)
.visibleByDefault(true));
public static final IShapeLayerIdentifier RECORDING = F.create(F.layer("Recording")
.category(CATEGORY)
.visibleByDefault(true));
public static final IShapeLayerIdentifier FPS = F.create(
F.category(PANEL).layerName("FPS").visibleByDefault(true));
public static final IShapeLayerIdentifier COORDINATES = F.create(
F.category(PANEL).layerName("Coordinates").visibleByDefault(true));
public static final IShapeLayerIdentifier RULER = F.create(
F.category(PANEL).layerName("Ruler").visibleByDefault(true));
public static final IShapeLayerIdentifier RECORDING = F.create(
F.category(PANEL).layerName("Recording").visibleByDefault(true));
}
Loading

0 comments on commit 7a4b8a6

Please sign in to comment.