38 #define cimg_plugin  "plugins/add_fileformat.h" 
   39 #define cimg_use_netcdf 
   41 #ifdef cimg_use_netcdf 
   42  #include "../NetCDF.Tool/struct_parameter_NetCDF.h" 
   45  #define     cimg_plugin2 "plugins/netcdf_file_format4CImg2.h" 
   46  #define cimglist_plugin2 "plugins/netcdf_file_format4CImgList2.h" 
   47  #include "../CImg.Tool/CImg_NetCDF.h" 
   50 #include "textcolor.h" 
   56 template<
typename Timg> 
 
   62     std::string class_name;
 
   63     std::string m_name, m_type;
 
   65     CImgList<Timg> m_img, m_curImg;
 
   66     CImg<char> m_mask, m_curMask;
 
   69     std::vector<float> m_pix;
 
   70     std::string m_maskName, m_dirPath; 
 
   71     int m_dim_sample, m_dim_image, m_dim;
 
   73     int m_storeImg, m_storeDef, m_storeRes, m_storeField, m_storeStr, m_storeActiv, m_display, m_mode;
 
   75     std::string m_oFormat;
 
   80     const char* m_paramPath;
 
   86       class_name = 
"Image : mother";
 
   90     virtual void init(CParameterNetCDF &fp)
 
   94       std::string attribute_name = 
"mode";
 
   95       int error = fp.loadAttribute(attribute_name,m_mode);
 
   96       if (this->m_verbose){printf(
"\t\t separate list mode -> %i\n", m_mode);}
 
   99       std::string m_variable = 
"output";
 
  102       fp.loadVar(var,&m_variable);
 
  106       attribute_name = 
"format";
 
  107       error = fp.loadAttribute(attribute_name,m_oFormat);
 
  108       if (this->m_verbose){printf(
"\t\t output file format -> %s\n", m_oFormat.c_str());}
 
  111       attribute_name = 
"display_mode";
 
  112       error = fp.loadAttribute(attribute_name,m_display);
 
  113       if (this->m_verbose){printf(
"\t\t display mode -> %i\n", m_display);}
 
  116       attribute_name = 
"store_img";
 
  117       error = fp.loadAttribute(attribute_name,m_storeImg);
 
  118       if (this->m_verbose){printf(
"\t\t input data storage -> %i\n", m_storeImg);}
 
  121       attribute_name = 
"store_def";
 
  122       error = fp.loadAttribute(attribute_name,m_storeDef);
 
  123       if (this->m_verbose){printf(
"\t\t deformed image storage -> %i\n", m_storeDef);}
 
  126       attribute_name = 
"store_field";
 
  127       error = fp.loadAttribute(attribute_name,m_storeField);
 
  128       if (this->m_verbose){printf(
"\t\t field storage -> %i\n", m_storeField);}
 
  131       attribute_name = 
"store_res";
 
  132       error = fp.loadAttribute(attribute_name,m_storeRes);
 
  133       if (this->m_verbose){printf(
"\t\t image residue storage -> %i\n", m_storeRes);}
 
  137       if (m_storeRes or m_storeField or m_storeDef){m_storeActiv = 1;}
 
  140       attribute_name = 
"store_strain";
 
  141       error = fp.loadAttribute(attribute_name,m_storeStr);
 
  142       if (this->m_verbose){printf(
"\t\t strain field storage -> %i\n", m_storeStr);}
 
  146       attribute_name = 
"ratio_pxmm";
 
  147       error = fp.loadAttribute(attribute_name,m_Rpxmm);
 
  148       if (this->m_verbose){std::cout<<
"\t\t ratio pix/mm -> "<<m_Rpxmm<<
"\n";}
 
  152     void exec(
int argc, 
char *argv[], 
const int &sample = 0)
 
  155       load_images(m_list, m_dirPath, sample);
 
  156       if (m_maskName != 
""){load_mask(m_maskName, m_dirPath);}
 
  161     virtual void load_paths(CParameterNetCDF &fp) = 0;
 
  163     virtual void load_images(CImg<char> &list, std::string &dir, 
const int &sample) = 0;
 
  165     void load_mask(std::string &name, std::string &dir)
 
  168       m_mask.load((dir + name).c_str());
 
  174       if (this->m_verbose){printf(
"\t mask : %s\n",(dir + name).c_str());}
 
  190         int suElem = std::pow(2,filter);
 
  193         for (
int i=0; i<3; i++)
 
  195           if (dim(i)>1){X.push_back(dim(i)/suElem);}
else{X.push_back(1);}
 
  196           m_pix.push_back(((
float)dim(i)/(
float)X[i])*m_Rpxmm);
 
  199         m_curImg.assign(m_img.size(), X[0], X[1], X[2], 1, 0);
 
  200         if (!m_mask.is_empty()){m_curMask.assign(X[0], X[1], X[2], 1, 1);}
 
  212           int X(0), Y(0), Z(0);
 
  214           std::vector<double> buff0;
 
  215           double buff1(0), counter(0);
 
  217           #pragma omp for schedule(runtime) 
  218           for (
int pix=0; pix<m_curImg[0].size(); pix++)
 
  221             m_curImg[0].contains(m_curImg[0][pix],X,Y,Z);
 
  223             buff0.assign(m_img.size(),0);
 
  227             for (
int x=0; x<suElem; x++)
 
  229               for (
int y=0; y<suElem; y++)
 
  231                 for (
int z=0; z<=(suElem-1)*(num_dims()-2); z++)
 
  234                   if (m_img[0].contains(m_img(0,X*suElem+x, Y*suElem+y, Z*suElem+z,0)))
 
  239                     cimglist_for(m_img, list)
 
  241                       buff0[list] += m_img(list, X*suElem+x, Y*suElem+y, Z*suElem+z);
 
  244                     if (!m_mask.is_empty())
 
  245                     {buff1 += m_mask(X*suElem+x, Y*suElem+y, Z*suElem+z);}
 
  252             cimglist_for(m_curImg, list){m_curImg[list][pix] = buff0[list]/counter;}
 
  253             if (!m_mask.is_empty()){m_curMask[pix] = buff1/counter;}
 
  265         m_curImg = m_img.get_shared();
 
  266         if (!m_mask.is_empty()){m_curMask = m_mask.get_shared();}
 
  268         for (
int i=0; i<3; i++)
 
  270           if (dim(i)>1){m_pix.push_back(m_Rpxmm);}
else{m_pix.push_back(1);}
 
  285       for (
int p=0; p<m_curImg[0].size(); p++)
 
  286       {m_res += std::pow((
double)m_curImg[0][p]-(
double)m_curImg[1][p],2);}
 
  287       m_res = std::sqrt(m_res);
 
  289       std::cout<<
"\nreference residue at current scale : "<<m_res<<
" in GL\n";
 
  295     void save_netcdf(CImgList<T> &img, std::string name = 
"images", 
const int &sample = 0)
 const 
  299       std::ostringstream sample_index;
 
  302       int n = std::floor(log10(img.size()) + 1);
 
  304       img.dim_names.clear();
 
  305       if (img[0].width() != 1 ){img.dim_names.push_back( 
"dimX" );}
 
  306       if (img[0].height() != 1 ){img.dim_names.push_back( 
"dimY" );}
 
  307       if (img[0].depth() != 1 ){img.dim_names.push_back( 
"dimZ" );}
 
  308       if (img[0].spectrum() != 1 ){img.dim_names.push_back( 
"dimC" );}
 
  310       img.var_names.clear();
 
  311       img.unit_names.clear();
 
  315         sample_index.width(n);
 
  316         sample_index.fill(
'0');
 
  319         path = 
"Var_" + sample_index.str();
 
  321         img.var_names.push_back( path );
 
  322         img.unit_names.push_back( 
"none" );
 
  324         sample_index.str(
"");
 
  328       std::string output_name = name + 
".nc";
 
  335     void save_netcdf(CImg<T> &img, std::string name = 
"images", 
const int sample = 0)
 const 
  338       img.dim_names.clear();
 
  339       if (img.width() != 1 ){img.dim_names.push_back( 
"dimX" );}
 
  340       if (img.height() != 1 ){img.dim_names.push_back( 
"dimY" );}
 
  341       if (img.depth() != 1 ){img.dim_names.push_back( 
"dimZ" );}
 
  342       if (img.spectrum() != 1 ){img.dim_names.push_back( 
"dimC" );}
 
  344       img.var_name = 
"Var";
 
  345       img.unit_name = 
"none";
 
  347       std::string output_name = name + 
".nc";
 
  354     void save_unlimited(CImgList<T> &imgOut, std::string &fileOut, 
const int &i)
 const 
  363         imgOut.save(fileOut.c_str());
 
  365         if (imgOut[0].depth() == 1){
 
  366           imgOut.dim_names.push_back( 
"dummy_0" );}
 
  367         if (imgOut[0].spectrum() == 1){
 
  368           imgOut.dim_names.push_back( 
"dummy_1" );}
 
  369         imgOut.dim_time=
"dimS";
 
  372           imgOut.pNc_file=NULL;
 
  373           imgOut.NetCDF_init();
 
  374           imgOut.save(fileOut.c_str());
 
  375           imgOut.is_NetCDF_open=
true;
 
  379           imgOut.save(fileOut.c_str());
 
  381       #endif //cimg_plugin2 
  395         imgOut.save(fileOut.c_str());
 
  397         if (imgOut.depth() == 1){
 
  398           imgOut.dim_names.push_back( 
"dummy_0" );}
 
  399         if (imgOut.spectrum() == 1){
 
  400           imgOut.dim_names.push_back( 
"dummy_1" );}
 
  401         imgOut.dim_time=
"dimS";
 
  404           imgOut.pNc_file=NULL;
 
  405           imgOut.NetCDF_init();
 
  406           imgOut.save(fileOut.c_str());
 
  407           imgOut.is_NetCDF_open=
true;
 
  411           imgOut.save(fileOut.c_str());
 
  413       #endif //cimg_plugin2 
  422       return m_curImg.size();
 
  426     int cur_dim(
const int &i)
 const 
  431         case 0: 
return m_curImg[0].width(); 
break;
 
  432         case 1: 
return m_curImg[0].height(); 
break;
 
  433         case 2: 
return m_curImg[0].depth(); 
break;
 
  434         case 3: 
return m_curImg[0].spectrum(); 
break;
 
  437           std::cerr<<class_name<<
"::"<<__func__<<
": error: id="<<i<<
" is unknown as CImg dimensions\n"<<std::flush;
 
  443     int dim(
const int &i)
 const 
  448         case 0: 
return m_img[0].width(); 
break;
 
  449         case 1: 
return m_img[0].height(); 
break;
 
  450         case 2: 
return m_img[0].depth(); 
break;
 
  451         case 3: 
return m_img[0].spectrum(); 
break;
 
  454           std::cerr<<class_name<<
"::"<<__func__<<
": error: id="<<i<<
" is unknown as CImg dimensions\n"<<std::flush;
 
  467     int num_samples()
 const 
void save_netcdf(CImgList< T > &img, std::string name="images", const int &sample=0) const 
Definition: Cimage.h:295
void save_unlimited(CImgList< T > &imgOut, std::string &fileOut, const int &i) const 
Definition: Cimage.h:354
void resize(const int &filter)
Definition: Cimage.h:178
void save_unlimited(CImg< T > &imgOut, std::string &fileOut, const int &i) const 
Definition: Cimage.h:386