marcomusy / vedo

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

Vedo can not display point #1015

Open OhmPuchiss opened 5 months ago

OhmPuchiss commented 5 months ago
from vedo import show,Points
import numpy as np

pts = np.random.randn(200, 3)
vpts = Points(pts).ps(10)
p = vpts.points()
p[0] = [5,5,4] # make this point stick out
vpts.points(p)

vpts.cmap('viridis', pts[:,2], name="mydata")
vpts.print()
show(vpts, axes=1).close()
cols = np.random.rand(200, 3)*255
cols[0] = [255,0,0] 

show(vpts, axes=1).close()

I try to run this code from someone in the example project. However, it turn out NO POINTS appear. I am so confused and would like to let someone check for me.

image
marcomusy commented 5 months ago

@OhmPuchiss thanks for reporting! I have seen this problem once but I could not reproduce it... Can you try these tests, type in your terminal:

vedo

this should show your system specs, in my case:

Screenshot 2024-01-15 at 00 07 22

then


import numpy as np
from vedo import show, Points

pts = np.random.randn(200, 3)
vpts = Points(pts).ps(10)
vpts.coordinates[0] = [5, 5, 4]  # make this point stick out
vpts.cmap("viridis", pts[:, 2], name="mydata")
# vpts.print()
# show(vpts, axes=1).close()

import vtk

# FIRST TEST ################################
poly = vpts.dataset

# SECOND TEST ################################
# poly = vtk.vtkPolyData()
# points = vtk.vtkPoints()
# for i in range(100):
#     points.InsertNextPoint(np.random.rand(3))
# poly.SetPoints(points)
# verts = vtk.vtkCellArray()
# for i in range(100):
#     verts.InsertNextCell(1)
#     verts.InsertCellPoint(i)
# poly.SetVerts(verts)
############################################

ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
ren.SetBackground(0.1, 0.2, 0.4)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
actor = vtk.vtkActor()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(poly)
mapper.SetScalarRange(poly.GetScalarRange())
actor.SetMapper(mapper)
actor.GetProperty().SetPointSize(10)
actor.GetProperty().RenderPointsAsSpheresOn() # try comment out this line
ren.AddActor(actor)
renWin.Render()
iren.Start()

the first test would show something like:

Screenshot 2024-01-15 at 00 07 04

the second test (by uncommenting) would show this:

Screenshot 2024-01-15 at 00 04 26
marcomusy commented 5 months ago

Sorry for the late reply, the problem is due to actor.GetProperty().RenderPointsAsSpheresOn(). Try:

vpts = Points(pts).ps(10).render_points_as_spheres(False)