2D和3D仿射变换之间的比较

时间:2015-04-22 09:00:07

标签: cgal affinetransform

预计以下测试是否会失败?

该测试比较了2D和3D仿射变换的结果。两者都被构造成在y和z方向上具有单位缩放和零偏移,但是在x方向上具有非零和非单位缩放和偏移。所有其他非对角线元素均为零。我相信这些变换在x和y方向上是相同的,因此应该产生相同的结果。

此外,我发现如果我使用这个内核,测试通过了:

using K = CGAL::Exact_predicates_exact_constructions_kernel;

如果我使用这个内核,是否可以预期测试通过​​?测试是否应该使用内核失败或通过内核传递?

TEST(TransformerTest, testCGALAffine) {
using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Float = typename K::FT;
using Transformation_2 = K::Aff_transformation_2;
using Transformation_3 = K::Aff_transformation_3;
using Point_2 = typename K::Point_2;
using Point_3 = typename K::Point_3;

double lowerCorner(17.005142946538115);
double upperCorner(91.940521484752139);
int resolution = 48;
double tmpScaleX((upperCorner - lowerCorner) / resolution);
Float scaleX(tmpScaleX);
Float zero(0);
Float unit(1);

// create a 2D voxel to world transform
Transformation_2 transformV2W_2(scaleX, zero, Float(lowerCorner),
                                zero, unit, zero,
                                unit);
// create it's inverse: a 2D world to voxel transform
auto transformW2V_2 = transformV2W_2.inverse();

// create a 3D voxel to world transform
Transformation_3 transformV2W_3(scaleX, zero, zero, Float(lowerCorner),
                                zero, unit, zero, zero,
                                zero, zero, unit, zero,
                                unit);
// create it's inverse: a 3D world to voxel transform
auto transformW2V_3 = transformV2W_3.inverse();

for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 2; ++j) {
        EXPECT_EQ(transformV2W_2.cartesian(i, j), transformV2W_3.cartesian(i, j)) << i << ", " << j;
        EXPECT_EQ(transformW2V_2.cartesian(i, j), transformW2V_3.cartesian(i, j)) << i << ", " << j;
    }
}

std::mt19937_64 rng(0);
std::uniform_real_distribution<double> randReal(0, resolution);
// compare the results of 2D and 3D transformations of random locations
for (int i = 0; i < static_cast<int>(1e4); ++i) {
    Float x(randReal(rng));
    Float y(randReal(rng));
    auto world_2 = transformV2W_2(Point_2(x, y));
    auto world_3 = transformV2W_3(Point_3(x, y, 0));
    EXPECT_EQ(world_2.x(), world_3.x()) << world_2 << ", " << world_3;

    auto voxel_2 = transformW2V_2(world_2);
    auto voxel_3 = transformW2V_3(world_3);
    EXPECT_EQ(voxel_2.x(), voxel_3.x()) << voxel_2 << ", " << voxel_3;

}
}

0 个答案:

没有答案