Pie chart from vtkDistancePolyDataFilter

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Pie chart from vtkDistancePolyDataFilter

VTK - Users mailing list
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 distanceFilter
2. Not sure if I am setting up the color table and getting the RGB values correctly
3. Is there a better way to create PieChart out of DistanceFilter?

Thanks
Rao

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers