source: XIOS/dev/branch_yushan_merged/src/transformation/axis_algorithm_zoom.cpp @ 1205

Last change on this file since 1205 was 1205, checked in by yushan, 4 years ago

branch merged with trunk @1200

File size: 5.2 KB
Line 
1/*!
2   \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.
8 */
9#include "axis_algorithm_zoom.hpp"
10#include "axis.hpp"
11#include "grid.hpp"
12#include "grid_transformation_factory_impl.hpp"
13#include "zoom_axis.hpp"
14
15namespace xios {
16CGenericAlgorithmTransformation* CAxisAlgorithmZoom::create(CGrid* gridDst, CGrid* gridSrc,
17                                                           CTransformation<CAxis>* transformation,
18                                                           int elementPositionInGrid,
19                                                           std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
20                                                           std::map<int, int>& elementPositionInGridSrc2AxisPosition,
21                                                           std::map<int, int>& elementPositionInGridSrc2DomainPosition,
22                                                           std::map<int, int>& elementPositionInGridDst2ScalarPosition,
23                                                           std::map<int, int>& elementPositionInGridDst2AxisPosition,
24                                                           std::map<int, int>& elementPositionInGridDst2DomainPosition)
25{
26  std::vector<CAxis*> axisListDestP = gridDst->getAxis();
27  std::vector<CAxis*> axisListSrcP  = gridSrc->getAxis();
28
29  CZoomAxis* zoomAxis = dynamic_cast<CZoomAxis*> (transformation);
30  int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid];
31  int axisSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid];
32
33  return (new CAxisAlgorithmZoom(axisListDestP[axisDstIndex], axisListSrcP[axisSrcIndex], zoomAxis));
34}
35bool CAxisAlgorithmZoom::registerTrans()
36{
37  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_ZOOM_AXIS, create);
38}
39
40CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)
41: CAxisAlgorithmTransformation(axisDestination, axisSource)
42{
43  zoomAxis->checkValid(axisSource);
44  zoomBegin_ = zoomAxis->begin.getValue();
45  zoomSize_  = zoomAxis->n.getValue();
46  zoomEnd_   = zoomBegin_ + zoomSize_ - 1;
47
48  if (zoomSize_ > axisSource->n_glo.getValue())
49  {
50    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_ );
54  }
55
56  if (!zoomAxis->index.isEmpty())
57  {
58    int sz = zoomAxis->index.numElements();
59    zoomIndex_.resize(sz);
60    for (int i = 0; i < sz; ++i)
61      zoomIndex_[i] = zoomAxis->index(i);
62
63    std::sort(zoomIndex_.begin(), zoomIndex_.end());
64  }
65}
66
67/*!
68  Compute the index mapping between axis on grid source and one on grid destination
69*/
70void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
71{
72  this->transformationMapping_.resize(1);
73  this->transformationWeight_.resize(1);
74
75  TransformationIndexMap& transMap = this->transformationMapping_[0];
76  TransformationWeightMap& transWeight = this->transformationWeight_[0];
77
78  StdSize niSource = axisSrc_->n.getValue();
79  StdSize ibeginSource = axisSrc_->begin.getValue();
80  StdSize iendSource = ibeginSource + niSource - 1;
81
82  StdSize ibegin = std::max(ibeginSource, zoomBegin_);
83  StdSize iend = std::min(iendSource, zoomEnd_);
84  StdSize ni = iend + 1 - ibegin;
85  if (iend < ibegin) ni = 0;
86
87  if (!zoomIndex_.empty())
88  {
89    std::vector<int>::iterator itZoomBegin, itZoomEnd;
90    itZoomBegin = std::lower_bound(zoomIndex_.begin(), zoomIndex_.end(), ibeginSource);
91    itZoomEnd   = std::upper_bound(zoomIndex_.begin(), zoomIndex_.end(), iendSource);           
92    for (; itZoomBegin != itZoomEnd; ++itZoomBegin)
93    {
94      transMap[*itZoomBegin].push_back(*itZoomBegin);
95      transWeight[*itZoomBegin].push_back(1.0);
96    }
97  }
98  else
99  {
100    for (StdSize idx = 0; idx < ni; ++idx)
101    {
102      transMap[ibegin+idx].push_back(ibegin+idx);
103      transWeight[ibegin+idx].push_back(1.0);
104    }
105  }
106
107  updateZoom();
108  updateAxisDestinationMask();
109}
110
111/*!
112  After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated
113*/
114void CAxisAlgorithmZoom::updateZoom()
115{
116  axisDest_->global_zoom_begin = zoomBegin_;
117  axisDest_->global_zoom_n  = zoomSize_;
118  if (!zoomIndex_.empty())
119  {
120    axisDest_->global_zoom_index.resize(zoomIndex_.size());
121    std::copy(zoomIndex_.begin(), zoomIndex_.end(), axisDest_->global_zoom_index.begin());
122  }
123}
124
125/*!
126  Update mask on axis
127  Because only zoomed region on axis is not masked, the remaining must be masked to make sure
128correct index be extracted
129*/
130void CAxisAlgorithmZoom::updateAxisDestinationMask()
131{
132  StdSize niMask = axisDest_->mask.numElements();
133  StdSize iBeginMask = axisDest_->begin.getValue();
134  StdSize globalIndexMask = 0;
135  TransformationIndexMap& transMap = this->transformationMapping_[0];
136  TransformationIndexMap::const_iterator ite = (transMap).end();
137  for (StdSize idx = 0; idx < niMask; ++idx)
138  {
139    globalIndexMask = iBeginMask + idx;
140    if (transMap.find(globalIndexMask) == ite)
141      (axisDest_->mask)(idx) = false;
142  }
143}
144
145}
Note: See TracBrowser for help on using the repository browser.