调试LineTree

dev-yyq
wuyize 2023-03-14 20:47:47 +08:00
parent 3f1421a1bd
commit 2cf45455ba
4 changed files with 28 additions and 23 deletions

View File

@ -1145,15 +1145,15 @@ bool drawElement(uint elementIndex, vec2 localUV, vec2 scale, out vec3 color, ou
p2Last = p[2];
}
// if(minDistance<=0.001)
// {
// hitElement = true;
// elementColor = vec4(0,0,0,1);
// if(debugBegin==1)
// elementColor = vec4(1,1,0,1);
// else if(debugBegin==2)
// elementColor = vec4(0,1,0,1);
// }
if(minDistance<=0.001)
{
hitElement = true;
elementColor = vec4(0,0,0,1);
if(debugBegin==1)
elementColor = vec4(1,1,0,1);
else if(debugBegin==2)
elementColor = vec4(0,1,0,1);
}
}
@ -1262,7 +1262,7 @@ void main()
imageStore(gBaseColor, pixelLocation, vec4(color.rgb,1));
imageStore(gMetallicRoughness, pixelLocation, vec4(metallicRoughness, 0, 1));
return;
//return;
if (/*color.a!=-1&&*/debugBVH==vec3(0))
{
//imageStore(gBaseColor, pixelLocation, vec4(vec3(1, 1, 0),1));

View File

@ -158,7 +158,7 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
{
//qDebug() << v.TexCoords.x << v.TexCoords.y;
v.TexCoords = (v.TexCoords - leftBottom) / (rightTop - leftBottom);
qDebug() << v.TexCoords.x << v.TexCoords.y;
//qDebug() << v.TexCoords.x << v.TexCoords.y;
}
mesh->vertices = vertices;
@ -254,21 +254,21 @@ GLuint Renderer::Model::loadPainting(std::string path)
vector<std::shared_ptr<ElementStyle>> style = {
std::make_shared<ElementStyleFillDemo>(),
std::make_shared<ElementStyleStrokeDemo>(0.02),
std::make_shared<ElementStyleStrokeRadialGradientDemo>(0.2)
std::make_shared<ElementStyleStrokeDemo>(0.06),
std::make_shared<ElementStyleStrokeRadialGradientDemo>(0.06)
};
vector<std::shared_ptr<Element>> element = {
std::make_shared<Element>(Element{ contours[0].first, style[0], contours[0].second}),
std::make_shared<Element>(Element{ contours[1].first, style[2], contours[1].second}),
std::make_shared<Element>(Element{ contours[2].first, style[0], contours[2].second}),
std::make_shared<Element>(Element{ contours[2].first, style[1], contours[2].second}),
};
Painting painting;
if (path == "0.json")
{
painting.addElement(*element[0], ElementTransform{ glm::vec2(-0.45,-0.45), glm::vec2(0.5,0.5) / 2.f, 0, glm::bvec2(false), 0 });
painting.addElement(*element[1], ElementTransform{ glm::vec2(-0.45, 0.45), glm::vec2(0.5,0.5) / 2.f, 0, glm::bvec2(false), 0 });
//painting.addElement(*element[1], ElementTransform{ glm::vec2(-0.45, 0.45), glm::vec2(0.5,0.5) / 2.f, 0, glm::bvec2(false), 0 });
painting.addElement(*element[2], ElementTransform{ glm::vec2(0.50,-0.45), glm::vec2(0.6,0.7) / 2.f, 0, glm::bvec2(false), 0 });
}
else

View File

@ -1,5 +1,6 @@
#include "Line.h"
#include <glm/detail/func_packing.hpp>
#include <qDebug>
using namespace Renderer;
using std::vector;
using std::pair;
@ -121,9 +122,10 @@ Point Line::getMinDistancePointOnSide(double xy, double l, double r, bool isY) {
swap(pMidr.x, pMidr.y);
}
double mid, midr;
//qDebug() << "Start" << xy << l << r << isY;
while (fabs(r - l) > eps) {
mid = (l + r) / 2;
midr = (mid + r) / 2;
mid = l + (r - l) / 3;
midr = r - (r - l) / 3;
if (isY) {
pMid.x = mid;
pMidr.x = midr;
@ -139,6 +141,7 @@ Point Line::getMinDistancePointOnSide(double xy, double l, double r, bool isY) {
r = midr;
}
}
//qDebug() << " End" << xy << l << r << isY;
Point ans = { xy, l };
if (isY) swap(ans.x, ans.y);
return ans;
@ -155,9 +158,9 @@ int Line::getPointSideOfLine(Point p) {
bool Line::judgeOneSideIntersectionWithWidth(double xy, double l, double r, bool isY, double width, int type) {
Point p = getMinDistancePointOnSide(xy, l, r, isY);
if (type && getPointSideOfLine(p) != type) {
return false;
}
//if (type && getPointSideOfLine(p) != type) {
// return false;
//}
return getMinDistanceFromPoint(p) <= width;
}

View File

@ -2,6 +2,7 @@
#include <queue>
#include <set>
#include <utility>
#include <qDebug>
using namespace Renderer;
using std::set;
@ -96,6 +97,7 @@ void LineTree::monotonization(vector<PointVector>& inLines, vector<std::shared_p
}
// 防止在首尾直线在与 X 轴平行上
int siz = outLines.size();
qWarning() << outLines.size();
if (!(outLines[0]->getBegin() == outLines[siz - 1]->getEnd()))
return;
if (isOffset) {
@ -141,12 +143,12 @@ bool LineTree::handleShortCutNode(LineTreeNode& fa, LineTreeNode& nowTreeNode, d
nowTreeNode.lineSet.push_back(lineIndex);
}
}
if (nowTreeNode.lineSet.size() <= requiredLineMin) {
if (nowTreeNode.lineSet.size() <= requiredLineMin || (nowTreeNode.bound.z()-nowTreeNode.bound.x()) *sqrt(2) <= lineWidth) {
if (nowTreeNode.lineSet.empty())
return false;
restOfTreeNodes.push_back(nowTreeNode);
nowTreeNode.divided = false;
v.push_back(nowTreeNode);
//v.push_back(nowTreeNode);
return false;
}
else {
@ -268,7 +270,7 @@ vector<BvhTreeData> LineTree::getPointLineAndBvhTree(vector<float>& resPoints, v
oneData.leftSon = resLines.size();
oneData.rightSon = 0;
oneData.bound = nowTreeNode.bound;
//std::cout << nowTreeNode.lineSet.size() << ' ';
qDebug() << nowTreeNode.bound << nowTreeNode.lineSet.size() << ' ';
resLines.push_back(nowTreeNode.lineSet.size());
for (auto& lineIndex : nowTreeNode.lineSet) {
resLines.push_back(lineIndex);