From 1813d42b006aea39d6625d852b0dc147b4dd20c8 Mon Sep 17 00:00:00 2001 From: yony Date: Fri, 31 May 2024 10:40:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8tinyxml2=20list:=20-=20Point?= =?UTF-8?q?=20-=20Geometry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 21 +++------- include/BranchPoint.h | 2 + include/Geometry.h | 96 ++++++++++++++----------------------------- include/Point.h | 14 +++---- include/ReadXML.h | 46 +++++++++++---------- include/stdafx.h | 6 +-- lib/Geometry.cpp | 38 +++++++++++++++++ src/xmlsql.cpp | 18 ++++---- 8 files changed, 120 insertions(+), 121 deletions(-) create mode 100644 lib/Geometry.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a2b834c..531e874 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ 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) + find_package(tinyxml2 CONFIG REQUIRED) elseif (UNIX) list(PREPEND CMAKE_PREFIX_PATH /home/yony/PROJECTS/Dependencies) # Linux find_package(tinyxml CONFIG REQUIRED) @@ -80,24 +80,17 @@ add_executable( # COMMAND ${CMAKE_COMMAND} -E copy_directory # ${CMAKE_SOURCE_DIR}/lib/$(IntDir)/WireRouting.dll $(outdir) # ) -file(COPY ${CMAKE_SOURCE_DIR}/lib/Debug/WireRouting.dll DESTINATION ${PROJECT_BINARY_DIR}/Debug) +# file(COPY ${CMAKE_SOURCE_DIR}/lib/Debug/WireRouting.dll DESTINATION ${PROJECT_BINARY_DIR}/Debug) #------------REQUIRED_5.2 将库链接到目标(通常是一个可执行文件),这个命令告诉 CMake 在构建目标时需要链接哪些库------------# # target_link_libraries(${PROJECT_NAME} PUBLIC {lib_name1} {lib_name1} ...) # 根据包管理工具在系统环境变量的情况,以及网络下载的包中CMakeLists.txt的编写情况 # 在这里链接库则可下方target_include_directories中可不添加 /include 或 _INCLUDE_DIRS -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() +target_link_libraries( + ${PROJECT_NAME} PUBLIC + tinyxml2::tinyxml2 +) target_link_libraries( ${PROJECT_NAME} PUBLIC @@ -114,8 +107,6 @@ target_include_directories( ${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR} # config.h.in 会生成配置在 build 目录 ${CMAKE_SOURCE_DIR}/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/BranchPoint.h b/include/BranchPoint.h index 7b356df..b38a9d4 100644 --- a/include/BranchPoint.h +++ b/include/BranchPoint.h @@ -7,6 +7,8 @@ #include #include #include +#include + using namespace std; // ֧ diff --git a/include/Geometry.h b/include/Geometry.h index 767e990..072ce06 100644 --- a/include/Geometry.h +++ b/include/Geometry.h @@ -1,5 +1,19 @@ #pragma once +#ifdef MY_LIB_SHARED_BUILD + #ifdef _WIN32 + #ifdef MY_LIB_EXPORTS + #define LIB_API __declspec(dllexport) + #else + #define LIB_API __declspec(dllimport) + #endif // MY_LIB_EXPORTS + #else + #define LIB_API + #endif // _WIN32 +#else + #define LIB_API +#endif // MY_LIB_SHARED_BUILD + #include #include #include @@ -47,37 +61,25 @@ public: return a; } - // Vec3 operator+(const Vec3 &other) const { - // return {a + other.a, b + other.b, c + other.c}; - // } Vec3 operator+(const Vec3 &other) const { return Vec3(a + other.a, b + other.b, c + other.c); - } // VS2008 + } - // Vec3 operator/(const float w) const { - // return {a / w, b / w, c / w}; - // } Vec3 operator/(const float w) const { return Vec3(a / w, b / w, c / w); - } // VS2008 + } - // Vec3 operator-(const Vec3 &other) const { - // return {a - other.a, b - other.b, c - other.c}; - // } Vec3 operator-(const Vec3 &other) const { return Vec3(a - other.a, b - other.b, c - other.c); - } // VS2008 + } - // Vec3 operator*(const float &w) const { - // return {a * w, b * w, c * w}; - // } Vec3 operator*(const float &w) const { return Vec3(a * w, b * w, c * w); - } // VS2008 + } float length() const { @@ -89,9 +91,6 @@ public: return *this / length(); } - // Vec3 cross(const Vec3 &other) const { - // return {b * other.c - c * other.b, c * other.a - a * other.c, a * other.b - b * other.a}; - // } Vec3 cross(const Vec3 &other) const { return Vec3(b * other.c - c * other.b, c * other.a - a * other.c, a * other.b - b * other.a); @@ -106,76 +105,43 @@ public: typedef Vec3 Vec3f; typedef Vec3 Vec3u; -class Mesh +extern "C" class LIB_API Mesh { public: std::vector vertices; std::vector indices; }; -class AABB +extern "C" class LIB_API AABB { public: Vec3f min, max; - /* - AABB() - :min(std::numeric_limits::max(), std::numeric_limits::max(),std::numeric_limits::max()), - max(std::numeric_limits::min(), std::numeric_limits::min(),std::numeric_limits::min()) - {} - */ - AABB() - { - min = Vec3f(1e5, 1e5, 1e5); - max = Vec3f(0, 0, 0); - } + AABB(); }; -class LineSegment +extern "C" class LIB_API LineSegment { public: Vec3f start; Vec3f end; + float length; + Vec3f dir; - // LineSegment(const Vec3f &s, const Vec3f &e) : start(s), end(e) { - // length = (end - start).length(); - // dir = (end - start).norm(); - // } - LineSegment(const Vec3f &s, const Vec3f &e) : start(s), end(e) - { - calculate(); - } + LineSegment(const Vec3f &s, const Vec3f &e); - float getLength() const - { - return length; - } + float getLength() const; - Vec3f getDir() const - { - return dir; - } + Vec3f getDir() const; - // private: - float length; - Vec3f dir; - void calculate() - { // VS2008 - Vec3f diff = end - start; // VS2008 - length = diff.length(); // VS2008 - dir = diff.norm(); // VS2008 - } // VS2008 + void calculate(); }; -struct FaceCenterComparator +extern "C" struct LIB_API FaceCenterComparator { const std::vector &faceCenters; // 滻 YourVectorType Ϊ int longAxis; - FaceCenterComparator(const std::vector ¢ers, int axis) - : faceCenters(centers), longAxis(axis) {} + FaceCenterComparator(const std::vector ¢ers, int axis); - bool operator()(const size_t &a, const size_t &b) const - { - return faceCenters[a][longAxis] < faceCenters[b][longAxis]; - } + bool operator()(const size_t &a, const size_t &b) const; }; \ No newline at end of file diff --git a/include/Point.h b/include/Point.h index 424b2df..2b81f57 100644 --- a/include/Point.h +++ b/include/Point.h @@ -3,15 +3,15 @@ #ifdef MY_LIB_SHARED_BUILD #ifdef _WIN32 #ifdef MY_LIB_EXPORTS - #define POINT_LIB_API __declspec(dllexport) + #define LIB_API __declspec(dllexport) #else - #define POINT_LIB_API __declspec(dllimport) + #define LIB_API __declspec(dllimport) #endif // MY_LIB_EXPORTS #else - #define POINT_LIB_API + #define LIB_API #endif // _WIN32 #else - #define POINT_LIB_API + #define LIB_API #endif // MY_LIB_SHARED_BUILD @@ -22,11 +22,11 @@ using namespace std; -extern "C" POINT_LIB_API const double eps = 1e-6; +extern "C" LIB_API const double eps = 1e-6; -extern "C" POINT_LIB_API bool Equal(double a, double b); +extern "C" LIB_API bool Equal(double a, double b); -extern "C" struct POINT_LIB_API P +extern "C" struct LIB_API P { double x, y, z; // double dx, dy, dz; // diff --git a/include/ReadXML.h b/include/ReadXML.h index f9f4237..1047ca1 100644 --- a/include/ReadXML.h +++ b/include/ReadXML.h @@ -7,7 +7,9 @@ #include #include #include + using namespace std; + string ini = "--"; // @@ -85,11 +87,11 @@ void init_readxml() cnt = 0; } -void producePin(TiXmlElement *pin) +void producePin(tinyxml2::XMLElement *pin) { pinidmap[pin->Attribute("id")] = pin->Attribute("name"); } -string safegave(TiXmlElement *pEle, const char *t) +string safegave(tinyxml2::XMLElement *pEle, const char *t) { if (pEle->Attribute(t) == NULL) return ini; @@ -103,7 +105,7 @@ string safegave(TiXmlElement *pEle, const char *t) } } -TiXmlElement *GetNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) +tinyxml2::XMLElement *GetNodePointerByName(tinyxml2::XMLElement *pRootEle, const char *strNodeName) { // if equal root node then return if (0 == strcmp(strNodeName, pRootEle->Value())) @@ -111,13 +113,13 @@ TiXmlElement *GetNodePointerByName(TiXmlElement *pRootEle, const char *strNodeNa return pRootEle; } - TiXmlElement *pEle = pRootEle; + tinyxml2::XMLElement *pEle = pRootEle; for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement()) { // recursive find sub node return node pointer if (0 != strcmp(pEle->Value(), strNodeName)) { - TiXmlElement *res = GetNodePointerByName(pEle, strNodeName); + tinyxml2::XMLElement *res = GetNodePointerByName(pEle, strNodeName); if (res != NULL) return res; } @@ -127,10 +129,10 @@ TiXmlElement *GetNodePointerByName(TiXmlElement *pRootEle, const char *strNodeNa return NULL; } -TiXmlElement *GetNextNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) +tinyxml2::XMLElement *GetNextNodePointerByName(tinyxml2::XMLElement *pRootEle, const char *strNodeName) { // if equal root node then return - TiXmlElement *pEle; + tinyxml2::XMLElement *pEle; for (pEle = pRootEle->NextSiblingElement(); pEle; pEle = pEle->NextSiblingElement()) { // recursive find sub node return node pointer @@ -139,7 +141,7 @@ TiXmlElement *GetNextNodePointerByName(TiXmlElement *pRootEle, const char *strNo } return NULL; } -void produceConnector(TiXmlElement *pcon) +void produceConnector(tinyxml2::XMLElement *pcon) { Connector con; con.id = pcon->Attribute("id"); @@ -154,8 +156,8 @@ void produceConnector(TiXmlElement *pcon) connectors[connectorNum] = con; - TiXmlElement *pEle; - TiXmlElement *p; + tinyxml2::XMLElement *pEle; + tinyxml2::XMLElement *p; for (pEle = pcon->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement()) { if (strcmp(pEle->Value(), "backshell") == 0) @@ -185,14 +187,14 @@ void produceConnector(TiXmlElement *pcon) } } -void produceWire(TiXmlElement *pwire) +void produceWire(tinyxml2::XMLElement *pwire) { Pin sn, en; - TiXmlElement *pconnection = GetNodePointerByName(pwire, "connection"); + tinyxml2::XMLElement *pconnection = GetNodePointerByName(pwire, "connection"); if (pconnection != NULL) { sn = pinmap[pconnection->Attribute("pinref")]; - TiXmlElement *pconnection2 = GetNextNodePointerByName(pconnection, "connection"); + tinyxml2::XMLElement *pconnection2 = GetNextNodePointerByName(pconnection, "connection"); if (pconnection2 != NULL) en = pinmap[pconnection2->Attribute("pinref")]; else @@ -242,7 +244,7 @@ void produceWire(TiXmlElement *pwire) wire_node[p] = bd; } } -void produce(TiXmlElement *pEle) +void produce(tinyxml2::XMLElement *pEle) { if (strcmp(pEle->Value(), "wire") == 0) produceWire(pEle); @@ -250,7 +252,7 @@ void produce(TiXmlElement *pEle) produceConnector(pEle); return; } -void ProduceNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) +void ProduceNodePointerByName(tinyxml2::XMLElement *pRootEle, const char *strNodeName) { // if equal root node then return if (0 == strcmp(strNodeName, pRootEle->Value())) @@ -259,7 +261,7 @@ void ProduceNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) return; } - TiXmlElement *pEle = pRootEle; + tinyxml2::XMLElement *pEle = pRootEle; for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement()) { // recursive find sub node return node pointer @@ -275,7 +277,7 @@ void ProduceNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) return; } -void readxml(const char *xml, const char *connectorFile) +void readxml(const string xml, const string connectorFile) { init_readxml(); ifstream infile; @@ -299,15 +301,17 @@ void readxml(const char *xml, const char *connectorFile) mp[fields[0]] = P(atof(fields[1].c_str()), atof(fields[2].c_str()), atof(fields[3].c_str())); } - TiXmlDocument *pDoc = new TiXmlDocument(xml); - if (!(pDoc->LoadFile())) + tinyxml2::XMLDocument pDoc; + tinyxml2::XMLError error = pDoc.LoadFile(xml.c_str()); + if (error != tinyxml2::XMLError::XML_SUCCESS) return; + // pDoc->Print(); // øԪأPersons // cout<<"connectivity"<RootElement(); - TiXmlElement *connectivity = GetNodePointerByName(RootElement, "connectivity"); + tinyxml2::XMLElement *RootElement = pDoc.RootElement(); + tinyxml2::XMLElement *connectivity = GetNodePointerByName(RootElement, "connectivity"); // cout<<(connectivity->Value())<Attribute("id")==NULL)< #include -#include +#include // #include diff --git a/lib/Geometry.cpp b/lib/Geometry.cpp new file mode 100644 index 0000000..9787108 --- /dev/null +++ b/lib/Geometry.cpp @@ -0,0 +1,38 @@ +// #include "stdafx.h" +#include "Geometry.h" + +AABB::AABB() +{ + min = Vec3f(1e5, 1e5, 1e5); + max = Vec3f(0, 0, 0); +} + +LineSegment::LineSegment(const Vec3f &s, const Vec3f &e) : start(s), end(e) +{ + calculate(); +} + +float LineSegment::getLength() const +{ + return length; +} + +Vec3f LineSegment::getDir() const +{ + return dir; +} + +void LineSegment::calculate() +{ + Vec3f diff = end - start; + length = diff.length(); + dir = diff.norm(); +} + +FaceCenterComparator::FaceCenterComparator(const std::vector ¢ers, int axis) + : faceCenters(centers), longAxis(axis) {} + +bool FaceCenterComparator::operator()(const size_t &a, const size_t &b) const +{ + return faceCenters[a][longAxis] < faceCenters[b][longAxis]; +} diff --git a/src/xmlsql.cpp b/src/xmlsql.cpp index afe4bef..ce1c29c 100644 --- a/src/xmlsql.cpp +++ b/src/xmlsql.cpp @@ -26,20 +26,20 @@ map pmp, clipName; struct Readexcel { vector slist; - TiXmlElement *GetNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) + tinyxml2::XMLElement *GetNodePointerByName(tinyxml2::XMLElement *pRootEle, const char *strNodeName) { // if equal root node then return if (0 == strcmp(strNodeName, pRootEle->Value())) { return pRootEle; } - TiXmlElement *pEle = pRootEle; + tinyxml2::XMLElement *pEle = pRootEle; for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement()) { // recursive find sub node return node pointer if (0 != strcmp(pEle->Value(), strNodeName)) { - TiXmlElement *res = GetNodePointerByName(pEle, strNodeName); + tinyxml2::XMLElement *res = GetNodePointerByName(pEle, strNodeName); if (res != NULL) return res; } @@ -52,20 +52,20 @@ struct Readexcel { slist.clear(); - TiXmlDocument *pDoc = new TiXmlDocument(); + tinyxml2::XMLDocument *pDoc = new tinyxml2::XMLDocument(); pDoc->LoadFile(xml.c_str()); - TiXmlElement *RootElement = pDoc->RootElement(); + tinyxml2::XMLElement *RootElement = pDoc->RootElement(); - TiXmlElement *row = GetNodePointerByName(RootElement, "Row"); + tinyxml2::XMLElement *row = GetNodePointerByName(RootElement, "Row"); - TiXmlElement *pEle; + tinyxml2::XMLElement *pEle; for (pEle = row; pEle; pEle = pEle->NextSiblingElement()) { // recursive find sub node return node pointer - TiXmlElement *cell; + tinyxml2::XMLElement *cell; string s[7]; int i = 0; for (cell = pEle->FirstChildElement(); cell; cell = cell->NextSiblingElement()) @@ -201,7 +201,7 @@ bool read_OBJ(const string &filename, vector &vertices, vector &in return true; } -void produceXML(const char *xml, const char *connectorFile, string resultfile) +void produceXML(const string xml, const string connectorFile, string resultfile) { ofstream ofs, oendpoint; ofs.open("result.txt", ios::out);