diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e8c0da..824549f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,18 +32,26 @@ configure_file(config.h.in config.h) # 添加自定义依赖路径到 CMAKE_PREFIX_PATH (find_package config 模式搜索路径之一) if (APPLE) list(PREPEND CMAKE_PREFIX_PATH /Users/yony/CODE/Dependencies) # MacOS + # Settign pkg-config for tinyxml usage + set(ENV{PKG_CONFIG_PATH} /opt/homebrew/lib/pkgconfig/) + find_package(PkgConfig) + pkg_search_module(TINYXML REQUIRED tinyxml) + message(STATUS "=== TINYXML_LIBRARIES: ${TINYXML_LIBRARIES}") + message(STATUS "=== TINYXML_INCLUDE_DIRS: ${TINYXML_INCLUDE_DIRS}") elseif (WIN32) list(PREPEND CMAKE_PREFIX_PATH D:/SOURCE/Dependencies) # Windows set(CMAKE_TOOLCHAIN_FILE "D:\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake") # vcpkg include(${CMAKE_TOOLCHAIN_FILE}) + find_package(tinyxml CONFIG REQUIRED) elseif (UNIX) list(PREPEND CMAKE_PREFIX_PATH /home/yony/PROJECTS/Dependencies) # Linux + find_package(tinyxml CONFIG REQUIRED) endif() # 输出 find_package 系统路径和当前指定路径 message(STATUS "CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}") message(STATUS "Self added CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") # 指定 CONFIG 模式,查看 /share//cmake/xxxConfig.cmake 文件名决定查找包名 -find_package(tinyxml CONFIG REQUIRED) +# find_package(tinyxml CONFIG REQUIRED) #------------REQUIRED_5.1.2 include 执行.cmake中的ContentFetch模块来引入库------------# # 添加cmake目录到CMAKE_MODULE_PATH,以供 include 方法使用 @@ -72,10 +80,19 @@ add_executable( # target_link_libraries(${PROJECT_NAME} PUBLIC {lib_name1} {lib_name1} ...) # 根据包管理工具在系统环境变量的情况,以及网络下载的包中CMakeLists.txt的编写情况 # 在这里链接库则可下方target_include_directories中可不添加 /include 或 _INCLUDE_DIRS -target_link_libraries( - ${PROJECT_NAME} PUBLIC - unofficial-tinyxml::unofficial-tinyxml -) + +if (WIN32) + target_link_libraries( + ${PROJECT_NAME} PUBLIC + unofficial-tinyxml::unofficial-tinyxml + ) +else() + target_link_libraries( + ${PROJECT_NAME} PUBLIC + /opt/homebrew/Cellar/tinyxml/2.6.2/lib/libtinyxml.dylib + ) +endif() + #------------OPTIONAL_1.2 添加生成的config.h头文件所在目录------------# # 为目标添加了一个目录,源码中的 #include "config.h" 将会被解析为 ${PROJECT_BINARY_DIR}/config.h @@ -87,6 +104,7 @@ target_include_directories( ${PROJECT_BINARY_DIR} # config.h.in 会生成配置在 build 目录 include ${TINYXML_INCLUDE_DIR} # tinyxml库的头文件目录 + ${TINYXML_INCLUDE_DIRS} # pkg-config tinyxml dir ) # TODO: 针对 MSVC 解决生成位于msvc_19.29_cxx11_32_md_debug下dll/lib 无法链接到可执行文件的问题 \ No newline at end of file diff --git a/include/Const.h b/include/Const.h index 4163f96..a1db782 100644 --- a/include/Const.h +++ b/include/Const.h @@ -50,17 +50,17 @@ typedef P Point3; typedef P Vector3; // жyǷ[x-margin,z+margin]ķΧ -inline bool inmid(double x, double y, double z, double margin = MARGIN) +inline bool inmid(const double x, const double y, const double z, const double margin = MARGIN) { return y >= x - margin && y <= z + margin; } -inline bool inbox(P &p) +inline bool inbox(const P &p) { return inmid(MINX, p.x, MAXX) && inmid(MINY, p.y, MAXY) && inmid(MINZ, p.z, MAXZ); } // d0Ƚϣ -inline int dcmp(double d) +inline int dcmp(const double d) { if (d < -eps) return -1; @@ -71,7 +71,7 @@ inline int dcmp(double d) // ľ뺯 -inline double distan1(P &p1, P &p2) +inline double distan1(const P &p1, const P &p2) { double x = p1.x - p2.x, y = p1.y - p2.y, z = p1.z - p2.z; return sqrt(x * x + y * y + z * z); @@ -93,14 +93,14 @@ inline double distan2(P &p1,P &p2){ return sqrt(x*x+y*y+z*z)*penalty_par; } */ -inline double Dot(Vector3 &A, Vector3 &B) { return A.x * B.x + A.y * B.y + A.z * B.z; } -inline double Length(Vector3 &A) { return sqrt(Dot(A, A)); } -inline double Angle(Vector3 &A, Vector3 &B) { return acos(Dot(A, B) / Length(A) / Length(B)); } -inline double DistanceToPlane(Point3 &p, Point3 &p0, Vector3 &n) +inline double Dot(const Vector3 &A, const Vector3 &B) { return A.x * B.x + A.y * B.y + A.z * B.z; } +inline double Length(const Vector3 &A) { return sqrt(Dot(A, A)); } +inline double Angle(const Vector3 &A, const Vector3 &B) { return acos(Dot(A, B) / Length(A) / Length(B)); } +inline double DistanceToPlane(const Point3 &p, const Point3 &p0, const Vector3 &n) { return fabs(Dot(p - p0, n)); // ȡֵõ } -inline int ParallelorVertical(P &p1, P &p2) +inline int ParallelorVertical(const P &p1, const P &p2) { double angel = Angle(p1, p2); if (angel <= minAngle || angel >= pi - minAngle) @@ -109,23 +109,23 @@ inline int ParallelorVertical(P &p1, P &p2) return 2; return 0; } -inline Point3 GetPlaneProjection(Point3 &p, Point3 &p0, Vector3 &n) +inline Point3 GetPlaneProjection(const Point3 &p, const Point3 &p0, const Vector3 &n) { return p - n * Dot(p - p0, n); } -inline Point3 LinePlaneIntersection(Point3 &p1, Point3 &p2, Point3 &p0, Vector3 &n) +inline Point3 LinePlaneIntersection(const Point3 &p1, const Point3 &p2, const Point3 &p0, const Vector3 &n) { Vector3 v = p2 - p1; double t = (Dot(n, p0 - p1) / Dot(n, p2 - p1)); // жϷĸǷΪ 0 return p1 + v * t; // ߶Σж t Dz 0 1 ֮ } -inline Vector3 Cross(Vector3 A, Vector3 B) +inline Vector3 Cross(const Vector3 A, const Vector3 B) { return Vector3(A.y * B.z - A.z * B.y, A.z * B.x - A.x * B.z, A.x * B.y - A.y * B.x); } -inline double Area2(Point3 &A, Point3 &B, Point3 &C) { return Length(Cross(B - A, C - A)); } +inline double Area2(const Point3 &A, const Point3 &B, const Point3 &C) { return Length(Cross(B - A, C - A)); } -inline double get_penalty_par_distance(double len) +inline double get_penalty_par_distance(const double len) { static const double intersection_distance = 180; if (len <= intersection_distance) @@ -312,7 +312,7 @@ inline double distan(P A, P B) } // ӡ·Ϣ -void printPath(vector

vecp) +void printPath(const vector

vecp) { for (int j = 0; j < vecp.size(); j++) { diff --git a/include/Point.h b/include/Point.h index 65970a9..731136f 100644 --- a/include/Point.h +++ b/include/Point.h @@ -101,7 +101,7 @@ struct P } // ÷ - void setDir(P &dir) + void setDir(const P &dir) { dx = dir.x; dy = dir.y; diff --git a/include/stdafx.h b/include/stdafx.h index 0b2fbff..32361d6 100644 --- a/include/stdafx.h +++ b/include/stdafx.h @@ -14,9 +14,11 @@ #include "targetver.h" #include -#include -#include -#include +#ifdef _WIN32 + #include + #include + #include +#endif #include #include #include diff --git a/parameters.txt b/parameters.txt index 41c0ad4..6072f30 100644 --- a/parameters.txt +++ b/parameters.txt @@ -8,14 +8,25 @@ output VScode CMake: +Win: { "cmake.debugConfig": { - "args": ["createTinyroute", - "..\\..\\data\\clip2", - "..\\..\\data\\wirexml", - "..\\..\\data\\connector.csv", - "..\\..\\data\\OBJ", + "..\\..\\data\\Tinyroute_test\\clip2", + "..\\..\\data\\Tinyroute_test\\wirexml", + "..\\..\\data\\Tinyroute_test\\connector.csv", + "..\\..\\data\\Tinyroute_test\\OBJ", + "output"] + } +} +UNIX: +{ + "cmake.debugConfig": { + "args": ["createTinyroute", + "../data/Tinyroute_test/clip2", + "../data/Tinyroute_test/wirexml", + "../data/Tinyroute_test/connector.csv", + "../data/Tinyroute_test/OBJ", "output"] } } diff --git a/src/xmlsql.cpp b/src/xmlsql.cpp index b2bbf9c..5775c49 100644 --- a/src/xmlsql.cpp +++ b/src/xmlsql.cpp @@ -8,11 +8,14 @@ #include #include #include -#include +// #include +#include #include #include #include #include +#include + using namespace std; map pmp, clipName; @@ -247,35 +250,56 @@ void produceXML(const char *xml, const char *connectorFile, string resultfile) branchTree.init(); } +// VSMC io.h 支持下使用 +// void getAllFiles(string path, vector &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) +// { +// files.push_back(p.assign(path).append("\\").append(fileinfo.name)); +// // 递归搜索 +// getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files); +// } +// } +// else +// { +// files.push_back(p.assign(path).append("\\").append(fileinfo.name)); +// } +// } while (_findnext(hFile, &fileinfo) == 0); // 寻找下一个,成功返回0,否则-1 +// _findclose(hFile); +// } +// } + void getAllFiles(string path, vector &files) { - // 文件句柄 - long long hFile = 0; - // 文件信息 - struct _finddata_t fileinfo; - string p; - if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) + + struct dirent *dirp; + DIR *dp; + if((dp = opendir(path.c_str())) == NULL) + cout << "Can't open " << path << endl; + + while((dirp = readdir(dp)) != NULL) { - 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 - { - files.push_back(p.assign(path).append("\\").append(fileinfo.name)); - } - } while (_findnext(hFile, &fileinfo) == 0); // 寻找下一个,成功返回0,否则-1 - _findclose(hFile); + if ( strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 ) + continue; + files.push_back(std::__fs::filesystem::path(path).append(dirp->d_name)); } + + + closedir(dp); } + // 初始化各个结构体 inline void init() { @@ -300,7 +324,7 @@ inline void init() cout << "INIT Finish" << endl; } -int _tmain(int argc, char *argv[]) +int main(int argc, char *argv[]) { // test(); // return 0;