<div dir="ltr">Hi all,<div><br></div><div>I have encountered a strange behavior. I have two vtkBarPlots, one in corner 0 and one in corner 1. I want to be able to add/remove any of them from a vtkChartXY. However the plot in the corner 0 cannot be added back to corner 0 once removed. This issues doe not seems to be a problem with the plot in corner 1 or when adding back the first plot into another corner.</div>
<div><br></div><div>I enclosed a simple example (derived from TestBarGraph) that shows the issue. Look at the end of the sample code to see the commented options that show the behavior explained above. </div><div><br></div>
<div>This is with vtk 6.0 and Windows 7.</div><div><br></div><div><br></div><div>Thanks all.</div><div><br></div><div><br></div><div><br></div><div>-----------------------------------------------</div><div><div>#include "vtkRenderer.h"</div>
<div>#include "vtkRenderWindow.h"</div><div>#include "vtkSmartPointer.h"</div><div>#include "vtkChartXY.h"</div><div>#include "vtkPlot.h"</div><div>#include "vtkPlotBar.h"</div>
<div>#include "vtkTable.h"</div><div>#include "vtkIntArray.h"</div><div>#include "vtkContextView.h"</div><div>#include "vtkContextScene.h"</div><div>#include "vtkRenderWindowInteractor.h"</div>
<div>#include "vtkNew.h"</div><div><br></div><div>// Monthly circulation data</div><div>static int data_2008[] = {10822, 10941, 9979, 10370, 9460, 11228,</div><div> 15093, 12231, 10160, 9816, 9384, 7892};</div>
<div>static int data_2009[] = {9058, 9474, 9979, 9408, 8900, 11569,</div><div> 14688, 12231, 10294, 9585, 8957, 8590};</div><div>static int data_2010[] = {9058, 10941, 9979, 10270, 8900, 11228,</div>
<div> 14688, 12231, 10160, 9585, 9384, 8590};</div><div><br></div><div>//----------------------------------------------------------------------------</div><div>int main(int)</div><div>{</div><div>
// Set up a 2D scene, add an XY chart to it</div><div> vtkNew<vtkContextView> view;</div><div> view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);</div><div> view->GetRenderWindow()->SetSize(400, 300);</div>
<div> vtkNew<vtkChartXY> chart;</div><div> view->GetScene()->AddItem(chart.GetPointer());</div><div><br></div><div> // Create a table with some points in it...</div><div> vtkNew<vtkTable> table;</div>
<div><br></div><div> vtkNew<vtkIntArray> arrMonth;</div><div> arrMonth->SetName("Month");</div><div> table->AddColumn(arrMonth.GetPointer());</div><div><br></div><div> vtkNew<vtkIntArray> arr2008;</div>
<div> arr2008->SetName("2008");</div><div> table->AddColumn(arr2008.GetPointer());</div><div><br></div><div> vtkNew<vtkIntArray> arr2009;</div><div> arr2009->SetName("2009");</div><div>
table->AddColumn(arr2009.GetPointer());</div><div><br></div><div> vtkNew<vtkIntArray> arr2010;</div><div> arr2010->SetName("2010");</div><div> table->AddColumn(arr2010.GetPointer());</div><div>
<br></div><div> table->SetNumberOfRows(12);</div><div> for (int i = 0; i < 12; i++)</div><div> {</div><div> table->SetValue(i,0,i+1);</div><div> table->SetValue(i,1,data_2008[i]);</div><div> table->SetValue(i,2,data_2009[i]);</div>
<div> table->SetValue(i,3,data_2010[i]);</div><div> }</div><div><br></div><div> // Add multiple bar plots, setting the colors etc</div><div> vtkPlot *plot = 0;</div><div><br></div><div> vtkSmartPointer<vtkPlotBar> plot1 = vtkSmartPointer<vtkPlotBar>::New();</div>
<div> chart->AddPlot(plot1);</div><div> plot1->SetInputData(table.GetPointer(), 0, 1);</div><div> plot1->SetColor(0, 255, 0, 255);</div><div> chart->SetPlotCorner(plot1,0);</div><div><br></div><div> vtkSmartPointer<vtkPlotBar> plot2 = vtkSmartPointer<vtkPlotBar>::New();</div>
<div> chart->AddPlot(plot2);</div><div> plot2->SetInputData(table.GetPointer(), 0, 2);</div><div> plot2->SetColor(255, 0, 0, 255);</div><div> chart->SetPlotCorner(plot2,1);</div><div><br></div><div> /* Code to see the problems */</div>
<div><br></div><div> /* The plot1 is NOT added back */</div><div> chart->RemovePlotInstance(plot1);</div><div> chart->AddPlot(plot1);</div><div><br></div><div> /* The plot1 IS added back */</div><div>// chart->RemovePlotInstance(plot1);</div>
<div>// chart->AddPlot(plot1);</div><div>// chart->SetPlotCorner(plot1,2);</div><div><br></div><div> /* The plot2 IS added back to the chart */</div><div>// chart->RemovePlotInstance(plot2);</div><div>// chart->AddPlot(plot2);</div>
<div>// chart->SetPlotCorner(plot2,1);</div><div><br></div><div> //Finally render the scene and compare the image to a reference image</div><div> view->GetRenderWindow()->SetMultiSamples(0);</div><div> view->GetInteractor()->Initialize();</div>
<div> view->GetInteractor()->Start();</div><div><br></div><div> return EXIT_SUCCESS;</div><div>}</div></div><div>-------------------------------------</div></div>