pyCAPS
pyCAPS: A Python Extension Module for CAPS
webviewer.py

Basic example use case for creating visualizing data using CAPS's web viewer pyCAPS.capsViewer

1 from pyCAPS import capsViewer
2 
3 # Initialize viewer
4 viewer = capsViewer()
5 
6 # Define nodes
7 nodes = [ [0, 0, 0],
8  [1, 1, 0],
9  [0, 1, 0],
10  [2, 0, 0],
11  [2, 2, 0],
12  [3, 2, 0],
13  [5, 0, 0],
14  [7, 3, 0]]
15 
16 # Define element connectivity
17 connectivity = [ [1, 2, 3],
18  [1, 4, 2],
19  [4, 5, 2],
20  [6, 5, 4],
21  [4, 7, 8, 6]]
22 
23 # Define scalar data at nodes
24 color = [1, 1, 2, 2, 4, 2, 3, 4]
25 
26 # Add nodes
27 viewer.addVertex( nodes)
28 
29 # Add element connectivity
30 viewer.addIndex( connectivity)
31 
32 # Add color/scalar data values at nodes
33 viewer.addColor( color)
34 
35 # Add second set of values
36 color = [0, 30, 40, 50, 60, 90, 10, 100]
37 viewer.addColor( color, name = "Color 2")
38 
39 # Add "mesh" connectivity - enables ploting the elemental mesh
40 viewer.addLineIndex(connectivity)
41 
42 # Set mesh color - a single value set a monotone color
43 viewer.addLineColor(1, colorMap = "grey")
44 
45 # Take all current "items" that have been added and create a triangle graphic primitive
46 viewer.createTriangle()
47 
48 # Start the webserver
49 viewer.startServer()
50 
51 # Optionally during each "add" function call we could have kept track of the "items"
52 # being created and explicitly used them to create the triangle graphic primitive.
53 #
54 # For example:
55 #
56 # Setup empty list to hold wvItems
57 #itemList = []
58 
59 #itemList.append(viewer.addVertex( nodes )
60 
61 #itemList.append(viewer.addIndex( connectivity ))
62 
63 #itemList.append(viewer.addColor( color ))
64 
65 #itemList.append(viewer.addLineIndex( connectivity ))
66 
67 #itemList.append(viewer.addLineColor( 1, "grey" ))
68 
69 #viewer.createTriangle(itemList)
70