From 46af775a551dda5d24c4a2e9d733994da9bb838e Mon Sep 17 00:00:00 2001 From: gjj Date: Sun, 8 Sep 2024 21:05:52 +0800 Subject: [PATCH] blobtree --- algoim/organizer/blobtree.hpp | 54 +++++++++++++++++++++++++++++++++++ gjj/primitiveDebug.hpp | 18 +++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 algoim/organizer/blobtree.hpp diff --git a/algoim/organizer/blobtree.hpp b/algoim/organizer/blobtree.hpp new file mode 100644 index 0000000..7c89882 --- /dev/null +++ b/algoim/organizer/blobtree.hpp @@ -0,0 +1,54 @@ +#pragma once +#include + +namespace algoim::organizer +{ +// bitfield +struct Blob { + unsigned int isPrimitive : 1; // 1 for leaf + unsigned int nodeOp : 5; // 0 for intersection, 1 for union, 2 for difference + // unsigned int ignoreMod : 2; // 目前用不到 + unsigned int inOut : 2; // 0 for unknown, 1 for in, 2 for out + unsigned int isLeft : 1; + unsigned int ancestor : 23; +}; + +bool isPrimitive(Blob b) { return b.isPrimitive == 1; } + +unsigned int type(Blob b) { return 0; } + +bool isLeft(Blob b) { return b.isLeft == 1; } + +struct BlobTree { + std::vector structure; +}; + +void propagate(BlobTree &tree, unsigned int nodeIdx, bool in) +{ + const std::size_t rootIdx = tree.structure.size() - 1; + for (unsigned int nowIdx = nodeIdx; nowIdx != rootIdx; ++nodeIdx) { + unsigned int nextIdx = isLeft(tree.structure[nowIdx]) ? tree.structure[nowIdx].ancestor : nodeIdx + 1; + if (tree.structure[nowIdx].inOut == 2) { + // out + if (tree.structure[nextIdx].nodeOp == 0) { + // intersection + tree.structure[nextIdx].inOut = 2; + nextIdx = nowIdx; + continue; + } else if (tree.structure[nextIdx].nodeOp == 2 && isLeft(tree.structure[nowIdx])) { + // difference + tree.structure[nextIdx].inOut = 2; + nextIdx = nowIdx; + // continue; + } else { + return; + } + } else if (tree.structure[nowIdx].inOut == 1) { + // in + // TODO: + } + } + return; +} + +}; // namespace algoim::organizer diff --git a/gjj/primitiveDebug.hpp b/gjj/primitiveDebug.hpp index 8962329..030e3e4 100644 --- a/gjj/primitiveDebug.hpp +++ b/gjj/primitiveDebug.hpp @@ -24,6 +24,8 @@ #include "organizer/primitive.hpp" #include "organizer/organizer.hpp" +#include "organizer/blobtree.hpp" + using namespace algoim::Organizer; using namespace algoim; @@ -187,9 +189,23 @@ void testDeCasteljau() std::cout << "sign = " << sign << std::endl; } +void testBlob() +{ + orgzer::Blob blob = {5, 3, 4, 5, 6}; + + // std::cout << blob.isPrimitive << std::endl; + // std::cout << blob.nodeOp << std::endl; + // std::cout << blob.ignoreMod << std::endl; + // std::cout << blob.isLeft << std::endl; + // std::cout << blob.ancestor << std::endl; + std::cout << sizeof(blob) << std::endl; + std::cout << sizeof(int) << std::endl; +} + void testPrimitive() { // casePolyhedron1(); // casePolyhedronSphere(); - testDeCasteljau(); + // testDeCasteljau(); + testBlob(); } \ No newline at end of file