7 #ifndef IMPEM2D_PROJECTION_MASK_H
8 #define IMPEM2D_PROJECTION_MASK_H
10 #include <IMP/em2d/em2d_config.h>
24 #include <cereal/access.hpp>
26 IMPEM2D_BEGIN_NAMESPACE
31 typedef std::shared_ptr<ProjectionMask> ProjectionMaskPtr;
32 typedef std::shared_ptr<MasksManager> MasksManagerPtr;
39 #if !defined(DOXYGEN) && !defined(SWIG)
41 double voxelsize,
double mass = 1.0);
59 void show(std::ostream &out = std::cout)
const;
68 friend class cereal::access;
70 template<
class Archive>
void serialize(Archive &ar) {
71 ar(dim_, sq_pixelsize_, data_);
80 template<
class Archive>
inline void save(
81 Archive &ar,
const std::map<
double,
82 IMP::em2d::ProjectionMaskPtr> &m) {
85 for (
const auto &p : m) {
91 template<
class Archive>
inline void load(
92 Archive &ar, std::map<double, IMP::em2d::ProjectionMaskPtr> &m) {
96 for (
size_t i = 0; i < sz; ++i) {
106 IMPEM2D_BEGIN_NAMESPACE
124 center[0] =
static_cast<int>(0.5 * m.rows);
125 center[1] =
static_cast<int>(0.5 * m.cols);
127 int start[2], end[2];
128 start[0] = -center[0];
129 start[1] = -center[1];
130 end[0] = m.rows - 1 - center[0];
131 end[1] = m.cols - 1 - center[1];
134 if (vi < start[0] || vi > end[0])
return;
135 if (vj < start[1] || vj > end[1])
return;
139 mcenter[0] =
static_cast<int>(0.5 * mask.rows);
140 mcenter[1] =
static_cast<int>(0.5 * mask.cols);
142 int mstart[2], mend[2];
143 mstart[0] = -mcenter[0];
144 mstart[1] = -mcenter[1];
145 mend[0] = mask.rows - 1 - mcenter[0];
146 mend[1] = mask.cols - 1 - mcenter[1];
149 int start_i = std::max(start[0] - vi, mstart[0]);
150 int start_j = std::max(start[1] - vj, mstart[1]);
151 int end_i = std::min(end[0] - vi, mend[0]);
152 int end_j = std::min(end[1] - vj, mend[1]);
154 int row = vi + center[0];
155 int col = vj + center[1];
157 for (
int i = start_i; i <= end_i; ++i) {
159 for (
int j = start_j; j <= end_j; ++j) {
160 m.at<
double>(p, j + col) +=
161 mask.at<
double>(i + mcenter[0], j + mcenter[1]);
174 setup_kernel(resolution, pixelsize);
180 pixelsize_ = pixelsize;
192 void create_mask(
double mass);
195 ProjectionMaskPtr find_mask(
double mass);
197 void show(std::ostream &out = std::cout)
const;
199 unsigned int get_number_of_masks()
const {
return mass2mask_.size(); }
205 std::map<double, ProjectionMaskPtr> mass2mask_;
213 friend class cereal::access;
215 template<
class Archive>
void serialize(Archive &ar) {
216 ar(mass2mask_, kernel_params_, pixelsize_, is_setup_);
223 IMPEM2D_END_NAMESPACE
A decorator for particles with mass.
Calculates and stores Gaussian kernel parameters.
void setup_kernel(double resolution, double pixelsize)
Initializes the kernel.
Calculates and stores Gaussian kernel parameters.
Interface with OpenCV Copyright 2007-2022 IMP Inventors. All rights reserved.
Exception definitions and assertions.
An approximation of the exponential function.
A more IMP-like version of the std::vector.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
int get_rounded(const T &x)
Rounds a number to next integer.
Stores and converts spherical coordinates.
Simple 3D rotation class.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
void do_place(cv::Mat &mask, cv::Mat &m, const algebra::Vector2D &v)
Decorator for a sphere-like particle.
Management of projection masks.