python - VTK coloring tube filter with connectivity information -
i have molecule want represent spheres , tubes connecting them. i'd color tubes according connectivity information. meaning have various disconnected regions or disconnected components color differently per region. far have this, in python , works. have commented tried achieve this. avariable data
polydata array contains points, scalars , cells connectivity information.
tube = vtk.vtktubefilter() tube.setinput(data) tube.setnumberofsides(5); #tube.setvaryradiustovaryradiusbyabsolutescalar() tube.setvaryradiustovaryradiusoff() tube.setradius(0.1) """appendfilter = vtk.vtkappendpolydata() appendfilter.addinputconnection(tube.getoutputport()) appendfilter.update() connectivityfilter = vtk.vtkpolydataconnectivityfilter() connectivityfilter.setinputconnection(appendfilter.getoutput()) connectivityfilter.scalarconnectivityon() connectivityfilter.fullscalarconnectivityon() connectivityfilter.setextractionmodetoallregions() connectivityfilter.colorregionson() connectivityfilter.update() """ #print (connectivityfilter.getnumberofextractedregions()) tubemapper = vtk.vtkpolydatamapper() tubemapper.setinputconnection(tube.getoutputport()) tubemapper.update()
i have working not sure if there problem connectivity definition. forgetting word "port" in getoutputport
. anyways, here answer (i omitting atom , tube radius , other irrelevant options)
tube = vtk.vtktubefilter() tube.setinput(data) tube.setvaryradiustovaryradiusoff() tube.setradius(tuberad) appendfilter = vtk.vtkappendpolydata() appendfilter.addinputconnection(tube.getoutputport()) appendfilter.update() connectivityfilter = vtk.vtkpolydataconnectivityfilter() connectivityfilter.setinputconnection(appendfilter.getoutputport()) connectivityfilter.setextractionmodetoallregions() connectivityfilter.colorregionson() connectivityfilter.update() tubemapper = vtk.vtkpolydatamapper() tubemapper.setinputconnection(connectivityfilter.getoutputport()) tubemapper.setscalarrange(connectivityfilter.getoutput().getpointdata().getarray("regionid").getrange()) tubemapper.update()
it ends looking good, may notice apparently connected components still colored differently , still wonder why.
Comments
Post a Comment