[vtk-developers] Problem in derived class

Marcus D. Hanwell marcus.hanwell at kitware.com
Mon Dec 20 18:07:22 EST 2010


On Mon, Dec 20, 2010 at 5:54 PM, Martin Waitzbauer <mazzok at gmx.at> wrote:
> Hello
>
> Im still quite new to VTK; but i hope you can help me on that
>
> i wrote a vtkClass derived from vtkRenderView, creating a 2d plot Rendering
> When filling the vtkTable with values, an error occurs in the following code
>
> void vtkContextView2::SetGaussDataColumn(double variance){
>
>          vtkSmartPointer<vtkFloatArray> arrC =vtkSmartPointer<vtkFloatArray>::New();
>          this->Table->AddColumn(arrC);
>          int column = Table->GetNumberOfColumns();
>          for(int i =0; i < 512;i++){
>                  double gauss =  some double
>                  this->Table->SetValue(i,0,gauss);      <--- ERROR
>
>          }
>          vtkPlot *line = this->chart->AddPlot(vtkChart::LINE);
>          line->SetInput(this->Table, 0, 0);
>      line->SetColor(0, 255, 0, 255);
>      line->SetWidth(1.0);
> }
> THe Error shows an unexpected handling and acces violation ( i was not able to get a proper errormessge via try/catch)
> but i could see on the console that the loop is broken if i == 0, so something seems not to be right with teh initiation of Table maybe?
> this->Table is an vtkTable, initialized in the constructor, and there set also to
>        this->Table->SetNumberOfRows(512);
> so it should be there, or?

This looks like an issue with initialization. If you set the number of
rows on a table before it has any columns I don't think it does
anything. Then you initialized an array, with no length. So you have
an empty array, and the table does not set the length of added
columns. If your table had columns it would then produce an error when
you added a column of a different length.
>
> i call this metod once on the object from a main method, thats why for the line->SetInput(this->Table, 0, 0); and this->Table->SetValue(i,0,gauss)
>
> I dont really see what the problem could be, maybe your experienced eyes can do better?

If you look at some of the tests in the Charts/Testing/Cxx directory
you can see how I built up tables. If you wish to initialize a table
you should add the columns to it, and then set the number of rows.
Then your code should work as you would expect.

There are also examples on the wiki that show some of this, and a
Source article talking about the charts API.

Hope that helps.

Marcus



More information about the vtk-developers mailing list