void DetectCornerPoint(float * const x,float *const y,float * const kDiff,char * const flag,char * const valid,uint num,uint r,float threshold) { for(int i=r;i<num-r;i++) { int n=0; float xx[num],yy[num]; for(int j=i;j>=0;j--) { if(valid[j]) { xx[n]=x[j]; yy[n]=y[j]; n++; } if(n>=r)break; } std::valarray <float> left_x(xx,n),left_y(yy,n); float lk,lb,le; bool ret; ret=LineFit(lk,lb,le,left_x,left_y); // cout<<"i:"<<i<<" lk:"<<lk<<" lb:"<<lb<<" le:"<<le<<endl; if(!ret)continue; if(le>threshold)continue; n=0; for(int j=i;j<num;j++) { if(valid[j]) { xx[n]=x[j]; yy[n]=y[j]; n++; } if(n>=r)break; } std::valarray <float> right_x(xx,n),right_y(yy,n); float rk,rb,re; ret=LineFit(rk,rb,re,right_x,right_y); // cout<<"i:"<<i<<" rk:"<<rk<<" rb:"<<rb<<" re:"<<re<<endl; if(!ret)continue; if(re>threshold)continue; flag[i]=1; kDiff[i]=fabs(atan(lk)-atan(rk)); if(kDiff[i]> xform::pi_2) kDiff[i]=xform::pi-kDiff[i]; // std::cout<<"i:"<<i<<" kDiff:"<<kDiff[i]<<std::endl; } }
int main() { { node::ptr_t left_d(create_left_tree_from("d")); boost::coroutines::coroutine<std::string>::pull_type left_d_reader( [&]( boost::coroutines::coroutine<std::string>::push_type & out) { traverse(left_d,out); }); std::cout << "left tree from d:\n"; std::copy(std::begin(left_d_reader), std::end(left_d_reader), std::ostream_iterator<std::string>(std::cout, " ")); std::cout << std::endl; node::ptr_t right_b(create_right_tree_from("b")); boost::coroutines::coroutine<std::string>::pull_type right_b_reader( [&]( boost::coroutines::coroutine<std::string>::push_type & out) { traverse(right_b,out); }); std::cout << "right tree from b:\n"; std::copy(std::begin(right_b_reader), std::end(right_b_reader), std::ostream_iterator<std::string>(std::cout, " ")); std::cout << std::endl; node::ptr_t right_x(create_right_tree_from("x")); boost::coroutines::coroutine<std::string>::pull_type right_x_reader( [&]( boost::coroutines::coroutine<std::string>::push_type & out) { traverse(right_x,out); }); std::cout << "right tree from x:\n"; std::copy(std::begin(right_x_reader), std::end(right_x_reader), std::ostream_iterator<std::string>(std::cout, " ")); std::cout << std::endl; } { node::ptr_t left_d(create_left_tree_from("d")); boost::coroutines::coroutine<std::string>::pull_type left_d_reader( [&]( boost::coroutines::coroutine<std::string>::push_type & out) { traverse(left_d,out); }); node::ptr_t right_b(create_right_tree_from("b")); boost::coroutines::coroutine<std::string>::pull_type right_b_reader( [&]( boost::coroutines::coroutine<std::string>::push_type & out) { traverse(right_b,out); }); std::cout << "left tree from d == right tree from b? " << std::boolalpha << std::equal(std::begin(left_d_reader), std::end(left_d_reader), std::begin(right_b_reader)) << std::endl; } { node::ptr_t left_d(create_left_tree_from("d")); boost::coroutines::coroutine<std::string>::pull_type left_d_reader( [&]( boost::coroutines::coroutine<std::string>::push_type & out) { traverse(left_d,out); }); node::ptr_t right_x(create_right_tree_from("x")); boost::coroutines::coroutine<std::string>::pull_type right_x_reader( [&]( boost::coroutines::coroutine<std::string>::push_type & out) { traverse(right_x,out); }); std::cout << "left tree from d == right tree from x? " << std::boolalpha << std::equal(std::begin(left_d_reader), std::end(left_d_reader), std::begin(right_x_reader)) << std::endl; } std::cout << "Done" << std::endl; return EXIT_SUCCESS; }