[vtk-developers] Variable output type
Karthik Krishnan
karthik.krishnan at kitware.com
Sun May 30 12:24:42 EDT 2010
David:
Please find attached the modified code. It works now..
Comes down to adding the following method that creates the right data object
//----------------------------------------------------------------------------
int vtkTestFilter::RequestDataObject(
vtkInformation*,
vtkInformationVector** inputVector ,
vtkInformationVector* outputVector)
{
// for each output
for(int i=0; i < this->GetNumberOfOutputPorts(); i++)
{
vtkInformation* info = outputVector->GetInformationObject(i);
vtkDataObject *output = info->Get(vtkDataObject::DATA_OBJECT());
// Populate the right type of output
this->FillOutputPortInformation( i, info );
// Create an instance of that output.
if(const char* dt = info->Get(vtkDataObject::DATA_TYPE_NAME()))
{
output = vtkDataObjectTypes::NewDataObject(dt);
// Set it on the executive.
this->GetExecutive()->SetOutputData(i, output, info);
if (output)
{
output->FastDelete();
}
}
}
return 1;
}
On Sat, May 29, 2010 at 9:09 PM, Wylie, Brian <bnwylie at sandia.gov> wrote:
> Also vtkRandomGraphSource has a similar tactic...
>
>
> // Copy the structure into the output.
> vtkGraph *output = vtkGraph::GetData(outputVector);
> if (this->Directed)
> {
> if (!output->CheckedShallowCopy(dirBuilder))
> {
> vtkErrorMacro(<<"Invalid structure.");
> return 0;
> }
> }
> else
> {
> if (!output->CheckedShallowCopy(undirBuilder))
> {
> vtkErrorMacro(<<"Invalid structure.");
> return 0;
> }
> }
> Brian Wylie - Org 1424
> Sandia National Laboratories
> MS 1323 - Building CSRI/242
> (505)844-2238 FAX(505)284-2518
> _______ __
> /_ __(_) /_____ _____
> / / / / __/ __ `/ __ \
> / / / / /_/ /_/ / / / /
> /_/ /_/\__/\__,_/_/ /_/
> Informatics Toolkit
>
>
> -----Original Message-----
> From: vtk-developers-bounces at vtk.org [mailto:
> vtk-developers-bounces at vtk.org] On Behalf Of Wylie, Brian
> Sent: Saturday, May 29, 2010 9:33 AM
> To: 'David Doria'; 'Karthik Krishnan'
> Cc: 'VTK Developers'
> Subject: Re: [vtk-developers] Variable output type
>
> Not sure if this helps but vtkTableToGraph can either output a directed or
> undirected graph...
>
> It just creates both and then conditional logic on the choice...
>
> // Create builder for the graph
> VTK_CREATE(vtkMutableDirectedGraph, dirBuilder);
> VTK_CREATE(vtkMutableUndirectedGraph, undirBuilder);
> vtkGraph *builder = 0;
> if (this->Directed)
> {
> builder = dirBuilder;
> }
> else
> {
> builder = undirBuilder;
> }
>
> // Add the correct number of vertices to the graph based on the number of
> // rows in the vertex table.
> builder->GetVertexData()->PassData(vertexTable->GetRowData());
> for (vtkIdType i = 0; i < vertexTable->GetNumberOfRows(); ++i)
> {
> if (this->Directed)
> {
> dirBuilder->AddVertex();
> }
> else
> {
> undirBuilder->AddVertex();
> }
> }
>
> Brian Wylie - Org 1424
> Sandia National Laboratories
> MS 1323 - Building CSRI/242
> (505)844-2238 FAX(505)284-2518
> _______ __
> /_ __(_) /_____ _____
> / / / / __/ __ `/ __ \
> / / / / /_/ /_/ / / / /
> /_/ /_/\__/\__,_/_/ /_/
> Informatics Toolkit
>
> -----Original Message-----
> From: vtk-developers-bounces at vtk.org [mailto:
> vtk-developers-bounces at vtk.org] On Behalf Of David Doria
> Sent: Saturday, May 29, 2010 9:27 AM
> To: Karthik Krishnan
> Cc: VTK Developers
> Subject: Re: [vtk-developers] Variable output type
>
> > In addition to what you have, please also try adding the following method
> :
> >
> > int vtkTestFilter::ProcessRequest(vtkInformation* request,
> > vtkInformationVector**
> > inInfoVec,
> > vtkInformationVector*
> > outInfoVec)
> > {
> > if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT()))
> > {
> > return vtkAlgorithm::ProcessRequest(request, inputVector,
> outputVector);
> > }
> >
> > return this->Superclass::ProcessRequest(request, inputVector,
> > outputVector);
> > }
>
> When I added that function (changing inputVector to inInfoVec and
> outputVector to outInfoVec), I now get:
>
> vtkStreamingDemandDrivenPipeline (0x8ba81c8): Algorithm
> vtkTestFilter(0x8ba73b8) did not create output for port 0 when asked
> by REQUEST_DATA_OBJECT and does not specify any DATA_TYPE_NAME.
>
> Thanks for your help - as usual I am trying not to answer just my
> specific question but generate something useful enough to put on the
> wiki!
>
> Thanks,
>
> David
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100530/335eed6a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkTestFilter.cxx
Type: text/x-c++src
Size: 3108 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100530/335eed6a/attachment-0001.cxx>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkTestFilter.h
Type: text/x-chdr
Size: 979 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100530/335eed6a/attachment-0001.h>
More information about the vtk-developers
mailing list