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

Function extract_contour

ops/cpp_modules/src/cpp_modules.cpp:521–558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

519
520
521std::tuple<py::array_t<int>, py::array_t<int>> extract_contour(py::array_t<int> idx_map) {
522 // input array
523 py::buffer_info im_buf = idx_map.request();
524 int *im_ptr = (int *) im_buf.ptr;
525 int h = im_buf.shape[0];
526 int w = im_buf.shape[1];
527
528 // return array
529 auto contour_map = py::array_t<int>(h * w);
530 py::buffer_info cm_buf = contour_map.request();
531 int *cm_ptr = (int *) cm_buf.ptr;
532
533 vector<int> idx_sequence_vec;
534 for (int h_i = 0; h_i < h; h_i++){
535 idx_sequence_vec.push_back(im_ptr[h_i * w]);
536 cm_ptr[h_i * w] = 1;
537 for (int w_i = 1; w_i < w; w_i++)
538 if (im_ptr[h_i * w + w_i] - im_ptr[h_i * w + w_i - 1] != 0){
539 idx_sequence_vec.push_back(im_ptr[h_i * w + w_i]);
540 cm_ptr[h_i * w + w_i] = 1;
541 }
542 else{
543 cm_ptr[h_i * w + w_i] = 0;
544 }
545 }
546
547 // return array
548 int seq_size = idx_sequence_vec.size();
549 auto idx_sequence = py::array_t<int>(seq_size);
550 py::buffer_info is_buf = idx_sequence.request();
551 int *is_ptr = (int *) is_buf.ptr;
552 for (int i = 0; i < seq_size; i++){
553 is_ptr[i] = idx_sequence_vec[i];
554 }
555
556 contour_map.resize({h, w});
557 return std::make_tuple(contour_map, idx_sequence);
558}
559
560
561py::array_t<int> recover_map(py::array_t<int> contour_map, py::array_t<int> idx_sequence) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected