Reading .vtk file

天涯浪子 提交于 2019-12-11 06:27:55

问题


I'm working on VTK (Qt on ubuntu 10.04).
I'm trying to read a .vtk file having 3D image. As I could understand, this

http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/GenericDataObjectReader

makes it possible to read any vtk file. However, it does not work. All I get is :

Starting /home/taha/Downloads/VTK/Examples/qtcreator-build/GenericDataObjectReader...
Usage: /home/taha/Downloads/VTK/Examples/qtcreator-build/GenericDataObjectReader InputFilename
/home/taha/Downloads/VTK/Examples/qtcreator-build/GenericDataObjectReader exited with code 1

1) Does the code I'm using work properly? Should I change something?

Even though I know that I need to pass the filename as arguments, I may not know how to do it from command prompt. I searched on internet in detail for this but the ways I'm following might be wrong.

2) How could one pass filename as arguments to program in C++?


回答1:


If you desire to call the compiled programm from the example given from vtk-wiki simply open up a shell/dos window and type:

yourExecutable.exe path-to-file.vtk

As the output stated above, you did not match the requirements for the example to run (2 parameters).

One parameter (the first) is the usage (to what program you call) and the second one containing the path to the vtk-file you want to read.

If you don't want to call it with parameters you could change the given example to this:

int main ( int argc, char *argv[] )
{

  // simply set filename here (oh static joy)
  std::string inputFilename = "setYourPathToVtkFileHere";

  // Get all data from the file
  vtkSmartPointer<vtkGenericDataObjectReader> reader = 
      vtkSmartPointer<vtkGenericDataObjectReader>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->Update();

  // All of the standard data types can be checked and obtained like this:
  if(reader->IsFilePolyData())
    {
    std::cout << "output is a polydata" << std::endl;
    vtkPolyData* output = reader->GetPolyDataOutput();
    std::cout << "output has " << output->GetNumberOfPoints() << " points." << std::endl;
    }

  return EXIT_SUCCESS;
}

and simply replace setYourPathToVtkFileHere with the (preferably absolute) your path.



来源:https://stackoverflow.com/questions/12300310/reading-vtk-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!