one thread for reading, one thread for rendering

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

one thread for reading, one thread for rendering

Sam Raby
Hello,

Is there an example that shows how to construct data-reading pipeline in one thread and then hand it off to the main thread for rendering? This design helps because I am constantly reading data from incoming ascii files and want to visualize them consecutively like an animation, but data reading from each file takes 200 millisecond and should not block the user from interacting with the scene, however I am open if any better architecture is preferred.

Thank you
Sam

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Jay
Reply | Threaded
Open this post in threaded view
|

Re: one thread for reading, one thread for rendering

Jay
I think this example can help you, using vtkcommand this can be achieved

https://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/Animation



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: one thread for reading, one thread for rendering

Sam Raby
Thanks Jay. The issue with using timer is that reading of each of my frames takes 200 milliseconds which freezes the screen. While I do not mind to give the reader 200 milliseconds to read the frame, I want to still be able to interact with the scene during the reading time. That is why I am looking for an example that shows how to read data in one thread and render it in another thread. 
Thanks

On Monday, May 21, 2018, Jay <[hidden email]> wrote:
I think this example can help you, using vtkcommand this can be achieved

https://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/Animation



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: one thread for reading, one thread for rendering

ochampao
Hi,

An approach that I am uing in my own applications with Qt/VTK, is to have a
Worker class that calls the Update() method of vtkAlgorithm in a separate
thread. Using this approach Qt's main thread is not blocked while waiting
for the reader to read the data.

Below I've included a method that reads from a folder multiple DICOM files
and returns a vtkImageData object for rendering. The reader is setup as
necessary in the main thread but the vtkDICOMImageReader::Update() method is
called by the Worker object in a separate thread. While the data are loaded,
the user sees a progress dialog.

Hope this helps,

Panos.

// ============================================
// = Method for loading data
// ============================================
vtkSmartPointer<vtkImageData> loadDicom(const char* filename) const
{
        vtkNew<vtkDICOMImageReader> reader;
        reader->FileLowerLeftOn();
        reader->SetDirectoryName(filename);
        reader->UpdateInformation();

        QProgressDialog progress(
                QString("Reading, please wait..."),
                QString("Close"), 0, 0);
        progress.show();
        qApp->processEvents();
        Worker thread(reader);  // calls Update()
        thread.start();
        while (!thread.isDone())
                qApp->processEvents();
        thread.quit(); // Stop thread's event loop.
        progress.hide();

        return reader->GetOutput();
}

// ============================================
// = Worker class for calling vtkAlgorithm::Update() in separate thread
// ============================================
#ifndef WORKER_H
#define WORKER_H

#include <QThread>
#include <vtkAlgorithm.h>

class Worker : public QThread
{
        Q_OBJECT

public:
        Worker(vtkAlgorithm *f) :
                QThread(),
                filter(f),
                done(false) { }

        bool isDone() { return this->done; }

protected:
        void run()
        {
                filter->Update(); // Read image.
                done = true;
        }

private:
        volatile bool done;
        vtkAlgorithm *filter;
};

#endif // !WORKER_H



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: one thread for reading, one thread for rendering

ochampao
Sorry, I forgot to mention that the code samle for the Worker class was
inspired from here:

http://www.comp.nus.edu.sg/~cs3249/lecture/multithreading.pdf
<http://www.comp.nus.edu.sg/~cs3249/lecture/multithreading.pdf>  



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers