CppNCorr
C++ ncorr Digital Image Correlation engine
Loading...
Searching...
No Matches
Data2D.h
Go to the documentation of this file.
1/*
2 * File: Data2D.h
3 * Author: justin
4 *
5 * Created on February 28, 2015, 8:57 PM
6 */
7
8#ifndef DATA2D_H
9#define DATA2D_H
10
11#include "Array2D.h"
12#include "Image2D.h"
13#include "ROI2D.h"
14
15namespace ncorr {
16
17namespace details {
18 class Data2D_nlinfo_interpolator;
19}
20
21class Data2D final {
22// -------------------------------------------------------------------------- //
23// -------------------------------------------------------------------------- //
24// Data2D encompasses everything associated with a 2D Data array. It //
25// supports: //
26// 1) Having a scalefactor, as some 2D data plots can be "reduced" to save //
27// space or computational savings. //
28// 2) Having a region of interest, as not all 2D Data are "full." This //
29// supports ROI2D based interpolation. // //
30// -------------------------------------------------------------------------- //
31// -------------------------------------------------------------------------- //
32public:
33 typedef std::ptrdiff_t difference_type;
34 typedef std::pair<difference_type,difference_type> coords;
35 typedef details::Data2D_nlinfo_interpolator nlinfo_interpolator;
36
37 // Rule of 5 and destructor ----------------------------------------------//
38 Data2D() noexcept : scalefactor() { }
39 Data2D(const Data2D&) = default;
40 Data2D(Data2D&&) noexcept = default;
41 Data2D& operator=(const Data2D&) = default;
42 Data2D& operator=(Data2D&&) = default;
43 ~Data2D() noexcept = default;
44
45 // Additional constructors -----------------------------------------------//
46 Data2D(Array2D<double>, const ROI2D&, difference_type); // r-value
47 Data2D(Array2D<double>, const ROI2D&); // r-value
48 Data2D(Array2D<double>, difference_type); // r-value
49 explicit Data2D(Array2D<double>); // r-value
50
51 // Static factory methods ------------------------------------------------//
52 static Data2D load(std::ifstream&);
53
54 // Operators interface ---------------------------------------------------//
55 friend std::ostream& operator<<(std::ostream&, const Data2D&);
56 friend void imshow(const Data2D&, difference_type delay);
57 friend bool isequal(const Data2D&, const Data2D&);
58 friend void save(const Data2D&, std::ofstream&);
59
60 // Access ----------------------------------------------------------------//
61 // Note that Data2D is immutable, so all access is const.
62 difference_type data_height() const { return A_ptr->height(); }
63 difference_type data_width() const { return A_ptr->width(); }
64 const Array2D<double>& get_array() const { return *A_ptr; }
65 const ROI2D& get_roi() const { return roi; }
66 difference_type get_scalefactor() const { return scalefactor; }
67
68 // Interpolator ----------------------------------------------------------//
70
71 // Utility ---------------------------------------------------------------//
72 std::string size_string() const { return std::to_string(A_ptr->size()); }
73 std::string size_2D_string() const { return "(" + std::to_string(data_height()) + "," + std::to_string(data_width()) + ")"; }
74
75private:
76 // Utility ---------------------------------------------------------------//
77 void chk_scalefactor() const;
78 void chk_data_roi_same_size() const;
79
80 difference_type scalefactor;
81 ROI2D roi; // immutable - ROI2D already has pointer semantics
82 std::shared_ptr<Array2D<double>> A_ptr; // immutable
83};
84
85namespace details {
86 class Data2D_nlinfo_interpolator final {
87 public:
88 typedef Data2D::difference_type difference_type;
89 typedef Data2D::coords coords;
90
91 friend Data2D;
92
93 // Rule of 5 and destructor --------------------------------------//
94 Data2D_nlinfo_interpolator() noexcept : scalefactor(), nlinfo_top(), nlinfo_left() { }
95 Data2D_nlinfo_interpolator(const Data2D_nlinfo_interpolator&) = default;
96 Data2D_nlinfo_interpolator(Data2D_nlinfo_interpolator&&) = default;
97 Data2D_nlinfo_interpolator& operator=(const Data2D_nlinfo_interpolator&) = default;
98 Data2D_nlinfo_interpolator& operator=(Data2D_nlinfo_interpolator&&) = default;
99 ~Data2D_nlinfo_interpolator() noexcept = default;
100
101 // Additional Constructors ---------------------------------------//
102 Data2D_nlinfo_interpolator(const Data2D&, difference_type, INTERP);
103
104 double operator()(double p1, double p2) const { return sub_data_interp(p1_unscaled(p1), p2_unscaled(p2)); }
105 const Array2D<double>& first_order(double p1, double p2) const {
106 const auto &fo_unscaled = sub_data_interp.first_order(p1_unscaled(p1), p2_unscaled(p2));
107 first_order_buf(0) = fo_unscaled(0); // value - do not modify
108 first_order_buf(1) = fo_unscaled(1) / scalefactor; // p1 gradient - must scale
109 first_order_buf(2) = fo_unscaled(2) / scalefactor; // p2_gradient - must scale
110
111 return first_order_buf;
112 }
113
114 private:
115 // Access methods ------------------------------------------------//
116 double p1_unscaled(double p1) const { return (p1 / scalefactor) - nlinfo_top + border; }
117 double p2_unscaled(double p2) const { return (p2 / scalefactor) - nlinfo_left + border; }
118
119 std::shared_ptr<Array2D<double>> sub_data_ptr; // immutable
120 Array2D<double>::interpolator sub_data_interp; // must have copy of interpolator
121 mutable Array2D<double> first_order_buf; // have copy
122 difference_type scalefactor;
123 difference_type nlinfo_top;
124 difference_type nlinfo_left;
125 difference_type border = 20;
126 };
127}
128
129}
130
131#endif /* DATA2D_H */
const Array2D< double > & get_array() const
Definition Data2D.h:64
details::Data2D_nlinfo_interpolator nlinfo_interpolator
Definition Data2D.h:35
const ROI2D & get_roi() const
Definition Data2D.h:65
friend bool isequal(const Data2D &, const Data2D &)
Definition Data2D.cpp:72
Data2D() noexcept
Definition Data2D.h:38
difference_type get_scalefactor() const
Definition Data2D.h:66
std::ptrdiff_t difference_type
Definition Data2D.h:33
Data2D(const Data2D &)=default
static Data2D load(std::ifstream &)
Definition Data2D.cpp:33
difference_type data_width() const
Definition Data2D.h:63
nlinfo_interpolator get_nlinfo_interpolator(difference_type, INTERP) const
Definition Data2D.cpp:88
std::string size_string() const
Definition Data2D.h:72
std::pair< difference_type, difference_type > coords
Definition Data2D.h:34
Data2D(Data2D &&) noexcept=default
difference_type data_height() const
Definition Data2D.h:62
friend void save(const Data2D &, std::ofstream &)
Definition Data2D.cpp:78
std::string size_2D_string() const
Definition Data2D.h:73
friend void imshow(const Data2D &, difference_type delay)
Definition Data2D.cpp:58
ROI2D::difference_type difference_type
Definition ncorr.cpp:5411
INTERP
Definition Array2D.h:77