[vtkusers] vtkDelimetedTextWriter error

Dean Inglis dean.inglis at camris.ca
Tue Jun 22 14:05:07 EDT 2010


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;
} 




More information about the vtkusers mailing list