Skip to content

Commit

Permalink
Update docs /examples page and add those to the demo folder
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoledoux committed Mar 11, 2024
1 parent 6309a80 commit fc0a975
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 5 deletions.
9 changes: 9 additions & 0 deletions demo/example_exporting_geojson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import startinpy
import numpy as np

#-- generate 100 points randomly in the plane
rng = np.random.default_rng(seed=42)
pts = rng.random((100, 3))
dt = startinpy.DT()
dt.insert(pts, insertionstrategy="AsIs")
dt.write_geojson("myfile.geojson")
13 changes: 13 additions & 0 deletions demo/example_exporting_meshio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import startinpy
import meshio
import laspy
import numpy as np

las = laspy.read("../data/small.laz")
pts = np.vstack((las.x, las.y, las.z)).transpose()
dt = startinpy.DT()
dt.insert(pts)
vs = dt.points
vs[0] = vs[1] #-- to ensure that infinite vertex is not blocking the viz
cells = [("triangle", dt.triangles)]
meshio.write_points_cells("mydt.vtu", vs, cells)
18 changes: 18 additions & 0 deletions demo/example_matplotlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import startinpy
import numpy as np

#-- generate 100 points randomly in the plane
rng = np.random.default_rng(seed=42)
pts = rng.random((100, 3))
#-- scale to [0, 100]
pts = pts * 100
t = startinpy.DT()
t.insert(pts)
pts = t.points
trs = t.triangles
#-- plot
import matplotlib.pyplot as plt
plt.triplot(pts[:,0], pts[:,1], trs)
#-- the vertex "0" shouldn't be plotted, so start at 1
plt.plot(pts[1:,0], pts[1:,1], 'o')
plt.show()
27 changes: 27 additions & 0 deletions demo/example_polyscope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import startinpy
import numpy as np
import polyscope as ps
import laspy

las = laspy.read("../data/small.laz")
pts = np.vstack((las.x, las.y, las.z)).transpose()
pts = pts[::10] #-- thinning to speed up, put ::10 to keep 1/10 of the points
dt = startinpy.DT()
dt.insert(pts)

pts = dt.points
pts[0] = pts[1] #-- first vertex has inf and could mess things
trs = dt.triangles

ps.init()
ps.set_program_name("mydt")
ps.set_up_dir("z_up")
ps.set_ground_plane_mode("shadow_only")
ps.set_ground_plane_height_factor(0.01, is_relative=True)
ps.set_autocenter_structures(True)
ps.set_autoscale_structures(True)
pc = ps.register_point_cloud("mypoints", pts[1:], radius=0.0015, point_render_mode='sphere')
ps_mesh = ps.register_surface_mesh("mysurface", pts, trs)
ps_mesh.reset_transform()
pc.reset_transform()
ps.show()
20 changes: 20 additions & 0 deletions demo/example_reading_geotiff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import startinpy
import rasterio
import random

d = rasterio.open('../data/dem_01.tif')
band1 = d.read(1)
t = d.transform
pts = []
for i in range(band1.shape[0]):
for j in range(band1.shape[1]):
x = t[2] + (j * t[0]) + (t[0] / 2)
y = t[5] + (i * t[4]) + (t[4] / 2)
z = band1[i][j]
if (z != d.nodatavals) and (random.randint(0, 100) == 5):
pts.append([x, y, z])
dt = startinpy.DT()
dt.insert(pts, insertionstrategy="BBox")
#-- exaggerate the elevation by a factor 2.0
dt.vertical_exaggeration(2.0)
dt.write_ply("mydt.ply")
11 changes: 11 additions & 0 deletions demo/example_reading_laz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import startinpy
import numpy as np
import laspy

las = laspy.read("../data/small.laz")
pts = np.vstack((las.x, las.y, las.z)).transpose()
pts = pts[::1] #-- thinning to speed up, put ::10 to keep 1/10 of the points
dt = startinpy.DT()
dt.insert(pts)
print("number vertices:", dt.number_of_vertices())
# -- number vertices: 39231
13 changes: 8 additions & 5 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pts = np.vstack((las.x, las.y, las.z)).transpose()
pts = pts[::1] #-- thinning to speed up, put ::10 to keep 1/10 of the points
dt = startinpy.DT()
dt.insert(pts)
print("# vertices:", dt.number_of_vertices())
print("number vertices:", dt.number_of_vertices())
```

## Exporting the DT to GeoJSON
Expand All @@ -28,18 +28,21 @@ rng = np.random.default_rng(seed=42)
pts = rng.random((100, 3))
dt = startinpy.DT()
dt.insert(pts, insertionstrategy="AsIs")
dt.write_geojson("/home/elvis/myfile.geojson")
dt.write_geojson("myfile.geojson")
```

## Exporting the DT to several mesh formats with [meshio](https://github.com/nschloe/meshio)

```python
import startinpy
import meshio
import laspy
import numpy as np

las = laspy.read("myfile.laz")
las = laspy.read("../data/small.laz")
pts = np.vstack((las.x, las.y, las.z)).transpose()
dt = startinpy.DT(pts)
dt = startinpy.DT()
dt.insert(pts)
vs = dt.points
vs[0] = vs[1] #-- to ensure that infinite vertex is not blocking the viz
cells = [("triangle", dt.triangles)]
Expand All @@ -63,7 +66,7 @@ import startinpy
import rasterio
import random

d = rasterio.open('data/dem_01.tif')
d = rasterio.open('../data/dem_01.tif')
band1 = d.read(1)
t = d.transform
pts = []
Expand Down

0 comments on commit fc0a975

Please sign in to comment.