Python/vtk - set each point size individually in a vtkPolyData object? -
i using following code populate point cloud: how display point cloud in vtk in different colors?
the points long, lat , depth of quakes in new zealand right now.
i want change point size, scale fourth value - mag
- magnitude data each quake in swarm.
i'm not familiar vtk wrapper, , wondered if point out @ point can address actor, , change each point size:
code:
import vtk import csv import numpy class points_maker(object): def __init__(self, fname): self.fname = fname self.points = [] self.points_mag = [] self.get_data() def get_data(self): reader = csv.reader(open(self.fname, "rb")) row in reader: if "fid" in row[0]: pass else: longitude = (float(row[3]) - 174) * 10 #de-localises value latitude = (float(row[4]) + 41) * 10 #de-localises value depth = float(row[5]) magnitude = float(row[6]) point = [longitude, latitude, depth] point_and_mag = [[longitude, latitude, depth], magnitude] point = numpy.asarray(point) point_and_mag = numpy.asarray(point_and_mag) self.points.append(point) self.points_mag.append(point_and_mag) class vtkpointcloud: def __init__(self, zmin=-0.0, zmax=100.0, maxnumpoints=1e6): #sets colou limits self.maxnumpoints = maxnumpoints self.vtkpolydata = vtk.vtkpolydata() self.clearpoints() mapper = vtk.vtkpolydatamapper() mapper.setinput(self.vtkpolydata) mapper.setcolormodetodefault() mapper.setscalarrange(zmin, zmax) mapper.setscalarvisibility(1) self.vtkactor = vtk.vtkactor() self.vtkactor.setmapper(mapper) def addpoint(self, point): mag = 10 if self.vtkpoints.getnumberofpoints() < self.maxnumpoints: pointid = self.vtkpoints.insertnextpoint(point[:]) self.vtkdepth.insertnextvalue(point[2]) self.vtkcells.insertnextcell(1) self.vtkcells.insertcellpoint(pointid) self.vtkcells.modified() self.vtkpoints.modified() self.vtkdepth.modified() def clearpoints(self): self.vtkpoints = vtk.vtkpoints() self.vtkcells = vtk.vtkcellarray() self.vtkdepth = vtk.vtkdoublearray() self.vtkdepth.setname('deptharray') self.vtkpolydata.setpoints(self.vtkpoints) self.vtkpolydata.setverts(self.vtkcells) self.vtkpolydata.getpointdata().setscalars(self.vtkdepth) self.vtkpolydata.getpointdata().setactivescalars('deptharray') def main(): pm = points_maker("quake.csv") pointcloud = vtkpointcloud() point_and_mag in pm.points_mag: mag = point_and_mag[1] point = point_and_mag[0] pointcloud.addpoint(point) renderer = vtk.vtkrenderer() renderer.addactor(pointcloud.vtkactor) renderer.setbackground(.2, .3, .3) #colour renderer.resetcamera() # render window renderwindow = vtk.vtkrenderwindow() renderwindow.addrenderer(renderer) # interactor renderwindowinteractor = vtk.vtkrenderwindowinteractor() renderwindowinteractor.setrenderwindow(renderwindow) # begin interaction renderwindow.render() renderwindowinteractor.start() if __name__ == '__main__': main()
snippet of points_and_mag data:
[[4.45699999999988, -5.540999999999983, 10.0391] 2.38] [[3.9390000000000214, -5.606999999999971, 17.7148] 3.7352] [[4.182999999999879, -5.519999999999996, 11.0938] 2.16] [[3.9979999999999905, -5.390999999999977, 8.5713] 2.4826] [[3.9560000000000173, -5.568000000000026, 12.1685] 3.5205] [[4.41900000000004, -5.381, 15.1953] 2.1109] [[4.507000000000119, -5.360999999999976, 14.3164] 2.5587] [[3.973000000000013, -5.688999999999993, 14.1406] 2.7651] [[4.139999999999873, -5.290000000000035, 10.9766] 2.6873] [[7.182999999999993, -3.92000000000003, 11.6797] 2.5306] [[4.07999999999987, -5.489999999999995, 17.4805] 5.7216] [[4.113000000000113, -5.416000000000025, 15.0195] 2.8919] [[3.7520000000000664, -6.462999999999965, 5.8203] 2.0667] [[7.727999999999895, -6.178999999999988, 29.0234] 2.0115]
using this: http://www.vtk.org/wiki/vtk/examples/python/geometricobjects/display/point
i have figure out how change whole set size, makes me suspect point cloud 1 actor, not each instance of point in pointcloud:-
def addpoint(self, point, mag): if self.vtkpoints.getnumberofpoints() < self.maxnumpoints: pointid = self.vtkpoints.insertnextpoint(point[:]) self.vtkdepth.insertnextvalue(point[2]) self.vtkcells.insertnextcell(1) self.vtkcells.insertcellpoint(pointid) self.vtkactor.getproperty().setpointsize(mag*10) self.vtkcells.modified() self.vtkpoints.modified() self.vtkdepth.modified() self.vtkactor.modified()
ah, figured out.
i needed have constructor pointcloud = vtkpointcloud()
inside loop steps through points, , renderer.addactor(pointcloud.vtkactor)
inside loop step.
Comments
Post a Comment