コード例 #1
0
ファイル: filter.cpp プロジェクト: maddisoj/imgen
void filter(image& img, const filter_t& filter)
{
    auto fw = filter.size1();
    auto fh = filter.size2();
    auto num_channels = gil::num_channels<image::pixel_t>();

    // Calculates the correlation result for each region. The correlation result
    // is calculated by multiplying the respective elements in neighbourhood and
    // filter mask and then taking the sum of those elements. This is done for
    // each channel of the pixel.
    nlfilter(img, fw, fh, [&](const ublas::matrix<image::pixel_t>& neighbourhood) {
        image::pixel_t correlation;

        for(decltype(fw) i = 0; i < fw; ++i) {
            for(decltype(fh) j = 0; j < fh; ++j) {
                const auto& src = neighbourhood(i, j);

                for(auto c = 0; c < num_channels; ++c) {
                    auto element_corr = src[c] * filter(i, j);

                    if(i == 0 && j == 0) {
                        correlation[c] = element_corr;
                    } else {
                        correlation[c] += element_corr;
                    }
                }
            }
        }

        return correlation;
    });
}
コード例 #2
0
ファイル: movement.cpp プロジェクト: Oxyd/APNS
int check_captures(position src, position dst, board const& board,
                   piece what, OutIter out) {
  piece::color_t const player = what.color();
  board::mask supporters;

  int score = 0;

  if (trap(dst)) {
    supporters = neighbourhood(dst) & board.player(player);
    supporters[src] = false;

    // Check for piece stepping into a trap.
    if (supporters.empty()) {
      *out++ = elementary_step::make_capture(dst, what);
      score -= CAPTURE_COEF * cost(what, src);
    }
  }

  // Check for piece abandoning another one standing on a trap.
  if (neighbourhood(src) & board::mask::TRAPS && !trap(dst)) {
    position const trap =
      (neighbourhood(src) & board::mask::TRAPS).first_set();
    boost::optional<piece> const trapped = board.get(trap);
    if (trapped) {
      piece::color_t const trapped_player = trapped->color();
      supporters = neighbourhood(trap) & board.player(trapped_player);
      supporters[src] = false;

      if (supporters.empty()) {
        *out++ = elementary_step::make_capture(trap, *trapped);
        score +=
          (trapped->color() == what.color() ? -1 : +1) *
          CAPTURE_COEF * cost(*trapped, trap);
      }
    }
  }

  return score;
}
コード例 #3
0
double nextgridstate(double t, Grid curstate, Grid nextstate) {
  /* update cell states asynchronously*/ 
  for (int x = 0; x < xmax; x++) {
    for (int y = 0; y < ymax; y++) {
      nextcellstate(t,
                    cell(curstate, x, y), 
                    neighbourhood(x, y), 
                    cell(nextstate, x, y));
    }
  }

  return t + 1.0;
}