Reputation: 45
I try to set colors to points but without loop InsertNextTuple3()
.
The ndarray np_rgb_array
is nx3 size.
def set_threshold(self, new_value):
np_rgb_array = (np.ones((self.points.shape))*new_value).astype(int)
rgb2 = npsup.numpy_to_vtk(np_rgb_array ,deep=1)
rgb2.SetName("Colors")
self.vtk_vertex.GetPointData().SetScalars(rgb2)
self.mapper.SetInputData(self.vtk_vertex)
self.mapper.Modified()
self.actor.GetProperty().Modified()
self.render_window.Render()
This function is invoked by slider of pyqt and the range is 0-255 new_value
,
when I run and change the slider first time the color of all points change to blue and then nothing changes... I have this function working but with loop and InsertNextTuple3
Any help will be welcome!
Upvotes: 0
Views: 389
Reputation: 45
In order it to work rgb2
was need to be Unsigned char type vtk array. So I basicly created new array rgb3
that have proper type and did .ShallowCopy()
the data from rgb2
which is double type array.
def set_threshold(self, new_value):
rgb3 = vtk.vtkUnsignedCharArray()
rgb3.SetNumberOfComponents(3)
rgb3.SetName("Colors")
test = np.ones((self.points.shape))*new_value
vtk_test = npsup.numpy_to_vtk(test,deep=1)
vtk_test.SetName("Colors")
rgb3.ShallowCopy(vtk_test)
self.vtk_vertex.GetPointData().SetScalars(rgb3)
self.mapper.SetInputData(self.vtk_vertex)
self.mapper.Modified()
self.actor.GetProperty().Modified()
self.render_window.Render()
Also rerendering works much faster!
Upvotes: 2