Search code examples
c++plotoverlapscatterdownsampling

find overlap and downsample scatter plot


I have huge data that consist of points(x,y) and need to present in a scatter plot.

To find overlap and remove invisible differences between the same point, I wrote bellow code :

void DownSampler::makeDownSample(QVector<double> keys,QVector<double> values, QVector<int> pixmapIdx, QSize resolution, sViewSize view)
{
m_calculating = true;
QTime now = QTime::currentTime();
QMap<QPair<double, double>,int> downsampledMap;

QSizeF stepValue( ( view.maxHorizontal - view.minHorizontal ) * m_downSampleRatio / (resolution.width() ),
                  ( view.maxVertical - view.minVertical ) * m_downSampleRatio/ (resolution.height() ) ) ;

for(int index = 0 ; index < keys.size() ; index++)
{
keys[index] = round((keys[index]) / stepValue.width());
keys[index] *= stepValue.width();

values[index] = round(values[index] / stepValue.height());
values[index] *= stepValue.height();

//remove same items
if((keys[index] >= view.minHorizontal) && (keys[index] <= view.maxHorizontal)) {
    if((values[index] >= view.minVertical) && (values[index] <= view.maxVertical)) {
    QPair<double, double> pairValue = qMakePair(keys[index], values[index]);
    if(!downsampledMap.contains(pairValue)){
        downsampledMap.insert(pairValue, pixmapIdx[index]);
    }
    }
}
}

QVector<int> retPixmapIdx;
QVector<double> retKey, retValue;
for(QMap<QPair<double, double>,int>::iterator iter = downsampledMap.begin() ; iter != downsampledMap.end() ; ++iter)
{
    retKey.append(iter.key().first);
    retValue.append(iter.key().second);
    retPixmapIdx.append(iter.value());
}

emit downSampledPlotReady(retKey, retValue, retPixmapIdx);
m_calculating = false;
//      qDebug() << __FUNCTION__ << "firstPointSize ==> "<< keys.size() << "downsampledSize ==> " << retKey.size() << "time ==> " << now.msecsTo(QTime::currentTime());
}

as you can see, at first, I rounded all positions to a pixel size step that expects to present data and after all iterate to all created boxes and return the created box list. according to this code, every box can contain many points, we return just a single position and therefore overlap point was removed. it's my handwriting code but I think it hasn't the best-expected performance. my question is : 1- is there any library or algorithm that collects all scatter data like our dependency? 2- is an improvement in our source code?


Solution

  • the point cloud library and Grid Voxel in 2D aspects can process and downsample point clouds perfectly.