-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathembedding.jl
78 lines (61 loc) · 2.25 KB
/
embedding.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using CompScienceMeshes
"""
Creates a predicate that checks that 2 edges belonging to `small` and `big`
lie on the same plane and the normals of its surrounding cells points in the
same direction
"""
function normal_cpredicate(small, big)
@assert dimension(small) == 2
@assert dimension(big) == 2
ss = skeleton(small,1)
sb = skeleton(big,1)
D1 = connectivity(ss,small)
D2 = connectivity(sb ,big)
function pred(e1,e2)
#TODO:Modify to take simplex rather than edge indices
edgefaces1 = D1[:,e1]
edgefaces2 = D2[:,e2]
faceid1 = edgefaces1.nzind
faceid2 = edgefaces2.nzind
N1 = length(faceid1)
N2 = length(faceid2)
narray1 = Vector{CompScienceMeshes.StaticArrays.SArray{
Tuple{3},Float64,1,3}}()
narray2 = copy(narray1)
for i = 1:N1
push!(narray1,chart(small,small.faces[faceid1[i]]).normals[1])
end
@assert all(y->y==narray1[1],narray1) "egde on small mesh found to lie on junction"
for i = 1:N2
push!(narray2,chart(big,big.faces[faceid2[i]]).normals[1])
end
@assert all(y->y==narray2[1],narray2) "egde on big mesh found to lie on junction"
return narray1[1] == narray2[1]
end
end
"""
Enforces extra constraint on edges in `small` and `big` that overlap with
edges in `pInt` during `embedding` to ensure that both edges in `small` and
`big` lie on planes with normals pointing in the same direction.
"""
function reembedding(small, big, pInt)
@assert dimension(small) == 2
@assert dimension(big) == 2
@assert dimension(pInt) == 2
ss = skeleton(small,1)
sb = skeleton(big,1)
sp = CompScienceMeshes.interior(pInt)
epred = normal_cpredicate(small,big)
overlaps = overlap_gpredicate(sp)
mpred(e1,e2) = overlaps(chart(sb,cells(sb)[e2])) ? epred(e1,e2) : true
#applies constraint during embedding only on edges that overlap with pInt
CompScienceMeshes.embedding(ss,sb,predicate=mpred)
end
isclosed(m) = (numcells(boundary(m)) == 0)
plate = meshrectangle(1.0,1.0,1.0)
G01 = CompScienceMeshes.SComplex2D(plate)
PT = weld(G01, -G01, seam=boundary(G01));
A1 = reembedding( G01, PT, G01)
A2 = reembedding(-G01, PT, G01)
@show A1
@show A2