Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xfischer committed Apr 14, 2020
2 parents 316cbca + 956bfcd commit e64675e
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 28 deletions.
24 changes: 24 additions & 0 deletions DEM.Net.Core/Helpers/HeightMapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -36,6 +37,29 @@ namespace DEM.Net.Core
/// </summary>
public static class HeightMapExtensions
{
/// <summary>
/// Centers height map on origin
/// </summary>
/// <param name="heightMap"></param>
/// <returns></returns>
/// <remarks>This can be used in an height map processing pipeline, as coordinates are changed only on enumeration</remarks>
public static HeightMap CenterOnOrigin(this HeightMap heightMap, out Matrix4x4 transform)
{
//Logger.Info("CenterOnOrigin...");
var bbox = heightMap.BoundingBox;

double xOriginOffset = bbox.xMax - (bbox.xMax - bbox.xMin) / 2d;
double yOriginOffset = bbox.yMax - (bbox.yMax - bbox.yMin) / 2d;
heightMap.Coordinates = heightMap.Coordinates.Translate(-xOriginOffset, -yOriginOffset);

// world to model is (x,y,z) -> (x,z,-y)
// translate (X,Y,0) -> (X,0,-Y)
transform = System.Numerics.Matrix4x4.CreateTranslation(-(float)xOriginOffset, 0, (float)yOriginOffset);

heightMap.BoundingBox = new BoundingBox(bbox.xMin - xOriginOffset, bbox.xMax - xOriginOffset
, bbox.yMin - yOriginOffset, bbox.yMax - yOriginOffset);
return heightMap;
}
/// <summary>
/// Centers height map on origin
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion DEM.Net.Core/Model/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public BoundingBox Scale(double scale)
}
public BoundingBox Scale(double scaleX, double scaleY)
{
return new BoundingBox(xMin + Width * scaleX, xMax - Width * scaleX, yMin + Height * scaleY, yMax - Height * scaleY);
return new BoundingBox(xMin - Width * scaleX, xMax + Width * scaleX, yMin - Height * scaleY, yMax + Height * scaleY);
}
/// <summary>
/// Add padding around bbox (bbox must be projected to cartesian first)
Expand Down
8 changes: 8 additions & 0 deletions DEM.Net.Core/Model/GeoPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ public bool Equals(GeoPoint other)
return Math.Abs(this.Latitude - other.Latitude) < double.Epsilon
&& Math.Abs(this.Longitude - other.Longitude) < double.Epsilon;
}

public override int GetHashCode()
{
int hashCode = -1416534245;
hashCode = hashCode * -1521134295 + Latitude.GetHashCode();
hashCode = hashCode * -1521134295 + Longitude.GetHashCode();
return hashCode;
}
}


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Setup(DEMDataSet dataSet, string dataSetLocalDir)
if (hasData)
{
// Only retrieve bbox and dem file link (zip file)
links.AddRange(result.Feed.Entry.Select(GetNasaDemFile));
links.AddRange(result.Feed.Entry.Select(GetNasaDemFile).Where(file => file != null));
}
}
}
Expand Down Expand Up @@ -108,18 +108,27 @@ public void Setup(DEMDataSet dataSet, string dataSetLocalDir)

private NasaDemFile GetNasaDemFile(Entry entry)
{
if (entry == null)
throw new ArgumentNullException(nameof(entry), "Entry is mandatory.");
if (entry.Boxes == null || entry.Boxes.Count == 0)
throw new ArgumentNullException(nameof(entry.Boxes), "Boxes should contain at least an element.");
if (entry.Links == null || entry.Links.Count == 0)
throw new ArgumentNullException(nameof(entry.Links), "Links should contain at least an element.");

var link = entry.Links.FirstOrDefault(l => l.Type == TypeEnum.ApplicationZip);
if (link == null)
throw new ArgumentNullException(nameof(link), "ApplicationZip Link is mandatory.");

return new NasaDemFile(entry.ProducerGranuleId, entry.Boxes.First(), link.Href.AbsoluteUri);
try
{
if (entry == null)
throw new ArgumentNullException(nameof(entry), "Entry is mandatory.");
if (entry.Boxes == null || entry.Boxes.Count == 0)
throw new ArgumentNullException(nameof(entry.Boxes), "Boxes should contain at least an element.");
if (entry.Links == null || entry.Links.Count == 0)
throw new ArgumentNullException(nameof(entry.Links), "Links should contain at least an element.");

var link = entry.Links.FirstOrDefault(l => l.Type == TypeEnum.ApplicationZip);
if (link == null)
throw new ArgumentNullException(nameof(link), "ApplicationZip Link is mandatory.");

return new NasaDemFile(entry.ProducerGranuleId, entry.Boxes.First(), link.Href.AbsoluteUri);
}
catch (Exception ex)
{
logger.LogWarning("Error parsing Nasa entry. File will be ignored: " + ex.Message);
return null;
}

}

private List<DEMFileSource> GetSources(DEMDataSet dataSet, string indexFileName)
Expand Down
25 changes: 12 additions & 13 deletions DEM.Net.Core/Services/GeometryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ public static BoundingBox GetBoundingBox(this IGeometry geom)
/// <returns></returns>
public static BoundingBox GetBoundingBox(this IEnumerable<GeoPoint> points)
{
BoundingBox bbox = new BoundingBox(double.MaxValue, double.MinValue, double.MaxValue, double.MinValue);
double xmin = double.MaxValue, ymin = double.MaxValue, xmax = double.MinValue, ymax = double.MinValue;

foreach (var pt in points)
{
bbox.xMin = Math.Min(bbox.xMin, pt.Longitude);
bbox.xMax = Math.Max(bbox.xMax, pt.Longitude);
xmin = Math.Min(xmin, pt.Longitude);
xmax = Math.Max(xmax, pt.Longitude);

bbox.yMin = Math.Min(bbox.yMin, pt.Latitude);
bbox.yMax = Math.Max(bbox.yMax, pt.Latitude);
ymin = Math.Min(ymin, pt.Latitude);
ymax = Math.Max(ymax, pt.Latitude);
}
return bbox;
return new BoundingBox(xmin, xmax, ymin, ymax);
}
/// <summary>
/// Returns the bouding box of a segment
Expand All @@ -114,15 +114,14 @@ public static BoundingBox GetBoundingBox(this IEnumerable<GeoPoint> points)
/// <returns></returns>
public static BoundingBox GetBoundingBox(this GeoSegment segment)
{
BoundingBox bbox = new BoundingBox(double.MaxValue, double.MinValue, double.MaxValue, double.MinValue);
double xmin = double.MaxValue, ymin = double.MaxValue, xmax = double.MinValue, ymax = double.MinValue;
xmin = Math.Min(segment.Start.Longitude, segment.End.Longitude);
xmax = Math.Max(segment.Start.Longitude, segment.End.Longitude);

bbox.xMin = Math.Min(segment.Start.Longitude, segment.End.Longitude);
bbox.xMax = Math.Max(segment.Start.Longitude, segment.End.Longitude);
ymin = Math.Min(segment.Start.Latitude, segment.End.Latitude);
ymax = Math.Max(segment.Start.Latitude, segment.End.Latitude);

bbox.yMin = Math.Min(segment.Start.Latitude, segment.End.Latitude);
bbox.yMax = Math.Max(segment.Start.Latitude, segment.End.Latitude);

return bbox;
return new BoundingBox(xmin, xmax, ymin, ymax);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion DEM.Net.glTF/gtlfSharp/IndexedTriangulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class IndexedTriangulation
{
private Triangulation Triangulation;

public List<Vector3> Positions { get; private set; }
public List<Vector3> Positions { get; set; }
public List<Vector4> Colors { get; private set; }
public List<int> Indices { get; private set; }

Expand Down

0 comments on commit e64675e

Please sign in to comment.