@@ -268,10 +268,11 @@ void RegisterNodelet::convert(const sensor_msgs::ImageConstPtr& depth_msg,
268268 const T* depth_row = reinterpret_cast <const T*>(&depth_msg->data [0 ]);
269269 const int row_step = depth_msg->step / sizeof (T);
270270 T* registered_data = reinterpret_cast <T*>(®istered_msg->data [0 ]);
271- int raw_index = 0 ;
271+ // TODO(lucasw) this isn't used
272+ // int raw_index = 0;
272273 for (unsigned v = 0 ; v < depth_msg->height ; ++v, depth_row += row_step)
273274 {
274- for (unsigned u = 0 ; u < depth_msg->width ; ++u, ++raw_index)
275+ for (unsigned u = 0 ; u < depth_msg->width ; ++u /* , ++raw_index */ )
275276 {
276277 const T raw_depth = depth_row[u];
277278 if (!DepthTraits<T>::valid (raw_depth))
@@ -293,7 +294,7 @@ void RegisterNodelet::convert(const sensor_msgs::ImageConstPtr& depth_msg,
293294 continue ;
294295 }
295296
296- T& reg_depth = registered_data[v_rgb*registered_msg-> width + u_rgb];
297+ T& reg_depth = registered_data[v_rgb*dst_width + u_rgb];
297298 // Validity and Z-buffer checks
298299 if (!DepthTraits<T>::valid (reg_depth) || reg_depth > new_depth)
299300 reg_depth = new_depth;
@@ -303,40 +304,53 @@ void RegisterNodelet::convert(const sensor_msgs::ImageConstPtr& depth_msg,
303304 {
304305 // TODO(lucasw) loop on two -0.5, 0.5 vectors, keep track of u_min/max and v_min/max
305306 // as it goes
306- int u_rgb_1;
307- int v_rgb_1;
308- T new_depth_1;
309- if (!transform_depth (depth_to_rgb,
310- u - 0.5 , v - 0.5 ,
311- depth_model_, rgb_model_,
312- inv_depth_fx, inv_depth_fy,
313- dst_width, dst_height,
314- depth,
315- u_rgb_1, v_rgb_1, new_depth_1)) {
316- // TODO(lucasw) need to be able to handle partiall out of bounds squares here
317- continue ;
307+ int u_rgb_min, u_rgb_max;
308+ int v_rgb_min, v_rgb_max;
309+ size_t count = 0 ;
310+ T new_depth_sum = 0.0 ;
311+ const std::array<double , 2 > uv_offsets = {-0.5 , 0.5 };
312+ for (const auto & v_offset : uv_offsets) {
313+ for (const auto & u_offset : uv_offsets) {
314+ int u_rgb;
315+ int v_rgb;
316+ T new_depth;
317+ if (!transform_depth (depth_to_rgb,
318+ u + u_offset, v + v_offset,
319+ depth_model_, rgb_model_,
320+ inv_depth_fx, inv_depth_fy,
321+ dst_width, dst_height,
322+ depth,
323+ u_rgb, v_rgb, new_depth)) {
324+ // TODO(lucasw) need to be able to handle partiall out of bounds squares here
325+ continue ;
326+ }
327+ if (count == 0 ) {
328+ u_rgb_min = u_rgb;
329+ u_rgb_max = u_rgb;
330+ v_rgb_min = v_rgb;
331+ v_rgb_max = v_rgb;
332+ } else {
333+ u_rgb_min = std::min (u_rgb, u_rgb_min);
334+ u_rgb_max = std::max (u_rgb, u_rgb_max);
335+ v_rgb_min = std::min (v_rgb, v_rgb_min);
336+ v_rgb_max = std::max (v_rgb, v_rgb_max);
337+ }
338+ new_depth_sum += new_depth;
339+ count++;
340+ }
318341 }
319342
320- int u_rgb_2;
321- int v_rgb_2;
322- T new_depth_2;
323- if (!transform_depth (depth_to_rgb,
324- u + 0.5 , v + 0.5 ,
325- depth_model_, rgb_model_,
326- inv_depth_fx, inv_depth_fy,
327- dst_width, dst_height,
328- depth,
329- u_rgb_2, v_rgb_2, new_depth_2)) {
343+ if (count == 0 ) {
330344 continue ;
331345 }
332346
333347 // fill in the square defined by uv range
334- const T new_depth = DepthTraits<T>::fromMeters (0.5 * (new_depth_1 + new_depth_2 ));
335- for (int nv=std::min (v_rgb_1, v_rgb_2) ; nv<=std::max (v_rgb_1, v_rgb_2) ; ++nv)
348+ const T new_depth = DepthTraits<T>::fromMeters (new_depth_sum / static_cast < double >(count ));
349+ for (int nv=v_rgb_min ; nv<=v_rgb_max ; ++nv)
336350 {
337- for (int nu=std::min (u_rgb_1, u_rgb_2) ; nu<=std::max (u_rgb_2, u_rgb_2) ; ++nu)
351+ for (int nu=u_rgb_min ; nu<=u_rgb_max ; ++nu)
338352 {
339- T& reg_depth = registered_data[nv*registered_msg-> width + nu];
353+ T& reg_depth = registered_data[nv*dst_width + nu];
340354 // Validity and Z-buffer checks
341355 if (!DepthTraits<T>::valid (reg_depth) || reg_depth > new_depth)
342356 reg_depth = new_depth;
0 commit comments