Skip to content
Open
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ test/examples/.DS_Store
test/examples/ohtcfrp/.DS_Store
.cache
compile_commands.json
build-test
bin/
.DS_Store
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,21 @@ option(FORCE_FETCH_DEPENDENCIES "Force using FetchContent for all dependencies"
# included, since the install directories are searched automatically by g++.

# Set files
SET(ncorr_src src/ncorr.cpp src/Strain2D.cpp src/Disp2D.cpp src/Data2D.cpp src/ROI2D.cpp src/Image2D.cpp src/Array2D.cpp)
SET(ncorr_h include/ncorr.h include/Strain2D.h include/Disp2D.h include/Data2D.h include/ROI2D.h include/Image2D.h include/Array2D.h)
SET(ncorr_src
src/ncorr.cpp
src/ncorr_seed.cpp
src/ncorr_serialization.cpp
src/ncorr_visualization.cpp
src/ImageProcessor.cpp
src/VideoImporter.cpp
src/Strain2D.cpp
src/Disp2D.cpp
src/Data2D.cpp
src/ROI2D.cpp
src/Image2D.cpp
src/Array2D.cpp
)
SET(ncorr_h include/ncorr.h include/Strain2D.h include/Disp2D.h include/Data2D.h include/ROI2D.h include/Image2D.h include/Array2D.h include/Array2DOpenCV.h include/Array2DFFTW.h include/Array2DLinSolver.h)

# Set include directory
INCLUDE_DIRECTORIES(include)
Expand Down
931 changes: 39 additions & 892 deletions include/Array2D.h

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions include/Array2DFFTW.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef ARRAY2D_FFTW_H
#define ARRAY2D_FFTW_H

#include "Array2D.h"

#include "fftw3.h"

namespace ncorr {

namespace details {
extern std::mutex fftw_mutex;

template <typename T>
class fftw_allocator final {
public:
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;

fftw_allocator() noexcept = default;
fftw_allocator(const fftw_allocator&) noexcept = default;
fftw_allocator(fftw_allocator&&) noexcept = default;
fftw_allocator& operator=(const fftw_allocator&) = default;
fftw_allocator& operator=(fftw_allocator&&) = default;
~fftw_allocator() noexcept = default;

pointer allocate(difference_type s, const void * = 0) {
pointer ptr = static_cast<pointer>(malloc_function(s * sizeof(value_type)));
if (!ptr) {
std::cerr << "Failed to allocate memory using allocate in fftw_allocator." << std::endl;
throw std::bad_alloc();
}

return ptr;
}
void deallocate(pointer ptr, difference_type) { free_function(ptr); }
void construct(pointer ptr, const_reference val = value_type()) { ::new((void *)ptr) value_type(val); }
void destroy(pointer ptr) { ptr->~value_type(); }
template<typename T2>
struct rebind { typedef fftw_allocator<T2> other; };

private:
void* malloc_function(difference_type s) { return malloc(s); }
void free_function(pointer ptr) { return free(ptr); }
};

template <>
inline void* fftw_allocator<double>::malloc_function(difference_type s) { return fftw_malloc(s); }

template <>
inline void fftw_allocator<double>::free_function(pointer ptr) { fftw_free(ptr); }
}

} // namespace ncorr

#endif
Loading