[vtkusers] vtkChartXY: Cannot add and then remove vtkPlotBar from corner 0 (VTK6.0)

Alexandre Boucher afboucher at gmail.com
Tue Jul 30 14:23:22 EDT 2013


Hi all,

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.

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.

This is with vtk 6.0 and Windows 7.


Thanks all.



-----------------------------------------------
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkChartXY.h"
#include "vtkPlot.h"
#include "vtkPlotBar.h"
#include "vtkTable.h"
#include "vtkIntArray.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkNew.h"

// Monthly circulation data
static int data_2008[] = {10822, 10941, 9979, 10370, 9460, 11228,
                          15093, 12231, 10160, 9816, 9384, 7892};
static int data_2009[] = {9058, 9474, 9979, 9408, 8900, 11569,
                          14688, 12231, 10294, 9585, 8957, 8590};
static int data_2010[] = {9058, 10941, 9979, 10270, 8900, 11228,
                          14688, 12231, 10160, 9585, 9384, 8590};

//----------------------------------------------------------------------------
int main(int)
{
  // Set up a 2D scene, add an XY chart to it
  vtkNew<vtkContextView> view;
  view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
  view->GetRenderWindow()->SetSize(400, 300);
  vtkNew<vtkChartXY> chart;
  view->GetScene()->AddItem(chart.GetPointer());

  // Create a table with some points in it...
  vtkNew<vtkTable> table;

  vtkNew<vtkIntArray> arrMonth;
  arrMonth->SetName("Month");
  table->AddColumn(arrMonth.GetPointer());

  vtkNew<vtkIntArray> arr2008;
  arr2008->SetName("2008");
  table->AddColumn(arr2008.GetPointer());

  vtkNew<vtkIntArray> arr2009;
  arr2009->SetName("2009");
  table->AddColumn(arr2009.GetPointer());

  vtkNew<vtkIntArray> arr2010;
  arr2010->SetName("2010");
  table->AddColumn(arr2010.GetPointer());

  table->SetNumberOfRows(12);
  for (int i = 0; i < 12; i++)
    {
    table->SetValue(i,0,i+1);
    table->SetValue(i,1,data_2008[i]);
    table->SetValue(i,2,data_2009[i]);
    table->SetValue(i,3,data_2010[i]);
    }

  // Add multiple bar plots, setting the colors etc
  vtkPlot *plot = 0;

  vtkSmartPointer<vtkPlotBar> plot1 = vtkSmartPointer<vtkPlotBar>::New();
  chart->AddPlot(plot1);
  plot1->SetInputData(table.GetPointer(), 0, 1);
  plot1->SetColor(0, 255, 0, 255);
  chart->SetPlotCorner(plot1,0);

  vtkSmartPointer<vtkPlotBar> plot2 = vtkSmartPointer<vtkPlotBar>::New();
  chart->AddPlot(plot2);
  plot2->SetInputData(table.GetPointer(), 0, 2);
  plot2->SetColor(255, 0, 0, 255);
  chart->SetPlotCorner(plot2,1);

  /* Code to see the problems */

  /* The plot1 is NOT added back */
  chart->RemovePlotInstance(plot1);
  chart->AddPlot(plot1);

  /* The plot1 IS added back */
//  chart->RemovePlotInstance(plot1);
//  chart->AddPlot(plot1);
//  chart->SetPlotCorner(plot1,2);

  /* The plot2 IS added back to the chart */
//  chart->RemovePlotInstance(plot2);
//  chart->AddPlot(plot2);
//  chart->SetPlotCorner(plot2,1);

  //Finally render the scene and compare the image to a reference image
  view->GetRenderWindow()->SetMultiSamples(0);
  view->GetInteractor()->Initialize();
  view->GetInteractor()->Start();

  return EXIT_SUCCESS;
}
-------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130730/2ae8a972/attachment.htm>


More information about the vtkusers mailing list