public final class HealpixNestedFast extends java.lang.Object implements HashComputer, VerticesAndPathComputer, NeighbourSelector
HealpixNested
.
The code has also been "denormalise" to try to be faster: we introduce redundancy by suppressing
method calls when a method must return more than one elements, ...
Motivations: in Java, all arguments of a function are passed-by-value. And, like most languages,
a function returns only one output. It means that if, e.g. a function as to return a pair of
coordinate you have only two solutions: the first one is to instantiate an object containing
the pair of coordinates and return it, or the method have to take an object and set the pair
of coordinates.
In this "fast version", we duplicate code to avoid creating objects inside critical methods and
we write the results in arguments instead of returning new objects. The instantiation of an
object in Java is cheap, but it cost is not negligible compared to the speed of HEALPix methods.Modifier and Type | Field and Description |
---|---|
static byte[][] |
D0H_NEIGHBOURS
For each of the 12 hash of depth 0, contains the list of the depth 0
neighbours sorted by increasing hash value.
|
static byte[][][] |
NEIGHBOURS |
ALL_CARDINAL_POINTS, LAT_INDEX, LON_INDEX
ALL_MAIN_WINDS
Constructor and Description |
---|
HealpixNestedFast(int depth,
FillingCurve2DType fillingCurveType) |
Modifier and Type | Method and Description |
---|---|
double[] |
center(long hash)
Compute the position on the unit sphere of the center (in the Euclidean projection plane)
of the cell associated to the given hash value.
|
void |
center(long hash,
double[] resultLonLat)
See
VerticesAndPathComputer.center(long) , except that the result is stored in the given array. |
int |
depth()
Returns the depth of the hash computed by
HashComputer.hash(double, double) method. |
FlatHashList |
externalEdges(long hash,
int deltaDepth) |
void |
externalEdges(long hash,
int toEdgeDeltaDepth,
FlatHashList result) |
long |
hash(double lonRad,
double latRad)
Returns the HEALPix hash value of the given coordinate at this object depth.
|
long |
internalCorner(long hash,
int toEdgeDeltaDepth,
CompassPoint.Cardinal direction) |
long |
internalCornerE(long hash,
int toEdgeDeltaDepth) |
long |
internalCornerN(long hash,
int toEdgeDeltaDepth) |
long |
internalCornerS(long hash,
int toEdgeDeltaDepth) |
long |
internalCornerW(long hash,
int toEdgeDeltaDepth) |
FlatHashList |
internalEdges(long hash,
int toEdgeDeltaDepth) |
void |
internalEdges(long hash,
int toEdgeDeltaDepth,
FlatHashList result) |
long |
neighbour(long hash,
CompassPoint.MainWind direction)
The hash value of the neighbour of the cell of given hash, in the given deirection.
|
NeighbourList |
neighbours(long hash)
Returns the list of the hash of the cells surrounding the cell defined
by the given hash.
|
NeighbourList |
neighbours(long hash,
java.util.EnumSet<CompassPoint.MainWind> directions)
Equivalent of
NeighbourSelector.neighbours(long, FlatHashList) but with the list of direction of the
wanted neighbours. |
void |
neighbours(long hash,
java.util.EnumSet<CompassPoint.MainWind> directions,
NeighbourList result)
Equivalent of
NeighbourSelector.neighbours(long, FlatHashList) but with the list of direction of the
wanted neighbours. |
void |
neighbours(long hash,
FlatHashList neighbours)
Idem as
NeighbourSelector.neighbours(long, NeighbourList) except that the result is put in a
simple FlatHashList . |
void |
neighbours(long hash,
NeighbourList result)
Equivalent of
NeighbourSelector.neighbours(long) but passing in argument the
list object to be filled. |
double[][] |
pathAlongCellEdge(long hash,
CompassPoint.Cardinal startingVertex,
boolean clockwiseDirection,
int nSegmentsBySide) |
void |
pathAlongCellEdge(long hash,
CompassPoint.Cardinal startingVertex,
boolean clockwiseDirection,
int nSegmentsBySide,
double[][] pathPoints)
See
#pathAlongCellEdge(long, Cardinal, boolean, int) . |
double[][] |
pathAlongCellSide(long hash,
CompassPoint.Cardinal fromVertex,
CompassPoint.Cardinal toVertex,
boolean isToVertexIncluded,
int nSegments)
Compute points on a given side of a given HEALPix cell on the unit sphere.
|
void |
pathAlongCellSide(long hash,
CompassPoint.Cardinal fromVertex,
CompassPoint.Cardinal toVertex,
boolean isToVertexIncluded,
int nSegments,
double[][] pathPoints)
See
#pathAlongCellSide(long, Cardinal, Cardinal, boolean, int) . |
FlatHashList |
sortedExternalEdges(long hash,
int deltaDepth) |
void |
sortedExternalEdges(long hash,
int toEdgeDeltaDepth,
FlatHashList result) |
FlatHashList |
sortedInternalEdge(long hash,
int deltaDepth,
CompassPoint.Ordinal direction) |
void |
sortedInternalEdge(long hash,
int deltaDepth,
CompassPoint.Ordinal direction,
FlatHashList result) |
FlatHashList |
sortedInternalEdgeNE(long hash,
int deltaDepth) |
void |
sortedInternalEdgeNE(long hash,
int deltaDepth,
FlatHashList result) |
FlatHashList |
sortedInternalEdgeNW(long hash,
int deltaDepth) |
void |
sortedInternalEdgeNW(long hash,
int deltaDepth,
FlatHashList result) |
FlatHashList |
sortedInternalEdges(long hash,
int deltaDepth) |
void |
sortedInternalEdges(long hash,
int toEdgeDeltaDepth,
FlatHashList result) |
FlatHashList |
sortedInternalEdgeSE(long hash,
int deltaDepth) |
void |
sortedInternalEdgeSE(long hash,
int deltaDepth,
FlatHashList result) |
FlatHashList |
sortedInternalEdgeSW(long hash,
int deltaDepth) |
void |
sortedInternalEdgeSW(long hash,
int deltaDepth,
FlatHashList result) |
double[] |
vertex(long hash,
CompassPoint.Cardinal cardinalPoint)
Compute the position of an HEALPix cell vertex on the unit sphere.
|
void |
vertex(long hash,
CompassPoint.Cardinal vertexDirection,
double[] resultLonLat)
See
#vertex(long, Cardinal) , except that the result is stored in the given array. |
void |
vertices(long hash,
java.util.EnumMap<CompassPoint.Cardinal,double[]> cardinalPoints)
|
java.util.EnumMap<CompassPoint.Cardinal,double[]> |
vertices(long hash,
java.util.EnumSet<CompassPoint.Cardinal> cardinalPoints)
Returns the vertices located at the given cardinal points.
|
public static final byte[][] D0H_NEIGHBOURS
public static final byte[][][] NEIGHBOURS
public HealpixNestedFast(int depth, FillingCurve2DType fillingCurveType)
public int depth()
HashComputer
HashComputer.hash(double, double)
method.depth
in interface HashComputer
depth
in interface HierarchyItem
HashComputer.hash(double, double)
method.public long hash(double lonRad, double latRad)
HashComputer
hash
in interface HashComputer
lonRad
- longitude in radians, must support reasonably large positive and negative values
producing accurate results with a naive range reduction like modulo 2*pi
(i.e. without having to resort on Cody-Waite or Payne Hanek range reduction).latRad
- latitude in [-pi/2, pi/2] radianspublic double[] center(long hash)
VerticesAndPathComputer
center
in interface VerticesAndPathComputer
hash
- hash value of the cell we look for the unprojected centerVerticesAndPathComputer.LON_INDEX
and VerticesAndPathComputer.LAT_INDEX
respectively.
Lat in [-pi/2, pi/2] radians, lon is in [0, 2pi] radians.public void center(long hash, double[] resultLonLat)
VerticesAndPathComputer
VerticesAndPathComputer.center(long)
, except that the result is stored in the given array.center
in interface VerticesAndPathComputer
hash
- hash value of the cell we look for the unprojected center.resultLonLat
- array used to store the result. Must be of size >= 2.public double[] vertex(long hash, CompassPoint.Cardinal cardinalPoint)
VerticesAndPathComputer
vertex
in interface VerticesAndPathComputer
hash
- hash value of the cell we look for the given vertex.cardinalPoint
- location of the vertex with respect to the cell centerVerticesAndPathComputer.LON_INDEX
and VerticesAndPathComputer.LAT_INDEX
respectively.
Lat is in [-pi/2, pi/2] radians, lon is in [0, 2pi] radians.public void vertex(long hash, CompassPoint.Cardinal vertexDirection, double[] resultLonLat)
VerticesAndPathComputer
#vertex(long, Cardinal)
, except that the result is stored in the given array.vertex
in interface VerticesAndPathComputer
hash
- hash value of the cell we look for the given vertex.vertexDirection
- location of the vertex with respect to the cell centerresultLonLat
- array used to store the result. Must be of size >= 2.public java.util.EnumMap<CompassPoint.Cardinal,double[]> vertices(long hash, java.util.EnumSet<CompassPoint.Cardinal> cardinalPoints)
VerticesAndPathComputer
EnumSet.allOf(Cardinal)
.
For West and East vertices, use EnumSet.of(Cardinal.W, Cardinal.E)
.vertices
in interface VerticesAndPathComputer
hash
- hash value of the cell we look for the given vertices.cardinalPoints
- locations of the vertices we look for the positionsVerticesAndPathComputer.LON_INDEX
and VerticesAndPathComputer.LAT_INDEX
respectively.
Lat is in [-pi/2, pi/2] radians, lon is in [0, 2pi] radians.public void vertices(long hash, java.util.EnumMap<CompassPoint.Cardinal,double[]> cardinalPoints)
VerticesAndPathComputer
VerticesAndPathComputer.vertices(long, EnumSet)
. The difference is that the user provides a
pre-set Map. The structure of the Map is not modified, but the coordinates of the values
(array values) are overwritten. An error will be thrown if a value is null or contains
less than two elements.vertices
in interface VerticesAndPathComputer
hash
- hash value of the cell we look for the given vertices.cardinalPoints
- the map to be modified ypublic double[][] pathAlongCellSide(long hash, CompassPoint.Cardinal fromVertex, CompassPoint.Cardinal toVertex, boolean isToVertexIncluded, int nSegments)
VerticesAndPathComputer
pathAlongCellSide
in interface VerticesAndPathComputer
hash
- hash value of the cell we look for side path on the unit sphere.fromVertex
- direction (from the cell center) of the path starting vertextoVertex
- direction (from the cell center) of the path ending vertexisToVertexIncluded
- if false
, the result contains nSegments
points and do
no include the result ending vertex. Else the result contains
nSegments + 1
points.nSegments
- number of segments in the path from the starting vertex to the ending vertexpublic void pathAlongCellSide(long hash, CompassPoint.Cardinal fromVertex, CompassPoint.Cardinal toVertex, boolean isToVertexIncluded, int nSegments, double[][] pathPoints)
VerticesAndPathComputer
#pathAlongCellSide(long, Cardinal, Cardinal, boolean, int)
. The difference is that
the user provides a list of points whose coordinates are going to be overwritten.
An error will be thrown if the array (of array) is not large enough (i.e. its is smaller than
nSegments or nSegments + 1) or if one of the array is null or contains less than two elements.pathAlongCellSide
in interface VerticesAndPathComputer
hash
- hash value of the cell we look for side path on the unit sphere.fromVertex
- direction (from the cell center) of the path starting vertextoVertex
- direction (from the cell center) of the path ending vertexisToVertexIncluded
- if false
, the result contains nSegments
points and do
no include the result ending vertex. Else the result contains
nSegments + 1
points.nSegments
- number of segments in the path from the starting vertex to the ending vertexpathPoints
- object used to store the result.public double[][] pathAlongCellEdge(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide)
pathAlongCellEdge
in interface VerticesAndPathComputer
hash
- hash value of the cell we look for the edge path on the unit sphere.startingVertex
- direction (from the cell center) of the path starting vertexclockwiseDirection
- if true
, result points are stored in a clockwise direction
order, else they are stored in counter-clockwise direction order.nSegmentsBySide
- number of segments in each each side is divided. Hence, the total number
of points in the result is 4 x nSegmentsBySide
.public void pathAlongCellEdge(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide, double[][] pathPoints)
VerticesAndPathComputer
#pathAlongCellEdge(long, Cardinal, boolean, int)
. The difference is that the user
provides a list of points whose coordinates are going to be overwritten.
An error will be thrown if the array (of array) is not large enough (i.e. its is smaller than
4 *nSegments) or if one of the array is null or contains less than two elements.pathAlongCellEdge
in interface VerticesAndPathComputer
hash
- hash hash value of the cell we look for the edge path on the unit sphere.startingVertex
- direction (from the cell center) of the path starting vertexclockwiseDirection
- if true
, result points are stored in a clockwise direction
order, else they are stored in counter-clockwise direction order.nSegmentsBySide
- number of segments in each each side is divided. Hence, the total number
of points in the result is 4 x nSegmentsBySide
.pathPoints
- object used to store the result.public void neighbours(long hash, FlatHashList neighbours)
NeighbourSelector
NeighbourSelector.neighbours(long, NeighbourList)
except that the result is put in a
simple FlatHashList
.
WARNING: the content of the provided list is overwritten, and be sure
the list is large enough (at least of size 8).neighbours
in interface NeighbourSelector
hash
- the hash code we want the neighboursneighbours
- which contains the list of neighbours from index 0 to the number of neighbourspublic long neighbour(long hash, CompassPoint.MainWind direction)
NeighbourSelector
neighbour
in interface NeighbourSelector
hash
- ash value of the cell we are looking for the neighbour.direction
- direction of the neighbour we are looking for.public NeighbourList neighbours(long hash)
NeighbourSelector
neighbours
in interface NeighbourSelector
hash
- hash value of the cell we are looking for the neighbours.public NeighbourList neighbours(long hash, java.util.EnumSet<CompassPoint.MainWind> directions)
NeighbourSelector
NeighbourSelector.neighbours(long, FlatHashList)
but with the list of direction of the
wanted neighbours.neighbours
in interface NeighbourSelector
hash
- hash value of the cell we are looking for the neighbours.directions
- the directions of the neighbours we are looking for.public void neighbours(long hash, NeighbourList result)
NeighbourSelector
NeighbourSelector.neighbours(long)
but passing in argument the
list object to be filled.
WARNING: the content of the provided list is overwritten, and be sure
the list is large enough (at least of size 8).
And the value -1 is returned if the given hash has no neighbour at the given main wind direction.neighbours
in interface NeighbourSelector
hash
- the hash code we want the neighboursresult
- which contains the list of neighbours from index 0 to the number of neighbourspublic void neighbours(long hash, java.util.EnumSet<CompassPoint.MainWind> directions, NeighbourList result)
NeighbourSelector
NeighbourSelector.neighbours(long, FlatHashList)
but with the list of direction of the
wanted neighbours.
And the value -1 is returned if the given hash has no neighbour at the given main wind direction.neighbours
in interface NeighbourSelector
hash
- hash value of the cell we are looking for the neighbours.directions
- the directions of the neighbours we are looking for.result
- the list holding the result.public FlatHashList internalEdges(long hash, int toEdgeDeltaDepth)
internalEdges
in interface NeighbourSelector
public void internalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)
internalEdges
in interface NeighbourSelector
public FlatHashList sortedInternalEdges(long hash, int deltaDepth)
sortedInternalEdges
in interface NeighbourSelector
public void sortedInternalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)
sortedInternalEdges
in interface NeighbourSelector
public FlatHashList sortedInternalEdge(long hash, int deltaDepth, CompassPoint.Ordinal direction)
sortedInternalEdge
in interface NeighbourSelector
public void sortedInternalEdge(long hash, int deltaDepth, CompassPoint.Ordinal direction, FlatHashList result)
sortedInternalEdge
in interface NeighbourSelector
public FlatHashList sortedInternalEdgeSE(long hash, int deltaDepth)
sortedInternalEdgeSE
in interface NeighbourSelector
public void sortedInternalEdgeSE(long hash, int deltaDepth, FlatHashList result)
sortedInternalEdgeSE
in interface NeighbourSelector
public FlatHashList sortedInternalEdgeNE(long hash, int deltaDepth)
sortedInternalEdgeNE
in interface NeighbourSelector
public void sortedInternalEdgeNE(long hash, int deltaDepth, FlatHashList result)
sortedInternalEdgeNE
in interface NeighbourSelector
public FlatHashList sortedInternalEdgeNW(long hash, int deltaDepth)
sortedInternalEdgeNW
in interface NeighbourSelector
public void sortedInternalEdgeNW(long hash, int deltaDepth, FlatHashList result)
sortedInternalEdgeNW
in interface NeighbourSelector
public FlatHashList sortedInternalEdgeSW(long hash, int deltaDepth)
sortedInternalEdgeSW
in interface NeighbourSelector
public void sortedInternalEdgeSW(long hash, int deltaDepth, FlatHashList result)
sortedInternalEdgeSW
in interface NeighbourSelector
public long internalCorner(long hash, int toEdgeDeltaDepth, CompassPoint.Cardinal direction)
internalCorner
in interface NeighbourSelector
public long internalCornerN(long hash, int toEdgeDeltaDepth)
internalCornerN
in interface NeighbourSelector
public long internalCornerS(long hash, int toEdgeDeltaDepth)
internalCornerS
in interface NeighbourSelector
public long internalCornerE(long hash, int toEdgeDeltaDepth)
internalCornerE
in interface NeighbourSelector
public long internalCornerW(long hash, int toEdgeDeltaDepth)
internalCornerW
in interface NeighbourSelector
public FlatHashList externalEdges(long hash, int deltaDepth)
externalEdges
in interface NeighbourSelector
public void externalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)
externalEdges
in interface NeighbourSelector
public FlatHashList sortedExternalEdges(long hash, int deltaDepth)
sortedExternalEdges
in interface NeighbourSelector
public void sortedExternalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)
sortedExternalEdges
in interface NeighbourSelector
Copyright © 2018 F.-X. Pineau, CDS, Observatoire Astronomique de Strasbourg, Universite de Strasbourg, CNRS. All Rights Reserved.