[vtkusers] Pie chart from vtkDistancePolyDataFilter
Koteswara Rao Ruvva
ruvva at yahoo.com
Mon Apr 24 20:17:21 EDT 2017
I need to display distance distribution coming out of vtkDistancePolyDataFilter as a Pie chart.
Here is what I did, but my color distribution do not seems to matching with the colors on the Polydata object.
numDistanceRanges = 10
#Step0: Create color table for distanceFilter and the PieChart colorTable.SetHueRange(0.667, 0.0) colorTable.SetNumberOfColors(numDistanceRanges)
colorTable.Build() distanceFilterMapper.SetLookupTable(colorTable)
#Step1: Get the distance values and divide that into 10 ranges and find their percentages
distanceValues = distanceFilter.GetOutput().GetPointData().GetScalars()
#Divide the data into ten ranges using numpy histogram dataRanges, data_edges = np.histogram(distanceValues, bins = numDistanceRanges) #Find the percentages to display in the PieChart totalDataRanges = sum(dataRanges) dataRanges = [int(round(val*100/totalDataRanges)) for val in dataRanges] #Step2: Setup PieChart data with the percent values vtkValues = vtk.vtkIntArray() vtkValues.SetNumberOfTuples(numDistanceRanges);
for i in range(numDistanceRanges): vtkValues.SetTuple1(i, dataRanges[i])
#Provide the data to the pieChart
distObj = vtk.vtkDataObject() distObj.GetFieldData().AddArray(vtkValues) pieChartActor.SetInputData(distObj) #Step3: Setup PieChart colors for i in range(numDistanceRanges): rgbValue = colorTable.GetTableValue(i) pieChartActor.SetPieceColor(i,rgbValue[0], rgbValue[1], rgbValue[2]) pieChartActor.SetPieceLabel(i, str(dataRanges[i]))
1. When the PieChart says 40% blue, I don't see 40% on the Polydata object from the distanceFilter2. Not sure if I am setting up the color table and getting the RGB values correctly3. Is there a better way to create PieChart out of DistanceFilter?
ThanksRao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170425/7c2de31a/attachment.html>
More information about the vtkusers
mailing list