Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order scattered points to create a spline/line #389

Closed
eivindtn opened this issue May 5, 2021 · 3 comments
Closed

Order scattered points to create a spline/line #389

eivindtn opened this issue May 5, 2021 · 3 comments

Comments

@eivindtn
Copy link

eivindtn commented May 5, 2021

Hi again @marcomusy, As in #349, we talked about ordering points in the "right" order, so it's possible to create lines/splines and increase the resolution of points from the intersection curve between two meshes. And you have added the function mesh.join(reset= True) which are great, and working with the intersectwith() . However, is it possible to use this function for scattered points along a line? Like for the smoothed points (pts) from the example examples/advanced/moving_least_squares1D

I have tried to create a mesh from the pts, but havent suceed into order the points, so I can increase the resolution by creating a spline. I think the issue is that I haven't figured how to create the mesh.lines() boundaries. Im not sure, but it is right that mesh.lines() need to be defined in order to order points with the function mesh.join(reset= True)?

I have tried to reconstruct one of my issue with the moving least square example:

from vedo import *
import numpy as np

N = 4  # nr. of iterations

# build some initial cloud of noisy points along a line
pts = [ (sin(6*x), cos(2*x)*x, cos(9*x)) for x in np.arange(0,2, .001)]
# pts = [ (0, sin(x), cos(x)) for x in arange(0,6, .002) ]
# pts = [(sqrt(x), sin(x), x/5) for x in arange(0, 16, 0.01)]

pts += np.random.randn(len(pts), 3) /20  # add noise
np.random.shuffle(pts)  # make sure points are not ordered

pts = Points(pts, r=5)

for i in range(1, N):
    pts = pts.clone().smoothMLS1D(f=0.4).color(i)

    if i == N-1:
        # at the last iteration make sure points
        # are separated by tol (in % of bbox)
        pts.clean(tol=0.02)

msh  = Mesh(pts).triangulate()
print(msh.lines()) # empty array
msh2 = msh.clone().join(reset=True)
msh2.points() # only one point           I think I do something strange here
# trying to create a spline from the pts
sph = Spline(pts)
show(pts, sph, N=2).close() 

image

@marcomusy
Copy link
Owner

This situation is very different from the one discussed in the other issue where te intersection implicitly defines the order of the points. In this case, which is way more general, there is no way a priori to identify the connectivity of the points. You may think of trying to order them by x,y, or z but that's obviously not enough:

from vedo import *
import numpy as np

N = 3  # nr. of iterations

# build some initial cloud of noisy points along a line
pts = [ (sin(6*x), cos(2*x)*x, cos(9*x)) for x in np.arange(0,2, .001)]

pts += np.random.randn(len(pts), 3) /30  # add noise
np.random.shuffle(pts)  # make sure points are not ordered

# try to sort them along y..
pts = utils.sortByColumn(pts, 1)

pts = Points(pts, r=9).c('r')

for i in range(1, N):
    pts = pts.clone().smoothMLS1D(f=0.4)
    if i == N-1:
        pts.clean(tol=0.02)

# trying to create a spline from the pts
sph = Line(pts)
show(pts, sph, axes=1)

Screenshot from 2021-05-05 21-34-50
I guess You need to "navigate" iteratively along closest point from a seed and fixing a threshold (?).
Maybe there's some more clever algorithm to achieve the same , but I can't think of any.

@eivindtn
Copy link
Author

eivindtn commented May 5, 2021

You're right! I see now that this is a very general case compared to the other issue. And selecting this example wasn't the best choice, regarding comparing it to my issue. I will look into it, and come back to you later!
Anyway, thank you!

@eivindtn
Copy link
Author

I will close this issue for now since I haven't find a clever solution for the problem above. And I also see that it isn't so related to my wanted approach. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants