void Projection::init(const IMP::algebra::Vector3Ds& points, double max_radius, int axis_size) { // determine the image size needed to store the projection x_min_ = y_min_ = std::numeric_limits<float>::max(); x_max_ = y_max_ = std::numeric_limits<float>::min(); // determine translation to center algebra::Vector3D center(0.0, 0.0, 0.0); for (unsigned int i = 0; i < points.size(); i++) { x_min_ = std::min(x_min_, points[i][0]); y_min_ = std::min(y_min_, points[i][1]); x_max_ = std::max(x_max_, points[i][0]); y_max_ = std::max(y_max_, points[i][1]); center += points[i]; } center /= points.size(); static IMP::em::KernelParameters kp(resolution_); const IMP::em::RadiusDependentKernelParameters& params = kp.get_params(max_radius); double wrap_length = 2 * params.get_kdist() + 1.0; x_min_ = x_min_ - wrap_length - scale_; y_min_ = y_min_ - wrap_length - scale_; x_max_ = x_max_ + wrap_length + scale_; y_max_ = y_max_ + wrap_length + scale_; int width = (int)((x_max_ - x_min_) / scale_ + 2); int height = (int)((y_max_ - y_min_) / scale_ + 2); int size = std::max(width, height); // the determined size should be below axis size if specified if (axis_size > 0 && size <= axis_size) size = axis_size; else { IMP_WARN("wrong size estimate " << size << " vs. estimate " << axis_size << std::endl); } this->resize(boost::extents[size][size]); int i = 0, j = 0; get_index_for_point(center, i, j); t_i_ = size / 2 - i; t_j_ = size / 2 - j; }
void Projection::project(const IMP::algebra::Vector3Ds& points, const std::vector<double>& mass) { // get mask const std::vector<MaskCell>& mask = get_sphere_mask(); int i, j; for (unsigned int p_index = 0; p_index < points.size(); p_index++) { // project if (get_index_for_point(points[p_index], i, j)) { for (unsigned int mask_index = 0; mask_index < mask.size(); mask_index++) { int i_shift = mask[mask_index].i; int j_shift = mask[mask_index].j; double density = mask[mask_index].d; (*this)[i + i_shift][j + j_shift] += mass[i] * density; } } } }