7 #ifndef IMPEM2D_PROJECTION_MASK_H
8 #define IMPEM2D_PROJECTION_MASK_H
10 #include <IMP/em2d/em2d_config.h>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/serialization/access.hpp>
26 #include <boost/serialization/split_free.hpp>
28 IMPEM2D_BEGIN_NAMESPACE
33 typedef boost::shared_ptr<ProjectionMask> ProjectionMaskPtr;
34 typedef boost::shared_ptr<MasksManager> MasksManagerPtr;
41 #if !defined(DOXYGEN) && !defined(SWIG)
43 double voxelsize,
double mass = 1.0);
61 void show(std::ostream &out = std::cout)
const;
70 friend class boost::serialization::access;
72 template<
class Archive>
void serialize(Archive &ar,
const unsigned int) {
73 ar & dim_ & sq_pixelsize_ & data_;
82 namespace serialization {
83 template<
class Archive>
inline void save(
84 Archive &ar,
const std::map<double, IMP::em2d::ProjectionMaskPtr> &m,
88 for (
const auto &p : m) {
94 template<
class Archive>
inline void load(
95 Archive &ar, std::map<double, IMP::em2d::ProjectionMaskPtr> &m,
100 for (
size_t i = 0; i < sz; ++i) {
109 template<
class Archive>
inline void serialize(
110 Archive &ar, std::map<double, IMP::em2d::ProjectionMaskPtr> &m,
111 const unsigned int version) {
112 boost::serialization::split_free(ar, m, version);
117 IMPEM2D_BEGIN_NAMESPACE
135 center[0] =
static_cast<int>(0.5 * m.rows);
136 center[1] =
static_cast<int>(0.5 * m.cols);
138 int start[2], end[2];
139 start[0] = -center[0];
140 start[1] = -center[1];
141 end[0] = m.rows - 1 - center[0];
142 end[1] = m.cols - 1 - center[1];
145 if (vi < start[0] || vi > end[0])
return;
146 if (vj < start[1] || vj > end[1])
return;
150 mcenter[0] =
static_cast<int>(0.5 * mask.rows);
151 mcenter[1] =
static_cast<int>(0.5 * mask.cols);
153 int mstart[2], mend[2];
154 mstart[0] = -mcenter[0];
155 mstart[1] = -mcenter[1];
156 mend[0] = mask.rows - 1 - mcenter[0];
157 mend[1] = mask.cols - 1 - mcenter[1];
160 int start_i = std::max(start[0] - vi, mstart[0]);
161 int start_j = std::max(start[1] - vj, mstart[1]);
162 int end_i = std::min(end[0] - vi, mend[0]);
163 int end_j = std::min(end[1] - vj, mend[1]);
165 int row = vi + center[0];
166 int col = vj + center[1];
168 for (
int i = start_i; i <= end_i; ++i) {
170 for (
int j = start_j; j <= end_j; ++j) {
171 m.at<
double>(p, j + col) +=
172 mask.at<
double>(i + mcenter[0], j + mcenter[1]);
185 setup_kernel(resolution, pixelsize);
191 pixelsize_ = pixelsize;
203 void create_mask(
double mass);
206 ProjectionMaskPtr find_mask(
double mass);
208 void show(std::ostream &out = std::cout)
const;
210 unsigned int get_number_of_masks()
const {
return mass2mask_.size(); }
216 std::map<double, ProjectionMaskPtr> mass2mask_;
224 friend class boost::serialization::access;
226 template<
class Archive>
void serialize(Archive &ar,
const unsigned int) {
227 ar & mass2mask_ & kernel_params_ & pixelsize_ & is_setup_;
234 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.
Decorator for OpenCV matrix to use relative coordinates Copyright 2007-2022 IMP Inventors. All rights reserved.