MCPcopy Create free account
hub / github.com/StevenWang30/R-PCC / point_modeling

Function point_modeling

ops/cpp_modules/src/cpp_modules.cpp:471–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469
470
471py::array_t<float> point_modeling(py::array_t<float> range_image, py::array_t<int> seg_idx) {
472 // input array
473 py::buffer_info ri_buf = range_image.request();
474 float *ri_ptr = (float *) ri_buf.ptr;
475 py::buffer_info si_buf = seg_idx.request();
476 int *si_ptr = (int *) si_buf.ptr;
477 int h = si_buf.shape[0];
478 int w = si_buf.shape[1];
479
480
481 int cluster_num = 0;
482 for (int h_i = 0; h_i < h; h_i++)
483 for (int w_i = 0; w_i < w; w_i++)
484 if (si_ptr[h_i * w + w_i] > cluster_num)
485 cluster_num = si_ptr[h_i * w + w_i];
486 cluster_num += 1;
487
488 vector< vector<float> > cluster_points;
489 for (int i = 0; i < cluster_num; i++){
490 vector<float> cur_cluster;
491 cluster_points.push_back(cur_cluster);
492 }
493
494 for (int h_i = 0; h_i < h; h_i++) {
495 for (int w_i = 0; w_i < w; w_i++){
496 int idx = si_ptr[h_i * w + w_i];
497 if (idx != 0 && idx != 1){
498 cluster_points[idx].push_back(ri_ptr[h_i * w + w_i]);
499 }
500 }
501 }
502
503
504 // return array
505 auto point_model = py::array_t<float>(cluster_num);
506 py::buffer_info qm_buf = point_model.request();
507 float *qm_ptr = (float *) qm_buf.ptr;
508
509
510 for (int i = 0; i < cluster_num; i++){
511 if (i == 0 || i == 1)
512 qm_ptr[i] = 0.0;
513 else
514 qm_ptr[i] = accumulate( cluster_points[i].begin(), cluster_points[i].end(), 0.0)/cluster_points[i].size();
515 }
516
517 return point_model;
518}
519
520
521std::tuple<py::array_t<int>, py::array_t<int>> extract_contour(py::array_t<int> idx_map) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected