修改建立快捷段逻辑,待测试
parent
1ad996c3eb
commit
09f2a32fc6
|
@ -54,17 +54,17 @@ BvhPtr BvhTree::subBvhTree(BvhTreeData initBound[], int l, int r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BvhTree::traverseBvhTree(BvhPtr now, std::vector<GLuint>& children, std::vector<QVector4D>& bounds) {
|
void BvhTree::traverseBvhTree(BvhPtr now, std::vector<GLuint>& children, std::vector<QVector4D>& bounds) {
|
||||||
if (now == NULL) return ;
|
|
||||||
children.push_back(now->getLeftSon(0));
|
children.push_back(now->getLeftSon(0));
|
||||||
children.push_back(now->getRightSon(1));
|
children.push_back(now->getRightSon(1));
|
||||||
bounds.push_back(now->bound);
|
bounds.push_back(now->bound);
|
||||||
|
if (now->isLeaf) return;
|
||||||
traverseBvhTree(now->child[0], children, bounds);
|
traverseBvhTree(now->child[0], children, bounds);
|
||||||
traverseBvhTree(now->child[1], children, bounds);
|
traverseBvhTree(now->child[1], children, bounds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BvhTree::getBvhArray(std::vector<GLuint>& children, std::vector<QVector4D>& bounds) {
|
void BvhTree::getBvhArray(std::vector<GLuint>& children, std::vector<QVector4D>& bounds) {
|
||||||
children.push_back(tot);
|
//children.push_back(tot);
|
||||||
children.push_back(0);
|
//children.push_back(0);
|
||||||
traverseBvhTree(root, children, bounds);
|
traverseBvhTree(root, children, bounds);
|
||||||
}
|
}
|
|
@ -115,7 +115,7 @@ int CubicBezier::judgeBoundIntersection(float xy, float l, float r, bool isY) {
|
||||||
if ((be - xy) * (en - xy) > eps) return 0;
|
if ((be - xy) * (en - xy) > eps) return 0;
|
||||||
float t = findTByValue(xy, isY);
|
float t = findTByValue(xy, isY);
|
||||||
float value = getLineValueByT(t, !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 1 + direction(isY);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "PaintingMesh.h"
|
#include "PaintingMesh.h"
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include "BvhTree.h"
|
#include "BvhTree.h"
|
||||||
|
#include "ShortCutTree.h"
|
||||||
|
|
||||||
Model::Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram)
|
Model::Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram)
|
||||||
: context(context)
|
: 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.8, 0.8, -0.7));
|
||||||
initBound.push_back(QVector4D(0.7, 0.7, 0.8, 0.8));*/
|
initBound.push_back(QVector4D(0.7, 0.7, 0.8, 0.8));*/
|
||||||
//bvhTree.buildBvhTree(initBound.data(), initBound.size());
|
//bvhTree.buildBvhTree(initBound.data(), initBound.size());
|
||||||
|
|
||||||
|
//vector<vector<point>> 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<vector<point>> 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<float> pointVector;
|
||||||
|
vector<GLuint> lineVector;
|
||||||
|
vector<BvhTreeData> bvhTreeData = shortCutTree.getPointLineAndBvhTree(pointVector, lineVector);
|
||||||
|
qDebug() << pointVector;
|
||||||
|
qDebug() << lineVector;
|
||||||
|
for (BvhTreeData data : bvhTreeData)
|
||||||
|
{
|
||||||
|
data.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
bvhTree.buildBvhTree(bvhTreeData.data(), bvhTreeData.size());
|
||||||
std::vector<GLuint> children;
|
std::vector<GLuint> children;
|
||||||
std::vector<QVector4D> bounds;
|
std::vector<QVector4D> bounds;
|
||||||
bvhTree.getBvhArray(children, bounds);
|
bvhTree.getBvhArray(children, bounds);
|
||||||
|
qDebug() << children;
|
||||||
|
qDebug() << bounds;
|
||||||
|
|
||||||
std::vector<GLuint> bvhChildren = {
|
std::vector<GLuint> 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<QVector4D> 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<GLuint> elementOffset = {
|
||||||
|
//element0
|
||||||
|
7, //elementBvhRoot
|
||||||
|
(GLuint)bounds.size(), //elementBvhLength
|
||||||
|
0, //pointsOffset
|
||||||
|
0, //linesOffset
|
||||||
|
};
|
||||||
|
std::vector<GLuint> elementIndex = lineVector;
|
||||||
|
std::vector<GLfloat> 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<GLuint> bvhChildren0 = {
|
||||||
//root
|
//root
|
||||||
1,2,
|
1,2,
|
||||||
3,4, 5,6,
|
3,4, 5,6,
|
||||||
|
@ -202,7 +259,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
||||||
encodeChild(0)/*line索引,element中第几条*/, 27
|
encodeChild(0)/*line索引,element中第几条*/, 27
|
||||||
|
|
||||||
};
|
};
|
||||||
std::vector<QVector4D> bvhBounds = {
|
std::vector<QVector4D> bvhBounds0 = {
|
||||||
//root
|
//root
|
||||||
QVector4D(-1,-1,1,1),
|
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.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
|
//elememt1
|
||||||
QVector4D(-1,-1,1,1)
|
QVector4D(-1,-1,1,1)
|
||||||
};
|
};
|
||||||
std::vector<GLuint> elementOffset = {
|
std::vector<GLuint> elementOffset0 = {
|
||||||
//element0
|
//element0
|
||||||
7, //elementBvhRoot
|
7, //elementBvhRoot
|
||||||
3, //elementBvhLength
|
3, //elementBvhLength
|
||||||
|
@ -226,7 +283,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
||||||
28, //linesOffset
|
28, //linesOffset
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<GLuint> elementIndex = {
|
std::vector<GLuint> elementIndex0 = {
|
||||||
//element0
|
//element0
|
||||||
//lines, 全部当作三阶贝塞尔, 每条线四个点索引
|
//lines, 全部当作三阶贝塞尔, 每条线四个点索引
|
||||||
0,1,1,2,
|
0,1,1,2,
|
||||||
|
@ -242,7 +299,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
||||||
0,1,1,2
|
0,1,1,2
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<GLfloat> elementData = {
|
std::vector<GLfloat> elementData0 = {
|
||||||
//element0
|
//element0
|
||||||
//points
|
//points
|
||||||
-0.2,1, -0.2,-0.2, 1,-0.2, -1,1, -1,-1, 1,-1, 1,1,
|
-0.2,1, -0.2,-0.2, 1,-0.2, -1,1, -1,-1, 1,-1, 1,1,
|
||||||
|
|
|
@ -736,11 +736,11 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, inout vec3 deb
|
||||||
{
|
{
|
||||||
if (leftChild >= elementBvhLength)
|
if (leftChild >= elementBvhLength)
|
||||||
{
|
{
|
||||||
debugBVH.g += 0.5;
|
debugBVH.r += 0.5;
|
||||||
|
|
||||||
uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y;
|
uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y;
|
||||||
// for(int i = 0; i<200;i++)
|
// for(int i = 0; i<200;i++)
|
||||||
if (elementData[styleIndex] == 0.) //Ãæ
|
if (elementData[styleIndex] == 0.||true) //Ãæ
|
||||||
{
|
{
|
||||||
uint contourIndex = leftChild - 0x80000000;
|
uint contourIndex = leftChild - 0x80000000;
|
||||||
|
|
||||||
|
@ -914,7 +914,7 @@ void main()
|
||||||
}
|
}
|
||||||
|
|
||||||
imageStore(gBaseColor, pixelLocation, vec4(color.rgb,1));
|
imageStore(gBaseColor, pixelLocation, vec4(color.rgb,1));
|
||||||
return;
|
//return;
|
||||||
if (color.a!=-1)
|
if (color.a!=-1)
|
||||||
imageStore(gBaseColor, pixelLocation, vec4(vec3(1, 1, 0),1));
|
imageStore(gBaseColor, pixelLocation, vec4(vec3(1, 1, 0),1));
|
||||||
else
|
else
|
||||||
|
|
|
@ -14,9 +14,10 @@ int ShortCutTree::getPointIndex(point now) {
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
++numPoint;
|
int res = numPoint;
|
||||||
pointMap.insert({ now, numPoint });
|
pointMap.insert({ now, numPoint });
|
||||||
return numPoint;
|
++numPoint;
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ bool ShortCutTree::isLineEqual(LineIndex& a, LineIndex& b) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortCutTree::Monotonization(vector<vLine>& inL, vector<LinePtr>& outL) {
|
void ShortCutTree::monotonization(vector<vLine>& inL, vector<LinePtr>& outL) {
|
||||||
for (vLine &l: inL) {
|
for (vLine &l: inL) {
|
||||||
LinePtr now;
|
LinePtr now;
|
||||||
switch(l.size()) {
|
switch(l.size()) {
|
||||||
|
@ -48,7 +49,6 @@ void ShortCutTree::generateShortCutSegement(ShortCutNode& now) {
|
||||||
for (int &index : now.lineSet) {
|
for (int &index : now.lineSet) {
|
||||||
int type = allLine[index]->judgeBoundIntersection(now.bound.z(), now.bound.y(), now.bound.w(), false), be, en;
|
int type = allLine[index]->judgeBoundIntersection(now.bound.z(), now.bound.y(), now.bound.w(), false), be, en;
|
||||||
if (type >= 2) {
|
if (type >= 2) {
|
||||||
numLine++;
|
|
||||||
v.push_back(numLine);
|
v.push_back(numLine);
|
||||||
if (type == 2) {
|
if (type == 2) {
|
||||||
p = allLine[index]->getEnd();
|
p = allLine[index]->getEnd();
|
||||||
|
@ -62,8 +62,19 @@ void ShortCutTree::generateShortCutSegement(ShortCutNode& now) {
|
||||||
lineIndexSet.push_back(be);
|
lineIndexSet.push_back(be);
|
||||||
lineIndexSet.push_back(en);
|
lineIndexSet.push_back(en);
|
||||||
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) {
|
for (int& index : v) {
|
||||||
now.lineSet.push_back(index);
|
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)
|
if (now.lineSet.empty() && now.windingIncrement == 0)
|
||||||
return false;
|
return false;
|
||||||
outTree.push_back(now);
|
outTree.push_back(now);
|
||||||
|
@ -199,13 +210,13 @@ void ShortCutTree::spliteToShortCutTree() {
|
||||||
|
|
||||||
void ShortCutTree::buildShortCutTree(vector<vLine>& lineSet) {
|
void ShortCutTree::buildShortCutTree(vector<vLine>& lineSet) {
|
||||||
init();
|
init();
|
||||||
Monotonization(lineSet, allLine);
|
monotonization(lineSet, allLine);
|
||||||
spliteToShortCutTree();
|
spliteToShortCutTree();
|
||||||
simplifyLineVector();
|
simplifyLineVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<BvhTreeData> ShortCutTree::getPointLineAndBvhTree(vector<float>& pointSet, vector<int>& lineSet) {
|
vector<BvhTreeData> ShortCutTree::getPointLineAndBvhTree(vector<float>& pointSet, vector<GLuint>& lineSet) {
|
||||||
vector<pair<int, point> > vp; vp.clear();
|
vector<pair<GLuint, point> > vp; vp.clear();
|
||||||
for (auto& now : pointMap) {
|
for (auto& now : pointMap) {
|
||||||
vp.push_back({ now.second , now.first});
|
vp.push_back({ now.second , now.first});
|
||||||
}
|
}
|
||||||
|
@ -213,25 +224,26 @@ vector<BvhTreeData> ShortCutTree::getPointLineAndBvhTree(vector<float>& pointSet
|
||||||
for (auto& now : vp) {
|
for (auto& now : vp) {
|
||||||
pointSet.push_back(now.second.x);
|
pointSet.push_back(now.second.x);
|
||||||
pointSet.push_back(now.second.y);
|
pointSet.push_back(now.second.y);
|
||||||
//now.second.show();
|
now.second.show();
|
||||||
//std::cout << '\n';
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
for (auto& now : lineIndexSet) {
|
for (auto& now : lineIndexSet) {
|
||||||
lineSet.push_back(now);
|
lineSet.push_back(now);
|
||||||
//std::cout << now << ' ';
|
std::cout << now << ' ';
|
||||||
}
|
}
|
||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
vector<BvhTreeData> v;
|
vector<BvhTreeData> v;
|
||||||
for (auto& now : outTree) {
|
for (auto& now : outTree) {
|
||||||
BvhTreeData oneData;
|
BvhTreeData oneData;
|
||||||
oneData.leftSon = lineSet.size();
|
oneData.leftSon = lineSet.size();
|
||||||
//std::cout << now.lineSet.size() << ' ';
|
oneData.bound = now.bound;
|
||||||
|
std::cout << now.lineSet.size() << ' ';
|
||||||
lineSet.push_back(now.lineSet.size());
|
lineSet.push_back(now.lineSet.size());
|
||||||
for (auto& index : now.lineSet) {
|
for (auto& index : now.lineSet) {
|
||||||
lineSet.push_back(index);
|
lineSet.push_back(index);
|
||||||
//std::cout << index << ' ';
|
std::cout << index << ' ';
|
||||||
}
|
}
|
||||||
//std::cout << '\n';
|
std::cout << '\n';
|
||||||
v.push_back(oneData);
|
v.push_back(oneData);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
|
|
@ -32,7 +32,7 @@ class ShortCutTree
|
||||||
private:
|
private:
|
||||||
vector<ShortCutNode> outTree;
|
vector<ShortCutNode> outTree;
|
||||||
vector<LinePtr> allLine;
|
vector<LinePtr> allLine;
|
||||||
int RequiredLineMi, numPoint, numLine;
|
int RequiredLineMin, numPoint, numLine;
|
||||||
map<point, int> pointMap;
|
map<point, int> pointMap;
|
||||||
vector<int> lineIndexSet;
|
vector<int> lineIndexSet;
|
||||||
|
|
||||||
|
@ -40,17 +40,18 @@ private:
|
||||||
void generateShortCutSegement(ShortCutNode& now);
|
void generateShortCutSegement(ShortCutNode& now);
|
||||||
bool handleShortCutNode(ShortCutNode& fa, ShortCutNode& now, float yValue, vector<ShortCutNode>& v, int& sumIncrement);
|
bool handleShortCutNode(ShortCutNode& fa, ShortCutNode& now, float yValue, vector<ShortCutNode>& v, int& sumIncrement);
|
||||||
void spliteToShortCutTree();
|
void spliteToShortCutTree();
|
||||||
static void Monotonization(vector<vLine>& inL, vector<LinePtr> &outL);
|
static void monotonization(vector<vLine>& inL, vector<LinePtr> &outL);
|
||||||
bool isLineEqual(LineIndex& a, LineIndex& b) const;
|
bool isLineEqual(LineIndex& a, LineIndex& b) const;
|
||||||
void simplifyLineVector();
|
void simplifyLineVector();
|
||||||
public:
|
public:
|
||||||
void init();
|
void init();
|
||||||
ShortCutTree(int lineMi = 3)
|
//lineMin最小线数目,即划分终止条件
|
||||||
:RequiredLineMi(lineMi), numPoint(0), numLine(0) {}
|
ShortCutTree(int lineMin = 3)
|
||||||
|
:RequiredLineMin(lineMin), numPoint(0), numLine(0) {}
|
||||||
// 传入一个vector<vector<point> > 作为所有输入的线
|
// 传入一个vector<vector<point> > 作为所有输入的线
|
||||||
void buildShortCutTree(vector<vLine>& lineSet);
|
void buildShortCutTree(vector<vLine>& lineSet);
|
||||||
// 获得点集合和线集合 返回输入BvhTree的数据集合
|
// 获得点集合和线集合 返回输入BvhTree的数据集合
|
||||||
vector<BvhTreeData> getPointLineAndBvhTree(vector<float> &pointSet, vector<int> &lineSet);
|
vector<BvhTreeData> getPointLineAndBvhTree(vector<float> &pointSet, vector<GLuint> &lineSet);
|
||||||
~ShortCutTree() {}
|
~ShortCutTree() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ int StraightLine::judgeBoundIntersection(float xy, float l, float r, bool isY) {
|
||||||
if (direction(isY)) {
|
if (direction(isY)) {
|
||||||
float t = findTByValue(xy, isY);
|
float t = findTByValue(xy, isY);
|
||||||
float value = getLineValueByT(t, !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 1 + direction(isY);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue