From 08bbebb034387e4b198ff4e6a5aca16ac00ab85f Mon Sep 17 00:00:00 2001 From: Xiaolong <714909217@qq.com> Date: Fri, 11 Oct 2024 14:19:10 +0800 Subject: [PATCH] Add Loader --- algoim/organizer/loader.hpp | 713 ++++++++++++++++++++++++++++++++++++ wxl/data.txt | 310 ++++++++++++++++ wxl/parser.py | 77 ++++ 3 files changed, 1100 insertions(+) create mode 100644 algoim/organizer/loader.hpp create mode 100644 wxl/data.txt create mode 100644 wxl/parser.py diff --git a/algoim/organizer/loader.hpp b/algoim/organizer/loader.hpp new file mode 100644 index 0000000..842bb62 --- /dev/null +++ b/algoim/organizer/loader.hpp @@ -0,0 +1,713 @@ +#pragma once +#include "organizer.hpp" +#include +#include "primitive.hpp" +#include + +class Vector3D +{ +public: + Vector3D() = default; + Vector3D(const double x, const double y, const double z) + { + this->m_x = x; + this->m_y = y; + this->m_z = z; + } + + double length() const + { + return std::sqrt(this->m_x * this->m_x + this->m_y * this->m_y + this->m_z * this->m_z); + } + + Vector3D operator/(const double scalar) const + { + if (scalar == 0) + { + throw std::runtime_error("Division by zero error."); + } + + return Vector3D( + this->m_x / scalar, + this->m_y / scalar, + this->m_z / scalar + ); + } + + Vector3D operator*(const double scalar) const + { + return Vector3D( + this->m_x * scalar, + this->m_y * scalar, + this->m_z * scalar + ); + } + + Vector3D cross(const Vector3D& other) const + { + return Vector3D( + this->m_y * other.m_z - this->m_z * other.m_y, + this->m_z * other.m_x - this->m_x * other.m_z, + this->m_x * other.m_y - this->m_y * other.m_x + ); + } + + double dot(const Vector3D& other) const + { + return this->m_x * other.m_x + this->m_y * other.m_y + this->m_z * other.m_z; + } + + algoim::uvector3 getUVector3Data() const + { + algoim::uvector3 node; + node(0) = this->m_x; + node(1) = this->m_y; + node(2) = this->m_z; + return node; + } + + double m_x, m_y, m_z; +}; + +class Direction3D : public Vector3D +{ +public: + Direction3D() = default; + Direction3D(const double x, const double y, const double z) + { + this->m_x = x; + this->m_y = y; + this->m_z = z; + + this->normalized(); + } + + Direction3D(const Vector3D& vector) + { + this->m_x = vector.m_x; + this->m_y = vector.m_y; + this->m_z = vector.m_z; + + this->normalized(); + } + + Direction3D cross(const Direction3D& other) const + { + return Direction3D( + this->m_y * other.m_z - this->m_z * other.m_y, + this->m_z * other.m_x - this->m_x * other.m_z, + this->m_x * other.m_y - this->m_y * other.m_x + ); + } + + double dot(const Direction3D& other) const + { + return this->m_x * other.m_x + this->m_y * other.m_y + this->m_z * other.m_z; + } + + void normalized() + { + double length = this->length(); + if (std::abs(length) < 1e-8) + { + throw std::runtime_error("Cannot normalize a zero-length vector."); + } + + this->m_x /= length; + this->m_y /= length, + this->m_z /= length; + } + + bool isParallel(const Direction3D& other) + { + auto cross = this->cross(other); + return std::abs(cross.length()) < 1e-8; + } + + Direction3D operator- () const + { + return Direction3D( + -this->m_x, + -this->m_y, + -this->m_z + ); + } +}; + +class Point3D : public Vector3D +{ +public: + Point3D() = default; + Point3D(const double x, const double y, const double z) + { + this->m_x = x; + this->m_y = y; + this->m_z = z; + } + + Vector3D operator- (const Point3D& other) const + { + return Vector3D( + this->m_x - other.m_x, + this->m_y - other.m_y, + this->m_z - other.m_z + ); + } + + Point3D operator- (const Direction3D& direction) const + { + return Point3D( + this->m_x - direction.m_x, + this->m_y - direction.m_y, + this->m_z - direction.m_z + ); + } + + Point3D operator- (const Vector3D& offset) const + { + return Point3D( + this->m_x - offset.m_x, + this->m_y - offset.m_y, + this->m_z - offset.m_z + ); + } + + Point3D operator+ (const Direction3D& direction) const + { + return Point3D( + this->m_x + direction.m_x, + this->m_y + direction.m_y, + this->m_z + direction.m_z + ); + } + + Point3D operator+ (const Vector3D& offset) const + { + return Point3D( + this->m_x + offset.m_x, + this->m_y + offset.m_y, + this->m_z + offset.m_z + ); + } + + double getDistance(const Point3D& other) const + { + return std::sqrt((other.m_x - this->m_x) * (other.m_x - this->m_x) + (other.m_y - this->m_y) * (other.m_y - this->m_y) + (other.m_z - this->m_z) * (other.m_z - this->m_z)); + } + + Point3D getMiddlePoint(const Point3D& other) const + { + return Point3D((this->m_x + other.m_x) / 2.0, (this->m_z + other.m_z) / 2.0, (this->m_z + other.m_z) / 2.0); + } +}; + +class Loader +{ +public: + /** + * @brief Compute the barycentric coordinates of polygon + * @param[in] points All points which define the polygon + * @return The barycentric coordinates + */ + Point3D computePolygonCentroid(const std::vector& points) const + { + double centroidX = 0, centroidY = 0, centroidZ = 0; + for (const auto& point : points) + { + centroidX += point.m_x; + centroidY += point.m_y; + centroidZ += point.m_z; + } + int n = points.size(); + return Point3D(centroidX / n, centroidY / n, centroidZ / n); + } + + /** + * @brief Create an empty blob tree + * @return The created empty blob tree + */ + static algoim::organizer::BlobTree createEmptyBlobTree() + { + algoim::organizer::BlobTree tree; + + algoim::organizer::Blob blob0; + blob0.isPrimitive = 1; + blob0.nodeOp = 0; + blob0.inOut = 0; + blob0.oneChildInOut = 0; + blob0.isLeft = 1; + blob0.ancestor = 2; + tree.structure.push_back(blob0); + + algoim::organizer::Blob blob1; + blob0.isPrimitive = 1; + blob0.nodeOp = 0; + blob0.inOut = 0; + blob0.oneChildInOut = 0; + blob0.isLeft = 0; + blob0.ancestor = 0; + tree.structure.push_back(blob1); + + algoim::organizer::Blob blob2; + blob0.isPrimitive = 0; + blob0.nodeOp = 3; // no set + blob0.inOut = 0; + blob0.oneChildInOut = 0; + blob0.isLeft = 0; + blob0.ancestor = 0; + tree.structure.push_back(blob2); + + tree.primitiveNodeIdx.push_back(0); + tree.primitiveNodeIdx.push_back(1); + + return tree; + } + + /** + * @brief Union two visible primitive node + * @param[in] rep1 The first visible primitive node + * @param[in] rep2 The second visible primitive node + * @return The unioned visible primitive + */ + static algoim::organizer::VisiblePrimitiveRep unionNode(const algoim::organizer::VisiblePrimitiveRep& rep1, const algoim::organizer::VisiblePrimitiveRep rep2) + { + auto tree = createEmptyBlobTree(); + tree.structure[2].nodeOp = 0; + + const std::vector reps = {rep1, rep2}; + std::vector minimalReps; + algoim::organizer::mergeSubtree2Leaf(tree, minimalReps, reps); + + algoim::organizer::VisiblePrimitiveRep result; + result.subBlobTree = tree; + for (auto& rep : minimalReps) + { + result.tensors.push_back(rep.tensor); + result.aabb.extend(rep.aabb); + } + + return result; + } + + /** + * @brief Intersect two visible primitive node + * @param[in] rep1 The first visible primitive node + * @param[in] rep2 The second visible primitive node + * @return The intersected visible primitive + */ + static algoim::organizer::VisiblePrimitiveRep intersectionNode(const algoim::organizer::VisiblePrimitiveRep& rep1, const algoim::organizer::VisiblePrimitiveRep rep2) + { + auto tree = createEmptyBlobTree(); + tree.structure[2].nodeOp = 1; + + const std::vector reps = {rep1, rep2}; + std::vector minimalReps; + algoim::organizer::mergeSubtree2Leaf(tree, minimalReps, reps); + + algoim::organizer::VisiblePrimitiveRep result; + result.subBlobTree = tree; + for (auto& rep : minimalReps) + { + result.tensors.push_back(rep.tensor); + result.aabb.extend(rep.aabb); + } + + return result; + } + + /** + * @brief Difference two visible primitive node + * @param[in] rep1 The first visible primitive node + * @param[in] rep2 The second visible primitive node + * @return The differenced visible primitive + */ + static algoim::organizer::VisiblePrimitiveRep differenceNode(const algoim::organizer::VisiblePrimitiveRep& rep1, const algoim::organizer::VisiblePrimitiveRep rep2) + { + auto tree = createEmptyBlobTree(); + tree.structure[2].nodeOp = 2; + + const std::vector reps = {rep1, rep2}; + std::vector minimalReps; + algoim::organizer::mergeSubtree2Leaf(tree, minimalReps, reps); + + algoim::organizer::VisiblePrimitiveRep result; + result.subBlobTree = tree; + for (auto& rep : minimalReps) + { + result.tensors.push_back(rep.tensor); + result.aabb.extend(rep.aabb); + } + + return result; + } + + /** + * @brief Create a polygonal column without top face and bottom face + * @param[in] points All the bottom point with counter clockwise + * @param[in] extusion The stretch direction + * @return The polygonal column + */ + algoim::organizer::VisiblePrimitiveRep createPolygonalColumnWithoutTopBottom(const std::vector& points, const Vector3D& extusion) + { + int pointNumber = points.size(); + + std::vector vertices; + std::vector indices; + std::vector indexInclusiveScan; + + /* All bottom point */ + for (int i = 0; i < pointNumber; i++) + { + vertices.push_back(points[i].getUVector3Data()); + } + /* All top point */ + for (int i = 0; i < pointNumber; i++) + { + vertices.push_back((points[i] + extusion).getUVector3Data()); + } + + /* Side face */ + int index = 0; + for (int i = 0; i < pointNumber; i++) + { + indices.push_back(i); + indices.push_back((i + 1) % pointNumber); + indices.push_back((i + 1) % pointNumber + pointNumber); + indices.push_back(i + pointNumber); + + indexInclusiveScan.push_back(index); + index += 4; + } + + algoim::organizer::MeshDesc polygonalColumn(vertices, indices, indexInclusiveScan); + algoim::organizer::VisiblePrimitiveRep result; + result.tensors.resize(2 + pointNumber, algoim::tensor3(nullptr, 3)); + std::vector*> temp; + algoim::algoimSparkAllocHeapVector(temp, result.tensors); + algoim::organizer::makeMesh(polygonalColumn, result); + + for (auto& pointer : temp) + { + this->m_allPointer.push_back(pointer); + } + + return result; + } + + /** + * @brief Create a cylinder column without top face and bottom face + * @param[in] origion The origion point of bottom circle of the cylinder + * @param[in] radius The radius of the cylinder + * @param[in] length The length of the cylinder + * @param[in] alignAxis The align axis of the cylinder + * @return The cylinder column + */ + algoim::organizer::VisiblePrimitiveRep createCylinderWithoutTopBottom(const Point3D& origion, const double radius, const double length, const int alignAxis) + { + algoim::organizer::CylinderDesc cylinderDesc(origion.getUVector3Data(), radius, length, alignAxis); + algoim::organizer::VisiblePrimitiveRep cylinder; + cylinder.tensors.resize(3, algoim::tensor3(nullptr, 3)); + std::vector*> temp; + algoim::algoim_spark_alloc(algoim::real, cylinder.tensors); + algoim::organizer::makeCylinder(cylinderDesc, cylinder); + + algoim::organizer::VisiblePrimitiveRep result; + result.tensors.resize(1, algoim::tensor3(nullptr, 3)); + std::vector*> resultTemp; + algoim::algoimSparkAllocHeapVector(temp, result.tensors); + this->m_allPointer.push_back(resultTemp[0]); + + result.tensors[0] = cylinder.tensors[0]; + result.aabb = cylinder.aabb; + result.subBlobTree.primitiveNodeIdx.push_back(0); + result.subBlobTree.structure.push_back(algoim::organizer::Blob{1, 2, 0, 0, 0, 0}); + + return result; + } + + /** + * @brief Create a half plane + * @param[in] basePoint The base point of the plane + * @param[in] normal The normal of the plane + * @return The half plane + */ + algoim::organizer::VisiblePrimitiveRep createHalfPlane(const Point3D& basePoint, const Direction3D& normal) + { + auto halfPlaneDesc = algoim::organizer::HalfPlaneDesc(basePoint.getUVector3Data(), normal.getUVector3Data()); + algoim::organizer::VisiblePrimitiveRep halfPlane; + halfPlane.tensors.resize(1, algoim::tensor3(nullptr, 3)); + std::vector*> temp; + algoim::algoim_spark_alloc(algoim::real, halfPlane.tensors); + algoim::organizer::makeHalfPlane(halfPlaneDesc , halfPlane); + this->m_allPointer.push_back(temp[0]); + + return halfPlane; + } + + /** + * @brief Add a extrude body to csg tree with only two points + * @param[in] points All the bottom point which define the base face + * @param[in] bulges All the bulge on each edge of the base face + * @param[in] extusion The Stretch direction and length + */ + void addExtrudeWithTwoPoint(const std::vector& points, const std::vector& bulges, const Vector3D& extusion) + { + + } + + /** + * @brief Add a extrude body to csg tree + * @param[in] points All the bottom point which define the base face + * @param[in] bulges All the bulge on each edge of the base face + * @param[in] extusion The Stretch direction and length + */ + void addExtrude(const std::vector& points, const std::vector& bulges, const Vector3D& extusion) + { + int pointNumber = points.size(); + assert(pointNumber >= 2); + if (pointNumber == 2) + { + addExtrudeWithTwoPoint(points, bulges, extusion); + return; + } + + /* Get base polygonal column */ + auto base = createPolygonalColumnWithoutTopBottom(points, extusion); + + auto normal = Direction3D(extusion); + for (int i = 0; i < points.size(); i++) + { + /* Get point and bulge data */ + auto bulge = bulges[i]; + if (std::abs(bulge) < 1e-8) + { + continue; + } + + auto& point1 = points[i]; + Point3D point2; + if (i + 1 == points.size()) + { + point2 = points[0]; + } + else + { + point2 = points[i + 1]; + } + + /* Compute the origion and radius */ + auto halfDistance = point1.getDistance(point2) / 2.0; + auto middlePoint = point1.getMiddlePoint(point2); + auto middleToOrigion = normal.cross(Direction3D(point2 - point1)); + + double sinHalfTheta = 2 * bulge / (1 + bulge * bulge); + double radius = halfDistance / sinHalfTheta; + double scalar = std::sqrt(radius * radius - halfDistance * halfDistance); + auto origion = middlePoint + middleToOrigion * scalar; + + /* Determine whether to merge or subtract */ + /* The operation is merge if flag is true, otherwise it is subtract */ + bool flag; + auto centroidPoint = computePolygonCentroid(points); + auto middleToCentroid = Direction3D(centroidPoint - middlePoint); + if (middleToCentroid.dot(middleToOrigion) > 0.0) + { + if (bulge > 0.0) + { + flag = true; + } + else + { + flag = false; + } + } + else + { + if (bulge > 0.0) + { + flag = false; + } + else + { + flag = true; + } + } + + /* Determine which axis is aligned */ + int alignAxis; + if (normal.isParallel(Direction3D(1, 0, 0))) + { + alignAxis = 0; + } + else if (normal.isParallel(Direction3D(0, 1, 0))) + { + alignAxis = 1; + } + else if (normal.isParallel(Direction3D(0, 0, 1))) + { + alignAxis = 2; + } + else + { + throw std::runtime_error("Non align axis cylinder."); + } + + /* Create the cylinder face */ + auto cylinder = createCylinderWithoutTopBottom(origion, radius, extusion.length(), alignAxis); + + + /* Perform union and difference operations on the basic prismatic faces */ + if (flag) + { + /* Union */ + /* cylinder - half plane */ + auto halfPlane = createHalfPlane(middlePoint, middleToOrigion); + auto subtraction = this->intersectionNode(cylinder, halfPlane); + + /* base + (cylinder - column) */ + base = this->unionNode(base, subtraction); + + } + else + { + /* difference */ + /* base - cylinder */ + base = this->differenceNode(base, cylinder); + } + + } + + auto halfPlane1 = createHalfPlane(points[0], -normal); + auto halfPlane2 = createHalfPlane(points[0] + extusion, normal); + base = this->unionNode(base, halfPlane1); + base = this->unionNode(base, halfPlane2); + + this->m_allVisible.push_back(base); + } + +private: + std::vector m_allVisible; + std::vector*> m_allPointer; +}; + +void test() +{ + Loader l; + + std::vector points; + std::vector bulges; + Vector3D extusion; + + points.clear(); + bulges.clear(); + points.push_back(Point3D{-32450.000001122418 ,-3.8391231093737305e-07 ,0.0000000000000000 }); + points.push_back(Point3D{32449.999998877582 ,-3.8392495305561452e-07 ,0.0000000000000000 }); + bulges.push_back(0.99999999999999989); + bulges.push_back(0.99999999999999989); + extusion = Vector3D{0.0000000000000000,0.0000000000000000,3300.0000000000000}; + l.addExtrude(points, bulges, extusion); + + points.clear(); + bulges.clear(); + points.push_back(Point3D{-32450.000001122418 ,-3.8391231093737305e-07 ,0.0000000000000000 }); + points.push_back(Point3D{32449.999998877582 ,-3.8392495305561452e-07 ,0.0000000000000000 }); + points.push_back(Point3D{33538.999998877582 ,-3.8392534654100421e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-33539.000001122418 ,-3.8391228016184551e-07 ,0.0000000000000000 }); + bulges.push_back(0.99999999999999989); + bulges.push_back(0.0000000000000000); + bulges.push_back(-0.99999999999999989); + bulges.push_back(0.0000000000000000); + extusion = Vector3D{0.0000000000000000,0.0000000000000000,3300.0000000000000}; + l.addExtrude(points, bulges, extusion); + + points.clear(); + bulges.clear(); + points.push_back(Point3D{-32450.000001122418 ,-3.8391231093737305e-07 ,0.0000000000000000 }); + points.push_back(Point3D{32449.999998877582 ,-3.8392495305561452e-07 ,0.0000000000000000 }); + points.push_back(Point3D{33538.999998877582 ,-3.8392534654100421e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-33539.000001122418 ,-3.8391228016184551e-07 ,0.0000000000000000 }); + bulges.push_back(0.99999999999999989); + bulges.push_back(0.0000000000000000); + bulges.push_back(-0.99999999999999989); + bulges.push_back(0.0000000000000000); + extusion = Vector3D{0.0000000000000000,0.0000000000000000,3300.0000000000000}; + l.addExtrude(points, bulges, extusion); + + points.clear(); + bulges.clear(); + points.push_back(Point3D{-32450.000001122418 ,-3.8391231093737305e-07 ,0.0000000000000000 }); + points.push_back(Point3D{32449.999998877582 ,-3.8392495305561452e-07 ,0.0000000000000000 }); + points.push_back(Point3D{33538.999998877582 ,-3.8392534654100421e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-33539.000001122418 ,-3.8391228016184551e-07 ,0.0000000000000000 }); + bulges.push_back(0.99999999999999989); + bulges.push_back(0.0000000000000000); + bulges.push_back(-0.99999999999999989); + bulges.push_back(0.0000000000000000); + extusion = Vector3D{0.0000000000000000,0.0000000000000000,3300.0000000000000}; + l.addExtrude(points, bulges, extusion); + + points.clear(); + bulges.clear(); + points.push_back(Point3D{-32450.000001122418 ,-3.8391231093737305e-07 ,0.0000000000000000 }); + points.push_back(Point3D{32449.999998877582 ,-3.8392495305561452e-07 ,0.0000000000000000 }); + points.push_back(Point3D{33538.999998877582 ,-3.8392534654100421e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-33539.000001122418 ,-3.8391228016184551e-07 ,0.0000000000000000 }); + bulges.push_back(0.99999999999999989); + bulges.push_back(0.0000000000000000); + bulges.push_back(-0.99999999999999989); + bulges.push_back(0.0000000000000000); + extusion = Vector3D{0.0000000000000000,0.0000000000000000,3300.0000000000000}; + l.addExtrude(points, bulges, extusion); + + points.clear(); + bulges.clear(); + points.push_back(Point3D{32449.999998877582 ,-3.8392495305561452e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-32450.000001122418 ,-3.8391231093737305e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-33539.000001122418 ,-3.8391191745198337e-07 ,0.0000000000000000 }); + points.push_back(Point3D{33538.999998877582 ,-3.8392498383114206e-07 ,0.0000000000000000 }); + bulges.push_back(0.99999999999999989); + bulges.push_back(0.0000000000000000); + bulges.push_back(-0.99999999999999989); + bulges.push_back(0.0000000000000000); + extusion = Vector3D{0.0000000000000000,0.0000000000000000,3300.0000000000000}; + l.addExtrude(points, bulges, extusion); + + points.clear(); + bulges.clear(); + points.push_back(Point3D{32449.999998877582 ,-3.8392495305561452e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-32450.000001122418 ,-3.8391231093737305e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-33539.000001122418 ,-3.8391191745198337e-07 ,0.0000000000000000 }); + points.push_back(Point3D{33538.999998877582 ,-3.8392498383114206e-07 ,0.0000000000000000 }); + bulges.push_back(0.99999999999999989); + bulges.push_back(0.0000000000000000); + bulges.push_back(-0.99999999999999989); + bulges.push_back(0.0000000000000000); + extusion = Vector3D{0.0000000000000000,0.0000000000000000,3300.0000000000000}; + l.addExtrude(points, bulges, extusion); + + points.clear(); + bulges.clear(); + points.push_back(Point3D{32449.999998877582 ,-3.8392495305561452e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-32450.000001122418 ,-3.8391231093737305e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-33539.000001122418 ,-3.8391191745198337e-07 ,0.0000000000000000 }); + points.push_back(Point3D{33538.999998877582 ,-3.8392498383114206e-07 ,0.0000000000000000 }); + bulges.push_back(0.99999999999999989); + bulges.push_back(0.0000000000000000); + bulges.push_back(-0.99999999999999989); + bulges.push_back(0.0000000000000000); + extusion = Vector3D{0.0000000000000000,0.0000000000000000,3300.0000000000000}; + l.addExtrude(points, bulges, extusion); + + points.clear(); + bulges.clear(); + points.push_back(Point3D{32449.999998877582 ,-3.8392495305561452e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-32450.000001122418 ,-3.8391231093737305e-07 ,0.0000000000000000 }); + points.push_back(Point3D{-33539.000001122418 ,-3.8391191745198337e-07 ,0.0000000000000000 }); + points.push_back(Point3D{33538.999998877582 ,-3.8392498383114206e-07 ,0.0000000000000000 }); + bulges.push_back(0.99999999999999989); + bulges.push_back(0.0000000000000000); + bulges.push_back(-0.99999999999999989); + bulges.push_back(0.0000000000000000); + extusion = Vector3D{0.0000000000000000,0.0000000000000000,3300.0000000000000}; + l.addExtrude(points, bulges, extusion); +} \ No newline at end of file diff --git a/wxl/data.txt b/wxl/data.txt new file mode 100644 index 0000000..05dfae1 --- /dev/null +++ b/wxl/data.txt @@ -0,0 +1,310 @@ +体1: +extrude(const CArray & polys,const PmGePoint3d &fixedPt,const PmGeVector3d &plgNormal,const PmGeVector3d &extusionVector); ++ (Vertexs).m_pData[0] {x=-32450.000001122418 y=-3.8391231093737305e-07 z=0.0000000000000000 } OdGePoint3d ++ (Vertexs).m_pData[1] {x=32449.999998877582 y=-3.8392495305561452e-07 z=0.0000000000000000 } OdGePoint3d + (bulge).m_pData[0] 0.99999999999999989 double + (bulge).m_pData[1] 0.99999999999999989 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=3300.0000000000000 } OdGeVector3d + +体2:同1 ++ (pt3ds).m_pData[0] {x=-32450.000001122418 y=-3.8391231093737305e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[1] {x=32449.999998877582 y=-3.8392495305561452e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[2] {x=33538.999998877582 y=-3.8392534654100421e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[3] {x=-33539.000001122418 y=-3.8391228016184551e-07 z=0.0000000000000000 } OdGePoint3d + (dBulges).m_pData[0] 0.99999999999999989 double + (dBulges).m_pData[1] 0.0000000000000000 double + (dBulges).m_pData[2] -0.99999999999999989 double + (dBulges).m_pData[3] 0.0000000000000000 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=3300.0000000000000 } OdGeVector3d + +体3:同1 ++ (pt3ds).m_pData[0] {x=-32450.000001122418 y=-3.8391231093737305e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[1] {x=32449.999998877582 y=-3.8392495305561452e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[2] {x=33538.999998877582 y=-3.8392534654100421e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[3] {x=-33539.000001122418 y=-3.8391228016184551e-07 z=0.0000000000000000 } OdGePoint3d + (dBulges).m_pData[0] 0.99999999999999989 double + (dBulges).m_pData[1] 0.0000000000000000 double + (dBulges).m_pData[2] -0.99999999999999989 double + (dBulges).m_pData[3] 0.0000000000000000 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=3300.0000000000000 } OdGeVector3d + +体4:createCone ++ topPt {x=-1.1224183253943920e-06 y=-3.8391322798592142e-07 z=0.0000000000000000 } OdGePoint3d ++ downPt {x=-1.1224183253943920e-06 y=-3.8391322798592142e-07 z=3300.0000000000000000 } OdGePoint3d + dRadius1 32450.000000000000 double + dRadius2 33539.000000000000 double + +体3被切割,以下为切割面的基点和矢量,保留矢量方向部分 ++ topPt {x=-1.1224183253943920e-06 y=-3.8391322798592142e-07 z=0.0000000000000000 } OdGePoint3d +kZAxis (体3被改变) + +体3和体4布尔差 + +体5:同1 ++ (pt3ds).m_pData[0] {x=-32450.000001122418 y=-3.8391231093737305e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[1] {x=32449.999998877582 y=-3.8392495305561452e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[2] {x=33538.999998877582 y=-3.8392534654100421e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[3] {x=-33539.000001122418 y=-3.8391228016184551e-07 z=0.0000000000000000 } OdGePoint3d + (dBulges).m_pData[0] 0.99999999999999989 double + (dBulges).m_pData[1] 0.0000000000000000 double + (dBulges).m_pData[2] -0.99999999999999989 double + (dBulges).m_pData[3] 0.0000000000000000 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=3300.0000000000000 } OdGeVector3d + +体5被切割,以下为切割面的基点和矢量,保留矢量方向部分 ++ topPt {x=-1.1224183253943920e-06 y=-3.8391322798592142e-07 z=3300.0000000000000000 } OdGePoint3d +kZAxis (体5被改变) + +体3和体5布尔并 + +体6:同1 ++ (pt3ds).m_pData[0] {x=-32450.000001122418 y=-3.8391231093737305e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[1] {x=32449.999998877582 y=-3.8392495305561452e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[2] {x=33538.999998877582 y=-3.8392534654100421e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[3] {x=-33539.000001122418 y=-3.8391228016184551e-07 z=0.0000000000000000 } OdGePoint3d + (dBulges).m_pData[0] 0.99999999999999989 double + (dBulges).m_pData[1] 0.0000000000000000 double + (dBulges).m_pData[2] -0.99999999999999989 double + (dBulges).m_pData[3] 0.0000000000000000 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=3300.0000000000000 } OdGeVector3d + +体6被切割,以下为切割面的基点和矢量,保留矢量方向部分 ++ topPt {x=-1.1224183253943920e-06 y=-3.8391322798592142e-07 z=3300.0000000000000000 } OdGePoint3d +kZAxis (体6被改变) + +体3和体6布尔并 + +体2和体3布尔差 + +体7:同1 ++ (pt3ds).m_pData[0] {x=32449.999998877582 y=-3.8392495305561452e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[1] {x=-32450.000001122418 y=-3.8391231093737305e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[2] {x=-33539.000001122418 y=-3.8391191745198337e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[3] {x=33538.999998877582 y=-3.8392498383114206e-07 z=0.0000000000000000 } OdGePoint3d + (dBulges).m_pData[0] 0.99999999999999989 double + (dBulges).m_pData[1] 0.0000000000000000 double + (dBulges).m_pData[2] -0.99999999999999989 double + (dBulges).m_pData[3] 0.0000000000000000 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=3300.0000000000000 } OdGeVector3d + +体8:同1 ++ (pt3ds).m_pData[0] {x=32449.999998877582 y=-3.8392495305561452e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[1] {x=-32450.000001122418 y=-3.8391231093737305e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[2] {x=-33539.000001122418 y=-3.8391191745198337e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[3] {x=33538.999998877582 y=-3.8392498383114206e-07 z=0.0000000000000000 } OdGePoint3d + (dBulges).m_pData[0] 0.99999999999999989 double + (dBulges).m_pData[1] 0.0000000000000000 double + (dBulges).m_pData[2] -0.99999999999999989 double + (dBulges).m_pData[3] 0.0000000000000000 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=3300.0000000000000 } OdGeVector3d + +体9:createCone ++ topPt {x=-1.1224183253943920e-06 y=-3.8392403600706615e-07 z=0.0000000000000000 } OdGePoint3d ++ downPt {x=-1.1224183253943920e-06 y=-3.8392403600706615e-07 z=3300.0000000000000000 } OdGePoint3d + dRadius1 32450.000000000000 double + dRadius2 33539.000000000000 double + +体8被切割,以下为切割面的基点和矢量,保留矢量方向部分 ++ topPt {x=-1.1224183253943920e-06 y=-3.8392403600706615e-07 z=3300.0000000000000000 } OdGePoint3d +kZAxis (体8被改变) + +体8和体9布尔差 + +体10:同1 ++ (pt3ds).m_pData[0] {x=32449.999998877582 y=-3.8392495305561452e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[1] {x=-32450.000001122418 y=-3.8391231093737305e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[2] {x=-33539.000001122418 y=-3.8391191745198337e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[3] {x=33538.999998877582 y=-3.8392498383114206e-07 z=0.0000000000000000 } OdGePoint3d + (dBulges).m_pData[0] 0.99999999999999989 double + (dBulges).m_pData[1] 0.0000000000000000 double + (dBulges).m_pData[2] -0.99999999999999989 double + (dBulges).m_pData[3] 0.0000000000000000 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=3300.0000000000000 } OdGeVector3d + +体10被切割,以下为切割面的基点和矢量,保留矢量方向部分 ++ topPt {x=-1.1224183253943920e-06 y=-3.8392403600706615e-07 z=3300.0000000000000000 } OdGePoint3d +kZAxis (体10被改变) + +体8和体10布尔并 + +体11:同1 ++ (pt3ds).m_pData[0] {x=32449.999998877582 y=-3.8392495305561452e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[1] {x=-32450.000001122418 y=-3.8391231093737305e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[2] {x=-33539.000001122418 y=-3.8391191745198337e-07 z=0.0000000000000000 } OdGePoint3d ++ (pt3ds).m_pData[3] {x=33538.999998877582 y=-3.8392498383114206e-07 z=0.0000000000000000 } OdGePoint3d + (dBulges).m_pData[0] 0.99999999999999989 double + (dBulges).m_pData[1] 0.0000000000000000 double + (dBulges).m_pData[2] -0.99999999999999989 double + (dBulges).m_pData[3] 0.0000000000000000 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=3300.0000000000000 } OdGeVector3d + +体11被切割,以下为切割面的基点和矢量,保留矢量方向部分 ++ topPt {x=-1.1224183253943920e-06 y=-3.8392403600706615e-07 z=3300.0000000000000000 } OdGePoint3d +kZAxis (体11被改变) + +体8和体11布尔并 + +体7和体8布尔差 + +体2和体7布尔并 + +体1和体2布尔并 +体1 Z轴偏移-3600 + +// 以上为回填土实体生成 +// +体11: ++ m_pt {x=-32050.000001122418 y=-3.8396319723688066e-07 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double ++ m_pt {x=32049.999998877582 y=-3.8387224776670337e-07 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=600.0000000000000 } OdGeVector3d + +体0: ++ m_pt {x=-11798.670446418590 y=5999.2409883221799 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double ++ m_pt {x=11801.337366082498 y=5999.2409883221590 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=600.0000000000000 } OdGeVector3d +体11和体0布尔差 +体11 Z轴偏移-3500 + + +体1和体11判交 + +体12: ++ m_pt {x=676.33403607269543 y=5999.2409883221790 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double ++ m_pt {x=-673.66711640879771 y=5999.2409883221790 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double ++ OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=600.0000000000000 } OdGeVector3d +体12 Z轴偏移-3500 + +体1和体12判交 +体11和体12布尔并保留体12 + +体13: ++ m_pt {x=-2398.6665401680511 y=5999.2409883221771 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double ++ m_pt {x=2401.3334598319489 y=5999.2409883221790 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double + + OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=600.0000000000000 } OdGeVector3d + +体14: ++ m_pt {x=-673.66711640879771 y=5999.2409883221790 z=0.0000000000000000 } OdGePoint3d + m_dBugle -0.99999999999999989 double ++ m_pt {x=676.33403607269543 y=5999.2409883221790 z=0.0000000000000000 } OdGePoint3d + m_dBugle -0.99999999999999989 double + +体13和体14布尔差 +体13 Z轴偏移-3500 + +体1和体13判交 +体11和体13布尔并保留体13 + +体1和体11布尔差 +获取体1 布尔前后的体积差和面积差 + +// +以下为一个循环 +定义空体 扣减体1 +{ + 循环体1: + + m_pt {x=-1000.0000000000000 y=1000.0000000000001 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.0000000000000000 double + + m_pt {x=-1000.0000000000000 y=-1000.0000000000000 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.0000000000000000 double + + m_pt {x=1000.0000000000000 y=-1000.0000000000000 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.0000000000000000 double + + m_pt {x=1000.0000000000000 y=1000.0000000000000 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.0000000000000000 double + + OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=600.0000000000000 } OdGeVector3d + 循环体1偏移+ 传入的X,Y,Z坐标值 已点的方式传入P + + 循环体2: BOX + +左下角点 minPt {x=P.X-1000 y=P.Y-1000 z=P.Z+0.0000000000005 } OdGePoint3d + 长 2000.0000000000036 宽 2000.0000000000036 高 600 + + + + 循环体3: + + m_pt {x=-32050.000001122418 y=-3.8396319723688066e-07 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double + + m_pt {x=32049.999998877582 y=-3.8387224776670337e-07 z=0.0000000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double + + OdGeVector3d {x=0.0000000000000000 y=0.0000000000000000 z=600.0000000000000 } OdGeVector3d + 循环体3 Z轴偏移-2900 + 循环体3和体2布尔交 + 循环体1和体3布尔交 + + 循环体1和体1判交 + 扣减体1和循环体1布尔并 +} + +以下为传入点: +{x=-21595.036456438422 y=-21609.173181957169 z=-2900.0000000000000 } +{x=-13505.711180076411 y=-13505.717935507526 z=-2900.0000000000000 } +{x=-2987.8729842756293 y=-18864.829751913778 z=-2900.0000000000000 } ++ InsertPt {x=2987.9196792985895 y=-18864.830728476278 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=13505.770265236089 y=-13505.722818320026 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=17018.254640236089 y=-8671.2047519137759 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=27220.281983986089 y=-13869.397623007526 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=21602.139405861089 y=-21602.103677695028 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=30173.926515236089 y=-4778.9669589450259 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=18864.887452736089 y=-2987.8275546481514 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-18864.815672263911 y=-2987.8811435153389 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-30173.856687888911 y=-4779.0570468356509 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-13869.422117576411 y=-27220.218912070028 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-11781.052000388911 y=-23121.591958945028 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-8671.2131332014105 y=-17018.193521445028 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-27220.229734763911 y=-13869.391763632526 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-17018.194578513911 y=-8671.1974276950259 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-30173.856687888911 y=4779.0965176174741 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-25630.485594138911 y=4059.4959316799741 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-18864.815672263911 y=2987.9134121487236 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-15863.798094138911 y=8083.0535488674741 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-27220.216062888911 y=13869.449056679974 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-21602.091062888911 y=21602.130697304972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-18349.393797263911 y=18349.437337929972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-13908.684812888911 y=13908.728353554974 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-9584.8552230451605 y=18811.339681679972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-13869.425047263911 y=27220.249837929972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-4779.0493148420355 y=30173.900228554972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=4779.0900894548395 y=30173.904134804972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=13869.430421486089 y=27220.275228554972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=9584.8806167985895 y=18811.363119179972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=13908.739015236089 y=13908.728353554974 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=18349.453858986089 y=18349.433431679972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=21602.147218361089 y=21602.130697304972 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=27220.268312111089 y=13869.454916054974 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=15863.852296486089 y=8083.0574551174741 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=18864.879640236089 y=2987.9153652737236 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=25630.543702736089 y=4059.4900723049741 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=30173.912843361089 y=4779.0896816799741 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=13869.432374611089 y=-27220.242349570028 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-4776.1108367703273 y=-30098.869302695028 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=4779.0915542985895 y=-30098.869302695028 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-23121.594969138911 y=-11781.033365195026 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=23121.637452736089 y=11781.092611367474 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=11781.053468361089 y=-23121.619302695028 z=-2900.0000000000000 } OdGePoint3d ++ InsertPt {x=-23121.583250388911 y=11781.089681679974 z=-2900.0000000000000 } OdGePoint3d + +体1和扣减体1布尔差 +获取体1 布尔前后的体积差和面积差 + + +// 3237 +体15:Ent1.bool +体1和体15布尔差 + +体16: ++ m_pt {x=-2503.6291053659488 y=5999.2409883221790 z=-3500.0000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double ++ m_pt {x=2501.2960250298465 y=5999.2409883221790 z=-3500.0000000000000 } OdGePoint3d + m_dBugle 0.99999999999999989 double ++ OdGeVector3d {x=-0.0000000000000000 y=-0.0000000000000000 z=-100.00000000000000 } OdGeVector3d +体1和体16布尔差 + +获取体1 布尔前后的体积差和面积差 + +// 3237 \ No newline at end of file diff --git a/wxl/parser.py b/wxl/parser.py new file mode 100644 index 0000000..2c5ea78 --- /dev/null +++ b/wxl/parser.py @@ -0,0 +1,77 @@ +import re + +class Parser: + + def __init__(self): + self.all = [] + + def parser(self): + + pattern1 = re.compile(r"m_pData\[\d+\]\t\{x=(.*?) y=(.*?) z=(.*?) \}\tOdGePoint3d\n", re.VERBOSE) + pattern2 = re.compile(r"m_pData\[\d+\]\t(.*?)\tdouble\n", re.VERBOSE) + pattern3 = re.compile(r"\{x=(.*?) y=(.*?) z=(.*?) \}") + end_pattern = re.compile(r"体(\d+)") + + with open("/home/xiaolong/HeteQuadrature/wxl/data.txt") as f: + points = [] + bulges = [] + extusion = [] + + for line in f: + + if line.find("体") != -1: + self.all.append([points, bulges, extusion]) + points = [] + bulges = [] + extusion = [] + continue + + match1 = pattern1.findall(line) + if match1 != []: + points.append(match1) + #print(match1) + continue + + match2 = pattern2.findall(line) + if match2 != []: + bulges.append(match2) + #print(match2) + continue + + match3 = pattern3.findall(line) + if match3 != []: + extusion = match3 + #print(match3) + continue + + def generate(self): + result = " Loader l;\n\n" + result += " std::vector points;\n" + result += " std::vector bulges;\n" + result += " Vector3D extusion;\n\n" + for value in self.all: + points, bulges, extusion = value + if points == []: + continue + + result += " points.clear();\n" + result += " bulges.clear();\n" + + for point in points: + result += " points.push_back(Point3D{" + point[0][0] + "," + point[0][1] + "," + point[0][2] +"});\n" + + + for bulge in bulges: + result += " bulges.push_back(" + bulge[0] + ");\n" + + result += " extusion = Vector3D{" + extusion[0][0] + "," + extusion[0][1] + "," + extusion[0][2] + "};\n" + result += " l.addExtrude(points, bulges, extusion);\n\n" + + print(result) + + + +p = Parser() +p.parser() +# print(p.all) +p.generate()