#include "pch.h"
int main()
{
//启动techlego程序
auto r = techlego::am::create_techlego_process2(LR"(C:\Program Files\Techlego\Techlego\Techlego.exe)", SW_SHOW);
if (r == techlego::create_process_result::m_failed)
return 0;
//通过IP端口创建协议
auto protocol = techlego::create_binary_protocol(L"localhost", 5252);
//通过协议创建客户端
bin::stack_object<techlego::h_scan3d_client> object_info;
bin::h_stack client(object_info(alloca(object_info)), protocol);//对象放在栈上的方法,作为局域变量,比放在堆上分配快一些,但alloca不能放到循环里,导致栈溢出
//auto client = techlego::h_scan3d_client::make_unique(protocol);//对象放在堆上,可以替代上面两行
auto buffer = techlego::h_buffer::make_shared();
/// 获取选中的点云
auto pos6f = client->get_select_points(*buffer);
techlego::pos6d plane;
/// 拟合直线,this:输出直线上的点和单位方向
double err = plane.fit_line(pos6f);
if (err == -1)
{
std::cerr << "选中点云不足2个" << std::endl;
return -1;
}
/// 获取选中的点云
auto pos = client->get_select_points(*buffer);
for (int i = 0;i < pos.size();i++)
{
//计算三维空间中点到直线的距离平方。
double dist = std::sqrt(plane.point_line_square_dist(pos[i]));
std::cout << "点到直线的距离:" << dist << std::endl;
}
return 0;
}