32 #ifndef KJB_CPP_M_CPP_M_CONVOLVE_H
33 #define KJB_CPP_M_CPP_M_CONVOLVE_H
48 #warning "This code requires FFTW version 3 to work properly."
58 #include <boost/scoped_ptr.hpp>
59 #include <boost/shared_ptr.hpp>
73 #define KJB_FFTW_VECTOR_NEEDS_END 0
92 #if KJB_FFTW_VECTOR_NEEDS_END
95 FFTW_vector<T>(
const FFTW_vector<T>&);
96 FFTW_vector<T>& operator=(
const FFTW_vector<T>&);
99 FFTW_vector(
size_t n = 0)
102 if (n && 0 == (m_begin = (T*) FFTW::fftw_malloc(
sizeof(T) * n)))
106 #if KJB_FFTW_VECTOR_NEEDS_END
113 if (m_begin) FFTW::fftw_free(m_begin);
121 const T* begin()
const
126 #if KJB_FFTW_VECTOR_NEEDS_END
138 void swap(FFTW_vector<T>& v)
141 swap(m_begin, v.m_begin);
142 #if KJB_FFTW_VECTOR_NEEDS_END
143 swap(m_end, v.m_end);
186 FFTW::fftw_plan plan;
197 FFTW::fftw_complex* out,
200 : plan(FFTW::fftw_plan_dft_r2c_2d(n0, n1, in, out, flags))
205 ~FFTW_Plan2d<double, FFTW::fftw_complex>()
207 FFTW::fftw_destroy_plan(plan);
212 FFTW::fftw_execute(plan);
215 void new_array_exec(
double *in, FFTW::fftw_complex *out)
const
217 FFTW::fftw_execute_dft_r2c(plan, in, out);
224 class FFTW_Plan2d<FFTW::fftw_complex, double>
226 FFTW::fftw_plan plan;
228 FFTW_Plan2d<FFTW::fftw_complex, double>(
229 const FFTW_Plan2d<FFTW::fftw_complex, double>&);
230 FFTW_Plan2d<FFTW::fftw_complex, double>& operator=(
231 const FFTW_Plan2d<FFTW::fftw_complex, double>&);
233 FFTW_Plan2d<FFTW::fftw_complex, double>(
236 FFTW::fftw_complex* in,
240 : plan(FFTW::fftw_plan_dft_c2r_2d(n0, n1, in, out, flags))
242 if (0 == plan)
KJB_THROW(Resource_exhaustion);
245 ~FFTW_Plan2d<FFTW::fftw_complex, double>()
247 FFTW::fftw_destroy_plan(plan);
252 FFTW::fftw_execute(plan);
255 void new_array_exec(FFTW::fftw_complex *in,
double* out)
const
257 FFTW::fftw_execute_dft_c2r(plan, in, out);
263 typedef FFTW_Plan2d<double, FFTW::fftw_complex> FFTW_plan_r2c;
266 typedef FFTW_Plan2d<FFTW::fftw_complex, double> FFTW_plan_c2r;
405 typedef std::pair< boost::shared_ptr<FFTW_real_vector>,
412 Sizes(
int,
int,
int,
int);
486 void reset_data_plan_()
const;
488 void convolution_by_dft_()
const;
497 const int fft_algorithm_type_;
506 boost::scoped_ptr<FFTW_plan_r2c> mask_plan_;
507 mutable boost::scoped_ptr<FFTW_plan_r2c> data_plan_;
508 mutable boost::scoped_ptr<FFTW_plan_c2r> data_inv_plan_;
524 return b.first.unique() && b.second.unique();
535 const Fftw_convolution_2d::Sizes&
int mask_cols
Definition: m_convolve.h:411
const int FFTW_PATIENT
Definition: m_convolve.h:51
RAII class to manage an FFTW plan.
Definition: m_convolve.h:176
const int FFTW_EXHAUSTIVE
Definition: m_convolve.h:52
void execute(const Matrix &i, Matrix &o) const
deprecated synonym for convolve method
Definition: m_convolve.h:453
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
int mask_rows
Definition: m_convolve.h:411
int get_num_rows() const
Return the number of rows in the matrix.
Definition: m_matrix.h:543
bool work_buffer_is_unique(const Fftw_convolution_2d::Work_buffer &b)
test whether a Work_buffer object is the last handle to its memory
Definition: m_convolve.h:522
void * FFTW_real_vector
Definition: m_convolve.h:159
void swap(Perspective_camera &cam1, Perspective_camera &cam2)
Swap two cameras.
Definition: perspective_camera.h:599
const int FFTW_MEASURE
Definition: m_convolve.h:50
bool is_matrix_size_same_as_data_size(const Matrix &m) const
Definition: m_convolve.h:414
Fftw_convolution_2d(int data_num_rows, int data_num_cols, int mask_max_rows, int mask_max_cols, int fft_alg_type=FFTW_MEASURE)
Initialize the convolver by specifying data and mask dimensions.
Definition: m_convolve.cpp:442
#define KJB_THROW(ex)
Definition: l_exception.h:46
int pad_rows
Definition: m_convolve.h:411
int data_cols
Definition: m_convolve.h:411
Object thrown if a resource allocation failed (memory, fp, etc.)
Definition: l_exception.h:635
A class for performing 2d convolution using the FFTW library.
Definition: m_convolve.h:402
int Ncomplex() const
Definition: m_convolve.h:426
void set_mask(const Matrix &)
set mask, which must fit with mask size maxima given to ctor
Definition: m_convolve.cpp:661
int get_num_cols() const
Return the number of columns in the matrix.
Definition: m_matrix.h:554
Work_buffer allocate_work_buffer() const
get a handle to a work buffer needed for threadsafe convolution.
Definition: m_convolve.cpp:703
int test_reflect_into_input_buf(const Matrix &in, Matrix *out, const Fftw_convolution_2d::Sizes &s)
test function provides transparency to hidden reflect_into_input_buf
Definition: m_convolve.cpp:728
bool is_mask_set() const
read access of the flag indicating whether the mask has been set
Definition: m_convolve.h:476
void set_gaussian_mask(double sigma)
set mask to a circular gaussian kernel of given sigma (pixels)
Definition: m_convolve.cpp:662
Sizes(int, int, int, int)
Definition: m_convolve.cpp:409
utility aggregate stores all sizes – rarely used by caller
Definition: m_convolve.h:409
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
const Sizes & get_sizes() const
read access to the sizes specified at ctor time
Definition: m_convolve.h:470
int pad_cols
Definition: m_convolve.h:411
int Nreal() const
Definition: m_convolve.h:422
void * FFTW_complex_vector
Definition: m_convolve.h:158
bool is_matrix_size_within_mask_size(const Matrix &m) const
Definition: m_convolve.h:418
void reflect_and_convolve(const Matrix &, Matrix &) const
convolve with mask, assuming input reflects at its boundaries
Definition: m_convolve.cpp:664
const int FFTW_DESTROY_INPUT
Definition: m_convolve.h:53
int data_rows
Definition: m_convolve.h:411
const int FFTW_ESTIMATE
Definition: m_convolve.h:49
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
for m
Definition: APPgetLargeConnectedEdges.m:64
void convolve(const Matrix &, Matrix &) const
Definition: m_convolve.cpp:663
std::pair< boost::shared_ptr< FFTW_real_vector >, boost::shared_ptr< FFTW_complex_vector > > Work_buffer
Definition: m_convolve.h:406