#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;
			
				}