diff --git a/ArchitectureColoredPainting/BvhTree.cpp b/ArchitectureColoredPainting/BvhTree.cpp index 6ebce18..ca3c01d 100644 --- a/ArchitectureColoredPainting/BvhTree.cpp +++ b/ArchitectureColoredPainting/BvhTree.cpp @@ -54,17 +54,17 @@ BvhPtr BvhTree::subBvhTree(BvhTreeData initBound[], int l, int r) { } void BvhTree::traverseBvhTree(BvhPtr now, std::vector& children, std::vector& bounds) { - if (now == NULL) return ; children.push_back(now->getLeftSon(0)); children.push_back(now->getRightSon(1)); bounds.push_back(now->bound); + if (now->isLeaf) return; traverseBvhTree(now->child[0], children, bounds); traverseBvhTree(now->child[1], children, bounds); } void BvhTree::getBvhArray(std::vector& children, std::vector& bounds) { - children.push_back(tot); - children.push_back(0); + //children.push_back(tot); + //children.push_back(0); traverseBvhTree(root, children, bounds); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/CubicBezier.cpp b/ArchitectureColoredPainting/CubicBezier.cpp index 459f0ac..83c41ab 100644 --- a/ArchitectureColoredPainting/CubicBezier.cpp +++ b/ArchitectureColoredPainting/CubicBezier.cpp @@ -115,7 +115,7 @@ int CubicBezier::judgeBoundIntersection(float xy, float l, float r, bool isY) { if ((be - xy) * (en - xy) > eps) return 0; float t = findTByValue(xy, isY); float value = getLineValueByT(t, !isY); - if (l <= value && value <= r && fabs(t) > eps) { + if (l <= value && value <= r && fabs(t) > eps && fabs(1 - t) > eps) { return 1 + direction(isY); } return 0; diff --git a/ArchitectureColoredPainting/Model.cpp b/ArchitectureColoredPainting/Model.cpp index 9dda971..7cea585 100644 --- a/ArchitectureColoredPainting/Model.cpp +++ b/ArchitectureColoredPainting/Model.cpp @@ -7,6 +7,7 @@ #include "PaintingMesh.h" #include #include "BvhTree.h" +#include "ShortCutTree.h" Model::Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram) : context(context) @@ -186,11 +187,67 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod initBound.push_back(QVector4D(0.7, -0.8, 0.8, -0.7)); initBound.push_back(QVector4D(0.7, 0.7, 0.8, 0.8));*/ //bvhTree.buildBvhTree(initBound.data(), initBound.size()); + + //vector> lineSet = { {point{-1,-1}, point{1,-1}},{point{1,-1}, point{1,1}}, {point{1,1}, point{-1,1}},{point{-1,1}, point{-1,-1}} }; + vector> lineSet = { {point{-1,-1}, point{1,-1}},{point{1,-1}, point{1,1}}, {point{1,1}, point{-1,1}},{point{-1,1}, point{-1,-1}} }; + ShortCutTree shortCutTree; + shortCutTree.buildShortCutTree(lineSet); + vector pointVector; + vector lineVector; + vector bvhTreeData = shortCutTree.getPointLineAndBvhTree(pointVector, lineVector); + qDebug() << pointVector; + qDebug() << lineVector; + for (BvhTreeData data : bvhTreeData) + { + data.show(); + } + + bvhTree.buildBvhTree(bvhTreeData.data(), bvhTreeData.size()); std::vector children; std::vector bounds; bvhTree.getBvhArray(children, bounds); + qDebug() << children; + qDebug() << bounds; std::vector bvhChildren = { + //root + 1,2, + 3,4, 5,6, + encodeChild(0),0, encodeChild(0),GLuint(30. / 360 * 65536 + 1 * 65536) /*右儿子用来表示旋转角度和zIndex*/, encodeChild(0),0, encodeChild(0),0 + }; + std::vector bvhBounds = { + //root + QVector4D(-1,-1,1,1), + QVector4D(-0.9,-0.9,-0.1,0.9), QVector4D(0.1, -0.9,0.9,0.9), + QVector4D(-0.8,-0.8,-0.2,-0.1), QVector4D(-0.7,0.2,-0.2,0.7), QVector4D(0.2,-0.8,0.8,-0.1), QVector4D(0.2,0.1,0.8,0.8), + }; + bvhChildren.insert(bvhChildren.end(), children.begin(), children.end()); + bvhBounds.insert(bvhBounds.end(), bounds.begin(), bounds.end()); + + + std::vector elementOffset = { + //element0 + 7, //elementBvhRoot + (GLuint)bounds.size(), //elementBvhLength + 0, //pointsOffset + 0, //linesOffset + }; + std::vector elementIndex = lineVector; + std::vector elementData = { + //fillStyle + //fill + 0, + //fillType + 0, //单色 + //fillColorMetallicRoughness + 1,1,0, 0,0.8, + }; + elementData.insert(elementData.begin(), pointVector.begin(), pointVector.end()); + qDebug() << elementIndex; + qDebug() << elementData; + + + std::vector bvhChildren0 = { //root 1,2, 3,4, 5,6, @@ -202,7 +259,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod encodeChild(0)/*line索引,element中第几条*/, 27 }; - std::vector bvhBounds = { + std::vector bvhBounds0 = { //root QVector4D(-1,-1,1,1), QVector4D(-0.9,-0.9,-0.1,0.9), QVector4D(0.1, -0.9,0.9,0.9), @@ -213,7 +270,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod //elememt1 QVector4D(-1,-1,1,1) }; - std::vector elementOffset = { + std::vector elementOffset0 = { //element0 7, //elementBvhRoot 3, //elementBvhLength @@ -226,7 +283,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod 28, //linesOffset }; - std::vector elementIndex = { + std::vector elementIndex0 = { //element0 //lines, 全部当作三阶贝塞尔, 每条线四个点索引 0,1,1,2, @@ -242,7 +299,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod 0,1,1,2 }; - std::vector elementData = { + std::vector elementData0 = { //element0 //points -0.2,1, -0.2,-0.2, 1,-0.2, -1,1, -1,-1, 1,-1, 1,1, diff --git a/ArchitectureColoredPainting/Shaders/painting.comp b/ArchitectureColoredPainting/Shaders/painting.comp index 71db44c..36648bd 100644 --- a/ArchitectureColoredPainting/Shaders/painting.comp +++ b/ArchitectureColoredPainting/Shaders/painting.comp @@ -736,11 +736,11 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, inout vec3 deb { if (leftChild >= elementBvhLength) { - debugBVH.g += 0.5; + debugBVH.r += 0.5; uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y; // for(int i = 0; i<200;i++) - if (elementData[styleIndex] == 0.) //面 + if (elementData[styleIndex] == 0.||true) //面 { uint contourIndex = leftChild - 0x80000000; @@ -914,7 +914,7 @@ void main() } imageStore(gBaseColor, pixelLocation, vec4(color.rgb,1)); - return; + //return; if (color.a!=-1) imageStore(gBaseColor, pixelLocation, vec4(vec3(1, 1, 0),1)); else diff --git a/ArchitectureColoredPainting/ShortCutTree.cpp b/ArchitectureColoredPainting/ShortCutTree.cpp index 81b9165..84ee8fd 100644 --- a/ArchitectureColoredPainting/ShortCutTree.cpp +++ b/ArchitectureColoredPainting/ShortCutTree.cpp @@ -14,9 +14,10 @@ int ShortCutTree::getPointIndex(point now) { return iter->second; } else { - ++numPoint; + int res = numPoint; pointMap.insert({ now, numPoint }); - return numPoint; + ++numPoint; + return res; } } @@ -29,7 +30,7 @@ bool ShortCutTree::isLineEqual(LineIndex& a, LineIndex& b) const { return true; } -void ShortCutTree::Monotonization(vector& inL, vector& outL) { +void ShortCutTree::monotonization(vector& inL, vector& outL) { for (vLine &l: inL) { LinePtr now; switch(l.size()) { @@ -48,7 +49,6 @@ void ShortCutTree::generateShortCutSegement(ShortCutNode& now) { for (int &index : now.lineSet) { int type = allLine[index]->judgeBoundIntersection(now.bound.z(), now.bound.y(), now.bound.w(), false), be, en; if (type >= 2) { - numLine++; v.push_back(numLine); if (type == 2) { p = allLine[index]->getEnd(); @@ -62,8 +62,19 @@ void ShortCutTree::generateShortCutSegement(ShortCutNode& now) { lineIndexSet.push_back(be); lineIndexSet.push_back(en); lineIndexSet.push_back(en); + numLine++; } } + if (now.windingIncrement != 0) { + v.push_back(numLine); + int be = getPointIndex({now.bound.z(), now.bound.y()}); + int en = getPointIndex({ now.bound.z(), now.bound.w() }); + lineIndexSet.push_back(be); + lineIndexSet.push_back(be); + lineIndexSet.push_back(en); + lineIndexSet.push_back(en); + numLine++; + } for (int& index : v) { now.lineSet.push_back(index); } @@ -82,7 +93,7 @@ bool ShortCutTree::handleShortCutNode(ShortCutNode& fa, ShortCutNode& now, float } } - if (now.lineSet.size() <= RequiredLineMi) { + if (now.lineSet.size() <= RequiredLineMin) { if (now.lineSet.empty() && now.windingIncrement == 0) return false; outTree.push_back(now); @@ -199,13 +210,13 @@ void ShortCutTree::spliteToShortCutTree() { void ShortCutTree::buildShortCutTree(vector& lineSet) { init(); - Monotonization(lineSet, allLine); + monotonization(lineSet, allLine); spliteToShortCutTree(); simplifyLineVector(); } -vector ShortCutTree::getPointLineAndBvhTree(vector& pointSet, vector& lineSet) { - vector > vp; vp.clear(); +vector ShortCutTree::getPointLineAndBvhTree(vector& pointSet, vector& lineSet) { + vector > vp; vp.clear(); for (auto& now : pointMap) { vp.push_back({ now.second , now.first}); } @@ -213,25 +224,26 @@ vector ShortCutTree::getPointLineAndBvhTree(vector& pointSet for (auto& now : vp) { pointSet.push_back(now.second.x); pointSet.push_back(now.second.y); - //now.second.show(); - //std::cout << '\n'; + now.second.show(); + std::cout << '\n'; } for (auto& now : lineIndexSet) { lineSet.push_back(now); - //std::cout << now << ' '; + std::cout << now << ' '; } std::cout << '\n'; vector v; for (auto& now : outTree) { BvhTreeData oneData; oneData.leftSon = lineSet.size(); - //std::cout << now.lineSet.size() << ' '; + oneData.bound = now.bound; + std::cout << now.lineSet.size() << ' '; lineSet.push_back(now.lineSet.size()); for (auto& index : now.lineSet) { lineSet.push_back(index); - //std::cout << index << ' '; + std::cout << index << ' '; } - //std::cout << '\n'; + std::cout << '\n'; v.push_back(oneData); } return v; diff --git a/ArchitectureColoredPainting/ShortCutTree.h b/ArchitectureColoredPainting/ShortCutTree.h index d422ba0..3f92381 100644 --- a/ArchitectureColoredPainting/ShortCutTree.h +++ b/ArchitectureColoredPainting/ShortCutTree.h @@ -32,7 +32,7 @@ class ShortCutTree private: vector outTree; vector allLine; - int RequiredLineMi, numPoint, numLine; + int RequiredLineMin, numPoint, numLine; map pointMap; vector lineIndexSet; @@ -40,17 +40,18 @@ private: void generateShortCutSegement(ShortCutNode& now); bool handleShortCutNode(ShortCutNode& fa, ShortCutNode& now, float yValue, vector& v, int& sumIncrement); void spliteToShortCutTree(); - static void Monotonization(vector& inL, vector &outL); + static void monotonization(vector& inL, vector &outL); bool isLineEqual(LineIndex& a, LineIndex& b) const; void simplifyLineVector(); public: void init(); - ShortCutTree(int lineMi = 3) - :RequiredLineMi(lineMi), numPoint(0), numLine(0) {} + //lineMin最小线数目,即划分终止条件 + ShortCutTree(int lineMin = 3) + :RequiredLineMin(lineMin), numPoint(0), numLine(0) {} // 传入一个vector > 作为所有输入的线 void buildShortCutTree(vector& lineSet); // 获得点集合和线集合 返回输入BvhTree的数据集合 - vector getPointLineAndBvhTree(vector &pointSet, vector &lineSet); + vector getPointLineAndBvhTree(vector &pointSet, vector &lineSet); ~ShortCutTree() {} }; diff --git a/ArchitectureColoredPainting/StraightLine.cpp b/ArchitectureColoredPainting/StraightLine.cpp index 4bcbf3c..7de7438 100644 --- a/ArchitectureColoredPainting/StraightLine.cpp +++ b/ArchitectureColoredPainting/StraightLine.cpp @@ -35,7 +35,7 @@ int StraightLine::judgeBoundIntersection(float xy, float l, float r, bool isY) { if (direction(isY)) { float t = findTByValue(xy, isY); float value = getLineValueByT(t, !isY); - if (l <= value && value <= r && fabs(t) > eps) { + if (l <= value && value <= r && fabs(t) > eps && fabs(1-t) > eps) { return 1 + direction(isY); } return 0;