|
|
@ -15,10 +15,10 @@ |
|
|
|
#include <time.h> |
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
|
|
map<P, string> pmp, clipName; |
|
|
|
|
|
|
|
struct Readexcel{ |
|
|
|
struct Readexcel |
|
|
|
{ |
|
|
|
vector<string> slist; |
|
|
|
TiXmlElement *GetNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) |
|
|
|
{ |
|
|
@ -34,13 +34,16 @@ struct Readexcel{ |
|
|
|
if (0 != strcmp(pEle->Value(), strNodeName)) |
|
|
|
{ |
|
|
|
TiXmlElement *res = GetNodePointerByName(pEle, strNodeName); |
|
|
|
if(res!=NULL)return res; |
|
|
|
if (res != NULL) |
|
|
|
return res; |
|
|
|
} |
|
|
|
else return pEle; |
|
|
|
else |
|
|
|
return pEle; |
|
|
|
} |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
vector<string> read(string xml){ |
|
|
|
vector<string> read(string xml) |
|
|
|
{ |
|
|
|
|
|
|
|
slist.clear(); |
|
|
|
TiXmlDocument *pDoc = new TiXmlDocument(); |
|
|
@ -59,7 +62,8 @@ struct Readexcel{ |
|
|
|
TiXmlElement *cell; |
|
|
|
string s[7]; |
|
|
|
int i = 0; |
|
|
|
for (cell =pEle->FirstChildElement(); cell; cell = cell->NextSiblingElement()){ |
|
|
|
for (cell = pEle->FirstChildElement(); cell; cell = cell->NextSiblingElement()) |
|
|
|
{ |
|
|
|
|
|
|
|
// cout<<(cell->FirstChildElement()->GetText())<<endl;
|
|
|
|
|
|
|
@ -71,18 +75,17 @@ struct Readexcel{ |
|
|
|
slist.push_back(s[4] + " " + s[5] + " " + s[6]); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return slist; |
|
|
|
} |
|
|
|
} rexcel; |
|
|
|
|
|
|
|
// 读取卡箍点
|
|
|
|
void read_points(string filename,Astar * pastar){ |
|
|
|
void read_points(string filename, Astar *pastar) |
|
|
|
{ |
|
|
|
// cout<<"read "<<filename<<endl;
|
|
|
|
vector<string> sl = rexcel.read(filename); |
|
|
|
// cout<<"------"<<endl;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sl.size(); i += 3) |
|
|
|
{ |
|
|
|
string s1 = sl[i + 1], s2 = sl[i + 2], s0 = sl[i]; |
|
|
@ -101,69 +104,84 @@ void read_points(string filename,Astar * pastar){ |
|
|
|
pastar->add_clip(clipSet.c[clipSet.clipnum]); |
|
|
|
// cout<<"--"<<endl;
|
|
|
|
kdtree.add(p1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
unsigned int extractAndConvert(const string& str) { |
|
|
|
unsigned int extractAndConvert(const string &str) |
|
|
|
{ |
|
|
|
size_t pos = str.find("/"); // 查找 "//" 的位置
|
|
|
|
if (pos == std::string::npos) { |
|
|
|
if (pos == std::string::npos) |
|
|
|
{ |
|
|
|
throw invalid_argument("No '/' found in the string."); |
|
|
|
} |
|
|
|
string numberStr = str.substr(0, pos); // 截取 "//" 之前的部分
|
|
|
|
char *endptr; |
|
|
|
long number = strtol(numberStr.c_str(), &endptr, 10); // 使用 strtol 将字符串转换为 long,并检查转换是否成功
|
|
|
|
if (endptr == numberStr.c_str() || *endptr != '\0' || number < 0 || static_cast<unsigned int>(number) != number) { |
|
|
|
if (endptr == numberStr.c_str() || *endptr != '\0' || number < 0 || static_cast<unsigned int>(number) != number) |
|
|
|
{ |
|
|
|
throw invalid_argument("Invalid input string for conversion to unsigned int."); |
|
|
|
} // 检查转换是否成功,以及值是否在 unsigned int 的范围内
|
|
|
|
return static_cast<unsigned int>(number); // 转换为 unsigned int 并返回
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool read_OBJ(const string &filename, vector<Vec3f> &vertices, vector<Vec3u> &indices) |
|
|
|
{ |
|
|
|
ifstream file(filename.c_str()); |
|
|
|
if (!file.is_open()) { |
|
|
|
if (!file.is_open()) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
string line; |
|
|
|
while (getline(file, line)) { |
|
|
|
while (getline(file, line)) |
|
|
|
{ |
|
|
|
// 忽略空行和注释行
|
|
|
|
if (line.empty() || line.at(0) == '#') { |
|
|
|
if (line.empty() || line.at(0) == '#') |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
// std::cout<<line<<std::endl;
|
|
|
|
istringstream iss(line); |
|
|
|
string token; |
|
|
|
if (iss >> token && token == "v") {// 解析顶点
|
|
|
|
if (iss >> token && token == "v") |
|
|
|
{ // 解析顶点
|
|
|
|
float x, y, z; |
|
|
|
iss >> x >> y >> z; |
|
|
|
// std::cout<<"v:"<<x<<" "<<y<<" "<<z<<std::endl;
|
|
|
|
// std::cout<<"vertices_length"<<vertices.size()<<std::endl;
|
|
|
|
vertices.push_back(Vec3f(x, y, z)); |
|
|
|
} |
|
|
|
else if (token == "f") {// 解析面(这里只提取顶点索引)
|
|
|
|
else if (token == "f") |
|
|
|
{ // 解析面(这里只提取顶点索引)
|
|
|
|
// std::cout<<"enter_f"<<std::endl;
|
|
|
|
string v1_s, v2_s, v3_s; |
|
|
|
unsigned int v1, v2, v3; // 通常一个面由三个顶点定义
|
|
|
|
if (!(iss >> v1_s >> v2_s >> v3_s)) { |
|
|
|
if (!(iss >> v1_s >> v2_s >> v3_s)) |
|
|
|
{ |
|
|
|
// 处理非三角形面或其他错误情况
|
|
|
|
continue; |
|
|
|
} |
|
|
|
try { |
|
|
|
try |
|
|
|
{ |
|
|
|
v1 = extractAndConvert(v1_s) - 1; |
|
|
|
} catch (const std::exception& e) { |
|
|
|
} |
|
|
|
catch (const std::exception &e) |
|
|
|
{ |
|
|
|
std::cerr << "Error: " << e.what() << std::endl; |
|
|
|
} |
|
|
|
try { |
|
|
|
try |
|
|
|
{ |
|
|
|
v2 = extractAndConvert(v2_s) - 1; |
|
|
|
} catch (const std::exception& e) { |
|
|
|
} |
|
|
|
catch (const std::exception &e) |
|
|
|
{ |
|
|
|
std::cerr << "Error: " << e.what() << std::endl; |
|
|
|
} |
|
|
|
try { |
|
|
|
try |
|
|
|
{ |
|
|
|
v3 = extractAndConvert(v3_s) - 1; |
|
|
|
} catch (const std::exception& e) { |
|
|
|
} |
|
|
|
catch (const std::exception &e) |
|
|
|
{ |
|
|
|
std::cerr << "Error: " << e.what() << std::endl; |
|
|
|
} |
|
|
|
// std::cout<<"f:"<<v1<<" "<<v2<<" "<<v3<<std::endl;
|
|
|
@ -177,18 +195,19 @@ bool read_OBJ(const string& filename,vector<Vec3f>& vertices,vector<Vec3u>& indi |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
void produceXML(const char * xml,const char * connectorFile,string resultfile){ |
|
|
|
void produceXML(const char *xml, const char *connectorFile, string resultfile) |
|
|
|
{ |
|
|
|
ofstream ofs, oendpoint; |
|
|
|
ofs.open("result.txt", ios::out); |
|
|
|
string endfilename = "end" + resultfile; |
|
|
|
// oendpoint.open(endfilename.c_str(),ios::out);
|
|
|
|
|
|
|
|
|
|
|
|
readxml(xml, connectorFile); |
|
|
|
|
|
|
|
cout << "wire_pairs num: " << wire_pairs.size() << endl; |
|
|
|
|
|
|
|
for(int i=0;i<wire_pairs.size();i++){ |
|
|
|
for (int i = 0; i < wire_pairs.size(); i++) |
|
|
|
{ |
|
|
|
// if(i!=6)continue;
|
|
|
|
Bund &bd = wire_pairs[i]; |
|
|
|
// oendpoint<<bd.start.x<<" "<<bd.start.y<<" "<<bd.start.z<<endl;
|
|
|
@ -197,49 +216,55 @@ void produceXML(const char * xml,const char * connectorFile,string resultfile){ |
|
|
|
bd.start.isend = 1; |
|
|
|
bd.goal.isend = 1; |
|
|
|
|
|
|
|
if(inbox(bd.start)&&inbox(bd.goal)){ |
|
|
|
if (inbox(bd.start) && inbox(bd.goal)) |
|
|
|
{ |
|
|
|
|
|
|
|
cout << "yes" << endl; |
|
|
|
Path path = astar.search_pair(bd); |
|
|
|
for(int j=0;j<path.points.size();j++){ |
|
|
|
for (int j = 0; j < path.points.size(); j++) |
|
|
|
{ |
|
|
|
P pp = path.points[j]; |
|
|
|
ofs << pp.x << " " << pp.y << " " << pp.z << endl; |
|
|
|
cout << setprecision(10) << "(" << pp.x << "," << pp.y << "," << pp.z << ")"; |
|
|
|
if(j!=path.points.size()-1)cout<<"->"; |
|
|
|
if (j != path.points.size() - 1) |
|
|
|
cout << "->"; |
|
|
|
} |
|
|
|
cout << endl; |
|
|
|
cout << endl; |
|
|
|
ofs << "#" << endl; |
|
|
|
ofs << endl; |
|
|
|
|
|
|
|
|
|
|
|
branchTree.addPath(path); |
|
|
|
} |
|
|
|
else cout<<"no "<<i<<endl; |
|
|
|
|
|
|
|
else |
|
|
|
cout << "no " << i << endl; |
|
|
|
} |
|
|
|
|
|
|
|
branchTree.init(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void getAllFiles(string path, vector<string>& files) { |
|
|
|
void getAllFiles(string path, vector<string> &files) |
|
|
|
{ |
|
|
|
// 文件句柄
|
|
|
|
long long hFile = 0; |
|
|
|
// 文件信息
|
|
|
|
struct _finddata_t fileinfo; |
|
|
|
string p; |
|
|
|
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) { |
|
|
|
do { |
|
|
|
if ((fileinfo.attrib & _A_SUBDIR)) { //比较文件类型是否是文件夹
|
|
|
|
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) { |
|
|
|
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) |
|
|
|
{ |
|
|
|
do |
|
|
|
{ |
|
|
|
if ((fileinfo.attrib & _A_SUBDIR)) |
|
|
|
{ // 比较文件类型是否是文件夹
|
|
|
|
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) |
|
|
|
{ |
|
|
|
files.push_back(p.assign(path).append("\\").append(fileinfo.name)); |
|
|
|
// 递归搜索
|
|
|
|
getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
files.push_back(p.assign(path).append("\\").append(fileinfo.name)); |
|
|
|
} |
|
|
|
} while (_findnext(hFile, &fileinfo) == 0); // 寻找下一个,成功返回0,否则-1
|
|
|
@ -248,7 +273,8 @@ void getAllFiles(string path, vector<string>& files) { |
|
|
|
} |
|
|
|
|
|
|
|
// 初始化各个结构体
|
|
|
|
inline void init(){ |
|
|
|
inline void init() |
|
|
|
{ |
|
|
|
kdtree.build(); |
|
|
|
cout << "kdtree build Finish" << endl; |
|
|
|
|
|
|
@ -259,7 +285,8 @@ inline void init(){ |
|
|
|
cout << "basicChannel build Finish" << endl; |
|
|
|
basicChannel.createBranchPoint(); |
|
|
|
cout << "branchPoint create Finish" << endl; |
|
|
|
for(int i=1;i<=branchPointSet.branchPointNum;i++){ |
|
|
|
for (int i = 1; i <= branchPointSet.branchPointNum; i++) |
|
|
|
{ |
|
|
|
astar.add_branchPoint(branchPointSet.b[i]); |
|
|
|
} |
|
|
|
astar.init(); |
|
|
@ -267,13 +294,11 @@ inline void init(){ |
|
|
|
basicEdge.buildEdgeBetweenClipAndBranchPoint(); |
|
|
|
cout << "edge build Finish" << endl; |
|
|
|
cout << "INIT Finish" << endl; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int _tmain(int argc, char *argv[]) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
// test();
|
|
|
|
// return 0;
|
|
|
|
cout << "Start" << endl; |
|
|
@ -283,7 +308,8 @@ int _tmain(int argc, char * argv[]) |
|
|
|
// cin>>mode;
|
|
|
|
mode = argv[1]; |
|
|
|
|
|
|
|
if(mode=="generateCATIA"){ |
|
|
|
if (mode == "generateCATIA") |
|
|
|
{ |
|
|
|
// 该模式为基本模式,使用它来生成通道模型
|
|
|
|
string clipDoc, xmlDoc, connectorFile, stlFileName, outputFileName; |
|
|
|
cin >> clipDoc >> xmlDoc >> connectorFile >> stlFileName >> outputFileName; |
|
|
@ -303,7 +329,8 @@ int _tmain(int argc, char * argv[]) |
|
|
|
|
|
|
|
vector<string> filenames; |
|
|
|
getAllFiles(xmlDoc, filenames); |
|
|
|
for(int i=0;i<filenames.size();i++){ |
|
|
|
for (int i = 0; i < filenames.size(); i++) |
|
|
|
{ |
|
|
|
// if(i!=0)break;
|
|
|
|
string wirebh; |
|
|
|
stringstream ss; |
|
|
@ -318,12 +345,12 @@ int _tmain(int argc, char * argv[]) |
|
|
|
string resultname = outputFileName + "ALL.txt"; |
|
|
|
basicChannel.printBundle(resultname); |
|
|
|
|
|
|
|
|
|
|
|
time(&r2); |
|
|
|
cout << "Astar time " << (r2 - r1) << endl; |
|
|
|
cout << "ALL FINISH" << endl; |
|
|
|
} |
|
|
|
else if(mode=="createChannel"){ |
|
|
|
else if (mode == "createChannel") |
|
|
|
{ |
|
|
|
// 该模式用于根据卡箍相对位置生成近似通道
|
|
|
|
string clipDoc, stlFileName, outputFileName; |
|
|
|
cin >> clipDoc >> stlFileName >> outputFileName; |
|
|
@ -347,7 +374,8 @@ int _tmain(int argc, char * argv[]) |
|
|
|
cout << "ALL FINISH" << endl; |
|
|
|
} |
|
|
|
//----------------------mark----------------------
|
|
|
|
else if(mode=="createTinyroute"){ |
|
|
|
else if (mode == "createTinyroute") |
|
|
|
{ |
|
|
|
// 该模式为狭小空间模式,使用它来生成狭小空间的路径
|
|
|
|
string clipDoc, xmlDoc, connectorFile, OBJDoc, outputFileName; |
|
|
|
// cin>>clipDoc>>xmlDoc>>connectorFile>>OBJDoc>>outputFileName;
|
|
|
@ -360,7 +388,8 @@ int _tmain(int argc, char * argv[]) |
|
|
|
vector<string> OBJFilenames; |
|
|
|
getAllFiles(OBJDoc, OBJFilenames); |
|
|
|
cout << "OBJfilename.size()" << OBJFilenames.size() << endl; |
|
|
|
for(int i=0;i<OBJFilenames.size();i++){ |
|
|
|
for (int i = 0; i < OBJFilenames.size(); i++) |
|
|
|
{ |
|
|
|
if (read_OBJ(OBJFilenames[i], vertices, indices)) |
|
|
|
{ |
|
|
|
cout << "read OBJ File succeed" << endl; |
|
|
@ -374,9 +403,9 @@ int _tmain(int argc, char * argv[]) |
|
|
|
static BVH_intersection bvh(mesh); |
|
|
|
bool hit = bvh.intersectWithLineSegment(lineSegment); |
|
|
|
cout << "Line segment intersects with Mesh:" << hit << endl; |
|
|
|
|
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
cerr << "Failed to parse OBJ file." << endl; |
|
|
|
} |
|
|
|
} |
|
|
@ -397,7 +426,8 @@ int _tmain(int argc, char * argv[]) |
|
|
|
getAllFiles(xmlDoc, filenames); |
|
|
|
|
|
|
|
cout << "filename.size()" << filenames.size() << endl; |
|
|
|
for(int i=0;i<filenames.size();i++){ |
|
|
|
for (int i = 0; i < filenames.size(); i++) |
|
|
|
{ |
|
|
|
cout << "i:" << i << " " << filenames[i] << endl; |
|
|
|
// if(i!=0)break;
|
|
|
|
string wirebh; |
|
|
@ -413,16 +443,11 @@ int _tmain(int argc, char * argv[]) |
|
|
|
string resultname = outputFileName + "ALL.txt"; |
|
|
|
basicChannel.printBundle(resultname); |
|
|
|
|
|
|
|
|
|
|
|
time(&r2); |
|
|
|
cout << "Astar time " << (r2 - r1) << endl; |
|
|
|
cout << "ALL FINISH" << endl; |
|
|
|
} |
|
|
|
system("pause"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|