VTK一次性读取多个图像文件的数据:
方法一:SetFileNames中传递一个路径数组
vtkSmartPointer<vtkStringArray > fileArray = vtkSmartPointer<vtkStringArray >::New();
char fileName[128]; //the file max length
for(inti = 1; i < n; i++) //read n slice of pic's route
{
sprintf(fileName,"../headsq/quarter%03d.jpg", i);
vtkstd::stringfileStr(fileName);
fileArray->InsertNextValue(fileStr);
}
vtkSmartPointer<vtkJPEGReader>reader = vtkSmartPointer<vtkJPEGReader>::New();
reader->SetFileNames(fileArray); //get the data of these pic
reader->Update();
方法二:SetFilePrefix/SetFilePattern搭配
vtkSmartPointer<vtkJPEGReader>reader = vtkSmartPointer<vtkJPEGReader>::New();
reader->SetFilePrefix ("F:\\vtkshuju\\Data\\headsq\\test");
reader->SetFilePattern("%s%03d.jpg");
reader ->SetDataExtent (0,255,0,255,1,99);//get 99 slice of pic with 256 * 256
reader->Update();
方法三:
SetFilePrefix/SetImageRange搭配
v16->SetFilePrefix("F:\\vtkshuju\\Data\\headsq\\quarter");
v16->SetImageRange(1, 93);
获取
F:\\vtkshuju\\Data\\headsq\\quarter.1 to F:\\vtkshuju\\Data\\headsq\\quarter.93
方法四:读取、叠加
vtkSmartPointer<vtkImageAppend > appendImage = vtkSmartPointer<vtkImageAppend >::New();
appendImage->SetAppendAxis(2);
vtkSmartPointer<vtkJPEGReader>reader = vtkSmartPointer<vtkJPEGReader>::New();
char fileName[128];//the file max length
for(int i = 1; i < 66; i++)
{
sprintf(fileName,"F:\\vtkshuju\\Data\\headsq\\test%02d.jpg", i);
reader->SetFileName(fileName);
appendImage->AddInputConnection(reader->GetOutputPort());
}