Go to the documentation of this file.00001 package edu.wpi.rail.jinteractiveworld.ros.msgs.interactiveworldmsgs;
00002
00003 import edu.wpi.rail.jrosbridge.messages.Message;
00004 import edu.wpi.rail.jrosbridge.messages.geometry.Point;
00005 import edu.wpi.rail.jrosbridge.messages.geometry.Pose;
00006 import edu.wpi.rail.jrosbridge.messages.geometry.Quaternion;
00007
00008 import javax.json.Json;
00009 import javax.json.JsonObject;
00010
00017 public class PointOfInterest extends Message {
00018
00022 public static final String FIELD_NAME = "name";
00023
00027 public static final String FIELD_WIDTH = "width";
00028
00032 public static final String FIELD_HEIGHT = "height";
00033
00037 public static final String FIELD_POSE = "pose";
00038
00042 public static final String TYPE = "interactive_world_msgs/PointOfInterest";
00043
00044 private final String name;
00045 private final double width, height;
00046 private final Pose pose;
00047
00051 public PointOfInterest() {
00052 this("", 0, 0, new Pose());
00053 }
00054
00067 public PointOfInterest(String name, double width, double height, Pose pose) {
00068
00069 super(Json.createObjectBuilder().add(PointOfInterest.FIELD_NAME, name)
00070 .add(PointOfInterest.FIELD_WIDTH, width)
00071 .add(PointOfInterest.FIELD_HEIGHT, height)
00072 .add(PointOfInterest.FIELD_POSE, pose.toJsonObject()).build(), PointOfInterest.TYPE);
00073 this.name = name;
00074 this.width = width;
00075 this.height = height;
00076 this.pose = pose;
00077 }
00078
00084 public String getName() {
00085 return this.name;
00086 }
00087
00093 public double getWidth() {
00094 return this.width;
00095 }
00096
00102 public double getHeight() {
00103 return this.height;
00104 }
00105
00111 public Pose getPose() {
00112 return this.pose;
00113 }
00114
00118 @Override
00119 public PointOfInterest clone() {
00120 return new PointOfInterest(this.name, this.width, this.height, this.pose);
00121 }
00122
00131 public static PointOfInterest fromJsonString(String jsonString) {
00132
00133 return PointOfInterest.fromMessage(new Message(jsonString));
00134 }
00135
00144 public static PointOfInterest fromMessage(Message m) {
00145
00146 return PointOfInterest.fromJsonObject(m.toJsonObject());
00147 }
00148
00157 public static PointOfInterest fromJsonObject(JsonObject jsonObject) {
00158
00159 String name = jsonObject.containsKey(PointOfInterest.FIELD_NAME) ? jsonObject
00160 .getString(PointOfInterest.FIELD_NAME) : "";
00161 double width = jsonObject.containsKey(PointOfInterest.FIELD_WIDTH) ? jsonObject
00162 .getJsonNumber(PointOfInterest.FIELD_WIDTH).doubleValue() : 0.0;
00163 double height = jsonObject.containsKey(PointOfInterest.FIELD_HEIGHT) ? jsonObject
00164 .getJsonNumber(PointOfInterest.FIELD_HEIGHT).doubleValue() : 0.0;
00165 Pose pose = jsonObject.containsKey(PointOfInterest.FIELD_POSE) ? Pose
00166 .fromJsonObject(jsonObject.getJsonObject(PointOfInterest.FIELD_POSE))
00167 : new Pose();
00168 return new PointOfInterest(name, width, height, pose);
00169 }
00170 }