/** * \file ProjectionMask.cpp * \brief projection masks * Copyright 2007-2013 IMP Inventors. All rights reserved. */ #include "IMP/em2d/ProjectionMask.h" #include "IMP/exception.h" IMPEM2D_BEGIN_NAMESPACE ProjectionMask::~ProjectionMask() { IMP_LOG_VERBOSE(" Projection mask destroyed." << std::endl); } ProjectionMask::ProjectionMask(const em::KernelParameters &KP, const em::RadiusDependentKernelParameters ¶ms, double pixelsize, double mass) { sq_pixelsize_ = pixelsize*pixelsize; // dim_ = 2*floor(params->get_kdist()/pixelsize)+1; // data_.create(dim_,dim_,CV_64FC1); dim_ = floor(params.get_kdist()/pixelsize); int mask_size = 2*dim_+1; // enough to go from -dim to dim data_.create(mask_size,mask_size,CV_64FC1); data_.setTo(0.0); create(KP,params, mass); } void ProjectionMask::apply(cv::Mat &m, const algebra::Vector2D &v) { do_place(data_, m, v); } void ProjectionMask::create(const em::KernelParameters &KP, const em::RadiusDependentKernelParameters ¶ms, double mass) { // Decorate the masks to use centered coordinates CenteredMat centered_mask(data_); IMP_LOG_VERBOSE(" Generating mask. " << centered_mask); double tmp,square_radius; for(int i=-dim_;i<=dim_;++i) { double isq = static_cast(i*i); for(int j=-dim_;j<=dim_;++j) { double jsq = static_cast(j*j); double ijsq = isq+jsq; for(int k=-dim_;k<=dim_;++k) { square_radius = (ijsq + static_cast(k*k))*sq_pixelsize_; // Add the value to the mask tmp= em::EXP(-square_radius * params.get_inv_sigsq()); // if statement to ensure even sampling within the box if (tmp> KP.get_lim() && centered_mask.get_is_in_range(i,j) ) { centered_mask(i,j) += params.get_normfac()*tmp * mass; } } } } IMP_LOG_VERBOSE(" Mask generated. " << std::endl); } void ProjectionMask::show(std::ostream &out) const { out << "ProjectionMask size " << data_.rows << "x" << data_.cols << std::endl; } ProjectionMaskPtr MasksManager::find_mask(double radius) { IMP_LOG_VERBOSE("Finding mask for radius " << radius << std::endl); std::map::iterator iter = radii2mask_.find(radius); if(iter == radii2mask_.end()) return ProjectionMaskPtr(); // null return iter->second; } void MasksManager::create_masks(const ParticlesTemp &ps) { IMP_LOG_TERSE("Creating Projection Masks " << std::endl); ProjectionMaskPtr mask; unsigned long n_particles = ps.size(); for (unsigned long i=0; ifind_mask(radius); if (!mask) { atom::Mass mass(ps[i]); double w = mass.get_mass(); this->create_mask(radius, w); } } IMP_LOG_TERSE("Finished creating Projection Masks " << std::endl); } void MasksManager::create_mask(double radius, double mass) { IMP_LOG_VERBOSE("Creating a projection mask for radius " << radius <