marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.04k stars 265 forks source link

Trace of image on surface like mousehover #445

Closed sonumathur closed 3 years ago

sonumathur commented 3 years ago

I want to trace a image diagram on surface of an object like mousehover example at the link

[(https://github.com/marcomusy/vedo/blob/master/examples/basic/mousehover.py)]

I have a surface on which want to trace image surface.zip Image to traced is design_1

Is there any option using vedo to get trace in a sequence.....

marcomusy commented 3 years ago

Hi I'm not sure i understand what are you trying to achieve.. looking at your dataset i get:

from vedo import *
import numpy as np

pts = Mesh("surface.PLY").c([202,209,238]).printInfo()
cols = pts.getCellArray("RGBA")
print(np.max(cols,axis=0))

show(pts, axes=1)
Screenshot 2021-08-19 at 13 54 56

what is it? are you trying to draw the image on top of this mesh? as a texture or somehow by free-hand drawing? Have a look at https://github.com/marcomusy/vedo/blob/master/examples/advanced/spline_draw.py (change pic to your mesh) and/or https://github.com/marcomusy/vedo/blob/master/examples/basic/spline_tool.py

sonumathur commented 3 years ago

@marcomusy sir actually I am trying 3D printing on object having non planner surface. Till today all the 3D printer Gcode generator work on plane surface. For for printing the above image on the surface the should be path like mousehover example. Like by mousehover we can get the coordinate that under mouse motion. As shown in clip

https://user-images.githubusercontent.com/60248559/130121038-02406890-8c1a-404e-894c-0f20614f198d.mp4

marcomusy commented 3 years ago

ok - but then my question is what else you need if the mousehover example already fits your needs?

sonumathur commented 3 years ago

Actually mousehover example pic the coordinate under mouse position. I want to run a trace as from a image. I want to try mousehover over a hand ply file but not working Hand.zip

I try this as

from vedo import *

def func(evt):
    if not evt.actor: return
    pt = evt.picked3d

    pid = evt.actor.closestPoint(pt, returnPointId=True)
    txt = f"Point:  {precision(pt[:2]  ,2)}\n" \
          f"Height: {precision(arr[pid],3)}\n" \
          f"Ground speed: {precision(evt.speed3d*100,2)}"
    arw = Arrow(pt - evt.delta3d, pt, s=0.001, c='orange5')
    vig = evt.actor.vignette(txt, point=pt, offset=(0.4,0.6),
                             s=0.04, c='k', font="VictorMono").followCamera()
    msg.text(txt)
    if len(plt.actors)>3:
        plt.pop()
    plt.add([arw, vig])

Hand = Mesh("model_1.ply").rotate(angle=180).addScalarBar()
arr = Hand.getPointArray("Scalars")
plt = Plotter(axes=1, bg2='lightblue')
plt.addCallback('mouse moving', func)
plt.addCallback('keyboard', lambda e: plt.remove(plt.actors[3:], render=True))

msg = Text2D("", pos='bottom-left', font="VictorMono")

plt.show(Hand, msg, __doc__, viewup='z') 
marcomusy commented 3 years ago

This seems to work fine though:

from vedo import *

def func(evt):
    if not evt.actor: return
    pt = evt.picked3d

    txt = f"Point: {precision(pt[:2],2)}"
    arw = Arrow(pt - evt.delta3d, pt, s=0.002, c='green4')
    vig = evt.actor.vignette(txt, point=pt, offset=(0.4,0.6),
                             s=0.04, c='k', font="VictorMono").followCamera()
    msg.text(txt)
    if len(plt.actors)>3:
        plt.pop()
    plt.add([arw, vig])

plt = Plotter(axes=1, bg2='lightblue')
plt.addCallback('mouse moving', func)
plt.addCallback('keyboard', lambda e: plt.remove(plt.actors[3:], render=True))

hand = Mesh("model_1.ply").rotateX(180)
msg = Text2D("", pos='top-left', font="VictorMono")

plt.show(hand, msg, viewup='z') 
Screenshot 2021-08-23 at 13 51 44

are you able to reproduce it ?

sonumathur commented 3 years ago

Thanks @marcomusy In 2D it's working, but may aim is to get all three coordinates as X, Y and Z what will be programm if there will be Z also.

marcomusy commented 3 years ago

I don't understand your question.. the above example already works in 3d

txt = f"Point: {pt}"

If you are trying to cut-off parts of the mesh you have a look at examples/basic/cutFreeHand.py or from command line vedo -e model_1.ply

sonumathur commented 3 years ago

Thanks @marcomusy

Its working. I have one more questions related to Dimension. How i can measure two points on any surface in millimeters

marcomusy commented 3 years ago

units are always arbitrary! you fix the scale.

If you mean the distance of 2 points walking on the surface check out: https://github.com/marcomusy/vedo/blob/master/examples/advanced/geodesic.py

sonumathur commented 3 years ago

What is method to set scale in mesh. Is there any method to remain the size of mesh to original mesh size. I have processed a mesh in vedo having size about 250mmx250mmx50mm as attached: CUT_Hand.zip

The code applied is: from vedo import * pts = Points("CUT_Hand.ply").clean(0.0075).pointSize(4) surf1 = delaunay2D(pts, mode='fit').clean().lighting('default') pts1= Points(surf1) pts1.write('points.xyz') show(pts, surf1, N=2, axes=1)

after processing and opened in CAD software to shows as: hand

marcomusy commented 3 years ago

Ops, sorry - I missed this one issue, Have you solved it by now?

sonumathur commented 3 years ago

Thanks for Reply. Not solved sir

marcomusy commented 3 years ago

You can simply use scale(). E.g.:


from vedo import *

m1 = Mesh("data/CUT_Hand.ply")
mcopy = m1.clone()
m1.scale(1.5).write("m2.xyz")

m2 = Mesh("m2.xyz").ps(2)

show(mcopy, m2, N=2, axes=1)

Screenshot from 2021-09-16 19-03-59

you can also use .shift() to move it around or equivalently origin() to define where the scaling operation should be centered. Sorry again for the late reply.

sonumathur commented 3 years ago

Thanks for your great support. This scale method solve the problem of unit. actually the unit of pointcloud data is meter and it was processed as millimeter.