From dcb882fb86c83027a61b833cee7bae18ec90a12e Mon Sep 17 00:00:00 2001 From: "yang.yongquan" <3395816735@qq.com> Date: Tue, 11 Oct 2022 18:57:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=87=8F=E5=B0=91=E4=BA=86Sh?= =?UTF-8?q?ortCutSegment=E7=9A=84=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArchitectureColoredPainting/ShortCutTree.cpp | 39 ++++++++++++-------- ArchitectureColoredPainting/ShortCutTree.h | 2 + 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/ArchitectureColoredPainting/ShortCutTree.cpp b/ArchitectureColoredPainting/ShortCutTree.cpp index 4717a3e..03180c1 100644 --- a/ArchitectureColoredPainting/ShortCutTree.cpp +++ b/ArchitectureColoredPainting/ShortCutTree.cpp @@ -46,11 +46,10 @@ void ShortCutTree::monotonization(vector& inL, vector& out void ShortCutTree::generateShortCutsegmentement(ShortCutNode& nowTreeNode) { Point p = {0, 0}; - vector v; + set > pointSet; for (int & lineIndex : nowTreeNode.lineSet) { int type = allLine[lineIndex]->judgeBoundIntersection(nowTreeNode.bound.z(), nowTreeNode.bound.y(), nowTreeNode.bound.w(), false), lineIndexBegin, lineIndexEnd; if (type >= 2) { - v.push_back(numLine); if (type == 2) { p = allLine[lineIndex]->getEnd(); } @@ -59,25 +58,33 @@ void ShortCutTree::generateShortCutsegmentement(ShortCutNode& nowTreeNode) { } lineIndexBegin = getPointIndex({ p.x, nowTreeNode.bound.w() }); lineIndexEnd = getPointIndex(p); - lineIndexs.push_back(lineIndexBegin); - lineIndexs.push_back(lineIndexBegin); - lineIndexs.push_back(lineIndexEnd); - lineIndexs.push_back(lineIndexEnd); - numLine++; + auto iter = pointSet.find({ lineIndexBegin, lineIndexEnd }); + if (iter != pointSet.end()) { + pointSet.erase(iter); + } + else { + pointSet.insert({ lineIndexBegin, lineIndexEnd }); + } } - } + } if (nowTreeNode.windingIncrement != 0) { - v.push_back(numLine); int lineIndexBegin = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.y()}); int lineIndexEnd = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.w() }); - lineIndexs.push_back(lineIndexBegin); - lineIndexs.push_back(lineIndexBegin); - lineIndexs.push_back(lineIndexEnd); - lineIndexs.push_back(lineIndexEnd); - numLine++; + auto iter = pointSet.find({ lineIndexBegin, lineIndexEnd }); + if (iter != pointSet.end()) { + pointSet.erase(iter); + } + else { + pointSet.insert({ lineIndexBegin, lineIndexEnd }); + } } - for (int& lineIndex : v) { - nowTreeNode.lineSet.push_back(lineIndex); + for (auto& iter : pointSet) { + nowTreeNode.lineSet.push_back(numLine); + lineIndexs.push_back(iter.first); + lineIndexs.push_back(iter.first); + lineIndexs.push_back(iter.second); + lineIndexs.push_back(iter.second); + numLine++; } } diff --git a/ArchitectureColoredPainting/ShortCutTree.h b/ArchitectureColoredPainting/ShortCutTree.h index d9a2527..59ee04f 100644 --- a/ArchitectureColoredPainting/ShortCutTree.h +++ b/ArchitectureColoredPainting/ShortCutTree.h @@ -3,10 +3,12 @@ #include "StraightLine.h" #include "BvhTree.h" #include +#include using std::queue; using std::map; using std::for_each; +using std::set; struct ShortCutNode { typedef vector vectorPoint;