[vtk-developers] Automatic input for examples?

David Doria daviddoria+vtk at gmail.com
Wed Jan 13 18:35:30 EST 2010


What do you guys think of using something like this for examples which
require an input file:

  vtkstd::string inputFilename;

  bool hasVTKData = false;
#ifdef VTK_DATA_ROOT
  hasVTKData = true;
#endif
  if(argc != 2 && !hasVTKData) //if the user did not pass the right arguments
    // and doesn't have VTKData
    {
      cout << "Required arguments: InputFilename" << endl;
      return EXIT_FAILURE;
    }

  if(argc != 2 && hasVTKData) // the user didn't pass the right arguments, but
    // does have VTKData
    {
    inputFilename = vtkstd::string(VTK_DATA_ROOT) + "/Data/political.vtp";
    cout << "Using file " << inputFilename << " from VTKData." << endl;
    }

  if(argc == 2)//the user passed the correct arguments
    {
    inputFilename = argv[1];
    cout << "Using file " << inputFilename << " from command line." << endl;
    }

This way if the user wants to use his own data file, he can use it,
but if he does not, it will automatically grab a reasonable file from
VTKData.

Clearly we wouldn't want to clutter up the examples with all of that
code, but it could easily be wrapped into a function.

Thoughts?

Thanks,

David



More information about the vtk-developers mailing list