From bfbcd4aac8ad12f1f34c3bcc71274cd092a8860f Mon Sep 17 00:00:00 2001 From: wuyize Date: Tue, 11 Oct 2022 22:22:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E5=88=B011bed6c706?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Shaders/painting.comp | 2 +- ArchitectureColoredPainting/ShortCutTree.cpp | 39 +++++++++++-------- ArchitectureColoredPainting/ShortCutTree.h | 2 + 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/ArchitectureColoredPainting/Shaders/painting.comp b/ArchitectureColoredPainting/Shaders/painting.comp index e92c494..b27a2b3 100644 --- a/ArchitectureColoredPainting/Shaders/painting.comp +++ b/ArchitectureColoredPainting/Shaders/painting.comp @@ -875,7 +875,7 @@ void main() if (leftChild >= bvhLength) { uint zIndex = bvhChildren[index].y / 65535; - float angle = (bvhChildren[index].y / 65535.0 - zIndex) * 2 * PI; + float angle = (float(bvhChildren[index].y) / 65535.0 - zIndex) * 2 * PI; mat2 rotation = {{cos(angle), -sin(angle)}, {sin(angle), cos(angle)}}; vec2 localUV = uv - (bound.xy + bound.zw) / 2; 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;