MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / checkGeneralLine

Function checkGeneralLine

test/geometry/test_iterator.cpp:126–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124
125template <typename PointT>
126void checkGeneralLine (unsigned x_start, unsigned y_start, unsigned x_end, unsigned y_end, PointCloud<PointT>& cloud, bool neighorhood)
127{
128 PointXYZ point;
129 point.x = point.y = point.z = 0.0f;
130 for (unsigned yIdx = 0; yIdx < cloud.height; ++yIdx)
131 {
132 for (unsigned xIdx = 0; xIdx < cloud.width; ++xIdx)
133 {
134 PointT& point = cloud.points [yIdx * cloud.width + xIdx];
135 point.x = static_cast<float>(xIdx);
136 point.y = static_cast<float>(yIdx);
137 point.z = 0.0f;
138 }
139 }
140
141 LineIterator::Neighborhood neighbors;
142 if (neighorhood)
143 neighbors = LineIterator::Neighbor8;
144 else
145 neighbors = LineIterator::Neighbor4;
146
147 LineIterator lineIt (x_start, y_start, x_end, y_end, cloud.width, neighbors);
148 // use polymorphic
149 OrganizedIndexIterator& iterator = lineIt;
150 unsigned idx = 0;
151 while (iterator.isValid ())
152 {
153 PointT& point = cloud [*iterator];
154 EXPECT_EQ (point.x, iterator.getColumnIndex ());
155 EXPECT_EQ (point.y, iterator.getRowIndex ());
156 //std::cout << idx << " :: " << iterator.getPointIndex () << " :: " << iterator.getColumnIndex () << " , " << iterator.getRowIndex () << std::endl;
157 point.z = 1.0f;
158 ++iterator;
159 ++idx;
160 }
161
162 int dx = x_end - x_start;
163 int dy = y_end - y_start;
164 unsigned dmax = std::max (std::abs(dx), std::abs(dy));
165
166 if (neighorhood)
167 EXPECT_EQ (dmax, idx);
168 else
169 EXPECT_EQ (std::abs(dx) + std::abs(dy), idx);
170
171 float length = std::sqrt (static_cast<float>(dx * dx + dy * dy));
172 float dir_x = static_cast<float>(dx) / length;
173 float dir_y = static_cast<float>(dy) / length;
174
175 // now all z-values should be 0 again!
176 for (int yIdx = 0; yIdx < static_cast<int>(cloud.height); ++yIdx)
177 {
178 for (int xIdx = 0; xIdx < static_cast<int>(cloud.width); ++xIdx)
179 {
180 PointT& point = cloud.points [yIdx * cloud.width + xIdx];
181 if (point.z != 0)
182 {
183 // point need to be close to line

Callers 1

TESTFunction · 0.85

Calls 6

absFunction · 0.85
fabsFunction · 0.85
maxFunction · 0.50
isValidMethod · 0.45
getColumnIndexMethod · 0.45
getRowIndexMethod · 0.45

Tested by

no test coverage detected