MCPcopy Create free account
hub / github.com/PDAL/PDAL / TEST

Function TEST

test/unit/filters/VoxelCentroidNearestNeighborFilterTest.cpp:62–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 }
61
62 TEST(VoxelCentroidNearestNeighborFilterTest, SyntheticCloudKnownOutput)
63 {
64 // Set up the point table and register dimensions.
65 PointTable table;
66 table.layout()->registerDims({Dimension::Id::X, Dimension::Id::Y, Dimension::Id::Z});
67 PointViewPtr inputView(new PointView(table));
68
69 // We use (5,5,5) as the first point which defines the grid origin.
70 // Points are chosen such that when downsampled with cell=10:
71 // - Points (5,5,5) & (11,11,11) fall in one voxel, with the candidate expected to be (11,11,11)
72 // - Points (0,0,0) & (1,1,1) (which fall to the left/below the origin) fall in the negative voxel,
73 // with the candidate expected to be (0,0,0) (i.e. closer to the voxel center).
74 // - (21,21,21) falls in another voxel and is kept.
75 std::vector<std::array<double, 3>> inputPoints = {
76 {5, 5, 5}, // First point, defines origin.
77 {0, 0, 0}, // Negative side.
78 {1, 1, 1}, // Same voxel as above.
79 {11, 11, 11}, // Same voxel as (5,5,5) but closer to its voxel center.
80 {21, 21, 21} // Different voxel.
81 };
82
83 PointId id = 0;
84 for (const auto &pt : inputPoints)
85 {
86 inputView->setField(Dimension::Id::X, id, pt[0]);
87 inputView->setField(Dimension::Id::Y, id, pt[1]);
88 inputView->setField(Dimension::Id::Z, id, pt[2]);
89 ++id;
90 }
91
92 // Create a BufferReader and add our synthetic view.
93 BufferReader reader;
94 reader.addView(inputView);
95
96 // Set up the filter. With a cell size of 10, the voxel grid is built relative to (5,5,5).
97 VoxelCentroidNearestNeighborFilter filter;
98 Options opts;
99 opts.add("cell", 10);
100 filter.setOptions(opts);
101 filter.setInput(reader);
102
103 filter.prepare(table);
104 PointViewSet outputViews = filter.execute(table);
105
106 // We expect one output view.
107 ASSERT_EQ(outputViews.size(), 1u);
108 PointViewPtr outputView = *outputViews.begin();
109
110 // Expected output:
111 // * For the voxel containing (5,5,5) and (11,11,11) the candidate is (11,11,11)
112 // * For the voxel containing (0,0,0) and (1,1,1) the candidate is (0,0,0)
113 // * For the voxel containing (21,21,21) the candidate is (21,21,21)
114 std::vector<std::array<double, 3>> expected = {
115 {11, 11, 11},
116 {0, 0, 0},
117 {21, 21, 21}
118 };
119

Callers

nothing calls this directly

Calls 9

pointFoundInOutputFunction · 0.85
registerDimsMethod · 0.80
setOptionsMethod · 0.80
setFieldMethod · 0.45
addMethod · 0.45
prepareMethod · 0.45
executeMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected