Browse Source

MacOS 环境迁移

divide_struct_def_imp
郑敬润 1 year ago
parent
commit
a02145adb8
  1. 28
      CMakeLists.txt
  2. 30
      include/Const.h
  3. 2
      include/Point.h
  4. 8
      include/stdafx.h
  5. 21
      parameters.txt
  6. 74
      src/xmlsql.cpp

28
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 <deps_dir>/share/<lib_name>/cmake/xxxConfig.cmake
find_package(tinyxml CONFIG REQUIRED)
# find_package(tinyxml CONFIG REQUIRED)
#------------REQUIRED_5.1.2 include .cmakeContentFetch------------#
# cmakeCMAKE_MODULE_PATH include 使
@ -72,10 +80,19 @@ add_executable(
# target_link_libraries(${PROJECT_NAME} PUBLIC {lib_name1} {lib_name1} ...)
# CMakeLists.txt
# target_include_directories <lib_name>/include <LIB_NAME>_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_debugdll/lib

30
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);
}
// 将d与0比较,返回正负
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 是不是在 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<P> vecp)
void printPath(const vector<P> vecp)
{
for (int j = 0; j < vecp.size(); j++)
{

2
include/Point.h

@ -101,7 +101,7 @@ struct P
}
// 设置方向
void setDir(P &dir)
void setDir(const P &dir)
{
dx = dir.x;
dy = dir.y;

8
include/stdafx.h

@ -14,9 +14,11 @@
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <atlstr.h>
#ifdef _WIN32
#include <tchar.h>
#include <windows.h>
#include <atlstr.h>
#endif
#include <ctype.h>
#include <iostream>
#include <tinyxml.h>

21
parameters.txt

@ -8,14 +8,25 @@ output
VScode CMake:
Win:
{
"cmake.debugConfig": {
"args": ["createTinyroute",
"..\\..\\data\\Tinyroute_test\\clip2",
"..\\..\\data\\Tinyroute_test\\wirexml",
"..\\..\\data\\Tinyroute_test\\connector.csv",
"..\\..\\data\\Tinyroute_test\\OBJ",
"output"]
}
}
UNIX:
{
"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"]
}
}

74
src/xmlsql.cpp

@ -8,11 +8,14 @@
#include <string>
#include <map>
#include <iomanip>
#include <io.h>
// #include <sys/io.h>
#include <dirent.h>
#include <vector>
#include <fstream>
#include <sstream>
#include <time.h>
#include <filesystem>
using namespace std;
map<P, string> 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<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)
// {
// 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<string> &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;

Loading…
Cancel
Save