NOTE: The test data has an accompanying jpg that depicts the points, their triangulation and the interesting barycentric calculation.
| 46 | // NOTE: The test data has an accompanying jpg that depicts the points, |
| 47 | // their triangulation and the interesting barycentric calculation. |
| 48 | TEST(FaceRasterTest, basic) |
| 49 | { |
| 50 | Options ro; |
| 51 | ro.add("filename", Support::datapath("filters/hagtest.txt")); |
| 52 | |
| 53 | StageFactory factory; |
| 54 | Stage& r = *(factory.createStage("readers.text")); |
| 55 | r.setOptions(ro); |
| 56 | |
| 57 | Options rngO; |
| 58 | rngO.add("limits", "Classification[2:2]"); |
| 59 | Stage& rng = *(factory.createStage("filters.range")); |
| 60 | rng.setOptions(rngO); |
| 61 | rng.setInput(r); |
| 62 | |
| 63 | Stage& d = *(factory.createStage("filters.delaunay")); |
| 64 | d.setInput(rng); |
| 65 | |
| 66 | Options fo; |
| 67 | fo.add("resolution", 1); |
| 68 | Stage& f = *(factory.createStage("filters.faceraster")); |
| 69 | f.setInput(d); |
| 70 | f.setOptions(fo); |
| 71 | |
| 72 | const std::string output_file = Support::temppath("test.tif"); |
| 73 | |
| 74 | Options wo; |
| 75 | wo.add("filename", output_file); |
| 76 | Stage& w = *(factory.createStage("writers.raster")); |
| 77 | w.setInput(f); |
| 78 | w.setOptions(wo); |
| 79 | |
| 80 | PointTable t1; |
| 81 | w.prepare(t1); |
| 82 | PointViewSet s = w.execute(t1); |
| 83 | PointViewPtr v = *s.begin(); |
| 84 | |
| 85 | gdal::Raster raster(output_file, "GTiff"); |
| 86 | if (raster.open() != gdal::GDALError::None) |
| 87 | throw pdal_error(raster.errorMsg()); |
| 88 | std::vector<double> data; |
| 89 | raster.readBand(data, 1); |
| 90 | int row = 0; |
| 91 | int col = 0; |
| 92 | |
| 93 | const std::vector<double> expected |
| 94 | { |
| 95 | -9999, 10, -9999, -9999, -9999, -9999, |
| 96 | -9999, 9, 7, -9999, -9999, -9999, |
| 97 | 10, 8, 6, 4, -9999, -9999, |
| 98 | 6.66667, 4.66667, 2.66667, 6, 7, -9999, |
| 99 | 3.33333, 1.33333, 4.66667, 8, 9, 10, |
| 100 | 0, 3.33333, 6.66667, 10, -9999, -9999 |
| 101 | }; |
| 102 | |
| 103 | size_t size = raster.width() * raster.height(); |
| 104 | for (size_t i = 0; i < size; ++i) |
| 105 | EXPECT_NEAR(expected[i], data[i], .00001); |