[vtkusers] vtkTable

Jeff Baumes jeff.baumes at kitware.com
Thu Oct 22 13:34:15 EDT 2009


>
>  vtkSmartPointer<vtkTable> Table = vtkSmartPointer<vtkTable>::New();
>  vtkSmartPointer<vtkVariantArray> Row =
> vtkSmartPointer<vtkVariantArray>::New();
>
>  Row->SetNumberOfValues(3);
>  //Row->SetNumberOfTuples(0);
>  Row->SetValue(0, vtkVariant(1.0));
>  Row->SetValue(1, vtkVariant(2.0));
>  Row->SetValue(2, vtkVariant(3.0));
>
>  Table->SetNumberOfRows(1);
>  Table->SetRow(0, Row);
>  //Table->InsertNextRow(Row);
>
>  vtkstd::cout << "NumRows: " << Table->GetNumberOfRows() << vtkstd::endl;
>  vtkstd::cout << "NumCols: " << Table->GetNumberOfColumns() <<
> vtkstd::endl;
>
>  Table->Dump(3);
>
> I get an error macro that says "Incorrect number of tuples in SetRow"
>
> Can anyone see what is wrong with that?
>

A vtkTable is a collection of arrays (the columns). Each column has a
specific type (there is no default), so currently you must explicitly add
each column array. In this code, you have no columns when you call
SetNumberOfRows(). Essentially you have created a 1-by-0 table. In the call
to SetRow(), the number of elements in the row array (3) must match the
number of columns in the table (0), so that is why you get an error. To make
it work, you must add columns first, which may simply be empty arrays.

Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091022/a487dd43/attachment.htm>


More information about the vtkusers mailing list