Skip to content

Commit 8df0ba7

Browse files
authored
Wpi field images (#6)
* Delete field configurations * Add WPI field image files * Refactor field image files * Changed extra field images to use WPILib format * Refactor DefaultFieldImages with new WPILib fields * Fixed DefaultFieldImage * WPILib fields fully integrated
1 parent 5c62337 commit 8df0ba7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+493
-288
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ repositories {
2020
url = uri("https://jitpack.io")
2121
}
2222
maven {
23-
url = uri("https://maven.pkg.github.com/jlbabilino/HelixTrajectory")
23+
url = uri("https://maven.pkg.github.com/SleipnirGroup/TrajoptLib")
2424
credentials {
2525
username = "jlbabilino"
26-
password = "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"
26+
password = "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"
2727
}
2828
}
2929
}

app/src/main/java/org/team2363/helixnavigator/document/field/configuration/HDefaultFieldConfiguration.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

app/src/main/java/org/team2363/helixnavigator/document/field/configuration/HFieldConfiguration.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/src/main/java/org/team2363/helixnavigator/document/field/configuration/HReferenceFieldConfiguration.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/src/main/java/org/team2363/helixnavigator/document/field/image/HDefaultFieldImage.java

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,90 @@
22

33
import java.io.InputStream;
44

5+
import javax.measure.Quantity;
6+
import javax.measure.quantity.Length;
7+
8+
import org.team2363.helixnavigator.global.DefaultFieldImages;
9+
510
import com.jlbabilino.json.DeserializedJSONConstructor;
611
import com.jlbabilino.json.DeserializedJSONObjectValue;
712
import com.jlbabilino.json.JSONDeserializable;
13+
import com.jlbabilino.json.JSONEntry.JSONType;
814
import com.jlbabilino.json.JSONSerializable;
915
import com.jlbabilino.json.SerializedJSONObjectValue;
10-
import com.jlbabilino.json.JSONEntry.JSONType;
11-
12-
import org.team2363.helixnavigator.global.DefaultFieldImages;
1316

1417
import javafx.scene.image.Image;
18+
import si.uom.SI;
19+
import tech.units.indriya.quantity.Quantities;
1520

1621
@JSONSerializable(JSONType.OBJECT)
1722
@JSONDeserializable({JSONType.OBJECT})
1823
public class HDefaultFieldImage implements HFieldImage {
1924

20-
private final String name;
25+
@SerializedJSONObjectValue(key = "game")
26+
public final String game;
27+
@SerializedJSONObjectValue(key = "field-image")
28+
public final String fieldImage;
29+
@SerializedJSONObjectValue(key = "field-corners")
30+
public final HFieldCorners fieldCorners;
31+
@SerializedJSONObjectValue(key = "field-size")
32+
public final HFieldSize fieldSize;
33+
@SerializedJSONObjectValue(key = "field-unit")
34+
public final HFieldUnit fieldUnit;
35+
36+
private final Image image;
2137
private final double imageRes;
2238
private final double imageCenterX;
2339
private final double imageCenterY;
24-
private final String fileName;
25-
private final Image image;
2640

2741
@DeserializedJSONConstructor
2842
public HDefaultFieldImage(
29-
@DeserializedJSONObjectValue(key = "name") String name,
30-
@DeserializedJSONObjectValue(key = "image_res") double imageRes,
31-
@DeserializedJSONObjectValue(key = "image_center_x") double imageCenterX,
32-
@DeserializedJSONObjectValue(key = "image_center_y") double imageCenterY,
33-
@DeserializedJSONObjectValue(key = "file_name") String fileName) {
34-
this.name = name;
35-
this.imageRes = imageRes;
36-
this.imageCenterX = imageCenterX;
37-
this.imageCenterY = imageCenterY;
38-
this.fileName = fileName;
39-
InputStream imageStream = DefaultFieldImages.class.getResourceAsStream(this.fileName);
40-
image = new Image(imageStream);
43+
@DeserializedJSONObjectValue(key = "game") String game,
44+
@DeserializedJSONObjectValue(key = "field-image") String fieldImage,
45+
@DeserializedJSONObjectValue(key = "field-corners") HFieldCorners fieldCorners,
46+
@DeserializedJSONObjectValue(key = "field-size") HFieldSize fieldSize,
47+
@DeserializedJSONObjectValue(key = "field-unit") HFieldUnit fieldUnit) {
48+
this.game = game;
49+
this.fieldImage = fieldImage;
50+
this.fieldCorners = fieldCorners;
51+
this.fieldSize = fieldSize;
52+
this.fieldUnit = fieldUnit;
53+
54+
InputStream imageStream = DefaultFieldImages.class.getResourceAsStream("wpifieldimages/" + this.fieldImage);
55+
if (imageStream == null) {
56+
imageStream = DefaultFieldImages.class.getResourceAsStream("extrafieldimages/" + this.fieldImage);
57+
}
58+
this.image = new Image(imageStream);
59+
60+
// Assume the image scales proportionally on both axes
61+
double fieldAreaWidthPx = fieldCorners.bottomRightCorner.x - fieldCorners.topLeftCorner.x;
62+
Quantity<Length> fieldAreaWidthUnits = Quantities.getQuantity(fieldSize.width, fieldUnit.unit);
63+
this.imageRes = fieldAreaWidthUnits.to(SI.METRE).getValue().doubleValue() / fieldAreaWidthPx;
64+
65+
this.imageCenterX = fieldCorners.topLeftCorner.x * imageRes;
66+
this.imageCenterY = fieldCorners.bottomRightCorner.y * imageRes;
4167
}
4268

43-
@SerializedJSONObjectValue(key = "name")
4469
@Override
4570
public String getName() {
46-
return name;
71+
return game;
4772
}
4873

49-
@SerializedJSONObjectValue(key = "image_res")
5074
@Override
5175
public double getImageRes() {
5276
return imageRes;
5377
}
5478

55-
@SerializedJSONObjectValue(key = "image_center_x")
5679
@Override
5780
public double getImageCenterX() {
5881
return imageCenterX;
5982
}
6083

61-
@SerializedJSONObjectValue(key = "image_center_y")
6284
@Override
6385
public double getImageCenterY() {
6486
return imageCenterY;
6587
}
6688

67-
@SerializedJSONObjectValue(key = "file_name")
68-
public String getFileName() {
69-
return fileName;
70-
}
71-
7289
@Override
7390
public Image getImage() {
7491
return image;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.team2363.helixnavigator.document.field.image;
2+
3+
import com.jlbabilino.json.DeserializedJSONArrayItem;
4+
import com.jlbabilino.json.DeserializedJSONConstructor;
5+
import com.jlbabilino.json.JSONDeserializable;
6+
import com.jlbabilino.json.JSONSerializable;
7+
import com.jlbabilino.json.SerializedJSONArrayItem;
8+
import com.jlbabilino.json.JSONEntry.JSONType;
9+
10+
@JSONSerializable(JSONType.ARRAY)
11+
@JSONDeserializable({JSONType.ARRAY})
12+
public class HFieldCorner {
13+
14+
@SerializedJSONArrayItem(index = 0)
15+
public final double x;
16+
@SerializedJSONArrayItem(index = 1)
17+
public final double y;
18+
19+
@DeserializedJSONConstructor
20+
public HFieldCorner(
21+
@DeserializedJSONArrayItem(index = 0) double x,
22+
@DeserializedJSONArrayItem(index = 1) double y) {
23+
this.x = x;
24+
this.y = y;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.team2363.helixnavigator.document.field.image;
2+
3+
import com.jlbabilino.json.DeserializedJSONConstructor;
4+
import com.jlbabilino.json.DeserializedJSONObjectValue;
5+
import com.jlbabilino.json.JSONDeserializable;
6+
import com.jlbabilino.json.JSONSerializable;
7+
import com.jlbabilino.json.SerializedJSONObjectValue;
8+
import com.jlbabilino.json.JSONEntry.JSONType;
9+
10+
@JSONSerializable(JSONType.OBJECT)
11+
@JSONDeserializable({JSONType.OBJECT})
12+
public class HFieldCorners {
13+
14+
@SerializedJSONObjectValue(key = "top-left")
15+
public final HFieldCorner topLeftCorner;
16+
@SerializedJSONObjectValue(key = "bottom-right")
17+
public final HFieldCorner bottomRightCorner;
18+
19+
@DeserializedJSONConstructor
20+
public HFieldCorners(
21+
@DeserializedJSONObjectValue(key = "top-left") HFieldCorner topLeftCorner,
22+
@DeserializedJSONObjectValue(key = "bottom-right") HFieldCorner bottomRightCorner) {
23+
this.topLeftCorner = topLeftCorner;
24+
this.bottomRightCorner = bottomRightCorner;
25+
}
26+
}

app/src/main/java/org/team2363/helixnavigator/document/field/image/HFieldImage.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,26 @@
1212
@JSONDeserializable({JSONType.OBJECT})
1313
public interface HFieldImage {
1414

15+
/**
16+
* @return the name of the field image
17+
*/
1518
public String getName();
19+
20+
/**
21+
* @return the resolution of image, in meters per pixel
22+
*/
1623
public double getImageRes();
24+
/**
25+
* @return the center x-coordinate of the image, in meters
26+
*/
1727
public double getImageCenterX();
28+
/**
29+
* @return the center y-coordinate of
30+
*/
1831
public double getImageCenterY();
32+
/**
33+
* @return the processed javafx image of the field
34+
*/
1935
public Image getImage();
2036

2137
@DeserializedJSONDeterminer
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.team2363.helixnavigator.document.field.image;
2+
3+
import com.jlbabilino.json.DeserializedJSONArrayItem;
4+
import com.jlbabilino.json.DeserializedJSONConstructor;
5+
import com.jlbabilino.json.JSONDeserializable;
6+
import com.jlbabilino.json.JSONSerializable;
7+
import com.jlbabilino.json.SerializedJSONArrayItem;
8+
import com.jlbabilino.json.JSONEntry.JSONType;
9+
10+
@JSONSerializable(JSONType.ARRAY)
11+
@JSONDeserializable({JSONType.ARRAY})
12+
public class HFieldSize {
13+
14+
@SerializedJSONArrayItem(index = 0)
15+
public final double width;
16+
@SerializedJSONArrayItem(index = 1)
17+
public final double height;
18+
19+
@DeserializedJSONConstructor
20+
public HFieldSize(
21+
@DeserializedJSONArrayItem(index = 0) double width,
22+
@DeserializedJSONArrayItem(index = 1) double height) {
23+
this.width = width;
24+
this.height = height;
25+
}
26+
}

0 commit comments

Comments
 (0)