vtkPolyDataAlgorithm是一个方便的类,使编写算法变得更容易。它还旨在帮助将旧算法转换为新的管道体系结构。这个类有一些假设和默认值,你应该知道。
- 这个类的默认设置是,过滤器将有一个输入端口和一个输出端口。如果不是这样,只需使用SetNumberOfInputPorts等更改它。请参阅此类构造函数以获取默认值。
- 该类还提供了一个FillInputPortInfo方法,默认情况下,该方法表示所有输入都将是PolyData。如果不是这样,请在子类中重写此方法。
1.类图结构
vtkPolyDataAlgorithm类图
vtkPolyDataAlgorithm写作图:
vtkPolyDataAlgorithm Class Reference
2.代码实现
2.1 ProcessRequest()
vtkTypeBool ProcessRequest(
vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
该方法是对基类vtkAlgorithm::ProcessRequest()方法的重写。
//------------------------------------------------------------------------------
vtkTypeBool vtkPolyDataAlgorithm::ProcessRequest(
vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
// generate the data
if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
{
return this->RequestData(request, inputVector, outputVector);
}
if (request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
{
return this->RequestUpdateExtent(request, inputVector, outputVector);
}
// execute information
if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
{
return this->RequestInformation(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
2.1.1 RequestData
//------------------------------------------------------------------------------
// This is the superclasses style of Execute method. Convert it into
// an imaging style Execute method.
//这是Execute方法的超类风格。将其转换为图像样式的执行方法
int vtkPolyDataAlgorithm::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
{
return 1;
}
vtkPolyDataAlgorithm类RequestData方法是个虚方法,实际场景调用vtkPolyDataAlgorithm子类的RequestData()方法。
例如绘制箭头时,就应当调用子类vtkArrowGlyphFilter的RequestData()方法。
int vtkArrowGlyphFilter::RequestData(
vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkDataObject* input = inInfo->Get(vtkDataObject::DATA_OBJECT());
vtkDataSet* dsInput = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
if (!dsInput)
{
if (input)
{
vtkErrorMacro("This filter cannot process input of type: " << input->GetClassName());
}
return 0;
}
// Glyph a subset.
vtkIdType maxNumPts = this->MaximumNumberOfPoints;
vtkIdType numPts = dsInput->GetNumberOfPoints();
vtkIdType totalNumPts = this->GatherTotalNumberOfPoints(numPts);
// What fraction of the points will this processes get allocated?
maxNumPts = (vtkIdType)((double)(maxNumPts) * (double)(numPts) / (double)(totalNumPts));
maxNumPts = (maxNumPts < 1) ? 1 : maxNumPts;
vtkInformationVector* inputVs[2];
vtkInformationVector* inputV = inputVector[0];
inputVs[0] = vtkInformationVector::New();
inputVs[0]->SetNumberOfInformationObjects(1);
vtkInformation* newInInfo = vtkInformation::New();
newInInfo->Copy(inputV->GetInformationObject(0));
inputVs[0]->SetInformationObject(0, newInInfo);
newInInfo->Delete();
inputVs[1] = inputVector[1];
int retVal = this->MaskAndExecute(numPts, maxNumPts, dsInput, request, inputVs, outputVector);
inputVs[0]->Delete();
return retVal;
}
2.1.2 RequestUpdateExtent
//------------------------------------------------------------------------------
int vtkPolyDataAlgorithm::RequestUpdateExtent(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector, vtkInformationVector* vtkNotUsed(outputVector))
{
int numInputPorts = this->GetNumberOfInputPorts();
for (int i = 0; i < numInputPorts; i++)
{
int numInputConnections = this->GetNumberOfInputConnections(i);
for (int j = 0; j < numInputConnections; j++)
{
vtkInformation* inputInfo = inputVector[i]->GetInformationObject(j);
inputInfo->Set(vtkStreamingDemandDrivenPipeline::EXACT_EXTENT(), 1);
}
}
return 1;
}
2.1.3 RequestInformation
//------------------------------------------------------------------------------
int vtkPolyDataAlgorithm::RequestInformation(vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
{
// do nothing let subclasses handle it
return 1;
}
vtkArrowGlyphFilter子类没有RequestInformation()方法。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END