[vtkusers] vtkDelimetedTextWriter error

David Doria daviddoria+vtk at gmail.com
Tue Jun 22 14:48:09 EDT 2010


On Tue, Jun 22, 2010 at 2:05 PM, Dean Inglis <dean.inglis at camris.ca> wrote:
> I'm trying to write out a vtkTable with vtkDelimetedTextWriter
> into a comma separated value file (csv) but I can only recover
> the first row of the table.  I modified the Wiki/Example Table.cxx
> below as a test.   Can anyone else verify this behaviour?
> (CMake 2.6 patch 4, Win Vista, VS 2005 Express, static build).
>
> Dean
>
>
> #include <vtkTable.h>
> #include <vtkDelimitedTextWriter.h>
> #include <vtkVariant.h>
> #include <vtkVariantArray.h>
> #include <vtkSmartPointer.h>
>
> int main(int, char *[])
> {
>  //construct an empty table
>  vtkSmartPointer<vtkTable> table =
>   vtkSmartPointer<vtkTable>::New();
>
>  for ( unsigned int i = 0; i < 3; i++ )
>   {
>   vtkSmartPointer<vtkVariantArray> col =
>     vtkSmartPointer<vtkVariantArray>::New();
>   col->SetName(vtkVariant(i).ToString().c_str());
>   col->InsertNextValue ( vtkVariant ( 0.0 ) );
>   col->InsertNextValue ( vtkVariant ( 0.0 ) );
>   col->InsertNextValue ( vtkVariant ( 0.0 ) );
>   table->AddColumn ( col );
>   }
>
>  //fill the table with values
>  unsigned int counter = 0;
>  for(vtkIdType r = 0; r < table->GetNumberOfRows(); r++ )
>   {
>   for(vtkIdType c = 0; c < table->GetNumberOfColumns(); c++ )
>     {
>     table->SetValue ( r,c, vtkVariant ( counter ) );
>     counter++;
>     }
>   }
>
>  //print information about the table
>  std::cout << "NumRows: " << table->GetNumberOfRows() << std::endl;
>  std::cout << "NumCols: " << table->GetNumberOfColumns() << std::endl;
>
>  //display the table
>  table->Dump ( 3 );
>
>  //access elements of the table
>  for(vtkIdType r = 0; r < table->GetNumberOfRows(); r++ )
>  {
>   for(vtkIdType c = 0; c < table->GetNumberOfColumns(); c++ )
>   {
>     vtkVariant v = table->GetValue( r,c);
>     std::cout << "(r,c) = (" << r << "," << c << ") = " << v << std::endl;
>   }
>  }
>
>  vtkSmartPointer<vtkDelimitedTextWriter> delimitedWriter =
> vtkSmartPointer<vtkDelimitedTextWriter>::New();
>  delimitedWriter->DebugOn();
>  delimitedWriter->SetFileName("test.csv");
>  delimitedWriter->SetInput(table);
>  delimitedWriter->Write();
>
>  return EXIT_SUCCESS;
> }

I can confirm this, the csv file that is created contains only
"0","1","2"

The table that is output in the code is 3x3, so we seem to only be
getting the first row.

David



More information about the vtkusers mailing list