24 #ifndef CCORRELATION_OPTICALFLOW_INTEGRATED
25 #define CCORRELATION_OPTICALFLOW_INTEGRATED
42 template<
typename T,
typename Timg>
52 this->class_name =
"Correlation : Optical Flow Integrated";
56 virtual void init(CParameterNetCDF &fp)
65 this->m_medianFilter = 0;
68 this->m_ref.assign(3,-1);
70 std::string attribute_name(
"refX");
71 int error = fp.loadAttribute(attribute_name,this->m_ref[0]);
73 attribute_name =
"refY";
74 error = fp.loadAttribute(attribute_name,this->m_ref[1]);
76 attribute_name =
"refZ";
77 error = fp.loadAttribute(attribute_name,this->m_ref[2]);
79 if (this->m_verbose){printf(
"\tReference system computed by user: [%f,%f,%f]\n", this->m_ref[0], this->m_ref[1], this->m_ref[2]);}
83 virtual void assignG(
const Cmesh<T,Timg> &oMesh, CImgList<T> &K, CImgList<T> &Ke)
88 K[0].assign(oMesh.num_mod(),oMesh.num_mod(),1,1, 0);
89 K[1].assign(1,oMesh.num_mod(),1,1, 0);
91 Ke[0].assign(oMesh.num_mod(),oMesh.num_mod(),1,this->m_threadNB, 0);
92 Ke[1].assign(1,oMesh.num_mod(),1,this->m_threadNB, 0);
96 virtual void assignL(
const Cmesh<T,Timg> &oMesh, CImgList<T> &Ve)
99 Ve.assign(1, oMesh.num_mod(),1,1,1, 0);
103 virtual void reset(
const int &thread, CImgList<T> &Ke)
106 cimglist_for(Ke, var)
113 virtual void evalGN(
const std::vector<T> &grad,
const CImgList<T> &N, CImgList<T> &Ve)
119 cimg_forX(N[dim], mode)
121 Ve[0][mode] += grad[dim] * N[dim][mode];
130 for (
int dim=0; dim<oMesh.num_var(); dim++)
132 if (this->m_ref[dim] == -1)
134 ref[dim] = (oImage.cur_dim(dim)*oImage.m_pix[dim])/2.;
138 ref[dim] = this->m_ref[dim]*oImage.m_Rpxmm;
144 virtual void evalU(
const CImgList<T> &solution,
const Cmesh<T,Timg> &oMesh,
const int &elem,
const CImgList<T> &N, std::vector<T> &U)
153 cimg_forX(N[0], mode)
156 U[dim] += solution[mode][elem] * N[dim][mode];
171 if (x[0] != 0 and x[0] != oImage.cur_dim(0)-1)
173 grad[0] = ((T)oImage.m_curImg[0](x[0]+1,x[1],x[2], 0) - (T)oImage.m_curImg[0](x[0]-1,x[1],x[2], 0))/(2.*oImage.m_pix[0]);
177 if (x[1] != 0 and x[1] != oImage.cur_dim(1)-1)
179 grad[1] = ((T)oImage.m_curImg[0](x[0],x[1]+1,x[2], 0) - (T)oImage.m_curImg[0](x[0],x[1]-1,x[2], 0))/(2.*oImage.m_pix[1]);
185 if (x[2] != 0 and x[2] != oImage.cur_dim(2)-1)
187 grad[2] = ((T)oImage.m_curImg[0](x[0],x[1],x[2]+1, 0) - (T)oImage.m_curImg[0](x[0],x[1],x[2]-1, 0))/(2.*oImage.m_pix[2]);
194 virtual void evalShape(
const CImg<Timg> &list,
const Cimage<Timg> &oImage,
const Cfield<T,Timg> &oField,
const std::vector<T> &ref,
const std::vector<T> &lCoor,
const std::vector<T> &gCoor, CImgList<T> &N)
197 std::vector<T> coor;coor.assign(3,0);
198 for (
int i=0; i<lCoor.size(); i++)
200 coor[i] = gCoor[i]*oImage.m_pix[i] - ref[i];
205 (oField.m_pShape)->exec(list, coor, N);
209 virtual void assembly(
const int &thread,
const Cmesh<T,Timg> &oMesh,
const int &elem,
const CImgList<T> &Ke, CImgList<T> &K)
215 cimg_forXYC(Ke[var],x,y,c)
217 K[var](x,y) += Ke[var](x,y,0,c);
224 virtual void metric(
const Cimage<Timg> &oImage,
const Cmesh<T,Timg> &oMesh, CImgList<T> &solution,
Cfield<T,Timg> &oField, CImgList<T> &N, CImgList<T> &Ve, CImgList<T> &Ke, std::vector<T> &ref, std::vector<T> &offset, std::vector<T> &lCoor, std::vector<T> &gCoor, std::vector<T> &U, std::vector<T> &grad, T &residue, T &deformed, CImg<Timg> &list, CImg<int> &p, CImg<T> ¤t_res, CImgList<T> &K)
227 int thread(0), enter(1);
233 cimglist_for(K,var){K[var].fill(0);}
241 e_ref(oImage, oMesh, 0, ref);
243 #pragma omp for schedule(runtime)
244 for (
int pix=0; pix<oImage.m_curImg[0].size(); pix++)
248 oImage.m_curImg[0].contains(oImage.m_curImg[0][pix],lCoor[0],lCoor[1],lCoor[2]);
249 for (
int i=0; i<gCoor.size(); i++){gCoor[i]=lCoor[i];}
253 if (!oImage.m_mask.is_empty())
254 {enter = oImage.m_curMask(gCoor[0], gCoor[1], gCoor[2]);}
260 thread = omp_get_thread_num();
267 evalShape(oImage.m_curImg[0], oImage, oField, ref, lCoor, gCoor, N);
273 evalU(solution, oMesh, 0, N, U);
276 this->
evalRes_loop(oImage, U, gCoor, residue, deformed);
279 current_res[thread] += std::pow(residue,2);
282 this->tensors(thread, Ve, residue, Ke);
290 assembly(thread, oMesh, 0, Ke, K);
291 oField.m_meanRes.push_back(std::sqrt(current_res.sum())*100/oImage.m_res);
296 virtual void solve(CImgList<T> &K,
const Cmesh<T,Timg> &oMesh, CImgList<T> &solution)
301 cimg_forY(K[1],y){solution[y][0] += K[1][y];}
303 if(this->m_verbose){
for(
int i=0; i<solution.size(); i++){std::cout<<solution[i][0]<<
" ";}std::cout<<
"\n";}
307 virtual void test(
const CImgList<T> &solution,
const double &epsilon,
Cfield<T,Timg> &oField, T &previous_res,
int &iter,
int &converged)
313 std::cout<<
"Solution vector : [ ";
314 for(
int i=0; i<oField.m_mode.size(); i++){std::cout<<oField.m_mode[i][0]<<
" ";}std::cout<<
"]\n\n";
319 virtual void export_res(
const Cimage<Timg> &oImage,
const Cmesh<T,Timg> &oMesh,
Cfield<T,Timg> &oField, CImgList<T> &N, std::vector<T> &ref, std::vector<T> &offset, std::vector<T> &lCoor, std::vector<T> &gCoor, std::vector<T> &U, T &residue, T &deformed, CImg<Timg> &list)
322 int thread(0),enter(1);
325 e_ref(oImage, oMesh, 0, ref);
327 #pragma omp for schedule(runtime)
328 for (
int pix=0; pix<oImage.m_curImg[0].size(); pix++)
332 oImage.m_curImg[0].contains(oImage.m_curImg[0][pix],lCoor[0],lCoor[1],lCoor[2]);
333 for (
int i=0; i<gCoor.size(); i++){gCoor[i]=lCoor[i];}
337 if (!oImage.m_mask.is_empty()){enter = oImage.m_curMask(gCoor[0], gCoor[1], gCoor[2]);}
343 thread = omp_get_thread_num();
346 evalShape(oImage.m_curImg[0], oImage, oField, ref, lCoor, gCoor, N);
349 evalU(oField.m_mode, oMesh, 0, N, U);
355 store(oField,oImage,gCoor,U,deformed,residue);
363 virtual void store(
Cfield<T,Timg> &oField,
const Cimage<Timg> &oImage,
const std::vector<T> gCoor,
const std::vector<T> &U,
const T &deformed,
const T &residue)
366 if (oImage.m_storeField)
368 cimglist_for(oField.m_field, dim)
370 oField.m_field(dim, gCoor[0],gCoor[1],gCoor[2]) = U[dim];
374 if (oImage.m_storeDef)
376 oField.m_def(gCoor[0],gCoor[1],gCoor[2]) = deformed;
379 if (oImage.m_storeRes)
381 oField.m_res(gCoor[0],gCoor[1],gCoor[2]) = residue;
void evalRes_final(const Cimage< Timg > &oImage, const std::vector< T > &U, const std::vector< T > &x, T &residue, T &deformed)
Definition: Ccorrelation_opticalFlow.h:230
virtual void gradient(const Cimage< Timg > &oImage, const std::vector< T > &x, std::vector< T > &grad)
Definition: Ccorrelation_opticalFlow_integrated.h:164
It implements optical flow strategy for FEM method.
virtual void init(CParameterNetCDF &fp)
Definition: Ccorrelation_opticalFlow_integrated.h:56
void evalRes_loop(const Cimage< Timg > &oImage, const std::vector< T > &U, const std::vector< T > &x, T &residue, T &deformed)
Definition: Ccorrelation_opticalFlow.h:209
Definition: Ccorrelation_opticalFlow_integrated.h:43
This is the mother class of Optical Flow strategies: It implements different steps required for the i...
Definition: Ccorrelation_opticalFlow.h:53
Definition: Ccorrelation_opticalFlow_fem.h:43
virtual void init(CParameterNetCDF &fp)
Definition: Ccorrelation_opticalFlow.h:69