简体   繁体   English

带有纹理 UV 映射的 HEALPix

[英]HEALPix with texture UV mapping

I found an implementation of the HEALpix algorithm this is the dokumentation And the output looks very nice.我找到了 HEALpix 算法的一个实现,这是文档并且输出看起来非常好。

The following images show the latitude / longitude conversion to HEALpix areas.下图显示了纬度/经度转换为 HEALpix 区域。 The x-axe goes from 0 to 2 * pi. x 轴从 0 到 2 * pi。 The y-axe goes from 0 to pi. y 轴从 0 到 pi。 The grey color represents the HEALpix pixel encoded in grey.灰色代表以灰色编码的 HEALpix 像素。

Nside = 1侧 = 1 在此处输入图片说明

Nside = 2侧 = 2 在此处输入图片说明

Nside = 4侧 = 4 在此处输入图片说明

Nside = 8侧 = 8 在此处输入图片说明

The different grey values are the IDs for the texture I have to use.不同的灰度值是我必须使用的纹理的 ID。 That means, that each HEALpix pixel represents one texture.这意味着,每个 HEALpix 像素代表一个纹理。 The missing part is the UV mapping within each of the HEALpix pixels like shown below:缺失的部分是每个 HEALpix 像素内的 UV 映射,如下所示:

nSide = 1 with UV mapping nSide = 1 带 UV 贴图在此处输入图片说明

Right now I am using the function:现在我正在使用该功能:

void ang2pix_ring( const long nside, double theta, double phi, long *ipix)

Which gives me the correct texture ID.这给了我正确的纹理 ID。 But I've no idea how to calculate the UV mapping for each HEALpix pixel.但我不知道如何计算每个 HEALpix 像素的 UV 映射。 Is there a way to calculate all four corners in lat/lon coordinates of a HEALpix pixel?有没有办法计算 HEALpix 像素的纬度/经度坐标中的所有四个角? Or even better a direct calculation to the UV coordinates?或者甚至更好地直接计算 UV 坐标?

BTW: I am using the RING scheme.顺便说一句:我正在使用 RING 方案。 But if the NESTED scheme is simpler to calculate I also would change to that.但是,如果 NESTED 方案更容易计算,我也会更改为。

After a lot of research I came to a solution for this problem:经过大量研究,我找到了解决此问题的方法:

First of all, I've changed the scheme to NESTED.首先,我已将方案更改为 NESTED。 With the NESTED scheme and a very high nSide value (8192), the returned value from the使用 NESTED 方案和非常高的 nSide 值 (8192),从

void ang2pix_ring( const long nside, double theta, double phi, long *ipix)

function gives back a long value where the UV coordinates can be read out in the following way:函数返回一个长值,可以通过以下方式读取 UV 坐标:

Bit 26 till 30 represents the level 0 (only the 12 HEALPix pixels).位 26 到 30 表示级别 0(仅 12 个 HEALPix 像素)。

By using higher levels, the Bits from 30 till 26 - (level * 2) represents the HEALPix pixels.通过使用更高级别,从 30 到 26 -(级别 * 2)的位代表 HEALPix 像素。

The leftover 26 - (level * 2) - 1 till bit 1 encode the UV texture-coordinates in the following way:剩余的 26 - (level * 2) - 1 直到位 1 以下列方式编码 UV 纹理坐标:

Each second odd bit shrink together represents the U coordinate and the even once represents the V coordinate.每第二个奇数位一起收缩代表 U 坐标,偶数一次代表 V 坐标。 To normalize these UV-coordinates the responding shrinked values need to be divided by the value of pow(2, (26 - level * 2) / 2).要标准化这些 UV 坐标,需要将响应收缩的值除以 pow(2, (26 - level * 2) / 2) 的值。

Code says more than 1000 words:代码一千多字:

unsigned long ignoreEverySecondBit(unsigned long value, bool odd, unsigned int countBits)
{
    unsigned long result = 0;
    unsigned long mask = odd == true ? 0b1 : 0b10;
    countBits = countBits / 2;
    for (int i = 0; i < countBits; ++i)
    {
        if ((value & mask) != 0)
        {
            result += std::pow(2, i);
        }
        mask = mask << 2;
    }

    return result;
}


//calculate the HEALPix values:
latLonToHealPixNESTED(nSide, theta, phi, &pix);

result.level = level;
result.texture = pix >> (26 - level * 2);
result.u = static_cast<float>(ignoreEverySecondBit(pix, true, 26 - level * 2));
result.v = static_cast<float>(ignoreEverySecondBit(pix, false, 26 - level * 2));

result.u = result.u / pow(2, (26 - level * 2) / 2);
result.v = result.v / pow(2, (26 - level * 2) / 2);

And of cause a few images to show the results.当然还有一些图像来显示结果。 The blue value represents the textureID, the red value represents the U-coordinate and the green value represents the V-coordinate:蓝色值代表纹理ID,红色值代表U坐标,绿色值代表V坐标:

Level 0 0级在此处输入图片说明

Level 1 1级在此处输入图片说明

Level 2 2 级在此处输入图片说明

Level 3级别 3 在此处输入图片说明

Level 4 4级在此处输入图片说明

I hope this solution will help others too.我希望这个解决方案也能帮助其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM