File: gfx_mapslab.py

package info (click to toggle)
openstructure 2.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 206,240 kB
  • sloc: cpp: 188,571; python: 36,686; ansic: 34,298; fortran: 3,275; sh: 312; xml: 146; makefile: 29
file content (58 lines) | stat: -rw-r--r-- 1,629 bytes parent folder | download | duplicates (4)
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
import math,random
from ost import img

# remove all objects from scene, just in case
scene.RemoveAll()

vmax=-10000.0
vmin=+10000.0
mh=img.CreateMap(img.Size(32,32,32))
for p in img.ExtentIterator(mh.GetExtent()):
  val=5*math.sin(0.4*math.sqrt(p[0]*p[0]+p[1]*p[1]))+7*math.cos(0.6*math.sqrt(p[2]*p[2]+p[1]*p[1]))
  mh.SetReal(p,val)
  vmin=min(vmin,val)
  vmax=max(vmax,val)
print(vmin, vmax)
for p in img.ExtentIterator(mh.GetExtent()):
  mh.SetReal(p,(mh.GetReal(p)-vmin)/(vmax-vmin))

pl = gfx.PrimList("box")
edge_list=[[[0,0,0],[0,1,0]],
           [[0,1,0],[1,1,0]],
           [[1,1,0],[1,0,0]],
           [[1,0,0],[0,0,0]],
           [[0,0,0],[0,0,1]],
           [[0,1,0],[0,1,1]],
           [[1,1,0],[1,1,1]],
           [[1,0,0],[1,0,1]],
           [[0,0,1],[0,1,1]],
           [[0,1,1],[1,1,1]],
           [[1,1,1],[1,0,1]],
           [[1,0,1],[0,0,1]]]

corners = [mh.IndexToCoord(mh.GetExtent().GetStart()),mh.IndexToCoord(mh.GetExtent().GetEnd())]

for e in edge_list:
    pl.AddLine(geom.Vec3(corners[e[0][0]][0],
                    corners[e[0][1]][1],
                    corners[e[0][2]][2]),
               geom.Vec3(corners[e[1][0]][0],
                    corners[e[1][1]][1],
                    corners[e[1][2]][2]),
               gfx.Color(1,1,0))

scene.Add(pl)
scene.SetCenter(pl.GetCenter())

go1=gfx.MapIso("iso", mh,0.5)
go1.SetLineWidth(1.5)
scene.Add(go1)
scene.SetCenter(go1.GetCenter())


go2 = gfx.MapSlab("slab",mh,geom.Plane(go1.GetCenter(),geom.Vec3(0.0,0.0,1.0)))
scene.Add(go2)

go2.ColorBy('HEAT_MAP',0.2,0.8)

print('Demo 4: Projecting the density of a map onto a plane...')