Changeset 31409 in osm for applications/editors
- Timestamp:
- 2015-07-27T14:08:33+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java
r31390 r31409 24 24 * to prevent concurrency problems. 25 25 */ 26 public static Lock lock= new ReentrantLock();26 public static Lock LOCK = new ReentrantLock(); 27 27 28 28 /** The time the image was captured, in Epoch format. */ … … 281 281 */ 282 282 public MapillaryAbstractImage next() { 283 synchronized ( lock) {283 synchronized (LOCK) { 284 284 if (this.getSequence() == null) 285 285 return null; … … 295 295 */ 296 296 public MapillaryAbstractImage previous() { 297 synchronized ( lock) {297 synchronized (LOCK) { 298 298 if (this.getSequence() == null) 299 299 return null; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31404 r31409 209 209 /** 210 210 * If the selected MapillaryImage is part of a MapillarySequence then the 211 * following visible MapillaryImage is selected. In case there is none, does 212 * nothing. 213 * 214 * @param moveToPicture 215 * True if the view must me moved to the next picture. 216 */ 217 public void selectNext(boolean moveToPicture) { 218 if (getSelectedImage() == null) 219 return; 220 if (getSelectedImage().getSequence() == null) 221 return; 222 MapillaryAbstractImage tempImage = selectedImage; 223 while (tempImage.next() != null) { 224 tempImage = tempImage.next(); 225 if (tempImage.isVisible()) { 226 setSelectedImage(tempImage, moveToPicture); 227 break; 228 } 229 } 230 } 231 232 /** 233 * If the selected MapillaryImage is part of a MapillarySequence then the 211 234 * previous visible MapillaryImage is selected. In case there is none, does 212 235 * nothing. … … 229 252 230 253 /** 254 * If the selected MapillaryImage is part of a MapillarySequence then the 255 * previous visible MapillaryImage is selected. In case there is none, does 256 * nothing. 257 * 258 * @param moveToPicture 259 * True if the view must me moved to the previous picture. 260 */ 261 public void selectPrevious(boolean moveToPicture) { 262 if (getSelectedImage() == null) 263 return; 264 if (getSelectedImage().getSequence() == null) 265 throw new IllegalStateException(); 266 MapillaryAbstractImage tempImage = selectedImage; 267 while (tempImage.previous() != null) { 268 tempImage = tempImage.previous(); 269 if (tempImage.isVisible()) { 270 setSelectedImage(tempImage, moveToPicture); 271 break; 272 } 273 } 274 } 275 276 /** 231 277 * Selects a new image.If the user does ctrl + click, this isn't triggered. 232 278 * … … 248 294 */ 249 295 public void setSelectedImage(MapillaryAbstractImage image, boolean zoom) { 250 if (image != null) {251 System.out.println("----------------------------");252 for (MapillaryAbstractImage img : getImages())253 System.out.println(img.getSequence());254 }255 296 MapillaryAbstractImage oldImage = selectedImage; 256 297 selectedImage = image; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java
r31401 r31409 22 22 23 23 /** 24 * Returns the loca ltion where the image was taken.24 * Returns the location where the image was taken. 25 25 * 26 26 * @return A String containing the location where the picture was taken. … … 40 40 41 41 /** 42 * Main con tructor of the class MapillaryImage42 * Main constructor of the class MapillaryImage 43 43 * 44 44 * @param key -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31404 r31409 153 153 */ 154 154 public synchronized static MapillaryLayer getInstance() { 155 if ( MapillaryLayer.INSTANCE == null)156 MapillaryLayer.INSTANCE = new MapillaryLayer();155 if (INSTANCE == null) 156 INSTANCE = new MapillaryLayer(); 157 157 return MapillaryLayer.INSTANCE; 158 158 } … … 171 171 public void destroy() { 172 172 setMode(null); 173 AbstractMode.resetThread(); 173 174 MapillaryDownloader.stopAll(); 174 175 MapillaryMainDialog.getInstance().setImage(null); … … 181 182 if (Main.map.mapView.getEditLayer() != null) 182 183 Main.map.mapView.getEditLayer().data.removeDataSetListener(this); 184 MapillaryData.INSTANCE = null; 183 185 MapillaryLayer.INSTANCE = null; 184 186 super.destroy(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadAction.java
r31401 r31409 12 12 import org.openstreetmap.josm.actions.JosmAction; 13 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 14 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;15 14 import org.openstreetmap.josm.tools.ImageProvider; 16 15 import org.openstreetmap.josm.tools.Shortcut; … … 41 40 public void actionPerformed(ActionEvent arg0) { 42 41 if (MapillaryLayer.INSTANCE == null) { 43 if (Main.map.mapView.getEditLayer() != null) 44 MapillaryDownloader.automaticDownload(); 42 MapillaryLayer.getInstance(); 45 43 } else { 46 44 if (Main.map.mapView.getActiveLayer() != MapillaryLayer.getInstance()) -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java
r31401 r31409 57 57 && (int) pane.getValue() == JOptionPane.OK_OPTION) { 58 58 thread = new WalkThread((int) dialog.spin.getValue(), 59 dialog.waitForPicture.isSelected() );59 dialog.waitForPicture.isSelected(), dialog.followSelection.isSelected()); 60 60 fireWalkStarted(); 61 61 thread.start(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java
r31401 r31409 4 4 import java.util.concurrent.locks.Lock; 5 5 import java.util.concurrent.locks.ReentrantLock; 6 7 import javax.swing.SwingUtilities; 6 8 7 9 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; … … 24 26 private Lock lock = new ReentrantLock(); 25 27 private boolean end = false; 26 private boolean waitForPicture; 28 private final boolean waitForFullQuality; 29 private final boolean followSelected; 27 30 private BufferedImage lastImage; 28 31 private volatile boolean paused = false; … … 33 36 * @param interval 34 37 * @param waitForPicture 38 * @param followSelected 35 39 */ 36 public WalkThread(int interval, boolean waitForPicture ) {40 public WalkThread(int interval, boolean waitForPicture, boolean followSelected) { 37 41 this.interval = interval; 38 this.waitForPicture = waitForPicture; 42 this.waitForFullQuality = waitForPicture; 43 this.followSelected = followSelected; 39 44 data = MapillaryLayer.getInstance().getMapillaryData(); 40 45 data.addListener(this); … … 46 51 while (!end && data.getSelectedImage().next() != null) { 47 52 MapillaryAbstractImage image = data.getSelectedImage(); 48 // Predownload next 5 pictures.49 53 if (image instanceof MapillaryImage) { 50 for (int i = 0; i < 5; i++) { 54 // Predownload next 10 thumbnails. 55 for (int i = 0; i < 10; i++) { 51 56 if (image.next() == null) 52 57 break; 53 58 image = image.next(); 54 Utils.downloadPicture((MapillaryImage) image );59 Utils.downloadPicture((MapillaryImage) image, Utils.PICTURE.THUMBNAIL); 55 60 } 56 61 } 62 if (waitForFullQuality) 63 // Start downloading 3 next full images. 64 for (int i = 0; i < 3; i++) { 65 if (image.next() == null) 66 break; 67 image = image.next(); 68 Utils.downloadPicture((MapillaryImage) image, Utils.PICTURE.FULL); 69 } 57 70 try { 58 71 synchronized (this) { 59 if (waitFor Picture72 if (waitForFullQuality 60 73 && data.getSelectedImage() instanceof MapillaryImage) { 61 74 while (MapillaryMainDialog.getInstance().mapillaryImageDisplay … … 84 97 .getImage(); 85 98 synchronized (lock) { 86 data.selectNext( );99 data.selectNext(followSelected); 87 100 } 88 101 } catch (InterruptedException e) { … … 93 106 return; 94 107 } 95 end = true; 96 data.removeListener(this); 97 MapillaryMainDialog.getInstance().setMode(MapillaryMainDialog.Mode.NORMAL); 108 end(); 98 109 } 99 110 100 111 @Override 101 112 public void interrupt() { 102 end = true;103 data.removeListener(this);104 MapillaryMainDialog.getInstance().setMode(MapillaryMainDialog.Mode.NORMAL);105 113 super.interrupt(); 106 114 } … … 139 147 */ 140 148 public void stopWalk() { 141 this.interrupt(); 149 if (!SwingUtilities.isEventDispatchThread()) { 150 SwingUtilities.invokeLater(new Runnable() { 151 @Override 152 public void run() { 153 stopWalk(); 154 } 155 }); 156 } else { 157 end(); 158 this.interrupt(); 159 } 160 } 161 162 /** 163 * Called when the walk stops by itself of forcefully. 164 */ 165 public void end() { 166 if (!SwingUtilities.isEventDispatchThread()) { 167 SwingUtilities.invokeLater(new Runnable() { 168 @Override 169 public void run() { 170 end(); 171 } 172 }); 173 } else { 174 end = true; 175 data.removeListener(this); 176 MapillaryMainDialog.getInstance() 177 .setMode(MapillaryMainDialog.Mode.NORMAL); 178 } 142 179 } 143 180 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/Utils.java
r31401 r31409 16 16 private static IgnoreDownload IGNORE_DOWNLOAD = new IgnoreDownload(); 17 17 18 /** Picture quality */ 19 public enum PICTURE { 20 /** Thumbnail quality picture () */ 21 THUMBNAIL, 22 /** Full quality picture () */ 23 FULL, 24 /** Both of them */ 25 BOTH; 26 } 27 18 28 /** 19 29 * Downloads the picture of the given image and does nothing when it is … … 23 33 */ 24 34 public static void downloadPicture(MapillaryImage img) { 25 new MapillaryCache(img.getKey(), MapillaryCache.Type.THUMBNAIL).submit( 26 IGNORE_DOWNLOAD, false); 27 new MapillaryCache(img.getKey(), MapillaryCache.Type.FULL_IMAGE).submit( 28 IGNORE_DOWNLOAD, false); 35 downloadPicture(img, PICTURE.BOTH); 36 } 37 38 /** 39 * Downloads the picture of the given image and does nothing when it is 40 * downloaded. 41 * 42 * @param img 43 * @param pic 44 * The picture type to be downloaded (full quality, thumbnail or 45 * both.) 46 */ 47 public static void downloadPicture(MapillaryImage img, PICTURE pic) { 48 if (pic == PICTURE.BOTH) { 49 if (new MapillaryCache(img.getKey(), MapillaryCache.Type.THUMBNAIL).get() == null) 50 new MapillaryCache(img.getKey(), MapillaryCache.Type.THUMBNAIL).submit( 51 IGNORE_DOWNLOAD, false); 52 if (new MapillaryCache(img.getKey(), MapillaryCache.Type.FULL_IMAGE) 53 .get() == null) 54 new MapillaryCache(img.getKey(), MapillaryCache.Type.FULL_IMAGE) 55 .submit(IGNORE_DOWNLOAD, false); 56 } else if (pic == PICTURE.THUMBNAIL 57 && new MapillaryCache(img.getKey(), MapillaryCache.Type.THUMBNAIL) 58 .get() == null) { 59 new MapillaryCache(img.getKey(), MapillaryCache.Type.THUMBNAIL).submit( 60 IGNORE_DOWNLOAD, false); 61 } else if (pic == PICTURE.FULL 62 && new MapillaryCache(img.getKey(), MapillaryCache.Type.FULL_IMAGE) 63 .get() == null) { 64 new MapillaryCache(img.getKey(), MapillaryCache.Type.FULL_IMAGE).submit( 65 IGNORE_DOWNLOAD, false); 66 } 29 67 } 30 68 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java
r31404 r31409 34 34 /** Client ID for the app */ 35 35 public final static String CLIENT_ID = "NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1YTA2NmNlODhlNWMwOTBm"; 36 /** Executor that will run the petitions */37 p ublic final static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(1,38 1 , 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50));36 /** Executor that will run the petitions. */ 37 private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5, 38 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50)); 39 39 40 40 /** … … 69 69 if (view.getArea() > MapillaryDownloadViewAction.MAX_AREA) 70 70 return; 71 for (Bounds bound : MapillaryLayer.getInstance().bounds) { 72 if (!view.intersects(bound)) 73 continue; 74 if (bound.equals(view)) { 75 // Already downloaded 76 return; 71 if (isViewDownloaded(view)) 72 return; 73 MapillaryLayer.getInstance().bounds.add(view); 74 getImages(view); 75 } 76 77 private static boolean isViewDownloaded(Bounds view) { 78 int n = 15; 79 boolean[][] inside = new boolean[n][n]; 80 for (int i = 0; i < n; i++) { 81 for (int j = 0; j < n; j++) { 82 if (isInBounds(new LatLon(view.getMinLat() 83 + (view.getMaxLat() - view.getMinLat()) * ((double) i / n), view.getMinLon() 84 + (view.getMaxLon() - view.getMinLon()) 85 * ((double) j / n)))) { 86 inside[i][j] = true; 87 } 77 88 } 78 89 } 79 MapillaryLayer.getInstance().bounds.add(view); 80 getImages(view); 90 for (int i = 0; i < n; i++) { 91 for (int j = 0; j < n; j++) { 92 if (!inside[i][j]) 93 return false; 94 } 95 } 96 return true; 97 } 98 99 private static boolean isInBounds(LatLon latlon) { 100 for (Bounds bounds : MapillaryLayer.getInstance().bounds) { 101 if (bounds.contains(latlon)) 102 return true; 103 } 104 return false; 81 105 } 82 106 … … 137 161 public static void stopAll() { 138 162 EXECUTOR.shutdownNow(); 163 EXECUTOR = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS, 164 new ArrayBlockingQueue<Runnable>(50)); 139 165 } 140 166 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31400 r31409 13 13 import java.util.List; 14 14 import java.util.concurrent.ExecutorService; 15 import java.util.concurrent.locks.Lock; 16 import java.util.concurrent.locks.ReentrantLock; 15 17 16 18 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.data.Bounds;18 19 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 19 20 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; … … 32 33 private static final String URL = MapillaryDownloader.BASE_URL + "search/s/"; 33 34 35 /** Lock to prevent multiple downloads to be imported at the same time. */ 36 private static final Lock LOCK = new ReentrantLock(); 37 34 38 private final String queryString; 35 39 private final ExecutorService ex; 36 private final List<Bounds> bounds;37 40 private final MapillaryLayer layer; 38 private final MapillarySquareDownloadManagerThread manager;39 41 40 42 /** … … 43 45 * @param ex 44 46 * @param queryString 45 * @param layer46 47 * @param manager 47 48 */ 48 49 public MapillarySequenceDownloadThread(ExecutorService ex, 49 String queryString, MapillaryLayer layer, 50 MapillarySquareDownloadManagerThread manager) { 50 String queryString) { 51 51 this.queryString = queryString; 52 52 this.ex = ex; 53 this.bounds = layer.bounds; 54 this.layer = layer; 55 this.manager = manager; 53 this.layer = MapillaryLayer.getInstance(); 56 54 } 57 55 … … 98 96 } 99 97 100 boolean imagesAdded = false;101 MapillaryImage.lock.lock();102 for (MapillaryImage img : finalImages) {103 if (layer.getMapillaryData().getImages().contains(img)) {104 // The image in finalImages is substituted by the one in the105 // database, as they are equal.106 img = (MapillaryImage) layer.getMapillaryData().getImages()107 .get(layer.getMapillaryData().getImages().indexOf(img));108 sequence.add(img);109 ((MapillaryImage) layer.getMapillaryData().getImages()110 .get(layer.getMapillaryData().getImages().indexOf(img)))111 .setSequence(sequence);112 finalImages.set(finalImages.indexOf(img), img);113 } else {114 img.setSequence(sequence);115 imagesAdded = true;116 sequence.add(img);98 MapillaryImage.LOCK.lock(); 99 synchronized (LOCK) { 100 for (MapillaryImage img : finalImages) { 101 if (layer.getMapillaryData().getImages().contains(img)) { 102 // The image in finalImages is substituted by the one in the 103 // database, as they represent the same picture. 104 img = (MapillaryImage) layer.getMapillaryData().getImages() 105 .get(layer.getMapillaryData().getImages().indexOf(img)); 106 sequence.add(img); 107 ((MapillaryImage) layer.getMapillaryData().getImages() 108 .get(layer.getMapillaryData().getImages().indexOf(img))) 109 .setSequence(sequence); 110 finalImages.set(finalImages.indexOf(img), img); 111 } else { 112 img.setSequence(sequence); 113 sequence.add(img); 114 } 117 115 } 118 116 } 119 MapillaryImage.lock.unlock(); 120 if (manager != null) { 121 manager.imagesAdded = imagesAdded; 122 } 117 MapillaryImage.LOCK.unlock(); 118 123 119 layer.getMapillaryData().addWithoutUpdate( 124 120 new ArrayList<MapillaryAbstractImage>(finalImages)); … … 131 127 132 128 private boolean isInside(MapillaryAbstractImage image) { 133 for (int i = 0; i < bounds.size(); i++)134 if ( bounds.get(i).contains(image.getLatLon()))129 for (int i = 0; i < layer.bounds.size(); i++) 130 if (layer.bounds.get(i).contains(image.getLatLon())) 135 131 return true; 136 132 return false; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31404 r31409 31 31 private final String signQueryString; 32 32 private final MapillaryLayer layer; 33 /** Whether if new images have been added in the download or not. */34 public boolean imagesAdded = false;35 33 36 34 /** … … 75 73 try { 76 74 downloadSequences(); 77 if (imagesAdded) { 78 Main.map.statusLine.setHelpText(tr("Downloading image's information")); 79 completeImages(); 80 MapillaryMainDialog.getInstance().updateTitle(); 81 Main.map.statusLine.setHelpText(tr("Downloading traffic signs")); 82 downloadSigns(); 83 } 75 Main.map.statusLine.setHelpText(tr("Downloading image's information")); 76 completeImages(); 77 MapillaryMainDialog.getInstance().updateTitle(); 78 Main.map.statusLine.setHelpText(tr("Downloading traffic signs")); 79 downloadSigns(); 84 80 } catch (InterruptedException e) { 85 81 Main.error("Mapillary download interrupted (probably because of closing the layer)."); … … 97 93 while (!ex.isShutdown()) { 98 94 ex.execute(new MapillarySequenceDownloadThread(ex, sequenceQueryString 99 + "&page=" + page + "&limit=10" , layer, this));95 + "&page=" + page + "&limit=10")); 100 96 while (ex.getQueue().remainingCapacity() == 0) 101 97 Thread.sleep(500); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryTrafficSignDownloaderThread.java
r31401 r31409 19 19 /** 20 20 * Downloads the signs information in a given area. 21 * 21 * 22 22 * @author nokutu 23 23 * … … 32 32 /** 33 33 * Main constructor. 34 * 34 * 35 35 * @param ex 36 36 * {@link ExecutorService} object that is executing this thread. -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java
r31398 r31409 503 503 }); 504 504 } else if (data != null && result == LoadResult.SUCCESS) { 505 System.out.println(attributes.getMetadata()); 505 506 try { 506 507 BufferedImage img = ImageIO.read(new ByteArrayInputStream(data -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryWalkDialog.java
r31401 r31409 10 10 /** 11 11 * Dialog to set the walk mode options. 12 * 12 * 13 13 * @author nokutu 14 14 * … … 22 22 /** Whether it must wait for the picture to be downloaded */ 23 23 public JCheckBox waitForPicture; 24 /** Whether the view must follow the selected image. */ 25 public JCheckBox followSelection; 24 26 25 27 /** … … 33 35 add(interval); 34 36 35 waitForPicture = new JCheckBox("Wait for the picture to be downloaded");37 waitForPicture = new JCheckBox("Wait for full quality pictures"); 36 38 waitForPicture.setSelected(true); 37 39 add(waitForPicture); 40 41 followSelection = new JCheckBox("Follow selected image"); 42 followSelection.setSelected(true); 43 add(followSelection); 38 44 } 39 45 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java
r31404 r31409 26 26 ZoomChangeListener { 27 27 28 private final static int DOWNLOAD_COOLDOWN = 2000; 29 28 30 protected MapillaryData data = MapillaryData.getInstance(); 29 private static finalSemiautomaticThread semiautomaticThread = new SemiautomaticThread();31 private static SemiautomaticThread semiautomaticThread = new SemiautomaticThread(); 30 32 31 33 /** … … 71 73 } 72 74 75 /** 76 * Resets the semiautomatic mode thread. 77 */ 78 public static void resetThread() { 79 semiautomaticThread.interrupt(); 80 semiautomaticThread = new SemiautomaticThread(); 81 } 82 73 83 private static class SemiautomaticThread extends Thread { 74 84 … … 82 92 while (true) { 83 93 if (moved 84 && Calendar.getInstance().getTimeInMillis() - lastDownload >= 2000) {94 && Calendar.getInstance().getTimeInMillis() - lastDownload >= DOWNLOAD_COOLDOWN) { 85 95 lastDownload = Calendar.getInstance().getTimeInMillis(); 86 96 MapillaryDownloader.completeView(); … … 92 102 wait(100); 93 103 } catch (InterruptedException e) { 94 Main.error(e);95 104 } 96 105 } -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillarySequenceDownloadThreadTest.java
r31381 r31409 62 62 while (!ex.isShutdown() && MapillaryLayer.getInstance().getMapillaryData().getImages().size() <= 0 && page < 50) { 63 63 System.out.println("Sending sequence-request "+page+" to Mapillary-servers…"); 64 Thread downloadThread = new MapillarySequenceDownloadThread(ex, queryString+"&page="+page , MapillaryLayer.getInstance(), null);64 Thread downloadThread = new MapillarySequenceDownloadThread(ex, queryString+"&page="+page); 65 65 downloadThread.start(); 66 66 downloadThread.join();
Note:
See TracChangeset
for help on using the changeset viewer.