Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
6c3e3bd
create CatmullClarkSubdivision.py and draw.py
X-wenhao Jun 6, 2018
92ababe
add build_index
X-wenhao Jun 8, 2018
6954f2e
DOO_Sabin begin
Shirhockton Jun 9, 2018
388002e
DOO_Sabin
Shirhockton Jun 9, 2018
8fb0347
add CCin
X-wenhao Jun 9, 2018
8a4090b
finish CatmullClarkSubdividion_in
X-wenhao Jun 9, 2018
0f66d14
DOO_Sabin
Shirhockton Jun 10, 2018
f297222
finish draw
X-wenhao Jun 10, 2018
01ef5a5
remove draw from division
X-wenhao Jun 11, 2018
6e9e38a
fix a bug in CCDivision
X-wenhao Jun 11, 2018
c5b6444
loop subdivision
JILLWONG Jun 12, 2018
b81d442
Merge pull request #2 from JILLWONG/master
X-wenhao Jun 12, 2018
e904186
Merge pull request #1 from Shirhockton/master
X-wenhao Jun 12, 2018
85e5f8f
Create loop2
Moonflynn Jun 13, 2018
cb997af
update
Moonflynn Jun 13, 2018
8b1c7f4
Update loop2.py
Moonflynn Jun 13, 2018
48ef0c4
Update loop2.py
Moonflynn Jun 13, 2018
c32fd36
Update loop2.py
Moonflynn Jun 13, 2018
72e2e5e
Update loop2.py
Moonflynn Jun 13, 2018
c0f356d
Update loop2.py
Moonflynn Jun 13, 2018
99b70c1
fix a bug
X-wenhao Jun 15, 2018
6980533
Merge branch 'master' of github.com:X-wenhao/relaxrender
X-wenhao Jun 15, 2018
5405c03
tian's work
Shirhockton Jun 15, 2018
ab55678
tian's work
Shirhockton Jun 15, 2018
43caf79
Merge pull request #3 from feature2/master
X-wenhao Jun 15, 2018
828efcc
Merge pull request #4 from Shirhockton/master
X-wenhao Jun 15, 2018
e9d435c
to merge
X-wenhao Jun 15, 2018
cac8fba
Merge branch 'master' of github.com:X-wenhao/relaxrender
X-wenhao Jun 15, 2018
1a01142
move
JILLWONG Jun 15, 2018
e8a117e
edit
JILLWONG Jun 15, 2018
21c2fbd
tian's work
Shirhockton Jun 15, 2018
2c83e2d
change draw and add test to it
X-wenhao Jun 15, 2018
46e128c
Merge pull request #5 from JILLWONG/master
X-wenhao Jun 15, 2018
f7e12f0
Merge pull request #6 from Shirhockton/master
X-wenhao Jun 15, 2018
7fe17cc
Merge branch 'master' of github.com:X-wenhao/relaxrender
X-wenhao Jun 15, 2018
a34ea3b
tian's work
Shirhockton Jun 15, 2018
0e57e8d
change name
X-wenhao Jun 15, 2018
9b45bcb
rename
JILLWONG Jun 15, 2018
c2f609c
Merge pull request #8 from Shirhockton/master
X-wenhao Jun 15, 2018
dd4661b
Merge pull request #9 from JILLWONG/master
X-wenhao Jun 15, 2018
547b1f2
Create design
494727889 Jun 15, 2018
2bfd00b
Create rela_tes
494727889 Jun 15, 2018
1035887
Update rela_tes
494727889 Jun 15, 2018
e07fd87
Create sce
494727889 Jun 15, 2018
7e03c3d
add annotation
X-wenhao Jun 15, 2018
623da30
Merge pull request #10 from 494727889/master
X-wenhao Jun 15, 2018
fc3e759
move file to test
X-wenhao Jun 15, 2018
93ce598
tian's work
Shirhockton Jun 16, 2018
1cce086
Merge pull request #11 from Shirhockton/master
X-wenhao Jun 16, 2018
a48820c
finish part of test
X-wenhao Jun 16, 2018
d879b07
tian's work
Shirhockton Jun 16, 2018
e8590f9
Merge pull request #12 from Shirhockton/master
X-wenhao Jun 16, 2018
fd8068f
add test
JILLWONG Jun 16, 2018
c90303c
Merge pull request #13 from JILLWONG/master
X-wenhao Jun 16, 2018
546828b
modified
JILLWONG Jun 17, 2018
791e1a8
tian's work
Shirhockton Jun 17, 2018
a17310b
Merge pull request #14 from JILLWONG/master
X-wenhao Jun 17, 2018
a59b413
Merge pull request #15 from Shirhockton/master
X-wenhao Jun 17, 2018
dcfdde4
tian's work
Shirhockton Jun 17, 2018
46a8877
move file
X-wenhao Jun 17, 2018
37753f8
add .idea/ to .gitignore
X-wenhao Jun 17, 2018
2e39012
fix a bug in test
X-wenhao Jun 17, 2018
eff62d0
change code
X-wenhao Jun 17, 2018
96b726d
Merge pull request #16 from Shirhockton/master
X-wenhao Jun 17, 2018
dc4f651
tian
Shirhockton Jun 17, 2018
836ba25
Merge pull request #17 from Shirhockton/master
X-wenhao Jun 17, 2018
91f865f
fix my code
X-wenhao Jun 17, 2018
e8887e0
hhhh
WteezzZ Jun 17, 2018
c73b9e9
Merge pull request #18 from WteezzZ/master
X-wenhao Jun 17, 2018
7718d66
Delete output_points.jpg
X-wenhao Jun 17, 2018
88f1ba6
organize the files
X-wenhao Jun 17, 2018
1739a16
delete some unused func
X-wenhao Jun 18, 2018
93339e5
Delete output_points.jpg
X-wenhao Jun 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ build
.coverage
.pytest_cache/
htmlcov/

132 changes: 132 additions & 0 deletions features/SubdivisionSurface/CatmullClarkSubdivision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
'''
This module uses Catmull Clark Subdivision
The interface is CatmullClarkSubdivision function
'''

from relaxrender.triangle import Triangle,Triangles
from relaxrender.points import Point,Point3D
import numpy as np

__author__="X-wenhao"

'''
interface
param:
faces : [face,face,...]
face: [line,line,...]
line: [point,point]
point: Point
num:how many times you want to subdivide
return:
faces
'''
def CatmullClarkSubdivision(faces,num):
lines=[]
points=[]
face_to_lines={}
line_to_points={}
point_to_lines={}
line_to_faces={}

for i in range(num):
lines,line_to_faces,face_to_lines=_build_index(faces)
#print(line_to_faces,face_to_lines)
points,point_to_lines,line_to_points=_build_index(lines)
#draw(face_to_lines,line_to_points,points)
#print("lines:",lines)
faces=_CatmullClarkSubdivision_in(faces,lines,points,face_to_lines,line_to_points,line_to_faces,point_to_lines)
return faces

'''
to build index among face line and point
I design this function and try to form index after each division to reduce time,but fail
'''
def _build_index(faces):
lines=[]
face_to_lines={}
line_to_faces={}
for face_i in range(len(faces)):
face=faces[face_i]
face_to_lines[face_i]=[]
for line_i in range(len(faces[face_i])):
line=face[line_i]
if line not in lines:
lines.append(line)
line_to_faces[len(lines)-1]=[]
face_to_lines[face_i].append(lines.index(line))
line_to_faces[lines.index(line)].append(face_i)
return lines,line_to_faces,face_to_lines



'''
subdivide a model according to its points and faces
return points and faces after subdivision

param:
faces : [face,face,...]
face: [line,line,...]
line: [point,point]
point: Point
return:
[points,faces]

PS:this func is not designed as a interface
'''
def _CatmullClarkSubdivision_in(faces,lines,points,face_to_lines,line_to_points,line_to_faces,point_to_lines):
#print("old_points:",list((p.data[0],p.data[1],p.data[2]) for p in points))
#print("face_to_lines:",face_to_lines)
#print("line_to_points:",line_to_points)
#print("line_to_faces:",line_to_faces)
#print("point_to_lines:",point_to_lines)
face_points=[]
for face in faces:
temp=[]
for l in face:
temp.append(l[0].data)
temp.append(l[1].data)
data=sum(temp)/2/len(face)
face_points.append(Point(p=Point3D.create(data)))
#print("face_points:",len(face_points),list((p.data[0],p.data[1],p.data[2]) for p in face_points))

edge_points=[]

for i in range(len(lines)):
temp=[]
temp.append(face_points[line_to_faces[i][0]].data)
temp.append(face_points[line_to_faces[i][1]].data)
temp.append(points[line_to_points[i][0]].data)
temp.append(points[line_to_points[i][1]].data)
data=sum(temp)/4
edge_points.append(Point(p=Point3D.create(data)))
#print("edge_points:",list((p.data[0],p.data[1],p.data[2]) for p in edge_points))

vertes_points=[]
for i in range(len(points)):
data1=np.array([0.0,0.0,0.0])
data2=np.array([0.0,0.0,0.0])
for j in point_to_lines[i]:
data1+=(lines[j][0].data+lines[j][1].data)/2.0/len(point_to_lines[i])
data2+=(face_points[line_to_faces[j][0]].data+face_points[line_to_faces[j][1]].data)/2/len(point_to_lines[i])
points[i].data=(data2+2*data1+(len(point_to_lines[i])-3)*points[i].data)/len(point_to_lines[i])
#print("new_points:",list((p.data[0],p.data[1],p.data[2]) for p in points))

re_faces=[]
for i in range(len(face_points)):
tmp=[]
for j in face_to_lines[i]:
for k in line_to_points[j]:
if k not in tmp:
re_faces.append([])
#print(point_to_lines[k],face_to_lines[i])
eps=list(edge_points[p_i] for p_i in [m for m in point_to_lines[k] if m in face_to_lines[i]] )
#print(eps)
for ep in eps:
re_faces[-1].extend([ [face_points[i],ep],[points[k],ep] ])
tmp.append(k)
#print(len(re_faces),'\n',re_faces[0])
return re_faces




207 changes: 207 additions & 0 deletions features/SubdivisionSurface/DOOSabinSubdivision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import numpy as np
from relaxrender.points import Point3D, Point

# points_doos=list()
# points_current=list()

'''
one point for another ones on the faces beside it
'''
# points_doos={}
current_points = []
current_faces = []
points_doos = []


class Face:
def __init__(self, points):
self.points = points


"""
DOO_Sabin(faces,times):
input:faces(list) , subdivision times
output:new faces(list)



faces :list of face
face : points : list of point
"""

def DOO_Sabin(faces,times):
new_faces=[]
for f in faces:
n_f=Face(f)
new_faces.append(n_f)
for i in range(0,times):
_DOO_Sabin_single_time(new_faces)
return new_faces


# class points_doo:
# def __init__(self,main_point,points):
# self.main_point=main_point
# self.points=points
# def add_point(self,p):
# self.points.append(p)

'''
def _change_faces(x_faces):
s_faces=[]
for f in x_faces:
new_points=[]
for l in f:
new_points.append(l[0])
new_points.append(l[1])
new_f=new_points
s_faces.append(new_f)
return s_faces
'''


def _DOO_Sabin_single_time(faces):
for f in faces:
f = _get_new_face(f)
for points_ds in points_doos:
new_face = Face(points_ds)
faces.append(new_face)
return faces


def _get_face_point(face):
face_point = _get_average_point(face.points)
return face_point


'''
for each point in a face, there would be a new point
'''


def _get_new_face(face):
face_point = _get_face_point(face)
new_face_points = []
for p in face.points:

'''
_______global variables_______
'''
if p not in current_points:
current_points.append(p)
flag = True
else:
flag=False

if face.points.index(p) == 0:
tmp1 = len(face.points) - 1
tmp2 = face.points.index(p) + 1

elif face.points.index(p) == len(face.points) - 1:
tmp1 = face.points.index(p) - 1
tmp2 = 0
else:
tmp1 = face.points.index(p) - 1
tmp2 = face.points.index(p) + 1

last_average_line = _get_average_point([p, face.points[tmp1]])
next_average_line = _get_average_point([p, face.points[tmp2]])

new_face_point = _get_average_point([p, face_point, last_average_line, next_average_line])

new_face_points.append(new_face_point)

# '''
# append p's points
# '''
# if points_doos.has_key(p):
# p_points = points_doos[p]
# p_points.append(new_face_point)
# '''
# _______global variables_______
# '''
# points_doos[p] = p_points
# else:
# p_points=[new_face_point,]
# p_points.append(new_face_point)
# '''
# _______global variables_______
# '''
# points_doos[p]=p_points
if flag:
points_doos.append([new_face_point, ])
else:
points_doos[current_points.index(p)].append(new_face_point)

face.points = new_face_points
new_face=Face(new_face_points)
return new_face


def _get_average_point(points):
x_sum = 0
y_sum = 0
z_sum = 0
for p in points:
x_sum = x_sum + p.data[0]
y_sum = y_sum + p.data[1]
z_sum = z_sum + p.data[2]
Apoint = Point3D(x_sum / len(points), y_sum / len(points), z_sum / len(points))
return Apoint


'''
def _print_point(p):
tmp = [p.data[0], p.data[1], p.data[2]]
print(tmp)

def _print_face(f):
for p in f.points:
_print_point(p)

def _print_points(ps):
for p in ps:
_print_point(p)

def print_obj(faces):
i=0
for f in faces:
i=i+1
print("face",i)
_print_face(f)

def _change_point(point,color):
new_point=Point(point)
new_point.color=color
return new_point
'''


"""
test:
input: cube's faces,6 times
output:new faces
"""
# if __name__ == '__main__':
# point_test_1 = Point3D(4, 4, 4)
# point_test_2 = Point3D(4, 4,0)
# point_test_3 = Point3D(4, 0, 4)
# point_test_4 = Point3D(4, 0, 0)
# point_test_5 = Point3D(0, 4, 4)
# point_test_6 = Point3D(0, 4, 0)
# point_test_7 = Point3D(0, 0, 4)
# point_test_8 = Point3D(0, 0, 0)
# face_test_1 = Face([point_test_1, point_test_2, point_test_3, point_test_4])
# face_test_2 = Face([point_test_1, point_test_5, point_test_6, point_test_2])
# face_test_3 = Face([point_test_1, point_test_5, point_test_7, point_test_3])
# face_test_4 = Face([point_test_3, point_test_4, point_test_8, point_test_7])
# face_test_5 = Face([point_test_5, point_test_6, point_test_8, point_test_7])
# face_test_6 = Face([point_test_2, point_test_4, point_test_8, point_test_6])
# faces_test=[face_test_1,face_test_2,face_test_3,face_test_4,face_test_5,face_test_6]
# _print_obj(DOO_Sabin(faces_test,6))
# # points_test=[point_test_1,point_test_2,point_test_3,point_test_4]
# # face_test=Face(points_test)
# # _print_face(_get_new_face(face_test))
# # for ps in points_doos:
# # _print_points(ps)
#
Loading