-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce repo size, move result to release files
- Loading branch information
0 parents
commit 9fce94a
Showing
79 changed files
with
19,181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
|
||
# Cmake files | ||
CMakeCache.txt | ||
CMakeFiles/ | ||
Makefile | ||
cmake_install.cmake | ||
main | ||
|
||
# R files | ||
.Rhistory | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Trinkle | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Computational Graphics - THU Spring 2018 | ||
|
||
## HW1 | ||
|
||
光栅图形学作业 (10’) | ||
|
||
实现一个感兴趣的光栅图形学算法 | ||
|
||
| 基本选题 | 加分项 | | ||
| ------------- | ---------------------------------------------------------- | | ||
| 画线(6’) | SSAA(2’), Kernel(2’), 区域采样(2’), 相交线反走样的case(4’) | | ||
| 画弧(8’) | 同上 | | ||
| 区域填充(10’) | 边界反走样(2’) | | ||
|
||
### Result | ||
|
||
图太丑了而且这个作业也很trivial就不放图了 | ||
<!--![](hw1/pic/4.png)--> | ||
|
||
## HW2 | ||
|
||
参数曲线/曲面的三维造形与渲染 (60') | ||
|
||
- 利用参数曲线/曲面凹一个造型 | ||
- 渲染 | ||
- 基本:光线与参数曲线/曲面的求交 | ||
- 其他:光子映射,加速,纹理景深,体积光等等 | ||
|
||
### Scoring | ||
|
||
``` | ||
占总评60分,按以下算法得出分值后,和全班一起归一化到70~100作为单项成绩。(负分倒扣, BUG倒扣) | ||
基本功能完整性[-20, 0]: 光线跟踪基本结果,反射折射阴影 | ||
实现网格化求交: [-5] | ||
实现参数曲面求交: [0, 10]: 解方程请写出求解过程,其他请写出迭代过程 | ||
算法选型[0, 40]: 需要实现对应效果才为有效 | ||
参考基准: PT: 15, DRT: 25, PM: 30, PPM: 30. | ||
DRT请在报告中注明使用的函数 | ||
加速[0, 10]: 算法型加速为有效 | ||
OpenMP: 2, GPU: 5 | ||
景深/软阴影/锯齿/贴图等[0,5] | ||
主观分[-10, 10]: 设计和构图 | ||
其他额外效果: 凹凸贴图、体积光等: [5, ?] | ||
``` | ||
|
||
代码基于smallpt,添加了纹理映射、旋转Bezier求交、景深的效果,详情可查阅 hw2/report/report.pdf | ||
|
||
### Compile & Run | ||
|
||
``` | ||
cd sppm | ||
g++ main.cpp -oa -O3 -fopenmp | ||
``` | ||
|
||
由于sppm代码里面还有bug,就先没调用……实际上里面是pt的接口,当然可以直接把main函数的baseline改成sppm,不过相应的参数也要跟着改了。 | ||
|
||
``` | ||
./a 640 480 try.ppm 10 | ||
./a 3840 2160 test.ppm 100000 | ||
``` | ||
|
||
欢迎pr! | ||
|
||
### Result | ||
|
||
![](hw2/report/wallpaper/small.jpg) | ||
|
||
upd 191005: branch `balls` has another scenario. Here's the (p过的) result: (another is `ball_*.png`) | ||
|
||
![](hw2/report/wallpaper/ball_p2.jpg) | ||
|
||
## HW3 | ||
|
||
图像大作业 (30') | ||
|
||
1. 基于优化的图像彩色化 Colorization Using Optimization, SIGGRAPH 2004. | ||
2. 内容敏感的图像缩放 Seam Carving for Content-Aware Image Resizing, SIGGRAPH 2007. | ||
3. 无缝图像拼接 Coordinates for Instant Image Cloning, SIGGRAPH 2009. | ||
|
||
此处选了第三个选题,实现了MVC和Poisson Image Editing两种算法 | ||
|
||
### Result | ||
|
||
![](hw3/MVC/pic/2_6.png) | ||
|
||
## Other Result | ||
|
||
### MashPlant | ||
|
||
Please refer to [https://github.com/MashPlant/computational_graphics_2019](https://github.com/MashPlant/computational_graphics_2019) for more details. | ||
|
||
![](result_MashPlant/finalr.jpg) | ||
|
||
![](result_MashPlant/finalb.jpg) | ||
|
||
![](https://github.com/MashPlant/computational_graphics_2019/blob/master/ray_tracer/readme_pic/heart_dispersion1.jpg) | ||
|
||
## LICENSE | ||
|
||
本项目基于Graphics A+ LICENSE,属于MIT LICENSE的一个延伸。 | ||
|
||
使用或者参考本仓库代码的时候,在遵循MIT LICENSE的同时,需要同时遵循以下两条规则: | ||
|
||
1. 如果您有效果图,则**必须**将效果图的链接加入到这个README中,可以以PR或者ISSUE的方式让本仓库拥有者获悉; | ||
|
||
2. 如果您在《计算机图形学基础》或者《高等计算机图形学》中拿到了A+的成绩,则**必须**请本仓库拥有者吃饭。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
title: "光栅图形学作业" | ||
author: "翁家翌 2016011446" | ||
date: "`r Sys.Date()`" | ||
output: | ||
pdf_document: | ||
latex_engine: xelatex | ||
number_sections: yes | ||
toc: yes | ||
word_document: | ||
toc: yes | ||
html_document: | ||
toc: yes | ||
header-includes: \usepackage{ctex} | ||
--- | ||
|
||
\newpage | ||
|
||
# 基本选题 | ||
|
||
基本选题为区域填充,顺便把画线给实现了。编程语言使用的是`python3`,使用的第三方库为`opencv`。使用如下命令安装依赖包: | ||
|
||
```{r, eval=FALSE} | ||
sudo pip3 install -r requirements.txt | ||
``` | ||
|
||
所有代码位于`main.py`中,使用命令`python3 main.py`即可运行。 | ||
|
||
## 画线 | ||
|
||
实现画线的函数为`line(p1,p2)`和`drawline(a,p1,p2,col)`,作用如下: | ||
|
||
- `line(p1,p2)`:输入两个点坐标,默认$|p_{1_x}-p_{2_x}|\ge|p_{1_y}-p_{2_y}|$,返回一个从$p_1$到$p_2$需要着色的点的list | ||
- `drawline(a,p1,p2,col)`:输入图像矩阵a、线段起点终点和需要着色的颜色,在a中画出该线段 | ||
|
||
实现效果如图\ref{fig:1}所示。 | ||
|
||
\begin{figure}[htpb] | ||
\centering | ||
\includegraphics[width=0.5\linewidth]{pic/1.png} | ||
\caption{一个五角星} | ||
\label{fig:1} | ||
\end{figure} | ||
|
||
可以看到放大之后的毛刺效果,如图\ref{fig:z1}所示。 | ||
|
||
\begin{figure}[htpb] | ||
\centering | ||
\includegraphics[width=0.6\linewidth]{pic/z1.png} | ||
\caption{放大之后的线段} | ||
\label{fig:z1} | ||
\end{figure} | ||
|
||
## 区域填充 | ||
|
||
实现函数为`colorize(a,p,bg,fg)`,具体为在矩阵$a$中,以点$p$为起始点,填充颜色$fg$,默认去覆盖颜色$bg$。使用队列实现,效果如图\ref{fig:2}所示。 | ||
|
||
\begin{figure}[htpb] | ||
\centering | ||
\includegraphics[width=0.4\linewidth]{pic/2.png} | ||
\caption{一个白白的五角星} | ||
\label{fig:2} | ||
\end{figure} | ||
|
||
可以看到毛刺效果并没有消失,如图\ref{fig:z2}所示。 | ||
|
||
\begin{figure}[htpb] | ||
\centering | ||
\includegraphics[width=0.6\linewidth]{pic/z2.png} | ||
\caption{放大之后的边缘} | ||
\label{fig:z2} | ||
\end{figure} | ||
|
||
\newpage | ||
# 加分项 | ||
|
||
此处实现了反走样功能 | ||
|
||
## 反走样 | ||
|
||
反走样使用卷积操作使图像平滑,其中卷积核为 | ||
|
||
$$ | ||
\mathfrak{F}=\frac{1}{16}\begin{bmatrix}1&2&1\\2&4&2\\1&2&1\end{bmatrix} | ||
$$ | ||
|
||
我自己手写了一下卷积实现(代码中91-95行,已注释),经过测试,运行效率远不如opencv中的`filter2D`函数来得快。实现反走样之后的效果如图\ref{fig:3}所示。 | ||
|
||
\begin{figure}[htpb] | ||
\centering | ||
\includegraphics[width=0.5\linewidth]{pic/3.png} | ||
\caption{一个没有毛刺的五角星} | ||
\label{fig:3} | ||
\end{figure} | ||
|
||
可以看到边缘已经平滑,如图\ref{fig:z3}所示。 | ||
|
||
\begin{figure}[htpb] | ||
\centering | ||
\includegraphics[width=0.6\linewidth]{pic/z3.png} | ||
\caption{放大之后的边缘} | ||
\label{fig:z3} | ||
\end{figure} | ||
|
||
出于美观角度,最后在背景中又人为地加入了一些噪点,能够拥有更好的视觉效果。最终成品如图\ref{fig:4}所示。 | ||
|
||
\begin{figure}[htpb] | ||
\centering | ||
\includegraphics[width=1\linewidth]{pic/4.png} | ||
\caption{一个有背景的五角星} | ||
\label{fig:4} | ||
\end{figure} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import cv2 | ||
import math | ||
import queue | ||
import random | ||
import numpy as np | ||
|
||
phi=2*math.sin(math.radians(18)) | ||
size,cx,cy=800,430,400 | ||
bg,fg=0,255 | ||
R=400 | ||
r=R/(phi+2) | ||
|
||
def line(p1,p2): | ||
# assume |x1-x2|>=|y1-y2| | ||
x1,y1=p1 | ||
x2,y2=p2 | ||
k=1.*(y2-y1)/(x2-x1) | ||
if x1>x2: | ||
x1,y1=p2 | ||
x2,y2=p1 | ||
result=[] | ||
while x1<=x2: | ||
result.append((int(x1+0.5),int(y1+0.5))) | ||
x1+=1 | ||
y1+=k | ||
return result | ||
|
||
def drawline(a,p1,p2,c): | ||
x1,y1=p1 | ||
x2,y2=p2 | ||
if (x1-x2)**2<(y1-y2)**2: | ||
res=line((y1,x1),(y2,x2)) | ||
for y,x in res: | ||
a[x%a.shape[0],y%a.shape[1]]=c | ||
else: | ||
res=line(p1,p2) | ||
for x,y in res: | ||
a[x%a.shape[0],y%a.shape[1]]=c | ||
|
||
def colorize(a,p,bg,fg): | ||
q=queue.deque() | ||
inq=np.zeros_like(a,dtype=np.uint8) | ||
q.append(p) | ||
inq[p]=1 | ||
while len(q)>0: | ||
x,y=q.popleft() | ||
if x>=0 and y>=0 and x<a.shape[0] and y<a.shape[1] and a[x,y]==bg: | ||
a[x,y]=fg | ||
if inq[x-1,y]==0: | ||
q.append((x-1,y)) | ||
inq[x-1,y]=1 | ||
if inq[x+1,y]==0: | ||
q.append((x+1,y)) | ||
inq[x+1,y]=1 | ||
if inq[x,y-1]==0: | ||
q.append((x,y-1)) | ||
inq[x,y-1]=1 | ||
if inq[x,y+1]==0: | ||
q.append((x,y+1)) | ||
inq[x,y+1]=1 | ||
|
||
inner=[] | ||
outer=[] | ||
for i in range(5): | ||
x,y=math.cos(math.radians(i*72))*r,math.sin(math.radians(i*72))*r | ||
inner.append((int(x+cx+0.5),int(y+cy+0.5))) | ||
x,y=math.cos(math.radians(i*72+36))*R,math.sin(math.radians(i*72+36))*R | ||
outer.append((int(x+cx+0.5),int(y+cy+0.5))) | ||
inner.append(inner[0]) | ||
outer.append(outer[0]) | ||
|
||
a=np.ones((size,size))*bg | ||
for i in range(5): | ||
drawline(a,outer[i],inner[i+1],fg) | ||
drawline(a,inner[i],outer[i],fg) | ||
cv2.imwrite('1.png',a) | ||
cv2.imwrite('z1.png',a[200:280,290:370]) | ||
print('1.png') | ||
|
||
colorize(a,(cx,cy),bg,fg) | ||
cv2.imwrite('2.png',a) | ||
cv2.imwrite('z2.png',a[200:280,290:370]) | ||
print('2.png') | ||
|
||
filter=np.array([ | ||
[1,2,1], | ||
[2,4,2], | ||
[1,2,1], | ||
])/16. | ||
b=cv2.filter2D(a,-1,filter) | ||
# b=np.zeros_like(a) | ||
# a=np.pad(a,((1,1),(1,1)),mode='constant') | ||
# for i in range(b.shape[0]): | ||
# for j in range(b.shape[1]): | ||
# b[i,j]=np.sum(a[i:i+3,j:j+3]*filter) | ||
cv2.imwrite('3.png',b) | ||
cv2.imwrite('z3.png',b[200:280,290:370]) | ||
print('3.png') | ||
|
||
x_=np.random.choice(b.shape[0],b.shape[0]) | ||
y_=np.random.choice(b.shape[0],b.shape[0]) | ||
for i in range(x_.shape[0]): | ||
b[x_[i],y_[i]]=fg | ||
cv2.imwrite('4.png',b) | ||
print('4.png') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
opencv-python | ||
numpy | ||
|
Binary file not shown.
Oops, something went wrong.