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

Implementing click_callback Functionality(Lack of clarity/focused example script) #408

Closed
DhruvaRajwade opened this issue Dec 30, 2022 · 6 comments

Comments

@DhruvaRajwade
Copy link

  • K3D version: 2.15.2(installed via conda-forge)
  • Python version:Python 3.9.12
  • Operating System: Arch Linux, Kernel: 6.1.1-arch1-1

Description

I was studying the mesh_callback example, linked here. I wanted to implement the click functionality to display metadata about a node when a graph is created, but could not get the on_click functionality to work.

Here is an example graph(Z=0), and what I was trying to do is get some metadata using the on_click callback when a point is clicked.
K3D_2D_Points

What I Did

I had a list of points(x,y,0). I converted them into a numpy array. I also had an array with areas for each set of Co-ordinates.
Here is the code I tried.

plot = k3d.plot()
object = k3d.points(xyz_coords, point_size=2)
plot += object
plot.mode = 'callback'
obj = plot.objects[0]
def display_area(obj):
  for i in range(31):
    if obj.positions == obj.positions[i]:
      point_id = i
    else:
        point_id=-1
  if point_id==-1:
    pass
  else:        
    area = areas[point_id]
    print(f"The area of the selected point is {area}")
obj.click_callback = display_area
plot.display()

I understand I must be doing something wrong(my display_area function seems very dodgy). What should I do to get the areas when I click on a point?
(I don't need the points to be exactly the size as their areas denote, they are merely for a graph representation with areas as features)

@artur-trzesiok
Copy link
Collaborator

Hi!

Your example is not working because k3d.points is not a DrawableWithCallback object

class DrawableWithCallback(Drawable):
)

So K3D at this moment simply dosen't support callbacks for

  • k3d.points,
  • k3d.line,
  • k3d.lines,
  • k3d.stl,
  • k3d.text,
  • k3d.text2d,
  • k3d.label,
  • k3d.texture_text,
  • k3d.vector_field,
  • k3d.vectors,
  • k3d.volume,
  • k3d.mip,

callbacks are available for:

  • k3d.marching_cubes
  • k3d.mesh
  • k3d.surface
  • k3d.texture
  • k3d.voxels
  • k3d.sparse_voxels
  • k3d.voxels_group

It is visible in code execution:
image

I will try to add that to documentation too.

@DhruvaRajwade
Copy link
Author

DhruvaRajwade commented Dec 30, 2022

Thank you for the prompt reply! One last query, will callback support be added for the k3d.points object in the near future?

@artur-trzesiok
Copy link
Collaborator

That will be dedicaded mechanism just for points (goal is to calculate ray-sphere intersection rather than ray-mesh). But many people use k3d.points with milions of points so even here I should have some octree... It is not stright forward

@artur-trzesiok
Copy link
Collaborator

Good news! BVH that we use has support for points - https://gkjohnson.github.io/three-mesh-bvh/example/bundle/pointCloudIntersection.html

I feel we can do that in k3d soon but I don't want to make a promises :)

@artur-trzesiok
Copy link
Collaborator

artur-trzesiok commented Dec 30, 2022

btw my benchmark data to points callback- 24m of points (credits: https://sketchfab.com/3d-models/recovering-oak-point-cloud-version-f6dd3f2b081b483bb3f40b6b931016fd )

cloud

@artur-trzesiok
Copy link
Collaborator

Click callback functions #409

Callback "on hover" to python. Green boxes shows BVH Tree [for debug purpose only] on 8 mln of points:

ezgif com-video-to-gif (1)

artur-trzesiok added a commit that referenced this issue Mar 3, 2023
Implementing click_callback Functionality(Lack of clarity/focused example script) #408
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