31 template<
typename U,
typename F>
32 void IterativeAlignmentEstimator<T>::updateEstimation(AlignmentEstimation &est,
33 const U &newVals,
const F &func) {
34 size_t len = newVals.size();
35 for (
size_t i = 0;
i <
len; ++
i) {
36 func(newVals.at(
i), est.poses.at(
i));
41 void IterativeAlignmentEstimator<T>::print(
const AlignmentEstimation &e) {
42 for (
auto &
m : e.poses) {
43 printf(
"([%f %f], %f) ",
MAT_ELEM(
m, 0, 2),
MAT_ELEM(
m, 1, 2),
RAD2DEG(atan2(
MAT_ELEM(
m, 1, 0),
MAT_ELEM(
m, 0, 0))));
49 T *IterativeAlignmentEstimator<T>::applyTransform(
const AlignmentEstimation &estimation) {
51 t.reserve(9 * estimation.poses.size());
54 for (
size_t j = 0;
j < estimation.poses.size(); ++
j) {
56 for (
int i = 0;
i < 9; ++
i) {
57 t.emplace_back(tmp.mdata[i]);
60 return m_transformer.interpolate(t);
66 const T * __restrict__ orig, T * __restrict__ copy,
bool hasSingleOrig) {
67 const size_t n = dims.
n();
68 const size_t z = dims.
z();
69 const size_t y = dims.
y();
70 const size_t x = dims.
x();
72 auto futures = std::vector<std::future<void>>();
74 auto workload = [&](
int id,
size_t signalId){
84 for (
size_t i = 0; i <
n; ++
i) {
85 futures.emplace_back(pool.
push(workload, i));
87 for (
auto &
f : futures) {
97 auto stepRotation = [&] {
98 m_rot_est.compute(m_transformer.getDest());
99 const auto &cRotEst = m_rot_est;
101 updateEstimation(est,
102 cRotEst.getRotations2D(),
109 auto stepShift = [&] {
110 m_shift_est.computeShift2DOneToN(m_transformer.getDest());
111 updateEstimation(est, m_shift_est.getShifts2D(),
119 m_transformer.copySrcToDest();
120 for (
unsigned i = 0; i < iters; ++
i) {
124 if ( ! m_sameEstimators) {
130 if ( ! m_sameEstimators) {
136 m_meritComputer.compute(m_transformer.getDest());
137 const auto &mc = m_meritComputer;
144 m_meritComputer.loadReference(ref);
145 m_shift_est.load2DReferenceOneToN(ref);
146 if ( ! m_sameEstimators) {
147 m_rot_est.loadReference(ref);
153 const T * __restrict__ others,
155 m_transformer.setSrc(others);
158 const size_t n = m_rot_est.getSettings().otherDims.n();
161 compute(iters, result_RS,
true);
164 compute(iters, result_SR,
false);
166 for (
size_t i = 0; i <
n; ++
i) {
167 if (result_RS.figuresOfMerit.at(i) < result_SR.figuresOfMerit.at(i)) {
168 result_RS.figuresOfMerit.at(i) = result_SR.figuresOfMerit.at(i);
169 result_RS.poses.at(i) = result_SR.poses.at(i);
178 if (m_rot_est.getSettings().otherDims != m_shift_est.getDimensions()) {
181 if (m_rot_est.getSettings().type != m_shift_est.getAlignType()) {
#define REPORT_ERROR(nerr, ErrormMsg)
auto push(F &&f, Rest &&... rest) -> std::future< decltype(f(0, rest...))>
CUDA_HD constexpr size_t z() const
#define MAT_ELEM(m, i, j)
CUDA_HD constexpr size_t x() const
#define M3x3_INV(Ainv, A)
static void sApplyTransform(ctpl::thread_pool &pool, const Dimensions &dims, const AlignmentEstimation &estimation, const T *orig, T *copy, bool hasSingleOrig)
AlignmentEstimation compute(const T *others, unsigned iters=3)
CUDA_HD constexpr size_t sizeSingle() const
std::vector< float > figuresOfMerit
CUDA_HD constexpr size_t y() const
CUDA_HD constexpr size_t n() const
std::vector< Matrix2D< float > > poses
void loadReference(const T *ref)
Some logical error in the pipeline.