CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   ParaView (http://www.cfd-online.com/Forums/paraview/)
-   -   Paraview pipeline when writing plugins (http://www.cfd-online.com/Forums/paraview/119467-paraview-pipeline-when-writing-plugins.html)

Tasche June 18, 2013 05:01

Paraview pipeline when writing plugins
 
Hello,
im new to Paraview, and im trying to write a plugin for the application.
I already managed to get going a bit by using on site examples, however i have severe difficulty understanding how to pass data between filters.

I have written a source plugin which generates some data, and a marching cubes filter to do some analyzing.
However, the data written to the source plugins' output data object never seems to arrive at the m.c. filters input.
The code below was more or less copy pasted and reworked from a couple of examples i could actually get to work,
and which had some sparse explanation to them.

Heres the code i think is relevant:
Code:

//first filter
vtkFirst::vtkFirst() {
    this->SetNumberOfInputPorts(0);
    this->SetNumberOfOutputPorts(1);
}

int vtkFirst::FillOutputPortInformation(int port, vtkInformation* info) {
    if (port == 0)
    info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUniformGrid");
    return 1;
}

int vtkFirst::RequestDataObject(vtkInformation *vtkNotUsed(request),
                              vtkInformationVector **vtkNotUsed(input),
                              vtkInformationVector *outputVector)
{
    for ( int i = 0; i < this->GetNumberOfOutputPorts(); ++i ){
        vtkInformation* outInfo = outputVector->GetInformationObject( i );
        vtkSmartPointer<vtkUniformGrid> output = vtkUniformGrid::SafeDownCast(outInfo->Get( vtkDataObject::DATA_OBJECT() ) );
        if (!output ) {
            output = vtkUniformGrid::New();
            outInfo->Set( vtkDataObject::DATA_OBJECT(), output );
        this->GetOutputPortInformation(i)->Set(vtkDataObject::DATA_EXTENT_TYPE(), output->GetExtentType() );
        }
    }
    return 1;
}

int vtkFirst::RequestData(vtkInformation *vtkNotUsed(request),
                              vtkInformationVector **vtkNotUsed(input),
                              vtkInformationVector *outputVector)
{
    vtkInformation* outInfo = outputVector->GetInformationObject(0);
    vtkUniformGrid* output = vtkUniformGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
    int dim[3] = {10,20,30}
    output->Initialize();
    output->SetDimensions(dim);
    int ext[6]; output->GetExtent(ext);
    cout << "Extent: " << ext[0] << ... <<ext[5] << endl;
}
//output: 0 9 0 19 0 29

//----------second filter------------------------
void vtkSecond::AddSourceConnection(vtkAlgorithmOutput* input) {
    this->AddInputConnection(1, input);
}

void vtkSecond::RemoveAllSources() {
    this->SetInputConnection(1, 0);
}

int vtkSecond::FillInputPortInformation( int port, vtkInformation* info ) {
    if (!this->Superclass::FillInputPortInformation(port, info)) {
    return 0;
    }
    if ( port == 0 ) {
    info->Set( vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkUniformGrid" );
    return 1;
    }
    return 0;
}

int vtkSecond::RequestData(vtkInformation *vtkNotUsed(request),
              vtkInformationVector **inputVector,
              vtkInformationVector *outputVector)
{
    // get the input and output objects from info
    vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
    vtkDataObject* inputDataObject = inInfo->Get(vtkDataObject::DATA_OBJECT());
    in_grid = vtkUniformGrid::SafeDownCast(inputDataObject);
    int ext[6]; output->GetExtent(ext);
    cout << "Extent: " << ext[0] << ... << ext[5] << endl;
}
//output 0 -1 0 -1 0 -1


Its not only the data thats getting lost, if i directly compare memory adresses of the DATA_OBJECTs, they are different.
I didnt post the .xml files since i assumed they would throw an error if something is wrong.
In short, the .xml file sets no pins for the first filter, and a single input pin for the second.


I also would appreciate an example which is as simple as possible explaning step by step how to talk to the pipeline.
It seems rather hard to find anything useful on the web (because its probably pretty trivial),or at least something that is so
minimal that it will work out of the box, and you can learn from it by expanding a working code, not reducing a
broken one to get it to work. Then again maybe it really is that complicated, then i'll just write my own vis package :)

Thanks alot,
Tasche

Tasche June 19, 2013 04:37

Ah sorry for the premature post, i found the problem!
In RequestDataObject(...) add the line:

Code:

...
    if (!output ) {
        output = vtkUniformGrid::New();
        outInfo->Set( vtkDataObject::DATA_OBJECT(), output );
        this->GetOutputPortInformation(i)->Set(vtkDataObject::DATA_EXTENT_TYPE(), output->GetExtentType() );
        outputVector->SetInformationObject(i, outInfo);      //this line is probably not needed, cant test atm..
        this->GetExecutive()->SetOutputData(i, output);      //this works for me
    }
...


From the paraview mailing list, i also got the tip to implement RequestInformation(...) method to set these things, but for testing, a newbie (like me) prefers minimal code :)
Can be marked as solved i guess.

EDIT: this didnt solve anything at all, i was just testing wrong. The problem still stands as is, any help is appreciated...


All times are GMT -4. The time now is 04:14.