56 4, 4, 4, 4, UNUSED, 3, UNUSED, UNUSED,
57 UNUSED, UNUSED, 0, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED,
58 UNUSED, UNUSED, UNUSED, 2, UNUSED, 3, UNUSED, 2,
59 UNUSED, UNUSED, 0, 2, UNUSED, UNUSED, UNUSED, 2,
60 5, UNUSED, UNUSED, UNUSED, 5, 3, UNUSED, UNUSED,
61 5, UNUSED, 0, UNUSED, 5, UNUSED, UNUSED, UNUSED,
62 UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, 3, UNUSED, UNUSED,
63 UNUSED, UNUSED, 0, UNUSED, 1, 1, 1, 1
67 {0, 1, 2, UNUSED}, {1, 2, 0, UNUSED}, {2, 0, 1, UNUSED},
68 {0, 1, 2, UNUSED}, {1, 2, 0, UNUSED}, {2, 0, 1, UNUSED}
71double const FACE_CONST[6][4] = {
72 { 1.0, 1.0, -1.0, 0.0},
73 { 1.0, 1.0, 1.0, 0.0},
74 { 1.0, -1.0, 1.0, 0.0},
75 {-1.0, -1.0, 1.0, 0.0},
76 {-1.0, -1.0, -1.0, 0.0},
77 {-1.0, 1.0, -1.0, 0.0}
81constexpr double DILATION = 1.0e-15;
95 face = (face + 4) % 6;
99 }
else if (s > stMax) {
100 face = (face + 1) % 6;
105 face = (face + 5) % 6;
109 }
else if (t > stMax) {
110 face = (face + 2) % 6;
122 int const face =
static_cast<int>(i >> (2 *
level)) - 10;
125 dst[0] = wrapIndex(level, face, s - 1, t - 1);
126 dst[1] = wrapIndex(level, face, s , t - 1);
127 dst[2] = wrapIndex(level, face, s + 1, t - 1);
128 dst[3] = wrapIndex(level, face, s - 1, t);
130 dst[5] = wrapIndex(level, face, s + 1, t);
131 dst[6] = wrapIndex(level, face, s - 1, t + 1);
132 dst[7] = wrapIndex(level, face, s , t + 1);
133 dst[8] = wrapIndex(level, face, s + 1, t + 1);
135 return static_cast<int>(
std::unique(dst, dst + 9) - dst);
138#if defined(NO_SIMD) || !defined(__x86_64__)
139 void makeQuad(
std::uint64_t i,
int level, UnitVector3d * verts) {
140 int const face =
static_cast<int>(i >> (2 *
level)) - 10;
141 double const faceScale = FACE_SCALE[
level];
147 double u1 = (u0 + faceScale) + DILATION;
148 double v1 = (v0 + faceScale) + DILATION;
151 std::tie(u0, v0) = atanApproxInverse(u0, v0);
152 std::tie(u1, v1) = atanApproxInverse(u1, v1);
153 verts[0] = faceToSphere(face, u0, v0, FACE_COMP, FACE_CONST);
154 verts[1] = faceToSphere(face, u1, v0, FACE_COMP, FACE_CONST);
155 verts[2] = faceToSphere(face, u1, v1, FACE_COMP, FACE_CONST);
156 verts[3] = faceToSphere(face, u0, v1, FACE_COMP, FACE_CONST);
161 if ((face & 1) == 0) {
166 void makeQuad(
std::uint64_t i,
int level, UnitVector3d * verts) {
167 int const face =
static_cast<int>(i >> (2 *
level)) - 10;
168 __m128d faceScale = _mm_set1_pd(FACE_SCALE[level]);
169 __m128d dilation = _mm_set1_pd(DILATION);
170 __m128d u0v0 = gridToFace(level, hilbertIndexInverseSimd(i, level));
171 __m128d u1v1 = _mm_add_pd(u0v0, faceScale);
172 u0v0 = atanApproxInverse(_mm_sub_pd(u0v0, dilation));
173 u1v1 = atanApproxInverse(_mm_add_pd(u1v1, dilation));
174 verts[0] = faceToSphere(face, u0v0, FACE_COMP, FACE_CONST);
175 verts[1] = faceToSphere(face, _mm_shuffle_pd(u1v1, u0v0, 2),
176 FACE_COMP, FACE_CONST);
177 verts[2] = faceToSphere(face, u1v1, FACE_COMP, FACE_CONST);
178 verts[3] = faceToSphere(face, _mm_shuffle_pd(u0v0, u1v1, 2),
179 FACE_COMP, FACE_CONST);
180 if ((face & 1) == 0) {
204template <
typename RegionType,
bool InteriorOnly>
205class Mq3cPixelFinder:
public detail::PixelFinder<
206 Mq3cPixelFinder<RegionType, InteriorOnly>, RegionType, InteriorOnly, 4>
209 using Base = detail::PixelFinder<
210 Mq3cPixelFinder<RegionType, InteriorOnly>, RegionType, InteriorOnly, 4>;
214 Mq3cPixelFinder(RangeSet & ranges,
215 RegionType
const & region,
218 Base(ranges, region,
level, maxRanges)
222 UnitVector3d pixel[4];
225 makeQuad(f, 0, pixel);
230 void subdivide(UnitVector3d
const *,
std::uint64_t i,
int level) {
231 UnitVector3d pixel[4];
234 makeQuad(c, level, pixel);
235 visit(pixel, c, level);
251 if ((j & 1) == 0 || (j == 1) || ((i >> (j - 3)) < 10)) {
263 makeQuad(i, l, verts);
264 return ConvexPolygon(verts[0], verts[1], verts[2], verts[3]);
273 int n = findNeighborhood(l, i, indexes);
278 static char const FACE_NORM[6][2] = {
279 {
'-',
'Z'}, {
'+',
'X'}, {
'+',
'Y'},
280 {
'+',
'Z'}, {
'-',
'X'}, {
'-',
'Y'},
288 char * p = s + (
sizeof(s) - 1);
289 for (; l > 0; --l, --p, i >>= 2) {
294 p[0] = FACE_NORM[i - 10][0];
295 p[1] = FACE_NORM[i - 10][1];
296 return std::string(p,
sizeof(s) -
static_cast<size_t>(p - s));
302 "Modified-Q3C subdivision level not in [0, 30]");
308 if (f < 10 || f > 15) {
312 makeQuad(i, _level, verts);
317#if defined(NO_SIMD) || !defined(__x86_64__)
319 int face = faceNumber(p, FACE_NUM);
321 double u = (p(FACE_COMP[face][0]) /
w) * FACE_CONST[face][0];
322 double v = (p(FACE_COMP[face][1]) /
w) * FACE_CONST[face][1];
328 return (
static_cast<std::uint64_t>(face + 10) << (2 * _level)) | h;
332 int face = faceNumber(p, FACE_NUM);
333 __m128d ww = _mm_set1_pd(p(FACE_COMP[face][2]));
334 __m128d uv = _mm_set_pd(p(FACE_COMP[face][1]), p(FACE_COMP[face][0]));
336 _mm_div_pd(uv, _mm_andnot_pd(_mm_set_pd(-0.0, -0.0), ww)),
337 _mm_set_pd(FACE_CONST[face][1], FACE_CONST[face][0])
339 __m128i st = faceToGrid(_level, atanApprox(uv));
341 return (
static_cast<std::uint64_t>(face + 10) << (2 * _level)) | h;
346 return detail::findPixels<Mq3cPixelFinder, false>(r, maxRanges, _level,
universe());
350 return detail::findPixels<Mq3cPixelFinder, true>(r, maxRanges, _level,
universe());
This file declares a class for representing convex polygons with great circle edges on the unit spher...
This file declares a Pixelization subclass for the modified Q3C indexing scheme.
This file provides a base class for pixel finders.
This file contains functions used by Q3C pixelization implementations.
This file declares a class for representing unit vectors in ℝ³.
ConvexPolygon is a closed convex polygon on the unit sphere.
static ConvexPolygon quad(std::uint64_t i)
quad returns the quadrilateral corresponding to the modified Q3C pixel with index i.
static constexpr int MAX_LEVEL
The maximum supported cube-face grid resolution is 2^30 by 2^30.
static int level(std::uint64_t i)
level returns the subdivision level of the given modified Q3C index.
RangeSet universe() const override
universe returns the set of all pixel indexes for this pixelization.
std::unique_ptr< Region > pixel(std::uint64_t i) const override
pixel returns the spherical region corresponding to the pixel with index i.
static std::string asString(std::uint64_t i)
toString converts the given modified-Q3C index to a human readable string.
std::uint64_t index(UnitVector3d const &v) const override
index computes the index of the pixel for v.
static std::vector< std::uint64_t > neighborhood(std::uint64_t i)
neighborhood returns the indexes of all pixels that share a vertex with pixel i (including i itself).
RangeSet _envelope(Region const &r, size_t maxRanges) const override
RangeSet _interior(Region const &r, size_t maxRanges) const override
Mq3cPixelization(int level)
This constructor creates a modified Q3C pixelization of the sphere with the given subdivision level.
A RangeSet is a set of unsigned 64 bit integers.
Region is a minimal interface for 2-dimensional regions on the unit sphere.
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
void visit(UnitVector3d const *pixel, uint64_t index, int level)
This file contains functions for space-filling curves.
std::uint64_t hilbertIndex(std::uint32_t x, std::uint32_t y, int m)
hilbertIndex returns the index of (x, y) in a 2-D Hilbert curve.
std::uint8_t log2(std::uint64_t x)
std::tuple< std::uint32_t, std::uint32_t > hilbertIndexInverse(std::uint64_t h, int m)
hilbertIndexInverse returns the point (x, y) with Hilbert index h, where x and y are m bit integers.