diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
index 360074c..bfce5ff 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
@@ -99,25 +99,26 @@
-
-
+
-
-
+
+
-
+
+
-
+
+
-
-
+
+
@@ -146,11 +147,11 @@
-
-
+
+
@@ -158,19 +159,19 @@
-
+
-
-
+
+
-
+
-
+
-
-
+
+
diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
index 87d0e67..be03bfa 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
@@ -35,6 +35,12 @@
{60515177-3da7-420f-8f5b-27c16bb2b77b}
+
+ {653d1291-0de8-4e0a-855d-7cfc755f7632}
+
+
+ {22909273-2b23-49fa-84ab-444cefb09656}
+
@@ -51,45 +57,24 @@
Source Files\Editor
-
- Source Files\Renderer
-
Source Files\Renderer
-
- Source Files\Renderer
-
-
- Source Files\Renderer
-
Source Files\Renderer
-
- Source Files\Renderer
-
Source Files\Renderer
Source Files\Renderer
-
- Source Files\Renderer
-
Source Files\Renderer
Source Files\Renderer
-
- Source Files\Renderer
-
-
- Source Files\Renderer
-
Source Files
@@ -114,6 +99,33 @@
Source Files
+
+ Source Files\Renderer\Painting
+
+
+ Source Files\Renderer\Painting
+
+
+ Source Files\Renderer\Painting
+
+
+ Source Files\Renderer\Painting
+
+
+ Source Files\Renderer\Painting
+
+
+ Source Files\Renderer\Painting
+
+
+ Source Files\Renderer\Painting
+
+
+ Source Files\Renderer\Painting
+
+
+ Source Files\Renderer\Painting
+
@@ -206,48 +218,54 @@
-
- Header Files\Renderer
-
Header Files\Renderer
-
- Header Files\Renderer
-
-
- Header Files\Renderer
-
Header Files\Renderer
Header Files\Renderer
-
- Header Files\Renderer
-
Header Files\Renderer
Header Files\Renderer
-
- Header Files\Renderer
-
Header Files\Renderer
-
- Header Files\Renderer
-
-
- Header Files\Renderer
-
Header Files
+
+ Header Files\Renderer\Painting
+
+
+ Header Files\Renderer\Painting
+
+
+ Header Files\Renderer\Painting
+
+
+ Header Files\Renderer\Painting
+
+
+ Header Files\Renderer\Painting
+
+
+ Header Files\Renderer\Painting
+
+
+ Header Files\Renderer\Painting
+
+
+ Header Files\Renderer\Painting
+
+
+ Header Files\Renderer\Painting
+
diff --git a/ArchitectureColoredPainting/MainWindow.ui b/ArchitectureColoredPainting/MainWindow.ui
index 2922f49..418a6af 100644
--- a/ArchitectureColoredPainting/MainWindow.ui
+++ b/ArchitectureColoredPainting/MainWindow.ui
@@ -94,7 +94,7 @@ QTabWidget::pane {
纹理编辑
-
+
场景渲染
@@ -109,7 +109,7 @@ QTabWidget::pane {
- RendererWidget
+ Renderer::RendererWidget
QWidget
Renderer/RendererWidget.h
diff --git a/ArchitectureColoredPainting/RendererWidget.ui b/ArchitectureColoredPainting/RendererWidget.ui
index 190a6ca..fdebb92 100644
--- a/ArchitectureColoredPainting/RendererWidget.ui
+++ b/ArchitectureColoredPainting/RendererWidget.ui
@@ -48,7 +48,7 @@
QLayout::SetDefaultConstraint
-
-
+
0
@@ -94,7 +94,7 @@
- RendererGLWidget
+ Renderer::RendererGLWidget
QOpenGLWidget
diff --git a/ArchitectureColoredPainting/Shaders/painting.comp b/ArchitectureColoredPainting/Shaders/painting.comp
index 5fb4ae9..e3f7cdf 100644
--- a/ArchitectureColoredPainting/Shaders/painting.comp
+++ b/ArchitectureColoredPainting/Shaders/painting.comp
@@ -251,6 +251,42 @@ int cubic_bezier_int_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3)
return n_ints;
}
+bool cubic_bezier_sign_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3)
+{
+ float cu = (-p0.y + 3. * p1.y - 3. * p2.y + p3.y);
+ float qu = (3. * p0.y - 6. * p1.y + 3. * p2.y);
+ float li = (-3. * p0.y + 3. * p1.y);
+ float co = p0.y - uv.y;
+
+ vec3 roots = vec3(1e38);
+ int n_roots = solve_cubic(vec3(co/cu,li/cu,qu/cu),roots);
+
+ int n_ints = 0;
+
+ for(int i=0;i<3;i++){
+ if(i < n_roots){
+ //if(roots[i] >= 0. && roots[i] <= 1.){
+ float x_pos = -p0.x + 3. * p1.x - 3. * p2.x + p3.x;
+ x_pos = x_pos * roots[i] + 3. * p0.x - 6. * p1.x + 3. * p2.x;
+ x_pos = x_pos * roots[i] + -3. * p0.x + 3. * p1.x;
+ x_pos = x_pos * roots[i] + p0.x;
+
+ if(x_pos < uv.x){
+ n_ints++;
+ }
+ //}
+ }
+ }
+
+ return n_ints%2==0;
+ // if(n_ints==0 || n_ints==2 || n_ints==4){
+ // return 1;
+ // }
+ // else{
+ // return 0;
+ // }
+}
+
const float eps = .000005;
const int halley_iterations = 8;
//lagrange positive real root upper bound
@@ -743,7 +779,7 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
// for(int i = 0; i<200;i++)
if (elementData[styleIndex] == 0.) //
{
- uint contourIndex = leftChild - 0x80000000;
+ uint contourIndex = linesOffset + leftChild - 0x80000000;
uint num_its = 0;
@@ -802,29 +838,69 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
else if (elementData[styleIndex] == 1) //
{
float strokeWidth = elementData[styleIndex+1];
- uint lineIndex = leftChild - 0x80000000;
- uint p0Index = elementIndexs[linesOffset + 4 * lineIndex];
- uint p1Index = elementIndexs[linesOffset + 4 * lineIndex + 1];
- uint p2Index = elementIndexs[linesOffset + 4 * lineIndex + 2];
- uint p3Index = elementIndexs[linesOffset + 4 * lineIndex + 3];
+ uint contourIndex = linesOffset + leftChild - 0x80000000;
+ float d = 1e38;
+ uint signTmp=0;
+ uint lineCountTmp=0;
+ uint lastPIndex = -1;
+ uint lineCount = elementIndexs[contourIndex];
+
+ for ( uint contourIterator = contourIndex + 1;contourIterator < contourIndex + 1 + lineCount; contourIterator++)
+ {
+ uint lineIndex = elementIndexs[contourIterator];
+ bool reverse = false;
+ if(lineIndex>=0x80000000)
+ {
+ reverse = true;
+ lineIndex -= 0x80000000;
+ }
+ uint pLocation = linesOffset + 4 * lineIndex;
+ uvec4 pxIndex = uvec4(pointsOffset)+2*uvec4(elementIndexs[pLocation], elementIndexs[pLocation+1], elementIndexs[pLocation+2], elementIndexs[pLocation+3]);
+ uvec4 pyIndex = uvec4(1)+pxIndex;
- vec2 p0 = vec2(elementData[pointsOffset + 2 * p0Index],
- elementData[pointsOffset + 2 * p0Index + 1]);
- vec2 p1 = vec2(elementData[pointsOffset + 2 * p1Index],
- elementData[pointsOffset + 2 * p1Index + 1]);
- vec2 p2 = vec2(elementData[pointsOffset + 2 * p2Index],
- elementData[pointsOffset + 2 * p2Index + 1]);
- vec2 p3 = vec2(elementData[pointsOffset + 2 * p3Index],
- elementData[pointsOffset + 2 * p3Index + 1]);
+ mat4x2 p = mat4x2(elementData[pxIndex[0]], elementData[pyIndex[0]],
+ elementData[pxIndex[1]], elementData[pyIndex[1]],
+ elementData[pxIndex[2]],elementData[pyIndex[2]],
+ elementData[pxIndex[3]], elementData[pyIndex[3]]);
+
+ if(lastPIndex!=pxIndex[0])
+ {
+ float lineType = elementData[styleIndex+4];
+ if(d<=0.001)
+ {
+ hitElement = true;
+ elementColor = vec4(0,0,0,1);
+ }
+ else if(d<=strokeWidth && signTmp==lineCountTmp)
+ {
+ hitElement = true;
+ elementColor = vec4(1);
+ if(elementData[styleIndex+3]==0)
+ {
+ elementColor = vec4(elementData[styleIndex+7],elementData[styleIndex+8],elementData[styleIndex+9],1);
+ metallicRoughness = vec2(elementData[styleIndex+10],elementData[styleIndex+11]);
+ }
+ }
+ d = 1e38;
+ signTmp=0;
+ lineCountTmp = 0;
+ }
+ lastPIndex = pxIndex[3];
+ lineCountTmp++;
+ float lineType = elementData[styleIndex+4];
+ d = min(d, cubic_bezier_dis(localUV, p[0], p[1], p[2], p[3], elementData[styleIndex+2]==0));
+ if(lineType==2 || cubic_bezier_sign_test(localUV, p[0], p[1], p[2], p[3])==(reverse? lineType==0: lineType==1))
+ ++signTmp;
+
+ }
float lineType = elementData[styleIndex+4];
- /*if(cubic_bezier_dis(localUV, p0, p1, p2, p3, true)<=0.001)
+ if(d<=0.001)
{
hitElement = true;
- elementColor = vec4(1);
+ elementColor = vec4(0,0,0,1);
}
- else */if(cubic_bezier_dis(localUV, p0, p1, p2, p3, elementData[styleIndex+2]==0)<=strokeWidth
- &&(lineType==2 ||cubic_bezier_int_test(localUV, p0, p1, p2, p3)==lineType))
+ else if(d<=strokeWidth && signTmp==lineCountTmp)
{
hitElement = true;
elementColor = vec4(1);
@@ -834,6 +910,45 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
metallicRoughness = vec2(elementData[styleIndex+10],elementData[styleIndex+11]);
}
}
+
+ // float strokeWidth = elementData[styleIndex+1];
+ // uint lineIndex = leftChild - 0x80000000;
+ // uint p0Index = elementIndexs[linesOffset + 4 * lineIndex];
+ // uint p1Index = elementIndexs[linesOffset + 4 * lineIndex + 1];
+ // uint p2Index = elementIndexs[linesOffset + 4 * lineIndex + 2];
+ // uint p3Index = elementIndexs[linesOffset + 4 * lineIndex + 3];
+
+ // vec2 p0 = vec2(elementData[pointsOffset + 2 * p0Index],
+ // elementData[pointsOffset + 2 * p0Index + 1]);
+ // vec2 p1 = vec2(elementData[pointsOffset + 2 * p1Index],
+ // elementData[pointsOffset + 2 * p1Index + 1]);
+ // vec2 p2 = vec2(elementData[pointsOffset + 2 * p2Index],
+ // elementData[pointsOffset + 2 * p2Index + 1]);
+ // vec2 p3 = vec2(elementData[pointsOffset + 2 * p3Index],
+ // elementData[pointsOffset + 2 * p3Index + 1]);
+
+ // // if(p0.y==p3.y)
+ // // {
+ // // p2.y-=0.0000001;
+ // // p3.y-=0.0000001;
+ // // }
+ // float lineType = elementData[styleIndex+4];
+ // if(cubic_bezier_dis(localUV, p0, p1, p2, p3, true)<=0.001)
+ // {
+ // hitElement = true;
+ // elementColor = vec4(0,0,0,1);
+ // }
+ // else if(cubic_bezier_dis(localUV, p0, p1, p2, p3, elementData[styleIndex+2]==0)<=strokeWidth
+ // &&(lineType==2 || cubic_bezier_sign_test(localUV, p0, p1, p2, p3)==(lineType==1)))
+ // {
+ // hitElement = true;
+ // elementColor = vec4(1);
+ // if(elementData[styleIndex+3]==0)
+ // {
+ // elementColor = vec4(elementData[styleIndex+7],elementData[styleIndex+8],elementData[styleIndex+9],1);
+ // metallicRoughness = vec2(elementData[styleIndex+10],elementData[styleIndex+11]);
+ // }
+ // }
}
elementBvhIndex = elementBvhLength;
diff --git a/ArchitectureColoredPainting/src/MainWindow.cpp b/ArchitectureColoredPainting/src/MainWindow.cpp
index d5c1af8..589b6c6 100644
--- a/ArchitectureColoredPainting/src/MainWindow.cpp
+++ b/ArchitectureColoredPainting/src/MainWindow.cpp
@@ -110,7 +110,7 @@ CentralWidget::CentralWidget(QWidget* parent) : QMainWindow(parent)
QObject::connect(navigationBarWidget->buttonGroup, &QButtonGroup::idClicked,
ui.tabWidget, &QTabWidget::setCurrentIndex);
QObject::connect(ui.tabWidget, &QTabWidget::currentChanged,
- ui.rendererWidget, &RendererWidget::currentTabChanged);
+ ui.rendererWidget, &Renderer::RendererWidget::currentTabChanged);
}
CentralWidget::~CentralWidget()
diff --git a/ArchitectureColoredPainting/src/Renderer/BvhTree.h b/ArchitectureColoredPainting/src/Renderer/BvhTree.h
deleted file mode 100644
index 6faafbc..0000000
--- a/ArchitectureColoredPainting/src/Renderer/BvhTree.h
+++ /dev/null
@@ -1,88 +0,0 @@
-#pragma once
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-using std::shared_ptr;
-
-struct BvhTreeData {
- QVector4D bound;
- GLuint leftSon, rightSon;
- void show() {
- printf("Bvh: (%lf, %lf) (%lf, %lf): %d %d\n",
- bound.x(), bound.y(), bound.z(), bound.w(),
- leftSon, rightSon);
- }
- BvhTreeData(QVector4D bound, GLuint leftSon, GLuint rightSon)
- : bound(bound), leftSon(leftSon), rightSon(rightSon) {}
- BvhTreeData()
- : leftSon(0), rightSon(0) {}
- ~BvhTreeData() {}
-};
-// BvhTree ڵ
-struct BvhNode {
- GLuint lab;
- bool isLeaf;
- QVector4D bound;
- shared_ptr child[2];
- static bool x_compare(BvhTreeData a, BvhTreeData b) {
- return a.bound.x() < b.bound.x();
- }
- static bool y_compare(BvhTreeData a, BvhTreeData b) {
- return a.bound.y() < b.bound.y();
- }
- GLuint getLeftSon(int k) {
- if (isLeaf) {
- return 0x80000000+child[0]->lab;
- }
- return child[0]->lab;
- }
- GLuint getRightSon(int k) {
- if (isLeaf) {
- return child[1]->lab;
- }
- return child[1]->lab;
- }
- BvhNode() {
- child[0] = child[1] = NULL;
- isLeaf = false;
- lab = 0;
- }
- int maximumBound() {
- return (std::fabs(bound.x() - bound.w()) < std::fabs(bound.y() - bound.z()));
- }
- ~BvhNode() {}
-};
-
-typedef std::shared_ptr BvhPtr;
-
-class BvhTree
-{
-
-private:
- GLuint tot;
- BvhPtr root;
- static QVector4D calcBound(BvhTreeData initBound[], int l, int r);
- static QVector4D Union(QVector4D a, QVector4D b);
- BvhPtr subBvhTree(BvhTreeData initBound[], int l, int r);
- void traverseBvhTree(BvhPtr now, std::vector& children, std::vector& bounds);
-public:
- BvhTree() {
- tot = 0;
- root = NULL;
- }
- // ݵײΧbvh
- void buildBvhTree(BvhTreeData initBound[], int len);
- // Bvh rootBvh֣ children 飬Χ vector
- void getBvhArray(std::vector& children, std::vector& bounds);
- // BvhTree нڵ
- GLuint getBvhNodeNum();
-};
-
diff --git a/ArchitectureColoredPainting/src/Renderer/Camera.cpp b/ArchitectureColoredPainting/src/Renderer/Camera.cpp
index 23703e6..4875435 100644
--- a/ArchitectureColoredPainting/src/Renderer/Camera.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Camera.cpp
@@ -1,5 +1,5 @@
#include "Camera.h"
-
+using namespace Renderer;
// constructor with vectors
diff --git a/ArchitectureColoredPainting/src/Renderer/Camera.h b/ArchitectureColoredPainting/src/Renderer/Camera.h
index a464c8f..cb29577 100644
--- a/ArchitectureColoredPainting/src/Renderer/Camera.h
+++ b/ArchitectureColoredPainting/src/Renderer/Camera.h
@@ -5,66 +5,69 @@
#include
#include
-// Default camera values
-const float YAW = -90.0f;
-const float PITCH = 0.0f;
-const float SPEED = 200.f;
-const float SENSITIVITY = 0.1f;
-const float ZOOM = 45.0f;
-
-// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
-enum Camera_Movement {
- FORWARD,
- BACKWARD,
- LEFT,
- RIGHT,
- UP,
- DOWN
-};
-
-class Camera
+namespace Renderer
{
-public:
- // camera Attributes
- QVector3D Position;
- QVector3D Front;
- QVector3D Up;
- QVector3D Right;
- QVector3D WorldUp;
- QVector3D PositionFront;
- QVector3D PositionRight;
- // euler Angles, Ƕ
- float Yaw;
- float Pitch;
- // camera options
- float MovementSpeed;
- float MouseSensitivity;
- float Zoom;
- float Ratio;
- float NearPlane = 10.f;
- float FarPlane = 5000.f;
+ // Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
+ enum Camera_Movement {
+ FORWARD,
+ BACKWARD,
+ LEFT,
+ RIGHT,
+ UP,
+ DOWN
+ };
- // constructor with vectors
- Camera(QVector3D position = QVector3D(0.0f, 0.0f, 0.0f), QVector3D up = QVector3D(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH);
+ class Camera
+ {
- // constructor with scalar values
- Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch);
+ public:
+ // Default camera values
+ static constexpr float YAW = -90.0f;
+ static constexpr float PITCH = 0.0f;
+ static constexpr float SPEED = 200.f;
+ static constexpr float SENSITIVITY = 0.1f;
+ static constexpr float ZOOM = 45.0f;
+ // camera Attributes
+ QVector3D Position;
+ QVector3D Front;
+ QVector3D Up;
+ QVector3D Right;
+ QVector3D WorldUp;
+ QVector3D PositionFront;
+ QVector3D PositionRight;
+ // euler Angles, Ƕ
+ float Yaw;
+ float Pitch;
+ // camera options
+ float MovementSpeed;
+ float MouseSensitivity;
+ float Zoom;
+ float Ratio;
+ float NearPlane = 10.f;
+ float FarPlane = 5000.f;
- // returns the view matrix calculated using Euler Angles and the LookAt Matrix
- QMatrix4x4 GetViewMatrix();
-
- // processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems)
- void ProcessKeyboard(Camera_Movement direction, float deltaTime);
+ // constructor with vectors
+ Camera(QVector3D position = QVector3D(0.0f, 0.0f, 0.0f), QVector3D up = QVector3D(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH);
- // processes input received from a mouse input system. Expects the offset value in both the x and y direction.
- void ProcessMouseMovement(float xoffset, float yoffset, GLboolean constrainPitch = true);
+ // constructor with scalar values
+ Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch);
- // processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
- void ProcessMouseScroll(float yoffset);
+ // returns the view matrix calculated using Euler Angles and the LookAt Matrix
+ QMatrix4x4 GetViewMatrix();
-private:
- // calculates the front vector from the Camera's (updated) Euler Angles
- void updateCameraVectors();
-};
+ // processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems)
+ void ProcessKeyboard(Camera_Movement direction, float deltaTime);
+ // processes input received from a mouse input system. Expects the offset value in both the x and y direction.
+ void ProcessMouseMovement(float xoffset, float yoffset, GLboolean constrainPitch = true);
+
+ // processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
+ void ProcessMouseScroll(float yoffset);
+
+ private:
+ // calculates the front vector from the Camera's (updated) Euler Angles
+ void updateCameraVectors();
+ };
+
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/CubicBezier.h b/ArchitectureColoredPainting/src/Renderer/CubicBezier.h
deleted file mode 100644
index d2691f7..0000000
--- a/ArchitectureColoredPainting/src/Renderer/CubicBezier.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-#include "Line.h"
-#include
-
-class CubicBezier : public Line
-{
- using Line::Line;
-private:
- static Point getPointByT(Point a, Point b, double t);
- static Point calculateControlPoint(Point a, Point b);
- static void findPointsOfDivison(vector &p, vector& res);
- void splitBezierCubic(double t, vector& res);
-public:
- virtual double findTByValue(double value, bool isY);
- virtual void monotonization(vector & res);
- virtual double getLineValueByT(double t, bool isY);
- virtual int judgeBoundIntersection(double xy, double l, double r, bool isY);
- void transformToCubic();
-};
-
diff --git a/ArchitectureColoredPainting/src/Renderer/CubicMonotonization.h b/ArchitectureColoredPainting/src/Renderer/CubicMonotonization.h
deleted file mode 100644
index 6531b27..0000000
--- a/ArchitectureColoredPainting/src/Renderer/CubicMonotonization.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#include
-#include
-#include
-#pragma once
-using std::pair;
-using std::vector;
-using std::min;
-using std::max;
-using std::sort;
-class CubicMonotonization
-{
-typedef pair point;
-typedef vector Line;
-private:
- static const double eps;
- point getPointByT(point a, point b, double t) const;
- void findPointsOfDivison(vector p, vector &res);
- double getBezierPoint(vector &p, double t) const;
- void splitBezierCubic(Line& p, point mid, double t, vector &res);
-public:
- // p Ϊ˵㡢Ƶ㡢Ƶ㡢˵㣬 res ΪеΪ0ĵ
- void getPointsOfDivision(Line p, vector &res);
-};
-
diff --git a/ArchitectureColoredPainting/src/Renderer/Drawable.h b/ArchitectureColoredPainting/src/Renderer/Drawable.h
index 583cf17..0e1f8ff 100644
--- a/ArchitectureColoredPainting/src/Renderer/Drawable.h
+++ b/ArchitectureColoredPainting/src/Renderer/Drawable.h
@@ -1,8 +1,10 @@
#pragma once
-class Drawable
+namespace Renderer
{
-public:
- virtual void draw() = 0;
- virtual void drawShadow() = 0;
-};
-
+ class Drawable
+ {
+ public:
+ virtual void draw() = 0;
+ virtual void drawShadow() = 0;
+ };
+}
diff --git a/ArchitectureColoredPainting/src/Renderer/Light.cpp b/ArchitectureColoredPainting/src/Renderer/Light.cpp
index a0a75ba..3bdd35f 100644
--- a/ArchitectureColoredPainting/src/Renderer/Light.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Light.cpp
@@ -1,6 +1,6 @@
#include "Light.h"
#include
-
+using namespace Renderer;
Light::Light(Camera* camera)
: camera(camera)
//, shadowCascadeLevels{ camera->FarPlane / 25.0f, camera->FarPlane / 12.0f, camera->FarPlane / 6.0f, camera->FarPlane / 3.0f }
diff --git a/ArchitectureColoredPainting/src/Renderer/Light.h b/ArchitectureColoredPainting/src/Renderer/Light.h
index 12ffbc2..2af104b 100644
--- a/ArchitectureColoredPainting/src/Renderer/Light.h
+++ b/ArchitectureColoredPainting/src/Renderer/Light.h
@@ -9,21 +9,24 @@
#include "Camera.h"
#include "Model.h"
-class Light
+namespace Renderer
{
-public:
- QVector3D lightDirection = QVector3D(0.2, 4, 1).normalized();
- std::vector shadowCascadeLevels;
- float blendRatio = 0.3;
- std::vector frustumSizes;
- Model* model;
- Light(Camera* camera);
- std::vector getFrustumCornersWorldSpace(const QMatrix4x4& projview);
- std::vector getFrustumCornersWorldSpace(const QMatrix4x4& proj, const QMatrix4x4& view);
- QMatrix4x4 getLightSpaceMatrix(const float nearPlane, const float farPlane);
- std::vector getLightSpaceMatrices();
-private:
- Camera* camera;
-
-};
+ class Light
+ {
+ public:
+ QVector3D lightDirection = QVector3D(0.2, 4, 1).normalized();
+ std::vector shadowCascadeLevels;
+ float blendRatio = 0.3;
+ std::vector frustumSizes;
+ Model* model;
+ Light(Camera* camera);
+ std::vector getFrustumCornersWorldSpace(const QMatrix4x4& projview);
+ std::vector getFrustumCornersWorldSpace(const QMatrix4x4& proj, const QMatrix4x4& view);
+ QMatrix4x4 getLightSpaceMatrix(const float nearPlane, const float farPlane);
+ std::vector getLightSpaceMatrices();
+ private:
+ Camera* camera;
+
+ };
+}
diff --git a/ArchitectureColoredPainting/src/Renderer/Line.h b/ArchitectureColoredPainting/src/Renderer/Line.h
deleted file mode 100644
index 6b2ee17..0000000
--- a/ArchitectureColoredPainting/src/Renderer/Line.h
+++ /dev/null
@@ -1,65 +0,0 @@
-#pragma once
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-using std::vector;
-using std::pair;
-using std::min;
-using std::max;
-using std::sort;
-using std::shared_ptr;
-using std::make_shared;
-using std::swap;
-
-const double eps = 1e-5;
-
-struct Point {
- double x, y;
- Point operator + (const Point a) { return { x + a.x, y + a.y }; }
- Point operator - (const Point a) { return { x - a.x, y - a.y }; }
- Point operator * (const double a) { return { x * a, y * a }; }
- double operator * (const Point a) { return x * a.y - y * a.x; }
- bool operator== (const Point& a) const {
- return fabs(x - a.x) <= eps && fabs(y - a.y) <= eps;
- }
- bool operator< (const Point& a) const {
- return fabs(x - a.x) <= eps ? y < a.y : x < a.x;
- }
- void show() {
- std::cout << '(' << x << ',' << y << ')' << ' ';
- }
-};
-
-class Line
-{
-protected:
- vector vX, vY;
- int siz;
-public:
- typedef shared_ptr LinePtr;
- Line() :siz(0) {}
- Line(vector Vp);
- int size();
- void clear();
- Point getBegin();
- Point getEnd();
- int direction(bool isY);
- virtual double getLineValueByT(double t, bool isY) = 0;
- virtual void monotonization(vector & res) = 0;
- virtual int judgeBoundIntersection(double xy, double l, double r, bool isY) = 0;
- virtual bool judgeIntersection(QVector4D bound);
- bool isLineContained(QVector4D bound);
- Point operator[](int index) const;
- Point getPointByIndex(int index) const;
- vector toPointVector() const;
- void setPointByIndex(int index, Point now);
- void push_back(Point now);
- virtual ~Line() {}
-};
-
-typedef shared_ptr LinePtr;
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/Mesh.cpp b/ArchitectureColoredPainting/src/Renderer/Mesh.cpp
index fb8531d..32652db 100644
--- a/ArchitectureColoredPainting/src/Renderer/Mesh.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Mesh.cpp
@@ -1,5 +1,5 @@
#include "Mesh.h"
-
+using namespace Renderer;
Mesh::Mesh(QOpenGLFunctions_4_5_Compatibility* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, aiMatrix4x4 model)
: glFunc(glFunc)
, shaderProgram(shaderProgram)
diff --git a/ArchitectureColoredPainting/src/Renderer/Mesh.h b/ArchitectureColoredPainting/src/Renderer/Mesh.h
index a67214d..50b473e 100644
--- a/ArchitectureColoredPainting/src/Renderer/Mesh.h
+++ b/ArchitectureColoredPainting/src/Renderer/Mesh.h
@@ -13,49 +13,51 @@
#include
#include
#include "Drawable.h"
-
-struct Vertex
+namespace Renderer
{
- QVector3D Position;
- QVector3D Normal;
- QVector2D TexCoords;
- QVector3D Tangent;
- QVector3D Bitangent;
-};
+ struct Vertex
+ {
+ QVector3D Position;
+ QVector3D Normal;
+ QVector2D TexCoords;
+ QVector3D Tangent;
+ QVector3D Bitangent;
+ };
-struct Texture
-{
- QOpenGLTexture texture;
- QString type;
- QString path;
- Texture() :texture(QOpenGLTexture::Target2D) {
- texture.create();
- texture.setWrapMode(QOpenGLTexture::DirectionS, QOpenGLTexture::Repeat);
- texture.setWrapMode(QOpenGLTexture::DirectionT, QOpenGLTexture::Repeat);
- texture.setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear);
- }
-};
+ struct Texture
+ {
+ QOpenGLTexture texture;
+ QString type;
+ QString path;
+ Texture() :texture(QOpenGLTexture::Target2D) {
+ texture.create();
+ texture.setWrapMode(QOpenGLTexture::DirectionS, QOpenGLTexture::Repeat);
+ texture.setWrapMode(QOpenGLTexture::DirectionT, QOpenGLTexture::Repeat);
+ texture.setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear);
+ }
+ };
-class Mesh : public Drawable
-{
-public:
- /* */
- QVector vertices; //
- QVector indices; //
- QVector textures; //
- QMatrix4x4 model; //ģ;
- QOpenGLFunctions_4_5_Compatibility* glFunc; //opengl
- QOpenGLShaderProgram* shaderProgram, * shadowProgram; //ɫ
+ class Mesh : public Drawable
+ {
+ public:
+ /* */
+ QVector vertices; //
+ QVector indices; //
+ QVector textures; //
+ QMatrix4x4 model; //ģ;
+ QOpenGLFunctions_4_5_Compatibility* glFunc; //opengl
+ QOpenGLShaderProgram* shaderProgram, * shadowProgram; //ɫ
- /* */
- Mesh(QOpenGLFunctions_4_5_Compatibility* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, aiMatrix4x4 model);
- void draw() override;
- void drawShadow() override;
- void setupMesh();
+ /* */
+ Mesh(QOpenGLFunctions_4_5_Compatibility* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, aiMatrix4x4 model);
+ void draw() override;
+ void drawShadow() override;
+ void setupMesh();
-private:
- /* Ⱦ */
- QOpenGLVertexArrayObject VAO;
- QOpenGLBuffer VBO, EBO;
+ private:
+ /* Ⱦ */
+ QOpenGLVertexArrayObject VAO;
+ QOpenGLBuffer VBO, EBO;
-};
+ };
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp
index 38106b3..d4f2640 100644
--- a/ArchitectureColoredPainting/src/Renderer/Model.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp
@@ -6,10 +6,11 @@
#include
#include "PaintingMesh.h"
#include
-#include "BvhTree.h"
-#include "ShortCutTree.h"
+#include "Painting/BvhTree.h"
+#include "Painting/ShortCutTree.h"
#include "../SvgParser.h"
-
+using namespace Renderer;
+using std::vector;
Model::Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram)
: context(context)
, glFunc(context->versionFunctions())
@@ -175,7 +176,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
m_mesh->indices.push_back(face.mIndices[j]);
}
}
-
+
BvhTree rootBvhTree;
vector rootBvhTreeData;
for (int i = 0; i < 1000; i++)
@@ -205,172 +206,178 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
// {{-0.5,0.3}, {-0.420466,0.379534}, {-0.736743,0.6}, {-0.624264,0.6}},
// {{-0.624264,0.6}, {-0.511785,0.6}, {-0.579534,0.979534}, {-0.5,0.9}}
//};
- vector> lineSet = SvgParser("M377,459.61a11.26,11.26,0,0,1,11.27-11.27H696.12a11.27,11.27,0,0,0,11-8.62A359.84,359.84,0,0,0,708,280.56a11.26,11.26,0,0,0-11-8.73H388.27A11.26,11.26,0,0,1,377,260.57h0a11.26,11.26,0,0,1,11.27-11.26H683.71A11.32,11.32,0,0,0,694.28,234C649.8,113.69,542.57,23.85,412.3,4.12a11.22,11.22,0,0,0-12.76,11.17v158.9a11.26,11.26,0,0,0,11.26,11.27H583.12a11.32,11.32,0,0,0,9.26-17.75c-31.67-46.59-78.51-75.2-109.11-90.07a11.25,11.25,0,0,0-16.13,10.17V115.2a11.24,11.24,0,0,0,6.22,10.07l7.51,3.76a11.28,11.28,0,0,1,5,15.12h0a11.27,11.27,0,0,1-15.11,5l-20-10a11.27,11.27,0,0,1-6.22-10.07V54a11.27,11.27,0,0,1,14.62-10.75c5.11,1.59,125.66,40.35,172.24,149A11.27,11.27,0,0,1,621.11,208H388.27A11.26,11.26,0,0,1,377,196.73V11.36A11.32,11.32,0,0,0,365.89.08C363.34,0,360.79,0,358.22,0s-5.11,0-7.66.08a11.32,11.32,0,0,0-11.11,11.28V196.74A11.26,11.26,0,0,1,328.18,208H95.35A11.27,11.27,0,0,1,85,192.3c46.57-108.67,167.12-147.42,172.23-149A11.26,11.26,0,0,1,271.86,54v75.11a11.25,11.25,0,0,1-6.23,10.07l-20,10a11.27,11.27,0,0,1-15.11-5h0a11.26,11.26,0,0,1,5-15.11l7.52-3.76a11.27,11.27,0,0,0,6.22-10.07V87.82a11.25,11.25,0,0,0-16.14-10.16c-30.6,14.87-77.45,43.48-109.1,90.07a11.3,11.3,0,0,0,9.25,17.74H305.66a11.26,11.26,0,0,0,11.27-11.26V15.31A11.22,11.22,0,0,0,304.17,4.14C173.88,23.86,66.66,113.71,22.17,234a11.32,11.32,0,0,0,10.56,15.29H328.18a11.26,11.26,0,0,1,11.27,11.26v0a11.26,11.26,0,0,1-11.27,11.26H19.52a11.26,11.26,0,0,0-11,8.72,359.84,359.84,0,0,0,.83,159.16,11.26,11.26,0,0,0,11,8.61H328.18a11.26,11.26,0,0,1,11.27,11.27h0a11.26,11.26,0,0,1-11.27,11.26h-294a11.32,11.32,0,0,0-10.53,15.4C69,604.65,175.3,692.78,304.16,712.3a11.21,11.21,0,0,0,12.76-11.16V542.22A11.26,11.26,0,0,0,305.66,531h-166c-9.53,0-14.89,11.22-8.69,18.47,34.09,39.77,74.45,65.66,101.77,80.18a11.25,11.25,0,0,0,16.53-10V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,271.85,591v63.85A11.27,11.27,0,0,1,256.8,665.5c-4.45-1.59-109.58-40-171-139.9a11.27,11.27,0,0,1,9.59-17.17H328.18a11.26,11.26,0,0,1,11.27,11.26V705.08a11.32,11.32,0,0,0,11.11,11.28q3.82.07,7.66.08c2.57,0,5.12,0,7.67-.08A11.32,11.32,0,0,0,377,705.08V519.69a11.25,11.25,0,0,1,11.27-11.26H621.1a11.26,11.26,0,0,1,9.59,17.16c-61.46,99.87-166.59,138.3-171,139.9a11.27,11.27,0,0,1-15-10.61V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,467.14,591v28.6a11.25,11.25,0,0,0,16.53,10c27.33-14.53,67.68-40.42,101.77-80.19,6.2-7.23.85-18.46-8.69-18.46h-166a11.26,11.26,0,0,0-11.26,11.26V701.12a11.21,11.21,0,0,0,12.76,11.17c128.86-19.51,235.14-107.66,280.48-226a11.33,11.33,0,0,0-10.53-15.41h-294A11.25,11.25,0,0,1,377,459.61ZM35.27,399.53V316.9a11.26,11.26,0,0,1,11.27-11.26H669.92a11.25,11.25,0,0,1,11.26,11.26v82.63a11.25,11.25,0,0,1-11.26,11.26H46.54a11.27,11.27,0,0,1-11.27-11.26Z", 716.45, 716.44).parse();
+ /*vector> lineSet = SvgParser("M377,459.61a11.26,11.26,0,0,1,11.27-11.27H696.12a11.27,11.27,0,0,0,11-8.62A359.84,359.84,0,0,0,708,280.56a11.26,11.26,0,0,0-11-8.73H388.27A11.26,11.26,0,0,1,377,260.57h0a11.26,11.26,0,0,1,11.27-11.26H683.71A11.32,11.32,0,0,0,694.28,234C649.8,113.69,542.57,23.85,412.3,4.12a11.22,11.22,0,0,0-12.76,11.17v158.9a11.26,11.26,0,0,0,11.26,11.27H583.12a11.32,11.32,0,0,0,9.26-17.75c-31.67-46.59-78.51-75.2-109.11-90.07a11.25,11.25,0,0,0-16.13,10.17V115.2a11.24,11.24,0,0,0,6.22,10.07l7.51,3.76a11.28,11.28,0,0,1,5,15.12h0a11.27,11.27,0,0,1-15.11,5l-20-10a11.27,11.27,0,0,1-6.22-10.07V54a11.27,11.27,0,0,1,14.62-10.75c5.11,1.59,125.66,40.35,172.24,149A11.27,11.27,0,0,1,621.11,208H388.27A11.26,11.26,0,0,1,377,196.73V11.36A11.32,11.32,0,0,0,365.89.08C363.34,0,360.79,0,358.22,0s-5.11,0-7.66.08a11.32,11.32,0,0,0-11.11,11.28V196.74A11.26,11.26,0,0,1,328.18,208H95.35A11.27,11.27,0,0,1,85,192.3c46.57-108.67,167.12-147.42,172.23-149A11.26,11.26,0,0,1,271.86,54v75.11a11.25,11.25,0,0,1-6.23,10.07l-20,10a11.27,11.27,0,0,1-15.11-5h0a11.26,11.26,0,0,1,5-15.11l7.52-3.76a11.27,11.27,0,0,0,6.22-10.07V87.82a11.25,11.25,0,0,0-16.14-10.16c-30.6,14.87-77.45,43.48-109.1,90.07a11.3,11.3,0,0,0,9.25,17.74H305.66a11.26,11.26,0,0,0,11.27-11.26V15.31A11.22,11.22,0,0,0,304.17,4.14C173.88,23.86,66.66,113.71,22.17,234a11.32,11.32,0,0,0,10.56,15.29H328.18a11.26,11.26,0,0,1,11.27,11.26v0a11.26,11.26,0,0,1-11.27,11.26H19.52a11.26,11.26,0,0,0-11,8.72,359.84,359.84,0,0,0,.83,159.16,11.26,11.26,0,0,0,11,8.61H328.18a11.26,11.26,0,0,1,11.27,11.27h0a11.26,11.26,0,0,1-11.27,11.26h-294a11.32,11.32,0,0,0-10.53,15.4C69,604.65,175.3,692.78,304.16,712.3a11.21,11.21,0,0,0,12.76-11.16V542.22A11.26,11.26,0,0,0,305.66,531h-166c-9.53,0-14.89,11.22-8.69,18.47,34.09,39.77,74.45,65.66,101.77,80.18a11.25,11.25,0,0,0,16.53-10V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,271.85,591v63.85A11.27,11.27,0,0,1,256.8,665.5c-4.45-1.59-109.58-40-171-139.9a11.27,11.27,0,0,1,9.59-17.17H328.18a11.26,11.26,0,0,1,11.27,11.26V705.08a11.32,11.32,0,0,0,11.11,11.28q3.82.07,7.66.08c2.57,0,5.12,0,7.67-.08A11.32,11.32,0,0,0,377,705.08V519.69a11.25,11.25,0,0,1,11.27-11.26H621.1a11.26,11.26,0,0,1,9.59,17.16c-61.46,99.87-166.59,138.3-171,139.9a11.27,11.27,0,0,1-15-10.61V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,467.14,591v28.6a11.25,11.25,0,0,0,16.53,10c27.33-14.53,67.68-40.42,101.77-80.19,6.2-7.23.85-18.46-8.69-18.46h-166a11.26,11.26,0,0,0-11.26,11.26V701.12a11.21,11.21,0,0,0,12.76,11.17c128.86-19.51,235.14-107.66,280.48-226a11.33,11.33,0,0,0-10.53-15.41h-294A11.25,11.25,0,0,1,377,459.61ZM35.27,399.53V316.9a11.26,11.26,0,0,1,11.27-11.26H669.92a11.25,11.25,0,0,1,11.26,11.26v82.63a11.25,11.25,0,0,1-11.26,11.26H46.54a11.27,11.27,0,0,1-11.27-11.26Z", 716.45, 716.44).parse();
qDebug() << lineSet.size();
for (vector& line : lineSet)
{
for (Point& p : line)
p.show();
std::cout << std::endl;
- }
-
-
- //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(20);
- shortCutTree.buildShortCutTree(lineSet);
- vector pointVector;
- vector lineVector;
- vector bvhTreeData = shortCutTree.getPointLineAndBvhTree(pointVector, lineVector);
- qDebug() << "----------------------------------------------";
- qDebug() << "element0CellNum: " << bvhTreeData.size();
- //qDebug() << pointVector;
- //qDebug() << lineVector;
- /*for (BvhTreeData data : bvhTreeData)
- {
- data.show();
}*/
- BvhTree element0Bvh;
- element0Bvh.buildBvhTree(bvhTreeData.data(), bvhTreeData.size());
- std::vector element0Children;
- std::vector element0Bounds;
- element0Bvh.getBvhArray(element0Children, element0Bounds);
- //qDebug() << element0Children;
- //qDebug() << element0Bounds;
-
- //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),
- //};
- std::vector bvhChildren;
- std::vector bvhBounds;
- rootBvhTree.getBvhArray(bvhChildren, bvhBounds);
- //qDebug() << bvhChildren;
- bvhChildren.insert(bvhChildren.end(), element0Children.begin(), element0Children.end());
- bvhBounds.insert(bvhBounds.end(), element0Bounds.begin(), element0Bounds.end());
- std::vector elementOffset = {
- //element0
- rootBvhTree.getBvhNodeNum(), //elementBvhRoot
- (GLuint)element0Bounds.size(), //elementBvhLength
- 0, //pointsOffset
- 0, //linesOffset
- };
- std::vector elementIndex = lineVector;
- std::vector elementData = {
- //fillStyle
- //fill
- 0,
- //fillType
- 0, //ɫ
- //fillColorMetallicRoughness
- 240/255.,220/255.,160/255., 0.996,0.18,
- };
- elementData.insert(elementData.begin(), pointVector.begin(), pointVector.end());
- //qDebug() << elementIndex;
- //qDebug() << elementData;
+ //ShortCutTree shortCutTree(20);
+ //shortCutTree.buildShortCutTree(lineSet);
+ //vector pointVector;
+ //vector lineVector;
+ //vector bvhTreeData = shortCutTree.getPointLineAndBvhTree(pointVector, lineVector);
+ //for (auto& data : bvhTreeData)
+ // data.rightSon = 0;
+ //qDebug() << "----------------------------------------------";
+ //qDebug() << "element0CellNum: " << bvhTreeData.size();
+ ////qDebug() << pointVector;
+ ////qDebug() << lineVector;
+ ///*for (BvhTreeData data : bvhTreeData)
+ //{
+ // data.show();
+ //}*/
+ //BvhTree element0Bvh;
+ //element0Bvh.buildBvhTree(bvhTreeData.data(), bvhTreeData.size());
+ //std::vector element0Children;
+ //std::vector element0Bounds;
+ //element0Bvh.getBvhArray(element0Children, element0Bounds);
+ ////qDebug() << element0Children;
+ ////qDebug() << element0Bounds;
+ ////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),
+ ////};
+ //std::vector bvhChildren;
+ //std::vector bvhBounds;
+ //rootBvhTree.getBvhArray(bvhChildren, bvhBounds);
+ //
+ ////qDebug() << bvhChildren;
+ //bvhChildren.insert(bvhChildren.end(), element0Children.begin(), element0Children.end());
+ //bvhBounds.insert(bvhBounds.end(), element0Bounds.begin(), element0Bounds.end());
- //std::vector bvhChildren0 = {
- // //root
- // 1,2,
- // 3,4, 5,6,
- // encodeChild(0),0, encodeChild(0),GLuint(30. / 360 * 65536 + 1 * 65536) /*ҶʾתǶȺzIndex*/, encodeChild(1),0, encodeChild(0),0,
- // //elememt0
- // 1,2,
- // encodeChild(20)/*contourcontourҪcontourelementIndexλ*/,14/*styleelementDataλ*/, encodeChild(24), 14,
- // //elememt1
- // encodeChild(0)/*lineelementеڼ*/, 27
-
- //};
- //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),
- // 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),
- // //elememt0
- // QVector4D(-1,-1,1,1),
- // QVector4D(-1,-1,-0.2,1), QVector4D(-0.2,-1,1,1),
- // //elememt1
- // QVector4D(-1,-1,1,1)
- //};
- //std::vector elementOffset0 = {
- // //element0
- // 7, //elementBvhRoot
- // 3, //elementBvhLength
- // 0, //pointsOffset
- // 0, //linesOffset
- // //element1
- // 10, //elementBvhRoot
- // 1, //elementBvhLength
- // 21, //pointsOffset
- // 28, //linesOffset
- //};
-
- //std::vector elementIndex0 = {
- // //element0
- // //lines, ȫױ, ÿĸ
- // 0,1,1,2,
- // 0,0,3,3,
- // 3,4,4,5,
- // 2,2,5,5,
- // 5,5,6,6,
- // //contours, һԪΪΪ
- // 3, 1,2,4,
- // 3, 0,2,3,
- // //element1
- // //lines
- // 0,1,1,2
- //};
-
- //std::vector elementData0 = {
- // //element0
- // //points
- // -0.2,1, -0.2,-0.2, 1,-0.2, -1,1, -1,-1, 1,-1, 1,1,
+
+ //std::vector elementIndex = lineVector;
+ //std::vector elementData = {
// //fillStyle
// //fill
// 0,
// //fillType
// 0, //ɫ
// //fillColorMetallicRoughness
- // 1,1,0, 0,0.8,
-
- // //element1
- // //points
- // 0,0.8, 1,0, 0,-0.8,
- // //strokeStyle
- // //stroke
- // 1,
- // //strokeWidth
- // 0.02,
- // //strokeEndType
- // 0, //Բ
- // //strokeFillType
- // 0, //ɫ
- // //
- // 1, //
- // //߿
- // 0,
- // //߷ʽ
- // 0, //ɫ
- // //strokeFillColorMetallicRoughness
- // 1,0,1, 0,0.8
+ // 240/255.,220/255.,160/255., 0.996,0.18,
//};
+ //std::vector elementOffset = {
+ // //element0
+ // rootBvhTree.getBvhNodeNum(), //elementBvhRoot
+ // (GLuint)element0Bounds.size(), //elementBvhLength
+ // (GLuint)elementData.size(), //pointsOffset
+ // 0, //linesOffset
+ //};
+ //elementData.insert(elementData.end(), pointVector.begin(), pointVector.end());
+ ////qDebug() << elementIndex;
+ ////qDebug() << elementData;
+
+
+ std::vector bvhChildren0 = {
+ //root
+ 1,2,
+ 3,4, 5,6,
+ encodeChild(0),0, encodeChild(0),GLuint(30. / 360 * 65536 + 1 * 65536) /*ҶʾתǶȺzIndex*/, encodeChild(1),0, encodeChild(0),0,
+ //elememt0
+ 1,2,
+ encodeChild(20)/*contourcontourҪcontourelementIndexλ*/,14/*styleelementDataλ*/, encodeChild(24), 14,
+ //elememt1
+ encodeChild(12)/*contour*/, 35
+
+ };
+ 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),
+ 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),
+ //elememt0
+ QVector4D(-1,-1,1,1),
+ QVector4D(-1,-1,-0.2,1), QVector4D(-0.2,-1,1,1),
+ //elememt1
+ QVector4D(-1,-1,1,1)
+ };
+ std::vector elementOffset0 = {
+ //element0
+ 7, //elementBvhRoot
+ 3, //elementBvhLength
+ 0, //pointsOffset
+ 0, //linesOffset
+ //element1
+ 10, //elementBvhRoot
+ 1, //elementBvhLength
+ 21, //pointsOffset
+ 28, //linesOffset
+ };
+
+ std::vector elementIndex0 = {
+ //element0
+ //lines, ȫױ, ÿĸ
+ 0,1,1,2,
+ 0,0,3,3,
+ 3,4,4,5,
+ 2,2,5,5,
+ 5,5,6,6,
+ //contours, һԪΪΪ
+ 3, 1,2,4,
+ 3, 0,2,3,
+ //element1
+ //lines
+ 0,0,1,1,
+ 1,2,3,4,
+ 5,5,6,6,
+ //contours
+ 3, 0+ 0x80000000 ,1,2
+ };
+
+ std::vector elementData0 = {
+ //element0
+ //points
+ -0.2,1, -0.2,-0.2, 1,-0.2, -1,1, -1,-1, 1,-1, 1,1,
+ //fillStyle
+ //fill
+ 0,
+ //fillType
+ 0, //ɫ
+ //fillColorMetallicRoughness
+ 1,1,0, 0,0.8,
+
+ //element1
+ //points
+ -0.5,-0.5, -0.5,0.5, 0.2,0.5, 0.5,0.2, 0.5,-0.5, -0.8,-0.5, -0.8,0.5,
+ //strokeStyle
+ //stroke
+ 1,
+ //strokeWidth
+ 0.02,
+ //strokeEndType
+ 0, //Բ
+ //strokeFillType
+ 0, //ɫ
+ //
+ 1, //
+ //߿
+ 0,
+ //߷ʽ
+ 0, //ɫ
+ //strokeFillColorMetallicRoughness
+ 1,0,1, 0,0.8
+ };
//m_mesh->paintingIndex = paintingHelper->addPainting(bounds.size(), std::vector(children.begin()+2, children.end()), bounds,
// elementOffset, elementIndex, elementData);
- m_mesh->paintingIndex = paintingHelper->addPainting(rootBvhTree.getBvhNodeNum(), bvhChildren, bvhBounds,
- elementOffset, elementIndex, elementData);
-
+ //m_mesh->paintingIndex = paintingHelper->addPainting(rootBvhTree.getBvhNodeNum(), bvhChildren, bvhBounds,
+ // elementOffset, elementIndex, elementData);
+ m_mesh->paintingIndex = paintingHelper->addPainting(7, bvhChildren0, bvhBounds0,
+ elementOffset0, elementIndex0, elementData0);
m_mesh->setupMesh();
return m_mesh;
}
diff --git a/ArchitectureColoredPainting/src/Renderer/Model.h b/ArchitectureColoredPainting/src/Renderer/Model.h
index 900dbf7..325ef9c 100644
--- a/ArchitectureColoredPainting/src/Renderer/Model.h
+++ b/ArchitectureColoredPainting/src/Renderer/Model.h
@@ -2,49 +2,52 @@
#include "Mesh.h"
#include "Drawable.h"
-#include "PaintingHelper.h"
+#include "Painting/PaintingHelper.h"
#include
-class Model
+namespace Renderer
{
-public:
- std::vector AABB;
+ class Model
+ {
+ public:
+ std::vector AABB;
- void draw();
- void drawShadow();
- void destroy();
- static Model* createModel(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram);
- Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram, PaintingHelper* paintingHelper);
-private:
- Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram);
+ void draw();
+ void drawShadow();
+ void destroy();
+ static Model* createModel(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram);
+ Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram, PaintingHelper* paintingHelper);
+ private:
+ Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram);
- ~Model();
- QOpenGLContext* context; //opengl
- QOpenGLFunctions_4_5_Compatibility* glFunc;
- QOpenGLShaderProgram* shaderProgram = nullptr;
- QOpenGLShaderProgram* paintingProgram = nullptr; //ʻɫ
- QOpenGLShaderProgram* shadowProgram = nullptr;
- PaintingHelper* paintingHelper = nullptr;
+ ~Model();
+ QOpenGLContext* context; //opengl
+ QOpenGLFunctions_4_5_Compatibility* glFunc;
+ QOpenGLShaderProgram* shaderProgram = nullptr;
+ QOpenGLShaderProgram* paintingProgram = nullptr; //ʻɫ
+ QOpenGLShaderProgram* shadowProgram = nullptr;
+ PaintingHelper* paintingHelper = nullptr;
- /* ģ */
- QVector textures_loaded; //
- QVector meshes; //
- QDir directory; //ģ·
+ /* ģ */
+ QVector textures_loaded; //
+ QVector meshes; //
+ QDir directory; //ģ·
- float minX = std::numeric_limits::max();
- float maxX = std::numeric_limits::min();
- float minY = std::numeric_limits::max();
- float maxY = std::numeric_limits::min();
- float minZ = std::numeric_limits::max();
- float maxZ = std::numeric_limits::min();
+ float minX = std::numeric_limits::max();
+ float maxX = std::numeric_limits::min();
+ float minY = std::numeric_limits::max();
+ float maxY = std::numeric_limits::min();
+ float minZ = std::numeric_limits::max();
+ float maxZ = std::numeric_limits::min();
- //ݹ
- void processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4 = aiMatrix4x4());
+ //ݹ
+ void processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4 = aiMatrix4x4());
- //
- Drawable* processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 model);
+ //
+ Drawable* processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 model);
- //ز
- QVector loadMaterialTextures(aiMaterial* mat, aiTextureType type, QString typeName);
+ //ز
+ QVector loadMaterialTextures(aiMaterial* mat, aiTextureType type, QString typeName);
-};
\ No newline at end of file
+ };
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/BvhTree.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.cpp
similarity index 98%
rename from ArchitectureColoredPainting/src/Renderer/BvhTree.cpp
rename to ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.cpp
index ca3c01d..f69c3f0 100644
--- a/ArchitectureColoredPainting/src/Renderer/BvhTree.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.cpp
@@ -1,5 +1,5 @@
#include "BvhTree.h"
-
+using namespace Renderer;
GLuint BvhTree::getBvhNodeNum() {
return tot;
}
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.h b/ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.h
new file mode 100644
index 0000000..0dfc795
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/BvhTree.h
@@ -0,0 +1,89 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace Renderer
+{
+ struct BvhTreeData {
+ QVector4D bound;
+ GLuint leftSon, rightSon;
+ void show() {
+ printf("Bvh: (%lf, %lf) (%lf, %lf): %d %d\n",
+ bound.x(), bound.y(), bound.z(), bound.w(),
+ leftSon, rightSon);
+ }
+ BvhTreeData(QVector4D bound, GLuint leftSon, GLuint rightSon)
+ : bound(bound), leftSon(leftSon), rightSon(rightSon) {}
+ BvhTreeData()
+ : leftSon(0), rightSon(0) {}
+ ~BvhTreeData() {}
+ };
+ // BvhTree ڵ
+ struct BvhNode {
+ GLuint lab;
+ bool isLeaf;
+ QVector4D bound;
+ std::shared_ptr child[2];
+ static bool x_compare(BvhTreeData a, BvhTreeData b) {
+ return a.bound.x() < b.bound.x();
+ }
+ static bool y_compare(BvhTreeData a, BvhTreeData b) {
+ return a.bound.y() < b.bound.y();
+ }
+ GLuint getLeftSon(int k) {
+ if (isLeaf) {
+ return 0x80000000 + child[0]->lab;
+ }
+ return child[0]->lab;
+ }
+ GLuint getRightSon(int k) {
+ if (isLeaf) {
+ return child[1]->lab;
+ }
+ return child[1]->lab;
+ }
+ BvhNode() {
+ child[0] = child[1] = NULL;
+ isLeaf = false;
+ lab = 0;
+ }
+ int maximumBound() {
+ return (std::fabs(bound.x() - bound.w()) < std::fabs(bound.y() - bound.z()));
+ }
+ ~BvhNode() {}
+ };
+
+ typedef std::shared_ptr BvhPtr;
+
+ class BvhTree
+ {
+
+ private:
+ GLuint tot;
+ BvhPtr root;
+ static QVector4D calcBound(BvhTreeData initBound[], int l, int r);
+ static QVector4D Union(QVector4D a, QVector4D b);
+ BvhPtr subBvhTree(BvhTreeData initBound[], int l, int r);
+ void traverseBvhTree(BvhPtr now, std::vector& children, std::vector& bounds);
+ public:
+ BvhTree() {
+ tot = 0;
+ root = NULL;
+ }
+ // ݵײΧbvh
+ void buildBvhTree(BvhTreeData initBound[], int len);
+ // Bvh rootBvh֣ children 飬Χ vector
+ void getBvhArray(std::vector& children, std::vector& bounds);
+ // BvhTree нڵ
+ GLuint getBvhNodeNum();
+ };
+
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/CubicBezier.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/CubicBezier.cpp
similarity index 98%
rename from ArchitectureColoredPainting/src/Renderer/CubicBezier.cpp
rename to ArchitectureColoredPainting/src/Renderer/Painting/CubicBezier.cpp
index 2ca4425..fcd8352 100644
--- a/ArchitectureColoredPainting/src/Renderer/CubicBezier.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/CubicBezier.cpp
@@ -1,5 +1,6 @@
#include "CubicBezier.h"
-
+using namespace Renderer;
+using std::vector;
double CubicBezier::getLineValueByT(double t, bool isY) {
vector p;
if (isY) p = vY;
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/CubicBezier.h b/ArchitectureColoredPainting/src/Renderer/Painting/CubicBezier.h
new file mode 100644
index 0000000..702936f
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/CubicBezier.h
@@ -0,0 +1,21 @@
+#pragma once
+#include "Line.h"
+#include
+namespace Renderer
+{
+ class CubicBezier : public Line
+ {
+ using Line::Line;
+ private:
+ static Point getPointByT(Point a, Point b, double t);
+ static Point calculateControlPoint(Point a, Point b);
+ static void findPointsOfDivison(std::vector& p, std::vector& res);
+ void splitBezierCubic(double t, std::vector& res);
+ public:
+ virtual double findTByValue(double value, bool isY);
+ virtual void monotonization(std::vector & res);
+ virtual double getLineValueByT(double t, bool isY);
+ virtual int judgeBoundIntersection(double xy, double l, double r, bool isY);
+ void transformToCubic();
+ };
+}
diff --git a/ArchitectureColoredPainting/src/Renderer/CubicMonotonization.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/CubicMonotonization.cpp
similarity index 95%
rename from ArchitectureColoredPainting/src/Renderer/CubicMonotonization.cpp
rename to ArchitectureColoredPainting/src/Renderer/Painting/CubicMonotonization.cpp
index 8e96f1b..b2c6953 100644
--- a/ArchitectureColoredPainting/src/Renderer/CubicMonotonization.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/CubicMonotonization.cpp
@@ -1,5 +1,9 @@
#include "CubicMonotonization.h"
-
+using namespace Renderer;
+using std::vector;
+using std::min;
+using std::max;
+using std::sort;
const double CubicMonotonization::eps = 1e-6;
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/CubicMonotonization.h b/ArchitectureColoredPainting/src/Renderer/Painting/CubicMonotonization.h
new file mode 100644
index 0000000..5207eb4
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/CubicMonotonization.h
@@ -0,0 +1,23 @@
+#pragma once
+#include
+#include
+#include
+
+namespace Renderer
+{
+ class CubicMonotonization
+ {
+ typedef std::pair point;
+ typedef std::vector Line;
+ private:
+ static const double eps;
+ point getPointByT(point a, point b, double t) const;
+ void findPointsOfDivison(std::vector p, std::vector& res);
+ double getBezierPoint(std::vector& p, double t) const;
+ void splitBezierCubic(Line& p, point mid, double t, std::vector & res);
+ public:
+ // p Ϊ˵㡢Ƶ㡢Ƶ㡢˵㣬 res ΪеΪ0ĵ
+ void getPointsOfDivision(Line p, std::vector & res);
+ };
+
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Element.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/Element.cpp
new file mode 100644
index 0000000..b716fa7
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/Element.cpp
@@ -0,0 +1 @@
+#include "Element.h"
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Element.h b/ArchitectureColoredPainting/src/Renderer/Painting/Element.h
new file mode 100644
index 0000000..ac8361a
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/Element.h
@@ -0,0 +1,18 @@
+#pragma once
+#include
+#include
+#include "Line.h"
+
+namespace Renderer
+{
+ class Element
+ {
+ public:
+ std::vector bvhChildren;
+ std::vector bvhBound;
+ std::vector elementIndex;
+ std::vector points;
+
+ Element(std::vector> lines);
+ };
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/Line.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/Line.cpp
similarity index 91%
rename from ArchitectureColoredPainting/src/Renderer/Line.cpp
rename to ArchitectureColoredPainting/src/Renderer/Painting/Line.cpp
index 53a4e02..b5ed91a 100644
--- a/ArchitectureColoredPainting/src/Renderer/Line.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/Line.cpp
@@ -1,5 +1,13 @@
#include "Line.h"
-
+using namespace Renderer;
+using std::vector;
+using std::pair;
+using std::min;
+using std::max;
+using std::sort;
+using std::shared_ptr;
+using std::make_shared;
+using std::swap;
Line::Line(vector Vp) {
siz = Vp.size();
for (Point now : Vp) {
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Line.h b/ArchitectureColoredPainting/src/Renderer/Painting/Line.h
new file mode 100644
index 0000000..6b0e57e
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/Line.h
@@ -0,0 +1,57 @@
+#pragma once
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+namespace Renderer
+{
+
+ const double eps = 1e-5;
+
+ struct Point {
+ double x, y;
+ Point operator + (const Point a) { return { x + a.x, y + a.y }; }
+ Point operator - (const Point a) { return { x - a.x, y - a.y }; }
+ Point operator * (const double a) { return { x * a, y * a }; }
+ double operator * (const Point a) { return x * a.y - y * a.x; }
+ bool operator== (const Point& a) const {
+ return fabs(x - a.x) <= eps && fabs(y - a.y) <= eps;
+ }
+ bool operator< (const Point& a) const {
+ return fabs(x - a.x) <= eps ? y < a.y : x < a.x;
+ }
+ void show() {
+ std::cout << '(' << x << ',' << y << ')' << ' ';
+ }
+ };
+
+ class Line
+ {
+ protected:
+ std::vector vX, vY;
+ int siz;
+ public:
+ typedef std::shared_ptr LinePtr;
+ Line() :siz(0) {}
+ Line(std::vector Vp);
+ int size();
+ void clear();
+ Point getBegin();
+ Point getEnd();
+ int direction(bool isY);
+ virtual double getLineValueByT(double t, bool isY) = 0;
+ virtual void monotonization(std::vector & res) = 0;
+ virtual int judgeBoundIntersection(double xy, double l, double r, bool isY) = 0;
+ virtual bool judgeIntersection(QVector4D bound);
+ bool isLineContained(QVector4D bound);
+ Point operator[](int index) const;
+ Point getPointByIndex(int index) const;
+ std::vector toPointVector() const;
+ void setPointByIndex(int index, Point now);
+ void push_back(Point now);
+ virtual ~Line() {}
+ };
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp
new file mode 100644
index 0000000..55cf5f6
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp
@@ -0,0 +1,64 @@
+#include "Painting.h"
+#include "../../SvgParser.h"
+#include "ShortCutTree.h"
+
+using namespace Renderer;
+Painting::Painting()
+{
+ Contour contour = SvgParser("M377,459.61a11.26,11.26,0,0,1,11.27-11.27H696.12a11.27,11.27,0,0,0,11-8.62A359.84,359.84,0,0,0,708,280.56a11.26,11.26,0,0,0-11-8.73H388.27A11.26,11.26,0,0,1,377,260.57h0a11.26,11.26,0,0,1,11.27-11.26H683.71A11.32,11.32,0,0,0,694.28,234C649.8,113.69,542.57,23.85,412.3,4.12a11.22,11.22,0,0,0-12.76,11.17v158.9a11.26,11.26,0,0,0,11.26,11.27H583.12a11.32,11.32,0,0,0,9.26-17.75c-31.67-46.59-78.51-75.2-109.11-90.07a11.25,11.25,0,0,0-16.13,10.17V115.2a11.24,11.24,0,0,0,6.22,10.07l7.51,3.76a11.28,11.28,0,0,1,5,15.12h0a11.27,11.27,0,0,1-15.11,5l-20-10a11.27,11.27,0,0,1-6.22-10.07V54a11.27,11.27,0,0,1,14.62-10.75c5.11,1.59,125.66,40.35,172.24,149A11.27,11.27,0,0,1,621.11,208H388.27A11.26,11.26,0,0,1,377,196.73V11.36A11.32,11.32,0,0,0,365.89.08C363.34,0,360.79,0,358.22,0s-5.11,0-7.66.08a11.32,11.32,0,0,0-11.11,11.28V196.74A11.26,11.26,0,0,1,328.18,208H95.35A11.27,11.27,0,0,1,85,192.3c46.57-108.67,167.12-147.42,172.23-149A11.26,11.26,0,0,1,271.86,54v75.11a11.25,11.25,0,0,1-6.23,10.07l-20,10a11.27,11.27,0,0,1-15.11-5h0a11.26,11.26,0,0,1,5-15.11l7.52-3.76a11.27,11.27,0,0,0,6.22-10.07V87.82a11.25,11.25,0,0,0-16.14-10.16c-30.6,14.87-77.45,43.48-109.1,90.07a11.3,11.3,0,0,0,9.25,17.74H305.66a11.26,11.26,0,0,0,11.27-11.26V15.31A11.22,11.22,0,0,0,304.17,4.14C173.88,23.86,66.66,113.71,22.17,234a11.32,11.32,0,0,0,10.56,15.29H328.18a11.26,11.26,0,0,1,11.27,11.26v0a11.26,11.26,0,0,1-11.27,11.26H19.52a11.26,11.26,0,0,0-11,8.72,359.84,359.84,0,0,0,.83,159.16,11.26,11.26,0,0,0,11,8.61H328.18a11.26,11.26,0,0,1,11.27,11.27h0a11.26,11.26,0,0,1-11.27,11.26h-294a11.32,11.32,0,0,0-10.53,15.4C69,604.65,175.3,692.78,304.16,712.3a11.21,11.21,0,0,0,12.76-11.16V542.22A11.26,11.26,0,0,0,305.66,531h-166c-9.53,0-14.89,11.22-8.69,18.47,34.09,39.77,74.45,65.66,101.77,80.18a11.25,11.25,0,0,0,16.53-10V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,271.85,591v63.85A11.27,11.27,0,0,1,256.8,665.5c-4.45-1.59-109.58-40-171-139.9a11.27,11.27,0,0,1,9.59-17.17H328.18a11.26,11.26,0,0,1,11.27,11.26V705.08a11.32,11.32,0,0,0,11.11,11.28q3.82.07,7.66.08c2.57,0,5.12,0,7.67-.08A11.32,11.32,0,0,0,377,705.08V519.69a11.25,11.25,0,0,1,11.27-11.26H621.1a11.26,11.26,0,0,1,9.59,17.16c-61.46,99.87-166.59,138.3-171,139.9a11.27,11.27,0,0,1-15-10.61V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,467.14,591v28.6a11.25,11.25,0,0,0,16.53,10c27.33-14.53,67.68-40.42,101.77-80.19,6.2-7.23.85-18.46-8.69-18.46h-166a11.26,11.26,0,0,0-11.26,11.26V701.12a11.21,11.21,0,0,0,12.76,11.17c128.86-19.51,235.14-107.66,280.48-226a11.33,11.33,0,0,0-10.53-15.41h-294A11.25,11.25,0,0,1,377,459.61ZM35.27,399.53V316.9a11.26,11.26,0,0,1,11.27-11.26H669.92a11.25,11.25,0,0,1,11.26,11.26v82.63a11.25,11.25,0,0,1-11.26,11.26H46.54a11.27,11.27,0,0,1-11.27-11.26Z", 716.45, 716.44).parse();
+ std::shared_ptr contourPtr = std::make_shared(contour);
+ contourPool.insert({ contourPtr, {nullptr, nullptr} });
+
+
+ std::vector style = {
+ //fillStyle
+ //fill
+ 0,
+ //fillType
+ 0, //ɫ
+ //fillColorMetallicRoughness
+ 240 / 255.,220 / 255.,160 / 255., 0.996,0.18,
+ };
+
+ Element element{ contourPtr, style, QVector4D(-0.8,-0.8,-0.2,-0.1), 0, 0 };
+ elements.push_back(element);
+ if (style[0] == 0 && contourPool[contourPtr].first == nullptr)
+ {
+ ShortCutTree shortCutTree(20);
+ shortCutTree.buildShortCutTree(*contourPtr);
+ ElementBuffer elementBuffer;
+ elementBuffer.bvhLeaves = shortCutTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer);
+ contourPool[contourPtr].first = std::make_shared(elementBuffer);
+ }
+}
+
+GLuint encodeZIndexRotation(GLuint zIndex, float rotation)
+{
+ return GLuint(rotation / 360 * 0x10000 + zIndex * 0x10000);
+}
+
+//void Painting::addElement(Contour contour, std::vector style, QVector4D bound, float rotation, int zIndex)
+//{
+// BvhTreeData(bound, 0, encodeZIndexRotation(zIndex, rotation));
+//
+// std::shared_ptr element = nullptr;
+// auto iterator = elementMap.find(lines);
+// if (iterator != elementMap.end())
+// element = iterator->second;
+// else
+// {
+// element = std::make_shared(lines);
+// elementMap.insert({ lines, element });
+// }
+//
+//}
+
+void Painting::generateBuffers()
+{
+ //std::unordered_map < std::shared_ptr, int>
+ for (auto& iter : contourPool)
+ {
+ elementData.insert(elementData.end(), iter.second.first->pointBuffer.begin(), iter.second.first->pointBuffer.end());
+
+ }
+}
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h
new file mode 100644
index 0000000..53b3a5c
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h
@@ -0,0 +1,51 @@
+#pragma once
+#include
+#include
+#include "Line.h"
+#include "BvhTree.h"
+//#include "Element.h"
+
+namespace Renderer
+{
+ using Contour = std::vector>;
+
+ struct Element
+ {
+ std::shared_ptr contour;
+ std::vector style;
+ QVector4D bound;
+ float rotation;
+ int zIndex;
+ };
+
+ struct ElementBuffer
+ {
+ std::vector pointBuffer;
+ std::vector lineBuffer;
+ std::vector bvhLeaves;
+ };
+
+ class Painting
+ {
+ public:
+ std::vector bvhChildren;
+ std::vector bvhBound;
+ std::vector elementOffset;
+ std::vector elementIndex;
+ std::vector elementData;
+ int paintingId = 0;
+
+ Painting();
+ //void addElement(Contour contour, std::vector style, QVector4D bound, float rotation, int zIndex);
+ void generateBuffers();
+ private:
+ std::vector bvhLeaves;
+ std::unordered_map< std::shared_ptr, std::pair, std::shared_ptr>> contourPool;
+ //std::vector> contourPool;
+ std::vector elements;
+ //std::unordered_map>, std::shared_ptr> elementMap;
+
+ };
+}
+
+
diff --git a/ArchitectureColoredPainting/src/Renderer/PaintingHelper.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.cpp
similarity index 88%
rename from ArchitectureColoredPainting/src/Renderer/PaintingHelper.cpp
rename to ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.cpp
index 7ec9261..38053be 100644
--- a/ArchitectureColoredPainting/src/Renderer/PaintingHelper.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.cpp
@@ -1,5 +1,5 @@
#include "PaintingHelper.h"
-
+using namespace Renderer;
PaintingHelper::PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc) :glFunc(glFunc)
{
@@ -24,34 +24,34 @@ void PaintingHelper::allocateBuffers()
{
glFunc->glGenBuffers(1, &paintingOffsetsSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, paintingOffsetsSSBO);
- glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, paintingOffsets.size() * sizeof(GLuint), paintingOffsets.data(), GL_DYNAMIC_DRAW);
+ glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, paintingOffsets.size() * sizeof(GLuint), paintingOffsets.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &bvhSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, bvhSSBO);
- glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, bvhChildren.size() * sizeof(GLuint), bvhChildren.data(), GL_DYNAMIC_DRAW);
+ glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, bvhChildren.size() * sizeof(GLuint), bvhChildren.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &bvhBoundSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, bvhBoundSSBO);
- glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, bvhBound.size() * sizeof(QVector4D), bvhBound.data(), GL_DYNAMIC_DRAW);
+ glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, bvhBound.size() * sizeof(QVector4D), bvhBound.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &elementOffsetSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, elementOffsetSSBO);
- glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementOffset.size() * sizeof(GLuint), elementOffset.data(), GL_DYNAMIC_DRAW);
+ glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementOffset.size() * sizeof(GLuint), elementOffset.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &elementIndexSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, elementIndexSSBO);
- glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementIndex.size() * sizeof(GLuint), elementIndex.data(), GL_DYNAMIC_DRAW);
+ glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementIndex.size() * sizeof(GLuint), elementIndex.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &elementDataSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, elementDataSSBO);
- glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementData.size() * sizeof(GLfloat), elementData.data(), GL_DYNAMIC_DRAW);
+ glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementData.size() * sizeof(GLfloat), elementData.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
}
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.h b/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.h
new file mode 100644
index 0000000..8b2b81b
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+#include "BvhTree.h"
+namespace Renderer
+{
+ class PaintingHelper
+ {
+ private:
+ QOpenGLFunctions_4_5_Compatibility* glFunc;
+ GLuint paintingOffsetsSSBO, bvhSSBO, bvhBoundSSBO, elementOffsetSSBO, elementIndexSSBO, elementDataSSBO;
+ std::vector paintingOffsets;
+ std::vector bvhChildren;
+ std::vector bvhBound;
+ std::vector elementOffset;
+ std::vector elementIndex;
+ std::vector elementData;
+ int paintingCount = 0;
+
+ public:
+ PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc);
+ int addPainting(GLuint paintingBvhLength, std::vector bvhChildren, std::vector bvhBound,
+ std::vector elementOffset, std::vector elementIndex, std::vector elementData);
+ void allocateBuffers();
+ void bindPaintingBuffers();
+ };
+
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/ShortCutTree.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.cpp
similarity index 97%
rename from ArchitectureColoredPainting/src/Renderer/ShortCutTree.cpp
rename to ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.cpp
index 25fda07..8a1069b 100644
--- a/ArchitectureColoredPainting/src/Renderer/ShortCutTree.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.cpp
@@ -1,6 +1,12 @@
#include "ShortCutTree.h"
#include
-
+using namespace Renderer;
+using std::queue;
+using std::map;
+using std::for_each;
+using std::set;
+using std::pair;
+using std::vector;
void ShortCutTree::init() {
restOfTreeNodes.clear();
allLine.clear();
@@ -57,9 +63,9 @@ bool ShortCutTree::isLineEqual(PointIndexVector& a, PointIndexVector& b) const {
return true;
}
-void ShortCutTree::monotonization(vector& inLines, vector& outLines) {
+void ShortCutTree::monotonization(vector& inLines, vector>& outLines) {
for (PointVector&l: inLines) {
- LinePtr nowLine;
+ std::shared_ptr nowLine;
switch(l.size()) {
case 2: nowLine.reset(new StraightLine(l)); break;
case 3: case 4: nowLine.reset(new CubicBezier(l)); break;
@@ -288,7 +294,7 @@ vector ShortCutTree::getPointLineAndBvhTree(vector& resPoint
for (auto& nowTreeNode : restOfTreeNodes) {
BvhTreeData oneData;
oneData.leftSon = resLines.size();
- oneData.rightSon = resPoints.size();
+ //oneData.rightSon = rightSon;
oneData.bound = nowTreeNode.bound;
std::cout << nowTreeNode.lineSet.size() << ' ';
resLines.push_back(nowTreeNode.lineSet.size());
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.h b/ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.h
new file mode 100644
index 0000000..cf58e99
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.h
@@ -0,0 +1,62 @@
+#pragma once
+#include "CubicBezier.h"
+#include "StraightLine.h"
+#include "BvhTree.h"
+#include
+#include
+namespace Renderer
+{
+
+
+ struct ShortCutNode {
+ typedef std::vector vectorPoint;
+ int windingIncrement, eastGroup;
+ bool divided;
+ /* type еĽڵࣺ
+ 0ҪĽڵ
+ 1Ҫ*/
+ QVector4D bound;
+ std::vector lineSet;
+ ShortCutNode() {
+ divided = true;
+ windingIncrement = 0;
+ eastGroup = 0;
+ lineSet.clear();
+ bound = { 0, 0, 0, 0 };
+ }
+ ~ShortCutNode() {}
+ };
+ class ShortCutTree
+ {
+ typedef std::vector PointVector;
+ typedef std::vector PointIndexVector;
+ private:
+ std::vector restOfTreeNodes;
+ std::vector> allLine;
+ int RequiredLineMin, numPoint, numLine;
+ std::map pointMap;
+ std::vector lineIndexs;
+
+ int getPointIndex(Point nowPoint);
+ void generateShortCutsegmentement(ShortCutNode& nowTreeNode);
+ bool handleShortCutNode(ShortCutNode& fa, ShortCutNode& nowTreeNode, double yValue, std::vector