OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
faceijk.hpp File Reference
+ Include dependency graph for faceijk.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define M_SQRT7   2.6457513110645905905016157536392604257102
 

Functions

DEVICE const GeoCoordArray (faceCenterGeo, NUM_ICOSA_FACES)
 icosahedron face centers in lat/lon radians More...
 
static DEVICE const Vec3dArray (faceCenterPoint, NUM_ICOSA_FACES)
 icosahedron face centers in x/y/z on the unit sphere More...
 
static DEVICE const FaceOrientIJK2DArray (faceNeighbors, NUM_ICOSA_FACES, 4)
 Definition of which faces neighbor each other. More...
 
EXTENSION_INLINE int isResClassIII (int res)
 
EXTENSION_NOINLINE bool _geoToFaceIjk (const GeoCoord(g), int res, FaceIJK(h))
 
EXTENSION_NOINLINE bool _geoToHex2d (const GeoCoord(g), int res, int *face, Vec2d(v))
 
EXTENSION_NOINLINE bool _hex2dToGeo (const Vec2d(v), int face, int res, int substrate, GeoCoord(g))
 
EXTENSION_NOINLINE bool _faceIjkToGeo (const FaceIJK(h), int res, GeoCoord(g))
 
EXTENSION_NOINLINE int _adjustOverageClassII (FaceIJK(fijk), int res, int pentLeading4, int substrate)
 

Variables

static DEVICE const double faceAxesAzRadsCII [NUM_ICOSA_FACES][3]
 icosahedron face ijk axes as azimuth in radians from face center to vertex 0/1/2 respectively More...
 
static DEVICE const int maxDimByCIIres []
 direction from the origin face to the destination face, relative to the origin face's coordinate system, or -1 if not adjacent. More...
 
static DEVICE const int unitScaleByCIIres []
 unit scale distance table More...
 

Macro Definition Documentation

#define M_SQRT7   2.6457513110645905905016157536392604257102

square root of 7

Definition at line 36 of file faceijk.hpp.

Referenced by _geoToHex2d(), and _hex2dToGeo().

Function Documentation

EXTENSION_NOINLINE int _adjustOverageClassII ( FaceIJK(fijk)  ,
int  res,
int  pentLeading4,
int  substrate 
)

Generates the cell boundary in spherical coordinates for a pentagonal cell given by a FaceIJK address at a specified resolution.

Parameters
hThe FaceIJK address of the pentagonal cell.
resThe H3 resolution of the cell.
startThe first topological vertex to return.
lengthThe number of topological vertexes to return.
gThe spherical coordinates of the cell boundary. Get the vertices of a pentagon cell as substrate FaceIJK addresses
fijkThe FaceIJK address of the cell.
resThe H3 resolution of the cell. This may be adjusted if necessary for the substrate grid resolution.
fijkVertsOutput array for the vertices Generates the cell boundary in spherical coordinates for a cell given by a FaceIJK address at a specified resolution.
hThe FaceIJK address of the cell.
resThe H3 resolution of the cell.
startThe first topological vertex to return.
lengthThe number of topological vertexes to return.
gThe spherical coordinates of the cell boundary. Get the vertices of a cell as substrate FaceIJK addresses
fijkThe FaceIJK address of the cell.
resThe H3 resolution of the cell. This may be adjusted if necessary for the substrate grid resolution.
fijkVertsOutput array for the vertices Adjusts a FaceIJK address in place so that the resulting cell address is relative to the correct icosahedral face.
fijkThe FaceIJK address of the cell.
resThe H3 resolution of the cell.
pentLeading4Whether or not the cell is a pentagon with a leading digit 4.
substrateWhether or not the cell is in a substrate grid.
Returns
0 if on original face (no overage); 1 if on face edge (only occurs on substrate grids); 2 if overage on new face interior

Definition at line 864 of file faceijk.hpp.

References _ijkAdd(), _ijkNormalize(), _ijkRotate60ccw(), _ijkRotate60cw(), _ijkScale(), _ijkSub(), _setIJK(), CCWROT_60_INDEX, CoordIJK, CoordIJK_clone, CoordIJK_ptr, FACE_EDGE, FACE_INDEX, I_INDEX, IJ, J_INDEX, JK, K_INDEX, KI, maxDimByCIIres, NEW_FACE, NO_OVERAGE, run_benchmark_import::res, and unitScaleByCIIres.

Referenced by _h3ToFaceIjk().

867  {
868  Overage overage = NO_OVERAGE;
869 
870  CoordIJK_ptr(ijk) = fijk;
871 
872  // get the maximum dimension value; scale if a substrate grid
873  int maxDim = maxDimByCIIres[res];
874  if (substrate)
875  maxDim *= 3;
876 
877  // check for overage
878  if (substrate && ijk[I_INDEX] + ijk[J_INDEX] + ijk[K_INDEX] == maxDim) // on edge
879  overage = FACE_EDGE;
880  else if (ijk[I_INDEX] + ijk[J_INDEX] + ijk[K_INDEX] > maxDim) // overage
881  {
882  overage = NEW_FACE;
883 
884  const int* fijkOrient;
885  if (ijk[K_INDEX] > 0) {
886  if (ijk[J_INDEX] > 0) // jk "quadrant"
887  fijkOrient = faceNeighbors[fijk[FACE_INDEX]][JK];
888  else // ik "quadrant"
889  {
890  fijkOrient = faceNeighbors[fijk[FACE_INDEX]][KI];
891 
892  // adjust for the pentagonal missing sequence
893  if (pentLeading4) {
894  // translate origin to center of pentagon
895  CoordIJK(origin);
896  _setIJK(origin, maxDim, 0, 0);
897  CoordIJK(tmp);
898  _ijkSub(ijk, origin, tmp);
899  // rotate to adjust for the missing sequence
900  _ijkRotate60cw(tmp);
901  // translate the origin back to the center of the triangle
902  _ijkAdd(tmp, origin, ijk);
903  }
904  }
905  } else // ij "quadrant"
906  fijkOrient = faceNeighbors[fijk[FACE_INDEX]][IJ];
907 
908  fijk[FACE_INDEX] = fijkOrient[FACE_INDEX];
909 
910  // rotate and translate for adjacent face
911  for (int i = 0; i < fijkOrient[CCWROT_60_INDEX]; i++)
912  _ijkRotate60ccw(ijk);
913 
914  CoordIJK(transVec) = CoordIJK_clone(fijkOrient);
915  int unitScale = unitScaleByCIIres[res];
916  if (substrate)
917  unitScale *= 3;
918  _ijkScale(transVec, unitScale);
919  _ijkAdd(ijk, transVec, ijk);
920  _ijkNormalize(ijk);
921 
922  // overage points on pentagon boundaries can end up on edges
923  if (substrate && ijk[I_INDEX] + ijk[J_INDEX] + ijk[K_INDEX] == maxDim) // on edge
924  overage = FACE_EDGE;
925  }
926 
927  return overage;
928 }
Overage
Definition: faceijk.h:78
#define CCWROT_60_INDEX
Definition: faceijk.h:53
static DEVICE const int unitScaleByCIIres[]
unit scale distance table
Definition: faceijk.hpp:323
EXTENSION_INLINE bool _ijkSub(const CoordIJK(h1), const CoordIJK(h2), CoordIJK(diff))
Definition: coordijk.hpp:198
#define J_INDEX
Definition: coordijk.h:43
EXTENSION_NOINLINE bool _ijkRotate60ccw(CoordIJK(ijk))
Definition: coordijk.hpp:385
#define IJ
Definition: faceijk.h:68
EXTENSION_NOINLINE bool _ijkRotate60cw(CoordIJK(ijk))
Definition: coordijk.hpp:407
EXTENSION_INLINE bool _ijkScale(CoordIJK(c), int factor)
Definition: coordijk.hpp:211
#define CoordIJK_clone(ijk)
Definition: coordijk.h:47
#define KI
Definition: faceijk.h:70
EXTENSION_INLINE bool _ijkAdd(const CoordIJK(h1), const CoordIJK(h2), CoordIJK(sum))
Definition: coordijk.hpp:184
#define I_INDEX
Definition: coordijk.h:42
#define CoordIJK_ptr(variable_name)
Definition: coordijk.h:46
#define CoordIJK(variable_name)
Definition: coordijk.h:45
#define JK
Definition: faceijk.h:72
#define FACE_INDEX
Definition: faceijk.h:35
static DEVICE const int maxDimByCIIres[]
direction from the origin face to the destination face, relative to the origin face&#39;s coordinate syst...
Definition: faceijk.hpp:302
#define K_INDEX
Definition: coordijk.h:44
EXTENSION_INLINE bool _setIJK(CoordIJK(ijk), int i, int j, int k)
Definition: coordijk.hpp:40
EXTENSION_NOINLINE bool _ijkNormalize(CoordIJK(c))
Definition: coordijk.hpp:224

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool _faceIjkToGeo ( const   FaceIJKh,
int  res,
GeoCoord(g)   
)

Determines the center point in spherical coordinates of a cell given by a FaceIJK address at a specified resolution.

Parameters
hThe FaceIJK address of the cell.
resThe H3 resolution of the cell.
gThe spherical coordinates of the cell center point.

Definition at line 495 of file faceijk.hpp.

References _hex2dToGeo(), _ijkToHex2d(), FACE_INDEX, and Vec2d.

Referenced by _h3ToGeo().

495  {
496  Vec2d(v);
497  _ijkToHex2d(h, v);
498  _hex2dToGeo(v, h[FACE_INDEX], res, 0, g);
499  return true;
500 }
EXTENSION_NOINLINE bool _hex2dToGeo(const Vec2d(v), int face, int res, int substrate, GeoCoord(g))
Definition: faceijk.hpp:442
#define Vec2d(variable_name)
Definition: vec2d.h:28
EXTENSION_INLINE bool _ijkToHex2d(const CoordIJK(h), Vec2d(v))
Definition: coordijk.hpp:155
#define FACE_INDEX
Definition: faceijk.h:35

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool _geoToFaceIjk ( const   GeoCoordg,
int  res,
FaceIJK(h)   
)

Encodes a coordinate on the sphere to the FaceIJK address of the containing cell at the specified resolution.

Parameters
gThe spherical coordinates to encode.
resThe desired H3 resolution for the encoding.
hThe FaceIJK address of the containing cell at resolution res.

Definition at line 362 of file faceijk.hpp.

References _geoToHex2d(), _hex2dToCoordIJK(), FACE_INDEX, and Vec2d.

Referenced by geoToH3().

362  {
363  // first convert to hex2d
364  Vec2d(v);
365  _geoToHex2d(g, res, &h[FACE_INDEX], v);
366 
367  // then convert to ijk+
368  _hex2dToCoordIJK(v, h);
369 
370  return true;
371 }
EXTENSION_NOINLINE bool _hex2dToCoordIJK(const Vec2d(v), CoordIJK(h))
Definition: coordijk.hpp:54
EXTENSION_NOINLINE bool _geoToHex2d(const GeoCoord(g), int res, int *face, Vec2d(v))
Definition: faceijk.hpp:382
#define Vec2d(variable_name)
Definition: vec2d.h:28
#define FACE_INDEX
Definition: faceijk.h:35

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool _geoToHex2d ( const   GeoCoordg,
int  res,
int *  face,
Vec2d(v)   
)

Encodes a coordinate on the sphere to the corresponding icosahedral face and containing 2D hex coordinates relative to that face center.

Parameters
gThe spherical coordinates to encode.
resThe desired H3 resolution for the encoding.
faceThe icosahedral face containing the spherical coordinates.
vThe 2D hex coordinates of the cell containing the point.

Definition at line 382 of file faceijk.hpp.

References _geoAzimuthRads(), _geoToVec3d(), _pointSquareDist(), _posAngleRads(), EPSILON, f(), faceAxesAzRadsCII, isResClassIII(), M_AP7_ROT_RADS, M_SQRT7, NUM_ICOSA_FACES, run_benchmark_import::res, RES0_U_GNOMONIC, Vec3d, X_INDEX, and Y_INDEX.

Referenced by _geoToFaceIjk().

382  {
383  Vec3d(v3d);
384  _geoToVec3d(g, v3d);
385 
386  // determine the icosahedron face
387  *face = 0;
388  double sqd = _pointSquareDist(faceCenterPoint[0], v3d);
389  for (int f = 1; f < NUM_ICOSA_FACES; f++) {
390  double sqdT = _pointSquareDist(faceCenterPoint[f], v3d);
391  if (sqdT < sqd) {
392  *face = f;
393  sqd = sqdT;
394  }
395  }
396 
397  // cos(r) = 1 - 2 * sin^2(r/2) = 1 - 2 * (sqd / 4) = 1 - sqd/2
398  double r = acos(1 - sqd / 2);
399 
400  if (r < EPSILON) {
401  v[X_INDEX] = v[Y_INDEX] = 0.0;
402  return true;
403  }
404 
405  // now have face and r, now find CCW theta from CII i-axis
406  double theta = _posAngleRads(faceAxesAzRadsCII[*face][0] -
407  _posAngleRads(_geoAzimuthRads(faceCenterGeo[*face], g)));
408 
409  // adjust theta for Class III (odd resolutions)
410  if (isResClassIII(res))
411  theta = _posAngleRads(theta - M_AP7_ROT_RADS);
412 
413  // perform gnomonic scaling of r
414  r = tan(r);
415 
416  // scale for current resolution length u
417  r /= RES0_U_GNOMONIC;
418  for (int i = 0; i < res; i++)
419  r *= M_SQRT7;
420 
421  // we now have (r, theta) in hex2d with theta ccw from x-axes
422 
423  // convert to local x,y
424  v[X_INDEX] = r * cos(theta);
425  v[Y_INDEX] = r * sin(theta);
426 
427  return true;
428 }
EXTENSION_INLINE int isResClassIII(int res)
Definition: faceijk.hpp:350
#define M_AP7_ROT_RADS
Definition: constants.h:51
static DEVICE const double faceAxesAzRadsCII[NUM_ICOSA_FACES][3]
icosahedron face ijk axes as azimuth in radians from face center to vertex 0/1/2 respectively ...
Definition: faceijk.hpp:89
#define NUM_ICOSA_FACES
Definition: constants.h:71
#define M_SQRT7
Definition: faceijk.hpp:36
EXTENSION_NOINLINE double _posAngleRads(double rads)
Definition: geoCoord.hpp:35
#define X_INDEX
Definition: vec2d.h:26
#define Vec3d(variable_name)
Definition: vec3d.h:29
#define EPSILON
Definition: constants.h:42
EXTENSION_NOINLINE bool _geoToVec3d(const GeoCoord(geo), Vec3d(v))
Definition: vec3d.hpp:52
#define RES0_U_GNOMONIC
Definition: constants.h:65
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
EXTENSION_NOINLINE double _geoAzimuthRads(const GeoCoord(p1), const GeoCoord(p2))
Definition: geoCoord.hpp:187
#define Y_INDEX
Definition: vec2d.h:27
EXTENSION_NOINLINE double _pointSquareDist(const Vec3d(v1), const Vec3d(v2))
Definition: vec3d.hpp:41

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool _hex2dToGeo ( const   Vec2dv,
int  face,
int  res,
int  substrate,
GeoCoord(g)   
)

Determines the center point in spherical coordinates of a cell given by 2D hex coordinates on a particular icosahedral face.

Parameters
vThe 2D hex coordinates of the cell.
faceThe icosahedral face upon which the 2D hex coordinate system is centered.
resThe H3 resolution of the cell.
substrateIndicates whether or not this grid is actually a substrate grid relative to the specified resolution.
gThe spherical coordinates of the cell center point.

Definition at line 442 of file faceijk.hpp.

References _geoAzDistanceRads(), _posAngleRads(), _v2dMag(), EPSILON, faceAxesAzRadsCII, GeoCoordCopy, isResClassIII(), M_AP7_ROT_RADS, M_SQRT7, run_benchmark_import::res, RES0_U_GNOMONIC, X_INDEX, and Y_INDEX.

Referenced by _faceIjkToGeo().

446  {
447  // calculate (r, theta) in hex2d
448  double r = _v2dMag(v);
449 
450  if (r < EPSILON) {
451  GeoCoordCopy(g, faceCenterGeo[face]);
452  return true;
453  }
454 
455  double theta = atan2(v[Y_INDEX], v[X_INDEX]);
456 
457  // scale for current resolution length u
458  for (int i = 0; i < res; i++)
459  r /= M_SQRT7;
460 
461  // scale accordingly if this is a substrate grid
462  if (substrate) {
463  r /= 3.0;
464  if (isResClassIII(res))
465  r /= M_SQRT7;
466  }
467 
468  r *= RES0_U_GNOMONIC;
469 
470  // perform inverse gnomonic scaling of r
471  r = atan(r);
472 
473  // adjust theta for Class III
474  // if a substrate grid, then it's already been adjusted for Class III
475  if (!substrate && isResClassIII(res))
476  theta = _posAngleRads(theta + M_AP7_ROT_RADS);
477 
478  // find theta as an azimuth
479  theta = _posAngleRads(faceAxesAzRadsCII[face][0] - theta);
480 
481  // now find the point at (r,theta) from the face center
482  _geoAzDistanceRads(faceCenterGeo[face], theta, r, g);
483 
484  return true;
485 }
EXTENSION_INLINE int isResClassIII(int res)
Definition: faceijk.hpp:350
#define M_AP7_ROT_RADS
Definition: constants.h:51
static DEVICE const double faceAxesAzRadsCII[NUM_ICOSA_FACES][3]
icosahedron face ijk axes as azimuth in radians from face center to vertex 0/1/2 respectively ...
Definition: faceijk.hpp:89
#define M_SQRT7
Definition: faceijk.hpp:36
EXTENSION_NOINLINE double _posAngleRads(double rads)
Definition: geoCoord.hpp:35
EXTENSION_NOINLINE bool _geoAzDistanceRads(const GeoCoord(p1), double az, double distance, GeoCoord(p2))
Definition: geoCoord.hpp:204
#define X_INDEX
Definition: vec2d.h:26
#define EPSILON
Definition: constants.h:42
#define RES0_U_GNOMONIC
Definition: constants.h:65
#define Y_INDEX
Definition: vec2d.h:27
EXTENSION_INLINE double _v2dMag(const Vec2d(v))
Definition: vec2d.hpp:30
#define GeoCoordCopy(dest_coord, src_coord)
Definition: h3api.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static DEVICE const FaceOrientIJK2DArray ( faceNeighbors  ,
NUM_ICOSA_FACES  ,
 
)
static

Definition of which faces neighbor each other.

DEVICE const GeoCoordArray ( faceCenterGeo  ,
NUM_ICOSA_FACES   
)

icosahedron face centers in lat/lon radians

EXTENSION_INLINE int isResClassIII ( int  res)

Returns whether or not a resolution is a Class III grid. Note that odd resolutions are Class III and even resolutions are Class II.

Parameters
resThe H3 resolution.
Returns
1 if the resolution is a Class III grid, and 0 if the resolution is a Class II grid.

Definition at line 350 of file faceijk.hpp.

Referenced by _faceIjkToH3(), _geoToHex2d(), _h3ToFaceIjk(), _h3ToFaceIjkWithInitializedFijk(), and _hex2dToGeo().

350  {
351  return res % 2;
352 }

+ Here is the caller graph for this function:

static DEVICE const Vec3dArray ( faceCenterPoint  ,
NUM_ICOSA_FACES   
)
static

icosahedron face centers in x/y/z on the unit sphere

Variable Documentation

DEVICE const double faceAxesAzRadsCII[NUM_ICOSA_FACES][3]
static
Initial value:
= {
{5.619958268523939882, 3.525563166130744542, 1.431168063737548730},
{5.760339081714187279, 3.665943979320991689, 1.571548876927796127},
{0.780213654393430055, 4.969003859179821079, 2.874608756786625655},
{0.430469363979999913, 4.619259568766391033, 2.524864466373195467},
{6.130269123335111400, 4.035874020941915804, 1.941478918548720291},
{2.692877706530642877, 0.598482604137447119, 4.787272808923838195},
{2.982963003477243874, 0.888567901084048369, 5.077358105870439581},
{3.532912002790141181, 1.438516900396945656, 5.627307105183336758},
{3.494305004259568154, 1.399909901866372864, 5.588700106652763840},
{3.003214169499538391, 0.908819067106342928, 5.097609271892733906},
{5.930472956509811562, 3.836077854116615875, 1.741682751723420374},
{0.138378484090254847, 4.327168688876645809, 2.232773586483450311},
{0.448714947059150361, 4.637505151845541521, 2.543110049452346120},
{0.158629650112549365, 4.347419854898940135, 2.253024752505744869},
{5.891865957979238535, 3.797470855586042958, 1.703075753192847583},
{2.711123289609793325, 0.616728187216597771, 4.805518392002988683},
{3.294508837434268316, 1.200113735041072948, 5.388903939827463911},
{3.804819692245439833, 1.710424589852244509, 5.899214794638635174},
{3.664438879055192436, 1.570043776661997111, 5.758833981448388027},
{2.361378999196363184, 0.266983896803167583, 4.455774101589558636},
}

icosahedron face ijk axes as azimuth in radians from face center to vertex 0/1/2 respectively

Definition at line 89 of file faceijk.hpp.

Referenced by _geoToHex2d(), and _hex2dToGeo().

DEVICE const int maxDimByCIIres[]
static
Initial value:
= {
2,
-1,
14,
-1,
98,
-1,
686,
-1,
4802,
-1,
33614,
-1,
235298,
-1,
1647086,
-1,
11529602
}

direction from the origin face to the destination face, relative to the origin face's coordinate system, or -1 if not adjacent.

overage distance table

Definition at line 302 of file faceijk.hpp.

Referenced by _adjustOverageClassII().

DEVICE const int unitScaleByCIIres[]
static
Initial value:
= {
1,
-1,
7,
-1,
49,
-1,
343,
-1,
2401,
-1,
16807,
-1,
117649,
-1,
823543,
-1,
5764801
}

unit scale distance table

Definition at line 323 of file faceijk.hpp.

Referenced by _adjustOverageClassII().