20 #ifndef KJB_EDGE_CHAMFER_LIKELIHOOD_H
21 #define KJB_EDGE_CHAMFER_LIKELIHOOD_H
26 #include <edge/edge_base.h>
27 #include <g/g_chamfer.h>
28 #include <l/l_int_matrix.h>
29 #include <m/m_matrix.h>
72 #ifdef KJB_HAVE_OPENGL
74 class Base_chamfer_likelihood
77 Base_chamfer_likelihood(
size_t width,
size_t height) :
82 square_values_(false),
83 offscreen_buffer_(width, height)
88 size_t get_num_model_points()
const
94 size_t get_num_correspondences()
const
96 return correspondences_;
100 size_t get_num_data_points()
const
110 double get_sum()
const
114 KJB_THROW_2(Runtime_error,
"Attempting to get sum when square_values is set. Use get_sq_sum() instead.");
124 double get_sq_sum()
const
128 KJB_THROW_2(Runtime_error,
"Attempting to get squared sum when square_values is not set. Use get_sum() instead, or call square_values(true) and re-evaluate.");
136 void square_values(
bool enabled)
138 square_values_ = enabled;
143 size_t model_points_;
145 size_t correspondences_;
149 ::kjb::opengl::Fbo_offscreen_buffer offscreen_buffer_;
155 class Base_gpu_chamfer_likelihood :
public Base_chamfer_likelihood
157 typedef Base_chamfer_likelihood Base;
163 Base_gpu_chamfer_likelihood(
int width_in,
int height_in) :
164 Base(width_in, height_in),
168 CU_ETX(cuGraphicsGLRegisterImage(
170 offscreen_buffer_.get_color_buffer(),
172 CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE));
177 virtual void operator()(
const Renderable&
object) = 0;
179 virtual ~Base_gpu_chamfer_likelihood()
181 cuGraphicsUnregisterResource(cuda_rbo_handle_);
188 void render_to_fbo(
const Renderable&
object);
192 CU_ETX(cuGraphicsUnmapResources(1, &cuda_rbo_handle_, 0));
195 CUgraphicsResource cuda_rbo_handle_;
197 gpu::Cuda_reduce_module reduce_mod_;
201 #ifdef KJB_HAVE_CUDPP
202 class Gpu_chamfer_likelihood :
public Base_gpu_chamfer_likelihood
208 Gpu_chamfer_likelihood(
int width,
int height);
212 virtual ~Gpu_chamfer_likelihood()
214 cudppDestroy(cudpp_handle_);
215 cuMemFree(buffer_ptr_);
216 cuMemFree(workspace_ui_);
228 void set_maps(
const CUdeviceptr distance,
const CUdeviceptr position,
size_t num_edges,
size_t N = 0);
234 CUdeviceptr create_distance_map(
const Matrix& distance_map);
242 CUdeviceptr create_position_map(
const std::vector<Int_matrix>& position_map)
244 return create_position_map(position_map[0], position_map[1]);
253 CUdeviceptr create_position_map(
const Int_matrix& row_position_map,
const Int_matrix& col_position_map);
262 void operator()(
const Renderable&
r);
269 void gold_standard_process(
const Renderable&
r,
const Chamfer_transform& xfm)
271 std::vector<Int_matrix> positions = xfm.position_map();
273 gold_standard_process(r, xfm.distance_map(), positions[0], positions[1], xfm.get_num_points());
277 void gold_standard_process(
const Renderable& r, Matrix distance,
const Int_matrix& row_position,
const Int_matrix& col_position,
size_t num_points) ;
280 Matrix get_buffer()
const;
284 void display_buffer(
const std::string& str =
"")
const;
289 CUdeviceptr array_to_linear(CUarray array);
299 void uint_cuda_sort_(CUdeviceptr uint_array);
312 double uint_reduce_(CUdeviceptr uint_array, CUdeviceptr workspace);
315 gpu::Cuda_utility_module util_mod_;
317 CUDPPHandle cudpp_handle_;
319 CUdeviceptr distance_map_;
320 CUdeviceptr position_map_;
321 CUdeviceptr buffer_ptr_;
322 CUdeviceptr workspace_ui_;
324 #if CUDA_VERSION < 3020
325 unsigned int buffer_pitch_bytes_;
327 size_t buffer_pitch_bytes_;
330 size_t buffer_pitch_elements_;
340 class Multi_gpu_chamfer_likelihood
348 Multi_gpu_chamfer_likelihood(
int width,
int height,
int modulo = 1) :
352 likelihood_(width, height),
357 square_values_(false),
362 Multi_gpu_chamfer_likelihood(
int width,
int height,
const std::vector<size_t>& view_list) :
366 likelihood_(width, height),
371 square_values_(false),
373 view_list_(view_list)
377 void square_values(
bool enabled)
382 square_values_ = enabled;
383 likelihood_.square_values(enabled);
389 virtual void push_back(
const Chamfer_transform& xfm);
400 virtual void push_back(
401 const Matrix& distance_map,
402 const Int_matrix& row_position_map,
403 const Int_matrix& col_position_map,
407 virtual void operator()(
const Mv_renderable&
m);
409 std::vector<size_t> get_view_list(
const size_t num_views);
418 void gold_standard_evaluate(
419 const Mv_renderable&
m,
420 std::vector<Matrix> distances,
421 std::vector<Int_matrix> row_positions,
422 std::vector<Int_matrix> col_positions,
423 std::vector<size_t> num_points
428 double get_sum()
const
432 KJB_THROW_2(Runtime_error,
"Attempting to get sum when square_values is set. Use get_sq_sum() instead.");
437 double get_sq_sum()
const
441 KJB_THROW_2(Runtime_error,
"Attempting to get squared sum when square_values is not set. Use get_sum() instead, or call square_values(true) and re-evaluate.");
447 size_t get_num_correspondences()
const
449 return correspondences_;
452 size_t get_num_data_points()
const
457 size_t get_num_model_points()
const
459 return model_points_;
463 void display_buffer(
const std::string title =
"")
const
465 likelihood_.display_buffer(title);
468 Matrix get_buffer()
const
470 return likelihood_.get_buffer();
474 ~Multi_gpu_chamfer_likelihood();
478 std::vector<CUdeviceptr> distance_maps_;
479 std::vector<CUdeviceptr> position_maps_;
480 std::vector<size_t> data_point_sizes_;
481 Gpu_chamfer_likelihood likelihood_;
484 size_t model_points_;
486 size_t correspondences_;
491 std::vector<size_t> view_list_;
501 class Chamfer_likelihood :
public Base_chamfer_likelihood
504 Chamfer_likelihood(
size_t width,
size_t height) :
505 Base_chamfer_likelihood(width, height),
513 const Matrix& distance,
514 const Int_matrix& row_position,
515 const Int_matrix& col_position,
519 void set_maps(
const Chamfer_transform& xfm)
521 xfm.position_map(row_position_, col_position_);
523 set_maps(xfm.distance_map(), row_position_, col_position_, xfm.get_num_points());
534 void operator()(
const Renderable& r,
bool invert_y =
true);
537 void evaluate_dispatch_(
float* buffer,
bool invert_y);
539 const Matrix* distance_;
540 Int_matrix row_position_;
541 Int_matrix col_position_;
height
Definition: APPgetLargeConnectedEdges.m:33
r
Definition: APPgetLargeConnectedEdges.m:127
Abstract class to render this object with GL.
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Code for a wrapper class around the C struct KJB_Image.
for m
Definition: APPgetLargeConnectedEdges.m:64