<html><head></head><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1493071484259_5248" dir="ltr">I need to display distance distribution coming out of vtkDistancePolyDataFilter as a Pie chart.</div><div id="yui_3_16_0_ym19_1_1493071484259_5248" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1493071484259_5248" dir="ltr">Here is what I did, but my color distribution do not seems to matching with the colors on the Polydata object.</div><div id="yui_3_16_0_ym19_1_1493071484259_5248" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1493071484259_5248" dir="ltr"> numDistanceRanges = 10</div><div id="yui_3_16_0_ym19_1_1493071484259_5248" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1493071484259_5248" dir="ltr">#Step0: Create color table for distanceFilter and the PieChart </div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_8339"> colorTable.SetHueRange(0.667, 0.0)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_8340"> colorTable.SetNumberOfColors(numDistanceRanges)<br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_8344"> colorTable.Build()</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_8345"><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_8398"> distanceFilterMapper.SetLookupTable(colorTable)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_8399"><br id="yui_3_16_0_ym19_1_1493071484259_8400"></div></div><div id="yui_3_16_0_ym19_1_1493071484259_5248" dir="ltr">#Step1: Get the distance values and divide that into 10 ranges and find their percentages<br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7823"> distanceValues = distanceFilter.GetOutput().GetPointData().GetScalars()</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7824"> <br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7826"> #Divide the data into ten ranges using numpy histogram </div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7827"> dataRanges, data_edges = np.histogram(distanceValues, bins = numDistanceRanges)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7834"> </div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7835"> #Find the percentages to display in the PieChart</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7836"> totalDataRanges = sum(dataRanges)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7837"> dataRanges = [int(round(val*100/totalDataRanges)) for val in dataRanges]</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7838"> </div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7838">#Step2: Setup PieChart data with the percent values</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7839"> vtkValues = vtk.vtkIntArray()</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7840"> vtkValues.SetNumberOfTuples(numDistanceRanges);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7841"><br id="yui_3_16_0_ym19_1_1493071484259_7842"></div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7843"> for i in range(numDistanceRanges):</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7844"> vtkValues.SetTuple1(i, dataRanges[i])</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7845"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7845"> #Provide the data to the pieChart<br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7848"> distObj = vtk.vtkDataObject()</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7849"> distObj.GetFieldData().AddArray(vtkValues) </div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7850"> pieChartActor.SetInputData(distObj)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7851"> </div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7852">#Step3: Setup PieChart colors</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7853"> for i in range(numDistanceRanges):</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7854"> rgbValue = colorTable.GetTableValue(i)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7855"> pieChartActor.SetPieceColor(i,rgbValue[0], rgbValue[1], rgbValue[2])</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7856"> pieChartActor.SetPieceLabel(i, str(dataRanges[i]))</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7857"><br id="yui_3_16_0_ym19_1_1493071484259_7858"></div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7857">1. When the PieChart says 40% blue, I don't see 40% on the Polydata object from the distanceFilter</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7857">2. Not sure if I am setting up the color table and getting the RGB values correctly</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7857">3. Is there a better way to create PieChart out of DistanceFilter?</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7857"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7859">Thanks</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493071484259_7859">Rao</div></div></body></html>