Package cds.healpix
Class HealpixNestedFast
- java.lang.Object
-
- cds.healpix.HealpixNestedFast
-
- All Implemented Interfaces:
HashComputer,HierarchyItem,NeighbourSelector,VerticesAndPathComputer
public final class HealpixNestedFast extends java.lang.Object implements HashComputer, VerticesAndPathComputer, NeighbourSelector
A faster, thread-safe, but ugly (sorry: less readable) version ofHealpixNested. 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.- Author:
- F.-X. Pineau
-
-
Field Summary
Fields Modifier and Type Field Description static byte[][]D0H_NEIGHBOURSFor each of the 12 hash of depth 0, contains the list of the depth 0 neighbours sorted by increasing hash value.static byte[][][]NEIGHBOURS-
Fields inherited from interface cds.healpix.NeighbourSelector
ALL_MAIN_WINDS
-
Fields inherited from interface cds.healpix.VerticesAndPathComputer
ALL_CARDINAL_POINTS, LAT_INDEX, LON_INDEX
-
-
Constructor Summary
Constructors Constructor Description HealpixNestedFast(int depth, FillingCurve2DType fillingCurveType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.voidcenter(long hash, double[] resultLonLat)SeeVerticesAndPathComputer.center(long), except that the result is stored in the given array.intdepth()Returns the depth of the hash computed byHashComputer.hash(double, double)method.FlatHashListexternalEdges(long hash, int deltaDepth)voidexternalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)longhash(double lonRad, double latRad)Returns the HEALPix hash value of the given coordinate at this object depth.longinternalCorner(long hash, int toEdgeDeltaDepth, CompassPoint.Cardinal direction)longinternalCornerE(long hash, int toEdgeDeltaDepth)longinternalCornerN(long hash, int toEdgeDeltaDepth)longinternalCornerS(long hash, int toEdgeDeltaDepth)longinternalCornerW(long hash, int toEdgeDeltaDepth)FlatHashListinternalEdges(long hash, int toEdgeDeltaDepth)voidinternalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)longneighbour(long hash, CompassPoint.MainWind direction)The hash value of the neighbour of the cell of given hash, in the given deirection.NeighbourListneighbours(long hash)Returns the list of the hash of the cells surrounding the cell defined by the given hash.voidneighbours(long hash, FlatHashList neighbours)Idem asNeighbourSelector.neighbours(long, NeighbourList)except that the result is put in a simpleFlatHashList.voidneighbours(long hash, NeighbourList result)Equivalent ofNeighbourSelector.neighbours(long)but passing in argument the list object to be filled.NeighbourListneighbours(long hash, java.util.EnumSet<CompassPoint.MainWind> directions)Equivalent ofNeighbourSelector.neighbours(long, FlatHashList)but with the list of direction of the wanted neighbours.voidneighbours(long hash, java.util.EnumSet<CompassPoint.MainWind> directions, NeighbourList result)Equivalent ofNeighbourSelector.neighbours(long, FlatHashList)but with the list of direction of the wanted neighbours.double[][]pathAlongCellEdge(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide)voidpathAlongCellEdge(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide, double[][] pathPoints)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.voidpathAlongCellSide(long hash, CompassPoint.Cardinal fromVertex, CompassPoint.Cardinal toVertex, boolean isToVertexIncluded, int nSegments, double[][] pathPoints)FlatHashListsortedExternalEdges(long hash, int deltaDepth)voidsortedExternalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)FlatHashListsortedInternalEdge(long hash, int deltaDepth, CompassPoint.Ordinal direction)voidsortedInternalEdge(long hash, int deltaDepth, CompassPoint.Ordinal direction, FlatHashList result)FlatHashListsortedInternalEdgeNE(long hash, int deltaDepth)voidsortedInternalEdgeNE(long hash, int deltaDepth, FlatHashList result)FlatHashListsortedInternalEdgeNW(long hash, int deltaDepth)voidsortedInternalEdgeNW(long hash, int deltaDepth, FlatHashList result)FlatHashListsortedInternalEdges(long hash, int deltaDepth)voidsortedInternalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)FlatHashListsortedInternalEdgeSE(long hash, int deltaDepth)voidsortedInternalEdgeSE(long hash, int deltaDepth, FlatHashList result)FlatHashListsortedInternalEdgeSW(long hash, int deltaDepth)voidsortedInternalEdgeSW(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.voidvertex(long hash, CompassPoint.Cardinal vertexDirection, double[] resultLonLat)SeeVerticesAndPathComputer.vertex(long, Cardinal), except that the result is stored in the given array.voidvertices(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.
-
-
-
Constructor Detail
-
HealpixNestedFast
public HealpixNestedFast(int depth, FillingCurve2DType fillingCurveType)
-
-
Method Detail
-
depth
public int depth()
Description copied from interface:HashComputerReturns the depth of the hash computed byHashComputer.hash(double, double)method.- Specified by:
depthin interfaceHashComputer- Specified by:
depthin interfaceHierarchyItem- Returns:
- the depth of the hash computed by
HashComputer.hash(double, double)method.
-
hash
public long hash(double lonRad, double latRad)Description copied from interface:HashComputerReturns the HEALPix hash value of the given coordinate at this object depth. WARNING: depending on the implementation, this method may or may not be thread-safe.- Specified by:
hashin interfaceHashComputer- Parameters:
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] radians- Returns:
- the hash value associated to the given coordinate, at this object depth.
-
center
public double[] center(long hash)
Description copied from interface:VerticesAndPathComputerCompute the position on the unit sphere of the center (in the Euclidean projection plane) of the cell associated to the given hash value.- Specified by:
centerin interfaceVerticesAndPathComputer- Parameters:
hash- hash value of the cell we look for the unprojected center- Returns:
- the unprojected position (on the unit sphere) of the center of the cell in the
Euclidean plane. The lon and lat coordinate are stored in the returned array at indices
VerticesAndPathComputer.LON_INDEXandVerticesAndPathComputer.LAT_INDEXrespectively. Lat in [-pi/2, pi/2] radians, lon is in [0, 2pi] radians.
-
center
public void center(long hash, double[] resultLonLat)Description copied from interface:VerticesAndPathComputerSeeVerticesAndPathComputer.center(long), except that the result is stored in the given array.- Specified by:
centerin interfaceVerticesAndPathComputer- Parameters:
hash- hash value of the cell we look for the unprojected center.resultLonLat- array used to store the result. Must be of size >= 2.
-
vertex
public double[] vertex(long hash, CompassPoint.Cardinal cardinalPoint)Description copied from interface:VerticesAndPathComputerCompute the position of an HEALPix cell vertex on the unit sphere.- Specified by:
vertexin interfaceVerticesAndPathComputer- Parameters:
hash- hash value of the cell we look for the given vertex.cardinalPoint- location of the vertex with respect to the cell center- Returns:
- the position (on the unit sphere) of the vertex located at the given cardinal direction
from the center of the given cell.
The lon and lat coordinate are stored in the returned array at indices
VerticesAndPathComputer.LON_INDEXandVerticesAndPathComputer.LAT_INDEXrespectively. Lat is in [-pi/2, pi/2] radians, lon is in [0, 2pi] radians.
-
vertex
public void vertex(long hash, CompassPoint.Cardinal vertexDirection, double[] resultLonLat)Description copied from interface:VerticesAndPathComputerSeeVerticesAndPathComputer.vertex(long, Cardinal), except that the result is stored in the given array.- Specified by:
vertexin interfaceVerticesAndPathComputer- Parameters:
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.
-
vertices
public java.util.EnumMap<CompassPoint.Cardinal,double[]> vertices(long hash, java.util.EnumSet<CompassPoint.Cardinal> cardinalPoints)
Description copied from interface:VerticesAndPathComputerReturns the vertices located at the given cardinal points. If you want the full 4 vertices, simply useEnumSet.allOf(Cardinal). For West and East vertices, useEnumSet.of(Cardinal.W, Cardinal.E).- Specified by:
verticesin interfaceVerticesAndPathComputer- Parameters:
hash- hash value of the cell we look for the given vertices.cardinalPoints- locations of the vertices we look for the positions- Returns:
- the positions (on the unit sphere) of the vertices located at the given cardinal
directions from the center of the given cell.
The lon and lat coordinates of each vertex are stored in the arrays at indices
VerticesAndPathComputer.LON_INDEXandVerticesAndPathComputer.LAT_INDEXrespectively. Lat is in [-pi/2, pi/2] radians, lon is in [0, 2pi] radians.
-
vertices
public void vertices(long hash, java.util.EnumMap<CompassPoint.Cardinal,double[]> cardinalPoints)Description copied from interface:VerticesAndPathComputerSeeVerticesAndPathComputer.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.- Specified by:
verticesin interfaceVerticesAndPathComputer- Parameters:
hash- hash value of the cell we look for the given vertices.cardinalPoints- the map to be modified y
-
pathAlongCellSide
public double[][] pathAlongCellSide(long hash, CompassPoint.Cardinal fromVertex, CompassPoint.Cardinal toVertex, boolean isToVertexIncluded, int nSegments)Description copied from interface:VerticesAndPathComputerCompute points on a given side of a given HEALPix cell on the unit sphere.- Specified by:
pathAlongCellSidein interfaceVerticesAndPathComputer- Parameters:
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- iffalse, the result containsnSegmentspoints and do no include the result ending vertex. Else the result containsnSegments + 1points.nSegments- number of segments in the path from the starting vertex to the ending vertex- Returns:
- a list of points on the given side of the given HEALPix cell on the unit sphere.
-
pathAlongCellSide
public void pathAlongCellSide(long hash, CompassPoint.Cardinal fromVertex, CompassPoint.Cardinal toVertex, boolean isToVertexIncluded, int nSegments, double[][] pathPoints)Description copied from interface:VerticesAndPathComputerSeeVerticesAndPathComputer.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.- Specified by:
pathAlongCellSidein interfaceVerticesAndPathComputer- Parameters:
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- iffalse, the result containsnSegmentspoints and do no include the result ending vertex. Else the result containsnSegments + 1points.nSegments- number of segments in the path from the starting vertex to the ending vertexpathPoints- object used to store the result.
-
pathAlongCellEdge
public double[][] pathAlongCellEdge(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide)- Specified by:
pathAlongCellEdgein interfaceVerticesAndPathComputer- Parameters:
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- iftrue, 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 is4 x nSegmentsBySide.- Returns:
- a list of points on the given edge of the given HEALPix cell on the unit sphere, clockwise or counter-clockwise ordered.
-
pathAlongCellEdge
public void pathAlongCellEdge(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide, double[][] pathPoints)Description copied from interface:VerticesAndPathComputerSeeVerticesAndPathComputer.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.- Specified by:
pathAlongCellEdgein interfaceVerticesAndPathComputer- Parameters:
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- iftrue, 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 is4 x nSegmentsBySide.pathPoints- object used to store the result.
-
neighbours
public void neighbours(long hash, FlatHashList neighbours)Description copied from interface:NeighbourSelectorIdem asNeighbourSelector.neighbours(long, NeighbourList)except that the result is put in a simpleFlatHashList. WARNING: the content of the provided list is overwritten, and be sure the list is large enough (at least of size 8).- Specified by:
neighboursin interfaceNeighbourSelector- Parameters:
hash- the hash code we want the neighboursneighbours- which contains the list of neighbours from index 0 to the number of neighbours
-
neighbour
public long neighbour(long hash, CompassPoint.MainWind direction)Description copied from interface:NeighbourSelectorThe hash value of the neighbour of the cell of given hash, in the given deirection.- Specified by:
neighbourin interfaceNeighbourSelector- Parameters:
hash- ash value of the cell we are looking for the neighbour.direction- direction of the neighbour we are looking for.- Returns:
- -1 if there is no neighbour in the given direction (hashes located at corners of base hases).
-
neighbours
public NeighbourList neighbours(long hash)
Description copied from interface:NeighbourSelectorReturns the list of the hash of the cells surrounding the cell defined by the given hash. The number of surrounding cells can be 8 (for all cells except the cells located at the corners of the 12 depth 0 cells), 7 (for the west and east corners of the polar caps, i.e. depth 0 cells number 0, 1, 2, 4, 8, 9, 10 and 11, or for the north and south corners of the equatorial regions, i.e. depth 0 cells number 4, 5, 6 and 7), or 6 for depth 0 pixels.- Specified by:
neighboursin interfaceNeighbourSelector- Parameters:
hash- hash value of the cell we are looking for the neighbours.- Returns:
- the list of neighbours hashes
-
neighbours
public NeighbourList neighbours(long hash, java.util.EnumSet<CompassPoint.MainWind> directions)
Description copied from interface:NeighbourSelectorEquivalent ofNeighbourSelector.neighbours(long, FlatHashList)but with the list of direction of the wanted neighbours.- Specified by:
neighboursin interfaceNeighbourSelector- Parameters:
hash- hash value of the cell we are looking for the neighbours.directions- the directions of the neighbours we are looking for.- Returns:
- the list of the hash of the neighbours of the cell having the given hash.
-
neighbours
public void neighbours(long hash, NeighbourList result)Description copied from interface:NeighbourSelectorEquivalent ofNeighbourSelector.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.- Specified by:
neighboursin interfaceNeighbourSelector- Parameters:
hash- the hash code we want the neighboursresult- which contains the list of neighbours from index 0 to the number of neighbours
-
neighbours
public void neighbours(long hash, java.util.EnumSet<CompassPoint.MainWind> directions, NeighbourList result)Description copied from interface:NeighbourSelectorEquivalent ofNeighbourSelector.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.- Specified by:
neighboursin interfaceNeighbourSelector- Parameters:
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.
-
internalEdges
public FlatHashList internalEdges(long hash, int toEdgeDeltaDepth)
- Specified by:
internalEdgesin interfaceNeighbourSelector
-
internalEdges
public void internalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)- Specified by:
internalEdgesin interfaceNeighbourSelector
-
sortedInternalEdges
public FlatHashList sortedInternalEdges(long hash, int deltaDepth)
- Specified by:
sortedInternalEdgesin interfaceNeighbourSelector
-
sortedInternalEdges
public void sortedInternalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)- Specified by:
sortedInternalEdgesin interfaceNeighbourSelector
-
sortedInternalEdge
public FlatHashList sortedInternalEdge(long hash, int deltaDepth, CompassPoint.Ordinal direction)
- Specified by:
sortedInternalEdgein interfaceNeighbourSelector
-
sortedInternalEdge
public void sortedInternalEdge(long hash, int deltaDepth, CompassPoint.Ordinal direction, FlatHashList result)- Specified by:
sortedInternalEdgein interfaceNeighbourSelector
-
sortedInternalEdgeSE
public FlatHashList sortedInternalEdgeSE(long hash, int deltaDepth)
- Specified by:
sortedInternalEdgeSEin interfaceNeighbourSelector
-
sortedInternalEdgeSE
public void sortedInternalEdgeSE(long hash, int deltaDepth, FlatHashList result)- Specified by:
sortedInternalEdgeSEin interfaceNeighbourSelector
-
sortedInternalEdgeNE
public FlatHashList sortedInternalEdgeNE(long hash, int deltaDepth)
- Specified by:
sortedInternalEdgeNEin interfaceNeighbourSelector
-
sortedInternalEdgeNE
public void sortedInternalEdgeNE(long hash, int deltaDepth, FlatHashList result)- Specified by:
sortedInternalEdgeNEin interfaceNeighbourSelector
-
sortedInternalEdgeNW
public FlatHashList sortedInternalEdgeNW(long hash, int deltaDepth)
- Specified by:
sortedInternalEdgeNWin interfaceNeighbourSelector
-
sortedInternalEdgeNW
public void sortedInternalEdgeNW(long hash, int deltaDepth, FlatHashList result)- Specified by:
sortedInternalEdgeNWin interfaceNeighbourSelector
-
sortedInternalEdgeSW
public FlatHashList sortedInternalEdgeSW(long hash, int deltaDepth)
- Specified by:
sortedInternalEdgeSWin interfaceNeighbourSelector
-
sortedInternalEdgeSW
public void sortedInternalEdgeSW(long hash, int deltaDepth, FlatHashList result)- Specified by:
sortedInternalEdgeSWin interfaceNeighbourSelector
-
internalCorner
public long internalCorner(long hash, int toEdgeDeltaDepth, CompassPoint.Cardinal direction)- Specified by:
internalCornerin interfaceNeighbourSelector
-
internalCornerN
public long internalCornerN(long hash, int toEdgeDeltaDepth)- Specified by:
internalCornerNin interfaceNeighbourSelector
-
internalCornerS
public long internalCornerS(long hash, int toEdgeDeltaDepth)- Specified by:
internalCornerSin interfaceNeighbourSelector
-
internalCornerE
public long internalCornerE(long hash, int toEdgeDeltaDepth)- Specified by:
internalCornerEin interfaceNeighbourSelector
-
internalCornerW
public long internalCornerW(long hash, int toEdgeDeltaDepth)- Specified by:
internalCornerWin interfaceNeighbourSelector
-
externalEdges
public FlatHashList externalEdges(long hash, int deltaDepth)
- Specified by:
externalEdgesin interfaceNeighbourSelector
-
externalEdges
public void externalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)- Specified by:
externalEdgesin interfaceNeighbourSelector
-
sortedExternalEdges
public FlatHashList sortedExternalEdges(long hash, int deltaDepth)
- Specified by:
sortedExternalEdgesin interfaceNeighbourSelector
-
sortedExternalEdges
public void sortedExternalEdges(long hash, int toEdgeDeltaDepth, FlatHashList result)- Specified by:
sortedExternalEdgesin interfaceNeighbourSelector
-
-