-
Notifications
You must be signed in to change notification settings - Fork 268
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
Real-time non-blocking mesh visualization #371
Comments
Hi, thanks for your interest, I'm not sure about the meaning of the loop: vertices and face should be defined and applied in advance to build the Mesh, you do not need a loop! Check out About looping and rendering see eg: |
Thanks for your quick reply! In |
Thanks! I have fixed this problem. Your vedo helps a lot! I will commit a new version of ROMP using vedo for visualization. |
Yes, check out |
i've seen this before.. i'll investigate the issue |
Thanks! Looking forward to your reply. |
Are you sure that your texture coordinate file is correct?
Also with pure vtk (no vedo) I cannot get rid of the problem... maybe I should ask in the vtk forum import numpy as np
txu = 'data/guy/SMPL_sampleTex_m.jpg'
uvmap = np.load('data/guy/uv_table.npy')
####### with pure vtk:
# import vtk
# from vtk.util.numpy_support import numpy_to_vtk
# mreader = vtk.vtkPolyDataReader()
# mreader.SetFileName('data/guy/guy.vtk')
# mreader.Update()
# pd = mreader.GetOutput()
# mesh = vtk.vtkActor()
# mapper = vtk.vtkPolyDataMapper()
# mapper.SetInputData(pd)
# mesh.SetMapper(mapper)
# reader = vtk.vtkJPEGReader()
# reader.SetFileName(txu)
# reader.Update()
# pd.GetPointData().SetTCoords(numpy_to_vtk(uvmap))
# tu = vtk.vtkTexture()
# tu.SetInputData(reader.GetOutput())
# tu.SetInterpolate(False)
# # tu.SetRepeat(False)
# # tu.SetEdgeClamp(True)
# mesh.SetTexture(tu)
# renderer = vtk.vtkRenderer()
# renderer.AddActor(mesh)
# render_window = vtk.vtkRenderWindow()
# render_window.AddRenderer(renderer)
# interactor = vtk.vtkRenderWindowInteractor()
# interactor.SetRenderWindow(render_window)
# renderer.SetBackground(1, 1, 1)
# renderer.ResetCamera()
# render_window.Render()
# interactor.Start()
#######################
####### with vedo:
from vedo import Mesh, Picture, show
mesh = Mesh('data/guy/guy.vtk', c='w').lw(0.1).texture(txu, uvmap)
mlab = mesh.labels(uvmap, ratio=1, precision=2, font="VTK", c='k')
show([(mesh,mlab), Picture(txu)], shape=(1,2), axes=1, sharecam=False) vtk is trying to interpolate the boundary jumps: Have you tried by chance to visualize this mesh with some other software? PS: uhmm.. this seems relevant https://stackoverflow.com/questions/39137374/vtk-inserts-incorrect-color-between-nodes-when-mapping-texture-to-mesh |
Yes, the reason stated in the link sounds reasonable. Here is it: The points lie in the border between different part of UV map correspond to multiple uv texture.
|
I kind of understand the second comment... but it looks rather complicated.. and it's non trivial to detect the seam of the texture.. I'll post this as an issue in the vtk forum let's see if they have some better solution.. |
Thanks! |
I got an answer from the vtk develpers here, and indeed it looks like a non trivial issue in vtk.. As I understand there will be a dedicated filter which will deal with it in some clever ways... The solution of collapsing the triangle strip that links different UV regions seems to go in the right direction, but definitely it's not ideal as it modifies the mesh.. Here is a quick test.. which only alleviates the problem..: import numpy as np
from vedo import *
txu = 'SMPL_sampleTex_m.jpg'
threshold = 4.0
mesh = Mesh('guy.vtk', c='w').texture(txu).lw(0.1)
# mesh.write("guy.ply") # doesn't work because of "warning complex.."
uvmap = mesh.getPointArray('tcoords')
mlab = mesh.labels(uvmap, precision=2, ratio=2, font="VTK", c='k')
grad = mesh.gradient("tcoords")
ugrad, vgrad = np.split(grad, 2, axis=1)
ugradm, vgradm = mag(ugrad), mag(vgrad)
gradm = np.log(ugradm*ugradm + vgradm*vgradm)
largegrad_ids = np.arange(mesh.N())[gradm>threshold]
# collapse faces that have large gradient
faces = mesh.faces()
points = mesh.points()
new_points = np.array(points)
for f in faces:
if np.isin(f, largegrad_ids).all():
new_points[f[0]] = new_points[f[1]] = np.mean(points[f], axis=0)
mesh.points(new_points)
mesh2 = mesh.clone().cmap('jet', gradm).addScalarBar()
mlab2a= mesh2.labels('id', font="VTK", c='k', justify="bottom-left")
mlab2b= mesh2.labels(gradm, precision=2, c='dg', justify="top-left", italic=1)
show([(mesh,mlab), (mesh2, mlab2a, mlab2b), Picture(txu)],
N=3, axes=1, sharecam=False) the other proposed solution to save to PLY and load it back, I could not test it because it seems that the numpy file of uvmap has some problems as per warning:
bottom line: I would wait for the vtk upstream solution of the dedicated filter. PS: this works a bit better: # collapse triangles that have large gradient
points = mesh1.points()
new_points = np.array(points)
for f in mesh1.faces():
if np.isin(f, largegrad_ids).all():
id1, id2, id3 = f
uv1, uv2, uv3 = uvmap[f]
d12 = mag(uv1-uv2)
d23 = mag(uv2-uv3)
d31 = mag(uv3-uv1)
idm = np.argmin([d12, d23, d31])
if idm == 0: # d12, collapse segment to pt3
new_points[id1] = new_points[id3]
new_points[id2] = new_points[id3]
elif idm == 1: # d23
new_points[id2] = new_points[id1]
new_points[id3] = new_points[id1]
mesh1.points(new_points) |
I have updated a new version of ROMP using vedo for visualization. |
Thanks for your amazing work.
I am intending to display the 3D mesh reconstruction results in real time.
But every time, the program will be ended after showing the mesh in first time. I have tried ioff(), interactive=False but they didn't work.
Here is a example, I intend to visualize a different mesh (with the same face).
The program will be stopped after running into show at the first time.
The text was updated successfully, but these errors were encountered: