将Renderer部分放入Renderer命名空间

dev-VirtualTexture
wuyize 2022-11-14 18:31:20 +08:00
parent 4446ef73dd
commit aee5003475
45 changed files with 854 additions and 773 deletions

View File

@ -103,20 +103,21 @@
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\MainWindow.cpp" />
<ClCompile Include="src\NavigationBarWidget.cpp" />
<ClCompile Include="src\Renderer\BvhTree.cpp" />
<ClCompile Include="src\Renderer\Painting\BvhTree.cpp" />
<ClCompile Include="src\Renderer\Camera.cpp" />
<ClCompile Include="src\Renderer\CubicBezier.cpp" />
<ClCompile Include="src\Renderer\CubicMonotonization.cpp" />
<ClCompile Include="src\Renderer\Painting\CubicBezier.cpp" />
<ClCompile Include="src\Renderer\Painting\CubicMonotonization.cpp" />
<ClCompile Include="src\Renderer\Light.cpp" />
<ClCompile Include="src\Renderer\Line.cpp" />
<ClCompile Include="src\Renderer\Painting\Line.cpp" />
<ClCompile Include="src\Renderer\Mesh.cpp" />
<ClCompile Include="src\Renderer\Model.cpp" />
<ClCompile Include="src\Renderer\PaintingHelper.cpp" />
<ClCompile Include="src\Renderer\Painting\Painting.cpp" />
<ClCompile Include="src\Renderer\Painting\PaintingHelper.cpp" />
<ClCompile Include="src\Renderer\PaintingMesh.cpp" />
<ClCompile Include="src\Renderer\RendererGLWidget.cpp" />
<ClCompile Include="src\Renderer\RendererWidget.cpp" />
<ClCompile Include="src\Renderer\ShortCutTree.cpp" />
<ClCompile Include="src\Renderer\StraightLine.cpp" />
<ClCompile Include="src\Renderer\Painting\ShortCutTree.cpp" />
<ClCompile Include="src\Renderer\Painting\StraightLine.cpp" />
<ClCompile Include="src\SvgParser.cpp" />
<ClCompile Include="src\TitleWidget.cpp" />
<QtRcc Include="MainWindow.qrc" />
@ -148,6 +149,7 @@
</ItemGroup>
<ItemGroup>
<QtMoc Include="src\MainWindow.h" />
<ClInclude Include="src\Renderer\Painting\Painting.h" />
<ClInclude Include="src\SvgParser.h" />
<QtMoc Include="src\TitleWidget.h" />
<QtMoc Include="src\IconWidget.h" />
@ -155,19 +157,19 @@
<QtMoc Include="src\NavigationBarWidget.h" />
<QtMoc Include="src\Renderer\RendererWidget.h" />
<QtMoc Include="src\Editor\EditorWidget.h" />
<ClInclude Include="src\Renderer\BvhTree.h" />
<ClInclude Include="src\Renderer\Painting\BvhTree.h" />
<ClInclude Include="src\Renderer\Camera.h" />
<ClInclude Include="src\Renderer\CubicBezier.h" />
<ClInclude Include="src\Renderer\CubicMonotonization.h" />
<ClInclude Include="src\Renderer\Painting\CubicBezier.h" />
<ClInclude Include="src\Renderer\Painting\CubicMonotonization.h" />
<ClInclude Include="src\Renderer\Drawable.h" />
<ClInclude Include="src\Renderer\Light.h" />
<ClInclude Include="src\Renderer\Line.h" />
<ClInclude Include="src\Renderer\Painting\Line.h" />
<ClInclude Include="src\Renderer\Mesh.h" />
<ClInclude Include="src\Renderer\Model.h" />
<ClInclude Include="src\Renderer\PaintingHelper.h" />
<ClInclude Include="src\Renderer\Painting\PaintingHelper.h" />
<ClInclude Include="src\Renderer\PaintingMesh.h" />
<ClInclude Include="src\Renderer\ShortCutTree.h" />
<ClInclude Include="src\Renderer\StraightLine.h" />
<ClInclude Include="src\Renderer\Painting\ShortCutTree.h" />
<ClInclude Include="src\Renderer\Painting\StraightLine.h" />
<QtMoc Include="src\Renderer\RendererGLWidget.h" />
</ItemGroup>
<ItemGroup>

View File

@ -35,6 +35,12 @@
<Filter Include="Resource Files\Shaders">
<UniqueIdentifier>{60515177-3da7-420f-8f5b-27c16bb2b77b}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Renderer\Painting">
<UniqueIdentifier>{653d1291-0de8-4e0a-855d-7cfc755f7632}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Renderer\Painting">
<UniqueIdentifier>{22909273-2b23-49fa-84ab-444cefb09656}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<QtUic Include="MainWindow.ui">
@ -51,45 +57,24 @@
<ClCompile Include="src\Editor\EditorWidget.cpp">
<Filter>Source Files\Editor</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\BvhTree.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Camera.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\CubicBezier.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\CubicMonotonization.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Light.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Line.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Mesh.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Model.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\PaintingHelper.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\PaintingMesh.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\RendererGLWidget.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\ShortCutTree.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\StraightLine.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -114,6 +99,30 @@
<ClCompile Include="src\TitleWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\BvhTree.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\CubicBezier.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\CubicMonotonization.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\PaintingHelper.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\ShortCutTree.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\StraightLine.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\Painting.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\Line.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="src\Renderer\RendererGLWidget.h">
@ -206,48 +215,51 @@
</QtUic>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Renderer\BvhTree.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Camera.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\CubicBezier.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\CubicMonotonization.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Drawable.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Light.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Line.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Mesh.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Model.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\PaintingHelper.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\PaintingMesh.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\ShortCutTree.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\StraightLine.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="src\SvgParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\BvhTree.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\CubicBezier.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\CubicMonotonization.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\Line.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\PaintingHelper.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\ShortCutTree.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\StraightLine.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\Painting.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtRcc Include="MainWindow.qrc">

View File

@ -94,7 +94,7 @@ QTabWidget::pane {
<string>纹理编辑</string>
</attribute>
</widget>
<widget class="RendererWidget" name="rendererWidget">
<widget class="Renderer::RendererWidget" name="rendererWidget">
<attribute name="title">
<string>场景渲染</string>
</attribute>
@ -109,7 +109,7 @@ QTabWidget::pane {
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>RendererWidget</class>
<class>Renderer::RendererWidget</class>
<extends>QWidget</extends>
<header>Renderer/RendererWidget.h</header>
</customwidget>

View File

@ -48,7 +48,7 @@
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="RendererGLWidget" name="openGLWidget">
<widget class="Renderer::RendererGLWidget" name="openGLWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -94,7 +94,7 @@
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>RendererGLWidget</class>
<class>Renderer::RendererGLWidget</class>
<extends>QOpenGLWidget</extends>
<header>RendererGLWidget.h</header>
</customwidget>

View File

@ -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()

View File

@ -1,88 +0,0 @@
#pragma once
#include <QOpenGLTexture>
#include <QOpenGLContext>
#include <QTextCodec>
#include <algorithm>
#include <QVector4D>
#include <iostream>
#include <memory>
#include <vector>
#include <cmath>
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<BvhNode> 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<BvhNode> 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<GLuint>& children, std::vector<QVector4D>& bounds);
public:
BvhTree() {
tot = 0;
root = NULL;
}
// 根据底层包围盒生成bvh树
void buildBvhTree(BvhTreeData initBound[], int len);
// 获得 Bvh rootBvh部分的 children 数组,包围盒数组 vector 传输
void getBvhArray(std::vector<GLuint>& children, std::vector<QVector4D>& bounds);
// 获得 BvhTree 中节点总数
GLuint getBvhNodeNum();
};

View File

@ -1,5 +1,5 @@
#include "Camera.h"
using namespace Renderer;
// constructor with vectors

View File

@ -5,66 +5,69 @@
#include <QtMath>
#include <QOpenGLFunctions_4_5_Compatibility>
// 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();
};
}

View File

@ -1,20 +0,0 @@
#pragma once
#include "Line.h"
#include <memory>
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<double> &p, vector<double>& res);
void splitBezierCubic(double t, vector<LinePtr>& res);
public:
virtual double findTByValue(double value, bool isY);
virtual void monotonization(vector <LinePtr>& res);
virtual double getLineValueByT(double t, bool isY);
virtual int judgeBoundIntersection(double xy, double l, double r, bool isY);
void transformToCubic();
};

View File

@ -1,24 +0,0 @@
#include <utility>
#include <vector>
#include <algorithm>
#pragma once
using std::pair;
using std::vector;
using std::min;
using std::max;
using std::sort;
class CubicMonotonization
{
typedef pair<double, double> point;
typedef vector<point> Line;
private:
static const double eps;
point getPointByT(point a, point b, double t) const;
void findPointsOfDivison(vector<double> p, vector<double> &res);
double getBezierPoint(vector<double> &p, double t) const;
void splitBezierCubic(Line& p, point mid, double t, vector <Line> &res);
public:
// p 为端点、控制点、控制点、端点, res 为所有导数为0的点
void getPointsOfDivision(Line p, vector <Line> &res);
};

View File

@ -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;
};
}

View File

@ -1,6 +1,6 @@
#include "Light.h"
#include <qDebug>
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 }

View File

@ -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<float> shadowCascadeLevels;
float blendRatio = 0.3;
std::vector<float> frustumSizes;
Model* model;
Light(Camera* camera);
std::vector<QVector4D> getFrustumCornersWorldSpace(const QMatrix4x4& projview);
std::vector<QVector4D> getFrustumCornersWorldSpace(const QMatrix4x4& proj, const QMatrix4x4& view);
QMatrix4x4 getLightSpaceMatrix(const float nearPlane, const float farPlane);
std::vector<QMatrix4x4> getLightSpaceMatrices();
private:
Camera* camera;
};
class Light
{
public:
QVector3D lightDirection = QVector3D(0.2, 4, 1).normalized();
std::vector<float> shadowCascadeLevels;
float blendRatio = 0.3;
std::vector<float> frustumSizes;
Model* model;
Light(Camera* camera);
std::vector<QVector4D> getFrustumCornersWorldSpace(const QMatrix4x4& projview);
std::vector<QVector4D> getFrustumCornersWorldSpace(const QMatrix4x4& proj, const QMatrix4x4& view);
QMatrix4x4 getLightSpaceMatrix(const float nearPlane, const float farPlane);
std::vector<QMatrix4x4> getLightSpaceMatrices();
private:
Camera* camera;
};
}

View File

@ -1,65 +0,0 @@
#pragma once
#include <vector>
#include <utility>
#include <vector>
#include <QVector4D>
#include <algorithm>
#include <memory>
#include <iostream>
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<double> vX, vY;
int siz;
public:
typedef shared_ptr<Line> LinePtr;
Line() :siz(0) {}
Line(vector<Point> 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 <LinePtr>& 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<Point> toPointVector() const;
void setPointByIndex(int index, Point now);
void push_back(Point now);
virtual ~Line() {}
};
typedef shared_ptr<Line> LinePtr;

View File

@ -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)

View File

@ -13,49 +13,51 @@
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#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<Vertex> vertices; //顶点数据
QVector<unsigned int> indices; //索引数组
QVector<Texture*> textures; //纹理数据
QMatrix4x4 model; //模型矩阵
QOpenGLFunctions_4_5_Compatibility* glFunc; //opengl函数入口
QOpenGLShaderProgram* shaderProgram, * shadowProgram; //着色器程序
class Mesh : public Drawable
{
public:
/* 网格数据 */
QVector<Vertex> vertices; //顶点数据
QVector<unsigned int> indices; //索引数组
QVector<Texture*> 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;
};
};
}

View File

@ -6,10 +6,11 @@
#include <iostream>
#include "PaintingMesh.h"
#include <QtMath>
#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<QOpenGLFunctions_4_5_Compatibility>())
@ -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<BvhTreeData> rootBvhTreeData;
for (int i = 0; i < 1000; i++)

View File

@ -2,49 +2,52 @@
#include "Mesh.h"
#include "Drawable.h"
#include "PaintingHelper.h"
#include "Painting/PaintingHelper.h"
#include <QDir>
class Model
namespace Renderer
{
public:
std::vector<QVector3D> AABB;
class Model
{
public:
std::vector<QVector3D> 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<Texture*> textures_loaded; //纹理
QVector<Drawable*> meshes; //网格
QDir directory; //模型所在路径
/* 模型数据 */
QVector<Texture*> textures_loaded; //纹理
QVector<Drawable*> meshes; //网格
QDir directory; //模型所在路径
float minX = std::numeric_limits<float>::max();
float maxX = std::numeric_limits<float>::min();
float minY = std::numeric_limits<float>::max();
float maxY = std::numeric_limits<float>::min();
float minZ = std::numeric_limits<float>::max();
float maxZ = std::numeric_limits<float>::min();
float minX = std::numeric_limits<float>::max();
float maxX = std::numeric_limits<float>::min();
float minY = std::numeric_limits<float>::max();
float maxY = std::numeric_limits<float>::min();
float minZ = std::numeric_limits<float>::max();
float maxZ = std::numeric_limits<float>::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<Texture*> loadMaterialTextures(aiMaterial* mat, aiTextureType type, QString typeName);
//加载材质纹理
QVector<Texture*> loadMaterialTextures(aiMaterial* mat, aiTextureType type, QString typeName);
};
};
}

View File

@ -1,5 +1,5 @@
#include "BvhTree.h"
using namespace Renderer;
GLuint BvhTree::getBvhNodeNum() {
return tot;
}

View File

@ -0,0 +1,89 @@
#pragma once
#include <QOpenGLTexture>
#include <QOpenGLContext>
#include <QTextCodec>
#include <algorithm>
#include <QVector4D>
#include <iostream>
#include <memory>
#include <vector>
#include <cmath>
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<BvhNode> 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<BvhNode> 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<GLuint>& children, std::vector<QVector4D>& bounds);
public:
BvhTree() {
tot = 0;
root = NULL;
}
// 根据底层包围盒生成bvh树
void buildBvhTree(BvhTreeData initBound[], int len);
// 获得 Bvh rootBvh部分的 children 数组,包围盒数组 vector 传输
void getBvhArray(std::vector<GLuint>& children, std::vector<QVector4D>& bounds);
// 获得 BvhTree 中节点总数
GLuint getBvhNodeNum();
};
}

View File

@ -1,5 +1,6 @@
#include "CubicBezier.h"
using namespace Renderer;
using std::vector;
double CubicBezier::getLineValueByT(double t, bool isY) {
vector<double> p;
if (isY) p = vY;

View File

@ -0,0 +1,21 @@
#pragma once
#include "Line.h"
#include <memory>
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<double>& p, std::vector<double>& res);
void splitBezierCubic(double t, std::vector<LinePtr>& res);
public:
virtual double findTByValue(double value, bool isY);
virtual void monotonization(std::vector <LinePtr>& res);
virtual double getLineValueByT(double t, bool isY);
virtual int judgeBoundIntersection(double xy, double l, double r, bool isY);
void transformToCubic();
};
}

View File

@ -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;

View File

@ -0,0 +1,23 @@
#pragma once
#include <utility>
#include <vector>
#include <algorithm>
namespace Renderer
{
class CubicMonotonization
{
typedef std::pair<double, double> point;
typedef std::vector<point> Line;
private:
static const double eps;
point getPointByT(point a, point b, double t) const;
void findPointsOfDivison(std::vector<double> p, std::vector<double>& res);
double getBezierPoint(std::vector<double>& p, double t) const;
void splitBezierCubic(Line& p, point mid, double t, std::vector <Line>& res);
public:
// p 为端点、控制点、控制点、端点, res 为所有导数为0的点
void getPointsOfDivision(Line p, std::vector <Line>& res);
};
}

View File

@ -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<Point> Vp) {
siz = Vp.size();
for (Point now : Vp) {

View File

@ -0,0 +1,57 @@
#pragma once
#include <vector>
#include <utility>
#include <vector>
#include <QVector4D>
#include <algorithm>
#include <memory>
#include <iostream>
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<double> vX, vY;
int siz;
public:
typedef std::shared_ptr<Line> LinePtr;
Line() :siz(0) {}
Line(std::vector<Point> 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 <LinePtr>& 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<Point> toPointVector() const;
void setPointByIndex(int index, Point now);
void push_back(Point now);
virtual ~Line() {}
};
}

View File

@ -0,0 +1,8 @@
#include "Painting.h"
using namespace Renderer;
Painting::Painting()
{
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <vector>
#include <QOpenGLFunctions_4_5_Compatibility>
#include "Line.h"
namespace Renderer
{
class Painting
{
std::vector<GLuint> paintingOffsets;
std::vector<GLuint> bvhChildren;
std::vector<QVector4D> bvhBound;
std::vector<GLuint> elementOffset;
std::vector<GLuint> elementIndex;
std::vector<GLfloat> elementData;
int paintingId = 0;
public:
Painting();
};
}

View File

@ -1,5 +1,5 @@
#include "PaintingHelper.h"
using namespace Renderer;
PaintingHelper::PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc) :glFunc(glFunc)
{

View File

@ -0,0 +1,31 @@
#pragma once
#include <vector>
#include <QDebug>
#include <QVector4D>
#include <QOpenGLFunctions_4_5_Compatibility>
#include "BvhTree.h"
namespace Renderer
{
class PaintingHelper
{
private:
QOpenGLFunctions_4_5_Compatibility* glFunc;
GLuint paintingOffsetsSSBO, bvhSSBO, bvhBoundSSBO, elementOffsetSSBO, elementIndexSSBO, elementDataSSBO;
std::vector<GLuint> paintingOffsets;
std::vector<GLuint> bvhChildren;
std::vector<QVector4D> bvhBound;
std::vector<GLuint> elementOffset;
std::vector<GLuint> elementIndex;
std::vector<GLfloat> elementData;
int paintingCount = 0;
public:
PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc);
int addPainting(GLuint paintingBvhLength, std::vector<GLuint> bvhChildren, std::vector<QVector4D> bvhBound,
std::vector<GLuint> elementOffset, std::vector<GLuint> elementIndex, std::vector<GLfloat> elementData);
void allocateBuffers();
void bindPaintingBuffers();
};
}

View File

@ -1,6 +1,12 @@
#include "ShortCutTree.h"
#include <qDebug>
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<PointVector>& inLines, vector<LinePtr>& outLines) {
void ShortCutTree::monotonization(vector<PointVector>& inLines, vector<std::shared_ptr<Line>>& outLines) {
for (PointVector&l: inLines) {
LinePtr nowLine;
std::shared_ptr<Line> nowLine;
switch(l.size()) {
case 2: nowLine.reset(new StraightLine(l)); break;
case 3: case 4: nowLine.reset(new CubicBezier(l)); break;

View File

@ -0,0 +1,62 @@
#pragma once
#include "CubicBezier.h"
#include "StraightLine.h"
#include "BvhTree.h"
#include <queue>
#include <set>
namespace Renderer
{
struct ShortCutNode {
typedef std::vector<Point> vectorPoint;
int windingIncrement, eastGroup;
bool divided;
/* type 代表进入广度优先搜索队列的节点种类:
0
1*/
QVector4D bound;
std::vector<int> lineSet;
ShortCutNode() {
divided = true;
windingIncrement = 0;
eastGroup = 0;
lineSet.clear();
bound = { 0, 0, 0, 0 };
}
~ShortCutNode() {}
};
class ShortCutTree
{
typedef std::vector<Point> PointVector;
typedef std::vector<int> PointIndexVector;
private:
std::vector<ShortCutNode> restOfTreeNodes;
std::vector<std::shared_ptr<Line>> allLine;
int RequiredLineMin, numPoint, numLine;
std::map<Point, int> pointMap;
std::vector<int> lineIndexs;
int getPointIndex(Point nowPoint);
void generateShortCutsegmentement(ShortCutNode& nowTreeNode);
bool handleShortCutNode(ShortCutNode& fa, ShortCutNode& nowTreeNode, double yValue, std::vector<ShortCutNode>& v, int& sumIncrement);
void spliteToShortCutTree();
static void monotonization(std::vector<PointVector>& inL, std::vector<std::shared_ptr<Line>>& outL);
bool isLineEqual(PointIndexVector& a, PointIndexVector& b) const;
void simplifyLineVector();
// 需要测试,随机获得合理的边界
static bool IsBorderValueResonable(double value, std::set <double>& valueSet);
static double findBorderValueNotOnLine(double value, std::set <double>& valueSet);
public:
void init();
//lineMin最小线数目即划分终止条件
ShortCutTree(int lineMin = 3)
:RequiredLineMin(lineMin), numPoint(0), numLine(0) {}
// 传入一个vector<vector<Point> > 作为所有输入的线
void buildShortCutTree(std::vector<PointVector>& lineSet);
// 获得点集合和线集合 返回输入BvhTree的数据集合
std::vector<BvhTreeData> getPointLineAndBvhTree(std::vector<float>& pointSet, std::vector<GLuint>& lineSet);
~ShortCutTree() {}
};
}

View File

@ -1,5 +1,6 @@
#include "StraightLine.h"
using namespace Renderer;
using std::swap;
double StraightLine::getLineValueByT(double t, bool isY) {
double valueBegin, valueEnd;
if (isY) {

View File

@ -0,0 +1,12 @@
#include "Line.h"
namespace Renderer
{
class StraightLine : public Line
{
using Line::Line;
virtual double getLineValueByT(double t, bool isY);
virtual void monotonization(std::vector <LinePtr>& res) {};
virtual double findTByValue(double value, bool isY);
virtual int judgeBoundIntersection(double xy, double l, double r, bool isY);
};
}

View File

@ -1,29 +0,0 @@
#pragma once
#include <vector>
#include <QDebug>
#include <QVector4D>
#include <QOpenGLFunctions_4_5_Compatibility>
#include "BvhTree.h"
class PaintingHelper
{
private:
QOpenGLFunctions_4_5_Compatibility* glFunc;
GLuint paintingOffsetsSSBO, bvhSSBO, bvhBoundSSBO, elementOffsetSSBO, elementIndexSSBO, elementDataSSBO;
std::vector<GLuint> paintingOffsets;
std::vector<GLuint> bvhChildren;
std::vector<QVector4D> bvhBound;
std::vector<GLuint> elementOffset;
std::vector<GLuint> elementIndex;
std::vector<GLfloat> elementData;
int paintingCount = 0;
public:
PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc);
int addPainting(GLuint paintingBvhLength, std::vector<GLuint> bvhChildren, std::vector<QVector4D> bvhBound,
std::vector<GLuint> elementOffset, std::vector<GLuint> elementIndex, std::vector<GLfloat> elementData);
void allocateBuffers();
void bindPaintingBuffers();
};

View File

@ -1,5 +1,5 @@
#include "PaintingMesh.h"
using namespace Renderer;
PaintingMesh::PaintingMesh(QOpenGLFunctions_4_5_Compatibility* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, aiMatrix4x4 model)
: glFunc(glFunc)
, shaderProgram(shaderProgram)

View File

@ -15,34 +15,37 @@
#include <assimp/postprocess.h>
#include "Drawable.h"
struct PaintingVertex
namespace Renderer
{
QVector3D Position;
QVector3D Normal;
QVector2D TexCoords;
QVector3D Tangent;
QVector3D Bitangent;
};
struct PaintingVertex
{
QVector3D Position;
QVector3D Normal;
QVector2D TexCoords;
QVector3D Tangent;
QVector3D Bitangent;
};
class PaintingMesh : public Drawable
{
public:
/* 网格数据 */
QVector<PaintingVertex> vertices; //顶点数据
QVector<unsigned int> indices; //索引数组
QMatrix4x4 model; //模型矩阵
QOpenGLFunctions_4_5_Compatibility* glFunc; //opengl函数入口
QOpenGLShaderProgram* shaderProgram, * shadowProgram; //着色器程序
GLuint paintingIndex;
/* 函数 */
PaintingMesh(QOpenGLFunctions_4_5_Compatibility* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, aiMatrix4x4 model);
void draw() override;
void drawShadow() override;
void setupMesh();
class PaintingMesh : public Drawable
{
public:
/* 网格数据 */
QVector<PaintingVertex> vertices; //顶点数据
QVector<unsigned int> indices; //索引数组
QMatrix4x4 model; //模型矩阵
QOpenGLFunctions_4_5_Compatibility* glFunc; //opengl函数入口
QOpenGLShaderProgram* shaderProgram, * shadowProgram; //着色器程序
GLuint paintingIndex;
/* 函数 */
PaintingMesh(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;
};
};
}

View File

@ -6,7 +6,7 @@
#include <QScreen>
#include <QGuiApplication>
#include <random>
using namespace Renderer;
//QVector3D lightPositions[] = { 2000 * QVector3D(0.2, 4, 1).normalized(), QVector3D(100,100,100) ,QVector3D(-100,100,100) ,QVector3D(100,100,-100) };
QVector3D lightColors[] = { 20 * QVector3D(0.7529,0.7450,0.6784).normalized(), QVector3D(0,0,0) ,QVector3D(0,0,0) ,QVector3D(0,0,0) };
static float sunPitch = 105, sunYaw = 80;

View File

@ -10,59 +10,60 @@
#include "Camera.h"
#include "Light.h"
#include "Model.h"
#include "PaintingHelper.h"
class RendererGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_4_5_Compatibility
#include "Painting/PaintingHelper.h"
namespace Renderer
{
Q_OBJECT
public:
RendererGLWidget(QWidget* parent = nullptr);
~RendererGLWidget();
class RendererGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_4_5_Compatibility
{
Q_OBJECT
public:
RendererGLWidget(QWidget* parent = nullptr);
~RendererGLWidget();
void startTimer();
void stopTimer();
public slots:
void setMainLightPitch(float pitch);
void setMainLightYaw(float yaw);
protected:
void initializeGL() override;
void paintGL() override;
void resizeGL(int width, int height) override;
void timerEvent(QTimerEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
void focusInEvent(QFocusEvent* event) override;
void focusOutEvent(QFocusEvent* event) override;
void startTimer();
void stopTimer();
public slots:
void setMainLightPitch(float pitch);
void setMainLightYaw(float yaw);
protected:
void initializeGL() override;
void paintGL() override;
void resizeGL(int width, int height) override;
void timerEvent(QTimerEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
void focusInEvent(QFocusEvent* event) override;
void focusOutEvent(QFocusEvent* event) override;
private:
int timerId = -1;
int frameWidth, frameHeight;
int depthWidth, depthHeight;
QSet<int> pressedKeys;
Camera camera;
Light light;
clock_t lastFrame;
float deltaTime;
int shadowMapResolution;
QOpenGLShaderProgram* shadowProgramPtr = nullptr;
QOpenGLShaderProgram* modelProgramPtr = nullptr;
QOpenGLShaderProgram* paintingProgramPtr = nullptr;
QOpenGLShaderProgram* paintingCompProgramPtr = nullptr;
QOpenGLShaderProgram* depthInitProgramPtr = nullptr;
QOpenGLShaderProgram* depthMipmapProgramPtr = nullptr;
QOpenGLShaderProgram* shadowMappingProgramPtr = nullptr;
QOpenGLShaderProgram* ssgiProgramPtr = nullptr;
QOpenGLShaderProgram* finalProgramPtr = nullptr;
QOpenGLFramebufferObject* fboPtr = nullptr;
GLuint gbuffers[10];
GLuint shadowFboHandle = 0;
GLuint shadowGbuffer;
GLuint lightSpaceMatricesUBO;
QOpenGLBuffer quadVBO;
QOpenGLVertexArrayObject quadVAO;
Model* model;
PaintingHelper* paintingHelper;
};
private:
int timerId = -1;
int frameWidth, frameHeight;
int depthWidth, depthHeight;
QSet<int> pressedKeys;
Camera camera;
Light light;
clock_t lastFrame;
float deltaTime;
int shadowMapResolution;
QOpenGLShaderProgram* shadowProgramPtr = nullptr;
QOpenGLShaderProgram* modelProgramPtr = nullptr;
QOpenGLShaderProgram* paintingProgramPtr = nullptr;
QOpenGLShaderProgram* paintingCompProgramPtr = nullptr;
QOpenGLShaderProgram* depthInitProgramPtr = nullptr;
QOpenGLShaderProgram* depthMipmapProgramPtr = nullptr;
QOpenGLShaderProgram* shadowMappingProgramPtr = nullptr;
QOpenGLShaderProgram* ssgiProgramPtr = nullptr;
QOpenGLShaderProgram* finalProgramPtr = nullptr;
QOpenGLFramebufferObject* fboPtr = nullptr;
GLuint gbuffers[10];
GLuint shadowFboHandle = 0;
GLuint shadowGbuffer;
GLuint lightSpaceMatricesUBO;
QOpenGLBuffer quadVBO;
QOpenGLVertexArrayObject quadVAO;
Model* model;
PaintingHelper* paintingHelper;
};
}

View File

@ -1,6 +1,6 @@
#include "RendererWidget.h"
#include "RendererGLWidget.h"
using namespace Renderer;
RendererWidget::RendererWidget(QWidget *parent)
: QWidget(parent)
{

View File

@ -2,17 +2,19 @@
#include <QWidget>
#include "ui_RendererWidget.h"
class RendererWidget : public QWidget
namespace Renderer
{
Q_OBJECT
class RendererWidget : public QWidget
{
Q_OBJECT
public:
public:
RendererWidget(QWidget *parent = nullptr);
~RendererWidget();
public slots:
void currentTabChanged(int index);
private:
Ui::RendererWidgetClass ui;
};
RendererWidget(QWidget* parent = nullptr);
~RendererWidget();
public slots:
void currentTabChanged(int index);
private:
Ui::RendererWidgetClass ui;
};
}

View File

@ -1,63 +0,0 @@
#pragma once
#include "CubicBezier.h"
#include "StraightLine.h"
#include "BvhTree.h"
#include <queue>
#include <set>
using std::queue;
using std::map;
using std::for_each;
using std::set;
struct ShortCutNode {
typedef vector<Point> vectorPoint;
int windingIncrement, eastGroup;
bool divided;
/* type 代表进入广度优先搜索队列的节点种类:
0
1*/
QVector4D bound;
vector<int> lineSet;
ShortCutNode() {
divided = true;
windingIncrement = 0;
eastGroup = 0;
lineSet.clear();
bound = { 0, 0, 0, 0 };
}
~ShortCutNode() {}
};
class ShortCutTree
{
typedef vector<Point> PointVector;
typedef vector<int> PointIndexVector;
private:
vector<ShortCutNode> restOfTreeNodes;
vector<LinePtr> allLine;
int RequiredLineMin, numPoint, numLine;
map<Point, int> pointMap;
vector<int> lineIndexs;
int getPointIndex(Point nowPoint);
void generateShortCutsegmentement(ShortCutNode& nowTreeNode);
bool handleShortCutNode(ShortCutNode& fa, ShortCutNode& nowTreeNode, double yValue, vector<ShortCutNode>& v, int& sumIncrement);
void spliteToShortCutTree();
static void monotonization(vector<PointVector>& inL, vector<LinePtr> &outL);
bool isLineEqual(PointIndexVector& a, PointIndexVector& b) const;
void simplifyLineVector();
// 需要测试,随机获得合理的边界
static bool IsBorderValueResonable(double value, set <double>& valueSet);
static double findBorderValueNotOnLine(double value, set <double>& valueSet);
public:
void init();
//lineMin最小线数目即划分终止条件
ShortCutTree(int lineMin = 3)
:RequiredLineMin(lineMin), numPoint(0), numLine(0) {}
// 传入一个vector<vector<Point> > 作为所有输入的线
void buildShortCutTree(vector<PointVector>& lineSet);
// 获得点集合和线集合 返回输入BvhTree的数据集合
vector<BvhTreeData> getPointLineAndBvhTree(vector<float> &pointSet, vector<GLuint> &lineSet);
~ShortCutTree() {}
};

View File

@ -1,10 +0,0 @@
#include "Line.h"
class StraightLine : public Line
{
using Line::Line;
virtual double getLineValueByT(double t, bool isY);
virtual void monotonization(vector <LinePtr>& res) {};
virtual double findTByValue(double value, bool isY);
virtual int judgeBoundIntersection(double xy, double l, double r, bool isY);
};

View File

@ -484,7 +484,7 @@ namespace SVGParser
}
}; // namespace SVGParser
using Renderer::Point;
SvgParser::SvgParser(const std::string path, double width, double height) : path(path), width(width), height(height)
{
}

View File

@ -1,173 +1,173 @@
#pragma once
#include "Renderer/Line.h"
#include "Renderer/Painting/Line.h"
#include <cmath>
#include <string>
using namespace std;
namespace SVGParser
{
enum SVGCommandType
{
SVG_INVALID = -1,
// SVG_MOVE_TO_REL, SVG_LINE_TO_REL, SVG_QUADRATIC_CURVE_TO_REL, SVG_CUBIC_CURVE_TO_REL,
// SVG_MOVE_TO_ABS, SVG_LINE_TO_ABS, SVG_QUADRATIC_CURVE_TO_ABS, SVG_CUBIC_CURVE_TO_ABS,
SVG_MOVE_TO_REL,
SVG_MOVE_TO_ABS,
SVG_LINE_TO_REL,
SVG_LINE_TO_ABS,
SVG_HORIZONTAL_LINE_TO_REL,
SVG_HORIZONTAL_LINE_TO_ABS,
SVG_VERTICAL_LINE_TO_REL,
SVG_VERTICAL_LINE_TO_ABS,
SVG_QUADRATIC_CURVE_TO_REL,
SVG_QUADRATIC_CURVE_TO_ABS,
SVG_CUBIC_CURVE_TO_REL,
SVG_CUBIC_CURVE_TO_ABS,
SVG_SMOOTH_CUBIC_CURVE_TO_REL,
SVG_SMOOTH_CUBIC_CURVE_TO_ABS,
SVG_SMOOTH_QUADRATIC_CURVE_TO_REL,
SVG_SMOOTH_QUADRATIC_CURVE_TO_ABS,
SVG_ARC_TO_REL,
SVG_ARC_TO_ABS,
enum SVGCommandType
{
SVG_INVALID = -1,
// SVG_MOVE_TO_REL, SVG_LINE_TO_REL, SVG_QUADRATIC_CURVE_TO_REL, SVG_CUBIC_CURVE_TO_REL,
// SVG_MOVE_TO_ABS, SVG_LINE_TO_ABS, SVG_QUADRATIC_CURVE_TO_ABS, SVG_CUBIC_CURVE_TO_ABS,
SVG_MOVE_TO_REL,
SVG_MOVE_TO_ABS,
SVG_LINE_TO_REL,
SVG_LINE_TO_ABS,
SVG_HORIZONTAL_LINE_TO_REL,
SVG_HORIZONTAL_LINE_TO_ABS,
SVG_VERTICAL_LINE_TO_REL,
SVG_VERTICAL_LINE_TO_ABS,
SVG_QUADRATIC_CURVE_TO_REL,
SVG_QUADRATIC_CURVE_TO_ABS,
SVG_CUBIC_CURVE_TO_REL,
SVG_CUBIC_CURVE_TO_ABS,
SVG_SMOOTH_CUBIC_CURVE_TO_REL,
SVG_SMOOTH_CUBIC_CURVE_TO_ABS,
SVG_SMOOTH_QUADRATIC_CURVE_TO_REL,
SVG_SMOOTH_QUADRATIC_CURVE_TO_ABS,
SVG_ARC_TO_REL,
SVG_ARC_TO_ABS,
SVG_CLOSE_PATH
};
SVG_CLOSE_PATH
};
bool isAbsolute(SVGCommandType);
class SVGCommand
{
public:
SVGCommand(double, double, bool = false);
static const int length;
double x, y;
bool absolute;
virtual const std::string toString() const = 0;
virtual SVGCommandType getType() = 0;
virtual std::string toString2() = 0;
};
class SVGMoveTo : public SVGCommand
{
public:
static const int length = 2;
SVGMoveTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
bool isAbsolute(SVGCommandType);
class SVGCommand
{
public:
SVGCommand(double, double, bool = false);
static const int length;
double x, y;
bool absolute;
virtual const std::string toString() const = 0;
virtual SVGCommandType getType() = 0;
virtual std::string toString2() = 0;
};
class SVGMoveTo : public SVGCommand
{
public:
static const int length = 2;
SVGMoveTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGLineTo : public SVGCommand
{
public:
static const int length = 2;
SVGLineTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGHLineTo : public SVGCommand
{
public:
static const int length = 1;
SVGHLineTo(double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGVLineTo : public SVGCommand
{
public:
static const int length = 1;
SVGVLineTo(double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGLineTo : public SVGCommand
{
public:
static const int length = 2;
SVGLineTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGHLineTo : public SVGCommand
{
public:
static const int length = 1;
SVGHLineTo(double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGVLineTo : public SVGCommand
{
public:
static const int length = 1;
SVGVLineTo(double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGQuadraticCurveTo : public SVGCommand
{
public:
SVGQuadraticCurveTo(double, double, double, double, bool = false);
double x0, y0;
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGQuadraticCurveTo : public SVGCommand
{
public:
SVGQuadraticCurveTo(double, double, double, double, bool = false);
double x0, y0;
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGCubicCurveTo : public SVGCommand
{
public:
double x0, y0, x1, y1;
SVGCubicCurveTo(double, double, double, double, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGSmoothQuadraticCurveTo : public SVGCommand
{
public:
SVGSmoothQuadraticCurveTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGCubicCurveTo : public SVGCommand
{
public:
double x0, y0, x1, y1;
SVGCubicCurveTo(double, double, double, double, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGSmoothQuadraticCurveTo : public SVGCommand
{
public:
SVGSmoothQuadraticCurveTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGSmoothCubicCurveTo : public SVGCommand
{
public:
double x1, y1;
SVGSmoothCubicCurveTo(double, double, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGSmoothCubicCurveTo : public SVGCommand
{
public:
double x1, y1;
SVGSmoothCubicCurveTo(double, double, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGArcTo : public SVGCommand
{
public:
double rx, ry, rot;
bool large, sweep;
SVGArcTo(double, double, double, bool, bool, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGArcTo : public SVGCommand
{
public:
double rx, ry, rot;
bool large, sweep;
SVGArcTo(double, double, double, bool, bool, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGClosePath : public SVGCommand
{
public:
SVGClosePath(bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
typedef vector<std::shared_ptr<SVGCommand>> SVGPath;
SVGPath parsePath(std::istream &);
class SVGClosePath : public SVGCommand
{
public:
SVGClosePath(bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
typedef std::vector<std::shared_ptr<SVGCommand>> SVGPath;
SVGPath parsePath(std::istream&);
std::ostream &operator<<(std::ostream &, const SVGParser::SVGPath &);
std::ostream &operator<<(std::ostream &, const SVGParser::SVGCommand *);
std::ostream& operator<<(std::ostream&, const SVGParser::SVGPath&);
std::ostream& operator<<(std::ostream&, const SVGParser::SVGCommand*);
}; // namespace SVGParser
class SvgParser
{
public:
SvgParser(const std::string path, const double width, const double height);
vector<vector<Point>> parse();
public:
SvgParser(const std::string path, const double width, const double height);
std::vector<std::vector<Renderer::Point>> parse();
private:
static constexpr const double eps = 1e-6;
static constexpr const double PI = 3.14159265358979323846;
const std::string path;
const double width;
const double height;
private:
static constexpr const double eps = 1e-6;
static constexpr const double PI = 3.14159265358979323846;
const std::string path;
const double width;
const double height;
Point convertPoint(double x, double y);
Point clampPoint(Point p);
Point convertAbsPoint(double x, double y);
Point convertRelPoint(Point pointBegin, double x, double y);
void ellipticalArcConverter(Point beginPoint, double radiusX, double radiusY, double phi, bool flagA,
bool flagS, Point endPoint,vector<vector<Point>>& lines);
vector<double> centerConverter(Point beginPoint, double radiusX, double radiusY, double phi, bool flagA, bool flagS,
Point endPoint);
double angleConverter(Point u, Point v);
Point eConverter(Point c, Point r, double cosPhi, double sinPhi, double t);
Point e2Converter(Point c, Point r, double cosPhi, double sinPhi, double t);
Renderer::Point convertPoint(double x, double y);
Renderer::Point clampPoint(Renderer::Point p);
Renderer::Point convertAbsPoint(double x, double y);
Renderer::Point convertRelPoint(Renderer::Point pointBegin, double x, double y);
void ellipticalArcConverter(Renderer::Point beginPoint, double radiusX, double radiusY, double phi, bool flagA,
bool flagS, Renderer::Point endPoint, std::vector<std::vector<Renderer::Point>>& lines);
std::vector<double> centerConverter(Renderer::Point beginPoint, double radiusX, double radiusY, double phi, bool flagA, bool flagS,
Renderer::Point endPoint);
double angleConverter(Renderer::Point u, Renderer::Point v);
Renderer::Point eConverter(Renderer::Point c, Renderer::Point r, double cosPhi, double sinPhi, double t);
Renderer::Point e2Converter(Renderer::Point c, Renderer::Point r, double cosPhi, double sinPhi, double t);
};