VTK reading several files into vector

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

VTK reading several files into vector

ygrabar
This post has NOT been accepted by the mailing list yet.
Hello!
I am new to VTK and would like to ask the question about how can I correctly write data from files after reading them into vector to be able to use that vector in future for showing on form or using some filters on.

That is what I have so far. I have created the vector std::vector<vtkAlgorithmOutput*> data, but I assume that dynamic_cast is not the best way to turn vtkDataObject * into vtkAlgorithmOutput*(which I need for example for Mapper), so what should I do here to get things working ?

template<class TReader> vtkAlgorithmOutput *readVTKfile(std::string fileName)
{
        vtkSmartPointer<TReader> reader =
                vtkSmartPointer<TReader>::New();
        reader->SetFileName(fileName.c_str());
        reader->Update();
        reader->GetOutput()->Register(reader);

        vtkAlgorithmOutput *pd = dynamic_cast<vtkAlgorithmOutput *>(reader->GetOutput());
        return pd;
}

void SideBySideRenderWindowsQt::loading_files()
{

        QStringList filenames = QFileDialog::getOpenFileNames(this, tr("Choose"), "", tr("Vtk files (*.vtk)"));
        std::vector<std::string> inputFilenames;
        inputFilenames.reserve(filenames.count());
        foreach(QString str, filenames) {
                inputFilenames.push_back(str.toStdString());
        }
        std::vector<vtkAlgorithmOutput *> data;
        data.resize(inputFilenames.size());

        for (int i = 0; i < inputFilenames.size(); i++)
        {
                data[i] = readVTKfile<vtkGenericDataObjectReader>(inputFilenames[i]);
        }
        cout << "Data size: " << data.size() << endl;
       
        vtkSmartPointer<vtkPolyDataMapper> objectMapper =
                vtkSmartPointer<vtkPolyDataMapper>::New();
       
        objectMapper->SetInputConnection(data[0]); // show first file

        vtkSmartPointer<vtkActor> objectActor =
                vtkSmartPointer<vtkActor>::New();
        objectActor->SetMapper(objectMapper);

        // VTK Renderer
        vtkSmartPointer<vtkRenderer> renderer =
                vtkSmartPointer<vtkRenderer>::New();
        renderer->AddActor(objectActor);

        // VTK/Qt wedded
        this->qvtkWidgetLeft->GetRenderWindow()->AddRenderer(renderer);
        cout << "qvtkWidget updated." << endl;
}


Loading...