7 #ifndef IMPEM2D_POLAR_RESAMPLING_PARAMETERS_H
8 #define IMPEM2D_POLAR_RESAMPLING_PARAMETERS_H
11 #include "IMP/em2d/em2d_config.h"
18 IMPEM2D_BEGIN_NAMESPACE
28 parameters_set_=
false;
52 void setup(
unsigned int rows,
unsigned int cols) {
57 ending_radius_=std::min(rows/2.,cols/2.);
58 n_rings_ = cv::getOptimalDFTSize((
int)ending_radius_);
59 radius_step_ = (ending_radius_-starting_radius_)/
60 (static_cast<double>(n_rings_));
61 parameters_set_ =
true;
63 "PolarResamplingParameters setup. Input matrix: "
64 << rows <<
" x " << cols
65 <<
" Starting radius= " << starting_radius_ <<
" Ending radius= "
66 << ending_radius_ <<
" Rings= " << n_rings_ << std::endl);
73 return starting_radius_;
79 return ending_radius_;
86 "PolarResamplingParameters: Requested ring is above the maximum number");
87 return starting_radius_+n_ring*radius_step_;
100 n_angles_ = cv::getOptimalDFTSize(aprox_value);
101 angle_step_ = (2*
PI) / static_cast<double>(n_angles_);
118 if(get_is_setup() ==
false) {
119 IMP_THROW(
"trying to get radius_step before initializing",
120 IMP::ValueException);
129 IMP_THROW(
"Number of sampling points for the angle is zero",
130 IMP::ValueException);
133 polar_map_.create(n_rings_,n_angles_,CV_32FC2);
137 for (
unsigned int i=0;i<n_rings_;++i) {
138 for (
unsigned int j=0;j<n_angles_;++j) {
139 double r = get_radius(i);
140 double theta = j*angle_step_;
142 double row =
static_cast<double>(matrix_rows_)/2.0 + r* sin(theta);
143 double col =
static_cast<double>(matrix_cols_)/2.0 + r* cos(theta);
144 polar_map_.at<cv::Vec2f>(i,j)[0] = static_cast<float>(row);
145 polar_map_.at<cv::Vec2f>(i,j)[1] = static_cast<float>(col);
150 cv::convertMaps(polar_map_,empty,map_16SC2_, map_16UC1_, CV_16SC2);
164 << polar_map_.rows <<
"x" << polar_map_.cols
165 <<
" depth " << polar_map_.depth()
166 <<
" type " << polar_map_.type() << std::endl);
171 void show(std::ostream &out)
const {
172 out <<
"starting_radius = " << starting_radius_ << std::endl;
173 out <<
"ending_radius = " << ending_radius_ << std::endl;
174 out <<
"n_rings = " << n_rings_ << std::endl;
178 bool get_is_setup()
const {
179 if(parameters_set_)
return true;
187 double starting_radius_;
188 double ending_radius_;
190 unsigned int n_rings_,n_angles_,matrix_rows_,matrix_cols_;
191 bool parameters_set_;
192 double radius_step_,angle_step_;
198 IMPEM2D_END_NAMESPACE