-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPMVC.pys
81 lines (71 loc) · 1.76 KB
/
PMVC.pys
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
79
80
import math
def pointsOnSphere(N):
N = float(N) # in case we got an int which we surely got
pts = [[],[],[]]
inc = math.pi * (3 - math.sqrt(5))
off = 2 / N
for k in range(0, int(N)):
y = k * off - 1 + (off / 2)
r = math.sqrt(1 - y*y)
phi = k * inc
pts[0].append(math.cos(phi)*r)
pts[1].append(y)
pts[2].append(math.sin(phi)*r)
return pts
xsi = Application
sparse = 1
c = xsi.Selection(1)
cPrim = c.Activeprimitive
cGeo = cPrim.Geometry
d = xsi.Selection(0)
dGeo = d.ActivePrimitive.Geometry
dPoints = dGeo.Points
#dGeo.RemoveICEAttribute("PMVWeight")
#dGeo.RemoveICEAttribute("PMVid")
nbSample = 64
Samples = pointsOnSphere(nbSample)
PMVC = [[],[]]
area = math.pi*4/nbSample
for p in dPoints:
w = [0]*cGeo.Points.Count
pos = p.Position
lPos = [pos.X,pos.Y,pos.Z]
posArray = [[lPos[i] for j in range(nbSample)] for i in range(3)]
loc = cGeo.GetRaycastIntersections( posArray, Samples,0 )
aI = cGeo.EvaluatePositions(loc)
aCoord = cGeo.GetTriangleWeightArray(loc)
ID = cGeo.GetTriangleVertexIndexArray( loc )
for s in range(nbSample):
if ID[0][s] != -1:
dist = XSIMath.CreateVector3(aI[0][s], aI[1][s], aI[2][s])
dist.SubInPlace(pos)
distScale = 1/dist.Length()*area
x=aCoord[0][s]*distScale
y=aCoord[1][s]*distScale
z=aCoord[2][s]*distScale
w[ID[0][s]]+=x
w[ID[1][s]]+=y
w[ID[2][s]]+=z
nW = []
id = []
tW = sum(w)
if sparse == 0:
for i in w:
if i/tW < 0.000001:
nW.append(0.0)
else:
nW.append(i/tW)
PMVC[0].append(nW)
else:
j=0
for i in w:
if i/tW > 0.000001:
nW.append(i/tW)
id.append(j)
j+=1
PMVC[0].append(nW)
PMVC[1].append(id)
attr = dGeo.AddIceAttribute("PMVWeight",4,2,2)
attr.DataArray2D = PMVC[0]
attr = dGeo.AddIceAttribute("PMVID",2,2,2)
attr.DataArray2D = PMVC[1]