Ignore:
Timestamp:
07/12/18 19:12:32 (6 years ago)
Author:
oabramkina
Message:

Replacing axis zoom by axis extract.
Zoom private attributes are gone for good.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/transformation/axis_algorithm_zoom.cpp

    r1202 r1559  
    11/*! 
    22   \file axis_algorithm_zoom.cpp 
    3    \author Ha NGUYEN 
    4    \since 03 June 2015 
    5    \date 12 June 2015 
    6  
    7    \brief Algorithm for zooming on an axis. 
     3   \brief Algorithm for zooming an axis. 
    84 */ 
    95#include "axis_algorithm_zoom.hpp" 
     
    4339  zoomAxis->checkValid(axisSource); 
    4440  zoomBegin_ = zoomAxis->begin.getValue(); 
    45   zoomSize_  = zoomAxis->n.getValue(); 
    46   zoomEnd_   = zoomBegin_ + zoomSize_ - 1; 
     41  zoomN_  = zoomAxis->n.getValue(); 
     42  zoomEnd_   = zoomBegin_ + zoomN_ - 1; 
    4743 
    48   if (zoomSize_ > axisSource->n_glo.getValue()) 
     44  if (zoomN_ > axisSource->n_glo.getValue()) 
    4945  { 
    5046    ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)", 
    51            << "Zoom size is greater than global size of axis source" 
    52            << "Global size of axis source " <<axisSource->getId() << " is " << axisSource->n_glo.getValue()  << std::endl 
    53            << "Zoom size is " << zoomSize_ ); 
     47           << "Zoom size is greater than global size of source axis" 
     48           << "Global size of source axis " <<axisSource->getId() << " is " << axisSource->n_glo.getValue()  << std::endl 
     49           << "Zoom size is " << zoomN_ ); 
    5450  } 
    5551 
    56   if (!zoomAxis->index.isEmpty()) 
     52  int idxSrc, nDest = 0, beginDestLoc, beginDestGlo = 0 ; 
     53  int indGloDest, indGloSrc, iSrc; 
     54  for (int i = 0; i < axisSrc_->n.getValue(); i++) 
    5755  { 
    58     int sz = zoomAxis->index.numElements(); 
    59     zoomIndex_.resize(sz); 
    60     for (int i = 0; i < sz; ++i) 
    61       zoomIndex_[i] = zoomAxis->index(i); 
     56    idxSrc = axisSrc_->index(i); 
     57    if ((idxSrc >= zoomBegin_) && (idxSrc <= zoomEnd_)) 
     58    { 
     59      if (nDest == 0) beginDestLoc = i; 
     60      ++nDest; 
     61    } 
     62  } 
     63  beginDestGlo = beginDestLoc + axisSrc_->begin - zoomBegin_; 
     64  axisDest_->n_glo.setValue(zoomN_); 
     65  axisDest_->n.setValue(nDest); 
     66  axisDest_->begin.setValue(beginDestGlo); 
     67  axisDest_->index.resize(nDest); 
    6268 
    63     std::sort(zoomIndex_.begin(), zoomIndex_.end()); 
    64   } 
     69  axisDest_->data_n.setValue(nDest); 
     70  axisDest_->data_begin.setValue(0); 
     71  axisDest_->data_index.resize(nDest); 
    6572 
    66 } 
    67  
    68 /*! 
    69   Compute the index mapping between axis on grid source and one on grid destination 
    70 */ 
    71 void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 
    72 { 
    73   // We use all index of source and destination to calculate the mapping index of zoom. 
    74   // The server who receives the "zoomed" fields will decide whether it will forward these fields or write "real zoomed" fields into file 
    75   // That means servers need to change to cover this problem. 
    76   StdSize niSource = axisSrc_->n.getValue(); 
    77   StdSize ibeginSource = axisSrc_->begin.getValue(); 
    78   StdSize iendSource = ibeginSource + niSource - 1; 
    79  
    80   StdSize ibegin = std::max(ibeginSource, zoomBegin_); 
    81   StdSize iend = std::min(iendSource, zoomEnd_); 
    82   StdSize ni = iend + 1 - ibegin; 
    83   if (iend < ibegin) ni = 0; 
     73  axisDest_->mask.resize(nDest); 
     74  if (axisSrc_->hasValue) axisDest_->value.resize(nDest); 
     75  if (axisSrc_->hasLabel) axisDest_->label.resize(nDest); 
     76  if (axisSrc_->hasBounds) axisDest_->bounds.resize(2,nDest); 
    8477 
    8578  this->transformationMapping_.resize(1); 
    8679  this->transformationWeight_.resize(1); 
    87  
    8880  TransformationIndexMap& transMap = this->transformationMapping_[0]; 
    8981  TransformationWeightMap& transWeight = this->transformationWeight_[0]; 
    9082 
    91   if (!zoomIndex_.empty()) 
     83  for (int iDest = 0; iDest < nDest; iDest++) 
    9284  { 
    93     std::vector<int>::iterator itZoomBegin, itZoomEnd; 
    94     itZoomBegin = std::lower_bound(zoomIndex_.begin(), zoomIndex_.end(), ibeginSource); 
    95     itZoomEnd   = std::upper_bound(zoomIndex_.begin(), zoomIndex_.end(), iendSource);             
    96     for (; itZoomBegin != itZoomEnd; ++itZoomBegin) 
     85    iSrc = iDest + beginDestLoc; 
     86    axisDest_->index(iDest) = iDest + beginDestGlo; 
     87    axisDest_->data_index(iDest) = axisSrc_->data_index(iSrc) - beginDestLoc; 
     88    axisDest_->mask(iDest) = axisSrc_->mask(iSrc); 
     89 
     90    if (axisSrc_->hasValue) 
     91      axisDest_->value(iDest) = axisSrc_->value(iSrc); 
     92    if (axisSrc_->hasLabel) 
     93      axisDest_->label(iDest) = axisSrc_->label(iSrc); 
     94    if (axisSrc_->hasBounds) 
    9795    { 
    98       transMap[*itZoomBegin].push_back(*itZoomBegin); 
    99       transWeight[*itZoomBegin].push_back(1.0); 
     96      axisDest_->bounds(0,iDest) = axisSrc_->bounds(0,iSrc); 
     97      axisDest_->bounds(1,iDest) = axisSrc_->bounds(1,iSrc); 
    10098    } 
    101   } 
    102   else 
    103   { 
    104     for (StdSize idx = 0; idx < ni; ++idx) 
    105     { 
    106       transMap[ibegin+idx].push_back(ibegin+idx); 
    107       transWeight[ibegin+idx].push_back(1.0); 
    108     } 
    109   } 
     99    indGloDest = axisDest_->index(iDest); 
     100    indGloSrc = axisSrc_->index(iSrc); 
     101    transMap[indGloDest].push_back(indGloSrc); 
     102    transWeight[indGloDest].push_back(1.0); 
    110103 
    111   updateZoom(); 
    112   // updateAxisDestinationMask(); 
    113 } 
    114  
    115 /*! 
    116   After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated 
    117 */ 
    118 void CAxisAlgorithmZoom::updateZoom() 
    119 { 
    120   axisDest_->global_zoom_begin = zoomBegin_; 
    121   axisDest_->global_zoom_n  = zoomSize_; 
    122   if (!zoomIndex_.empty()) 
    123   { 
    124     axisDest_->global_zoom_index.resize(zoomIndex_.size()); 
    125     std::copy(zoomIndex_.begin(), zoomIndex_.end(), axisDest_->global_zoom_index.begin()); 
    126104  } 
    127105} 
    128106 
    129107/*! 
    130   Update mask on axis 
    131   Because only zoomed region on axis is not masked, the remaining must be masked to make sure 
    132 correct index be extracted 
     108  Compute the index mapping between domain on grid source and one on grid destination 
    133109*/ 
    134 // void CAxisAlgorithmZoom::updateAxisDestinationMask() 
    135 // { 
    136 //   StdSize niMask = axisDest_->mask.numElements(); 
    137 //   StdSize iBeginMask = axisDest_->begin.getValue(); 
    138 //   StdSize globalIndexMask = 0; 
    139 //   TransformationIndexMap& transMap = this->transformationMapping_[0]; 
    140 //   TransformationIndexMap::const_iterator ite = (transMap).end(); 
    141 //   for (StdSize idx = 0; idx < niMask; ++idx) 
    142 //   { 
    143 //     globalIndexMask = iBeginMask + idx; 
    144 //     if (transMap.find(globalIndexMask) == ite) 
    145 //       (axisDest_->mask)(idx) = false; 
    146 //   } 
    147 // } 
     110void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 
     111{ 
     112} 
    148113 
    149114} 
Note: See TracChangeset for help on using the changeset viewer.