06 - 从Algorithm 算法派生类中删除ExecuteInformation() 和ExecuteData() VTK 6.0 迁移
在先前的vtk中,如vtkPointSetAlgorithm 等算法派生类中定义了虚方法:ExecuteInformation() 和 ExecuteData()。这些方法的定义是为了平稳的从VTK4到VTK5中。我们从如下的类中删除了ExecuteInformation() 和 ExecuteData():
- vtkDataObjectAlgorithm
- vtkGenericDataSetAlgorithm
- vtkHyperOctreeAlgorithm
- vtkPiecewiseFunctionAlgorithm
- vtkPolyDataAlgorithm
- vtkRectilinearGridAlgorithm
- vtkSelectionAlgorithm
- vtkStructuredGridAlgorithm
- vtkUnstructuredGridAlgorithm
任何上面的派生类都应该改ExecuteInformation() 和 ExecuteData()变成 RequestInformation() 和 RequestData()。你还应该利用这个机会来使用输入和输出信息对象来访问输入和输出数据的对象,相对于GetInput() 和 GetOutput()。这儿有一个列外类vtkImageAlgorithm仍然支持 ExecuteData() 和 Execute()。
例子1:
void vtkMyReader::ExecuteInformation()
{
vtkImageData* output = this->GetOutput();
output->SetWholeExtent(…);
output->SetScalarType(VTK_UNSIGNED_CHAR);
}
替换成:
int vtkMyReader::RequestInformation(vtkInformation*, vtkInformationVector**,
vtkInformationVector* outInfoVec)
{
vtkInformation* outInfo = outInfoVec->GetInformationObject(0);
outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), …);
vtkDataObject::SetPointDataActiveScalarInfo(
outInfo, VTK_UNSIGNED_CHAR, 1);
return 1;
}
例子2:
void vtkMyAlgorithm::Execute()
{
vtkImageData* input= this->GetInput();
vtkPolyData* output = this->GetOutput();
替换成:
int vtkMyReader::RequestData(vtkInformation*,
vtkInformationVector**, inInfoVec,
vtkInformationVector* outInfoVec)
{
vtkImageData* input = vtkImageData::GetData(inInfoVec[0]);
vtkPolyData* output = vtkPolyData::GetData(outInfoVec);