Skip to content

Commit 9fce94a

Browse files
committed
reduce repo size, move result to release files
0 parents  commit 9fce94a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+19181
-0
lines changed

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# Cmake files
35+
CMakeCache.txt
36+
CMakeFiles/
37+
Makefile
38+
cmake_install.cmake
39+
main
40+
41+
# R files
42+
.Rhistory
43+
result

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Trinkle
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Computational Graphics - THU Spring 2018
2+
3+
## HW1
4+
5+
光栅图形学作业 (10’)
6+
7+
实现一个感兴趣的光栅图形学算法
8+
9+
| 基本选题 | 加分项 |
10+
| ------------- | ---------------------------------------------------------- |
11+
| 画线(6’) | SSAA(2’), Kernel(2’), 区域采样(2’), 相交线反走样的case(4’) |
12+
| 画弧(8’) | 同上 |
13+
| 区域填充(10’) | 边界反走样(2’) |
14+
15+
### Result
16+
17+
图太丑了而且这个作业也很trivial就不放图了
18+
<!--![](hw1/pic/4.png)-->
19+
20+
## HW2
21+
22+
参数曲线/曲面的三维造形与渲染 (60')
23+
24+
- 利用参数曲线/曲面凹一个造型
25+
- 渲染
26+
- 基本:光线与参数曲线/曲面的求交
27+
- 其他:光子映射,加速,纹理景深,体积光等等
28+
29+
### Scoring
30+
31+
```
32+
占总评60分,按以下算法得出分值后,和全班一起归一化到70~100作为单项成绩。(负分倒扣, BUG倒扣)
33+
34+
基本功能完整性[-20, 0]: 光线跟踪基本结果,反射折射阴影
35+
实现网格化求交: [-5]
36+
实现参数曲面求交: [0, 10]: 解方程请写出求解过程,其他请写出迭代过程
37+
算法选型[0, 40]: 需要实现对应效果才为有效
38+
参考基准: PT: 15, DRT: 25, PM: 30, PPM: 30.
39+
DRT请在报告中注明使用的函数
40+
加速[0, 10]: 算法型加速为有效
41+
OpenMP: 2, GPU: 5
42+
景深/软阴影/锯齿/贴图等[0,5]
43+
主观分[-10, 10]: 设计和构图
44+
其他额外效果: 凹凸贴图、体积光等: [5, ?]
45+
```
46+
47+
代码基于smallpt,添加了纹理映射、旋转Bezier求交、景深的效果,详情可查阅 hw2/report/report.pdf
48+
49+
### Compile & Run
50+
51+
```
52+
cd sppm
53+
g++ main.cpp -oa -O3 -fopenmp
54+
```
55+
56+
由于sppm代码里面还有bug,就先没调用……实际上里面是pt的接口,当然可以直接把main函数的baseline改成sppm,不过相应的参数也要跟着改了。
57+
58+
```
59+
./a 640 480 try.ppm 10
60+
./a 3840 2160 test.ppm 100000
61+
```
62+
63+
欢迎pr!
64+
65+
### Result
66+
67+
![](hw2/report/wallpaper/small.jpg)
68+
69+
upd 191005: branch `balls` has another scenario. Here's the (p过的) result: (another is `ball_*.png`)
70+
71+
![](hw2/report/wallpaper/ball_p2.jpg)
72+
73+
## HW3
74+
75+
图像大作业 (30')
76+
77+
1. 基于优化的图像彩色化 Colorization Using Optimization, SIGGRAPH 2004.
78+
2. 内容敏感的图像缩放 Seam Carving for Content-Aware Image Resizing, SIGGRAPH 2007.
79+
3. 无缝图像拼接 Coordinates for Instant Image Cloning, SIGGRAPH 2009.
80+
81+
此处选了第三个选题,实现了MVC和Poisson Image Editing两种算法
82+
83+
### Result
84+
85+
![](hw3/MVC/pic/2_6.png)
86+
87+
## Other Result
88+
89+
### MashPlant
90+
91+
Please refer to [https://github.com/MashPlant/computational_graphics_2019](https://github.com/MashPlant/computational_graphics_2019) for more details.
92+
93+
![](result_MashPlant/finalr.jpg)
94+
95+
![](result_MashPlant/finalb.jpg)
96+
97+
![](https://github.com/MashPlant/computational_graphics_2019/blob/master/ray_tracer/readme_pic/heart_dispersion1.jpg)
98+
99+
## LICENSE
100+
101+
本项目基于Graphics A+ LICENSE,属于MIT LICENSE的一个延伸。
102+
103+
使用或者参考本仓库代码的时候,在遵循MIT LICENSE的同时,需要同时遵循以下两条规则:
104+
105+
1. 如果您有效果图,则**必须**将效果图的链接加入到这个README中,可以以PR或者ISSUE的方式让本仓库拥有者获悉;
106+
107+
2. 如果您在《计算机图形学基础》或者《高等计算机图形学》中拿到了A+的成绩,则**必须**请本仓库拥有者吃饭。

hw1/hw1.Rmd

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: "光栅图形学作业"
3+
author: "翁家翌 2016011446"
4+
date: "`r Sys.Date()`"
5+
output:
6+
pdf_document:
7+
latex_engine: xelatex
8+
number_sections: yes
9+
toc: yes
10+
word_document:
11+
toc: yes
12+
html_document:
13+
toc: yes
14+
header-includes: \usepackage{ctex}
15+
---
16+
17+
\newpage
18+
19+
# 基本选题
20+
21+
基本选题为区域填充,顺便把画线给实现了。编程语言使用的是`python3`,使用的第三方库为`opencv`。使用如下命令安装依赖包:
22+
23+
```{r, eval=FALSE}
24+
sudo pip3 install -r requirements.txt
25+
```
26+
27+
所有代码位于`main.py`中,使用命令`python3 main.py`即可运行。
28+
29+
## 画线
30+
31+
实现画线的函数为`line(p1,p2)``drawline(a,p1,p2,col)`,作用如下:
32+
33+
- `line(p1,p2)`:输入两个点坐标,默认$|p_{1_x}-p_{2_x}|\ge|p_{1_y}-p_{2_y}|$,返回一个从$p_1$到$p_2$需要着色的点的list
34+
- `drawline(a,p1,p2,col)`:输入图像矩阵a、线段起点终点和需要着色的颜色,在a中画出该线段
35+
36+
实现效果如图\ref{fig:1}所示。
37+
38+
\begin{figure}[htpb]
39+
\centering
40+
\includegraphics[width=0.5\linewidth]{pic/1.png}
41+
\caption{一个五角星}
42+
\label{fig:1}
43+
\end{figure}
44+
45+
可以看到放大之后的毛刺效果,如图\ref{fig:z1}所示。
46+
47+
\begin{figure}[htpb]
48+
\centering
49+
\includegraphics[width=0.6\linewidth]{pic/z1.png}
50+
\caption{放大之后的线段}
51+
\label{fig:z1}
52+
\end{figure}
53+
54+
## 区域填充
55+
56+
实现函数为`colorize(a,p,bg,fg)`,具体为在矩阵$a$中,以点$p$为起始点,填充颜色$fg$,默认去覆盖颜色$bg$。使用队列实现,效果如图\ref{fig:2}所示。
57+
58+
\begin{figure}[htpb]
59+
\centering
60+
\includegraphics[width=0.4\linewidth]{pic/2.png}
61+
\caption{一个白白的五角星}
62+
\label{fig:2}
63+
\end{figure}
64+
65+
可以看到毛刺效果并没有消失,如图\ref{fig:z2}所示。
66+
67+
\begin{figure}[htpb]
68+
\centering
69+
\includegraphics[width=0.6\linewidth]{pic/z2.png}
70+
\caption{放大之后的边缘}
71+
\label{fig:z2}
72+
\end{figure}
73+
74+
\newpage
75+
# 加分项
76+
77+
此处实现了反走样功能
78+
79+
## 反走样
80+
81+
反走样使用卷积操作使图像平滑,其中卷积核为
82+
83+
$$
84+
\mathfrak{F}=\frac{1}{16}\begin{bmatrix}1&2&1\\2&4&2\\1&2&1\end{bmatrix}
85+
$$
86+
87+
我自己手写了一下卷积实现(代码中91-95行,已注释),经过测试,运行效率远不如opencv中的`filter2D`函数来得快。实现反走样之后的效果如图\ref{fig:3}所示。
88+
89+
\begin{figure}[htpb]
90+
\centering
91+
\includegraphics[width=0.5\linewidth]{pic/3.png}
92+
\caption{一个没有毛刺的五角星}
93+
\label{fig:3}
94+
\end{figure}
95+
96+
可以看到边缘已经平滑,如图\ref{fig:z3}所示。
97+
98+
\begin{figure}[htpb]
99+
\centering
100+
\includegraphics[width=0.6\linewidth]{pic/z3.png}
101+
\caption{放大之后的边缘}
102+
\label{fig:z3}
103+
\end{figure}
104+
105+
出于美观角度,最后在背景中又人为地加入了一些噪点,能够拥有更好的视觉效果。最终成品如图\ref{fig:4}所示。
106+
107+
\begin{figure}[htpb]
108+
\centering
109+
\includegraphics[width=1\linewidth]{pic/4.png}
110+
\caption{一个有背景的五角星}
111+
\label{fig:4}
112+
\end{figure}

hw1/hw1.pdf

110 KB
Binary file not shown.

hw1/main.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import cv2
2+
import math
3+
import queue
4+
import random
5+
import numpy as np
6+
7+
phi=2*math.sin(math.radians(18))
8+
size,cx,cy=800,430,400
9+
bg,fg=0,255
10+
R=400
11+
r=R/(phi+2)
12+
13+
def line(p1,p2):
14+
# assume |x1-x2|>=|y1-y2|
15+
x1,y1=p1
16+
x2,y2=p2
17+
k=1.*(y2-y1)/(x2-x1)
18+
if x1>x2:
19+
x1,y1=p2
20+
x2,y2=p1
21+
result=[]
22+
while x1<=x2:
23+
result.append((int(x1+0.5),int(y1+0.5)))
24+
x1+=1
25+
y1+=k
26+
return result
27+
28+
def drawline(a,p1,p2,c):
29+
x1,y1=p1
30+
x2,y2=p2
31+
if (x1-x2)**2<(y1-y2)**2:
32+
res=line((y1,x1),(y2,x2))
33+
for y,x in res:
34+
a[x%a.shape[0],y%a.shape[1]]=c
35+
else:
36+
res=line(p1,p2)
37+
for x,y in res:
38+
a[x%a.shape[0],y%a.shape[1]]=c
39+
40+
def colorize(a,p,bg,fg):
41+
q=queue.deque()
42+
inq=np.zeros_like(a,dtype=np.uint8)
43+
q.append(p)
44+
inq[p]=1
45+
while len(q)>0:
46+
x,y=q.popleft()
47+
if x>=0 and y>=0 and x<a.shape[0] and y<a.shape[1] and a[x,y]==bg:
48+
a[x,y]=fg
49+
if inq[x-1,y]==0:
50+
q.append((x-1,y))
51+
inq[x-1,y]=1
52+
if inq[x+1,y]==0:
53+
q.append((x+1,y))
54+
inq[x+1,y]=1
55+
if inq[x,y-1]==0:
56+
q.append((x,y-1))
57+
inq[x,y-1]=1
58+
if inq[x,y+1]==0:
59+
q.append((x,y+1))
60+
inq[x,y+1]=1
61+
62+
inner=[]
63+
outer=[]
64+
for i in range(5):
65+
x,y=math.cos(math.radians(i*72))*r,math.sin(math.radians(i*72))*r
66+
inner.append((int(x+cx+0.5),int(y+cy+0.5)))
67+
x,y=math.cos(math.radians(i*72+36))*R,math.sin(math.radians(i*72+36))*R
68+
outer.append((int(x+cx+0.5),int(y+cy+0.5)))
69+
inner.append(inner[0])
70+
outer.append(outer[0])
71+
72+
a=np.ones((size,size))*bg
73+
for i in range(5):
74+
drawline(a,outer[i],inner[i+1],fg)
75+
drawline(a,inner[i],outer[i],fg)
76+
cv2.imwrite('1.png',a)
77+
cv2.imwrite('z1.png',a[200:280,290:370])
78+
print('1.png')
79+
80+
colorize(a,(cx,cy),bg,fg)
81+
cv2.imwrite('2.png',a)
82+
cv2.imwrite('z2.png',a[200:280,290:370])
83+
print('2.png')
84+
85+
filter=np.array([
86+
[1,2,1],
87+
[2,4,2],
88+
[1,2,1],
89+
])/16.
90+
b=cv2.filter2D(a,-1,filter)
91+
# b=np.zeros_like(a)
92+
# a=np.pad(a,((1,1),(1,1)),mode='constant')
93+
# for i in range(b.shape[0]):
94+
# for j in range(b.shape[1]):
95+
# b[i,j]=np.sum(a[i:i+3,j:j+3]*filter)
96+
cv2.imwrite('3.png',b)
97+
cv2.imwrite('z3.png',b[200:280,290:370])
98+
print('3.png')
99+
100+
x_=np.random.choice(b.shape[0],b.shape[0])
101+
y_=np.random.choice(b.shape[0],b.shape[0])
102+
for i in range(x_.shape[0]):
103+
b[x_[i],y_[i]]=fg
104+
cv2.imwrite('4.png',b)
105+
print('4.png')

hw1/pic/1.png

6.4 KB
Loading

hw1/pic/2.png

5.78 KB
Loading

hw1/pic/3.png

10.7 KB
Loading

hw1/pic/4.png

12.2 KB
Loading

0 commit comments

Comments
 (0)