GithubHelp home page GithubHelp logo

Comments (6)

akaszynski avatar akaszynski commented on June 19, 2024 1

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.

banesullivan avatar banesullivan commented on June 19, 2024

@daavoo, is this something PyntCloud could handle?

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

@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.

banesullivan avatar banesullivan commented on June 19, 2024

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:

Screen Shot 2019-06-23 at 7 06 57 PM

from pyvista-support.

akaszynski avatar akaszynski commented on June 19, 2024

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.

banesullivan avatar banesullivan commented on June 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.