Stream of Cloud Point Visualization using PCL
Asked Answered
S

1

13

I am doing some processing on RGB and Depth data and constructing cloud points that are to be visualized, I currently use PCL Visualizer and it works fine. I want to have the visualizer in a different thread (real time so it will redraw the global cloud point, I tried boost threads but I get a runtime error "VTK bad lookup table"

Anyone knows how to visualize stream of cloud points in a different thread ?

Stickseed answered 25/1, 2012 at 13:7 Comment(0)
S
9

OK, I got it to work now, maybe I did something wrong before, here is how I did it using boost threads and mutex

    bool update;
    boost::mutex updateModelMutex;
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);

    void visualize()  
    {  
        // prepare visualizer named "viewer"

        while (!viewer->wasStopped ())
        {
            viewer->spinOnce (100);
            // Get lock on the boolean update and check if cloud was updated
            boost::mutex::scoped_lock updateLock(updateModelMutex);
            if(update)
            {
                if(!viewer->updatePointCloud(cloud, "sample cloud"))
                  viewer->addPointCloud(cloud, colorHandler, "sample cloud");
                update = false;
            }
            updateLock.unlock();

        }   
   }  


    int main()
    {
        //Start visualizer thread
        boost::thread workerThread(visualize); 

        while(notFinishedProcessing)
        {
           boost::mutex::scoped_lock updateLock(updateModelMutex);
          update = true;
          // do processing on cloud
           updateLock.unlock();

        }
        workerThread.join();  
    }

UPDATE:

According to this page The reason is that adding an empty point cloud to the visualizer causes things to go crazy so I edited the code above

Stickseed answered 25/1, 2012 at 23:59 Comment(4)
Hi @khaled !. So, is the viusalizer running in a different thread and working well?. In the PCLVisualizer doxy docs I found this: This class can NOT be used across multiple threads. Only call functions of objects of this class from the same thread that they were created in! Some methods, e.g. addPointCloud, will crash if called from other threads. I'm really interested in having the visualizer running in another thread, so please. Could you confirm that your approach is working?. :DMcmahan
yes this actually works. the docs is still correct, you should call methods like addPointCloud only from the thread of the visualization not from another thread. So you can't call addPointCloud from the main method if your visualization loop is in a different thread.Stickseed
Hey!. I tried your snippet and it worked like a charm. You're a lifesaver, man!. Thanks!.Mcmahan
How to use this code? Where are we supposed to place it even? Inside the visualizer? Some context would be helpful.Coast

© 2022 - 2024 — McMap. All rights reserved.