慕容3067478
我找到了有关颜色问题的解决方案 - 我不知道这是否是最佳实践。但是我仍然需要帮助来确定边界框内的点。我还想创建一个 gui,使用户能够修改边界框的大小和方向。[但那是另一个话题]import numpy as npfrom mayavi.mlab import draw, points3dfrom tvtk.api import tvtk# PrimitivesN = 3000 # Number of pointsones = np.ones(N) #np.hstack((np.tile(np.array([1]), int(N/2)).T, np.tile(np.array([4000]), int(N/2)).T))scalars = ones #np.arange(N) # Key point: set an integer for each point# Define color table (including alpha), which must be uint8 and [0,255]colors = np.vstack((np.tile(np.array([[255],[255],[0]]), int(N/2)).T, np.tile(np.array([[0],[0],[255]]), int(N/2)).T))# Define coordinates and pointsx, y, z = (np.random.random((N, 3))*255).astype(np.uint8).T # Assign x, y, z values to match colorpts = points3d(x, y, z, scale_factor=10) # Create points#pts.glyph.color_mode = 'color_by_vector' # Color by scalar# Set look-up table and redraw#pts.module_manager.scalar_lut_manager.lut.table = colorspts.glyph.scale_mode = 'scale_by_vector'sc=tvtk.UnsignedCharArray()sc.from_array(colors)pts.mlab_source.dataset.point_data.scalars = scdraw()