Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display image detections better on panorama images (not perfect yet)
- Loading branch information
Showing
6 changed files
with
214 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/org/openstreetmap/josm/plugins/mapillary/gui/panorama/UVMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.openstreetmap.josm.plugins.mapillary.gui.panorama; | ||
|
||
import java.awt.geom.Point2D; | ||
|
||
public final class UVMapping { | ||
private UVMapping() { | ||
// Private constructor to avoid instantiation | ||
} | ||
/** | ||
* Returns the point of the texture image that is mapped to the given point in 3D space (given as {@link Vector3D}) | ||
* See <a href="https://en.wikipedia.org/wiki/UV_mapping">the Wikipedia article on UV mapping</a>. | ||
* @param vector the vector to which the texture point is mapped | ||
* @return a point on the texture image somewhere in the rectangle between (0, 0) and (1, 1) | ||
*/ | ||
public static Point2D.Double getTextureCoordinate(final Vector3D vector) { | ||
final double u = 0.5 + (Math.atan2(vector.getX(), vector.getZ()) / (2 * Math.PI)); | ||
final double v = 0.5 + (Math.asin(vector.getY()) / Math.PI); | ||
return new Point2D.Double(u, v); | ||
} | ||
|
||
/** | ||
* For a given point of the texture (i.e. the image), return the point in 3D space where the point | ||
* of the texture is mapped to (as {@link Vector3D}). | ||
* | ||
* @param u x-coordinate of the point on the texture (in the range between 0 and 1, from left to right) | ||
* @param v y-coordinate of the point on the texture (in the range between 0 and 1, from top to bottom) | ||
* @return the vector from the origin to where the point of the texture is mapped on the sphere | ||
*/ | ||
public static Vector3D getVector(final double u, final double v) { | ||
final double vectorY = Math.cos(v * Math.PI); | ||
return new Vector3D( | ||
-Math.sin(2 * Math.PI * u) * Math.sqrt(1 - vectorY * vectorY), | ||
-vectorY, | ||
-Math.cos(2 * Math.PI * u) * Math.sqrt(1 - vectorY * vectorY) | ||
); | ||
} | ||
} |
18 changes: 13 additions & 5 deletions
18
src/org/openstreetmap/josm/plugins/mapillary/gui/panorama/Vector3D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
// License: GPL. For details, see LICENSE file. | ||
package org.openstreetmap.josm.plugins.mapillary.gui.panorama; | ||
|
||
public class Vector3D { | ||
final class Vector3D { | ||
|
||
private double x; | ||
private double y; | ||
private double z; | ||
|
||
public Vector3D(double x, double y, double z) { | ||
Vector3D(double x, double y, double z) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
} | ||
|
||
public double getX() { | ||
double getX() { | ||
return x; | ||
} | ||
public double getY() { | ||
double getY() { | ||
return y; | ||
} | ||
public double getZ() { | ||
double getZ() { | ||
return z; | ||
} | ||
|
||
synchronized Vector3D normalize() { | ||
final double length = Math.sqrt(x*x + y*y + z*z); | ||
x /= length; | ||
y /= length; | ||
z /= length; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.