void HomogeneousPoint3fIntegralImage::compute(const Eigen::MatrixXi &indices, const HomogeneousPoint3fVector &points) {
  if (cols() != indices.cols() || rows() != indices.rows())
    resize(indices.rows(), indices.cols());
  clear();
  
  HomogeneousPoint3fAccumulator *acc = data();
  const int *pointIndex = indices.data();
  int s = rows() * cols();
  // fill the accumulators with the points
  for (int i=0; i<s; i++, acc++, pointIndex++){
    if (*pointIndex<0)
      continue;
    const HomogeneousPoint3f& point = points[*pointIndex];
    acc->operator += (point);
  }

  // fill by column
  #pragma omp parallel for
  for (int c=0; c<cols(); c++){
    for (int r=1; r<rows(); r++){
      coeffRef(r,c) += coeffRef(r-1,c);
    }
  }

  // fill by row
  #pragma omp parallel for
  for (int r=0; r<rows(); r++){
    for (int c=1; c<cols(); c++){
      coeffRef(r,c) += coeffRef(r,c-1);
    }
  }
}
HomogeneousPoint3fAccumulator HomogeneousPoint3fIntegralImage::getRegion(int xmin, int xmax, int ymin, int ymax) const {
  HomogeneousPoint3fAccumulator pa;
  if (! rows() || !cols())
    return pa;
  xmin = _clamp(xmin-1, 0, rows()-1);
  xmax = _clamp(xmax-1, 0, rows()-1);
  ymin = _clamp(ymin-1, 0, cols()-1);
  ymax = _clamp(ymax-1, 0, cols()-1);
  pa = coeffRef(xmax,ymax); //total
  pa += coeffRef(xmin,ymin);  //upper right
  pa -= coeffRef(xmin, ymax);  //upper rectangle
  pa -= coeffRef(xmax, ymin);  //rightmost rectangle
  return pa;
}
Esempio n. 3
0
void Bitmap::printB64Encoded(const Vector2i &glbSize, const Vector2i &lclSize, const Point2i &offset, const int percent) {
    png::image<png::rgb_pixel> img(cols(), rows());

        for(int i=0;i < rows();i++)
            for(int j=0;j<cols();j++)
            {
                Color4f  curColor = coeffRef(i, j);
                png::rgb_pixel pixel((int) (clamp(std::pow(curColor(0), 1.0f / m_gamma), 0.0f, 1.0f) * 255.0f),
                                     (int) (clamp(std::pow(curColor(1), 1.0f / m_gamma), 0.0f, 1.0f) * 255.0f),
                                     (int) (clamp(std::pow(curColor(2), 1.0f / m_gamma), 0.0f, 1.0f) * 255.0f));
                img.set_pixel(j, i, pixel);
            }
    std::ostringstream buf;
    img.write_stream(buf);
    const std::string s = buf.str();

    //ToDo write function convert the image to base64 data @Markus
    std::string b64imgData = base64_encode(reinterpret_cast<unsigned char const*>(s.c_str()), s.length());

    cout << "{\"percentage\" : " << percent << ",";
    cout << "\"x\" : " << offset(0) << ",";
    cout << "\"y\" : " << offset(1) << ",";
    cout << "\"width\" : " << glbSize(0) << ",";
    cout << "\"height\" : " << glbSize(1) << ",";
    cout << "\"patchWidth\" : " << lclSize(0) << ",";
    cout << "\"patchHeight\" : " << lclSize(1) << ",";
    cout << "\"data\" : \"data:image/png;base64," << b64imgData << "\"}" << endl;
    cout.flush();
}
Esempio n. 4
0
void Bitmap::savePNG(const std::string &filename, const int percent) {
    //cout << "{\"percentage\" : " << percent << "}" << endl;
    //cout.flush();
    png::image<png::rgb_pixel> img(cols(), rows());

        for(int i=0;i < rows();i++)
            for(int j=0;j<cols();j++)
            {
                Color4f  curColor = coeffRef(i, j);
                png::rgb_pixel pixel((int) (clamp(std::pow(curColor(0), 1.0f / m_gamma), 0.0f, 1.0f) * 255.0f),
                                     (int) (clamp(std::pow(curColor(1), 1.0f / m_gamma), 0.0f, 1.0f) * 255.0f),
                                     (int) (clamp(std::pow(curColor(2), 1.0f / m_gamma), 0.0f, 1.0f) * 255.0f));
                img.set_pixel(j, i, pixel);
            }


        //Write png to file
        img.write(filename);
}