读取 .vtk 文件
我正在研究 VTK(ubuntu 10.04 上的 Qt)
.
我正在尝试读取具有 3D 图像的 .vtk
文件.据我所知,这个
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/例子/Cxx/IO/GenericDataObjectReader
可以读取任何 vtk 文件.但是,它不起作用.我得到的只是:
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) 我使用的代码是否正常工作?我应该改变什么吗?
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) 如何将文件名作为参数传递给 C++ 程序?
2) How could one pass filename as arguments to program in C++?
如果您想从 vtk-wiki 给出的示例中调用已编译的程序,只需打开一个 shell/dos 窗口并输入:
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
如上述输出所示,您不符合示例运行的要求(2 个参数).
As the output stated above, you did not match the requirements for the example to run (2 parameters).
一个参数(第一个)是用法(您调用的程序),第二个参数包含您要读取的 vtk 文件的路径.
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;
}
并简单地将 setYourPathToVtkFileHere 替换为(最好是绝对的)您的路径.
and simply replace setYourPathToVtkFileHere with the (preferably absolute) your path.