Commit 241df539 authored by Danny Boxhoorn's avatar Danny Boxhoorn
Browse files

Version 3.1.2 as distributed

parents
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Data.Sql;
/*=====================================================================
File: AssemblyInfo.cs for Spatial Sample
Summary: Asembly-wide attributes
Date: August 16, 2005
======================================================= */
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SphericalHtm")]
[assembly: AssemblyDescription("HTM library")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Johns Hopkins University")]
[assembly: AssemblyProduct("Spherical Htm")]
[assembly: AssemblyCopyright("Copyright Johns Hopkins University 2002-2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: System.CLSCompliant(true)]
[assembly: System.Runtime.InteropServices.ComVisible(false)]
[assembly: System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.RequestMinimum)]
[assembly: System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.MayCorruptInstance, System.Runtime.ConstrainedExecution.Cer.None)]
using System;
using System.Collections;
using System.Collections.Generic;
using Spherical;
using Spherical.Quickhull;
#region Copyright Gyorgy Fekete
/*
* Copyright Alex Szalay, Gyorgy Fekete, Jim Gray 2007
* The Spherical Geometry and Hierarchical Triangular Mesh libraries and source code are
* provided as-is with no warranties. The user is hereby granted a non-exclusive license to use,
* modify and extend these libraries. We ask that the authors (A. Szalay, T. Budavari, G. Fekete
* at The Johns Hopkins University, and Jim Gray, Microsoft Research be credited in any publication
* or derived product that incorporates the whole or any part of our system
*/
#endregion
/*=====================================================================
File: Chull.cs
Summary: Computes the convex hull of a collection of points
on the surface of the sphere.
Date: August 10, 2005
======================================================================= */
namespace Spherical.Shape
{
/// <summary>
///
/// Computes the convex hull of a collection of points
/// on the surface of the sphere. Uses QuickHull3D
/// </summary>
public sealed class Chull {
/// <summary>
/// Various error conditions for unsuccesful convex hull creation
/// </summary>
public enum Cherror {
/// <summary>
/// operation was succesful
/// </summary>
Ok,
/// <summary>
/// points were coplanar, convex hull undefined
/// </summary>
Coplanar,
/// <summary>
/// points can not be confined to any hemisphere, convex hull undefined
/// </summary>
BiggerThanHemisphere,
/// <summary>
/// The required number of points were not present
/// </summary>
NotEnoughPoints,
/// <summary>
/// Other error, not defined
/// </summary>
Unkown
}
/// <summary>
/// Create a convex spherical polygon from the spherical convex hull of the given points
/// </summary>
/// <param name="xs">list of x coords</param>
/// <param name="ys">list of y coords</param>
/// <param name="zs">list of z coords</param>
/// <param name="err">error code</param>
/// <returns>a new Convex object</returns>
public static Convex Make(List<double> xs, List<double> ys, List<double> zs, out Cherror err) {
Convex con = PointsToConvex(xs, ys, zs, out err);
return con;
}
/// <summary>
/// Do not allow default constructor
/// </summary>
private Chull(){
}
public static Convex ToConvex(IList<Cartesian> points, out Cherror err) {
Cartesian origin = new Cartesian(0.0, 0.0, 0.0, false);
Quickhull.QuickHull3D qh = new QuickHull3D();
Cartesian planeNormal;
Convex con = null;
//
// Ingest points into input
//
if(points.Count < 3) {
err = Cherror.NotEnoughPoints;
return con; // Should still be null
}
err = Cherror.Ok; // benefit of doubt;
//
// Add the origin too
//
points.Add(new Cartesian(0.0, 0.0, 0.0, false));
try {
qh.build(points);
// See if the origin is in it
//
//
foreach (Quickhull.Face face in qh.GetFaceList()) {
//
//
double D = face.distanceToPlane(origin);
if (D >= -Spherical.Htm.Trixel.DblTolerance) {
planeNormal = face.getNormal();
if (con == null) {
con = new Convex();
}
con.Add(new Halfspace(-planeNormal.X, -planeNormal.Y, -planeNormal.Z, true, 0.0));
}
}
if (con == null) {
err = Cherror.BiggerThanHemisphere;
}
} catch (Quickhull.QuickHull3D.CoplanarException) {
err = Cherror.Coplanar;
return null;
} catch (Exception) {
err = Cherror.Unkown;
throw;
}
return con;
}
/// <summary>
/// Internal function for which Make(...) serves as a public wrapper
/// </summary>
/// <param name="xs">list of x coorsd</param>
/// <param name="ys">list of y coords</param>
/// <param name="zs">list of z coords</param>
/// <param name="err">error code</param>
/// <returns></returns>
internal static Convex PointsToConvex(List<double> xs, List<double> ys, List<double> zs, out Cherror err) {
Cartesian origin = new Cartesian(0.0, 0.0, 0.0, false);
Quickhull.QuickHull3D qh = new QuickHull3D();
Cartesian planeNormal;
Convex con = null;
//
// Ingest points into input
//
if(xs.Count < 3) {
err = Cherror.NotEnoughPoints;
return con; // Should still be null
}
err = Cherror.Ok; // benefit of doubt;
//
// Add the origin too
//
xs.Add(0.0);
ys.Add(0.0);
zs.Add(0.0);
try {
qh.build(xs, ys, zs);
// See if the origin is in it
//
//
foreach (Quickhull.Face face in qh.GetFaceList()) {
//
//
double D = face.distanceToPlane(origin);
if (D >= -Spherical.Htm.Trixel.DblTolerance) {
planeNormal = face.getNormal();
if (con == null) {
con = new Convex();
}
con.Add(new Halfspace(-planeNormal.X, -planeNormal.Y, -planeNormal.Z, true, 0.0));
}
}
if (con == null) {
err = Cherror.BiggerThanHemisphere;
}
} catch (Quickhull.QuickHull3D.CoplanarException) {
err = Cherror.Coplanar;
return null;
} catch (Exception) {
err = Cherror.Unkown;
throw;
}
return con;
}
}
}
using System;
using Spherical;
#region Copyright Gyorgy Fekete
/*
* Copyright Alex Szalay, Gyorgy Fekete, Jim Gray 2007
* The Spherical Geometry and Hierarchical Triangular Mesh libraries and source code are
* provided as-is with no warranties. The user is hereby granted a non-exclusive license to use,
* modify and extend these libraries. We ask that the authors (A. Szalay, T. Budavari, G. Fekete
* at The Johns Hopkins University, and Jim Gray, Microsoft Research be credited in any publication
* or derived product that incorporates the whole or any part of our system
*/
#endregion
/*=====================================================================
File: Circle.cs
Summary: Implements a circular region of interest on the celestial sphere.
Date: August 10, 2005
======================================================= */
namespace Spherical.Shape
{
/// <summary>
/// Compute a Convex consisting of a single Halfspace based on
/// the parameters of the given circle
/// </summary>
public class Circle
{
/// <summary>
/// Make a Convex from the parameters of the given circle
/// </summary>
/// <param name="ra">Right Ascensionof center</param>
/// <param name="dec">Declinationof center</param>
/// <param name="radius">radius in minutes of arc</param>
/// <returns>a new Convex object</returns>
public static Convex Make(double ra, double dec, double radius)
{
double x, y, z;
Cartesian.Radec2Xyz(ra, dec, out x, out y, out z);
return Make(x, y, z, radius);
}
/// <summary>
/// Make a Convex from the parameters of the given circle
/// </summary>
/// <param name="x">X coord of center on unit sphere</param>
/// <param name="y">Y coord of center on unit sphere</param>
/// <param name="z">Z coord of center on unit sphere</param>
/// <param name="radius">radius in arc minutes</param>
/// <returns>a new Convex object</returns>
public static Convex Make(double x, double y, double z, double radius)
{
Convex con = new Convex();
double arg = Math.PI * radius / 10800.0;
double d;
d = Math.Cos(arg);
con.Add(new Halfspace(new Cartesian (x, y, z, false), d));
return con;
}
}
}
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using Spherical;
#region Copyright Gyorgy Fekete
/*
* Copyright Alex Szalay, Gyorgy Fekete, Jim Gray 2007
* The Spherical Geometry and Hierarchical Triangular Mesh libraries and source code are
* provided as-is with no warranties. The user is hereby granted a non-exclusive license to use,
* modify and extend these libraries. We ask that the authors (A. Szalay, T. Budavari, G. Fekete
* at The Johns Hopkins University, and Jim Gray, Microsoft Research be credited in any publication
* or derived product that incorporates the whole or any part of our system
*/
#endregion
/*=====================================================================
File: Enums.cs
Summary: All enumerated types not in a class
Date: August 10, 2005
======================================================= */
/// <summary>
/// All Enumerated types and their text descriptions are here
///
/// </summary>
///
namespace Spherical.Htm {
/// <summary>
/// Markup is a classification of a trixel with respect to the way it intersects a
/// region.
/// </summary>
public enum Markup {
/// <summary>trixel is completely inside</summary>
Inner,
/// <summary>trixel non-trivially intersects</summary>
Partial,
/// <summary>trixel is completely outside</summary>
Reject,
/// <summary>trixel's status is not known</summary>
Undefined,
/// <summary>
/// used for requesting trixels that are either Inner or Partial
/// </summary>
Outer
};
/// <summary>
/// HaltCodition
/// </summary>
enum HaltCondition {
Continue,
Hold,
Backup
};
}

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spherical.HTM", "Spherical.HTM.csproj", "{9F6D1199-5581-487C-850F-08AC5505DAE8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9F6D1199-5581-487C-850F-08AC5505DAE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F6D1199-5581-487C-850F-08AC5505DAE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F6D1199-5581-487C-850F-08AC5505DAE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F6D1199-5581-487C-850F-08AC5505DAE8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
#region Copyright Gyorgy Fekete
/*
* Copyright Alex Szalay, Gyorgy Fekete, Jim Gray 2007
* The Spherical Geometry and Hierarchical Triangular Mesh libraries and source code are
* provided as-is with no warranties. The user is hereby granted a non-exclusive license to use,
* modify and extend these libraries. We ask that the authors (A. Szalay, T. Budavari, G. Fekete
* at The Johns Hopkins University, and Jim Gray, Microsoft Research be credited in any publication
* or derived product that incorporates the whole or any part of our system
*/
#endregion
/*=====================================================================
File: HidRanges.cs
Summary: Implements a sorted list of HtmID intervals.
Date: December, 2006
======================================================= */
namespace Spherical.Htm
{
public struct Int64AugPair {
public bool full;
public Int64 lo;
public Int64 hi;
public Int64AugPair(Int64Pair lohi, bool full) {
this.lo = lohi.lo;
this.hi = lohi.hi;
this.full = full;
}
public Int64AugPair(Int64 lo, Int64 hi, bool full) {
this.lo = lo;
this.hi = hi;
this.full = full;
}
}
public struct Int64Pair
{
public Int64 lo;
public Int64 hi;
public Int64Pair(Int64 lo, Int64 hi) {
this.lo = lo;
this.hi = hi;
}
};
public class Hidranges
{
public List<Int64Pair> pairList = new List<Int64Pair>();
public Hidranges() {
}
internal Hidranges(List<SmartTrixel> nodeList, bool sortandcheck, int deepest) {
if(nodeList != null) {
foreach(SmartTrixel qt in nodeList) {
if(qt.Level <= deepest) {
Int64Pair range = Trixel.Extend(qt.Hid, 20);
this.AddRange(range);
} else {
break;
}
}
if(sortandcheck) {
this.Sort();
this.Compact();
this.Check();
}
}
}
internal Hidranges(List<SmartTrixel> nodeList, bool sortandcheck){
if (nodeList != null) {
foreach (SmartTrixel qt in nodeList) {
Int64Pair range = Trixel.Extend(qt.Hid, 20);
this.AddRange(range);
}
if (sortandcheck) {
this.Sort();
this.Compact();
this.Check();
}
}
}
static private bool isDisjoint(Int64Pair a, Int64Pair b) {
return (a.hi < b.lo || b.hi < a.lo);
}
public static List<Int64Pair> Combine(List<Int64Pair> ranges, List<Int64Pair> newranges) {
List<Int64Pair> result = new List<Int64Pair>(ranges.Count);
Int64Pair proto;
// Pop one list into proto
bool protomod = false;
bool protovalid = false;
if(newranges.Count < 1) {
foreach(Int64Pair p in ranges) {
result.Add(p);
}
return result;
}
// Build a new range
int left = newranges.Count + ranges.Count;
int i = 0, j = 0;
if(ranges.Count > 0 && ranges[0].lo <= newranges[0].lo) {
proto.lo = ranges[0].lo;
proto.hi = ranges[0].hi;
protomod = true;
protovalid = true;
i++;
} else {
proto.lo = newranges[0].lo;
proto.hi = newranges[0].hi;
protomod = true;
protovalid = true;
j++;
}
left--;
while(left > 0) {
protomod = false; // See if this iteration modifies proto..
if(!protovalid) {
if(i >= ranges.Count) { // main list is exhausted
proto.lo = newranges[j].lo;
proto.hi = newranges[j].hi;
protomod = true;
protovalid = true;
j++;
} else if(j >= newranges.Count) { // newrange exhausted
proto.lo = ranges[i].lo;
proto.hi = ranges[i].hi;
protomod = true;
protovalid = true;
i++;
} else if(ranges.Count > 0 && ranges[i].lo <= newranges[j].lo) {
proto.lo = ranges[i].lo;
proto.hi = ranges[i].hi;
protomod = true;
protovalid = true;
i++;
} else {
proto.lo = newranges[j].lo;
proto.hi = newranges[j].hi;
protomod = true;
protovalid = true;
j++;
}
left--;
}
if(i < ranges.Count) {
if(protovalid && !isDisjoint(proto, ranges[i])) {
proto.lo = Math.Min(ranges[i].lo, proto.lo);
proto.hi = Math.Max(ranges[i].hi, proto.hi);
i++;
left--;
protomod = true;
}
}
// proto may have been modified above
//
if(j < newranges.Count) {
if(protovalid && !isDisjoint(proto, newranges[j])) {
proto.lo = Math.Min(newranges[j].lo, proto.lo);
proto.hi = Math.Max(newranges[j].hi, proto.hi);
j++;
left--;
protomod = true;
}
}
if(!protomod) { // proto was disjoint from both rangetops
result.Add(proto);
protomod = false;
protovalid = false;
}
// only continue, if both lists are nonempty
//if (j >= newranges.Count || i >= pairList.Count) {
// break;
//}
}
if(protovalid) {
result.Add(proto);
protovalid = false;
}
return result;
}
/// <summary>
/// merge a given list into the current list of pairs
/// </summary>
/// <param name="newranges"></param>
internal void Merge(List<Int64Pair> newranges) {
pairList = Combine(this.pairList, newranges);
}
/// <summary>
/// Add pair of hids to internal list of pairs. Does not do checking
/// </summary>
/// <param name="pair"></param>
//TODO: make internal
public void AddRange(Int64Pair pair) {
pairList.Add(pair);
}
/// <summary>
/// add pair of hids to internal list of pairs. Does not do checking
/// </summary>
/// <param name="lo"></param>
/// <param name="hi"></param>
//TODO: deprecate:
public void AddRange(Int64 lo, Int64 hi) {
Int64Pair tp;
tp.lo = lo;
tp.hi = hi;
pairList.Add(tp);
return;
}
public void Clear() {
pairList.Clear();
}
/// <summary>
/// Comparator for sorting ranges
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int CompareTo(Int64Pair a, Int64Pair b) {
return a.lo.CompareTo(b.lo);
}
/// <summary>
/// Ensure that ranges are disjoint
/// </summary>
public void Check() {
for (int i = 1; i < pairList.Count; i++) {
if (pairList[i - 1].hi > pairList[i].lo) {
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Range.check i={0}: ({1}, {2}), ({3}, {4})",
i, pairList[i-1].lo, pairList[i-1].hi,
pairList[i].lo, pairList[i].hi);
throw new InternalErrorException(sb.ToString());
}
}
}
/// <summary>
/// Sort Interval by lows
/// </summary>
public void Sort() {
pairList.Sort(CompareTo);
}
/// <summary>
/// perform sanity check for the health of sorted pairs
/// throws an exception if check fails, else returns quietly
/// </summary>
/// <param name="sortedpairs"></param>
/// <returns></returns>