Giter Club home page Giter Club logo

Comments (6)

marcomusy avatar marcomusy commented on September 26, 2024 1

Well I have not tested this but you can try with some specific configuration:

from vedo import *
vol1 = Box(size=(35,10, 5)).binarize()
vol2 = Box(size=( 5,10,35)).binarize()
vol = vol1.operation("and", vol2)
dx, dy, dz = vol.spacing() # voxel size
counts = np.unique(vol.pointdata[0], return_counts=True)
n0, n1 = counts[1]
vol_value = dx*dy*dz * n1
vol1.cmap('g')
vol2.cmap('r')
vol.cmap('m')
show(vol1, vol2, vol, f"volume = {vol_value}", axes=1).close()

image

from vedo.

marcomusy avatar marcomusy commented on September 26, 2024 1

You can automatize the radius value by histogramming the point relative distances, something like

from vedo import *
from vedo.pyplot import histogram

pcd1 = Points("pcd1.ply").color("blue5")
pcd2 = Points("pcd2.ply").color("red5")

dists1 = []
for p1 in pcd1.coordinates:
    q1 = pcd1.closest_point(p1, n=2)[1]
    dists1.append(mag(p1 - q1))
histo1 = histogram(dists1, bins=25).clone2d()
radius = histo1.mean * 10

tetm1 = pcd1.generate_delaunay3d(radius=radius)
surf1 = tetm1.tomesh().compute_normals()
surf1.color("blue5").alpha(0.1)

tetm2 = pcd2.generate_delaunay3d(radius=radius)
surf2 = tetm2.tomesh().compute_normals()
surf2.color("red5").alpha(0.1)

s12 = surf1.boolean("intersect", surf2)
s12.color("green5").lw(1)
print(s12.volume())

show(pcd1, pcd2, surf1, surf2, s12, histo1, axes=1)

image

from vedo.

ttsesm avatar ttsesm commented on September 26, 2024 1

Thanks @marcomusy, as always really helpful 👍
For the moment, it seems to do the job so I will be closing this issue.

from vedo.

ttsesm avatar ttsesm commented on September 26, 2024

Hi @marcomusy,

Lovely, this works fine. The point is now I want to apply this on two point clouds.
image

However, the issue that I face now is that when I try to extract the volume from the point clouds directly I get nothing. I tried the different parameters to the .tovolume() function but it doesn't seem to give me something that I can use:

pcd1.tovolume(kernel='shepard', n=4)
<vedo.volume.Volume object at 0x7fc247ea2800>
pcd1.pointdata
Point Data is empty.

The same with pcd2. Then I tried first to make them as meshes by using the .reconstruct_surface() method and use .binarize() on them and then extract overlap but the reconstructed meshes are really bad.

Any idea how to handle this.

Thanks.
pcds.zip

from vedo.

marcomusy avatar marcomusy commented on September 26, 2024

Hi, what about this alternative solution

from vedo import *

pcd1 = Points("pcd1.ply").color("blue5")
pcd2 = Points("pcd2.ply").color("red5")

ug1 = pcd1.generate_delaunay3d(radius=0.01)
surf1 = ug1.tomesh().compute_normals()
surf1.color("blue5").alpha(0.1)
ug2 = pcd2.generate_delaunay3d(radius=0.01)
surf2 = ug2.tomesh().compute_normals()
surf2.color("red5").alpha(0.1)

s12 = surf1.boolean("intersect", surf2)
s12.color("green5").lw(1)
vol = s12.volume()

show(pcd1, pcd2, surf1, surf2, s12, f"volume = {vol}", axes=1)

Screenshot from 2024-05-31 15-32-26

PS : creating a volume from a pointcloud is not possible because there is no face normal which defines the "inside" from the "outside".

from vedo.

ttsesm avatar ttsesm commented on September 26, 2024

Using the meshes is good as alternative the only issue that I have though with this approach is that radius needs to change each time because I am loading different point clouds each time so using 0.01 as a fixed number it doesn't always work, e.g.:
image

that's why I wanted to go volumes instead.

Do you have any idea how I can dynamically specify the radius value for the triangulation, depending on the point cloud that I have each time... 🤔

from vedo.

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.