Пример #1
0
QLineF CurveTracker::curveLineAt( 
    const QwtPlotCurve *curve, double x ) const
{
    QLineF line;

    if ( curve->dataSize() >= 2 )
    {
        const QRectF br = curve->boundingRect();
        if ( ( br.width() > 0 ) && ( x >= br.left() ) && ( x <= br.right() ) )
        {
            int index = qwtUpperSampleIndex<QPointF>( 
                *curve->data(), x, compareX() );

            if ( index == -1 && 
                x == curve->sample( curve->dataSize() - 1 ).x() )
            {
                // the last sample is excluded from qwtUpperSampleIndex
                index = curve->dataSize() - 1;
            }

            if ( index > 0 )
            {
                line.setP1( curve->sample( index - 1 ) );
                line.setP2( curve->sample( index ) );
            }
        }
    }
    
    return line;
}
Пример #2
0
static int indexLower( double x, const QwtSeriesData<QPointF> &data ) 
{
    int index = qwtUpperSampleIndex<QPointF>( data, x, compareX() );
    if ( index == -1 )
        index = data.size();

    return index - 1;
}
Пример #3
0
bool MergeHull3D::compareY(Point* first, Point* second)
{
    if(first->getCoord(1) < second->getCoord(1))
        return true;
    else
    {
        if(first->getCoord(1) == second->getCoord(1))
            return compareX(first, second);
        else
            return false;
    }
}
Пример #4
0
void calculateMatrix(std::vector<cv::Point2f>& pointList, 
                     float radius, 
                     std::vector<std::vector<cv::Point2f>>& pointMatrix)
{
  if (!pointList.size())
    return;

  std::sort(pointList.begin(), pointList.end(), compareY());

  /// try to find automaticly pixel distance *************
  if (radius < 0.)
  {
    // calculate derivation of y axis;
    std::vector<float> derivationY;
    derivationY.reserve(pointList.size());
    for (size_t i = 1; i < pointList.size(); ++i)
      derivationY.push_back(pointList[i].y - pointList[i - 1].y);

    radius = (*std::max_element(derivationY.begin(), derivationY.end())) / 2;
  }

  /// find Lines *************
  std::vector<size_t> jumpLines;
  jumpLines.push_back(0);

  for (size_t i = 1; i < pointList.size(); ++i)
  {
    float dy = abs(pointList[i - 1].y - pointList[i].y);
    if (dy > radius)
      jumpLines.push_back(i);
  }
  jumpLines.push_back(pointList.size());

  // find columns *************
  std::vector<std::vector<size_t>> jumps;
  for (size_t i = 1; i < jumpLines.size(); ++i)
  {
    size_t lo = jumpLines[i - 1];
    size_t hi = jumpLines[i];

    auto b = pointList.begin() + lo;
    auto e = pointList.begin() + hi;
    std::sort(b, e, compareX());

    std::vector<size_t> jumpColumn;
    jumpColumn.push_back(lo);
    for (size_t j = lo + 1; j < hi; ++j)
    {
      float dy = abs(pointList[j - 1].x - pointList[j].x);
      if (dy > radius)
        jumpColumn.push_back(j);
    }
    jumpColumn.push_back(hi);

    jumps.push_back(jumpColumn);
  }

  // create matrix
  pointMatrix.clear();
  pointMatrix.reserve(jumps.size());

  for (size_t y = 0; y < jumps.size(); ++y)
  {
    // calculate y mean
    size_t lineB = jumps[y].front();
    size_t lineE = jumps[y].back();

    float meanY = 0.0;
    for (size_t i = lineB; i < lineE; ++i)
      meanY += pointList[i].y;
    meanY /= (lineE - lineB);

    // calculate x 
    std::vector<cv::Point2f> linePoints;
    linePoints.reserve(jumps[y].size());

    for (size_t x = 1; x < jumps[y].size(); ++x)
    {
      size_t columnB = jumps[y][x - 1];
      size_t columnE = jumps[y][x];

      float meanX = 0.0;
      for (size_t i = columnB; i < columnE; ++i)
        meanX += pointList[i].x;
      meanX /= (columnE - columnB);

      // store point
      linePoints.push_back(cv::Point2f(meanX, meanY));
    }

    pointMatrix.push_back(linePoints);
  }
}