Point Cloud Library: Sliced points to custom colors



  • I'm using pcl and vtk library with Qt for point cloud visualization. My setup is as the below link http://unanancyowen.com/en/pcl-with-qt/

    Now when we slice points ie, press 'x' and select a region by AreaPickingEvent and that selected sliced points become red colored. It's done by the following function

    void PointCloudVisualizer::highlightPoint(std::vector<int>& slice)
        {
            if (slice.size()<1) return;
    
            for (std::vector<int>::iterator it = slice.begin(); it != slice.end(); it++)    {
                m_cloudLabel[*it] = SELECTED_POINT;//SELECTED_POINT = 1
            }
        }
    
       void PointCloudVisualizer::updateCloud()
       {
        m_pViewer->updatePointCloud<PointT>(m_pCloud, m_pColorHandler, m_sCurrentPointCloudId.toStdString());
        m_pPointCloudVisualizerUI->qvtkWidget->update();
    }
    
    //area picking event, after the points are sliced we call these 2 functions and the sliced points gets red
    void PointCloudVisualizer::AreaPickingEventProcess(const pcl::visualization::AreaPickingEvent& event)
    {
        vector<int> newSelectedSliceVector;
        event.getPointsIndices(newSelectedSliceVector);
    
        if (newSelectedSliceVector.empty()) return;
    
        // remove ground points
        vector<int> groundPointsVector;
    
        for (auto point : newSelectedSliceVector)
        {
            if (m_cloudLabel[point] != GROUND_POINT)
            {
                groundPointsVector.push_back(point);
            }
        }
        .
        .
        .
        newSelectedSliceVector = groundPointsVector;
    
        m_lastSelectedSliceVector = newSelectedSliceVector;
        .
        .
        .
        highlightPoint(m_lastSelectedSliceVector);//red color selected points
        updateCloud();
        .
        .
        .
        }
    
    //other variables
        int* m_cloudLabel;
        PointCloudTPtr m_pCloud;
    
        //initializing m_cloudLabel
        m_cloudLabel = new int[m_pCloud->size()];
        memset(m_cloudLabel, 0, m_pCloud->size()*sizeof(int));
    
        m_pColorHandler.setInputCloud(m_pCloud);
        m_pColorHandler.setLabel(m_cloudLabel);
        //----------------------------------------
    
        const int DEFAULT_POINT =  0;
        const int SELECTED_POINT = 1;
    const int GROUND_POINT = 2;
    

    Now if we pass GROUND_POINT it becomes blue color, which is used for Plane detect or threshold.

    Now my requirement is to color the sliced points as the user defines it. How can I apply my custom color to the sliced points by pcl::RGB.

    Any suggestion is appreciated!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.