7 #ifndef IMPEM2D_POLAR_RESAMPLING_PARAMETERS_H
8 #define IMPEM2D_POLAR_RESAMPLING_PARAMETERS_H
10 #include "IMP/em2d/em2d_config.h"
18 IMPEM2D_BEGIN_NAMESPACE
26 parameters_set_ =
false;
48 void setup(
unsigned int rows,
unsigned int cols) {
49 starting_radius_ = 5.0;
54 std::min(rows / 2., cols / 2.);
55 n_rings_ = cv::getOptimalDFTSize((
int)ending_radius_);
57 (ending_radius_ - starting_radius_) / (static_cast<double>(n_rings_));
58 parameters_set_ =
true;
60 << rows <<
" x " << cols <<
" Starting radius= "
61 << starting_radius_ <<
" Ending radius= " << ending_radius_
62 <<
" Rings= " << n_rings_ << std::endl);
68 return starting_radius_;
74 return ending_radius_;
81 "PolarResamplingParameters: Requested ring is above the "
83 return starting_radius_ + n_ring * radius_step_;
96 n_angles_ = cv::getOptimalDFTSize(aprox_value);
97 angle_step_ = (2 *
PI) / static_cast<double>(n_angles_);
110 if (get_is_setup() ==
false) {
111 IMP_THROW(
"trying to get radius_step before initializing",
120 if (n_angles_ == 0) {
121 IMP_THROW(
"Number of sampling points for the angle is zero",
125 polar_map_.create(n_rings_, n_angles_, CV_32FC2);
129 for (
unsigned int i = 0; i < n_rings_; ++i) {
130 for (
unsigned int j = 0; j < n_angles_; ++j) {
131 double r = get_radius(i);
132 double theta = j * angle_step_;
134 double row =
static_cast<double>(matrix_rows_) / 2.0 + r * sin(theta);
135 double col =
static_cast<double>(matrix_cols_) / 2.0 + r * cos(theta);
136 polar_map_.at<cv::Vec2f>(i, j)[0] = static_cast<float>(row);
137 polar_map_.at<cv::Vec2f>(i, j)[1] = static_cast<float>(col);
142 cv::convertMaps(polar_map_, empty, map_16SC2_, map_16UC1_, CV_16SC2);
156 << polar_map_.rows <<
"x" << polar_map_.cols <<
" depth "
157 << polar_map_.depth() <<
" type " << polar_map_.type()
162 void show(std::ostream &out)
const {
163 out <<
"starting_radius = " << starting_radius_ << std::endl;
164 out <<
"ending_radius = " << ending_radius_ << std::endl;
165 out <<
"n_rings = " << n_rings_ << std::endl;
168 bool get_is_setup()
const {
169 if (parameters_set_)
return true;
179 double starting_radius_;
180 double ending_radius_;
182 unsigned int n_rings_, n_angles_, matrix_rows_, matrix_cols_;
183 bool parameters_set_;
184 double radius_step_, angle_step_;
189 IMPEM2D_END_NAMESPACE
void create_maps_for_resampling()
static const double PI
the constant pi
Various useful constants.
PolarResamplingParameters(const cv::Mat &m)
void set_estimated_number_of_angles(unsigned int aprox_value)
Interface with OpenCV Copyright 2007-2020 IMP Inventors. All rights reserved.
#define IMP_LOG_VERBOSE(expr)
Exception definitions and assertions.
A more IMP-like version of the std::vector.
void get_resampling_map(cv::Mat &m1) const
double get_ending_radius() const
Gets the largest radius.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
void get_resampling_maps(cv::Mat &m1, cv::Mat &m2) const
double get_angle_step() const
get the angular step used
Logging and error reporting support.
double get_radius_step() const
Get the step for the radius coordinate.
double get_starting_radius() const
Gets the initial radius of the resampling.
unsigned int get_number_of_rings() const
Get the number of rings (that is, the number of radius values considered)
Various useful constants.
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
unsigned int get_number_of_angles() const
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
void setup(unsigned int rows, unsigned int cols)
double get_radius(unsigned int n_ring) const
Gets the current radius employed for the ring in consideration)
PolarResamplingParameters(unsigned int rows, unsigned int cols)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Logging and error reporting support.
An exception for an invalid value being passed to IMP.