Comments (6)
Sorry I didn’t get back to you earlier.
Send me the link via Slack and I’ll see if I can make it work with some of my personal tools.
from pyvista-support.
@daavoo, is this something PyntCloud could handle?
from pyvista-support.
@akaszynski - have you ever needed to decimate large meshes like this? Any ideas on why the decimate
and decimate_pro
filters might be taking a very long time?
from pyvista-support.
One solution I have discovered is to leave the meshes in 2D (z variation being none - there's a commented out portion in read_lidar_img
to control this) with the elevation values as a scalar array then use the .sample
filter onto another planar surface with the desired resolution.
...
# Merge into a single mesh - this takes ~1 minute to execute
geom = all_surfaces.extract_geometry()
grid = pv.create_grid(geom, (1000,1000,1))
low_res = grid.sample(geom)
# Address bug with resample filter for no-data points
low_res['lidar'][np.argwhere(foo['vtkValidPointMask'] == 0)] = np.nan
low_res['lidar'][low_res['lidar'] == -1.000e+38] = np.nan
# Make a 3D surface and render
surf = low_res.threshold().warp_by_scalar()
surf.plot(scalars='lidar', notebook=False,
cmap='gist_earth', enable_eye_dome_lightin=True)
Which renders in milliseconds with 596451 cells and 598810 points:
from pyvista-support.
Cheated a little bit since it was structured.
You'll have to change the indexing a little bit since there's some holes in the data now.
# this is new:
from tqdm import tqdm
import pyvista as pv
import xarray as xr
import numpy as np
import glob
import os
# DO NOT USE PANEL WITH THIS BIG OF DATA
pv.rcParams['use_panel'] = False
# Simplification factor
sfac = 10
assert type(sfac) is int, 'sfac must be an int'
def read_lidar_img(filename):
"""Read lidar point cloud from `.img` file to a single mesh
Helpful: http://xarray.pydata.org/en/stable/auto_gallery/plot_rasterio.html
"""
# Read in the data
data = xr.open_rasterio(filename)
values = np.asarray(data)
nans = values == data.nodatavals
if np.any(nans):
# values = np.ma.masked_where(nans, values)
values[nans] = np.nan
# Make a mesh
xx, yy = np.meshgrid(data['x'], data['y'])
zz = values.reshape(xx.shape)
# zz = np.zeros_like(xx)
mesh = pv.StructuredGrid(xx, yy, zz)
mesh['lidar'] = values.ravel(order='F')
return mesh
files = glob.glob(os.path.join('./2017DTM_lidar_GP_MSH_SpiritLake/', '*.img'))
print('Number of files {}'.format(len(files)))
# remeshed
remeshed_files = glob.glob(os.path.join('./remeshed/', '*.ply'))
all_surfaces = pv.MultiBlock()
for i,f in tqdm(enumerate(files)):
name = os.path.basename(f).replace('.img', '')
print('{}/{}: {}'.format(i, len(files), name), end='\r')
surface = read_lidar_img(f)
# could use pyacvd
# import pyacvd
# tri_surf = surface.extract_surface().tri_filter()
# clus = pyacvd.Clustering(tri_surf)
# clus.cluster(surface.n_points // sfac)
# clus.create_mesh()
# all_surfaces[-1, name] = clus.remesh
# clus.remesh.save('./remeshed/%s.ply' % name)
# or since it's already structured...
surf = pv.StructuredGrid(surface.x[::sfac][:, ::sfac][:, :,::sfac],
surface.y[::sfac][:, ::sfac][:, :,::sfac],
surface.z[::sfac][:, ::sfac][:, :,::sfac])
scalars = surface.point_arrays['lidar'].reshape(surface.x.shape)
surf.point_arrays['lidar'] = scalars[::sfac][:, ::sfac][:, :,::sfac].ravel()
all_surfaces[-1, name] = surf
print('Done.')
# all_surfaces.plot(notebook=False, multi_colors=True, eye_dome_lighting=True)
# all_surfaces.plot(notebook=False, multi_colors=False, eye_dome_lighting=True)
# combined = all_surfaces.combine()
from pyvista-support.
This is really awesome, thanks @akaszynski! This approach should work well for this particular dataset and my use case
I have some lingering questions that might be useful to other users about repairing the holes in this mesh... I'll create a new issue with a more general example.
from pyvista-support.
Related Issues (20)
- create uniform mesh HOT 3
- Change the orientation of a scalar bar's title
- Applying textures on models from .obj files HOT 6
- How to create an Unstructured grid from points and faces HOT 2
- Type of data, plotting with glyphs HOT 3
- Controlling the thickness and orientation of a slice in Pyvista HOT 3
- Controlling the image position in window, without any click
- Mask/Remove Voxels in Air (small intersection with surface) HOT 3
- custom slider parameters
- running pyvista on headless machine with Centos OS HOT 1
- Seismic Horizon with Pyvista HOT 8
- Algorithm in sample function?
- Automatically updates HOT 3
- Slow interaction HOT 1
- read from text HOT 4
- Uniform Grid thresholding question HOT 8
- Take data by an input x,y,x coordinate (csv file) from vtk data file HOT 4
- Program broke when creating a mesh using pv.PolyData() HOT 4
- ATTENTION: Please move questions to PyVista's Discussions HOT 1
- plotter.enable_terrain_style not working for me HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyvista-support.