001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.plugins.streetside;
003
004import java.util.List;
005
006import org.openstreetmap.josm.data.coor.LatLon;
007import org.openstreetmap.josm.plugins.streetside.cubemap.CubemapUtils;
008import org.openstreetmap.josm.plugins.streetside.model.UserProfile;
009
010/**
011 * A StreetsideImage object represents each of the images stored in Streetside.
012 *
013 * @author nokutu
014 * @author renerr18
015 *
016 * @see StreetsideSequence
017 * @see StreetsideData
018 */
019public class StreetsideImage extends StreetsideAbstractImage {
020  /**
021   * Rn is a Bing Streetside image attribute - currently not
022   * used, mapped or supported in the Streetside plugin -
023   * left out initially because it's an unrequired complex object.
024   */
025  public static class Rn {
026          // placeholder for nexted Rn attribute
027  }
028
029  // latitude of the Streetside image
030  private double la;
031
032  //longitude of the Streetside image
033  private double lo;
034
035  // The bubble altitude, in meters above the WGS84 ellipsoid
036  private double al;
037
038  // Roll
039  private double ro;
040
041  // Pitch
042  private double pi;
043
044  // Heading (equivalent to Mapillary cd attribute - not currently supported.
045  private double he;
046
047  // Blurring instructions - not currently used by the plugin
048  private String bl;
049
050  // Undocumented Attributes
051  private int ml;
052  private long ne;
053  private long pr;
054  private List<String> nbn;
055  private List<String> pbn;
056  private int ad;
057  private Rn rn;
058
059  /**
060   * Set of traffic signs in the image.
061   *//*
062  private final List<ImageDetection> detections = Collections.synchronizedList(new ArrayList<>());
063*/
064  /**
065   * Main constructor of the class StreetsideImage
066   *
067   * @param id     The unique identifier of the image.
068   * @param latLon The latitude and longitude where it is positioned.
069   * @param he     The direction of the images in degrees, meaning 0 north.
070   */
071  public StreetsideImage(String id, LatLon latLon, double he) {
072    super(id, latLon, he);
073  }
074
075  public StreetsideImage(String id, LatLon latLon) {
076    super(id, latLon, 0.0);
077  }
078
079  public StreetsideImage(String id, double la, double lo) {
080    super(id, new LatLon(la,lo), 0.0);
081  }
082
083  public StreetsideImage(String id) {
084            super(id);
085  }
086
087  // Default constructor for Jackson/JSON Deserializattion
088  public StreetsideImage() {
089    super(CubemapUtils.IMPORTED_ID, null, 0.0);
090  }
091
092  /**
093   * Returns the unique identifier of the object.
094   *
095   * @return A {@code String} containing the unique identifier of the object.
096   */
097  @Override
098public String getId() {
099    return String.valueOf(id);
100  }
101
102  /*public List<ImageDetection> getDetections() {
103    return detections;
104  }*/
105
106  /*public void setAllDetections(Collection<ImageDetection> newDetections) {
107    Logging.debug("Add {0} detections to image {1}", newDetections.size(), getId());
108    synchronized (detections) {
109      detections.clear();
110      detections.addAll(newDetections);
111    }
112  }*/
113
114  public UserProfile getUser() {
115            return getSequence().getUser();
116  }
117
118  @Override
119  public String toString() {
120    return String.format(
121      // TODO: format date cd (Gradle build error command line)
122      "Image[id=%s,lat=%f,lon=%f,he=%f,user=%s]",
123      id, latLon.lat(), latLon.lon(), he, "null"//, cd
124    );
125  }
126
127  // TODO: implement equals @rrh
128  @Override
129  public boolean equals(Object object) {
130    return object instanceof StreetsideImage && id.equals(((StreetsideImage) object).getId());
131  }
132
133  // TODO: implement compareTo @rrh
134  @Override
135  public int compareTo(StreetsideAbstractImage image) {
136    if (image instanceof StreetsideImage) {
137      return id.compareTo(((StreetsideImage) image).getId());
138    }
139    return hashCode() - image.hashCode();
140  }
141
142  // TODO: implement hashcode @rrh
143  @Override
144  public int hashCode() {
145    return id.hashCode();
146  }
147
148  @Override
149  public void stopMoving() {
150    super.stopMoving();
151    checkModified();
152  }
153
154  private void checkModified() {
155    if (StreetsideLayer.hasInstance()) {
156      if (isModified()) {
157        StreetsideLayer.getInstance().getLocationChangeset().add(this);
158      } else {
159        StreetsideLayer.getInstance().getLocationChangeset().remove(this);
160      }
161    }
162  }
163
164  @Override
165  public void turn(double ca) {
166    super.turn(ca);
167    checkModified();
168  }
169
170  /**
171   * @return the altitude
172   */
173  public double getAl() {
174    return al;
175  }
176
177  /**
178   * @param altitude the altitude to set
179   */
180  public void setAl(double altitude) {
181    al = altitude;
182  }
183
184  /**
185   * @return the roll
186   */
187  public double getRo() {
188    return ro;
189  }
190
191  /**
192   * @param roll the roll to set
193   */
194  public void setRo(double roll) {
195    ro = roll;
196  }
197
198  /**
199   * @return the pi
200   */
201  public double getPi() {
202    return pi;
203  }
204
205  /**
206   * @param pitch the pi to set
207   */
208  public void setPi(double pitch) {
209    pi = pitch;
210  }
211
212  /**
213   * @return the burringl
214   */
215  public String getBl() {
216    return bl;
217  }
218
219  /**
220   * @param blurring the blurring to set
221   */
222  public void setBl(String blurring) {
223    bl = blurring;
224  }
225
226  /**
227   * @return the ml
228   */
229  public int getMl() {
230    return ml;
231  }
232
233  /**
234   * @param ml the ml to set
235   */
236  public void setMl(int ml) {
237    this.ml = ml;
238  }
239
240  /**
241   * @return the ne
242   */
243  public long getNe() {
244    return ne;
245  }
246
247  /**
248   * @param ne the ne to set
249   */
250  public void setNe(long ne) {
251    this.ne = ne;
252  }
253
254  /**
255   * @return the pr
256   */
257  public long getPr() {
258    return pr;
259  }
260
261  /**
262   * @param pr the pr to set
263   */
264  public void setPr(long pr) {
265    this.pr = pr;
266  }
267
268  /**
269   * @return the nbn
270   */
271  public List<String> getNbn() {
272    return nbn;
273  }
274
275  /**
276   * @param nbn the nbn to set
277   */
278  public void setNbn(List<String> nbn) {
279    this.nbn = nbn;
280  }
281
282  /**
283   * @return the pbn
284   */
285  public List<String> getPbn() {
286    return pbn;
287  }
288
289  /**
290   * @param pbn the pbn to set
291   */
292  public void setPbn(List<String> pbn) {
293    this.pbn = pbn;
294  }
295
296  /**
297   * @return the ad
298   */
299  public int getAd() {
300    return ad;
301  }
302
303  /**
304   * @param ad the ad to set
305   */
306  public void setAd(int ad) {
307    this.ad = ad;
308  }
309
310  /**
311   * @return the la
312   */
313  public double getLa() {
314    return la;
315  }
316
317  /**
318   * @param la the la to set
319   */
320  public void setLa(double la) {
321    this.la = la;
322  }
323
324  /**
325   * @return the lo
326   */
327  public double getLo() {
328    return lo;
329  }
330
331  /**
332   * @param lo the lo to set
333   */
334  public void setLo(double lo) {
335    this.lo = lo;
336  }
337
338  /**
339   * @param id the id to set
340   */
341  @Override
342public void setId(String id) {
343    this.id = id;
344  }
345
346  /**
347   * @return the rn
348   */
349  public Rn getRn() {
350    return rn;
351  }
352
353  /**
354   * @param rn the rn to set
355   */
356  public void setRn(Rn rn) {
357    this.rn = rn;
358  }
359}