Changeset 31512 in osm for applications/editors/josm/plugins/mapillary
- Timestamp:
- 2015-08-21T20:44:09+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31501 r31512 29 29 /** Listeners of the class. */ 30 30 private CopyOnWriteArrayList<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>(); 31 32 31 /** The bounds of the areas for which the pictures have been downloaded. */ 33 32 public CopyOnWriteArrayList<Bounds> bounds; … … 94 93 * 95 94 * @param images 96 * The setof {@link MapillaryAbstractImage} objects that are going95 * A {@link List} of {@link MapillaryAbstractImage} objects that are going 97 96 * to be removed. 98 97 */ … … 348 347 349 348 /** 350 * Adds a MapillaryImage object to the list of selected images, (when ctrl + 349 * Adds a {@link MapillaryImage} object to the list of selected images, (when ctrl + 351 350 * click) 352 351 * 353 352 * @param image 354 * The MapillaryImage object to be added. 353 * The {@link MapillaryImage} object to be added. 355 354 */ 356 355 public void addMultiSelectedImage(MapillaryAbstractImage image) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryDataListener.java
r31401 r31512 25 25 public void selectedImageChanged(MapillaryAbstractImage oldImage, 26 26 MapillaryAbstractImage newImage); 27 28 27 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java
r31501 r31512 12 12 */ 13 13 public class MapillaryImage extends MapillaryAbstractImage { 14 /** Unique identifier of the object */ 14 /** Unique identifier of the object. */ 15 15 private final String key; 16 /** The user that made the image */ 16 /** The user that made the image. */ 17 17 private String user; 18 /** Set of traffic signs in the image */ 18 /** Set of traffic signs in the image. */ 19 19 private List<String> signs; 20 /** Where the picture was taken. */ 20 21 private String location; 21 22 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31501 r31512 124 124 this.mode.zoomChanged(); 125 125 } 126 if (MapillaryPlugin.EXPORT_MENU != null) {// Does not execute when in127 // headless mode126 // Does not execute when in headless mode 127 if (MapillaryPlugin.EXPORT_MENU != null) { 128 128 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, true); 129 129 if (!MapillaryMainDialog.getInstance().isShowing()) … … 362 362 * @param g 363 363 * @param p 364 * The {@link Point} where the image must be set. 364 365 * @param size 366 * The width in pixels of the highlight. 365 367 */ 366 368 private void drawPointHighlight(Graphics2D g, Point p, int size) { … … 385 387 * @param g 386 388 * @param image 389 * The {@link MapillaryAbstractImage} which is being drown. 387 390 * @param icon 391 * The {@link ImageIcon} that represents the image. 388 392 * @param p 393 * The P¡{@link Point} when the image lies. 389 394 */ 390 395 private void draw(Graphics2D g, MapillaryAbstractImage image, ImageIcon icon, … … 437 442 438 443 /** 439 * Returns the 2 closest images belonging to a different sequence. 444 * Returns the 2 closest images belonging to a different sequence and 445 * different from the currently selected one. 440 446 * 441 447 * @return An array of length 2 containing the two closest images belonging to … … 500 506 if (oldLayer == null && newLayer != null) { 501 507 newLayer.data.addDataSetListener(this); 502 503 508 } else if (oldLayer != null && newLayer == null) { 504 509 oldLayer.data.removeDataSetListener(this); … … 513 518 } 514 519 520 /** 521 * Threads that runs a delayed Mapillary download. 522 * 523 * @author nokutu 524 * 525 */ 515 526 private class delayedDownload extends Thread { 516 527 … … 569 580 @Override 570 581 public void layerAdded(Layer newLayer) { 571 // Nothing572 582 } 573 583 574 584 @Override 575 585 public void layerRemoved(Layer oldLayer) { 576 // Nothing577 586 } 578 587 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java
r31501 r31512 12 12 */ 13 13 public class MapillarySequence { 14 /** The images in the sequence. */ 14 15 private final List<MapillaryAbstractImage> images; 16 /** Unique identifier. Used only for {@link MapillaryImage} sequences. */ 15 17 private String key; 18 /** Epoch time when the sequence was created */ 16 19 private long created_at; 17 20 … … 42 45 * object. 43 46 * 44 * @return A List object containing all the {@link MapillaryAbstractImage} 45 * objects that are part of the sequence. 47 * @return A {@link List} object containing all the 48 * {@link MapillaryAbstractImage} objects that are part of the 49 * sequence. 46 50 */ 47 51 public List<MapillaryAbstractImage> getImages() { … … 72 76 * Returns the unique identifier of the sequence. 73 77 * 74 * @return A Stringcontaining the unique identifier of the sequence.null75 * means that the sequence has been created locally for imported 78 * @return A {@code String} containing the unique identifier of the sequence. 79 * null means that the sequence has been created locally for imported 76 80 * images. 77 81 */ … … 123 127 124 128 /** 125 * Returns the previous {@link MapillaryAbstractImage} in the sequence of a given126 * {@link MapillaryAbstractImage} object. 129 * Returns the previous {@link MapillaryAbstractImage} in the sequence of a 130 * given {@link MapillaryAbstractImage} object. 127 131 * 128 132 * @param image -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31495 r31512 14 14 15 15 import org.apache.commons.imaging.ImageReadException; 16 import org.apache.commons.imaging.Imaging;17 import org.apache.commons.imaging.common.ImageMetadata;18 import org.apache.commons.imaging.common.RationalNumber;19 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;20 import org.apache.commons.imaging.formats.tiff.TiffField;21 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;22 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;23 16 import org.openstreetmap.josm.Main; 24 17 import org.openstreetmap.josm.actions.JosmAction; 25 import org.openstreetmap.josm.data.coor.LatLon;26 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 27 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;28 19 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 29 20 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; … … 44 35 45 36 private JFileChooser chooser; 46 47 /**48 * Amount of pictures without the proper EXIF tags.49 */50 private int noTagsPics = 0;51 37 52 38 /** … … 84 70 continue; 85 71 for (int j = 0; j < file.listFiles().length; j++) { 86 int k = file.listFiles()[j].getName().lastIndexOf('.'); 87 String extension = null; 88 if (k > 0) { 89 extension = file.listFiles()[j].getName().substring(k + 1); 90 } 72 String extension = MapillaryUtils.getExtension(file.listFiles()[j]); 91 73 try { 92 74 if (extension.equals("jpg") || extension.equals("jpeg")) 93 images.add(readJPG(file.listFiles()[j])); 94 75 images.add(MapillaryUtils.readJPG(file.listFiles()[j])); 95 76 else if (extension.equals("png")) 96 images.add(readPNG(file.listFiles()[j])); 77 images.add(MapillaryUtils.readPNG(file.listFiles()[j])); 97 78 } catch (ImageReadException | IOException | NullPointerException e1) { 98 79 Main.error(e1); … … 100 81 } 101 82 } else { 102 if (file.getPath().substring(file.getPath().length() - 4) 103 .equals(".jpg") 104 || file.getPath().substring(file.getPath().length() - 5) 105 .equals(".jpeg")) { 83 String extension = MapillaryUtils.getExtension(file); 84 if (extension.equals("jpg") || extension.equals("jpeg")) { 106 85 try { 107 images.add(readJPG(file)); 86 images.add(MapillaryUtils.readJPG(file)); 108 87 } catch (ImageReadException ex) { 109 88 Main.error(ex); … … 113 92 } else if (file.getPath().substring(file.getPath().length() - 4) 114 93 .equals(".png")) { 115 images.add(readPNG(file)); 94 images.add(MapillaryUtils.readPNG(file)); 116 95 } 117 96 } … … 121 100 } 122 101 } 123 124 /**125 * Reads a JPG pictures that contains the needed GPS information (position and126 * direction) and creates a new icon in that position.127 *128 * @param file129 * The file where the picture is located.130 * @return The imported image.131 * @throws ImageReadException132 * If the file isn't an image.133 * @throws IOException134 * If the file doesn't have the valid metadata.135 */136 public MapillaryImportedImage readJPG(File file) throws IOException,137 ImageReadException {138 final ImageMetadata metadata = Imaging.getMetadata(file);139 if (metadata instanceof JpegImageMetadata) {140 final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;141 final TiffField lat_ref = jpegMetadata142 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);143 final TiffField lat = jpegMetadata144 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);145 final TiffField lon_ref = jpegMetadata146 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);147 final TiffField lon = jpegMetadata148 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);149 final TiffField ca = jpegMetadata150 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);151 final TiffField datetimeOriginal = jpegMetadata152 .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);153 if (lat_ref == null || lat == null || lon == null || lon_ref == null) {154 return readNoTags(file);155 }156 double latValue = 0;157 double lonValue = 0;158 double caValue = 0;159 if (lat.getValue() instanceof RationalNumber[])160 latValue = MapillaryUtils.degMinSecToDouble(161 (RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());162 if (lon.getValue() instanceof RationalNumber[])163 lonValue = MapillaryUtils.degMinSecToDouble(164 (RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());165 if (ca != null && ca.getValue() instanceof RationalNumber)166 caValue = ((RationalNumber) ca.getValue()).doubleValue();167 if (datetimeOriginal != null)168 return new MapillaryImportedImage(latValue, lonValue, caValue, file,169 datetimeOriginal.getStringValue());170 else171 return new MapillaryImportedImage(latValue, lonValue, caValue, file);172 }173 throw new IllegalStateException("Invalid format.");174 }175 176 /**177 * Reads a image file that doesn't contain the needed GPS information. And178 * creates a new icon in the middle of the map.179 *180 * @param file181 * The file where the image is located.182 * @return The imported image.183 */184 public MapillaryImportedImage readNoTags(File file) {185 return readNoTags(186 file,187 Main.map.mapView.getProjection().eastNorth2latlon(188 Main.map.mapView.getCenter()));189 }190 191 /**192 * Reads a image file that doesn't contain the needed GPS information. And193 * creates a new icon in the middle of the map.194 *195 * @param file196 * The file where the image is located.197 * @param pos198 * A {@link LatLon} object indicating the position in the map where199 * the image must be set.200 * @return The imported image.201 */202 public MapillaryImportedImage readNoTags(File file, LatLon pos) {203 double HORIZONTAL_DISTANCE = 0.0001;204 double horDev;205 if (this.noTagsPics % 2 == 0)206 horDev = HORIZONTAL_DISTANCE * this.noTagsPics / 2;207 else208 horDev = -HORIZONTAL_DISTANCE * ((this.noTagsPics + 1) / 2);209 this.noTagsPics++;210 return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file);211 }212 213 /**214 * Reads an image in PNG format.215 *216 * @param file217 * The file where the image is located.218 * @return The imported image.219 */220 public MapillaryImportedImage readPNG(File file) {221 return readNoTags(file);222 }223 102 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java
r31495 r31512 16 16 17 17 import org.apache.commons.imaging.ImageReadException; 18 import org.apache.commons.imaging.Imaging;19 import org.apache.commons.imaging.common.ImageMetadata;20 import org.apache.commons.imaging.common.RationalNumber;21 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;22 import org.apache.commons.imaging.formats.tiff.TiffField;23 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;24 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;25 18 import org.openstreetmap.josm.Main; 26 19 import org.openstreetmap.josm.actions.JosmAction; 27 20 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 28 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;29 21 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 30 22 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; … … 86 78 if (file.isDirectory()) { 87 79 for (int j = 0; j < file.listFiles().length; j++) { 88 int k = file.listFiles()[j].getName().lastIndexOf('.'); 89 String extension = null; 90 if (k > 0) { 91 extension = file.listFiles()[j].getName().substring(k + 1); 92 } 80 String extension = MapillaryUtils.getExtension(file.listFiles()[j]); 93 81 try { 94 82 if (extension.equals("jpg") || extension.equals("jpeg")) 95 readJPG(file.listFiles()[j]); 83 MapillaryUtils.readJPG(file.listFiles()[j], true); 96 84 } catch (ImageReadException | NullPointerException | IOException e) { 97 85 Main.error(e); … … 99 87 } 100 88 } else { 101 if (file.getPath().substring(file.getPath().length() - 4) 102 .equals(".jpg") 103 || file.getPath().substring(file.getPath().length() - 5) 104 .equals(".jpeg")) { 89 String extension = MapillaryUtils.getExtension(file); 90 if (extension.equals("jpg") || extension.equals("jpeg")) { 105 91 try { 106 readJPG(file); 92 this.images.add(MapillaryUtils.readJPG(file, true)); 107 93 } catch (ImageReadException ex) { 108 94 Main.error(ex); 109 95 } catch (IOException ex) { 110 96 Main.error(ex); 97 } catch (IllegalArgumentException ex) { 98 // Ignored image. 111 99 } 112 100 } … … 117 105 } 118 106 MapillaryUtils.showAllPictures(); 119 }120 121 /**122 * Reads a JPG pictures that contains the needed GPS information (position and123 * direction) and creates a new icon in that position.124 *125 * @param file126 * The file where the image is located.127 * @throws ImageReadException128 * If the file doesn't contain an image.129 * @throws IOException130 * If the file doesn't contain valid metadata.131 */132 public void readJPG(File file) throws ImageReadException, IOException {133 final ImageMetadata metadata = Imaging.getMetadata(file);134 if (metadata instanceof JpegImageMetadata) {135 final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;136 final TiffField lat_ref = jpegMetadata137 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);138 final TiffField lat = jpegMetadata139 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);140 final TiffField lon_ref = jpegMetadata141 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);142 final TiffField lon = jpegMetadata143 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);144 final TiffField ca = jpegMetadata145 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);146 final TiffField datetimeOriginal = jpegMetadata147 .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);148 if (lat_ref == null || lat == null || lon == null || lon_ref == null149 || datetimeOriginal == null)150 return;151 152 double latValue = 0;153 double lonValue = 0;154 double caValue = 0;155 if (lat.getValue() instanceof RationalNumber[])156 latValue = MapillaryUtils.degMinSecToDouble(157 (RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());158 if (lon.getValue() instanceof RationalNumber[])159 lonValue = MapillaryUtils.degMinSecToDouble(160 (RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());161 if (ca != null && ca.getValue() instanceof RationalNumber)162 caValue = ((RationalNumber) ca.getValue()).doubleValue();163 164 MapillaryImportedImage image = new MapillaryImportedImage(latValue,165 lonValue, caValue, file, datetimeOriginal.getStringValue());166 this.images.add(image);167 }168 107 } 169 108 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryJoinAction.java
r31425 r31512 14 14 15 15 /** 16 * Changes the mode of the Layer, from Select mode to Join mode and viceversa. 16 * Changes the mode of the Layer, from Select mode to Join mode and vice versa. 17 17 * 18 18 * @author nokutu … … 36 36 @Override 37 37 public void actionPerformed(ActionEvent arg0) { 38 if (MapillaryLayer.getInstance().mode instanceof SelectMode) {38 if (MapillaryLayer.getInstance().mode instanceof SelectMode) 39 39 MapillaryLayer.getInstance().setMode(new JoinMode()); 40 } else {40 else 41 41 MapillaryLayer.getInstance().setMode(new SelectMode()); 42 }43 42 } 44 43 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryUploadAction.java
r31491 r31512 21 21 22 22 /** 23 * Action called when an upload to the Mapillary servers is going to be 24 * performed. It lets you select a couple of options. 25 * 23 26 * @author nokutu 24 27 * … … 60 63 @Override 61 64 public void imagesAdded() { 62 // Nothing63 65 } 64 66 … … 71 73 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.UPLOAD_MENU, false); 72 74 } 73 74 75 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31501 r31512 95 95 } 96 96 97 /** 98 * Downloads the sequence positions, directions and keys. 99 * 100 * @throws InterruptedException 101 * if the thread is interrupted while running this method. 102 */ 97 103 private void downloadSequences() throws InterruptedException { 98 104 int page = 0; … … 109 115 } 110 116 117 /** 118 * Downloads the image's author's username and the image's location. 119 * 120 * @throws InterruptedException 121 * if the thread is interrupted while running this method. 122 */ 111 123 private void completeImages() throws InterruptedException { 112 124 int page = 0; … … 122 134 } 123 135 136 /** 137 * Downloads the traffic signs in the images. 138 * 139 * @throws InterruptedException 140 * if the thread is interrupted while running this method. 141 */ 124 142 private void downloadSigns() throws InterruptedException { 125 143 int page = 0; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java
r31501 r31512 34 34 private String text; 35 35 private URL url; 36 private String key; 36 37 37 38 /** … … 63 64 */ 64 65 public void setURL(String key) { 66 this.key = key; 65 67 if (key == null) { 66 68 this.url = null; … … 110 112 private static final long serialVersionUID = 1384054752970921552L; 111 113 112 JMenuItem copy; 114 private JMenuItem copy; 115 private JMenuItem copyTag; 116 private JMenuItem edit; 113 117 114 118 public LinkPopUp() { 115 this.copy = new JMenuItem("Copy key"); 119 this.copy = new JMenuItem(tr("Copy key")); 116 120 this.copy.addActionListener(new copyAction()); 117 121 add(this.copy); 122 123 this.copyTag = new JMenuItem(tr("Copy key tag")); 124 this.copyTag.addActionListener(new copyTagAction()); 125 add(this.copyTag); 126 127 this.edit = new JMenuItem(tr("Edit on webpage")); 128 this.edit.addActionListener(new editAction()); 129 add(this.edit); 118 130 } 119 131 … … 128 140 clpbrd.setContents(stringSelection, null); 129 141 } 130 142 } 143 144 private class copyTagAction implements ActionListener { 145 146 @Override 147 public void actionPerformed(ActionEvent arg0) { 148 StringSelection stringSelection = new StringSelection( 149 "mapillary=" 150 + ((MapillaryImage) MapillaryMainDialog.getInstance() 151 .getImage()).getKey()); 152 Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); 153 clpbrd.setContents(stringSelection, null); 154 } 155 } 156 157 private class editAction implements ActionListener { 158 159 @Override 160 public void actionPerformed(ActionEvent arg0) { 161 try { 162 MapillaryUtils.browse(new URL("http://www.mapillary.com/map/e/" 163 + HyperlinkLabel.this.key)); 164 } catch (MalformedURLException e) { 165 Main.error(e); 166 } 167 } 131 168 } 132 169 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java
r31511 r31512 53 53 return; 54 54 MapillaryAbstractImage closest = getClosest(e.getPoint()); 55 if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer55 if (!(Main.map.mapView.getActiveLayer() instanceof MapillaryLayer) 56 56 && closest != null && Main.map.mapMode == Main.map.mapModeSelect) { 57 57 this.lastClicked = this.closest; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java
r31476 r31512 8 8 9 9 /** 10 * Represents the current logged in user and stores its data. 11 * 10 12 * @author nokutu 11 13 * … … 38 40 isTokenValid = false; 39 41 } 40 41 42 return username; 42 43 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java
r31511 r31512 15 15 16 16 /** 17 * Listens to the OAuth port in order to get the access token. 17 * Listens to the OAuth port (8763) in order to get the access token and sends 18 * back a simple reply. 18 19 * 19 20 * @author nokutu … … 66 67 Main.info("The username is: " + MapillaryUser.getUsername()); 67 68 } 68 69 69 } catch (BindException e) { 70 70 return; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java
r31496 r31512 265 265 ((MapillaryImportedImage) image).getDate("yyyy/MM/dd hh:mm:ss")); 266 266 267 // Removes the ImageDescription tag, that causes problems in the upload. 267 268 rootDirectory.removeField(TiffTagConstants.TIFF_TAG_IMAGE_DESCRIPTION); 268 269 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java
r31511 r31512 4 4 5 5 import java.awt.Desktop; 6 import java.io.File; 6 7 import java.io.IOException; 7 8 import java.net.URISyntaxException; … … 14 15 import javax.swing.SwingUtilities; 15 16 17 import org.apache.commons.imaging.ImageReadException; 18 import org.apache.commons.imaging.Imaging; 19 import org.apache.commons.imaging.common.ImageMetadata; 16 20 import org.apache.commons.imaging.common.RationalNumber; 21 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; 22 import org.apache.commons.imaging.formats.tiff.TiffField; 23 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; 17 24 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants; 18 25 import org.openstreetmap.josm.Main; … … 21 28 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 22 29 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 30 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 23 31 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 24 32 import org.openstreetmap.josm.plugins.mapillary.MapillarySequence; … … 33 41 34 42 private static double MIN_ZOOM_SQUARE_SIDE = 0.002; 43 44 private static int noTagsPics = 0; 35 45 36 46 /** … … 281 291 return formatter.format(cal.getTime()); 282 292 } 293 294 /** 295 * Reads a JPG pictures that contains the needed GPS information (position and 296 * direction) and creates a new icon in that position. 297 * 298 * @param file 299 * The file where the picture is located. 300 * @return The imported image. 301 * @throws ImageReadException 302 * If the file isn't an image. 303 * @throws IOException 304 * If the file doesn't have the valid metadata. 305 */ 306 public static MapillaryImportedImage readJPG(File file) throws IOException, 307 ImageReadException { 308 return readJPG(file, false); 309 } 310 311 /** 312 * Reads a JPG pictures that contains the needed GPS information (position and 313 * direction) and creates a new icon in that position. 314 * 315 * @param file 316 * The {@link File} where the picture is located. 317 * @param exceptionNoTags 318 * {@code true} if an exception must be thrown if the image doesn't 319 * have all the needed EXIF tags; {@code false} returns an image in 320 * the center of the screen. 321 * @return The imported image. 322 * @throws ImageReadException 323 * If the {@link File} isn't an image. 324 * @throws IOException 325 * If the {@link File} doesn't have the valid metadata. 326 * @throws IllegalArgumentException 327 * if exceptionNoTags is set to {@code true} and the image doesn't 328 * have the needed EXIF tags. 329 */ 330 public static MapillaryImportedImage readJPG(File file, 331 boolean exceptionNoTags) throws IOException, ImageReadException { 332 final ImageMetadata metadata = Imaging.getMetadata(file); 333 if (metadata instanceof JpegImageMetadata) { 334 final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; 335 final TiffField lat_ref = jpegMetadata 336 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); 337 final TiffField lat = jpegMetadata 338 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE); 339 final TiffField lon_ref = jpegMetadata 340 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); 341 final TiffField lon = jpegMetadata 342 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); 343 final TiffField ca = jpegMetadata 344 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); 345 final TiffField datetimeOriginal = jpegMetadata 346 .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); 347 if (lat_ref == null || lat == null || lon == null || lon_ref == null) { 348 if (exceptionNoTags) 349 throw new IllegalArgumentException( 350 "The image doesn't have the needed EXIF tags."); 351 else 352 return readNoTags(file); 353 } 354 double latValue = 0; 355 double lonValue = 0; 356 double caValue = 0; 357 if (lat.getValue() instanceof RationalNumber[]) 358 latValue = MapillaryUtils.degMinSecToDouble( 359 (RationalNumber[]) lat.getValue(), lat_ref.getValue().toString()); 360 if (lon.getValue() instanceof RationalNumber[]) 361 lonValue = MapillaryUtils.degMinSecToDouble( 362 (RationalNumber[]) lon.getValue(), lon_ref.getValue().toString()); 363 if (ca != null && ca.getValue() instanceof RationalNumber) 364 caValue = ((RationalNumber) ca.getValue()).doubleValue(); 365 if (datetimeOriginal != null) 366 return new MapillaryImportedImage(latValue, lonValue, caValue, file, 367 datetimeOriginal.getStringValue()); 368 else 369 return new MapillaryImportedImage(latValue, lonValue, caValue, file); 370 } 371 throw new IllegalStateException("Invalid format."); 372 } 373 374 /** 375 * Reads a image file that doesn't contain the needed GPS information. And 376 * creates a new icon in the middle of the map. 377 * 378 * @param file 379 * The file where the image is located. 380 * @param pos 381 * A {@link LatLon} object indicating the position in the map where 382 * the image must be set. 383 * @return The imported image. 384 */ 385 public static MapillaryImportedImage readNoTags(File file, LatLon pos) { 386 double HORIZONTAL_DISTANCE = 0.0001; 387 double horDev; 388 if (noTagsPics % 2 == 0) 389 horDev = HORIZONTAL_DISTANCE * noTagsPics / 2; 390 else 391 horDev = -HORIZONTAL_DISTANCE * ((noTagsPics + 1) / 2); 392 noTagsPics++; 393 return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file); 394 } 395 396 /** 397 * Reads an image in PNG format. 398 * 399 * @param file 400 * The file where the image is located. 401 * @return The imported image. 402 */ 403 public static MapillaryImportedImage readPNG(File file) { 404 return readNoTags(file); 405 } 406 407 /** 408 * Reads a image file that doesn't contain the needed GPS information. And 409 * creates a new icon in the middle of the map. 410 * 411 * @param file 412 * The file where the image is located. 413 * @return The imported image. 414 */ 415 public static MapillaryImportedImage readNoTags(File file) { 416 return readNoTags( 417 file, 418 Main.map.mapView.getProjection().eastNorth2latlon( 419 Main.map.mapView.getCenter())); 420 } 421 422 /** 423 * Returns the extension of a {@link File} object. 424 * 425 * @param file 426 * The {@link File} object whose extension is going to be returned. 427 * @return A {@code String} object containing the extension. 428 */ 429 public static String getExtension(File file) { 430 if (file.isDirectory()) 431 throw new IllegalArgumentException("The file is a directory"); 432 int k = file.getName().lastIndexOf('.'); 433 if (k > 0) { 434 return file.getName().substring(k + 1).toLowerCase(); 435 } 436 throw new IllegalArgumentException("Error parsing the extension"); 437 } 283 438 } -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportTest.java
r31460 r31512 11 11 12 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.plugins.mapillary. actions.MapillaryImportAction;13 import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils; 14 14 15 15 /** … … 27 27 public void importNoTagsTest() { 28 28 File image = new File("images/icon16.png"); 29 MapillaryImportedImage img = newMapillaryImportAction().readNoTags(image,29 MapillaryImportedImage img = MapillaryUtils.readNoTags(image, 30 30 new LatLon(0, 0)); 31 31 assertEquals(0, img.getCa(), 0.01); -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/UploadTest.java
r31460 r31512 20 20 import org.openstreetmap.josm.plugins.mapillary.AbstractTest; 21 21 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 22 import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction;23 22 import org.openstreetmap.josm.plugins.mapillary.oauth.UploadUtils; 24 23 import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils; … … 38 37 public void updateFileTest() { 39 38 File image = new File("images/icon16.png"); 40 MapillaryImportedImage img = newMapillaryImportAction().readNoTags(image,39 MapillaryImportedImage img = MapillaryUtils.readNoTags(image, 41 40 new LatLon(0, 0)); 42 41 File updatedFile = null;
Note:
See TracChangeset
for help on using the changeset viewer.