@@ -164,6 +164,10 @@ bool decimateSpatioTemporal(const std::string &file_stub, double vox_width, int
164164 return true ;
165165}
166166
167+ int sign (double x)
168+ {
169+ return (x > 0.0 ) - (x < 0.0 );
170+ }
167171
168172bool decimateRaysSpatial (const std::string &file_stub, double vox_width)
169173{
@@ -193,7 +197,11 @@ bool decimateRaysSpatial(const std::string &file_stub, double vox_width)
193197 const Eigen::Vector3d source = starts[i] / width;
194198 const Eigen::Vector3d target = ends[i] / width;
195199 #endif
200+
201+ #define OLD_METHOD
202+ #if defined OLD_METHOD
196203 const double length = dir.norm ();
204+ dir /= length;
197205 for (int a = 0 ; a<3 ; a++)
198206 {
199207 if (dir[a] == 0.0 )
@@ -236,16 +244,76 @@ bool decimateRaysSpatial(const std::string &file_stub, double vox_width)
236244 (std::round (p[2 ] + offsets[2 ]) - p[2 ]) / dir[2 ] };
237245 int axis = (ls[0 ] < ls[1 ] && ls[0 ] < ls[2 ]) ? 0 : (ls[1 ] < ls[2 ] ? 1 : 2 );
238246 inds[axis] += adds[axis];
239- double minL = ls[axis] * length;
240- depth += minL + eps;
241- p = source + dir * (depth / length);
247+ depth += ls[axis] + eps;
248+ p = source + dir * depth;
242249
243250 if (voxel_set.insert (inds).second )
244251 {
245252 subsample.push_back (i);
246253 break ; // only adding to one cell
247254 }
248255 } while (depth <= maxDist);
256+ #else
257+ Eigen::Vector3i p = Eigen::Vector3d (std::floor (source[0 ]), std::floor (source[1 ]), std::floor (source[2 ])).cast <int >();
258+ Eigen::Vector3i end = Eigen::Vector3d (std::floor (target[0 ]), std::floor (target[1 ]), std::floor (target[2 ])).cast <int >();
259+
260+ if (voxel_set.insert (p).second )
261+ {
262+ std::cout << " missed p: " << p.transpose () << " between " << source.transpose () << " and " << target.transpose () << std::endl;
263+ subsample.push_back (i);
264+ continue ; // only adding to one cell
265+ }
266+
267+ Eigen::Vector3i step (sign (target[0 ] - source[0 ]), sign (target[1 ] - source[1 ]), sign (target[2 ] - source[2 ]));
268+ Eigen::Vector3d tmax, tdelta;
269+ for (int j = 0 ; j<3 ; j++)
270+ {
271+ step[j] = sign (target[j] - source[j]);
272+ double to = std::abs (source[j] - p[j] - (double )std::max (0 , step[j]));
273+ double dir = std::max (std::numeric_limits<double >::min (), std::abs (source[j] - target[j]));
274+ tmax[j] = to / dir;
275+ tdelta[j] = 1.0 / dir;
276+ }
277+
278+ while (p != end)
279+ {
280+ int ax = tmax[0 ] < tmax[1 ] && tmax[0 ] < tmax[2 ] ? 0 : (tmax[1 ] < tmax[2 ] ? 1 : 2 );
281+ p[ax] += step[ax];
282+ tmax[ax] += tdelta[ax];
283+ /* if (tmax[0] < tmax[1])
284+ {
285+ if (tmax[0] < tmax[2])
286+ {
287+ p[0] += step[0];
288+ tmax[0] += tdelta[0];
289+ }
290+ else
291+ {
292+ p[2] += step[2];
293+ tmax[2] += tdelta[2];
294+ }
295+ }
296+ else
297+ {
298+ if (tmax[1] < tmax[2])
299+ {
300+ p[1] += step[1];
301+ tmax[1] += tdelta[1];
302+ }
303+ else
304+ {
305+ p[2] += step[2];
306+ tmax[2] += tdelta[2];
307+ }
308+ }*/
309+ if (voxel_set.insert (p).second )
310+ {
311+ std::cout << " missed p: " << p.transpose () << " between " << source.transpose () << " and " << target.transpose () << std::endl;
312+ subsample.push_back (i);
313+ break ; // only adding to one cell
314+ }
315+ }
316+ #endif
249317 }
250318 chunk.resize (subsample.size ());
251319 for (int64_t i = 0 ; i < (int64_t )subsample.size (); i++)
0 commit comments