mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2026-03-02 18:26:01 +08:00
Non square image rasterization for meshes
Summary: There are a couple of options for supporting non square images: 1) NDC stays at [-1, 1] in both directions with the distance calculations all modified by (W/H). There are a lot of distance based calculations (e.g. triangle areas for barycentric coordinates etc) so this requires changes in many places. 2) NDC is scaled by (W/H) so the smallest side has [-1, 1]. In this case none of the distance calculations need to be updated and only the pixel to NDC calculation needs to be modified. I decided to go with option 2 after trying option 1! API Changes: - Image size can now be specified optionally as a tuple TODO: - add a benchmark test for the non square case. Reviewed By: jcjohnson Differential Revision: D24404975 fbshipit-source-id: 545efb67c822d748ec35999b35762bce58db2cf4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0216e4689a
commit
d07307a451
@@ -3,11 +3,44 @@
|
||||
#pragma once
|
||||
|
||||
// Given a pixel coordinate 0 <= i < S, convert it to a normalized device
|
||||
// coordinate in the range [-1, 1]. We divide the NDC range into S evenly-sized
|
||||
// coordinates in the range [-1, 1]. We divide the NDC range into S evenly-sized
|
||||
// pixels, and assume that each pixel falls in the *center* of its range.
|
||||
// TODO: delete this function after updating the pointcloud rasterizer to
|
||||
// support non square images.
|
||||
__device__ inline float PixToNdc(int i, int S) {
|
||||
// NDC x-offset + (i * pixel_width + half_pixel_width)
|
||||
return -1 + (2 * i + 1.0f) / S;
|
||||
// NDC: x-offset + (i * pixel_width + half_pixel_width)
|
||||
return -1.0 + (2 * i + 1.0) / S;
|
||||
}
|
||||
|
||||
// The default value of the NDC range is [-1, 1], however in the case that
|
||||
// H != W, the NDC range is set such that the shorter side has range [-1, 1] and
|
||||
// the longer side is scaled by the ratio of H:W. S1 is the dimension for which
|
||||
// the NDC range is calculated and S2 is the other image dimension.
|
||||
// e.g. to get the NDC x range S1 = W and S2 = H
|
||||
__device__ inline float NonSquareNdcRange(int S1, int S2) {
|
||||
float range = 2.0f;
|
||||
if (S1 > S2) {
|
||||
range = ((S1 / S2) * range);
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
||||
// Given a pixel coordinate 0 <= i < S1, convert it to a normalized device
|
||||
// coordinates. We divide the NDC range into S1 evenly-sized
|
||||
// pixels, and assume that each pixel falls in the *center* of its range.
|
||||
// The default value of the NDC range is [-1, 1], however in the case that
|
||||
// H != W, the NDC range is set such that the shorter side has range [-1, 1] and
|
||||
// the longer side is scaled by the ratio of H:W. The dimension of i should be
|
||||
// S1 and the other image dimension is S2 For example, to get the x and y NDC
|
||||
// coordinates or a given pixel i:
|
||||
// x = PixToNonSquareNdc(i, W, H)
|
||||
// y = PixToNonSquareNdc(i, H, W)
|
||||
__device__ inline float PixToNonSquareNdc(int i, int S1, int S2) {
|
||||
float range = NonSquareNdcRange(S1, S2);
|
||||
// NDC: offset + (i * pixel_width + half_pixel_width)
|
||||
// The NDC range is [-range/2, range/2].
|
||||
float offset = (range / 2.0f);
|
||||
return -offset + (range * i + offset) / S1;
|
||||
}
|
||||
|
||||
// The maximum number of points per pixel that we can return. Since we use
|
||||
|
||||
Reference in New Issue
Block a user