<div dir="ltr">Hi all,<div><br></div><div>I'm using vtkChartXY to plot some data.</div><div><br></div><div>I now need to update the data that is displayed but I'm having trouble doing so.</div><div><br></div><div><br></div><div>Some people were able to call ClearPlots() to recreate the plot. This is a bit problematic since I have multiple lines on my figure. I was able to refactor my code to store the line properties (color, width, etc.) and re-apply them after they are added back to the figure. See for example those:</div><div><br class=""><a href="http://public.kitware.com/pipermail/vtkusers/2012-March/073136.html">http://public.kitware.com/pipermail/vtkusers/2012-March/073136.html</a><br></div><div><a href="http://vtk.1045678.n5.nabble.com/Cannot-update-vtkChartXY-td5734681.html">http://vtk.1045678.n5.nabble.com/Cannot-update-vtkChartXY-td5734681.html</a><br></div><div><a href="http://vtk.1045678.n5.nabble.com/How-to-update-a-2d-plot-vtkChartXY-with-new-data-online-using-C-td5725677.html">http://vtk.1045678.n5.nabble.com/How-to-update-a-2d-plot-vtkChartXY-with-new-data-online-using-C-td5725677.html</a></div><div><br></div><div>Since I have multiple lines, I found it easier for now to store a std::vector<vtkSmartPointer<vtkTable> > and a vector of my line class. So to update line index "tableToUpdate", I do something like: </div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">const int prevNbRows = table[tableToUpdate]->GetNumberOfRows();</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">// FIXME: Don't insert one row at the time!</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">size_t j = prevNbRows;</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">for (int i = 0 ; i < x.size() ; i++) {</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">    table[tableToUpdate]->InsertNextBlankRow();</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">    table[tableToUpdate]->SetValue(j, 0, x[i]);</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">    table[tableToUpdate]->SetValue(j, 1, y[i]);</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">    j++;</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">}</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">chart->ClearPlots();</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">for (int k = 0 ; k < lines.size() ; k++)</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">{</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">    lines[k].linePtr = chart->AddPlot(vtkChart::LINE);</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">    lines[k].RestoreLineProperties();</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">    lines[k].linePtr->SetInputData(table[k], 0, 1);</font></blockquote></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">}</font></blockquote></div></blockquote><div><br class="">I have three questions.<br></div><div><br></div><div>1) Does the ClearPlots() frees all memory used? What happens to the previous linePtr? Are they free? If I update the figure thousands of time for a "large" number of lines, is there a risk of a memory leak somewhere? How to properly free the resources?<br></div><div><br></div><div>2) Is there a better way to update a single line out of many? Without memory leaks?</div><div><br></div><div>3) Most importantly, this breaks setting the axis range. For example, doing this after a line update:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">chart->GetAxis(vtkAxis::BOTTOM)->SetRange(minval, maxval);</font></blockquote></blockquote><div>will change the axis values, but the lines look exactly the same as before this "zooming".</div><div><br></div><div>Maybe it has something to do with how I put everything together: </div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">vtkSmartPointer<vtkRenderer> vRenderer = vtkSmartPointer<vtkRenderer>::New();<br></font><font face="monospace, monospace">vtkGenericOpenGLRenderWindow *renderWindow = GetRenderWindow();<br></font><font face="monospace, monospace">renderWindow->AddRenderer(renderer);</font><font face="monospace, monospace"><br></font><font face="monospace, monospace">vtkSmartPointer<vtkContextScene> chartScene = vtkSmartPointer<vtkContextScene>::New();<br></font><font face="monospace, monospace">vtkSmartPointer<vtkContextActor> chartActor = vtkSmartPointer<vtkContextActor>::New();</font><font face="monospace, monospace"><br></font><font face="monospace, monospace">vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();<br></font><font face="monospace, monospace">chartScene->AddItem(chart);<br></font><font face="monospace, monospace">chartActor->SetScene(chartScene);<br></font><font face="monospace, monospace">renderer->AddActor(chartActor);</font></blockquote></div></blockquote><div><br></div><div><br></div><div>Any ideas or suggestions?</div><div><br></div><div>Thanks!</div><div><br></div><div>Nicolas</div></div>