VTK/Examples/Cxx/Utilities/FileOutputWindow

From KitwarePublic

Jump to: navigation, search

This example shows how to pipe error output to a text file instead of the usual vtk pop-up window.

FileOutputWindow.cxx

#include <vtkFileOutputWindow.h>
#include <vtkOutputWindow.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkSmartPointer.h>
 
int main(int, char *[])
{
  vtkSmartPointer<vtkFileOutputWindow> fileOutputWindow = 
      vtkSmartPointer<vtkFileOutputWindow>::New();
  fileOutputWindow->SetFileName( "output.txt" );
 
  vtkOutputWindow* outputWindow = vtkOutputWindow::GetInstance();
  if ( outputWindow )
    {
    outputWindow->SetInstance( fileOutputWindow );
    }
 
  //this causes an error - file name not specified
  vtkSmartPointer<vtkXMLPolyDataReader> reader = 
      vtkSmartPointer<vtkXMLPolyDataReader>::New();
  reader->Update();
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
PROJECT(FileOutputWindow)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
ADD_EXECUTABLE(FileOutputWindow FileOutputWindow.cxx)
TARGET_LINK_LIBRARIES(FileOutputWindow vtkHybrid)
Personal tools