Skip to content

Commit 40a6901

Browse files
committed
Add example of using scalar fields
1 parent 315aa66 commit 40a6901

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

docs/examples.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Loading a file
2121
.. literalinclude:: ../script_examples/loading_a_file.py
2222
:language: Python
2323

24+
Scalar Field
25+
------------
26+
27+
.. literalinclude:: ../script_examples/scalar_field.py
28+
:language: Python
29+
2430

2531
Sub sampling
2632
------------

script_examples/scalar_field.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Example that shows how to add a scalar field
2+
as well as how to make it properly be displayed in the UI
3+
"""
4+
import pycc
5+
import numpy as np
6+
7+
xs = np.arange(0.0, 5.0, 0.1, pycc.PointCoordinateType)
8+
ys = np.ones(len(xs), pycc.PointCoordinateType) * 18.5
9+
zs = np.ones(len(xs), pycc.PointCoordinateType) * 17.33
10+
11+
pc = pycc.ccPointCloud(xs, ys, zs)
12+
13+
# Create and add a new scalar field
14+
idx = pc.addScalarField("Intensity")
15+
scalar_field = pc.getScalarField(idx)
16+
17+
# Change the values
18+
sfArray = pc.getScalarField(idx).asArray()
19+
num_chunk = 4
20+
chunk_size = len(xs) // num_chunk
21+
for i in range(num_chunk):
22+
sfArray[i*chunk_size:(i+1)*chunk_size] = i
23+
24+
# Make it so the scalar field is displayed
25+
scalar_field.computeMinAndMax()
26+
pc.setCurrentDisplayedScalarField(idx)
27+
pc.showSF(True)
28+
29+
# Optional: choose the color scale
30+
scale = pycc.ccColorScalesManager.GetDefaultScale(
31+
pycc.ccColorScalesManager.YELLOW_BROWN
32+
)
33+
scalar_field.setColorScale(scale)
34+
35+
pc.setName("Scalar Field Example")
36+
# Change the point size so that the cloud is more
37+
# visible by default (only needed here as the point cloud
38+
# is very small)
39+
pc.setPointSize(7)
40+
41+
pycc.GetInstance().addToDB(pc)

0 commit comments

Comments
 (0)