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

Point cloud to SDF? #35

Open
BartBruininks opened this issue Nov 11, 2022 · 5 comments
Open

Point cloud to SDF? #35

BartBruininks opened this issue Nov 11, 2022 · 5 comments

Comments

@BartBruininks
Copy link

Dear developer,

I am trying to convert a point cloud to an SDF object. I have an array of XYZs. I have been trying the following:

from sdf import *

def place_bead(x, y, z, size):
    """
    Creates a SDF sphere of given size at the 
    indicated position.
    """
    bead = sphere(size)
    bead.translate(X*x)
    bead.translate(Y*y)
    bead.translate(Z*z)
    return bead

# Setting some sphere properties
size = dict()
aa_names_list = ['oxygen', 'hydrogen', 'carbon']
aa_sizes_list = [.152, .120, .170]
size_dict = dict(zip(aa_names_list, aa_sizes_list))

# Generating some data, the goal is a some spheres on a line. However
#  this will be practically random XYZs in the real case.
aa_xpositions = np.arange(100)
aa_ypositions = np.zeros(100)
aa_zpositions = np.zeros(100)
aa_types = np.random.choice(aa_names_list[:3], 100)
aa_sizes = np.asarray([size_dict[aa_type] for aa_type in aa_types])
aa_array = np.vstack([aa_xpositions, aa_ypositions, aa_zpositions, aa_sizes]).T
aa_objects = [place_bead(*bead) for bead in aa_array]

# Generating the unified SDF
s = aa_objects[0]
for aa_object in aa_objects[1:]:
    s.union(aa_object)

However, I always end up with just a single sphere. Also it feels pretty convoluted, but as I am only aiming at small point clouds for now (for sure less than a 1000) I do do not worry too much about the performance.

It would be great if you could nudge me in the right direction.

Cheers,

Bart

@fogleman
Copy link
Owner

At a glance, you may need s = s.union(aa_object) instead of s.union(aa_object). Or just s = union(*aa_objects)

@BartBruininks
Copy link
Author

I will try this fix, for now the second option I suggested is working so I think I am happy.

@BartBruininks
Copy link
Author

BartBruininks commented Nov 15, 2022 via email

@BartBruininks
Copy link
Author

BartBruininks commented Nov 17, 2022 via email

@BartBruininks
Copy link
Author

BartBruininks commented Nov 17, 2022 via email

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