| 43 | |
| 44 | template <typename PointT> |
| 45 | void checkSimpleLine8 (unsigned x_start, unsigned y_start, unsigned x_end, unsigned y_end, PointCloud<PointT>& cloud) |
| 46 | { |
| 47 | PointXYZ point; |
| 48 | point.x = point.y = point.z = 0.0f; |
| 49 | for (unsigned yIdx = 0; yIdx < cloud.height; ++yIdx) |
| 50 | { |
| 51 | for (unsigned xIdx = 0; xIdx < cloud.width; ++xIdx) |
| 52 | { |
| 53 | PointT& point = cloud.points [yIdx * cloud.width + xIdx]; |
| 54 | point.x = static_cast<float>(xIdx); |
| 55 | point.y = static_cast<float>(yIdx); |
| 56 | point.z = 0.0f; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | LineIterator lineIt (x_start, y_start, x_end, y_end, cloud.width, LineIterator::Neighbor8); |
| 61 | // use polymorphic |
| 62 | OrganizedIndexIterator& iterator = lineIt; |
| 63 | unsigned idx = 0; |
| 64 | while (iterator.isValid ()) |
| 65 | { |
| 66 | PointT& point = cloud[*iterator]; |
| 67 | EXPECT_EQ (point.x, iterator.getColumnIndex ()); |
| 68 | EXPECT_EQ (point.y, iterator.getRowIndex ()); |
| 69 | point.z = 1.0f; |
| 70 | ++iterator; |
| 71 | ++idx; |
| 72 | } |
| 73 | int dx = x_end - x_start; |
| 74 | int dy = y_end - y_start; |
| 75 | unsigned dmax = std::max (std::abs(dx), std::abs(dy)); |
| 76 | |
| 77 | EXPECT_EQ (dmax, idx); |
| 78 | |
| 79 | int x_step = 0; |
| 80 | int y_step = 0; |
| 81 | |
| 82 | EXPECT_GT (dmax, 0); |
| 83 | if (dx == 0) |
| 84 | { |
| 85 | x_step = 0; |
| 86 | y_step = (dy > 0) ? 1 : -1; |
| 87 | } |
| 88 | else if (dy == 0) |
| 89 | { |
| 90 | y_step = 0; |
| 91 | x_step = (dx > 0) ? 1 : -1; |
| 92 | } |
| 93 | else if (std::abs(dx) == std::abs(dy)) |
| 94 | { |
| 95 | y_step = (dy > 0) ? 1 : -1; |
| 96 | x_step = (dx > 0) ? 1 : -1; |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | // only horizontal, vertical and 45deg diagonal lines handled here |
| 101 | EXPECT_TRUE (false); |
| 102 | } |
no test coverage detected