VTK/Examples/Cxx/InfoVis/DelimitedTextWriter
From KitwarePublic
Is the output of
"","","" 0,1,2 3,4,5 6,7,8
expected? What is the first line indicating? Simply that there are 3 string fields?
DelimitedTextWriter.cxx
#include <vtkSmartPointer.h> #include <vtkPolyData.h> #include <vtkDelimitedTextWriter.h> #include <vtkSphereSource.h> #include <vtkVariantArray.h> #include <vtkTable.h> int main(int argc, char *argv[]) { std::string outputFilename = "output.txt"; // Use the specified filename if it is provided if(argc == 2) { outputFilename = argv[1]; } // 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->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++; } } vtkSmartPointer<vtkDelimitedTextWriter> writer = vtkSmartPointer<vtkDelimitedTextWriter>::New(); writer->SetFileName(outputFilename.c_str()); #if VTK_MAJOR_VERSION <= 5 writer->SetInputConnection(table->GetProducerPort()); #else writer->SetInputData(table); #endif writer->Write(); return EXIT_SUCCESS; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.8) PROJECT(DelimitedTextWriter) find_package(VTK REQUIRED) include(${VTK_USE_FILE}) if (APPLE) add_executable(DelimitedTextWriter MACOSX_BUNDLE DelimitedTextWriter.cxx) else() add_executable(DelimitedTextWriter DelimitedTextWriter.cxx) endif() if(VTK_LIBRARIES) target_link_libraries(DelimitedTextWriter ${VTK_LIBRARIES}) else() target_link_libraries(DelimitedTextWriter vtkHybrid ) endif()