[vtk-developers] Variable output type

David Doria daviddoria+vtk at gmail.com
Fri May 28 15:40:09 EDT 2010


I want to make a filter in which I can specify the output type.

I tried something like this (yes I know that for this particular
example vtkGraphAlgorithm will set the output type to match the input
type, but it seems like a reasonable example anyway):

vtkGraph *output = vtkGraph::SafeDownCast(
                                    outInfo->Get(vtkDataObject::DATA_OBJECT()));

  if(this->OutputType == "vtkMutableUndirectedGraph")
    {
    output = vtkMutableUndirectedGraph::SafeDownCast(

outInfo->Get(vtkDataObject::DATA_OBJECT()));
    }
  else if(this->OutputType == "vtkMutableDirectedGraph")
    {
    output = vtkMutableDirectedGraph::SafeDownCast(

outInfo->Get(vtkDataObject::DATA_OBJECT()));
    }

  std::cout << "Output is type: " << output->GetClassName() << std::endl;
  output->AddVertex();

The problem here is that vtkGraph does not have an AddVertex function,
so the compiler, not knowing that it will be casted to something that
DOES have an AddVertex function, produces an error. The output type
that is written to the screen is correct (if I comment the AddVertex
call).

Any thoughts on how to do something like this?

Thanks,

David



More information about the vtk-developers mailing list