Comments (38)
If you can find a way to compute the size sizes then all you would need to do is this (leverage version 2.0.3
of PVGeo which I just released a few minutes ago):
import pyvista as pv
import PVGeo
import pandas as pd
import numpy as np
df = pd.read_csv('sub_blocks.csv')
point_cloud = PVGeo.points_to_poly_data(df)
# Replace this with some sort of way to compute size of each voxel
x_cell_sizes = np.random.randint(3, 6, point_cloud.n_points)
y_cell_sizes = np.random.randint(3, 6, point_cloud.n_points)
z_cell_sizes = np.random.randint(3, 6, point_cloud.n_points)
voxelizer = PVGeo.filters.VoxelizePoints(unique=True, estimate=False)
voxelizer.set_deltas(x_cell_sizes, y_cell_sizes, z_cell_sizes)
grid = voxelizer.apply(point_cloud)
p = pv.Plotter(notebook=False)
p.add_mesh(grid)
p.show_grid()
p.add_axes()
p.show()
from pyvista-support.
Thanks, @laserman781 - The VoxelizePoints
filter from PVGeo is built for regularly spaced grids however it is possible to use it to create voxels of uniform size throughout a non-uniform/unstructured point cloud like yours.
I'm not sure if this is what you want, but here's a go at it:
import pyvista as pv
import PVGeo
import pandas as pd
df = pd.read_csv(filename)
point_cloud = PVGeo.points_to_poly_data(df)
voxelizer = PVGeo.filters.VoxelizePoints()
voxelizer.set_deltas(5, 5, 2) # Your block sizes in dx, dy, dz
voxelizer.set_estimate_grid(False) # This is crucial for this point cloud
grid = voxelizer.apply(point_cloud)
grid.plot(notebook=False)
from pyvista-support.
I am currently taking a stab at an algorithm that can solve this. But if I already have the incrementation between blocks (the block sizes), will we be able to produce the result?
(See email)
from pyvista-support.
Now possibly - voxelise them as above
Add that to a plot (with transparent opacity)
them add the original point clouds mesh to the same plot?
from pyvista-support.
Can you also include the point set that you are working with? (Attach as a file here)
from pyvista-support.
I would prefer not to share the files, is this a problem @banesullivan ?
Thank you.
from pyvista-support.
I'm not sure I can track down this issue without seeing your data - perhaps you could email them to me and I'll delete the file when finished testing
from pyvista-support.
@banesullivan email sent.
from pyvista-support.
From looking at your dataset, it appears to be a slice/threshold through a structured grid. If possible, I'd recommend trying to figure out where that data came from and if there is an original grid that you could use instead. If you do acquire that additional info, you could follow appoaches similar to those in the examples in #16 and #28
from pyvista-support.
@banesullivan In this case, each point represents a block centroid, so since the grid is non-uniform, the blocks will not be all the same sizes, some will be larger or smaller than others. But, they should all be touching... How can we accomplish this?
Thank you so much!
from pyvista-support.
Do you know the block sizes? Because the VoxelizePoints
filter allows you to manually set the block sizes for every block
from pyvista-support.
All you would need are three arrays: the X, Y, and Z sizes for each voxel
from pyvista-support.
@banesullivan that is an unknown and is based on the distances between the points, the goal is to be able to plot the blocks for any grid, whether the blocks all be the same size or have several different sizes. I attempted this with a regular grid and it was able to determine automatically the recovered cell size and recovered angle but only if they are in a regular grid.
Is it possible to do the same thing with several different block sizes depending on the different block centroid distance?
from pyvista-support.
I attempted this with a regular grid and it was able to determine automatically the recovered cell size and recovered angle but only if they are in a regular grid.
That's good to hear as the VoxelizePoints
filter was designed for exactly that.
Is it possible to do the same thing with several different block sizes depending on the different block centroid distance?
Perhaps - but the VoxelizePoints
filter is likely not the algorithm of choice as it is intedended for regular/uniform grids.
How would you compute the block centroid distance?
from pyvista-support.
So I've been experimenting with this and I don't have an immediate solution - I did, however, fix a few bugs with the VoxelizePoints
filter which is updated on PVGeo's master branch.
In the meantime, I think PyntCloud might have some features that could help recover the grid from the point cloud. I'd recommend checking out that library. FYI, I built some interoperability between PyntCloud and PyVista a while back, but we might need to add in a few additional features if PyntCloud can properly recreate the grid to be able to put that grid into a PyVista object
@daavoo, would you be able to chime in here?
Using code above:
from pyntcloud import PyntCloud
cloud = PyntCloud.from_pyvista(point_cloud)
# Now leverage PyntCloud on the `cloud` object
from pyvista-support.
Upon revising the thread, when you mentioned "A recovered connected grid with proper geometry". This is what is needed. The block point data is based on their centroids and the goal is to recover their proper geometry. They are all touching in reality and should, in general, be the same size. Although, that is not always the case and in some areas, the blocks can become smaller and in more quantity (denser) as we have seen in the point when they were displayed.
Does this make a difference in the solution to the problem? I leveraged the PVGeo voxelizer filter in order to accomplish this for a uniform grid but all I am trying to do is recover the original geometry.
Does the solution change if we want to recover the original geometry of the blocks instead of simply Voxelize them?
from pyvista-support.
Does this make a difference in the solution to the problem?
Well, sort of. What changes is how we estimate the cell sizes which has to be done in the X, Y, and Z directions separately for every cell/voxel. Once you have a way to calculate what the cell sizes should be for every point, then we can use the VoxelizePoints
filter in just the same way.
Computing those cell sizes is a lot easier said than done. I've tried to develop an algorithm to do this in the past with no luck - even for just rectilinear grids like this:
import pyvista as pv
import numpy as np
x = np.array([0, 2, 2.5, 2.75, 3.0, 4, 6])
y = np.array([0, 1, 1.5, 1.75, 2, 2.5, 4.5])
z = np.array([0])
grid = pv.RectilinearGrid(x, y, z)
p = pv.Plotter()
p.add_mesh(grid, show_edges=True, )
p.add_mesh(grid.cell_centers(), color='black')
p.show_grid()
p.enable_parallel_projection()
p.show(cpos='xy')
Trying to recover the original cell sizes given just the cell centers is incredibly challenging because the cell edges are not directly in the middle of two nodes. The solver would have to account for almost all the nodes on a mesh in order to make a decision about the size of a single cell.
If someone has an idea of how to implement an algorithm that can solve that problem, I will very happily code it up!
from pyvista-support.
The mesh type you emailed me, @laserman781, is more like a TreeMesh or UnstructuredGrid so solving that kind of geometry is a whole other beast that I'm not sure how to approach
from pyvista-support.
Yes, just pass those cell sizes into arrays as I do in #41 (comment)
from pyvista-support.
After trying to pass the x,y,z cell sizes as an array to the voxelizer I keep receiving this error:
PVGeoError: X-Cell spacings are not properly defined for all points.
Code:
x_cell_sizes = df[['XINC']].values
y_cell_sizes = df[['YINC']].values
z_cell_sizes = df[['ZINC']].values
voxelizer = PVGeo.filters.VoxelizePoints()
voxelizer.set_deltas(x_cell_sizes.values , y_cell_sizes.values, z_cell_sizes.values)
voxelizer.set_estimate_grid(False) # This is crucial for this point cloud
grid = voxelizer.apply(vtkpoints)
grid.plot(notebook=False)
How can I fix this?
from pyvista-support.
Make sure you have the latest version of PVGeo and don't call .values
twice:
x_cell_sizes = df[['XINC']].values
y_cell_sizes = df[['YINC']].values
z_cell_sizes = df[['ZINC']].values
voxelizer = PVGeo.filters.VoxelizePoints()
voxelizer.set_deltas(x_cell_sizes , y_cell_sizes, z_cell_sizes)
voxelizer.set_estimate_grid(False) # This is crucial for this point cloud
grid = voxelizer.apply(vtkpoints)
grid.plot(notebook=False)
from pyvista-support.
Same error occurs for me
from pyvista-support.
Is vtkpoints
the proper object? - that is, does this condition hold?
vtkpoint.GetNumberOfPoints() == len(x_cell_sizes) == len(y_cell_sizes) == len(z_cell_sizes)
from pyvista-support.
This is the code I use to create vtkpoints:
iregular_blocks = pd.read_csv('blocks.csv')
vtkpoints = PVGeo.points_to_poly_data(iregular_blocks)
They all seem to have the same number of points although it returns False...
from pyvista-support.
Something is wrong with your code - Try restarting your kernel and running in sequential order. It looks like something modified the cell sizes arrays between when you print the lengths and when you ran the conditional
from pyvista-support.
I figured out the problem, turns out the points data frame had had fewer points than the size data frame. It now plots exactly the way I want it to.
Thank you so much for your help!
from pyvista-support.
Hi there, I have a question related to the voxelization of the 3D scene. I have a 3D scene that I want to voxelize and want to analyze the point clouds inside those voxels. The original 3D lidar point clouds look something as
and when I run the code
cloud = PyntCloud.from_file(fault_file)
vtkpoints = PVGeo.points_to_poly_data(cloud.points)
voxelizer = PVGeo.filters.VoxelizePoints()
voxelizer.set_deltas(0.4, 0.2, 0.2) # Your block sizes in dx, dy, dz
voxelizer.set_estimate_grid(False)
grid = voxelizer.apply(vtkpoints)
grid.plot(notebook=False)
Its plots the voxels that are solid gray
Is there any way that I can plot voxel with boundaries as being transparent to see point clouds inside them?
from pyvista-support.
Use opacity=0.5 or whatever suits in plots
from pyvista-support.
HI @RichardScottOZ. thanks for the tip. I tried it with opaciy=05 and 0.1 but the plot makes the solid face of the voxel transparent but the point clouds occupied inside the voxel are still invisible
from pyvista-support.
You are saying each voxel has something inside it?
from pyvista-support.
Yes, you can see from the first image that i have plotted. As these are the point clouds with intensity values. After that, I have applied a grid structure for generating voxels in the 3D scene.
from pyvista-support.
#482 might be of interest?
from pyvista-support.
Still not sure I see, what does one of your voxels and cloud inside look like?
from pyvista-support.
Sorry for not being clear, actually i am trying to be something like this
so far i have just managed to plot the point clouds which look like
Not i want to apply voxel upon the above point cloud similarly as the first image i have shown.
from pyvista-support.
Thanks - so the plot above is just the point clouds?
from pyvista-support.
Thanks - so the plot above is just the point clouds?
Yes absolutely
from pyvista-support.
Now possibly - voxelise them as above
Add that to a plot (with transparent opacity) them add the original point clouds mesh to the same plot?
Thanks for the tip really appreciate that. I will give it a try as you suggested
from pyvista-support.
Now possibly - voxelise them as above
Add that to a plot (with transparent opacity)
them add the original point clouds mesh to the same plot?
Yep - specifically, you may want to use style='wireframe'
when plotting the voxels: https://docs.pyvista.org/api/plotting/_autosummary/pyvista.Plotter.add_mesh.html#add-mesh
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.